akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main(){
  int n;  cin >> n;
  vector<long> a(n+1, 0);
  for(int i=1; i<=n; i++)  cin >> a[i];

  long idx = 1, yen = 1000;
  while(idx < n){
    if(a[idx] > a[idx+1]){
      //      cout << idx << " is contin\n";
      idx++;
      continue;
    }
    int s = 1;
    while(idx + s <= n && a[idx+s-1] <= a[idx+s])  s++;
    //    while(a[idx+s] <= a[idx+s+1])  s++;
    yen = yen + (a[idx+s-1]-a[idx]) * (yen/a[idx]);
    //    cout << " a is  " << a[idx] << "   b is  " << a[idx+s-1] << endl;
    //    cout << " new yen  ~ " << yen << endl; 
    idx += s;

  }

  cout << yen << endl;

  return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int d[100005];
int had[100005];
int has[100005];
int main(){
	had[0]=3;
	has[0]=3;
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>d[i];
		d[i]++;
	}
	long long ans=1;
	for(int i=0;i<n;i++){
		ans*=(had[d[i]-1]-has[d[i]]);
		ans%=1000000007;
		had[d[i]]++;
		has[d[i]]++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1408
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<bitset>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long int ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
#define REP(i,n) for(int i=0;i<(n);i++)
const int INF=100000000;

int main(){
	int x1,y1,x2,y2,x3,y3,x4,y4;
	cin>>x1>>y1>>x2>>y2;
	int xsa=x2-x1;
	int ysa=y2-y1;
	x3=x2-ysa;
	y3=y2+xsa;
	x4=x3-xsa;
	y4=y3-ysa;
	cout<<x3<<" "<<y3<<" "<<x4<<" "<<y4<<endl;
	return 0;
}

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

#define rep(i,n)  for(int i=0;i<n;++i)
#define per(i,n)  for(int i=n-1;i>=0;--i)
#define sc1(a)  scanf("%d",&a)
#define sc2(a,b)  scanf("%d %d",&a,&b)
#define sc3(a,b,c)  scanf("%d %d %d",&a,&b,&c)
#define sl1(a)  scanf("%lld",&a)
#define sl2(a,b)  scanf("%lld %lld",&a,&b)
#define sl3(a,b,c)  scanf("%lld %lld %lld",&a,&b,&c)
#define PI 3.1415926535897932

int main(){
    double a,b,c,d;
    scanf("%lf %lf %lf %lf",&a,&b,&c,&d);
    printf("%.10lf\n",sqrt(pow(a-c,2)+pow(b-d,2)));
    return 0;
}



Measured memory_bytes: 3228
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> i_i;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int f(int in){
    if(in < 10){
        return in;
    }
    return in % 10 + f(in / 10);
}

int main() {
    //cout.precision(10);
    int k;
    cin >> k;
    vector<i_i> pathes[100020];
    int cost[100020];
    for(int i = 0; i <= 100005; i++){
        cost[i] = INF;
        for(int j = 0; j < 10; j++){
            int next = i + j * k;
            pathes[i].push_back({next % 10, next / 10});
        }
        if(i > 0) pathes[i].push_back({f(i), 100005});
    }
    cost[0] = 0;
    priority_queue<i_i, vector<i_i>, greater<i_i> > search;
    search.push({0, 0});
    while(!search.empty()){
        int now = search.top().second;
        //cout << now << " " << search.top().first << endl;
        search.pop();
        if(now == 100005){
            cout << cost[now] << endl;
            return 0;
        }
        for(int i = 0; i < pathes[now].size(); i++){
            int next = pathes[now][i].second;
            int next_cost = cost[now] + pathes[now][i].first;
            if(next_cost >= cost[next]){
                continue;
            }
            cost[next] = next_cost;
            search.push({next_cost, next});
        }
    }
    return 0;
}


Measured memory_bytes: 20212
#include <algorithm>
#include <cstdio>
typedef long long LL;
const int N = 100050;
LL W[N];
int main() {
  int n, p;
  scanf("%d%d", &n, &p);
  LL S = 0;
  int w, b;
  for (int i = 0; i < n; ++i) {
    scanf("%d%d", &w, &b);
    W[i] = (LL)w * (100 - p) + (LL)b * p;
    S += (LL)p * b;
  }
  std::sort(W, W + n);
  for (int i = n - 1; ~i; --i) {
    S -= W[i];
    if (S <= 0) {
      printf("%d\n", n - i);
      break;
    }
  }
  return 0;
}


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

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

using namespace std;

int main(){
	int n; scanf("%d",&n);

	printf("? ");
	rep(i,n) printf("%d%c",i+1,i<n-1?' ':'\n');
	fflush(stdout);
	char s[5]; scanf("%s",s);
	char L0=s[0];
	char R0=(L0=='R'?'B':'R');

	int lo=0,hi=n;
	while(hi-lo>1){
		int mi=(lo+hi)/2;

		printf("? ");
		rep(i,n) printf("%d%c",mi+i+1,i<n-1?' ':'\n');
		fflush(stdout);
		scanf("%s",s);

		if(s[0]==L0) lo=mi;
		else         hi=mi;
	}

	vector<int> ans(2*n,-1);
	ans[lo]=0;
	ans[lo+n]=1;
	rep(k,2*n) if(k<lo || lo+n<k) {
		printf("? ");
		rep(i,n-1) printf("%d ",lo+i+2);
		printf("%d\n",k+1);
		fflush(stdout);
		scanf("%s",s);
		ans[k]=(s[0]==L0?0:1);
	}
	for(int k=lo+1;k<lo+n;k++){
		printf("? ");
		rep(i,lo) printf("%d ",i+1);
		for(int i=lo+n+1;i<2*n;i++) printf("%d ",i+1);
		printf("%d\n",k+1);
		fflush(stdout);
		scanf("%s",s);
		ans[k]=(s[0]==L0?0:1);
	}

	printf("! ");
	rep(i,2*n) putchar(ans[i]==0?L0:R0);
	puts("");

	return 0;
}


Measured memory_bytes: 724
import java.io.PrintWriter;
import java.util.*;

public class Main {
    static Scanner scanner;
    static PrintWriter out;
    public static void main(String[] args) {
        scanner = new Scanner(System.in);
        out = new PrintWriter(System.out);
        String txt = next();
        char a = txt.charAt(0);
        char b = txt.charAt(1);
        char c = txt.charAt(2);
        if (a == 'R') {
            if (b == 'R') {
                if (c == 'R') {
                    println("3");
                } else {
                    println("2");
                }
            } else {
                println("1");
            }
        } else if (b == 'R') {
            if (c == 'R') {
                System.out.println("2");
            } else {
                System.out.println("1");
            }
        } else if (c == 'R') {
            System.out.println("1");
        } else {
            System.out.println("0");
        }


        out.flush();
    }

    public static void println(Object o) {
        out.println(o);
    }

    public static void print(Object o) {
        out.print(o);
    }

    public static void printf(String format, Object... o) {
        out.printf(format, o);
    }

    public static String next() {
        return scanner.next();
    }

    public static int nextInt() {
        return Integer.parseInt(scanner.next());
    }

    public static long nextLong() {
        return Long.parseLong(scanner.next());
    }

    public static double nextDouble() {
        return Double.parseDouble(scanner.next());
    }

    public static short nextShort() {
        return Short.parseShort(scanner.next());
    }

    public static float nextFloat() {
        return Float.parseFloat(scanner.next());
    }

    public static void printYes() {
        System.out.println("Yes");
    }

    public static void printYES() {
        System.out.println("YES");
    }

    public static void printNo() {
        System.out.println("No");
    }

    public static void printNO() {
        System.out.println("NO");
    }

    public static String nextLine() {
        return scanner.nextLine();
    }

    public static double distance(double x, double y, double x2, double y2) {
        return Math.sqrt((x2 - x) * (x2 - x) + (y2 - y) * (y2 - y));
    }

    public static int MOD = 1_000_000_007;
    public static int MAX = 100000;
    public static long[] fac = new long[MAX];
    public static long[] finv = new long[MAX];
    public static long[] inv = new long[MAX];

    public static void combinit() {
        fac[0] = fac[1] = 1;
        finv[0] = finv[1] = 1;
        inv[1] = 1;
        for (int i = 2; i < MAX; i++) {
            fac[i] = fac[i - 1] * i % MOD;
            inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
            finv[i] = finv[i - 1] * inv[i] % MOD;
        }
    }

    public static long combination(int n, int k) {
        if (n < k || n < 0 || k < 0) return 0;
        return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
    }

    public static long factorial(long n) {
        return n <= 0 ? 1 : n * factorial(n - 1);
    }
}

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

int main(){
	int s,t,p,q,M,y;cin>>s>>t>>p>>q>>M>>y;
	cout<<(s^t^y)<<endl;
}


Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long int
#define rep(i, n) for(int i = 0; i < n; i++)
#define repp(i, n) for(int i = 1; i <= n; i++)
#define sort(v) sort((v).begin(), (v).end())
#define pb push_back
#define mp make_pair
#define riverse(v) reverse((v).begin(), (v).end())
using vi = vector<int>;
using vs = vector<string>;
using vvi = vector<vi>;
using vll = vector<ll>;
const ll MOD = 1e9+7;
vi alphabet = {'a','b','c','d','e','f','g','h','i','j','k','l','m',
               'n','o','p','q','r','s','t','u','v','w','x','y','z'};
 
 
 
bool f [100001];
int c [100002];
int N ,L , R ;
int main (){
	for ( int i =2; i <=100000; i ++) if (! f [ i ]) for ( int j = i + i ;j <=100000; j += i )
	f[ j ]= true ;
	for ( int i =3; i <=100000; i +=2) if (! f [ i ]&&! f [( i +1)/2]) c [ i ]++;
	for ( int i =3; i <=100000; i ++) c [ i ]+= c [i -1];
	int Q;
  	cin>>Q;
  	rep(i,Q){
    	int L,R;
      	cin >> L>> R;
      	cout << c [ R ] - c [L -1] << endl;
    }
}

Measured memory_bytes: 1152
/* All men have limits. They learn what they are and learn
   not to exceed them, I ignore mine. -Batman           */
#include <bits/stdc++.h>
//#include <iostream>
//#include <Windows.h>
using namespace std;
void swap(char &i,char &j){
	char temp;
	temp=i;i=j;j=temp;	
}

int main(){
string s;
cin>>s;
for(int i=0;i<s.length()/2;i++){
	swap(s[i],s[s.length()-i-1]);
}
cout<<s<<endl;
return 0;
}

Measured memory_bytes: 3148
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int D = sc.nextInt();
		int E = sc.nextInt();
		int F = sc.nextInt();
		sc.close();
        int w = 100 * A;	// 水
        int s = 0;	// 砂糖
        for(int a = 0; 100 * a <= F; a++) {
        	for(int b = 0; 100 * b <= F; b++) {
        		int tmpW = 100 * A * a+ 100 * B *b;
        		if(tmpW == 0) continue;
        		for(int c = 0; tmpW + c * C <= F; c++) {
        			for(int d = 0; tmpW + d * D + c * C <= F; d++) {
        				int tmpS = c * C + d * D;
        				if(tmpS == 0) continue;
        				int maxS = (A * a + B * b) * E;
        				if(maxS < tmpS) break;
        				int val = s * (tmpS + tmpW);
        				int tmpVal = tmpS * (s + w);
        				if(val < tmpVal) {
        					w = tmpW;
        					s = tmpS;
        				}
        			}
        		}
        	}
        }
        System.out.printf("%d %d\n", w + s, s);
    }
}

