akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;

int main(){

    while(1){

	string s; cin >> s;

    if(s == "#") return 0;

    int cnt = 1;
    rep(i,s.size()){
        if(s[i] == '/') cnt ++;
    }

    vector<string> g(cnt, "");

    ll id = 0;

    rep(i,s.size()){

        if(s[i] == 'b'){
            g[id] = g[id] + "b";
            continue;
        }

        else if (s[i] != '/'){

            rep(j,(s[i] - '0')) g[id] = g[id] + ".";
            continue;

        }

        if(s[i] == '/'){
            id++;
            continue;
        }

    }

    //rep(i,cnt){
        //cout << g[i] << endl;
    //}

    int h1, w1, h2, w2; cin >> h1 >> w1 >> h2 >> w2;
    h1--; w1--; h2--; w2--;

    g[h1][w1] = '.'; g[h2][w2] = 'b';

    //rep(i,cnt){
        //cout << g[i] << endl;
    //}

    string ans = "";

    ll tmpi = 0;
    rep(i, cnt){
        rep(j, g[0].size()){

            if(g[i][j] == '.'){
                tmpi++;
                continue;
            }
            
            if(g[i][j] == 'b'){

                if(tmpi == 0){
                    ans = ans + "b";
                }

                else{
                    ans = ans + string(1,(tmpi + '0')) + "b";
                    tmpi = 0;
                }

            }
        }

        if(tmpi != 0) ans = ans + string(1,(tmpi + '0'));
        if(i != cnt -1) ans = ans + "/";

        tmpi = 0;

    }

    cout << ans << endl;

    }

}




Measured memory_bytes: 3220
import math
A,B,H,M=map(int,input().split())
pi=3.14159265358979
time=H*60+M
Hth=pi/360*time
Mth=pi/30*time
theta=min(abs(Hth-Mth),abs(Mth-Hth))
l=(A**2+B**2-2*A*B*math.cos(theta))**0.5
print(l)

Measured memory_bytes: 9508
#include<iostream>
#include<algorithm>
using namespace std;
using ll = long long;

int main() {
	int n, a, b;
	cin >> n >> a >> b;
	int h[n];
	for (int i = 0;i < n;i++)cin >> h[i];
	sort(h, h + n);
	ll right = h[n - 1], left = 0;//回数
	while (right - left > 1) {
		ll mid = (right + left) / 2;
		ll sum = 0;
		for (int i = 0;i < n;i++) {
			if (h[i] > b*mid) {
				if ((h[i] - b * mid) % (a - b)==0)sum += (h[i] - b * mid) / (a - b);
				else sum += (h[i] - b * mid) / (a - b) + 1;
			}
		}
		if (sum > mid) {
			left = mid;
		}
		else {
			right = mid;
		}
	}
	cout << right << endl;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main() {
  int N;
  int R;
  cin >>N>>R;
  if(N>=10) {
cout<<R<<endl;
  }
else {
  cout<<R+100*(10-N)<< endl;
}
}

Measured memory_bytes: 256
n=int(input())
s=[input() for i in range(n)]
m=0
a=0
r=0
c=0
h=0

for i in s:
  if i[0]=="M":
    m+=1
  elif i[0]=="A":
    a+=1
  elif i[0]=="R":
    r+=1
  elif i[0]=="C":
    c+=1
  elif i[0]=="H":
    h+=1

nan=0
li=[m,a,r,c,h]

for i in li:
  if i>0:
    nan+=1

import itertools

if nan<3:
  print(0)
else:
  ans=0
  for x,y,z in itertools.combinations(range(5),3):
    ans+=li[x]*li[y]*li[z]
  print(ans)

Measured memory_bytes: 9772
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
    static int[] w = new int[100010];
    static int[] v = new int[100010];
    static int[][] dp = new int[110][100010];
    static int k;

    static int chmin(int a, int b) {
        if (a > b) {
            a = b;
            return a;
        }
        return a;
    }

    static int chmax(int a, int b) {
        if (a < b) {
            a = b;
            return a;
        }
        return a;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int cat = sc.nextInt();
        int b=sc.nextInt();
        int x = sc.nextInt();
        if (cat > x) {
            System.out.println("NO");
            return;
        } else if (cat + b >= x) {
            System.out.println("YES");
            return;
        } else {
            System.out.println("NO");
        }

    }
}


