akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
  // 標準入力高速化のおまじない
  // scanfとの同期を切る。以降紛らわしいのでscanf使用不可。
  ios::sync_with_stdio(false);
  // // cin前の自動flashをやめる
  cin.tie(nullptr);

  int N;
  cin >> N;
  ll result=1;
  for(int i=0; i<N; i++){
    ll x = 0;
    cin >> x;
    if(x == 0){
      cout << 0 << endl;
      return 0;
    }
    if(result != -1 && x <= (ll)pow(10,18) / result){
      result *= x;
    }
    else{
      result =- 1;
    }

  }
  cout << result << endl;
  return 0;
}


Measured memory_bytes: 3620
#include <iostream>
#include <ccomplex>
#include <vector>
#include <cassert>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <numeric>
#include <list>
#include <assert.h>
#include <math.h>
#include <valarray>
#include <stdio.h>
#include <algorithm>
#include <set>
#include <complex>
#include <list>
#include <time.h>
#include <stack>
#include <locale>
#include <clocale>
#include <ctype.h>
#include <wchar.h>

using namespace std;
typedef long long int LL;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;

#define SORT(c) sort((c).begin(),(c).end())
#define BACKSORT(c) sort((c).begin(),(c).end(),std::greater<LL>())
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)


#define ALL(x) (x).begin(),(x).end()

LL mod = 1000000007;

int main() {
	LL N, K;
	cin >> N >> K;
	vector <LL> a(100001);
	vector <LL> ap(100001);
	vector <LL> am(100001);
	a[0] = 0;
	ap[0] = 0;
	am[0] = 0;
	LL min = -100000000000000;
	REP(j, N) {
		LL i = j + 1;
		cin >> a[i];

			if (a[i] >= 0) {
				ap[i] = a[i]+ap[i-1];
				am[i] = am[i - 1];
			}
			else {

				ap[i] =  ap[i - 1];
				am[i] = a[i] + am[i - 1];
			}
			if (i >= K) {
				if (min < -(ap[i] - ap[i - K])) {
					min = -(ap[i] - ap[i - K]);
				}
				if (min < am[i] - am[i - K]) {
					min = am[i] - am[i - K];
				}
			}
	}
	cout << ap[N] + min << endl;



}

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

using namespace std;

typedef long long llint;
typedef pair<llint, llint> P;
const long long INF = 1e18;