Measured memory_bytes: 23252
N,A,B,C = map(int,input().split())
l = [int(input()) for _ in range(N)]
ans = float("inf")
for i in range(4**N):
    a,b,c = [],[],[]
    cost = 0
    for j in range(N):
        r = (i//(4**j)) % 4
        if r == 1:
            a.append(l[j])
        elif r == 2:
            b.append(l[j])
        elif r == 3:
            c.append(l[j])
    if a and b and c:
        cost += sum(max((len(x)-1), 0)*10 for x in [a,b,c])
        a = sum(a)
        b = sum(b)
        c = sum(c)
        cost += sum(abs(x-y) for x,y in [(a,A),(b,B),(c,C)])
        ans = min(ans, cost)
print(ans)

Measured memory_bytes: 9192
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
  int X; cin>>X;
  vector<int> v({3,5,7});
  string s;
  if (find(v.begin(), v.end(), X) != v.end()){
    s = "YES";
  } else {
    s = "NO";
  }
  cout<<s<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <string>

using namespace std;

const int mod = 1000000007;

#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

int findIndex(vector<string> vec, string value)
{
    vector<string>::iterator iter = std::find(vec.begin(), vec.end(), value);
    size_t index = distance(vec.begin(), iter);
    if(index == vec.size())
    {
        return -1;
    }
    return index;
}

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

    string preStr;
    char lastChara;
    vector<string> vec;
    bool isDuplicate = false;
    for (int i = 0; i < n; i++)
    {
        string w;
        cin >> w;

        if (i == 0)
        { 
            preStr = w;
            lastChara = w[w.size()-1];
            vec.push_back(w);
            continue;
        }

        if (isDuplicate)
        {
            continue;
        }
        
        if (w[0] != lastChara || findIndex(vec, w) > -1)
        {
            isDuplicate = true;
        }

        preStr = w;
        lastChara = w[w.size()-1];
        vec.push_back(w);
    }
    
    cout << (isDuplicate ? "No" : "Yes") << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int64_t X;
  cin >> X;
  int64_t memo = 100;
  for (int i = 0; i < 3760; i++) {
    if (memo + memo / 100 >= X) {
      cout << i + 1 << endl;
      break;
    }
    else {
       memo = memo + memo / 100;
    }
  }
}

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