Measured memory_bytes: 84052
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll k,a,b,bis,yen;
int main(){
	ios::sync_with_stdio(false);
	cin >> k >> a >> b;
	bis = 1;
	if(b-a <= 2 || k+1 < a) cout << k+1;
	else{
		while(bis < a){
			k --;
			bis ++;
		}
		if(k%2 == 0) cout << (k/2)*(b-a) +bis;
		else cout << (k/2)*(b-a) + 1 + bis;
	}
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pcc pair<char,char>
#define vi vector <int>
#define vl vector <ll>
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define pd(x) printf("%d",x)
#define plld(x) printf("%lld",x)
#define pds(x) printf("%d ",x)
#define pllds(x) printf("%lld ",x)
#define pdn(x) printf("%d\n",x)
#define plldn(x) printf("%lld\n",x)
#define INF 2e9
#define INFLL 4e18
#define spn setprecision
#define fr(x,a,b,c) for(int x = a; x <= b; x+=c)
using namespace std;
ll multiply(ll num1, ll num2, ll mod) { // with mod > 1e9
	ll ans = 0;
	num1 %= mod;
	num2 %= mod;
	while (num2) {
		if (num2&1) {
			ans += num1;
			ans %= mod;
		}
		num1 *= 2;
		num1 %= mod;
		num2 /= 2;
	}
	return ans;
}
ll powmod2(ll base,ll exponent,ll mod){ // with mod > 1e9
	ll ans = 1;
	while (exponent) {
		if (exponent&1) {
			ans = multiply(ans, base, mod);
		}
		base = multiply(base, base, mod);
		exponent /= 2;
	}
	return ans;
}
ll powmod(ll base,ll exponent,ll mod){ // with mod < 1e9
	ll ans=1;
	while(exponent){
		if(exponent&1)ans=(ans*base)%mod;
		base=(base*base)%mod;
		exponent/=2;
	}
	return ans;
}
ll gcd(ll a, ll b){
	if(b==0) return a;
	else return gcd(b,a%b);
}
const int upperlimit = 1e6+100;
const int mod = 1e9+7;
int arr[upperlimit];
int main() {
	int n;
	sd(n);
	for(int i = 1; i <= n; i++){
		sd(arr[i]);
		arr[i]-=i;
	}
	sort(arr+1,arr+n+1);
	int ind=(n+1)/2;
	ll sum=0;
	for(int i = 1; i <= n; i++){
		sum+=abs(arr[i]-arr[ind]);
	}
	pllds(sum);
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
using namespace std;
int main() {
  string s;
  int r_count = 0, ans = 0;
  cin >> s;
  for (int i=0; i<3; i++) {
    if (s[i] == 'R') r_count++;
    else r_count = 0;
    ans = max(ans, r_count);
  }
  cout << ans << endl;
}

Measured memory_bytes: 3140
#include <bits/stdc++.h>
#define rep(i,s,n) for(int i=s;i<n;i++)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define int long long
using namespace std;
using P=pair<int,int>;
using Graph=vector<vector<int>>;
using ll=long long;


vector<pair<int,int>> soinsuu(int n){
    vector<pair<int,int>> ret;
    for(int i=2;i*i<=n;i++){
        if(n%i !=0) continue;
        int ex=0;
        while(n%i ==0){
            ex++;
            n /= i; //n変更することで、それ以降の約数で割り切れることはない
        }
        ret.push_back(make_pair(i,ex));
    }
    //nが素数だった場合
    if(n!=1) ret.push_back(make_pair(n,1));
    return ret;
}

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

    vector<pair<int,int>> soin = soinsuu(n);

    int res=0;

    for(auto p:soin){
        int pi=p.first;
        int ni=p.second;

        int mi=1;
        while(ni-mi>=0){
            res++;
            ni-=mi;
            mi++;
        }
    }

    cout<<res<<endl;
}  

Measured memory_bytes: 3628
#include<iostream>
#include<math.h>
#include<stdio.h>
#include<stdlib.h>
#include<string>
using namespace std;

string a, b;

int main(){
    cin >> a >> b;
    string c = a + b;
    int num = atoi(c.c_str());
    // cout << num << endl;
    // bool flag = true;
    int target = 1;
    while (target * target < 100100)
    {
        if(target * target == num){
            printf("%s", "Yes");
            return 0;
        }
        target++;
    }
    printf("%s", "No");
}

Measured memory_bytes: 3716
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h,w,n;
    cin >> h >> w >> n;
    h = max(h,w);
    cout << (n-1)/h + 1 << endl;

    return 0;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

int main(){
  vector<int> v;
  rep(i,3){
    int a;
    cin >> a;
    v.push_back(a);
  }
  sort(ALLOF(v));

  cout << v[2] * 10 + v[1] + v[0] << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>

int main() {
  long long x;
  std::cin >> x;
  long long i = 1;
  bool ansFound = false;
  while (true) {
    long long sum = i * (i + 1) / 2;
    if (sum >= x) {
      ansFound = true;
      std::cout << i << "\n";
      break;
    }
    i++;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using intpair=pair<int,int>;
using llpair=pair<ll,ll>;
using llvec=vector<ll>;
using llmat=vector<vector<ll>>;
#define llmattp(name,a,b,num) name(a,vector<ll>(b,num))
#define INTINF 1<<30
#define LLINF 1LL<<60
#define ABS(x) ( (x)>0 ? (x) : -(x) )

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

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

ll gcd(ll a, ll b) {
	if(a==0||b==0) return 0;
	if(a<b) swap(a,b);
	ll tmp = a%b;
	while(tmp!=0) {
		a = b;
		b = tmp;
		tmp = a%b;
	}
	return b;
}

ll factorial(ll x) {
	ll f=1;
	for(ll i=2; i<x; i++) {
		f*=i;
	}
	return f;
}

ll nPr(ll n, ll r) {
	ll result=1;
	for(ll i=r+1; i<=n; i++) result*=i;
	return result;
}

ll nCr(ll n, ll r) {
	if (n == r) { return 1; }
	if (r > n) { return 0; }

	if (r > n / 2) { r = n - r; }

	if (n == 0) { return 0; }
	if (r == 0) { return 1; }
	if (r == 1) { return n; }

	double result = 1;
	for (double i = 1; i <= r; i++) {
		result *= (n - i + 1) / i;
	}

	return (ll)result;
}

bool IsPrime(ll num) {
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

	double sqrtNum = sqrt(num);
	for (ll i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			// 素数ではない
			return false;
		}
	}

	// 素数である
	return true;
}

ll GreaterBinarySearch(ll *array, ll key, ll max, ll min) {
	if(array[max]<array[min]) {
		return NULL;
	} else {
		ll mid = max + (min-max)/2;
		if(array[mid]<key) {
			return GreaterBinarySearch(array,key,max,mid-1);
		} if(array[mid]>key) {
			return GreaterBinarySearch(array,key,mid+1,min);
		} else {
			return mid;
		}
	}
}

void PrimeFact(ll x) { // 素因数分解 出力部を適切に書き換え
	int i=2;
	while(x%2&&i*i<=x) {
		cout<<2<<endl;
		x/=2;
	}
	i++;
	while(i*i<=x) {
		if(x%i) {
			i+=2;
			continue;
		}
		cout<<i<<endl;
		x/=i;
	}
}

bool Palind(string s) {
	return s == string(s.rbegin(), s.rend());
}

int main() {
	int N,M; cin>>N>>M;
	priority_queue<int> A;
	for(int i=0; i<N; i++) {
		int ai; cin>>ai;
		A.push(ai);
	}

	for(int i=0; i<M; i++) {
		A.push(A.top()/2);
		A.pop();
	}

	ll result=0LL;
	while(!A.empty()) {
		result+=A.top();
		A.pop();
	}

	cout<<result<<endl;
}


Measured memory_bytes: 892
#include <iostream> 
#include <math.h>
#include <algorithm>

using namespace std;



int main() 
{
    int a, b, k, ans, i, counter=0;
    int m[102];

    cin >> a >> b >> k;
    
    for (i=0;i<102;i++) 
    {
        m[i] = 1;
    }

    for (i=100;i>0;i--) 
    {
        if ( (a%i==0) && (b%i==0) )
        {
            counter += 1; 
            m[counter] = i;
            if (counter > k) 
            {
                break;
            }
        }
    }
    cout << m[k];

    return 0;
}

Measured memory_bytes: 256
a,b,c = gets.split.map(&:to_i)
d = []
n = 0

loop do
  n += a
  amari = n % b
  if amari == c
    puts 'YES'
    break
  elsif !d[amari]
    d[amari] = amari
  else
    puts 'NO'
    break
  end
end


Measured memory_bytes: 1788
s = list(input())
ls = len(s)
ss = sorted(s, reverse=True)
cnt = [0, 0]
ans = 0
w = 0

while ss[w] == "W":
    w += 1
    if ls == w:
        break

for i in range(ls):
    if s[i] == "B":
        ans += w + cnt[0] - i
    else:
        ans += i - cnt[1]
    cnt[s[i] != "B"] += 1

print(ans//2)


Measured memory_bytes: 83832
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair < int,int > PII;
typedef pair < ll,ll > PLL;
#define pb push_back
//#all(x) (x).begin(),(x).end()

//int const N = 1;
int const MOD = 1e9 + 7;

ll bigmod(ll a, ll b)
{
    if(b==0)
        return 1 % MOD;
    ll x = bigmod(a,b/2);
    x = (x * x) % MOD;
    if(b%2)
        x = (x * a) % MOD;
    return x;
}

int const N = 1e5 + 10;

ll n,w;// h[N];
ll dp[110][N] ;
ll ara[N][5] ;

ll wei[110] , val[110] ;


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

    cin >> n >> w;
    ll tot = 0;
    for(int i = 1; i <= n; i++)
        cin >> wei[i] >> val[i] , tot += val[i];

//    ll
    for(int i = 1; i <= tot; i++)
        dp[0][i] = 1e12;

    for(int i = 1; i <= n; i++)
    {
        for(int value = 0; value <= tot; value++)
        {
            dp[i][value] = dp[i-1][value];
            if(value >= val[i])
            {
                dp[i][value] = min(dp[i][value],
                            wei[i] + dp[i-1][value-val[i]]) ;
            }
        }
    }

    int ans = 0;
    for(int val = 0; val <= tot; val++)
    {
        if(dp[n][val] <= w)
            ans = val;
    }
    cout << ans << endl;
    return 0;
}




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

struct Loc {
    int dyx;
    int y;
    int x;

    Loc(T t) {
        dyx = get<0>(t);
        y = get<1>(t);
        x = get<2>(t);
    }
};

int main() {
    int h, w, cy, cx, dy, dx;
    cin >> h >> w >> cy >> cx >> dy >> dx;
    char s[h][w];
    rep(i, h) rep(j, w) cin >> s[i][j];
    cy--, cx--, dy--, dx--;

    vector<vector<int>> d(h, vector<int>(w, 1e9));
    d[cy][cx] = 0;

    priority_queue<T> q;
    q.push({0, cy, cx});

    while (!q.empty()) {
        Loc loc = Loc(q.top());
        q.pop();
        if (loc.dyx > d[loc.y][loc.x]) continue;

        for (int i = -2; i <= 2; i++) {
            int y = loc.y + i;
            if (y < 0 || y >= h) continue;

            for (int j = -2; j <= 2; j++) {
                int x = loc.x + j;
                if (x < 0 || x >= w) continue;
                if (s[y][x] == '#') continue;

                int dt = d[loc.y][loc.x] + (abs(i) + abs(j) > 1 ? 1 : 0);
                if (dt < d[y][x]) {
                    d[y][x] = dt;
                    q.push({-dt, y, x});
                }
            }
        }
    }

    cout << (d[dy][dx] != 1e9 ? d[dy][dx] : -1) << endl;
    return 0;
}


Measured memory_bytes: 8516
#include <iostream>
#include <cmath>
using namespace std;
int n, d, nr;
double p, x, y;

int main()
{
    cin>>n;
    cin>>d;
    for(int i=1; i<=n; i++)
    {
        cin>>x>>y;
        p=(x*x)+(y*y);
        if(sqrt(p)<=d) nr++;
    }
    cout<<nr;
    return 0;
}


Measured memory_bytes: 3840
use proconio::input;

const A: usize = 1000_000;

fn main() {
    input! {
        n: usize,
        a: [usize; n],
    }

    let mut ma = 0;
    let mut ac = vec![0; A + 1];
    for &a in &a {
        ac[a] += 1;
        ma = ma.max(a);
    }

    let mut pc = true;
    for i in 2..=ma {
        let mut c = 0;
        for j in (0..=ma).skip(i).step_by(i) {
            c += ac[j];
        }
        if c > 1 {
            pc = false;
            break;
        }
    }

    println!("{} coprime", if pc {
        "pairwise"
    } else {
        let mut v = a[0];
        for i in 1..n {
            v = num_integer::gcd(a[i], v);
        }
        if v == 1 {
            "setwise"
        } else {
            "not"
        }
    });
}


Measured memory_bytes: 20524
#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>
#define ll long long int


int main(void){
	ll k,a,b,c=1;
	scanf("%lld%lld%lld",&k,&a,&b);
	ll ans=1+k;
	if(b-a>2){
		ans=a+(b-a)*((k-(a-1))/2)+(k-(a-1))%2;
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 128
l,r = gets.split.map(&:to_i)

if l/2019 != r/2019 || l % 2019 == 0
  p 0
else
  ans = 2018
  l.upto(r-1) do |i|
    (l+1).upto(r) do |j|
      t = i*j % 2019
      ans = t if t < ans
    end
  end
  p ans
end


Measured memory_bytes: 1788
/*
author: diradon
10-Aug-19
17:39:36
*/

#include<bits/stdc++.h>
typedef long long int ll;
using namespace std;

void count(vector<string> v)
{
    ll ans = 0;
    map<string, ll> m;
    for (ll i = 0; i < v.size(); i++)
    {
        m[v[i]]++;
    }

    for (auto it = m.begin(); it != m.end(); it++)
    {
        ll count = it->second;
        ans += (count * (count - 1))/2;
    }

    cout << ans << "\n";
}

int main()
{
    //ios_base::sync_with_stdio(false);
    //cin.tie(NULL);
    vector<string> v;
    int n;
    string s;
    cin >> n;
    for (int i= 0; i < n; i++)
    {
        cin >> s;
        sort(s.begin(), s.end());
        v.push_back(s);
    }

    count(v);

}

Measured memory_bytes: 12788
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 1000000000
#define LLINF 1000000000000000ll
#define sz(x) ((int)(x).size())
#define sq(x) ((x)*(x))
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()

int h,w;
int dx[4]={0,0,1,-1};
int dy[4]={1,-1,0,0};
vector<string> f;
vector<int> pos;
int start;
int d[402][402];
int dp[1<<11][11];
int K;
int id(int x,int y){
    return x*w+y;
}
string binary(int a){
    string ret;
    for(int i=0;i<4;i++){
        if((1<<i)&a)ret+="1";
        else ret+="0";
    }
    return ret;
}
int rec(int S,int v){
    if(dp[S][v]!=-1)return dp[S][v];
    if(S==0)return 0;
    int ret = INF;
    for(int i=0;i<K;i++){
        if((S&(1<<i))!=0)ret = min(ret,rec(S-(1<<i),i)+d[pos[i]][pos[v]]);
    }
    //cout << S << ' ' << v << ' ' << ret << endl; 
    return dp[S][v]=ret;
}
int solve(){
    f.clear();
    pos.clear();
    scanf("%d %d",&w,&h);
    int N = w*h;
    if(h+w==0)return 1;
    f.resize(h);
    for(int i=0;i<h;i++)cin >> f[i];
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            d[i][j]=INF;
            if(i==j)d[i][j]=0;
        }
    }
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            for(int dir=0;dir<4;dir++){
                int nx = i+dx[dir];
                int ny = j+dy[dir];
                if(nx<0||nx>=h||ny<0||ny>=w)continue;
                if(f[i][j]=='x'||f[nx][ny]=='x')continue;
                //cout << id(i,j) << ' ' << id(nx,ny) << endl;
                d[id(nx,ny)][id(i,j)]=1;
                d[id(i,j)][id(nx,ny)]=1;
            }
        }
    }
    for(int k=0;k<N;k++){
        for(int i=0;i<N;i++){
            for(int j=0;j<N;j++){
                d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
            }
        }
    }

    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(f[i][j]=='o')start = pos.size();
            if(f[i][j]=='o'||f[i][j]=='*')pos.pb(id(i,j));
        }
    }
    K = pos.size();
    for(int i=0;i<(1<<K);i++){
        for(int j=0;j<K;j++){
            dp[i][j]=-1;
        }
    }
    int ans = rec((1<<K)-1-(1<<start),start);
    if(ans==INF)ans = -1;
    printf("%d\n",ans);
    return 0;
}