int main() {
  llint n, d, a;
  cin >> n >> d >> a;
  vector<P> monster;
  for (int i = 0; i < n; i++) {
    llint x, h;
    cin >> x >> h;
    monster.emplace_back(x, h);
  }
  sort(monster.begin(), monster.end());
  monster.emplace_back(INF, INF);

  vector<int> range(n);
  int r = 0;
  for (int l = 0; l < n; l++) {
    llint xl = monster[l].first;
    llint xr = monster[r].first;
    while (xr - xl <= 2 * d && r < n) {
      r++;
      xr = monster[r].first;
    }
    range[l] = r - 1;
  }

  llint ans = 0;
  vector<llint> sum(n + 2, 0);
  for (int i = 0; i < n; i++) {
    llint h = monster[i].second;
    if (0 < h - sum[i]) {
      h -= sum[i];
      llint cnt = (h + a - 1) / a;
      int j = range[i];
      sum[i] += a * cnt;
      sum[j + 1] -= a * cnt;
      ans += cnt;
    }
    sum[i + 1] += sum[i];
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 6636
#include <stdio.h>
int main(void){
	char chara[1200];//文字列
	int count[26];//文字のカウント配列
	//初期化
	for(int i=0;i<1200;i++)chara[i]=0;
	for (int i = 0; i<26; i++)count[i] = 0;
	//コンソール読み込み
	while(fgets(chara, sizeof(chara), stdin) != NULL){
    	for (int i = 0; i < sizeof(chara);i++) {
    		int ch = chara[i];
    		if (ch < 65 || ch >122)continue;
    		if (ch >= 97 && ch <= 122)ch = ch - 32;//小文字を大文字に
    		count[ch - 65]+=1;
    	}
		for(int i=0;i<1200;i++)chara[i]=0;//初期化
    }
	for (int i = 0; i < sizeof(count) / 4; i++){
		printf("%c : %d\n", 97+i, count[i]);
	}
	return 0;
}

Measured memory_bytes: 944
#include<bits/stdc++.h>
using namespace std;
#define MAXN	105
#define MAXP	405
#define MAXQ	1000005
#define MAXV	10000005
#define INF	1e9
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
struct edge {int dest, flow; unsigned home; };
vector <edge> a[MAXP];
unsigned curr[MAXP];
int s, t, dist[MAXP];
int odd, vodd[MAXN], even, veven[MAXN];
int tot, f[MAXV], prime[MAXV];
bool isprime[MAXV], mark[MAXV];
void addedge(int x, int y, int z) {
	a[x].push_back((edge) {y, z, a[y].size()});
	a[y].push_back((edge) {x, 0, a[x].size() - 1});
}
bool bfs() {
	static int q[MAXP];
	memset(dist, 0, sizeof(dist));
	int l = 0, r = 0;
	q[0] = s; dist[s] = 1;
	while (l <= r) {
		int now = q[l];
		for (unsigned i = 0; i < a[now].size(); i++)
			if (dist[a[now][i].dest] == 0 && a[now][i].flow != 0) {
				dist[a[now][i].dest] = dist[now] + 1;
				q[++r] = a[now][i].dest;
			}
		l++;
	}
	return dist[t] != 0;
}
int dinic(int pos, int limit) {
	if (pos == t) return limit;
	int used = 0, tmp;
	for (unsigned &i = curr[pos]; i < a[pos].size(); i++)
		if (dist[a[pos][i].dest] == dist[pos] + 1 && a[pos][i].flow && (tmp = dinic(a[pos][i].dest, min(limit - used, a[pos][i].flow)))) {
			used += tmp;
			a[pos][i].flow -= tmp;
			a[a[pos][i].dest][a[pos][i].home].flow += tmp;
			if (used == limit) return used;
		}
	return used;
}
int main() {
	int n; read(n);
	for (int i = 1; i <= n; i++) {
		int x; read(x);
		mark[x] ^= true;
		mark[x + 1] ^= true;
	}
	for (int i = 1; i < MAXV; i++)
		if (mark[i]) {
			if (i & 1) vodd[++odd] = i;
			else veven[++even] = i;
		}
	for (int i = 2; i < MAXV; i++) {
		if (f[i] == 0) {
			f[i] = i;
			prime[++tot] = i;
			isprime[i] = true;
		}
		for (int j = 1; j <= tot && prime[j] <= f[i]; j++) {
			int tmp = prime[j] * i;
			if (tmp >= MAXV) break;
			f[tmp] = prime[j];
		}
	}
	s = 0, t = odd + even + 1;
	for (int i = 1; i <= odd; i++)
		addedge(s, i, 1);
	for (int i = 1; i <= even; i++)
		addedge(i + odd, t, 1);
	for (int i = 1; i <= odd; i++)
	for (int j = 1; j <= even; j++)
		if (isprime[abs(vodd[i] - veven[j])]) addedge(i, j + odd, 1);
	int ans = 0;
	while (bfs()) {
		memset(curr, 0, sizeof(curr));
		ans += dinic(s, INF);
	}
	cout << ans + (odd - ans) / 2 * 2 + (even - ans) / 2 * 2 + (odd - ans) % 2 * 3 << endl;
	return 0;
}

Measured memory_bytes: 61312
#include <bits/stdc++.h>
using namespace std;
int main(){
	
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  if(a+b>c+d){
  	cout<<"Left"<<endl;
  	}
  if(a+b==c+d){
  	cout<<"Balanced"<<endl;
         }
  if(a+b<c+d){
         cout<<"Right"<<endl;
}
  }

Measured memory_bytes: 3636
#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() {
  string s;
  cin>>s;
  if(s=="AAA"||s=="BBB"){
    cout<<"No"<<endl;
  }
  else{
    cout<<"Yes"<<endl;
  }
}
  


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

 using namespace std;
 int main() {
   string A, B, C;
   cin >> A >> B >> C;
   if (A.at(A.length() - 1) == B.at(0) && B.at(B.length() - 1) == C.at(0)) cout << "YES" << endl;
   else cout << "NO" << endl;
 }


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
int n,m,C,S,T,p[21],q[21][51],r[21][51];
int G[20][101][101];

void init(){
  for(int i=0;i<20;i++)
    for(int j=0;j<100;j++)
      for(int k=0;k<100;k++)G[i][j][k]=1e9;
}

int calc(int c,int D){
  int res=0;
  for(int i=1;i<p[c]&&D;i++){
    int d=min(D,q[c][i]-q[c][i-1]);
    D-=d;
    res+=d*r[c][i-1];
  }
  if(D) res+=D*r[c][p[c]-1];
  return res;
}

int dijkstra(){
  int D[101];
  for(int i=0;i<101;i++) D[i]=1e9;
  priority_queue<P,vector<P>,greater<P> > Q;
  Q.push(P(0,S));
  D[S]=0;
  while(!Q.empty()){
    P t=Q.top();Q.pop();
    int pos=t.second,cost=t.first;
    if(pos==T)return cost;
    if(D[pos]<cost)continue;
    
    for(int c=0;c<C;c++)
      for(int i=0;i<n;i++){
	if(G[c][pos][i]==1e9)continue;
	int ncost=cost+calc(c,G[c][pos][i]);
	if(D[i]>ncost)D[i]=ncost,Q.push(P(ncost,i));
      }
  }
  return -1;
}

void WF(){

  for(int c=0;c<C;c++)
    for(int k=0;k<n;k++)
      for(int i=0;i<n;i++)
	for(int j=0;j<n;j++)
	  G[c][i][j]=min(G[c][i][j],G[c][i][k]+G[c][k][j]);

}

int main(){
  while(1){
  cin>>n>>m>>C>>S>>T;
  S--,T--;
  if(!n)break;

  init();
  for(int i=0,a,b,d,c;i<m;i++){
    cin>>a>>b>>d>>c; a--,b--,c--;
    G[c][a][b]=G[c][b][a]=min(G[c][a][b],d);
  }

  for(int i=0;i<C;i++) cin>>p[i];
  for(int i=0;i<C;i++){
    for(int j=1;j<p[i];j++)cin>>q[i][j];    
    for(int j=0;j<p[i];j++)cin>>r[i][j];
  }

  WF();
  cout<<dijkstra()<<endl;
  }
  return 0;
}

Measured memory_bytes: 4000
package main

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

type point struct {
	x, y, h int
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	sc.Scan()
	N, _ := strconv.Atoi(sc.Text())

	points := make([]point, N)
	allZero := true
	for i := 0; i < N; i++ {
		sc.Scan()
		x, _ := strconv.Atoi(sc.Text())
		sc.Scan()
		y, _ := strconv.Atoi(sc.Text())
		sc.Scan()
		h, _ := strconv.Atoi(sc.Text())

		if h != 0 {
			allZero = false
		}

		points[i] = point{x, y, h}
	}

	for x := 0; x < 101; x++ {
		for y := 0; y < 101; y++ {
			ok := true
			nowHeight := 0
			if allZero {
				nowHeight = 1
			}

			remainings := make([]int, 0)
			for i, p := range points {
				// 高さが0だとheightを推測出来ない
				if p.h == 0 && nowHeight == 0 {
					remainings = append(remainings, i)
				} else if nowHeight == 0 {
					nowHeight = p.h + abs(p.x-x) + abs(p.y-y)
				} else if (p.h != 0 && nowHeight != p.h+abs(p.x-x)+abs(p.y-y)) ||
					(p.h == 0 && nowHeight > abs(p.x-x)+abs(p.y-y)) {
					ok = false
					break
				}
			}

			for _, i := range remainings {
				p := points[i]
				if p.h == 0 && nowHeight > p.h+abs(p.x-x)+abs(p.y-y) {
					ok = false
				}
			}

			if ok {
				fmt.Printf("%d %d %d\n", x, y, nowHeight)
				return
			}
		}
	}
}

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}


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

