akhauriyash/Code-Regression huggingface dataset:
/*
    Author:zeke
    
    pass System Test!
    GET AC!!
*/
#include <iostream>
#include <queue>
#include <vector>
#include <iostream>
#include <vector>
#include <string>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
#include <iomanip>
#include <utility>
#include <stack>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rep3(var, min, max) for (ll(var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll(var) = (max)-1; (var) + 1 > (min); --(var))
#define Mp(a, b) make_pair((a), (b))
#define F first
#define S second
#define Icin(s) \
    ll(s);      \
    cin >> (s);
#define Scin(s) \
    ll(s);      \
    cin >> (s);
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;
}
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll MOD = 1e9 + 7;
ll INF = 1e18;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin>>s;
    ll n=s.size();
    V vec1(n+1);
    V vec2(n+1);
    rep(i,s.size()){
        if(s[i]=='<'){
            vec1[i+1]=vec1[i]+1;
        }else{
            vec1[i+1]=0;
        }
    }
    for(int i=s.size()-1;i>=0;i--){
        if(s[i]=='>'){
            vec2[i]=vec2[i+1]+1;
        }else{
            vec2[i]=0;
        }
    }
    ll res=0;
    rep(i,n+1){
     //   cout<<vec1[i]<<" "<<vec2[i]<<endl;
        res+=max(vec1[i],vec2[i]);
    }
    cout<<res<<endl;
}


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

using namespace std;

#define int          long long
#define fast()        ios_base :: sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define all(v)       v.begin() , v.end()
#define ff           first
#define ss           second
#define out(x)       cerr << #x << " is : " << x << endl
#define endl         "\n"

void up()
{
    int x , n;
    cin >> x >> n;
    int ans = -1;
    int a[n];
    int mn = INT_MAX;
    for(int i = 0 ; i < n ; i++) cin >> a[i];
    for(int i = 0 ; i <= 110 ; i++)
    {
        bool cond = true;
        for(int j = 0 ; j < n ; j++)
        {
            if(a[j] == i)
                cond = false;
        }
        if(cond)
        {
            if(abs(x - i) < mn)
            {
                mn = abs(x - i);
                ans = i;
            }
        }
    }
    cout << ans << endl;
    return;
}


int32_t main()
{
    fast();
    up();
    return 0;
}



Measured memory_bytes: 3652
#include<stdio.h>
#include<cstring>
#include<algorithm>
using namespace std;
#define N 100005
#define ll long long

int n,l,r,i,a[N],b[N],c[N];
ll ans;

int main()
{
	scanf("%d",&n);
	for(i=1;i<=n;i++)scanf("%d",&a[i]);sort(a+1,a+n+1);
	for(i=1;i<=n;i++)scanf("%d",&b[i]);sort(b+1,b+n+1);
	for(i=1;i<=n;i++)scanf("%d",&c[i]);sort(c+1,c+n+1);
	l=0,r=1;
	for(i=1;i<=n;i++){
		while(l<n&&a[l+1]<b[i])l++;
		while(r<=n&&c[r]<=b[i])r++;
		ans+=1ll*l*(n-r+1);
	}printf("%lld\n",ans); 
	return 0;
}

Measured memory_bytes: 1280
n, y = map(int, input().split()) ##[1000,1234000]
flg = False

for m in range(n+1):
    for g in range(n-m+1):
        s = n - (m + g)
        ##print(m,g,s)
        if 10000*m + 5000*g + 1000*s == y:
            print('{} {} {}'.format(m, g, s))
            flg = True
        if flg:
            break
    if flg:
        break

if flg == False:
    m, g, s = [-1,-1,-1]
    print('{} {} {}'.format(m, g, s))


Measured memory_bytes: 3064
a = [list(map(int, input().split())) for _ in range(3)]
n = int(input())

for i in range(n):
    b = int(input())
    for r in range(3):
        for c in range(3):
            if a[r][c] == b:
                a[r][c] = 0

is_bingo = False
for i in range(3):
    if sum([a[i][j] for j in range(3)]) == 0:
        is_bingo = True
        break
    if sum([a[j][i] for j in range(3)]) == 0:
        is_bingo = True
        break

if sum([a[j][j] for j in range(3)]) == 0:
    is_bingo = True
if sum([a[j][2 - j] for j in range(3)]) == 0:
    is_bingo = True

ans = 'Yes' if is_bingo else 'No'
print(ans)


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
 
#define mod 1000000007
 
int n,m,cnt,flag1,flag2,s1,s2;
long long k;
char s[2001][2001];
 
long long quickpow(long long base,long long to)
{
	if(to<=0)return 1;
	if(to==1)return base;
	long long mid=quickpow(base,to>>1);
	if(to&1)return mid*mid%mod*base%mod;
	else return mid*mid%mod;
}
 
struct Matrix{
	long long a[3][3];
	Matrix(){memset(a,0,sizeof(a));}
	Matrix operator*(Matrix &m)
	{
		Matrix ans;
		for(int i=1;i<=2;++i)
			for(int j=1;j<=2;++j)
				for(int k=1;k<=2;++k)
					ans.a[i][j]=(ans.a[i][j]+a[i][k]*m.a[k][j]%mod)%mod;
		return ans;
	}
};
 
