akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

typedef pair<int, int> pii;

int n, num;
vector<int> a, b, c;
vector<pii> vec;

int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> num;
		if(num < 0)
			a.push_back(num);
		else if(num == 0)
			c.push_back(num);
		else
			b.push_back(num);
	}
	sort(a.begin(), a.end());
	sort(b.begin(), b.end(), greater<int>());
	if(a.empty() && b.empty()) {
		cout << "0\n";
		for (int i = 0; i < n - 1; i++)
			cout << 0 << ' ' << 0 << '\n';
		return 0;
	}
	if(a.empty()) {
		if(c.size())
			a = c;
		else {
			a.push_back(b.back());
			b.pop_back();
		}
	}
	else if(b.empty()) {
		if(c.size())
			b = c;
		else {
			b.push_back(a.back());
			a.pop_back();
		}
	}
	else {
		for (int num: c)
			a.push_back(num);
	}
	
	for (int i = 0; i < n - 1; i++) {
		if(a.size() < b.size()) {
			vec.push_back(pii(a.back(), b.back()));
			int num = a.back() - b.back();
			a.pop_back(), b.pop_back();
			a.push_back(num);
		}
		else {
			vec.push_back(pii(b.back(), a.back()));
			int num = b.back() - a.back();
			a.pop_back(), b.pop_back();
			b.push_back(num);
		}
	}
	cout << b.back() << '\n';
	for (pii p: vec)
		cout << p.first << ' ' << p.second << '\n';
	return 0;
}

Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
 
int GetDigitsSum(int N) {
	int digitsSum = 0;
	while (N > 0) {
		digitsSum += N % 10;
		N /= 10;
	}
	return digitsSum;
}

int main()
{
	int N;
	int A_quotient;
	int B_quotient;
	int A_B_DigitsSum;
	int answer = 2147483647;

	cin >> N;

	for (int A = 1 ; A <= ( N + 1 ) / 2  ; A++) {
		A_quotient = A;
		B_quotient = N - A;
		// 合計 
		A_B_DigitsSum = GetDigitsSum(A_quotient) + GetDigitsSum(B_quotient);
		if ( A_B_DigitsSum < answer )
			answer = A_B_DigitsSum;
	}
	
	cout << answer << endl;
	return 0;
}

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

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

  int N; cin >> N;
  ll ans = 1;
  ll MOD = 1e9 + 7;
  for (int i = 2; i <= N; i++) {
    ans = (ans * i) % MOD;
  }
  cout << ans << '\n';
  return 0;
}

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

#define rep(i, a, b) for(int i = (a); i <= (b); ++i)
#define per(i, b, a) for(int i = (b); i >= (a); --i)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define boost ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)

#define M (ll)(1e9+7)
#define inf (ll)(2e9+9)
#define infl (ll)(2e18+9)
#define debug1(a) cout<<#a<<" = " <<a<<endl; 
#define debug2(a,b) cout<<#a<<" = " <<a<<" , "<<#b<<" = "<<b<<endl; 
#define debug3(a,b,c) cout<<#a<<" = " <<a<<" , "<<#b<<" = "<<b<<" , "<<#c<<" = "<<c<<endl; 
#define debug4(a,b,c,d) cout<<#a<<" = " <<a<<" , "<<#b<<" = "<<b<<" , "<<#c<<" = "<<c<<" , "<<#d<<" = " <<d<<endl; 
  
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<char> vc; 
typedef vector<ll> vll; 
typedef vector< pair<int,int> > vpii;

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



void solve(){
  int n,k; cin>>n>>k; 
  vi h(n); rep(i,0,n-1) cin>>h[i]; 
  vi dp(n,inf); 
  dp[0]=0; 
  rep(i,1,n-1){
    rep(j,max(i-k,0),i-1)
      dp[i]=min(dp[i],dp[j]+abs(h[j]-h[i])); 
  }
  cout<<dp[n-1]<<endl; 
}

int main() {
  clock_t beg=clock(); 
  boost;
  int t=1; 
  // cin>>t; 
  while(t--){
    solve(); 
  }
  clock_t end=clock(); 
  fprintf(stderr, "%lf\n", (double)(end-beg)/CLOCKS_PER_SEC);
}


Measured memory_bytes: 1024
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long N = sc.nextLong();
        long A = sc.nextLong();
        long B = sc.nextLong();
        sc.close();

        long dist = B - A;
        long ans = (dist % 2 != 0 ? Math.min(A - 1, N - B) + 1 : 0) + dist / 2;
        System.out.println(ans);
    }
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
#define EPS 1e-9
#define INF 1070000000LL
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(auto it=(X).begin();it!=(X).end();it++)
#define numa(x,a) for(auto x: a)
#define ite iterator
#define mp make_pair
#define mt make_tuple
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define pb push_back
#define pf push_front
#define sec second
#define sz(x) ((int)(x).size())
#define ALL( c ) (c).begin(), (c).end()
#define gcd(a,b) __gcd(a,b)
#define endl "\n"
using namespace std;
template <int POS, class TUPLE> void deploy(std::ostream &os, const TUPLE &tuple){}
template <int POS, class TUPLE, class H, class ...Ts> void deploy(std::ostream &os, const TUPLE &t){ os << (POS == 0 ? "" : ", ") << get<POS>(t); deploy<POS + 1, TUPLE, Ts...>(os, t); }
template <class T> std::ostream& operator<<(std::ostream &os, std::vector<T> &v){ int remain = v.size(); os << "{"; for(auto e: v) os << e << (--remain == 0 ? "}" : ", "); return os; }
template <class T> std::ostream& operator<<(std::ostream &os, std::set<T> &v){ int remain = v.size(); os << "{"; for(auto e: v) os << e << (--remain == 0 ? "}" : ", "); return os; }
template <class T, class K> std::ostream& operator<<(std::ostream &os, std::map<T, K> &mp){ int remain = mp.size(); os << "{"; for(auto e: mp) os << "(" << e.first << " -> " << e.second << ")" << (--remain == 0 ? "}" : ", "); return os; }
#define DEBUG1(var0) { std::cerr << (#var0) << "=" << (var0) << endl; }
#define DEBUG2(var0, var1) { std::cerr << (#var0) << "=" << (var0) << ", ";DEBUG1(var1); }
#define DEBUG3(var0, var1, var2) { std::cerr << (#var0) << "=" << (var0) << ", ";DEBUG2(var1,var2); }
#define DEBUG4(var0, var1, var2, var3) { std::cerr << (#var0) << "=" << (var0) << ", ";DEBUG3(var1,var2,var3); }
typedef long long ll;


