akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef pair<int, int>P;

struct edge { int from, to, cost; };
int p[20], q[20][55], r[20][55], d[100], k[100][100], sum[20][55];
int main() {
	int n, m, c, s, g;
	while (scanf("%d%d%d%d%d", &n, &m, &c, &s, &g), n) {
		vector<P>E[100];
		vector<edge>v[20];
		s--; g--;
		rep(i, m) {
			int x, y, d, c; scanf("%d%d%d%d", &x, &y, &d, &c); x--; y--; c--;
			v[c].push_back({ x,y,d });
		}
		rep(i, c)scanf("%d", &p[i]);
		rep(i, c) {
			rep(j, p[i] - 1)scanf("%d", &q[i][j + 1]);
			q[i][p[i]] = INF;
			rep(j, p[i]) {
				scanf("%d", &r[i][j + 1]);
				if (j)sum[i][j] = sum[i][j - 1] + (q[i][j] - q[i][j - 1])*r[i][j];
			}
		}
		rep(t, c) {
			memset(k, 0x3f, sizeof(k));
			rep(i, n)k[i][i] = 0;
			for (edge j : v[t])k[j.from][j.to] = k[j.to][j.from] = min(k[j.from][j.to], j.cost);
			rep(t, n)rep(i, n)rep(j, n)k[i][j] = min(k[i][j], k[i][t] + k[t][j]);
			rep(i, n)for (int j = i + 1; j < n; j++) {
				if (k[i][j] == INF)continue;
				int u = lower_bound(q[t], q[t] + p[t], k[i][j]) - q[t];
				int y = sum[t][u - 1] + (k[i][j] - q[t][u - 1])*r[t][u];
				E[i].push_back(P(y, j)); E[j].push_back(P(y, i));
			}
		}
		priority_queue<P, vector<P>, greater<P>>que;
		memset(d, 0x3f, sizeof(d));
		d[s] = 0; que.push(P(0, s));
		while (!que.empty()) {
			P p = que.top(); que.pop();
			if (d[p.second] != p.first)continue;
			for (P u : E[p.second]) {
				if (d[u.second] > p.first + u.first) {
					d[u.second] = p.first + u.first;
					que.push(P(d[u.second], u.second));
				}
			}
		}
		if (d[g] == INF)puts("-1");
		else printf("%d\n", d[g]);
	}
}

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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n; string s; cin>>n>>s;
	vector<int>a(n);
	for(int i=0;i<n;++i){
		a.at(i)=s.at(i)%3;
	}
	vector<int64_t>cnt(3);
	for(auto&i:a)++cnt.at(i);
	int64_t ans=1;
	for(auto&i:cnt)ans*=i;
	for(int j=0;j<n;++j){
		for(int i=0;i<j;++i){
			int k=j+(j-i);
			if(k<n){
				if(a.at(i)==a.at(j)||a.at(j)==a.at(k)||a.at(k)==a.at(i))continue;
				--ans;
			}
		}
	}
	cout<<ans<<"\n"s;
}

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

using namespace std;
using ll =long long;
typedef pair<int,int> P;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//Write From this Line

int main()
{
	ll x, y, z, k; 
	cin >> x >> y >> z >> k;
	vector<ll> a(x), b(y), c(z);
	rep(i,x) cin >> a[i];
	rep(i,y) cin >> b[i];
	rep(i,z) cin >> c[i];

	// aとbの組なら全列挙出来る
	vector<ll> ab(0);
	rep(i,x){
		rep(j,y){
			ab.push_back(a[i]+b[j]);
		}
	}
	sort(ab.begin(),ab.end());
	int n = ab.size();

	// abにaとbの和が昇順に入っているがそこからどうしたらいいんだ
	// 各Ciにおける最大値を優先度付きキューにぶちこむ
	priority_queue<pair<ll,int>> pque;
	rep(i,z){
		pque.push({ab[n-1]+c[i], n-1});
	}

	while(k--){
		auto X = pque.top();
		pque.pop();
		ll sum, ind_ab;
		sum = X.first;
		ind_ab = X.second;
		cout << sum << endl;
		sum -= ab[ind_ab];
		if(ind_ab!=0){
			ind_ab--;
			sum += ab[ind_ab];
			pque.push({sum, ind_ab});
		}
	}
}


Measured memory_bytes: 11680
import Data.List

f [] = [[]]
f (x:xs) = concat $ [map (:ys) [x-1,x,x+1]| ys <- f xs]

main = do
	n <- readLn :: IO Int
	as <- map read . words <$> getLine :: IO [Int]

	print $ length $ filter even $ map product (f as)

Measured memory_bytes: 1020
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char** argv){
  int i;
  int j;
  int num;
  int total;
  
  scanf("%d", &num);
  for(i=0; i<num; i++){
    for(j=0; j<num; j++){
      total = 4*i + 7*j;
	  if(total == num) {
		printf("Yes");
		return 0;
      }
    }	
  }
  printf("No");	
}  

Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#define N 100050
#define LL long long
using namespace std;
int n,s=0,t;
int a[N];
int main(){
	scanf("%d",&n);
	a[0]=0;a[n+1]=0;
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		s+=abs(a[i]-a[i-1]);
	}
	s+=abs(a[n+1]-a[n]);
	for(int i=1;i<=n;i++){
		t=s-abs(a[i]-a[i-1])-abs(a[i]-a[i+1])+abs(a[i+1]-a[i-1]);
		printf("%d\n",t);
	}
	return 0;
}
/*
5
5 3 3
2 1 2
2 1 1
4 2 2
4 2 1
2 2 1

*/

Measured memory_bytes: 1664
import kotlin.math.cos