int main(){
    string S;
    cin >> S;

    int le = S.length();
    int cou = 0;
    int max = 0;

    for(int i = 0; i <= le; i++){
        if(i == le){
            if(cou >= max){
                max = cou;
                cou = 0;
            }
            break;
        }
        if(S.substr(i,1) == "A" || S.substr(i,1) == "G" ||S.substr(i,1) == "C" ||S.substr(i,1) == "T"){
            cou++;
        }else{
            if(cou >= max){
                max = cou;
                cou = 0;
            }
        }
    }

    cout << max << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <memory.h>

typedef struct _element {
	int index;
	int val;
	char c;
} element;

int is_stable(element lst[], int n) {
	int i;
	element last;

	memcpy((char*)&last, (char*)&lst[0], sizeof(element));
	for(i=1;i<n;i++) {
		if(last.val == lst[i].val) {
			if(last.index > lst[i].index) {
				return 0;
			}
		}
		memcpy((char*)&last, (char*)&lst[i], sizeof(element));
	}
	
	return 1;
}

 
void swap(element A[], int i, int j) {
    element t;
    memcpy((char*)&t, (char*)&A[i], sizeof(t));
    memcpy((char*)&A[i], (char*)&A[j], sizeof(t));
    memcpy((char*)&A[j], (char*)&t, sizeof(t));
}
 
int partition(element A[], int p, int r) {
    int i,j,t;
    element x;
    memcpy((char*)&x, (char*)&A[r], sizeof(x));
    i=p;
    for(j=p;j<r;j++) {
        if(A[j].val <= x.val) {
            swap(A, i, j);
            i++;
        }
    }
     
    swap(A, i, r);
    return i;
}

int quick_sort(element A[], int p, int r, int n) {
	int q;
	if(p < r) {
		q = partition(A, p, r);
        quick_sort(A, p, q-1, n);
        quick_sort(A, q+1, r, n);
	}
	
	return is_stable(A, n);
}

int main(void) {
	int i, val, n;
	int stable;
	element lst[100001];
	element q_lst[100001];

	scanf("%d\n", &n);
	for(i=0;i<n;i++) {
		lst[i].index = i;
		scanf("%c%d ", &(lst[i].c), &(lst[i].val));
	}
	memcpy((char*)q_lst, (char*)lst, sizeof(lst));

	stable = quick_sort(q_lst, 0, n-1, n);
	if(stable == 1) {
		printf("Stable\n");
	} else {
		printf("Not stable\n");
	}
	for(i=0;i<n;i++) {
		printf("%c %d\n", q_lst[i].c, q_lst[i].val);
	}
	
	return 0;
}

Measured memory_bytes: 2968
#define _USE_MATH_DEFINES
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

const int MOD = 1000000007; 
const int INF = 1000000000; //1e9
const int NIL = -1;
const long long LINF = 1000000000000000000; // 1e18
const long double EPS = 1E-10;

template<class T, class S> inline bool chmax(T &a, const S &b){
    if(a < b){
        a = b; return true;
    }
    return false;
}
template<class T, class S> inline bool chmin(T &a, const S &b){
    if(b < a){
        a = b; return true;
    }
    return false;
}






int main(){
    int N, M, X; std::cin >> N >> M >> X;
    std::vector<int> C(N);
    std::vector<std::vector<int>> A(N, std::vector<int>(M));
    for(int i(0); i < N; ++i){
        std::cin >> C[i];
        for(int j(0); j < M; ++j){
            std::cin >> A[i][j];
        }
    }
    int ans(INF), cost(0);
    for(int i(0), i_len(1 << N); i < i_len; ++i){
        cost = 0;
        std::vector<int> undrstnd(M, 0);
        for(int ii(0); ii < N; ++ii){
            if((i >> ii) & 1){
                for(int j(0); j < M; ++j){
                    undrstnd[j] += A[ii][j];
                }
                cost += C[ii];
            }
        }
        bool okay(true);
        for(int j(0); j < M; ++j){
            if(undrstnd[j] < X){
                okay = false;
                break;
            }
        }
        if(okay) chmin(ans, cost);
    }
    std::cout << ((ans != INF) ? ans : -1) << std::endl;
    return 0;
}


Measured memory_bytes: 3636
H,W=map(int,input().split())
field=[list(input()) for _ in range(H)]

l=[[0]*W for _ in range(H)]
r=[[0]*W for _ in range(H)]
u=[[0]*W for _ in range(H)]
d=[[0]*W for _ in range(H)]

for j in range(H):
  for i in range(W):
    if field[j][i]==".":
      if i==0:
        l[j][i]=1
      else:
        l[j][i]=l[j][i-1]+1
      if j==0:
        u[j][i]=1
      else:
        u[j][i]=u[j-1][i]+1
        

for j in reversed(range(H)):
  for i in reversed(range(W)):
    if field[j][i]==".":
      if i==W-1:
        r[j][i]=1
      else:
        r[j][i]=r[j][i+1]+1
      if j==H-1:
        d[j][i]=1
      else:
        d[j][i]=d[j+1][i]+1

A=[]
for j in range(H):
  for i in range(W):
    A.append(l[j][i]+r[j][i]+d[j][i]+u[j][i]-3)

print(max(A))


Measured memory_bytes: 413516
#include <iostream>
#include <vector>
#include <algorithm>

#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

inline int min(int x, int y) {return x < y ? x : y;}
inline long min(long x, long y) {return x < y ? x : y;}
inline int max(int x, int y) {return x > y ? x : y;}
inline long max(long x, long y) {return x > y ? x : y;}

inline void swap(int &a, int &b) {
    int tmp = a;
    a = b;
    b = tmp;
}

inline int euclid(int a, int b) {
    if (a > b) swap(a, b);
    int r = a % b;
    while (r > 0) {
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}

using namespace std;

signed main() {
    int N, M;
    cin >> N >> M;
    vector<int> X(M);
    for (int i = 0; i < M; i++) {
        int x;
        cin >> x;
        X[i] = x;
    }

    sort(X.begin(), X.end());
    int L = X[M - 1] - X[0];
    if (M <= N) {
        cout << 0 << endl;
        return 0;
    }
    if (N == 1) {
        cout << L << endl;
        return 0;
    }

    vector<int> diff(M - 1);
    for (int i = 0; i < M - 1; i++) {
        diff[i] = X[i + 1] - X[i];
    }
    sort(diff.begin(), diff.end(), greater<int>());
    for (int i = 0; i < N - 1; i++) {
        L -= diff[i];
    }

    cout << L << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <bitset>

using namespace std;
using ll = long long int;

int main() {
  ll man = 0;
  ll go = 0;
  ll sen = 0;

  ll N, Y;
  cin >> N >> Y;
  Y /= 1000;

  bool ok = false;
  for (ll i = 0; i <= N; i++)
  {
    for (ll j = 0; j <= N; j++)
    {
      ll k = N - i - j;
      if (k < 0) {
        continue;
      }
      ll sum = i * 10 + 5 * j + k;
      if (sum == Y && (i + j + k) == N) {
        ok = true;
        man = i;
        go = j;
        sen = k;
        break;
      }
    }
  }

  if (ok) {
    cout << man << " " << go << " " << sen << endl;
  } else {
    cout << "-1 -1 -1" << endl;
  }
  
}

Measured memory_bytes: 3632
let f = function
    'I' -> 1
    | 'V' -> 5
    | 'X' -> 10
    | 'L' -> 50
    | 'C' -> 100
    | 'D' -> 500
    | 'M' -> 1000
    | _ -> 0
;;

let get_num s =
    let len = String.length s in
    let rec loop sum prev = function
        i when len = i -> sum
      | i -> let n = f s.[i] in
            if n > prev then
              loop (sum + (f s.[i]) - (2*prev)) n (i+1)
            else
                loop (sum + (f s.[i])) n (i+1)
    in loop 0 0 0
;;

let () =
    let rec read () =
        try let line = read_line () |> String.trim in
            get_num line |> print_int
            ;print_newline ()
            ;read ()
        with End_of_file -> ()
    in read ()
;;

Measured memory_bytes: 2036
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> P;
int main()
{
  int n;
  string s;
  cin >> n >> s;
  vector<int> a(n);
  rep(i, n)
  {
    if (s[i] == 'R')
      a[i] = 0;
    if (s[i] == 'G')
      a[i] = 1;
    if (s[i] == 'B')
      a[i] = 2;
  }
  vector<ll> cnt(3);
  rep(i, n) cnt[a[i]]++;
  ll ans = 1;
  rep(i, 3) ans *= cnt[i];
  rep(j, n) rep(i, j)
  {
    int k = 2*j - i;
    if (k < n)
    {
      if (s.at(i) == s.at(j))
        continue;
      if (s.at(i) == s.at(k))
        continue;
      if (s.at(k) == s.at(j))
        continue;
      ans--;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define LL long long
const LL MOD = 1000000007;
const int SQRT = 66000;
using namespace std;

int N, K;
LL dp[2][SQRT];
map<int, int> pos;
vector<int> ps;

int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	
	cin >> N >> K;
	
	int l = 1;
	ps.push_back(0);
	while (l <= N) {
		ps.push_back(N / (N / l));
		pos[ps.back()] = ps.size() - 1;
		l = N / (N / l) + 1;
	}
	
	for (int i = 1; i < ps.size(); i++) {
		dp[1][i] = ps[i];
	}
	for (int i = 2; i <= K; i++) {
		LL *cur = dp[i % 2], *pre = dp[(i - 1) % 2];
		for (int j = 1; j < ps.size(); j++) {
			cur[j] = ((ps[j] - ps[j - 1]) * pre[pos[N / ps[j]]] + cur[j - 1]) % MOD;
		}
	}
	
	cout << dp[K % 2][ps.size() - 1] << '\n';
}

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

using namespace std;

int main() {
	int n, k;
	scanf("%d%d", &n, &k);
	vector<int> v;
	for (int i = 1; i <= n; ++i) {
		int x;
		scanf("%d", &x);
		v.push_back(x);
	}
	sort(v.begin(), v.end());

	int res = 0;
	for (int i = 0; i < (int)v.size(); ++i) {
		if (i == (int)v.size() - 1) {
			if (k == v[i]) {
				++res;
				break;
			}
			else
				break;
		}
		if (v[i] <= k) {
			k -= v[i];
			++res;
		}
		else {
			printf("%d\n", res);
			return 0;
		}
	}
	printf("%d\n", res);
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
#define res register int
using namespace std;

inline int read()
{
	char ch=getchar();
	int x=0,f=0;
	while(ch<'0'||ch>'9')
	{
		f|=ch=='-';
		ch=getchar();
	}
	while(ch>='0'&&ch<='9')
	{
		x=x*10+ch-'0';
		ch=getchar();
	}
	return f?-x:x;
}
int a[4];
int main()
{
	a[1]=read(),a[2]=read(),a[3]=read();
	if(a[1]%2==0||a[2]%2==0||a[3]%2==0)
	{
		printf("0\n");
		return 0;
	}
	sort(a+1,a+4);
	printf("%lld\n",(long long)a[1]*a[2]);
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>

int main(){
    int n, k;
    std::cin>>n>>k;
    std::vector<int> x(n);
    for(int i = 0;i < n;i++){
        std::cin>>x[i];
    }

    std::transform(x.begin(), x.end(),x.begin(),
            [&k](int x) -> int {
                return std::min(x, k -x) * 2;
            });

    std::cout<<std::accumulate(x.begin(),x.end(), 0)
        <<std::endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define vvi vector<vi>
#define vs vector<string>
#define pb push_back
#define P pair<int,int>
#define vp vector<P>
#define PP pair<P,int>
#define vpp vector<PP>
#define fi first
#define se second
#define INF (1<<30)
#define MOD 1000000007
#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 all(x) (x).begin(),(x).end()
int main(){
    int n,m;
    cin>>n>>m;
    map<int,int> ma;
    REP(i,n){
        int t;
        cin>>t;
        ma[t]++;
    }
    vi vec;
    for(auto itr:ma){
        vec.pb(itr.se);
    }
    sort(all(vec));
    int ans=0;
    REP(i,(int)vec.size()-m){
        ans+=vec[i];
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 10748
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;

template<class T> void read(T &x){
	int f=0; x=0; char ch=getchar();
	for(;!isdigit(ch);ch=getchar()) f|=(ch=='-');
	for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';
	if(f) x=-x;
}

const int N=(1<<18)+5;
int v[N],w[N],a[N],b[N];
int x,y,n,Q,cnt,nA,nB;
vector<pii> AA[N];
pii A[N],B[N];

void dfs(int l,int r,int V,int W,pii A[],int &nA){
	if(l>r){
		A[++nA]=mp(W,V);
		return;
	}
	dfs(l+1,r,V,W,A,nA);
	dfs(l+1,r,V+a[l],W+b[l],A,nA);
}

int main(){
	read(n);
	rep(i,1,n){
		read(v[i]);
		read(w[i]);
	}
	REP(i,min(n+1,1024)){
		int x=i;
		cnt=0;
		for(;x;x>>=1){
			a[++cnt]=v[x];
			b[cnt]=w[x];
		}
		nA=0;
		dfs(1,cnt,0,0,A,nA);
		sort(A+1,A+nA+1);
		AA[i].resize(nA);
		rep(j,1,nA){
			AA[i][j-1]=A[j];
		}
	}
	read(Q);
	rep(i,1,Q){
		read(x);
		read(y);
		cnt=0;
		int z=x;
		for(;x;x>>=1){
			a[++cnt]=v[x];
			b[cnt]=w[x];
		}
		reverse(a+1,a+cnt+1);
		reverse(b+1,b+cnt+1);
		per(t,cnt,cnt/2+1){
			z=z>>1;
		}
		nA=AA[z].size();
		REP(i,nA){
			A[i+1]=AA[z][i];
		}
		nB=0;
		dfs(cnt/2+1,cnt,0,0,B,nB);
		sort(B+1,B+nB+1);
		rep(i,1,nA){
			A[i].se=max(A[i].se,A[i-1].se);
		}
		rep(i,1,nB){
			B[i].se=max(B[i].se,B[i-1].se);
		}
		int p=nA,ans=0;
		rep(i,1,nB){
			while(p&&A[p].fi+B[i].fi>y){
				p--;
			}
			if(A[p].fi+B[i].fi<=y){
				ans=max(ans,A[p].se+B[i].se);
			}
		}
		printf("%d\n",ans);
	}

	return 0;
}

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

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

  if (R < 1200) {
    cout << "ABC" << endl;
  } else if (R < 2800) {
    cout << "ARC" << endl;
  } else {
    cout << "AGC" << endl;
  }
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	static Main instance = new Main();

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		//入力値
		int N = scan.nextInt();

		//WK変数
		String result = "No";

		//演算
		if (N / 100 == 7 || (N / 10) % 10 == 7 || N % 10 == 7) {
			result = "Yes";
		}

		//結果出力
		System.out.println(result);
	}
}

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

int n;

int main(){

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

    cin>>n;
    for(int i=0;i+1<n;i++){
        for(int j=i+1;j<n;j++){
            int k=i^j,cnt=0;
            while(k){
                k>>=1;
                cnt++;
            }
            cout<<cnt<<' ';
        }
        cout<<endl;
    }

    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b;
	cin>>a>>b;
	int sum=0;
	int depth=0;
	int n=1;
	for(int i=1;i<=b-a;i++) sum+=i;
	
	cout<<sum-b<<endl;
	return 0; 
 } 

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


using namespace std;

int main(int argc, const char * argv[]) {
    string s;
    cin >> s;
    if (s.length() == 26) {
        int counter = 25;
        int fl = 0;
        for (int i = 0; i < s.length(); i++) {
            if ((s[i] - 'a') == counter) {
                counter--;
            } else {
                fl = 1;
            }
        }
        if (!fl) {
            cout << -1;
            return 0;
        }
        string s2 = s;
        next_permutation(s.begin(),s.end());
        for(int i = 0; i < s.length(); i++) {
            if (s[i] != s2[i]) {
                for(int j = 0; j < i+1; j++) {
                    cout << s[j];
                }
                return 0;
            }
        }
    }
    if (s.length() < 26) {
        vector<int> chars(26, 0);
        for (int i = 0; i < s.length(); i++) {
            chars[s[i] - 'a']++;
        }
        cout << s;
        for (int i = 0; i < 26; i++) {
            if (chars[i] == 0) {
                cout << char('a' + i);
                return 0;
            }
        }
    }
    return 0;
}

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

int main(){
   int X;
   cin>>X;
   if(X>=400&&X<=599){
       cout<<8<<endl;
   }else if(X>=600&&X<=799){
       cout<<7<<endl;
   }else if(X>=800&&X<=999){
       cout<<6<<endl;
   }else if(X>=1000&&X<=1199){
       cout<<5<<endl;
   }else if(X>=1200&&X<=1399){
       cout<<4<<endl;
   }else if(X>=1400&&X<=1599){
       cout<<3<<endl;
   }else if(X>=1600&&X<=1799){
       cout<<2<<endl;
   }else if(X>=1800&&X<=1999){
    cout<<1<<endl;
   }

}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define rep(i,a,b) for(int i = (a);i <= (b);i++)
#define pii pair<int,int>
#define pll pair<long long, long long>
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const int maxn = 2e5 + 5;
const int maxm = 1e6 + 5;
const double eps = 1e-8;
const double pi = acos(-1.0);
ll gcd(ll a,ll b){return !b?a:gcd(b,a%b);}
ll lcm(ll a,ll b){return a * b / gcd(a,b);}
ll poww(ll x,ll y,ll p){ll ans = 1;while(y){if(y & 1) ans = ans * x % p;x = x * x % p;y >>= 1;}return ans % p;}
bool isp(ll x){if(x < 2) return 0; for(ll i = 2;i * i <= x;i++){if(x % i == 0) return 0;}return 1;}
string s;
int ans;
int main(){
// 	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> s;
	for(int i = 0,j = s.size()-1;i<=j;i++,j--){
		if(s[i] != s[j]) ans++;
	}
	cout << ans << endl;
	return 0;
}
//do smt instead of nothing! never give up!
//take care of long long!
//take care of upper or lower case e.g "yes" or "YES"?
//boundary condition! e.g. n = 0?
//brute force is always the first choice!
// print the ans to look for patterns in the data!

Measured memory_bytes: 256
#include<stdio.h>
int c=0, n,i,j,l,m,r,q,a[1000000],temp[1000000];
void input(){
  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&a[i]);
}
void pri(){
  for(i=0;i<n-1;i++)printf("%d ",a[i]);
  printf("%d\n%d\n",a[n-1],c);
}
void M(int x[],int left,int right){
  int mid,i,j,k;
  if(left>=right)return;
  mid=(left+right)/2;
  M(x, left, mid);
  M(x, mid + 1, right);
  for (i = left; i <= mid; i++) temp[i] = x[i];
  for (i = mid + 1, j = right; i <= right; i++, j--) temp[i] = x[j];
  i = left;
  j = right;
  for (k = left; k <= right; k++){
    if (temp[i] <= temp[j]){
        x[k] = temp[i++];
        c++;
    }else{
        x[k] = temp[j--];
        c++;
    }
  }
}
int main(){
  input();
  M(a,0,n-1);
  pri();
}


Measured memory_bytes: 5632
// -----------------------------------
// author   : MatsuTaku
// country  : Japan
// created  : 07/05/20 20:45:24
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

  int n; cin>>n;
  if (n % 1000 == 0)
    cout << 0 << endl;
  else
    cout << (1000 - (n % 1000)) << endl;

  return 0;
}


Measured memory_bytes: 3656
object Main extends App {
	val temp = scala.io.StdIn.readLine.split(" ").map(_.toInt)
	var result = 0

	def f(x: Int): Int = {
		var temp = x/10
		var z = x%10

		while(temp != 0){
			z = z + temp%10
			temp = temp / 10
		}
		z
	}

	for(i<-1 to temp(0)){
		val t = f(i)
		if(temp(1) <= t && t <= temp(2)) result = result + i
	}

	println(result)
}

Measured memory_bytes: 27212
#include<bits/stdc++.h>
using namespace std;
/*#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
/*template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
*/typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> pl;
typedef pair<int,int> pii;

#define int ll
#define LOCAL 0
#define dbg(x) cout << #x << " is " << x << "\n"
#define gll(x) scanf("%d",&x)
#define gll2(x,y) scanf("%d%d",&x,&y)
#define gll3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define gllarr(arr,n) f(i,n) gll(arr[i]);
#define sz(x) ((int)x.size())
#define s(x) sort(x.begin(),x.end())
#define all(v) v.begin(),v.end()
#define rs(v) { s(v) ; r(v) ; }
#define r(v) {reverse(all(v));}
#define pb push_back
#define f(i,n) for(int i=0;i<n;i++)
#define fr(i,n) for(int i=n-1;i>=0;i--)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)

const ll mod = (ll)1e9 + 7;
const ll inf = (ll)1e16;
const ld eps = 1e-12;
const ll N = (int)1e5 + 5;
const ll LOGN = 19;
const ld PI = 3.14159265358979323846;
inline ll mul(ll a, ll b, ll m = mod) { return (ll)(a * b) % m;}
inline ll add(ll a, ll b, ll m = mod) { a += b; if(a >= m) a -= m; if(a < 0) a += m; return a;}
inline ll power(ll a, ll b, ll m = mod) { if(b == 0) return 1; if(b == 1) return (a % m); ll x = power(a, b / 2, m); x = mul(x, x, m); if(b % 2) x = mul(x, a, m); return x;}

int n, d;
string s;
int dp[10005][105][2];

int rec(int pos, int rem, bool lead) {
	if(pos == n) {
		if(lead) return 0;
		return (rem == 0);
	}
	int &ans = dp[pos][rem][lead];
	if(ans != -1) return ans;
	ans = 0;
	for(int j = 0; j <= 9; j++) {
		int crem = (rem + j) % d;
    	bool clead = false;
    	if(lead && (j == 0)) clead = true;
    	ans = add(ans, rec(pos + 1, crem, clead));
	}
	return ans;
}

int check() {
	int rem = 0;
	for(int i = 0; i < n; i++) {
		rem = (rem + s[i] - '0') % d;
	}
	return (rem == 0);
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    if (LOCAL) {
        freopen("C:\\Users\\Dishant\\Desktop\\Collection-DEV c++\\input.txt", "r", stdin);
        freopen("C:\\Users\\Dishant\\Desktop\\Collection-DEV c++\\output.txt", "w", stdout);
    }
    cin>>s;
    n = sz(s);
    cin>>d;
    memset(dp, -1, sizeof(dp));
    int rem = 0;
    bool lead = true;
    int ans = 0;
    for(int i = 0; i < n; i++) {
    	int curr = s[i] - '0';
    	for(int j = 0; j < curr; j++) {
    		int crem = (rem + j) % d;
    		bool clead = false;
    		if(lead && (j == 0)) clead = true;
    		ans = add(ans, rec(i + 1, crem, clead));
    	}
    	lead = false;
    	rem = (rem + curr) % d;
    }
    cout<<add(ans, check());
    return 0;
}

Measured memory_bytes: 17280
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.InputMismatchException;
import java.util.Set;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static int INF = 1 << 30;
	static long LINF = 1L << 55;
	static int MOD = 1000000007;
	static int[] mh4 = { 0, -1, 1, 0 };
	static int[] mw4 = { -1, 0, 0, 1 };
	static int[] mh8 = { -1, -1, -1, 0, 0, 1, 1, 1 };
	static int[] mw8 = { -1, 0, 1, -1, 1, -1, 0, 1 };

	static class TaskX {

		public void solve(int testNumber, InputReader in, PrintWriter out) {

			char[] s = in.nextString().toCharArray();
			int n = s.length;

			Set<Character> set = new HashSet<>();
			int l = (n-1)/2, r = n/2, ans = n/2;
			while (0 <= l && r < n) {
				set.add(s[l]);
				set.add(s[r]);
				l--; r++;
				if (set.size() >= 2) break;
				ans++;
			}

			out.println(ans);
		}
	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(nextString());
		}

		public long nextLong() {
			return Long.parseLong(nextString());
		}

		public double nextDouble() {
			return Double.parseDouble(nextString());
		}

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public int[] nextIntArrayDec(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt() - 1;
			}
			return res;
		}

		public int[] nextIntArray1Index(int n) {
			int[] res = new int[n + 1];
			for (int i = 0; i < n; i++) {
				res[i + 1] = nextInt();
			}
			return res;
		}

		public long[] nextLongArray(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		}

		public long[] nextLongArrayDec(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong() - 1;
			}
			return res;
		}

		public long[] nextLongArray1Index(int n) {
			long[] res = new long[n + 1];
			for (int i = 0; i < n; i++) {
				res[i + 1] = nextLong();
			}
			return res;
		}

		public double[] nextDoubleArray(int n) {
			double[] res = new double[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextDouble();
			}
			return res;
		}

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}
	}

}


Measured memory_bytes: 25044
// 6/30 解き直し
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;

// 予めアルファベットごとに、sの中での登場indexをメモっておく。
// tを一文字ずつ見ていく。
// int cur_s = 0;
// for i in |t|:
//     sの中のindexを探す。（cur_sの次の）
//     なければ0から探す。
//     それでもなければ-1を返す。

int main() {
    string s, t;
    cin >> s >> t;

    int n = 26;
    vector<int> a[n];
    for (int i = 0; i < s.size(); i++) {
        a[s[i]-'a'].push_back(i);
    }

    // rep(i, 26) {
    //     printf("a")
    // }

    int cur_idx = 0;
    ll res = 0;
    for (int i = 0; i < t.size(); i++) {
        int p = t[i] - 'a';

        // そもそもsにpがない時はお手上げ。
        if (a[p].size()==0) {
            cout << "-1" << endl;
            return 0;
        }

        // cur_idx以降でいつ出てくるか。
        auto itr = lower_bound(a[p].begin(), a[p].end(), cur_idx);

        // if (next == a[p].size()) {
        if (itr == a[p].end()) {
            // もし出てこない場合は、次のところまで増やす。
            res += (s.size() - cur_idx);
            cur_idx = a[p][0] + 1;
            res += cur_idx;
        }
        else {
            // 出てきた場合はそこまで進める。
            res += (*itr - cur_idx + 1);
            cur_idx = *itr + 1;
        }

        // printf("p, next, res = %d, %d, %d\n", p, *itr, res);
    }

    cout << res << endl;
}

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

int main(){
	int k,s;
	cin>>k>>s;
	int count = 0;
	for(int x=0;x<=k;x++){
		for(int y=0;y<=k;y++){
			if(s-(x+y)<=k && s-(x+y) >= 0) count++;
		}
	}
	cout<<count;
}


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

int main() {
    string s, t;
    cin >> s >> t;
    int count = 0;
    for (int i = 0; i < 3; i++)
        if (s[i] == t[i])
            count++;

    cout << count;
    return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10 ** 6)
from functools import reduce
#import math
K = int(input())

def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x % y)