int Euler_phi(int mynum){//オイラーのファイ関数
  
  int ret = mynum;
  for(int i = 2; i * i <= mynum;i++){
    if(mynum%i == 0){
      ret -= ret/i;
      while(mynum%i == 0){
        mynum /= i;
      }
    }
  }
  if(mynum > 1){
    ret -= ret/mynum;
  }
  return ret;
}

int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  int n;
  cin >> n;
  cout << Euler_phi(n) << endl;
  return 0;
}

Measured memory_bytes: 1200
x, y = map(int, input().split())
listB = [4, 6, 9, 11]
listA = [1, 3, 5, 7, 8, 10, 12]

if x == 2 or y == 2:
    print("No")
else:
    if x in listB and y in listB:
        print("Yes")
    elif x in listA and y in listA:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 3060
#include<stdio.h>
using namespace std;

int main(){
    while(true){
        int m,f,r;
        scanf("%d%d%d",&m,&f,&r);
        if(m==-1&&f==-1&&r==-1)break;
        if(m==-1 || f==-1)printf("F\n");
        else if(m+f>=80)printf("A\n");
        else if(m+f>=65&&m+f<80)printf("B\n");
        else if(m+f>=50&&m+f<65)printf("C\n");
        else if(m+f>=30&&m+f<50){
            if(r>=50)printf("C\n");
            else printf("D\n");
        }
        else if(m+f<30)printf("F\n");
    }
    
    
}


Measured memory_bytes: 2580
#include "bits/stdc++.h"

#define ed cout<<"\n";
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long 
#define ffor(i,a,b) for(ll i=(ll)(a);i<(ll)(b);++i)
#define rep(i, n) ffor(i,0,n)
#define All(obj) (obj).begin(),(obj).end()
#define INF ((ll)1e9+7)
#define c(a) cout<<a<<"\n";
using namespace std;
const int N = 100005;



int main() {
	speed;
	cout << fixed << setprecision(6);
	/*start*/
	int n, a;
	cin >> n >> a;
	int memo = n % 500;
	if (memo <= a) {
		c("Yes");
	}
	else c("No");
	return 0;
}



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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<string> vs;
typedef pair<int, int> P;

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

void YN(bool flg){if(flg) cout << "YES" << endl; else cout << "NO" << endl;}
void Yn(bool flg){if(flg) cout << "Yes" << endl; else cout << "No" << endl;}
void yn(bool flg){if(flg) cout << "yes" << endl; else cout << "no" << endl;}

int main()
{
    int h, w, k;
    cin >> h >> w >> k;
    vs s(h);
    rep(i, h) cin >> s[i];

    int ans = 0;
    rep(ybit, (1<<h)) {
        rep(xbit, (1<<w)) {
            vs t(h);
            rep(i, h) t[i] = s[i];
            rep(i, h) {
                if(ybit & (1<<i)) {
                    //行を赤に
                    rep(j, w) t[i][j] = 'a';
                }
            }
            rep(i, w) {
                if(xbit & (1<<i)) {
                    //列を赤に
                    rep(j, h) t[j][i] = 'a';
                }
            }
            int cnt = 0;
            rep(i, h) rep(j, w) {
                if(t[i][j] == '#') cnt++;
            }
            if(cnt == k) ans++;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1);
long N, L, T[3000];
int main() {
  cin >> N >> L;
  for (int i = 0; i < N; ++i) {
    cin >> T[i];
  }
  double x = 0;
  double y = 0;
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < N; ++j) {
      if (i == j) continue;
      long a = T[i];
      long b = T[j];
      if (b < a) b += L;
      double rad = PI * (a + b) / L;
      int cont = i - j - 1;
      if (cont < 0) cont += N;
      x += cont * cos(rad);
      y += cont * sin(rad);
    }
  }
  x /= N * (N - 1) * (N - 2) / 6;
  y /= N * (N - 1) * (N - 2) / 6;
  cout << fixed << setprecision(16) << x << ' ' << y << endl;
}    

Measured memory_bytes: 640
#include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>

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

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
int N;
double P,A,B,C,D,E,F,S,M;
int main(){
	while(cin>>N,N){
		vector<pair<double,string> > rank;
		rank.clear();
		string str;
		for(int i = 0;i < N;i++){
			cin>>str>>P>>A>>B>>C>>D>>E>>F>>S>>M;//F*S
			double sum = -(F*S*M-P)/(A+B+C+(D+E)*M);
			rank.push_back(make_pair(sum,str));
		}
		sort(rank.begin(),rank.end());
		for(int i = 0;i < N;i++){
			cout <<rank[i].second<<endl;
		}
		cout <<'#'<<endl;
	}
	return 0;
}

Measured memory_bytes: 1252
#include <iostream>
#include <math.h>
using namespace std;

int count(int* flags);
unsigned long decode(int* flags);

