akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <unordered_map>
#include <ctime>
#include <list>
#include <numeric>
#include <utility>
#include <ctime>
#define INF 1000000000
#define LINF 9000000000000000000
#define mod 1000000007

#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair
#define MOD(x) (x%(mod))

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
bool debug=false;

/*---------------------------------------------------*/

ll similarity_multiple(ll a,ll b){
  return (a/b*b+(a%b!=0?1:0)*b);
}

int main(){
  ll n,a[100005],b[100005];
  cin>>n;
  rep(i,n){
    cin>>a[i]>>b[i];
  }
  reverse(a,a+n);
  reverse(b,b+n);
  ll ans=0;
  rep(i,n){
    a[i]+=ans;
    ll tmp=similarity_multiple(a[i],b[i]);
    ans+=tmp-a[i];
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <set>
#include <queue>
#include <stack>
using namespace std;
typedef long long int ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define drep(i, n) for(int i = n - 1; i >= 0; i--)
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define yes cout << "yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define no cout << "no" << endl

const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const int mod = 1000000007;
#define PI 3.14159265359;

void P(int x) {cout << x << endl;}
void P(long x) {cout << x << endl;}
void P(double x) {cout << x << endl;}
void P(ll x) {cout << x << endl;}
void P(string x) {cout << x << endl;}
void P(char x) {cout << x << endl;}

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main() {
  int n, k;
  cin >> n >> k;
  map<int, int> mp;
  rep (i, n) {
    int tmp;
    cin >> tmp;
    auto itr = mp.find(tmp);
    if (itr != mp.end()) mp[tmp]++;
    else mp[tmp] = 1;
  }

  vector<int> v;
  for (auto itr = mp.begin(); itr != mp.end(); itr++) {
    v.push_back(itr->second);
    // cout << itr->first << "=>" << itr->second << endl;
  }

  sort(v.begin(), v.end());
  int ans = 0;
  int vSize = v.size();
  int i = 0;
  while (vSize > k) {
    ans += v[i];
    vSize--;
    i++;
  }
  P(ans);
  return 0;
}





Measured memory_bytes: 10748
#include <bits/stdc++.h>
#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define PRINT(x) cout << (x) << "\n"
using namespace std;
using ll = long long; using pint = pair<int, int>; using pll = pair<ll, ll>;
template<typename T> auto compare = [](T x, T y) -> bool{return (x < y);};
const int MOD = 1000000007;

class Combination_Mod{
    public:
        Combination_Mod(long long MAX, long long MOD) : fact(MAX + 1), inv(MAX + 1), finv(MAX + 1), MAX(MAX + 1), MOD(MOD){
            init();
        }

        void init(){
            fact[0] = fact[1] = 1;
            finv[0] = finv[1] = 1;
            inv[1] = 1;
            for(long long i = 2; i < MAX; ++i){
                fact[i] = fact[i - 1] * i % MOD;
                inv[i] = MOD - inv[MOD % i] *  (MOD / i) % MOD;
                finv[i] = finv[i - 1] * inv[i] % MOD;
            }
        }

        long long bin(long long n, long long r){
            if(n < r || n < 0 || r < 0) return 0;
            return fact[n] * (finv[r] * finv[n - r] % MOD) % MOD;
        }

        long long perm(long long n, long long r){
            return (bin(n, r) * fact[r]) % MOD;
        }

        long long factorial(long long n){
            return fact[n];
        }

        long long modinv(long long n){
            return inv[n];
        }

        long long modfinv(long long n){
            return finv[n];
        }

    private:
        vector<long long> fact;
        vector<long long> inv;
        vector<long long> finv;
        const long long MAX;
        const long long MOD;
};

Combination_Mod c(2000010, MOD);

ll f(ll i, ll j){
    return c.bin(i + j, j);
}

ll g(ll i, ll j){
    return (f(i + 1, j + 1) - f(0, j) + MOD) % MOD;
}

signed main(){
    ll r1, c1, r2, c2;
    cin >> r1 >> c1 >> r2 >> c2;
    Combination_Mod c(1000001, MOD);
    ll ans = g(r2, c2) + (MOD - g(r1 - 1, c2)) % MOD + (MOD - g(r2, c1 - 1)) % MOD + g(r1 - 1, c1 - 1);
    ans %= MOD;
    PRINT(ans);
    return 0;
}

Measured memory_bytes: 73464
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n,m;
vector<int> G[100001];
int col[100001];
ll dp[2][901];
vector<P> p;
P po;

bool dfs(int v,int c){
	if(c==1){
		po.first++;
	}else{
		po.second++;
	}
	col[v]=c;
	for(int i=0;i<G[v].size();i++){
		if(col[G[v][i]]==0){
			if(!dfs(G[v][i],-c))return false;
		}else if(col[G[v][i]]==c){
			return false;
		}
	}
	return true;
}

int main(void){
	scanf("%d%d",&n,&m);
	for(int i=0;i<m;i++){
		int a,b;
		scanf("%d%d",&a,&b);
		a--;
		b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	for(int i=0;i<n;i++){
		if(col[i]==0){
			po=P(0,0);
			if(!dfs(i,1)){
				printf("-1\n");
				return 0;
			}
			p.push_back(po);
		}
	}
	dp[0][0]=1;
	int cur=0,nxt=1;
	for(int i=0;i<p.size();i++){
		for(int j=0;j<900;j++){
			for(int k=0;k<2;k++){
				int v=p[i].first;
				int dig=v/60;
				int diff=v%60;
				if(j+dig<900){
					ll va=dp[cur][j]&((1LL<<(60-diff))-1LL);
					dp[nxt][j+dig]|=va<<diff;
				}
				if(j+dig+1<900 && diff>0){
					dp[nxt][j+dig+1]|=dp[cur][j]>>(60-diff);
				}
				swap(p[i].first,p[i].second);
			}
		}
		swap(cur,nxt);
		memset(dp[nxt],0,sizeof(dp[nxt]));
	}
	int best=0;
	for(int i=0;i<900;i++){
		for(int j=0;j<60;j++){
			if(dp[cur][i]>>j & 1){
				int val=j+i*60;
				if(abs(n/2-val)<abs(n/2-best)){
					best=val;
				}
			}
		}
	}
	printf("%lld\n",(ll)best*(n-best)-m);
	return 0;
}


Measured memory_bytes: 9688
#include<stdio.h>
int main()
{
	int N;
  scanf("%d",&N);
 	long A[N];
    int i=0;
  for(i=0;i<N;i++){
	scanf("%ld",&A[i]);
  }
  
  long len1 = 0;
  long len2 = 0;
  long dif = 0;
  int count = 0;
  int  count2 = 0;
  int sum  = 0;
  
  for(i=0;i<N;i++){
    if((len1 - len2) <= 0){
		len1 = len1 + A[count];
      //printf("len1:%ld\n",len1);
      	count++;
      	sum++;
     // printf("sum1:%d",sum);
      	if(sum == N){
      	    goto end;
      	}
    }if((len2 - len1) <= 0){
    	len2 = len2 + A[N-count2-1];
      //printf("len2:%ld\n",len2);
      	count2++;
      	sum++;
     //  printf("sum2:%d",sum);
      	if(sum == N){
      	    goto end;
      	}
    }
  }
  
  end:
  if(len2 >= len1){
      dif = len2 - len1;
  }
  if(len1 >= len2){
      dif = len1 - len2;
  }
  
 printf("%ld",dif);
    return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e16)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))
//tie(a,b,c) = make_tuple(10,9,87);
#define pop(a) __builtin_popcount((a))
ll keta(ll a){ll r=0;while(a){a/=10;r++;}return r;}



int main(){

  ll N;
  cin >> N;
  vector<ll> A(N+1);

  FOR(i,1,N+1){
    cin >> A[i];
  }

  ll ans = 0;
  map<ll,ll> ma;
  FOR(i,1,N+1){
    ans += ma[i-A[i]];
    ma[A[i]+i]++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 27376
use io::*;
use std::*;

fn solve(N: i64,mut A: Vec<i64>) {
    A.sort();
    let mut minus = 0;
    let mut hurui = Vec::new();
    hurui.resize((A[A.len() - 1] + 1) as usize, 0);
    let half = (A[A.len() - 1] / 2)as usize;
    for i in 0..N as usize {
        let mut counter = 1;
        if A[i] as usize <= half {
            loop {
                let baisu: usize = A[i] as usize * counter;
                if baisu > A[A.len() - 1] as usize {
                    break;
                }
                hurui[baisu] += 1;
                counter += 1;
            }
        } else {
            hurui[A[i] as usize] += 1;
        }
    }
    let mut res = 0;
    for i in 0..N as usize {
        if hurui[A[i] as usize] < 2{
            res += 1;
        }
    }
    println!("{}", res - minus);
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
fn main() {
    let con = read_string();
    let mut scanner = Scanner::new(&con);
    let mut N: i64;
    N = scanner.next();
    let mut A: Vec<i64> = vec![0i64; (N) as usize];
    for i in 0..(N) as usize {
        A[i] = scanner.next();
    }
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(move || solve(N, A)).unwrap().join().unwrap();
}

pub mod io {
    use std;
    use std::str::FromStr;

    pub struct Scanner<'a> {
        iter: std::str::SplitWhitespace<'a>,
    }

    impl<'a> Scanner<'a> {
        pub fn new(s: &'a str) -> Scanner<'a> {
            Scanner {
                iter: s.split_whitespace(),
            }
        }

        pub fn next<T: FromStr>(&mut self) -> T {
            let s = self.iter.next().unwrap();
            if let Ok(v) = s.parse::<T>() {
                v
            } else {
                panic!("Parse error")
            }
        }

        pub fn next_vec_len<T: FromStr>(&mut self) -> Vec<T> {
            let n: usize = self.next();
            self.next_vec(n)
        }

        pub fn next_vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
            (0..n).map(|_| self.next()).collect()
        }
    }

    pub fn read_string() -> String {
        use std::io::Read;

        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }

    pub fn read_line() -> String {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        s.trim_right().to_owned()
    }
}


Measured memory_bytes: 8800
class Array
	def bsearch_last_index(l = 0, r = size - 1, &pred)
		return nil if l > r
		c = (l + r) / 2 
		if pred[self[c]]
			bsearch_last_index(c+1, r, &pred) || c
		else
			bsearch_last_index(l, c-1, &pred)
		end
	end

	def bsearch_last_item(l = 0, r = size - 1, &pred)
		i = bsearch_last_index(l, r, &pred)
		i ? self[i] : nil
	end
end

loop do
	n = gets.to_i
	break if n == 0
	
	segments = { -1 => [[0, Float::INFINITY]] }	

	n.times do
		command, i, s = gets.chomp.split
		i = i.to_i

		if command == "W"
			s = s.to_i
			next if s <= 0
			
			seg = []
			loop do
				emp = segments[-1].shift
				start, len = emp
				if s < len
					emp[0] += s
					emp[1] -= s
					seg << [start, s]
					segments[-1].unshift emp
					break
				else 
					s -= len
					seg << emp
				end
			end
			segments[i] = seg

		elsif command == "D"
			merged = []
			e_segs = segments[-1]
			d_segs = segments[i]

			loop do
				if e_segs.empty? || d_segs.empty?
					merged += d_segs + e_segs
					break
				end

				target = nil
				if e_segs[0][0] < d_segs[0][0]
					target = e_segs.shift	
				else
					target = d_segs.shift	
				end

				if !merged.empty? && merged[-1][0] + merged[-1][1] == target[0]
					merged[-1][1] += target[1]
				else
					merged << target
				end
			end
			
			segments[-1] = merged
			segments.delete(i)

		else
			segments.each do |k, arr|
				start, len = arr.bsearch_last_item {|start, len| start <= i}
				if start && i < start + len
					puts k
					break
				end
			end
		end
	end

	puts
end

Measured memory_bytes: 32052
a,b = map(int,input().split())

res = 0

if a == 1 :
    res += 300000
elif a == 2 :
    res += 200000
elif a == 3 :
    res += 100000

if b == 1 :
    res += 300000
elif b == 2 :
    res += 200000
elif b == 3 :
    res += 100000

if a == 1 and b == 1 :
    res += 400000

print(res)

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

int main(){
    int H,W;
    while(1){
        cin>>H>>W;
        if(H==0 && W==0)break;
        for(int a=0;a<H;a++){
            for(int b=0;b<W;b++){
                if((a+b)%2==0){
                    cout<<"#";
                }
                if((a+b)%2==1){
                    cout<<".";
                }
            }
            cout<<endl;
        }
        cout<<endl;
    }
    return 0;
}


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

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

  bool flg=true;
  for(int i=0; i<s.size(); i++){
    for(int j=i+1; j<s.size(); j++){
      if(s[i]==s[j])flg=false;
    }
  }

  if(flg)cout<<"yes"<<endl;
  else cout<<"no"<<endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;
#define MAX 21
#define NMAX  50001
int main()
{
    int n,m;
    int T[NMAX],c[MAX];
    cin>>n>>m;
    for(int i=0;i<m;i++){
        cin>>c[i];
    }
    for(int i=0;i<NMAX;i++){
        T[i] = (1<<21);
    }
    T[0] = 0;
    for(int i=0;i<m;i++){
        for(int j=0;j+c[i]<=n;j++){
            T[j+c[i]] = min(T[j]+1,T[j+c[i]]);
        }
    }
    cout<<T[n]<<endl;
    return 0;
}



Measured memory_bytes: 3288
N, M = list(map(int, input().split()))
V = 10 ** 9 + 7
a = [int(input()) for _ in range(M)]
A = set(a)
ANS = [0 for _ in range(N + 5)]

ANS[0] = 1
for i in range(N):
    ANS[i] %= V
    if not i + 1 in A:
        ANS[i + 1] += ANS[i]
    if not i + 2 in A:
        ANS[i + 2] += ANS[i]

print(ANS[N] % V)


Measured memory_bytes: 13192
#include <bits/stdc++.h>
using namespace std;
int main() {
	int N, M, K;
	cin >> N >> M >> K;
	for (int i = 0; i <= N; ++ i) {
		for (int j = 0; j <= M; ++ j) {
			if (i*M + j*N - 2*i*j == K) {
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A; cin >>A;
  int B; cin >>B;
  if(A+B==3){
    cout<<3<<endl;
  }else if(A+B==4){
    cout<<2<<endl;
  }else{
    cout<<1<<endl;
  }
}

Measured memory_bytes: 256
#include<stdio.h>
#define N 3

typedef struct{
  int P[N][N];
}Pazz;

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

int Heu(Pazz Q){
  int i ,j;
  int hx,hy,sum=0;
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(Q.P[i][j]==0)continue;

      hx=(Q.P[i][j]-1)%N-j;
      hy=(Q.P[i][j]-1)/N-i;

      if(hx<0)sum-=hx;
      else sum+=hx;

      if(hy<0)sum-=hy;
      else sum+=hy;
    }
  }
  return sum;
}
int dfs (int x,int y,int max,int count,int n){
  int i,temp;
  int x0,y0,ans=-1,h;

  h=Heu(Q);

  if(h==0)return count;
  if((count+h) > max)return -1;

  for(i=0;i<4;i++){
    x0=x+dx[i];
    y0=y+dy[i];

    if(((i == (n+2)%4 )&& (n!=-1))||!((0<=x0 )&&( x0<N) && (0<=y0) && (y0<N)))continue;
    temp=Q.P[y][x];
    Q.P[y][x]=Q.P[y0][x0];
    Q.P[y0][x0]=temp;

    ans= dfs(x0,y0,max,count+1,i);

    if(ans!=-1)return ans;
    temp=Q.P[y][x];
    Q.P[y][x]=Q.P[y0][x0];
    Q.P[y0][x0]=temp;
  }

  return -1;

}

int main(){
  int i,j;
  int kx,ky,ans,a;
  Pazz tP;

  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      scanf("%d",&a);
      Q.P[i][j]=a;
      if(a==0){
        kx=j;
        ky=i;
      }
    }
  }

  tP=Q;
  for(i=1;i<46;i++){
    Q=tP;
    ans=dfs(kx,ky,i,0,-1);
    if(ans!=-1){
      printf("%d\n",ans);
      break;
    }
  }

  return 0;
}



Measured memory_bytes: 2124
#pragma GCC optimize(2)
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using PII = pair<int,int>;
using PLL = pair<LL, LL>;
const int INF = 1e9;
const int MXN = 5005;
const int MXV = 0;
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define FOR(i, L, R) for(int i = L; i != (int)R; ++i)
#define FORD(i, L, R) for(int i = L; i != (int)R; --i)
#define IOS cin.tie(nullptr); cout.tie(nullptr); ios_base::sync_with_stdio(false);
vector<LL> d(MXN), a(MXN), zero(MXN), sum(MXN);

LL sol(LL k, LL n, LL x, LL m)
{
    x %= m;
    zero[0] = sum[0] = 0;
    FOR(i, 1, k + 1)
    {
        a[i] = d[i] % m;
        zero[i] = zero[i - 1] + (a[i] == 0);
        sum[i] = sum[i - 1] + a[i];
    }
    LL ans = n - 1;
    // cout << zero[k] << ' ' << sum[k] << '\n';
    ans -= ((n - 1) / k) * zero[k] + zero[(n - 1) % k];
    ans -= (((n - 1) / k) * sum[k] + sum[(n - 1) % k] + x) / m - x / m;
    return ans;
}

int main()
{
    IOS;
    int k, q;
    cin >> k >> q;
    FOR(i, 1, k + 1) { cin >> d[i]; }
    while(q--)
    {
        LL n, x, m;
        cin >> n >> x >> m;
        cout << sol(k, n, x, m) << '\n';
    }
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  vector<vector<int>> l(n, vector<int>(3));
  
  for (int i = 0; i < n; i++){
    for(int j = 0; j < 3; j++){
      cin >> l.at(i).at(j);
    }
  }
  vector<vector<int>> dp(n+1, vector<int>(3));
  dp.at(0).at(0) = 0;
  dp.at(0).at(1) = 0;
  dp.at(0).at(2) = 0;
  //dp.at(1) = abs(h.at(1)-h.at(0));
  
  for(int k = 1;k < n+1;k++){
    for(int m = 0;m < 3;m++){
      if(m == 0){
        dp[k][m] = max(dp[k-1][1],dp[k-1][2]) + l[k-1][m];
      }else if(m == 1){
        dp[k][m] = max(dp[k-1][0],dp[k-1][2]) + l[k-1][m];     
      }else{
        dp[k][m] = max(dp[k-1][1],dp[k-1][0]) + l[k-1][m];   
      }
    }
  }
  int res =max(max(dp[n][0],dp[n][1]),dp[n][2]);
  cout << res << endl;
}

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

typedef long long ll;

const int maxn = 2e4 + 5;

int n;
ll c1, c2;
int a[maxn], b[maxn];

int main()
{
	scanf("%d", &n);
	for(int i = 1; i <= n; i++)
		scanf("%d", &a[i]);
	for(int i = 1; i <= n; i++)
		scanf("%d", &b[i]);
	for(int i = 1; i <= n; i++)
	{
		b[i] -= a[i];
		if(b[i] < 0)
			c1 -= b[i];
		else
			c2 += b[i] / 2;
	}
	if(c1 > c2)
		puts("No");
	else
		puts("Yes");
	return 0;
}

Measured memory_bytes: 384
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
            Console.ReadLine();
        }

        public void Solve(ConsoleInput cin)
        {
            if (cin.ReadInt * cin.ReadInt % 2 == 0)
                Console.WriteLine("Even");
            else
                Console.WriteLine("Odd");
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long num) { var ret = new string[num]; for (long i = 0; i < num; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long num) { var ret = new int[num]; for (long i = 0; i < num; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long num) { var ret = new long[num]; for (long i = 0; i < num; ++i) ret[i] = ReadLong; return ret; }
    }
}

Measured memory_bytes: 11220
#include<iostream>

using namespace std;

int h, w;
char s[2050][2050];
int c[2050][2050];
int l[2050][2050], r[2050][2050], u[2050][2050], d[2050][2050];
int ans[2050][2050];

void solver(){
  int answer = 0;
  
  for(int i = 0; i < h; ++i){
    for(int j = 0; j < w; ++j){
      if(c[i][j] == 0){
        l[i][j] = 0;
      }else if(j == 0){
        l[i][j] = 1;
      }else{
        l[i][j] = l[i][j - 1] + 1;
      }
    }
  }
  for(int i = 0; i < h; ++i){
    for(int j = w - 1; j >= 0; --j){
      if(c[i][j] == 0){
        r[i][j] = 0;
      }else if(j == w - 1){
        r[i][j] = 1;
      }else{
        r[i][j] = r[i][j + 1] + 1;
      }
    }
  }
  for(int i = 0; i < h; ++i){
    for(int j = 0; j < w; ++j){
      if(c[i][j] == 0){
        u[i][j] = 0;
      }else if(i == 0){
        u[i][j] = 1;
      }else{
        u[i][j] = u[i - 1][j] + 1;
      }
    }
  }
  for(int i = h - 1; i  >= 0; --i){
    for(int j = 0; j < w; ++j){
      if(c[i][j] == 0){
        d[i][j] = 0;
      }else if(i == h - 1){
        d[i][j] = 1;
      }else{
        d[i][j] = d[i + 1][j] + 1;
      }
    }
  }
  
  for(int i = 0; i < h; ++i){
    for(int j = 0; j < w; ++j){
      ans[i][j] = l[i][j] + r[i][j] + u[i][j] + d[i][j] - 3;
      if(ans[i][j] > answer){
        answer = ans[i][j];
      }
      //cout << ans[i][j] << endl;
    }
  }

 cout << answer << endl;

  
}

int main(){
  cin >> h >> w;
  for(int i = 0; i < h; ++i){
    for(int j = 0; j < w; ++j){
      cin >> s[i][j];
      if(s[i][j] == '.'){
        c[i][j] = 1;
      }else{
        c[i][j] = 0;
      }
      //cout << c[i][j];
    }
  }
  solver();
}

Measured memory_bytes: 102784
#include<bits/stdc++.h>
#define ll long long
#define debug(a) cout<<a<<endl
#define pii pair<ll,ll>
#define maxn 59
using namespace std;
int n,k;
ll dp[maxn][maxn][110],vet[maxn];
ll solve(int l,int r,int k){
    if(l>r || r<l || k<=0)return 0;
    if(dp[l][r][k]!=-1)return dp[l][r][k];
    ll a=0,b=0,c=0,d=0;
    a=solve(l+1,r,k-1)+vet[l];
    if(k>=2)b=solve(l+1,r,k-2);
    c=solve(l,r-1,k-1)+vet[r];
    if(k>=2)d=solve(l,r-1,k-2);
    dp[l][r][k]=max(a,max(b,max(c,d)));
    return dp[l][r][k];
}
int main(){
    ios::sync_with_stdio(false);    
    cin>>n>>k;
    memset(dp,-1,sizeof dp);
    for(int i=0;i<n;i++){
        cin>>vet[i];
    }
    cout<<solve(0,n-1,k)<<endl;
    return 0;
}
///usar double sempre ou long double
///pensar em casos que coisas dao negativas
///N esquecer de limpar as coisas em quest de varios testes
///OLHAR A COMPLEXIDADE PRA VER SE N PASSA POR BRUTE FORCE OU BRUTE FORCE COM ALGUMAS OTIMIZACOES

Measured memory_bytes: 3200
#include<iostream>

using namespace std;

#define N 100

//grobal
int data[N],num1,num2;

//flag
bool flag=false;

//function solve
bool solve(int i,int m){

  //if i >num1 then false
  if(i>num1) return false;

  //if m=0 then  true
  if(m==0){
    flag=true;
    return true;
  }
  //execute
  solve(i+1,m);
  solve(i+1,m-data[i]);  

}


int main(){

  int i,m;

  //load number
  cin >>num1;

  //load data
  for(i=0;i<num1;i++){
    cin >>data[i];
  }
  //load number
  cin >>num2;
  //load  data and execute
  for(i=0;i<num2;i++){
    cin >>m;
    //initial flag
    flag=false;
    //execute solve
    solve(0,m);

    //print yes or no
    if(flag==true){
      cout <<"yes"<<endl;
    }  
    else cout <<"no"<<endl;
  }

  return 0;
}

Measured memory_bytes: 856
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

int main() {
	char b;
	scanf("%c", &b);
	if (b == 'A') {
		printf("T");
	}
	else if (b =='T') {
		printf("A");
	}
	else if (b == 'G') {
		printf("C");
	}
	else if (b == 'C') {
		printf("G");
	}
}

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

using namespace std;

typedef long long int ll;

#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;

int main()
{
	int n,k,q;
	cin >> n >> k >> q;
	vector<int> a(n);
	for(int i = 0; i < n; i++){
		cin >> a[i];
	}
	int ans= 1e9;
	for(int i = 0; i < n; i++){
		//cout << a[i] << endl;
		vector<vector<int> > b;
		vector<int> res;
		for(int j = 0; j < n; j++){
			if(a[j]>=a[i]){
				res.push_back(a[j]);
				if(j==n-1){
					b.push_back(res);
					res.clear();
				}
			}else{
				b.push_back(res);
				res.clear();
			}
		}
		//cout << a[i] << endl;
		for(int j = 0; j < b.size(); j++){
			sort(all(b[j]));
			// cout << b[j].size() << endl;
			// for(int l = 0; l < b[j].size(); l++){
			// 	cout << b[j][l] << endl;
			// }
			if(b[j].size()<k) continue;
			for(int l = 0; l < b[j].size()-k+1; l++){
				res.push_back(b[j][l]);
			}
		}
		if(!res.empty()){
			sort(all(res));
			// for(int j = 0; j < res.size(); j++){
			// 	cout << res[j] << " ";
			// }printf("\n");
			if(res.size()>=q){
				ans = min(ans,res[q-1]-a[i]);
			}
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 384
#include<iostream>
using namespace std;
static const int MAX = 100;
static const int INFTY = (1<<21);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n, M[MAX][MAX];

void dijkstra() {
  int minv;
  int d[MAX], color[MAX];

  for(int i = 0; i < n; i++) {
    d[i] = INFTY;
    color[i] = WHITE;
  }

  d[0] = 0;
  color[0] = GRAY;
  while(1){
    minv = INFTY;
    int u = -1;
    for(int i = 0; i < n; i++) {
      if (minv > d[i] && color[i] != BLACK){
        u = i;
        minv = d[i];
      }
    }
    if ( u == -1) break;
    color[u] = BLACK;
    for(int v = 0; v < n; v++){
      if (color[v] != BLACK && M[u][v] != INFTY){
        if (d[v] > d[u] + M[u][v]) {
          d[v] = d[u] + M[u][v];
          color[v] = GRAY;
        }
      }
    }
  }

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

int main() {
  cin >> n;
  for ( int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      M[i][j] = INFTY;
    }
  }

  int k, c, u, v;
  for ( int i = 0; i < n; i++) {
    cin >> u >> k;
    for (int j = 0; j < k; j++) {
      cin >> v >> c;
      M[u][v] = c;
    }
  }
  dijkstra();
  return 0;
}

Measured memory_bytes: 3132
/*
Author:Jenil Mehta
Not yet serious but trying to be serious :)
Coding is lub
*/
 
#include <iostream>
#include <sstream>
#include <cstdio>
#include <climits>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
typedef long long int ll;
ll power(ll a, ll n) {ll p = 1;while (n > 0) {if(n%2) {p = p * a;} n >>= 1; a *= a;} return p;}
ll power(ll a, ll n, ll mod) {ll p = 1;while (n > 0) {if(n%2) {p = p * a; p %= mod;} n >>= 1; a *= a; a %= mod;} return p % mod;}
using namespace std;
int main()
{
    ll n;
    cin>>n;
    ll k;
    cin>>k;
    ll dp[n];
    ll a[n];
    ll i,j;
    ll ans=0;
    ll index=0;
    vector <ll> res;
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    dp[0]=0;
    dp[1]=abs(a[0]-a[1]);
    for(i=2;i<n;i++)
    {
        ans=INT_MAX;
        for(j=1;j<=min(i,k);j++)
        {
            dp[i]=min(ans,dp[i-j]+abs(a[i]-a[i-j]));   
            ans=dp[i];
        }
    }
    cout<<dp[n-1]<<endl;
}

Measured memory_bytes: 1792
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1186&lang=jp>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

int H,W;
vector<pair<int,pii>> rect;
void init(){
    for(int h = 1; h < 500; h++){
        for(int w = h+1; w < 500; w++){
            rect.push_back({h*h+w*w,{h,w}});
        }
    }
    sort(rect.begin(),rect.end());
}
void solve(){
    pair<int,pii> info = {H*H+W*W,{H,W}};
    auto p = upper_bound(rect.begin(),rect.end(),info)->second;
    cout << p.first << " " << p.second << endl;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    init();
    while(cin >> H >> W,H){
        solve();
    }
    return 0;
}



Measured memory_bytes: 4348
#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 n;
    cin>>n;
    vector<int> x(n);
    rep(i,n){
        cin>>x[i];
    }
    vector<int> co(100);
    rep(i,100){
        co[i] = 0;
    }
    rep(i,100){
        rep(j,n){
            co[i]+=(x[j]-i)*(x[j]-i);
        }
    }
    sort(co.begin(),co.end());
    cout<<co[0]<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
#include<iomanip>
#define rep(i, a, n) for(int i = a; i < n; i++)
using namespace std;
int main(){
  long long int a, b;
  cin >> a >> b;
  if(a == 1 || b == 1){
    cout << "1\n";
    return 0;
  }
  long long int c = a * b;
  if(c % 2 == 0){
    cout << c / 2 << "\n";
    return 0;
  }
  cout << c / 2 + 1 << "\n";
}


Measured memory_bytes: 3536
import java.math.BigInteger;
import java.util.Scanner;

public class Main {

	public static void main(String args[]){

		int MOD = 1000000007;

		Scanner sc = new Scanner(System.in);
		Long first_N = sc.nextLong();
		Long first_M = sc.nextLong();

		Long first_limit;

		if(first_N == 1){
			System.out.println((first_M+1)%MOD);
		}else{

			if((first_M+1)%(first_N-1) == 0){
				first_limit = (first_M+1)/(first_N-1)-1;
			}else{
				first_limit = (first_M+1)/(first_N-1);
			}

			if(first_limit <= 0){
				System.out.println((first_M+1)%MOD);
			}else{

				BigInteger bigMOD = BigInteger.valueOf(MOD);

				BigInteger limit = BigInteger.valueOf(first_limit);

				BigInteger A = BigInteger.valueOf(first_M+1);

				BigInteger B = BigInteger.valueOf(2*(first_M+1));
				B = B.multiply(limit);

				BigInteger C = BigInteger.valueOf(first_N-1);
				C = C.multiply(limit);
				C = C.multiply(BigInteger.valueOf(first_limit+1));

				A = A.add(B).subtract(C);

				System.out.println(A.remainder(bigMOD));

			}

		}


	}
}

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

#define int long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

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

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>
void print1(T begin, T end) {
  while (begin != end) {
    cout << (*begin) << " ";
    *begin++;
  }
  cout << endl;
}

template<typename T>
void print2(T Array, int height, int width) {
  for (int i = 0; i < height; i++) {
    for (int j = 0; j < width; j++) {
      cout << " " << Array[i][j];
    }
    cout << endl;
  }
}

void print() { std::cerr << endl; }
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  std::cerr << head << " ";
  print(std::forward<Tail>(tail)...);
}

template<class T>
void Add(T &a, const T &b, const T &mod=1000000007) {
  int val = ((a % mod) + (b % mod)) % mod;
  if (val < 0) { val += mod; }
  a = val;
}

template <typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); }

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

const int INF = 1e18;

signed main() {
  int n, m, q;
  cin >> n >> m >> q;
  vec<int> x(n), y(m);
  rep (i, n) { cin >> x[i]; }
  rep (i, m) { cin >> y[i]; }
  x.push_back(INF);
  x.push_back(-INF);
  y.push_back(INF);
  y.push_back(-INF);
  sort(all(x));
  sort(all(y));

  while (q--) {
    int u;
    cin >> u;
    int s[2];
    int t[2];
    s[0] = *lower_bound(all(x), u);
    s[1] = *prev(upper_bound(all(x), u));
    t[0] = *lower_bound(all(y), u);
    t[1] = *prev(upper_bound(all(y), u));

    int ans = 8e18;
    for (int i = 0; i < 2; i++) {
      for (int j = 0; j < 2; j++) {
        chmin(ans, abs(u - s[i]) + abs(s[i] - t[j]));
        chmin(ans, abs(u - t[j]) + abs(s[i] - t[j]));
      }
    }

    cout << ans << endl;
  }

  return 0;
}

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

typedef long long ll;

int n;
ll ans;

int main() {
	cin >> n;
	ll lim = 1;
	for (int i = 0; i < n; i++) {
		ll x; cin >> x;
		if (x == lim) {
			lim++;
			continue;
		}
		ll add = (x - 1) / lim;
		ans += add;
		if (x - add * lim == 1 && lim == 1) lim++;
	}	
	cout << ans;
}


Measured memory_bytes: 3600
#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
//using ll = long long;
using P = pair<int,int>;

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,a[100010],b[100010],c[100010],k = 0;
	vector<int> G[100010];
	cin >> n;
	for(int i = 0;i < n - 1;i++){
		cin >> a[i] >> b[i]; a[i]--;b[i]--;
		G[a[i]].push_back(i);
		G[b[i]].push_back(i);
		c[i] = -1;
	}
	for(int i = 0;i < n;i++) chmax(k,(int)G[i].size());
	for(int i = 0;i < n;i++){
		set<int> st;
		int cnt = 0;
		for(int e : G[i]){
			if(c[e] != -1){
				st.insert(c[e]);
			}
		}
		for(int e : G[i]){
			if(c[e] == -1){
				while(st.count(cnt)) cnt++;
				st.insert(cnt);
				c[e] = cnt++;
			}
		}
	}
	cout << k << endl;
	for(int i = 0;i < n - 1;i++) cout << c[i] + 1 << endl;
}


