akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<int(n);i++)
#define FOR(i,n,m) for(int i=n;i<int(m);i++)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;

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

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a*b/gcd(a,b);}	

const ll mod=1e9+7;
const int INF=INT_MAX/2;
const int N_MAX=100010;

int main(){
	int x,y;
	int sum=0;
	cin>>x>>y;
	if(x==3){
		sum+=100000;
	}else if(x==2){
		sum+=200000;
	}else if(x==1){
		sum+=300000;
	}
	if(y==3){
		sum+=100000;
	}else if(y==2){
		sum+=200000;
	}else if(y==1){
		sum+=300000;
	}
	if(x==1 && y==1){
		sum+=400000;
	}
	cout<<sum<<endl;
	return 0;
}



Measured memory_bytes: 256
// Template
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <numeric>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>

using namespace std;
typedef long long ll;

#define REP(i, n) for(int i = 0;i < n;i++)
#define INF 1 << 30

int MOD = 1000000007;
int n,k,l;
vector<bool> visited;

map<int, vector<int>> road;
vector<int> color1;

map<int, vector<int>> railroad;
vector<int> color2;

void dfs1(int node, int color){
    visited[node] = true;

    color1[node] = color;

    for(int i=0; i<road[node].size(); ++i){
        if(visited[road[node][i]]) continue;
        dfs1(road[node][i], color);
    }
}

void dfs2(int node, int color){
    visited[node] = true;

    color2[node] = color;

    for(int i=0; i<railroad[node].size(); ++i){
        if(visited[railroad[node][i]]) continue;
        dfs2(railroad[node][i], color);
    }
}

int main(){
    std::ios_base::sync_with_stdio(false);

    cin >> n >> k >> l;

    REP(i,k){
        int p,q; cin >> p >> q; p--; q--;
        road[p].push_back(q);
        road[q].push_back(p);
    }

    REP(i,l){
        int p,q; cin >> p >> q; p--; q--;
        railroad[p].push_back(q);
        railroad[q].push_back(p);
    }

    REP(i,n){
        road[i].push_back(i);
        railroad[i].push_back(i);
    }


    int c = 1;
    color1 = std::vector<int>(n, 0);
    visited = std::vector<bool>(n, false);

    REP(i,n){
        if(!visited[i]){
            dfs1(i, c);
            c++;
        }
    }

    c = 1;
    color2 = std::vector<int>(n, 0);
    visited = std::vector<bool>(n, false);

    REP(i,n){
        if(!visited[i]){
            dfs2(i, c);
            c++;
        }
    }

    map<pair<int, int>, int> cnt;

    REP(i,n){
        cnt[make_pair(color1[i], color2[i])]++;
    }

    REP(i,n){
        cout << cnt[make_pair(color1[i], color2[i])] << " ";
    }
    cout << '\n';




    return 0;
}


Measured memory_bytes: 57984
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_6_D
require "matrix"

n,m = gets.split.map(&:to_i)

nArr = []
n.times.each {
    nArr.push(gets.split.map(&:to_i))
}
a = Matrix.rows(nArr)

mArr = []
m.times.each {
    mArr.push(gets.split.map(&:to_i))
}
b = Matrix.rows(mArr)

puts (a * b).to_a

Measured memory_bytes: 6996
#include<bits/stdc++.h>
    using namespace std;
     
    int  main(){
     
    	string a;
    	cin >> a;
    	long long  k;
    	cin >> k;
     
    	long long  n = a.length();
    	long long  ans = 0;
    	
    	//string t;
    	a=a+a+a;
    	//a=a+a;
    	//cout << a << "\n";
    	long long  l=0,m=0,r=0;
    	for(long long  i=1;i<n;i++){
    		if(a[i]==a[i-1]){
    			l++;
    			a[i]='1';
    		}
    	}
     
    	for(long long  i=n;i<2*n;i++){
    		if(a[i]==a[i-1]){
    			m++;
    			a[i]='1';
    		}
    	}
     
    	for(long long  i=2*n;i<3*n;i++){
    		if(a[i]==a[i-1]){
    			r++;
    			a[i]='1';
     
    		}
    	}
     
    	if( k==1 ){
    		cout << l << "\n";
    	}else if(k==2){
    		cout << l + m << "\n";
    	}else{
    		if(k%2==1)
    		cout << (k/2)*(l + m) + (k%2)*r << "\n";
    		else
    		cout << l +(k-2)*(m) + r << "\n";

    	}
    	return 0;
    }

Measured memory_bytes: 256
MOD=10**9+7
N=int(input())
x=list(map(int, input().split()))
y=[x[i+1]-x[i] for i in range(N-1)]
 
upp=[1]*(N+1)
for i in range(2, N+1):
  upp[i]=upp[i-1]*i
  upp[i]%=MOD
  
N_1=N-1
b=[0]*(N_1)
b[0]=upp[N_1]
tmp=upp[N_1]
for i in range(1, N_1):
  a=tmp*pow(i+1, MOD-2, MOD)%MOD
  b[i]=(b[i-1]+a)%MOD


print(sum([b[i]*y[i]%MOD for i in range(N_1)])%MOD)

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

# define pb push_back
# define fr first
# define sc second
# define mk make_pair

using namespace std;

const int inf = 1e9 + 7;
const int N = 55;

typedef long long ll;

ll n, a, x[N], dp[N][N][N * N], ans;

int main()
{
      cin >> n >> a;

      for(int i = 1; i <= n; i ++)
      {
            cin >> x[i];
            dp[i][1][x[i]] ++;
      }

      for(int i = 1; i <= n; i ++)
            for(int j = 1; j <= i; j ++)
                  for(int k = 1; k <= 50 * 50; k ++)
                  {
                        dp[i][j][k] += dp[i - 1][j][k];
                        if(j > 0 && x[i] <= k)
                              dp[i][j][k] += dp[i - 1][j - 1][k - x[i]];
                  }
      for(int i = 1; i <= n; i ++)
            ans += dp[n][i][a * i];

      cout << ans << endl;
}


Measured memory_bytes: 65792
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main() {
	int n; cin >> n;
	string s; cin >> s;

	int cnt = 0;
	REP(i, 10) {
		auto posA = find(s.begin(), s.end(), i + '0');
		if (posA != s.end()) {
			REP(j, 10) {
				auto posB = find(posA+1, s.end(), j + '0');
				if (posB != s.end()) {
					REP(k, 10) {
						auto posC = find(posB+1, s.end(), k + '0');
						if (posC != s.end())
							cnt++;
					}
				}
			}
		}
	}

	cout << cnt << '\n';
	return 0;
}

Measured memory_bytes: 3704
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<cstdio>
#include<string>
using namespace std;

typedef long long ll;
typedef pair<ll,int> P;

