akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
    #include <ext/pb_ds/assoc_container.hpp>
    #include <ext/pb_ds/tree_policy.hpp>
    #include <ext/pb_ds/detail/standard_policies.hpp>
    using namespace std;
    using namespace __gnu_pbds;
    #define endl "\n"
    #define fi first
    #define se second
    #define pb push_back
    #define ll long long
    #define ld long double
    #define pii pair<ll,ll>
    #define read(t) ll t;cin>>t;
    #define all(x) x.begin(),x.end()
    #define f(a,b,c) for(ll a=b;a<c;a++)
    #define For(i,n) for(ll i=0;i<n;i++)
    #define what(x) cerr << #x << " is " << x << endl;
    #define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) ;
    typedef tree<pair<ll,ll>, null_type,less<pair<ll,ll>>, rb_tree_tag,tree_order_statistics_node_update> ordered_mset;
    typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
    typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
/*.....................................................................................................................*/

    const ll mod=(ll)1e9+7;
    ll add(ll x,ll y) {return (x+y)%mod;}
    ll mult(ll x, ll y){return ((x%mod )* (y%mod)) % mod;}
    long long binpow(long long x, long long p) 
    {
        if (p == 0) {return 1;}
    	if (p == 2 || (p & 1)) {return mult(x, binpow(x, p - 1));}
    	return binpow(binpow(x, p / 2), 2);
    }
    ll modinv(ll a) {return binpow(a,mod-2);}
    double pi=3.141592653589793238462641;
    ll dx[4]={1,-1,0,0},dy[4]={0,0,1,-1};
    const ll man=(ll)1e5+5;
/*........................................................................................................................*/


signed main()
{
    fast;
    ll h,n;
    cin>>h>>n;
    ll a[n];
    ll sum=0;
    For(i,n)
    {
        cin>>a[i];
        sum+=a[i];
    }
    if(sum>=h)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;    
}

Measured memory_bytes: 4400
#include <bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define int long long
#define ld long double
#define fi first
#define se second
#define all(uiet) uiet.begin(),uiet.end()
#define read(UIET) for(int i = 0; i < n; ++i) cin >> UIET[i]
#define out(UIET) for(int i = 0; i < n; ++i) cout << UIET[i]
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define vpp vector<pair< int, int > >
#define pll pair<int , int >
#define ppll pair < pll , pll >
#define debug(n1) cout << n1 << endl
#define len(a) ((int) (a).size())
#define endl "\n"
#define mod 1000000007
const int INF=(1LL<<60)-1;
const int maxN = 1000001;
string extractStringAtKey(string str, int key){
    char *s = strtok((char *)str.c_str(), " ");
    while(key > 1){
        s = strtok(NULL, " ");
        key--;
    }
    return (string)s;
}
bool prime[maxN + 1];
void seive(){
    memset(prime, true, sizeof(prime));
    for(int i = 2; i * i <= maxN; ++i){
        if(prime[i]){
            for(int j = i * i; j <= maxN; j += i){
                prime[j] = false;
            }
        }
    }
}
int32_t main(){
    SPEED;
    int n;
    cin >> n;
    int nc = n;
    vector<int> arr(n);
    for(int i = 0; i < n; ++i){
        cin >> arr[i];
    }
    for(int i = 1; i < n; ++i){
        if(arr[i] > arr[i - 1]) arr[i]--;
    }
    for(int i = 0; i < n - 1; ++i){
        if(arr[i + 1] < arr[i]){
            cout << "No";
            return 0;
        }
    }
    cout << "Yes" ;
}

Measured memory_bytes: 3928
import re
S=input()
keyence = 'keyence'
patterns = []
for i in range(len(keyence)):
    patterns.append('^'+keyence[:i]+'[a-z]*'+keyence[i:]+'$')
for p in patterns:
    if re.match(p,S):
        print('YES')
        exit()
print('NO')

Measured memory_bytes: 3188
#include<bits/stdc++.h>
#define sz(x) ((int)x.size())
#define mp(x, y) make_pair(x, y)
using namespace std;

int n, a[105];
stack<int> ans;

bool check(){
    for(int i = n; i >= 1; i --){
        for(int j = i; j >= 1; j --) if(a[j] == j){
            ans.push(j);
            for(int k = j; k < i; k ++)
                a[k] = a[k + 1];
            a[i] = 0;
            break;
        }
    }
    for(int i = 1; i <= n; i ++) if(a[i])
        return false;
    return true;
}

int main(){
    scanf("%d", &n);
    for(int i = 1; i <= n; i ++)
        scanf("%d", a + i);
    if(check()){
        while(sz(ans)){
            cout << ans.top() << '\n';
            ans.pop();
        }
    }
    else
        cout << -1;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int F(int n);

int main(void)
{
	int n;
	
	while (scanf("%d", &n) != EOF){
		printf("%d\n", F(n));
	}
	
	return (0);
}

int F(int n)
{
	if (n == 1){
		return (2);
	}
	else {
		return (F(n-1) + n);
	}
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;

typedef long long LL;

const int N = 1e5 + 5;

int A[N];
set <int> S1, S2;
map <int, int> M;

int main()
{
    ios::sync_with_stdio(0); cin.tie(0);
    int n;
    cin>>n;

    for(int i = 1; i <= n; i++)
    {
        cin>>A[i];
        S1.insert(A[i]);
        M[A[i]]++;
    }

    for(int i: S1)
    {
        if(M[i] >= 2)
            S2.insert(i);
    }

    LL area, l = 0, b = 0;
    if(S2.size() >= 2)
    {
        if(M[*S2.rbegin()] >= 4)
        {
            l = b = *S2.rbegin();
        }
        else
        {
            set <int> :: reverse_iterator it = S2.rbegin();
            l = *it;
            it++;
            b = *it;
        }
    }
    else if(M[*S2.begin()] >= 4)
    {
        l = b = *S2.begin();
    }

    area = l * b;
    cout<<area<<"\n";
    return 0;
}

Measured memory_bytes: 9984
import java.util.*;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		int Q = sc.nextInt();
      	int[] Player;
      	int Current;
      	Player=new int[N]; 	
      	for (int i = 0 ; i < Q; i ++){
          Current = sc.nextInt();
          Player[Current-1]=Player[Current-1]+1;          
        }
      	for ( int i = 0 ; i < N ; i ++){
          if((Player[i]+K-Q)>0){
          	System.out.println("Yes");
          }else{
            System.out.println("No");
          }
        }
	}
}