int main(){
    int n,m,r;
    cin >> n >> m >> r;
    int c[r];
    for(int i=0; i<r; i++){
        cin >> c[i];
        c[i]--;
    }
    sort(c,c+r);
    int d[n][n];
    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            if(i!=j)d[i][j] = 100000000;
            else d[i][j] = 0;
        }
    }
    for(int i=0; i<m; i++){
        int a,b,e;
        cin >> a >> b >> e;
        a--;b--;
        d[a][b] = e;
        d[b][a] = e;
    }
    for(int k=0; k<n; k++){
        for(int i=0; i<n; i++){
            for(int j=0; j<n; j++){
                d[i][j] = min(d[i][j],d[i][k]+d[k][j]);
            }
        }
    }
    int ans = 1000000000;
    do{
        int t = 0;
        for(int i=1; i<r; i++){
            if(d[c[i]][c[i-1]] < 0){
                t = ans;
                break;
            }
            t += d[c[i]][c[i-1]];
        }
        ans = min(t,ans);
    }while(next_permutation(c,c+r));
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 384
package main

import (
	"fmt"
)

func main(){
	var counter,temp,flag int
	fmt.Scanf("%d",&temp)
	counter=temp
	arr :=make([] int,counter,1000)
	for i:=0;i<counter ;i++  {
		fmt.Scanf("%d",&temp)
		arr[i]=temp
	}
	for i:=0; i<len(arr);i++  {
		mini:=i
		for j:=i; j<len(arr); j++  {
			if arr[j]<arr[mini]{
				mini=j
			}
		}
		if mini!=i {
			temp=arr[i]
			arr[i]=arr[mini]
			arr[mini]=temp
			flag++
		}

	}
	putout(arr)
	fmt.Println(flag)
}
func putout(arr []int) {
	i := 0
	for i = 0; i < len(arr)-1; i++ {
		fmt.Printf("%d ", arr[i])
	}
	fmt.Print(arr[i])
	fmt.Println()
}
/*1 for i = 0 to A.length-1
2     mini = i
3     for j = i to A.length-1
4         if A[j] < A[mini]
5             mini = j
6     swap A[i] and A[mini]*/


Measured memory_bytes: 1128
import itertools

N = int(input())
F = [list(map(int,input().split())) for i in range(N)]
P = [list(map(int,input().split())) for i in range(N)]

#print(F)
#print(P)

ans = -10**10
for v in itertools.product([1,0],repeat=10):
    if v != (0,0,0,0,0,0,0,0,0,0):
        bene = 0
        for i in range(N):
            c = 0
            for j in range(10):
                if v[j] == F[i][j] == 1:
                    c += 1
            bene += P[i][c]
        ans = max(ans,bene)
print(ans)


Measured memory_bytes: 3064
a=int(input())
b=int(input())
c=int(input())
x=int(input())

cnt=0

for i in range(a+1):
    newx=x
    newx=x-500*i
    for j in range(b+1):
        newx2=newx-100*j
        for k in range(c+1):
            newx3=newx2-50*k
            
            if newx3==0:
                cnt+=1
            else:
                continue

print(cnt)

Measured memory_bytes: 3064
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>

#define _CRT_SECURE_NO_WARNINGS

int main(int argc, char const *argv[])
{
	int s;
	int l,r;
	scanf("%d",&s);
	l = s / 100;	r = s % 100;
	if(1 <= l && l <= 12){
		if(1 <= r && r <= 12)	puts("AMBIGUOUS");
		else puts("MMYY");
	}
	else{
		if(1 <= r && r <= 12)	puts("YYMM");
		else puts("NA");
	}
	return 0;
}

Measured memory_bytes: 128
import sys
sys.setrecursionlimit(100000000)
class UnionFind:
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return {i for i in range(self.n) if self.find(i) == root}

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

n,m,k=map(int,input().split())
block = [0]*n
uf = UnionFind(n)
for _ in range(m):
  a,b=map(int,input().split())
  block[a-1] += 1
  block[b-1] += 1
  uf.union(a-1,b-1)

uf.find(0)
for _ in range(k):
  c,d=map(int,input().split())
  if uf.same(c-1,d-1):
    block[c-1] += 1
    block[d-1] += 1

ans = [uf.size(i) - block[i] - 1 for i in range(n)]
print(*ans)

Measured memory_bytes: 18520
#include <iostream>
#include <cstdio>
#include <set>
#include <algorithm>
using namespace std;

#define REP(i,m,n)  for(i=m;i<n;i++)
#define N_MAX 100000

