akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
using namespace std;
long long int n,m,a[52][2]= {0},b[52]= {0},num=0;
int yun()
{
    int i,j;
    for(i=0; i<n; i++)
    {
        for(j=0; j<n; j++)
        {
            if(i==j)
                continue;
                a[j][1]+=a[i][0];
                a[j][0]+=a[j][1]/n;
                a[j][1]%=n;
        }
        num+=a[i][0];
        a[i][0]=0;
    }
}
int judge()
{
    int i,j,flag=0;
    for(i=0; i<n; i++)
        if(a[i][0]!=0)
        {
            flag=1;
            break;
        }
    return flag;
}
int main()
{
    int i,j;
    cin>>n;
    for(i=0; i<n; i++)
        cin>>b[i];
    for(i=0; i<n; i++)
    {
        a[i][0]=b[i]/n;
        a[i][1]=b[i]%n;
    }
    while(1)
    {
        if(judge()==0)
            break;
        yun();
    }
    cout<<num;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
#define MAX 5000
class Tetoris{
    public:
    int stack[MAX+1], top;
    Tetoris(){ stack[0] = 31; top = 0; }
    
    void insert( int o, int p, int q ){
	int value = (o == 1 ? (((2 << p-1)-1) << (q-1)) : (1 << (q-1)));
        int target = getTarget( value );
        for ( int i = target;  i < target + ((o == 2) ? p : 1); i++ ){
            if ( i > top ){
                stack[i] = value;
                top = i;
            } else {
		stack[i] += value;
	    }
	}
        while( erase());
    }
    
    bool erase(){
	for ( int i = 1; i <= top; i++ ){
	    if ( stack[i] == 31 ){
		for ( int j = i+1; j <= top; j++ ) stack[j-1] = stack[j];
		top--; return true;
	    }
	}
	return false;
    }
    
    int getResult(){
	int sum = 0;
	for ( int i = top; i >= 1; i-- ){
	    int val = stack[i];
	    while( val ){
		if ( val%2 ) sum++;
		val /= 2;
	    }
	}
	return sum;
    }
    
    int getTarget( int value ){
	int target = top;
	while( (stack[target] & value) == 0 ) target--;
	return target + 1;
    }
};

int main(){
    int n, o, p, q;
    while( cin >> n && n ){
	Tetoris tetoris;
	for ( int i = 0; i < n; i++ ) {
	    cin >> o >> p >> q;
	    tetoris.insert(o, p, q);
	}
	cout << tetoris.getResult() << endl;
    }
    return 0;
}

Measured memory_bytes: 0
#include <iostream>
using namespace std;
int main()
{
  int N;
  cin >> N;
  int count = 0;
  for (int i = 0; i < N; i++)
  {
    int A;
    cin >> A;
    if (A % 2 != 0)
      count++;
  }
  if (count % 2 == 0)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>

using namespace std;

const double LIMIT = 25;

bool bmi(double weight, double hight) {
	if ((weight / (hight * hight)) >= LIMIT) {
		return true;
	} else {
		return false;
	}
}

int main() {
	int student_num;
	double weight;
	double hight;
	while (scanf("%d,%lf,%lf", &student_num, &weight, &hight) != EOF) {
		if (bmi(weight, hight)) {
			printf("%d\n", student_num);
		}
	}
	
	return 0;
}

Measured memory_bytes: 1056
#include <iostream>
#include <queue>
#include <functional>
#include <vector>
#include <algorithm>
using namespace std;

vector<pair<long long, long long>>x[100009], y[100009];
long long N, M, S, T, u[200009], v[200009], a[200009], b[200009], dist1[200009], dist2[200009], P[200009];

priority_queue<pair<long long, long long>, vector<pair<long long, long long>>, greater<pair<long long, long long>>>Q;

int main() {
	cin >> N >> M >> S >> T;
	for (int i = 1; i <= M; i++) {
		cin >> u[i] >> v[i] >> a[i] >> b[i];
		x[u[i]].push_back(make_pair(v[i], a[i]));
		x[v[i]].push_back(make_pair(u[i], a[i]));
		y[u[i]].push_back(make_pair(v[i], b[i]));
		y[v[i]].push_back(make_pair(u[i], b[i]));
	}
	for (int i = 1; i <= N; i++) { dist1[i] = (1LL << 60); dist2[i] = (1LL << 60); }
	
	dist1[S] = 0; Q.push(make_pair(0, S));

	while (!Q.empty()) {
		int pos = Q.top().second; Q.pop();
		for (int i = 0; i < x[pos].size(); i++) {
			long long to = x[pos][i].first, cost = x[pos][i].second;
			if (dist1[to] > dist1[pos] + cost) {
				dist1[to] = dist1[pos] + cost;
				Q.push(make_pair(dist1[to], to));
			}
		}
	}

	dist2[T] = 0; Q.push(make_pair(0, T));

	while (!Q.empty()) {
		int pos = Q.top().second; Q.pop();
		for (int i = 0; i < y[pos].size(); i++) {
			long long to = y[pos][i].first, cost = y[pos][i].second;
			if (dist2[to] > dist2[pos] + cost) {
				dist2[to] = dist2[pos] + cost;
				Q.push(make_pair(dist2[to], to));
			}
		}
	}
	for (int i = 1; i <= N; i++) P[i] = dist1[i] + dist2[i];
	for (int i = N - 1; i >= 1; i--) P[i] = min(P[i], P[i + 1]);
	for (int i = 1; i <= N; i++) {
		cout << 1000000000000000LL - P[i] << endl;
	}
	return 0;
}

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

int main(){
  string N; cin >> N;
  int s=N.size();
  
  int c=0;
  for(int i=0; i<s; i++){
    c+=(int)(N[i]-'0');
  }
  cout << (c%9==0?"Yes":"No") << endl;
}

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

using namespace std;

int main(){
  int n; cin >> n;
  vector<double> a(n);
  for(auto &e:a) cin >> e;
  sort(a.begin(),a.end(),greater<>());
  double ans=0;
  for(int i=3;i<n;++i)
    ans=max(ans,(a[0]+a[1])/(a[i-1]-a[i]));
  ans=max(ans,(a[2]+a[3])/(a[0]-a[1]));
  ans=max(ans,(a[0]+a[3])/(a[1]-a[2]));
  ans=max(ans,(a[0]+a[2])/(a[1]-a[3]));
  printf("%.9f\n",ans);
  
  return 0;
}



Measured memory_bytes: 3252
N = int(input())
b = list(map(int, input().split()))
#print(b)

ans = []
i = len(b)-1
while(1):
    if i == -1:
        print("-1")
        exit()
    if b[i] == i + 1:
        #print("check")
        ans.append(b.pop(i))
        if len(b) == 0:
            break
        i = len(b)-1
    else:
        i -= 1



for i in range(len(ans)-1, -1, -1):
    print(ans[i])

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

int main() {
	int x, y, z;
	for (;;) {
		cin >> x >> y;
		if (x == 0 && y == 0)break;

		if (x > y) {
			z = x;
			x = y;
			y = z;
		}

		cout << x << " " << y << endl;
	}

}


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

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

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

int main()
{
    ll A, P;
    cin >> A >> P;
    P += A * 3;
    cout << P / 2 << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[100101];
int main()
{
    ios::sync_with_stdio(false);
    int n,x = 0;
    cin>>n;
    a[0]=1;
    for (int i = 1;i <= n;i ++) cin>>a[i];
    for (int i = n-1;i;i --)
        if (a[i]>a[i+1]) a[i] --;
    for (int i = 1;i < n;i ++) if (a[i] > a[i+1]) cout<<"No"<<endl,exit(0);
    cout<<"Yes"<<endl;
    return 0;
}


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

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

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

  int r;
  cin >> r;

  cout << ((r*r)/(1*1)) << endl;
  return 0;
}


Measured memory_bytes: 3656
#include <iostream>
#define MAX 100000
using namespace std;

int parent(int i) { return i / 2; }
int left(int i) { return 2 * i; }
int right(int i) { return 2 * i + 1; }

int main()
{
	int H, i, A[MAX + 1];
	cin >> H;
	for (int i = 1; i <= H; i++)cin >> A[i];
	for (int i = 1; i <= H; i++)
	{
		cout << "node " << i << ": key = " << A[i] << ", ";
		if (parent(i) >= 1)cout << "parent key = " << A[parent(i)] << ", ";
		if (left(i) <= H)cout << "left key = " << A[left(i)] << ", ";
		if (right(i) <= H)cout << "right key = " << A[right(i)] << ", ";
		cout << endl;
	}
	return 0;
}




Measured memory_bytes: 3100
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{
    int N,X; cin>>N>>X;
    vint a(N);
    REP(i,N) cin>>a[i];

    sort(ALL(a));
    REP(i,N-1) a[i+1]+=a[i];

    int ans=0;
    if(a[N-1]<X) ans=N-1;
    else if(a[N-1]==X) ans=N;
    else{
        REP(i,N){
            if(a[i]<=X) ans=i+1;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;


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

	int x, a, b;
	cin >> x >> a >> b;
	if (abs(x - a) > abs(x - b)) cout << "B\n";
	else cout << "A\n";

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for(int i=0;i<n;i++)
#define repb(i, a, b) for(int i=a;i<b;i++)

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

const int INF = 1<<30;

int main(){
  int n, m;cin>>n>>m;
  vector<P> student(n), check(m);
  rep(i, n){
    int x, y;cin>>x>>y;
    student[i]=P(x, y);
  }
  rep(i, m){
    int x, y;cin>>x>>y;
    check[i]=P(x, y);
  }
  rep(i, n){
    P s = student[i];
    int min_dis = INF;
    int ch_can;
    rep(j, m){
      P c = check[j];
  	  int dis = abs(s.first-c.first)+abs(s.second-c.second);
      if(min_dis>dis){
      	min_dis=dis;ch_can=j;
      }
    }
    cout<<ch_can+1<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
IMPLICIT NONE
 INTEGER :: A,B,C,D
 READ*, A,B,C,D
 IF (A+B > C+D) THEN
     PRINT*, "Left"
 ELSE IF(A+B == C+D) THEN
 	PRINT*, "Balanced"
 ELSE
 	PRINT*, "Right"
 END IF
END

Measured memory_bytes: 2840
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();

int main() {
    int n;
    cin >> n;
    vector<int> arr(n, 0);
    for(auto& val: arr)
        cin >> val;
    int M = *max_element(arr.begin(), arr.end());
    int S = accumulate(arr.begin(), arr.end(), 0);
    if ((S-M) > M)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}




Measured memory_bytes: 256
use std::io::BufRead;

pub struct StdinReader<R: BufRead> {
    pub buf_reader: R,
    pub buf: String,
}

impl<R: BufRead> StdinReader<R> {
    pub fn new(r: R) -> Self {
        StdinReader {
            buf_reader: r,
            buf: String::with_capacity(10000),
        }
    }
}

#[macro_export]
macro_rules! input {
    ($reader : expr, $t : ty) => { // one variable
        match &mut $reader {
            reader => {
                use std::io::BufRead;
                reader.buf_reader.read_line(&mut reader.buf).unwrap();
                let tmp_var: $t = reader.buf.trim().parse().unwrap();
                reader.buf.clear();
                tmp_var
            },
        }
    };
    ($reader : expr, $t0 : ty, $t1 : ty) => { // 2 tuple
        match &mut $reader {
            reader => {
                use std::io::BufRead;
                reader.buf_reader.read_line(&mut reader.buf).unwrap();
                let tmp_var: Vec<$t0> = reader.buf.trim().split_whitespace().map(|a| a.parse().unwrap()).collect();
                reader.buf.clear();
                (tmp_var[0].clone(), tmp_var[1].clone())
            }
        }
    };
    ($reader : expr, $t0 : ty, $t1 : ty, $t2 : ty) => { // 3 tuple
        match &mut $reader {
            reader => {
                use std::io::BufRead;
                reader.buf_reader.read_line(&mut reader.buf).unwrap();
                let tmp_var: Vec<$t0> = reader.buf.trim().split_whitespace().map(|a| a.parse().unwrap()).collect();
                reader.buf.clear();
                (tmp_var[0].clone(), tmp_var[1].clone(), tmp_var[2].clone())
            }
        }
    };
    ($reader : expr, $t : ty; $size : expr) => { // Vector
        match &mut $reader {
            reader => {
                use std::io::BufRead;
                reader.buf_reader.read_line(&mut reader.buf).unwrap();
                let tmp_var: $t = reader.buf.trim().split_whitespace().map(|a| a.parse().unwrap()).collect();
                reader.buf.clear();
                tmp_var
            }
        }
    };
}

fn main() {
    solve_c();
}

fn solve_c() {
    let handle = std::io::stdin();
    let mut r = StdinReader::new(handle.lock());
    let (n, q): (usize, usize) = input!(r, usize, usize);
    let mut v: Vec<usize> = Vec::with_capacity(n + 1);
    v.push(0);
    let s = input!(r, String);
    //
    let mut bingo_chance = false;
    for (i, c) in s.char_indices() {
        let last = *v.last().unwrap();
        match c {
            'C' => {
                if bingo_chance {
                    v.push(last + 1);
                } else {
                    v.push(last);
                }
                bingo_chance = false;
            },
            'A' => {
                bingo_chance = true;
                v.push(last);
            },
            _ => {
                bingo_chance = false;
                v.push(last);
            },
        }
    }
    for _ in 0..q {
        let (start, end): (usize, usize) = input!(r, usize, usize);
        println!("{}", v[end] - v[start]);
    }
}



Measured memory_bytes: 4860
/*	* In the name of GOD
	* Thanks God */
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
#define F first
#define S second

int32_t main(){
	int a, b, c, k;
	cin >> a >> b >> c >> k;
	int ans = 0;
	ans += min(k, a);
	k -= min(k, a);
	k -= min(k, b);
	ans -= min(k, c);
	cout << ans << endl;
}


Measured memory_bytes: 3624
import sys
if sys.version[0] == '2':
    range, input = xrange, raw_input


class HeavyLightDecomposition:
    def __init__(self, g, root=0):
        self.g = g
        self.vid, self.head, self.heavy, self.parent = [0] * len(g), [-1] * len(g), [-1] * len(g), [-1] * len(g)
        self.dfs(root)
        self.bfs(root)

    def dfs(self, root):
        stack = [(root, -1, False)]
        sub, max_sub = [1] * len(self.g), [(0, -1)] * len(self.g)
        while stack:
            v, par, flag = stack.pop()
            if not flag:
                self.parent[v] = par
                stack.append((v, par, True))
                stack.extend((c, v, False) for c in self.g[v] if c != par)
            else:
                if par != -1:
                    sub[par] += sub[v]
                    max_sub[par] = max(max_sub[par], (sub[v], v))
                self.heavy[v] = max_sub[v][1]

    def bfs(self, root=0):
        from collections import deque
        k, que = 0, deque([root])
        while que:
            r = v = que.popleft()
            while v != -1:
                self.vid[v], self.head[v] = k, r
                for c in self.g[v]:
                    if c != self.parent[v] and c != self.heavy[v]:
                        que.append(c)
                k += 1
                v = self.heavy[v]

    def lca(self, u, v):
        while self.head[u] != self.head[v]:
            if self.vid[u] > self.vid[v]:
                u, v = v, u
            v = self.parent[self.head[v]]
        else:
            if self.vid[u] > self.vid[v]:
                u, v = v, u
        return u

N = int(input())
g = [[] for _ in range(N)]
for i in range(N):
    for c in map(int, input().split()[1:]):
        g[i].append(c)
        g[c].append(i)
hld = HeavyLightDecomposition(g)
Q = int(input())
for _ in range(Q):
    u, v = map(int, input().split())
    print(hld.lca(u, v))

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

using namespace std;

int main() {
    int N;
    cin >> N;
    int X, L;
    pair<int, int> P[N];
    for (int i = 0; i < N; i++) {
        cin >> X >> L;
        P[i] = pair<int, int>((X + L), (X - L));
    }
    sort(P, P + N);
    int prev_pos = -1000000000;
    int count = 0;
    for (int i = 0; i < N; i++) {
        if (prev_pos <= P[i].second) {
            count++;
            prev_pos = P[i].first;
        }
    }
    cout << count << "\n";
    return 0;
}


Measured memory_bytes: 1152
N, K = map(int,input().split())
ans = 0
b, c = 0, 0
amari = [0] * (K+1)

for i in range(1,N+1):
    amari[i%K] += 1

for a in range(K):
    b = (K-a) % K
    c = (K-a) % K
    if (b+c)%K == 0:
        ans += amari[a] * amari[b] * amari[c]

print(ans)


Measured memory_bytes: 4596
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;

const int MOD = 1000000007;
const int INF = 1001001001;

#define rep(i, n)  for(int i=0;i<(n);++i)
#define all(x) (x).begin(),(x).end()

int main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    ll ans = 0;
    rep(i, 60) {
        ll x = 0;
        rep(j, n) if (a[j] >> i & 1) ++x;
        ll ansi = x*(n-x)%MOD;
        rep(j, i) ansi = ansi*2%MOD;
        ans += ansi;
        ans %= MOD;
    }

    cout << ans << endl;
}

Measured memory_bytes: 2560
#define _USE_MATH_DEFINES
#include<bits/stdc++.h>
#include<map>
#include<iostream>
#include<math.h>
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;


int main(){
   double N,M;
   cin >> N >> M;
   vector<int> A(N);
   int cnt = 0;
   int a = 0;
   rep(i,N){
      cin >> A[i];
      a += A[i];
   }
   rep(i,N){
      if(A[i] >= (a / (4.0*M))) cnt++;
   }
   cout << (cnt >= M ? "Yes" : "No") << endl;
}

Measured memory_bytes: 3700
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define putchar putchar_unlocked
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], *ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}
inline bool getA() {
	bool A;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = ct & 1;
	else while ((ct = *ci++) >= '0') A = ct & 1;
	return A;
}

const int dm = 1 << 21;
char dn[dm], *di = dn, dt;
inline void putints(int X) {
	int keta = 0;
	char C[10];
	while (X) {
		*(C + keta) = '0' + X % 10;
		X /= 10;
		keta++;
	}
	for (int i = keta - 1; i >= 0; i--) *di++ = (*(C + i));
	*di++ = ' ';
}
inline void putint(int X) {
	int keta = 0;
	char C[10];
	while (X) {
		*(C + keta) = '0' + X % 10;
		X /= 10;
		keta++;
	}
	for (int i = keta - 1; i >= 0; i--) *di++ = (*(C + i));
	*di++ = '\n';
}

inline void putk(int X) {
	if (X == 0) putchar('0');
	int keta = 0;
	char C[10];
	while (X) {
		*(C + keta) = '0' + X % 10;
		X /= 10;
		keta++;
	}
	for (int i = keta - 1; i >= 0; i--) putchar(*(C + i));
	putchar('\n');
}

int main() {


	int H, W;
	bool a = 0, b = 0;
	H = getint();
	W = getint();
	int k = 0;
	rep1(i, H) {
		bool c;
		rep1(ii, W - 1) {
			c = getA();
			a ^= c;
			if (a) {
				k++;
				putints(i);
				putints(ii);
				putints(i);
				putint(ii + 1);
			}
		}
		c = getA();
		if (i != H) {
			b ^= a ^ c;
			if (b) {
				k++;
				putints(i);
				putints(W);
				putints(i + 1);
				putint(W);
			}
		}
		a = false;
	}

	putk(k);
	fwrite(dn, 1, di - dn, stdout);

	Would you please return 0;
}

Measured memory_bytes: 4096
n = int(input())
x = list(map(int, input().split()))
x_sorted = sorted(x)

x_med_l = x_sorted[n//2 - 1]
x_med_r = x_sorted[n//2]

for i in range(n):
  if x[i] <= x_med_l:
    print(x_med_r)
  else:
    print(x_med_l)

Measured memory_bytes: 25220
#define rep(i,n) fo(i,0,n)
#define fo(i,s,n) for((i)=(s);(i)<(n);(i)++)
#define scan(k) scanf("%d",&k)
#define PI 3.14159265359
#define INF (ll)(2e18+100)
#define MOD (int)(1e9+7)
#define MAX 10000
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef long long ll;

int comp( const void *c1, const void *c2 )
{
  int tmp1 = *(int *)c1;
  int tmp2 = *(int *)c2;

  if( tmp1 < tmp2 )  return -1;
  if( tmp1 == tmp2 ) return  0;
  if( tmp1 > tmp2 )  return  1;
}

int main(void){
	int n;
	int l[500];
	int i;
	scan(n);
	rep(i,500){
		l[i]=0;
	}
	rep(i,2*n){
		scan(l[i]);
	}
	qsort(l,500,sizeof(int),comp);
	int ans=0;
	for(i=0;i<500;i+=2){
		ans+=l[i];
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 128
n, x = map(int, input().split())
A = list(map(int, input().split()))

ans = 0

for i in range(1, n):
    s = A[i] + A[i-1]
    r = s - x
    if r > 0:
        if A[i] >= r:
            A[i] -= r
        else:
            A[i-1] -= r - A[i]
            A[i] = 0
        ans += r

print(ans)


Measured memory_bytes: 14592
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;
    
#define rep(i,n) for(ll (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(ll i=(a);i<(b);i++)
#define rrrep(i,a,b) for(ll i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 
#define U_MAP unordered_map<ll,ll>
#define pq priority_queue<ll>
#define rpq priority_queue<ll,vector<ll>,greater<ll>>
#define p_b push_back
    
ll n,cnt,ans,a[ohara],b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k,q;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};
    
//------ Believe yourself as a genius!!!!!! ------
    
int main(void){
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    
    cin>>n>>k>>q;
    rep(i,n)cin>>a[i];
    ans=LINF;
    rep(i,n){
        ll Y=a[i],X=0;
        //Y未満はダメです
        ll out[n+10]={},now_lo=0,out_cou=0;
        rep(j,n){
            if(a[j]<Y)out[out_cou++]=j;
        }
        out[out_cou++]=n;
        rpq que;
        rep(j,n){
            if(j+k-1>=out[now_lo]){
                if(j==out[now_lo])now_lo++;
                continue;
            }
            if(j==out[now_lo])now_lo++;
            rpq que2;
            ll kosuu=0;
            rrep(z,j,out[now_lo]){
                que2.push(a[z]);
                kosuu++;
            }
            rep(z,kosuu-k+1){
                que.push(que2.top());
                que2.pop();
            }
            j=out[now_lo]-1;
        }
        if(Size(que)<q)continue;
        rep(j,q){
            X=max(X,que.top());
            que.pop();
        }
        ans=min(ans,X-Y);
    }
    Cout(ans);
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define in(x,y,h,w) x >= 0 && x < h && y >= 0 && y < w

#define int long long
//typedef    long long          ll;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;

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

signed main(){
	int n,q,cnt[200010] = {};
	string s;
	cin >> n >> q >> s;
	for(int i = 1;i < n;i++){
		cnt[i] = cnt[i - 1];
		if(s[i] == 'C' && s[i - 1] == 'A') cnt[i]++;
	}
	for(int i = 0;i < q;i++){
		int l,r;
		cin >> l >> r;
		cout << cnt[r - 1] - cnt[l - 1] << endl;
	}
	return 0;
}

Measured memory_bytes: 2560
#include<ctime>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cmath> 
#include<cstring> 
#include<cassert>
#include<string>
#include<sstream>
#include<fstream>
#include<deque>
#include<queue>
#include<vector>
#include<map>
#include<list>
#include<stack>
#include<set>
#include<bitset>
#include<iomanip>
#include<utility>
#include<functional>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cwchar>
#include<cwctype>
#include<exception>
#include<locale>
#include<numeric>
#include<new>
#include<stdexcept>
#include<limits>
using namespace std;

#define ll long long
#define INF 1e9
#define rep(i,n) for(int (i)=0;(i)<n;i++)
#define REP(i,n) for(int (i)=1;(i)<=n;i++)
#define mk(a,b) make_pair(a,b)
#define fi first
#define se second
#define pii pair<int,int>
#define sz(s) s.size()
#define all(s) (s.begin(),s.end())

const int maxn=100005;
const int mod=1e9+7;
int n,m,a,b;
int inv[maxn*2],mult[maxn*2],ans;

int quick_pow(int power,int x){
	int res=1;
	while(power){
		if(power&1)res=((ll)res*(ll)x)%mod;
		x=((ll)x*(ll)x)%mod;
		power>>=1;
	}
	return res;
}

int C(int a,int b){
	return (ll)mult[a]*(ll)inv[b]%mod*(ll)inv[a-b]%mod;
}

int GET(int x1,int y1,int x2,int y2){
	int r=x2-x1+1,c=y2-y1+1;
	return C(r+c-2,c-1);
}

int main(){
	cin>>n>>m>>a>>b;
	mult[0]=1;
	REP(i,n+m)mult[i]=(ll)mult[i-1]*(ll)i%mod;
	inv[0]=1;
	REP(i,n+m)inv[i]=(ll)inv[i-1]*(ll)quick_pow(mod-2,i)%mod;
	REP(i,n-a){
		int cur=((ll)GET(1,1,i,b)*(ll)GET(i,b+1,n,m))%mod;
		ans=(ans+cur)%mod;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <fstream>
#include <algorithm>
#include <functional>
#include <chrono>
#include <random>
#include <vector>
#include <string>
#include <cmath>
#include <bitset>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cassert>

#define sq(x) ((x) * (x))
#define err(x) cerr << "["#x"]  " << (x) << "\n";
#define errp(x) cerr << "["#x"]  {" << ((x).first) << ", " << ((x).second) << "}\n";
#define errv(x) {cerr << "["#x"]  [";for(const auto& ___ : (x)) cerr << ___ << ", "; cerr << "]\n";}
#define errvn(x, n) {cerr << "["#x"]  [";for(auto ___ = 0; ___ < (n); ++___) cerr << (x)[___] << ", "; cerr << "]\n";}
#define errf() cerr << "\n\n";

//#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast, unroll-loops", "omit-frame-pointer","inline")
#pragma GCC option("arch=native","tune=native","no-zero-upper")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native,avx2")

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int getrnd(int l, int r) {
    return uniform_int_distribution<int>(l, r)(rng);
}

ll getrndll(ll l, ll r) {
    return uniform_int_distribution<ll>(l, r)(rng);
}

template <typename T1, typename T2>
inline bool relax(T1& a, const T2& b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}

template <typename T1, typename T2>
inline bool strain(T1& a, const T2& b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}

// :::::::::::::::::::::::::::::::

const int N = 2e5 + 3;

int p[N];
vector<int> graph[N];

void dfs(int v, int prev) {
    p[v] = prev;
    for (int to : graph[v])
        if (to != prev)
            dfs(to, v);
}

void solve() {
    int n;
    cin >> n;
    
    for (int i = 0; i < n - 1; ++i) {
        int x, y;
        cin >> x >> y;
        --x; --y;
        
        graph[x].emplace_back(y);
        graph[y].emplace_back(x);
    }
    dfs(0, -1);
    
    ll ans = 0;
    for (int i = 0; i < n; ++i) {
        if (p[i] == -1) {
            ans += 1LL * (i + 1) * (n - i);
        }
        else {
            ans += 1LL * (i + 1) * (n - i) - 1LL * (min(p[i], i) + 1) * (n - max(p[i], i));
        }
    }
    cout << ans << '\n';
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr); cout.tie(nullptr);
    srand(time(0));
    
    int t = 1;
//    cin >> t;
    while (t--)
        solve();
    
    return 0;
}


Measured memory_bytes: 24592
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#define vll vector<ll>
#define vvv vector<vvl>
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvvl(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d)));
#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;
typedef __int128_t lll;
using namespace std;

string s;
ll n;
vvl dp = vv(1000001, 2, -1, ll);

ll calc(ll keta, ll rev){
  if(keta==-1) return 0;
  if(dp[keta][rev]!=-1) return dp[keta][rev];
  ll now = s[s.size() - 1 - keta] - '0', ret;
  if(rev) now = (keta==0?10:9) - now;
  ret = calc(keta-1, rev) + now;
  if(keta!=n-1&&now!=9) ret = min(ret, calc(keta-1, (rev==1?0:1)) + 1 + now);
  if(keta==n-1) ret = min(ret, calc(keta-1, 1) + 1);
  return dp[keta][rev] = ret;
}

int main(int argc, char const *argv[]){
  std::cin >> s;
  s = '0' + s;
  string t = "";
  ll c = 0;
  for(int i=s.size()-1;i>=0;i--) {
    if(s[i]=='0') c++;
    else break;
  }
  for(int i=0;i<s.size()-c;i++) t += s[i];
  s = t;
  n = s.size();
  ll ans = calc(n-1, 0);
  std::cout << ans << '\n';
  return 0;
}


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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    long long n;
    cin >> n;
    long long smallest = n;
    vector<long long> xs(5);
    for (auto& x : xs) {
        cin >> x;
        smallest = min(smallest, x);
    }
    cout << (n + smallest - 1)/smallest + 4 << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
 
public class Main {
	public static void main(String[] args) {
    	Scanner scanner = new Scanner(System.in);
        int n1 = scanner.nextInt();
        int n2 = scanner.nextInt();
        if (n1 * n2 % 2 == 0) {
        	System.out.println("Even");
        } else {
        	System.out.println("Odd");
        }
    }
}

Measured memory_bytes: 21716
import java.util.Arrays;
import java.util.Scanner;
 
 
public class Main {
 
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long judge = (long) (Math.pow(10, 18));
		long[] a = new long[n];
		for(int i = 0; i < n; i++) {
			a[i] = sc.nextLong();
		}
		Arrays.sort(a);
		if(a[0]==0) {
			System.out.println(0);
			return;
		}
		long ans = a[0];
		for(int i = 1; i < n; i++) {
			ans*=a[i];
			if(ans>judge||ans<a[i]) {
				System.out.println(-1);
				return;
			}
		}
		System.out.println(ans);
	}
}

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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
using P = pair<ll,ll>;
using ld=long double;

int main(){
    ll a,b,c;cin >>a>>b>>c;
    ll k;cin >>k;
    ll ans=a+b+c;
    ll mx=max({a,b,c});
    for (int i = 0; i < k; ++i) {
        ans+=mx;
        mx+=mx;
    }
    cout <<ans <<endl;
    return 0;
}

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

    typedef long long ll;
    typedef long double ld;
    ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
    ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
    #define endl '\n'
    #define max3(a,b,c) max(a,max(b,c))

    const int q = 1e9+9;




    int main()
    {
        int n,k;
        cin>>n>>k;
        string s;
        cin>>s;
        s[k-1]= tolower(s[k-1]);
        cout<<s<<endl;


        return 0;
    }
        // gotcha;


Measured memory_bytes: 256
#coding: utf-8
m,d = map(int, input().split())
ans = 0

for i in range(4,m+1):
	for j in range(22,d+1):
		if int(str(j)[0]) >=2 and int(str(j)[1]) >=2 and i == int(str(j)[0]) * int(str(j)[1]):
			ans += 1

print(ans)


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

#define GO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int

const int maxr = 1e5 + 5;


int32_t main()
{
	GO;
	int a, b;
	cin >> a >> b;
	int count = 1;
	int ans = 0;
	while (count < b) {
		ans++;
		count--;
		count += a;
	}
	cout << ans << endl;
	return 0;
}

//!

Measured memory_bytes: 3644
use proconio::input;
fn main() {
    let info = Info::read();
    let mut ans = Vec::new();
    for _ in 0..info.day {
        let next = (0..26).max_by_key(|&contest| {
            ans.push(contest);
            let key = info.score(&ans);
            ans.pop();
            key
        });
        ans.push(next.unwrap());
    }
    ans.iter().for_each(|&contest| println!("{}", contest + 1));
}
struct Info {
    day: usize,
    dec: Vec<i32>,
    inc: Vec<Vec<i32>>,
}
impl Info {
    fn read() -> Self {
        input!(d: usize, c: [i32; 26], s: [[i32; 26]; d]);
        Self {
            day: d,
            dec: c,
            inc: s,
        }
    }
    fn score(&self, ans: &[usize]) -> i32 {
        let mut last = vec![-1; 26];
        ans.iter().enumerate().fold(0, |score, (date, &contest)| {
            last[contest] = date as i32;
            (0..26).fold(score + self.inc[date][contest], |score, contest| {
                score - self.dec[contest] * (date as i32 - last[contest])
            })
        })
    }
}


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

 int main() {
 int N;
cin >> N;
vector<int> a(N);
 int sum = 0;

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

 int mini = sum;
int prefix_sum = 0;
 for (int i = 0; i < N; ++i) {
 cin >> a[i];
 prefix_sum += a[i];
 mini = min(mini, abs(prefix_sum - (sum - prefix_sum)));
 }

 cout << mini << endl;
 return 0;
 }

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

int ReturnDigitsSum(int n){
    int sum=0;
    while(n){
        sum += n % 10;
        n = n / 10;
    }
    return sum;
}

int main(){
    int N,A,B;
    cin >> N >> A >> B;
    int total=0;
    for(int i=1;i<=N;++i){
        int sum = ReturnDigitsSum(i);
        if( sum >= A && sum <= B ){
            total+=i;
        }
    }
    cout << total << endl;
    return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n, alice, bob int
	fmt.Scan(&n)
	cards := make([]int, n)

	for i := 0; i < n; i++ {
		fmt.Scan(&cards[i])
	}

	sort.Sort(sort.Reverse(sort.IntSlice(cards)))

	for i, v := range cards {
		if i%2 == 0 {
			alice += v
		} else {
			bob += v
		}
	}
	fmt.Println(alice - bob)
}


Measured memory_bytes: 512
X, K, D = map(int, input().split())

# Xは0以上として一般性を失わない
X = abs(X)
ans = 0
# 「X-KD>=0」であれば、その地点で終了
# 「X-KD<0」であれば、原点周りを振動する
if X - K*D >= 0:
  ans = X - K*D
else:
  count = X // D
  K = K - (X // D) # math.floor() を使うより簡潔
  if K % 2 == 0: 
    ans = X - count*D
  else: 
    ans = D - (X - count*D)
    
print(ans)

Measured memory_bytes: 9132
#include <cstdio>
#include <queue>
#include <cstring>
using namespace std;

int w, h;
char f1[54][54], f2[54][54];
bool visit[54][54][54][54];
int dys[] = {-1, 0, 1, 0};
int dxs[] = {0, -1, 0, 1};

void trymove(const char f[][54], int &y, int &x, int dy, int dx){
	if(f[y + dy][x + dx] != '#'){
		y += dy;
		x += dx;
	}
}

bool solve(){
	memset(f1, '#', sizeof f1);
	memset(f2, '#', sizeof f2);
	memset(visit, 0, sizeof visit);

	int ly = -1, lx = -1, ry = -1, rx = -1;
	for(int i = 1; i <= h; ++i){
		scanf("%s%s", f1[i] + 1, f2[i] + 1);
		f1[i][w + 1] = f2[i][w + 1] = '#';
		
		for(int j = 1; j <= w; ++j){
			if(f1[i][j] == 'L'){
				ly = i;
				lx = j;
			}
			if(f2[i][j] == 'R'){
				ry = i;
				rx = j;
			}
		}
	}

	visit[ly][lx][ry][rx] = true;
	queue<int> q;
	q.push(ly << 24 | lx << 16 | ry << 8 | rx);
	while(!q.empty()){
		for(int i = 0; i < 4; ++i){
			ly = q.front() >> 24;
			lx = q.front() >> 16 & 0xff;
			ry = q.front() >> 8 & 0xff;
			rx = q.front() & 0xff;

			trymove(f1, ly, lx, dys[i], dxs[i]);
			trymove(f2, ry, rx, dys[i], dxs[(i + 2) & 3]);
			if(visit[ly][lx][ry][rx]){ continue; }
			visit[ly][lx][ry][rx] = true;
			int chk = (f1[ly][lx] == '%') + (f2[ry][rx] == '%');
			if(chk == 2){ return true; }
			if(chk == 0){
				q.push(ly << 24 | lx << 16 | ry << 8 | rx);
			}
		}
		q.pop();
	}
	return false;

}

int main(){
	while(scanf("%d%d", &w, &h), w){
		puts(solve() ? "Yes" : "No");
	}
}

Measured memory_bytes: 9512
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define each(a, b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define pb push_back
#define sint(x) cout <<#x<<" = "<<(x)<<endl
#define spair(p) cout <<#p<<": "<<p.fi<<" "<<p.se<<endl
#define svec(v) cout<<#v<<":";rep(i,v.size())cout<<" "<<v[i];cout<<endl
#define sset(s) cout<<#s<<":";each(i,s)cout <<" "<<i;cout<<endl

using namespace std;


typedef pair<int,int>P;

const int MAX_N = 100005;

int main()
{
    int n,m;
    cin >> n;
    map<string,int> mp;
    int pos = 1;
    rep(i,n){
        string s;
        cin >> s;
        mp[s] = i+1;
    }
    cin >> m;
    rep(i,m){
        string s;
        cin >> s;
        if(mp[s] == 0){
            cout << "Unknown " << s << "\n";
        }else{
            if(pos == 0){
                cout << "Closed by " << s << "\n";
                pos = 1;
            }else{
                cout << "Opened by " << s << "\n";
                pos = 0;
            }
        }
    }
}

Measured memory_bytes: 3220
#include<iostream>
#include<cmath>
#include<cstdio>
using namespace std;
int main(){
  int n;
  cin >>n;
  while(n--){
    double a[2],b[2],c[2],o[2],m[2][2],x[2],y[2],det,i[2][2],r;
    cin >>a[0]>>a[1]>>b[0]>>b[1]>>c[0]>>c[1];
    b[0]-=a[0];
    b[1]-=a[1];
    c[0]-=a[0];
    c[1]-=a[1];
    m[0][0] = 2*b[0];
    m[0][1] = 2*b[1];
    m[1][0] = 2*c[0];
    m[1][1] = 2*c[1];
    y[0] = b[0]*b[0]+b[1]*b[1];
    y[1] = c[0]*c[0]+c[1]*c[1];
    det = m[0][0]*m[1][1]-m[1][0]*m[0][1];
    i[0][0] = m[1][1]/det;
    i[0][1] = -m[0][1]/det;
    i[1][0] = -m[1][0]/det;
    i[1][1] = m[0][0]/det;
    x[0] = y[0]*i[0][0]+y[1]*i[0][1];
    x[1] = y[0]*i[1][0]+y[1]*i[1][1];
    r = sqrt(x[0]*x[0]+x[1]*x[1]);
    x[0]+=a[0];
    x[1]+=a[1];
    printf("%.3lf %.3lf %.3lf\n",x[0],x[1],r);
  }
  return 0;
}

Measured memory_bytes: 1244
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<set>
#include<map>
#include<iomanip>

using namespace std;

int main(void) {
	int a, b;
	cin >> a >> b;
	int h[999];
	h[0] = 1;
	for (int i = 1; i <= 999; i++) {
		h[i] = h[i - 1] + i + 1;
		if (b - a == h[i] - h[i - 1]) {
			cout << h[i - 1] - a;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;

using ULL = int64_t;
using pii = pair<int, int>;

int bridge[100000] = {};
pii request[100000] = {};

int main(void) {

	int N, M;
	int l = 0,result = 0;
	cin >> N >> M;

	for (int i = 0; i < M; i++)
	{
		cin >> request[i].first >> request[i].second;
		request[i].first--;
		request[i].second--;
	}

	sort(request,request + M);

	for (int i = 0; i < M; i++)
	{
		bridge[request[i].second] = i + 1;
	}

	for (int i = 0; i < N; i++)
	{
		if (bridge[i] != 0) {
			result++;
			for (int j = l; j < M; j++) {
				if (request[j].first < i) {
					if(bridge[request[j].second] == j + 1)
						bridge[request[j].second] = 0;
				}
				else {
					l = j;
					break;
				}

			}
		}
	}

	cout << result << endl;

	return 0;
}


Measured memory_bytes: 1408
import java.util.*;
class Main {
  public static void main(String args[]) {
    Scanner sc = new Scanner(System.in);
    final int A = sc.nextInt();
    final int B = sc.nextInt();

    if(A % 3 == 0 || B % 3 == 0 || (A + B) % 3 == 0)
      System.out.println("Possible");
    else
      System.out.println("Impossible");
  }
}

Measured memory_bytes: 21844
#include<iostream>
#include<fstream>
#include<cmath>
#include<string>
#include<set>
#include <map>
#include<algorithm>
#include<vector>
#include <queue>
#include <stack>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
const double PI = acos(-1.0);
const ll INF = LLONG_MAX;
const int A = 1234567;
double arr[A]; 
 
int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (c >= a && c <= b)
		cout << "Yes";
	else
		cout << "No";
	
}

Measured memory_bytes: 888
#include<iostream>
#include<queue>
#include<cstring>
#include<map>
using namespace std;
typedef pair<int,int>Pt;
#define fr first
#define sc second
Pt st[10];
int h,w,n,dx[]={0,1,0,-1},dy[]={1,0,-1,0},used[1000][1000];
char mas[1000][1000],tmp[]="S123456789";
int bfs(Pt,Pt);
int main(){
  cin >> h >> w >> n;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cin >> mas[i][j];
      for(int k=0;k<=n;k++){
	if(mas[i][j] == tmp[k]) st[k] = Pt(i,j);
      }
    }
  }
  int cnt = 0;
  for(int i=1;i<=n;i++){
    memset(used,-1,sizeof(used));
    cnt += bfs(st[i-1],st[i]);
  }
  cout << cnt << endl;
}

int bfs(Pt S,Pt G){
  queue<Pt> que;
  que.push(S);
  used[S.fr][S.sc] = 0;
  while(!que.empty()){
    Pt p = que.front();
    que.pop();
    if(p == G) break;
    for(int i=0;i<4;i++){
      int nx = p.fr + dx[i],ny = p.sc + dy[i];
      if(nx>=0 && nx<h && ny>=0 && ny<w && used[nx][ny]==-1 && mas[nx][ny]!='X'){
	used[nx][ny] = used[p.fr][p.sc] + 1;
	que.push(Pt(nx,ny));
      }
    }
  }
  return used[G.fr][G.sc];
}  

Measured memory_bytes: 6104
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define MOD 1000000007

int main() {
  int n;
  cin >> n;
  set<int> st;
  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    if (st.find(a) == st.end()) {
      st.insert(a);
    } else {
      st.erase(a);
    }
  }
  cout << st.size() << endl;
  return 0;
}

Measured memory_bytes: 4864
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<math.h>
#include<assert.h>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr int INFI = 1000000007;
const int mod = 1000000007;

int main(){
int n,a,b;
int cnt=0,sum=0;
int c=0;
cin>>n>>a>>b;
for(int i=1;i<=n;i++){
    c=i;
    cnt=0;
    while(c>0){
        cnt+=c%10;
        c=c/10;
    }
    if(cnt>=a&&cnt<=b){
        sum+=i;
        }
}
cout<<sum<<endl;
}













Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
//FILE *fi = freopen("1.txt", "r", stdin);
//FILE *fo = freopen("1", "w", stdout);
//FILE *fi = freopen("P.inp", "r", stdin);
//FILE *fo = freopen("P.out", "w", stdout);
int n;
int m;
vector<int> a[200001];
bool used[200001];
int cnt = 0;
void dfs(int u)
{
    ++cnt;
    used[u] = true;
    for (auto v : a[u])
    {
        if (!used[v])
            dfs(v);
    }
}
int main()
{
    //------------------------------
    // Faster
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //-------------------------------
    cin >> n >> m;
    for (int i = 1; i <= m; i++)
    {
        int u, v;
        cin >> u >> v;
        a[u].push_back(v);
        a[v].push_back(u);
    }
    int ans = 0;
    for (int i = 1; i <= n; i++)
    {
        if (!used[i])
        {
            cnt = 0;
            dfs(i);
            ans = max(ans, cnt);
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 21020
A, B, C = (int(i) for i in input().split())

if max(A,B,C) == A:
    print(A*10+B+C)
elif max(A,B,C) == B:
    print(B*10+A+C)
elif max(A,B,C) == C:
    print(C*10+B+A)


Measured memory_bytes: 2940
#include<iostream>
#include <iomanip>
#include <ios>
#include <vector>
#include <string>
#include <algorithm>
#include <string>
#include<limits>
#include<cstdlib>
#include<functional>
#include<cassert>
#include <cstdio>
#include <stack>
#include <queue>
#include <map>
//#include <bits/stdc++.h>//atcoderでsqrtを使うときに必要
#define fi(p) for(int i=0;i<(p);i++)
#define ce(d) cout<<d<<endl;
#define ll long long
#define sorts(c) sort((c).begin(),(c).end());

using namespace std;



void solve() {
	ll a,b,k;
	cin >> a >> b >>k;

	if (k <= a) {
		ce(a - k);
		ce(b)
	}
	else {
		ce(0);
		if (b + a - k < 0) {
			ce(0);
		}
		else {
			ce(b + a - k)
		}
	}

	
}

int main()
{
	solve();

	int a;//止める用
	cin >> a;
	return 0;
}

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

int main(){
	string W;
	cin >> W;
  	if (W == "a"){
    cout << "vowel" << endl;
    }
  	else if (W == "i"){
    cout << "vowel" << endl;
    }
	else if (W == "u"){
    cout << "vowel" << endl;
    }
  	else if (W == "e"){
    cout << "vowel" << endl;
    }
  	else if (W == "o"){
    cout << "vowel" << endl;
    }
  	else {
    cout << "consonant" << endl;
    }
}

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

int main() {
    int N, M; cin >> N >> M;
    vector<vector<char>> A(N, vector<char>(N));
    vector<vector<char>> B(M, vector<char>(M));
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) cin >> A.at(i).at(j);
    }
    for (int i = 0; i < M; i++) {
        for (int j = 0; j < M; j++) cin >> B.at(i).at(j);
    }
    
    if (N == M) {
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                if (A.at(i).at(j) != B.at(i).at(j)) {
                    cout << "No" << endl;
                    return 0;
                }
            }
        }
        cout << "Yes" << endl;
        return 0;
    }
    
    for (int i = 0; i < N-M; i++) {
        for (int j = 0; j < N-M; j++) {
            bool flag = true;
            for (int k = 0; k < M; k++) {
                for (int l = 0; l < M; l++) {
                    if (A.at(i+k).at(j+l) != B.at(k).at(l)) {
                        flag = false;
                        break;
                    }
                }
                if (!(flag)) break;
            }
            if (flag) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 3604
package main

import "fmt"

func main() {
        var N, Y int
        fmt.Scanf("%d %d", &N, &Y)

        for x := 0; x <= N; x++ {
                for y := 0; (x + y) <= N; y++ {
                        z := N - x - y
                        if (10000*x + 5000*y + 1000*z) == Y {
                                fmt.Printf("%d %d %d", x, y, z)
                                return
                        }
                }
        }

        fmt.Printf("%d %d %d", -1, -1, -1)
}


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

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

int main() {
	cin.sync_with_stdio(false);
	ll N, x;
	cin >> N >> x;
	vector<int>a(N);
	vector<int>mint(N);
	rep(i, N) {
		cin >> a[i];
		mint[i] = a[i];
	}
	ll ans = INF;
	
	rep(i, N) {
		ll t = x*i;
		rep(j, N) {
			mint[j] = min(mint[j], a[(j - i >= 0 ? j - i : N + j - i)]);
			t += mint[j];
		}
		ans = min(ans, t);
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
H,W,K = map(int,input().split())

a = [list(input()) for _ in range(H)] #listの中にlist()を標準入力する。H行分作成する。
#a = np.zeros((int(H),int(W)))

ans = 0
for i in range(2**H): #行の塗り方のパターン
    for j in range(2**W): #列の塗り方のパターン
        count = 0
        for s in range(H):
            for t in range(W):
                if(i >> s)&1 and (j>>t) & 1 and a[s][t] =="#":
                    count += 1
        if count == K:
            ans += 1
print(ans)

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



int main() 
{
    string s;
    cin >> s;
    if(s=="ABC")
    {
        cout << "ARC" << endl;
    }
    else
    {
        cout << "ABC" << endl;
    }

    return 0;
}

Measured memory_bytes: 3624