akhauriyash/Code-Regression huggingface dataset:
n = int(input())
x = []

for i in range(n):
    a, b = map(int, input().split())
    x.append([a, b])
    
ans = 0
for i in range(len(x) - 1):
    for j in range(i+1, len(x)):
        ans += ((x[i][0]-x[j][0])**2 + (x[i][1]-x[j][1])**2)**0.5
        
print((2*ans)/n)

Measured memory_bytes: 9376
#include <cstdio>
#include <string>

using namespace std;

bool contains(const char *s, char c) {
  return s[0] == c || s[1] == c || s[2] == c;
}

int main() {
  char s[3];
  scanf("%s", s);

  if (contains(s, 'a') && contains(s, 'b') && contains(s, 'c')) {
    printf("Yes\n");
    return 0;
  }

  printf("No\n");
  return 0;
}


Measured memory_bytes: 128
import java.util.*;
public class Main {
  
 public static void main(String[] args)
 {
  Scanner scan = new Scanner(System.in);
  int x = scan.nextInt();
  int y = scan.nextInt();
  if(x==y){System.out.println(x+y);}
  else if(x>y){System.out.println(x*2-1);}
  else{System.out.println(y*2-1);}
 }

}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=200010;
ll mod=1e9+7;

struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint& operator+=(const mint a) { if ((x += a.x) >= mod) x -= mod; return *this; }
    mint& operator-=(const mint a) { if ((x += mod-a.x) >= mod) x -= mod; return *this; }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
    mint operator+(const mint a) const { mint res(*this); return res+=a; }
    mint operator-(const mint a) const { mint res(*this); return res-=a; }
    mint operator*(const mint a) const { mint res(*this); return res*=a; }
    mint pow(ll t) const { if (!t) return 1; mint a = pow(t>>1); a *= a; if (t&1) a *= *this; return a; }
    // for prime mod
    mint inv() const { return pow(mod-2); }
    mint& operator/=(const mint a) { return (*this) *= a.inv(); }
    mint operator/(const mint a) const { mint res(*this); return res/=a; }
};


vector<int> v[mx];
vector<ll> dp1(mx,0), dp2(mx,0);
vector<mint> dpa(mx,1), dpb(mx,1);   //ruisekiseki
int n;

void dfs1(int x, int p){
  mint ret=1;
  for(auto to:v[x]){
    if(to==p) continue;
    dfs1(to,x);
    ret *= (dp1[to]+1);
  }
  dp1[x] = ret.x;
}

void dfs2(int x, int p){
  mint ret = 1;
  int sz = v[x].size();
  for(int i=0; i<sz; i++){
    int to = v[x][i];
    dpa[to] = ret;
    if(to==p){
      mint tmp = dpa[x]*dpb[x]+1; 
      ret *= tmp;
    } else {
      ret *= (dp1[to]+1);
    }
  }
  ret = 1;
  for(int i=sz-1; i>=0; i--){
    int to = v[x][i];
    dpb[to] = ret;
    if(to==p){
      mint tmp = dpa[x]*dpb[x]+1; 
      ret *= tmp;
    } else {
      ret *= (dp1[to]+1);
    }
  }
  
  dp2[x] = ret.x;
  for(auto to:v[x]){
    if(to==p) continue;
    dfs2(to,x);
  }
}

int main(){
  cin >> n >> mod;
  rep(i,n-1){
    int a,b; cin >> a >> b; a--; b--;
    v[a].push_back(b);
    v[b].push_back(a);
  }
  dfs1(0,-1);
  dfs2(0,-1);
  rep(i,n) cout << dp2[i] << endl;
  return 0;
}


Measured memory_bytes: 20864
#include <iostream>
using namespace std;
int main() {
	int h,w,a,b;
	for (;;) {
		cin >> h >> w;
		if (h == 0 && w == 0) {
			return 0;
		}
		a = h;
		b = w;
		for (h = a; h > 0; h = h - 1) {
			for (w = b; w > 0; w = w - 1) {
				cout << "#";
			}
			cout<<endl;
		}
		cout << endl;
	}
}


Measured memory_bytes: 3020
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <functional>
using namespace std;

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define rep(n, i) Rep(0, n-1, i)
#define MAX 200000
#define MOD 1000000007

typedef long long ll;

//階乗とその逆元
ll fac[MAX+1],facInv[MAX+1];

ll power(ll e, ll x){ //e^x % MOD
    if (x == 0) return 1LL;
    if (x % 2 != 0) return ((power(e, x-1) * e) % MOD);
    ll temp = power(e, x / 2);
    return (temp * temp) % MOD;
}

ll nck(ll n, ll k){
    if (k > n or k < 0) return 0;
    ll temp = (fac[n] * facInv[n-k]) % MOD;
    return ((temp * facInv[k]) % MOD);
}

void fact(void){
    //階乗とその逆元
    fac[0] = facInv[0] = 1; //0! = 1
    //(x!)^(-1) ≡ (x!)^(p-2) (mod p)
    Rep(1, MAX, i) fac[i] = (fac[i-1] * i) % MOD;
    facInv[MAX] = power(fac[MAX], MOD-2);
    Rep(1, MAX-1, i) facInv[MAX-i] = (facInv[MAX-i+1] * (MAX-i+1)) % MOD;
}

void solve(void){
    int n; scanf("%d\n", &n);

    fact();

    int xs[n+1];
    rep(n+1, i) scanf("%d", &xs[i]);
    bool flag[n]; fill(flag, flag + n, false);
    int daburi; int daburi_indices[2];
    rep(n+1, i) {
        if(!flag[xs[i]-1]) flag[xs[i]-1] = true;
        else daburi = xs[i]-1;
    }
    int k = 0;
    rep(n+1, i) if (xs[i]-1 == daburi) daburi_indices[k++] = i;
    /*
    int insiders = daburi_indices[1] - daburi_indices[0] + 1;
    Rep(1, n+1, i) {
        printf("%lld\n", (nck(n+1, i) - nck(n+1-insiders, i-1) + MOD) % MOD);
    }
    */
    
    int outsiders = n + daburi_indices[0] - daburi_indices[1];
    Rep(0, outsiders, i){
        printf("%lld\n", (nck(n+1, i+1)-nck(outsiders, i) + MOD) % MOD);
    }
    Rep(outsiders+2, n+1, j){
        printf("%lld\n", nck(n+1, j));
    }

}