fun main(args: Array<String>) {
  val (N, M, X) = readInts()
  val CA = (1..N).map { readInts() }

  var result = Int.MAX_VALUE
  fun dfs(depth: Int, cost: Int, array: Array<Int>) {
    val afterCost = cost + CA[depth][0]
    val afterArray = array.copyOf()
    (0 until M).forEach { afterArray[it] += CA[depth][it + 1] }

    if (depth + 1 == N) {
//      println(array.joinToString())
//      println(afterArray.joinToString())
      if (array.all { it >= X }) result = Math.min(result, cost)
      if (afterArray.all { it >= X }) result = Math.min(result, afterCost)
    } else {
      dfs(depth + 1, cost, array)
      dfs(depth + 1, afterCost, afterArray)
    }
  }
  dfs(0, 0, Array(M) { 0 })
  println(if (result == Int.MAX_VALUE) -1 else result)
}

fun readString() = readLine()!!
fun readStrings() = readString().split(" ")
fun readInt() = readString().toInt()
fun readLong() = readString().toLong()
fun readInts() = readStrings().map { it.toInt() }
fun readLongs() = readStrings().map { it.toLong() }


Measured memory_bytes: 40432
#include <set>
#include <iostream>
using namespace std;
int main()
{
  int n;
  cin >> n;
  set<int> s;
  for(int i = 0; i < n;i++){
    int a;
    cin >> a;
    auto it = s.find(a);
    if (it == s.end()){
      s.insert(a);
    }else{
      s.erase(it);
    }
  }
  cout << s.size() << endl;
}



Measured memory_bytes: 4992
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <complex>
#include <deque>
#include <valarray>
#include <unordered_map>
#include <unordered_set>
#include <array>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <chrono>
#include <random>
#include <numeric>
using namespace std;
using ll = long long;
using ld = long double;
using str = string;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vs> vvs;
typedef vector<vc> vvc;
typedef vector<vb> vvb;
using P = pair<ll,ll>;
#define REP(i, n) for (ll i = 0; i < (int)(n); i++)
#define RREP(i, n) for (ll i = (int)(n)-1; i > -1 ; i--)
#define IN(T, x) T x;cin >> x;
#define AIN(T, a, n) vector<T> a(n);REP(i, n){cin >> a[i];}
#define A2IN(T1, a, T2, b, n) vector<T1> a(n);vector<T2> b(n);REP(i, n){cin >> a[i] >> b[i];}
#define ALL(a) (a).begin(),(a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) SORT(a);reverse(ALL(a))
#define pb push_back
#define mp make_pair
#define PF first
#define PS second
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 A, size_t N, typename T>void Fill(A (&array)[N], const T &val){fill( (T*)array, (T*)(array+N), val );}
#define OUT(x) cout << x << endl;
#define OUTD(x) cout << fixed << setprecision(12) << x << endl;
#define BOUT(b) if(b){OUT("Yes");}else{OUT("No");}
const ll MOD = 1000000007;
const ll INF = 10e9;
#define PI 3.14159265358979
ll dx[4] = {1,-1,0,0};
ll dy[4] = {0,0,1,-1};
ll ddx[8] = {1,1,1,-1,-1,-1,0,0};
ll ddy[8] = {0,1,-1,0,1,-1,1,-1};

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  IN(ld,A);
  IN(ld,B);
  IN(ll,H);
  IN(ll,M);
  ld hour = (ld)((H*60 + M) % 720) / 360.L;
  ld minute = (ld)M / 30.L;
  ld deg = hour - minute;
  ld ans = sqrt(A*A + B*B - 2*A*B*cos(PI*deg));
  OUTD(ans);
}

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

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  string s;
  cin >> s;
  int n = s.size();
  for (int i = 0; i < n; i++) {
    cout << char('1' + '9' - s[i]);
  }
  cout << endl;

  return 0;
}

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


using namespace std;


using ull = long long;


int main()
{
    ull N, K;
    cin >> N >> K;

    vector<pair<ull, ull>> A;

    for (ull i = 0; i < N; i++) {
        ull a, b;
        cin >> a >> b;
        A.push_back(make_pair(a, b));
    }

    sort(A.begin(), A.end(), [](auto &l, auto &r) { return l.first < r.first; });

    ull now = 1;
    ull ans;
    for (auto e : A) {
        // cout << e.first << ", " << e.second << endl;
        if (now <= K && K < now + e.second) {
            ans = e.first;
            break;
        }
        now += e.second;
    }
    cout << ans << endl;
}


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

#define all(x) (x).begin(),(x).end()
#define puts(x) cout<< x << endl;
#define rep(i,m,n) for(int i=m;i<n;i++)
#define fore(i,a) for(auto i:a)
#define ll long long
using namespace std;

