akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <string.h>
#include <utility>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>

using namespace std;
typedef long long ll;

#define INT_MAX std::numeric_limits<int>().max()
#define INT_MIN std::numeric_limits<int>().min()
#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())

ll N, T;

int main()
{
    ll ans = 0;
    ll t;
    cin >> N >> T >> t;
    REP(i, N-1) {
        ll t_next;
        cin >> t_next;
        if(t + T > t_next) { ans += (t_next - t); }
        else { ans += T; }
        t = t_next;
    }
    printf("%lld\n", ans + T);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
 
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("-ffloat-store")
 
#define int  long long
#define rep(i,begin,end) for(__typeof(end)i=(begin)-((begin)>(end));i!=(end)-((begin)>(end));i+=1-2*((begin)>(end)))
#define F first
#define S second
#define sz(x) ((int)x.size())
#define pb push_back
#define pf push_front
#define eb emplace_back
#define all(v) (v).begin(), (v).end()
#define mod 1000000007
#define what_is(x) cerr << #x << " is " << x <<"\n";
#define sortA(v) sort(v.begin(), v.end())
#define sortD(v) sort(v.rbegin(), v.rend())
#define PI 3.14159265358979323846
#define vout(a) for(auto x:a) cout<<x<<" ";
#define INF (int)(2e18) //1e16
#define oset tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
 
 
using namespace __gnu_pbds;
using namespace std;
 
using ll  = long long;
using vi  = vector<int>;
using vvi = vector<vi>;
using pii = pair<int,int>;
using vii = vector<pii>;
using mi  = multiset<int>;
using mii = multiset<pii>;
using ld  = long double;
 
int lcm(int a,int b) {return (a*(b/__gcd(a,b)));}

int modp(int a,int m,int n)
{
    n=n%(m-1);
    a=a%m;
    int res=1;
    while(n>0)
    {
        if(n&1) res=(res*a)%m;
        a=(a*a)%m;
        n>>=1;
    }
    return res;
}


const int p=(int)1e9+7;



 // const int p=(int)1e9+7;
 
 
 int modInverse(int n, int p) 
 { 
     return modp(n, p, p-2); 
 }
 
 int nCrModP(int n, int r,int p) 
 { 
     if (r==0) return 1; 
     vi fac(n+1); 
     fac[0] = 1; 
     for (int i=1 ; i<=n; i++) fac[i] = fac[i-1]*i%p; 
   
     return (fac[n]*modInverse(fac[n-r],p)%p)%p; 
 }  

void solve()
{
    int n,m,t,i,k,l,r,s,u,v,w,j,pos,sum=0,flag=0,count=0;
    string S,T; 
    // int a,b,da,db;
    cin>>n;
    if(n==1)
    {
        cout<<"0";
        return;
    }
    if(n==2)
    {
        cout<<"2";
        return;
    }
    int ans=(modp(10,mod,n))%mod-2*modp(9,mod,n)+modp(8,mod,n);
    ans+=4ll*mod;
    ans%=mod;
    cout<<ans;
    return;
    // int ans=modp(10,mod,n-2);//-modp(8,mod,n);
    // // cout<<ans;
    // // return;
    // // ans*=2;
    // ans%=mod;
    // ans*=n;
    // ans*=(n-1);
    // // ans/=2;
    // ans%=mod;
    // cout<<ans;
}


signed main()
{
    #ifndef ONLINE_JUDGE 
       freopen("input.txt","r",stdin);
       freopen("output.txt","w",stdout);
    #endif
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--)
    {
        solve();
        if(t)cout<<"\n";
    }
    return 0;
}

Measured memory_bytes: 3608
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>
#include <random>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
//#define int long long

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;
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; }

// constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
// constexpr int MOD = 1'000'000'007;
//inline void modAdd(LL &l, LL &r) {l = (l + r) % MOD;}

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

void solve() {
    int x;
    cin >> x;
    cout << 1 - x << endl;
}

signed main() {
    solve();
    
    return 0;
}

Measured memory_bytes: 3632
#include <cstdio>
#include <vector>
#include <algorithm>
#include <array>
#include <set>
#include <map>
#include <queue>
#include <tuple>
#include <unordered_set>
#include <unordered_map>
#include <functional>
#include <cassert>
#define repeat_from(i, m, n) for (int i = (m); (i) < int(n); ++(i))
using namespace std;
template <class T> inline void setmax(T & a, T const & b) { a = max(a, b); }

int main() {
    while (true) {
        int x, y, s; scanf("%d%d%d", &x, &y, &s);
        if (x == 0 and y == 0 and s == 0) break;
        int result = 0;
        repeat_from (a, 1, s-1) {
            repeat_from (b, 1, s-1) {
                if (a * (100 + x) / 100 + b * (100 + x) / 100 == s) {
                    setmax(result, a * (100 + y) / 100 + b * (100 + y) / 100);
                }
            }
        }
        printf("%d\n", result);
    }
    return 0;
}

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

using namespace std;

typedef long long llint;
typedef long double ld;
#define inf 1e18
#define mod 1000000007
priority_queue<llint,vector<llint>,greater<llint>> que;
//priority_queue<llint> q;

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

void solve(){
  char x;
  cin >> x;
  if(x=='A')cout << 'T';
  if(x=='T')cout << 'A';
  if(x=='C')cout << 'G';
  if(x=='G')cout << 'C';
  cout << endl;

}

int main(int argc, char *argv[]) {
  solve();
  return 0;
}


Measured memory_bytes: 384
#include<stdio.h>
#include<string.h>
#define LEN 1000000
  
typedef struct pp{
  char name[100];
  int t;
}P;
 
P Q[LEN+1];
  
int main(){
  int n, i, q, sum =0, last, cnt=0;
  scanf("%d %d", &n, &q);
  
  for ( i = 1; i <= n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }
  i = 1;
  last = n;
  while(1){
    if(Q[i].t > q){
      sum += q;
      strcpy(Q[last+1].name, Q[i].name);
      Q[last+1].t = Q[i].t - q;
      last++;
    } else {
      sum += Q[i].t;
      printf("%s %d\n", Q[i].name, sum);
      cnt++;
    }
    i++;
    if(cnt == n) break;
  }   
  return 0;
}



