akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int N; cin >> N;
    string S; cin >> S;
    vector<set<int>> x(10);
    for(int i = 0; i < N; i++){
        int d = S[i] - '0';
        x[d].insert(i);
    }
    int ans = 0;
    for(int a = 0; a <= 9; a++){
        for(int b = 0; b <= 9; b++){
            for(int c = 0; c <= 9; c++){
                int pos = -1;
                if(x[a].upper_bound(pos) == x[a].end())continue;
                pos = *x[a].upper_bound(pos);
                if(x[b].upper_bound(pos) == x[b].end())continue;
                pos = *x[b].upper_bound(pos);                
                if(x[c].upper_bound(pos) == x[c].end())continue;
                pos = *x[c].upper_bound(pos);
                ans++;
            }
        }
    }
    cout << ans << endl;
}


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

int main(){
  int N;
  cin>>N;
  int x=N%10;
  if(x==3){
    cout<<"bon"<<endl;
  }else if(x==0||x==1||x==6||x==8){
    cout<<"pon"<<endl;
  }else{
    cout<<"hon"<<endl;
  }
}


Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
using namespace std;
 
int main() {
    int H1, M1, H2, M2, K;
    cin >> H1 >> M1>> H2>> M2 >> K;
    int minute = 0;
    if (M2 < M1) {
        minute += (M2 + 60) - M1;
        H2 -= 1;
    }
    else{
        minute += M2 - M1;
    }
    
    minute += (H2 - H1) * 60;
    
    int ans = minute - K;
    cout << ans << endl;
}


Measured memory_bytes: 3636
#include <iostream>
#include <string>
using namespace std;
 
int main(void){
  int A, B, C;
  cin >> A;
  cin >> B;
  cin >> C;
  int sum = A + B + C;
  string str = "NO";
  if(sum ==  17)
    str = "YES";
  cout << str << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rrep(i,a,b) for(int i=(int)(a);i>=(int)(b);--i)
#define fore(i,a) for(auto &i:a)
#define all(a) (a).begin(),(a).end()
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
using ll = long long; constexpr int inf = INT_MAX / 2; constexpr ll infl = 1LL << 60;
template<class T>void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T>void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T>void POSS(T condition){ if(condition) cout << "POSSIBLE" << endl; else cout << "IMPOSSIBLE" << endl; }
template<class T>void Poss(T condition){ if(condition) cout << "Possible" << endl; else cout << "Impossible" << endl; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
template<class T>T gcd(T a, T b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }}
template<class T>T lcm(T a, T b){ return a / gcd(a, b) * b; }


void _main() {
  int N, K;
  cin >> N >> K;
  vector<int> x(N);
  rep(i, 0, N) cin >> x[i];

  int l = 0;
  int r = K-1;
  int ans = inf;
  while (r < N) {
    ans = min({ans, abs(x[r])+abs(x[r]-x[l]), abs(x[l])+abs(x[r]-x[l])});
    l++;
    r++;
  }

  cout << ans << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
//const int INF = 1e8;
using namespace std;

const int dy[16] = { 0,-1, 0, 1, 1,-1, 1,-1, 0,-2, 0, 2};
const int dx[16] = { 1, 0,-1, 0, 1, 1,-1,-1, 2, 0,-2, 0};

void dfs(int y, int x, char t, vector<vector<char>>& m, vector<vector<bool>>& u){
	u[y][x] = true;
	rep(d,4){
		int ny = y + dy[d];
		int nx = x + dx[d];
		if(ny < 0 || ny >= 100 || nx < 0 || nx >= 100) continue;
		if(u[ny][nx] or m[ny][nx] != t) continue;
		dfs(ny, nx, t, m, u);
	}
}

void deleteWhite(vector<vector<char>>& m, int k){
	for(int i = 1; i < 100 - 4; i+=4){
		for(int j = 1; j < 100 - 4; j+=4){
			k--;
			m[i + 1][j + 1] = '#';
			if(k == 0) return;
		}
	}
}

void deleteBlack(vector<vector<char>>& m, int k){
	int y = 4;
	while(y < 100 - 4){
		k--;
		m[y][2] = '#';
		if(k == 0) return;
		y += 4;
	}

	for(int i = 2; i < 100 - 4; i += 4){
		for(int j = 4; j < 100 - 4; j += 4){
			k--;
			m[i][j] = '#';
			if(k == 0) return;
		}
	}
}

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

	vector<vector<char>> m = vector<vector<char>>(100, vector<char>(100, '.'));
	int cnt = 0;
	for(int i = 1; i < 100 - 4; i+=4){
		for(int j = 1; j < 100 - 4; j+=4){
			cnt++;
			rep(k,3){
				rep(l,3){
					if(not (k == 1 and l == 1)){
						m[i + k][j + l] = '#';
					}
				}
			}
		}
	}

	deleteWhite(m, 577 - a);
	deleteBlack(m, 576 - b);

	vector<vector<bool>> u(100, vector<bool>(100,0));
	int B = 0, W = 0;
	rep(i,100){
		rep(j,100){
			if(u[i][j] == 0){
				if(m[i][j] == '.') W++;
				else B++;
				dfs(i, j, m[i][j], m, u);
			}
		}
	}
	//show(W) show(B)

	cout << 100 << ' ' << 100 << endl;
	range(i,0,100){ range(j,0,100){ cout << m[i][j]; } cout << endl; }
}


Measured memory_bytes: 512
n, m = list(map(int, input().split()))
lisA = [int(i) for i in input().split()]
#print(n, m)
#print(lisA)
 
lisA.sort(reverse=True)
half0 = lisA[0] // 2
count = 0
for i in range(m):
	if (count > n - 1):
		count = 0
	if (lisA[count] < half0):
		lisA.sort(reverse=True)
		half0 = lisA[0] // 2
		count = 0
	lisA[count] //= 2
	count += 1
print(sum(lisA))

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

using namespace std;
vector< vector<int> > map( 51 ,vector<int>(51,0));
int h,w;

void serch_island(int x,int y){
  map[y][x] = 0;
  const int dirX[] = {1 ,0, -1,  0, 1 , 1 , -1, -1};
  const int dirY[] = {0 ,1,  0, -1, 1 ,-1 ,  1, -1};
    for(int dir = 0; dir < 8; dir++){
      int nx = x + dirX[dir];
      int ny = y + dirY[dir];
      /*
      for(int i = 0; i < h ; i++){
        for(int j = 0; j < w; j++){
          cout << map[i][j] ;
        }
        cout << endl;
      }
      cout << endl;//*/
      if(nx >= 0 && nx < w &&
         ny >= 0 && ny < h &&
         map[ny][nx] == 1){
        serch_island(nx,ny);
      }
    }
    return ;
}

void solve(){
  int island = 0;

  for(int i = 0; i < h ; i++){
    for(int j = 0; j < w; j++){
      if(map[i][j] == 1){
        island++;
        serch_island(j, i);
      }
    }
  }
  cout << island << endl;
  map.clear();
  return ;
}
int main(){
  while(true){
    cin >> w >> h;
    if(h + w == 0) break;
    for(int i = 0; i < h ; i++){
      for(int j = 0; j < w; j++){
        cin >> map[i][j];
      }
    }
    solve();
  }
  return 0;
}



Measured memory_bytes: 3380
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{

    ll i,j,c=0,n;
    //vector<ll>v;
    double x;
    cin>>n;
    if(n%2==0)
    {
        x=(n/2)/(n*1.0);
    }
    else
    {
        j=(n/2)+1;
        x=j/(n*1.0);
    }
    cout<<fixed<<setprecision(10)<<x<<endl;
    return 0;
}


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

int main() {
    long long N;
    cin >> N;
    vector<long long> A(N);

    for (long long i = 0; i < N; i++) {
        cin >> A[i];
    }

    long long ans = 0;
    map<long long, long long> LiMap;
    for (long long i = 1; i <= N; i++) {
        LiMap[i + A[i - 1]]++;
    }
    for (long long i = 1; i <= N; i++) {
        ans += LiMap[i - A[i - 1]];
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 27312
// 参考
// https://techracho.bpsinc.jp/jhonda/2019_08_05/78537

// Input macro
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! stdin {
    () => {{
        use std::io::Read;
        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }};
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

// Test Code
macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input), $output);
            )*
        }
    };
}