int main()
{
	scanf("%d%d%lld",&n,&m,&k);
	for(int i=1; i<=n; ++i)
		scanf("%s",s[i]+1);
	for(int i=1; i<=n; ++i)
	{
		for(int j=1; j<=m; ++j)
			if(s[i][j]=='#')
			{
				++cnt;
				s1+=s[i][j-1]=='#';
				s2+=s[i-1][j]=='#';
			}
		if(s[i][1]=='#' && s[i][m]=='#')++flag1;
	}
	for(int i=1;i<=m;++i)if(s[1][i]=='#' && s[n][i]=='#')++flag2;
	if(flag1 && flag2)
	{
		puts("1");
		return 0;
	}
	if(!flag1 && !flag2)
	{
		printf("%lld\n",quickpow(cnt,k-1));
		return 0;
	}
	if(!flag1)swap(flag1,flag2),swap(s1,s2);
	Matrix A;
	A.a[1][1]=cnt;
	A.a[2][1]=s1;
	A.a[2][2]=flag1;
	--k;
	Matrix ANS;
	ANS.a[1][1]=ANS.a[2][2]=1;
	while(k)
	{
		if(k&1)ANS=ANS*A;
		A=A*A;
		k>>=1;
	}
	printf("%lld\n",(ANS.a[1][1]-ANS.a[2][1]+mod)%mod);
}

Measured memory_bytes: 5752
import math
 
X = int(input())
ans = 0
 
while ans == 0:
  factor = 0
  if X % 2 == 0 and X != 2:
    X +=1
    continue      
  for divisor in range(2, X // 2):
    if X % divisor == 0:
      factor += 1          
  if factor == 0:
    ans =X
  X +=1    
    
print(ans) 

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


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

    vector<string> S(N);
    for(int i = 0; i < N; i++){
        cin >> S[i];
    }

    int Ans = 1;

    sort(S.begin(),S.end());
    for(int i = 0; i < N-1; i++){
        if(S[i] != S[i+1]) Ans ++;
    }

    cout << Ans << endl;
}


Measured memory_bytes: 9604
//#include<bits/stdc++.h>
#include<iostream>
#include <stdio.h>
#include<vector>

using namespace std;

//#define io freopen("test.txt", "r", stdin);
#define fast ios_base::sync_with_stdio(0);cin.tie(0);
#define lli long long int
int main(){
    fast 
    //io
    lli n;
    cin>>n;
    if(n>=30) cout<<"Yes\n";
    else cout<<"No\n";

    return 0;
}


Measured memory_bytes: 3044
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
using namespace std;
using ll = long long int;
template<typename T>
ostream& operator+(ostream& out, const vector<T> &vec){
    for(const auto &x : vec){
        out<<x<<" ";
    }
    out<<"\n";
    return out;
}
template<typename T>
ostream& operator*(ostream& out, const vector<T> &vec){
    for(const auto &x : vec){
        out+x;
    }
    return out;
}
template<typename T>
istream& operator>>(istream& in, vector<T> &vec){
    for(auto &x : vec){
        in>>x;
    }
    return in;
}
template<typename T>
struct segment_tree {
    int n;
    vector<T> segtree;
    function<T(const T&,const T&)> join;
    T base = T();
    segment_tree(int n, function<T(const T&,const T&)> join, T base = T()) : n(n), join(join), base(base){
        segtree.resize(n << 1, base);
    }
    void build() {
        for (int i = n - 1; i > 0; --i) {
            segtree[i] = join(segtree[(i << 1)], segtree[(i << 1) | 1]);
        }
    }
    segment_tree(vector<T> seq, function<T(const T&,const T&)> join, T base = T()) : n(seq.size()), join(join), base(base){
        segtree.resize(n << 1, base);
        for (int i = 0; i < n; i++) {
            segtree[n + i] = seq[i];
        }
        build();
    }
    void update(int pos, T val) {
        pos += n;
        segtree[pos] = val;
        pos >>= 1;
        while (pos) {
            segtree[pos] = join(segtree[pos << 1], segtree[(pos << 1) | 1]);
            pos >>= 1;
        }
    }
    T query(int l, int r) {
        T ansl = base;
        T ansr = base;
        l += n;
        r += n + 1;
        while (l < r) {
            if (l & 1) {
                ansl = join(ansl, segtree[l++]);
            }
            if (r & 1) {
                ansr = join(segtree[--r], ansr);
            }
            l >>= 1;
            r >>= 1;
        }
        return join(ansl, ansr);
    }
};
const int MAXA = 3e5 + 7;
void solve(){
    int n,k;
    cin>>n>>k;
    vector<int> seq(n);
    cin>>seq;
    segment_tree<int> segtree(MAXA+1, [&](const int &x, const int &y){
        return (x<y ? y : x);
    }, 0);
    for(int i=0;i<n;i++){
        segtree.update(seq[i], segtree.query(max(0,seq[i]-k), min(MAXA,seq[i]+k)) + 1);
    }
    cout<<segtree.query(0,MAXA)<<"\n";
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
}

Measured memory_bytes: 6636
#include <iostream>
#include <string>

using namespace std;

int main(void) {
	int num, i, j;
	string s, t;
	cin >> num >> s >> t;
	for (i = 0; i < num; i++) {
		for (j = 0; i + j < num; j++) {
			if (s[i + j] != t[j])
				break;
		}
		if (j == num - i)
			break;
	}
	cout << i + num << "\n";
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define sz(x) (int)(x.size()) 
#define fi first
#define se second

signed main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int n;
    cin >> n;
    vector<string> s(n);
    map<string, int> cnt;
    for (int i = 0; i < n; i++) {
        cin >> s[i];
        sort(s[i].begin(), s[i].end());
        cnt[s[i]]++;
    }
    int ans = 0;
    for (auto &el : cnt) {
        ans += el.se * (el.se - 1) / 2;
    }
    cout << ans << "\n";
}


