akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;

class Procon
{
    public Procon() { }
    static void Main(string[] agrs)
    {
        new Procon().Do();
    }

    Scanner cin;

    public void Do()
    {
        cin = new Scanner();
        int N = cin.nextInt();
        int K = cin.nextInt();

        var a = new List<int>();
        var b = new List<int>();
        a.Add(0);
        b.Add(0);
        for (int i = 0; i < N; i++)
        {
            int x = cin.nextInt();
            if (x > 0)
            {
                a.Add(x);
            }
            else
            {
                b.Add(-x);
            }
        }

        a.Sort();
        b.Sort();
        int min = 1000000001;

        for (int i = 0; i <= K; i++)
        {
            if (a.Count() > i && b.Count() > K - i)
            {
                min = Math.Min(2 * a[i] + b[K - i], min);
            }
        }

        for (int i = 0; i <= K; i++)
        {
            if (b.Count() > i && a.Count() > K - i)
            {
                min = Math.Min(2 * b[i] + a[K - i], min);
            }
        }

        Console.WriteLine(min);
    }
}

class Scanner
{
    string[] s;
    int i;
    int max_i;

    public Scanner()
    {
        s = new string[0];
        max_i = 0;
        i = 0;
    }

    public string nextString()
    {
        if (i >= s.Length)
        {
            s = Console.ReadLine().Split(' ');
            max_i = s.Length;
            i = 0;
            if (max_i == 0)
            {
                return "";
            }
            return s[i++];
        }
        else
        {
            return s[i++];
        }
    }

    public int nextInt()
    {
        return int.Parse(nextString());
    }


    public long nextLong()
    {
        return long.Parse(nextString());
    }

    public double nextDouble()
    {
        return double.Parse(nextString());
    }

    public string[] arrayString()
    {
        return Console.ReadLine().Split(' ');
    }

    public int[] arrayInt()
    {
        string[] str = Console.ReadLine().Split(' ');
        int[] array = new int[str.Length];
        for (int i = 0; i < str.Length; i++)
        {
            array[i] = int.Parse(str[i]);
        }
        return array;
    }

    public long[] arrayLong()
    {
        string[] str = Console.ReadLine().Split(' ');
        long[] array = new long[str.Length];
        for (int i = 0; i < str.Length; i++)
        {
            array[i] = long.Parse(str[i]);
        }
        return array;
    }

    public double[] arrayDouble()
    {
        string[] str = Console.ReadLine().Split(' ');
        double[] array = new double[str.Length];
        for (int i = 0; i < str.Length; i++)
        {
            array[i] = double.Parse(str[i]);
        }
        return array;
    }
}


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


int main(){
    ll n,a,b,c;cin>>n>>a>>b>>c;
    string s[100010];
    rep(i,0,n)cin>>s[i];
    char an[100010];
    int ok=1;
    rep(i,0,n-1){
        if(a<0||b<0||c<0)ok=0;
        if(s[i]=="AB"&&a*b==1&&c==0){
            if(s[i+1]=="AC"){
                a++;b--;
                an[i]='A';
            }
            else{
                b++;a--;
                an[i]='B';
            }
        }
        else if(s[i]=="AC"&&a*c==1&&b==0){
            if(s[i+1]=="AB"){
                a++;c--;
                an[i]='A';
            }
            else{
                c++;a--;
                an[i]='C';
            }
        }
        else if(s[i]=="BC"&&c*b==1&&a==0){
            if(s[i+1]=="AC"){
                c++;b--;
                an[i]='C';
            }
            else{
                b++;c--;
                an[i]='B';
            }
        }
        else if(s[i]=="AB"&&a>=b){
            a--;b++;
            an[i]='B';
        }
        else if(s[i]=="AB"&&a<b){
            a++;b--;
            an[i]='A';
        }
        else if(s[i]=="AC"&&a>=c){
            a--;c++;
            an[i]='C';
        }
        else if(s[i]=="AC"&&a<c){
            a++;c--;
            an[i]='A';
        }
        else if(s[i]=="BC"&&b>=c){
            b--;c++;
            an[i]='C';
        }
        else if(s[i]=="BC"&&b<c){
            b++;c--;
            an[i]='B';
        }
    }
    rep(i,n-1,n){
        if(a<0||b<0||c<0)ok=0;
        if(s[i]=="AB"&&a>=b){
            a--;b++;
            an[i]='B';
        }
        else if(s[i]=="AB"&&a<b){
            a++;b--;
            an[i]='A';
        }
        else if(s[i]=="AC"&&a>=c){
            a--;c++;
            an[i]='C';
        }
        else if(s[i]=="AC"&&a<c){
            a++;c--;
            an[i]='A';
        }
        else if(s[i]=="BC"&&b>=c){
            b--;c++;
            an[i]='C';
        }
        else if(s[i]=="BC"&&b<c){
            b++;c--;
            an[i]='B';
        }
        
    }
    if(a<0||b<0||c<0)ok=0;
    if(ok){
        cout<<"Yes"<<endl;
        rep(i,0,n)cout<<an[i]<<endl;
    }
    else cout<<"No"<<endl;
}

    









Measured memory_bytes: 6856
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;


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

    vector<int> nums;
    if(s[0] == '0') nums.push_back(0);
    
    for(int i = 0; i < n;){
        int j = i;
        while(j < n && s[j] == s[i]) j++;
        nums.push_back(j - i);
        i = j;
    }
    
    if(s.back() == '0') nums.push_back(0);

    int nl = nums.size();
    vector<int> sums(nl + 1, 0);
    for(int i = 0; i < nl; i++)
        sums[i+1] = sums[i] + nums[i];

    int sl = sums.size();
    int res = 0;
    for(int left = 0; left < sl; left += 2){
        int right = left + 2*k+1;
        if(right >= sl) right = sl - 1;
        res = max(res, sums[right] - sums[left]);
    }
    cout << res << endl;
}