int main(void){
  int flags[64];
  for(int i=0;i<64;i++){
    flags[i]=0;
  }
  int q;
  cin>>q;
  int query,i;
  for(int j=0;j<q;j++){
    cin>>query;
    if(query==0){
      cin>>i;
      cout<<flags[i]<<endl;
    }
    else if(query==1){
      cin>>i;
      flags[i]=1;
    }
    else if(query==2){
      cin>>i;
      flags[i]=0;
    }
    else if(query==3){
      cin>>i;
      flags[i]=1-flags[i];
    }
    else if(query==4){
      if(count(flags)==64){
        cout<<1<<endl;
      }
      else{
        cout<<0<<endl;
      }
    }
    else if(query==5){
      if(count(flags)>0){
        cout<<1<<endl;
      }
      else{
        cout<<0<<endl;
      }
    }
    else if(query==6){
      if(count(flags)==0){
        cout<<1<<endl;
      }
      else{
        cout<<0<<endl;
      }
    }
    else if(query==7){
      cout<<count(flags)<<endl;
    }
    else if(query==8){
      cout<<decode(flags)<<endl;
    }
  }
  return 0;
}

int count(int* flags){
  int retval=0;
  for(int i=0;i<64;i++){
    retval+=flags[i];
  }
  return retval;
}

unsigned long decode(int* flags){
  unsigned long retval=0;
  for(int i=0;i<64;i++){
    retval+=((unsigned long)flags[i])*((unsigned long)pow(2,i));
  }
  return retval;
}