Measured memory_bytes: 9080
N = int(input())
p = list(map(int,input().split()))
sorted_p = sorted(p)
count = 0
if p != sorted_p:
    for i in range(N):
        if p[i] != sorted_p[i]:
            count += 1

ans = "YES" if count <= 2 else "NO"
print(ans)



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

using namespace std;

int main() {
	int n, m;
	scanf("%d %d", &n, &m);
	long long ans = 0;

	if (n > m) swap(n, m);

	if (n > 1) {
		ans = (long long) (n - 2) * (m - 2);
	} else {
		if (m == 1) {
			ans = 1;
		} else {
			ans = m - 2;
		}
	}



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

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>

int main() {
	int w; std::cin >> w;
	int W[w];
	for (int i=0; i<w; i++) W[i] = i+1;
	int n; std::cin >> n;
	int a, b, tmp;
	while (~scanf("%d,%d", &a, &b)) {
		tmp = W[a-1];
		W[a-1] = W[b-1];
		W[b-1] = tmp;
	}
	for (int i=0; i<w; i++) std::cout << W[i] << std::endl;
	return 0;
}


Measured memory_bytes: 3156
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		int total1 = 0, total2 = 0;
		long ans1 = 0, ans2 = 0;
		for(int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
			total1 += a[i];
			total2 += a[i];
			if(i % 2 == 0) {
				if(total1 >= 0) {
					ans1 += total1 + 1;
					total1 = -1;
				}
				if(total2 <= 0) {
					ans2 -= total2-1;
					total2 = 1;
				}
			}
			else {
				if(total2 >= 0) {
					ans2 += total2 +1;
					total2 = -1;
				}
				if(total1 <= 0) {
					ans1 -= total1-1;
					total1 = 1;
				}
			}
		}
		System.out.println(Math.min(ans1, ans2));
	}

}