Measured memory_bytes: 1272
#include <stdio.h>
int main(void) {
  int n[100000], x[100000], cnt[100000] = {0};
  int i, j, k, l, num;

  num = 0;
  do {
    scanf("%d %d", &n[num], &x[num]);
    num++;
  } while (!(n[num - 1] == 0 && x[num - 1] == 0));

  i = 1;
  j = 2;
  k = 3;
  for (l = 0; l < num; l++) {
    for (i = 1; i < j; i++) {
      for (j = 2; j < k; j++) {
        for (k = 3; k <= n[l]; k++) {
          if (i + j + k == x[l]) {
            if (i < j && j < k) {
              // printf("%d + %d + %d == %d\n", i, j, k, x);
              cnt[l]++;
            }
          }
        }
      }
    }
  }

  for (i = 0; i < num - 1; i++)
    printf("%d\n", cnt[i]);
  return 0;
}

Measured memory_bytes: 1436
import java.util.*;
public class Main {
  static int mod = 1_000_000_007;
  public static void main(String[] args) { 
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      long[] arr = new long[n];
      for(int i = 0; i < n; i++)
        arr[i] = sc.nextLong();
      long[] kCnt = new long[60];
      for(long num : arr) {
        int digit = 0;
        while((num >> digit) > 0) {
          if(((num >> digit) & 1) == 1)
            kCnt[digit]++;
          digit++;
        }
      }
      
      long res = 0L;
      for(int i = 0; i < kCnt.length; i++)
        res = (res + (kCnt[i] * (n - kCnt[i]) % mod) * modPow(2, i)) % mod;
      System.out.println(res);
  }

  private static long modPow(int a, int b) {
    if(b == 0) return 1;
    if(b == 1) return a;
    long res = modPow(a, b/2) % mod;
    if(b % 2 == 0)
      return res * res % mod;
    return (res * res % mod) * a % mod; 
  }
}

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

 

int main(){
  int S,W;
  cin>>S>>W;
  if(W>=1&&W<=100&&S>=1&&S<=100)
  if(W>=S){
      cout<<"unsafe";
  }
  else{
      cout<<"safe";
  }
    return 0;
}

Measured memory_bytes: 3572
n=int(input())
s = [input()for i in range(n)]

cnta = 0
cntb = 0
isok = False
cnt = 0


for i in range(n):
    if s[i][0] == 'B' and s[i][-1] =='A':
        cnta+=1
        cntb+=1
    elif s[i][0] =='B':
        cntb+=1
        isok = True
    elif s[i][-1] =='A':
        cnta+=1
        isok=True
    for j in range(len(s[i])-1):
        if s[i][j] =='A' and s[i][j+1] == 'B':
            cnt += 1


if isok:
    print(min(cnta,cntb)+cnt)
else:
    print(max(cnta-1,0)+cnt)    

Measured memory_bytes: 3700
#include <cstdio>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);++i)
inline char tc(){
  static char fl[100],*A=fl,*B=fl;
  return A==B&&(B=(A=fl)+fread(fl,1,100,stdin),A==B)?EOF:*A++;  
}
inline int read(){
  int a=0;static char c;
  while((c=tc())<48||c>57);
  while(c>=48&&c<=57)a=a*10+c-48,c=tc();
  return a;
}
int h[100001];
int main(){
  int n=read(),a=read(),b=read();a-=b;
  double a_=1.0/a;
  rep(i,n)h[i]=read();
  int left=0,right=1000000000;
  ll temp,cnt=0,mid;
  while (right>left+1) {
    mid=(right+left)>>1;
    cnt=0;
    rep(i,n){
      temp=h[i]-b*mid+a-1;
      if(temp>0)cnt+=temp*a_;
    }
    if(cnt<=mid)right=mid;
    else left=mid;
  }
  printf("%d\n",right);
}

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

using namespace std;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    int arr[n+1]{0}, a, b;
    for(int i = 0; i < m; i++) {
        cin >> a >> b;
        arr[a]++;
        arr[b]++;
    }
    for(int i = 1 ; i <= n; i++) cout << arr[i] << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<vector>
#include<queue>
#include<list>
#include<stack>
#include<algorithm>
#include<cmath>
#include<memory>

using namespace std;

int main()
{
  char ball, c1, c2, c;

  ball = 'A';
  
  while ( cin >> c1 >> c >> c2 )
    {
      if ( c1 == ball )
        ball = c2;
      else if ( c2 == ball )
        ball = c1;
    }

  cout << ball << endl;
  
  return 0;
}

Measured memory_bytes: 1132
x = gets
y = x.split
z = []

# unless (1 <= y[0].to_i || y[0].to_i <= 10000) ||
#       (1 <= y[1].to_i || y[1].to_i <= 10000)||
#       (1 <= y[2].to_i || y[2].to_i <= 10000)
# return
for w in 0 ... 2 do
  unless (1 <= y[w].to_i || y[w].to_i <= 10000)
    return
  end
end

if y[0].to_i <= y[1].to_i

  if y[0].to_i <= y[2].to_i
    z[0] = y[0]
    if y[1].to_i <= y[2].to_i
      z[1] = y[1]
      z[2] = y[2]
    else
      z[1] = y[2]
      z[2] = y[1]
    end
  end

elsif y[0].to_i <= y[2].to_i
  z[0] = y[1]
  z[1] = y[0]
  z[2] = y[2]
elsif y[1].to_i <= y[2].to_i
  z[0] = y[1]
  z[1] = y[2]
  z[2] = y[0]
else
  z[0] = y[2]
  z[1] = y[1]
  z[2] = y[0]
end

puts z[0].to_s + " " + z[1].to_s + " " + z[2].to_s


Measured memory_bytes: 6876
#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline") //Optimization flags
#pragma GCC option("arch=native","tune=native","no-zero-upper") //Enable AVX
#pragma GCC target("avx2")  //Enable AVX
#include<bits/stdc++.h>
using namespace std;
#define int ll
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define ll long long
#define vi vector<int>
#define pi pair<int,int>
#define mp make_pair
 
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
 
const int mod=998244353;
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
int mul(int a,int b)
{
	return ((a)*1ll*(b))%mod;
}
 
void add(int &a,int b)
{
	a+=b;
	if(a>=mod)a-=mod;
}
 
int sub(int a,int b){
	a-=b;
	if(a<0){
		a+=mod;
	}
	return a;
}
 