Measured memory_bytes: 3272
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define maxn 100010
int n;
int a[maxn],b[maxn],c[maxn];
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++)scanf("%d",&c[i]);
    sort(a+1,a+n+1);
    sort(b+1,b+n+1);
    sort(c+1,c+n+1);
    ll cnt=0;
    for(int i=1;i<=n;i++)
    {
        int x=lower_bound(a+1,a+n+1,b[i])-a;
        int y=upper_bound(c+1,c+n+1,b[i])-c;
        cnt+=(ll)(x-1)*(ll)(n-y+1);
    }
    printf("%lld\n",cnt);
    return 0;
}



Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,NAME,...) NAME
#define pr(...) cerr<< GET_MACRO(__VA_ARGS__,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__) <<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
using namespace std;
using Int = long long;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<55)+1e9; // ~ 3.6 * 1e16
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
using T = tuple<Int,Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
ostream& operator<<(ostream& o,P p){return o<<"("<<p.first<<","<<p.second<<")";}
ostream& operator<<(ostream& o,T t){return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
istream& operator>>(istream& i,P &p){return i>>p.first>>p.second;}
ostream& operator<<(ostream& o,vector<auto> &a){Int i=0;for(auto t:a)o<<(i++?" ":"")<<t;return o;}
istream& operator>>(istream& i,vector<auto> &a){for(auto &t:a)i>>t;return i;}
void prArr(auto a,string s=" "){Int i=0;for(auto t:a)cout<<(i++?s:"")<<t;cout<<endl;}

Int calcEven(Int n){
  Int res = 0;
  for(Int i=1, sum = 2;i<=n;i++) res += sum, sum += 4;
  return res;
}

Int calcAllOdd(Int n){
  Int res = 1;
  for(Int i=1;i<n;i++) res += (i * 2 + 1);
  return res;
}

Int calc(vector<Int> Even, vector<Int> Odd){
  Int n = Even.size();
  Int m = Odd.size();

  if(Even.empty()) return calcAllOdd(m);
  
  Int b = 0;
  for(Int i=1;i<=m;i++) b += 1 + 2*i;
  for(Int i=1;i<n;i++) b += m * 2;
  return calcEven(n) + b;  
}

signed main(){
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  Int n,m;
  cin>>n>>m;
  vector<vector<Int> > G(n);
  for(Int i=0;i<m;i++){
    Int u, v;
    cin>>u>>v; u--, v--;
    G[u].push_back(v);
    G[v].push_back(u);
  }

  if( m == 0 ){cout<<n * n <<endl; return 0;}

  vector<Int> Odd, Even;
  {
    vector<Int> used(n, -1);
    Int cnt, flag;
    function<void(Int,Int,Int)> dfs = [&](Int pos, Int pre,Int turn){
      if(used[pos] != -1){flag |= used[pos] != turn; return;}
      used[pos] = turn;
      cnt++;
      for(Int to:G[pos]) if(to != pre) dfs(to, pos, !turn);
    };
    
    for(Int i=0;i<n;i++){
      if(used[i] != -1) continue;
      cnt = flag = 0;
      dfs(i, -1, 0);
      flag == 0? Even.push_back(cnt):Odd.push_back(cnt);
    }
    sort(Odd.begin(), Odd.end());
    sort(Even.begin(), Even.end(),greater<Int>());
  }

  
  
  Int one = 0;
  while(!Even.empty() && Even.back() == 1) one++, Even.pop_back();

  Int ans = calc(Even, Odd);
  if(one) ans += 2 * n * one - one * one;
  cout<<ans<<endl;
  
  return 0;
}


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

using namespace std;

int main(void)
{
    int N;
    cin >> N;

    vector<int> A;
    vector<int> B;
    vector<int> C;

    int num;
    for (int i = 0; i < N; i++)
    {
        cin >> num;
        A.push_back(num-1);
    }
    for (int i = 0; i < N; i++)
    {
        cin >> num;
        B.push_back(num);
    }
    for (int i = 0; i < N - 1; i++)
    {
        cin >> num;
        C.push_back(num);
    }

    int result = 0;
    for (int i = 0; i < N; i++)
    {
        result += B[A[i]];

        if (i != 0)
        {
            if (A[i] - 1 == A[i - 1])
            {
                result += C[A[i] - 1];
            }
        }
      
    }

    cout << result << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ;
#endif

#define equals(a,b) (fabs((a)-(b)) < EPS)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

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>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

template <typename T>
void print_array(const T &ary, int size){
    REP(i,size){
        cout << ary[i] << " ";
    }
    cout << endl;
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;
const double EPS = (1e-10);

LL query(string S, int l, int r){
    int len = S.length();
    LL acc = 1;
    char pre = S[l];
    LL ans = 0;
    FOR(i,l+1,r+1){
        if(pre != S[i]){
            ans += acc / 2;
            acc = 1;
            pre = S[i];
        }else{
            acc++;
        }
    }
    ans += acc / 2;
    return ans;

}

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(12);

    string S; cin >> S;
    LL K; cin >> K;
    if(K <= 2){
        if(K ==2) S += S;
        int len = S.length();
        LL ans = query(S,0,len-1);
        cout << ans << endl;
    }else{
        bool allsame = true;
        int len = S.length();
        REP(i,len){
            if(S[i] != S[0]) allsame = false;
        }
        if(allsame){
            cout << len * K / 2 << endl;
            return 0;
        }

        int l,r;
        REP(i,len){
            if(S[i] != S[0]){
                l = i;
                break;
            }
        }
        for(int i = len-1; i >= 0; i--){
            if(S[i] != S[len-1]){
                r = i;
                break;
            }
        }

        if(S[0] != S[len-1]){
            LL ans = query(S,0,len-1);
            cout << ans * K << endl;

        }else{
            LL L = 0, R = 0, C = 0, O = 0;
            L = query(S,0,r);
            R = query(S,l,len-1);
            C = query(S,l,r);
            O = (len - (r-l + 1)) / 2;
            cout << L + O*(K-1) + C*(K-2) + R << endl;






        }
    }

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std ;
class Graph{
public:
    vector<int> * v ;
    int number_of_vertices ;
    Graph( int n ){
        v = new vector<int> [n+1] ;
        number_of_vertices = n ;
    }
    void add_edge( int f, int t){
        v[f].push_back(t) ;
    }
    void DFS( int node, bool visited[], int dp[] ){
        visited[node] = true ;
        for( auto it : v[node] ){
            if( !visited[it] )
                DFS( it, visited, dp ) ;
            dp[node] = max( dp[node], 1 + dp[it] ) ;
        }
    }
    int longest_path(){
        bool visited[number_of_vertices+1] ;
        for( int i = 0 ; i <= number_of_vertices ; i++ ) visited[i] = false ;
        int dp[ number_of_vertices + 1 ] ;
        for( int i = 0 ; i <= number_of_vertices ; i++ ) dp[i] = 0 ;
        for( int i = 1 ; i <= number_of_vertices ; i++ ){
            DFS( i, visited, dp ) ;
        }
        int ans = 0 ;
        for( int i = 1 ; i <= number_of_vertices ; i++ ){
            ans = max( ans, dp[i] ) ;
        }
        return ans ;
    }
};
int main(){
    int N, E ;
    cin >> N >> E ;
    int t2, t1 ;
    Graph g( N ) ;
    for( int i = 0 ; i < E ; i++ ){
        cin >> t1 >> t2 ;
        g.add_edge( t1, t2 ) ;
    }
    cout << g.longest_path() ;
    return 0 ;
}

Measured memory_bytes: 7552
#include <stdio.h>

int main()
{
  char s[3];
  int i;
  int cnt=0;
  for(i=0;i<3;++i)
  {   scanf("%c",&s[i]);
      if(s[i]=='1')
          cnt++;
  }
  
  printf("%d",cnt);
  
}  

Measured memory_bytes: 128
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;
use std::cmp::max;

fn main() {
    let cin = stdin();
    let mut scan = Scanner::new(cin.lock());
    let n = scan.read::<usize>();
    let mut a = vec![];
    let mut g = vec![vec![];n];
    for i in 0..n {
        a.push(scan.read::<usize>());
        for _ in 0..a[i] {
            let x = scan.read::<usize>()-1;
            let y = scan.read::<usize>();
            g[i].push((x, y));
        }
    }

    let mut ret = 0;
    'outer: for mask in 0..1<<n {
        for i in 0..n {
            if (mask >> i) & 1 == 1 {
                for &(v, k) in &g[i] {
                    if (mask >> v) & 1 != k {
                        continue 'outer;
                    }
                }
            }
        }
        ret = max(ret, (mask as u64).count_ones());
    }
    println!("{}", ret);
}



// region template
#[allow(dead_code)]
fn iu(i: i64) -> usize { i as usize }

#[allow(dead_code)]
fn ui(i: usize) -> i64 { i as i64 }

#[allow(dead_code, deprecated)]
fn join<T: std::fmt::Display>(slice: &[T], sep: &str) -> String {
    let strings = slice.iter().map(|t| format!("{}", t)).collect::<Vec<_>>();
    strings.connect(sep)
}

#[allow(dead_code)]
fn arr<'a, S, T>(n: usize, mut f: S) -> Vec<T> where S: FnMut(usize) -> T + 'a {
    (0..n).map(|i| f(i)).collect::<Vec<T>>()
}

struct Scanner<'a> {
    cin: StdinLock<'a>,
}

#[allow(dead_code)]
impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }

    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }

    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }

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

    fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}
// endregion

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define all(V) V.begin(),V.end()
using ll = long long;

string S = "";
int N;
vector<string> X;

void solve(char c, int x) {
	if (x == N) {
		X.push_back(S);
		return;
	}
	for (char w = 'a';w <= c;w++) {
		S[x] = w;
		solve(c, x + 1);
	}
	S[x] = c + 1;
	solve(c + 1, x + 1);
}

int main() {
	cin >> N;
	for (int i = 0;i < N;i++) {
		S += "a";
	}
	solve('a', 1);
	for (auto x : X) {
		cout << x << endl;
	}
}

Measured memory_bytes: 7796
n = int(input())
hs = list(map(int, input().split()))

results = list()

results.append(0)
results.append(abs(hs[0] - hs[1]))

for i in range(2, n):
    results.append(min(abs(hs[i]-hs[i-2]) + results[i-2], abs(hs[i]-hs[i-1]) + results[i-1]))

print(results[n-1])