test! {
r"8
" => r"2",

r"2
" => r"0",

r"9
" => r"3"
}

use std::cmp;
use std::collections::HashSet;
use std::f32::MAX;

fn main() {
    println!("{}", solve(&stdin!()));
}

fn solve(src: &str) -> String {
    input! {
        source = src,
        n: i32
    }

    (n / 3).to_string()
}


Measured memory_bytes: 4352
n = int(input())
S = [input() for _ in range(n)]
ab = 0
ba = 0
bx = 0
xa = 0
for s in S:
    if s[0] == 'B' and s[-1] == 'A':
        ba += 1
    elif s[0] == 'B' and s[-1] != 'A':
        bx += 1
    elif s[0] != 'B' and s[-1] == 'A':
        xa += 1
    for i in range(len(s) - 1):
        if s[i] == 'A' and s[i + 1] == 'B':
            ab += 1
if ba > 1:
    ab += ba - 1
    ba = 1
ab += min(xa, bx)
xa -= min(xa, bx)
bx -= min(xa, bx)
if ba == 1 and xa != bx:
    ab += 1
print(ab)

Measured memory_bytes: 3700
#include<iostream>
#include<cstdio>
#include<numeric>
#include<algorithm>
#include<vector>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;
int main(){
	int n;
	string s;
	cin>>n>>s;
	ll ans=0;
	//暴力时间过不去，所以最大只能采用n^2的算法
	// for(int i=0;i<n-2;i++){
	// 	for(int j=i+1;j<n-1;j++){
	// 		if(s[i]==s[j])continue;
	// 		for(int k=j+1;k<n;k++){
	// 			if(s[j]!=s[k]&&s[i]!=s[k]&&j-i!=k-j){
	// 				ans++;
	// 			}
	// 		}
	// 	}
	// }
	for(int i=0;i<n;i++){
		for(int j=i+1;j<n;j++){
			int k=j-i+j;//表示i,j,k三者之间间隔相同
			if(k>n-1)continue;
			if(s[i]!=s[j]&&s[i]!=s[k]&&s[j]!=s[k])ans++;
		}
	}
	ll r=0,g=0,b=0;
	for(int i=0;i<n;i++){
		if(s[i]=='R')r++;
		else if(s[i]=='G')g++;
		else b++;
	}
	ll res=r*b*g;
	cout<<res-ans<<endl;
	return 0;
}

Measured memory_bytes: 3576
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
typedef long long LL;
int N;
LL a[200001];
LL sum=0;
int main(){
    cin>>N;
    REP(i,N){
        cin>>a[i];
        sum+=a[i];
    }
    LL now=0;
    LL ans=1e15;
    REP(i,N-1){
        now+=a[i];
        sum-=a[i];
        ans=min(ans,abs(now-sum));
    }
    cout<<ans<<endl;
    return(0);
}

Measured memory_bytes: 1792
import java.util.*;