Measured memory_bytes: 52164
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author yassin
 */

#include <bits/stdc++.h>

using namespace std;

constexpr int INF = 1'000'000'001;

class arc092_e {
private:
    vector<int> solve(set<int> &take, vector<int> &a) {
        vector<int> res;
        int n = a.size();
        vector<int> keep(n, 0);
        for (int i = 0; i < n; ++i) {
            keep[i] = take.count(i);
        }
        while (keep.size() > 1U) {
            int m = keep.size();
            if (!keep[m - 1]) {
                res.push_back(m);
                keep.pop_back();
            } else if (!keep[0]) {
                res.push_back(1);
                keep.erase(begin(keep));
            } else {
                for (int i = 1; i + 1 < m; ++i) {
                    if (keep[i - 1] && keep[i + 1]) {
                        keep[i - 1] = 1;
                        res.push_back(i + 1);
                        keep.erase(begin(keep) + i, begin(keep) + i + 2);
                        break;
                    } else if (!keep[i - 1] && !keep[i] && !keep[i + 1]) {
                        keep[i - 1] = 0;
                        res.push_back(i + 1);
                        keep.erase(begin(keep) + i, begin(keep) + i + 2);
                        break;
                    }
                }
            }
        }
        return res;
    }
public:
    void solve(istream& in, ostream& out) {
        int N;
        in >> N;
        vector<int> a(N);
        for (int i = 0; i < N; ++i) {
            in >> a[i];
        }
        set<int> take0, take1;
        for (int i = 0; i < N; ++i) {
            if (a[i] >= 0) {
                if (i % 2) take1.insert(i);
                else take0.insert(i);
            }
        }
        if (take0.empty()) {
            int mx = -INF, ind = -1;
            for (int i = 0; i < N; i += 2) {
                if (a[i] > mx) {
                    mx = a[i];
                    ind = i;
                }
            }
            take0.insert(ind);
        }
        if (take1.empty()) {
            int mx = -INF, ind = -1;
            for (int i = 1; i < N; i += 2) {
                if (a[i] > mx) {
                    mx = a[i];
                    ind = i;
                }
            }
            take1.insert(ind);
        }
        long long sum0 = 0, sum1 = 0;
        for (int i : take0) sum0 += a[i];
        for (int i : take1) sum1 += a[i];
        vector<int> res;
        if (sum0 >= sum1) {
            res = solve(take0, a);
        } else {
            res = solve(take1, a);
        }
        out << max(sum0, sum1) << "\n" << res.size() << "\n";
        for (int x : res) {
            out << x << "\n";
        }
    }
};