def gcd2(number):
    return reduce(gcd, number)

ans = 0
for i in range(1, K + 1):
    for j in range(1, K + 1):
        for k in range(1, K+1):
            ans += gcd2([i,j,k])
print(ans)

Measured memory_bytes: 79892
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;
#define int long long int
const int INF = 1001001001001001LL;

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

int dp[5010][5];

signed main(){
    
    int n; cin >> n;
    vector<int> p(n);
    for(int i = 0; i < n; i++) cin >> p[i];
    
    for(int i = 0; i < 5010; i++) for(int j = 0; j < 5; j++) dp[i][j] = INF;

    dp[0][0] = 0;

    for(int i = 0; i < n; i++){
        for(int j = 0; j < 5; j++){
            for(int k = j; k <= p[i]; k++){
                int nj = p[i] - k;
                int cost = k;
                if(i != 0) cost *= 2;
                dp[i + 1][nj] = min(dp[i + 1][nj], dp[i][j] + cost);
            }
        }
    }
/*
    for(int i = 0; i <= n; i++){
        for(int j = 0; j < 4; j++){
            cout << dp[i][j] << " ";
        }
        cout << endl;
    }
*/
    
    int ans = INF;
    for(int j = 0; j < 5; j++) ans = min(ans, dp[n][j] + j);
    cout << ans << endl;

    return 0;
}



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