Measured memory_bytes: 55400
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define gc getchar
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define x1 uvuvwevwevwe
#define y1 onyetenyevwe
#define x2 ugwemubwem
#define y2 ossas
typedef long long LL;
typedef long double LD;
typedef pair<int,int> pii;
template <typename T> void scan(T &angka){
	angka=0;char input=gc();T kali=1;
	while(!(48<=input&&input<=57)){	if(input=='-')	kali=-1;input=gc();}
	while(48<=input&&input<=57)	angka=(angka<<3)+(angka<<1)+input-48,input=gc();angka*=kali;
}
template <typename T1,typename T2> void scan(T1 &angka1,T2 &angka2){
	scan(angka1);scan(angka2);
}
int jarak,nodes,subtree[100005]={},par[100005];
vector <int> node[100005];
void hitungsubtree(int now,int _par=-1){
	subtree[now]=1;
	par[now]=_par;
	for(auto v:node[now])
	{
		if(v==_par)
			continue;
		hitungsubtree(v,now);
		subtree[now]+=subtree[v];
	}
}
int main()
{
	scan(nodes);
	for(int i=1;i<=nodes-1;i++)
	{
		int u,v;
		scan(u,v);
		node[u].pb(v);
		node[v].pb(u);
	}
	hitungsubtree(1);
	jarak=0;
	int now=nodes;
	while(par[now]!=1)
	{
		jarak++;
		now=par[now];
	}
	jarak+=2;
	int satu,dua=0;
	now=nodes;
	int tadi=-1;
	for(int i=0;i<jarak/2;i++)
	{
		dua+=subtree[now]-((tadi==-1)?0:subtree[tadi]);
		tadi=now;
		now=par[now];
	}
	satu=subtree[1]-dua;
	if(satu>dua)
	{
		cout<<"Fennec"<<endl;
	}
	else if(dua>satu)
	{
		cout<<"Snuke"<<endl;
	}
	else
	{
		cout<<"Snuke"<<endl;
	}
}

Measured memory_bytes: 12800
#!/usr/bin/env php
<?php
const YES = "Yes";
const NO = "No";

fscanf(STDIN, "%d", $N);

    $pre_x = 0;
    $pre_y = 0;
    $pre_t = 0;
    while(($line = fgets(STDIN)) !== false) {
        list($time, $cur_x, $cur_y) = explode(' ', $line);
        $move_t = $time - $pre_t;
        $move_s = abs($cur_x - $pre_x) + abs($cur_y - $pre_y);
        if ($move_s > $move_t) {
            echo NO.PHP_EOL;
            exit;
        }
        if (($move_s % 2) != ($move_t % 2)) {
            echo NO.PHP_EOL;
            exit;
        }

        $pre_x = $cur_x;
        $pre_y = $cur_y;
        $pre_t = $time;
    }
    echo YES.PHP_EOL;


Measured memory_bytes: 4728
//{{{
#include<algorithm>
#include<cmath>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<random>
#include<set>
#include<sstream>
#include<sys/time.h>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printw) FUNC(printwe) FUNC(printb) FUNC(printbe) FUNC(printd) FUNC(printde) FUNC(printdu);
#endif
template <class S, class T>
istream& operator >> (istream& in, pair<S, T>& p){ return in >> p.first >> p.second; }
template <class T>
istream& operator >> (istream& in, vector<T>& v){ for(auto& e : v){ in >> e; } return in; }
//}}}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    vector<pair<int, int>> abs(n); cin >> abs;
    sort(abs.begin(), abs.end());
    int rem = m;
    ll sum = 0;
    for(auto& ab : abs){
        ll num = min(rem, ab.second);
        rem -= num;
        sum += num * ab.first;
    }
    cout << sum << '\n';
}


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

int N;
int A[210];         

