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

int main(){
    vvi A(3,vi(3));
    rep(i,3){
        rep(j,3){
            cin >> A[i][j];
        }
    }
    int N;
    cin >> N;

    //穴が開く箇所は1,空いてない箇所は0とする
    int b;
    vvi value(3,vi(3,0));
    rep(i,N){
        cin >> b;
        rep(j,3){
            rep(k,3){
                if(A[j][k] == b) value[j][k] = 1;
            }
        }
    }

    //ビンゴ判定
    bool ans = false;
    bool flag = false;
    bool sub1,sub2;
    sub1 = (value[0][0] == 1)&&(value[2][2] == 1);
    sub2 = (value[0][2] == 1)&&(value[2][0] == 1);
    if((value[1][1] == 1)&&(sub1||sub2)) ans = true;
    rep(i,3){
        rep(j,3){
            if(value[i][j] == 0) break;
            if(j == 2){
                ans = true;
                flag = true;
                break;
            }
        }
        if(flag) break;
    }
    if(!ans){
        flag = false;
        rep(i,3){
            rep(j,3){
                if(value[j][i] == 0) break;
                if(j == 2){
                    ans = true;
                    flag = true;
                    break;
                }
            }
            if(flag) break;
        }
    }

    if(ans) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

int main () {
  int x;
  cin >> x;
  x = abs(x);
  int d = 0, t = 0;
  while(x > d) {
    t++;
    d += t;
  }
  cout << t << endl;
  return 0;
}


Measured memory_bytes: 256
import heapq
N, M = map(int, input().split())
w = [[] for i in range(M)]
for i in range(N):
    a, b = map(int, input().split())
    try:
        w[a-1].append(-b)
    except:
        pass
ans = 0
a = []
heapq.heapify(a)
for i in range(M):
    for x in w[i]:
        heapq.heappush(a, x)
    try:
        ans += -heapq.heappop(a)
    except:
        pass
print(ans)

Measured memory_bytes: 72864
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] num = new int[100001];
		for (int i = 0; i < n; i++) {
			int a = sc.nextInt();
			num[a]++;
		}
		
		int ans = 1;
		for (int x = 1; x < 99999; x++) {
			int cnt = num[x - 1] + num[x] + num[x + 1];
			ans = Math.max(ans, cnt);
		}
		
		System.out.println(ans);
	}
}


Measured memory_bytes: 49576
#include <stdio.h>

long GCD(long a, long b){
  long dividend, divisor;
  if (a >= b) {
    dividend = a;
    divisor = b;
  } else {
    dividend = b;
    divisor = a;
  }
  long remainder;
  while (1) {
    if (divisor == 1) {
      return 1;
    }
    remainder = dividend % divisor;
    if (remainder == 0) {
      break;
    } else {
      dividend = divisor;
      divisor = remainder;
    }
  }
  return divisor;
}