int main(){

    int n;
    int i;
    int a[N_MAX+1];
    int list[N_MAX+1];
    int temp1,temp2;
    set<int> s;
    set<int>::iterator ite;;
    int ans = 0;

    cin >> n;


    REP(i, 1, n+1){
        cin >> a[i];
        if (a[i] == 1){
            s.insert(i);
        }
    }

    temp2 = 1;
    REP(i, 0, n){
        ans++;
         temp1 = a[temp2];
         temp2 = temp1;
         if (temp2 == 2)
             break;
         ite = s.find(temp2);
         if (ite == s.end()){
             s.insert(temp2);
         }
         else {
             ans = -1;
             break;
         }
    }


    cout << ans << endl;

//    for (ite = s.begin(); ite != s.end(); ++ite)
//        cout << *ite << endl;




}

Measured memory_bytes: 5376
#include <bits/stdc++.h>
using namespace std;
#define REP(i,x,n) for(int i = x; i < n; i++)
#define MAX 100
#define INF 1000000001
 
int n;
int x[101];
int y[101];
int h[101];
// char X[100][100];
// int dp[1000000001];
 
int main(void){
    cin >> n;
    int p = 0;
    REP(i,0,n) {
        cin >> x[i] >> y[i] >> h[i];
        if (!p&&h[i]) p = i;
    }
    
    REP(X,0,101) {
        REP(Y,0,101) {
            bool flag = true;
            int needH = abs(X - x[p]) + abs(Y - y[p]) + h[p];
            
            REP(i,0,n) {
                if (max(needH - (abs(X - x[i]) + abs(Y - y[i])),0) != h[i]) {
                    flag = false;
                    break;
                }

            }
            
            if (flag) {
                printf("%d %d %d",X,Y,needH); 
                return 0;
            }
        }
    }
    
 
    
 
}

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

// big-array.cpp
// author: Seong Yong-ju ( @sei40kr )
// Copyright (c) 2017 Seong Yong-ju

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

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

using namespace std;

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

  int n;
  long k;
  cin >> n >> k;
  vector<tuple<int, int>> pairs;
  REP(i, n) {
    int a, b;
    cin >> a >> b;
    pairs.push_back(make_tuple(a, b));
  }
  sort(ALL(pairs));

  long cnt = 0;
  for (auto &pair: pairs) {
    int a, b;
    tie(a, b) = pair;
    cnt += b;
    if (k <= cnt) {
      cout << a << endl;
      break;
    }
  }
}


Measured memory_bytes: 1400
import java.util.*;

class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long l=sc.nextInt();
        long r=sc.nextInt();
        long ans=2018;
        for(int i=0;i<Math.min(r-l,2019);i++){
            for(int j=i+1;j<Math.min(r-l+1,2019);j++){
                ans=Math.min((l+i)*(l+j)%2019,ans);
            }
        }
        System.out.println(ans);
    }
}


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

#define HASH 10007

typedef struct List {
	struct List *next;
	char *s;
	int l;
} list;

long long div_mod(long long x, long long y, long long z)
{
	if (x % y == 0) return x / y;
	else return (div_mod((1 + x / y) * y - x, (z % y), y) * z + x) / y;
}

int hash_string(char* s)
{
	int i, x = 0;
	for (i = 0; s[i] != 0; i++) x = ((x << 5) + s[i] - 'a') % HASH;
	return x;
}

int lex_smaller(char* s1, char* s2)
{
	int i;
	for (i = 0; s1[i] != 0 && s2[i] != 0; i++) {
		if (s1[i] < s2[i]) return 1;
		else if (s1[i] > s2[i]) return -1;
	}
	if (s1[i] == s2[i]) return 0;
	else if (s1[i] == 0) return 1;
	else return -1;
}

int main()
{
	int i, j, l[200001], N;
	char *S[200001], T[1000001];
	scanf("%d", &N);
	for (i = 1; i <= N; i++) {
		scanf("%s", T);
		for (l[i] = 0; T[l[i]] != 0; l[i]++);
		S[i] = (char*)malloc(sizeof(char) * (l[i] + 1));
		for (j = 0; j <= l[i]; j++) S[i][j] = T[j];
	}
	
	int h[200001];
	list *p, *hash[HASH], d[200001];
	for (i = 1; i <= N; i++) {
		h[i] = hash_string(S[i]);
		d[i].s = S[i];
		d[i].l = l[i];
		d[i].next = hash[h[i]];
		hash[h[i]] = &(d[i]);
	}
	
	int k, dp[26];
	long long ans = 0, tmp, pow[32];
	const long long inv = div_mod(1, 32, HASH);
	for (k = 1, pow[0] = 32; k < 32; k++) pow[k] = pow[k-1] * pow[k-1] % HASH;
	for (i = 1; i <= N; i++) {
		if (l[i] <= 1) continue;
		for (j = 0; j <= l[i]; j++) T[j] = S[i][j];
		for (j = l[i] - 1, k = 0, tmp = 1; j > 0; j >>= 1, k++) if ((j & 1) == 1) tmp = tmp * pow[k] % HASH;
		h[i] = (h[i] - tmp * (T[0] - 'a') % HASH + HASH) % HASH;
		tmp = tmp * inv % HASH;
		h[i] = (h[i] - tmp * (T[1] - 'a') % HASH + HASH) % HASH;
		for (j = 0; j < 26; j++) dp[j] = 0;
		dp[S[i][0] - 'a'] = 1;
		for (j = 1; j < l[i]; j++) {
			dp[S[i][j] - 'a'] = 1;
			for (k = 0; k < 26; k++) {
				if (dp[k] == 0) continue;
				T[j] = 'a' + k;
				h[0] = (tmp * k + h[i]) % HASH;
				for (p = hash[h[0]]; p != NULL; p = p->next) if (p->l == l[i] - j && p->s[0] == T[j] && p->s[p->l - 1] == T[l[i] - 1] && lex_smaller(p->s, &(T[j])) == 0) break;
				if (p != NULL) ans++;
			}
			tmp = tmp * inv % HASH;
			h[i] = (h[i] - tmp * (S[i][j+1] - 'a') % HASH + HASH) % HASH;
		}
	}
	
	printf("%lld\n", ans);
	fflush(stdout);
	return 0;
}

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