#define rep(i,x) for(int i = 0 ; i < x ; i ++)
#define rep1(i,x) for(int i = 1 ; i <= x ; i ++)
#define rrep(i,x) for(int i = x-1 ; i >= 0 ; i --)
#define pb push_back
#define sor(vec) sort(vec.begin(),vec.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define fr first
#define sc second

const ll M = 1000000007;

int main(){
	int n,k;
	int a[102];
	scanf("%d%d",&n,&k);
	rep1(i,n)scanf("%d",&a[i]);
	
	static ll dp[102][102][256] = {};
	dp[0][0][0] = 1;
	rep1(i,n){
		dp[i][0][0] = 1;
		rep1(j,i){
			rep(t,256){
				dp[i][j][t] = dp[i-1][j][t] + dp[i-1][j-1][t^a[i]];
				if(dp[i][j][t] >= M)dp[i][j][t] -= M;
			}
		}
	}
	
	ll ret = 0;
	ll x = 1;
	rep1(i,n){
		x *= i;
		x %= M;
		ret += dp[n][i][k]*x;
		ret %= M;
	}
	cout << ret << endl;
}
				


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

int main(){
	int min = 1000000, max = -1000000, n, tmp, i;
	long sum = 0;
	
	cin >> n;
	
	for(i = 0; i < n; i++){
		cin >> tmp;
		
	if(tmp < min){
		min = tmp;
	}
	if(tmp > max){
		max = tmp;
	}
	sum += tmp;
}
		
	cout << min << " " << max << " " << sum << endl;
	
	return 0;
}

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

const int MOD = 1000000007;
const int INF = 1e9;

//long long
using ll = long long;

//出力系
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
 
// begin() end()
#define all(x) (x).begin(),(x).end()

//for
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n, i##_len=(n); i>=0; i--)
#define FOR(i,a,b) for(int i=(a), i##_len=(b); i<i##_len; ++i)

//最大公約数 
unsigned gcd(unsigned a, unsigned b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
} 

int main(){
int A, B, C, D;
cin >> A >> B >> C >> D;

int f = max(A, C);
int a = min(B, D);

if(a - f > 0) cout << a - f << endl;
else cout << 0 << endl;

}

Measured memory_bytes: 256
#include <set>
#include <map>
#include <list>
#include <stack>
#include <queue>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
#define int long long

typedef pair<int,int> P;

signed main(void){
  int n,k;
  cin >> n >> k;
  vector<P> ab;

  for(int i = 0; i < n; i++){
    P buf;
    cin >> buf.first >> buf.second;
    ab.push_back(buf);
  }

  sort(ab.begin(), ab.end());

  for(int i = 1; i < n; i++){
    ab[i].second += ab[i-1].second;
  }

  int buf2 = -1;
  for(int i = 0; i < n; i++){
    if(ab[i].second >= k){
      buf2 = i;
      break;
    }
  }

  cout << ab[buf2].first << "\r\n";
  return 0;
}


Measured memory_bytes: 2420
#include <iostream>

#define N_NUMBER 3
using namespace std;

int Numbers[N_NUMBER];

int c_1, c_2, c_3, c_4;
void Sort_1(int *p_1);
void Sort_2(int *p_2);

void Sort_1(int *p_1)
{
	int box_1[N_NUMBER];
	for (int i = 0; i < N_NUMBER; i++)
		box_1[i] = p_1[i];
	for (c_1 = 0; c_1 < N_NUMBER; c_1++)
		Sort_2(box_1);
	for (int i = 0; i < N_NUMBER; i++)
		p_1[i] = box_1[i];
};
void Sort_2(int *p_2)
{
	int box_2[N_NUMBER];
	for (c_3 = 0; c_3 < N_NUMBER - c_1; c_3++)
		box_2[c_3] = p_2[c_3];
	for (c_2 = 0; c_2 < N_NUMBER - c_1 - 1; c_2++)
	{
		if (box_2[c_2] > box_2[c_2 + 1]) //????????????????§?
		{
			int para = box_2[c_2];
			box_2[c_2] = box_2[c_2 + 1];
			box_2[c_2 + 1] = para;
		}

	}
	for (c_4 = 0; c_4 < N_NUMBER - c_1; c_4++)
		p_2[c_4] = box_2[c_4];
};