int powz(int a,int b)
{
	int res=1;
	while(b)
	{
		if(b&1){
			res=mul(res,a);
		}
		b/=2;
		a=mul(a,a);
	}
	return res;
}
 
template <typename A, typename B>
istream& operator>>(istream& input,pair<A,B>& x) {
	input>>x.F>>x.S;
	return input;
}
 
template <typename A>
istream& operator>>(istream& input,vector<A>& x) {
	for(auto& i:x)
		input>>i;
	return input;
}
 
template<typename A>
ostream& operator<<(ostream& output,vector<A>& x) {
	for(auto& i:x)
		output<<i<<' ';
	return output;
}
 
const int N=1000002;

void solve(){
	int k,x;
	cin>>k>>x;
	if(k*500>=x){
		cout<<"Yes";
	}
	else{
		cout<<"No";
	}
}

signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int tc=1;
	//~ cin>>tc;
	for(int _=0;_<tc;_++){
		//~ cout<<"Case #"<<_+1<<": ";
		solve();
		if(_!=tc-1)
		cout<<"\n";
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(a,n) for (ll a = 0; a < (n); ++a)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<vector<ll> > Graph;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1e18;


int main(){
    int n;
    string s;
    cin >> n >> s;
    int cnt = 0;
    string l = "";
    string r = "";
    rep(i,n){
        if(s[i]=='(')cnt++;
        else cnt--;
        if(cnt==-1){
            l+='(';
            cnt=0;
        }
    }
    rep(i,cnt)r+=')';
    string ans = l + s + r;
    cout << ans << endl;
    return 0;
}


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

#define MOD (1000000000+7)
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) x.begin(), x.end()
#define print(vec,l,r) for(int i = l; i <= r; i++) cout << vec[i] <<" "; cout << endl;
#define forf(i,a,b) for(int i = (a); i < (b); i++)
#define forr(i,a,b) for(int i = (a); i > (b); i--)
// template starts
typedef long long int ll;
ll fact(ll n, ll p){
	ll ans = 1;
	for(ll i = 1; i <= n; i++){
		ans *= i;
		ans %= p;
	}
	return ans;
}
ll power(ll x, ll n, ll p){
	ll res = 1;
	if(n == 1) return x%p;
	if(n%2 == 1) res = x%p;

	ll temp = power(x,n/2,p);
	return res*((temp*temp)%p)%p;
}
ll inv(ll a, ll p){
	return power(a,p-2,p);
}
ll nCr(ll n, ll r, ll p){
	if(r > n) return 0;
	ll t1 = fact(n,p);
	ll t2 = inv(fact(r,p),p);
	ll t3 = inv(fact(n-r,p),p);

	return (((t1*t2)%p)*t3)%p;
}
vector<vector<ll> > multiply(vector<vector<ll> > &a, vector<vector<ll> > &b, ll p){
	int r1,c1,r2,c2;
	r1 = a.size(); c1 = a[0].size();
	r2 = b.size(); c2 = b[0].size();

	vector<vector<ll> > result(r1,vector<ll>(c2,0));

	if(c1 != r2) return result;

	for(int i = 0; i < r1; i++){
		for(int j = 0; j < c2; j++){
			for(int k = 0; k < c1; k++){
				result[i][j] += a[i][k]*b[k][j];
				result[i][j] %= p;
			}
		}
	}
	return result;
}

vector<vector<ll> > power(vector<vector<ll> >&a,ll n, ll p){
	int r = a.size();
	vector<vector<ll> > result(r,vector<ll>(r,0));
	for(int i = 0; i < r; i++) result[i][i] = 1;

	while(n > 0){
		if(n%2 == 1){
			result = multiply(result,a,p);
		}
		n /= 2;
		a = multiply(a,a,p);
	}
	return result;
}
// template ends here

void solve(){
	// code starts from here
	ll N, K;
	cin >> N >> K;
	
	ll temp = N/K;
	N = N - temp*K;
	if(2*N >= K) cout << K-N << endl;
	else cout << N << endl;
}

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

	int T;
	//cin >> T;
	 T = 1;
	while(T--){
		solve();
	}

	return 0;
}


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

//#define int long long
#define MOD 1000000007

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()
#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
template <typename T>
void print(T x)
{
    std::cout << x << '\n';
}
typedef long long ll;