int main(){
    while(1){
        if(solve())return 0;
    }
    return 0;
}

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

using namespace std;

bool Cmp(const pair<int, int>& lhs, const pair<int, int>& rhs) {
    return lhs.second < rhs.second;
}

int main() {
    int N; cin >> N;
    
    vector<pair<int, int>> h;
    for (int i = 0; i < N; ++i) {
        int num; cin >> num;
        h.push_back(make_pair(i, num));
    }
    
    sort(h.begin(), h.end(), Cmp);
    
    for (int i = 0; i < N; ++i) {
        cout << h[i].first + 1;
        if (i != N - 1) {
            cout << " ";
        }
    }
    
    cout << "\n";
}

Measured memory_bytes: 1780
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<string>
#include <set>
#include<cmath>
using namespace std;
typedef long long ll;
int main()
{
	int n;
	cin >> n;
	int cnt = 0;
	int flag = 0;
	int a[1005] = { 0 }, b[1005] = { 0 };
	for(int i=0;i<n;i++)
	{
		cin >> a[i] >> b[i];
	}
	for (int i = 0;i < n;i++)
	{
		if (a[i] == b[i])
		{
			cnt++;
			if (cnt >= 3)
			{
				cout << "Yes" << endl;
				break;
			}
		}
		else
			cnt = 0;
	}
	if(cnt<3)
	    cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 3640
#include "bits/stdc++.h"
 
using ll = long long;
using namespace std;

int sum(int x) {
   if(x < 10) return x;
   return x % 10 + sum(x / 10);
}

void solveCase() {
   int n;
   cin >> n;

   vector <int> v(n);
   for(auto &e: v) {
      cin >> e;
   }

   vector <int> cntArr;
   int cur = v[0];
   int cnt = 1;
   for(int i = 1; i < n; i++) {
      if(v[i] == cur) {
         cnt++;
      } else {
         cntArr.push_back(cnt);
         cnt = 1;
         cur = v[i];
      }
   }
   cntArr.push_back(cnt);
   int ans = 0;
   for(auto x: cntArr) {
      ans += x / 2;
   }
   cout << ans << endl;
}

 
int main() {
   cin.tie(0);
   cin.sync_with_stdio(0);
   
   int testcase = 1;
   // cin >> testcase;
 
   for(int i = 0; i < testcase; i++) {
      solveCase();
   }
 
   return 0;
}

Measured memory_bytes: 3572
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cassert>
using namespace std;

#define REP(i,n) for (ll i = 0; i < n; i++)
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
typedef long long ll;

int H,W,N;
int X[200010];
int Y[200010];
int T[200010];

int main ()
{
    cin >> H >> W >> N;
    REP(i,N) cin >> X[i] >> Y[i];
    REP(i,N) {
        X[i]--;
        Y[i]--;
    }

    fill(T, T + 200010, 1e9);
    REP(i,N) T[X[i]] = min(T[X[i]], Y[i]);
    set < pair < int,int > > used;
    REP(i,N) used.insert(make_pair(X[i], Y[i]));
        
    int Aoki = 0;
    int Takahashi = 0;
    int pre = -10;
    for (int i = 1; i < H; i += 1) {
        if (T[i] <= Aoki) {
            cout << i << endl;
            return 0;
        }
        if (T[i] != Aoki + 1) {
            Aoki++;
        }
    }

    cout << H << endl;

    return 0;
}




Measured memory_bytes: 12032
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include <numeric>
#include<map>
#include<unordered_map>
#include<queue>

using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<n; ++i)
#define ALL(a) (a).begin(),(a).end()
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)