Measured memory_bytes: 16640
use std::cmp::*;
use std::io::*;
fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let n: usize = itr.next().unwrap().parse().unwrap();

    let mut m = n;
    let mut ans = 0;
    while m > 0 {
        ans += m % 10;
        m /= 10;
    }

    let mut f = false;
    for i in 1..6 {
        if n == 10usize.pow(i) {
            f = true;
        }
    }

    if f {
        println!("10");
    } else {
        println!("{}", ans);
    }
}


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

int main() {
  string s;cin>>s;
  int an[26];rep(i,26)an[i]=0;
  for (auto c: s) {
    int x=c - 'a';
    an[x]++;
  }
  rep(i,26) {
    if (an[i]%2==1) {
      cout << "No";
      return 0;
    }
  }
  cout << "Yes";
    
}


Measured memory_bytes: 256
// #pragma GCC optimize("no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// #pragma vector temporal
// #pragma simd
// #pragma GCC diagnostic ignored "-W"

#include<cassert>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<iostream>
#include<iomanip>
#include<sstream>
#include<deque>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<vector>
#include<utility>
#include<functional>
#include<complex>
#include<climits>

// #include<ext/pb_ds/assoc_container.hpp>
// #include<ext/pb_ds/tree_policy.hpp>

using namespace std;
// using namespace __gnu_pbds;

#define ll long long
#define ld long double
#define X first
#define Y second
#define pb push_back
#define eb emplace_back
#define pii pair<int,int>
#define vint vector<int>
#define SS stringstream
#define PQ priority_queue
#define MS(x,v) memset((x),(v),sizeof(x))
#define RZUNI(x) sort(x.begin(),x.end()), x.resize(unique(x.begin(),x.end())-x.begin())
#define FLH fflush(stdout)
#define CPPinput ios_base::sync_with_stdio(0); cin.tie(0)
#define FIN(fname) freopen(fname,"r",stdin)
#define FOUT(fname) freopen(fname,"w",stdout)

#define tm Ovuvuevuevue
#define y1 Enyetuenwuevue
#define left Ugbemugbem
#define ws Osas
#define dec tetteterette
#define exp expexpexpexp
#define expl explexplexpl

#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl

#ifdef WEAK
#include"/home/edison/Coding/cpp/template/debug.cpp"
#define DEB(...) printf(__VA_ARGS__),fflush(stdout)
#define WHR() printf("%s: Line %d",__PRETTY_FUNCTION__,__LINE__),fflush(stdout)
#define LOG(...) printf("%s: Line %d ",__PRETTY_FUNCTION__,__LINE__),printf(__VA_ARGS__),fflush(stdout)
#define DEBUG 1
#define exit(x) cout<<"exit code "<<x<<endl, exit(0)
#else
#define PDE(...) ;
#define DEB(...) ;
#define WHR() ;
#define LOG(...) ;
#define DEBUG 0
#endif

#define lowbit(x) ((x)&(-(x)))

#if __cplusplus >= 201103L
#include<unordered_map>
#include<unordered_set>
#include<tuple>
#endif

void JIZZ(string output=""){cout<<output; exit(0);}

const ld PI=3.14159265358979323846264338327950288;
const ld eps=1e-13;
const ll mod=1e9+7;

pair<int,int> dp[1<<19];

void update(pii &a,pii b){
    vector<int> x;
    x.pb(a.first);
    x.pb(a.second);
    x.pb(b.first);
    x.pb(b.second);
    sort(x.begin(),x.end());
    a=make_pair(x[2],x[3]);
}

int main(){
    CPPinput;
    int k; cin>>k;
    int n=1<<k;
    for(int i=0;i<n;++i)cin>>dp[i].first;
    for(int i=0;i<k;++i){
        for(int j=n-1;j>=0;--j){
            if(j&(1<<i))update(dp[j],dp[j^(1<<i)]);
            PDE(i,j,dp[j]);
        }
    }
    int mx=0;
    for(int i=1;i<n;++i){
        mx=max(mx,dp[i].first+dp[i].second);
        cout<<mx<<'\n';
    }
}


Measured memory_bytes: 7168
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <numeric>
#include <iomanip>
#include <map>
#include <set>
#include <deque>
#include <utility>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define all(vec) vec.begin(), vec.end()
#define MOD 1e9 + 7
#define INF 1e9
#define SENTINEsL 2e9
#define PIE 3.1415a926535

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;}
template <class T>
inline T GCD(T a, T b){if (b == 0) return a; else return GCD(b, a % b);}
template <class T>
inline T LCM(T a, T b) {return (a * b) / GCD(a, b);}

int main(){
    ll n, a, b;
    cin >> n >> a >> b;
    ll sum = (n / (a + b)) * a;
    n -= (a + b) * (n / (a + b));
    if (n <= a)
        sum += n;
    else
        sum += a;
    cout << sum << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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;
}

using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl

ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}


const long long MOD = 1000000007;
const long long INF = 1e9;
const long long LINF = 1LL << 50;
#define int long long

class Union_Find {
private:
	vector<int>par;
	vector<int>rank;
public:
	Union_Find(int n) {
		rep(i, n) {
			par.push_back(i);
			rank.push_back(0);
		}
	}
	int find(int x) {
		if (par.at(x) == x)return x;
		else return par.at(x) = find(par.at(x));
	}
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y)return;
		if (rank.at(x) < rank.at(y)) {
			par.at(x) = y;
		}
		else {
			par.at(y) = x;
			if (rank.at(x) == rank.at(y))rank.at(x)++;
		}
	}
	bool same(int x, int y) {
		return find(x) == find(y);
	}
};

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, k, l; cin >> n >> k >> l;
	Union_Find road(n), train(n);
	rep(i, k) {
		int a, b; cin >> a >> b;
		road.unite(a - 1, b - 1);
	}
	rep(i, l) {
		int a, b; cin >> a >> b;
		train.unite(a - 1, b - 1);
	}
	map<P, int>m;
	rep(i, n) {
		m[P(road.find(i), train.find(i))]++;
	}
	rep(i, n - 1) {
		cout << m[P(road.find(i), train.find(i))] << " ";
	}
	cout << m[P(road.find(n - 1), train.find(n - 1))] << endl;
	return 0;
}