Measured memory_bytes: 20952
{-# OPTIONS_GHC -O2 #-}
{-# LANGUAGE BangPatterns          #-}
{-# LANGUAGE CPP                   #-}
{-# LANGUAGE LambdaCase            #-}
{-# LANGUAGE MagicHash             #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE MultiWayIf            #-}
{-# LANGUAGE OverloadedStrings     #-}
{-# LANGUAGE TupleSections         #-}
{-# LANGUAGE TypeFamilies          #-}
{-# LANGUAGE ViewPatterns          #-}

import           Control.Applicative
import           Control.Exception
import           Control.Monad
import           Control.Monad.Primitive
import           Control.Monad.ST
import           Control.Monad.State.Strict
import           Data.Bool
import qualified Data.ByteString             as B
import qualified Data.ByteString.Builder     as B
import qualified Data.ByteString.Char8       as C
import qualified Data.ByteString.Internal    as B
import qualified Data.ByteString.Unsafe      as B
import           Data.Char
import qualified Data.Foldable               as F
import           Data.Function
import qualified Data.IntMap.Strict          as IM
import qualified Data.IntSet                 as IS
import qualified Data.List                   as L
import qualified Data.Map.Strict             as M
import           Data.Monoid
import           Data.Ord
import           Data.Primitive.MutVar
import qualified Data.Set                    as S
import           Data.Tuple
import qualified Data.Vector                 as V
import qualified Data.Vector.Generic         as G
import qualified Data.Vector.Generic.Mutable as GM
import qualified Data.Vector.Storable         as U
import qualified Data.Vector.Unboxed.Mutable as UM
import           Debug.Trace
import           Foreign                     hiding (void)
import           GHC.Exts
import qualified System.IO                   as IO
import           Unsafe.Coerce

main :: IO ()
main = do
    [h, w] <- map read.words <$> getLine :: IO [Int]
    B.PS p 0 l <- C.hGetNonBlocking IO.stdin (h*(w+1))
    let mat = U.unsafeFromForeignPtr0 p l
    print $ solve h (w+1) mat

solve :: Int -> Int -> U.Vector Word8 -> Int
solve h w mat = subtract 1 . U.maximum $ U.zipWith (+) lr ud
  where
    trans :: U.Vector Int -> U.Vector Int
    trans m = U.unsafeBackpermute m $ U.generate (h * w) $ \ij ->
        let (i, j) = quotRem ij w
        in j * h + i

    lr :: U.Vector Int
    lr = U.concatMap (\i ->
          U.scanl1' (\acc x -> if x == 0 then 0 else max acc x)
            . U.postscanr' (\c acc -> if c /= B.c2w '.' then 0 else acc + 1) 0
            $ U.unsafeSlice (i * w) w mat
        )
        $ U.generate h id

    ud :: U.Vector Int
    ud = trans
        . U.concatMap (\j ->
            U.scanl1' (\acc x -> if x == 0 then 0 else max acc x)
              . U.postscanr' (\c acc -> if c /= B.c2w '.' then 0 else acc + 1) 0
              $ U.map (U.unsafeIndex mat) $ U.iterateN h (+w) j
        )
        $ U.generate w id


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

int main() {
 char c;
  cin >> c;
  if (c == 'a' || c == 'e') {
    cout << "vowel" << endl;
  }
  else if (c == 'i' || c == 'o'){
    cout << "vowel" << endl;
  }
  else if ( c == 'u') {
    cout << "vowel" << endl;
  }
  
    else {
      cout << "consonant" << endl;
    }
}  




Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<bitset>
#include<algorithm>
#include<map>
#include<queue>
#include<cmath>
#include<set>
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

int main() {
	int n;
	cin >> n;
	
	long long mod = 1e9 + 7;

	long long ans = 0;
	long long ansA = 1, ansB = 1, ansC = 1;
	for (int i = 1; i <= n; i++) {
		ansA = (ansA * 10) % mod;
		ansB = (ansB * 9) % mod;
		ansC = (ansC * 8) % mod;
	}
	ans = (ansA - 2 * ansB + ansC) % mod;
	ans = (ans + mod) % mod;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3580
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int main(void){
    ll a,b,c,t,s,u;
    cin >> a >> b >> c;
    t = a * b;
    u = 4 * t;
    s = c - a - b;
    if(s>0&&u<s*s)cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

typedef long long ll;

const int INF = 1000000000;
const int MOD = 1000000007;

int main(int argc, char *argv[]) {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    string s; cin >> s;

    ll ans = 0, w = 0;
    for (int i = s.size() - 1; i >= 0; --i) {
        if (s[i] == 'B') ans += w;
        else w++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
int main(void){
  double a,b,H,M;
  cin >> a >> b >> H >> M;
  
  double a_r = 30.0 * H + 0.5 * M;
  double b_r = 6.0 * M;
  
  double g = abs(a_r - b_r);
  
  double x_2 = a * a + b * b - 2 * a * b * cos(g * 3.14159265358979 / 180);
  double ans = sqrt(x_2);
  
  cout << setprecision(20) << ans << endl;
  
  return 0;
}


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

typedef int64_t i64;
typedef uint64_t ui64;

class graph{
public:
    struct adj{
        int index;
        int start;
        int to;
        i64 cost;
    };
    int nd;
    int eg;
    vector<adj> *node;
    vector<adj> edge;
    graph(int n,int m){
        nd=n;
        eg=m;
        node=new vector<adj>[nd]{};
        edge={};
    }
    void add_dir(int i,int s,int t,i64 c){
        node[s].push_back({i,s,t,c});
        edge.push_back({i,s,t,c});
    }
    void add_undir(int i,int s,int t,i64 c){
        node[s].push_back({i,s,t,c});
        node[t].push_back({i,t,s,c});
        edge.push_back({i,s,t,c});
    }
    void refr(void){
        for(int i=0;i<nd;i++) vector<adj>().swap(node[i]);
        delete[] node;
        vector<adj>().swap(edge);
    }
    bool IsLink(void);
    void DFS(int r,i64 *&p,bool *&vst);
    bool IsPlus(void);
    void BellmanFord(int s,i64 *&d);
    void Dijkstra(int s,i64 *&d);
    void BFS(int s,i64 *&d);
    void WarshallFloyd_dir(i64 **&d);
    void WarshallFloyd_undir(i64 **&d);
    i64 WMST_dir(int r);
    i64 WMST_undir(void);
    void Edmonds(int r,vector<adj> &p);
    void Kruscal(vector<adj> &p);
    void Prim(vector<adj> &p);
    void Artic(vector<int> &p);
    void Artic_sub(int r,int &k,int par,vector<int> &p,int *&ord,int *&low,bool *&vst);
    void Bridge(vector<adj> &p);
    void Bridge_sub(int r,int &k,int par,vector<adj> &p,int *&ord,int *&low,bool *&vst);
    void Cumul(int s,i64 *&d);
};

void graph::Bridge(vector<adj> &p){
    int *ord=new int[nd]{};
    int *low=new int[nd]{};
    bool *vst=new bool[nd]{};
    int k=0;
    Bridge_sub(0,k,-1,p,ord,low,vst);
    delete[] ord;
    delete[] low;
    delete[] vst;
}

void graph::Bridge_sub(int r,int &k,int par,vector<graph::adj> &p,int *&ord,int *&low,bool *&vst){
    vst[r]=1;
    ord[r]=low[r]=k;
    k++;
    for(const auto &i:node[r]){
        if(!vst[i.to]){
            Bridge_sub(i.to,k,r,p,ord,low,vst);
            low[r]=min(low[r],low[i.to]);
            if(ord[r]<low[i.to]) p.push_back({i.index,i.start,i.to,i.cost});
        }
        else if(i.to!=par){
            low[r]=min(low[r],ord[i.to]);
        }
    }
}

int main(void){
    int v,e;
    scanf("%i%i",&v,&e);
    graph g(v,e);
    int s,t;
    for(int i=0;i<e;i++){
        scanf("%i%i",&s,&t);
        g.add_undir(i,s,t,1);
    }
    vector<graph::adj> p;
    g.Bridge(p);
    for(auto &i:p){
        if(i.start>i.to){
            int t=i.start;
            i.start=i.to;
            i.to=t;
        }
    }
    sort(p.begin(),p.end(),[](const graph::adj &p1,const graph::adj &p2){
        if(p1.start<p2.start) return 1;
        else if(p1.start>p2.start) return 0;
        else{
            if(p1.to<p2.to) return 1;
            else return 0;
        }
    });
    for(const auto &i:p) printf("%i %i\n",i.start,i.to);
    return 0;
}



Measured memory_bytes: 9004
S = input()
A = int(S[0])
B = int(S[1])
C = int(S[2])
D = int(S[3])
def ope(x,y,n,s):
    if n % 2 == 0:
        return x+y, str(s) + '+' + str(y)
    else:
        return x-y, str(s) + '-' + str(y)
for i in range(8):
    X1, S1 = ope(A,B,i,A)
    j = int(i/2)
    X2, S2 = ope(X1,C,j,S1)
    k = int(j/2)
    X3, S3 = ope(X2,D,k,S2)
    if X3 == 7:
        print(S3 + '=7')
        break


Measured memory_bytes: 3188
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
const int maxn = 1e5 + 5;
int pre[maxn], sum[maxn], x[maxn], y[maxn];
long long ans[maxn];
int find(int x)
{
    return x == pre[x] ? x : pre[x] = find(pre[x]); //这里一开始写错了，写成了x = find。。
}
void join(int a, int b)
{
    a = find(a), b = find(b);
    if(a != b)
    {
        sum[a] += sum[b];
        sum[b] = 0;
        pre[b] = a;
    }
}
int main()
{
    int n, m;
    while(cin >> n >> m)
    {
        for(int i = 0; i < maxn; i++) sum[i] = 1, pre[i] = i;
        memset(ans, 0, sizeof(ans));
        for(int i = 1; i <= m; i++)
        {
            scanf("%d%d", &x[i], &y[i]);
        }
        long long cnt = n;
        ans[m+1] = cnt * (cnt-1) / 2;
        for(int i = m; i >= 2; i--)
        {
            int xx = find(x[i]), yy = find(y[i]);
            if(xx != yy)
            {
                ans[i] = ans[i+1] - sum[xx] * sum[yy];
                join(x[i], y[i]);
            }
            else
                ans[i] = ans[i+1];
        }
        for(int i = 2; i <= m+1; i++)
            printf("%lld\n", ans[i]);
    }

    return 0;
}


Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
int main () {
    int a, b;
    cin >> a >> b;
    int ans = 0;
    for (int i = 1; i <= 12; i++) {
        if (a == i) {
            if (i <= b) {
                ans++;
            }
            break;
        }
        ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
using vi = vector<int>;
using vll = vector<ll>;
ll fast_exp(ll base,ll e){
    ll r=1;
    while(e>0){
        if(e%2)r=(r*base);
        base=base*base;
        e/=2;
    }
    return r;
}
ll gcd(ll a,ll b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s,t;cin>>s>>t;
    vector<vector<int> > matrix(s.size()+1,vector<int> (t.size()+1,0));
    for(int i=1;i<=s.size();i++){
        for(int j=1;j<=t.size();j++){
            if(s[i-1]==t[j-1]){
                matrix[i][j]=1+matrix[i-1][j-1];
            }
            else matrix[i][j]=max(matrix[i-1][j],matrix[i][j-1]);
        }
    }
    int l=matrix[s.size()][t.size()];
    string ans="";
    int i=s.size(),j=t.size();
    while(i>0&&j>0){
        if(s[i-1]==t[j-1]){
            ans+=s[i-1];
            i--;j--;l--;
        }
        else if(matrix[i-1][j]>matrix[i][j-1])i--;
        else j--;
    }
    reverse(ans.begin(),ans.end());
    cout<<ans;
}


Measured memory_bytes: 35584
import java.util.Scanner;
//import java.io.*;
//import java.util.Arrays;
public class Main {
	public static void main(String[] args) throws java.io.IOException {
		Scanner scan = new Scanner(System.in);
		//InputStreamReader is = new InputStreamReader(System.in);
		//BufferedReader br = new BufferedReader(is);
		Main myclass = new Main();
		int H = scan.nextInt();
		int W = scan.nextInt();
		while(H != 0 && W != 0){
			String mozi[] = new String[H];
			char HW[][] = new char[H][W];
			for(int i = 0 ; i < H ; i++){
				mozi[i] = scan.next();
			}
			for(int i = 0 ; i < H ; i++){
				for(int j = 0 ; j < W ; j++){
					HW[i][j] = mozi[i].charAt(j);
				}
			}
			myclass.tadoru(HW , 0 , 0 , H ,W);
			H = scan.nextInt();
			W = scan.nextInt();
		}
	}
	void tadoru(char[][] HW , int x , int y , int H , int W){
		if(HW[y][x] == '>'){
			HW[y][x] = '0';
			if(x+1 < W){
				tadoru(HW , x+1 , y , H , W);
			}else{
				System.out.println("LOOP");
			}
		}else if(HW[y][x] == 'v'){
			if(y+1 < H){
				HW[y][x] = '0';
				tadoru(HW , x , y+1 , H , W);
			}else{
				System.out.println("LOOP");
			}
		}else if(HW[y][x] == '<'){
			HW[y][x] = '0';
			if(x-1 >= 0){
				tadoru(HW , x-1 , y , H , W);
			}else{
				System.out.println("LOOP");
			}
		}else if(HW[y][x] == '^'){
			HW[y][x] = '0';
			if(y-1 >= 0){
				tadoru(HW , x , y-1 , H , W);
			}else{
				System.out.println("LOOP");
			}
		}else if(HW[y][x] == '.'){
			System.out.println(x+" "+y);
		}else{
			System.out.println("LOOP");
		}
	}
}

Measured memory_bytes: 28836
#!/usr/bin/env python3
import sys


def solve(N: int, W: "List[int]"):
    weightSums = [0]*N
    weightSums[0] = W[0]
    for i in range(1, N):
        weightSums[i] = weightSums[i-1] + W[i]
    m = 10**16
    for i in range(1, N-1):
        m = min(m, abs((weightSums[N-1]-weightSums[i]) - weightSums[i]))
    print(m)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    W = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, W)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
# coding: utf-8
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
A = np.array(lr(), dtype=np.int32)
counter = np.bincount(A)
case = (counter * (counter-1) // 2).sum()
answer = case - (counter[A] - 1)
print('\n'.join(map(str, answer)))


Measured memory_bytes: 51644
import java.util.*;
 
public class Main {
	public static void main (String[] args) {
		Scanner in = new Scanner(System.in);
		
		int n = in.nextInt();
      	int lamp[] = new int[n+1];
      
      lamp[0] = -1;
      for(int i = 1;i < n+1;i++){
      lamp[i] = in.nextInt();
      }
      
      int now = lamp[1];int co = 0;
      for(int i = 0;i<n;i++){
        if(now==2){
          	co++;
        	break;
        }else{
        now = lamp[now];
        co++;
        }
      }
      if(co>n-1){System.out.print(-1);}
      else{System.out.print(co);}
      
	}
}


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

int main() {

  long xs[3];
  bool isZero = false;
  for(int i = 0; i < 3; ++i) {
    scanf("%ld", &xs[i]);
    if( xs[i] % 2 == 0 ) isZero = true;
  }
  std::sort(xs, xs + 3);

  if( isZero ) {
    printf("0\n");
  }
  else {
    printf("%ld\n", xs[0] * xs[1]);
  }  
  
  return 0;
}



Measured memory_bytes: 256
N, K = map(int, input().split())
P = list(map(int, input().split()))
ans = 0

E = [(1+p)/2 for p in P]
S = [0]
for i in range(len(E)):
    S.append(S[i] + E[i])

for j in range(K, len(S)):
    ans = max(ans, S[j]-S[j-K])
print(ans)


Measured memory_bytes: 25060
import collections

N, M = map(int, input().split())
A = list(map(int, input().split()))

S = [0 for _ in range(N+1)]
for i in range(len(A)):
    S[i+1] = (S[i]+A[i])%M

c = collections.Counter(S)
ans = 0
for val in c.values():
    ans += (val*(val-1))//2
print(ans)

Measured memory_bytes: 16528
#include <iostream>

int main(){
    int n;
    std::cin>>n;
    bool ans=false;
    for(int i=1;i<10;++i){
        if(n%i==0&&n/i<10){
            ans=true;
            break;
        }
    }
    if(ans){
        std::cout<<"Yes";
    }
    else{
        std::cout<<"No";
    }
    return 0;
}

Measured memory_bytes: 256
<?php

class In {

	private $buf = [];
	private $count = 0;
	private $pointer = 0;

	public function nextLine() {
		$ret = '';
		if($this->hasNext()){
			while($this->hasNext()){
				$ret .= $this->next();
			}
		}else{
			$ret = trim(fgets(STDIN));
		}

		return $ret;
	}

	public function next() {
		if(!$this->hasNext()) {
			$str = trim(fgets(STDIN));
			$this->buf = explode(' ',$str);
			$this->count = count($this->buf);
			$this->pointer = 0;
		}

		return $this->buf[$this->pointer++];
	}

	public function hasNext() {
		return $this->pointer < $this->count;
	}

	public function nextInt() {
		return (int)$this->next();
	}

	public function nextDouble() {
		return (double)$this->next();
	}
}

class Out {
	public function println($str = '') {
		echo $str . PHP_EOL;
	}
}

$in = new In();
$out = new Out();

$N = $in->nextInt();
$A = $in->nextInt();
$B = $in->nextInt();

if ($A > $B) {
	$out->println(0);
	return;
}

if ($N <= 1) {
	if ($A == $B) {
		$out->println(1);
	} else {
		$out->println(0);
	}
	return;
}

$ans = ($N - 2) * ($B - $A) + 1;

$out->println($ans);

?>


Measured memory_bytes: 4856
import java.util.Scanner;

public class Main {

	private void solve() {
		Scanner in = new Scanner(System.in);
		int N = in.nextInt();
		int min = Integer.MAX_VALUE;
		for(int i=1; i<N; i++) {
			int A = i;
			int B = N-i;
			int sum = 0;
			while(A>0) {
				sum += A % 10;
				A /= 10;
			}
			while(B>0) {
				sum += B % 10;
				B /= 10;
			}
			min = Math.min(min, sum);
		}
		System.out.println(min);
	}

	public static void main(String[] args) {
		new Main().solve();
	}
}

Measured memory_bytes: 22100
#include<bits/stdc++.h>
#define int long long

#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define rep(N) for (int i = 0; i < N; ++i)
#define Rep(a, b) for (int i = a; i < b; ++i)
#define For(i, N) for (int i = 0; i < N; ++i)

#define all(v) v.begin(), v.end()
#define rev(v) v.rbegin(), v.rend()

#define mi(N) int N; cin >> N;
#define ms(s) string s; cin >> s;
#define md(d) double d; cin >> d;
#define mv(v, N) vi v(N); rep(N)cin >> v[i];

#define mod 1000000007
#define is_out_of_grid(x, y) x < 0 || y < 0 || x >= h || y >= w

using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vs = vector<string>;
using pii = pair<int, int>;
using pis = pair<int, string>;
using msi = map<string, int>;

template<typename T>
void say(T s) {
	cout << s << "\n";
}

template<typename T>
void say(vector<T> s) {
	auto itr = s.begin();
	cout << *(itr++);
	while (itr != s.end()) {
		cout << " " << *(itr++);
	}
	cout << "\n";
}

template<typename T>
void say(vector<T> s, char r) {
	auto itr = s.begin();
	cout << *(itr++);
	while (itr != s.end()) {
		cout << r << *(itr++);
	}
	cout << "\n";
}

void yn(bool b) {
	if (b)say("yes");
	else say("no");
}

void Yn(bool b) {
	if (b)say("Yes");
	else say("No");
}

void YN(bool b) {
	if (b)say("YES");
	else say("NO");
}

void Yay(bool b) {
	if (b)say("Yay!");
	else say(":(");
}

template<typename T>
void maxi(T& a, T b) {
	a = max(a, b);
}

template<typename T>
void mini(T& a, T b) {
	a = min(a, b);
}

void exact_say(double x) {
	cout << setprecision(numeric_limits<double>::max_digits10) << x << endl;
}

template<typename T>
vector<vector<T>> fill_vector(int h, int w, T val) {
	vector<vector<T>> ret;
	vector<T> v(w, val);
	rep(h)ret.push_back(v);
	return ret;
}


vi enum_div(int n) {
	vi ans;
	for (int i = 1; i * i <= n; ++i) {
		if (n % i == 0) {
			ans.push_back(i);
			if (i != 1 && i * i != n) {
				ans.push_back(n / i);
			}
		}
	}
	ans.push_back(n);
	return ans;
}

signed main() {
	int ans = 0;
	int n;
	cin >> n;
	if (n == 1) {
		cout << 0 << endl;
		return 0;
	}
	vi v = enum_div(n);
	v.erase(v.begin());
	for (int m : v) {
		m--;
		if (n / m == n % m)ans += m;
	}
	cout << ans << endl;
}

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

using namespace std;
#define lint long long
typedef pair<lint, lint> P;

int main() {
    int W, H;
    
    cin >> W >> H;
    
    vector<lint> p(W);
    vector<lint> q(H);
    priority_queue<P,vector<P>, greater<P>> que;
    
    for(int i = 0; i < W ; ++i){
        cin >> p[i];
        que.push(make_pair(p[i], 0));
    }
    for(int i = 0; i < H; ++i){
        cin >> q[i];
        que.push(make_pair(q[i], 1));
    }
    
    int a = W + 1;
    int b = H + 1;
    
    lint cost = 0;
    
    while(!que.empty()){
        auto p = que.top(); que.pop();
        
        if(!p.second){
            cost += p.first * b;
            a--;
        } else {
            cost += p.first * a;
            b--;
        }
    }
    
    cout << cost << endl;
}

Measured memory_bytes: 7664
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<int(n);++i)
#define rep1(i,n) for(int i=1;i<=int(n);++i)
#define all(a) a.begin(),a.end()

int result[1<<16];
vector<string> exps[17];

bool eval(vector<bool> &table,string s,int &i){
    if(isdigit(s[i])) return s[i++] == '1';
    if(s[i] == '-') return !eval(table,s,++i);
    if(isalpha(s[i])) return table[s[i++]-'a'];
    i++; // (
    bool e1 = eval(table,s,i);
    char op = s[i++];
    bool e2 = eval(table,s,i);
    i++; // )
    if(op == '^') return e1^e2;
    if(op == '*') return e1*e2;
}

int get_feature(string &E){
    vector<bool> table(4);
    int k = 0;
    int res = 0;
    rep(a,2)rep(b,2)rep(c,2)rep(d,2){
        table[0] = a;
        table[1] = b;
        table[2] = c;
        table[3] = d;
        int i = 0;
        if(eval(table,E,i)){
            res |= 1<<k;
        }
        k++;
    }
    return res;
}

int main(void){
    rep(i,1<<16){
        result[i] = 20;
    }
    exps[1] = {"a","b","c","d"};
    for(int m = 2; m <= 16; m++){
        for(string E : exps[m-1]){
            if(E[0] == '-') continue;
            exps[m].push_back("-"+E);
        }
        rep1(x,m-2){
            int y = m-3-x;
            if(x>y) continue;
            assert(x>0 && y>0 && x<=y);
            for(string E1 : exps[x]){
                for(string E2 : exps[y]){
                    bool ng = false;
                    for(char ch : {'a','b','c','d'}){
                        string E = E1+E2;
                        if(count(all(E),ch)>1){
                            ng = false;
                        }
                    }
                    if(ng) continue;
                    exps[m].push_back("("+E1+"^"+E2+")");
                    exps[m].push_back("("+E1+"*"+E2+")");
                }
            }
        }
        
    }
    exps[1].push_back("0");
    exps[1].push_back("1");

    rep1(m,16){
        for(string E : exps[m]){
            int f = get_feature(E);
            result[f] = min(result[f], m);
        }
    }

    string E;
    while(cin>>E, E != "."){
        cout<<result[get_feature(E)]<<endl;
    }
    return 0;
}



Measured memory_bytes: 13276
import java.util.Vector;
import java.util.Scanner;

class Main{
	public static void main(String[] args){
		Scanner scan=new Scanner(System.in);
		Vector<Integer> vec=new Vector<>();
		
		int n=scan.nextInt();
		for(int i=0;i<n;i++){
			int com=scan.nextInt();
			if(com==0)
				vec.add(scan.nextInt());
				
			if(com==1)
				System.out.println(vec.elementAt(scan.nextInt()));
				
			if(com==2)
				vec.remove(vec.size()-1);
		}
	}
}


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

int main()
{
  long N; cin >> N;
  
  long ans;
  long root_N = pow(N, 0.5);
  for (long i = root_N; i >= 1; i--)
  {
    long j = N / i;
    if (N == i * j)
    {
      ans = (i - 1) + (j - 1);
      break;
    }
  }
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(s) (s).begin(), (s).end()
#define ALLA(a) a,a+a.size();
using namespace std;
typedef long long unsigned int llu;
typedef long long ll;


struct Node{ int p, l, r;};

const int NIL = -1;

Node T[100005];
int D[100005];

void print(int u){
  cout << "node " << u << ": parent = " << T[u].p << ", depth = " << D[u];
  cout << ", ";
  if(T[u].p == NIL)cout << "root";
  else if(T[u].l != NIL)cout << "internal node";
  else cout << "leaf";

  cout << ", [";
  int ch = T[u].l;
  if(ch != NIL){
    cout << ch;
    ch = T[ch].r;
  }
  while(ch != NIL){
    cout << ", " << ch;
    ch = T[ch].r;
  }
  cout << "]" << endl;
}

void rec(int u, int p){
  D[u] = p;
  
  if(T[u].r != NIL) rec(T[u].r, p);
  if(T[u].l != NIL) rec(T[u].l, p + 1);
}

int main (){
  int n;
  while (cin >> n){

    //配列初期化
    REP(i,n) T[i].p = T[i].l = T[i].r = NIL;

    int l , c, id, k;
    REP(i,n){
      cin >> id >> k;

      //子ノードのループ
      REP(j,k){
	cin >> c;
	//最も左の子だった
        if(j == 0) T[id].l = c;
	//そうでない(一つ前に処理した兄弟にright情報を追加する。)
	else T[l].r = c;
	//前回処理した兄弟のidを記録
	l = c;
	//親を設定する
	T[c].p = id;
      }
    }

    int r;
    REP(i,n){
      //親を持っていない(最上位のノード)
      if(T[i].p == NIL) r = i;
    }

    //深さを格納する配列Dに値を設定
    rec(r , 0);
    //出力する
    REP(i,n)print(i);
   
  }
  return 0;
}



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

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;

const int N = 100010;

int n;
int a[N];

int main()
{
    memset(a, 0x3f, sizeof a);

    scanf("%d", &n);
    for(int i = 1; i <= n; i++) scanf("%d", a + i);

    int res = 0;
    for(int i = 1; i <= n; i++)
    {
        int cnt = 0, j = i;
        while(j <= n && a[j + 1] <= a[j]) j++;
        res = max(res, j - i);
        i = j;
    }

    printf("%d\n", res);
    return 0;
}


Measured memory_bytes: 640
a, b, c, x, y = map(int, input().split())
n = min(x,y)
res = 0
if a+b > c*2:
    prod = c*n*2
    x -= n
    y -= n
    res += prod

if x > y:
    if a - c*2 > 0:
        res += c*2*x
        x -= x
else:
    if b - c*2 > 0:
        res += c*2*y
        y -= y

res += a*x + b*y
print(res)

Measured memory_bytes: 3064
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)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $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, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (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")
    };
}

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        n: usize,
        v: [(i64, i64); n]
    }
    let d = 998244353;
    let mut v: Vec<(i64, i64)> = v.iter().map(|&(x, d)| (x, x + d)).collect();
    v.sort_by_key(|x| x.0);
    let mut t = vec![vec![]; n];
    let mut i = 0;
    while i + 1 < n {
        i = dfs(i, i + 1, &v, &mut t);
    }
    let mut last: Vec<usize> = (0..n).collect();
    let mut done = vec![false; n];
    for i in 0..n {
        if done[i] {
            continue;
        }
        done[i] = true;
        dfs2(i, &t, &mut last, &mut done);
    }
    let mut dp = vec![0; n + 1];
    dp[0] = 1;
    for i in 0..n {
        dp[i + 1] = (dp[i + 1] + dp[i]) % d;
        dp[last[i] + 1] = (dp[last[i] + 1] + dp[i]) % d;
    }
    println!("{}", dp[n]);
}

fn dfs(r: usize, j: usize, v: &Vec<(i64, i64)>, t: &mut Vec<Vec<usize>>) -> usize {
    let n = v.len();
    let mut i = j;
    while i < n {
        if v[r].1 <= v[i].0 {
            break;
        }
        t[r].push(i);
        i = dfs(i, i + 1, v, t);
    }
    i
}

fn dfs2(r: usize, t: &Vec<Vec<usize>>, last: &mut Vec<usize>, done: &mut Vec<bool>) {
    for &v in &t[r] {
        done[v] = true;
        dfs2(v, t, last, done);
        last[r] = max(last[r], last[v]);
    }
}


Measured memory_bytes: 42492
// "include" {{{
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
#include <iomanip>
#include <tuple>
// }}}
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define pii pair<int,int> 
#define int long long
#define setout(n,x) setw(n) << setfill(x)
#define Fixed fixed << setprecision(10)
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const long long mod = 1000000007;

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,m;
	cin >> n >> m;
	vector<pii > stu(n+1);
	vector<pii > pnt(m+1);
	reps(i,n){
		cin >> stu[i].first >> stu[i].second;
	}
	reps(i,m){
		cin >> pnt[i].first >> pnt[i].second;
	}
	reps(i,n){
		pii minv;
		minv = make_pair(LINF,INF);
		reps(j,m){
			if(abs(stu[i].first - pnt[j].first) + abs(stu[i].second - pnt[j].second) < minv.first){
				minv.first = abs(stu[i].first - pnt[j].first) + abs(stu[i].second - pnt[j].second);
				minv.second = j;
			}
		}
		cout << minv.second << '\n';
	}
	return 0;
}


Measured memory_bytes: 256
s = input()
n = len(s)

MOD = 2019
T = [1] + [0] * 2018
d, p = 0, 1
for c in reversed(s):
	d = (d + p * int(c)) % MOD
	p = p * 10 % 2019
	T[d] += 1

print(sum(x * (x - 1) // 2 for x in T))


Measured memory_bytes: 68412
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
using namespace std;
#define ll long long
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define FORL(i,x) for(int i=head[x];i;i=nxt[i])
#define clr(x,y) memset(x,y,sizeof(x))
#define in(a) a=read()
#define out(a) printf("%d\n",a)
inline ll read(){
    char c=getchar();ll f=1,x=0;
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9')x=x*10+(c-'0'),c=getchar();
    return x*f;
}
#define mod 1000000007
void MOD(int &x){if(x>=mod)x-=mod;}
#define maxn 100010
#define inf (1<<30)
struct node{ll a,b;}a[maxn];
bool cmp(node a,node b){return a.a<b.a;}
int main(){
	int n,m;
	in(n);in(m);
	ll ans=0;
	FOR(i,1,n)in(a[i].a),in(a[i].b);
	sort(a+1,a+n+1,cmp);
	FOR(i,1,n){
		if(m>a[i].b){
			m-=a[i].b;
			ans+=a[i].b*a[i].a;
		}
		 else {ans+=a[i].a*m;break;}
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define revrep(i,n,g) for (int i = n-1; i >= g; i--)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int n,p;
  string s;
  cin >> n >> p >> s;
  ll ans = 0;
  if (p == 2 || p == 5) {
    revrep(i,n,0) {
      int k = stoi(s.substr(i,1));
      if (k % p == 0) {
        ans += i + 1;
      }
    }
  } else {
    map<int, int> d;
    d[0] = 1;
    int t = 1;
    int c = 0;
    revrep(i,n,0) {
      int k = stoi(s.substr(i,1));
      c += t * k; c %= p;
      t *= 10; t %= p;
      ans += d[c];
      d[c] += 1;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4020
//                                    ∴In the name of God∴
//                     ✫✗⚡😳😳😄😄😝😝😁😁😎😎😛😛😄😄😮😮⚡✗✫
//                                       H.Pouya  ◠?◠
#include<set>
#include<map>
#include<list>
#include<queue>
#include<stack>
#include<vector>
#include<math.h>
#include<bitset>
#include<iostream>
#include<algorithm>
using namespace std;
typedef short int ss;
typedef long double dd;
typedef long long int ll;
#define give_up return 0;
#define mix(x,y) x*pow(10,y)+10
const ll hp1=999998727899999;
const ll hp2=1012345678901;
const int hp3=2147483647;
const int maxn=mix(2,5);
int main()
{
    int n;
    scanf("%d",&n);
    printf("%d",180*n-360);
    give_up
}
//  🙄


Measured memory_bytes: 256
using System;

class flame {
  static void Main() {
    int H, W;
    string[] str;
    while (true) {
      str = Console.ReadLine().Split();
      H = int.Parse(str[0]);
      W = int.Parse(str[1]);
      if (H == 0 && W == 0) {
        break;
      }
      for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
          if ((i != 0 && i != H-1) && (j != 0 && j != W-1)) {
            Console.Write(".");
          } else {
            Console.Write("#");
          }
        }
        Console.WriteLine();
      }
      Console.WriteLine();
    }
  }
}

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

int main(){
    string S;
    cin >> S;
    if (S[0] == 'R') {
        if (S[1] == 'R') {
            if (S[2] == 'R') {
                cout << 3;
            } else {
                cout << 2;
            }
        } else {
            if (S[2] == 'R') {
                cout << 1;
            } else {
                cout << 1;
            }
        }
    } else {
        if (S[1] == 'R') {
            if (S[2] == 'R') {
                cout << 2;
            } else {
                cout << 1;
            }
        } else {
            if (S[2] == 'R') {
                cout << 1;
            } else {
                cout << 0;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 3620
import sys
input = sys.stdin.readline
rev=0
ST=""
EN=""
S=input()
Q=int(input())
for i in [0]*Q:
 A=list(input().split())
 if int(A[0])==1 :
  rev+=1
 else:
  if (int(A[1])+rev)%2==1:
   ST+=A[2]
  else:
   EN+=A[2]
if rev%2==0:
 print(ST[::-1].strip()+S.strip()+EN.strip())
else:
 print(EN[::-1].strip()+S[::-1].strip()+ST.strip())


Measured memory_bytes: 4980
#include<iostream> 
#include<iomanip> 
#include<vector> 
#include<map> 
#include<set> 
#include<algorithm> 
#include<numeric> 
#include<limits> 
#include<bitset> 
#include<functional> 
#include<type_traits> 
#include<queue> 
#include<stack> 
#include<array> 
#include<random> 
#include<utility> 
#include<cstdlib> 
#include<ctime>
//#define _LIBCPP_DEBUG 0
//#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define all(a) (a).begin(),(a),end()
#define rep(i,n) for (ll i = 0; i < (ll)(n); ++i)	

int max(int a, int b) {
	int max;
	if (a > b) max = a;
	else max = b;
	return max;
}
int min(int a, int b) {
	int min;
	if (a < b) min = a;
	else min = b;
	return min;
}


int main(void) {
	 int a, b, c;
	
		 scanf("%d%d%d", &a, &b, &c);
	
		 int ispoor = 0;
	if (a == b && b != c) ispoor = 1;
	 if (b == c && c != a) ispoor = 1;
	 if (c == a && a != b) ispoor = 1;
	
		 if (ispoor) {
		 puts("Yes");
		
	}
		else {
		 puts("No");
		
	}
	
		 return 0;
	
}


Measured memory_bytes: 888
#include <stdio.h>

#include <iostream>
#include <string>
using namespace std;

int main() {
    string S, T;
    int A, B;
    string U;

    cin >> S >> T;
    cin >> A >> B;
    cin >> U;

    if (S == U) {
        cout << A-1 << " " << B << endl;
    } else {
        cout << A << " " << B-1 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
 
using namespace std;
 
#define MP 999983
#define MAX 1000000
int Prime[MAX+1];
bool prime[MAX+1];
 
void make()
{
    fill(prime, prime+MAX, true);
    prime[0] = prime[1] = false;
 
    for (int i = 2; i*i <= MAX; i++) {
	if (prime[i]) {
	    for (int j = i*i; j <= MAX; j += i) {
		prime[j] = false;
	    }
	}
    }
 
    int sum = 0;
    for (int i = 0; i <= MAX; i++) {
	if (prime[i]) {
	    sum++;
	}
	Prime[i] = sum;
    }
}
 
int main()
{
    int n;
 
    make();
    while (cin >> n, n) {
	int p, m, ans = 0;
	for (int i = 0; i < n; i++) {
	    cin >> p >> m;
 
	    int large = p + m;
	    int small = p - m;
 
	    if (large > MP) {
		large = MP;
	    }     
	    if (small < 0) {
		small = 0;
	    }
	    int X = Prime[large] - Prime[small] + prime[small];
	    if (X == 0) {
		ans--;
	    } else {
		ans += X-1;
	    }
	}
	cout << ans << endl;
    }
    return 0;
}

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

int main() {
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  if(b <= c || d <= a){
    cout << 0 << endl;
  }
  else if(a <= c && b <= d){
    cout << b-c << endl;
  }
  else if(a <= c && d <= b){
    cout << d-c << endl;
  }
  else if(c <= a && d <= b){
    cout << d-a << endl;
  }
  else{
    cout << b-a << endl;
  }
}


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

int dp1[1000001];
int dp2[1000001];

int main() {
	int N = 1000000;

	vector<int> v1,v2;
	int n = 1;
	while(n*(n+1)*(n+2)/6<=N) {
		int p = n*(n+1)*(n+2) / 6;
		v1.push_back(p);
		if(p%2==1)
			v2.push_back(p);
		n++;
	}

	for(int i = 0;i < N+1;i++) {
		dp1[i] = i;
		dp2[i] = i;
	}
	//cout << v1.size() << " " << v2.size() << endl;
	for(auto v : v1) {
		for(int j = v;j < N + 1;j++) {
			dp1[j] = min(dp1[j],dp1[j - v] + 1);
		}
	}
	for(auto v : v2) {
		for(int j = v;j < N + 1;j++) {
			dp2[j] = min(dp2[j],dp2[j - v] + 1);
		}
	}

	while(true) {
		int m;
		cin >> m;
		if(m == 0)
			break;
		cout << dp1[m] << " " << dp2[m] << endl;
	}
	return 0;
	
}


Measured memory_bytes: 10968
# AOJ 0007 Debt Hell
# Python3 2018.6.7 bal4u

a = 100000;
n = int(input())
while n > 0:
	n -= 1
	a = a + (a * 5) // 100
	a = ((a - 1) // 1000 + 1) * 1000   # 1000未満の切り上げ
print(a)


Measured memory_bytes: 5592
#include <stdio.h>

#define N 100000
typedef struct{
char name[10];
int time;
}process;

int isempty(void);
int isfull(void);
void enqueue(process);
process dequeue(void);


int head = 0, tail = 0,q;
process p[N];


int main(){
process x;
int i,n,t = 0;

scanf("%d%d",&n,&q);
for(i = 0; i < n; i++){
scanf("%s%d",x.name,&x.time);
enqueue(x);
}

while(head != tail){
if(p[head].time > q) {
p[head].time = p[head].time-q;
t += q;
enqueue(dequeue());
}

 else if(p[head].time <= q) {
t += p[head].time;
printf("%s %d\n",p[head].name,t);
dequeue();
}
}
return 0;
}


int isempty(){
return head == tail;
}

int isfull(){
return head == (tail + 1)%N;
}

void enqueue(process x){
/*if (isfull()){
ERROR();
exit(1);
}
*/
p[tail] = x;
if(tail + 1 == N-1) tail = 0;
 else tail++;
}

process dequeue(){
process x;

/*if(isempty()){
ERROR();
exit(1);
}
*/
x = p[head];
if(head + 1 == N-1) head = 0;
 else head++;
return x;
}

Measured memory_bytes: 2160
N,M = map(int,input().split())
L = []
for i in range(M):
  L.append(list(map(int,input().split())))
for i in range(M):
  L[i].append(i)
cnt = [0]*N
L = sorted(L, key = lambda x:x[1])
for i in range(M):
  L[i].append(cnt[L[i][0]-1])
  cnt[L[i][0]-1] += 1
L = sorted(L, key = lambda x:x[2])
for i in range(M):
  ID = str(L[i][0]).zfill(6)+str(L[i][3]+1).zfill(6)
  print(ID)

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

int main(){
    int n,b,t,y,r;
    
    for(;;){
        cin >> n;
        if(!n) break;
        
        cin >> y;
        int mn = 0;
        double max = 0;
        while(n--){
            double g = 0;
            cin >> b >> r >> t;
            
            if(t == 1){
                g = 1 + (double)y*r/100;
            }
            else{
                g = pow(1+(double)r/100,y);
            }
            if(max < g){
                max = g;
                mn = b;
            }
        }
        cout << mn << endl;
    }
    
    return 0;
}

Measured memory_bytes: 1164
h1, w1 = gets.chomp.split.map(&:to_i)
arr1, arr2, arr3, cum = [], [], [], Array.new(h1){[0]}
h1.times{arr1 << gets.chomp.split.map(&:to_i)}
h1.times{arr2 << gets.chomp.split.map(&:to_i)}
h3, w3 = gets.chomp.split.map(&:to_i)
h3.times{arr3 << gets.chomp.split.map(&:to_i)}
arr1.each_with_index{|ar, i| ar.each_with_index{|x, j| cum[i][j+1] = cum[i][j] + x}}

max = nil
for y in 0..(h1-h3)
    for x in 0..(w1-w3)
        same = true
        for addy in 0..(h3-1)
            if arr2[y + addy][x, w3] != arr3[addy][0, w3]
                same = false
                break
            end
        end
        if same
            sum = 0
            for addy in 0..(h3-1)
                sum += cum[y + addy][x + w3] - cum[y + addy][x]
            end
            max = sum if max.nil? || max < sum
        end
    end
end
puts max.nil? ? "NA" : max



Measured memory_bytes: 6972