signed main()
{
    int n;
    cin >> n;
    vector<int> a(n - 1);
    rep(i, n - 1)
    {
        cin >> a[i];
    }

    unordered_map<int, int> ans;
    rep(i, n - 1)
    {
        ans[a[i] - 1]++;
    }

    rep(i, n)
    {
        cout << ans[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 12208
#include<iostream>
#include<string>
#include<algorithm>	
#include<cmath>
using namespace std;
int main() {
	long long n, a, sum = 0; cin >> n; int test[100001] = { 0 };
	for (int h = 1; h <= n; h++) {
		cin >> a; test[h] = a;
	}
	for (int h = 0; h <= n; h++) {
		sum += abs(test[h] - test[h + 1]);
	}
	for (int h = 1; h <= n; h++) {
		if (test[h - 1] <= test[h] && test[h] <= test[h + 1]) {
			cout << sum << endl;
		}
		else if (test[h - 1] >= test[h] && test[h] >= test[h + 1]) {
			cout << sum << endl;
		}
		else {
			cout << sum - abs(test[h] - test[h + 1]) - abs(test[h - 1] - test[h]) + abs(test[h - 1] - test[h + 1]) << endl;
		}
	}
	cin >> n;
}

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

int main() {
  int N, Y;
  cin >> N >> Y;
  int a = -1, b = -1, c = -1;
  for (int x = 0; x <= N; ++x) {
    for (int y = 0; y <= N - x; ++y) {
      int z = N - x - y;
      int total = 10000 * x + 5000 * y + 1000 * z;
      if (total == Y) {
        a = x;
        b = y;
        c = z;
      }
    }
  }
  cout << a << " " << b << " " <<  c << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <queue>
#include <cmath>
#include <limits>
#include <stack>

using namespace std;

int main(){
  long N,tmp;
  vector<long> a,b,c;
  long s[100005];
  long count = 0;
  cin >> N;
  for(int i=0;i<N;++i){
    cin >> tmp;
    a.push_back(tmp);
  }
  for(int i=0;i<N;++i){
    cin >> tmp;
    b.push_back(tmp);
  }
  for(int i=0;i<N;++i){
    cin >> tmp;
    c.push_back(tmp);
  }
  sort(a.begin(),a.end());
  sort(b.begin(),b.end());
  sort(c.begin(),c.end());
  for(int i=0;i<N;++i){
    vector<long>::iterator it1 = lower_bound(a.begin(),a.end(),b[i]);
    vector<long>::iterator it2 = upper_bound(c.begin(),c.end(),b[i]);
    count += (it1-a.begin())*(c.end()-it2);
  }
  cout << count << endl;
}


Measured memory_bytes: 3444
#include <stdio.h>

int main()
{
	int A, B, C;
	scanf("%d%d%d", &A, &B, &C);
	if(A==B && B==C && C==A)
	{
		printf("No");
	}
	else if(A==B || B==C || C==A)
	{
		printf("Yes");
	}
	else
	{
		printf("No");
	}
	return 0;
}

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

typedef long long ll;


#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
#define LINF 1e18


vector<int> dx{1,0,-1,0};
vector<int> dy{0,1,0,-1};

struct Coord{
    int x1,y1,x2,y2;
};

int main() {
    int H,W; cin >> H >> W;
    vector<vector<int>> A(H+2, vector<int>(W+2,0));
    REP(i,H){
        REP(j,W){
            cin >> A[i+1][j+1];
        }
    }

    vector<Coord> ans;

    FOR(i,1,H+1){
        FOR(j,1,W+1){
            if(A[i][j]%2 == 1){
                REP(n,4){
                    if(A[i+dy[n]][j+dx[n]]%2 == 1){
                        A[i+dy[n]][j+dx[n]]++;
                        A[i][j]--;
                        ans.push_back({i,j,i+dy[n],j+dx[n]});
                        break;
                    }else if(A[i+dy[n]][j+dx[n]]%2==0 && n==3){
                        if(i!=H){
                            A[i+1][j]++;
                            A[i][j]--;
                            ans.push_back({i,j,i+1,j});
                        }else if(i==H && j!=W){
                            A[i][j+1]++;
                            A[i][j]--;
                            ans.push_back({i,j,i,j+1});
                        }else if(i==H && j==W){
                            continue;
                        }
                    }
                }
            }
        }
    }

    cout << ans.size() << endl;
    REP(i,ans.size()){
        cout << ans[i].x1 << " " << ans[i].y1 << " " << ans[i].x2 << " " << ans[i].y2 << endl;
    }


    return 0;
}

Measured memory_bytes: 6364
#include <iostream>
#include <vector>

using namespace std;

const int inf = 10000;

int main() {
  int h, w;
  cin >> h >> w;

  vector<vector<char>> vec(h + 2, vector<char>(w + 2, '#'));
  for (int x = 1; x <= h; ++x)
    for (int y = 1; y <= w; ++y)
      cin >> vec[x][y];

  vector<vector<int>> ans((h + 2) * (w + 2), vector<int>((h + 2) * (w + 2), inf));

  for (int x = 1; x <= h; ++x) {
    for (int y = 1; y <= w; ++y) {
      for (int d = 0; d < 4; ++d) {
        int dx = vector<int>({0, 0, -1, 1})[d];
        int dy = vector<int>({-1, 1, 0, 0})[d];
        int idx1 = (x) * (w + 2) + (y);
        int idx2 = (x + dx) * (w + 2) + (y + dy);
        if (vec[x][y] == '.' && vec[x + dx][y + dy] == '.')
          ans[idx1][idx2] = ans[idx2][idx1] = 1;
        ans[idx1][idx1] = 0;
      }
    }
  }

  for (int k = 1; k < (h + 2) * (w + 2); ++k) {
    for (int i = 1; i < (h + 2) * (w + 2); ++i) {
      for (int j = 1; j < (h + 2) * (w + 2); ++j) {
        int x1 = i / (w + 2);
        int y1 = i % (w + 2);
        int xm = k / (w + 2);
        int ym = k % (w + 2);
        int x2 = j / (w + 2);
        int y2 = j % (w + 2);
        int idx1 = x1 * (w + 2) + y1;
        int idxm = xm * (w + 2) + ym;
        int idx2 = x2 * (w + 2) + y2;
        if (ans[idx1][idxm] + ans[idxm][idx2] < ans[idx1][idx2])
          ans[idx1][idx2] = ans[idx2][idx1] = ans[idx1][idxm] + ans[idxm][idx2];
      }
    }
  }

  int vmax = 0;
  for (auto &seq : ans) {
    for (auto &v : seq) {
      if (v < inf && vmax < v)
        vmax = v;
    }
  }

  cout << vmax << endl;
}

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


int main() {
  vector<vector<int>> bingo(3, vector<int>(3));
  for(int i = 0; i < 3; i++){
    for(int j = 0; j < 3; j++){
      cin >> bingo.at(i).at(j);
    }
  }
  int N;
  cin >> N;
  vector<int> choice(N);
  for(int i = 0; i < N; i++){
    cin >> choice.at(i);
  }
  
  vector<vector<int>> hav(3, vector<int>(3));
  
  for(int i = 0; i < N; i++){
    for(int j = 0; j < 3; j++){
    for(int k = 0; k < 3; k++){
      if(bingo.at(j).at(k) == choice.at(i)){
        hav.at(j).at(k) = 1;
      }
    }
    }
  }
    
  bool have = false;
  
  for(int i = 0; i < 3; i++){
    if(hav.at(i).at(0) == 1 && hav.at(i).at(0) == hav.at(i).at(1) && hav.at(i).at(2) == hav.at(i).at(1)){
      have = true;
    }
    if(hav.at(0).at(i) == 1 && hav.at(0).at(i) == hav.at(1).at(i) && hav.at(0).at(i) == hav.at(2).at(i)){
      have = true;
    }
     
    }
 
  if(hav.at(0).at(0) == 1 && hav.at(1).at(1) == hav.at(2).at(2) && hav.at(1).at(1) == hav.at(0).at(0)){
      have = true;
    }
  
  if(hav.at(1).at(1) == 1 && hav.at(2).at(0) == hav.at(1).at(1) && hav.at(0).at(2) == hav.at(1).at(1)){
      have = true;
    }
  
  
  if(have){
    cout << "Yes";
  }
  else{
    cout << "No";
  }


  return 0;
}

Measured memory_bytes: 256
<?php
	$n=fgets(STDIN);
	$t=explode(' ',fgets(STDIN));
	for($i=0;$i<$n;$i++)$s+=$t[$i];
	$m=fgets(STDIN);
	for($i=0;$i<$m;$i++)
	{
		fscanf(STDIN,"%d%d",$d,$u);
		echo $s-$t[$d-1]+$u,"\n";
	}


Measured memory_bytes: 4084
N = int(input())
XL =[list(map(int, input().split())) for _ in range(N)]
LR = [[XL[i][0] - XL[i][1], XL[i][0] + XL[i][1]] for i in range(N)]
LR.sort(key = lambda x: x[1])

cp = LR[0][1]

ans = 0

for i in range(1,N):
	if LR[i][0] < cp:
		ans += 1
	else:
		cp = LR[i][1]
print(N-ans)

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

int main() {
	int N;
	cin >> N;
	int ans = 1;
	for (int i = 0; i < N; i++) {
		int A;
		cin >> A;
		ans *= (A % 2 == 0 ? 2 : 1);
	}
	cout << (int)pow(3, N) - ans << endl;
}

Measured memory_bytes: 384
def main():
  N = int(input())
  S = list(str(input()))
  num_1 = 0
  num_2 = 0
  for i in range(N):
    if S[i] == '(':
      num_1 += 1
    else:
      if num_1 > 0: num_1 -= 1
  for i in range(N-1, -1, -1):
    if S[i] == ')':
      num_2 += 1
    else:
      if num_2 > 0: num_2-=1
  for i in range(num_1):
    S.append(')')
  for i in range(num_2):
    S.insert(0, '(')
  print(''.join(S))

if __name__ == "__main__":
  main()

Measured memory_bytes: 3064
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define PI 3.14159265358979323

//void quick(int *,long long,long long);
//int comp(char *a,char *b);

int main(){
	
	int i,j;
	
	scanf("%d",&i);
	j=100000;
	while(i>0){
		j=(float)j*1.05-0.1;
		j=(j/1000+1)*1000;
		i--;
	}
	printf("%d\n",j);
	//for(i=0;i<=1000000000;i++);
	return 0;
}

Measured memory_bytes: 592
#include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;

#define int long long int
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define rep(i,a,b) for (int i = a; i < b; ++i)
#define IOS ios::sync_with_stdio(false); cin.tie(NULL);
#ifndef LOCAL
#define dbg(...) ;
#define endl '\n'
#endif

const int inf = 1e15;
const int MOD = 1e9 + 7;
const int N = 2e5 + 5;



signed main(){
    IOS;
    set<int> s;
    int n;
    cin >> n;
    int m = n - 1;
    for (int i = 1; i <= sqrt(m); i++) {
    	if (m % i == 0) {
    		s.insert(i);
    		s.insert(m/i);
    	}
    }
    s.insert(n);
    m = n;
    vector<int> fact;
    for (int i = 2; i <= sqrt(m); i++) {
    	if (m % i == 0) {
    		int t = m;
    		while (t % i == 0)
    			t /= i;
    		t %= i;
    		if (t == 1) s.insert(i);
    		int j = m / i;
    		t = m;
    		while (t % j == 0)
    			t /= j;
    		if (t == 1) s.insert(j);
    	}
    }
    s.erase(1);
    cout << s.size() << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#include <ctype.h>

int main (void)
{
	int n, d;
	scanf("%d %d",&n, &d);
	int x = 0;
	if (n%(2*d+1) != 0)
		x = 1;
	printf("%d\n",(n/(2*d+1))+x);
	return(0);
}


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

void swap (int *p ,int *q){
    int tmp;
    tmp = *p;
    *p = *q;
    *q = tmp;
}

int main(){
    int a, b, c;
    std::cin >> a>> b >> c;
    swap(a,b);
    swap(a,c);
    std::cout << a << " " << b << " " << c <<endl;
}

Measured memory_bytes: 256
use text_io::*;
use std::collections::*;
use std::process::exit;

fn main() {
    let mut n:usize = read!();
    let mut m:usize = read!();
    let mut wa = vec![0; n];
    let mut ac = vec![0; n];
    let mut ss = 0;
    let mut pp = 0;
    for _ in 0..m {
        let mut p:usize = read!();
        let s:String = read!();
        p -= 1;
        if ac[p] == 0 {
            if s == "AC" {
                ac[p] = 1;
                ss += 1;
                pp += wa[p];
            } else {
                wa[p] += 1;
            }
        }
    }
    println!("{} {}", ss, pp);
}


Measured memory_bytes: 2708
# define _CRT_SECURE_NO_WARNINGS 1
# define _USE_MATH_DEFINES
# include <iostream>
# include <numeric>
# include <string>
# include <bitset>
# include <vector>
# include <algorithm>
# include <cstdlib>
# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iomanip>
# include <queue>
# include <sstream>
# include <climits>
# include <complex>
# include <cmath>
# include <list>
# include <functional>
# include <string>
# include <ctime>
# include <set>
# include <forward_list>
# include <map>
# include <stack>
using namespace std;
# define INF ((int)(1<<25))
# define REP(i,n) for(int i=0;i<(int)n;i++)
# define FOR(i,n) REP(i,n)
# define FORI(i,k,n) for(int i=k;i<(int)n;i++)
# define TORAD 2.0*M_PI/360.0
# define INT(x) int x;cin>>x;
# define ALL(x) begin(x),end(x)
# define RALL(x) (x).rbegin(),(x).rend()
# define DEBUG(x) cout<<#x<<":"<<x<<endl;
# define EPS 1e-12
#ifdef _MSC_VER
#include <intrin.h>
#define __builtin_popcount __popcnt
#endif
typedef long long lint;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
const int dx[4] = { 0, 1, 0, -1 }, dy[4] = { -1, 0, 1, 0 };
template<class T> void debug(T a) { for (auto i : a)cout << i << endl; }


int main()
{
	while (true)
	{
		int b, r, g, c, s, t;
		cin >> b >> r >> g >> c >> s >> t;
		if (t == 0)break;
		int ans = 100 - (t - b * 5 - r * 3-s) * 3 - (b * 5 + r * 3) * 2 + b * 5 * 15 + b * 15 + r * 3 * 15 + r * 15 + g * 7 + c * 2;
		cout << ans << endl;
	}
}

Measured memory_bytes: 2984
#include <stdio.h>

int Selectionsort(int *, int);

int main(){
  int a[100],n,i,s;

   scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }

  s=Selectionsort(a,n);
  
  for(i=0;i<n;i++){
    printf("%d",a[i]);
    if(i<n-1){
      printf(" ");
    }
  }
    printf("\n");
  printf("%d\n",s);
  
  return 0;
  
}

int Selectionsort(int *a, int n){

  int i,j,count=0,minj,t;

  for(i=0;i<n-1;i++){
    minj=i;
    for(j=i;j<n;j++){
      if(a[j]<a[minj]){
	minj=j;
      }
    }
    t=a[i];
    a[i]=a[minj];
    a[minj]=t;
    if(i!=minj) count++;
  }
  return count;
}
  



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

#pragma GCC optimize ("O2")
#pragma GCC optimize ("tree-vectorize")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define FFOR(i, a, b) FOR(i, a, b+1)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) FOR(i, 1, n+1)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define LEN(x) (int)(x).size()
#define DUMP(x) cerr<<__LINE__<<' '<<#x<<"="<<(x)<<endl;
#define pb push_back
#define eb emplace_back
#define mp make_pair

using namespace std;
using lint = long long;
using pii =  pair<int, int>;
using pll =  pair<lint, lint>;
template <typename T> using vc = vector<T>;
template <typename T> using vvc = vector<vector<T>>;
template <typename T> inline bool chmax(T &a, T b){if(a<b){a = b; return true;} return false;}
template <typename T> inline bool chmin(T &a, T b){if(a>b){a = b; return true;} return false;}

constexpr lint ten(int n) {return n==0 ? 1 : ten(n-1)*10;}

class DPowerfulDiscountTickets {
public:
    void solve(std::istream& in, std::ostream& out){
        ios_base::sync_with_stdio(false);
        in.tie(nullptr), out.tie(nullptr);
        int N, M;
        in>>N>>M;
        priority_queue<int> pq;
        REP(i, N){
            int a;
            in>>a;
            pq.push(a);
        }
        REP(i, M){
            int p = pq.top();
            pq.pop();
            pq.push(p/2);
        }
        lint ans = 0;
        while(not pq.empty()){
            ans += pq.top();
            pq.pop();
        }
        out<<ans<<'\n';
    }
};


int main() {
	DPowerfulDiscountTickets solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 3812
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}
 
ll nCr(ll n, ll r){
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
 
//-----------------------ここから-----------
ll dp[100100][2] = {0};

int main(void){
    string l;
    cin >> l;

    dp[0][0] = 1;

    for(int i = 0; i < l.size(); i++){
        int now = l[i] - '0';
        for(int j = 0; j < 2; j++){
            if(j == 1){
                dp[i + 1][j] += dp[i][j] * 3;
            } else {
                if(now == 0){
                    dp[i + 1][0] += dp[i][j];
                } else {
                    dp[i + 1][0] += dp[i][j] * 2;
                    dp[i + 1][1] += dp[i][j];
                }
            }
            dp[i + 1][j] %= MOD;
            //cout << i + 1 << " " << j << " " << dp[i + 1][j] << endl;
        }
    }

    cout << (dp[l.size()][0] + dp[l.size()][1]) % MOD << endl;

    
}

Measured memory_bytes: 2048
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
typedef long long  ll;
#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)

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

	ll cnt = 0;
	string t;
	rep(i, 0, s.size()) {
		if (s[i] == '(') {
			cnt++;
			t += s[i];
		}
		else {
			cnt--;
			t += s[i];
		}

		if (cnt < 0) {
			t = '(' + t;
			cnt++;
		}
	}

	rep(i, 0, cnt) {
		t += ')';
	}
	cout << t << endl;
	return 0;
}

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

vector<ll> cnt(1e5 + 1, 0);

void solve(long long N, std::vector<long long> a) {
    rep(i, N) {
        if (a[i] - 1 >= 0) {
            cnt[a[i] - 1]++;
        }
        cnt[a[i]]++;
        if (a[i] + 1 <= N) {
            cnt[a[i] + 1]++;
        }
    }
    cout << *max_element(cnt.begin(), cnt.end()) << endl;
}

int main() {
    long long N;
    scanf("%lld", &N);
    std::vector<long long> a(N);
    for (int i = 0; i < N; i++) {
        scanf("%lld", &a[i]);
    }
    solve(N, std::move(a));
    return 0;
}


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

// APG4b-M
int main() {
  int H,W;
  cin >> H >> W;

  vector<vector<char>> s(H,vector<char>(W));
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> s.at(i).at(j);
    }
  }

  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (s.at(i).at(j) != '#') {
        int bomb = 0;
        for (int k = -1; k < 2; k++) {
          for (int l = -1; l < 2; l++) {
            if (k != 0 || l != 0) { // 自分自身は飛ばす
              if (i+k>=0 && i+k<H && j+l>=0 && j+l<W) { // 存在する座標だけ使う
                if (s.at(i+k).at(j+l) == '#') bomb++;
              }
            }
          }
        }
        s.at(i).at(j) = (char)('0'+bomb);
      }
    }
  }

  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cout << s.at(i).at(j);
    }
    cout << endl;
  }


}


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