public class Main{
	public static long[][] weight_value,dp;
	public static int i,j,W;


	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N=sc.nextInt();
		W=sc.nextInt();
		long ans=0;


		weight_value=new long[N+1][3];
		dp=new long[N+1][W+1];

		//weight_valueの読み込み
		for(int i=1;i<=N;i++){
			for (int k=1;k<=2;k++){
			weight_value[i][k]=sc.nextInt();
			}
		}

		//dpの初期化
		for(int i=0;i<=N;i++){
			for (int k=0;k<=2;k++){
			dp[i][k]=Long.MIN_VALUE;
			}
		}

		dp[1][0]=0;
		dp[1][(int) weight_value[1][1]]=weight_value[1][2];


		//dp_change
		for (i=1;i<=N-1;i++) {
			for (j=0;j<=W;j++) {
			chmax(i,j);
			}
		}
		for(i=0;i<=W;i++){
		ans=Math.max(dp[N][i],ans);
		}
		System.out.println(ans);
	}

	//dp更新用の関する定義
	public static void chmax(int i,int j){
		dp[i+1][j]=Math.max(dp[i+1][j],dp[i][j]);
		if(j+weight_value[i+1][1]<=W){
			dp[i+1][(int) (j+weight_value[i+1][1])]=Math.max(dp[i+1][(int) (j+weight_value[i+1][1])],dp[i][j]+weight_value[i+1][2]);
		}

	}
}

Measured memory_bytes: 128980
using System;
class ProgramA
    {
        static void Main(string[] args)
        {
            //入力
            string n = Console.ReadLine();

            if(n.Length % 2 == 1)
            {
                Console.WriteLine("No");
                return;
            }


            //奇数なら(n+1)/2、偶数ならn/2。intは切り捨てなのでこれで解答可能
            for(int i = 0;i < n.Length;i = i+ 2)
            {
                if(n[i] != 'h' || n[i+1] != 'i')
                {
                    Console.WriteLine("No");
                    return;
                }
            }

            Console.WriteLine("Yes");
        }
    }

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

int main(){
    int a,b;
    cin >> a >> b;
    if (a>b){
        cout << "a > b" << endl;
    }
    else if (a<b){
        cout << "a < b" << endl;
    }
    else{
        cout << "a == b" << endl;
    }
    return 0;
}


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

struct color {
	int r, g, b;
};
map<string, color>mp{
	{"black",{0,0,0}},
	{"blue",{0,0,0xff}},
	{"lime",{0,0xff,0} },
	{"aqua",{0,0xff,0xff}},
	{"red",{0xff,0,0}},
	{"fuchsia",{0xff,0,0xff}},
	{"yellow",{0xff,0xff,0}},
	{"white",{0xff,0xff,0xff}}
};
int main() {
	string s;
	while (cin >> s, s != "0") {
		int r, g, b;
		sscanf(s.data(), "%*c%2x%2x%2x", &r, &g, &b);
		int Min = INT_MAX;
		string ans;
		for (auto p : mp) {
			int d = abs((r - p.second.r)*(r - p.second.r) + (g - p.second.g)*(g - p.second.g) + (b - p.second.b)*(b - p.second.b));
			if (d < Min) {
				Min = d;
				ans = p.first;
			}
		}
		cout << ans << endl;
	}
}

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

typedef double du ;
typedef string st ;
typedef long long ll ;
typedef long double ld ;
typedef long long int lli ;

#define vi vector <lli>
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

int main ()
{
    fastio

    st s , spa1 , spa2 , spb1 , spb2 ;
    int pa1 , pa2 , pb1 , pb2 ;

    cin >> s ;

    spa1 = s . substr (5 , 1) ;
    spa2 = s . substr (6 , 1) ;
    spb1 = s . substr (8 , 1) ;
    spb2 = s . substr (9 , 1) ;

    pa1 = spa1[0] - '0' ;
    pa2 = spa2[0] - '0' ;
    pb1 = spb1[0] - '0' ;
    pb2 = spb2[0] - '0' ;

    if (pa1 == 0)
    {
        if (pa2 <= 4) cout << "Heisei" ;
        else if (pa2 > 4 ) cout << "TBD" ;
        else if (pa2 == 4)
        {
            if (pb1 <= 3 && pb2 == 0) cout << "Heisei" ;
            else if (pb1 == 3 && pb2 > 0) cout << "TBD" ;
        }
    }
    else if (pa1 > 0 )
        cout << "TBD" ;
    return 0 ;
}

/*___________________________________________________________________functions___________________________________________________________________________*/


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

#define all(x) (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define ll long long
#define ld long double
#define pb push_back
#define MOD 1000000007
#define LLMN LONG_LONG_MIN
#define LLMX LONG_LONG_MAX
#define LDMX LDBL_MAX
#define LDMN LDBL_MIN
#define MAX 1000000

ll mulmod(ll, ll);
ll fastpower(ll, ll);
void getprime(vector<ll>&);
void getfact(vector<ll>&, vector<ll>&);
ll ncr(ll, ll, vector<ll>&, vector<ll>&);


