akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) begin(x),end(x)
typedef long long ll;
int OO = 0x3f3f3f3f;

int n;
int arr[100005];
int mem[100005];

int solve(int x)
{
    int op1, op2;
    if(x == n-1)
        return 0;

    if(mem[x] != -1)
        return mem[x];

    op1 = solve(x+1) + abs(arr[x]-arr[x+1]);
    op2 = OO;

    if(x+3 <= n)
        op2 = solve(x+2) + abs(arr[x]-arr[x+2]);

    return mem[x] = min(op1, op2);
}

int main()
{
    cin >> n;
    memset(mem, -1, sizeof mem);
    for(int i = 0; i< n; i++)
    {
        cin >> arr[i];
    }
    cout << solve(0) << endl;
    return 0;
}


Measured memory_bytes: 4096
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <random>
#include <chrono>
#include <tuple>
#include <random>

using namespace std;

typedef long long ll;
typedef long double ld;
#define fastInp cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);

const ll SIZE = 1e6 * 2 + 10, INF = 1e9 * 1e9 + 10;



int main()
{
	fastInp;

	ll h, w, a, b;
	cin >> h >> w >> a >> b;

	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if ((j < a && i < b) || (j >= a && b <= i)) {
				cout << "1";
			} else {
				cout << "0";
			}
			
		}
		cout << "\n";
	}
	return 0;
}

Measured memory_bytes: 3668
#include <stdio.h>
#include <stdlib.h>

int main(void)
{
	unsigned long n;
	unsigned m, a[10010], s = 0;
	int i, b;
	
	scanf("%ld%d", &n, &m);
	for (i = 1; i <= m; ++i) {
		scanf("%d", &a[i]);
		s += a[i];
	}
	b = n - s;
	if (b >= 0)
		printf("%d", b);
	else
		printf("%d", -1);
	return EXIT_SUCCESS;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  
  sort(A.begin(), A.end());
  reverse(A.begin(), A.end());

  int Alice = 0, Bob = 0;
  for (int i = 0; i < N; i++) {
    if (i % 2 == 0) Alice += A.at(i);
    else Bob += A.at(i);
  }

  cout << Alice - Bob << endl;
}


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

int main(){
    ll N;
    cin >> N;
    vector<ll> A(N);
    rep(i, 0, N) cin >> A[i];
    sort(A.begin(), A.end(), greater<ll>());

    ll c = 0, i = 0;
    ll l1 = 0, l2 = 0;
    while(i < N-1){
        if(A[i] == A[i+1]){
            if(c == 0){
                l1 = A[i];
                c++;
            }else if(c == 1){
                l2 = A[i];
                c++;
            }
            i++;
        }
        i++;
    }
    cout << l1*l2 << endl; 
    return 0;
}

Measured memory_bytes: 1024
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}