//型定義
typedef long long ll;

//定数
const int INF=1e+9;
const int MOD=1e+9+7;

//REPマクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define REP2(i,a,b) for(ll i=a;i<(ll)(b);i++)
#define REPD2(i,a,b) for(ll i=a;i>(ll)(b);i--)

// 多次元 vector 生成
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

//vectorの扱い
#define ALL(x) (x).begin(),(x).end() //sortなどの引数省略
#define SIZE(x) ((ll)(x).size()) //size
#define MAX(x) *max_element(ALL(x)) //最大値
#define MIN(x) *min_element(ALL(x)) //最小値

int main(){
    ll N;
    cin>>N;
    vector<int> ans;
    if(N==0){
        cout<<0<<endl;
        return 0;
    }
    ll bit=60;
    while(bit>0){
        int dig=0;
 
        if((pow(4,bit/2)-1)/3+1<=N&&N<=(pow(4,(bit+1)/2)-1)/3){
            dig=1;
        }else if((-2*pow(4,(bit)/2)-1)/3<=N&&N<=-2*(pow(4,(bit-1)/2)-1)/3-1){
            dig=1;
        }


        if(!(dig==0&&ans.size()==0)){
            ans.push_back(dig);
        }
        N-=dig*pow(-2,bit-1);
        bit--;
    }
    REP(i,ans.size()){
        cout<<ans[i];
    }
    cout<<endl;
}