void solve()
{
    ll n;
    cin>>n;
    vector<ll>a(n);
    for(ll i=0;i<n;i++) cin>>a[i];
    ll xr = 0;
    for(ll i=0;i<n;i++)
        xr ^= a[i];
    
    for(ll i=0;i<n;i++)
    {
        cout<<(xr^a[i])<<" ";
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll t = 1;
    //cin>>t;
    while(t--)
    {
        solve();        
    }
    return 0;
}

ll mulmod(ll a, ll b)
{
    ll res = 0; 
    a = a % MOD;
    while(b > 0)
    {
        if (b % 2 == 1)
            res = (res + a) % MOD;
 
        a = (a * 2) % MOD; 
        b /= 2;
    } 
    return res % MOD; 
}

ll  fastpower(ll a, ll n)
{
    ll res = 1;
    while(n > 0)
    {
        if(n % 2 != 0)
        {
            res = (res * a) % MOD;
        }
        n /= 2;
        a = (a * a) % MOD;
    }
    return res;
}

void getprime(vector<bool>&prime)
{
    prime[0] = false;
    prime[1] = false;
    
    for(ll i = 2;i <= MAX; i++)
    {
        if(prime[i])
        {
            for(ll j = i*i; j <= MAX; j += i)
                prime[j] = false;
        }
    }
}

void getfact(vector<ll> &fact, vector<ll> &ifact)
{
    fact[0] = 1;
    ifact[0] = 1;
    
    for(ll i = 1; i <= MAX; i++)
    {
        fact[i] = (fact[i-1] * i)%MOD;
        ifact[i] = (ifact[i-1] * fastpower(i, MOD -2) )%MOD;
    }
}

ll ncr(ll n, ll r, vector<ll>&fact, vector<ll>&ifact)
{
    ll res;
    res = (((fact[n] * ifact[r]) % MOD) * ifact[n-r]) % MOD;
    return res;
}


Measured memory_bytes: 4692
#include <cstdio>
using namespace std;

int main() {
	int a,b;
	scanf("%d%d",&a,&b);
	if (a==b) {
		printf("a == b\n");
	} else if (a > b) {
		printf("a > b\n");
	} else {
		printf("a < b\n");
	}
	return 0;
}

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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1777777777ll
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;


int main() {
    li n, k;
    cin >> n >> k;
    li res = 0;
    rin{
        li x;
        cin >> x;
        res += min(x, k - x) * 2;
    }
    cout << res << endl;

    return 0;
}


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

int main(){
		int N, K;
		cin >> N >> K;
		int h[N];
		int dp[N];
		for(int i = 0; i < N; i++){
			cin >> h[i];
			dp[i] = 2147483647;
	  }
	  dp[0] = 0;
	  for(int i = 0; i < N; i++){
				for(int j = 1; j <= min(N-i-1,K); j++){
					int m = max(h[i+j] - h[i], h[i] - h[i+j]);
					dp[i+j] = min(dp[i+j], dp[i] + m);
				}
		}
		cout << dp[N-1] << endl; 
		return 0;
}


Measured memory_bytes: 1152
#ライブラリインポート
from collections import defaultdict

#入力受け取り
def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	N = int(input())
	S = []
	T = []
	for i in range(N):
		s, t = list(input().split())
		t = int(t)
		S.append(s)
		T.append(t)

	X = input()
	ans = 0
	val = None
	for i in range(N):
		if S[i] == X:
			val = i
			break
	for i in range(val + 1, N):
		ans += T[i]

	print(ans)

if __name__ == '__main__':
	main()

Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 int s;
 cin >> s;
 vector<int> a(1);
  a.at(0) = s;
  
  int ans = 0;
  bool flag = false;
  for(int i = 0;i<=1000000;i++){
    if(a.at(i) %2 ==0) a.push_back(a.at(i)/2);
    else a.push_back(3 * a.at(i) + 1);

  for(int j = 0;j<=i;j++){
    if(a.at(i+1) == a.at(j)){
      ans = i+2;
      flag = true;
      break;
    } 
   }
    if(flag) break;
  }
cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <algorithm>

#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
using namespace std;

int main() {
  int n,T,min=2000;
  cin >> n >> T;
  int c[n],t[n];
  for (size_t i = 0; i < n; i++) {
    cin >> c[i] >> t[i];

  }
  for (size_t i = 0; i < n; i++) {
    if(t[i] <= T) {
      if(c[i] < min) min = c[i];
    }
  }
  if(min == 2000) cout << "TLE" <<endl;
  else cout << min << endl;
}


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

int n,W;
int w[110];
long long v[110];
long long dp[110][110000];

int main() {
    cin >> n >> W;
    for (int i = 1; i <= n; ++i) {
        cin >> w[i] >> v[i];
    }

    for (int i = 1; i <= n; ++i) {
        for (int j = 0; j <= W; ++j) {
            dp[i][j] = dp[i-1][j]; // why? this line is needed?
            if (j-w[i] < 0) continue;
            dp[i][j] = max(dp[i-1][j],
                           dp[i-1][j-w[i]] + v[i]);
        }
    }
    cout << dp[n][W] << "\n";
    return 0;
}


Measured memory_bytes: 81936
#include<stdio.h>
static const int N = 100;

int main(){
  int A[N][N];
  int n,k,v,c;
  int i, j;

  scanf("%d", &n);

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

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

  for ( i = 0; i < n; i++ ){
    for ( j = 0; j < n; j++ ){
        if ( j )
        printf(" ");
      printf("%d", A[i][j]);
    }
    printf("\n");
  }

  return 0;
}


Measured memory_bytes: 2052
#include <bits/stdc++.h>
#define typeof(x) __typeof__(x)
#define int long long int
#define double long double
#define mod(x) ((x % MOD) + MOD) % MOD
#define REP(i,a,b) for(int i=(a);i<(b);++i)
#define RREP(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define ALL(c) (c).begin(),(c).end()
#define RALL(c) (c).rbegin(),(c).rend()
#define SZ(c) (int)((c).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define LB(c,x) (int)(lower_bound(ALL(c),x)-(c).begin())
#define UB(c,x) (int)(upper_bound(ALL(c),x)-(c).begin())
#define COUNT(c,x) (UB(c,x)-LB(c,x))
#define UNIQUE(c) SORT(c); (c).erase(unique(ALL(c)),(c).end());
#define COPY(c1,c2) copy(ALL(c1),(c2).begin())
#define EXIST(s,e) (s).find(e)!=(s).end()
#define PB push_back
#define MP make_pair
#define vec vector
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define NL cerr << endl;

using namespace std;

typedef pair<int,int> P;
struct edge { int from, to; int cost; };
ostream& operator << (ostream& s, const edge& e) {
   s << "(" << e.from << "->" << e.to << ": " << e.cost << ")";
   return s;
}
bool operator< (const edge &edge1, const edge &edge2){
   return edge1.cost < edge2.cost;
};

const int INF = 1e18;
const int MOD = 1e9+7;

template<typename T> ostream& operator << (ostream& s, const vector<T>& v) {
   s << "[";
   for (int i = 0; i < v.size(); i++) { s << v[i]; if (i < v.size() - 1) s << " "; }
   s << "]";
   return s;
}
template<typename T> ostream& operator << (ostream& s, const set<T>& se) {
   s << "{";
   for (auto i = se.begin(); i != se.end(); ++i) {
      s << *i;
      if (next(i) != se.end()) s << ", ";
   }
   s << "}";
   return s;
}
template<typename T1, typename T2> ostream& operator << (ostream& s, const pair<T1,T2>& p) {
   s << "(" << p.first << "," << p.second << ")";
   return s;
}
template<typename T1, typename T2> ostream& operator << (ostream& s, const map<T1,T2>& m) {
   s << "{";
   for (auto i = m.begin(); i != m.end(); ++i) {
      s << i->first << ":" << i->second;
      if (next(i) != m.end()) s << ", ";
   }
   s << "}";
   return s;
}

signed main()
{
   int n, a, b; cin >> n >> a >> b;
   cout << min(a,b) << endl;
   cout << max(0LL, (a+b)-n) << 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++)
using ll = long long;
using P = pair<int, int>;
int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    ll ans = 0;
    for (int i = 1; i < n; i++){
        if(a[i] < a[i-1]){
            ans += a[i-1] - a[i];
            a[i] = a[i-1];
        }
    }
    cout << ans << endl;
return 0;
}

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

