akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define si scanf
#define so printf
#define N 110
#define M 
#define INF  
template<typename TP>inline bool rd(TP& r)
{
	r=0;
	char tmp=getchar();
	while(tmp<'0'||tmp>'9')
	{
		if(tmp==EOF)
			return 0;
		tmp=getchar();
	}
	while('0'<=tmp&&tmp<='9')
	{
		r=(r<<3)+(r<<1)+tmp-'0';
		tmp=getchar();
	}
	return 1;
	
} 
int n;
char inn[N];
int in[N],s[N];
bool vis[30];
int ok(int c)
{
	memcpy(s,in,sizeof(in));
	bool all=0;
	all=1;
		for(int j=1;j<=n&&all;++j)
			if(s[j]!=c)
				all=0;
		if(all)
			return 0;
	for(int i=1;i<=n;++i)
	{
		for(int j=1;j<=n-i;++j)
			if(s[j]==c||s[j+1]==c)
				s[j]=c;
			else
				s[j]=s[j];
		all=1;
		for(int j=1;j<=n-i&&all;++j)
			if(s[j]!=c)
				all=0;
		if(all)
			return i;
	}
}
int main()
{
	si("%s",inn+1);
	n=strlen(inn+1);
	for(int i=1;i<=n;++i)
	{
		in[i]=inn[i]-'a'+1;
		vis[in[i]]=1;
	}
	int ans=10000000;
	for(int i=1;i<=26;++i)
		if(vis[i])
			ans=min(ok(i),ans);
	so("%d\n",ans);
	return 0;
} 

Measured memory_bytes: 256
import numpy as np
n = int(input())
s = list(input())
for i in range(n):
    if s[i] == 'E':
        s[i] = 0
    else:
        s[i] = 1
cs = np.cumsum(s)
minturn = n
for i in range(n):
    if i == 0:
        turn = n-cs[n-1]+cs[0]-1
    else:
        turn = cs[i-1]+n-i-cs[n-1]+cs[i]-1
    minturn = min(turn,minturn)
print(minturn)

Measured memory_bytes: 19984
package main

import (
	"fmt"
)

func main() {
	var a, b, c int
	fmt.Scan(&a, &b, &c)

	for i := 0; i < b; i++ {
		if a*i%b == c {
			fmt.Println("YES")
			return
		}
	}
	fmt.Println("NO")
}


Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<string>
#include<stack>
#include<cstdio>
#include<cmath>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<int,P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i,x) for(int i=0;i<x;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rrep1(i,x) for(int i=x;i>0;i--)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
#define mp1(a,b,c) P1(a,P(b,c))