Measured memory_bytes: 4108
// Author: HarshKumar

#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
const ll N = 1e6 + 6, M = 1e9 + 7;
int main()
{
    ios::sync_with_stdio(false), cin.tie(nullptr);
    ll x, y;
    cin >> x >> y;
    for (ll i = 0; i <= x; i++)
    {
        if (2 * i + 4 * (x - i) == y)
            return cout << "Yes", 0;
    }
    cout << "No";
}


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

typedef long long ll;
int n, q;

int par[10000];

int root(int a) {
    if(a == par[a])
        return a;
    return par[a] = root(par[a]);
}

bool same(int a, int b) { return root(a) == root(b); }

void unite(int a, int b) {
    a = root(a);
    b = root(b);
    par[a] = b;
}

int main() {
    cin >> n >> q;
    for(int i = 0; i < n; i++)
        par[i] = i;
    for(int i = 0; i < q; i++) {
        int com, x, y;
        cin >> com >> x >> y;
        if(com == 0)
            unite(x, y);
        else
            cout << (same(x, y) ? 1 : 0) << endl;
    }
}


Measured memory_bytes: 3136
"""
自分が前より小さいとき前の人に合わせる
大きいときそのまま
"""
n = int(input())
a = list(map(int, input().split()))
cnt = 0
m = int(a[0])
for i in range(1, n):
    if m > int(a[i]):
        cnt += m - int(a[i])
    else:
        m = int(a[i])