int main(){
  int n;
  char c;
  int a = 'a';
  int A = 'A';
  int charc;
  cin >> n;
  string s;
  cin >> s;
  for(int i = 0; i < s.size(); i++){
    c = s.at(i);
    charc = c;
    if(isupper(c)){
      c = (char)(A + (charc - A + n)%26);
    }
    else{
      c = (char)(a + (charc - a + n)%26);
    }
    cout << c;
  }
  cout << endl;
}

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

using namespace std;
typedef long long llint;
#define inf 1e18

llint n,k;
void solve(){
	cin >> n >> k;
	llint ans=1;
	if(n%k==0)ans=0;
	cout << ans << endl;
}

int main(int argc, char *argv[]) {
  solve();
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define all(a) a.begin(), a.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;
typedef long long ll;

int main(){

    int N;
    cin >> N;

    vector<bool> exist(31, false);
    vector<int> cnt(31, 0);
    int XOR = 0;

    rep(loop, N){
        int a;
        cin >> a;
        exist[__builtin_ctz(a)] = true;
        XOR ^= a;
    }

    int ans = 0, now = 0;
    for(int digit = 30; digit >= 0; digit--){
        if(XOR & (1 << digit))cnt[digit]++;
        if((cnt[digit] + now) & 1){
            if(!exist[digit]){
                cout << -1 << endl;
                return 0;
            } else {
                ans++;
                now++;
            }
        }
    }

    cout << ans << endl;
    return 0;

}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>
#include <bitset>
#include <cstdlib>
#include <cmath>
#define INF 100000000000
#define MOD 1000000007
#define ll long long int
//#define int long long int
using namespace std;


int main(){

  string s; cin>>s;

  if(s == "Sunny") cout<<"Cloudy"<<endl;
  if(s == "Cloudy") cout<<"Rainy"<<endl;
  if(s == "Rainy") cout<<"Sunny"<<endl;



return 0;
}

Measured memory_bytes: 256
/*
 * author: calgagi
 *         Calvin Gagliano 
 */
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ull unsigned long long
#define ii pair<int, int>
#define ar array
#define f first
#define s second
#define dd long double

int n, m, q;
int ans = 0;
vector<ar<int,4>> quad;

void check(vector<int>& x) {
    int ans2 = 0;
    for (auto& z : quad) {
        if (x[z[1]] - x[z[0]] == z[2]) {
            ans2 += z[3];
        }
    }
    ans = max(ans, ans2);

    /* cout << "CHECK: "; */
    /* for (int i = 1; i <= n; i++) { */
    /*     cout << x[i] << " "; */
    /* } */
    /* cout << ans2 << endl; */

    return;
}

void build(vector<int>& x, int i) {
    if (i == n+1) {
        check(x);    
        return;
    }
    for (int j = x[i-1]; j <= m; j++) {
        x[i] = j;
        build(x, i+1);
    }
    return;
}

int main() {
    ios_base::sync_with_stdio(false);  
    cin.tie(NULL);
    srand(chrono::steady_clock::now().time_since_epoch().count()); 
    // freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); 
    
    cin >> n >> m >> q;
    quad.resize(q);
    for (int i = 0; i < q; i++) {
        cin >> quad[i][0] >> quad[i][1] >> quad[i][2] >> quad[i][3];
    }

    vector<int> x(n+1);
    x[0] = 1;
    build(x, 1); 

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3652
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

s, t = readline().decode('utf-8').split()
a, b = map(int, readline().split())
u = read().decode('utf-8').rstrip()

if u == s:
    a -= 1
else:
    b -= 1

print(a, b)


Measured memory_bytes: 2940
<?php
fscanf(STDIN, "%d", $n);
fscanf(STDIN, "%s", $s);
$cc = count_chars($s, 1);
$max = 0;
foreach ($cc as $c => $v) {
	$k = chr($c);
	$a[$k] = $v;
	$b[$k] = 0;
	if ($v >= 2) $max++;
}
if ($max <= 1) exit("$max");
$p = $x = 0;
for ($i = 0; $i < $n; $i++) {
	$a[$s[$i]]--;
	$b[$s[$i]]++;
	if ($a[$s[$i]] > 0 && $b[$s[$i]] == 1) {
		if (++$p == $max) exit("$max");
		if ($p > $x) $x = $p;
	} elseif ($a[$s[$i]] == 0 && $b[$s[$i]] >= 2) {
		$p--;
	}
}
echo $x;

Measured memory_bytes: 4728
#include <iostream>
#include <vector>
#include <algorithm>
#define INF 1e9
using namespace std;

int main(){
    //declaration and input
    int n;
    cin >> n;
    vector<vector<int>> graph(n, vector<int>(n));
    for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) cin >> graph[i][j];
    
    //get Minimum Spanning Tree by Prim's algorithm
    vector<int> parent_of(n, -1);
    vector<int> cost(n, INF);
    vector<int> state(n, 0);
    cost[0] = 0;
    state[0]++;

    int sum = 0;
    int parent = -1;
    while (true){
        int min_cost = INF;
        int next = -1;
        for (int i = 0; i < n; i++){
            if (state[i] == 1 && cost[i] < min_cost){
                min_cost = cost[i];
                next = i;
            }
        }
        if (min_cost == INF)
            break;
        sum += cost[next];
        state[next] = 2;
        for (int i = 0; i < n; i++){
            if (state[i] != 2 && graph[i][next] != -1){
                state[i] = 1;
                if (cost[i] > graph[i][next])
                    cost[i] = graph[i][next];
            }
        }
    }

    /*int sum = 0;
    for (int i = 0; i < n; i++){
        if (parent_of[i] != -1)
            sum += graph[i][parent_of[i]];
    }*/

    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 3148
using System;
using System.Linq;
using System.Collections.Generic;

namespace D
{
  class Program
  {
    static void Main(string[] args)
    {
      Console.WriteLine(Run(args));
    }

    private static long Run(string[] args)
    {
      var input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
      var N = input[0];
      var M = input[1];

      var items = Console.ReadLine().Split(' ').Select(double.Parse).ToList();
      items.Sort();
      items.Reverse();

      var ret = 0L;
      while (M > 0)
      {
        items[0] /= 2;
        M--;
        if (M == 0) break;

        for (int i = 1; i < N; i++)
        {
          if (items[0] > items[i])
          {
            items.Sort();
            items.Reverse();
            break;
          }
          items[i] /= 2;
          M--;
          if (M == 0) break;
        }
      }

      ret = items.Select(d => (long)d).Sum();

      return ret;
    }
  }
}


Measured memory_bytes: 26844
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  if(N%111==0){
    cout << (N/111 * 111) << endl;
  }
  else{
    cout << ((N/111)+1) * 111 << endl;
  }
  return 0;
    

}


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

namespace ConsoleApplication3
{
    class Program
    {
        static void Main(string[] args)
        {
            // 素因数分解
            long N = long.Parse(Console.ReadLine());

            long sqrt = 0;

            while(sqrt*sqrt <= N)
            {
                sqrt++;
            }

            long insuu = sqrt - 1;
            long shou = 0;
            while(true)
            {
                if(N % insuu == 0)
                {
                    shou = N / insuu;
                    break;
                }
                insuu--;
            }

            // ketasuu
            int keta_insuu = insuu.ToString().Length;
            int keta_shou = shou.ToString().Length;

            if (keta_insuu >= keta_shou) Console.WriteLine(keta_insuu);
            else Console.WriteLine(keta_shou);  

            Console.ReadLine();
        }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
#include <ext/rope>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#define int long long
#define pb push_back
#define x first
#define y second
#define mk(a,b) make_pair(a,b)
#define rr return 0
#define sqr(a) ((a)*(a))
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()

using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template<class value, class cmp = less<value> >
using ordered_set = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class value, class cmp = less_equal<value> >
using ordered_multiset = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class key, class value, class cmp = less<key> >
using ordered_map = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;

/// find_by_order()
/// order_of_key()
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
inline int randll(int l = INT_MIN, int r = INT_MAX) {
    return uniform_int_distribution<int>(l, r)(rng);
}

const int INF = 1e9, MOD = 998244353; /// think
const ll LINF = 1e15;

const int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};
inline bool inside (int x, int y, int n, int m) {
    return 0 <= x && 0 <= y && x < n && y < m;
}

template<class T> bool umin (T &a, T b) {return a > b ? (a = b, true) : false; }
template<class T> bool umax (T &a, T b) {return a < b ? (a = b, true) : false; }

main()
{
    ios::sync_with_stdio(0);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    string s;
    cin >> s;
    for (int i = 0; i < sz(s); i++) {
        if (i & 1) {
            if (s[i] == 'R') {
                cout << "No\n";
                rr;
            }
        }
        else {
            if (s[i] == 'L') {
                cout << "No\n";
                rr;
            }
        }
    }
    cout << "Yes\n";
}


Measured memory_bytes: 3632
from itertools import permutations
n,m=map(int,input().split())
ab=[[] for _ in range(n)]
for i in range(m):
    a,b=map(int,input().split())
    ab[a-1].append(b-1)
    ab[b-1].append(a-1)
l=list(range(1,n))
p=list(permutations(l,n-1))
ans=0
for i in p:
    flg=0
    if i[0] not in ab[0]:
        continue   
    for j in range(n-2):
        if i[j+1] in ab[i[j]]:
            continue
        else:
            flg=1
            break
    if flg==0:
        ans+=1
print(ans)

Measured memory_bytes: 3572
#include <iostream>
#include <sstream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <iomanip>
#include <cstdlib>
#include <climits>
#include <set>
using namespace std;

//関数getinputdata宣言
vector<vector<string>> getinputdata();
vector<vector<int>> getinputdata2();
vector<vector<double>> getinputdata3();

void abc125_b(vector<vector<string>> vec) {

    int n = atoi(vec[0][0].c_str());

    int mysum = 0;

    for (int i = 0; i < n; i++) {
        
        int v = atoi(vec[1][i].c_str());
        int c = atoi(vec[2][i].c_str());
    
        if(v-c>0){
            mysum+=v-c;
        }
        
    }

    cout << mysum << endl;


}

int main() {

    vector<vector < string>> vec_arr_result;
    //    vector<vector<int>> vec_arr_result;
    vec_arr_result = getinputdata();

    abc125_b(vec_arr_result);

    return 0;
}

//関数getinputdata実装

vector<vector<double>> getinputdata3() {

    string str;
    string ret;
    stringstream ss;
    vector<string> v1;
    vector<vector<double>> vec_arr;

    //標準入力から入力がある間ループ処理でvector配列にデータ格納
    while (getline(cin, str)) {

        v1.push_back(str);

    }

    //stringstreamを利用してvector配列v1をスペースで分解処理
    for (string s : v1) {

        vector<double> array_data;
        ss << s;

        while (!ss.eof()) {

            ss >> ret;

            array_data.push_back(atof(ret.c_str()));
        }

        //vector配列に追加
        vec_arr.push_back(array_data);

        //バッファクリア
        ss.str("");
        //ストリームクリア
        ss.clear(stringstream::goodbit);

    }

    return vec_arr;
}

//関数getinputdata実装

vector<vector<int>> getinputdata2() {

    string str;
    string ret;
    stringstream ss;
    vector<string> v1;
    vector<vector<int>> vec_arr;

    //標準入力から入力がある間ループ処理でvector配列にデータ格納
    while (getline(cin, str)) {

        v1.push_back(str);

    }

    //stringstreamを利用してvector配列v1をスペースで分解処理
    for (string s : v1) {

        vector<int> array_data;
        ss << s;

        while (!ss.eof()) {

            ss >> ret;

            array_data.push_back(atoi(ret.c_str()));
        }

        //vector配列に追加
        vec_arr.push_back(array_data);

        //バッファクリア
        ss.str("");
        //ストリームクリア
        ss.clear(stringstream::goodbit);

    }

    return vec_arr;


}

//関数getinputdata実装

vector<vector < string >> getinputdata() {

    string str;
    string ret;
    stringstream ss;
    vector<string> v1;
    vector<vector < string>> vec_arr;

    //標準入力から入力がある間ループ処理でvector配列にデータ格納
    while (getline(cin, str)) {

        v1.push_back(str);

    }

    //stringstreamを利用してvector配列v1をスペースで分解処理
    for (string s : v1) {

        vector<string> array_data;
        ss << s;

        while (!ss.eof()) {

            ss >> ret;

            array_data.push_back(ret);
        }

        //vector配列に追加
        vec_arr.push_back(array_data);

        //バッファクリア
        ss.str("");
        //ストリームクリア
        ss.clear(stringstream::goodbit);

    }

    return vec_arr;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a,b,c,d; //高橋a,b 青木c,d
  cin >> a >> b >> c >> d;
  
  //高橋が勝つならyes, 負けはno
  int damage1, damage2;
  while(1){
    damage1 = c - b;
    if(damage1 <= 0){
      cout << "Yes" << endl;
      break;
    }
   
    damage2 = a - d ;
    if(damage2 <= 0){
      cout << "No" << endl;
      break;
    }
    
    c = damage1, a = damage2;
  }
  

}

Measured memory_bytes: 3632
from collections import deque

h, w = map(int, input().split())
total_block = h * w
h += 2
w += 2
area = []
explored = []

wall_num = 0

for i in range(h):
    if i == 0 or i == h-1:
        a = '#' * w
    else:
        a = input()
        for j in a:
            if j == '#':
                wall_num += 1
        a = '#' + a + '#'
    area.append(a)

distance = [[float('inf') for _ in range(w)] for _ in range(h)]
distance[1][1] = 0

q = deque()
if area[1][2] == '.':
    q.append([1, 2])
    distance[1][2] = 1
    explored.append([1, 2])
if area[2][1] == '.':
    q.append([2, 1])
    distance[2][1] = 1
    explored.append([2, 1])

explored.append([1, 1])

while len(q) != 0:
    now = q.popleft()
    a = now[0]
    b = now[1]
    d = distance[a][b]
    l = [[a+1, b], [a-1, b], [a, b+1], [a, b-1]]
    for x, y in l:
        if area[x][y] == '.' and [x, y] not in explored:
            q.append([x, y])
            distance[x][y] = d + 1
            explored.append([x, y])

if distance[h-2][w-2] == float('inf'):
    print(-1)
else:
    print(total_block - wall_num - distance[h-2][w-2] - 1)

Measured memory_bytes: 3700
#include <stdio.h>
#include <map>
using namespace std;

typedef long long ll;

map<ll, ll> M;
ll a[111111];

int main(void)
{
	ll n, q, sum = 0, i;

	scanf("%lld", &n);
	for (i = 1; i <= n; i++)
	{
		scanf("%lld", &a[i]);
		sum += a[i];
		M[a[i]]++;
	}

	scanf("%lld", &q);
	while (q--)
	{
		ll b, c;

		scanf("%lld %lld", &b, &c);

		sum -= M[b] * b - M[b] * c;
		M[c] += M[b];
		M[b] = 0;

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

Measured memory_bytes: 10008
#C
N = int(input())

count = [0] * 10050
for j in range(1, 105):
    for k in range(1, 105):
        for l in range(1, 105):
            v = (j+k+l) ** 2 - (j*k + k*l + l*j)
            if v < 10050:
                count[v] += 1

for i in range(1, N+1):
    print(count[i])

Measured memory_bytes: 9296
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
#include <deque>
#include <iterator>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
template<class T> inline bool chmax(T& a, T b) {if (a<b) {a=b; return true;} return false;}
template<class T> inline bool chmin(T& a, T b) {if (a>b) {a=b; return true;} return false;}

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

int main() {
  ll h, w, n; cin >> h >> w >> n;
  map<P<ll, ll>, ll> black;
  REP(i, n) {
    ll a, b; cin >> a >> b;
    black[make_pair(a-1, b-1)]++;
    black[make_pair(a, b-1)]++;
    black[make_pair(a+1, b-1)]++;
    black[make_pair(a-1, b)]++;
    black[make_pair(a, b)]++;
    black[make_pair(a+1, b)]++;
    black[make_pair(a-1, b+1)]++;
    black[make_pair(a, b+1)]++;
    black[make_pair(a+1, b+1)]++;
  }
  vll ans(10, 0);
  ll sans = 0;
  for (auto bl: black) {
    if (bl.first.first>1 && bl.first.first<h && bl.first.second>1 && bl.first.second<w) {
      ans[bl.second]++;
      sans++;
    }
  }
  cout << (h-2)*(w-2)-sans << endl;
  rep(i, 1, 10) {
    cout << ans[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 56448
import java.util.Scanner;

public class Main {

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String s = sc.next();
		String t = sc.next();
		String[] sarray = s.split("");
		String[] tarray = t.split("");

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

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

int main() {
  int n,ans = 0;
  cin>>n;
  rep(i,n){
  int l,r;
  cin>>l>>r;
  ans += r-l+1;
  }
  cout<<ans<<endl;
}


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

using namespace std;

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

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

  int N;
  int d[210][210];
  int dp_x[210][210];
  int dp[210][210];
  while(cin >> N && N){
	int W, H;
	fill((int*)d, (int*)d+210*210,0);
	cin >> W >> H;
	REP(i,N){
	  int x, y; cin >> x >> y;
	  d[y][x] = 1;
	}
	int S, T; cin >> S >> T;

	fill((int*)dp_x, (int*)dp_x+210*210, 0);
	REP(y,H+1){
	  REP(i,S) dp_x[y][0] += d[y][i];
	  for(int x=1;x<=W;++x){
		dp_x[y][x] = dp_x[y][x-1] - d[y][x-1] + d[y][x+S-1];
	  }
	}

	//REP(y,H+1){REP(x,W+1)cout<< dp_x[y][x]<<" ";cout<<endl;}
	int ans = 0;
	fill((int*)dp, (int*)dp+201*201, 0);
	REP(x,W+1){
	  REP(i,T) dp[0][x] += dp_x[i][x];
	  for(int y=1;y<=H;++y){
		dp[y][x] = dp[y-1][x] - dp_x[y-1][x] + dp_x[y+T-1][x];
		ans = max(ans, dp[y][x]);
	  }
	}
	cout << ans << endl;
  }
  
  return 0;
}

Measured memory_bytes: 1700
#include <stdio.h>

int main()
{
	char ch[1001];
	int sum, i;
	
    while(1){
    	scanf("%s", ch);
    	if (ch[0] == '0') break; 
        sum = 0; i = 0;
        while(ch[i]){
            sum += ch[i] - '0';
            i++;
        }
        printf("%d\n", sum);
    }
    return 0;
}

Measured memory_bytes: 536
dishes = sorted([int(input()) for _ in range(5)], key=lambda x:int(str(x)[-1]))

for dish in dishes:
    if int(str(dish)[-1]) == 0:
        new_dishes = dishes[1:]
        new_dishes.append(dish)
        dishes = new_dishes
    else:
        pass

time = 0
for i, dish in enumerate(dishes):
    if i == 0:
        time += dish
    else:
        if dish % 10 != 0:
            rest = 10 - (dish % 10)
        else:
            rest = 0
        time += dish + rest

print(time)


Measured memory_bytes: 3064
<?php
fscanf(STDIN, "%d", $k);
fscanf(STDIN, "%d %d", $a, $b);

$ans = "NG";
for ($i=$a; $i<=$b; $i++){
  if ($i%$k==0) {
    $ans="OK";
    $break;
  }
}

echo $ans;
?>


Measured memory_bytes: 16152
n=1
r=1
while n !=0 and r!=0:
    n,r=input().split()
    n,r=int(n),int(r)

    card= [[int(i) for i in input().split()] for i in range(r)]
    yama= list(range(n,0,-1))
    
    if n ==0 and r==0:
        break

    for i in range(r):
        p=card[i][0]
        c=card[i][1]
        x=yama[:p-1]
        y=yama[p-1:p-1+c]
        z=yama[p-1+c:] 
      
       
        yama=(y+x+z)
        
    print(yama[0])
    




Measured memory_bytes: 5620