int main() {
	std::ios::sync_with_stdio(false); cin.tie(nullptr);
	arc092_e solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
def answer(R, G, B, N):
    r_count = N // R
    g_count = N // G
    ans = 0
    for i in range(r_count+1):
        for j in range(g_count+1):
            k = N - (R * i) - (G * j)
            if k < 0: continue
            if k % B == 0: ans += 1
    return ans  
    
R, G, B, N = map(int, input().split())
print(answer(R, G, B, N))

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

class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int l = sc.nextInt();
		List<Integer> list = new ArrayList<>();
		for (int i = 0; i < n; i++) {
			list.add(l);
			l++;
		}
		
		int min = Integer.MAX_VALUE;
		int index = 0;
		for (int i = 0; i < list.size(); i++) {
			if (min > Math.abs(list.get(i))) {
				min = Math.abs(list.get(i));
				index = i;
			}
		}
		
		list.remove(index);
		int sum = 0;
		for (Integer integer : list) {
			sum += integer;
		}
		
		System.out.println(sum);
	}
}

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

#define ll long long
#define rep(A,B,C) for(A=B;A<C;++A)
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////

ll N, M, K;
ll As[202020], Bs[202020];

ll i, j, k;

int main(){
    scanf("%lld%lld%lld", &N, &M, &K);
    
    rep(i,0,N){
        ll a;
        scanf("%lld", &a);
        As[i + 1] = As[i] + a;
    }
    rep(i,0,M){
        ll b;
        scanf("%lld", &b);
        Bs[i + 1] = Bs[i] + b;
    }
    ll ans = 0;
    j = M;
    rep(i,0,N+1){
        if(As[i]>K)
            break;
        while(j>0&&As[i]+Bs[j]>K){
            --j;
        }
        ans = max(ans, i + j);
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 6852
#include <cstdlib>
#include <iostream>
#include <sstream>
#include <string>
using namespace std;

int stoi(const string& s) {
	int res;
	istringstream is(s);
	is >> res;
	return res;
}

string s;

int factor(int, int);
int term(int, int);
int formula(int, int);

int factor(int l, int r) {
	if(s[l] == '(')
		return formula(l + 1, r - 1);

	return stoi(s.substr(l, r - l));
}

int term(int l, int r) {
	int cnt = 0;
	for(int i = r - 1; i >= l; --i) {
		if(s[i] == ')')
			++cnt;

		else if(s[i] == '(')
			--cnt;

		else if(!cnt) {
			if(s[i] == '*')
				return term(l, i) * factor(i + 1, r);

			else if(s[i] == '/')
				return term(l, i) / factor(i + 1, r);
		}
	}

	return factor(l, r);
}

int formula(int l, int r) {
	int cnt = 0;
	for(int i = r - 1; i >= l; --i) {
		if(s[i] == ')')
			++cnt;

		else if(s[i] == '(')
			--cnt;

		else if(!cnt) {
			if(s[i] == '+')
				return formula(l, i) + term(i + 1, r);

			else if(s[i] == '-')
				return formula(l, i) - term(i + 1, r);
		}
	}

	return term(l, r);
}

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

	int n;
	cin >> n;

	for(int i = 0; i < n; ++i) {
		cin >> s;
		cout << formula(0, s.size() - 1) << endl;
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1224
#include <bits/stdc++.h>
using namespace std;
 
#define ull unsigned long long
#define endl '\n'
#define ll long long
const int N = 2e5 + 5;
pair<ll,ll> x[N];
ll mx[N], st[N * 4], dp[N], sum[N];
set<pair<ll,ll>, greater<pair<ll,ll>>> s;
set<pair<ll,ll>> ok;
ll mod = 998244353;
bool cmp(pair<ll,ll> a, pair<ll,ll> b){
        return a.first < b.first;
}
void upd(ll k, ll l, ll r, ll x, ll val){
        if (x > r || x < l) return;
        if (l == r){
                st[k] = val;
                return;
        }
        ll mid = (l + r) >> 1;
        upd(k << 1, l, mid, x, val);
        upd(k << 1 | 1, mid + 1, r, x, val);
        st[k] = max(st[k << 1 | 1], st[k << 1]);
}
ll get(ll k, ll l, ll r, ll x, ll y){
        if (x > r || y < l) return -1e18;
        if (x <= l && y >= r) return st[k];
        ll mid = (l + r) >> 1;
        return max(get(k << 1, l, mid, x, y), get(k << 1 | 1, mid + 1, r, x, y));
}
int main(){
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
        //freopen("test.txt", "r", stdin);
        ll n;
        cin >> n;
        for (int i = 1; i <= n; i++){
                cin >> x[i].first >> x[i].second;
        }
        sort(x + 1, x + n + 1, cmp);
        for (int i = 1; i <= n; i++){
                upd(1, 1, n, i, x[i].first + x[i].second);
                s.insert({x[i].first, i});
                ok.insert({x[i].first, i});
        }
        ok.insert({1e18, n + 1});
        dp[n + 1] = 0;
        sum[n + 1] = 0;
        ll ans = 0;
        for (int i = n; i >= 1; i--){
                auto it = s.lower_bound({x[i].first + x[i].second - 1, 1e18});
                ll cur = get(1, 1, n, i, (*it).second);
                upd(1, 1, n, i, cur);
                auto it2 = ok.lower_bound({cur, -1e18});
                dp[i] = (sum[(*it2).second] + 1) % mod;
                sum[i] = (sum[i + 1] + dp[i]) % mod;
        }
        for (int i = 1; i <= n; i++){
                ans += dp[i];
                ans %= mod;
        }
        cout << ans + 1;
}
/*
3
1 1
5 1
9 1
*/

Measured memory_bytes: 37248
#include <stdio.h>
int main(void){
	int a,b,c,d;
	scanf("%d",&a);
	b=a/3600;
	a-=b*3600;
	c=a/60;
	a-=c*60;
	d=a;
	printf("%d:%d:%d\n",b,c,d);
	return 0;
}

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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a*b/gcd(a, b);
}

int main()
{
    cout << fixed << setprecision(15);
    ll A, B;
    cin >> A >> B;

    if(A%2==1 && B%2==1){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256