Measured memory_bytes: 18660
using System;
using System.Linq;

class Program
{
    static void Main()
    {
        var input = Console.ReadLine().Split().Select(long.Parse).ToArray();
        var A = input[0];
        var B = input[1];
        var N = input[2];

        long Calc(long x) => (A * x / B) - (A * (x / B));

        Console.WriteLine(Calc(Math.Min(B - 1, N)));
    }
}


Measured memory_bytes: 28056
// https://atcoder.jp/contests/abc120/tasks

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

vector<int> calc_common_divisor(int n) {
    vector<int> common_divisors;

    for (int i = 1; i <= n; i++) {
        if (n%i == 0) {
            common_divisors.push_back(i);
        }
    }

    return common_divisors;
}

int main() {
    int a, b, k; cin >> a >> b >> k;

    vector<int> a_divs = calc_common_divisor(a);
    vector<int> b_divs = calc_common_divisor(b);

    vector<int> common_divs;
    for (int i = 0; i < a_divs.size(); i++) {
        for (int j = 0; j < b_divs.size(); j++) {
            if (a_divs[i] == b_divs[j]) {
                common_divs.push_back(a_divs[i]);
            }
        }
    }

    reverse(common_divs.begin(), common_divs.end());
    cout << common_divs[k-1] << endl;

    return 0;
}

Measured memory_bytes: 256
n = int(input())
s = input()
al = [chr(ord('a') + i) for i in range(26)]
ans = 0
for i in range(n - 1):
    sh = 0
    for j in al:
        if j in s[0:i+1] and j in s[i+1:n]:
            sh += 1
    if sh > ans:
        ans = sh
print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n,k,r,c,i,ir;
	cin>>n>>r;
	if(n>=10){
		cout<<r<<endl;
	}
	else{
		k=n;
		c=10-k;
		i=100*c;
		ir=r+i;
		cout<<ir<<endl;
	}
}

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

int main() {
    int n, cnt=0, v, k, l=0;
    cin >> n;
    int a[n];
    for(int i=0; i<n; i++) {
        cin >> a[i];
    }
    vector<int> g;
    int h = 0;
    for (int h=1; ; ) {
        if (h>n) break;
        g.push_back(h);
        h = 3*h + 1;
        l++;
    }
    for (int i=l; 0<=i; i--) {
        for(int j=g[i]; j<n; j++) {
            v = a[j];
            k = j - g[i];
            while (k>=0 && a[k]>v) {
                a[k+g[i]] = a[k];
                k-=g[i];
                cnt ++;
            }
            a[k+g[i]] = v;
        }
    }
    cout << l << endl;
    for(int i=l-1;0<=i;i--){
        cout << g[i];
        if(i!=0){
            cout << " ";
        }else{
            cout << endl;
        }
    }
    
    cout << cnt << endl;
    
    for(int i=0;i<n;i++){
        cout << a[i] << endl;
    }
    
    return 0;
}


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

#define rep(i, n) for (int i = 0; i < (n); i++)

int main(){
    int N;  
    cin >> N;
    string S;
    cin >> S;
    int A=0,C=0;
    rep(i,N){
        if(S[i] == '(')C++;
        else if(C) C--;
        else A++;
    }
    int B=0;
    C=0;
    for(int i=N-1;0<=i;i--){
        if(S[i] == ')')C++;
        else if(C) C--;
        else B++;
    }

    cout << string(A,'(') << S << string(B,')') << endl;

    return 0;
}

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

using namespace std;
using ll = long long;
#define int ll
using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define PB push_back

const ll INF = (1LL<<60);
const int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }
template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')';
  return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'[';
  REP(i, a.size()) {out<<a[i];if(i!=a.size()-1)out<<',';}
  out<<']';
  return out;
}

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

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

  int n;
  cin >> n;

  int ret = 0;
  for(int i=1; i<=n; i+=2) {
    int tmp = 0;
    FOR(j, 1, i+1) {
      if(i%j==0) tmp++;
    }
    if(tmp==8) ret++;
  }
  cout << ret << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
#include <random>
#include <string.h>
#include <cmath>
using namespace std;
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define int long long
#define P pair<int,int>
#define all(vec) vec.begin(),vec.end()

int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}

int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}

int n;
vector<int> vec[100010];
bool bl[100010];
int cnt[100010];
queue<P> que;

signed main() {
	cin >> n;
	if (n % 2) {
		cout << "First" << endl;
		return 0;
	}
	for (int i = 0; i < n - 1; i++) {
		int a, b; cin >> a >> b;
		vec[a].push_back(b);
		vec[b].push_back(a);
	}
	for (int i = 1; i <= n; i++)if ((int)vec[i].size() == 1) {
		que.push(make_pair(vec[i][0], 0));
		if (bl[vec[i][0]]) {
			cout << "First" << endl;
			return 0;
		}
		bl[vec[i][0]] = true;
	}
	while (!que.empty()) {
		int v = que.front().first, p = que.front().second; que.pop();
		for (int i = 0; i < (int)vec[v].size(); i++) {
			if ((int)vec[vec[v][i]].size() != 2)continue;
			for (int j = 0; j < 2; j++)if (v != vec[vec[v][i]][j]) {
				if (vec[vec[v][i]][j] == p)continue;
				if (bl[vec[vec[v][i]][j]]) {
					cout << "First" << endl;
					return 0;
				}
				bl[vec[vec[v][i]][j]] = true;
				que.push(make_pair(vec[vec[v][i]][j], v));
			}
		}
	}
	for (int i = 1; i <= n; i++) {
		if ((int)vec[i].size() <= 2)continue;
		bool bl2 = true;
		for (int j = 0; j < (int)vec[i].size(); j++)if (!bl[vec[i][j]])bl2 = false;
		if (bl2) {
			cout << "First" << endl;
			return 0;
		}
	}
	cout << "Second" << endl;
}