print(cnt)

Measured memory_bytes: 94220
#include <bits/stdc++.h>  // g++ -std=c++14 -o a a.cpp

using namespace std;

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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repto(i, n) for(int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;

__attribute__((constructor))
void initial() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

int main() {
    int N, W;
    cin >> N >> W;
    vector<P> items;
    int value[101] = {0};
    int weight[101] = {0};
    int vmax[101][10001] = {0};

    rep(i, N) {
        int vi, wi;
        cin >> vi >> wi;
        value[i] = vi;
        weight[i] = wi;
    }

    rep(j, W + 1) {
        if(j < weight[N-1]) {
            vmax[N-1][j] = 0;
        } else {
            vmax[N-1][j] = value[N-1];
        }
    }

    for (int i = N-2; i >= 0; i--) {
        for (int j = 0; j <= W; j ++) {
            if (j < weight[i]) {
                vmax[i][j] = vmax[i + 1][j];
            } else {
                vmax[i][j] = max(
                    vmax[i+1][j], 
                    value[i] + vmax[i+1][j - weight[i]]
                );
            }
        }
    }

    // rep(i, N) {
    //     rep(j, W + 1) {
    //         DEBUG(i);
    //         DEBUG(j);
    //         DEBUG(vmax[i][j]);
    //     }
    // }

    cout << vmax[0][W] << endl;
}



Measured memory_bytes: 7168
N = int(input())
h = input().split()

def watering(num_list):
    num_list_ = []
    l_ = [str(l-1) for l in map(int, num_list)]
    num_list_.extend(list_split(l_, '0'))

    return num_list_

def list_split(num_list, s):
    if '0' not in num_list:
        return [num_list]
    else:
        new_list = []
        
        n0 = num_list[:num_list.index(s)]
        n1 = num_list[num_list.index(s)+1:]
        
        for _ in [n0, n1]:
            if _ == []:
                continue
            else:
                new_list.extend(list_split(_, '0'))

        return new_list    

h_ = list_split(h, '0') 

i = 0
while(1):
    if len(h_) == 0:
        break
    else:
        new_h = []
        for _ in h_:
            new_h.extend(watering(_))
            i += 1
        h_ = new_h
            
print(i)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;
const int INF=1e9;
const ll MOD=1e9+7;
template<typename A,size_t N,typename T>
void Fill(A (&array)[N],const T &val)
{
    std::fill( (T*)array,(T*)(array+N),val );
}

int main(void)
{
    int N,cnt=1,crash=0;
    int a[200005];
    cin >> N;
    for(int i=0;i<N;i++)
    {
        cin >> a[i];
    }
    for(int i=0;i<N;i++)
    {
        if(a[i]>cnt || a[i]<cnt)
        {
            crash++;
        }
        else if(a[i]==cnt)
        {
            cnt++;
        }
    }
    if(crash!=N)
    {
        cout << crash << endl;
    }
    else
    {
        cout << -1 << endl;
    } 
}

Measured memory_bytes: 1024
#include<iostream>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int n,A[110000];
const string ans[2]={"First","Second"};
void solve(int k){
	long long tot=0; int pd=0,where=0,num=0;
	for (int i=1;i<=n;i++){
		tot+=A[i]; if (A[i]==1) pd=1;
		if (A[i]&1) num++,where=i;
	}
	if (pd){
		if ((tot-n)&1) cout<<ans[k]<<endl; else cout<<ans[k^1]<<endl;
		exit(0);
	}
	if ((tot-n)&1){
		if (n==2&&num==2){
			A[1]--; 
		} else {
			cout<<ans[k]<<endl; exit(0);
		}
	} else {
		if (num==1){
			A[where]--;
		} else {
			cout<<ans[k^1]<<endl; exit(0);
		}
	}
	int d=0;
	for (int i=1;i<=n;i++) d=__gcd(d,A[i]);
	for (int i=1;i<=n;i++) A[i]/=d;
	solve(k^1);
}
int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d",&A[i]);
	solve(0);
	return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;

int gcd(int a, int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int lcm(int a, int b){
    return a/gcd(a,b)*b;
}


signed main(void) {
    int a,b;
    cin >> a >> b;
    int n;
    cin >> n;
    int ans = 0;
    rep(i,n){
        int x,y;
        cin >> x >> y;
        if((x <= a && a < y) || (x < b && b <= y)|| (a <= x && y <= b)){
            ans = 1;
        }
    }
    cout << ans << endl;
}



Measured memory_bytes: 3104
n, k = tuple(map(int, input().split(' ')))
r, s, p = tuple(map(int, input().split(' ')))
t = (input())
def char2int(c):
    if c == 'r':
        return p
    elif c == 's':
        return r
    else:
        return s
st = {i:t[i] for i in range(k)}
ans1 = sum(map(char2int, t[:k]))
ans2 = 0
for i in range(k, n):
    h = t[i]
    m = i%k
    if st[m] != h:
        ans2 += char2int(h)
        st[m] = h
    else:
        st[m] = 'any' 
print(ans1 + ans2)

Measured memory_bytes: 15208
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int h = sc.nextInt();
    int m = sc.nextInt();
    sc.close();

    double hd=((h*60+m)*6)%360;
    double md=h*30+(m*1.0)/2;
//    double an=Math.abs(x-y);
//    if(an>180)
//        an=360-an;

//    double hd = (60 * h + m) * 0.5;
//    double md = m * 6;

    double r = 0.000000000;
    if(hd < md) {
      r = md - hd;
      if(r > 180) {
        r = 360 - r;
      }
      double ans = Math.sqrt(a * a + b * b - 2 * a * b * Math.cos(r * Math.PI/180));
      System.out.println(ans);
    }else if(hd > md) {
      r = hd - md;
      if(r > 180) {
        r = 360 - r;
      }
      double ans = Math.sqrt(a * a + b * b - 2 * a * b * Math.cos(r * Math.PI/180));
      System.out.println(ans);
    }else {
      System.out.println(Math.abs(a-b));
    }
  }

}


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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef int64_t ll; typedef vector<int> VI;typedef pair<int,int> pii;
const int mod = (int)1e9 + 7;