int main() {
int x,y,i;
i=1;
while(i=1){
cin >> x >> y;
if ( x == 0 && y == 0 ) break;
else if ( x > y ) {
cout << y <<" "<< x << endl;
} else {
cout << x <<" "<< y << endl;
}
}

return 0;
}


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

int main(){
  string s;
  cin>>s;
  int n = (int)s.length();
  bool ok = 1;
  for(int i = 0; i < n; i++){
    if(s[i] == 'R' && (i+1)%2 == 0) ok = 0;
    if(s[i] == 'L' && (i+1)%2) ok = 0;
  }
  cout<<(ok?"Yes":"No");
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define intt long long 
using namespace std;
int read(){int k;scanf("%d",&k);return k;}
multiset<intt>S;
multiset<intt>::iterator it,it1;
intt flag=0,ans,n,x;
int main(){	
	n=read();
	for(int i=1;i<=n;i++)x=read(),S.insert(x);
	while(!S.empty()){	
		it=S.end();it--;
		flag=0;
		S.erase(it);
		for(int i=1;i<=31;i++){	
			intt v=(1<<i)-*it;
			it1=S.find(v);
			if(it1==S.end())continue;
			flag=1;
			S.erase(it1);ans++;
		}	
	}		
	cout<<ans<<endl;
	return 0;
}	

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

int G[3][3];
bool T[3][3];

int main() {
  rep(i, 3) rep(j, 3) cin>>G[i][j];
  int n; cin>>n;
  vector<int> b(n);
  rep(i, n) cin>>b[i];

  bool frag=false;
  rep(i, n) {
    rep(j, 3) {
      rep(k, 3) {
        if (b[i]==G[j][k]) T[j][k]=true;
      }
    }
  }
  rep(i, 3) {
    if (T[0][i]&&T[1][i]&&T[2][i]) frag=true;
    if (T[i][0]&&T[i][1]&&T[i][2]) frag=true;
  }
  if (T[0][0]&&T[1][1]&&T[2][2]) frag=true;
  if (T[2][0]&&T[1][1]&&T[0][2]) frag=true;

  if (frag) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


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

typedef long long ll;

typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define ALL(s) (s).begin(),(s).end()
#define ALLn(s,n) s,s+n
#define F first
#define S second
#define pb push_back
#define tc(t) int t; cin >> t; while(t--)
#define _ ios_base::sync_with_stdio(false); cin.tie(NULL);

const ll MOD = 1e9 + 7;
const ll MAXN = 1e6 + 7;

void solve() {
	int n;
	cin >> n;
	map<string, int> m;
	int cnt = 0;
	
	F0R(i, n) {
		string s;
		cin >> s;
		m[s]++;
	}

	for(auto x:m) cnt++;
	cout << cnt << "\n";
}

int32_t main() {_
	//tc(t)
		solve();
}



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

using namespace std;
bool IsPrime[60000];
vector<int> Prime;

void PrimeCalc()
{
	for(int i = 0; i < 60000; ++i)
	{
		IsPrime[i] = true;
	}
	IsPrime[0] = IsPrime[1] = false;
	for(int i = 2; i < 60000; ++i)
	{
		if(IsPrime[i])
		{
			Prime.push_back(i);
			for(int j = 2 * i; j < 60000; j += i)
			{
				IsPrime[j] = false;
			}
		}
	}
}

void solve()
{
	PrimeCalc();
	int n;
	while(~scanf("%d", &n))
	{
		int count = 0;
		while(n > Prime[count])
		{
			++count;
		}
		cout << Prime[count - 1] << " ";
		if(IsPrime[n])
		{
			++count;
		}
		cout << Prime[count] << endl;
	}
}

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

Measured memory_bytes: 0
#include<iostream>
#include<string>
using namespace std;
#define ll long long
#define MAX 100001
#define MAXN 1000000007
#define pb push_back
#define f first
#define s second

int main()
{
    string s; cin>>s;
    // cout<<s;
    int sum=0;
    for(int i=0; i<s.length(); i++)
    {
        int k = s[i] - '0';
        sum+=k;
    }
    if(sum%9)   cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
}

Measured memory_bytes: 3692
#include <stdio.h>

#define MAX 100
#define INF 1000000
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n, G[MAX][MAX];

void dij() {
	int i, u, v, min, d[MAX], color[MAX];

	for (i = 0; i < n; i++) {
		d[i] = INF;
		color[i] = WHITE;
	}

	d[0] = 0;
	color[0] = GRAY;

	while (1) {
		min = INF;
		u = -1;
		for (i = 0; i < n; i++) {
			if (min > d[i] && color[i] != BLACK) {
				u = i;
				min = d[i];
			}
		}
		if (u == -1) break;
		color[u] = BLACK;
		for (v = 0; v < n; v++) {
			if (color[v] != BLACK && G[u][v] != INF) {
				if (d[v] > d[u] + G[u][v]) {
					d[v] = d[u] + G[u][v];
					color[v] = GRAY;
				}
			}
		}
	}

	for (i = 0; i < n; i++) {
		printf("%d ",i);
		if (d[i] == INF) printf("-1\n");
		else printf("%d\n",d[i]);
	}
}

int main() {
	int i, j,u,k,v,c;

	scanf("%d", &n);

	for (i = 0; i < n; i++) {
		for (j = 0; j < n; j++) {
			G[i][j] = INF;
		}
	}

	for (i = 0; i < n; i++) {
		scanf("%d%d", &u, &k);
		for (j = 0; j < k; j++) {
			scanf("%d%d", &v, &c);
			G[u][v] = c;
		}
	}

	dij();

	return 0;

}



Measured memory_bytes: 2056
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
using namespace std;
int main(){
  int kazu = 0;
  cin >> kazu;
  vector<int> iti(kazu);
  long long hei = 0;
  for(int i = 0;i <= kazu - 1;i++){
    cin >> iti[i];
  }
  long long kotae = 10000000000;
  long long ko = 0;
  for(int i = 1;i <= 100;i++){
    for(int j = 0;j <= kazu - 1;j++){
      ko = ko + ( (i - iti[j]) * (i - iti[j]) );
    }
    //cout << ko << endl;
    if(kotae >= ko){
      kotae = ko;
    }
    ko = 0;
  }
  cout << kotae << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
  private static final int mod = 1_000_000_007;
  private static void solve(int n, int m, int[] a) {
    int brokenIndex = 0;
    int[] steps = new int[n + 1];
    steps[0] = 1;
    if (brokenIndex < m && a[brokenIndex] == 1) {
      brokenIndex++;
    } else {
      steps[1] = 1;
    }
    for (int i = 2; i <= n; i++) {
      if (brokenIndex < m && a[brokenIndex] == i) {
        steps[i] = 0;
        brokenIndex++;
      } else {
        steps[i] = steps[i - 1] + steps[i - 2];
        if (steps[i] >= mod) steps[i] -= mod;
      }
    }
    System.out.println(steps[n]);
  }
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String[] nums = sc.nextLine().split(" ");
    int n = Integer.parseInt(nums[0]);
    int m = Integer.parseInt(nums[1]);
    int[] a = new int[m];
    for (int i = 0; i < m; i++) a[i] = Integer.parseInt(sc.nextLine());
    sc.close();
    solve(n, m, a);
  }
}

Measured memory_bytes: 91604
#include <stdio.h>

int main(void){
  int n, k, x, y;
  int sum = 0;
  scanf("%d", &n);
  scanf("%d", &k);
  scanf("%d", &x);
  scanf("%d", &y);
  if(n >= k){
    for(int i = 0; i < k; i++){
      sum += x;
    }
    for(int i = k; i < n; i++){
      sum += y;
    }
  }else{
    for(int i = 0; i < n; i++){
      sum += x;
    }
  }

  printf("%d\n", sum);
  return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<math.h>

int main()
{
	double v;
	
	while( std::cin >> v ){
		int n = 1;
		while( sqrt( ( n * 5 - 5 ) / 4.9 ) * 9.8 < v )n++;
		std::cout << n << std::endl;
	}

 	return 0;
}

Measured memory_bytes: 1224
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        long n = sc.NextLong();
        long a = sc.NextLong();
        long b = sc.NextLong();

        long[] x = sc.LongArray();

        long answer = 0;

        for (int i = 1; i < n; i++)
        {
            answer += Math.Min(a * (x[i] - x[i - 1]), b);
        }

        Console.WriteLine(answer);
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}


Measured memory_bytes: 38608
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
using namespace std;
int vis[100005];
int x[100005];
int main(){
    int n;
    while(~scanf("%d",&n)){
        memset(vis,0,sizeof(vis));
        int i,k;
        for(i=1;i<=n;i++){
            scanf("%d",&x[i]);
            if(x[i]==i)
                vis[i]=1;
        }
        int ans=0;
        for(i=1;i<=n;i++){
            if(vis[i]&&vis[i+1]){
                ans++;
                i++;
            }
            else if(vis[i]){
                for(k=i+1;k<=n;k++){
                    if(x[i]!=k)
                        break;
                }
                //printf("%d++%d\n",i,k);
                ans+=(k-i);
                i+=(k-i);
            }
        }
        printf("%d\n",ans);
    }
return 0;}


Measured memory_bytes: 1024
#include <stdio.h>

int n, m;
char change[112345678][2], data[112345678];
int main(void) {
	while (true) {
		scanf("%d", &n);
		if (n == 0) { break; }
		for (int i = 0; i < n; ++i) { scanf("%s%s", &change[i][0], &change[i][1]); }
		scanf("%d", &m);
		for (int i = 0; i < m; ++i) { scanf("%s", &data[i]); }

		for (int i = 0; i < m; ++i) {
			for (int j = 0; j < n; ++j) {
				if (data[i] == change[j][0]) {
					data[i] = change[j][1];
					break;
				}
			}
		}

		printf("%s\n", data);
	}
	return 0;
}

Measured memory_bytes: 2640