Measured memory_bytes: 6784
N = int(input())
XY = [list(map(int, input().split())) for _ in range(N)]

def distance(x1, y1, x2, y2):
    dist = ((x1-x2)**2 + (y1-y2)**2) ** (1/2)
    return dist

def factorial(n):
    if n == 1:
        return n
    else:
        return n * factorial(n-1)

ans = 0
for i in range(N):
    for j in range(N):
        if i == j:
            continue
        else:
            x1 = XY[i][0]
            y1 = XY[i][1]
            x2 = XY[j][0]
            y2 = XY[j][1]
            ans += distance(x1, y1, x2, y2)
#            print('============')
#            print(x1, y1, x2, y2)
#            print(distance(x1, y1, x2, y2))

# xxxx
ans /= 2
ans *= 2/N
print(ans)


Measured memory_bytes: 3064
#include <iostream>

using namespace std;

int main(void) {
    int i, j, M, N, X[100010], P[100010], T[100010], Q;
    cin >> N;
    for (i=0;i<N;i++) cin >> T[i];
    cin >> M;
    for (j=0;j<M;j++) cin >> P[j] >> X[j];

    for (j=0;j<M;j++) {
        Q = 0;
        for (i=0;i<N;i++) {
            if (P[j] == i+1) Q += X[j];
            else Q += T[i];
        }
        cout << Q << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define BUF_CLEAR (scanf("%*[^\n]%*c"))

int main(void)
{
	char tbl[256];
	int n, i;
	char cbuf;
	
	while (1){
		scanf("%d", &n);
		BUF_CLEAR;
		if (!n) break;
		for (i = 0; i < 256; i++) tbl[i] = i;
		while (n--){
			scanf("%c", &cbuf);
			scanf(" %c", tbl + cbuf);
			BUF_CLEAR;
		}
		
		scanf("%d", &n);
		BUF_CLEAR;
		while (n--){
			scanf("%c", &cbuf);
			BUF_CLEAR;
			printf("%c", tbl[cbuf]);
		}
		puts("");
	}
	return (0);
}

Measured memory_bytes: 388
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#ifdef _DEBUG_
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl
#else
#define dump(val)
#endif

using namespace std;

typedef long long int ll;

template<typename T>
vector<T> make_v(size_t a, T b) {
    return vector<T>(a, b);
}
template<typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}

#include <functional>
template<typename T>
class SegmentTreeOneAll {
    using Func = function<T(T, T)>;

public:
    vector<T> data;
    int n;
    T init;
    Func update_func;
    Func query_func;
    SegmentTreeOneAll(int _n, T _init, Func up, Func qu) {
        init = _init;
        update_func = up;
        query_func = qu;
        for (n = 1; n < _n; n *= 2)
            ;
        data.resize(2 * n - 1, init);
    }
    void update(int pos, T val) {
        pos += n - 1;
        data[pos] = update_func(data[pos], val);
        while (pos > 0) {
            pos = (pos - 1) / 2;
            data[pos] = query_func(data[2 * pos + 1], data[2 * pos + 2]);
        }
    }
    T query(int l, int r) {
        T res = init;
        for (l += n - 1, r += n - 1; l < r; l = l / 2, r = (r - 1) / 2) {
            if (!(l & 1)) {
                res = query_func(res, data[l]);
            }
            if (!(r & 1)) {
                res = query_func(res, data[r - 1]);
            }
        }
        return res;
    }
};

#include <utility>
using P = pair<int, int>;
using SegmentTree = SegmentTreeOneAll<P>;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, q;
    cin >> n >> q;
    auto Sum = [](P a, P b) {
        a.first += b.first;
        a.second = b.second;
        return a;
    };
    auto Max = [](P a, P b) {
        return max(a, b);
    };
    SegmentTree seg(n, P(0, -n - 1), Sum, Max);
    REP (i, 0, q) {
        int a, v;
        cin >> a >> v;
        seg.update(a - 1, P(v, -a));
        auto res = seg.query(0, n);
        cout << -res.second << " " << res.first << endl;
    }
    return 0;
}



Measured memory_bytes: 19212
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