int main(void){
  solve();
  return 0;
}


Measured memory_bytes: 4864
#include <bits/stdc++.h>
using namespace std;
long long a,b,c,d; 
typedef long long ll;
int h;

long long Euclid(ll x,ll y){return y?Euclid(y,x%=y):x;}

int main() {
  cin>>a>>b;
  c=Euclid(a,b);
  d=sqrt(c);
  for(int i=2;i<=d;i++){
    if(c%i==0){
      while(c%i==0)
        c=c/i;
      h++;
    }
  }
  if(c!=1)
    h++;
  cout<<h+1;
}


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

int main(){
    long long a,b,c;
    cin >> a >> b;
    c = max(a,b);
    if (c == a){
        a = b;
    }
    long long saidai,aa,cc,hozon;
    aa = a;
    cc = c;
    while(1){
        if (cc%aa == 0){
            saidai = aa;
            break;
        }
        hozon = aa;
        aa = cc%aa;
        cc = hozon;
    }
    if (saidai == 1){
        cout << a*c << "\n";
        return 0;
    }
    long long ll = 0;
    ll = (a/saidai)*(c/saidai)*saidai;
    cout << ll << "\n";
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

//A>B のときGREATER、A<B のときLESS、A=B のときEQUALと出力せよ。
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String strA = sc.next();
		String strB = sc.next();
		
		int lenA = strA.length();
		int lenB = strB.length();		
		
		if(lenA > lenB) {
			System.out.println("GREATER");
		} else if(lenA < lenB) {
			System.out.println("LESS");
		} else {
			int i;
			for(i = 0; i < lenA; i++) {
				if(strA.charAt(i) > strB.charAt(i)) {
					System.out.println("GREATER");
					break;
				} else if(strA.charAt(i) < strB.charAt(i)) {
					System.out.println("LESS");
					break;
				}
			}
			if(i == lenA) {
				System.out.println("EQUAL");
			}
		}		

	}

}


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

int main(){
  
  int n;
  cin >> n;
  
  int*a = new int[n];
  int*b = new int[n];
  int*c = new int[n];
  
  for( int i=0; i<n ; i++){
  	cin >> a[i] >> b[i] >> c[i];
  }
  
  int**  dp = new int*[n+1];
  
  for(int i=0 ; i<n+1 ; i++){
  	dp[i] = new int[3]();
  }
  
  for(int i=0 ; i<n ; i++){
  	dp[i+1][0] = a[i] + max( dp[i][1], dp[i][2] ); // ith day if he chooses to pllay the 0th game 
	dp[i+1][1] = b[i] + max( dp[i][0], dp[i][2] );
	dp[i+1][2] = c[i] + max( dp[i][0], dp[i][1] );
  }
  
  cout << max(dp[n][0], max(dp[n][1], dp[n][2])) << endl;
  
  
  return 0;
}

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

using namespace  std;

int main(void)
{
    int N;
    cin >> N;
    vector<char> c(N);
    for(int i = 0; i < N; i++){
        cin >> c[i];
    }
    
    int l = 0;
    int r = N - 1;
    int count = 0;
    while(true){
        while(l < N){
            if(c[l] == 'W'){
                break;
            }
            l++;
        }
        while(r >= 0){
            if(c[r] == 'R'){
                break;
            }
            r--;
        }
        if(r <= l) break;
        count++;
        l++;
        r--;
        
    }
    cout << count << endl;

    return 0;
}

Measured memory_bytes: 3616
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cmath>
 
using namespace std;

struct node{
	int time;
	int i;
	int j;
};

char matrix[1000][1000];
int dx[4] = {-1,0,1,0};
int dy[4] = {0,-1,0,1};

void init(){
	for(int i = 0; i < 1000; i++){
		for(int j = 0; j < 1000; j++){
			matrix[i][j] = '.';
		}
	}
}

int main()
{
	queue<struct node> nodeList;
	int H,W;
	cin>>H>>W;
	for(int i = 0; i < H; i++){
		for(int j = 0; j < W; j++){
			cin>>matrix[i][j];
			if( matrix[i][j] == '#'){
				struct node n1;
				n1.time = 0;
				n1.i = i;
				n1.j = j;
				nodeList.push(n1);
			}
		}
	}

	int time = 0;
	while(!nodeList.empty()){
		struct node n1;
		n1 = nodeList.front();
		time = n1.time;
		for(int i = 0; i < 4; i++){
			int ni,nj;
			ni = n1.i + dx[i];
			nj = n1.j + dy[i];
			if(0 <= ni && ni < H &&  0 <= nj && nj < W && matrix[ni][nj] == '.'){
				matrix[ni][nj] = '#';
				struct node nextNode;
				nextNode.i = ni;
				nextNode.j = nj;
				nextNode.time = time + 1;
				nodeList.push(nextNode);
			}
		}
		nodeList.pop();
	} 
	cout<<time<<endl;
	return 0;
}

Measured memory_bytes: 13328
#include <iostream>
#include<algorithm>
#include <vector>
#include <iomanip>
#include<string.h>
#include<stdio.h>

int main()
{
    long N;
    std::cin >> N;
    long H[100000]={};
    for(long i=0; i<N; i++){
        std::cin >>H[i];
    }
    long temp=0;
    long temphigh=0;
    for(long i=0; i<N-1; i++){
        if(H[i]>=H[i+1]){
            temp++;
        }else{
            if(temphigh<temp){
                temphigh=temp;
            }
            temp=0;
        }
    }
    if(temphigh<temp){
        temphigh=temp;
    }
    std::cout << temphigh << std::endl;
    return 0;
}

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

int main() {
  int H,W,i,j;
  cin >> H >> W;
  char a;
  string S[H];
  for(i = 0;i < H;i++){
    S[i] = "#";
    for(j = 0;j < W;j++){
      cin >> a;
      S[i] += a;
    }
    S[i] += "#";
  }
  for(i = 0;i < W + 2;i++){cout << "#";}
  cout << endl;

  for(i = 0; i < H;i++){
    cout << S[i] << endl;
  }
  
  for(i = 0;i < W + 2;i++){cout << "#";}
}

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