#define INF 1e18
#define REP(i, n) for (int i=0; i<n; i++)
#define print(x) cout << x << endl
#define debug(x) cout << #x << " = "<< x << endl

const double PI=3.141592653589793238462643383279502884197169399375105820974944;

typedef long long ll;

using namespace std;

void solve() {
    int N;
    cin >> N;
    vector<ll> a(N);
    REP(i, N) cin >> a[i];

    ll total = 0; 
    REP(i, N) {
        total += a[i];
    }

    ll ans = 1001001001001001001LL;
    ll x = 0;
    for (int i = 0; i < N-1; i++) {
        x += a[i];
        ll y = total - x;
        ll diff = abs(x - y);
        ans = min(ans, diff);
    }
    print(ans);
}

signed main() {
    solve();
}


Measured memory_bytes: 1792
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <vector>
#include <numeric>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9+7))
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
template<class T> inline bool chmin(T& a, T b){return a>b ? a=b, true : false;}
template<class T> inline bool chmax(T& a, T b){return a<b ? a=b, true : false;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

pii mpair[100010];

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<vector<int>> m(N);
    // vector<pii> mpair(N-1);
    map<pii, int> mmap;
    REP(i, N-1) {
        int a,b;
        cin>> a >> b;
        // scanf("%d %d", &a, &b);
        a--;b--;
        m[a].pb(b);
        m[b].pb(a);
        mpair[i] = pii(a,b);
        // mmap[mpair[i]] = -1;
    }

    queue<pii> q;
    q.push(pii(0,N));
    vector<int> ok(N+1);
    while(!q.empty()){
        auto f = q.front();q.pop();
        fill(ALL(ok), 0);
        ok[f.se] = 1;
        for(auto &&c : m[f.fi]){
            pii pc = (f.fi<c?pii(f.fi,c):pii(c,f.fi));

            if(mmap.find(pc) != mmap.end())
                continue;

            int id = 1;
            while(ok[id])
                id++;
            ok[id] = 1;
            mmap[pc] = id;
            q.push(pii(c,id));
        
            // auto &mmapit = mmap[pc];
            // if(mmapit == -1){
            //     while(ok[id])
            //         id++;
            //     ok[id] = 1;
            //     mmapit = id;
            //     q.push(pii(c,id));
            // }
            // if(mmap[pc] == -1){
            //     while(ok[id])
            //         id++;
            //     ok[id] = 1;
            //     mmap[pc] = id;
            //     q.push(pii(c,id));
            // }
        }
    }

    int ans = 0;
    for(auto && i : mmap){
        ans = max(ans, i.se);
    }

    pr(ans);
    REP(i, N-1){
        pr(mmap[mpair[i]]);
        // printf("%d\n", mmap[mpair[i]]);
    }
}

Measured memory_bytes: 13472
#include<stdio.h>
#include<string.h>

int main(){

    char s[100];
    scanf("%s",s);

    int len = strlen(s);
    int cnt = 0;

    for(int i = 0; i <= (len-1)/2; i += 1){
        if(s[i] != s[len - i - 1]){cnt += 1;}
    }

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

    return 0;
    
}

Measured memory_bytes: 128
#include <iostream>

int main()
{
  using namespace std;
  int X;
  int C500, C5, C100, C50, C10, C1;
  cin >> X;
  // cout << X << endl;
  C500 = X / 500;
  // cout << "C500 = " << C500 << " C5 = " << C5 << endl;
  C5 = (X - (500 * C500)) / 5;
  cout << C500 * 1000 + C5 * 5;
  return 0;
}

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

int main() {
    int n=0;
	cin>>n;
	long long arr[n+1];
	memset(arr,0,sizeof(arr));
	long long totalSum=0;
	for(int i=1;i<=n;i++) cin>>arr[i], totalSum+=arr[i];
	long long prefixSum[n+1];
	memset(prefixSum,0,sizeof(prefixSum));
	for(int i=1;i<=n;i++) prefixSum[i]=arr[i]+prefixSum[i-1];
    long long dp[n+1][n+1];
	memset(dp,0,sizeof(dp));
	int len=0;
	while(++len<=n){
		for(int i=1;i<=n-len+1;i++){
			int j=i+len-1;
			if (len==1)
			   dp[i][j]=arr[i];
			else{
				dp[i][j]=max(arr[i]+prefixSum[j]-prefixSum[i]-dp[i+1][j],
				          arr[j]+prefixSum[j-1]-prefixSum[i-1]-dp[i][j-1]);
			}
		}
	}
	// cout<<"start -- "<<endl;
	// for(int i=1;i<=n;i++){
	// 	for(int j=1;j<=n;j++)
	// 	   cout<<dp[i][j]<<" ";
	// 	cout<<endl;
	// }
	cout<<2*dp[1][n]-totalSum<<endl;
	return 0;
}