int main() {
	int N;
	cin >> N;
	
	vector<int> X(N), Y(N), P(N);
	REP(i, N) scanf("%d %d %d", &X[i], &Y[i], &P[i]);
	
	auto compress = [](auto &&v, auto &&cv, auto &z) -> void {
		for (auto &&u : v) cv.emplace_back(u);
		cv.emplace_back(INF);
		cv.emplace_back(-INF);
		cv.emplace_back(0);
		sort(ALL(cv));
		cv.erase(unique(ALL(cv)), cv.end());
		for (auto &&u : v) u = lower_bound(ALL(cv), u) - cv.begin();
		z = lower_bound(ALL(cv), 0) - cv.begin();
	};
	
	vector<int> cx, cy;
	int zx, zy;
	compress(X, cx, zx);
	compress(Y, cy, zy);

	vector<vector<int>> distx(1<<N, vector<int>(cx.size(), INF));
	vector<vector<int>> disty(1<<N, vector<int>(cy.size(), INF));
	vector<int> cntx(1<<N), cnty(1<<N);
	
	auto solve = [N](auto &&v, auto &&z, auto &&cv, auto&& distv, auto &&cntv) -> void {
		REP(s, 1 << N) {
			REP(i, N) if (s >> i & 1) distv[s][v[i]] = 0;
			distv[s][z] = 0;
			
			REP(i, cv.size()) if (i != z && distv[s][i] == 0) ++cntv[s];
			
			REP(i, cv.size() - 1) if (distv[s][i] != INF) chmin(distv[s][i + 1], distv[s][i] + cv[i + 1] - cv[i]);
			for (int i = cv.size() - 1; i > 0; --i) if (distv[s][i] != INF) chmin(distv[s][i - 1], distv[s][i] + cv[i] - cv[i - 1]);
		}
	};
	
	solve(X, zx, cx, distx, cntx);
	solve(Y, zy, cy, disty, cnty);
	
	vector<ll> ans(N + 1, longINF);
	REP(s1, 1 << N) { // 鉄道が通る集落
		for (int s2 = s1;; s2 = (s2 - 1) & s1) { // s1 の内、上下に伸びる鉄道の集合
			int s3 = s2 ^ s1; // 左右
			
			ll cur = 0;
			REP(i, N) cur += (ll)min(distx[s2][X[i]], disty[s3][Y[i]]) * P[i];
			chmin(ans[cntx[s2] + cnty[s3]], cur);
			
			if (s2 == 0) break;
		}
	}
	REP(i, N) chmin(ans[i + 1], ans[i]);
	
	REP(i, N + 1) cout << ans[i] << endl;
	return 0;
}


Measured memory_bytes: 10264
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp111 {
    class Program {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int[] inputInt = new int[2];

            for(int i = 0; i < input.Length; i++)
            {
                inputInt[i] = int.Parse(input[i]);
            }

            int sum = 0;
            for (int i = 0; i < 2; i++) {
                if (inputInt[0] > inputInt[1])
                {
                    sum += inputInt[0];
                    inputInt[0] -= 1;
                }
                else
                {
                    sum += inputInt[1];
                    inputInt[1] -= 1;
                }
            }
            Console.WriteLine(sum);
        }
    }
}

Measured memory_bytes: 13140
import math
import sys

def getinputdata():

    # 配列初期化
    array_result = []
    
    data = input()

    
    array_result.append(data.split(" "))

    flg = 1

    try:


        while flg:

            data = input()

            array_temp = []

            if(data != ""):
                
                array_result.append(data.split(" "))

                flg = 1

            else:

                flg = 0
    finally:


        return array_result





arr_data = getinputdata()

h = int(arr_data[0][0])
w = int(arr_data[0][1])

strdata="ABCDEFGHIJKLMNOPQRSTUVWXYZ"


#width
for i in range(0,w):
   
    #height
    for j in range(0,h):
        
        if arr_data[j+1][i]=="snuke":
#             print(i,j+1)
             print(strdata[i] + str(j+1))


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=((n)-1);(i)>=0;(i)--)
#define itn int
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
using P = pair <int,int>; //to, cost
using WeightedGraph = vector<vector <P>>; //to cost
const long long INF = 1LL << 60;
const int MOD = 1000000007;
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; }
//https://www.creativ.xyz/dump-cpp-652/
#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
 