Measured memory_bytes: 57624
#include <iostream>
using namespace std;

int main() {
	int w, h, x, y; cin >> w >> h >> x >> y;
	double ans = (double)w * h / 2;
	int multi = (w == x * 2 && h == y * 2) ? 1 : 0;
	printf("%.10f %d", ans, multi);

	return 0;
}

Measured memory_bytes: 256
N,M,L=map(int,input().split())
G=[[10**15 for i in range(N)] for i in range(N)]
for i in range(M):
    a,b,c=map(int,input().split())
    G[a-1][b-1]=c
    G[b-1][a-1]=c
for k in range(N):
    for i in range(N):
        for j in range(N):
            G[i][j]=min(G[i][j],G[i][k]+G[k][j])
H=[[10**15 for i in range(N)] for i in range(N)]
for i in range(N):
    for j in range(N):
        if G[i][j]<=L:
            H[i][j]=1
for k in range(N):
    for i in range(N):
        for j in range(N):
            H[i][j]=min(H[i][j],H[i][k]+H[k][j])
Q=int(input())
for line in range(Q):
    s,t=map(int,input().split())
    s-=1;t-=1
    if H[s][t]==10**15:
        print(-1)
    else:
        print(H[s][t]-1)


Measured memory_bytes: 60632
#include <bits/stdc++.h>
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rrepi(i,a,b) for(int i=((int)(b)-1);i>=(a);--i)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) rrepi(i,0,n)
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define ZERO(x) memset(x,0,sizeof(x))
#define MINUS(x) memset(x,-1,sizeof(x))
#define UNIQUE(x) (x).erase(unique(ALL(x)), (x).end())
#define debug(var)  do{std::cout << #var << " : "; view(var);}while(0)
#define fi first
#define se second
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){for(const auto& v : vv){ view(v); } }
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void viewarr(T arr[], int n) { for(int i = 0; i < n; ++i) std::cout << arr[i] << " "; std::cout << std::endl; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll qp(ll a,ll b){ll ans=1;do{if(b&1)ans=1ll*ans*a;a=1ll*a*a;}while(b>>=1);return ans;}
ll qp(ll a,ll b,ll mo){ll ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const int INF = 1e9;
const ll INFL = 1e18;
const int MOD = 1e9 + 7;
const int MAX_N = 1e5;

int main() {
    ll H, W; cin >> H >> W;
    ll ans = 0;
    if(H == 1 || W == 1) {
        ans = 1;
    } else if(H % 2 == 0) {
        if(W % 2 == 0) {
            ans = (H/2)*W;
        } else {
            ans = (H/2)*W;
        }
    } else {
        if(W % 2 == 0) {
            ans = (W/2)*H;
        } else {
            ans = H * (W/2) + ((H+1)/2);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
#include<iomanip>
#define pi 3.14159265358979323846
#define ill long long int
#define rep(i, a, n) for(int i = a; i < n; i++)
using namespace std;
int main(){
  ill a, b, x;
  cin >> x >> a >> b;
  a -= x;
  b -= x;
  if(b < 0){
    b = b * (-1);
  }
  if(a < 0){
    a = a * (-1);
  }
  
  if(a < b){
    cout << "A\n";
    return 0;
  }
  cout << "B\n";
}

Measured memory_bytes: 3564
#include <bits/stdc++.h>
using namespace std;

int main() {
  
  int n,k,x,y;
  cin >> n >> k >> x >> y;
  
  if( n >= k ){
    cout << k * x + (n - k) * y << endl;
  }else{
    cout << n * x << endl;
  }
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

// 最大公約数
ll gcd(ll m, ll n)
{
    if (n == 0)
        return m;
    else
        return gcd(n, m % n);
}

// 最小公倍数
ll lcm(ll a, ll b)
{
    return a / gcd(a, b) * b;
}
// https://yamakasa.net/atcoder-abc-150-d/
int main()
{
    int N;
    ll M;
    cin >> N >> M;

    ll a[N];
    ll b = 0;
    for (int i = 0; i < N; i++)
    {
        cin >> a[i];
        b = max(b, a[i] / 2);
    }

    ll l = 1;
    for (int i = 0; i < N; i++)
    {
        l = lcm(l, a[i] / 2);
        if (l > M)
        {
            cout << "0\n";
            return 0;
        }
    }

    for (int i = 0; i < N; i++)
    {
        ll t = l / (a[i] / 2);
        if (t % 2 == 0)
        {
            cout << "0\n";
            return 0;
        }
    }

    cout << (M - l) / (2 * l) + 1 << "\n";
    return 0;
}

Measured memory_bytes: 4372
S = input()
N = len(S)
N1 = int( (N+1) / 2 )

S1 = S[0:N1-1]
S2 = S[-N1+1:]
S1_r = S1[::-1]

if S1==S2 and S1 == S1_r:
    print("Yes")
else:
    print ("No")

Measured memory_bytes: 3060
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner scan = null;
		try{
			scan = new Scanner(System.in);
			int n;
			while((n = scan.nextInt())!=0){
				Dice dice= new Dice();
				int sum = 1;
				for(int i = 0 ;i < n;i++){
					sum += dice.Change(scan.next().charAt(0));
				}
				System.out.println(sum);
			}
		}finally{
			if(scan !=null)scan.close();
		}

	}
}
class Dice{
	int[] dice;
	final int seven = 7;
	Dice(){
		dice = new int[3];
		for(int i =0;i < dice.length;i++){
			dice[i] = i+1;
		}
	}
	private void change(int i,int j){
		int tmp = dice[i];
		dice[i] = dice[j];
		dice[j] = seven - tmp;
	}
	private int North(){
		change(0,1);
		return dice[0];
	}
	private int East(){
		change(2,0);
		return dice[0];
	}
	private int West(){
		change(0,2);
		return dice[0];
	}
	private int South(){
		change(1,0);
		return dice[0];
	}
	private int Right(){
		change(1,2);
		return dice[0];
	}
	private int Left(){
		change(2,1);
		return dice[0];
	}
	public int Change(char data){
		switch(data){
		case 'N':
			return North();
		case 'E':
			return East();
		case 'W':
			return West();
		case 'S':
			return South();
		case 'R':
			return Right();
		case 'L':
			return Left();
		}
		return 0;
	}
}

Measured memory_bytes: 23552
#include <bits/stdc++.h>
#define rep(a,n) for (ll a = 0; a < (n); ++a)
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<vector<ll> > Graph;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1e18;

//素因数分解
vector<P> prime_factorize(ll n){
    vector<P> res;
    for (ll a = 2; a * a <= n; ++a){
        ll ex = 0; //指数
        //割り切れる限り割る
        while(n % a == 0){
            ++ex;
            n /= a;
        }
        res.push_back({a,ex});
    }
    if (n != 1) res.push_back({n,1});
    return res;
}

int main(){
    ll n;
    cin >> n;
    vector<ll>a(n),b(n);
    rep(i,n)cin>>a[i]>>b[i];
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    ll l,r;
    if(n%2==1){
        n--;
        l = a[n/2];
        r = b[n/2];
    }
    else{
        n--;
        l = (a[n/2]+a[n/2+1]);
        r = (b[n/2]+b[n/2+1]);
    }
    cout << r-l+1 << endl;
    return 0;
}


Measured memory_bytes: 6376
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

  public static void main(String[] args) throws IOException {
    
    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      int n = Integer.parseInt(br.readLine());
      String[] line;
      MyList list = new MyList();

      for(int i=0; i<n; i++) {
        line = br.readLine().split(" ");
        switch( line[0] ) {
          case "insert" :
            list.insertFirst( Integer.parseInt(line[1]) );
            break;
          case "deleteFirst" :
            list.deleteFirst();
            break;
          case "deleteLast" :
            list.deleteLast();
            break;
            case "delete" :
              list.delete( Integer.parseInt(line[1]) );
              break;
          default :
            System.out.println("n:" + i + " is failed.");
        }
      }

      System.out.println ( list.getAllElements() );
    }
  }
}

class Node {
  Node next,prev;
  int key;

  public Node(int key) {
    this.key = key;
  }
}

class MyList {
  Node nil;
  Node current;
  int size;

  public MyList() {
    nil = new Node(0);
    nil.next = nil.prev = nil;
    size = 0;
  }

  public String getAllElements() {
    StringBuilder buf = new StringBuilder(size*2);

    if(size > 0){
      current = nil.next;
      for(int i=0; i<size; i++){
        buf.append(current.key).append(" ");
        current = current.next;
      }
    }
    buf.setLength(buf.length()-1);

    return buf.toString();
  }
  public void insertFirst(int x) {
    if(size == 0) {
      current = new Node(x);
      nil.next = current;
      nil.prev = current;
      current.prev = nil;
      current.next = nil;
      size++;
    }
    else {
      Node add = new Node(x);
      
      current.prev.next = add;
      add.prev = current.prev;

      add.next = current;
      current.prev = add;

      current = add;
      size++;
    }
  }
  public void deleteFirst() {
    nil.next = current.next;
    current.next.prev = current.prev;

    current = current.next;
    size--;
  }
  public void deleteLast() {
    current = nil.prev;

    nil.prev = current.prev;
    current.prev.next = current.next;

    current = nil.next;
    size--;
  }
  public void delete(int x) {
    Node target = findFirst(x);

    if(target == nil) current = current.next;
    else {
      current.prev.next = target.next;
      current.next.prev = target.prev;
      current = nil.next;
      size--;
    }
  }
  private Node findFirst(int x) {
    while(current != nil) {
      if(current.key == x) break;
      current = current.next;
    }

    return current;
  }
}


Measured memory_bytes: 189400
#include <iostream>
using namespace std;

int main(){
    int h1,h2,m1,m2,s1,s2;
    int del;
    for(int i=0;i<3;i++){
	cin >> h1 >> m1 >> s1 >> h2 >> m2 >> s2;
	s2 -= s1;
	if(s2 < 0){
	    m2--;
	    s2 += 60;
	}
	m2 -= m1;
	if(m2 < 0){
	    h2--;
	    m2 += 60;
	}
	h2 -= h1;
	cout << h2 << " " << m2 << " " << s2 << endl;
    }
    return 0;
}

Measured memory_bytes: 1160
N = int(input())
h = [int(i) for i in input().split()]
end_flag = False
counter = 0
f = [0 for i in range(N)]
while end_flag == False:
    loop_flag = False
    flag = False
    for i in range(N):
        if f[i] < h[i]:
            flag = True
            loop_flag = True
            f[i] += 1
        else:
            if flag == True:
                counter += 1
                flag = False
    if flag == True:
        counter += 1
    if loop_flag == False:
        end_flag = True
print(counter)


Measured memory_bytes: 65912
#include <bits/stdc++.h>
using namespace std;
int main(){
	string str;
	cin>>str;
	bool A = false, B = false;
	for(int i = 0; i < (int) str.size(); i++){
		if(str[i]=='A')
			A = true;
		else
			B = true;
	}
	if(A && B)
		puts("Yes");
	else
		puts("No");
		
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
using pii=std::pair<int,int>;
using namespace std;

const int maxn = 1e5 + 5;

int n, k, a, b, v, p, mi[maxn], ma[maxn], reqparity[2][maxn];
vector<int> adj[maxn];
vector<pii> mivals[maxn], mavals[maxn]; // {mi / ma, from}

void up(int x, int p)
{
    for(auto v : adj[x])
        if(v != p)
        {
            up(v, x);
            mivals[x].push_back({mi[v] - 1, v});
            mavals[x].push_back({ma[v] + 1, v});
            for(int j = 0; j < 2; j++)
                reqparity[j][x] |= reqparity[j ^ 1][v];
        }
    sort(mivals[x].begin(), mivals[x].end(), greater<pii>());
    sort(mavals[x].begin(), mavals[x].end());
    if(!mivals[x].empty())
        mi[x] = max(mi[x], mivals[x][0].first);
    if(!mavals[x].empty())
        ma[x] = min(ma[x], mavals[x][0].first);
}

void down(int x, int p, int parmi, int parma)
{
    if(p != -1)
    {
        mivals[x].push_back({parmi - 1, p});
        mavals[x].push_back({parma + 1, p});
        for(int j = 0; j < 2; j++)
            reqparity[j][x] |= reqparity[j ^ 1][p];
        sort(mivals[x].begin(), mivals[x].end(), greater<pii>());
        sort(mavals[x].begin(), mavals[x].end());
    }
    if(!mivals[x].empty())
        mi[x] = max(mi[x], mivals[x][0].first);
    if(!mavals[x].empty())
        ma[x] = min(ma[x], mavals[x][0].first);
    for(auto v : adj[x])
        if(v != p)
        {
            int takemi = -2e9, takema = 2e9;
            for(auto y : mivals[x])
                if(y.second != v)
                {
                    takemi = y.first;
                    break;
                }
            for(auto y : mavals[x])
                if(y.second != v)
                {
                    takema = y.first;
                    break;
                }
            down(v, x, takemi, takema);
        }
}

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < 2; j++)
            reqparity[j][i] = 0;
        mi[i] = -2e9;
        ma[i] = 2e9;
    }
    for(int i = 0; i < n - 1; i++)
    {
        cin >> a >> b;
        a--; b--;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    cin >> k;
    for(int i = 0; i < k; i++)
    {
        cin >> v >> p;
        v--;
        reqparity[p & 1][v] = 1;
        mivals[v].push_back({p, v});
        mavals[v].push_back({p, v});
    }
    up(0, -1);
    down(0, -1, -2e9, 2e9);
    int bad = 0;
    for(int i = 0; i < n; i++)
        if((reqparity[0][i] && reqparity[1][i]) || mi[i] > ma[i])
            bad = 1;
    if(bad)
        cout << "No\n";
    else
    {
        cout << "Yes\n";
        for(int i = 0; i < n; i++)
            cout << mi[i] << "\n";
    }
    return 0;
}

Measured memory_bytes: 40268
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define int long long
typedef long long ll;
typedef pair<int,int> P;

signed main(){
    int n;
    cin >> n;
    int a[n];
    map<int,int> mp;
    rep(i,n){
        int aa;
        cin >> aa;
        a[i]=aa;
        mp[aa]++;
    }
    ll ans=0;
    for(auto i=mp.begin();i!=mp.end();i++){
        if(mp[i->first]>=2) ans+=(mp[i->first]*(mp[i->first]-1))/2;
    }

    rep(i,n){
        cout << ans-(mp[a[i]]-1) << endl;
    }


}

Measured memory_bytes: 11904
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <numeric>
#include <string>
#include <functional>

using namespace std;

int main(void){
    int N;
    cin>>N;
    vector<char*> s(N);
    for(int i=0;i<N;i++){
        s[i]=new char[10];
        cin>>s[i];
        sort(s[i],s[i]+sizeof(char)*10);
    }
    vector<string> s1(N);
    for(int i=0;i<N;i++){
        string temp(s[i],10);
        s1[i]=temp;
    }
    sort(s1.begin(),s1.end());
    
    long long ans=0;
    long long memo=0;
    for(int i=1;i<N;i++){
        if(s1[i]==s1[i-1]){
            memo++;
            ans+=memo;
        }else{
            memo=0;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 9600
package main

import "fmt"

func main() {
	var n, m int
	fmt.Scan(&n, &m)
	a := make([]string, n)
	for i := range a {
		fmt.Scan(&a[i])
	}
	b := make([]string, m)
	for i := range b {
		fmt.Scan(&b[i])
	}
	var ok bool
	for y := 0; y < n; y++ {
		for x := 0; x < n; x++ {
			// スタート地点が点(i,j)となる
			ok = true
			var dy, dx int
			for dy = 0; dy < m && y+dy < n; dy++ {
				for dx = 0; dx < m && x+dx < n; dx++ { // O(N^4)だが、1<=N,M<=50のため間に合う
					if a[y+dy][x+dx] != b[dy][dx] {
						ok = false
						break
					}
				}
				if !ok {
					break
				}
			}
			if ok && dy == m && dx == m {
				fmt.Println("Yes")
				return
			}
		}
	}
	fmt.Println("No")
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define FASTIO
using namespace std;

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

constexpr double D_INF = 1e+60;

using Pos = valarray<double>;
using Pi = pair<double, ll>;

double distance(const Pos& a, const Pos& b) {
    Pos dr = a - b;
    return sqrt(dr[0] * dr[0] + dr[1] * dr[1]);
}

double dist[1005][1005];

void solve() {
    Pos xs(2), xt(2);
    cin >> xs[0] >> xs[1];
    cin >> xt[0] >> xt[1];
    ll N;
    cin >> N;
    vector<pair<Pos, double>> bs(N);
    for (ll i = 0; i < N; i++) {
        Pos c(2);
        double r;
        cin >> c[0] >> c[1] >> r;
        bs[i] = {c, r};
    }

    for (ll i = 0; i < N + 2; i++) {
        for (ll j = 0; j < N; j++) {
            dist[i][j] = D_INF;
        }
    }
    for (ll i = 0; i < N + 2; i++) {
        dist[i][i] = 0.0;
    }

    // バリア同士
    for (ll i = 0; i < N; i++) {
        for (ll j = i + 1; j < N; j++) {
            double d = distance(bs[i].first, bs[j].first) - bs[i].second - bs[j].second;
            if (d > 0.0) {
                dist[i][j] = dist[j][i] = d;
            }
            else {
                dist[i][j] = dist[j][i] = 0.0;
            }
        }
    }

    // スタートとバリア
    for (ll i = 0; i < N; i++) {
        double d = distance(xs, bs[i].first) - bs[i].second;
        if (d > 0.0) {
            dist[i][N] = dist[N][i] = d;
        }
        else {
            dist[i][N] = dist[N][i] = 0.0;
        }
    }

    // ゴールとバリア
    for (ll i = 0; i < N; i++) {
        double d = distance(xt, bs[i].first) - bs[i].second;
        if (d > 0.0) {
            dist[i][N + 1] = dist[N + 1][i] = d;
        }
        else {
            dist[i][N + 1] = dist[N + 1][i] = 0.0;
        }
    }

    // スタートとゴール
    {
        double d = distance(xs, xt);
        dist[N][N + 1] = dist[N + 1][N] = d;
    }

    vector<double> costs(N + 2, D_INF);
    priority_queue<Pi, vector<Pi>, greater<Pi>> pq;
    costs[N] = 0.0;
    pq.emplace(0.0, N);
    while (!pq.empty()) {
        double co;
        ll idx;
        tie(co, idx) = pq.top();
        pq.pop();
        if (co > costs[idx]) continue;
        for (ll i = 0; i < N + 2; i++) {
            double nco = co + dist[idx][i];
            if (nco >= costs[i]) continue;
            pq.emplace(nco, i);
            costs[i] = nco;
        }
    }

    cout << setprecision(20) << costs[N + 1] << endl;
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif
#ifdef FILEOUTPUT
    ofstream ofs("./in_out/output.txt");
    cout.rdbuf(ofs.rdbuf());
#endif
    solve();
    cout << flush;
    return 0;
}

Measured memory_bytes: 14068
function Main(input) {
	var S = input.split('\n')
	var A = 0;
	switch (S[0]) {
		case "SUN":
			A = 0;
			break;
		case "MON":
			A = 1;
			break;
		case "TUE":
			A = 2;
			break;
		case "WED":
			A = 3;
			break;
		case "THU":
			A = 4;
			break;
		case "FRI":
			A = 5;
			break;
		case "SAT":
			A = 6;
			break;
	}
	console.log(7 - A);
}
 
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
from collections import defaultdict

H, W, K = map(int, input().split())
dp1 = [[0]*2 for _ in range(W)]
dp1[0][0] = 1

for i in range(W-1):
    dp1[i+1][0] = dp1[i][0]+dp1[i][1]
    dp1[i+1][1] = dp1[i][0]

d = defaultdict(int)
d[-1] = 1

for i in range(W):
    d[i] = dp1[i][0]+dp1[i][1]

dp2 = [[0]*W for _ in range(H+1)]
dp2[0][0] = 1
MOD = 10**9+7

for i in range(H):
    for j in range(W):
        for k in range(max(0, j-1), min(W-1, j+1)+1):
            l = min(j, k)-1
            r = W-2-max(j, k)
            dp2[i+1][k] += dp2[i][j]*d[l]*d[r]
            dp2[i+1][k] %= MOD

print(dp2[H][K-1])

Measured memory_bytes: 39664
#include<iostream>
#include<cmath>
using namespace std;

int main(){
    int N,X,sum=0;
    cin>>N>>X;
    int m[100];
    int MIN=1e9;
    for(int i=0;i<N;i++){
        cin>>m[i];
        sum+=m[i];
        MIN=min(MIN,m[i]);
    }
    cout<<N+(X-sum)/MIN<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <cstring>
#include <queue>
#include <stack>
#include <vector>
#include <iostream> 
using namespace std;

string s;

int main() {
	cin >> s;
	int ans = 0;
	int len = s.length();
	int sum_ = 0;
	for (int i = 0; i < len; i++) {
		if (s[i] == 'R') {
			sum_ ++;
			ans = max(sum_, ans);
		}
		else {
			ans = max(sum_, ans);
			sum_ = 0;
		}
	}
	printf("%d", ans);
	return 0;
}

Measured memory_bytes: 3664
import java.util.*;
import java.lang.*;
import java.io.*;


public class Main {
    public static int maxOfArray(int[] a){
    	int ans = a[0];
    	for(int i=1;i<a.length;i++){
    		if(a[i]>ans) ans=a[i];
    	}
    	return ans;
    }
    public static int minOfArray(int[] a){
    	int ans = a[0];
    	for(int i=1;i<a.length;i++){
    		if(a[i]<ans) ans=a[i];
    	}
    	return ans;
    }
    public static int cost(int[] array, int target){
        int ans=0;
        for(int n=0;n<array.length;n++) ans += (array[n]-target)*(array[n]-target);
        return ans;
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] a = new int[N];
        for(int n=0;n<N;n++) a[n]=sc.nextInt();
        
        int min = minOfArray(a);
        int max = maxOfArray(a);
        int ans = Integer.MAX_VALUE;
        for(int target=min;target<=max;target++){
        	ans = Math.min(ans, cost(a,target));
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 23636
#include <cstdio>
#include <algorithm>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <string>
#include <string.h>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <map>
#include <set>
#include <iostream>
#include <sstream>
#include <numeric>
#include <cctype>
#include <bitset>
#include <cassert>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define gep(i,g,j) for(int i = g.head[j]; i != -1; i = g.e[i].next)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcount
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define df(x) int x = in()
#define dame { puts("-1"); return 0;}
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,vector<T>,greater<T> >
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
inline void priv(vi a) { rep(i,sz(a)) printf("%d%c",a[i],i==sz(a)-1?'\n':' ');}
template<typename T>istream& operator>>(istream&i,vector<T>&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(vector<T>&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>ostream& operator<<(ostream&o,vector<T>&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>ostream& operator<<(ostream&o,pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
const int MX = 40005, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;



int main() {
  int n;
  scanf("%d",&n);
  vi p(n);
  rep(i,n) scanf("%d",&p[i]), p[i]--;
  vi a(n);
  vi b(n);
  rep(i,n) a[i] = 1+i*MX;
  rep(i,n) b[n-1-i] = 1+i*MX;
  rep(i,n) a[p[i]] += i;
  cout<<a<<"\n"<<b<<endl;
  return 0;
}































Measured memory_bytes: 1500
a = input().split()
men = int(a[0])
score = int(a[1])
prob = 0
for i in range(1, men + 1):
  get = i
  count = 0
  while get < score:
    count += 1
    get *= 2
  prob += (1 / men) * ((1/2)**count)

print(prob)

Measured memory_bytes: 3060
from operator import itemgetter

def key_func(n):
	return n[0]

N, M = map(int, input().split())

list_price_and_energydrink = []

for i in range(N):
	A_i, B_i = map(int, input().split())
	list_shop_number_i = [A_i, B_i]
	list_price_and_energydrink.append(list_shop_number_i)

count_number_drink = 0
count_price_drink = 0

list_price_and_energydrink.sort(key=itemgetter(0))

while count_number_drink < M:
	list_minimum_i = list_price_and_energydrink[0]
	
	if count_number_drink + list_minimum_i[1] > M:
		count_price_drink += list_minimum_i[0] * (M - count_number_drink)
		count_number_drink = M
	else:
		count_number_drink += list_minimum_i[1]
		count_price_drink += list_minimum_i[0] * list_minimum_i[1]	
	
	list_price_and_energydrink.remove(list_minimum_i)

print(count_price_drink)


Measured memory_bytes: 21276
#include "bits/stdc++.h"
using namespace std;


//wierd debugging stuff
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
//end of weird debugging stuff
using ll = long long;
using vi = vector<int>;
using ii = pair<int,int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
#define FASTER ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define invec(v) for(auto& x : v)cin>>x;
#define Test int T;cin>>T;while(T--)
#define REP(i,j,k) for(int i=(j);(i)<(k);(i)++)
#define Time()	cerr <<'\n' << clock() * 1000 / CLOCKS_PER_SEC << "ms\n"
#define SZ(x) (int)x.size();
#define all(x) x.begin,x.end()
// no ichange 

//const int MxN = 1e9+5;
const int MOD = 2019;
int main() {
	FASTER;
	string s;
	cin>>s;
	int n = s.length();
	int suf = 0;
	int pot = 1;
	vi cur_suf(MOD);
	long long answer = 0;
	cur_suf[suf]++;
	
	for(int i = n-1;i>=0;i--){
		int digit = s[i] - '0';
		suf = (suf + digit*pot) % MOD;
		//debug()<<imie(suf)<<imie(digit);
		pot = (10 * pot)%MOD;
		debug()<<imie(pot)<<imie(suf)<<imie(cur_suf[suf]);
		answer += cur_suf[suf];
		cur_suf[suf]++;
	}
	cout<<answer;
	
	
	
}


Measured memory_bytes: 3748
#include <stdio.h>

int main(void){

  int a,b;
  scanf("%d %d", &a, &b);

	int plus = a+b;
	int minus = a-b;
	int multiple = a*b;
	int max = plus;
	if (minus > max) {
		max = minus;
	}
	if (multiple > max) {
		max = multiple;
	}
	printf("%d\n", max);

  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>

using namespace std;

typedef unsigned uint;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ldbl;
typedef pair<int, int> pii;
typedef pair<uint, uint> puu;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pull;
typedef pair<double, double> pdd;
typedef vector<int> vi;
typedef vector<uint> vu;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pii> vpii;
typedef vector<puu> vpuu;
typedef vector<pll> vpll;
typedef vector<pull> vpull;
typedef vector<string> vstr;
typedef vector<double> vdbl;
typedef vector<ldbl> vldbl;
#define pb push_back
#define ppb pop_back
#define pfr push_front
#define ppfr pop_front
#define emp emplace
#define empb emplace_back
#define be begin
#define rbe rbegin
#define all(x) (x).be(), (x).end()
#define rall(x) (x).rbe(), (x).rend()
#define fir first
#define sec second
#define mkp make_pair
#define brif(cond) if (cond) break
#define ctif(cond) if (cond) continue
#define retif(cond) if (cond) return
void canhazfast() {ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);}
template<typename T> T gcd(T a, T b) {return b ? gcd(b, a%b) : a;}
template<typename T> T extgcd(T a, T b, T &x, T &y)
{
    T x0 = 1, y0 = 0, x1 = 0, y1 = 1;
    while (b) {
        T q = a/b; a %= b; swap(a, b);
        x0 -= q*x1; swap(x0, x1);
        y0 -= q*y1; swap(y0, y1);
    }
    x = x0; y = y0; return a;
}
int ctz(uint x) {return __builtin_ctz(x);}
int ctzll(ull x) {return __builtin_ctzll(x);}
int clz(uint x) {return __builtin_clz(x);}
int clzll(ull x) {return __builtin_clzll(x);}
int popcnt(uint x) {return __builtin_popcount(x);}
int popcntll(ull x) {return __builtin_popcountll(x);}
int bsr(uint x) {return 31^clz(x);}
int bsrll(ull x) {return 63^clzll(x);}

int main()
{
    canhazfast();

    char s[8];
    int v0, v1;
    bool yymm = false, mmyy = false;

    cin >> s;
    v0 = 10*(s[0]-'0')+s[1]-'0';
    v1 = 10*(s[2]-'0')+s[3]-'0';
    if (v0 && v0 <= 12) mmyy = true;
    if (v1 && v1 <= 12) yymm = true;
    if (yymm) {
        if (mmyy) cout << "AMBIGUOUS";
        else cout << "YYMM";
    } else {
        if (mmyy) cout << "MMYY";
        else cout << "NA";
    }
    cout << '\n';

    return 0;
}


Measured memory_bytes: 256
import math
def main():
  x = int(input())
  sum=0
  if x==0 or x==1:
    sum=x
  else:
    for i in range(2,int(math.sqrt(x))+1):
      j=2
      while True:
        if pow(i,j) <= x:
          if pow(i,j) > sum:
            sum=pow(i,j)
        else:
          break
        j+=1
  print(sum)
main()


Measured memory_bytes: 9176
#include <bits/stdc++.h>
using namespace std;

int main() {
  int A, B, ans;
  cin >> A >> B;
  ans = -1;
  
  for(int i=1; i<15000; i++){
    int a=i*8/100;
    int b=i*10/100;
    if(a==A && b==B){
      ans = i;
      break;
    }
  }
  
  cout << ans << endl;
    
}


Measured memory_bytes: 3632
var n,i,x:longint;
    s:int64;
    a:array[0..300003] of longint;
    fi,fo:text;
procedure start;
begin
    assign(fi,''); reset(fi);
    assign(fo,''); rewrite(fo);
    readln(fi,n);
    n:= 3*n;
    for i:= 1 to n do read(fi,a[i]);
end;
procedure sort(l,r:longint);
var i,j,mid,tmp:longint;
begin
    i:= l; j:= r; mid:= a[(l+r)div 2];
    repeat
        while a[i]<mid do inc(i);
        while a[j]>mid do dec(j);
        if i<=j then
        begin
            tmp:= a[i]; a[i]:= a[j]; a[j]:= tmp;
            inc(i); dec(j);
        end;
    until i>j;
    if l<j then sort(l,j);
    if i<r then sort(i,r);
end;
procedure main;
begin
    s:= 0;
    x:= n+1;
    for i:= 1 to n div 3 do s:= s+a[x-2*i];
end;
begin
    start;
    sort(1,n);
    main;
    writeln(fo,s);
    close(fi); close(fo);
end.


Measured memory_bytes: 1280
#include "bits/stdc++.h"
using namespace std;
const int MOD = 1e9 + 7;
typedef long long lint;
const int INF = 1e7;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repi(i, k, n) for (int i = (k); i < (int)(n); ++i)
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(), (x).end()
#define pb push_back
int main()
{
    int a, b, c, d, e, f;
    cin >> a >> b >> c >> d >> e >> f;
    if ((max({a, b, c, d, e}) - min({a, b, c, d, e})) <= f)
    {
        cout << "Yay!" << endl;
    }
    else
    {
        cout << ":(" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define MAX 100

int main(void) {
    int i, j, h, w, v, ary[MAX], tbl[MAX][MAX];
    scanf("%d %d", &h, &w);
    for(i = 0; i < h; i++) {
        for(j = 0; j < w; scanf("%d", &tbl[i][j++]));
    }
    for(i = 0; i < w; scanf("%d", &ary[i++]));
    for(i = 0; i < h; i++) {
        for(j = v = 0; j < w; v += tbl[i][j] * ary[j++]);
        printf("%d\n", v);
    }
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int q; cin>>q;
	deque<int>que;
	for(int i=0;i<q;++i){
		int qu,dp; cin>>qu>>dp;
		if(qu==0){
			int x; cin>>x;
			if(dp==0)que.emplace_front(x);
			else que.emplace_back(x);
		}else if(qu==1)cout<<que.at(dp)<<"\n"s;
		else if(dp==0)que.pop_front();
		else que.pop_back();
	}
}


Measured memory_bytes: 4656
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

     Scanner sc=new Scanner(System.in);
     int n=sc.nextInt();
     boolean flag=false;
     while(n>0)
     {
         if(n%10==7)
              flag=true;
         n/=10;

     }
     if(flag)
          System.out.println("Yes");
     else
         System.out.println("No");

    }
}


Measured memory_bytes: 35748
s = input()
t = input()

sl = len(s)
tl = len(t)

s = set(s)
t = set(t)

flag = False
for x in s:
    for y in t:
        if x < y:
            flag = True
            break
    if flag:
        break

if s == t and sl < tl:
    flag = True

if flag:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>

using namespace std;

int k, s;
int cnt;

int main()
{
    scanf("%d%d", &k, &s);
    for(int i = 0; i <= k; i++)
    {
        cnt += max(min(s-i, k) - max(s - k - i, 0) + 1, 0);
    }
    printf("%d", cnt);
    return 0;
}


Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip> // fixed, setprecision 
#include <math.h> // double sqrt
#define rep(i,n) for(int i=0;i<(n);++i)
#define ll long long
using namespace std;

bool is_integer( double x ){
  return std::
  floor(x)==x;
}

int f(int n){
    int count=0;
    while(n>0){
        n/=10;
        count++;
    }
return count;
}
int main(){
    int  a,b;
    cin>>a>>b;
    int x=a*pow(10,f(b))+b;
    double y=sqrt(x);
   if(is_integer(y))cout<<"Yes";
   else cout<<"No";
   return 0;
}

Measured memory_bytes: 3368
n,t = map(int,input().split())
x = []
y = []
for i in range(n):
    x1,y1=[int(i) for i in input().split()]
    if(y1<=t):
        x.append(x1) #x += [x1]
        y.append(y1) #y += [y1]
print(min(x) if len(x)>0 else "TLE")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  int N;cin >> N;
  vector<PIL> v(N);
  rep(i,N) cin >> v[i].first >> v[i].second;
  int now = 0;
  ll ans = 0;
  map<int,PLL> mp;
  mp[1] = PII(10,1);
  mp[2] = PII(5,1);
  mp[3] = PII(4,3);
  mp[4] = PII(3,3);
  mp[5] = PII(2,1);
  mp[6] = PII(2,3);
  mp[7] = PII(2,5);
  mp[8] = PII(2,7);
  mp[9] = PII(2,9);

  rep(i,N){
    if(v[i].first == 0){
      ans += v[i].second;
      continue;
    }
    int x = v[i].first;
    ll y = v[i].second;
    while(y>0){
      ll y_ = y/mp[x].first;
      int x_ = mp[x].second;
      ans += y%mp[x].first;
      now += (y%mp[x].first) * x;
      if(now/10!=0){
        now = now%10 + now/10;
        ++ans;
      }
      ans += y_*mp[x].first;
      x = x_;
      y = y_;
    }
  }
  cout << ans -1 << endl;
  return 0;
}


Measured memory_bytes: 3456
#include <bits/stdc++.h>
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
#define SUM(n) ((n)+1)*(n)/2　//1〜nまでの総和を求める式
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) fixed<<setprecision(x+1) //小数点桁数を指定する
#define abs(x,y) max(x,y)-min(x,y)
#define all(v) v.begin(),v.end()
#define UPDight(a,b) (a+b-1)/b //小数点切り上げ 
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD=int(1e9)+7; 
using namespace std;
using pii = pair<int,int>;
typedef vector<int> vit;

signed main(void){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);

  int n;
  cin >> n;
  int a[n + 5];
  reps(i, n){
    cin >> a[i];
  }
  int ans = 0;
  reps(i, n){
    if(i < a[i] && a[ a[i] ] == i){
      ans ++;
    }
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;

#define INF 1e9
#define LLINF 1e18
#define pi 3.14159265358979323
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;

int gcd(int a, int b) {
    if(a % b == 0) {
        return b;
    }
    else {
        return(gcd(b, a % b));
    }
}


int main() {
    string t;
    cin >> t;
    for (int i = t.size() - 1; i >= 0; i--) {
        if (t.at(i) == '?') {
            t.at(i) = 'D';
        }
    }
    cout << t << endl;
}

Measured memory_bytes: 3700
package main

import (
	"fmt"
	"math"
	"strconv"
)

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return (-a)
}

func main() {
	var S string
	fmt.Scan(&S)
	mind := math.MaxInt32
	for i := 0; i < len(S); i++ {
		for j := i + 1; j < len(S)+1; j++ {
			k, _ := strconv.Atoi(S[i:j])
			if k < 100 || k > 1000 {
				continue
			}
			d := abs(753 - k)
			if mind > d {
				mind = d
			}
		}
	}
	fmt.Println(mind)
}


Measured memory_bytes: 512
n, m = map(int, input().split())
mat = [[0 for x in range(m+1)] for y in range(n+1)]

for i in range(n):
    r = list(map(int,input().split()))
    for j in range(m):
        mat[i][j] = r[j]

for i in range(n):
    for j in range(m):
        mat[i][-1] += mat[i][j]
        mat[-1][j] += mat[i][j]
    mat[-1][-1] += mat[i][-1]

for i in range(n+1):
    print(*mat[i])




Measured memory_bytes: 6216
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  int n, m;
  cin >> n >> m;
  
  cout << m*(m-1)/2 + n*(n-1)/2 << endl;
    
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef DEBBY
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
      *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define ll long long
#define rep(i,a,b) for(int i=int(a); i<=int(b); i++)
#define sz(v)  (int)(v).size()
#define all(v) (v).begin(), (v).end()
#define pi pair<int,int>
#define vi vector<int>
#define vpi vector<pi>
#define fs first
#define sd second
#define pb push_back

void solve(){
      int n; ll k;
      cin >> n >> k;
      vi a(n+1);
      rep(i, 1, n)
            cin >> a[i];
      bool visited[n+1]; memset(visited, false, sizeof(visited));
      deque<int> vis; 
      int now = 1;
      bool repeat = false;
      //ll old_k = k;
      while(k>0){
            if(a[now]==now)
                  break;
            if(visited[now] && !repeat){
                  int count = 1;
                  while(vis.back()!=now){
                        vis.pop_back();
                        count++;
                  }
                  repeat = true;
                  k = k%count;
                  debug() << imie(count) imie(k) imie(now);
            } else{
                  visited[now] = true;
                  vis.push_back(now);
                  debug() << imie(vis);
                  now = a[now];
                  k--;
            }
            // 1 3 4 1
      }
      cout << now;
} 

int main(){
      ios_base::sync_with_stdio(false);
      cin.tie(NULL);
      solve();
      return 0;
}
      





Measured memory_bytes: 5048
N = int(input())
A = []
B = []
C = []
now = 0

for i in range(N):
    a, b = list(map(int, input().split()))
    A.append(a)
    B.append(b)
    C.append([a, b])

C.sort(key=lambda x:x[0])
C.sort(key=lambda x:x[1])

Flag = False

for i in range(N):
    now += C[i][0]
    if now > C[i][1]:
        Flag = True
        break

if Flag == True:
    print('No')
else:
    print('Yes')

Measured memory_bytes: 42084
#include <bits/stdc++.h>

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, a, b) for (ll i = (a); i < (b); i++)
typedef uint64_t ull;
typedef int64_t ll;
typedef std::pair<ll, ll> PLL;

using namespace std;

signed main() {
  vector<set<char>> v = {{'R', 'U', 'D'}, {'L', 'U', 'D'}};
  string s;
  cin >> s;
  rep(i,s.size()) {
    if (v[i%2].find(s[i]) == v[i%2].end()) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 256