#define MOD 1000000007
int main(){
    ll n;
    cin >> n;

    ll dp[1000][5][5][5] = {};
    dp[0][0][0][0] = 1;
    rep(x, n)rep(i, 5)rep(j, 5)rep(k, 5){
        for(int l = 1; l < 5; ++l){
            if (i == 1 && j == 2 && l == 3) continue;
            if (i == 1 && k == 2 && l == 3) continue;
            if (j == 1 && k == 2 && l == 3) continue;
            if (j == 2 && k == 1 && l == 3) continue;
            if (j == 1 && k == 3 && l == 2) continue;
            dp[x+1][j][k][l] = (dp[x+1][j][k][l] + dp[x][i][j][k])%MOD;
        }
    }
    ll res = 0;
    for(int i = 1; i < 5; ++i)for(int j = 1; j < 5; ++j)for(int k = 1; k < 5; ++k){
        res = (res + dp[n][i][j][k])%MOD;
    }
    cout << res << endl;
}

Measured memory_bytes: 1280
#include <stdio.h>
int i, j, k, n, m, x, y, ans=0, a[100005], s[100005]; 
int main(){
    scanf("%d%d", &n, &m);
    for(i=1; i<=n; i++){
    	scanf("%d", &a[i]);
    }
    for(i=1; i<=m; i++){
    	scanf("%d%d", &x, &y);
    	if(a[x] <= a[y]) s[x] = -1;
        if(a[y] <= a[x]) s[y] = -1;
    }
    for(i=1; i<=n; i++){
    	if(s[i] != -1) ans++;
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 2512
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define mod 1000000007 //10^9+7
#define INF 1000000000000 //10^12
#define P pair<int,int>
#define rep(i,n) for(int i=0;i<n;i++)
int x;
signed main(){
    cin>>x;
    if(x<100)cout<<0<<endl;
    else if(x>=2000)cout<<1<<endl;
    else{
        int h=x/100;
        int t=x%100;
        if(t<=h*5)cout<<1<<endl;
        else cout<<0<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#import numpy as np
#import math
#from decimal import *
#from numba import njit

#@njit
def main():
    N = int(input())
    A = list(map(int, input().split()))

    A = sorted(enumerate(A), key = lambda x: x[1])[::-1]

    #dp = np.zeros((N+1,N+1), dtype='int64')
    dp = [[0]*(N+1-i) for i in range(N+1)]

    m = 0
    for i in range(1,len(A)+1):
        index,a = A[i-1]
        for j in range(i+1):
            if (i-j,j) == (0,0):
                dp[i-j][j] = 0
            elif i-j == 0:
                dp[i-j][j] = dp[i-j][j-1] + (N-j-index)*a
            elif j == 0:
                dp[i-j][j] = dp[i-j-1][j] + (abs(index-(i-j-1)))*a
            else:
                dp[i-j][j] = max(dp[i-j][j-1] + (N-j-index)*a, dp[i-j-1][j] + (abs(index-(i-j-1)))*a)
            if i == len(A):
                m = max(m, dp[i-j][j])

    #print(dp)
    #print(np.max(dp))
    print(m)

main()


Measured memory_bytes: 114564
import itertools,math,bisect,pprint,sys
s = raw_input()
n = len(s)
ans = []
for i in range(n):
    for j in list(itertools.combinations(range(n-1),i)):
        S = s
        a = 0
        for k in reversed(j):
            a += int(S[k+1:])
            S = S[:k+1]
        else:
            a += int(S)
        ans.append(a)
print sum(ans)

Measured memory_bytes: 2944
import std.stdio;
import std.string;

void main() {
	const string m = "kstnhm";
	const string ch = "aiueo";
	const string dir = "TLURD";
	auto str = readln;
	bool flag = false;
	foreach (int i, c; str) {
		if (!(i % 2)) {
			auto a = c - '0';
			if (a == 0) flag = true;
			else if (2 <= a && a <= 7) {
				write(m[a-2]);
			} else if (a == 9) {
				write('r');
			} else if (a == 8) {
				write('y');
			}
		} else {
			auto a = dir.indexOf(c);
			if (flag) {
				if (a == 0) {
					write("wa");
				} else if (a == 2) {
					write("nn");
				} else {
					write("wo");
				}
				flag = false;
			} else {
				write(ch[a]);
			}
		}
	}
	writeln;
}

Measured memory_bytes: 2492
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int M = 2e5 + 5;
int n, W;

int32_t main() 
{
	ios_base::sync_with_stdio(0);	cin.tie(0);	cout.tie(0);
	cin >> n >> W;
	vector <int> w(n), v(n);
	for(int i = 0; i < n; ++i)	
		cin >> w[i] >> v[i];
	int sum = 0;
	for(auto &i : v)
		sum += i;
	vector <int> dp(sum + 1, 1e9); 
	dp[0] = 0;

	// dp[i] - the minimum total w of items with total v exactly i
	for(int i = 0; i < n; i++) 
		for(int val = sum - v[i]; val >= 0; val--)
		    dp[val + v[i]] = min(dp[val + v[i]], dp[val] + w[i]);
	int ans = 0;
	for(int i = 0; i <= sum; i++)
		if(dp[i] <= W)
	    		ans = max(ans, i);
	cout << ans << "\n";
    	return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>

int main(){

  int H,W,i,j;

  while(scanf("%d %d",&H,&W),H!=0&&W!=0){

  for(i=0;i<H;i++){
    for(j=0;j<W;j++){
      printf("#");
    }
      printf("\n");
  }
      printf("\n");
}
  return 0;
}


Measured memory_bytes: 572
#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
#define lson x<<1
#define rson x<<1|1
#define mid ((l+r)>>1) 
int n,s[500100],sum[500100],zero[500100],f[500100],tag[2001000],res;
vector<int>v;
void pushdown(int x){
	tag[lson]+=tag[x],tag[rson]+=tag[x],tag[x]=0;
}
void update(int x,int l,int r,int P){
	if(l>P||r<P)return;
	if(l==r){(zero[P]+=1ll*tag[x]*sum[P]%mod)%=mod,tag[x]=0;return;}
	pushdown(x),update(lson,l,mid,P),update(rson,mid+1,r,P);
}
void read(int &x){
	x=0;
	char c=getchar(); 
	while(c>'9'||c<'0')c=getchar();
	while(c>='0'&&c<='9')x=(x<<3)+(x<<1)+(c^48),c=getchar();
}
int main(){
	read(n),f[0]=sum[0]=1;
	for(int i=1;i<=n;i++)read(s[i]),s[i]^=s[i-1],v.push_back(s[i]);
	sort(v.begin(),v.end()),v.resize(unique(v.begin(),v.end())-v.begin());
	for(int i=1;i<=n;i++)s[i]=lower_bound(v.begin(),v.end(),s[i])-v.begin(),zero[s[i]]=1;
	if(!v.front())v.erase(v.begin());
	else{puts("1");return 0;}
//	for(int i=1;i<=n;i++)printf("%d ",s[i]);puts("");
	if(!s[n]){
		for(int i=1;i<=n;i++)if(!s[i])f[i]=zero[0],(zero[0]+=f[i])%=mod;
		for(int i=1;i<=n;i++){
			if(!s[i])tag[1]++;
			else update(1,1,v.size(),s[i]),f[i]=zero[s[i]],(sum[s[i]]+=f[i])%=mod;
		}
		for(int i=1;i<=v.size();i++)(f[n]+=sum[i])%=mod;
		printf("%d\n",f[n]);
	}else{
		int s0=1,s1=0;
		for(int i=1;i<=n;i++){
			if(!s[i])f[i]=s1,(s0+=f[i])%=mod;
			if(s[i]==s[n])f[i]=s0,(s1+=f[i])%=mod;
		}
		printf("%d\n",f[n]);
	}
	return 0;
}
/*
3
1 2 3
3
1 2 2
24
1 2 5 3 3 6 1 1 8 8 0 3 3 4 6 6 4 0 7 2 5 4 6 2
5
1 5 4 2 3
50
0 0 1 1 0 0 1 1 2 2 0 0 3 3 0 0 1 2 3 0 0 3 3 1 3 2 0 0 0 0 0 0 0 1 2 3 0 0 1 1 2 2 3 2 0 1 0 0 0 0 
*/

Measured memory_bytes: 15384
#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <vector>
#include <string>
#include <cmath>

//Some constants don't work
#ifndef INT_MAX
#define INT_MAX 2147483647
#endif
#ifndef INT_MIN
#define INT_MIN -2147483648
#endif
//short hand tricks
typedef long long ll;

using namespace std;

double dist(double x, double y) {
    double res = sqrt(x*x+y*y);
    return res;
}

int main(int argc, char * argv[]) {
    ios_base::sync_with_stdio(false);
    int N, D;
    cin >> N >> D;
    int count = 0;
    for(int i=0; i<N; i++) {
        ll x,y;
        cin >> x >> y;
        ll d = ceil(dist((double)x,(double)y));
        if(d<=D) {
            count++;
        }
    }
    cout << count << "\n";
    return 0;
}


Measured memory_bytes: 3704
import java.io.*;
import java.util.*;


public class Main {

	private static Scanner sc;
	private static Printer pr;

	private static void solve() {
		int x = sc.nextInt();

		if (x < 1200) {
			pr.println("ABC");
		} else {
			pr.println("ARC");
		}
	}

	// ---------------------------------------------------
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		pr = new Printer(System.out);

		solve();

		pr.close();
		sc.close();
	}

	private static class Printer extends PrintWriter {
		Printer(PrintStream out) {
			super(out);
		}
	}
}


Measured memory_bytes: 9684
n,m=map(int,input().split())
sc=[]
for i in range(m):
    sc.append(list(map(int,input().split())))
# print((sc))
if n==1:l=[i for i in range(0,10)]
if n==2:l=[i for i in range(10,100)]
if n==3:l=[i for i in range(100,1000)]

for ll in l:
    k=list(str(ll))
    if all([k[s-1]==str(c) for s,c in sc]):
        print(str(ll))
        exit()
print(-1)
        

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

typedef long long int   ll;
#define f(i,st,en)    for(int i=st;i<en;i++)
#define s(n)            scanf("%d",&n)
#define sc(n)           scanf("%c",&n)
#define sl(n)           scanf("%lld",&n)
#define sf(n)           scanf("%lf",&n)

using namespace std;

int main(){
    int t;
    cin>>t;
    ll sum=0;
    for(int i=1;i<=t;i++){
        if(i%3!=0 && i%5!=0){
            sum+=i;
        }
    }
    cout<<sum;
}


Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <string>

using namespace std;


int main() {
    std::ios::sync_with_stdio(false); cin.tie(nullptr);
    string s;
    cin >> s;
    int n = s.length();
    vector<int> ans(n, 0);

    int r = -1;
    for(int i=0;i<n;++i) {
        if(s[i] == 'L') {
            ++ans[r+(i-r)%2];
        } else {
            r = i;
        }
    }

    int l = n;
    for(int i=n-1;i>=0;--i) {
        if(s[i] == 'R') {
            ++ans[l-(l-i)%2];
        } else {
            l = i;
        }
    }

    for(int i=0;i<n-1;++i) {
        cout << ans[i] << " ";
    }
    cout << ans[n-1] << endl;
}


Measured memory_bytes: 1104
N,T = map(int,input().split())
a = []
for i in range(N):
 a.append(list(map(int,input().split())))
b = []
for i in range(N):
 if a[i][1] <= T:
  b.append(a[i][0])
if len(b) == 0:
 print("TLE")
else:
 print(min(b))
  


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


const ll MOD = (ll)998244353;
struct mint {
    long long x;
    mint(long long _x=0):x((_x%MOD+MOD)%MOD){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += MOD-a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=a;
    }
    mint modpow(long long t) const {
        if (!t) return 1;
        mint a = modpow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime MOD
    mint inv() const {
        return modpow(MOD-2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res/=a;
    }
    friend std::ostream& operator<<(std::ostream& os, const mint& a){
        os << a.x;
        return os;
    }
};
mint dp[3010][3010];
int main() {

    int N, S;
    cin >> N >> S;
    vector<int> A(N);
    rep(i,N)cin>>A[i];
    rep(i,N)rep(j,S+1)dp[i][j] = 0;
    rep(i,N)dp[i][0] = 1;
    rep(i,N)rep(j,S+1){
        dp[i+1][j] += dp[i][j];
        dp[i+1][min(S+1, j + A[i])] += dp[i][j];
    }
    mint ans = 0;
    rep(i,N+1)ans += dp[i][S];
    cout << ans << endl;
    
}

Measured memory_bytes: 71040
#include <iostream>
using namespace std;
typedef long long ll;

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

  int cnt = 0;
  for(int x = 0; x <= k; x++) {
    for(int y = 0; y <= k; y++) {
      if(s-x-y >= 0 && s-x-y <= k)cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}


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

#define ll long long
using namespace std;
ll N,M;
ll A[101234];
ll ans=0,a;
map<ll,ll> llmap;
int i,j,k;

int main(){
    cin>>N>>M;
    for(i=0;i<N;i++){
        cin>>A[i];
    }
    a=0;
    llmap[0]=1;
    for(i=0;i<N;i++){
        a=(a+A[i])%M;
        llmap[a]++;
    }
    for(auto l:llmap){
        ans+=(l.second-1)*l.second/2;
    }
    cout<< ans<<endl;
    return 0;
}

Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
int  main()
{
    int t;
    cin>>t;
        string name;
        cin>>name;
        if(t>=name.size())
        {
             cout<<name<<endl;
        }

        else
        {
            int i;
            for(i=0;i<t;i++)
            {
                cout<<name[i];
            }
            cout<<"..."<<endl;
        }
}


Measured memory_bytes: 3588
// in the name of Allah

#include <bits/stdc++.h>
using namespace std;

#define endl '\n'
#define pb push_back
#define ll long long
#define double long double
#define sz(x) ((int) (x.size()))

#define fr first
#define se second

const ll mod = 998244353;

ll add(ll a, ll b) {
	a += b;
	if(a >= mod) return a - mod;
	return a;
}

ll mul(ll a, ll b) {
	a *= b;
	if(a >= mod) return a % mod;
	return a;
}

ll power(ll a, ll b) {
	if(b == 0) return 1;
	ll p = 1;
	while(b) {
		if(b&1) p = mul(p, a);
		a = mul(a, a);
		b /= 2;
	}
	return p;
}

int main() {
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	map <int, int> mp;
	for(int i=0; i<6; i++) {
		int x;
		cin >> x;
		mp[x]++;
	}
	for(auto e : mp) {
		if(e.se >= 3) {
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;
	return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<cmath>
#include<cstdio>
#include<cstring>
#include<bitset>
#include<iostream>
#include<algorithm>
#include<string>
#include<utility>
#include<tuple>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<numeric>
#include<functional>
#include<iomanip>
#include<random>

#define IOS ios::sync_with_stdio(false),cin.tie(0)
#define REP(i,n) for(int i = 0;i < n;i++)
#define FOR(i,a,b) for(int i = a;i < b;i++)
#define MEM(a,b) memset(a,b,sizeof(a))
#define ALL(x) (x).begin(),(x).end()
#define dump(x) cout << (x) << endl
#define LMAX 9223372036854775807
#define LMIN -9223372036854775808

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

struct UnionFind {
	vector<int> data;
	UnionFind(int size) : data(size, -1) {}
	void unionSet(int x, int y) {
		x = root(x), y = root(y);
		if (x != y) {
			if (data[y] < data[x])swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	int k = a % b;
	if (k == 1)return 1;
	if (k == 0)return b;
	int ans = gcd(b, k);
	return ans;
}
ll digitsum(ll a) {
	int sum = 0;
	while (a) {
		sum += a % 10;
		a /= 10;
	}
	return sum;
}
int getdigit(ll a) {
	return to_string(a).size();
}
int countpow(ll a, ll b) {
	int ans = 0;
	if (b == 0)return -1;
	while (1) {
		if (a % b == 0) {
			a /= b;
			ans++;
		}
		else break;
	}
	return ans;
}
int to_num(char c) {
	if (c >= '0' && c <= '9')return (c - '0');
	else return -1;
}

int main() {
	IOS;
	int n;
	cin >> n;
	vector<ll> v(n);
	REP(i, n) {
		int a;
		cin >> a;
		if (i == 0)v[i] = a;
		else v[i] = v[i - 1] + a;
	}
	ll ans = LMAX;
	REP(i, n - 1) {
		if (abs(v[n - 1] - v[i] * 2) < ans)ans = abs(v[n - 1] - v[i] * 2);
	}
	dump(ans);
}



Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <complex>
#include <string.h>
#include <numeric>
using namespace std;

#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) rep(i,(n)+1)
#define repst(i,s,n) reps(i,s,(n)+1)
#define reprt(i,n,t) for(int (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(i,v) for(auto &(i):(v))
#define eachr(i,v) for(auto &(i)=(v).rbegin();(i)!=(v).rend();(i)++)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define bln(i,n) (((i)==(n)-1)?'\n':' ')
#define dbg(x) cout<<#x" = "<<(x)<<ln<<flush
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ')<<flush;}}
#define zero(a) memset(a,0,sizeof(a))
#define unq(a) sort(all(a)),a.erase(unique(all(a)),a.end())

//typedef complex<double> P;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

ll mop(ll a,ll b,ll m=mod) {ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r;}
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) {return a/gcd(a,b)*b;}
bool ool(int x,int y,int h,int w) {return((x<0)||(h<=x)||(y<0)||(w<=y));}
bool deq(double a,double b) {return abs(a-b)<eps;}

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;



int n, w, a, b, dp[101][100100];

signed main() {
	cin >> n >> w;
	rep(i,n) {
		cin >> a >> b;
		rep(j,w) {
			chmax(dp[i+1][j], dp[i][j]);
			if (j+a<=w) chmax(dp[i+1][j+a], dp[i][j] + b);
		}
	}
	cout << *max_element(dp[n], dp[n]+w+1) << endl;
}

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

string divide[4] = {"dream", "dreamer", "erase", "eraser"};

int main(){
	string S;
	cin >> S;
	
	reverse(S.begin(), S.end());
	for(int i = 0; i < 4; ++i) reverse(divide[i].begin(), divide[i].end());
	
	bool can = true;
	for(int i = 0; i < S.size();){
		bool can2 = false;
		for(int j = 0; j < 4; ++j){
			string d = divide[j];
			if(S.substr(i, d.size()) == d){
				can2 = true;
				i += d.size();
			}
		}
		if(!can2){
			can = false;
			break;
		}
	}
	if(can) cout << "YES" << endl;
	else cout << "NO" << endl;
}


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

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define SZ(x) ((int)(x).size())
#define INF (1e16)
typedef long long ll;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int cnt = 0;
    rep1(i, n){
        string s = to_string(i);
        if(s.length() % 2 == 1){
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}

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

int main(){
	int n;
	cin >> n;
	ll h[n];
	for (int i = 0; i < n; ++i) cin >> h[i];
	ll dp[n] = {0};
	dp[0] = 0;	dp[1] = abs(h[1] - h[0]);
	for (int i = 2; i < n; ++i){
		dp[i] = min(dp[i-2] + abs(h[i] - h[i-2]), dp[i-1] + abs(h[i] - h[i-1]) );
	}
	cout << dp[n-1] << '\n';
	return 0;
}

Measured memory_bytes: 1792
import java.lang.Math.sqrt

fun main(args:Array<String>):Unit {
    repeat(readLine()!!.trim().toInt()){
        val arg = readLine()!!.trim().split(' ').map(String::toInt)
        val points = Array(5){
            val (x, y) = arg.drop(it * 2).take(2)
            Point(x, y)
        }
        val (a, b, c, d, e) = points
        val edge = Edge(d, e)
        val ta = Edge(a, b)
        val tb = Edge(b, c)
        val tc = Edge(c, a)
        println(if (listOf(ta, tb, tc).count{edge.isCross(it)} == 1) "OK" else "NG")
    }
}
data class Vector(val x:Int, val y:Int){
    fun cross(that:Vector):Int = x * that.y - y * that.x
    fun sin(that:Vector):Double = cross(that) / length / that.length
    val length:Double
        get() = sqrt(x.toDouble() * x + y * y)
    constructor(from:Point, to:Point):this(to.x - from.x, to.y - from.y)
}
data class Point(val x:Int, val y:Int)
data class Edge(val from:Point, val to:Point){
    fun isCross(that:Edge):Boolean {
        val eVec = Vector(from, to)
        val ffVec = Vector(from, that.from)
        val ftVec = Vector(from, that.to)
        val tVec = Vector(that.from, that.to)
        val tffVec = Vector(that.from, from)
        val tftVec = Vector(that.from, to)
        return eVec.sin(ffVec) * eVec.sin(ftVec) <= 0 && tVec.sin(tffVec) * tVec.sin(tftVec) <= 0
    }
}


Measured memory_bytes: 71012
#include <iostream>
#include <climits>
#include <algorithm>


using namespace std;

int N, K;
string S;


int main()
{

    cin >> S ;

    int n = 6;
    
//    cout << S[2] << S[3] << "\n";

    if (S[2] == S[3] && S[4] == S[5] ) {

        cout << "Yes" << "\n";

    }else{

        cout << "No" << "\n";

    }


}


Measured memory_bytes: 256
def main():
    n = int(input())
    # h, w, k = map(int, input().split())
    # a = list(map(int, input().split()))
    # s = input()

    while True:
        s = str(n)
        if s[0] == s[1] and s[1] == s[2]:
            print(int(s))
            exit()
        n += 1


if __name__ == '__main__':
    main()


Measured memory_bytes: 61612
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <vector>
using namespace std;

inline int getint()
{
	static char c;
	while ((c = getchar()) < '0' || c > '9');

	int res = c - '0';
	while ((c = getchar()) >= '0' && c <= '9')
		res = res * 10 + c - '0';
	return res;
}

const int MaxN = 100000;

int n;
int a[MaxN + 1];

vector<int> adj[MaxN + 1];

bool ok = true;

int dfs(int u, int prev)
{
	if (adj[u].size() == 1u)
		return a[u];

	int w = a[u] << 1;
	for (int v : adj[u])
		if (v != prev)
		{
			int l = dfs(v, u);
			if (l > a[u])
				ok = false;
			w -= l;
		}

	if (w < 0 || (!prev && w) || w > a[u])
		ok = false;

	return w;
}

int main()
{
	cin >> n;
	for (int u = 1; u <= n; ++u)
		a[u] = getint();
	for (int i = 1; i < n; ++i)
	{
		int u = getint(), v = getint();
		adj[u].push_back(v);
		adj[v].push_back(u);
	}

	if (n == 2)
		ok = a[1] == a[2];

	for (int u = 1; u <= n; ++u)
		if (adj[u].size() > 1u)
		{
			dfs(u, 0);
			break;
		}

	puts(ok ? "YES" : "NO");

	return 0;
}

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

#define ll long long
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define ios ios_base:sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;

const int N = 1e5 + 1;
const int MXN = 3e5 + 1;
const int MOD = 1e9 + 7;
const ll INF = 1e18;
const double PI = acos(-1.0);

int a, b;

int main() {
  cin >> a >> b;
  if(b < a) {
    cout << a - 1;
  }
  else {
    cout << a;
  }
return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <vector>
#include <cmath>
#include <tuple>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <queue>
#include <numeric>
#include <iostream>

using namespace std;


int main() {

    double T, X;

    cin >> T >> X;

    cout << (T / X) << "\n";
    return 0;
}

Measured memory_bytes: 256