// vector
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec) is >> x;
    return is;
}
// pair
template <typename T, typename U>
ostream &operator<<(ostream &os, pair<T, U> &pair_var) {
    os << "(" << pair_var.first << ", " << pair_var.second << ")";
    return os;
}
// vector
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
// map
template <typename T, typename U>
ostream &operator<<(ostream &os, map<T, U> &map_var) {
    os << "{";
    repi(itr, map_var) {
        os << *itr;
        itr++;
        if (itr != map_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
// set
template <typename T>
ostream &operator<<(ostream &os, set<T> &set_var) {
    os << "{";
    repi(itr, set_var) {
        os << *itr;
        itr++;
        if (itr != set_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
 
#define DUMPOUT cerr
 
void dump_func() {
    DUMPOUT << endl;
}
template <class Head, class... Tail>
void dump_func(Head &&head, Tail &&... tail) {
    DUMPOUT << head;
    if (sizeof...(Tail) > 0) {
        DUMPOUT << ", ";
    }
    dump_func(std::move(tail)...);
}

#ifdef DEBUG_
#define DEB
#define dump(...)                                                              \
    DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                            \
            << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]"        \
            << endl                                                            \
            << "    ",                                                         \
        dump_func(__VA_ARGS__)
#else
#define DEB if (false)
#define dump(...)
#endif

signed main(void) { cin.tie(0); ios::sync_with_stdio(false);
    int h,n; cin>>h>>n;
    vector <int> a(n);
    rep(i,n) cin>>a[i]; 
    int d = accumulate(all(a),0);
    if(d >= h) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 1024
S = input()

ans = 0
num = len(S) - 1

for i in range(2**num):
    tmp_s = S
    for j in range(num):
        if((i >> j) & 1):
            tmp_s = tmp_s[:num-j] + "+" + tmp_s[num-j:]
    ans += sum(list(map(int, tmp_s.split("+"))))

print(ans)


Measured memory_bytes: 3060
from collections import defaultdict
import sys
import math
from datetime import datetime

def sol(a, b, c, d):
    S = [a, b, c, d]
    for i in range(1<<3):
        ttl = a
        ans = "%s" % a
        for j in range(3):
            if i & (1 << j): # '+'
                ttl += S[j+1]
                ans += "+%s" % S[j+1]
            else:
                ttl -= S[j+1]
                ans += "-%s" % S[j+1]
        if ttl == 7:
            return ans+"=7"
        else:
            assert(True)


do_submit = True
#do_submit = False

def input_parse(input_str):
    lines = [x.strip() for x in input_str.split("\n") if x.strip()]
    parsed_lines = [list(map(str, line.split())) for line in lines]
    print(parsed_lines)
    n = int(parsed_lines[0][0])
    k = int(parsed_lines[0][1])
    S = parsed_lines[1][0]
    return n, k, S


if not do_submit:
    a, b, c = input_parse("""
    3 1
    ABC
    """)
    print(sol(a, b, c))

    a, b, c = input_parse("""
    4 3
    CABA
    """)
    print(sol(a, b, c))

else:
    #a, b, c = list(map(int, input().split()))
    S = input()
    a = int(S[0])
    b = int(S[1])
    c = int(S[2])
    d = int(S[3])
    # S = input()
    # T = input()
    print(sol(a, b, c, d))
    # S = input().strip()
    # print(sol(S))

Measured memory_bytes: 3688
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <cstdio>
#include <string>
#include <numeric>
using namespace std;

int main()
{
    int N;
    cin >> N;
    vector<int> A(N+1, 0);
    for (int i = 0; i < N - 1; ++i)
    {
        int b;
        cin >> b;
        ++A.at(b);
    }

    for (int i = 1; i <= N; ++i){
        cout << A.at(i) << endl;
    }
    return 0;
}

Measured memory_bytes: 4000
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <math.h>
#include <numeric>
#include <set>
#include <list>
#include <bitset>
using namespace std;

int main()
{
    int a, b;
    cin >> a >> b;
    int A = 0;
    for (int i = 1; i < b - a; i++)
    {
        A += i;
    }
    cout << A - a << endl;
    return 0;
}

Measured memory_bytes: 256
/*
String[]の初期化、整数の型がlongになっているか
関数（splitとかcontainsとか）内では"+"とかは正規表現となされるので"\\+"とする
配列のコピーはarr1=arr.clone()
HashSet<>[]はおのおの初期化した？？？？？
 */
import java.util.*;
import java.awt.*;
import java.awt.geom.*;
import static java.lang.System.*;
import static java.lang.Math.*;
public class Main {
    public static void main(String[] $) {
        Scanner sc = new Scanner(in);
        String[] s=sc.next().split("/");
        int m=Integer.parseInt(s[1]);
        int d=Integer.parseInt(s[2]);
        if(m<4){
            out.println("Heisei");
        }else if(m==4){
            if(d<=30)out.println("Heisei");
            else out.println("TBD");
        }else out.println("TBD");
    }
}


Measured memory_bytes: 21844
#include <stdio.h>
int main(void){
    int n,x;
    while(1){
        scanf("%d",&n);
        if(n==-1) break;
       
        if(n<=10) x=1150;
        else if(10<n&&n<=20) x=1150+125*(n-10);
        else if(20<n&&n<=30) x=1150+1250+140*(n-20);
        else x=1150+1250+1400+160*(n-30);
    
        printf("%d\n",4280-x);
    }
    return 0;
}



Measured memory_bytes: 2588
#include <iostream> // cin, cout, cerr
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota
#include <cstdio> // printf, scanf
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <iomanip> // cout<<setprecision(n)
#include <functional> // function<void(int)>
#include <cmath>
#include <cassert>
#include <bitset>

#ifdef DEBUG
#include "debug.hpp"
#else
#define debug(...)
#endif

#define int long long // at least int64 > 9*10^18
#define EL '\n'
#define rep(i,n) for(int i = 0; i < (n); i++)
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
/* libraries */

signed main() {
	int x;
	std::cin >> x;
	int f=x/500;
	int y=(x%500)/5;
	print(f*1000+y*5);
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
	int N, R;
	scanf("%d %d", &N, &R);
	
	if (N<= 10){
		printf("%d", (100*(10-N))+R);
	}else if (N>10){
		printf("%d", R);
	}
	
	
	return 0;
}

Measured memory_bytes: 1660
#include <stdio.h>
#include <string>
#include <sstream>
#include <iostream>

using namespace std;

int main(void)
{
	unsigned int a, b;
	string s, ans;
	
	cin >> a >> b;
	cin >> s;

	//if (&s[a] == "-"){
	if (s.find("-") == a){
		for (int i = 0; i < s.length(); i++){
			if (i != a){
				try{
					stoi(&s[a]);
				}
				catch (invalid_argument e){
					ans = "No";
					break;
				}
			}
			ans = "Yes";
		}
	}
	else{
		ans = "No";
	}

	cout << ans << endl;

	return 0;
}

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

/* 繰り返し自乗法. */
int modPow(long long a, long long n, long long p) {
	if (n == 0) return 1; // 0乗にも対応する場合.
	if (n == 1) return a % p;
	if (n % 2 == 1) return (a * modPow(a, n - 1, p)) % p;
	long long t = modPow(a, n / 2, p);
	return (t * t) % p;
}

int main() {
    int L, R, d;
    cin >> L >> R >> d;

    int cnt = 0;
    for (int i=1; i <= 100; i++) {
        if (i < L) continue;
        if (i > R) break;
        if ((i%d) == 0) cnt++;
    }

    cout << cnt << endl;

    return 0;
}


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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

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

using ll = long long;

using namespace std;

int main() {
  in(int, n);
  vector<int> w(n);
  rep(i, n) cin >> w[i];
  vector<int> s(n + 1);
  rep(i, n) s[i + 1] = s[i] + w[i];
  int ans = 1000000;
  rep(i, n + 1) ans = min(ans, abs(s[n] - 2 * s[i]));
  out(ans);
}


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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int A, B;
  cin >> A >> B;
  if(A * B % 2 != 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

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

int main() {
  int N;
  cin >> N;
  VI a(N);
  ll sum = 0;
  rep(i, N) {
    if ((i + 1) % 3 != 0 && (i + 1) % 5 != 0) {
      sum += (i + 1);
    }
  }
  cout << sum << endl;
}


Measured memory_bytes: 7120
#include <cstdio>
#include <cstring>
#include <algorithm>
char S[11];
int n;
int len;
int ans;

void dfs(int now, int num, bool at, bool af, bool as){
	if(at && af && as && num <= n) ans++;
	if(now > len) return;
	dfs(now + 1, num * 10 + 3, 1, af, as);
	dfs(now + 1, num * 10 + 5, at, 1, as);
	dfs(now + 1, num * 10 + 7, at, af, 1);
}

int main(){
	scanf("%s", S);
	len = strlen(S);
	for(int i = len; i; i--) S[i] = S[i - 1] - '0';
	for(int i = 1; i <= len; i++) n = n * 10 + S[i];
	dfs(1, 0, 0, 0, 0);
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 128
x, y, z = map(int, input().split())
count = z
p = 0
ite = 1
while count < x:
    if ite % 2 == 0:
        if count + y > x:
            break
        else:
            count += y
            p += 1
            ite += 1
    elif ite % 2 != 0:
        if count + z > x:
            break
        else:
            count += z
            ite += 1

print(p)


Measured memory_bytes: 2940
import std.stdio, std.string, std.conv, std.range;
import std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;

enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;


void main() {
    auto a = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51];
    int k;
    scan(k);
    writeln(a[k - 1]);
}



void scan(T...)(ref T args) {
    auto line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront;
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;
    foreach (arg; args) if (x > arg) {
        x = arg;
        isChanged = true;
    }
    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;
    foreach (arg; args) if (x < arg) {
        x = arg;
        isChanged = true;
    }
    return isChanged;
}

void yes(bool ok, string y = "Yes", string n = "No") {
    return writeln(ok ? y : n);
}


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

using namespace std;

#define int long long

int n, ans;

int32_t main() {
    cin >> n;
    for (int i = 1; i * i <= n; i++)
	if (n % i == 0 && i < n / i - 1)
	    ans += n / i - 1;
    return cout << ans, 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using LL=int64_t;
const int INF=0x3f3f3f3f;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin>>n;
    cout<<(24-n)+24;
    return 0;
}


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

int main(){
    int64_t e;
    while(cin >> e && e > 0){
        int64_t x = 0, y = 0, z = 0, m = 1000;
		for (z = 0; z * z * z <= e; z++){
			for (y = 0; y * y + z * z * z <= e; y++){
			    x = e - y * y - z * z * z;
				m = min (m, x + y + z);
			}
		}
        cout << m << endl;
    }
    return 0;
}



Measured memory_bytes: 3072
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define PI 3.14159265358979323846
#define vll vector<long long>
using namespace std;
using ll = long long;
using ld = long double;

// -------------------------------------------------
class UnionFind {
private:
  ll n;
  vll P;
  ll root(ll x);
  void setN(ll N);
  void init();

public:
  UnionFind(ll N);
  void unite(ll x, ll y);
  bool same(ll x, ll y);
};

// コンストラクタ
UnionFind::UnionFind(ll N) {
  setN(N);
  init();
}

// nを変更
void UnionFind::setN(ll N) { n = N; }

// Union-Find Treeを初期化する
void UnionFind::init() {
  P.clear();
  rep(i, n) { P.push_back(i); }
}

// 根の値を返す
ll UnionFind::root(ll x) {
  if (P[x] == x) { return x; }
  return (P[x] = root(P[x])); // パス圧縮しつつ返す
}

// 木を結合する（rankはとりあえず無視）
void UnionFind::unite(ll x, ll y) { P[root(x)] = root(y); }

// xとyが同じ集合にあるか判別
bool UnionFind::same(ll x, ll y) {
  if (root(x) == root(y)) {
    return true;
  } else {
    return false;
  }
}
// -------------------------------------------------

// ----本問について----
// 問題：最小全域木
// 問題文URL：https://onlinejudge.u-aizu.ac.jp/problems/ALDS1_12_A
// 所要時間：
// 学んだこと：
// ------------------

// ----ここから本問のソースコード----

struct edge {
  ll w, s, e; // weight, start, end

  edge(ll W, ll S, ll E) {
    w = W;
    s = S;
    e = E;
  }
};

bool cmpI(const edge &a, const edge &b) { return a.w < b.w; }

// グローバル変数（入力）
ll n;
vector<vll> A;

// 隣接行列から辺の情報を取り出す
vector<edge> MakeEdges() {
  vector<edge> edges;
  rep(i, n) {
    for (ll j = i + 1; j < n; j++) {
      if (A[i][j] != -1) { edges.push_back(edge(A[i][j], i, j)); }
    }
  }
  return edges;
}

// 入力
void input() {
  cin >> n;
  rep(i, n) {
    vll a(n);
    rep(j, n) { cin >> a[j]; }
    A.push_back(a);
  }
}

// 最小全域木の重みの合計を求める（クラスカル法）．
void solve() {
  vector<edge> edges = MakeEdges();
  // 辺を重みをキーに昇順ソート
  sort(edges.begin(), edges.end(), cmpI);
  UnionFind u(n);
  ll ans = 0;
  rep(i, edges.size()) {
    if (!u.same(edges[i].s, edges[i].e)) { // 閉路ができない
      u.unite(edges[i].s, edges[i].e);
      ans += edges[i].w;
    }
  }
  cout << ans << endl;
}

int main() {
  input();
  solve();
  return 0;
}



Measured memory_bytes: 3136