int main()
{
	for (int i = 0; i < N_NUMBER; i++)
		cin >> Numbers[i];
	Sort_1(Numbers);
	// Numbers???????????????????????????

	for (int i = 0; i < N_NUMBER - 1; i++)
		cout << Numbers[i] << " ";
	cout << Numbers[N_NUMBER - 1] << endl;
	//Numbers?????????????????????

	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <string>
#include <cstdio>
#include <vector>
#include <queue>
#include <algorithm>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <functional>
#define MOD 1000000007

int i,j;

struct edge {
    int to;
    int cost;
};

typedef long long ll;
using namespace std;
using P = pair<int, int>;

bool compare_by_b(pair<int,pair<string,int>> a, pair<int,pair<string,int>> b) {
    if(a.second.first != b.second.first){
        return a.second.first < b.second.first;
    }else{
    return a.second.second > b.second.second;
    }
}

int main(void) {
    int n;
    cin >> n;
    vector<pair<int,pair<string,int>>> lst;
    for(i=0;i<n;i++){
        string s;
        int b;
        cin >> s >> b;
        lst.push_back(make_pair(i+1,make_pair(s,b)));
    }
    sort(lst.begin(),lst.end(),compare_by_b);
    for(i=0;i<n;i++){
        cout << lst[i].first << endl;
    }
    return 0;
}


Measured memory_bytes: 256
from decimal import Decimal
from heapq import heapify, heappop, heappush
N, K = map(int, input().split())
*A, = map(int, input().split())

tot = sum(A)

ng = 0
ok = 10**9

m = 4

while ng + 1 < ok:
    m = (ng+ok)//2
    c = sum((a-1)//m for a in A)
    if c > K:
        ng = m
    else:
        ok = m
print(ok)


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

using namespace std;
using ll = long long;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

int main() {
  int n;
  cin >> n;
  int d[n][3];
  rep(i, n) rep(j, 3) cin >> d[i][j];

  int dp[n + 1][3];
  rep(i, 3) dp[0][i] = 0;

  rep(i, n) {
    rep(j, 3) {
      int j1 = (j + 1) % 3, j2 = (j + 2) % 3;
      dp[i + 1][j] = max(dp[i][j1] + d[i][j1], dp[i][j2] + d[i][j2]);
    }
  }

  int ans = 0;
  rep(i, 3) ans = max(ans, dp[n][i]);
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 2560
import sys
input = lambda: sys.stdin.readline().strip()
from collections import deque
s=deque(str(input()))
q=int(input())
flag=0
for i in range(q):
    j=input()
    if j[0]=="1":
        flag+=1
    else:
        if flag%2==1:
            if j[2]=="1":
                s.append(j[4])
            else:
                s.appendleft(j[4])
        else:
            if j[2]=="1":
                s.appendleft(j[4])
            else:
                s.append(j[4])
s=''.join(s)
if flag%2==1:
    s=s[::-1]
print(s)

Measured memory_bytes: 8692
#define _USE_MATH_DEFINES
#include  <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include <stdlib.h>
#include<stdio.h>
#include <queue>
#include<map>
#include <sstream>
#include<set>
#include<stack>

//#include<bits/stdc++.h>


using namespace std;

vector<long long int>t;
int n;
long long int ans;
void R(vector<long long int>a) {
    if (a.size() >= n) {
        int d = 1;
        for (int i = 0; i < a.size(); i++) {
            if (a[i] % 2 == 0) {
                d = 0;
            }
                
        //    cout << a[i] << " ";
            
            
        } if (!d)ans++;
      //  cout<<d <<" "<<ans<< endl;
       
        return;

    }int i = a.size();
    
    a.push_back(t[i]); R(a);
    a[i] = t[i] - 1; R(a);
    a[i] = t[i ]+ 1; R(a);

}

int main()
{

    int n, m, x;
    cin >> n >> m >> x;
    vector<vector<int>>p(n, vector<int>(m));
    vector<int>c(n);
    for (int i = 0; i < n; i++) {
        cin >> c[i];
        for (int j = 0; j < m; j++) {
            cin >> p[i][j];
           
        }
    }
    long long int ans = 99999999999999999;
    for (int i = 0; i < 1 << n; i++) {
       
        vector<int>g(m);
        int d = 0; long long int y = 0,v=0;
        
        for (int j = 0; j < n; j++) {
            if (!(i & 1 << j))continue;
           y += c[j]; v++;
            for (int k = 0; k < m; k++) {
                if (g[k] >= x)continue;
                
                g[k] += p[j][k];
                if (g[k] >= x)d++;
           }
        }
        if (d == m)ans = min(ans, y);
        
    }
    if (ans > 10000000000)ans = -1;
    cout << ans << endl;
    return 0;

}

Measured memory_bytes: 3660
import scala.io.StdIn.readLine

object Main {
  def getTop3() = {
    {
      for(i<-1 to 8) yield {
        val n = readLine.split(" ")
        (n(0).toInt, n(1).toDouble)
      }
    }.toList.sortBy(_._2)
  }

  def main(args:Array[String]) = {
    val x1 = getTop3
    val x2 = getTop3
    val x3 = getTop3
    val r = List(x1(0),x1(1),x2(0),x2(1),x3(0),x3(1))
    r.foreach {e => println(e._1+" "+"%.2f".format(e._2)) }
    val r2 = (x1.drop(2) ++ x2.drop(2) ++ x3.drop(2)).sortBy(_._2)
    println(r2(0)._1 + " " + "%.2f".format(r2(0)._2))
    println(r2(1)._1 + " " + "%.2f".format(r2(1)._2))
  }
}

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

int main() {

  string base;
  
  cin >> base;
  
  if(base == "A") {
    
    cout << "T" << endl;
    
  } else if(base == "T") {
    
    cout << "A" << endl;
    
  } else if(base == "G")  {
    
    cout << "C" << endl;
    
  } else if(base == "C") {
    
    cout << "G" << endl;
    
  }
  
  return 0;
  
}

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

int main(){
	int n;
	cin >>n;

	int a[n], b[n], c[n];

	for(int i=0; i<n; i++){
		cin >> a[i] >> b[i] >> c[i];
	}

	for(int i=0; i<n; i++){
		if(a[i]*a[i] == b[i]*b[i] + c[i]*c[i]){
			cout << "YES" << endl;
			continue;
		}
		if(b[i]*b[i] == a[i]*a[i] + c[i]*c[i]){
			cout << "YES" << endl;
			continue;
		}
		if(c[i]*c[i] == b[i]*b[i] + a[i]*a[i]){
			cout << "YES" << endl;
			continue;
		}
		cout << "NO" << endl;
	}

	return 0;
}

Measured memory_bytes: 3084
/*
  AOJ 2086
  Title:!
  @kankichi573
*/
#include <stdio.h>
#include <string.h>
#define min(x,y) (((x)<(y))?(x):(y))

int N;
char M[12];
char primes[]={2,3,5,7,11,13,17,19,23,29,31};
int biggest_prime(int x)
{
  int i;
  for(i=10;i>=0;i--)
    {
      //printf("%d %d::",primes[i],x % primes[i]);
      if((x % primes[i])==0)
	return(primes[i]);
    }
  return(-1);
}
// (24,2)=>3
// (16,2)=>4
int biggest_prime_times(int x,int p)
{
  if((x % p)!=0)
    return(0);
  return(1+biggest_prime_times(x/p,p));
}
int myatoi(char c)
{
  if(isdigit(c))
    return(c-'0');
  else
    return(c-'A'+10);
}
unsigned long long todecimal(char x[],int base)
{
  int i,l;
  unsigned long long ret;
  l=strlen(x);
  ret=0;
  for(i=0;i<l;i++)
    {
      ret *= base;
      ret += myatoi(x[i]);
    }
  return(ret);
}


unsigned long long devide_times(unsigned long long n,int d)
{
  unsigned long long ret,dd;
  ret=0;dd=d;
  while(dd <= n)
    {
      ret += n/dd;
      dd *= d;
    }

  return(ret);
}
main()
{
  unsigned long long ret;
  int bp; // prime

  //printf("%llu\n",devide_times(100,5));
  
  while(scanf("%d %s",&N,M) && (N || M[0]!='0'))
    {
      if(N==12)
	{
	  ret=min(devide_times(todecimal(M,N),2)/2,
		  devide_times(todecimal(M,N),3));
	}
      else if(N==24)
	{
	  ret=min(devide_times(todecimal(M,N),2)/3,
		  devide_times(todecimal(M,N),3));
	}
      else
	{
	  bp=biggest_prime(N);
	  ret=devide_times(todecimal(M,N),bp)/biggest_prime_times(N,bp);
	}
      printf("%llu\n",ret);
    }
  
  return(0);
}

Measured memory_bytes: 616
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <bitset>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <queue>

#define mp make_pair
#define pb push_back


typedef long long ll;
typedef long double ld;

using namespace std;

#ifndef LOCAL
#define cerr _cer
struct _cert
{
    template <typename T> _cert& operator << (T) { return *this; }
};
_cert _cer;
#endif

template <typename T> void dprint(T begin, T end) {
    for (auto i = begin; i != end; i++) {
		cerr << (*i) << " ";
    }
    cerr << "\n";
}
const int MX = 1200000;

int z[MX];
string s[2100];
string t;
string bs;
int av[MX];

void calcz() {
	z[0] = 0;
	int l = 0, r = 0;
	for (int i = 1; i < t.size(); ++i) {
		if (r > i)
			z[i] = min(r - i, z[i - l]);
		else
			z[i] = 0;
		while (i + z[i] < t.size() && t[z[i]] == t[i + z[i]])
			++z[i];
		if (i + z[i] > r)
			r = i + z[i], l = i;
	}
	z[t.size()] = 0;
}

int n, k;
char buf[MX];
int dp[2100][11000];

int main() {
	scanf("%d%d", &n, &k);
	for (int i = 0; i < n; ++i) {
		scanf(" %s", buf);
		s[i] = buf;
	}
	dp[n][0] = 1;
	for (int i = n - 1; i >= 0; --i) {
		for (int j = 0; j <= k; ++j)
			dp[i][j] = dp[i + 1][j];
		for (int j = 0; j + s[i].size() <= k; ++j)
			dp[i][j + s[i].size()] |= dp[i + 1][j];
	}
	av[0] = 1;
	for (int i = 0; i < n; ++i) {
		int bstp = -1;
		pair<int, char> bst = make_pair(k + 1, 0);
		t = s[i] + "$" + bs;
		calcz();
		int len = s[i].size();
		for (int j = 0; j <= bs.size(); ++j) {
			if (av[j] && (j + len <= k) && dp[i + 1][k - j - len]) {
				int cm = z[len + 1 + j];
				if (cm < len && j + cm < bs.size() && s[i][cm] < bs[j + cm]) {
					if (make_pair(j + cm, s[i][cm]) < bst)
						bst = make_pair(j + cm, s[i][cm]), bstp = j;
					else if (make_pair(j + cm, s[i][cm]) == bst) {
						int cm2 = z[j - bstp];
						if (j - bstp + cm2 == s[i].size() || s[i][cm2] < s[i][j - bstp + cm2])
							bstp = j;
					}
				}
			}
		}
		if (bstp != -1) {
			for (int i = bst.first + 1; i <= bs.size(); ++i)
				av[i] = 0;
			bs.resize(bstp);
			bs += s[i];
			av[bs.size()] = 1;
		}
		else {
			int lst = -1;
			for (int j = 0; j <= bs.size(); ++j) {
				if (av[j] && (j + len) <= k && dp[i + 1][k - j - len]) {
					int cm = z[len + 1 + j];
					if (j + cm == bs.size()) {
						if (lst == -1)
							lst = j;
						else {
							int cm = z[j - lst];
							if (j - lst + cm == s[i].size() || s[i][cm] < s[i][j - lst +cm])
								lst = j;
						}
					}
				}
			}
			if (lst != -1) {
				bs.resize(lst);
				bs += s[i];
				av[bs.size()] = 1;
			}
		}
		t = s[i] + "$" + bs;
		calcz();
		for (int j = (int)bs.size() - 1; j >= 0; --j) {
			if (av[j] && (j + len <= k) && dp[i + 1][k - j - len]) {
				int cm = z[len + 1 + j];
				if (cm == len) {
					av[j + len] = 1;
				}
			}
		}
	}
	cout << bs << "\n";
	return 0;
}




Measured memory_bytes: 91520
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace q3
{
    class Program
    {
        static void Main(string[] args)
        {
            var input1 = Console.ReadLine().Split(' ').Select(x => Convert.ToInt32(x)).ToArray();
            var K = input1[0];
            var N = input1[1];
            var A = Console.ReadLine().Split(' ').Select(x => Convert.ToInt32(x)).ToArray();
            A = A.OrderBy(x => x).ToArray();
            var max = 0;
            var maxIdx = 0;
            for (var i=0; i<A.Length; i++)
            {
                var dist = ((A[(i + 1) % N]) - A[i] + K) % K;
                if (dist > max) {
                    max = dist;
                    maxIdx = i;
                }
            }
            Console.WriteLine(K - max);
        }
    }
}


Measured memory_bytes: 39156
#include "bits/stdc++.h"

#define rep(i,n) for(int i = 0;i<n;i++)
#define cint(a) int a; cin >> a;
#define cstr(str) string str; cin >> str;


using namespace std;
using ll = long long;

const ll mod = 1e9 + 7;

int main(void) {

	ios::sync_with_stdio(false);
	cin.tie(0);

	ll n; cin >> n;
	vector<ll> a(n);
	ll sum = 0;
	rep(i, n) cin >> a[i];
	sort(a.begin(), a.end());

	if (n % 2) {
		rep(i, n / 2) sum += a[(n / 2) + i + 1] + a[(n / 2) + i];
	}
	else {
		rep(i, (n-2) / 2) sum += a[(n / 2) + i + 1] + a[(n / 2) + i];
		sum += a[n / 2];

	}

	cout << sum << endl;


	return 0;
}
 

Measured memory_bytes: 4772
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    N,K=map(int,input().split())
    A=tuple(map(int1,input().split()))
    doubling=[[A[i]]*(K.bit_length()+1) for i in range(N)]
    for k in range(K.bit_length()):
        for i in range(N):
            doubling[i][k+1]=doubling[doubling[i][k]][k]
    ans=0
    k=0
    while K>0:
        if K&1:
            ans=doubling[ans][k]
        K>>=1
        k+=1
    print(ans+1)

if __name__ == '__main__':
    main()


Measured memory_bytes: 207936
#include <algorithm>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;

struct A {
  int y1, x1, y2, x2;
};

int main() {
  int h, w;
  cin >> h >> w;
  long long a[505][505] = {0};
  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++)
      cin >> a[i][j];
  vector<A> ans;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w - 1; j++) {
      if (a[i][j] % 2 == 1) {
        ans.push_back(A{(i + 1), (j + 1), (i + 1), (j + 2)});
        a[i][j + 1] += 1;
      }
    }
    if (i < h - 1) {
      if (a[i][w - 1] % 2 == 1) {
        ans.push_back(A{(i + 1), w, (i + 2), w});
        a[i + 1][w - 1] += 1;
      }
    }
  }
  cout << ans.size() << endl;
  for (int i = 0; i < ans.size(); i++)
    cout << ans[i].y1 << " " << ans[i].x1 << " " << ans[i].y2 << " "
         << ans[i].x2 << endl;
  return 0;
}