int main(){
  double w,h,x,y;
  cin >> w >> h >> x >> y;
  if (2*x == w && 2*y == h) cout << w*(h/2.0) << " " << 1 << endl;
  else cout << w*(h/2.0) << " " << 0 << endl;
}

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

int main()
{
    int x, y;
    int j;
    cin >> x >> y;
    for (int i = 0; i <= x; i++)
    {
        j = x - i; //kame
        if ((i * 2 + j * 4) == y)
        {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3604
#include<stdio.h>
int main(){
  int n,s=0,i,j,a;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a);
    for(j=0;a%2==0;j++)a/=2;
    s+=j;
  }
  printf("%d\n",s);
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
vector<pair<int, int>> A;

int main(){
    int N,M;
    cin >> N >> M;
    int q,w;
    rep(i,N){
        cin >> q >> w;
        A.push_back(make_pair(q,w));
    }
    sort(A.begin(),A.end(),
    [](const pair<int,int>& x, const pair<int,int>& y) {
        return (x.first < y.first);
        //if(x.second > y.second){
        //    return true;
        //}else if(x.second == y.second){
        //    return (x.first < y.first);
        //}else{
        //    return false;
        //}
    });

    int cu = 1;
    int cnt=0;
    //rep(j,N){
      //  cout << A[j].first <<"::"<<A[j].second << endl;
    //}
    int flag[100010]={};
    priority_queue<int> que;
    int i=0;
    while(M >= cu){
        while(i<N && A[i].first <= cu){
            //cnt += A[i].second;
            //A.erase(A.begin()+i);
            //flag[i] = 1;
            //cout << A[1].first << "." << A[i].second <<endl;
            que.push(A[i].second);
            //N--;
            //rep(j,N){
            //    cout << A[j].first <<","<<A[j].second << endl;
            //}
            //cout << endl;
            //break;
            i++;
            
        }
        //cout << cu << endl;
        if(!que.empty()){
            cnt += que.top();
            que.pop();
        }
        //cout << cu << endl;
        cu++;
    }

    cout << cnt << endl;
}

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

const int MaxN=1e5+5;

int N;

vector<int> To[MaxN];

int Check(int u,int fa){
	int i,v,cnt=0;
	for(i=0;i<To[u].size();i++)
		if((v=To[u][i])^fa)
			cnt+=Check(v,u);
	return cnt^(cnt<2);
}

int main(){
	int i,u,v;
	scanf("%d",&N);
	for(i=1;i<N;i++){
		scanf("%d%d",&u,&v);
		To[u].push_back(v);
		To[v].push_back(u);
	}
	puts(Check(1,0)?"First":"Second");
	return 0;
}

Measured memory_bytes: 5888
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
typedef pair<int, pair<int, int>> PP;
typedef pair<P, int> PPi;
constexpr double PI = 3.1415926535897932;   // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define chadd(x, y) x = (x + y) % mod

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n, z, w;
    cin >> n >> z >> w;
    vector<int> a(n);
    for(int i = 0; i < n; ++i)  cin >> a[i];
    if(n == 1){
        cout << abs(a[0] - w) << endl;
        return 0;
    }
    cout << max(abs(a[n - 2] - a[n - 1]), abs(a[n - 1] - w)) << endl;
}

Measured memory_bytes: 256
[N,M] = list(map(int,input().split()))

KA = []
for i in range(N):
    KA.append(list(map(int,input().split())))

flag = [0]*M
for i in range(N):
    for j in range(1,KA[i][0]+1):
        flag[KA[i][j]-1] += 1
#print(flag)
count=0
for i in range(M):
    if flag[i]==N:
        count+=1
print(count)

Measured memory_bytes: 38256
#include <cstdio>
#include <algorithm>
#include <vector>
static const int MAXN = 100003;
static const int MAXH = 209;
 
static const int MAXV = MAXH * 2;
static const int MAXE = 1e6 + 10;
 
int n, h;
int head[MAXV], dest[MAXE], next[MAXE];
bool vis[MAXE] = { false };
 
int m = 0;
int in[MAXV] = { 0 }, out[MAXV] = { 0 };
 
inline void add_edge(int u, int v)
{
    dest[m] = v; next[m] = head[u]; head[u] = m++;
    ++out[u], ++in[v];
}
 
int cur[MAXV];
 
void dfs(int u)
{
    for (int &w = cur[u]; w != -1; w = next[w]) if (!vis[w]) {
        vis[w] = true;
        dfs(dest[w]);
        if (cur[u] == -1) break;
    }
}
 
std::vector<int> as, bs;
bool marked[MAXV] = { false };
 
int main()
{
    scanf("%d%d", &n, &h);
 
    int verts = (h + 1) * 2;
    for (int i = 0; i < verts; ++i) head[i] = -1;
 
#define node_a(_h) ((_h) * 2)
#define node_b(_h) ((_h) * 2 + 1)
    for (int i = 0, a, b, c, d; i < n; ++i) {
        scanf("%d%d%d%d", &a, &b, &c, &d);
        int u, v;
        u = (c == 0 ? node_b(a) : node_a(c));
        v = (d == 0 ? node_a(b) : node_b(d));
        add_edge(u, v);
    }
    for (int i = 0; i <= h; ++i) {
        if (in[node_a(i)] < out[node_a(i)]) { puts("NO"); return 0; }
        if (in[node_b(i)] > out[node_b(i)]) { puts("NO"); return 0; }
        for (int r = 0; r < in[node_a(i)] - out[node_a(i)]; ++r) {
            as.push_back(node_a(i));
            marked[node_a(i)] = true;
        }
        for (int r = 0; r < out[node_b(i)] - in[node_b(i)]; ++r) {
            bs.push_back(node_b(i));
            marked[node_b(i)] = true;
        }
    }
    for (int u : as) {
        if (bs.empty()) { puts("NO"); return 0; }
        add_edge(u, bs.back());
        bs.pop_back();
    }
 
    for (int i = 0; i < verts; ++i) cur[i] = head[i];
    for (int i = 0; i < verts; ++i) if (marked[i]) dfs(i);
    for (int i = 0; i < m; ++i) if (!vis[i]) { puts("NO"); return 0; }
    puts("YES"); return 0;
}


Measured memory_bytes: 5880
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define mp make_pair
#define F first
#define S second
#define pf pop_front
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
typedef long long ll;
const ll mod=1e9+7;
const ll maxn=100005;
const ll inf=1e9+7;
ll n;
typedef pair<ll,ll> pll;
vector<pll> g[maxn];
ll color[maxn];
void dfs(ll now,ll p,ll pcolor)
{
    int c=1;
    for(auto i:g[now])
    {
        ll v=i.F,index=i.S;
        if(v==p) continue;
        if(c==pcolor) c++;
        color[index]=c;
        dfs(v,now,c);
        c++;
    }
}
int main()
{
    while(cin>>n)
    {
        ll mx=0;
        rep(i,n-1)
        {
            ll a, b;
            cin>>a>>b;
            g[a].pb({b,i});
            g[b].pb({a,i});
            mx=max(mx,ll(g[a].size()));
            mx=max(mx,ll(g[b].size()));
        }
        memset(color,0,sizeof(color));
        dfs(1,-1,-1);
        cout<<mx<<"\n";
        rep(i,n-1) cout<<color[i]<<"\n";
    }
}


Measured memory_bytes: 10112
#include <algorithm>
#include <iostream>
#include <iterator>
#include <vector>
using namespace std;

int main() {
	int nm;
	cin >> nm;
	vector<int> a(nm), c;
	for (int& i : a) cin >> i;
	cin >> nm;
	vector<int> b(nm);
	for (int& i : b) cin >> i;
	set_union(a.begin(), a.end(), b.begin(), b.end(), inserter(c, c.end()));
	for (int& i : c) cout << i << endl;
}


Measured memory_bytes: 6492
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <cstdlib>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
#include <memory.h>

// pi = atan(1)*4;

#define MAX 2100000000
#define PI 3.14159265358979323846
const int Mod = 100000007;

using namespace std;

long long int l[87];

void locas(void)
{
	l[0] = 2;
	l[1] = 1;
	for (int i = 2; i <= 86; i++)
	{
		l[i] = l[i - 1] + l[i - 2];
	}
}
int main(void)
{
	int n;
	locas();

	cin >> n;

	cout << l[n] << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
 
int main(){
	int A,B,C;
       cin >> A >> B >> C;
	if(A>=B && A>=C){
	 cout <<10*A + B + C <<endl;
	}
	else if(B>=C){
	 cout << A + 10*B + C << endl;
	}else {
	 cout << A + B + 10*C << endl;
       }
	return 0;
}

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

ll dp[100005][13];
const ll mod=1e9+7;

int main(){
  string s;
  cin>>s;
  reverse(s.begin(),s.end());
  dp[0][0]=1;
  ll m=1;
  rep(i,s.size()){
    if(s[i]=='?'){
      rep(j,13){
	rep(k,10){
	  dp[i+1][(j+(k*m))%13]=(dp[i+1][(j+(k*m))%13]+dp[i][j])%mod;
	}
      }
    }
    else{
      rep(j,13){
	dp[i+1][(j+((s[i]-'0')*m))%13]=(dp[i+1][(j+((s[i]-'0')*m))%13]+dp[i][j])%mod;
      }
    }
    m=(m*10)%13;
  }
  cout<<dp[s.size()][5]<<endl;
  return 0;
}




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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

const int MAX_N = (int)(1e2 + 5);

int n, x;
int l[MAX_N];

int ans;

int main(void) {
  // Here your code !
  scanf("%d %d", &n, &x);

  for (int i = 0; i < n; ++i) {
    scanf("%d", &(l[i]));
  }

  int last = 0;

  int cnt = (last <= x) ? 1 : 0;

  for (int i = 1; i <= n; ++i) {
    last += l[i - 1];
    cnt += (last <= x) ? 1 : 0;
  }

  ans = cnt;

  printf("%d\n", ans);

  return 0;
}


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

int main() {
  int a, b;
  cin >> a >> b;
  int ans = 0;
  for (int i=1; i<a; i++) {
    for (int j=1; j<=31; j++) {
      if (i == j) ans++;
    }
  }
  for (int j=0; j<=b; j++) {
    if (j == a) ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#define MAXN 100
int jadge(char T[],char H[]){
    size_t Tlen = strlen(T);
    size_t Hlen = strlen(H);
    int i;
    int M;
    if(Tlen < Hlen){
        M = 0;
        for(i = 0;i < Tlen;i++){
            if(T[i] < H[i]){
                return 0;
            }

            else if(T[i] > H[i]){
                return 1;
            }
        }
    }
    else if(Tlen > Hlen){
        M = 1;
        for(i = 0;i < Hlen;i++){
            if(T[i] < H[i]){
                return 0;
            }

            else if(T[i] > H[i]){
                return 1;
            }
        }
    }
    else if(Tlen == Hlen){
        M = 2;
        for(i = 0;i < Hlen;i++){
            if(T[i] < H[i]){
                return 0;
            }

            else if(T[i] > H[i]){
                return 1;
            }
        }
    }
    switch(M){
    case 0:
        return 0;
        break;
    case 1:
        return 1;
        break;
    case 2:
        return 2;
        break;
    }
    return -1;
}
int main(){
    int n,i;
    char Hanako[MAXN] = {0};
    char Taro[MAXN] = {0};
    int HanakoP = 0;
    int TaroP = 0;
    scanf("%d",&n);
    for(i = 0;i < n;i++){
        scanf("%s",Taro);
        scanf("%s",Hanako);
        int B = jadge(Taro,Hanako);
        if(B == 0){
            HanakoP+=3;
        }
        else if(B == 1){
            TaroP+=3;
        }
        else{
            TaroP++;
            HanakoP++;
        }
    }
    printf("%d %d\n",TaroP,HanakoP);
    return 0;
}

Measured memory_bytes: 604
import string
import sys
from collections import Counter

# sys.stdin = open('b1.in')


def read_int_list():
    return list(map(int, input().split()))


def read_str_list():
    return input().split()


def read_int():
    return int(input())


def read_str():
    return input()


def main():
    a = list(string.ascii_lowercase)
    res = None
    s = read_str_list()
    l = list(s)
    l.sort()
    s = ''.join(l)

    c = Counter(s)
    for i in a:
        if c[i] == 0:
            res = i
            break

    print(res)


main()


Measured memory_bytes: 3892
/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner s=new Scanner(System.in);
		long n=s.nextLong();
		long m=s.nextLong();
		long a=n;
		long b=m;
		for(int i=1;i<m;i++)
		{a=a*10+n;}
		for(int i=1;i<n;i++)
		{b=b*10+m;}
		if(n>m)
		System.out.println(b);
	    else
	    System.out.println(a);
	}}

Measured memory_bytes: 24404
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <set>
#include <queue>
#include <deque>
#include <map>
#include <stack>
using namespace std;

#define mod 1000000007
#define ten5 100005
#define ten52 200005
#define ten6 1000005
#define PI 3.1415926
#define pb(x) push_back(x)
#define all(x) x.begin(),x.end()
#define mkpr(x1,x2) make_pair(x1,x2)
typedef long long int ll;


//stack<char> stk;
//set<ll> sll;
//map<string,ll> mp,mp1;
//map<pair<ll,ll>,ll>::iterator iter;
//map<ll,ll> mp;
//deque<char> deq;
//vector<ll> vll;
ll num[ten52];
ll l[ten52],r[ten52];

int main(void)
{
    //double ans=0.0,d,d1,d2;
    //float f,g,h;
    long long int m,n,i,j,k=1;
    long long int a,a1,a2,a3,sum;
    string s,s1,s2;
    //char c,c1;
    sum=a=a1=a2=a3=0;
    cin>>n;
    for(i=-1000;i<=1000;i++)
    {
        for(j=-1000;j<=1000;j++)
        {
            if(i*i*i*i*i-j*j*j*j*j==n)
            {
                cout<<i<<' '<<j;
                return 0;
            }
        }
    }
    return 0;
}





Measured memory_bytes: 3572
N, Y = map(int, input().split())

answer = []

if Y > 10000*N or Y < 1000*N:
    answer = [-1, -1, -1]
else:
    for i in range(N+1):
        x = i
        for j in range(N-x+1):
            y = j
            z = N-x-y
            if 10000*x + 5000*y + 1000*z == Y and z >= 0:
                answer = [x, y, z]
                answer = [str(v) for v in answer]
                print(' '.join(answer))
                exit()
        answer = [-1, -1, -1]

answer = [str(v) for v in answer]
print(' '.join(answer))

Measured memory_bytes: 41196
#include <bits/stdc++.h>
using namespace std;
inline void read (int &x) {
	char ch = getchar(); x = 0;
	while (!isdigit(ch)) ch = getchar();
	while (isdigit(ch)) x = x * 10 + ch - 48, ch = getchar();
} const int N = 105;
int h, w, f[N][N], k[N][N]; char ch[N];
#define judge(i, j, x, y) (k[i][j] == 1 && k[x][y] == 0)
signed main() {
	read (h), read (w);
	for (int i = 1; i <= h; ++i) {
		scanf ("%s", ch + 1);
		for (int j = 1; j <= w; ++j) k[i][j] = (ch[j] == '#');
	} for (int i = 1; i <= h; ++i)
		for (int j = 1; j <= w; ++j) {
			f[i][j] = 1e9;
			if (i == 1 && j == 1) f[i][j] = k[i][j];
			if (i - 1) f[i][j] = f[i - 1][j] + judge (i, j, i - 1, j);
			if (j - 1) f[i][j] = min (f[i][j], f[i][j - 1] + judge (i, j, i, j - 1));
		}
	return printf ("%d\n", f[h][w]), 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define sol (k+k)
#define sag (k+k+1)
#define orta (bas + (son-bas)/2)
#define coc g[node][i]
#define mod 1000000007
#define inf 1e18
#define N 1000005

using namespace std;
 
typedef long long ll;

string s;

int main()
{
	cin >> s;

	if (s == "Sunny")
	{
		cout << "Cloudy";
	}
	else if (s == "Rainy")
	{
		cout << "Sunny";
	}
	else
		cout << "Rainy";

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int d;
    cin>>d;
    if(d==25){
        cout<<"Christmas";
    }
    else if(d<25){
        if(d==24){
            cout<<"Christmas Eve";
        }
        else if(d==23){
            cout<<"Christmas Eve Eve";
        }
        else if(d==22){
            cout<<"Christmas Eve Eve Eve";
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define In_The_Name_Of_Allah_The_Merciful ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define Alhamdulillah return 0;
#define loop(i,k,n) for (ll i = k ; i < n ; ++i)
#define all(v) v.begin(),v.end()
#define debug(n) cerr << "[" << #n << " = " << n << "]" << endl

void Suhaib_Sawalha (){

    char c;
    while (cin >> c){
        if (c == '?') cout << 'D';
        else cout << c;
    }

}

int main(){
                                In_The_Name_Of_Allah_The_Merciful   /* بسم الله الرحمن الرحيم  */
#ifndef ONLINE_JUDGE
    freopen("SuhaibSawalha1.txt","r",stdin);
#endif
//int _;for(cin>>_;_;--_,cout<<endl)
        Suhaib_Sawalha();
                                         Alhamdulillah                    /* الحمد لله */
}


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

int main() {
  int N;
  cin >> N;
  
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  sort(vec.begin(), vec.end());
  
  int x = 0, y = 0;
  for (int i = 0; i < N - 1; i++) {
    if (vec.at(i) == vec.at(i+1))
      x += 1;
  }
  cout << N - x <<endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define int long long

int mod = 1000000007;
signed main() {
	int a,b,c,d,e,k;
	cin >> a >> b >> c >> d >> e >> k;
	//vector<int> v(n);
	//for (size_t i = 0; i < n; ++i)
	//{
	//	cin >> v[i];
	//}

	if (e - a <= k) {
		cout << "Yay!" << endl;
	}
	else {
		cout << ":(" << endl;
	}

	

	

}




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

int main() {
  vector<int> x(101,0);
  vector<int> color(3);
  for(int i=0;i<3;i++) cin>>color.at(i);
  for(int i=0;i<3;i++) x.at(color.at(i))=1;
  cout<<accumulate(x.begin(),x.end(),0)<<endl;
  
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;

int main() {
    int a, b;
    cin >> a >> b;
    cout << (a - 1) * (b - 1) << endl;
}


Measured memory_bytes: 3592
//"push hoge"と言われたらhogeを最後に入れ、"pop"と言われたら最後尾を取りだす。"quit"で終わり。
#include<iostream>
using namespace std;

int main(){
	int n,money = 100000;

	cin >> n;
	for(int i=0;i<n;i++){
		money = money * 1.05;
		if(money % 1000)
			money = money / 1000 * 1000 + 1000;
	}
	cout << money << endl;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
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; }
int main(){
    cout << fixed << setprecision(10);
    string s;
    cin >> s;
    vector<pair<int,int>> v;
    int pre;
    int now = 0;
    rep(i, s.size()){
        if(i == 0){
            if(s[i] == '<'){
                pre = 1;
                now++;
                if(i == s.size()-1) v.push_back({pre,now});
            }else{
                pre = 0;
                now++;
                if(i == s.size()-1) v.push_back({pre,now});
            }
        }else{
            if(s[i] == '<'){
                bool push = 0;
                if(pre == 1){
                    now++;
                    if(i == s.size()-1) v.push_back({pre,now});
                }else{
                    push = 1;
                    //cout << "> input " << i << endl;
                    v.push_back({pre,now});
                    pre = 1;
                    now = 1;
                    if(i == s.size()-1){
                        //cout << "hit1" << endl;
                        v.push_back({pre,now});
                    }
                }
            }else{
                if(pre == 0){
                    now++;
                    if(i == s.size()-1) v.push_back({pre,now});
                }else{
                    //cout << "< input" << i << endl;
                    v.push_back({pre,now});
                    pre = 0;
                    now = 1;
                    if(i == s.size()-1){
                        v.push_back({pre,now});
                        //cout << "hit2" << endl;
                    }
                }
            }
        }
    }

    ll ans = 0;

    //cout << endl;
    // for(auto u : v){
    //     cout << u.first << " " << u.second << endl;
    // }
    //cout << endl;

    rep(i, v.size()){
        //cout << v[i].first << " " << v[i].second << endl;
        if(i == 0){
            rep(j,v[i].second+1){
                ans += j;
            }
            if(v[i].first == 1){
                //cout << "Yes" << endl;
                if(v.size() != 1) ans -= min(v[i].second, v[i+1].second);
            }
        }else if(i == v.size()-1){
            rep(j,v[i].second+1){
                ans += j;
            }
        }else{
            rep(j,v[i].second+1){
                ans += j;
            }
            if(v[i].first == 1){
                //cout << "Yes" << endl;
               ans -= min(v[i].second, v[i+1].second);
            }
        }
        //cout << ans << endl;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6056
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Competitive.lib
{

    internal class Solution
    {
        public string[] M;
        public int H, W;

        public void Run()
        {
            var line = Input.ReadIntArray();
            H = line[0];
            W = line[1];
            M = new string[H];

            for (int i = 0; i < H; i++)
            {
                M[i] = Console.ReadLine();
            }

            for (int y = 0; y < H; y++)
            for (int x = 0; x < W; x++)
            {
                var color = M[y][x];
                if(color == '.') continue;

                bool flag = false;
                if (y - 1 >= 0 && M[y - 1][x] == '#') flag = true;
                if (y + 1 < H  && M[y + 1][x] == '#') flag = true;
                if (x - 1 >= 0 && M[y][x - 1] == '#') flag = true;
                if (x + 1 < W  && M[y][x + 1] == '#') flag = true;

                if (!flag)
                {
                    Console.WriteLine("No");
                    Environment.Exit(0);
                }
            }

            Console.WriteLine("Yes");
        }
    }

    // libs ----------


    // common ----------

    internal static class Input
    {
        public static int ReadInt()
        {
            string line = Console.ReadLine();
            return int.Parse(line);
        }

        public static int[] ReadIntArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(int.Parse).ToArray();
        }

        public static double[] ReadDoubleArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(double.Parse).ToArray();
        }
    }

    internal class Program
    {
        public static void Main(string[] args)
        {
            var s = new Solution();
            s.Run();
        }
    }
}

Measured memory_bytes: 13396
N = int(input())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]

res = sum(B)
for i in range(N-1):
  if A[i]+1 == A[i+1]:
    res += C[A[i]-1]

print(res)
    

Measured memory_bytes: 3060
//#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<cstdio>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<utility>
#include<algorithm>
#include<cstring>
#include<sstream>
#include <iomanip>

using namespace std;

typedef long long ll ;
typedef double db;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector< pair<int,int> > vii;
const double pi = 2*acos(0) ;

#define pf		  	printf
#define sf			  scanf
#define pb(a)         push_back(a)
#define mp			make_pair
#define fi			 first
#define se			 second
#define for0(i,n)        for(int i=0;i<n;i++)
#define for1(i,n)        for(int i=1;i<=n;i++)
#define forab(i,a,b)       for(int i=a;i<=b;i++)
#define lcm(a, b)     ((a)*((b)/gcd(a,b)))
#define sq(a)		   (a)*(a)
#define nw				"\n"
#define abs(x)		fabs(x)
#define pcase(z,x)    cout<<"Case "<<z<<": "<<x<<"\n"
ll gcd(ll a, ll b){
	while(b){
		ll r=a%b;
		a=b;
		b=r;
		}
	return a;
	}
ll go(ll b, ll c, ll d){
	ll l= lcm(c,d);
	return b - (b/c + b/d - b/l);
	}
int main()
{
	ll a,b,c,d,ans;
	cin>>a>>b>>c>>d;
	ans = go(b,c,d) - go(a-1,c,d);
	cout<<ans<<nw;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include<math.h>
#include<bitset>
#include<string>
#include<iostream>
#include<vector>
#include<string.h>
using namespace std;

int main()
{
    int D,G,ans,sum=1000000;
    cin>>D>>G;
    int p[D],c[D];
    for(int i=0;i<D;i++) cin>>p[i]>>c[i];
    
    int n = D;

    // {0, 1, ..., n-1} の部分集合の全探索
    for (int bit = 0; bit < (1<<n); ++bit)
    {
        int P[D];
        memcpy(P,p,sizeof(p));
        
        vector<int> S;
        int point=0,cnt=0;
        for (int i = 0; i < n; ++i) {
            if (bit & (1<<i)) { // i が bit に入るかどうか
            point+=P[i]*100*(i+1)+c[i];
            cnt+=P[i];
            P[i]=-1;
            if(G<=point and cnt<sum){
                sum=cnt;
                break;
            }
            }
        }

        int CNT=D-1;
        while(G>point){
            if(P[CNT]==-1){
                CNT--;
            }else{
                for(int i=0;i<P[CNT];i++){
                    point+=(CNT+1)*100;
                    cnt++;
                    if(G<=point and cnt<sum){
                    sum=cnt;
                    }
                }
                break;
            }
  
        }
        
    }
    cout<<sum<<endl;
    
    

    
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<string.h>
#include<queue>
#include<stack>
#include<climits>
#include<cmath>
#include<stdio.h>
using namespace std;

vector<int> p(30);
int target[30]={1,1,1,1,1,1,1,1,1,2,2,2,4,4,4,6,6,6,5,5,5,3,3,3,3,3,3,3,3,3};
int change[4][10]={{1,2,3,15,19,   28,29,30,16,21},
                    {7,8,9,13,10,   22,23,24,18,12},
                    {1,4,7,10,16,   24,27,30,21,18},
                    {3,6,9,12,13,   22,25,28,19,15}};
int ans=INT_MAX;
map<vector<int>,int >m;
void dfs(vector<int>t,int co){
    if((m.count(t)&&m[t]<=co) || co>=min(9,ans)){
        return;
    }
    m[t]=co;
    bool ok=true;
    for(int i=0;i<30;i++){
        if(t[i]!=target[i]){
            ok=false;
        }
    }
    if(ok){
        ans=co;
        return;
    }
    for(int i=0;i<4;i++){
        for(int k=0;k<5;k++){
            swap(t[change[i][k]-1], t[change[i][5+k]-1]);
        }
        dfs(t,co+1);
        for(int k=0;k<5;k++){
            swap(t[change[i][k]-1], t[change[i][5+k]-1]);
        }
    }
    return;
}
int main(){
    int n;
    cin>>n;
    while(n--){
        ans=INT_MAX;
        m.clear();
        for(int i=0;i<30;i++){
            cin>>p[i];
        }
        dfs(p,0);
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 1260
def main():
    n, m = map(int, input().split())
    answer = ["" for _ in range(m)]
    all_pref = {}
    for i in range(m):
        p, y = map(int, input().split())
        if p in all_pref:
            all_pref[p].append([y, i])
        else:
            all_pref[p] = [[y, i]]
    for pref, date in all_pref.items():
        date.sort(key=lambda x: x[0])
        order = 0
        for year, num in date:
            answer[num] = str(pref).zfill(6) + str(order + 1).zfill(6)
            order += 1
    print("\n".join(answer))


if __name__ == '__main__':
    main()



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

using namespace std;

typedef long long ll;

ll dp[100005];

void solve() {
  int n, maxw;
  cin >> n >> maxw;
  while(n--) {
    int w, v;
    cin >> w >> v;
    for(int i = maxw; i >= w; i--) {
      dp[i] = max(dp[i], dp[i-w] + v);
    }
  }
  cout << dp[maxw] << endl;
}

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


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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define INF         INT_MAX/3
#define LLINF       LLONG_MAX/3
#define MOD         (1000000007LL)
#define MODA(a, b)  a=((a)+(b))%MOD
#define MODP(a, b)  a=((a)*(b))%MOD
#define inc(i, l, r)   for(long long i=(l);i<(r);i++)
#define dec(i, l, r)   for(long long i=(r)-1;i>=(l);i--)
#define pb          push_back
#define se          second
#define fi          first
#define mset(a, b)  memset(a, b, sizeof(a))

using LL  = long long;
using G   = vector<vector<int>>;

int di[] = {0, -1, 0, 1};
int dj[] = {1, 0, -1, 0};
// }}}

int h, w;
string c[50];
int d[50][50];
//int kita[50][50];

int main() {
    std::ios::sync_with_stdio(false);
    cin >> h >> w;
    inc(i, 0, h){
        cin >> c[i];
    }

    int sum = 0;
    inc(i, 0, h){
        inc(j, 0, w){
            if(c[i][j] == '#'){
                sum++;
            }
            d[i][j] = INF;
        }
    }

    //mset(kita, 0);

    queue<pair<pair<int, int>, int>> q;
    q.push({{0, 0}, 0});
    while(!q.empty()){
        auto n = q.front();q.pop();
        int i = n.fi.fi;
        int j = n.fi.se;
        int dist = n.se;

        //if(kita[i][j]){
            //continue;
        //}

        //kita[i][j] = 1;
        if(d[i][j] != INF) continue;
        d[i][j] = dist;

        inc(k, 0, 4){
            int ni = i + di[k];
            int nj = j + dj[k];
            if(ni >= 0 && ni < h && nj >= 0 && nj < w){
                if(c[ni][nj] == '#') continue;
                q.push({{ni, nj}, dist+1});
            }
        }
    }

    if(d[h-1][w-1] == INF){
        cout << -1 << endl;
        return 0;
    }

    cout << h*w - d[h-1][w-1] - sum -1 << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;

int main(){
    ll N, K;
    cin >> N >> K;
    vector<ll> A(N);
    for(int i=0; i<N; i++){
        cin >> A[i];
    }

    vector<ll> count(N, -1);
    count[0] = 0;

    ll x;
    ll loop;
    ll s, t;
    s = 0;
    while(1){
        if(count[s] == K){
            cout << s+1 << endl;
            return 0;
        }
        t = A[s]-1;
        if(count[t] >= 0){
            x = t;
            loop = count[s] + 1 - count[t];
            break;
        }else{
            count[t] = count[s] + 1;
            s = t;
        }
    }

    ll amari = (K-count[t])%loop;
    s = t;
    for(int i=0; i<amari; i++){
        t = A[s] - 1;
        s = t;
    }

    cout << t+1 << endl;
}

Measured memory_bytes: 6424
#include <bits/stdc++.h>
#define maxn 200005
using namespace std;

vector<int> cute, loli;
int n;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n;
    for(int i = 0; i < n; i++) {
        int x, y; cin >> x >> y;
        cute.push_back(x - y);
        loli.push_back(x + y);
    }
    cout << max(*max_element(begin(cute), end(cute)) - *min_element(begin(cute), end(cute)),
                *max_element(begin(loli), end(loli)) - *min_element(begin(loli), end(loli))) << '\n';
    return 0;
}


Measured memory_bytes: 5108
use std::io;

fn read_line() -> String {
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s
}

macro_rules! from_line {
    ($($a:ident : $t:ty),+) => {
        $(let $a: $t;)+
        {
            let _line = read_line();
            let mut _it = _line.trim().split_whitespace();
            $($a = _it.next().unwrap().parse().unwrap();)+
            assert!(_it.next().is_none());
        }
    };
}

fn main() {
    from_line!(n: isize);
    if n % 7 == 0 || n % 4 == 0 {
        println!("Yes");
        return;
    }
    for i in 1..n/7 + 1 {
        let k = n - 7*i;
        if k % 4 == 0 {
            println!("Yes");
            return;
        }
    }
    println!("No");
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
int c = 100000;
int a[120000]={},b[120000]={},d[120000];
int main(){
    for(int i=2;i<=c;i++){
        int k=1;
        while(i*k<=c){
            a[i*k]++;
            k++;
        }
    }
    for(int i=3;i<=c;i++){
        if(a[i]==1&&a[(i+1)/2]==1) b[i] = 1;
    }
    for(int i=0;i<c;i++) d[i+1] = d[i] + b[i];
    int q;
    cin >> q;
    for(int i=0;i<q;i++){
        int x,y;
        cin >> x >> y;
        cout << d[y+1]-d[x] << endl;
    }
}

Measured memory_bytes: 1792
# pragma warning(disable:4996)
#include<cstdio>
#include<string>
#include <iostream>
using namespace std;
char arr[4][4];
string a;
string b;
string c;
int main()
{
	int n,k;//A%B>=k  
	cin >> a;
	cin >> b;
	cin >> c;
	
	printf("%c%c%c", a.at(0), b.at(1), c.at(2));

	
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int a,b;
  char map[300][300];
  while(1){
    cin>>a>>b;
    if(a==0&&b==0){
      break;
    }
    for(int i=0;i<a;i++){
      for(int j=0;j<b;j++){
	map[j][i]='#';
	cout<<map[j][i];
      }
      cout<<endl;
    }
    cout<<endl;
  }
  return(0);
}

Measured memory_bytes: 3108
#include <iostream>
#include<sstream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<iomanip>
#define  mem(a,b) memset(a,b,sizeof(a))

const int mo=1000000007;
const int inf=0x3f3f3f3f;
double pi=3.14159265358979323846;
double e= 2.71828182845904523536;
typedef long long ll;
using namespace std;
ll a[100005];
ll b[100005];
int main()
{
    int n;
    ll ans=1;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        scanf("%lld",&a[i]);
    }
    sort(a,a+n);
    b[0]=a[0];
    for(int i=1;i<n;i++)
    {
        b[i]=b[i-1]+a[i];
    }
    for(int i=n-2;i>=0;i--)
    {
        if(b[i]*2>=a[i+1])
        {
            ++ans;
            //cout<<a[i]<<' '<<a[i-1]<<endl;
        }
        else
            break;
    }
    cout<<ans<<endl;
}




Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

int main()
{
    int n,a;
    cin>>n>>a;
    int cnt=n/500;
    if(n-cnt*500<=a) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 256
def gcd(m, n):
    r = m % n
    return n if r == 0 else gcd(n, r)


n = int(input())
A = list(map(int, input().split()))

GCD_left = A[:]
for i in range(1, n):
    GCD_left[i] = gcd(GCD_left[i - 1], GCD_left[i])
GCD_right = A[:]
for i in range(n - 2, -1, -1):
    GCD_right[i] = gcd(GCD_right[i], GCD_right[i + 1])

GCD = [1] * n
GCD[0], GCD[-1] = GCD_right[1], GCD_left[-2]
for i in range(1, n - 1):
    GCD[i] = gcd(GCD_left[i - 1], GCD_right[i + 1])

print(max(GCD))


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

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
    ll q,h,s,d,n;
    cin>>q>>h>>s>>d>>n;
    ll one=min(s,min(h*2,q*4));
    ll two=min(d,one*2);
    cout<<(n/2)*two+(n%2)*one;
    return 0;
}


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

typedef long long ll;
ll a[3];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>a[0]>>a[1]>>a[2];
    sort(a,a+3);
    if(a[0]==a[1] && a[1]==5 && a[2]==7) cout<<"YES\n";
    else cout<<"NO\n";



}


Measured memory_bytes: 256
import math
n=int(input())
a=[]

for i in range(n):
  a.append(input())
cnt=0
b=[int(i) for i in a]

for i in range(n):
    c=math.sqrt(b[i])
    c=int(c)
    if b[i]==2:
      cnt+=1
    for j in range(2,b[i]):
      if b[i]%j==0:
        break
      if math.sqrt(b[i])<j:
        cnt+=1
        break
print(cnt)       
      


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

int main() {
  int a, b;
  cin >> a >> b;
  int S = 0;
  if(a > b) {
    for(int i = 0; i < a; i++) {
      S += b * pow(10, i);
    }
  }
  else {
    for(int i = 0; i < b; i++) {
      S += a * pow(10, i);
    }
  }
  cout << S << endl;
}

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

const ll mod =1e9+7;

int main() {
    string l;
    cin>>l;
    ll n=l.size();
    vector<vector<ll>> dp(n,vector<ll>(2));
    dp[0][1]=1; 
    dp[0][0]=2;

    rep(i,n-1){
        if(l[i+1]=='1'){
            dp[i+1][1]=(dp[i][1]*3+dp[i][0])%mod;
            dp[i+1][0]=dp[i][0]*2%mod;
        }else{
            dp[i+1][1]=dp[i][1]*3%mod;
            dp[i+1][0]=dp[i][0]%mod;
        }
    }
    cout<<(dp[n-1][0]+dp[n-1][1])%mod<<endl;
    return 0;
}



Measured memory_bytes: 8812