int main()
{

	//cin.tie(0); ios_base::sync_with_stdio(false);
	int n; ll k;
	cin >>n >>k;
	vector<ll> a(n);
	rep(i,n) cin >>a[i];
	
	sort(all(a));
	int ans = -1;
	vector<char> tbl(k+5,0);
	tbl[0] = 1;
	repr(j,n-1,0) repr(p,k-1,0) if(tbl[p] >0){
		tbl[min(k, p + a[j])] = 1;
		if(p+a[j] >=k) ans = j;
	}
	
	cout << (ans<0? n : ans) << endl;
	return 0;

}


Measured memory_bytes: 256
def resolve():
    K, S = list(map(int, input().split()))
    cnt = 0
    for x in range(K+1):
        for y in range(K+1):
            z = S - x - y
            if 0 <= z and z <= K:
                cnt += 1
    print(cnt)
    

if '__main__' == __name__:
    resolve()

Measured memory_bytes: 40940
#include "bits/stdc++.h"
using namespace std;
const int MAX = 700000;
const int MOD = 1000000007;

long long  fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y){
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}

// index が条件を満たすかどうか
int dp[500020][2] = {};
int main() {
	int n, m;
	cin >> n >> m;
	int wanumber = 0;
	int ansnumber = 0;
	for (int i = 0; i < m; i++) {
		int a;
		string s;
		cin >> a >> s;
		if (s == "AC") {
			if (dp[a][0] == 0) {
				ansnumber = ansnumber + 1;
				dp[a][0] = 1;
				wanumber = wanumber + dp[a][1];
			}
		}
		else {
			dp[a][1] = dp[a][1] + 1;
		}
	}
	cout << ansnumber << " " << wanumber;
}

Measured memory_bytes: 1024
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
using namespace std;
const long long Mod=1e9+7;
int n,a[410],b[410],pa[410],pb[410];
long long g[410][410],f[150][410][410];
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		pa[a[i]]=i;
	}
	for (int i=1;i<=n;i++)
	{
		scanf("%d",&b[i]);
		pb[b[i]]=i;
	}
	for (int i=1;i<=n;i++)
	{
		for (int j=1;j<=n;j++)
		{
			for (int k=1;k<=n;k++)
			{
				if (pa[k]<=i || pb[k]<=j)
				{
					g[i][j]++;
				}
			}
		}
	}
	f[0][0][0]=1;
	for (int i=1;i<=n/3;i++)
	{
		for (int j=1;j<=n;j++)
		{
			for (int k=1;k<=n;k++)
			{
				f[i][j][k]=(f[i][j-1][k]+f[i][j][k-1]-f[i][j-1][k-1]+Mod)%Mod;
				if (pb[a[j]]>k && pa[b[k]]>j)
				{
					f[i][j][k]=(f[i][j][k]+1LL*(3*i-g[j][k])*f[i-1][j-1][k-1]%Mod)%Mod;
				}
			}
		}
	}
	long long ans=f[n/3][n][n];
	for (int i=0;i<n/3;i++)
	{
		ans=ans*(i*3+1)%Mod*(i*3+2)%Mod; 
	}
	printf("%lld\n",ans);
    return 0;
}
//凄凉别后两应同，最是不胜清怨月明中。
//——纳兰性德《虞美人·曲阑深处重相见》

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

#define li long long int
#define rep(i, to) for (li i = 0; i < ((li)(to)); i++)
#define repp(i, start, to) for (li i = (li)(start); i < ((li)(to)); i++)
#define allof(v) (v).begin(), (v).end()

li n, t;

int main(void)
{
	cin >> n >> t;
	li res = 0;
	li last = -1;
	rep(i, n) {
		li tt;
		cin >> tt;
		if (tt >= last) {
			res += t;
		} else {
			res += tt + t - last;
		}
		last = tt + t;
	}
	cout << res << endl;

	return 0;
}

Measured memory_bytes: 384