int main(){
  int N, rate, rateType;
  cin >> N;
  vector<int> rateCnt(9,0);
  for(int i = 0; i < N; i++){
    cin >> rate;

    rateType = rate / 400;
    if(rateType >= 8) rateCnt[8]++;
    else rateCnt[rateType] ++;
    // if(rate <= 399) rateCnt[0]++;
    // else if(rate <= 799) rateCnt[1]++;
    // else if(rate <= 1199) rateCnt[2]++;
    // else if(rate <= 1599) rateCnt[3]++;
    // else if(rate <= 1999) rateCnt[4]++;
    // else if(rate <= 2399) rateCnt[5]++;
    // else if(rate <= 2799) rateCnt[6]++;
    // else if(rate <= 3199) rateCnt[7]++;
    // else rateCnt[8]++;
  }
  int minTypes = 0, maxTypes = 0;
  for(int i = 0; i < 8; i++){
    if(rateCnt[i] > 0){
      minTypes ++;
      maxTypes ++;
    }
  }
  if(minTypes == 0 && rateCnt[8] > 0) minTypes++;
  maxTypes += rateCnt[8];
  cout << minTypes << ' '<< maxTypes << endl;
  return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UncheckedIOException;
import java.util.StringTokenizer;
class Main{
	static String s;
	static int N,Q;
	static int[][] move;
	static int[] place;
	public static void main(String[] args) {
		SC sc=new SC(System.in);
		N=sc.nextInt();
		Q=sc.nextInt();
		s=sc.next();
		move=new int[Q][2];
		place=new int[N];
		for(int i=0; i<N; i++) {
			place[i]=s.charAt(i)-'A';
		}
		for(int i=0; i<Q; i++) {
			move[i][0]=((sc.next()).charAt(0))-'A';
			move[i][1]=0;
			String tmp=sc.next();
			if(tmp.charAt(0)=='L') {
				move[i][1]=-1;
			}
			else if(tmp.charAt(0)=='R') {
				move[i][1]=1;
			}
		}
		int MIGI=0;
		int HIDARI=0;
		int min=0;
		int max=N;
		while(max-min>1) {	//二分探索でどこまで落ちるかを考える	→
			int mid=(max+min)/2;
			boolean totatu=migi(mid);
			if(totatu) {
				max=mid;
			}
			else {
				min=mid;
			}
		}
		boolean minok=migi(min);
		boolean maxok=migi(max);
		if(minok) {
			MIGI=min;
		}
		else if(maxok) {
			MIGI=max;
		}
		else {
			MIGI=-1;
		}

		min=0;
		max=N;
		while(max-min>1) {
			int mid=(max+min)/2;
			boolean totatu=hidari(mid);
			if(totatu) {
				min=mid;
			}
			else {
				max=mid;
			}
		}
		minok=hidari(min);
		maxok=hidari(max);
		if(maxok) {
			HIDARI=max;
		}
		else if(minok) {
			HIDARI=min;
		}
		else {
			HIDARI=-1;
		}
		int ans=N;
		if(MIGI>=0) {
			ans-=(N-MIGI);
		}
		if(HIDARI>=0) {
			ans-=(HIDARI+1);
		}
		pl(ans);
	}
	static boolean migi(int mid) {
		int now=mid;
		if(mid==N) {
			return true;
		}
		else {
			for(int i=0; i<Q; i++) {
				if(move[i][0]==place[now]) {
					if(move[i][1]==1) {
						now++;
					}
					else if(move[i][1]==-1) {
						now--;
					}
				}
				if(now==N) {
					return true;
				}
				else if(now<0) {
					return false;
				}
			}
			return false;
		}
	}

	static boolean hidari(int mid) {
		int now=mid;
		if(mid==N) {
			return false;
		}
		else {
			for(int i=0; i<Q; i++) {
				if(move[i][0]==place[now]) {
					if(move[i][1]==1) {
						now++;
					}
					else if(move[i][1]==-1) {
						now--;
					}
				}
				if(now<0) {
					return true;
				}
				else if(now>=N) {
					return false;
				}
			}
			return false;
		}
	}
	static class SC {
		private BufferedReader reader = null;
		private StringTokenizer tokenizer = null;
		public SC(InputStream in) {
			reader = new BufferedReader(new InputStreamReader(in));
		}
		public String next() {
			if (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
	}
	public static void pl(Object o) {
		System.out.println(o);
	}
	public static void pl() {
		System.out.println();
	}
	public static void p(Object o) {
		System.out.print(o);
	}
}

Measured memory_bytes: 56984
#include <iostream>
#include <queue>
#include <algorithm>
 
using namespace std;
 
#define MAX 120
#define INF 1e9
 
int H, W;
char field[MAX][MAX];
const int dx[] = {-1,0,0,1};
const int dy[] = {0,-1,1,0};
 
bool inField(int y, int x){
  return 0 <= y && y < H && 0 <= x && x < W;
}
 
bool check(int y, int x){
  if(y == 0 || y == H-1) return true;
  if(x == 0 || x == W-1) return true;
  return false;
}
 
void bfs(int y, int x){
  int ans = INF;
  int cost[MAX][MAX];
  fill(cost[0], cost[MAX], INF);
  queue<int> nowx, nowy;
  nowx.push(x); nowy.push(y); 
  cost[y][x] = 0;
 
  while(!nowx.empty()){
    int xx = nowx.front(); nowx.pop();
    int yy = nowy.front(); nowy.pop();
    int cnt = cost[yy][xx];
 
    for(int i = 0 ; i < 4 ; i++){
      int nx = xx + dx[i];
      int ny = yy + dy[i];
 
      if(!inField(ny, nx)) continue;
      if(check(ny, nx)){
        if(field[yy][xx] != '#' && field[ny][nx] == '#'){
          cost[ny][nx] = min(cost[ny][nx], cnt+1);
        }else{
          cost[ny][nx] = min(cost[ny][nx], cnt);
        }
        continue;
      }
      int ncnt = cnt;
      if(field[yy][xx] != '#' && field[ny][nx] == '#') ncnt++;
      if(ncnt < cost[ny][nx]){
        cost[ny][nx] = ncnt;
        nowx.push(nx); nowy.push(ny);
      }
    }
  }
  for(int i = 0 ; i < H ; i++){
    ans = min(ans, cost[i][0]);
    ans = min(ans, cost[i][W-1]);
  }
  for(int i = 0 ; i < W ; i++){
    ans = min(ans, cost[0][i]);
    ans = min(ans, cost[H-1][i]);
  }
 
  cout << ans << endl;
}
 
int main(){
  int sx, sy;
  while(cin >> W >> H, (W | H)){
    for(int i = 0 ; i < H ; i++){
      for(int j = 0 ; j < W ; j++){
        cin >> field[i][j];
        if(field[i][j] == '&'){
          sx = j; sy = i;
        }
      }
    }  
    bfs(sy, sx);
  }
 
  return 0;
}

Measured memory_bytes: 3156
N = int(input())

C=[[0]*10 for _ in range(10)]

for n in range(1,N+1):
    n=str(n)
    n_s=int(n[0])
    n_e=int(n[-1])
    
    C[n_s][n_e]+=1
    
ans=0
for c_1 in range(10):
    for c_2 in range(10):
        ans += C[c_1][c_2]*C[c_2][c_1]
        
print(ans)

Measured memory_bytes: 73452
#include <bits/stdc++.h> 
#define rep(a,b) for(int i = a;i < b; i++)
using namespace std;

int ja_foi[1123456];

int main() {
	int x, indc = 1;
	long long resto = 7;
	
	scanf("%d", &x);

	if (x%2==0) {
		puts("-1");
	}else{
		while(1) {
			if (resto%x == 0){
				break;
			}

			if (ja_foi[resto]) {
				indc = -1;
				break;
			}else{
				ja_foi[resto] = 1;
			}

			resto = ((resto*10)+7)%x;
			// printf("%lld\n", resto);
			indc++;
		}
		printf("%d\n", indc);
	}
	

	return 0;
}

Measured memory_bytes: 7612
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 100000000
#define INF 300000000000000000
#define MOD 1000000007
#define mod 1000000007
#define INT_MAX_ 2147483647
#define REP(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define REPE(i, a, n) for (ll i = a; i <= (ll)(n); i++)
#define rep(i,n)for (ll i = 0; i < (ll)(n); i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
#define me memset
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<int,int>Pin;
typedef pair<ll,ll>Pll;
template<class T> using V=vector<T>;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
long long GCD(long long a, long long b) {return b?GCD(b,a%b):a;}
long long LCM(long long a, long long b) {return a/GCD(a,b)*b;}
int dx[5]={-1,0,1,0,0};
int dy[5]={0,-1,0,1,0};
int ddx[8]={-1,0,1,0,1,1,-1,-1};
int ddy[8]={0,-1,0,1,1,-1,1,-1};
ll cmp1(pair<ll,ll>a,pair<ll,ll> b){
        if(a.se!=b.se)
        return a.se<b.se;
        else
        return a.fi<b.fi;
}
//----------------------------------------------------------------------
ll a[110];
//----------------------------------------------------------------------
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------  
    //ll begin_time=clock();
    //-------------------------------
    int n,k;cin>>n>>k;
    for(ll i=0;i<k;i++){
        int d;cin>>d;
        for(ll j=0;j<d;j++){
            int aa;cin>>aa;
            a[aa]++;
        }
    }
    int ans=0;
    for(int i=1;i<=n;i++){
        if(a[i]==0)ans++;
    }
    cout<<ans<<endl;
    //-------------------------------  
    //ll end_time=clock();cout<<"time="<<end_time-begin_time<<"ms"<<endl;
    //-------------------------------
    return 0;
}
//----------------------------------------------------------------------





































Measured memory_bytes: 3644
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <ctype.h>
#include <map>
#include <vector>
#include <stdlib.h>
#include <cctype>
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define REP1(j,n) for(int j=0;j<(int)n;++j)
#define REPD(i,n) for(int i=n;i>=0;--i)
#define REPD1(j,n) for(int j=n;j=>0;--j)
#define REPS(i,n) for(int i=1;i<=(int)n;++i)
#define REPS1(j,n) for(int j=1;j<=(int)n;++j)
#define rep(i,a,n) for(int i=a;i<=(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define DescSort(a) sort(a.begin(),a.end(),std::greater<int>())

using namespace std;
typedef long long ll;

int main(void) {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	int ans1 = min(b, d), ans2 = max(a, c);
	if (ans1 >= ans2)
		cout << min(b, d) - max(a, c) << endl;
	else
		cout << "0" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int n;
  cin >> n;
  int ans = 0;
  for(int i=1;i<=n;i+=2) {
    int cnt = 0;
    for(int j=1;j<=i;j++) {
      if(i%j == 0) cnt++;
    }
    if(cnt == 8) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#define ffor(_a,_f,_t) for(int _a=(_f),__t=(_t);_a<__t;_a++)
#define all(_v) (_v).begin() , (_v).end()
#define sz size()
#define pb push_back
#define SET(__set, val) memset(__set, val, sizeof(__set))
#define FOR(__i, __n) ffor (__i, 0, __n)
typedef long long LL;

using namespace std;

vector<LL> A, B;

int main() {
	int N;
	cin >> N;
	LL x, y;
	LL ret = 0LL;
	bool theSame = true;
	LL m = 0LL;
	FOR (i, N) {
		cin >> x >> y;
		if (x != y)
			theSame = false;
		ret += x + y;
		if (x > y) {
			if (m == 0 || y < m)
				m = y;
		}
	}
	if (theSame) {
		cout << 0 << endl;
		return 0;
	}
	ret -= 2 * m;
	ret /= 2;
	cout << ret << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
	int a[3][3], c[3][3]={0};
	for(int i=0;i<3;i++){
		for(int j=0;j<3;j++){
			scanf("%d", &a[i][j]);
		}
	}
	int N;
	scanf("%d", &N);
	int b[N];
	for(int i=0;i<N;i++){
		scanf("%d", &b[i]);
	}
	for(int k=0;k<N;k++){
		for(int i=0;i<3;i++){
			for(int j=0;j<3;j++){
				if(a[i][j] == b[k]){
					c[i][j]++;	
				}
			}
		}
	}
	for(int i=0; i<N; i++){
		if(c[i][0]+c[i][1]+c[i][2] == 3){
			printf("Yes\n");
			return 0;
		}
		if(c[0][i]+c[1][i]+c[2][i] == 3){
			printf("Yes\n");
			return 0;
		}
	}
	if(c[0][0]+c[1][1]+c[2][2] == 3){
		printf("Yes\n");
		return 0;
	}
	if(c[2][0]+c[1][1]+c[0][2] == 3){
		printf("Yes\n");
		return 0;
	}
	printf("No\n");
	return 0;
}

Measured memory_bytes: 3140
#!/usr/bin/python3

from decimal import *

#標準出力からの読み込み
input_1 = input()
a = Decimal(input_1.split(" ")[0])
b = Decimal(input_1.split(" ")[1])

if (a == 0) or (b == 0):
    output = 0
else:
    s = str(a*b)
    try:
        output = s[:s.index('.')]
    except:
        output = s

print(output)


Measured memory_bytes: 9936
H,W=map(int,input().split())
a=[list(input()) for i in range(H)]
b=[["." for i in range(W)] for i in range(H)]
c=[["." for i in range(W)] for i in range(H)]
for i in range(H):
    c[i][0]="#"
    b[i][-1]="#"
for i in range(H):
    for j in range(W):
        if i%2==0:
            b[i][j]="#"
        else:
            c[i][j]="#"
for i in range(H):
    c[i][-1]="."
    b[i][0]="."
for i in range(H):
    for j in range(W):
        if a[i][j]=="#":
            b[i][j]="#"
            c[i][j]="#"

for i in b:
    print("".join(i))
print()
for i in c:
    print("".join(i))


Measured memory_bytes: 10100
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
char s[114514];
int x,y,n;
int main(){
	scanf("%s",s+1);
	x=y=n=strlen(s+1);
	for(int i=1;i<=n;++i)if(s[i]=='1')x=min(x,max(i-1,n-i));else
	y=min(y,max(i-1,n-i));
	printf("%d",max(x,y));
	return 0;
}

Measured memory_bytes: 1788
import numpy as np
from collections import Counter
n = int(input())
As = input().split()
As = [int(A) for A in As]

A_odd = As[::2]         #奇数列
A_even = As[1:][::2]    #偶数列

# 最頻の要素を並べる
odd_pair = Counter(A_odd).most_common(2)
even_pair = Counter(A_even).most_common(2)

if odd_pair[0][0] != even_pair[0][0]:               # TOPの数字が違う
    N = n-odd_pair[0][1]-even_pair[0][1]
else:                                               # TOPの数字が一緒
    if len(odd_pair) == 1 and len(even_pair) == 1:  # 文字列がそもそも1種類
        N = n/2
    elif len(odd_pair) == 1:                        # oddが1種類
        N = n-even_pair[1][1]
    elif len(even_pair) == 1:                       # evenが1種類
        N = n-odd_pair[1][1] 
    elif odd_pair[1][1] > even_pair[1][1]:          # oddの2番目のが多い
        N = n-even_pair[0][1]-odd_pair[1][1]
    else:
        N = n-odd_pair[0][1]-even_pair[1][1]        # oddの1番目のが多い
print(int(N))

Measured memory_bytes: 32900
// AOJ ALDS1_4_C Dictionary
// 2018.4.27 bal4u

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

// 数値のハッシュ関数
#define HASHSIZ 1500007
int hash[HASHSIZ+3], *hashend = hash+HASHSIZ;

int lookup(int n)
{
	int *p;
	
	n++; p = hash + n % HASHSIZ;
	while (*p) {
		if (*p == n) return 1;
		if (++p == hashend) p = hash;
	}
	return 0;
}

void insert(int n)
{
	int *p;
	
	n++; p = hash + n % HASHSIZ;
	while (*p) {
		if (*p == n) return;
		if (++p == hashend) p = hash;
	}
	*p = n;
}

char tr['T'+1];
char buf[20], *p;

int trans(char *p)
{
	int k, w;

	w = k = 0; while (*p >= ' ') {
		k = (k<<2) | tr[*p++], w++;
	}
	return k | (w<<24);
}

int main()
{
	int n;

	tr['A'] = 0, tr['C'] = 1, tr['G'] = 2, tr['T'] = 3;
	fgets(buf, 10, stdin), n = atoi(buf);
	while (n--) {
		fgets(p=buf, 20, stdin);
		if (*p == 'i') insert(trans(p+7));
		else puts(lookup(trans(p+5))? "yes": "no");
	}
	return 0;
}



Measured memory_bytes: 6692
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int main(){
	string S;
	int ans;
	ll K,counter = 0;
	cin >> S >> K;
	for (int i = 0;i< S.size();i++){
		if (S[i] == '1'){
			counter++;
		}
		else{
			ans = i;
			break;
		}
	}
	if (K <= counter){
		ans = 0;
	}
	cout << S[ans] << endl;
	return 0;
}

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

int main()
{
	int k, a, b;
	cin >> k >> a >> b;

	for (int i = a; i <= b; i++)
	{
		if (i % k == 0)
		{
			cout << "OK" << endl;
			return 0;
		}
	}

	cout << "NG" << endl;

	return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <algorithm>

int calc(char op, std::vector<int> xs) {

	switch (op) {
	case '+': {
		int v = xs.at(0);
		for (int i = 1; i < xs.size(); i++) {
			v += xs.at(i);
		}
		return v;
	}
	case '*': {
		int v = xs.at(0);
		for (int i = 1; i < xs.size(); i++) {
			v *= xs.at(i);
		}
		return v;
	}
	}

	return xs.at(0);
}

int main() {
	while (true)
	{
		int n;
		std::cin >> n;

		if (n == 0) {
			break;
		}


		int depth = -1;

		std::stack<char> ops;
		ops.push(0);
		std::stack<std::vector<int>> vstack;

		std::vector<int> vs;

		for (int i = 0; i < n; i++) {
			std::string s;
			std::cin >> s;
			
			int d = std::count(s.begin(), s.end(), '.');
			s = s.substr(d);

			if (d < depth) {
				for (; depth != d; depth--) {
					
					int tmp = calc(ops.top(), vs);
					vs = vstack.top();
					vs.push_back(tmp);
					vstack.pop();
					ops.pop();
				}
			}
			depth = d;

			try {
				int tmp = std::stoi(s);
				vs.push_back(tmp);
			}
			catch (...) {
				ops.push(s.at(0));
				vstack.push(vs);
				vs.clear();
			}
			
			
		}

		int v = 0;
		while(true) {
			
			v = calc(ops.top(), vs);
			if (--depth <= 0) {
				break;
			}
			ops.pop();
			vs = vstack.top();
			vs.push_back(v);
			vstack.pop();
		}
		std::cout << v << std::endl;
	}
}

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

#define     bip(a)         __builtin_popcount(a)
#define     ull            unsigned long long
#define     ll             long long
#define     u              unsigned
#define     pb             push_back
#define     pf             push_front ///for list
#define     mp             make_pair
#define     is             insert
#define     ff             first
#define     ss             second
#define     vi             vector<int>
#define     vl             vector<ll>
#define     si             set<int>
#define     sl             set<ll>
#define     li             list<int>
#define     pii            pair<int,int>
#define     pll            pair<ll,ll>
#define     mii            map<int,int>
#define     mll            map<ll,ll>
#define     ma             INT_MAX
#define     mi             INT_MIN
#define     mod            1000000007
#define     pi             3.14159265359
#define     e              2.71828182846
#define     inf            1000000000000000LL
#define     all(x)         x.begin(), x.end()
#define     lb(a,b,c)      lower_bound(a,a+b,c)-a
#define     ub(a,b,c)      upper_bound(a,a+b,c)-a
#define     lbv(a,c)       lower_bound(all(a),c)-a.begin()
#define     ubv(a,c)       upper_bound(all(a),c)-a.begin()
#define     srt1(a,b)      sort(a,a+b)
#define     srt2(a,b)      sort(a,a+b,greater<int>())
#define     gcd(a,b)       __gcd(a,b)
#define     lcm(a,b)       (a*(b/gcd(a,b)))
#define     harmonic(n)    0.57721566490153286l+log(n)
#define     mem(a, b)      memset(a, b, sizeof(a))

///s.lower_bound(a),s.upper_bound(a), for set
///nCr(x, y) = nCr(x-1, y-1) + nCr(x-1, y)
///factorial digit   ((n * log10(n / e) +log10(2 * pi * n) /2.0));


int main()
{
    int k;
    string str;
    cin>>k>>str;
    for(int i=0;i<str.length();i++){
        if(i+1>k){cout<<"...";break;}
        else cout<<str[i];
    }
    cout<<endl;
}



Measured memory_bytes: 3628
#include<stdio.h>
signed main(){
    int n,k,p[10000];
    int i,j,temp,sum=0;
    scanf("%d %d",&n,&k);
    for(i=0;i<n;i++){
        scanf("%d",&p[i]);
    }
    for(i=0;i<n;i++){
       for(j=0;j<n-i-1;j++){
            if(p[j]>p[j+1]){
                temp=p[j];
                p[j]=p[j+1];
                p[j+1]=temp;
            }
        }
    }
    for(i=0;i<k;i++){
        sum+=p[i];
    }
    printf("%d\n",sum);
    return(0);
}

Measured memory_bytes: 1716
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>		
using namespace std;
typedef long long ll;

int a1,a2,a3,a4;
int main()
{char a[100000],b[]="AC",c[]="WA",d[]="TLE",e[]="RE";
	int x;
	scanf("%d", &x);
	for (int i = 1; i <= x; i++) {
		scanf("%s", a);
		if (strcmp(a, b)==0)a1++;
		else if (strcmp(a, c)==0)a2++;
		else if (strcmp(a, d)==0)a3++;
		else a4++;
	}	
	printf("AC x %d\n", a1);
	printf("WA x %d\n", a2);
	printf("TLE x %d\n", a3);
	printf("RE x %d\n", a4);
	return 0;
}

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

int main() 
{ 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	long long int n,k,sum=0;
	cin>>n>>k;
	int a[n];
	for(int i=0;i<n;i++)
	    cin>>a[i];
	sort(a,a+n);
	for(int i=0;i<k;i++)
	    sum+=a[i];
	cout<<sum<<endl;
	return 0; 
} 


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

int main(){
    int r,g,b;
    cin>>r>>g>>b;

    int total=100*r+g*10+b;
    bool can=false;
    if(total%4==0)can=true;
    if(can)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;

    return 0;
}


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

int main(){
	int n,m;
	vector<string> v(256);
	cin >> n;
	for(int i=0;i<n;i++){
		cin >> v[i];
	}
	cin >> m;
	bool open = false;
	for(int i=0;i<m;i++){
		string t;
		cin	>> t;
		if(find(v.begin(),v.end(),t) != v.end()){
			if(open){
				cout << "Closed by ";
			} else {
				cout << "Opened by ";
			}
			open=(open+1)%2;
			cout << t << endl;
		} else {
			cout << "Unknown " << t << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3192
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    
	String a = sc.next();
	String b = sc.next();
    
    if(a.equals("H") && b.equals("H")) {
      System.out.println("H");
    }
    if(a.equals("H") && b.equals("D")) {
      System.out.println("D");
    }
    if(a.equals("D") && b.equals("H")){
      System.out.println("D");
    }
    if(a.equals("D") && b.equals("D")){
      System.out.println("H");
    }
  }
}

Measured memory_bytes: 21716
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define mod 1000000007
using ll=long long;
const int INF=1000000000;
const ll LINF=1001002003004005006ll;
int dx[]={1,0,-1,0},dy[]={0,1,0,-1};
// ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}
 
struct IOSetup{
    IOSetup(){
        cin.tie(0);
        ios::sync_with_stdio(0);
        cout<<fixed<<setprecision(12);
    }
} iosetup;
 
template<typename T1,typename T2>
ostream &operator<<(ostream &os,const pair<T1,T2>&p){
    os<<p.first<<" "<<p.second;
    return os;
}
 
template<typename T>
ostream &operator<<(ostream &os,const vector<T>&v){
    for(int i=0;i<(int)v.size();i++) os<<v[i]<<(i+1==(int)v.size()?"":" ");
    return os;
}

template<typename T1,typename T2>
istream &operator>>(istream &is,pair<T1,T2>&p){
    is>>p.first>>p.second;
    return is;
}

template<typename T>
istream &operator>>(istream &is,vector<T>&v){
    for(T &x:v)is>>x;
    return is;
}

int h,w;
void solve(){
    vector<vector<int>> g(h,vector<int>(w));
    rep(i,h)rep(j,w)cin>>g[i][j];
    
    int si,sj,gi,gj;
    rep(i,h)rep(j,w){
        if(g[i][j]==2)si=i,sj=j;
        if(g[i][j]==3)gi=i,gj=j;
    }

    int res=INF;
    function<void(int,int,int)> dfs=[&](int i,int j,int c){
        if(c>=10) return ;

        rep(k,4){
            for(int ni=i,nj=j;0<=ni and ni<h and 0<=nj and nj<w;ni+=dx[k],nj+=dy[k]){
                if(g[ni][nj]==3){
                    chmin(res,c+1);
                    return ;
                }
                if(g[ni][nj]==1){
                    g[ni][nj]=0;
                    if(i!=ni-dx[k] or j!=nj-dy[k])dfs(ni-dx[k],nj-dy[k],c+1);
                    g[ni][nj]=1;
                    break;
                }
            }
        }
    };
    dfs(si,sj,0);

    if(res<INF) cout<<res<<endl;
    else cout<<-1<<endl;
}

signed main(){
    while(cin>>w>>h,h)solve();
    return 0;
}



Measured memory_bytes: 3108
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define rnt re int
#define re register
#define I inline int
#define V inline void
#define ll long long int
#define isnum(ch) ('0'<=ch&&ch<='9')
#define FOR(i,a,b) for(rnt i=a;i<=b;i++)
#define ROF(i,a,b) for(rnt i=a;i>=b;i--)
#define gc (_op==_ed&&(_ed=(_op=_buf)+fread(_buf,1,100000,stdin),_op==_ed)?EOF:*_op++)
char _buf[100000],*_op(_buf),*_ed(_buf);
I getint(){
	rnt _s=0;re char _ch=gc;
	while(!isnum(_ch))_ch=gc;
	while(isnum(_ch))_s=_s*10+_ch-48,_ch=gc;
	return _s;
}
const int N=1e4+1,INF=0x3f3f3f3f;
int n,k;
char a[N];ll ans;
V input(){cin>>a+1>>k,n=strlen(a+1);}
int f[N][2][2];
I min(const int&x,const int&y){return x<y?x:y;}
V init(){
	f[1][1][1]=1,f[1][1][0]=f[1][0][1]=INF;
	FOR(i,2,n)FOR(j,0,1){
		if(a[i]==a[i-1]){
			f[i][j][1]=min(f[i-1][j][0],f[i-1][j][1])+1;
			f[i][j][0]=f[i-1][j][1];
		}
		else{
			f[i][j][1]=min(f[i-1][j][0],f[i-1][j][1])+1;
			f[i][j][0]=min(f[i-1][j][0],f[i-1][j][1]);
		}
	}
}
ll t[4],s[4],A[4][4];
V mul(ll x[4],ll y[4],ll z[4]){
	ll tmp[4];
	FOR(i,0,3)tmp[i]=1ll<<62;
	FOR(i,0,3)FOR(j,0,3)if(A[i][j])
		tmp[(i&2)|(j&1)]=min(tmp[(i&2)|(j&1)],x[i]+y[j]);
	FOR(i,0,3)z[i]=tmp[i];
}
V work(){
	FOR(i,0,1)FOR(j,0,1)t[i<<1|j]=f[n][i][j];
	FOR(i,0,3)FOR(j,0,3)A[i][j]=1;
	if(a[1]==a[n])A[0][0]=A[0][1]=A[2][1]=A[2][0]=0;
	while(k){
		if(k&1)mul(s,t,s);
		mul(t,t,t),k>>=1;
	}ans=1ll<<62;
	FOR(i,0,3)ans=min(ans,s[i]);
	cout<<ans;
}
int main(){
//	freopen("test.in","r",stdin);
//	freopen(".out","w",stdout);
	input();
	init();
	work();
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S;
  cin >> S;
  int tmp = 0;
  int m = 0;
  for (int i = 0; i < S.size(); i++) {
    char c = S.at(i);
    if (c == 'A' || c == 'G' || c == 'C' || c == 'T') { tmp++; }
    else if (tmp > m) {
      m = tmp;
      tmp = 0;
    }
  }
  m = max(m, tmp);
  cout << m << endl;
}

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

int main()
{
	int n, q; std::cin >> n >> q;
	
	std::stack<int>* st = new std::stack<int>[n];
	
	;
	for (int i=0; i<q; i++) {
		int op, x, t;
		std::cin >> op;
		switch (op) {
		case 0:
			std::cin >> t >> x;
			st[t].push(x);
			break;
		case 1:
			std::cin >> t;
			if (!st[t].empty()) std::cout << st[t].top() << std::endl;
			break;
		case 2:
			std::cin >> t;
			if (!st[t].empty()) st[t].pop();
			break;
		}
	}
	
	delete[] st;
	
	return 0;
}
		



Measured memory_bytes: 4348
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)     for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = m; i < (int)(n); i++)
#define MOD 1000000007
#define Graph vector<vector<int>>
typedef pair<int, int> PII;
typedef long long int ll;

int main(){
  int H,N;
  cin >> H >> N;

  vector<int> Ai(N);
  int sumAtk = 0;

  rep(i,N){
    cin >> Ai[i];
    sumAtk += Ai[i];
  }

  if(sumAtk >= H){
    cout << "Yes" << endl;  
  }else{
    cout << "No" << endl;
  } 
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
int main(void){
    int a,b,c,d,e;
    cin>>a>>b>>c>>d>>e;
    int x=-(b+a*60)+(d+c*60);
    cout<<x-e<<endl;

}



Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define st first
#define nd second

using ll = long long ;
using namespace std;
using pii = pair<int,int>;
int a[(int)2e5 + 10];
int main(){
	int n;
	scanf("%d", &n);
	for(int i =1; i <n;i++){
		int x;
		scanf("%d", &x);
		a[x]++;
	}	
	for(int i = 1; i <=n;i++){
		printf("%d\n", a[i]);
	}


}

Measured memory_bytes: 4540
#include <bits/stdc++.h>  
using namespace std;  
#define INF 0x3f3f3f3f  
typedef long long ll;  
const int N = 551;  
char s[N];
int main()  
{  
  //  freopen("in.txt", "r", stdin);
    int n;
    while (~scanf("%d", &n))
    {
    	int rec[26] = {0};
    	for (int i = 0; i < 26; i++)
    		rec[i] = 100;
    	for (int i = 0; i < n; i++)
    	{
    		int tmp[26] = {0};
    		scanf("%s", s);
    		for (int j = 0; s[j]; j++)
    			tmp[s[j] - 'a']++;
    		for (int j = 0; j < 26; j++)
    			rec[j] = min(rec[j], tmp[j]);
    	}
    	for (int i = 0; i < 26; i++)
    	{
    		for (int j = 0; j < rec[i]; j++)
    			printf("%c", i + 'a');
    	}
    	putchar('\n');
    }
  
   return 0;  
}  

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

int main()
{
	int N, x[110], y[110], H, count = 0, k = 0;
	long long int h[110];
	scanf("%d", &N);
	for (int i = 0; i < N; i++) {
		scanf("%d%d%lld", &x[i], &y[i], &h[i]);
	}
	for (int i = 0; i <= 100; i++) {
		for (int j = 0; j <= 100; j++){
			for (long long  l = max(h[0] - 200,1LL); l <= h[0] + 200; l++) {
				count = 0;
				k = 0;
				while (k < N) {
					if (h[k] == max(l - abs(x[k] - i) - abs(y[k] - j),0LL)) {
						count++;
					}
					k++;
				}
				if (count == N) {
					printf("%d %d %lld", i, j, l);
					return 0;
				}
			}
		}
	}
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
const long long MOD = 1e9+7;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ll> pdl;
typedef pair<ld, ld> pdd;
//typedef boost::multiprecision::cpp_int bigint;

ld W, H, X, Y;

int main() {
	cin >> W >> H >> X >> Y;
	cout << setprecision(12) << W * H / 2 << endl;
	if (W / 2 == X && H / 2 == Y)cout << 1 << endl;
	else cout << 0 << endl;
	return 0;
}

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

using namespace std;

typedef long long ll;

int main() {
    ll x, k, d;  cin >> x >> k >> d;
    ll near = abs(x) / d;
    ll mn = min(k, near);
    k = k - mn;
    if(x > 0)
    x -= (d * mn);
    else
    x +=(d * mn);
    if(x > 0) {
    if(k % 2 == 1) x = x - d;
    }
    else {
    if(k % 2 == 1) x = x + d;
    }
    cout << abs(x) << endl;
    return 0;
}


Measured memory_bytes: 3568
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#include <ext/pb_ds/detail/standard_policies.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef tree<pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag,
		tree_order_statistics_node_update> ordered_set;

#define el				'\n'
#define sz(v)			((int)((v).size()))
#define all(v)          ((v).begin()),((v).end())
#define clr(v, d)		memset(v, d, sizeof(v))

double const EPS = 1e-8, PI = acos(-1);
const int N = 200000 + 9, M = 20 + 9, OO = (int) 1e9 + 1;
const long long MOD = 1e9 + 7, INF = 1e18 + 9;

typedef long long ll;

void OUTPUT() {
	cout << fixed << setprecision(0);
	ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
}

void INPUT() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif
}

int n, k, x, arr[N];

int main() {
//	INPUT();
	OUTPUT();
	cin >> n >> k;
	for (int i = 0; i < n; ++i) {
		cin >> x;
		arr[x]++;
	}
	vector<int> v;
	for (int i = 1; i < N; i++) {
		if (arr[i])
			v.push_back(arr[i]);
	}
	sort(v.begin(), v.end());
	ll ans = 0;
	int m = max(0, sz(v) - k);
	for (int i = 0; i < m; i++) {
		ans += v[i];
	}
	cout << ans;

	return 0;

}



Measured memory_bytes: 2168
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
    ll N;
    cin>>N;
    map<ll, ll> prime;
    vector<ll> parr;
    for(ll i=2;i*i<=N;++i){
        if(N%i==0){
            parr.push_back(i);
        }
        while(N%i==0) {
            prime[i]++;
            N /= i;
        }
    }
    if(N>1){
        parr.push_back(N);
        prime[N]++;
    }
    /**
    for(int i=0;i<parr.size();++i){
        cout<<parr[i]<<" "<<prime[parr[i]]<<endl;
    }
    **/
    ll ans = 0;
    ll tmp;
    for(int i=0;i<parr.size();++i){
        for(int j=0;j<=prime[parr[i]];++j){
            if(j*(j+1)<=2*prime[parr[i]]){
                tmp = j;
            }
            else break;
        }
        ans += tmp;
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 3636
# coding: utf-8
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

X, N = lr()
P = set(lr())
flag = True
answer = X
while answer in P:
    if flag:
        diff = abs(X - answer)
        answer = X - diff - 1
        flag = False
    else:
        diff = abs(X - answer)
        answer = X + diff
        flag = True

print(answer)


Measured memory_bytes: 9136
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int MAXN = 1e5 + 7;

int arr[MAXN];

int main()
{
    ios::sync_with_stdio(0);
    //while(1){
    int n, flag = 0;
    cin>>n;
    arr[0] = 0;
    for(int i = 1; i <= n; i++)
    {
        cin>>arr[i];
    }
    for(int i = 1; i <= n; i++)
    {
        if(arr[i-1] - arr[i] == 1)
            arr[i-1]--;
        else if(arr[i] == arr[i-1] && arr[i] > arr[i-2])
            arr[i-1]--;
        else if(arr[i] < arr[i-1] && arr[i-1] - arr[i] > 1)
        {
            flag = 1;
            break;
        }
    }
    for(int i = 1; i <= n; i++)
    {
        if(arr[i] < arr[i-1])
        {
            flag = 1;
            break;
        }
    }
    if(flag) cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
    //}
    return 0;
}



Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main()
{
    IOS;
    //ll t;cin>>t;while(t--)
    {
        ll a,b,c,d,i,j,k,l,m,n,sum=0,temp=0,f=0,cnt=0;
        cin>>n;
        m=1000-n%1000;
        
        cout<<m%1000<<endl;

    }
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
typedef pair<ll, int> PII;
constexpr int MAXN = 100000 + 5;
constexpr ll INF = 100000LL * 1000000000 + 100;
constexpr ll MOD = 1000000000 + 7;
int N, M, S, T;
int U, V;
ll D;
ll dad1[MAXN];
ll dist1[MAXN];

ll dad2[MAXN];
ll dist2[MAXN];
int UU[2 * MAXN];
int VV[2 * MAXN];
ll DD[2 * MAXN];
vector<vector<PII>> edges(MAXN);
ll dd(int S, int T, ll *dad, ll *dist) {
  // use priority queue in which top element has the "smallest" priority
  fill(dist, dist + N + 1, INF);
  dad[S] = 1;
  priority_queue<PII, vector<PII>, greater<PII>> Q;
  Q.push(make_pair(0, S));
  dist[S] = 0;
  while (!Q.empty()) {
    PII p = Q.top();
    Q.pop();
    int here = p.second;

    if (dist[here] != p.first) continue;
    for (vector<PII>::iterator it = edges[here].begin();
         it != edges[here].end(); it++) {
      if (dist[here] + it->first < dist[it->second]) {
        dist[it->second] = dist[here] + it->first;
        dad[it->second] = dad[here];
        Q.push(make_pair(dist[it->second], it->second));
      } else if (dist[here] + it->first == dist[it->second]) {
        dist[it->second] = dist[here] + it->first;
        dad[it->second] += dad[here];
        dad[it->second] %= MOD;
      }
    }
  }

  return dist[T];
}
int main() {
  ios::sync_with_stdio(false);
  cin >> N >> M >> S >> T;

  for (int i = 0; i < M; ++i) {
    cin >> U >> V >> D;
    UU[i] = U;
    VV[i] = V;
    DD[i] = D;
    edges[U].push_back(make_pair(D, V));
    edges[V].push_back(make_pair(D, U));
  }
  const ll mindist = dd(S, T, dad1, dist1);
  // cerr << "shortest path: " << mindist << endl;
  dd(T, S, dad2, dist2);
  ll tot = (dad1[T] * dad1[T]) % MOD;
  // cerr << "tot: " << tot << endl;
  for (int i = 1; i <= N; ++i) {
    if (dist1[i] == dist2[i] && dist1[i] == mindist / 2) {
      ll dec = (dad1[i] * dad2[i]) % MOD;
      dec = dec * dec % MOD;
      tot -= dec;
      tot %= MOD;
      tot += MOD;
      tot %= MOD;
    }
  }
  // cerr << "tot: " << tot << endl;

  for (int i = 0; i < M; ++i) {
    const ll d = DD[i];
    int u = UU[i];
    int v = VV[i];
    if (dist1[u] + d + dist2[v] == mindist && dist1[u] < mindist / 2 &&
        dist2[v] < mindist / 2) {
      ll dec = (dad1[u] * dad2[v]) % MOD;
      dec = dec * dec % MOD;
      tot -= dec;
      tot %= MOD;
      tot += MOD;
      tot %= MOD;
    } else {
      swap(u, v);
      if (dist1[u] + d + dist2[v] == mindist && dist1[u] < mindist / 2 &&
          dist2[v] < mindist / 2) {
      ll dec = (dad1[u] * dad2[v]) % MOD;
      dec = dec * dec % MOD;
      tot -= dec;
      tot %= MOD;
      tot += MOD;
      tot %= MOD;
      
      }
    }
  }
  cout << tot;
}

Measured memory_bytes: 21844
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int l = sc.nextInt();

		String[] array = new String[n];

		for(int i = 0; i < n; i++){
			array[i] = sc.next();
		}

		Arrays.sort(array);

		for(int i = 0; i < n; i++){
			System.out.print(array[i]);
		}
		System.out.println();
	}
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
const lint mod=1e9+7;

int K;
std::vector<std::vector<std::vector<int>>> memo;

int gcd(int a, int b, int c){

  if(memo[a-1][b-1][c-1] != -1) return memo[a-1][b-1][c-1];
  if(memo[b-1][c-1][a-1] != -1) return memo[b-1][c-1][a-1];
  if(memo[c-1][a-1][b-1] != -1) return memo[c-1][a-1][b-1];
  if(memo[a-1][c-1][b-1] != -1) return memo[a-1][c-1][b-1];
  if(memo[b-1][a-1][c-1] != -1) return memo[b-1][a-1][c-1];
  if(memo[c-1][b-1][a-1] != -1) return memo[c-1][b-1][a-1];
  int res = 1;
  REP(i,K){
    if(i+1 > a || i+1 > b || i+1 > c) break;
    if(a%(i+1) == 0 && b%(i+1) == 0 && c%(i+1) == 0){
      res = i+1;
    }
  }
  memo[a-1][b-1][c-1] = res;
  //cout << res << "\n";
  return res;
}

int main()
{
  cin >> K;
  memo = std::vector<std::vector<std::vector<int>>>(K,std::vector<std::vector<int>>(K,std::vector<int>(K,-1)));
  lint cnt = 0;
  REP(i,K){
    REP(j,K){
      REP(s,K){
        cnt += gcd(i+1,j+1,s+1);
      }
    }
  }
  cout << cnt << "\n";
  return 0;
}


Measured memory_bytes: 36196
import itertools
import collections

class PrimeFactorize:
    def __init__(self, n):
        self.prime_factor_table = self.create_prime_factor_table(n)

    # O(NloglogN)
    def create_prime_factor_table(self, n):
        self.table = [0] * (n + 1)
        
        for i in range(2, n + 1):
            if self.table[i] == 0:
                for j in range(i + i, n + 1, i):
                    self.table[j] = i
        return self.table

    def prime_factor(self, n):
        prime_count = collections.Counter()
        
        while self.prime_factor_table[n] != 0:
            prime_count[self.prime_factor_table[n]] += 1
            n //= self.prime_factor_table[n]
        prime_count[n] += 1
        return prime_count

N = int(input())
pf = PrimeFactorize(10**5+5)

for i in range(N,10**5+5):
    if pf.prime_factor_table[i]==0:
        print(i)
        break

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

int main()  
{  
    long long int n, k;
    cin>>n>>k;
    long long int a[n];
    for(long long int i=0; i<n; i++) {
        cin>>a[i];
    }
    sort(a,a+n);
    long long int sum = 0;
    for(long long int i=0; i<n-k; i++) {
        sum+=a[i];
    }
    cout<<sum;
}  

Measured memory_bytes: 1792
#include <fstream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <cmath>
#include <climits>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <numeric>
#include <sstream>

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())

using namespace std;
typedef long long ll;

int main() {
#ifdef RUN_LOCAL
  ifstream in("../input.txt");
  cin.rdbuf(in.rdbuf());
#endif

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

  int n;
  cin >> n;
  unordered_map<int, int> set;
  ll cnt = 0;
  for (int i = 1; i <= n; ++i) {
    int h;
    cin >> h;
    if (set.count(i - h) > 0) {
      cnt += set[i - h];
    }
    set[h + i]++;
  }

  cout << cnt << endl;

  return 0;
}


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

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

  queue<int64_t> que;

  for(int64_t i=1; i<10; i++){
    que.push(i);
  }

  for(int i=0; i<k; i++){
    int64_t x = que.front();
    que.pop();
    int a=x%10;

    if(a != 0) que.push(10*x + a - 1);
    que.push(10*x + a);
    if(a != 9) que.push(10*x + a + 1);

    if(i==k-1) cout << x << endl;
  }

}


Measured memory_bytes: 1792
import java.util.Scanner;

class Main {
	public static void main(String[] args){
		Scanner input = new  Scanner(System.in);
		int[] c = new int[6];
		int i;
		int sum;
		
		for (i = 0; i < 6; i++){
			c[i] = input.nextInt();
		}
		
		sum = c[5] * 500 + c[4] * 100 + c[3] * 50 + c[2] * 10 + c[1] * 5 + c[0];
		
		if (sum >= 1000){
			System.out.println("1");
		}
		else {
			System.out.println("0");
		}
	}
}

Measured memory_bytes: 17360
#include<bits/stdc++.h>
using namespace std;
int x[100005],y[100005];
int main()
{
	int a,b,i;
	long long k;
	cin>>a>>b;
	k=a;
	for(i=2;i<=a;i++)
	{
		if(k==1) break;
		while(k%i==0)
		{
			k=k/i;
			x[i]++;
		}
	}
	k=b;
	for(i=2;i<=b;i++)
	{
		if(k==1) break;
		while(k%i==0)
		{
			k=k/i;
			y[i]++;
		}
	}
	for(i=1;i<=min(a,b);++i)
	{
		if(x[i]>y[i])
		{
			y[i]=0;
		}
		if(x[i]==y[i])
		{
			x[i]=0;
		}
		if(x[i]<y[i])
		{
			x[i]=0;
		}
	}
	k=1;
	for(i=1;i<=max(a,b);++i)
	{
		if(x[i]!=0)
		{
			while(x[i])
			{
				x[i]--;
				k=k*i;
			}
		}
		if(y[i]!=0)
		{
			while(y[i])
			{
				y[i]--;
				k=k*i;
			}
		}
	}
	cout<<k;
	return 0;
}


Measured memory_bytes: 640
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    // 入力値の読み込み
    Scanner sc = new Scanner(System.in);
    long A = sc.nextLong()-1;
    long B = sc.nextLong();
    long C = sc.nextLong();
    long D = sc.nextLong();
    
    long A_C = A / C; // Cの個数
    long A_D = A / D; // Dの個数
    long A_CD = A / lcm(C, D); //最小公倍数
    long cntA = A_C + A_D - A_CD;
    
    long B_C = B / C; // Cの個数
    long B_D = B / D; // Dの個数
    long B_CD = B / lcm(C, D); //最小公倍数
    long cntB = B_C + B_D - B_CD;
    System.out.println(B - A - (cntB - cntA));
  }
  
  private static long lcm(long m, long n) {
    return m * n / gcd(m, n);
  }
  private static long gcd(long m, long n) {
    if(m < n) return gcd(n, m);
    if(n == 0) return m;
    return gcd(n, m % n);
  }
  
}

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

typedef long long ll;

char tmp[15];
int n;
map <string, int> M;
ll res;

int main()
{
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%s", tmp);
        string s = tmp;
        sort(s.begin(), s.end());
        res += M[s]++;
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 11136
import sys, heapq
from collections import defaultdict
from itertools import product, permutations, combinations
from bisect import bisect_left # bisect(list, value) -> index

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

N, M = map(int, input().split())
pS = [list(input().split()) for _ in range(M)]

was = defaultdict(int) # number of WA
chk = defaultdict(int) # chkflg
wass = 0
for ps in pS:
    p, S = int(ps[0]), ps[1]
    if chk[p] == 1:
        continue
    else:
        if S == 'AC':
            chk[p] = 1
            wass += was[p]
        else:
            was[p] += 1

print(sum(list(chk.values())), wass)



Measured memory_bytes: 44492
#include<bits/stdc++.h>
#define int long long int
#define rep(i,a,b)	for(i=a;i<b;i++)
using namespace std;
struct knap{
	int w,v;
};
knap a[105];
int ma[105][100005];
int knapsack(int n,int W)
{
	if(W<=0)	return 0;
	if(n<0)	return 0;
	if(ma[n][W]!=-1)	return ma[n][W];
	if(a[n].w<=W){
		ma[n][W]=max(knapsack(n-1,W),knapsack(n-1,W-a[n].w)+a[n].v);
	}
	else{
		ma[n][W]=knapsack(n-1,W);
	}
	return ma[n][W];
}
int32_t main()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
	
	int n,W;
	cin >> n >> W;
	for(int i=0;i<n;i++){
		cin >> a[i].w >> a[i].v;
	}
	for(int i=0;i<101;i++){
		for(int j=0;j<100005;j++){
			ma[i][j]=-1;
		}
	}
	int ans=knapsack(n-1,W);
	cout << ans;

	return 0;
}

Measured memory_bytes: 82536