int main(void){

  long a,b;
  scanf("%ld %ld", &a, &b);

  long gcd_ = GCD(a,b);
  long answer = a*b;
  answer /= gcd_;

  printf("%ld\n", answer);

  return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <time.h>
#define sf scanf
#define pf printf
#define lf double
#define ll long long
#define p123 printf("123\n");
#define pn printf("\n");
#define pk printf(" ");
#define p(n) printf("%d",n);
#define pln(n) printf("%d\n",n);
#define s(n) scanf("%d",&n);
#define ss(n) scanf("%s",n);
#define ps(n) printf("%s",n);
#define sld(n) scanf("%lld",&n);
#define pld(n) printf("%lld",n);
#define slf(n) scanf("%lf",&n);
#define plf(n) printf("%lf",n);
#define sc(n) scanf("%c",&n);
#define pc(n) printf("%c",n);
#define gc getchar();
#define re(n,a) memset(n,a,sizeof(n));
#define len(a) strlen(a)
#define LL long long
using namespace std;
#include<vector>
#include<algorithm>
#include <iostream>
#include <math.h>
#define ll long long
using namespace std;
const ll mod = 1e9+7;
//快速幂
ll pow_quick(ll a,ll b){
    ll r = 1,base = a;
    while(b){
        if(b & 1){
            r *= base;
            r %= mod;
        }
        base *= base;
        base %= mod;
        b >>= 1;
    }
    return r;
}
//组合数
ll C(ll n, ll m){
    if(m > n)
        return 0;
    ll ans = 1;
    for(int i=1; i<=m; i++){
        ll a = (n+i-m)%mod;
        ll b = i%mod;
        ans = (ans*(a*pow_quick(b,mod-2)%mod))%mod;
    }
    return ans;
}
//卢卡斯定理
ll Lucas(ll n, ll m){
    if(m == 0)
        return 1;
    return C(n%mod, m%mod)*Lucas(n/mod,m/mod)%mod;
}
ll sum0 = 0;

int main(){
    ll H,W,A,B;
    cin >> H>>W>>A>>B;
    //cout << 15*14*13*12*11*10/6/5/4/3/2/1;
    /*H--;
    W--;
    A--;
    B--;*/

    //10 7 3 4
    //Lucas(H-A+i-2,H-A-1)*Lucas(W-i+A-1,A-1
    //流泪 sum = Lucas(H+W,H);
    ll a = Lucas(H-A+(B+1)-2,H-A-1);
    ll b = Lucas(W-(B+1)+A-1,A-1);
    for(ll i = B+1; i <= W; i ++){
        sum0 += (a*b)%mod;
        sum0 %= mod;
        a *= (H-A+i-2+1);
        a %= mod;
        a *= pow_quick(H-A+i-2-(H-A-1)+1,mod-2);
        a %= mod;
        b *= W-i+A-1-(A-1);
        b %= mod;
        b *= pow_quick(W-i+A-1,mod-2);
        b %= mod;
        //pld(i) pn
        /*if(i % 10 == 0){
            pld(i) pn
        }*/
    }
    /*sum0 += (a*b)%mod;
    sum0 %= mod*/
    cout << (sum0+mod)%mod;


    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL


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

    string s;
    cin >> s;

    int snum = 0;
    int tnum = 0;
    bool calc = false;
    int ans = 0;
    rep (i, s.size())
    {
        if (s[i] == 'S')
        {
            if (calc)
            {
                calc = false;
                int add = MIN(snum, tnum);
                ans += add << 1;
                snum -= add;
                tnum = 0;
            }
            ++snum;
        }
        else if (s[i] == 'T')
        {
            calc = true;
            ++tnum;
        }
    }

    if (calc)
    {
        calc = false;
        int add = MIN(snum, tnum);
        ans += add << 1;
        snum -= add;
        tnum = 0;
    }

    cout << s.size() - ans << "\n";
    return 0;
}



Measured memory_bytes: 720
A, B, C, D, E, F = [int(item) for item in input().rstrip().split(" ")]

mizu_arr = []
for i in range(F // (A*100) + 1):
    for j in range((F - i * A * 100) // (B*100) + 1):
        mizu = i * A * 100 + j * B * 100
        if mizu > 0:
            mizu_arr.append(mizu)

mizu_arr = sorted(mizu_arr)

def func(sato):
    min_mizu = sato * 100.0 / E
    max_mizu = F - sato
    for mizu in mizu_arr:
        if max_mizu < mizu:
            return None
        if min_mizu <= mizu:
            return mizu
    return None

max_nodo = 0
ans = [A*100, 0]
max_sato = (F // (100 + E)) * E
for i in range(max_sato // C + 1):
    for j in range((max_sato - i * C) // D + 1):
        sato = i * C + j * D
        mizu = func(sato)
        if not mizu == None:
            if 100 * sato / (mizu + sato) > max_nodo:
                ans = [mizu + sato, sato]
                max_nodo = 100 * sato / (mizu + sato)
              
print("{} {}".format(ans[0], ans[1]))

Measured memory_bytes: 3064
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
const int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

int main() {
  int l, r, d; cin >> l >> r >> d;
  int ans = 0;
  FOR(i, l, r + 1) ans += i % d == 0;
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 3596
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cstring>
#include <queue>
#include <vector>
#include <functional>
#include <map>
#include <set>
#include <cmath>
#include <string>
#define SIZE 200005
#define INF 1000000005LL

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

int n;
ll K;

int C[25];
int T[100005];


void dps(){
	C[0]=1;
	C[1]=6;
	C[2]=9;
	for(int i=1;i<=7;i++){
		int j=i*2;
		C[j+1] = C[j-1]*6;
		C[j+2] = C[j]*9;
	}
	sort(C,C+17);
	reverse(C,C+17);
}


int main()
{
	int m=17;
	scanf("%d",&n);
	dps();

	for(int i=0;i<=n;i++)T[i]=99999999;
	T[0] = 0;

	for(int i=1;i<=m;i++){
		for(int j=C[i];j<=n;j++){
			T[j] = min(T[j],T[j-C[i]]+1);
		}
	}

	printf("%d\n",T[n]);
	return 0;
}


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

int main(void) {
	int n, a, c = 1, ans = 0;

	scanf("%d", &n);

	for (int i = 0; i < n; i++) {
		scanf("%d", &a);
		if (a != c) {
			ans++;
		}
		else {
			c++;
		}
	}

	if (ans == n) {
		printf("-1");
	}
	else {
		printf("%d", ans);

	}
}

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

int main(){
	
	double a[2];
	int b[4][2]={0};
	while(cin>>a[0]>>a[1]){
	for(int i=0;i<2;i++){
	if(a[i]<0.2)
		b[3][i]++;
	else if(a[i]<0.6)
		b[2][i]++;
	else if(a[i]<1.1)
		b[1][i]++;
	else
		b[0][i]++;
	}
	}
	for(int i=0;i<4;i++)
		cout<<b[i][0]<<" "<<b[i][1]<<endl;
	

}

Measured memory_bytes: 1224
n = int(input())
a = list(map(int, input().split()))

color = [0] * 8
free = 0
for i in a:
    if i < 3200:
        c = i // 400
        color[c] = 1
    else:
        free += 1

ans = sum(color)
print(max(1, ans), ans + free)


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

#define ll long long
#define ld long double

#define x first
#define y second
#define pb push_back
#define mp make_pair

#define len(a) (int)(a).size()
#define all(a) (a).begin(), (a).end()

int su[200007], co[200007];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, p;
    string s;
    cin >> n >> p >> s;
    if (p == 2) {
        ll ans = 0;
        for (int i = 0; i < n; i++) {
            if ((s[i] - '0') % 2 == 0) ans += i + 1;
        }
        cout << ans;
        return 0;
    }
    if (p == 5) {
        ll ans = 0;
        for (int i = 0; i < n; i++) {
            if (s[i] == '0' || s[i] == '5') ans += i + 1;
        }
        cout << ans;
        return 0;
    }
    su[0] = 0;
    int cur = 1;
    for (int i = 0; i < n; i++) {
        cur = cur * 10 % p;
        su[i + 1] = su[i] + (s[n - i - 1] - '0') * cur % p;
        if (su[i + 1] >= p) su[i + 1] -= p;
    }
    ll ans = 0;
    for (int i = 0; i <= n; i++) {
        ans += co[su[i]];
        co[su[i]]++;
    }
    cout << ans;
    return 0;
}


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

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);
		//入力表示

		int N = sc.nextInt();
		double[]v=new double[N];
		
		for(int i=0;i<N;i++) {
			v[i]=sc.nextInt();
		}
		//昇順に並べる
		Arrays.sort(v); 
		
		double ans =v[0];
		
		for(int i=1;i<N;i++) {
			ans=(ans+v[i])/2;
		}
		System.out.println(ans);
     
    }
}

Measured memory_bytes: 27236
use std::io;


fn main() {
    let (a, b) = {
        let i = read::<usize>();
        (i[0], i[1])
    };
    println!("{}", lcm(a, b));
}

#[allow(unused)]
fn lcm(a: usize, b: usize) -> usize {
    (a / gcd(a, b)) * b
}

#[allow(unused)]
fn gcd(a: usize, b: usize) -> usize {
    if b == 0 {
        a
    } else {
        gcd(b, a % b)
    }
}

#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
std::str::FromStr,
T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
std::str::FromStr,
T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

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

int main() {
    int a, b, c, d;
    int left, right;
    cin >> a >> b >> c >> d;
    left = a + b;
    right = c + d;
    
    if (left > right) {
        cout << "Left" << endl;
    } else if (left == right) {
        cout << "Balanced" << endl;
    } else {
        cout << "Right" << endl;
    }
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
#define ll long long
#define int ll
using namespace std;
inline int lowbit(int x){return (x&(-x));}
const int N=2e5+5;
int tree[N],n,h[N],a[N],ans;
int search(int x)
{
	int res=0;
	for(;x!=0;x-=lowbit(x))
	{
		res=max(res,tree[x]);
	}
	return res;
}
void update(int x,int y)
{
	for(;x<=n;x+=lowbit(x))	
	{
		tree[x]=max(tree[x],y);
	}
	return;
}
signed main()
{
	cin>>n;
	for(int i=0;i<n;i++)cin>>h[i];
	for(int i=0;i<n;i++)cin>>a[i];
	for(int i=0;i<n;i++)
	{
		int sum=search(h[i])+a[i];
		ans=max(ans,sum);
		update(h[i],sum);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 4992
#include <iostream>

int max(int x, int y) {
  return x > y ? x : y;
}

int main(int argc, char** argv) {
  int a;
  int b;
  std::cin >> a >> b;
  int result = max(a+b, max(a-b, a*b));
  std::cout << result;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <iomanip>
#include <list>
#include <cmath>
#include <math.h>
using namespace std;

void Koch_Curve(int d, double x1, double y1, double x2, double y2) {
  if(d == 0)
    return;
  double sx = (2*x1+x2)/3, sy = (2*y1+y2)/3, tx = (x1+2*x2)/3, ty = (y1+2*y2)/3;
  double dx = tx - sx, dy = ty - sy;
  double ux = dx*cos(M_PI/3)-dy*sin(M_PI/3)+sx, uy = dx*sin(M_PI/3)+dy*cos(M_PI/3)+sy;
  
  Koch_Curve(d-1, x1, y1, sx, sy);
  cout << sx << ' ' << sy << endl;
  Koch_Curve(d-1, sx, sy, ux, uy);
  cout << ux << ' ' << uy << endl;
  Koch_Curve(d-1, ux, uy, tx, ty);
  cout << tx << ' ' << ty << endl;
  Koch_Curve(d-1, tx, ty, x2, y2);
}

int main() {
  int N;
  cin >> N;
  
  double x1 = 0.0, y1 = 0.0, x2 = 100.0, y2 = 0.0;
  cout << fixed << setprecision(8) << x1 << ' ' << y1 << endl;
  Koch_Curve(N, 0, 0, 100, 0);
  cout << x2 << ' ' << y2 << endl;

  return 0;
}

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

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//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 EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

int main() {
	int n; cin >> n;
	vector<vector<pair<int,int>>> d(n, vector<pair<int,int>>());

	for (int i = 0; i < n; i++) {
		int a; cin >> a;
		for (int j = 0; j < a; j++) {
			int x; cin >> x;
			int y; cin >> y;
			x--;
			d[i].push_back(make_pair(x, y));
		}
	}

	int ans = 0;
	for (LL bit = 0; bit < (1 << n); ++bit) {
		//たってるなら正直者
		bool f = true;
		int cnt = 0;
		for (int j = 0; j < n; j++) {
			if (bit&(1 << j)) {
				cnt++;
				for (int k = 0; k < d[j].size(); k++) {
					//正直者の証言の対象
					int man = (int)d[j][k].first;
					//正直者の発言
					int hatugen = (int)d[j][k].second;

					//実際のbit列の結果
					int fact = 0;
					if (bit & (1 << man)) {
						fact = 1;
					}
					

					if (hatugen!=fact) {
						f = false;
					}
				}
			}
			
		}

		if (f) {
			ans = max(ans, cnt);
		}
	}
	cout << ans<< endl;
	return 0;
}

/*
2
1
2 1
1
1 1
*/

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define N 1000000007
#define pll pair<ll,ll>


int main() {

	ll n, w;
	scanf("%lld %lld",&n,&w);
	vector<ll> dp(w+1,0);

	ll maxi = 0;
	for(ll i=0;i<n;i++){
		ll we, v;
		scanf("%lld %lld",&we,&v);

		for(ll j = w-we;j>=0;j--){
			dp[j+we] = max(dp[j]+v,dp[j+we]);
			maxi = max(dp[j+we],maxi);
		}

	}
	cout<<maxi<<endl;

	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
const ll MOD = 1e9+7;
 
int main(){
  int a, p;
  cin >> a >>p;
  cout << (3*a+p)/2 << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>

#include <cstdio>

using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
typedef long long ll;
typedef unsigned long long ull;

int main()
{
	ll N;
	ll ans = 10000000000000;

	cin >> N;

	for (ll i = 1; i * i <= N; i++) {
		if (N % i == 0) {
			ans = min(ans, i + N / i) - 2;
		}
	}

	cout << ans << endl;

	return 0;
}

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

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt(), K = sc.nextInt();
		int[] h = new int[N];
		for(int i = 0; i < N; i++) h[i] = sc.nextInt();
		int ans = Integer.MAX_VALUE;
		Arrays.sort(h);
		for(int i = 0; i + K - 1 < N; i++) ans = Math.min(ans, h[i + K - 1] - h[i]);
		System.out.println(ans);
	}
}

Measured memory_bytes: 50696
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; 
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

////////////////////
template< typename T>
struct SparseTable{
    vector<vector<T> > st;
    vector<int> lookup;
    T op(T a,T b){
        //max , min or etc...
        return max(a,b);
    }
 
    SparseTable(const vector<T> &v){
        int b=0;
        while((1<<b)<=v.size()) b++;
        //resize  st[k][i]:iの2^k先までの範囲の
        st.assign(b,vector<T>(1<<b));
        for(int i=0;i<v.size();i++) st[0][i]=v[i];
        for(int i=1;i<b;i++){
            for(int j=0;j+(1<<i)<=(1<<b);j++){
                st[i][j]=op(st[i-1][j],st[i-1][j+(1<<(i-1))]);
            }
        }
        lookup.resize(v.size()+1);
        for(int i=2;i<lookup.size();i++){
            lookup[i]=lookup[i>>1]+1;
        }
    }
    //[)
    T f(int l,int r){
        assert(l<=r);
        //a[l~l+2^k],a[r-2^k~r]が区間を覆うように
        int b=lookup[r-l];
        return op(st[b][l],st[b][r-(1<<b)]);
    }
};
//////////////


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

    ll n,c;cin>>n>>c;
    vector<ll> x(n),v(n);
    rep(i,n) cin>>x[i]>>v[i];
    ll a1=0,a2=0,a3=0,a4=0;
    ll ans=0;
    //右回りだけ
    vector<ll> vv;
    ll cal=0;
    for(int i=0;i<n;i++){
        cal+=v[i];
        vv.push_back(cal-x[i]);
        a1=max(a1,cal-x[i]);
    }
    //左回りだけ
    vector<ll> vvv;
    cal=0;
    for(int i=n-1;i>=0;i--){
        cal+=v[i];
        vvv.push_back(cal-(c-x[i]));
        a2=max(a2,cal-(c-x[i]));
    }

    //折り返す。
    //それぞれ左にいったとこから右の最大まで行く
    SparseTable<ll> sp(vv);
    cal=0;
    for(int i=n-1;i>0;i--){
        ll dis=c-x[i];
        cal+=v[i];
        ll tmp=cal-2*dis+sp.f(0,i);
        a3=max(a3,tmp);
    }


    //右に行って左の最大までいく
    SparseTable<ll> st(vvv);
    cal=0;
    for(int i=0;i<n-1;i++){
        ll dis=x[i];
        cal+=v[i];
        ll tmp=cal-2*dis+st.f(0,n-i-1);
        a4=max(a4,tmp);
    }

    // cout<<a1<<endl;
    // cout<<a2<<endl;
    // cout<<a3<<endl;
    // cout<<a4<<endl;

    ans=max({a1,a2,a3,a4});
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 40016
n, m = map(int, input().split())

r = [False] * n
r[0] = True
l = [1] * n

for _ in range(m):
    x, y = map(int, input().split())
    l[x - 1] -= 1
    l[y - 1] += 1
    #if r[x - 1]:
    #    r[y - 1] = True
    r[y - 1] = r[x - 1] | r[y - 1]
    if l[x - 1] == 0:
        r[x - 1] = False

c = 0
for i in range(n):
    if r[i] == True and l[i] > 0:
        c += 1

print(c)


Measured memory_bytes: 4596
N, K = map(int, input().split())
S = input()

# https://drken1215.hatenablog.com/entry/2019/04/14/222900
# 1が連続する個数の列に直す

SS = []
if S[0] == '0':
    SS.append(0)
i = 0
while i < len(S):
    j = i
    while j < len(S) and S[j] == S[i]:
        j += 1
    SS.append(j - i)
    i = j
if S[-1] == '0':
    SS.append(0)

# print(SS)

# 累積和
sums = [0 for _ in range(len(SS) + 1)]
for i in range(len(SS)):
    sums[i + 1] = sums[i] + SS[i]
# print(sums)

# 偶数番目からはじまる長さ (2K + 1) 区間の総和
ans = 0
for left in range(0, len(sums), 2):
    right = left + K * 2 + 1
    if right >= len(sums): # 飛び越したら末尾まで
        right = len(sums) - 1
    ans = max(ans, sums[right] - sums[left])
print(ans)


Measured memory_bytes: 46940
//ABC084
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define LL_MIN -9223372036854775808
#define LL_MAX 9223372036854775807
#define segment_size 65536
int main(){
    int M;
    cin >> M;
    cout << 24-M + 24 << endl;
    
    return 0;
}

Measured memory_bytes: 256
use std::io;
use std::str::FromStr;

fn input_int_tuple() -> (i32, i32) {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    let vec: Vec<i32> = line.split_whitespace().map(|s| s.parse().unwrap()).collect();
    (vec[0], vec[1])
}

fn main() {
    let (n, h) = input_int_tuple();
    let mut a_vec: Vec<i32> = Vec::new();
    let mut b_vec: Vec<i32> = Vec::new();
    for _ in 0..n {
        let (a, b) = input_int_tuple();
        a_vec.push(a);
        b_vec.push(b);
    }
    a_vec.sort_by(|a, b| b.cmp(a));
    let a_max = a_vec[0];
    b_vec.sort_by(|a, b| b.cmp(a));

    // println!("{:?}", a_vec);
    // println!("{:?}", b_vec);

    let mut sum = 0;
    let mut count = 0;
    for b in b_vec {
        if b > a_max {
            sum += b;
            count += 1;
        } else {
            break;
        }
         if sum >= h {
            println!("{}", count);
            return;
        }
    }
    if (h - sum) % a_max == 0{
        println!("{}", count + (h - sum) / a_max);
    } else {
        println!("{}", count + (h - sum) / a_max + 1);
    }
    
}


Measured memory_bytes: 6396
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<stack>
#include<ctime>
#include<cstdlib>
#include<vector>
#include<cmath>
using namespace std;
int n,m;
struct node{
	int x,y;
}a[55],b[55];
int dis(int i,int j)
{
	return abs(a[i].x-b[j].x)+abs(a[i].y-b[j].y);
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)scanf("%d%d",&a[i].x,&a[i].y);
	for(int i=1;i<=m;i++)scanf("%d%d",&b[i].x,&b[i].y);
	for(int i=1;i<=n;i++)
	{
		int minn=1e9;int p=0;
		for(int j=1;j<=m;j++)
		{
			
			if(dis(i,j)<minn)
			{
				minn=dis(i,j);p=j;
			}
			
		}cout<<p<<endl;
	}
	return 0;
}


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


int main()
{
    string S;
    cin >> S;

    int red=0;
    int blue=0;
    for (int i = 0; i < S.size(); ++i)
    {
        if(S[i] == '0'){
            ++red;
        }else{
            ++blue;
        }
    }

    int ans = min(red, blue) * 2;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<math.h>
#include<algorithm>
#include<vector>
#include<string>
typedef long long ll;
using namespace std;
ll gcd(ll a, ll b) {
	if (b > a) {
		ll tmp = b;
		b = a;
		a = tmp;
	}
	if (a%b == 0)return b;
	else return gcd(b, a%b);
}

int main(void){
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    ll x=b/c-(a-1)/c;
    ll y=b/d-(a-1)/d;
    ll l=c*d/gcd(c,d);
    ll z=b/l-(a-1)/l;
    cout<<(b-a+1)-(x+y-z)<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
	int N;
	cin >> N;
	vector<pair<int, int> > W(N);
	for (int i = 0; i < N; ++i) {
		cin >> W[i].second >> W[i].first;
	}
	sort(W.begin(), W.end());
	long long sum = 0;
	bool ok = true;
	for (int i = 0; i < N; ++i) {
		sum += W[i].second;
		if (sum > W[i].first) {
			ok = false;
		}
	}
	cout << (ok ? "Yes" : "No") << endl;
	return 0;
}

Measured memory_bytes: 4760
#include <bits/stdc++.h>
#define ll long long
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = 1; i <= n; i++)
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }
using P = pair <int, int>;

ll MOD = 1000000007;
ll INF =1<<29;
ll dp[100100];
int main() {
    int k;
    string s;
    cin >> k>>s;
    if(s.size()<=k){
        cout << s<<endl;
        return 0;
    }
    else {
        rep(i,k){
            cout << s[i];
        }
        cout << "...";
    }
}

Measured memory_bytes: 3628
package main

import (
	"bufio"
	"math"
	"os"
	"sort"
	"strconv"
	"strings"
	"fmt"
)

var sc = bufio.NewScanner(os.Stdin)

func read() string {
	sc.Scan()
	return sc.Text()
}

func geti() int {
	n, _ := strconv.Atoi(read())
	return n
}

// 10 11 12 => [10, 11, 12]
func getli(size int) ([]int) {
	a := make([]int, size)
	list := strings.Split(read(), " ")
	for i, s := range list {
		n, _ := strconv.Atoi(s)
		a[i] = n
	}
	return a
}

func get2byte(size int) ([][]byte) {
	a := make([][]byte, size)
	for i := 0; i < size; i++ {
		var low string
		fmt.Scan(&low)
		a[i] = []byte(low)
	}
	return a
}

func transpose(a [][]int) {
	n := len(a)
	for i := 0; i < n; i++ {
		for j := i + 1; j < n; j++ {
			a[i][j], a[j][i] = a[j][i], a[i][j]
		}
	}
}

func min(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Min(float64(res), float64(nums[i])))
	}
	return res
}

func main() {
	n := geti()
	ds := getli(n)
	fmt.Println(solve(ds))
}

func solve(ds []int) int {
	if len(ds) == 1 {
		return ds[0]
	}
	var res [25]bool
	res[0] = true
	res[24] = true

	sort.Ints(ds)

	for i, d := range ds {
		if i % 2 == 0 {
			if res[d] {
				return 0
			}
			res[d] = true
		} else {
			if res[24-d] {
				return 0
			}
			res[24-d] = true
		}
	}
	minnum := 100000
	counter := 1000000
	for _, b := range res {
		if b {
			minnum = min(counter, minnum)
			counter = 0
		}
		counter += 1
	}
	return minnum
}

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

int main() {
  int N;
  string S;
  cin >> N;
  cin >> S;
  
  int a;
  string ans;
  
  for (int i = 0; i < S.length(); i++) {
    a = S[i] - 'A'; //"A"ではなく'A'で書く
    a += N;
    a %= 26; //アルファベットは26文字
    ans += a + 'A';
  }
  cout << ans << endl;
  return 0;
}


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

class Program
{
    static void Main(string[] args)
    {
        var input = long.Parse(Console.ReadLine());
        long m = 100;
        var year = 0;
        var flag = true;
        while (flag)
        {
            m = m + (long)Math.Truncate(m * 0.01);
            year++;
            if(m >= input)
            {
                flag = false;
            }
        }
        Console.WriteLine(year);

        Console.ReadLine();
    }
}



Measured memory_bytes: 17672
def lcs(s1_raw, s2_raw):
    dp = []
    for s2 in s2_raw:
        start = 0
        for i, cnt in enumerate(dp):
            index = s1_raw.find(s2, start) + 1
            if not index:
                break
            else:
                dp[i]  = min(cnt , index)
                start = cnt
        index = s1_raw.find(s2, start) + 1
        if index:
            dp.append(index)
    return len(dp)


if __name__ == "__main__":
    q = int(input())
    for _ in range(q):
        x = input()
        y = input()
        print(lcs(x, y))


Measured memory_bytes: 5616
#include<bits/stdc++.h>
#define ALL(c) (c).begin(),(c).end()
#define EACH(i,c) for(auto i=(c).begin();i!=(c).end();++i)
using namespace std;

int main(){
  int N,M;
  cin >> N >> M;
  int res=1;
  vector<bool> boxes;
  vector<int> balls;
  for(int i=0;i<N;i++){
      balls.push_back(1);
      boxes.push_back(false);
  }
  boxes[0]=true;
  for(int i=0;i<M;i++){
    int x,y;
    cin >> x >> y;
    balls[x-1]--;
    balls[y-1]++;

    if(!boxes[y-1] && boxes[x-1]){
      
res++;
      boxes[y-1]=true;
    }
    if(balls[x-1]==0){
      if(boxes[x-1])
	res--;
      boxes[x-1]=false;
      
    }
  }
 
  cout <<res<<endl;

  
  return 0;
}


Measured memory_bytes: 892
n = gets.chomp.to_i
s = gets.chomp
hash = {
  "R"=> 0,
  "G"=> 0,
  "B"=> 0
}
s.split("").each do |c|
  hash[c] += 1
end
ans = hash["R"] * hash["G"] * hash["B"]
0.upto(n-3) do |i|
  (i+1).upto(n-2).each do |j|
    k = 2 * j - i
    next if k >= n
    ans -= 1 if s[i] != s[j] && s[j] != s[k] && s[k] != s[i]
  end
end

puts ans


Measured memory_bytes: 14556
import sys
input = sys.stdin.readline

#n = int(input())
#l = list(map(int, input().split()))

'''
a=[]
b=[]
for i in range():
    A, B = map(int, input().split())
    a.append(A)   
    b.append(B)'''

n=int(input())
ans=[0]*n
for i in range(1,int(n**(1/2))+1):
    for j in range(1,int(n**(1/2))+1):
        for k in range(1,int(n**(1/2))+1):
            if i**2+j**2+k**2+i*j+j*k+k*i<n+1:
                ans[i**2+j**2+k**2+i*j+j*k+k*i-1]+=1
for i in range(n):
    print(ans[i])

Measured memory_bytes: 9672
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
typedef long long int ll;
typedef pair<ll,ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
const ll MOD = 998244353;
const ll INF = 1e18;
#define REP(i,n) for(int i=0;i<n;i++)
#define ALL(v) v.begin(),v.end()

template<typename T>
struct Segtree{
	int N; T M; function<T(T,T)> F;
	vector<T> dat;
	Segtree(int N_, T M_, function<T(T,T)> F_):dat(N_*4,M), M(M_), F(F_){
		int x=1;
		while(N_>x){x*=2;}
		N=x;
	}
	void update(int i, T x){
		i+=N-1;
		dat[i]=x;
		while(i>0){
			i=(i-1)/2;
			dat[i]=F(dat[i*2+1],dat[i*2+2]);
		}
	}
	T query(int a, int b){
		return query_sub(a,b,0,0,N);
	}
	T query_sub(int a, int b, int k, int l, int r){
		if(r<=a||b<=l)
			return M;
		else if(a<=l&&r<=b)
			return dat[k];
		else{
			T vl=query_sub(a,b,k*2+1,l,(l+r)/2);
			T vr=query_sub(a,b,k*2+2,(l+r)/2,r);
			return F(vl,vr);
		}
	}
};
//Segtree<T> st(n,m,[](T x,T y){return x+y});
const int M=300010;

int main(){
	int n, k; cin >> n >> k;
	VI a(n); REP(i,n) cin >> a[i];
	Segtree<int> st(M+1,0,[](int x, int y){return max(x,y);});
	REP(i,n){
		st.update(a[i],st.query(a[i]-k,a[i]+k+1)+1);
	}
	cout << st.query(0,M+1) << endl;
	return 0;
}

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

int main(){

    int ans=700;
    string s;
    cin>>s;
    if(s[0]=='o') ans+=100;
    if(s[1]=='o') ans+=100;
    if(s[2]=='o') ans+=100;

    cout<<ans<<endl;







    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    int y = Integer.parseInt(s.substring(0, 4));
    int m = Integer.parseInt(s.substring(5, 7));
    int d = Integer.parseInt(s.substring(8));
    String ans = "TBD";
    if(y < 2019) {
      ans = "Heisei";
    } else if(y == 2019) {
      if(m < 4) {
        ans = "Heisei";
      } else if(m == 4) {
        if(d <= 30) ans = "Heisei";
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 23252
#include <iostream>
using namespace std;
int main(){
    int n, i;
    double ans=0, a[1000];
    cin >> n;
    for(i=0;i<n;i++){
        cin >> a[i];
    }
    for(i=0;i<n;i++){
        ans=ans+(1.0/a[i]);
    }
    ans=1/ans;
    cout << ans <<endl;
    return 0;
}

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

#define ll long long

int main(){
    ll A, B, M, ans = 2*pow(10,5);
    cin >> A >> B >> M;
    vector<ll> a(A+1), b(B+1), c(M+1), x(M+1), y(M+1);
    for(int i = 1; i <= A; ++i) cin >> a[i];
    for(int i = 1; i <= B; ++i) cin >> b[i];
    for(int i = 1; i <= M; ++i) cin >> x[i] >> y[i] >> c[i];
    for(int i = 1; i <= M; ++i){
        ans = min(ans, a[x[i]]+b[y[i]]-c[i]);
    }
    sort(a.begin()+1, a.end());
    sort(b.begin()+1, b.end());
    ans = min(ans, a[1] + b[1]);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 7204
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = Integer.parseInt(scan.next());
		int x = 0;
		int y = 0;
		int t = 0;
		boolean possible = true;
		for(int i=0; i<n; ++i) {
			int ti = Integer.parseInt(scan.next());
			int xi = Integer.parseInt(scan.next());
			int yi = Integer.parseInt(scan.next());

			int kyori = Math.abs(x-xi) + Math.abs(y-yi);
			int jikokuNoSa = Math.abs(ti - t);

			if(kyori <=  jikokuNoSa && Math.abs(jikokuNoSa - kyori) % 2 == 0) {
				t = ti;
				x = xi;
				y = yi;
			} else {
				possible = false;
				break;
			}
		}
		scan.close();

		if(possible) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}

	}

}


Measured memory_bytes: 60396
#include <cstdio>

using namespace std;

int main()
{
    char input[5];
    scanf("%s",input);
    for(int i=0;input[i];i++)
    {
        if(input[i]=='1')
            input[i]='9';
        else if(input[i]=='9')
            input[i]='1';
    }
    printf("%s\n",input);
    return 0;
}


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

int comb(int n,int r){
    r = min(r,n-r);
    int ans;
    if(r==0){
        ans = 1;
    }else{
        ans = comb(n,r-1) * (n-r+1) / r;
    }
    return ans;
}

int main(void){
    int x,y,z,k,s;
    scanf("%d %d",&k,&s);
    int cnt=0;
    for(x=0;x<=k;x++){
        for(y=0;y<=k;y++){
            if(0<=s-x-y&&s-x-y<=k)cnt++;
        }
    }
    printf("%d\n",cnt);
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <array>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <limits>

using namespace std;

void dfs(const vector<vector<int>>& edges, const vector<int>& imos, vector<int>& res, int acc, int id) {
	acc += imos[id];
	res[id] = acc;
	for (int edge : edges[id]) {
		dfs(edges, imos, res, acc, edge);
	}
}

int main (int argc, char* argv[]) {
	int n, q;
	cin >> n >> q;

	vector<vector<int>> edges(n);
	for (int i = 0; i < n - 1; i++) {
		int from, to;
		cin >> from >> to;
		from--; to--;
		edges[from].push_back(to);
	}

	vector<int> imos(n);
	for (int i = 0; i < q; i++) {
		int id, x;
		cin >> id >> x;
		id--;
		imos[id] += x;
	}

	vector<int> res(n);
	dfs(edges, imos, res, 0, 0);

	for (int num : res) {
		cout << num << " ";
	}
	cout << endl;
}


Measured memory_bytes: 27392
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
#define P pair<int,ll>
const ll MOD=998244353;
const int INF=1e9;
const double PI=acos(-1);



int main() {
    ios_base::sync_with_stdio(false);

    int a;
    cin >> a;
    cout << a+a*a+a*a*a << endl;
     

    return 0;
}


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

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

using namespace std;


signed main(){
  int N;
  cin >> N;
  string S[N];
  rep(i, N){
    cin >> S[i];
  }
  int matsu = 0;
  int sen = 0;
  int matsusen = 0;
  int count = 0;
  rep(i, N){
    if(S[i][0]=='B'){
      if(S[i][S[i].length()-1]=='A'){
        matsusen++;
      }else{
        sen++;
      }
    }else{
      if(S[i][S[i].length()-1]=='A'){
        matsu++;
      }
    }
  }
  
  rep(i, N){
    rep(j, S[i].length()-1){
      if(S[i][j]=='A' && S[i][j+1]=='B'){
        count++;
      }
    }
  }
  if(matsusen){
    count+=matsusen-1;
    if(matsu){
      count++;
      matsu--;
    }
    if(sen){
      count++;
      sen--;
    }
  }
  
  count = count + min(matsu, sen);
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 768
N = int(input())
A = list(map(int, input().split()))

ans = 1
cnt = 0
A.sort(reverse=True)
hikae = None
for e in A:
    if hikae is None:
        hikae = e
    elif hikae == e:
        ans *= e
        cnt += 1
        hikae = None
        if cnt == 2:
            print(ans)
            exit(0)
    else:
        hikae = e
print(0)

Measured memory_bytes: 62704
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long int ll;
 
int main(){
    int N;
    cin >> N;

    vector<int> W(N);
    int sum = 0;
    for(int i = 0; i < N; i++){
        cin >> W[i];
        sum += W[i];
    }

    int S1 = 0;
    int tmp = 100000;
    for(int i = 0; i < N; i++){
        S1 += W[i];
        int S2 = sum - S1;
        if(abs(S1 - S2) < tmp) tmp = abs(S1 - S2);
    }
    cout << tmp << endl;
}

Measured memory_bytes: 256
N, A, B = map(int, input().split())
H = []
for i in range(N):
    h = int(input())
    H.append(h)


def enough(T):
    num = 0
    for i in range(N):
        if H[i] - B * T > 0:
            num += (H[i] - B * T) // (A - B)
            num += int((H[i] - B * T) % (A - B) != 0)
    return T >= num


left, right = 0, 10 ** 9 + 1
mid = (left + right) // 2
while right - left > 1:
    mid = (left + right) // 2
    if enough(mid):
        right = mid
    else:
        left = mid

print(right)

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
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; }
const ll MOD = 1e9+7;

ll a, b, c, K;

typedef vector<int> vec;
typedef vector<vec> mat;

//単位元
const int ID = 1;

void print_mat(mat A){
    for(int i = 0; i < A.size(); i++){
        for(int j = 0; j < A[0].size(); j++){
            printf("%d ", A[i][j]);
        }
        printf("\n");
    }
    printf("\n");
}

void print_vec(vec A){
    for(int i = 0; i < A.size(); i++){
        printf("%d ", A[i]);
    }
    printf("\n\n");
}

//calc A*B
mat mul(mat& A, mat& B){
    mat C(A.size(), vec(B[0].size()));
    for(int i = 0; i < A.size(); i++){
        for(int k = 0; k < B.size(); k++){
            for(int j = 0; j < B[0].size(); j++){
                C[i][j] = (C[i][j] + A[i][k] * B[k][j]);
            }
        }
    }
    return C;
}

//calc A**n
mat pow(mat A, ll n, bool& flag){
    mat B(A.size(), vec(A.size()));
    for(int i = 0; i < A.size(); i++){
        B[i][i] = ID;
    }

    flag = false;
    while(n > 0){
        if(n & 1) B = mul(B, A);
        A = mul(A, A);
        n >>= 1;

        ll taka = B[0][0]*a + B[0][1]*b + B[0][2]*c;
        ll naka = B[1][0]*a + B[1][1]*b + B[1][2]*c;
        if(abs(taka - naka) > 1e18) flag = true;
    }

    return B;
}



int main(){
    cin >> a >> b >> c >> K;

    mat A(3, vec(3));
    A[0][0] = 0;
    A[0][1] = 1;
    A[0][2] = 1;

    A[1][0] = 1;
    A[1][1] = 0;
    A[1][2] = 1;

    A[2][0] = 1;
    A[2][1] = 1;
    A[2][2] = 0;

    bool flag = false;
    mat B = pow(A, K, flag);

    if(flag){
        cout << "Unfair" << endl;
    }
    else{
        ll taka = B[0][0]*a + B[0][1]*b + B[0][2]*c;
        ll naka = B[1][0]*a + B[1][1]*b + B[1][2]*c;
        ll ans = taka - naka;
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <ios>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <utility>
using namespace std;

#define MOD 1000000007
#define INF 1e9+7
#define INF_LONG 1e18
#define rep(i, n) for(int i=0; i<n; ++i)
#define rrep(i, m, n) for(int i=m; i<n; ++i)
typedef long long ll;

#define MAX_N 200000
#define MAX_M 100000
#define MAX_V 100
#define MAX_E 100
#define MAX_Q 100000

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

int ddx[] = {-1, 0, 1, 0, -1, 1, -1, 1};
int ddy[] = {0, -1, 0, 1, 1, 1, -1, -1};

ll gcd(ll x, ll y) {
  if(y==0) return x;
  else return gcd(y, x%y);
}

ll lcm(ll x, ll y) {
  return (x*y)/gcd(x, y);
}

//--------------------------

int n;
int a[100001];

int main() {

  cin >> n;
  rep(i, n) cin >> a[i];

  int num = 0, c = 0, cnt = 0;

  sort(a, a+n);

  num = a[0];
  c = 1;

  for(int i=1; i<n+1; ++i) {
    if(num==a[i]) {
      ++c;
    }else {
      if(c%2==1) ++cnt;
      num = a[i];
      c = 1;
    }
  }

  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 768
//This program is written by Brian Peng.
#pragma GCC optimize("Ofast","inline","no-stack-protector")
#include<bits/stdc++.h>
using namespace std;
#define Rd(a) (a=rd())
#define Gc(a) (a=getchar())
#define Pc(a) putchar(a)
int rd(){
	int x;char c(getchar());bool k;
	while(!isdigit(c)&&c^'-')if(Gc(c)==EOF)exit(0);
	c^'-'?(k=1,x=c&15):k=x=0;
	while(isdigit(Gc(c)))x=x*10+(c&15);
	return k?x:-x;
}
void wr(int a){
	if(a<0)Pc('-'),a=-a;
	if(a<=9)Pc(a|'0');
	else wr(a/10),Pc((a%10)|'0');
}
signed const INF(0x3f3f3f3f),NINF(0xc3c3c3c3);
long long const LINF(0x3f3f3f3f3f3f3f3fLL),LNINF(0xc3c3c3c3c3c3c3c3LL);
#define Ps Pc(' ')
#define Pe Pc('\n')
#define Frn0(i,a,b) for(int i(a);i<(b);++i)
#define Frn1(i,a,b) for(int i(a);i<=(b);++i)
#define Frn_(i,a,b) for(int i(a);i>=(b);--i)
#define Mst(a,b) memset(a,b,sizeof(a))
#define File(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout)
#define N (3010)
int n,a[N],u,v;
bool f[N],vs[N];
bool dfs(int u);
vector<int>e[N];
signed main(){
	Rd(n);
	Frn1(i,1,n)Rd(a[i]);
	Frn0(i,1,n){
		Rd(u),Rd(v);
		if(a[u]>a[v])e[u].push_back(v);
		else if(a[v]>a[u])e[v].push_back(u);
	}
	Frn1(i,1,n)if(dfs(i))wr(i),Ps;
	exit(0);
}
bool dfs(int u){
	if(vs[u])return f[u];vs[u]=1;
	for(int v:e[u])if(!dfs(v))f[u]=1;
	return f[u];
}


Measured memory_bytes: 3800
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N,*A = map(int,read().split())

MOD = 10 ** 9 + 7

A = [x + 1 for x in A]

counter = [0] * (N+100)
counter[0] = 3
answer = 1
for x in A:
    answer *= counter[x-1]
    counter[x-1] -= 1
    counter[x] += 1
    answer %= MOD

print(answer)

Measured memory_bytes: 11640
fn main() {
  let n: usize = read();
  let mat: Vec<Vec<i64>> = read_mat(n);
  
  let mut acc = 0;
  
  for i in 0 .. n {
    for j in 0 .. n {
      for k in 0 .. n {
        if i<j && i!=k && j!=k {
          match (mat[i][j], mat[i][k] + mat[k][j]) {
            (ij, ikj) if ij > ikj  => {println!("-1"); return},
            (ij, ikj) if ij == ikj => {acc += ij; break},
            _ => ()
          }
        }
      }
    }
  }
  
  let ans = mat.iter().map(|v| v.iter().sum::<i64>()).sum::<i64>() / 2 - acc;
  println!("{}", ans);
}

fn read<T: std::str::FromStr>() -> T {
  let mut buf = String::new();
  std::io::stdin().read_line(&mut buf).ok();
  buf.trim().parse::<T>().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
  let mut buf = String::new();
  std::io::stdin().read_line(&mut buf).ok();
  buf.trim().split_whitespace().map(|t| t.parse::<T>().ok().unwrap()).collect()
}

fn read_mat<T: std::str::FromStr>(h: usize) -> Vec<Vec<T>> {
  let mut mat: Vec<Vec<T>> = vec![];
  for _ in 0 .. h {
    mat.push(read_vec());
  }
  mat
}

Measured memory_bytes: 6396
#include <stdio.h>

int main() {
    int n;
    int a;
    int min = 1000000;
    int max = -1000000;
    long sum = 0L;

    scanf("%d", &n);
    for (int i=0; i<n; ++i) {
        scanf("%d", &a);
        if (a < min) {
            min = a;
        }
        if (a > max) {
            max = a;
        }
        sum += a;
    }
    printf("%d %d %ld\n", min, max, sum);

    return 0;
}



Measured memory_bytes: 2148
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vll vector<ll>
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(int argc, char const *argv[]) {
  ll t, n;std::cin >> n;
  multiset<ll, greater<ll>> s;
  re(i, n) {
    std::cin >> t;
    s.insert(t);
  }
  ll a=0, b=0;
  for(;b==0&&s.size()!=0;){
    auto itr = s.begin();
    if(s.count(*itr)<2) {
      s.erase(*itr);
      continue;
    }
    if(a==0){
      if(s.count(*itr)>=4) {
        a = *itr, b = *itr;
        s.erase(*itr);
      }else a = *itr, s.erase(*itr);
    }else{
      b = *itr;
    }
  }
  std::cout << a*b << '\n';
}


Measured memory_bytes: 4992
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include<cstring>
using namespace std;
 
int main(){

  int a, b;
  bool flag;
  string s;
  string num="1234567890";
  cin >> a >> b;
  cin >> s;

  for(int i=0; i<a; i++){
    for(int j=0; j<10; j++){
      if(s[i]==num[j]){
      flag=true;
      }
    }
    if(!flag){
      cout << "No" << endl;
      return 0;
    }
    flag=false;
  }

  flag=false;

  if(s[a]!='-'){
    cout << "No" << endl;
    return 0;
  }

  for(int i=0; i<b; i++){
    for(int j=0; j<10; j++){
      if(s[a+1+i]==num[j]){
      flag=true;
      }
    }
    if(!flag){
      cout << "No" << endl;
      return 0;
    }
    flag=false;
  }

  cout << "Yes" << endl;

  return 0;
}

Measured memory_bytes: 256