const int INF=1000000000;
const int dir_4[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
const int dir_8[8][2]={{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};

int main(){
	int r,c;
	char a[32][32];
	scanf("%d%d",&r,&c);
	rep(i,32)rep(j,32)a[i][j] = '#';
	rep1(i,r){
		scanf("\n");
		rep1(j,c){
			scanf("%c",&a[i][j]);
		}
	}
	
	int sx,sy,gx,gy;
	rep1(i,r)rep1(j,c){
		if(a[i][j] == 'S'){ sx = i ; sy = j ; }
		if(a[i][j] == 'G'){ gx = i ; gy = j ; }
	}
	
	bool used[32][32];
	int d[32][32];
	priority_queue<P1,vector<P1>,greater<P1>> que;
	rep(i,32)rep(j,32){
		used[i][j] = false;
		d[i][j] = INF;
	}
	d[sx][sy] = 0;
	que.push( mp1 ( d[sx][sy] , sx , sy ) );
	
	while(!que.empty()){
		P1 p = que.top(); que.pop();
		//cout << p.fr << " " << p.sc.fr << " " << p.sc.sc << endl;
		if(p.sc.fr == gx && p.sc.sc == gy)break;
		if(!used[p.sc.fr][p.sc.sc]){
			rep(i,4){
				int nx = p.sc.fr + dir_4[i][0];
				int ny = p.sc.sc + dir_4[i][1];
				if(a[nx][ny] == 'o'){
					if(d[nx][ny] > d[p.sc.fr][p.sc.sc] + 1){
						d[nx][ny] = d[p.sc.fr][p.sc.sc] + 1;
						que.push( mp1 ( d[nx][ny] , nx , ny ) );
					}
				}
				else if(a[nx][ny] == '.' || a[nx][ny] == 'G'){
					if(d[nx][ny] > d[p.sc.fr][p.sc.sc] + 2){
						d[nx][ny] = d[p.sc.fr][p.sc.sc] + 2;
						que.push( mp1 ( d[nx][ny] , nx , ny ) );
					}
				}
			}
			rep(i,4){
				int nx = p.sc.fr; int ny = p.sc.sc;
				rep1(j,3){
					nx += dir_4[i][0];
					ny += dir_4[i][1];
					if(a[nx][ny] == '#')break;
					if(d[nx][ny] > d[p.sc.fr][p.sc.sc] + 2+j){
						d[nx][ny] = d[p.sc.fr][p.sc.sc] + 2+j;
						que.push( mp1 ( d[nx][ny] , nx , ny ) );
					}
				}
			}
			used[p.sc.fr][p.sc.sc] = true;
		}
	}
	
	cout << d[gx][gy] << endl;
}

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

int main(){
  int A,B,C;
  cin >>A >> C >> B;
  int m=min(A,C);
  int M=max(A,C);
  if(m<=B && B<=M){cout << "Yes" << endl;}
  else{cout << "No" << endl;}
}

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

// 各桁の和を計算する関数
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

int main() {
  int N, A, B;
  cin >> N >> A >> B;
  int total = 0;
  for (int i = 1; i <= N; ++i) {
    int sum = findSumOfDigits(i); // i の各桁の和
    if (sum >= A && sum <= B) { //  i の各桁の和が A 以上 B 以下かどうか
      total += i;
    }
  }
  cout << total << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#ifdef _DEBUG_
	#define debug(...) printf(__VA_ARGS__)
#else
	#define debug(...) (void)0
#endif
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;

int main() {
	string S;
	cin >> S;
	puts(SZ(S) >= 4 && S.substr(0, 4) == string("YAKI") ? "Yes" : "No");
	return 0;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,c) for (int i = 0; i < (int)c; i++)
#define all(v) v.begin(), v.end()
const int inf = 1000000000; //10^9
using ll = long long;
using P = pair<int,int>;
//加算代入演算子は+=！！！！！
//int 2^31 10^9まで
int main() {
    int a, b;
    char op;
    cin >> a >> op >> b;
    if (op == '+') cout << a + b << endl;
    else cout << a - b << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " is " << x << endl

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef V<int> vi;

const int INF = 1e9 + 7;

ld p[3000], dp[3000][3000];

signed main()
{
	IO_OP;
	
	int n;
	cin >> n;
	for(int i=0;i<n;i++) cin >> p[i];
	dp[0][0] = 1 - p[0], dp[0][1] = p[0];
	for(int i=1;i<n;i++) {
		dp[i][0] = (1 - p[i]) * dp[i-1][0];
		for(int j=1;j<=i+1;j++) {
			dp[i][j] = dp[i-1][j] * (1 - p[i]) + dp[i-1][j-1] * p[i];
		}
	}
	ld ans = 0;
	for(int i=n/2+1;i<=n;i++) ans += dp[n-1][i];
	cout << fixed << setprecision(10) << ans << endl;
}





Measured memory_bytes: 139008
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

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

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

  ll W, H, x, y;
  cin >> W >> H >> x >> y;

  ll area = W * H;
  cout << fixed << setprecision(6) << (double)(area / 2.0) << " ";

  if (x == W / 2.0 && y == H / 2.0) {
    cout << 1 << endl;
  } else {
    cout << 0 << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define clr(x) memset(x, 0, sizeof(x))
#define sz(x) (int)x.size()

using namespace std;

typedef long long ll;
typedef pair<long , long> pll;

const ll mx = 105;
const ll maxn = 1000001;
const ll mod = 1000000007;

vector<vector<int>> adj;
vector<int> res;
vector<int> ord;


int main(){

   ios_base::sync_with_stdio(false);
   cin.tie(0);
   
    ll n, i ,j , k;
    
    cin>>k>>n;

    ll a[n];

    for(i =0 ;i < n;i++)
     cin>>a[i];

    ll res = a[n-1]-a[0]; 

    for(i = 1;i < n;i++){
        ll cur = k-a[i];

        cur += a[i-1];
        res = min(cur, res);
    }
    cout<<res<<"\n";

}




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

int main()
{
    int n;
    cin >> n;
    ll ans = 0;
    int prev = 0;
    while (n--)
    {
        int a;
        cin >> a;
        if (a < prev)
            ans += prev - a;
        prev = max(a, prev);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3564
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
using namespace std;

typedef istringstream ISS;
typedef ostringstream OSS;
typedef vector<string> VS;
typedef int INT;
typedef vector<INT> VI;
typedef vector<VI> VVI;
typedef pair <INT, INT> II;
typedef vector <II> VII;


typedef pair <int, II> STATE; 
typedef pair <int, STATE> NODE; 
typedef priority_queue <NODE, vector<NODE>, greater<NODE> > QUEUE;
typedef map <STATE, int> MIN_COST;
typedef set<II> HASH;
const int OBJECT_NUMBER = 1001;
const int MOD = 6;
const int NONE = -1;

const int dr[2][7] = {
    { 1, 0, -1, -1, -1, 0, 0 },
    { 1, 1, 0, -1, 0, 1, 0 }
};
const int dc[2][7] = {
    { 0, 1, 1, 0, -1, -1, 0 },
    { 0, 1, 1, 0, -1, -1, 0 }
};

int sr, sc, gr, gc; 
int n;
int R[OBJECT_NUMBER]; 
int C[OBJECT_NUMBER];
int H, W; 

MIN_COST MC; 
QUEUE Q;
HASH OBJ;

void init() {
    OBJ.clear();
    for ( int i = 0; i < n; ++ i ) {
        OBJ.insert( II( R[i], C[i] ) );
    }
}

bool input() {
    if ( ! ( cin >> sc >> sr >> gc >> gr ) ) return false;
    cin >> n;
    for ( int i = 0; i < n; ++ i ) {
        cin >> C[i] >> R[i];
    }
    cin >> W >> H;
    return true;
}

bool is_min_cost( int cost, STATE state ) {
    return MC.count(state) ? cost < MC[state] : true;
}

int solve() {
    Q = QUEUE();
    MC.clear();
    STATE start_state( 0, II( sr, sc ) );
    Q.push( NODE( 0, start_state ) );
    MC[start_state] = 0;

    while ( ! Q.empty() ) {
        NODE node = Q.top();
        Q.pop();

        int cost = node.first;
        int steps = node.second.first;
        int r = node.second.second.first;
        int c = node.second.second.second;

        if ( r == gr && c == gc ) return cost;

        for ( int i = 0; i < 7; ++ i ) {
            int free_dir = abs( r * c * steps ) % MOD;
            int new_cost = cost + ( i == free_dir ? 0 : 1 );
            
            int d_type = c % 2 == 0 ? 0 : 1;
            int nr = r + dr[d_type][i];
            int nc = c + dc[d_type][i];
            II new_pos( nr, nc );
            if ( abs(nr) > H || abs(nc) > W ) continue;
            if ( OBJ.count( new_pos ) ) continue;
            
            int new_steps = ( steps + 1 ) % MOD;
            STATE new_state( new_steps, new_pos );
            if ( ! is_min_cost( new_cost, new_state ) ) continue;
            MC[new_state] = new_cost;
            
            Q.push( NODE( new_cost, new_state ) );
        }
    }

    return NONE;
}

int main() {
    while ( input() ) {
        init();
        cout << solve() << endl;
    }
    return 0;
}

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

int main() {

	int n, m;
	cin >> n >> m;
	
	priority_queue<pair<int, int> > jobs;
	
	for (int i=0; i<n; i++) {
		int deadline, reward;
		cin >> deadline >> reward;
		jobs.push(make_pair(m-deadline, reward));
	}
	
	priority_queue<pair<int, int> > tasks;
	
	int total = 0;
	
	for (int day = m; day >= 0; day--) {
		// cout << "day: " << day << endl;
		while (jobs.size() > 0 && jobs.top().first >= day) {
			// cout << " > av: " << jobs.top().first << " " << jobs.top().second << endl;
			tasks.push(make_pair(jobs.top().second, jobs.top().first));
			jobs.pop();
		}
		if (tasks.size() == 0) continue;
		total += tasks.top().first;
		tasks.pop();
	}
	
	cout << total << endl;
	
	
	
}


Measured memory_bytes: 2548
using System;

public class Program
{

    public void Solve()
    {
        var sc = new Scanner();
        int H = sc.NextInt();
        int A = sc.NextInt();
        
        Console.WriteLine((H+A-1)/A);
    }

    public static void Main(string[] args)
    {
        new Program().Solve();
    }
}

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

    const char Separator = ' ';
    private int _pos;
    private string[] _line;

    #region スペース区切りで取得

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

        return _line[_pos++];
    }

    public int NextInt()
    {
        return int.Parse(Next());
    }

    public long NextLong()
    {
        return long.Parse(Next());
    }

    public double NextDouble()
    {
        return double.Parse(Next());
    }

    #endregion

    #region 型変換

    private int[] ToIntArray(string[] array)
    {
        var result = new int[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = int.Parse(array[i]);
        }

        return result;
    }

    private long[] ToLongArray(string[] array)
    {
        var result = new long[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = long.Parse(array[i]);
        }

        return result;
    }

    private double[] ToDoubleArray(string[] array)
    {
        var result = new double[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = double.Parse(array[i]);
        }

        return result;
    }

    #endregion

    #region 配列取得

    public string[] Array()
    {
        if (_pos >= _line.Length)
            _line = Console.ReadLine().Split(Separator);

        _pos = _line.Length;
        return _line;
    }

    public int[] IntArray()
    {
        return ToIntArray(Array());
    }

    public long[] LongArray()
    {
        return ToLongArray(Array());
    }

    public double[] DoubleArray()
    {
        return ToDoubleArray(Array());
    }

    #endregion
}

Measured memory_bytes: 13012
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <set>
#include <map>
#include <queue>
#include <vector>
#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
#define eps 1e-8
#define mp make_pair
#define np next_permutation
#define pb push_back
#define all(x) (x.begin(),x.end())
#define rep(i,a,n) for(int i=a;i<n;++i)
#define per(i,a,n) for(int i=n-1;i>=a;--i)
#define ms(x,a) memset((x),a,sizeof(x))
#define fi first
#define se second 
using namespace std;
const int maxn=1e5+5;
const int maxl=26;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pii;


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

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

int main() {
  int n;
  cin >> n;
  vector<int> p(n);
  for (int i = 0; i < n; i++) cin >> p[i];
  int ans = 0;
  for (int i = 0; i < n-2; i++) {
    if (p[i] < p[i+1] && p[i+1] < p[i+2]) ans++;
    else if (p[i] > p[i+1] && p[i+1] > p[i+2]) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
# from math import factorial,sqrt
# from itertools import permutations as permus
# from fractions import gcd
# from collections import deque,Counter
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np
# import scipy as scp

# 入力の受け取り
n = int(input())
arrA = list(map(int,input().split()))

ans = "Yes"
minH = arrA[0]-1
for i in arrA:
    if i-1 >= minH:
        minH = max(minH,i-1)
    elif i >= minH:
        minH = max(minH,i)
    else:
        ans = "No"
        break

print(ans)
# print("{:.10f}".format(ans))
# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する



Measured memory_bytes: 14252
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int*a=new int[n];
    for(int i=0;i<n;i++)
    cin>>a[i];
    int* dp=new int[n];
    for(int i=0;i<n;i++)
    dp[i]=INT_MAX;
    dp[n-1]=0;
    dp[n-2]=abs(a[n-1]-a[n-2]);
    for(int i=n-3;i>=0;i--)
    {
        dp[i]=min(abs(a[i]-a[i+1])+dp[i+1],abs(a[i]-a[i+2])+dp[i+2]);
    }
    cout<<dp[0];
}


Measured memory_bytes: 1024
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container, std.format;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] lreads(T = long)(long n){return generate(()=>readln.chomp.to!T()).take(n).array();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on

void main()
{
    long H, W;
    scan(H, W);
    auto A = new string[](H);
    foreach (i; 0 .. H)
        A[i] = sread();
    string[] B;
    foreach (i; 0 .. H)
        if (A[i].any!"a == '#'")
        {
            B ~= A[i];
        }
    auto C = new string[](B.length);
    foreach (i; 0 .. W)
    {
        bool b;
        foreach (j; 0 .. B.length)
            if (B[j][i] == '#')
            {
                b = true;
                break;
            }
        if (b)
            foreach (j; 0 .. B.length)
            {
                C[j] ~= B[j][i];
            }
    }
    foreach (c; C)
        writeln(c);
}


Measured memory_bytes: 380
#include<bits/stdc++.h>
#define re register
using namespace std;

inline int read() {
    int X=0,w=1; char c=getchar();
    while (c<'0'||c>'9') { if (c=='-') w=-1; c=getchar(); }
    while (c>='0'&&c<='9') X=X*10+c-'0',c=getchar();
    return X*w;
}

const int N=100000+10;
const int mod=1e9+7;

int n,m,cnt,top;
int a[N],b[N],S[N];
pair<int,int> p[N];
int f[N];

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

int c[N];
inline int lowbit(int x) { return x&-x; }
inline int query(int x) { int res=0;
    for (;x;x-=lowbit(x)) res=(res+c[x])%mod;
    return res;
}
inline void add(int x,int y) {
    for (;x<=top;x+=lowbit(x)) c[x]=(c[x]+y)%mod;
}

int main() {
    n=read(),m=read();
    for (re int i=1;i<=n;++i) a[i]=read();
    for (re int i=1;i<=m;++i) b[i]=read();
    for (re int i=1;i<=n;++i) {
        if (a[i]<=b[1]||a[i]>=b[m]) continue;
        int x=lower_bound(b+1,b+m+1,a[i])-b;
        if (b[x]==a[i]) continue;
        p[++cnt]=make_pair(a[i]-b[x-1],b[x]-a[i]);
        S[++top]=b[x]-a[i];
    }
    sort(S+1,S+top+1); top=unique(S+1,S+top+1)-S-1;
    for (re int i=1;i<=cnt;++i)
        p[i].second=lower_bound(S+1,S+top+1,p[i].second)-S;
    sort(p+1,p+cnt+1,cmp); cnt=unique(p+1,p+cnt+1)-p-1;
    f[0]=1;
    for (re int i=1;i<=cnt;++i)
        f[i]=query(p[i].second-1)+1,add(p[i].second,f[i]);
    int ans=0;
    for (re int i=0;i<=cnt;++i) ans=(ans+f[i])%mod;
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 2688
#include <iostream>
#include <deque>
#include <utility>
using namespace std;
typedef pair<int, int> vertex; //pair<頂点番号, 距離>

long long int solve(long long int k);
int main(){
  int k; cin >> k;
  cout << solve(k) << endl;

  return 0;
}

long long int solve(long long int k){
  bool visited[k];
  for(int i=0; i<k; i++) visited[i]=false;

  deque<vertex> dq;  dq.push_front(vertex(1, 1));
  visited[1]=true;

  long long int ans;
  while(!dq.empty()){
    //dequeueの先頭をポップし、それが頂点0なら終了
    vertex now = dq.front(); dq.pop_front();
    int cur = now.first, cnt = now.second;
    if(cur==0) return cnt;

    visited[cur]=true;

    //0方向の遷移
    int next= (cur*10)%k;
    if(!visited[next]){
      dq.push_front(vertex(next, cnt));
    }

    //1方向の遷移
    next = (cur+1)%k;
    if(!visited[next]){
      dq.push_back(vertex(next, cnt+1));
    }
  }
}


Measured memory_bytes: 896
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int main()
{
    #ifdef LOCAL_DEBUG
    freopen("text.in","r",stdin);
    freopen("text.out","w",stdout);
    #endif // LOCAL_DEBUG
    int n;
    cin>>n;
    int a=n/100;
    int b=(n/10)%10;
    int c=n%10;
    if(a==b && b==c)
        cout<<n<<endl;
    else
    {
        if(b>a)
            cout<<(a+1)*100+(a+1)*10+(a+1)<<endl;
        else
            if(c>a)
                cout<<(a+1)*100+(a+1)*10+(a+1)<<endl;
            else
                cout<<a*100+a*10+a<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
using namespace std;
#define lint long long int
/*
vector<char>al(26);
al = {'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'};
vector<char>AL(26);
AL = {'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'};
*/



int main() {
	string S;
	cin >> S;
	if (S == "SUN") {
		cout << 7 << endl;
	}
	else if (S == "MON") {
		cout << 6 << endl;
	}
	else if (S == "TUE") {
		cout << 5 << endl;
	}
	else if (S == "WED") {
		cout << 4 << endl;
	}
	else if (S == "THU") {
		cout << 3 << endl;
	}
	else if (S == "FRI") {
		cout << 2 << endl;
	}
	else if (S == "SAT") {
	cout<<1<<endl;
}
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<string>
#include<unordered_map>
#include<set>
using namespace std;

#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j,k
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define sort(a) sort(a.begin(),a.end())
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define sizeoof(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
llfor;///////////////////////////////////////////////////////////
int main(){
 ll n;
 sc(n);
 vector<ll>a;
 ll b;
 rep(i,0,n){
   sc(b);push(a,b);
 }
 sort(a);
 reverse(a.begin(),a.end());
 ll ans=a[0];ll cnt=2;
 rep(i,1,n-1){
  ans+=a[i];cnt++;
  if(cnt==n)break;
  ans+=a[i];cnt++;
  if(cnt==n)break;
 }
 pr(ans);
  
return 0;}

Measured memory_bytes: 5360
n = int(input())
city = list(map(int,input().split(' ')))
hero = list(map(int,input().split(' ')))

ans = 0
for i, ihero in enumerate(hero):
    point = hero[i]
    imonster =city[i]
    i1monster =city[i+1]
    
    if point > imonster:
        point= point - imonster
        ans += imonster
        imonster=0
    if point <= imonster:
        ans +=point
        imonster -= point
        point = 0
    if n ==1:
        break
    
    if point > i1monster:
        point= point - i1monster
        ans += i1monster
        i1monster=0
    if point <= i1monster:
        ans +=point
        i1monster -= point
        point = 0
    city[i] =imonster
    city[i+1] =i1monster    
    

print(ans)
            

Measured memory_bytes: 18752
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { 0, -1, 1, 0 };
const ll dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
void mul(ll a, ll b) {
	a = a * b % INF;
}
using Graph = vector<vector<int>>;
ll mypow(ll x, ll n, ll m) {
	if (n == 0) {
		return 1;
	}
	if (n % 2 == 0) {
		return mypow(x*x%m, n / 2, m);
	}
	else {
		return x * mypow(x, n - 1, m) % m;
	}
}
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
const int MAX = 510000;
ll fac[MAX], finv[MAX], inv[MAX];
//テーブルをつくる前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;//mod pにおける1,2,,,nの逆元
	for (int i = 2; i < MAX; ++i) {
		fac[i] = fac[i - 1] * i%INF;
		inv[i] = INF - inv[INF%i] * (INF / i) % INF;
		finv[i] = finv[i - 1] * inv[i] % INF;
	}
}

ll COM(int n, int k) {
	if (n < k)return 0;
	if (n < 0 || k < 0)return 0;
	return fac[n] * (finv[k] * finv[n - k] % INF) % INF;
}
///////////////////////////////////////


int main() {
	string s; int q;
	cin >> s >> q;
	int key = 0;
	vector<char>l, r;
	REP(i, q) {
		int a; cin >> a;
		if (a == 1) {
			if (key)key = 0;
			else key = 1;
		}
		else {
			int f; char q;
			cin >> f >> q;
			if (f == 1) {
				if (key) {
					r.push_back(q);
				}
				else {
					l.push_back(q);
				}
			}
			else {
				if (key) {
					l.push_back(q);
				}
				else {
					r.push_back(q);
				}
			}
		}
	}
	reverse(l.begin(), l.end());
	string ans = "";
	if (l.size()) {
		REP(i, l.size()) {
			ans += l[i];
		}
	}
	ans += s;
	if (r.size()) {
		REP(i, r.size()) {
			ans += r[i];
		}
	}
	if (!key) {
		cout << ans << endl;
	}
	else {
		reverse(ans.begin(), ans.end());
		cout << ans<< endl;
	}
	return 0;
}


Measured memory_bytes: 1368
require 'set'
 
class Arrow
  attr_reader :source, :sink, :label

  def initialize(source, sink, label)
    @source = source
    @sink = sink
    @label = label
  end
end

def push(queue, key)
  size = queue.size
  index = queue.index{|target, _| target >= key} || size

  return queue[index][1] if index < size && queue[index][0] == key
  return nil if index > 0 && !key.start_with?(queue[index - 1][0])
  queue.slice!(index..-1) if index < size && !queue[index][0].start_with?(key)

  value = {}
  queue.insert(index, [key, value])
  value
end

def calc(n, arrows, start, goal)
  ins = Array.new(n){[]}
  arrows.each do |arrow|
    ins[arrow.sink] << arrow.source
  end

  reachable_from = {}
  stack = [goal]
  until stack.empty?
    node = stack.pop
    reachable_from[node] = true
    ins[node].each do |source|
      stack << source unless reachable_from[source]
    end
  end

  return nil unless reachable_from[start]
  arrows.select!{|arrow| reachable_from[arrow.sink]}

  outs = Array.new(n){[]}
  arrows.each do |arrow|
    outs[arrow.source] << arrow
  end

  max = n * arrows.map{|arrow| arrow.label.size}.max

  queue = [['', {start => true}]]
  until queue.empty?
    spell, map = queue.shift
    return spell if map[goal]

    return nil if spell.size > max

    map.each do |node, _|
      outs[node].each do |arrow|
        t = push(queue, spell + arrow.label)
        t[arrow.sink] = true if t
      end
    end
  end
  nil
end

loop do
  n, a, s, g = gets.split.map(&:to_i)
  break if n == 0

  arrows = (0...a).map do |i|
    x, y, lab = gets.split
    Arrow.new(x.to_i, y.to_i, lab)
  end

  puts calc(n, arrows, s, g) || 'NO'
end

Measured memory_bytes: 10960
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
const ll LINF=0x1fffffffffffffff;
const int INF=0x3fffffff;
const int MOD=1000000007;
#define VAR(type,...) type __VA_ARGS__;in(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size);each(x, name)in(x)
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,a,b) for(int i=(a-1);i>=(b);--i)
#define each(x,v) for(auto &x:(v))
#define all(x) (x).begin(),(x).end()
#define print(x) cout<<(x)<<endl
void in(){} template<class T,class... U> void in(T &t,U &...u){cin>>t;in(u...);}
void solve();
int main(){cin.tie(0);ios::sync_with_stdio(0);solve();}

void solve() {
  VAR(int, W, H, N);
  vi X(N), Y(N), a(N);
  rep(i, 0, N) {
    in(X[i], Y[i], a[i]);
  }
  int l = 0;
  int r = W;
  int d = 0;
  int u = H;
  rep(i, 0, N) {
    switch(a[i]) {
      case 1: l = max(l, X[i]); break;
      case 2: r = min(r, X[i]); break;
      case 3: d = max(d, Y[i]); break;
      case 4: u = min(u, Y[i]); break;
    }
  }
  print(max(r - l, 0) * max(u - d, 0));
}


Measured memory_bytes: 256
S=input()
if S == S[::-1] and S[:int((len(S)-1)/2):] == S[:int((len(S)-1)/2):-1] and S[int((len(S)+1)/2)::]==S[len(S):int((len(S)-1)/2):-1]:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
using System;
using System.Collections.Generic;

public class Program
{
    public void Solve()
    {
        var sc = new Scanner();
        int N = sc.NextInt();
        int[] A = sc.IntArray();

        // 2個以上あるやつ
        var map = new HashMap<int, int>();
        foreach (int i in A)
        {
            map[i]++;
        }

        var two = new List<int>();
        var four = new List<int>();

        foreach (KeyValuePair<int, int> pair in map)
        {
            if (pair.Value >= 2) two.Add(pair.Key);
            if (pair.Value >= 4) two.Add(pair.Key);
        }
        
        two.Sort((a,b) => -a.CompareTo(b));
        four.Sort((a,b) => -a.CompareTo(b));

        long t = two.Count < 2 ? 0 : (long) two[0] * two[1];
        long f = four.Count < 1 ? 0 : (long) four[0] * four[0];
        Console.WriteLine(Math.Max(t,f));
    }

    public static void Main(string[] args)
    {
        new Program().Solve();
    }
}

class HashMap<K, V> : Dictionary<K, V>
{
    new public V this[K i]
    {
        get
        {
            V v;
            return TryGetValue(i, out v) ? v : base[i] = default(V);
        }
        set { base[i] = value; }
    }
}

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

    const char Separator = ' ';
    private int _pos;
    private string[] _line;

    #region スペース区切りで取得

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

        return _line[_pos++];
    }

    public int NextInt()
    {
        return int.Parse(Next());
    }

    public long NextLong()
    {
        return long.Parse(Next());
    }

    public double NextDouble()
    {
        return double.Parse(Next());
    }

    #endregion

    #region 型変換

    private int[] ToIntArray(string[] array)
    {
        var result = new int[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = int.Parse(array[i]);
        }

        return result;
    }

    private long[] ToLongArray(string[] array)
    {
        var result = new long[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = long.Parse(array[i]);
        }

        return result;
    }

    private double[] ToDoubleArray(string[] array)
    {
        var result = new double[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = double.Parse(array[i]);
        }

        return result;
    }

    #endregion

    #region 配列取得

    public string[] Array()
    {
        if (_pos >= _line.Length)
            _line = Console.ReadLine().Split(Separator);

        _pos = _line.Length;
        return _line;
    }

    public int[] IntArray()
    {
        return ToIntArray(Array());
    }

    public long[] LongArray()
    {
        return ToLongArray(Array());
    }

    public double[] DoubleArray()
    {
        return ToDoubleArray(Array());
    }

    #endregion
}

Measured memory_bytes: 27744
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;

public class Main {
	InputStream is;
	PrintWriter out;
	String INPUT = "";

	void solve() {
		int[] f = new int[100005];
		for(int i = 1; i < 10; i++) f[i]++;
		for(int i = 100; i < 1000; i++) f[i]++;
		for(int i = 10000; i < 100000; i++) f[i]++;
		for(int i = 1; i < 100005; i++) {
			f[i] += f[i-1];
		}
		int n = ni();
		out.println(f[n]);
	}
			    
	void run() throws Exception {
		is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
		out = new PrintWriter(System.out);

		long s = System.currentTimeMillis();
		solve();
		out.flush();
		if (!INPUT.isEmpty())
			tr(System.currentTimeMillis() - s + "ms");
	}

	public static void main(String[] args) throws Exception {
		new Main().run();
	}

	private byte[] inbuf = new byte[1024];
	public int lenbuf = 0, ptrbuf = 0;

	private int readByte() {
		if (lenbuf == -1)
			throw new InputMismatchException();
		if (ptrbuf >= lenbuf) {
			ptrbuf = 0;
			try {
				lenbuf = is.read(inbuf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (lenbuf <= 0)
				return -1;
		}
		return inbuf[ptrbuf++];
	}

	private boolean isSpaceChar(int c) {
		return !(c >= 33 && c <= 126);
	}

	private int skip() {
		int b;
		while ((b = readByte()) != -1 && isSpaceChar(b))
			;
		return b;
	}

	private double nd() {
		return Double.parseDouble(ns());
	}

	private float nf() {
		return Float.parseFloat(ns());
	}

	private char nc() {
		return (char) skip();
	}

	private String ns() {
		int b = skip();
		StringBuilder sb = new StringBuilder();
		while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ')
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	private char[] ns(int n) {
		char[] buf = new char[n];
		int b = skip(), p = 0;
		while (p < n && !(isSpaceChar(b))) {
			buf[p++] = (char) b;
			b = readByte();
		}
		return n == p ? buf : Arrays.copyOf(buf, p);
	}

	private char[][] nm(int n, int m) {
		char[][] map = new char[n][];
		for (int i = 0; i < n; i++)
			map[i] = ns(m);
		return map;
	}

	private int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}

	private int ni() {
		int num = 0, b;
		boolean minus = false;
		while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
			;
		if (b == '-') {
			minus = true;
			b = readByte();
		}

		while (true) {
			if (b >= '0' && b <= '9') {
				num = num * 10 + (b - '0');
			} else {
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private long nl() {
		long num = 0;
		int b;
		boolean minus = false;
		while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
			;
		if (b == '-') {
			minus = true;
			b = readByte();
		}

		while (true) {
			if (b >= '0' && b <= '9') {
				num = num * 10 + (b - '0');
			} else {
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private static void tr(Object... o) {
		System.out.println(Arrays.deepToString(o));
	}
}

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

using namespace std;
typedef long long ll;
typedef long double ld;

const int N = 606;
ld E[N];
vector<int> ch[N];
int n, m;

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  cin >> n >> m;
  for (int i=1; i<=m; ++i) {
    int u, v;
    cin >> u >> v;
    ch[u].push_back(v);
  }

  ld ans = 1e30;

  for (int x=1; x<=n; ++x) {
    E[n] = 0;
    for (int u=n-1; u>=1; --u) {
      ld esum = 0;
      for (auto& v : ch[u]) {
        esum += E[v];
      }
      E[u] = esum/ch[u].size();

      if (u == x && ch[u].size() > 1) {
        ld emax = 0;
        for (auto& v : ch[u]) {
          emax = max(emax, E[v]);
        }
        E[u] = min(E[u], (esum-emax)/(ch[u].size()-1));
      }

      E[u] += 1;
    }
    ans = min(ans, E[1]);
    cerr << " x " << x << " E " << E[1] << endl;
  }
  cout << fixed << setprecision(10) << ans << endl;
  return 0;
}


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

using namespace std;
#define X first
#define Y second
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

#define debug(x) cerr << #x << " = " << (x) << endl;
template<typename T>
ostream& operator<<(ostream& o, vector<T>& v) {
    for (auto& x : v) o << x << ' ';
    return o;
}

const int MAXN = 100100;
vi adj[MAXN];
ll arr[MAXN];
int n;

ll dp(int u, int p){
    if ((int)adj[u].size() == 1){
        return arr[u];
    }
    ll pos = 0, mpos = 0;
    for (int v : adj[u]){
        if (v == p) continue;
        ll c = dp(v, u);
        if (c == LLONG_MIN) return LLONG_MIN;
        if (c) {
            pos += c;
            mpos = max(mpos, c);
        }
    }
    // cerr << u << ' ' << pos << ' ' << mpos << endl;
    if (arr[u] > pos || arr[u] * 2LL < pos) {
        // cerr << "FAILED1: " << u << endl;
        // cerr << arr[u] << ' ' << pos << endl;
        return LLONG_MIN;
    }
    ll j = pos - arr[u];
    // check if can join
    if (pos - mpos < j) {
        // cerr << "FAILED2: " << u << endl;
        // cerr << pos << ' ' << mpos << ' ' << j << endl;
        return LLONG_MIN;
    }

    return arr[u] - j;
}

int main(){
    std::ios_base::sync_with_stdio(false); cin.tie(0);
    cin >> n;
    for (int i = 0; i < n; i++) cin >> arr[i];
    for (int i = 0; i < n-1; i++){
        int u, v; cin >> u >> v;
        u--; v--;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    if (n == 2) {
        if (arr[0] == arr[1]) cout << "YES" << endl;
        else cout << "NO" << endl;
        return 0;
    }
    int p = -1;
    ll valp = -1;
    ll Ma = *max_element(arr, arr + n);

    for (int i = 0; i < n; i++)
        if (adj[i].size() >= 2) {
            if (arr[i] > valp){
                valp = arr[i];
                p = i;
            }
        }
    if (valp < Ma) {
        cout << "NO" << endl;
        return 0;
    }

    if (dp(p, -1) == 0) cout << "YES" << endl;
    else cout << "NO" << endl;
}


Measured memory_bytes: 13184
import sys
sys.setrecursionlimit(10**6)

S = list(input())
T = list(input())
ret = 'Yes'
t = {}
for i in range(len(S)):
    if S[i] in t:
        if t[S[i]] == T[i]:
            continue
        else:
            ret = 'No'
    if ret == 'No':
        break
    t[S[i]] = T[i]

if ret == 'No':
    print(ret)
elif len(t) == len(set(t.values())):
    print('Yes')
else:
    print('No')


Measured memory_bytes: 6704
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <functional>
#include <algorithm>
 
using namespace std;

using ll = long long;
using ull = unsigned long long;


pair<int,int> P(int i){
  int a = i % 10;
  int b = 0;
  while(i != 0){
    b = i;
    i /= 10;
  }
  return {b,a};
}

pair<int,int> reverse(const pair<int,int>& p){
  return {p.second,p.first};
}
 
int main(){

  int N;
  cin >> N;
  auto p = P(N);
  map<pair<int,int>, int> m;

  int result = 0;

  for(int i = 1; i <= N; ++i){
    auto p = P(i);
    ++m[p];
  }

  for(auto& it: m){
    auto p = reverse(it.first);
    result += m[p] * it.second;
  }

  cout << result;
}

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

using namespace std;
using ll = long long;
using ld = long double;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define reps(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define allsort(v) sort(v.begin(),v.end())
const ll mod = 1e9 + 7;
const ll INF = 1e10;

int main() {
	cin.sync_with_stdio(false);
	int N;
	cin >> N;
	vector<int>a(N);
	ll sum = 0;
	rep(i, N) {
		cin >> a[i];
		sum += a[i];
	}
	ll suma = 0,dif=INF;
	rep(i, N-1) {
		suma += a[i];
		dif = min(abs(sum - suma -suma),dif);
	}
	cout << dif << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename Q_type>
using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>;

const int MOD_TYPE = 1;
const ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
const int INF = (int)1e9;
const ll LINF = (ll)4e18;
const ld PI = acos(-1.0);
const ld EPS = 1e-11;

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define possible(n) cout << ((n) ? "possible" : "impossible") << endl
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << endl;

vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(30) << setiosflags(ios::fixed);
  int n;
  cin >> n;
  string s[3];
  rep(i, 3) cin >> s[i];
  int cnt = 0;
  rep(i, n)
  {
    if (s[0][i] == s[1][i] && s[1][i] == s[2][i])
      continue;
    if (s[0][i] != s[1][i] && s[1][i] != s[2][i] && s[0][i] != s[2][i])
      cnt += 2;
    else
      cnt++;
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 256
#!/usr/bin/ruby
#encoding: utf-8

n = gets.to_i

ps = n.times.map{|i|
  s,p = gets.chomp.split
  [s,-p.to_i,i+1]
}
# ps は各要素が[s,-p.to_i,i+1]の二次元配列となる。

ps.sort! 
#p ps 

#ps.each{|_,_,i| p i}

(0..ps.size-1).each do |i|
  puts ps[i][2]
end


Measured memory_bytes: 1788
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int NP = 4;
const int NR = 13;

/* typedef */

struct Card {
  int rnk;
  char st;

  Card() {}

  int stlvl(char tr, char ldst) const {
    if (st == tr) return 2;
    if (st == ldst) return 1;
    return 0;
  }

  bool higher(char tr, char ldst, const Card& cd) const {
    int lvl0 = stlvl(tr, ldst);
    int lvl1 = cd.stlvl(tr, ldst);
    return (lvl0 > lvl1 || (lvl0 == lvl1 && rnk > cd.rnk));
  }

  void print() { printf("%c%d", st, rnk); }
};

/* global variables */

Card cards[NP][NR];

/* subroutines */

int rank2num(char rank) {
  if (rank == 'A') return NR - 1;
  if (rank == 'K') return NR - 2;
  if (rank == 'Q') return NR - 3;
  if (rank == 'J') return NR - 4;
  if (rank == 'T') return NR - 5;
  return (rank - '2');
}

/* main */

int main() {
  for (;;) {
    char tr;
    cin >> tr;
    if (tr == '#') break;

    for (int i = 0; i < NP; i++)
      for (int j = 0; j < NR; j++) {
	string crd;
	cin >> crd;
	cards[i][j].rnk = rank2num(crd[0]);
	cards[i][j].st = crd[1];
      }

    int nswin = 0, ewwin = 0, ld = 0;
    
    for (int j = 0; j < NR; j++) {
      int wi = ld;
      Card wcd = cards[ld][j];
      char ldst = wcd.st;

      if (false) {
	printf("%d", ld);
	for (int i = 0; i < NP; i++) putchar(':'), cards[i][j].print();
	putchar('\n');
      }
      
      for (int i = 0; i < NP; i++)
	if (cards[i][j].higher(tr, ldst, wcd))
	  wi = i, wcd = cards[i][j];

      if (wi == 0 || wi == 2) nswin++;
      else ewwin++;

      ld = wi;
    }
    //printf("ns=%d, ew=%d\n", nswin, ewwin);

    if (nswin > ewwin)
      printf("NS %d\n", nswin - 6);
    else
      printf("EW %d\n", ewwin - 6);
  }

  return 0;
}

Measured memory_bytes: 1164
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

S = input()

l = len(S)

S = S[:-1] if l % 2 != 0 else S[:-2]

for i in range(l // 2):
    if S[:l // 2 - i] == S[l // 2 - i:l - 2 * i]:
        print(l - 2 * i)
        break

Measured memory_bytes: 3572
fun main(args: Array<String>) {
    val N = readLine()!!.toInt()
    val H = readLine()!!.split(" ").map(String::toInt)
    var count = 0
    var ans = 0
    for(i in 1 until N){
        if(H[i-1] >= H[i]){
            count++
        }else{
            count = 0
        }
        if (count > ans){
            ans = count
        }
    }
    println(ans)
}

Measured memory_bytes: 59368
from collections import deque
x, y, a, b, c = map(int, input().split())
p = deque(sorted(list(map(int, input().split())) + [0]))
q = deque(sorted(list(map(int, input().split())) + [0]))
r = deque(sorted(list(map(int, input().split())) + [0]))

xy = x+y
count = 0
pp, qq, rr = p.pop(), q.pop(), r.pop()
maxelements = max(pp, qq, rr)

for i in range(xy):
    if pp == maxelements:
        count += pp
        x -= 1
        pp = p.pop() if x != 0 else 0
        xy -= 1
    elif qq == maxelements:
        count += qq
        y -= 1
        qq = q.pop() if y != 0 else 0
        xy -= 1
    elif rr == maxelements:
        count += rr
        rr = r.pop()
        xy -= 1

    if xy == 0:
        break
    else:
        maxelements = max(pp, qq, rr)

print(count)

Measured memory_bytes: 24024
program h_and_v
  implicit none
  integer :: h, w, k, i, j, l, u, a(6, 6) = 0, b(6, 6) = 0, m = 0
  character(6) :: s
  read(*,*) h, w, k
  do i = 1, h
    read(*,*) s
    do j = 1, w
      if (s(j:j) == '#') a(i, j) = 1
    end do
  end do
  u = lshift(1, h + w) - 1
  do l = 0, u
    b = a
    do i = 1, h
      if (btest(l, i - 1)) b(i, :) = -1
    end do
    do j = 1, w
      if (btest(l, j + h - 1)) b(:, j) = -1
    end do
    if (sum(b, b > 0) == k) m = m + 1
  end do
  write(*,'(i0)') m
end program h_and_v

Measured memory_bytes: 2796
N,M = map(int, input().split())
A = [int(a) for a in input().split()]

dic = {}
mod = 0
for i in range(N):
    mod += A[i]
    mod = mod%M
    if mod in dic:
        dic[mod] += 1
    else:
        dic[mod] = 1
    
ans = 0
for key in dic:
    if key == 0:
        ans += dic[key]
    ans += dic[key]*(dic[key]-1)//2
    
print(ans)

Measured memory_bytes: 14252
import java.util.*;
import static java.lang.System.*;
import static java.lang.Math.*;
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(in);
String A=sc.next();
String B=sc.next();
if(A.length()>B.length()){
    out.println("GREATER");
}else if(A.length()<B.length()){
    out.println("LESS");
}else{
if(A.compareTo(B)>0){
    out.println("GREATER");
}else if(A.compareTo(B)<0){
    out.println("LESS");
}else{
    out.println("EQUAL");
}
}
}
}

Measured memory_bytes: 22608
def slove():
    import sys
    import collections
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    a = list(map(int, input().rstrip('\n').split()))
    t = 0
    tl = [0]
    for v in a:
        t += v
        tl.append(t)
    tl = collections.Counter(tl)
    s = 0
    for k, v in tl.items():
        s += (v * (v - 1) // 2)
    print(s)


if __name__ == '__main__':
    slove()


Measured memory_bytes: 110160