int a,b,c;
int main(){
    cin>>a>>b>>c;
    if((a==b&&a!=c)||(b==c&&a!=b)||(a==c&&a!=b)){
        puts("Yes");
    }else{
        puts("No");
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <limits>
#include <cassert>
#define REP(i,n) for(long (i)=0;(i)<(n);(i)++)
#define REPI(i,a,b) for(long (i)=(a);(i)<(b);(i)++)
#define INF numeric_limits<double>::infinity()
constexpr long MOD = 998244353;
using namespace std;
using P = pair<long, long>;
using VI = deque<long>;

void cut(VI &v) {
    long flag = 0;
    long a = v.front();
    v.pop_front();
    while (1) {
        if (v.empty()) {
            return;
        }
        long b = v.front();
        if (flag == 1) { // increasing
            if (a > b) {
                v.push_front(b);
                return;
            }
            a = b;
            v.pop_front();
        } else if (flag == -1) { //decreasing
            if (a < b) {
                v.push_front(b);
                return;
            }
            a = b;
            v.pop_front();
        } else {
            if (a < b) {
                flag = 1;
            } else if (b < a) {
                flag = -1;
            }
            a = b;
            v.pop_front();
        }
    }
}

int main() {
    long n;
    cin >> n;
    VI as;
    REP(i,n) {
        long a;
        cin >> a;
        as.push_back(a);
    }
    
    long cnt = 0;
    while (as.size()) {
        cut(as);
        cnt++;
    }
    cout << cnt << endl;
}



Measured memory_bytes: 1024
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()

const ll MX = 1e18;

int main () {
    int n; cin >> n;
    __int128 ans = 1;
    bool flag = false;
    rep(i, n) {
        ll a; cin >> a;
        if (a == 0) {
            cout << 0 << endl;
            return 0;
        }
        ans *= a;
        if (ans > MX) flag = true;
    }

    if (flag) {
        cout << -1 << endl;
    } else {
        cout << (ll)ans << endl;
    }

    return 0;
}

Measured memory_bytes: 3636
/*
    Mbak Sana Dong
    Mbak Chaeyoung Dong
*/
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int arr[500500], bit[500500], sana[500500], last[500500];
vector<pair<int,int> > vi[500500];
void add(int x, int val)
{
    for(x;x<=500000;x+=(x&-x)) bit[x] += val;
}
int get(int x)
{
    int res = 0;
    for(x;x>0;x-=(x&-x)) res += bit[x];
    return res;
}
int main()
{
    int n,i,j,k,x,y,ans,curr,temp,m;
    int tc;
    int q;
    cin >> n >> q;
    for(i=1;i<=n;i++) {
        scanf("%d", &arr[i]);
    }
    for(i=1;i<=q;i++) {
        cin >> x >> y;
        vi[y].push_back({i, x});
    }
    for(i=1;i<=n;i++) {
        int now = arr[i];
        if(last[now] > 0) {
            add(last[now], -1);
        }
        last[now] = i;
        add(i, 1);
        for(auto x : vi[i]) {
            sana[x.first] = get(i) - get(x.second - 1);
        }
    }
    for(i=1;i<=q;i++) cout << sana[i] << endl;
    return 0;
}


Measured memory_bytes: 33176
'''A - Signboard
https://atcoder.jp/contests/code-festival-2016-qualb/tasks/codefestival_2016_qualB_a

>>> main('C0DEFESTIVAL2O16')
2
>>> main('FESTIVAL2016CODE')
16
'''


def main(s):
    base = 'CODEFESTIVAL2016'
    count = 0

    for _s, _b in zip(s, base):
        if _s != _b:
            count += 1

    print(count)


if __name__ == "__main__":
    main(input())


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

int main(){
    int n,k,ans=0;cin>>n>>k;
    for(int i=0;i<n;i++){
        int x;cin>>x;
        ans+=min(max(k-x,x-k),x)*2;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;n>i;++i)
using namespace std;
using ll=int64_t;
using vi=vector<int>;
using VI=vector<ll>;
using vis=vector<string>;
using vvi=vector<vi>;
int main(){
    string s;
    cin>>s;
    string hitachi="";
    for(int i=0;5>i;++i){
        hitachi+="hi";
        if(hitachi==s){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
}

Measured memory_bytes: 3596
<?php
fscanf(STDIN, "%s", $s);
$len = strlen($s);
$str = '';
for($i = 0; $i < $len; $i++){
    if($s[$i] === '0'){
        $str .= 0;
    }elseif($s[$i] === '1'){
        $str .= 1;
    }else{
        $str = substr($str, 0, -1);
    }
}
print $str;


Measured memory_bytes: 4984
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b, h, m; 
  cin >> a >> b >> h >> m;

  long double theta = 2 * M_PI * ((long double)h / 12.0 + ((long double)m / 60.0) / 12.0  - (long double)m / 60.0);

  long double c = (long double)(a * a + b * b) - (long double)(2 * a * b) * cosl(theta);

  cout << fixed << setprecision(20) << sqrtl(c);

}


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


public class Main {

	public static void main(String[] args){
		
		
		Scanner sc = new Scanner(System.in);
		List<Integer> firstList  = new ArrayList<>();
		List<String>  secondList = new ArrayList<>();
		
		while(sc.hasNext()){
			
			String next = sc.next();
			
			try{
				int number = Integer.parseInt(next);
				firstList.add(number);
				
			}catch(NumberFormatException e){
				
				for(int i= 0; i < next.length();i++){
					
					secondList.add(String.valueOf(next.charAt(i)));
					
				}
				
			}
			
		}
		
		Main.Dice dice = new Main().new Dice(firstList);
		
		for(String direction : secondList){
			
			dice =dice.roll(direction);
			
		}
		
		System.out.println(dice.showTop());
		
		sc.close();
		

	}
	
	
	class Dice{
		
		private int one;
		private int two;
		private int three;
		private int four;
		private int five;
		private int six;
		
		Dice(List<Integer> arg){
			
			if(arg == null || arg.size() != 6){
				throw new IllegalArgumentException();
			}
			
			this.one  = arg.get(0);
			this.two  = arg.get(1);
			this.three= arg.get(2);
			this.four = arg.get(3);
			this.five = arg.get(4);
			this.six  = arg.get(5);
			
		}
		
		
		Dice roll(String direction){
			int tmp;
			switch(direction){
			
			case "N":
				
				tmp = this.five;
				this.five = this.one;
				this.one  = this.two;
				this.two  = this.six;
				this.six  = tmp;
				break;
				
			case "S":
				tmp = this.five;
				this.five = this.six;
				this.six  = this.two;
				this.two  = this.one;
				this.one  = tmp;
				break;
			case "W":
				tmp = this.one;
				this.one = this.three;
				this.three  = this.six;
				this.six  = this.four;
				this.four  = tmp;
				break;
				
			case "E":
				tmp = this.one;
				this.one = this.four;
				this.four  = this.six;
				this.six  = this.three;
				this.three  = tmp;
				break;
			}
			
			return this;
		}
		
		
		int showTop(){
			return this.one;
		}
	}

}



Measured memory_bytes: 26180
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
typedef long long lng;
#define UP(i,a,b) for(int i=(a); i<=(b); ++i)
#define DOWN(i,b,a) for(int i=(b); i>=(a); --i)
#define REP(i,n) UP(i,0,n-1)
#define ALL(a) (a).begin(), (a).end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end()) //NOTE: <a> must be sorted in advance

lng power(lng b, int n) {lng sol=1; while(n>0) {if(n&1) {sol=sol*b;} n>>=1; b*= b;} return sol;} //calculate b^n

const int MOD = 1000000007; //10^9+7
const double PI = 3.1415926535897932384626;

/*********** variables ************/
int N;
int s[101];
/**********************************/


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin>>N;
    REP(i, N) cin >> s[i];

    int mini = 1<<30;
    int sum = 0;
    REP(i, N) {
        sum += s[i];
        if(s[i]%10!=0&&s[i]<mini) {
            mini = s[i];
        }
    }
    if(sum%10!=0) {
        cout << sum << endl;
    }
    else if(mini!= 1<<30) {
        cout << sum - mini << endl;
    }
    else {
        cout << 0 << endl;
    }
}


Measured memory_bytes: 256
import numpy
def Resistors(n , al):

    ans = 0
    count = 0

    for i in range(n):
        count += 1/al[i]

    return numpy.reciprocal(count)

def main():
    n = int(input())
    al = list(map(int , input().split()))
    print(Resistors(n , al))

if __name__ == '__main__':
    main()

Measured memory_bytes: 12496
#include <iostream>
#include <iomanip> //! for setprecision(10)
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>

using namespace std;

typedef long long LL;

#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define rep(i,n) for (int i = 0; i < (n); ++i)

const int MOD = 1000000007;

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

    int A, B, C, D;
    cin >> A >> B >> C >> D;

    int t = (C+B-1)/B;
    int a = (A+D-1)/D;

    cout << (t <= a ? "Yes" : "No") << endl;

    return 0;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int main() {
    ll h, w;
    cin >> h >> w;
    
    ll ans;
    if (h == 1 || w == 1) {
        ans = 1;
        cout << ans << endl;
        return 0;
    }        
    
    if ((h % 2 == 1) && (w % 2 == 1))
        ans = h * w / 2 + 1;
    if ((h % 2 == 1) && (w % 2 == 0))
        ans = (h-1) * w / 2 + (w / 2);
    if ((h % 2 == 0) && (w % 2 == 1))
        ans = h * (w-1) / 2 + (h / 2);
    if ((h % 2 == 0) && (w % 2 == 0))
        ans = h * w / 2;
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 256
/*@author hussein zayed ;
    ___  ___
   |\  \|\  \
   \ \  \_\  \
    \ \   ___ \USSEIN
     \ \  \\ \ \
      \ \__\\ \_\
       \|__| \|__|
****************************************
*/

#include <bits/stdc++.h>
using namespace std;
#define fr for(int i=0;i<n;++i)
#define fr1 for(int i=1;i<=n;++i)
#define cinA for(int i=0;i<n;++i){cin>>arr[i];}
#define cinA1 for(int i=1;i<=n;++i){cin>>arr[i];}
#define coutA for(int i=0;i<n;++i){cout<<arr[i]<<" ";}
#define ll long long
#define lnarray sizeof(arr)/sizeof(*arr)
#define vi vector<int>
#define vs vector<string>
void Fast()
{
    ios_base :: sync_with_stdio( 0 ) ;
    cin.tie( 0 ) ;
    cout.tie( 0 ) ;
}
inline int RD()
{
    int i ;
    cin>>i;
    return i;
}

inline float RF()
{
    float i ;
    cin>>i;
    return i;
}

inline double RDO()
{
    double i ;
    cin>>i;
    return i;
}

inline string RS()
{
    string i ;
    cin>>i;
    return i;
}

inline ll RLL()
{
    ll i ;
    cin>>i;
    return i;
}

ll sumSet(ll n)
{
    return (1ll*n*(n+1))/2;
}


bool isPrime(int n)
{
    if(n==1)
        return false;
    for(int i=2; i*i<=n; ++i)
    {
        if(n%i==0)
            return false;
    }
    return true;
}
int sumDigit(int n){
int sum =0;
  while (n != 0)
    {
        sum+= + n % 10;
        n = n / 10;
    }
    return sum;
}

ll power2(int n){
  ll ans=(1<<n);
  return ans;
}

ll sumpow2(ll n){
 ll sum=(n*(n+1)*(2*n-1))/6;
 return sum;
}
const int MX=3e5+100;
int n,arr[MX],cm[MX];
int Left,Right,add;
bool can(int x){
 for(int i=1,j=x;j<=n;++i,++j){
  if(cm[j]-cm[i-1]+add>=x){
  Left=i,Right=j;
   return true;}
 }
 return false;
}
int main(){
    Fast();
//freopen("output.txt" , "w" , stdout);
//freopen("wall.in" , "r" , stdin);

   string A=RS(), B=RS(), C=RS();
    cout << A[0] << B[1] << C[2];
 }


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

int main(){
  string s,base="abcdefghijklmnopqrstuvwxyz"; cin>>s;
  int k; cin>>k;
  string t="";
  for(int i=0;i<s.size();i++){
    if(i==s.size()-1){
      int num=((s[i]-'a')+k)%26;
      t+=base[num];
    }else{
      if('z'-s[i]+1<=k && s[i]!='a'){
        t+='a';
        k-=('z'-s[i]+1);
      }else{
        t+=s[i];
      }
    }
  }
  cout<<t<<endl;
}

Measured memory_bytes: 640
import java.util.*;
import static java.util.stream.Collectors.*;

/**
 * @author shengboxu
 */

public class Main {
    public static void main(String [] args)
    {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();

        HashMap<Integer, Integer> hashE = new HashMap<>();
        HashMap<Integer, Integer> hashO = new HashMap<>();
        for (int i = 0; i < n; i++) {
            int in = sc.nextInt();
            if (i % 2 == 0) {
                hashE.put(in, hashE.getOrDefault(in, 0) + 1);
            } else {
                hashO.put(in, hashO.getOrDefault(in, 0) + 1);
            }
        }
    
        List<Map.Entry<Integer, Integer>> listE =
                hashE.entrySet().stream().sorted(Map.Entry.comparingByValue(Comparator.reverseOrder())).collect(toList());
    
        List<Map.Entry<Integer, Integer>> listO =
                hashO.entrySet().stream().sorted(Map.Entry.comparingByValue(Comparator.reverseOrder())).collect(toList());
    
        Map.Entry<Integer, Integer> e1 = listE.get(0);
        Map.Entry<Integer, Integer> e2 = 1 < listE.size() ? listE.get(1) :
                new AbstractMap.SimpleEntry<>(-1,0);
    
        Map.Entry<Integer, Integer> o1 = listO.get(0);
        Map.Entry<Integer, Integer> o2 = 1 < listO.size() ? listO.get(1) :
                new AbstractMap.SimpleEntry<>(-1,0);
        
        if (e1.getKey().equals(o1.getKey())) {
            System.out.println(n - Math.max(e1.getValue() + o2.getValue(),
                    e2.getValue() + o1.getValue()));
        } else {
            System.out.println(n - e1.getValue() - o1.getValue());
        }
    }
}


Measured memory_bytes: 62572
/*
* @Author: Nazrul Islam
* @Date:   2020-09-19 22:49:56
* @Last Modified by:   Nazrul Islam
* @Last Modified time: 2020-09-19 23:45:48
*/

#include<bits/stdc++.h>
using namespace std;
#define IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
typedef long long ll; 
typedef double dd;
typedef vector<int> vi;
typedef vector<char> vc;
typedef list<int> li;
typedef set<int> si;
typedef map<int,int> mp;
#define pb push_back
#define pf push_front
#define mk make_pair
#define sc scanf
#define pr printf
#define pi acos(-1.0)
#define endl '\n'
// char s[200009];
// char st[200009];
// int a[600][600];
// int b[29][10];
// int a[200009];
// int c[200009];
void solve()
{
	ll m, n; 
	cin >> m >> n;
       
    ll cn = 0;
    for(ll i = m; i <= n; i++)
    {
        string s = to_string(i);
        if(s[0] == s[4] && s[1] == s[3]) cn++;
    }
    
    cout << cn << endl;

}
int main()
{
	IO;
	int t; 
	t = 1;
	// cin >> t;
	while(t--)
		solve();
	return 0;
}

Measured memory_bytes: 3776
#include <vector>
#include <iostream>
#include <string>
#include <queue>

using namespace std;

int main() {
  int H, W;
  cin >> H >> W;
  vector<string> board;
  for (int i = 0; i < H; i++) {
    string row;
    cin >> row;
    board.push_back(row);
  }
  queue<vector<int>> q;
  vector<vector<bool> > doneBoard;
  doneBoard.assign(H, vector<bool>(W, false));
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (board[i][j] == '#') {
        q.push(vector<int>({i,j,0}));
        doneBoard[i][j] = true;
      }
    }
  }
  int count = 0;
  while(!q.empty()) {
    auto x = q.front();
    count = max(count, x[2]);
    if (x[0] > 0) {
      if (!doneBoard[x[0]-1][x[1]]){
        q.push(vector<int>({x[0]-1,x[1],count+1}));
        doneBoard[x[0]-1][x[1]] = true;
      }
    }
    if (x[0] < H-1) {
      if (!doneBoard[x[0]+1][x[1]]) {
        q.push(vector<int>({x[0]+1,x[1],count+1}));
        doneBoard[x[0]+1][x[1]] = true;
      }
    }
    if (x[1] > 0) {
      if (!doneBoard[x[0]][x[1]-1]) {
        q.push(vector<int>({x[0],x[1]-1,count+1}));
        doneBoard[x[0]][x[1]-1] = true;
      }
    }
    if (x[1] < W-1) {
      if (!doneBoard[x[0]][x[1]+1]) {
        q.push(vector<int>({x[0],x[1]+1,count+1}));
        doneBoard[x[0]][x[1]+1] = true;
      }
    }
    doneBoard[x[0]][x[1]] = true;
    q.pop();
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 56884
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

	private static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		String s = sc.next();
		Set<String> set = new HashSet<>();
		for (int i = 0; i < s.length(); i++) {
			if (!set.contains(s.charAt(i) + "")) {
				set.add(s.charAt(i) + "");
			} else {
				System.out.println("no");
				return;
			}
		}
		System.out.println("yes");
	}
}

Measured memory_bytes: 23508
n = int(input())
a = list(map(int,input().split()))

d = {}
for i in a:
    if i in d:
        d[i] += 1
    else:
        d[i] = 1
d = sorted(d.items(), key=lambda x:x[0], reverse=True)

m = len(d)
ans = 0
flg = True
for i in range(m):
    k, v = d[i][0], d[i][1]
    if ans == 0:
        if v >= 4:
            ans = k**2
            flg = True
            break
        elif v >= 2:
            ans = k
    elif v >= 2:
        ans *= k
        flg = True
        break
print(ans) if flg else print(0)
        

Measured memory_bytes: 26352
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
typedef long long ll;
using namespace std;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
#define repi(i, n, init) for (ll i = init; i < (n); i++)

int main()
{
    string s;
    cin >> s;
    stack<char> sta;
    repi(i, s.size(), 0)
    {
        if (!sta.empty())
        {
            if (sta.top() == 'S' && s[i] == 'T')
            {
                sta.pop();
            }
            else
            {
                sta.push(s[i]);
            }
        }
        else
        {
            sta.push(s[i]);
        }
    }
    cout << sta.size() << endl;
    return 0;
}

Measured memory_bytes: 644
#include <stdio.h>

void shuffle(char *word, int x)
{
    int j = 0, q = 0, k = 0;
    char text[210];
    for(j = 0; j < x; j++){
        text[j] = *(word + j);
    }
    while(1){
        *(word + q) = *(word + x + q);
        q++;
        if(*(word + x + q) == '\0')
            break;
    }
    while(1){
        *(word + q) = text[k];
        q++;
        k++;
        if(*(word + q) == '\0')
            break;
    }
    
}

int main(void){
    char word[210];
    int x, y, z;
    int j, q, k, a;
    
    while(1){
        scanf("%s", word);
        if(word[0] == '-')
            break;
        scanf("%d", &x);
        for(j = 0; j < x; j++){
            scanf("%d", &y);
            shuffle(word, y);
        }
        printf("%s\n", word);
    }
    return 0;
}


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

int main() {
    int r, D, x[11];
    cin >> r >> D >> x[0];
    
    for(int i = 0; i<10; i++) {
        cout << r*x[i] - D << endl;
        x[i + 1] = r*x[i] - D;
    }
}

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

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

	vector<long long> a(2),b(2);
	for(long long &e : a)
		cin >> e;
	
	for(long long &e : b)
		cin >> e;
	
	priority_queue<long long> heap;
	for(int i = 0;i < 2;++i)
		for(int j = 0;j < 2;++j)
			heap.push(a[i] * b[j]);

	cout << heap.top();	
}


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

using namespace std;

int main()
{
  vector <int> x(3,0);
  cin >> x[0] >> x[1] >> x[2];
  int c = 0;

  while(1)
    {
      sort(x.begin(), x.end());
      if( x[0]==x[1] && x[1]==x[2] )
	break;
      else if( x[0]==x[1] )
	{
	  x[0]++;
	  x[1]++;
	}
      else
	x[0] += 2;
      c++;
    }
  cout << c << endl;
}


Measured memory_bytes: 256
from heapq import heappush, heappop, heapify, heapreplace
from collections import defaultdict
from bisect import bisect_left

class Solution:
    def main(self):
        S = input()
        for i in range(len(S)-1):
            if S[i] == S[i+1]:
                print('Bad')
                break
        else:
            print('Good')

if __name__ == '__main__':
    Solution().main()

Measured memory_bytes: 3444
n,m=map(int,input().split())
nn=''
mm=''
for i in range(m):
  nn=nn+str(n)
for i in range(n):
  mm=mm+str(m)
mm=int(mm)
nn=int(nn)
if nn>mm:
  print(nn)
else:
  print(mm)  


Measured memory_bytes: 2940
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect, bisect_left, bisect_right

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
S = [input() for i in range(N)]
dic = defaultdict(list)

for s in S:
    dic[s[0]].append(s)

L = list(combinations(list("MARCH"), 3))
# print(L)

cnt = 0
for l in L:
    # print(l)
    cnt += len(dic[l[0]]) * len(dic[l[1]]) * len(dic[l[2]])
print(cnt)

Measured memory_bytes: 18700
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getInts(N int) []int {
	ret := make([]int, N)
	for i := 0; i < N; i++ {
		ret[i] = getInt()
	}
	return ret
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer([]byte{}, 1000000)
	N, X, T := getInt(), getInt(), getInt()

	ans := (N + X - 1) / X * T

	out(ans)
}


Measured memory_bytes: 1772
def main():
    n,m=map(int,input().split())
    ans=0
    for i in range(1,min(int(m**0.5//1)+2,m//n+1)):
        if m%i==0:
            if i>=n:
              ans=max(m//i,ans)
            else:
              ans=max(i,ans)
    print(ans)     
if __name__=='__main__':
    main()

Measured memory_bytes: 3060
def main():
    n = list(input())
 
    if n[0] == '1':
        n[0] = '9'
    else:
        n[0] = '1'
 
    if n[1] == '1':
        n[1] = '9'
    else:
        n[1] = '1'
 
    if n[2] == '1':
        n[2] = '9'
    else:
        n[2] = '1'
 
    print(''.join(n))
 
main()

Measured memory_bytes: 3064
import bisect
N, M, X = list(map(int, input().split()))
A = list(map(int, input().split()))
A.sort()
 
index = bisect.bisect_right(A, X)
if X in A:
  print(max(0, min(index - 1, len(A) - index)))
else:
  print(max(0, min(index, len(A) - index)))

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <numeric>
#include <functional>
#include <set>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cctype>
#include <climits>
#include <fstream>
#include <bitset>
#include <time.h>
#include <assert.h>

#define LL long long
#define VI vector<int>
#define VL vector<long long>
#define FOR(i,a,b) for(int i= (a); i<((int)b); ++i)
#define RFOR(i,a) for(int i=(a); i >= 0; --i)
#define FOE(i,a) for(auto i : a)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v,x) (std::find(v.begin(), v.end(), x) != v.end())
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define EPS 1e-14

using namespace std;

const int MAX_V = 100000;
const int MAX_LOG_V = 20;
// ??\???
vector<int> G[MAX_V]; // ??°???????????£??\???????????¨???
int root = 0; // ?????????????????????
int parent[MAX_LOG_V][MAX_V]; // ??????2^k????????£?????°???????????????(???????????????????????´??????-1??¨??????)
int depth[MAX_V]; // ??????????????±???

void dfs(int v, int p, int d) {
    parent[0][v] = p;
    depth[v] = d;
    for (int i = 0; i < G[v].size(); i++) {
        if (G[v][i] != p) dfs(G[v][i], v, d + 1);
    }
}

// ?????????
void init(int V) {
    // parent[0]??¨depth??????????????????
    dfs(root, -1, 0);
    // parent??????????????????
    for (int k = 0; k + 1 < MAX_LOG_V; k++) {
        for (int v = 0; v < V; v++) {
            if (parent[k][v] < 0) parent[k + 1][v] = -1;
            else parent[k + 1][v] = parent[k][parent[k][v]];
        }
    }
}

// u??¨v???LCA????±???????
int lca(int u, int v) {
    // u??¨v?????±??????????????????????????§????????????
    if (depth[u] > depth[v]) swap(u, v);
    for (int k = 0; k < MAX_LOG_V; k++) {
        if ((depth[v] - depth[u]) >> k & 1) {
            v = parent[k][v];
        }

    }
    if (u == v) return u;
    // ????????¢?´¢??§LCA????±???????
    for (int k = MAX_LOG_V - 1; k >= 0; k--) {
        if (parent[k][u] != parent[k][v]) {
            u = parent[k][u];
            v = parent[k][v];
        }
    }
    return parent[0][u];
}

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

    int n, k, c;
    cin >> n;
    
    FOR(i, 0, n) {
        cin >> k;
        FOR(j, 0, k) {
            cin >> c;
            G[i].push_back(c);
            G[c].push_back(i);
        }
    }
    init(n);

    int q, u, v;
    cin >> q;
    FOR(i, 0, q) {
        cin >> u >> v;
        cout << lca(u, v) << "\n";
    }

    return 0;
}

Measured memory_bytes: 23096
#include<bits/stdc++.h>
using namespace std;
int flag=-1;
int main(){
	string s;
	cin>>s;
	for(int i=0;i<s.length();i++){
		if(s[i]=='C'){
			flag=i;
			break;
		}
	}
	if(flag==-1) cout<<"No"<<endl,exit(0);
	else{
		for(int i=flag;i<s.length();i++){
			if(s[i]=='F') cout<<"Yes"<<endl,exit(0);
		}
	}
	cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std; 
  
// function to construct new array 
void constructXOR(int a[], int n) 
{ 
    // calculate xor of array 
    int XOR = 0; 
    for (int i = 0; i < n; i++) 
        XOR ^= a[i]; 
  
    // update array 
    for (int i = 0; i < n; i++) 
        a[i] = XOR ^ a[i]; 
} 
  
// Driver code 
int main() 
{ 
    int n;
    cin >> n;
    int a[n];
    for(int i = 0; i < n; ++i)
        cin >> a[i];
    constructXOR(a, n); 
    for (int i = 0; i < n; i++) 
        cout << a[i] << " "; 
    return 0; 
} 

Measured memory_bytes: 4408
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append(cnt)

    if temp!=1:
        arr.append(1)

    if arr==[]:
        arr.append(1)

    return arr

n = int(input())
if n == 1:
  print(0)
  exit()
f = factorization(n)
ans = 0
sum_list = [1, 3, 6, 10, 15, 21, 28, 36, 45]
for i in f:
  for j, m in enumerate(sum_list):
    if i < m:
      ans += j
      break
print(ans)

Measured memory_bytes: 63376
/*
      author  : nishi5451
      created : 14.08.2020 19:25:35
*/

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


int main(){
    ll n;
    cin >> n;
    string s = to_string(n);
    ll sn = 0;
    rep(i,int(s.size())){
        sn += s[i]-'0';
    }
    if(n%sn==0) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

#define ll long long
#define INF 99999999
#define rep(i,n) for(int i=0,temp=(int)(n);i<temp;++i) //vec.size()がnの時等の高速化
#define all(x) (x).begin(),(x).end()
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define vint vector<int>
#define vvint vector<vector<int>>

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; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

char rev(char b){
  if(b=='A') return 'T';
  if(b=='C') return 'G';
  if(b=='T') return 'A';
  return 'C';

}

int main(){
  char b; cin >> b;
  cout << rev(b) << endl;

  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
  vector<int> a(3);
  for(int i=0;i<3;i++)scanf("%d",&a[i]);
  sort(a.begin(),a.end());
  printf("%d",a[2]-a[0]);
  return 0;
}

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

using namespace std ;
int n , m , ans = 0 ;
int main () {
	cin >> n >> m ;
	if(m == 1) {
		cout << 0 << endl ;
		return 0 ;
	}
	int c = 1 ;
	while(c < m) {
		c += n-1 ;
		ans ++ ;
	}
	cout << ans << endl ;
	return 0 ;
}	

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T> using gpp_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T, typename L> using gpp_map = tree<T, L, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T> using gpp_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;*/
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define bit_exist(x, n) ((x >> n) & 1)
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) { cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl; }
#define mdebug(m) { cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;} }
#define Return(ans) { cout << (ans) << endl; return 0; }
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p){ cout << '(' << p.first << ',' << p.second << ')'; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void Ans(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }
 
using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;
 
//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};
 
const int mod = 1000000007;
//const int mod = 998244353;
//#define Add(x, y) x = (x + (y)) % mod
//#define Mult(x, y) x = (x * (y)) % mod

#include <bits/stdc++.h>
using namespace std;
signed main(){
    int N; cin>>N;
    vec a(N);
    int total = 0;
    REP(i,N){
        cin>>a[i];
        total += a[i];
    }
    int temp = 0;
    int ans = INF;
    REP(i,N-1){
        temp += a[i];
        int rest = total-temp;
        ans = min(ans,abs(temp-rest));
    }
    Out(ans);
}


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

int main() {
  int B,N,K;  
  string S,T;
  cin >> N;
  vector<long long>A(N);
  for(int i=0;i<N;i++){
    cin >> A.at(i);
    A.at(i)=A.at(i)*1000000+i+1;
  }
  std::sort(A.begin(),A.end());
  
  for(int i=0;i<N;i++){
    B=A.at(i)%1000000;
    cout << B ;
    if(i!=(N-1)){
      cout << ' ';
    }
  }

  cout << endl;


}


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

int main() {
  string s;
  cin >> s;
  
  for(int i = 0; i < 4; i++) cout << s.at(i);
  cout << " ";
  for(int i = 4; i < 12; i++) cout << s.at(i);
  cout << endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
  
  public static void main (String[] args){
  
  	Scanner scanner = new Scanner (System.in);
    
  	int N = scanner.nextInt();
    int K = scanner.nextInt();
    int sum = 0;
    
  	for (int i=0; i<N; i++){
      int temp = scanner.nextInt();
      
      if (temp>Math.abs(temp-K)){
        sum+=Math.abs((temp-K)*2);
      } else {
        sum+=temp*2;
      }
    }
    System.out.println(sum);
  }
}

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

int main() {
    int K ; string S ; string ans  = "" ;
    cin >> K ;
    cin >> S ;
    if(K>=S.size())  cout << S ; 
    else {
        for(int i  = 0;i<K;i++) {
            ans = ans+S[i] ;
        }
        ans = ans+"..." ;
        cout << ans ;

    }

}

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

int main()
{
    string s;
    cin >> s;
    int N;
    N=s.size();
    int i;
    bool kaibun=true;
    for(i=0;i<(N-1)/2;i++){
        if(s[i]!=s[N-1-i]){
            kaibun=false;
            break;
        }
    }
    N=(N-1)/2;
    if(kaibun){
        if(((N-1)/2)%2!=0){
            for(i=0;i<(N-1)/2;i++){
                if(s[i]!=s[N-1-i]){
                    kaibun=false;
                    break;
                }
            }
        }else{
            for(i=0;i<N/2;i++){
                if(s[i]!=s[N-1-i]){
                    kaibun=false;
                    break;
                }
            }
        }
    }
    if(kaibun){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n'
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    int n;
    cin >> n;
    vector<pair<int, int>> a(n);
    int x, y;
    REP(i, n) {
        cin >> x >> y;
        a[i] = make_pair(x, y);
    }

    SORT(a);
    for (auto p : a) cout << p.first << " " << p.second << endl;
}



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

int main(){
  string s;
  cin >> s;
  int n = s.size();
  string t,u;
  int ans;
  n -= 2;
  while(true){
    t = s.substr(0,n/2);
    u = s.substr(n/2,n/2);
    if(t.compare(u) == 0){
      ans = t.size();
      break;
    }
    else{
      n -= 2;
      t = "";
      u = "";
    }
  }
  cout << ans*2 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>

// template {{{
using namespace std;

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

using int64 = long long;

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

bool in_field(int W, int H, int x, int y) {
  return (0 <= x && x < W) && (0 <= y && y < H);
}

// pair
template <typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) {
  return s << "(" << p.first << ", " << p.second << ")";
}
// vector
template <typename T> ostream &operator<<(ostream &s, const vector<T> &v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i];
    if (i < len - 1)
      s << "\t";
  }
  return s;
}

// }}}

// url: https://atcoder.jp/contests/tenka1-2019-beginner/tasks/tenka1_2019_c

int N;
string S;

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

  int right_white = 0, right_black = 0;
  int left_white = 0, left_black = 0;
  rep(i, N) {
    if (S[i] == '.') {
      right_white++;
    }
    if (S[i] == '#') {
      right_black++;
    }
  }

  int ans = right_white;
  rep(i, N) {
    if (S[i] == '#') {
      right_black--;
      left_black++;
    }
    if (S[i] == '.') {
      right_white--;
      left_white++;
    }
    ans = min({left_black + right_white, ans});
  }
  cout << ans << endl;

  return 0;
}

// vim: foldmethod=marker


Measured memory_bytes: 832
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,i,j,k;
	cin>>n;
	int mat[n][3];
	for (i=0;i<n;i++)
	cin>>mat[i][0]>>mat[i][1]>>mat[i][2];
	int dp[n][3];
	dp[0][0]=mat[0][0];
	dp[0][1]=mat[0][1];
	dp[0][2]=mat[0][2];
	for (i=1;i<n;i++)
	{
		for (j=0;j<3;j++)
		{
			dp[i][j]=max(dp[i-1][(j+1)%3]+mat[i][j],dp[i-1][(j+2)%3]+mat[i][j]);
		}
	}
	cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
}

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

int main() {
    int n, q;
    cin >> n >> q;
    queue<P> p;

    rep(i, n) {
        string s;
        int t;
        cin >> s >> t;
        p.push(make_pair(s, t));
    }

    int sum = 0;
    while (!p.empty()) {
        P pi = p.front();
        p.pop();

        int t = pi.second - q;
        if (t <= 0) {
            sum += pi.second;
            cout << pi.first << ' ' << sum << endl;
        } else {
            sum += q;
            p.push(make_pair(pi.first, t));
        }
    }

    return 0;
}



Measured memory_bytes: 6224