Measured memory_bytes: 74048
#include <iostream>
using namespace std;
int main()
{
	int a[55];
	int n, cnt=0, t;
	cin >> n;
	for (int i=1; i<=n; i++)
	{
		cin >> t;
		if (t!=i)
			cnt++;
	}
	if (cnt==2 || cnt==0)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
 int main(){
   int n,a;
   a=0;
   cin >>n;
   vector<int> d(n);
   rep(i,n){
   cin>>d.at(i);
     if(d.at(i)%2==0){
      if((d.at(i)%3!=0)&&(d.at(i)%5!=0)){
        a++;
      }
     }
   }
   if(a==0)
   cout<<"APPROVED"<<endl;
   else
   cout<<"DENIED"<<endl;
   
}


Measured memory_bytes: 256
package main

import "fmt"

const inf = 1 << 60

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func main() {
	var n, k int
	fmt.Scan(&n, &k)
	ts := make([]int, n+1)
	for i := 0; i < n; i++ {
		fmt.Scan(&ts[i])
	}
	ts[n] = inf

	ans := 0
	for i := 0; i < n; i++ {
		ans += min(ts[i+1]-ts[i], k)
	}
	fmt.Println(ans)
}


Measured memory_bytes: 4992
#include <stdio.h>

void swap(int *,int *);
int main(void){
	int i,n;
	int count=0,flag;
	int a[100];
	
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	
	flag=1;
	while(flag){
		flag=0;
		for(i=n-1;i>0;i--){
			if(a[i]<a[i-1]){
				swap(&a[i],&a[i-1]);
				flag=1;
				count++;
			}
		}
	}
	
	for(i=0;i<n;i++){
		printf("%d",a[i]);
		if(i<n-1)
			printf(" ");
	}
	printf("\n");
	printf("%d\n",count);
	
	
	return 0;
}

void swap(int *px,int *py){
	int tmp=*px;
	*px=*py;
	*py=tmp;
}

Measured memory_bytes: 1852
#include <iostream>
#include <string>
using namespace std;
 
int main() {
    string s,t;
    int count=0;
    cin >> s >> t;
    for(int i=0;i<3;i++){
        if(s[i]==t[i]){
            count++;
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
if __name__ == "__main__":
    S = input()
    N = len(S)
    result = 0
    for bit in range(1 << (N - 1)):
        tmp = ""
        for x in range(N - 1):
            tmp += S[x]
            if ((bit >> x) & 1):
                tmp += '+'
        tmp += S[-1]
        result += eval(tmp)
    print (result)
        


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m,sum1=0,sum2=0;
    cin>>n>>m;
    n=n-1;
    m=m-1;
    while(n>=1)
    {
        sum1=sum1+n;
        n--;
    }
    //cout<<sum1<<endl;
    while(m>=1)
    {
        sum2=sum2+m;
        m--;
    }
    //cout<<sum2<<endl;
    cout<<sum1+sum2<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream> 
#include <cstdio> 
#include <cstring> 
using namespace std; 
int main()
{
 char a[50],b[50],c[100];
 while(cin>>a>>b)
{
int j;
 c[0]=a[0]; 
for(int i=1,j=0;i<=100;i++)
{
 if(i%2!=0) {c[i]=b[j];j++;} 
else 
c[i]=a[j]; 
}
 cout<<c<<endl;
 } 
return 0; 
} 


Measured memory_bytes: 256
a, b, c, x, y = gets.split.map(&:to_i)
result = 0
if a + b > c * 2
  less = x < y ? x : y
  result += c * 2 * less
  x -= less
  y -= less
  single = a * x + b * y 
  half = (x + y) * 2 * c
  if single < half
    result += single
  else
    result += half
  end
else
  result += a * x
  result += b * y
end
puts result

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

#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define out(x) cout << x << endl;
#define all(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;
template <typename T>
vector<T> v1init(int len){
    vector<T> vec(vector<T>(len, 0));
    return vec;
}
vector<string> v1init(int len){
    vector<string> vec(vector<string>(len, ""));
    return vec;
}
template <typename T>
T v1sum(vector<T> vec){
    T ret = 0;
    for(int i = 0; i < vec.size(); i++) ret += vec[i];
    return ret;
}
template <typename T>
vector<T> v1sort(vector<T> vec, bool min_to_max=true){
    sort(vec.begin(), vec.end(), [min_to_max](const T a, const T b){return (min_to_max == true) ? (a < b) : (b < a);});
    return vec;
}
template <typename T>
void v1show(vector<T> vec){
    for(int i = 0; i < vec.size(); i++){
        cout << vec[i] << " ";
    }
    cout << endl;
}
template <typename T>
vector<vector<T> > v2init(int y_len, int x_len){
    vector<vector<T> > vec(y_len, vector<T>(x_len, 0));
    return vec;
}
template <typename T>
vector<vector<T> > v2sort(vector<vector<T> > vec, int index){
    sort(vec.begin(), vec.end(), [index](const vector <T>  a, const vector <T> b){return (a[index] > b[index]);});
    return vec;
}
template <typename T>
void v2show(vector<vector<T> > vec){
    for(int i = 0; i < vec.size(); i++){
        for(int j = 0; j < vec[0].size(); j++){
            cout << vec[i][j] << " ";
        }
        cout << endl;
    }
}
int main(){
    int N, M;
    cin >> N >> M;
    auto a = v1init<ll>(N);
    rep(i, N){
        cin >> a[i];
    }
    auto vec = v2init<ll>(M, 2);
    rep(i, M){
        cin >> vec[i][0] >> vec[i][1];
    }
    vec = v2sort(vec, 1);
    a = v1sort(a, false);
    ll tmpmax = 0;
    ll tmpnum = 0;
    ll ans = 0;
    int is_end = 0;
        rep(i, M){
            rep(j, vec[i][0]){
                if(a[tmpmax] < vec[i][1] || tmpmax >= N){
                    tmpnum++;
                    ans += vec[i][1];
                }else{
                    tmpnum++;
                    ans += a[tmpmax];
                    tmpmax++;
                    j--;
                }
                //cout << ans << " " << tmpnum << " " << tmpmax << endl;
                if(tmpnum == N){
                    is_end = 1;
                    break;
                }
            }
            if(is_end == 1){
                break;
            }
        }
    for(int i = tmpnum; i < N; i++){
        ans += a[tmpmax];
        tmpmax++;
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

int main ()
{
  int N,M,k,s;
  cin>>N>>M;
  if(N>=2)
  {
    k=N*(N-1);
  }
  else
  {
    k=0;
  }
  if(M>=2)
  {
    s=M*(M-1);
  }
  else
  {
    s=0;
  }
  cout<<(k+s)/2<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	int n;
	int x;
	int sum=0;
  cin>>n;
	for(int i=1;i<=n;++i)
	{
		cin>>x;
     // cout<<x;
		if(x!=i)
        {
          sum++;
        }
	}
  //cout<<sum;
	if(sum<=2)
		cout<<"YES";
	else
		cout<<"NO";
}

Measured memory_bytes: 256
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.InputMismatchException;
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) {

			long x = in.nextLong(), y = in.nextLong();
			long k = 0;
			while (x * 1 << k <= y) {
				k++;
			}
			out.println(k);

		}
	}

	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: 23252
import math

l = int(input())

n = int(math.log2(l)) + 1
g = []

for i in range(1, n):
    g.append([i, i + 1, 2**(n - i - 1)])
    g.append([i, i + 1, 0])
    
s = 2**(n - 1)

while l > s:
    t = n - int(math.log2(l - s))
    g.append([1, t, s])
    s += 2**int(math.log2(l - s))
    
print(n, len(g))
for i in range(0, len(g)):
    print(" ".join(list(map(str, g[i]))))

Measured memory_bytes: 3064
// tsukasa_diary's programing contest code template
#include <bits/stdc++.h>
using namespace std;
// define
#define for_(i,a,b) for(int i=a;i<b;++i)
#define for_rev(i,a,b) for(int i=a;i>=b;--i)
#define allof(a) a.begin(),a.end()
#define minit(a,b) memset(a,b,sizeof(a))
#define size_of(a) (int)a.size()
// typedef
typedef long long lint;
typedef double Double;
typedef pair<int, int> pii;
//
typedef vector< int > Array;
typedef vector< Array > Matrix;
typedef vector< Double > DArray;
typedef vector< DArray > DMatrix;
typedef vector< string > SArray;
typedef vector< pii > PArray;
// popcount
inline int POPCNT(int _x) { return __builtin_popcount(_x); }
inline int POPCNT(lint _x) { return __builtin_popcountll(_x); }
// inf
const int iINF = 1L << 30;
const lint lINF = 1LL << 60;
// eps
Double EPS = 1e-9;
// in range
inline bool in_range(int _v, int _mx, int _mi) { return _mi <= _v && _v < _mx; }
inline bool in_range(Double _v, Double _mi, Double _mx) { return -EPS < _v - _mi && _v - _mx < EPS; }
inline bool in_range(int _x, int _y, int _W, int _H) { return 0 <= _x && _x < _W && 0 <= _y && _y < _H; }
// neighbor clockwise
const int DX[4] = {0,1,0,-1}, DY[4] = {-1,0,1,0};
const int DX_[8] = {0,1,1,1,0,-1,-1,-1}, DY_[8] = {-1,-1,0,1,1,1,0,-1};
// variable update
inline void modAdd(int& _a, int _b, int _m) { _a = (_a + _b) % _m; }
inline void modAdd(lint& _a, lint _b, lint _m) { _a = (_a + _b) % _m; }
inline void minUpdate(int& _a, int _b) { _a = min(_a, _b); }
inline void minUpdate(lint& _a, lint _b) { _a = min(_a, _b); }
inline void maxUpdate(int& _a, int _b) { _a = max(_a, _b); }
inline void maxUpdate(lint& _a, lint _b) { _a = max(_a, _b); }

int H, W;
string grid[555];

struct Point {
	int x, y;
	Point(int _x, int _y) : x(_x), y(_y) {}
};

vector< vector< Point > > vvp;

bool is_able(int x, int y, int gx, int gy, int d, bool flp) {
	if (!in_range(x, y, W, H)) return false;
	if (grid[y][x] != '.' && grid[y][x] != grid[gy][gx]) return false;
	if (x == gx && y == gy) return true;
	
	if (is_able(x + DX[d], y + DY[d], gx, gy, d, flp)) return true;
	if (flp && is_able(x + DX[(d + 1) % 4], y + DY[(d + 1) % 4], gx, gy, (d + 1) % 4, false)) return true;
	if (flp && is_able(x + DX[(d + 3) % 4], y + DY[(d + 3) % 4], gx, gy, (d + 3) % 4, false)) return true;
	
	return false;
}

void solve() {
	vvp.assign(26, vector< Point >());
	
	for_(y,0,H) for_(x,0,W) {
		if (grid[y][x] != '.') {
			int id = grid[y][x] - 'A';
			vvp[id].push_back(Point(x, y));
		}
	}
	
	int ans = 0;
	
	for_(rep,0,26) {
		for_(i,0,26) {
			if (size_of(vvp[i]) == 0) continue;
			Point p1 = vvp[i][0], p2 = vvp[i][1];
			
			if (p1.x == p2.x && p1.y + 1 == p2.y) continue;
			if (p1.y == p2.y && p1.x + 1 == p2.x) continue;
			
			bool flag = false;
			for_(d,0,4) flag |= is_able(p1.x, p1.y, p2.x, p2.y, d, true);

			if (flag) {
				grid[p1.y][p1.x] = grid[p2.y][p2.x] = '.';
				ans += 2;
				vvp[i].clear();
			}
		}
	}
	
	cout << ans << endl;
}

int main() {
	cin >> H >> W;
	for_(i,0,H) cin >> grid[i];
	solve();	
	return 0;
}

Measured memory_bytes: 1568
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<queue>
#include<functional>
#include<map>
#include<set>
#include<cstring>
#include<string>
#include<stack>
#include<stdlib.h>
#include<math.h>
using namespace std;
#define int long long
typedef pair<int, int> pii;
typedef pair<int, char> pic;
typedef priority_queue<pii, vector<pii>, greater<pii> > RPQ;
#define mk make_pair
#define INF (1ll << 30ll)
#define INFL (1ll << 60ll)
#define mod 1000000007

int N, Q, a[100100], x[100100];

signed main(){
    cin >> N >> Q;
    for(int i = 0; i < N; i++){
        cin >> a[i];
    }
    for(int i = 0; i < Q; i++){
        cin >> x[i];
    }
    for(int i = 0; i < Q; i++){
        int ans = 0;
        int l = 0, r = 0, s = 0;
        for(r = 0; r < N; r++){
            s += a[r];
            while(s > x[i] && l <= r){
                s -= a[l++];
            }
            ans += (r - l + 1);
        }
        cout << ans << endl;
    }

    return 0;
}

/*


*/


Measured memory_bytes: 3868
#include <iostream>
#include <vector>
#include <queue>

//幅優先探索
class Point{
private:
  int x;//x座標
  int y;//y座標
  int depth;//深さ

public:
  Point(int a,int b);
  int GetXpoint();
  int GetYpoint();
  int GetDepth();
  std::vector<Point> make_offspring(int x_limit,int y_limit,std::vector<Point> exception);

};

void search();

std::vector<Point> get_exception(int exception_num);//通行できない点を求める。

int get_root_num(int x_limit,int y_limit,std::vector<Point> exception);//通学経路の個数を求める。

bool judge_point(int depth1,int depth2);//深さでその点が目的地かどうかを判断する。

Point::Point(int a,int b){
  this->x= a;
  this->y=b;
  this->depth=a+b-2;
}

int Point::GetXpoint(){
  return this->x;
}

int Point::GetYpoint(){
  return this->y;
}

int Point::GetDepth(){
  return this->depth;
}

std::vector<Point> Point::make_offspring(int x_limit,int y_limit,std::vector<Point> exception){
  std::vector<Point> offsprings;
  if(x_limit>= (this->x+1)){
    Point tmp= Point(this->x+1,this->y);
    bool flag = true;
    for(Point tmp1:exception){
      if(tmp1.GetXpoint()==tmp.GetXpoint() &&tmp1.GetYpoint()==tmp.GetYpoint()){
        flag = false;
        break;
      }
    }
    if(flag == true){
      offsprings.push_back(tmp);
    }
  //  std::cout<<this->x<<","<<this->y<<" x  "<<tmp.GetXpoint()<<","<<tmp.GetYpoint();
  }

  if(y_limit>=(this->y+1)){
    Point tmp= Point(this->x,this->y+1);
    bool flag = true;
    for(Point tmp1: exception){
      if(tmp1.GetXpoint()==tmp.GetXpoint() &&tmp1.GetYpoint()==tmp.GetYpoint()){
        flag = false;
        break;
      }
    }
    if(flag == true){
      offsprings.push_back(tmp);
    }
  //  std::cout<<"  y  "<<tmp.GetXpoint()<<" "<<tmp.GetYpoint()<<std::endl;
  }

  return offsprings;
}

void search(){
  int x_limit,y_limit;//x座標,y座標の上限

  while(std::cin >> x_limit >> y_limit && x_limit!=0 && y_limit!=0){
    int exception_num;
    std::cin >> exception_num;
    std::vector<Point> exception = get_exception(exception_num);
    std::cout << get_root_num(x_limit,y_limit,exception)<<std::endl;
  }
}

std::vector<Point> get_exception(int exception_num){
  std::vector<Point> exception;
  for(int i = 0;i< exception_num;i++){
    int x,y;
    std::cin>>x>>y;
    Point tmp=Point(x,y);
    exception.push_back(tmp);
  }

  return exception;
}

int get_root_num(int x_limit,int y_limit,std::vector<Point> exception){
  std::queue<Point> que;
  int num=0;
  Point start = Point(1,1),end=Point(x_limit,y_limit);
  que.push(start);
  while(que.empty() != true){
    Point tmp = que.front();
    que.pop();
    if(judge_point(tmp.GetDepth(),end.GetDepth() ) ){
      //std::cout<<num+1<<" "<<tmp.GetXpoint()<<" "<<tmp.GetYpoint()<<std::endl;
      num ++ ;
    }else{
      std::vector<Point> offsprings = tmp.make_offspring(x_limit,y_limit,exception);
      if(!offsprings.empty()){
        for(Point tmp_child:offsprings){
          que.push(tmp_child);
        }
      }
    }
  }
  return num;
}

bool judge_point(int depth1,int depth2){
  if(depth1== depth2){
    return true;
  }
  return false;
}

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



Measured memory_bytes: 12144
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
typedef unsigned int uint;
using namespace std;

int main() {
    cin.sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int n, k;
    cin >> n >> k;

    if (n >= 2 * k - 1) {
        cout << "YES\n";
    } else {
        cout << "NO\n";
    }

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    
    StringBuilder sb = new StringBuilder();
    for(int i=0;i<s.length();i++){
      switch(s.charAt(i)){
        case '1':
          sb.append('1');break;
        case '0':
          sb.append('0');break;
        case 'B':
          if(sb.length()>=1){
            sb.setLength(sb.length()-1);
          }
          break;
      }
    }
    System.out.print(sb.toString());
    System.out.flush();
  }
}


Measured memory_bytes: 21844
import java.util.Scanner;
public class Main {
	public static void main(String args[]) {
		Scanner scan = new Scanner(System.in);
		String str = scan.nextLine();
		
		String[] strAry = str.split(" ");
		int int1 = Integer.parseInt(strAry[0]);
		int int2 = Integer.valueOf(strAry[1]).intValue();
		
		int i = 0;
		boolean b = true;
		while(b) {
			if(int1 <Math.pow(int2, i)){
				System.out.println(i);
				b = false;
			}
			i++;
		scan.close();
		}
		
	
		
	}

}


Measured memory_bytes: 23892
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <vector>

typedef long long ll;
using namespace std;

ll Mod = 1e9 + 7;
int main()
{
    int a, b;
    cin >> a >> b;

    if (a%3 == 0 || b%3 == 0 || (a+b)%3 == 0) cout << "Possible" << endl;
    else cout << "Impossible" << endl;

    return 0;
}

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

struct Mod
{
    static const auto P = 3;
    int k;

    Mod() = default;
    Mod(const int k) : k(k%P >= 0 ? k%P : k%P + P) {}
};

Mod operator+(const Mod a, const Mod b) { return a.k + b.k; }
Mod operator-(const Mod a, const Mod b) { return a.k - b.k; }
bool operator==(const Mod a, const Mod b) { return a.k == b.k; }

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

    string S, T; cin >> S >> T;

    auto prefix_S = vector<Mod>(S.size() + 1);
    for (auto i = 1; i <= int(S.size()); i++)
        prefix_S[i] = prefix_S[i-1] + (S[i-1] == 'A' ? 1 : -1);

    auto prefix_T = vector<Mod>(T.size() + 1);
    for (auto i = 1; i <= int(T.size()); i++)
        prefix_T[i] = prefix_T[i-1] + (T[i-1] == 'A' ? 1 : -1);

    int Q; cin >> Q;
    for (auto q = 0; q < Q; q++)
    {
        int a, b, c, d; cin >> a >> b >> c >> d;
        cout << (prefix_S[b] - prefix_S[a-1] == prefix_T[d] - prefix_T[c-1] ? "YES" : "NO") << "\n";
    }
}


Measured memory_bytes: 1744