int main() {
	cin >> N;
	for (int i = 0; i < N; ++i) cin >> A[i];

	int res = 0;

	while (true) {
		bool exist_odd = false;  
		for (int i = 0; i < N; ++i) {
			if (A[i] % 2 != 0) exist_odd = true;  
		}

		if (exist_odd) break;  

		
		for (int i = 0; i < N; ++i) {
			A[i] /= 2;
		}
		++res;  
	}

	cout << res << endl;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import numpy as np
def main():
    mod = 10 ** 9 + 7
    N = int(input())
    A = list(map(int, input().split()))
    A = np.array(A, np.int64)
    ans = 0
    for i in range(60):
        bit = np.count_nonzero(A & 1)
        ans += bit * (N - bit) * (2 ** i)
        ans %= mod
        A >>= 1
    print(ans)

if __name__ == '__main__':
    main()

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

using namespace std;

#define rep(i, a) for (int i = 0; i < a; i++)
#define reps(i, a, b) for (int i = a; i < b; i++)

int main()
{
	string s;
	cin >> s;
	int x = 0;
	rep(i, 4) {
		if (s[i] == '+') x++;
		else x--;
	}
	cout << x << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#include <string.h>


int main(){
    
    
    int i;
    char str[210];
    gets(str);
    
    for (i=0; i<strlen(str); i++) {
        if(str[i]>='a' && str[i]<='z')
            str[i] =str[i]-32;
    }
    printf(str);
    printf("\n");
    
    
    return 0;
    
}

Measured memory_bytes: 524
#include<stdio.h>

int main(){
  int n;
  scanf("%d",&n);
  int v[n];
  for(int i=0;i<n;i++){
    scanf("%d",&v[i]);
  }
  for(int i=n-1;i>0;i--){
    for(int j=0;j<i;j++){
      if(v[j]>v[j+1]){
        int buf = v[j];
        v[j] = v[j+1];
        v[j+1] = buf;
      }
    }
  }
  float ans=v[0];
  for(int i=1;i<n;i++){
    ans += v[i];
    ans = ans/2;
  }
  printf("%lf",ans);
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <atcoder/lazysegtree>
#include <atcoder/modint>
#include <atcoder/math>
using namespace std;

#define rep(i,x,y) for(ll i=(x);i<(y);i++)
#define rrep(i,x,y) for(ll i=(ll)(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
#define itrout(x) for(int i=0;i<x.size();i++) {cout << x[i] << (i==x.size()-1 ? "\n" : " ");}
#ifdef LOCAL
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#define debugbit(x, n) cerr << #x << " = " << bitset<n>(x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#define itrdebug(x) cerr << #x << " "; for (auto & el : (x)) {cerr << (el) << " ";} cerr << endl
#define dassert(...) assert(__VA_ARGS__)
#else
#define debug(x)
#define debugbit(x, n)
#define itrdebug(x)
#define dassert(...)
#endif
//#define int long long
//using mint = atcoder::modint;

typedef long long ll;
const ll MOD = 1e9 + 7;
const long double EPS = 1e-8;

using mint = atcoder::modint998244353;

struct S { // when 23
    mint num; // num = 23
    mint multiplier; // multiplier = 10^2
    unsigned int value () const { return num.val(); }
};

struct F {
    mint num;
};

S op(S l, S r) { return S{l.num * r.multiplier + r.num, l.multiplier * r.multiplier}; }

S e() { return S{0, 1}; }

S mapping(F l, S r) { return S{l.num == 0 ? r.num : ((r.multiplier-1)/9 * l.num) , r.multiplier}; }

F composition(F l, F r) { return F{l.num == 0 ? r.num : l.num}; }

F id() { return F{0}; }

void solve(long long N, long long Q, std::vector<long long> L, std::vector<long long> R, std::vector<long long> D){
    vector<S> a(N+1);
    rep(i,1,N+1) {
        a[i] = S{1, 10};
    }
    atcoder::lazy_segtree<S, op, e, F, mapping, composition, id> seg(a);
    rep(qi,0,Q) {
        seg.apply(L[qi], R[qi]+1, F{D[qi]});
        cout << seg.prod(1, N+1).value() << endl;
    }
}

signed main(){
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    long long N;
    scanf("%lld",&N);
    long long Q;
    scanf("%lld",&Q);
    std::vector<long long> L(Q);
    std::vector<long long> R(Q);
    std::vector<long long> D(Q);
    for(int i = 0 ; i < Q ; i++){
        scanf("%lld",&L[i]);
        scanf("%lld",&R[i]);
        scanf("%lld",&D[i]);
    }
    solve(N, Q, std::move(L), std::move(R), std::move(D));
    return 0;
}


Measured memory_bytes: 14604
import java.util.*;
 
public class Main {
    static Scanner scanner = new Scanner(System.in);
 
    public static void main(String[]$) {
        int n = scanner.nextInt();
        int m = scanner.nextInt();
        int k = scanner.nextInt();
        for (int i = 0; i <= n; i++) {
            for (int j = 0; j <= m; j++) {
                if (i * m + j * n - i * j * 2 == k) {
                    System.out.println("Yes");
                    return;
                }
            }
        }
        System.out.println("No");
    }
}

Measured memory_bytes: 21972
#include <stdio.h>
int fibonach(int,int*);
int main(){
  int n,i,F[44];
  scanf("%d",&n);
  for(i = 0;i<44;i++){
    F[i] = -1;
  }
  printf("%d\n",fibonach(n,F));
 
}
int fibonach(int n,int* F){
  F[0] = F[1] = 1;
  if(n == 0 || n == 1){
    return 1;
  }
  if(F[n] > 0){
    return F[n];
  }
  return F[n] = fibonach(n-1,F) + fibonach(n-2,F);
}



Measured memory_bytes: 2052
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

int main(){
    string s;
    int k;
    cin>>s>>k;
    int n=s.size();
    rep(i,n){
        if(s[i]!='a'){
            int x=26-(s[i]-'a');
            if(k>=x){
                s[i]='a';
                k-=x;
            }
        }
        
    }
    

    k%=26;
    
    while(k>0){
        if(s[n-1]=='z') s[n-1]='a';
        else s[n-1]++;
        k--;
    }


    cout<<s<<endl;
} 


Measured memory_bytes: 3740
#include<iostream>
using namespace std;
#include<cstdio>
#include<cstring>

//メイン関数
int main()
{
  char str[81];
   while(fgets(str,sizeof(str),stdin)!=NULL){
  // while(scanf("%[^/n]s",str)!=EOF){

    //strstrで探索
  if((strstr(str,"the")) || (strstr(str,"this")) || (strstr(str,"that"))){
    printf("%s",str);
    continue;
  }
  int len=strlen(str);
    for(int i=1;i<=26;i++){
      for(int j=0;j<len;j++){
	if(str[j]>='a' && str[j]<='z'){       
	  str[j]++;
	  if(str[j]=='{'){
	    str[j]='a';
	  }
	}
      }
      //strstrで探索
      if((strstr(str,"the")) || (strstr(str,"this")) || (strstr(str,"that")))break;
    }
    printf("%s",str);
  }
   return 0;
}

	

Measured memory_bytes: 1124
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		int[] dp = new int[N+1];
		for(int i=1;i<=N;i++) dp[i] = i;
		List<int> nines = new List<int>();
		nines.Add(9);
		while(nines[nines.Count - 1] * 9 <= N) nines.Add(nines[nines.Count - 1] * 9);
		List<int> sixs = new List<int>();
		sixs.Add(6);
		while(sixs[sixs.Count - 1] * 6 <= N) sixs.Add(sixs[sixs.Count - 1] * 6);
		
		for(int i=0;i<N;i++){
			dp[i+1] = Math.Min(dp[i] + 1, dp[i+1]);
			foreach(var nine in nines){
				if(i + nine <= N) dp[i + nine] = Math.Min(dp[i + nine], dp[i] + 1);
			}
			foreach(var six in sixs){
				if(i + six <= N) dp[i + six] = Math.Min(dp[i + six], dp[i] + 1);
			}
		}
		Console.WriteLine(dp[N]);
		
	}
	long N;
	public Sol(){
		N = ri();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


Measured memory_bytes: 13408
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count etc.
#include <cstdlib>	// require abs
#include <cstdio>	// require printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>	// require tolower, toupper
#include <fstream>	// require freopen
#include <complex>

using namespace std;

// deq notes ½Êô½É¨¯éxNgZ http://www.deqnotes.net/acmicpc/2d_geometry/

typedef complex<double> P;
#define EPS (1e-10)
#define EQ(a,b) (abs((a)-(b)) < EPS)

// àÏ (dot product) : a&#8901;b = |a||b|cosÆ
double dot(P a, P b) {
	return (a.real() * b.real() + a.imag() * b.imag());
}

// OÏ (cross product) : a~b = |a||b|sinÆ
double cross(P a, P b) {
	return (a.real() * b.imag() - a.imag() * b.real());
}

// 2¼üÌ½t»è: a//b <=> cross(a, b) = 0
int is_paralell (P a, P b) {
	return EQ ( cross(a, b), 0.0 );
}

int main()
{
//	cut here before submit 
//	freopen ("testcase.ar", "r", stdin );

	double D;

	while (cin >> D && D != 0.0 ){
		double d = 0.0;
		P p,v;
		cin >> p.real() >> p.imag() >> v.real() >> v.imag();
		bool pass = false;

		if (is_paralell(p, v) ){
			pass = true;
			if (dot(p, v )/( abs(p)*abs(v) ) < 0. ){ 
				d = abs(p);
			}else{
				d = 2.0 - abs (p);		
			} // end if
		} // end while
		if (pass && d <= D ){
			printf ("%.9lf\n", d );
		}else{
			cout << "impossible" << endl;
		} // end if			
	} // end loop
		
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <queue>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<P> vec;
    for(int i = 0; i < n; i++)
    {
        int s, t;
        cin >> s >> t;
        vec.push_back(P(t, s));
    }
    sort(vec.begin(), vec.end());
    int ans = 0;
    int tmp = -1;
    for(int i = 0; i < n; i++)
    {
        if(vec[i].second <= tmp) continue;
        tmp = vec[i].first;
        ans++;
    }
    cout << ans << endl;
    return 0;
}




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

#define int int64_t
#define pb push_back
#define pi pair<int, int>
#define pii pair<pi, int>
#define fir first.first
#define sec first.second
#define ter second
#define MAXN 100001
#define mod 1000000007

signed main()
{
  string s;
  cin >> s;
  int ans = 0;
  for (int i = 0; i < s.size(); i++)
    ans += s[i] - '0';
  (ans % 9 == 0) ? cout << "Yes\n" : cout << "No\n";
  return 0;
}


Measured memory_bytes: 3756
#include <iostream>
#include <algorithm>

using namespace std;

long diff(long A, long B, long C, long D){
    return max(max(A, B), max(C, D)) - min(min(A, B), min(C, D)); 
}

int main(){
    int N;
    int A[200000];
    int left, right, mid;
    long sumll, sumlr, sumrl, sumrr;
    long ans = __LONG_MAX__;
    cin >> N;
    sumrr = 0;
    sumrl = 0;
    for(int i = 0; i < N; i++){
        cin >> A[i];
        if(i >= 2) sumrr += A[i];
    }
    
    if(A[0] < A[1]){
        left = 0;
        sumll = A[0];
        sumlr = A[1];
    }else{
        left = -1;
        sumll = 0;
        sumlr = A[0]+A[1];
    }
    right = 1;
    for(int i = 2; i < N-2; i++){
        if(sumrl + A[i] < sumrr - A[i]){
            sumrl = sumrl + A[i];
            sumrr = sumrr - A[i];
            right++;
        }else{
            break;
        }
    }
    ans = min(ans, diff(sumll, sumlr, sumrl, sumrr));
    ans = min(ans, diff(sumll, sumlr, sumrl+A[right+1], sumrr-A[right+1]));
    ans = min(ans, diff(sumll+A[left+1], sumlr-A[left+1], sumrl, sumrr));
    ans = min(ans, diff(sumll+A[left+1], sumlr-A[left+1], sumrl+A[right+1], sumrr-A[right+1]));
    for(mid = 2; mid < N-2; mid++){
        sumlr += A[mid];
        sumrl -= A[mid];
        for(int i = left+1; i < N-2; i++){
            if(sumll + A[i] < sumlr - A[i]){
                sumll = sumll + A[i];
                sumlr = sumlr - A[i];
                left++;
            }else{
                break;
            }
        }
        for(int i = right+1; i < N-2; i++){
            if(sumrl + A[i] < sumrr - A[i]){
                sumrl = sumrl + A[i];
                sumrr = sumrr - A[i];
                right++;
            }else{
                break;
            }
        }
        ans = min(ans, diff(sumll, sumlr, sumrl, sumrr));
        ans = min(ans, diff(sumll, sumlr, sumrl+A[right+1], sumrr-A[right+1]));
        ans = min(ans, diff(sumll+A[left+1], sumlr-A[left+1], sumrl, sumrr));
        ans = min(ans, diff(sumll+A[left+1], sumlr-A[left+1], sumrl+A[right+1], sumrr-A[right+1]));
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#![allow(unused_imports)]

use text_io::*;
use proconio::*;
use std::collections::*;
use itertools::Itertools;
use std::process::exit;
use std::cmp::*;
use num::*;
use num::integer::Roots;

fn main() {
    input! {
    a:usize,
    }
    println!("{}",if a==0 {"1"}else{"0"})
}

Measured memory_bytes: 2112
#include <iostream>
using namespace std;
 
int main() {
	while(1){
		int tnok, yj;
		cin >> tnok;
		if (tnok == 0){
			return 0;
		}
		tnok = 1000 - tnok;
		if(tnok >= 500){
			yj = 1;
			tnok = tnok - 500;
		} else {
			yj = 0;
		}
		if(tnok >= 400){
			yj = yj + 4;
			tnok = tnok - 400;
		}
		else if(tnok >= 300){
			yj = yj + 3;
			tnok = tnok - 300;
		}
		else if(tnok >= 200){
			yj = yj + 2;
			tnok = tnok - 200;
		}
		else if(tnok >= 100){
			yj = yj + 1;
			tnok = tnok - 100;
		}
		if(tnok >= 50){
			yj = yj + 1;
			tnok = tnok - 50;
		}
		if(tnok >= 40){
			yj = yj + 4;
			tnok = tnok - 40;
		}
		else if(tnok >= 30){
			yj = yj + 3;
			tnok = tnok - 30;
		}
		else if(tnok >= 20){
			yj = yj + 2;
			tnok = tnok - 20;
		}
		else if(tnok >= 10){
			yj = yj + 1;
		tnok = tnok - 10;
		}
		if(tnok >= 5){
			yj = yj + 1;
			tnok = tnok - 5;
		}
		cout << tnok + yj <<endl;
	}
}

Measured memory_bytes: 1160
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        n: usize,
        m: usize,
        xs: [i64; n],
        ys: [i64; m],
    }
    let d = 1000000007;
    let mut xsum = 0;
    for i in 0..n-1 {
        xsum = (xsum + (xs[i+1] - xs[i]) * (i + 1) as i64 * (n - i - 1) as i64) % d;
    }
    let mut ysum = 0;
    for i in 0..m-1 {
        ysum = (ysum + (ys[i+1] - ys[i]) * (i + 1) as i64 * (m - i - 1) as i64) % d;
    }
    println!("{}", xsum * ysum % d);
}


Measured memory_bytes: 6396
from decimal import Decimal
from collections import Counter

N = int(input())
A = sorted([int(_) for _ in input().split()])
max_a = max(A)
min_a = min(A)
counter_A = Counter(A)
set_A = set(A)

for a in A:
  if a not in set_A:
    continue
  
  if counter_A[a] > 1:
    set_A.remove(a)
  
  i = 2
  while True:
    num = a * i
    if num > max_a:
      break
    if num in set_A:
      set_A.remove(num)
    i += 1

print(len(set_A))

Measured memory_bytes: 150836
#include <iostream>
#include <cmath>

using namespace std;

int main()
{
	int stu = 0;                //学生数
	double dis = 0.0;           //分散
	double dev = 0.0;           //標準偏差
	int i = 0;

	cin >> stu;
	while (stu != 0)
	{
		
		double point[1000];    //得点 
		double sum = 0.0;      //合計得点
		double ave = 0.0;      //平均
		double dif = 0.0;      //差分
		double dissum = 0.0;   //差分合計 
		for (i = 0; i < stu; i++) {
			cin >> point[i];
			sum += point[i];
		}
		ave = sum / stu;
		for (i = 0; i < stu; i++) {
			
			dif = ave - point[i];
			dis = pow(dif, 2);
			dissum += dis;
		}
			dis = dissum / stu;
			dis = sqrt(dis);

			cout << dis << endl;
			cin >> stu;
	}


}



Measured memory_bytes: 3300
#include<bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
 
ll x;
double p;
int main() {
    IOS; cin >> x;
    p=100.0;
    for(int i=1;; ++i) {
        p*=1.01;
        if(p-(double)(x)>0.0) {cout << i; break;}
      	p=floor(p);
    }
    return 0;
}

Measured memory_bytes: 3652
#include<iostream>
#include<cstring>

using namespace std;

int main()
{
	string S;
	cin>>S;
	unsigned long long int k;
	cin>>k;
	for(unsigned long long i=0;i<min(k,105ull);i++)
		if(S[i]!='1')
			goto a;
	cout<<1<<endl;
	return 0;
	a:;
	int tag;
	for(int i=0;;i++){
		if(S[i]!='1'){
			tag=i;
			break;
		}
	}
	cout<<S[tag]<<endl;
	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

int main() {
	ll n, k;
	ll ans = 0;
	
	cin >> n >> k;

	REP(i, n) {
		if (i == 0) {
			ans = k;
		}
		else {
			ans = ans * (k - 1);
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
// #include "prettyprint.hpp"

bool comp(tuple<long, long, bool> a, tuple<long, long, bool> b) {
  if (get<0>(a) == get<0>(b)) {
    return get<2>(a) < get<2>(b);  // remove -> insert
  }
  return get<0>(a) < get<0>(b);
}

int main() {
  int N, Q;
  cin >> N >> Q;

  vector<tuple<long, long, bool>> events;
  for (int i = 0; i < N; i++) {
    long S, T, X;
    cin >> S >> T >> X;
    events.emplace_back(S - X, X, true);
    events.emplace_back(T - X, X, false);
  }

  sort(events.begin(), events.end(), comp);

  set<long, less<long>> bst;
  long eventIndex = 0;

  for (int i = 0; i < Q; i++) {
    long D;
    cin >> D;

    while (eventIndex < events.size() && get<0>(events[eventIndex]) <= D) {
      if (get<2>(events[eventIndex])) {
        bst.insert(get<1>(events[eventIndex]));
      } else {
        bst.erase(get<1>(events[eventIndex]));
      }
      eventIndex++;
    }

    if (bst.size() == 0) {
      cout << -1 << endl;
    } else {
      cout << *(bst.begin()) << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 20712
n = gets.chomp.to_i
a = gets.chomp.split(' ').map{|i| i.to_i}
cnt = 0
b = true
i = 2
while b
        b = false
        a.each do |j|
                if j % i == 0
                        b = true
                        cnt += 1
                end
        end
        i *= 2
end
puts cnt

Measured memory_bytes: 2428