Measured memory_bytes: 6128
#include <cmath>
#include <cstdio>
#include <queue>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define ll long long
#define maxn 500400
using namespace std;
inline void read(int &x){
    char ch;
    bool flag=false;
    for (ch=getchar();!isdigit(ch);ch=getchar())if (ch=='-') flag=true;
    for (x=0;isdigit(ch);x=x*10+ch-'0',ch=getchar());
    x=flag?-x:x;
}

inline void write(int x){
    static const int maxlen=100;
    static char s[maxlen];
        if (x<0) {   putchar('-'); x=-x;}
    if(!x){ putchar('0'); return; }
    int len=0; for(;x;x/=10) s[len++]=x % 10+'0';
    for(int i=len-1;i>=0;--i) putchar(s[i]);
}
int n,p;
int a[110];
int tot0,tot1;



long long get(int n,int m){
long long tmp=1;
for (int i=1;i<=m;i++)
    {
        tmp=tmp*1ll*(n-i+1)/(1ll*i);
    }
return tmp;
}



int main(){
    read(n); read(p);
    for (int i=1;i<=n;i++)
    {
        read(a[i]);
        if (a[i]%2==0)
            tot0++;
        else
            tot1++;
    }
    if (p==0)
        {
            /*
            if  ( (tot0==0)&&(tot1<2) )
            {
                puts("1");
                return 0;
            }
            */
            long long ans=1ll<<tot0;
            long long sum=1ll;
            for (int i=2;i<=tot1;i+=2)
                sum+=get(tot1,i);
            ans=ans*sum;
            printf("%lld\n",ans);
        }
    else
        {
            /*
            if  (tot1==0)
            {
                puts("0");
                return 0;
            }
            */
            long long ans=1ll<<tot0;
            long long sum=0ll;
            //printf("%d %d\n",tot0,tot1);
            for (int i=1;i<=tot1;i+=2)
                sum+=get(tot1,i);
            ans=ans*sum;
            printf("%lld\n",ans);
        }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, n) for (int i = 1; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
int main()
{
    int n;
    cin >> n;
    vector<int> h(n);
    rep(i, n) cin >> h[i];

    int best = 0;
    int cnt = 0;
    rep(i, n - 1) {
        if (h[i] >= h[i+1]) {
            cnt++;
        }
        else {
            best = max(best, cnt);
            cnt = 0;
        }
    }
    best = max(best, cnt);

    put(best);

    return 0;
}

Measured memory_bytes: 3780
#include <stdio.h>

int main(void)
{
        long n,a,r,s,m;

        scanf("%ld%ld%ld",&n,&a,&r);

        s=a*(n/(a+r));
        m=n%(a+r);
        if(a>m)
                printf("%ld",s+m);
        else
                printf("%ld",s+a);

        return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include<iostream>
using namespace std;

struct Point{
	double x,y;
};

int main(){

	int n,m,checkTable[101],path[101],id,start,goal,count,min_index;
	double distance[101][101],x,y,calc[101][101],min_value;
	bool canGO[101];
	Point table[101];
	stack<int> S;

	while(true){
		scanf("%d",&n);
		if(n == 0)break;

		for(int i=1; i <= n; i++){
			scanf("%d %lf %lf",&id,&x,&y);
			table[id].x = x;
			table[id].y = y;
		}

		for(int i = 1; i <= n; i++){
			for(int k = 1; k <= n; k++){
				distance[i][k] = sqrt((table[i].x-table[k].x)*(table[i].x-table[k].x)+(table[i].y-table[k].y)*(table[i].y-table[k].y));
			}
		}

		scanf("%d",&m);

		for(int i = 1; i <= m; i++){
			scanf("%d %d",&start,&goal);

			for(int k = 1; k <= n; k++){
				checkTable[k] = 0;
				if(distance[start][k] < 50 || fabs(distance[start][k] - 50) < 0.00000001){
					canGO[k] = true;
				}else{
					canGO[k] = false;
				}
				path[k] = start;
				for(int p = 1; p <= n; p++)calc[k][p] = distance[k][p];
			}

			count = 1;
			checkTable[start] = 1;

			while(count < n){
				min_value = 1000000000;

				for(int k = 1; k <= n; k++){
					if(checkTable[k] == 0 && canGO[k] == true && calc[start][k] < min_value){
						min_value = calc[start][k];
						min_index = k;
					}
				}

				if(min_value == 1000000000)break;

				checkTable[min_index] = 1;
				count++;

				for(int p = 1; p <= n; p++){
					if((canGO[p] == false || calc[start][p] > calc[start][min_index]+calc[min_index][p]) && (distance[min_index][p] < 50 || fabs(distance[min_index][p] - 50) < 0.00000001)){
						calc[start][p] = calc[start][min_index]+calc[min_index][p];
						canGO[p] = true;
						path[p] = min_index;
					}
				}
			}

			if(canGO[goal] == false)cout<<"NA"<<endl;
			else{
				int t = goal;
				while(true){
					S.push(t);
					t = path[t];
					if(t == start)break;
				}
				printf("%d",start);
				while(!S.empty()){
                    cout<<" "<<S.top();
					S.pop();
				}
				cout<<endl;
			}
		}
	}


	return 0;
}


Measured memory_bytes: 3376
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main(){
  int a,i,n;
  char str[200];
  fgets(str , sizeof(str) , stdin);

  n=strlen(str);

  a='a'-'A';   /*大文字と小文字の差*/

  for(i=0 ; i<n-1 ; i++){
    if(str[i] >= 'A' && str[i] <= 'Z'){  /*大文字なら　a を足す*/
      printf("%c",str[i]+a);
    }

    else if(str[i] >='a' && str[i] <= 'z'){  /*小文字なら a　で引く*/
      printf("%c",str[i]-a);
    }

    else{
      printf("%c",str[i]);
    }
  }

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

Measured memory_bytes: 524
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
using namespace std;

bool compare(const pair<int, long long> &a, const pair<int, long long> &b) {
	return a.second < b.second;
}

int main()
{
	int n, m;
	vector<pair<int, long long>> nb;

	cin >> n >> m;

	for (int i = 0; i < m; i++) {
		long long p, y;
		cin >> p >> y;
		nb.push_back(make_pair(i, p * 10000000000 + y));
	}

	sort(nb.begin(), nb.end(), compare);

	long long j = 0, k = 1;

	for (int i = 0; i < m; i++) {
		if (j < nb[i].second / 10000000000) {
			j = nb[i].second / 10000000000;
			k = 1;
		}
		nb[i].second = j * 1000000 + k;
		k++;
	}

	sort(nb.begin(), nb.end());

	for (int i = 0; i < m; i++)
		cout << setw(12) << setfill('0') << nb[i].second << endl;

	return 0;
}

Measured memory_bytes: 3184
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <limits.h>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string>
#include <vector>
#include <cstdio>
#include <iomanip>
#define ll long long
#define rep2(i,a,b) for(int i=a;i<=b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define rep3(i,a,b) for(int i=a;i>=b;i--)
#define REP(e,v) for(auto e:v)
#define queint queue<int>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>()>
#define pb push_back
#define vec vector<int>
#define vecvec vector<vector<int>>
#define vecll vector<ll>
#define vecvecll vector<vector<ll>>
#define bs binary_search
#define All(c) (c).begin(),(c).end()
#define mp make_pair
using namespace std;
int in(){int x;scanf("%d",&x);return x;}
string stin(){string s;cin>>s;return s;}
ll lin(){ll x;scanf("%lld",&x);return x;}
int main(){
    int n=in();
    vec a(n);
    rep(i,n)a[i]=in();
    if(a[0]!=0){
        cout<<-1<<endl;
        return 0;
    }
    int id=n-1,tmp=a[n-1];
    ll cnt=a[n-1];
    while(id>0){
        if(a[--id]==tmp-1){
            tmp--;
            continue;
        }else{
            if(tmp>a[id]+1){
                cout<<-1<<endl;
                return 0;
            }
            cnt+=a[id];
            tmp=a[id];
        }
    }
    cout<<cnt<<endl;
}

Measured memory_bytes: 1024
import java.io.*;
import java.util.*;

public class Main {
	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		Scanner sc=new Scanner(System.in);
		Stack<Integer>s1=new Stack<Integer>();
		Stack<Integer>s2=new Stack<Integer>();
		int time=sc.nextInt();
		int a[]=new int[10];
		while(time-->0) {
			s1.clear();
			s2.clear();
		    for(int i=0;i<10;i++) {
		    	a[i]=sc.nextInt();
		    }
		    s1.add(0);
		    s2.add(0);
		    int flag=0;
		    for(int i=0;i<10;i++) {
		    	if(s1.peek()>=s2.peek()) {
		    		if(s1.peek()<a[i]) {
		    			s1.add(a[i]);
		    		}else if(s2.peek()<a[i]) {
		    			s2.add(a[i]);
		    		}else {
		    			flag=1;
		    			break;
		    		}
		    	}else {
		    		if(s2.peek()<a[i]) {
		    			s2.add(a[i]);
		    		}else if(s1.peek()<a[i]) {
		    			s1.add(a[i]);
		    		}else {
		    			flag=1;
		    			break;
		    		}
		    	}
		    }
		    if(flag==1) {
		    	System.out.println("NO");
		    }else {
		    	System.out.println("YES");
		    }
		}
	}
}



Measured memory_bytes: 26256
#include <stdio.h>

int main()
{
	int a[1000000]={0};
	int i, j, m, ans;
	while(scanf("%d", &m)!=EOF) {
		for(i=0;i<=m;i++)
			a[i]=0;
			ans=0;
			for(i=2;i<=m;i++) {
				if (a[i]==0) {
					ans++;
					for(j=1;i*j<=m;j++) {
						a[i*j]=1;
					}
				}
			}
		printf("%d\n", ans);
		}
	return (0);
}


Measured memory_bytes: 5760
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func Scanner() string {
	sc.Scan()
	return sc.Text()
}

func intScanner() int {
	n, _ := strconv.Atoi(Scanner())
	return n
}

func floatScanner() float64 {
	n, _ := strconv.ParseFloat(Scanner(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func stringSliceScanner(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scanner()
	}
	return a
}
func intSliceScanner(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = intScanner()
	}
	return a
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}

var mod int
var t float64

func main() {
	mod = 1000000007
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	n := intScanner()
	ans := make(map[string]int)
	for i := 0; i < n; i++ {
		ans[Scanner()]++
	}
	fmt.Print("AC x ")
	fmt.Println(ans["AC"])
	fmt.Print("WA x ")
	fmt.Println(ans["WA"])
	fmt.Print("TLE x ")
	fmt.Println(ans["TLE"])
	fmt.Print("RE x ")
	fmt.Println(ans["RE"])
}


Measured memory_bytes: 2080
# coding:utf-8

import sys
import math
import time
#import numpy as np
import collections
from collections import deque
import queue
import copy
import bisect
import heapq


def dfs(s, prev, pre):
  val[s] += Ope[s] + prev
  for i in G[s]:
    if(i == pre):
      continue
    dfs(i, val[s], s)

def bfs(sx, sy, n):
  que = deque([[sy,sx]])
  while que:
    y,x = que.popleft()
    for i,j in D:
      if(x+i<0 or y+j<0 or x+i>W-1 or y+j>H-1):
        continue
      dist = G[y+j][x+i]
      if(G[y+j][x+i] != "X"):
        if(type(G[y+j][x+i]) is str):
          G[y+j][x+i] = G[y][x]+1
          que.append([y+j,x+i])
        elif(dist>G[y][x]+1):
          G[y+j][x+i] = G[y][x]+1
          que.append([y+j,x+i])
        

def combinations_count(n, r):
  return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def ispalindrome(s):
  h = int(math.floor(len(s) / 2))
  #print(s[h+1:], s[:h])
  hh = h+1
  if(len(s)%2==0):
    hh = h
  for a, b in zip(s[hh:], reversed(s[:h])):
    if a != b: return 0
  return 1

#sys.setrecursionlimit(10**7)
#N, Q = map(int, input().split())
#G = [list(input()) for i in range(H)]
#V, E, r = map(int, input().split())
#INF = V * 10001

S = str(input())
ans = "No"
h = int(math.floor(len(S) / 2))

#print(S[5:])

if(ispalindrome(S)==1):
  if(ispalindrome(S[:h])==1):
    ans = "Yes"

print(ans)


Measured memory_bytes: 38636
#include <bits/stdc++.h>
#define itn int
#define REP(i, n) for (ll i = 0; i < n; i++)
#define IREP(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i < b + 1; i++)
#define all(v) v.begin(), v.end()
#define SENTINEL 2000000000
#define NIL -1
using namespace std;
typedef long long ll;

const ll MAX = 510000;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template <class T>inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}

int main()
{
    int l,r,d;
    cin >> l >> r >> d;
    int ans=(r/d)-(l/d);
    if(l%d==0){
        ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3620
using System;

class Program
{
    public static void Main()
    {
        int N = int.Parse(Console.ReadLine());
        String S = Console.ReadLine();

        int count = 0;
        char[] str = S.ToCharArray();
        for (int i = 0; i < N - 1; i++)
        {
            if (str[i] ==str[i + 1])
                count++;
        }

        Console.WriteLine(N - count);
    }
}

Measured memory_bytes: 11488
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0, i##_range = (n); i < i##_range; i++)
#define all(a) a.begin(), a.end()
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; }
using namespace std;

template<typename Monoid>
struct SegmentTree{ //セグメント木
private:
    int sz = 1; vector<Monoid> node;
    using Func = function<Monoid(Monoid, Monoid)>;
    const Func pick; const Monoid init; //モノイドに対する操作と、その単位元
public:
    SegmentTree(vector<Monoid> vec, const Func f, const Monoid m): pick(f), init(m) {
        while(sz < (int)vec.size())sz <<= 1;
        node = vector<Monoid>(sz * 2 - 1, init);
        for(int i = 0; i < (int)vec.size(); i++){
            node[i + sz - 1] = vec[i]; 
        }
        for(int i = sz - 2; i >= 0; i--){
            node[i] = pick(node[i * 2 + 1], node[i * 2 + 2]);
        }
    }
    void initialize(){
        fill(node.begin(), node.end(), init);
    }
    void update(int i, Monoid v){ //単一の要素を変更する
        for(node[(i += sz) - 1] = v; i >>= 1;){
            node[i - 1] = pick(node[i * 2 - 1], node[i * 2]);
        }
    }
    void add(int i, Monoid v){ //単一の要素にある値を加える
        update(i, node[i + sz - 1] + v);
    }
    Monoid get(int l, int r){ //区間取得
        Monoid vl = init, vr = init;
        for((l += sz), (r += sz); l < r; (l >>= 1), (r >>= 1)){
            if(l & 1)vl = pick(vl, node[(l++) - 1]);
            if(r & 1)vr = pick(node[(--r) - 1], vr);
        }
        return pick(vl, vr);
    }
    inline Monoid operator [] (int i){ //[]でアクセス
        return node[i + sz - 1];
    }
};

int main(){

    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N)cin >> A[i];

    vector<int> seg_vec(2 * N + 1, 0);
    auto seg_func = [](int x, int y){ return x + y; };
    SegmentTree<int> seg(seg_vec, seg_func, 0);

    auto check = [&](int x){
        int now = N;
        long long res = 0;
        seg.initialize();
        seg.add(now, 1);
        rep(i, N){
            if(A[i] >= x)now++;
            else now--;
            res += seg.get(0, now + 1);
            seg.add(now, 1);
        }
        return res * 2 >= (long long)N * (N + 1) / 2;
    };

    int lb = 0, ub = 1000000007;
    while(ub - lb > 1){
        int md = (lb + ub) / 2;
        if(check(md))lb = md;
        else ub = md;
    }

    cout << lb << endl;
    return 0;

}

Measured memory_bytes: 4224
import java.util.*;
import java.io.PrintWriter;
import static java.lang.Integer.*;
import static java.lang.Long.*;
import static java.lang.Math.*;
import static java.lang.System.*;

public class Main {
	public static final int AB = 26;
	public static void main(String[] args) {
		long i=0,j=0,k=0;
		Scanner sc = new Scanner(in);
		long n = parseLong(sc.next());
		sc.close();
		long mn = 10;
		for (i = 1; i*i <= n; i++) {
			if(n%i==0) {
				long tmp=(long) Math.max(floor(log10(i)+1),floor(log10(n/i)+1));
				if(tmp<mn)mn=tmp;
			}
		}
		out.println(mn);
	}
}


Measured memory_bytes: 23764
#include <stdio.h>

int main()
{
    int R,G,B,N,i,j,k,m1,m2,m3,n2,n3,time=0;
    scanf("%d",&R);
    scanf("%d",&G);
    scanf("%d",&B);
    scanf("%d",&N);

    if (R<=G && G<=B) {
        m1 = R;
        m2 = G;
        m3 = B;
    }
    if (R<=B && B<=G) {
        m1 = R;
        m2 = B;
        m3 = G;
    }
    if (G<=R && R<=B) {
        m1 = G;
        m2 = R;
        m3 = B;
    }
    if (G<=B && B<=R) {
        m1 = G;
        m2 = B;
        m3 = R;
    }
    if (B<=R && R<=G) {
        m1 = B;
        m2 = R;
        m3 = G;
    }
    if (B<=G && G<=R) {
        m1 = B;
        m2 = G;
        m3 = R;
    }

    n3 = N/m3;
    
    for(i=0;i<=n3;i++){

        n2 = (N-i*m3)/m2;

        for(j=0;j<=n2;j++){

            if((N-i*m3-j*m2)%m1 == 0){
                time++;
            }
        }
    }
    printf("%d",time);
    return 0;
}

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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define ALL(x) x.begin(),x.end()
#define EPS (1e-8)
#define equals(a,b) (fabs((a)-(b))<EPS)

using namespace std;

typedef long long ll;
bool LTE(double a,double b) { return equals(a,b) || a < b; }
bool LT(double a,double b) { return !equals(a,b) && a < b; }

void compute() {

}

int main() {
  int D,N;
  cin >> D >> N;
  if( D == 0 ) {
    if( N < 100 ) {
      cout << N << endl;
    } else {
      puts("101");
    }
    return 0;
  }
  long long v = 1;
  rep(_,D) {
    v *= 100LL;
  }
  int coef = 0;
  rep(_,N) {
    ++coef;
    while( coef % 100 == 0 ) ++coef;
  }
  cout << v * (ll)coef << endl;
  compute();
  return 0;
}


Measured memory_bytes: 256
// By Shreehari Bodas

#include <bits/stdc++.h>

#define PB push_back
#define MP make_pair
#define MT make_tuple

#define forn(i,n) for(int i=0;i<n;i++)
#define forsn(i,s,n) for(int i=s;i<n;i++)
#define rforn(i,n) for(int i=n;i>=0;i--)
#define rforsn(i,s,n) for(int i=n;i>=s;i--)
#define forstl(a,s) for(auto a:s)

using namespace std;

typedef long long LL;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
typedef vector<pii> vpii;

const int MOD=1e9+7;

LL pow(LL a, LL b){
	if(b==0) return 1;
	LL res=pow(a,b/2);
	if(b%2 ==1) return res*res*a;
	else if(b%2 ==0) return res*res;
}

int main(){

	int n; cin>>n;
	set<string> s;
	for(int i=0;i<n;i++){
		string str; cin>>str;
		s.insert(str);
	}

	cout<<s.size()<<endl;

	return 0;
} 

Measured memory_bytes: 19124
#ifdef LOCAL
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cstring>
#else
#include <bits/stdc++.h>
#endif
using namespace std ;

typedef long long ll ;
#define rep(i , n ) for ( int i =0; i < n ; i++)
#define _sort(arg) sort(begin(arg), end(arg))
#define MOD 1000000007
#define pb push_back
#define DEBUG(x) cout << #x << ": " << x << endl;

class UnionFind {
private:
	unsigned size_; 
	std::vector<unsigned> par, rank;
public:
	UnionFind() : size_(0), par(std::vector<unsigned>()), rank(std::vector<unsigned>()) {};
	UnionFind(unsigned size__) : size_(size__) {
		par.resize(size_); rank.resize(size_);
		for (unsigned i = 0; i < size_; i++) par[i] = i, rank[i] = 0;
	}
	unsigned size() { return size_; }
	//unsigned root(unsigned x) { return par[x] == x ? x : par[x] = root(par[x]); }
	unsigned root(unsigned x)
	{
		while(par[x] != x)
		{
			par[x] = par[par[x]];
			x = par[x];
		}
		return x;
	}
	bool same(unsigned x, unsigned y) { return root(x) == root(y); }
	void unite(unsigned x, unsigned y) {
		x = root(x), y = root(y);
		if (x == y) return;
		if (rank[x] < rank[y]) par[x] = y;
		else if (rank[x] == rank[y]) par[y] = x, rank[x]++;
		else par[y] = x;
	}
	bool operator==(const UnionFind &u) { return par == u.par; }
	bool operator!=(const UnionFind &u) { return par != u.par; }
};

ll modpow(ll a, ll b)
{
	if (b == 0)
	{
		return 1;
	}

	if (b % 2)
	{
		return a * modpow(a, b-1) % MOD;
	}
	else
	{
		ll halfB = b / 2;
		ll half = modpow(a, halfB);
		return half * half % MOD;
	}
}

ll calcComb(ll n, ll m)
{
	if (m > n-m)
	{
		return calcComb(n, n-m);
	}

	ll ansMul = 1;
	ll ansDiv = 1;

	rep(i, m)
	{
		ansMul *= (n-i);
		ansDiv *= (i+1);
		ansMul %= MOD;
		ansDiv %= MOD;
	}

	return ansMul * modpow(ansDiv, MOD - 2) % MOD;
}

__attribute__((constructor))
void initial()
{
	cin.tie(NULL);
	ios::sync_with_stdio(false);
}


int main()
{
	int n, m;
	
	cin >> n >> m;

	int p[n];

	rep(i, n)
	{
		cin >> p[i];
	}

	UnionFind un_tree(n);

	rep(i, m)
	{
		int x, y;
		cin >> x >> y;
		un_tree.unite(x-1, y-1);
	}

	int total = 0;
	rep(i, n)
	{
		if (un_tree.same(i, p[i]-1))
		{
			total++;
		}
		/*
		else
		{
			cout << "root(i) = " << un_tree.root(i) << " root(p[i]) = " << un_tree.root(p[i]) << endl;
		}
		*/
	}

	cout << total << endl;
	
	return 0;
}


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

ll n, a[505000], f[505000], g[505000], T, x;

int main(){
  ios::sync_with_stdio(false);
  cin>>n>>f[0];
  for (int i=1;i<=n;++i){
    cin>>a[i];
    f[i]=min(f[i-1],abs(a[i]-f[i-1]));
  }
  g[n+1]=0;
  for (int i=n;i;--i){
    if (a[i]/2<=g[i+1]) g[i]= g[i+1]+a[i];
    else g[i]= g[i+1];
  }
  for (cin>>T;T--;){
    cin>>x;
    puts(f[x-1]<=g[x+1]? "NO": "YES");
  }
}

Measured memory_bytes: 13824
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <set>
#include <vector>
#include <queue>

using namespace std;

#define ll long long
#define ld long double

constexpr double EPS = 1e-16;

void preambule() {
  cin.tie(0);
  cout.precision(16);
  cout << fixed;
}

char b;

void input() {
  cin >> b;
}

void solve1() {
  map<char, char> a = {
      {'A', 'T'},
      {'T', 'A'},
      {'C', 'G'},
      {'G', 'C'}
  };

  cout << a[b];
}

int main() {
#ifdef _DEBUG
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  preambule();
  input();
  solve1();
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
int main(void){
  int cost,M,N,cnt,yatta,flg,cnt1;
   
  while(1){
    cnt = yatta = flg = cnt1 = 0;
     
    cin >> cost;
    if( cost == 0 ) break;
 
    while(1){
 
    
      if( cnt1 == 12 ) break;
 
      cin >> M >> N;
 
      if( flg == 0 ){
      yatta += (M - N);
      if( cost <= yatta ) flg = 1;
      cnt++;
      }
      cnt1++;
    }
 
    if( cost <= yatta ) cout << cnt << endl;
    else cout << "NA" << endl;
  }
  return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef pair<ii, int> ri3;
#define mp make_pair
#define pb push_back
#define fi first
#define sc second
#define SZ(x) (int)(x).size()
#define ALL(x) begin(x), end(x) 
#define REP(i, n) for (int i = 0; i < n; ++i) 
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define RFOR(i, a, b) for (int i = a; i >= b; --i)

const ll is_query = -(1LL<<62);
struct Line {
    ll m, b;
    mutable function<const Line*()> succ;
    bool operator<(const Line& rhs) const {
        if (rhs.b != is_query) return m > rhs.m;
        const Line* s = succ();
        if (!s) return 0;
        ll x = rhs.m;
        return m*x + b > s->m * x + s->b;
    }
};

struct HullDynamic : multiset<Line> { // min hull
    bool bad(iterator y) {
        auto z = next(y);
        if (y == begin()) {
            if (z == end()) return 0;
            return y->m == z->m and y->b > z->b;
        }
        auto x = prev(y);
        if (z == end()) return y->m == x->m and y->b > x->b;
        return (x->b - y->b) * (z->m - y->m) >= (y->b - z->b) * (y->m - x->m);
    }

    void add(ll m, ll b) {
        auto y = insert({m, b});
        y->succ = [=] { return next(y) == end() ? 0 : &*next(y); };
        if (bad(y)) { erase(y); return; }
        while (y != begin() && bad(prev(y))) erase(prev(y));
        while (next(y) != end() && bad(next(y))) erase(next(y));
    }

    ll eval(ll x) {
        auto l = *lower_bound({ x, is_query });
        return l.m*x + l.b;
    }
};

int main() {
    //freopen("in.txt", "r", stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n; ll c; cin >> n >> c;
    int h[n];
    FOR(i,0,n-1){
        cin >> h[i];
    }

    ll dp[n];
    dp[n-1] = 0;
    HullDynamic ch;
    ch.add(-2*h[n-1], dp[n-1] + (ll)h[n-1]*h[n-1]);

    RFOR(i, n-2, 0){
        //dp[i] = min(dp[j] + (h[j] - h[i]) ** 2 + C);
        //dp[i] = min(dp[j] + h[j]*h[j] - 2*h[j]*h[i]) + h[i]*h[i] + C;
        dp[i] = ch.eval(h[i]) + (ll)h[i]*h[i] + c;
        ch.add(-2*h[i], dp[i] + (ll)h[i]*h[i]);
    }

    cout << dp[0] << '\n';
}



Measured memory_bytes: 21376