akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<cctype>
#include<string>
using namespace std;

int main(){
    int i,n,t,h;
    string tc,hc;
    cin >> n;
    t=0;
    h=0;
    for(i=0; i<n; i++){
        cin >> tc >> hc;
        if(tc==hc){t++; h++;}
        else if(tc<hc)h=h+3;
        else if(tc>hc)t=t+3;
    }
    cout << t << " " << h << endl;
    return 0;
}


Measured memory_bytes: 3132
#include <stdio.h>
#include <vector>
#include <set>
#include <queue>
#define MOD 998244353

struct str{
	int x0;
	int y0;
	int z0;
	long long int value;
};
bool operator<(str a, str b)
{
	return a.x0+a.y0+a.z0>b.x0+b.y0+b.z0;
}
std::priority_queue<str> Q;
int a;
long long int power(long long int a, long long int b)
{
	long long int s = 1;
	long long int t = a;
	while(b)
	{
		if(b%2==1) s *= t, s%=MOD;
		t*=t, t%=MOD;
		b/=2;
	}
	return s;
}

std::vector<int> ans[5];
std::set<int> V[5][100010];
int check[100010];
std::pair<int,int> edge[5][100010];
void func(int C)
{
	std::vector<int> V2,V3,V4;
	for(int i=a;i>=1;i--) V2.push_back(i);
	while(V2.size()>0)
	{
		V4.clear();
		V3.clear();
		for(int i=0;i<V2.size();i++) check[V2[i]] = 0;
		for(int i=0;i<V2.size();i++)
		{
			if(check[V2[i]]==0)
			{
				check[V2[i]] = 1;
				V4.push_back(V2[i]);
				std::set<int> ::iterator it;
				for(it=V[C][V2[i]].begin();it!=V[C][V2[i]].end();it++)
				{
					int v;
					if(edge[C][*it].first!=V2[i]) v = edge[C][*it].first;
					else v = edge[C][*it].second;
					check[v] = 1;
					V[C][v].erase(*it);
				}
			}
			else V3.push_back(V2[i]);
		}
		
		long long int sum = 0;
		for(int i=0;i<V4.size();i++)
		{
			sum += power(10,18*V4[i]);
			sum %= MOD;
		}
		ans[C].push_back(sum);
		
		V2.clear();
		V2 = V3;
	}
}

int check1[510][510],check2[510][510],check3[510][510];
int main()
{
	int b,c,d;
	scanf("%d",&a);
	scanf("%d",&b);
	for(int i=1;i<=b;i++)
	{
		int s,t;
		scanf("%d%d",&s,&t);
		edge[1][i] = std::make_pair(s,t);
		V[1][s].insert(i);
		V[1][t].insert(i);
	}
	scanf("%d",&c);
	for(int i=1;i<=c;i++)
	{
		int s,t;
		scanf("%d%d",&s,&t);
		edge[2][i] = std::make_pair(s,t);
		V[2][s].insert(i);
		V[2][t].insert(i);
	}
	scanf("%d",&d);
	for(int i=1;i<=d;i++)
	{
		int s,t;
		scanf("%d%d",&s,&t);
		edge[3][i] = std::make_pair(s,t);
		V[3][s].insert(i);
		V[3][t].insert(i);
	}
	func(1);
	func(2);
	func(3);
	
	long long int sum = 0;
	for(int i=0;i<ans[1].size()+ans[2].size()-1;i++)
	{
		for(int j=0;j<ans[1].size();j++)
		{
			//j, i-j
			if(i-j<0) continue;
			if(i-j>=ans[2].size()) continue;
			for(int k=0;k<ans[3].size();k++)
			{
				if(check1[j][k]) continue;
				if(check2[i-j][k]) continue;
				long long int s = ans[1][j];
				s *= ans[2][i-j], s%=MOD;
				s *= ans[3][k], s %= MOD;
				sum +=s, sum%=MOD;
				check1[j][k] = check2[i-j][k] = 1;
				break;
			}
		}
	}
	printf("%lld",sum);
}

Measured memory_bytes: 58356
# coding: utf-8

def main():
    S = input()
    target = "keyence"

    if len(S) >= 7 and S[0:7] == "keyence":
        return "YES"

    for i in range(len(S)):
        if S[i] != target[i]:
            itti_len = i
            break

    latter = target[itti_len:7]

    if S[len(S)-(7-itti_len):len(S)] == latter:
        return "YES"
    else:
        return "NO"


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

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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;++A)
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////
#define MOD (ll)(1e9+7)
ll moddiv(ll a,ll b){
    a %= MOD;
    b %= MOD;
    for(ll m=MOD-2;m>0;m/=2){
        if(m&1){
            a=a*b%MOD;
        }
        b=b*b%MOD;
    }
    return a;
}
ll powl(ll a,ll b){
    if(b==0)
        return 1;
    ll c = powl(a * a%MOD, b / 2);
    return (c * (b & 1 ? a : 1)) % MOD;
}


ll N,A,B;
ll i, j, k,ans;

int main(){
    scanf("%lld%lld%lld", &N,&A,&B);
    
    ans = powl(2,N);
    j = 1;
    fornum(i,0,A){
        j = moddiv(j * (N - i), i + 1);
    }
    ans = (ans - j + MOD) % MOD;
    j = 1;
    fornum(i,0,B){
        j = moddiv(j * (N - i), i + 1);
    }
    ans = (ans - j + MOD) % MOD;

    printf("%lld", (ans - 1 + MOD) % MOD);

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,x;
  cin >> n;
  vector<int> hash(2*n);
  for(int i = 0; i < 2*n ; i++){
    cin >> x;
    hash[i] = x;
  }
  sort(hash.begin(),hash.end());
  int sum = 0;
  for(int i = 0; i<2*n ; i+=2){
    sum = sum + hash[i];
  }
  cout<<sum;
}

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

// gropus(vector and is_cycle)
using Edges = multiset<pair<int, int>>;
using Graph = map<int, pair<vector<int>, bool>>;
using GraphID = map<int, int>;
using Component = tuple<Edges, Graph, GraphID, int>;

vector<vector<int>> tree;
vector<int> ans;
vector<pair<int, int>> colors;

int get_id(const GraphID &idm, int key) {
    auto ite = idm.find(key);
    if(ite == idm.end()) return -1;
    else return ite->second;
}

int add_node(Graph &graph, GraphID &gid, int node) {
    graph[node] = make_pair(vector<int>(1, node), false);
    gid[node] = node;
    return node;
}

int add_edge(Edges &edges, Graph &graph, GraphID &gid, pair<int, int> edge) {
    int a, b;
    tie(a, b) = edge;
    if(b < a) swap(a, b);
    edges.emplace(a, b);
    
    int id_a = get_id(gid, a);
    if(id_a == -1) id_a = add_node(graph, gid, a);
    
    int id_b = get_id(gid, b);
    if(id_b == -1) id_b = add_node(graph, gid, b);

    if(id_a == id_b) {
        int ret = !graph[id_a].second;
        graph[id_a].second = true;
        return ret;
    }

    auto g1 = move(graph[id_a].first);
    auto g2 = move(graph[id_b].first);
    bool ba = graph[id_a].second;
    bool bb = graph[id_b].second;
    int ret = !ba || !bb;

    graph.erase(id_a);
    graph.erase(id_b);

    if(g1.size() < g2.size()) {
        swap(id_a, id_b);
        swap(g1, g2);
    }
    for(auto &&node : g2) {
        g1.push_back(node);
        gid[node] = id_a;
    }

    graph[id_a] = move(make_pair(move(g1), ba || bb));
    return ret;
}

void add_edge(Component &component, pair<int, int> edge) {
    int ret = add_edge(get<0>(component), get<1>(component), get<2>(component), edge); 
    get<3>(component) += ret;
}

void merge(Component &v, Component &u) {
    auto v_e = move(get<0>(v));
    auto u_e = move(get<0>(u));
    if(v_e.size() < u_e.size()) {
        swap(v, u);
        swap(v_e, u_e);
    }
    auto v_g = move(get<1>(v));
    auto v_id = move(get<2>(v));
    auto cnt = get<3>(v);

    for(auto &&edge : u_e) cnt += add_edge(v_e, v_g, v_id, edge);
    v = move(make_tuple(move(v_e), move(v_g), move(v_id), cnt));
}

Component dfs(int cur, int pre = -1) {
    Component component;
    for(int nxt : tree[cur]) if(nxt != pre) {
        auto rec = dfs(nxt, cur);
        merge(component, rec);
    }
    add_edge(component, colors[cur]);
    ans[cur] = get<3>(component);
    return component;
}

int main() {
    int N, K;
    cin >> N >> K;
    ans.resize(N);
    tree.resize(N);
    colors.resize(N);
    for(int i = 1; i < N; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        tree[a].push_back(b);
        tree[b].push_back(a);
    }
    for(int i = 0; i < N; i++) {
        int c, d;
        cin >> c >> d;
        if(d < c) swap(c, d);
        colors[i] = make_pair(c, d);
    }
    dfs(0);
    for(auto ele : ans) cout << ele << endl;
    return 0;
}



Measured memory_bytes: 48196
using System;
class ProgramB
    {
        static void Main(string[] args)
        {
            
            //入力
            string input = Console.ReadLine();
            long n = long.Parse(input);
            string s = Console.ReadLine();
            long count = 0;


            for(int i = 0;i < n - 2;i++) 
            {
                if(s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C')
                {
                    count++;
                    i += 2;
                }
            }

            Console.WriteLine(count);
                
        }
    }

Measured memory_bytes: 13140
#include <cstdio>
#include <cctype>
#include <utility>
#include <vector>
#include <algorithm>
using namespace std;

#define gcu getchar_unlocked
#define pcu putchar_unlocked
#define _T template <typename T>
#define _HT template <typename H, typename... T>
#define _il inline
#define _in _il int in
#define _sc _il bool scan
_T T in(int c){T n=0;bool m=false;while(isspace(c)){c=gcu();}if(c=='-')m=true,c=gcu();
	do{n=10*n+(c-'0'),c=gcu();}while(c>='0'&&c<='9');return m?-n:n;}
_in() {return in<int>(gcu());}
_T T scan(T &n){int c=gcu();return c==EOF?false:(n=in<T>(c),true);}
_sc(char &c){c=gcu();gcu();return c!=EOF;}
#ifdef _GLIBCXX_STRING
_sc(string &s){int c;s="";
	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=c;}}
#endif
_HT _sc(H &h, T&&... t){return scan(h)&&scan(t...);}
#define _vo _il void out
#define _vl _il void outl
_vo(bool b) {pcu('0'+b);}
_vo(const char *s){while(*s)pcu(*s++);}
_vo(char c){pcu(c);}
#ifdef _GLIBCXX_STRING
_vo(string s){for(char c:s)pcu(c);}
#endif
_T _vo(T n){static char buf[20];char *p=buf;
	if(n<0)pcu('-'),n*=-1;if(!n)*p++='0';else while(n)*p++=n%10+'0',n/=10;
	while (p!=buf)pcu(*--p);}
_vl(){out('\n');}
#ifdef _GLIBCXX_VECTOR
_T _vo(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);outl();}
#endif
_HT _vo(H&& h, T&&... t){out(h);out(move(t)...);}
template <typename... T> _vl(T&&... t){out(move(t)...);outl();}

int main() {
	for (int t = in(); t; t--) {
		int n = in() - 1, k = in() - 1, p = in(), r = 0;
		vector<int> v;
		while (n--) {
			int c = in(), d = c - p;
			r += d;
			v.push_back(d);
			p = c;
		}
		int m = min((int) v.size(), k);
		nth_element(v.begin(), v.begin() + m, v.end(), [](int a, int b) {return a > b;});
		for (int i = 0; i < m; i++)
			r -= v[i];
		outl(r);
	}
}


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

#define watch(x) cout << (#x) << " is " << (x) << endl
#define fr(i,n) for(int i=0; i<n; i++)
#define rep(i, st, en) for(int i=st; i<=en; i++)
#define repn(i, st, en) for(int i=st; i>=en; i--)
#define sq(a) (a) * (a)
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll mod = 1e9+7;
const ll INF = 1e18L + 5;

vector<ll> h;

struct line{
    ll m, c;
    ll val(ll x){
        return m * x + c;
    }
    ll intesectX(line b){
        /// mx + c = b.mx + b.c
        ll x = (b.c - c) / (m - b.m);
        return x;
    }
};

void solve(){
    ll n, c, x;
    cin>>n>>c;
    h.resize(n);
    fr(i, n) {
        cin>>h[i];
    }

    deque<line> dq;

    auto d = [&](ll x){
        return sq(x);
    };

    dq.push_back({-2ll * h[0], 0ll + d(h[0])});
    ll best = 0ll;
    rep(i, 1, n-1){
        x = h[i];
        /// query
        while(dq.size() >= 2 && dq.back().val(x) >= dq[dq.size() - 2].val(x))
            dq.pop_back();
        ll val = dq.back().val(x);
        best = c + d(h[i]) + val;
        line l = {-2ll * h[i], best + d(h[i])};

        /// insertion
        while(dq.size() >= 2 && l.intesectX(dq.front()) <= dq.front().intesectX(dq[1]))
            dq.pop_front();

        dq.push_front(l);
    }

    cout<<best;
}

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

    ll t = 1;
    //  cin>>t;
    while(t--){
        solve();
    }

    return 0;
}



Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1E9
#define EPS 1E-9
#define MOD (1E9+7)
#define PI 3.1415926535897932384

std::ostream &operator<<(std::ostream &out, const vector<int> &tgt)
{
	string s;
	for (int i = 0; i<tgt.size(); i++) {
		s += (to_string(tgt[i]) + ((i != tgt.size() - 1) ? " " : ""));
	}
	out << s;
	return out;
}

int main() {
	ll a, b, c, d, n;
	cin >> a >> b >> c >> d >> n;
	b = min(b, a * 2);
	c = min(c, b * 2);
	d = min(d, c * 2);
	ll ans = min(c*n,d*(n/2)+c*(n%2));
	cout << ans << endl;
	
}


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
int C[505],S[505],F[505];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	FOR(i,N-1) {
		cin>>C[i]>>S[i]>>F[i];
	}
	FOR(i,N) {
		x=i;
		y=0;
		while(x<N-1) {
			if(y<S[x]) y=S[x];
			y=(y+F[x]-1)/F[x]*F[x]+C[x];
			x++;
		}
		cout<<y<<endl;
	}
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <bitset>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <utility>
#include <set>
#include <map>
#include <tuple> 
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <list>
using namespace  std;
using ll = long long;
using P = pair<ll, ll>;
#define REP(i, n) for(long long (i)=0, i_bound = (long long)(n); (i)<i_bound; ++i)
#define FOR(i, a, b) for(long long (i)=(a); (i)<(b); ++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
const long long MOD = static_cast<long long>(1e9) + 7LL;
const long long INF = 1234567891234567890LL;
int main(){
    cin.tie(0);
    cout.sync_with_stdio(false);
    int H, W, N;
    cin >> H >> W >> N;
    vector<int> A(N);
    REP(i, N) cin >> A[i];
    vector<vector<int>> res(H, vector<int>(W));
    int col = 0;
    int row = 0;
    REP(i, N){
        while(A[i]){
            if(col+A[i] >= W){
                FOR(j, col, W) res[row][j] = i+1;
                A[i] -= W - col;
                col = 0;
                row++;
            } else {
                FOR(j, col, col+A[i]) res[row][j] = i+1;
                col += A[i];
                A[i] = 0;
            }
        }
        //cout << "-----------" << endl;
        //cout << row << " " << col << endl;
        //cout << res ;
        //cout << "-----------" << endl;
    }
    REP(i, H){
        if(i%2==1) reverse(ALL(res[i]));
        cout << res[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 384
c = [list(map(int,input().split())) for _ in range(3)]
import sys
a = [0,0,0]
b= [0,0,0]

min_1 = min(c[0])
for j in range(0,min_1+1):
  a[0] = j
  b[0] = c[0][0]-j
  b[1] = c[0][1]-j
  b[2] = c[0][2]-j
  a[1] = c[1][0]-b[0]
  a[2] = c[2][0]-b[0]
  if a[1]<0 or a[2]<0: continue
  for i in [1,2]:
    for k in [1,2]:
      if c[i][k] != a[i]+b[k]:
        break
      else:
        if i==2 and k==2:
          print("Yes")
          sys.exit()
    else:
      continue
    break

print("No")

Measured memory_bytes: 3064
#import<iostream>
#import<string>
using namespace std;

int main () {
    string abcd;
    cin >> abcd;

    int ans;

    for(int i = 0; i < 8; i++){
        int bit = i;
        int sum = abcd[0] - '0';
        for(int j = 1; j <= 3; j++){
            sum += ( (bit&1)? 1: -1 )*(abcd[j] - '0');
            bit >>= 1;
        }
        if(sum == 7) {
            ans = i;
            break;
        }
    }

    cout << abcd[0];
    for(int i = 1; i <= 3; i++){
        cout << ( (ans&1)? '+': '-' ) << (abcd[i] - '0');
        ans >>= 1;
    }
    cout << "=7" << endl;

    return 0;
}

Measured memory_bytes: 256
import           Control.Applicative
import           Control.Monad
import           Data.List
import           Text.Printf

main :: IO ()
main = (mapM_ (sovle . map (read :: String -> Int) . words) . lines) =<< getContents
  where
    sovle [a,b] = putStrLn $ unwords $ map show [gcd' a b, lcm' a b]
    gcd' a 0 = a
    gcd' a b = gcd' b (a `rem` b)
    lcm' 0 0 = 0
    lcm' a b = a `div` (gcd' a b) * b


Measured memory_bytes: 4044
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
using namespace std;
int main() {
	int a[6];
	for (int i = 0;i < 6;++i) scanf("%d", &a[i]);
	if (a[0] + a[1] * 5 + a[2] * 10 + a[3] * 50 + a[4] * 100 + a[5] * 500 >= 1000) {
		printf("1\n");
	}
	else {
		printf("0\n");
	}
}


Measured memory_bytes: 1012
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#define _GLIBCXX_DEBUG // check []
#define DIVISOR 1000000007

using namespace std;
typedef pair<int,int> pii;
typedef pair<int64_t, int64_t> pII;

template<typename T>
void cins(vector<T>& arr) { for(T& e: arr) cin >> e; }

#ifdef DEBUG
#define debug(fmt, ...) \
    printf("[debug: %s] " fmt, __func__, __VA_ARGS__)
#define ps(arr) \
    for(auto e: arr) cout << e << " "; \
    cout << endl;
#else
#define debug(fmt, ...)
#define ps(arr)
#endif

#define JUMP_MAX 1000000
int main(void) {
    int num;
    cin >> num;
    int cur = 0;
    for(int i = 1; i <= JUMP_MAX; i++) {
        cur += i;
        if(cur >= num) {
            cout << i << endl;
            return 0;
        }
    }
    return 0;
}

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

#define llint long long int

using namespace std;

int main(){
    int N, M, K;

    cin >> N >> M >> K;

    vector<llint> A(N), B(M);

    for(int i = 0; i < N; i ++){
        cin >> A[i];
    }
    for(int i = 1; i < N; i ++){
        A[i] += A[i - 1];
    }
    for(int i = 0; i < M; i ++){
        cin >> B[i];
    }
    for(int i = 1; i < M; i ++){
        B[i] += B[i - 1];
    }
    auto it = upper_bound(B.begin(), B.end(), K);

    int ans = (it - B.begin());

    for(int i = 0; i < N; i ++){
        if(A[i] > K){
            break;
        }
        it = upper_bound(B.begin(), B.end(), K - A[i]);

        int temp = (i + 1) + (it - B.begin());

        if(temp > ans){
            ans = temp;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 6412
#include <iostream>

using namespace std;

int main(){

  int ansl,answ,l,n,sum = 0;
  int x[66] = {};
  int w[66] = {};

  cin >> l >> n;

  for(int i = 0;i < n;i++){

    cin >> x[i] >> w[i];

    sum += x[i] * w[i];
  }
  if (sum == 0){
    cout << '0' << endl;
    return 0;
  }
  else{  
    for(int i = -l;i <l; i++){
      for(int j = 1;j < 5000;j++){
	if(i * j == -sum) {
	  ansl = i;
	  answ = j;
	}
      }
    }

    cout << '1' << endl << ansl << ' ' << answ << endl;
  }
}


  

Measured memory_bytes: 3104
#include <iostream>
#include <vector>
typedef long long ll;
using namespace std;

int main(void) {
    string S, T;
    
    cin >> S >> T;
    
    int min = 0;
    int tmp = 0;
    for (int i = 0; S[i]; i++) {
        tmp = 0;
        if (S.length() - i < T.length())
            break;
        for(int j = i, k = 0; T[k]; j++,k++){
            if (S[j] != T[k])
                tmp++;
        }
        if (i == 0){
            min = tmp;
        }else{
            if (tmp < min) {
                min = tmp;
            }
        }
    }
    cout << min << endl;
    
    return 0;
}

Measured memory_bytes: 3628
#include <stdio.h>
void print_32bits(unsigned x) //32ビットで表示する
{
    for (int i = 31; i >= 0; i--)
    {
        unsigned s = (x >> i);
        if (s & 1U)
        {
            putchar('1');
        }
        else
        {
            putchar('0');
        }
    }
    printf("\n");
}
int main(void)
{
    unsigned a, b;
    scanf("%u %u", &a, &b);

    print_32bits(a & b);
    print_32bits(a | b);
    print_32bits(a ^ b);

    return 0;
}


Measured memory_bytes: 2696
# Aizu Problem 0104: Magical Tiles
#
import sys, math, os

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")


def magical_tiles(H, W, tiles):
    moves = {'>': [0, 1], '<': [0, -1], '^': [-1, 0], 'v': [1, 0]}
    visited = set()
    row, col = 0, 0
    while True:
        if tiles[row][col] == '.':
            print(col, row)
            return
        if (row, col) in visited:
            print("LOOP")
            return
        visited.add((row, col))
        direction = tiles[row][col]
        row += moves[direction][0]
        col += moves[direction][1]
    
while True:
    H, W = [int(_) for _ in input().split()]
    if H == W == 0:
        break
    tiles = [[_ for _ in input().strip()] for __ in range(H)]
    magical_tiles(H, W, tiles)

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

const int N = 1010;

int n;
int indegree[N * N];
vector<int> g[N * N];

int toint(int x, int y) {
  if (x > y)
    swap(x, y);
  return n * x + y;
}

pair<int, int> demap(int x) {
  return {x / n, x % n};
}

int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    int last;
    scanf("%d", &last);
    last--;
    for (int j = 0; j < n - 2; j++) {
      int cur;
      scanf("%d", &cur);
      cur--;
      g[toint(i, last)].push_back(toint(i, cur));
      indegree[toint(i, cur)]++;
      last = cur;
    }
  }

  int proc = 0, ans = 0;
  vector<int> cur_set;
  for (int i = 0; i <= (n - 2) * (n + 1) + 1; i++)
    if (!indegree[i] && demap(i).first < demap(i).second)
      cur_set.push_back(i);

  while ((int) cur_set.size() > 0) {
    ans++;
    proc += (int) cur_set.size();
    vector<int> nxt;
    for (int u : cur_set)
      for (int v : g[u]) {
        indegree[v]--;
        if (!indegree[v])
          nxt.push_back(v);
      }
    cur_set = nxt;
  }

  printf("%d\n", (proc == n * (n - 1) / 2 ? ans : -1));
  return 0;
}

Measured memory_bytes: 43648
def main():
  n, m = map(int, input().split())
  A = list(map(int, input().split()))
  
  voteSum = sum(A)
  
  B = sorted(A, reverse = True)
  
  #for i in range(0, m):
  if B[m-1] >= voteSum / (4*m):
    print('Yes')
  else:
    print('No')
      
  
main()

Measured memory_bytes: 9104
def main():
  num = list(map(int,input().split()))
  if num[0]==num[1]:
    if num[0]!=num[2]:
      print("Yes")
    else:
      print("No")
  else:
    if num[0]==num[2] or num[1]==num[2]:
      print("Yes")
    else:
      print("No")
main()

Measured memory_bytes: 3060
using System;

namespace a
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = Convert.ToChar(Console.ReadLine());
            
            if(s == 'A'){
                Console.WriteLine("T");
            }

            if(s == 'T'){
                Console.WriteLine("A");
            }

            if(s == 'C'){
                Console.WriteLine("G");
            }

            if(s == 'G'){
                Console.WriteLine("C");
            }
        }
    }
}


Measured memory_bytes: 11220
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ss second
#define ff first
#define pb push_back
#define mp make_pair
map<pair<int,int>,bool> m;
int n;
vector<pair<int,int> > v;
int main() {
    cin>>n;
    for(int i=0;i<n;i++)
     {
         int x,y;
         cin>>x>>y;
         v.pb(mp(x,y));
         m[mp(x,y)]=1;
     }
     sort(v.begin(),v.end());
     int sum=n;
     for(int i=0;i<n;i++)
     {
         for(int j=i+1;j<n;j++)
         {  int o=n;
             int a=v[j].ff-v[i].ff,b=v[j].ss-v[i].ss;
             for(int k=1;k<n;k++)
             {
                 for(int k2=0;k2<k;k2++)
                 {
                    if(v[k].ff-v[k2].ff==a&&v[k].ss-v[k2].ss==b)
                    {
                        o--;
                        break;
                    }
                 }
             }
             sum=min(sum,o);
         }
     }
    cout<<sum;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#define REP(i,n) for(i=0;i<n;i++)
#define rep(i,n) for(i=1;i<=n;i++)
typedef long long ll;
using namespace std;
int main(void){
	int i;
	string S;
	int A[100];
	int N,Q;
	cin >> N;
	if (N < 1200) cout << "ABC" << endl;
	else if (N<2800) cout << "ARC" << endl;
	else cout << "AGC" << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{

long long a,b,c,d,ct=0,e,f=0,g=0,h;

cin>>a;
b=a;
c=a;
while(b)
{
ct=ct+b%10;
b=b/10;

}
if(c%ct==0)
cout<<"Yes";
else
cout<<"No";


}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define rREP(i,m,n) for(ll i = (m); i >= (n); i--)
#define ALL(c) (c).begin(), (c).end()
#define print(x) cout << (x) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    string s,t;
    cin >> s >> t;
    int n = s.length();
    bool flag = true;
    rep(i,n)
    {
        if (s[i]!=t[i]) flag = false;

    }
    if (flag)
    {
        cout << "Yes"  << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    
    
}




Measured memory_bytes: 3640
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <tuple>

#define rep(i,n) for(ll i=0;i<n;i++)
#define dup(x,y) (((x)+(y)-1)/(y)) // dup * y >= x なる最小のdup.
using namespace std;
typedef long long ll;
using Graph = vector<vector<ll>>;
//	std::cout<<std::fixed<<std::setprecision(10);

int main() {
	const ll mod = 1e9 + 7;
	int N;
	cin >> N;
	ll A[N];
	rep(i, N) cin >> A[i];

	// A < 2^60
	ll B[60] = {0};
	rep(i, 60) {
		ll zero = 0LL;
		ll one = 0LL;
		rep(j, N) {
			// A[j]の i bit が0か1か
			if(((A[j] >> i) & 1LL)==1LL) one++;
			else zero++;
		}
		
		B[i] = (one * zero) % mod;
	}	

	/* calculate sum */
	ll ans = 0LL;
	rep(i, 60) {
		ans += (B[i] * ((1LL << i) % mod))%mod;
		/* (1 << i) とすると、 i>31の時に overflow する！ */ 
		ans %= mod;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 2560
import Control.Monad
import Data.List
import System.IO.Unsafe

type Pos  = (Int, Int)
type Move = (Dir, Int)
type Dir  = String

main = liftM read getLine >>= loop
  where
    loop 0 = return ()
    loop nGem = do
      gems <- getGemPos nGem

      moves <- liftM read getLine >>= getMove

      -- print gems
      -- print moves

      let (newPos, newGot) =
            foldl (\(curPos, curGot) -> \move -> processMove curPos curGot move gems)
                  ((10, 10), replicate (length gems) False)
                  moves

      -- print (newPos, newGot)

      putStrLn $ if all id newGot then "Yes" else "No"

      liftM read getLine >>= loop

movePos :: Move -> Pos -> Pos
movePos ("N", n) (x, y) = (x, y+n)
movePos ("S", n) (x, y) = (x, y-n)
movePos ("W", n) (x, y) = (x-n, y)
movePos ("E", n) (x, y) = (x+n, y)

processMove :: Pos -> [Bool] -> Move -> [Pos] -> (Pos, [Bool])
processMove pos got move gems =
  aux (snd move) pos got (fst move, 1) gems
  where aux 0 pos got _ _ = (pos, got)
        aux n pos got move gems =
          let (newPos, newGot) = processMove1 pos got move gems
          in aux (n-1) newPos newGot move gems

processMove1 :: Pos -> [Bool] -> Move -> [Pos] -> (Pos, [Bool])
processMove1 pos got move gems =
  let newPos = movePos move pos
      index = elemIndex newPos gems
      newGot = maybe got (\i -> (take i got) ++ [True] ++ (drop (i+1) got)) index
  in
     (newPos, newGot)

readPos :: String -> Pos
readPos s = let [x, y] = map read $ words s in (x, y)

readMove :: String -> Move
readMove s = let [d, n] = words s in (d, read n :: Int)

getGemPos :: Int -> IO [Pos]
getGemPos n = replicateM n (liftM readPos getLine)

getMove :: Int -> IO [Move]
getMove n = replicateM n (liftM readMove getLine)

Measured memory_bytes: 3936
#include<iostream>
#include<string>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<algorithm>
#include<complex>
using namespace std ;
typedef vector<int> vi ;
typedef vector<vi> vvi ;
typedef vector<string> vs ;
typedef pair<int, int> pii; 
typedef long long ll ;

#define loop(i,a,b) for(int i = a ; i < b ; i ++)
#define rep(i,a) loop(i,0,a)
#define all(a) (a).begin(),(a).end()


int main(void){
  string buf;
  vector<string> ans;
  getline(cin,buf);
  string str="";
  rep(i,buf.size()){
    if(buf[i] == ',' || buf[i] == '.' || buf[i] == ' '){
      if(3 <= str.size() && str.size() <= 6)
	ans.push_back(str);
      str = "";
      continue;
    }
    str+=buf[i];
  }
  rep(i,ans.size()-1)
    cout << ans[i] << " ";
  cout<<ans[ans.size()-1]<<endl;
}

Measured memory_bytes: 1184
import java.util.Scanner;
public class Main {
  static final long LLINF = 1100000000000000000l;
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();
    int Q = sc.nextInt();
    long[] s = new long[A + 2];
    for (int i = 1; i <= A; i++) {
      s[i] = sc.nextLong();
    }
    s[0] = -LLINF;
    s[A + 1] = LLINF;
    long[] t = new long[B + 2];
    for (int i = 1; i <= B; i++) {
      t[i] = sc.nextLong();
    }
    t[0] = -LLINF;
    t[B + 1] = LLINF;
    long[] x = new long[Q];
    for (int i = 0; i < Q; i++) {
      x[i] = sc.nextLong();
    }

    for (int q = 0; q < Q; q++) {
      long ans = LLINF;
      int sl = lower_bound(s, x[q], 0, s.length);
      int tl = lower_bound(t, x[q], 0, t.length);
      for (int i = sl; i <= sl + 1; i++) {
        for (int j = tl; j <= tl + 1; j++) {
          ans = Math.min(ans, Math.abs(s[i] - x[q]) + Math.abs(t[j] - s[i]));
          ans = Math.min(ans, Math.abs(t[j] - x[q]) + Math.abs(s[i] - t[j]));
        }
      }
      System.out.println(ans);
    }
  }
  static int lower_bound(long[] a, long x, int lb, int ub) {
    if (ub  - lb <= 1) {
      return lb;
    } else {
      int mid = (lb + ub) / 2;
      if (a[mid] <= x) return lower_bound(a, x, mid, ub);
      else return lower_bound(a, x, lb, mid);
    }
  }
}

Measured memory_bytes: 93240
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e9+7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
signed main() {
    int D;
    cin >> D;
    vector<int>c(26);
    for(int i = 0; i < 26; i++) {
        cin >> c[i];
    }
    vector<vector<int>>s(D,vector<int>(26));
    for(int i = 0; i < D; i++) {
        for(int j = 0; j < 26; j++) {
            cin >> s[i][j];
        }
    }
    vector<int>t(D);
    for(int i = 0; i < D; i++) {
        t[i] = rand()%26+1;
    }
    int ans = 0;
    vector<int>Last(26);
    for(int i = 0; i < D; i++) {
        ans+=s[i][t[i]-1];
        Last[t[i]-1] = i+1;
        for(int j = 0; j < 26; j++) {
            ans-=c[j]*(i+1-Last[j]);
        }
    }
    int M = 1000;
    for(int i = 0; i < M; i++) {
        int d = rand()%D+1;
        int q = rand()%26+1;
        int ord = ans;
        int X = 0;
        int Y = 0;
        int A = 0;
        int B = 0;
        ans+=s[d-1][q-1]-s[d-1][t[d-1]-1];
        for(int j = 0; j < D; j++) {
            if(t[j] == t[d-1]) {
                if(j == d-1) {
                    Y = j+1;
                }
                else {
                    X = j+1;
                }
                A = j+1;
            }
            if(t[j] == q) {
                Y = j+1;
                B = j+1;
            }
            ans-=c[t[d-1]-1]*(j+1-X)-c[t[d-1]-1]*(j+1-A);
            ans+=c[q-1]*(j+1-B)-c[q-1]*(j+1-Y);
        }
        if(ans > ord) {
            ord = ans;
            t[d-1] = q;
        }
        else {
            ans = ord;
        }
    }
    for(int i = 0; i < D; i++) {
        cout << t[i] << endl;
    }
}

Measured memory_bytes: 3704
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner scan =  new Scanner(System.in);
		int N = scan.nextInt();
		long[] arr = new long[1000000];
		long ans = 0;
		for(int i=0;i<N;i++){
			int c = scan.nextInt();
			arr[c]++;
			ans+=c;
		}
		int d = scan.nextInt();
		for(int i=0;i<d;i++){
			int p = scan.nextInt();
			int q = scan.nextInt();
			ans += (q-p)*arr[p];
			arr[q]+=arr[p];
			arr[p]=0;
			System.out.println(ans);
		}
	}
}


Measured memory_bytes: 66536
#include<bits/stdc++.h>
using namespace std;
unsigned int n,k,f[100],ans;
bool cmp(unsigned x,unsigned y)
{
	return x>y;
}
int main()
{
	cin>>n>>k;
	for(int i=1;i<=n;i++)
	{
		cin>>f[i];
	}
	sort(f+1,f+1+n,cmp);
	for(int i=1;i<=k;i++)
	{
		ans+=f[i];
	}
	cout<<ans;
	return 0;
}

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

typedef long long ll;
#define rep(i, s, n) for(int i=s;i<n;i++)
#define repeq(i,s,n) for(int i=s;i<=n;i++)
#define MOD 10e9+7

void max_self(int& a, int b) { a=a>b?a:b; }
void min_self(int& a, int b) { a=a<b?a:b; }

using namespace std;

int n, k;

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

    if(n*500>=k)
        cout << "Yes";
    else
        cout << "No";

    cout << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.Hashtable;
import java.util.Scanner;

class Main {
	public static void main(String args[]){
		Scanner scan = new Scanner(System.in);
		String line;
		Hashtable<Character,Integer> hash = new Hashtable<Character,Integer>();
		hash.put('I',1);
		hash.put('V',5);
		hash.put('X',10);
		hash.put('L',50);
		hash.put('C',100);
		hash.put('D',500);
		hash.put('M',1000);
		
		while(scan.hasNext()){
			line = scan.next();
			int strLen = line.length();
			char[] roman = line.toCharArray();
			int sum=0;
			int prev = Integer.MAX_VALUE;
			
			for(int i=0;i<strLen;i++){
				if(prev >= hash.get(roman[i])){
					sum += hash.get(roman[i]);
				}else{
					sum = sum - prev*2 + hash.get(roman[i]);
				}
				prev = hash.get(roman[i]);
			}
			
			System.out.println(sum);
		}
	}
}

Measured memory_bytes: 17164
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		String result = "Good";
		String[] split = s.split("");
		if (split[0].equals(split[1]) || split[1].equals(split[2]) || split[2].equals(split[3])) {
			result = "Bad";
		}
		System.out.println(result);
	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
//----***やべーやつら***----
using namespace std;
#define int long long

//----***型定義***----
using ll = long long;
using pll = pair<ll, ll>;
using pdd = pair<double, double>;
typedef long double lb;
typedef vector<int,vector<int>> vvec;
typedef long double ld;

//----***Like a Pythonista***----
#define REP(i,j,n) for (ll i=j;i<(n);i++)
#define RREP(i,n,j) for (ll i = n; j<i;i--)
#define each(i,...) for (auto&& i:__VA_ARGS__)
#define ALL(vec) (vec).begin(),(vec).end()
#define sum(...) accumulate(ALL(__VA_ARGS__),0LL)
#define dsum(...) accumulate(ALL(__VA_ARGS__),0.0L)
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
template<class T> inline auto max(const T& a){ return *max_element(ALL(a)); }
template<class T> inline auto min(const T& a){ return *min_element(ALL(a)); }
inline ll gcd(ll a, ll b){ while(b){ ll c = b; b = a % b; a = c; } return a; }
inline ll lcm(ll a, ll b){ if(!a || !b) return 0; return a * b / gcd(a, b); }

//----***定数***----
const int MOD=1000000007;
#define INF 1e9;
#define EPS 1e-9;

//----***入出力***----
#define print(out) cout<< out  << "\n";
#define debug(var)  do{std::cerr << #var << " ↓ "<<"\n";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
#define HERE  cout<<"Here"<<endl;

//----***初期時読み込み***----
struct initial{initial(){cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}initial_;

signed main(){
  int N;cin>>N;
  int ans=N*(N-1)/2;
  print(ans)
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    A=list(range(1,4))
    a=int(input())
    b=int(input())
    A.remove(a)
    A.remove(b)
    print(*A)
resolve()

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

using namespace std;
using llong = long long;
using ldbl = long double;
using P = pair<llong, llong>;

#define ALL(x) x.begin(), x.end()

const llong inf = 1100100100100100ll;
const llong mod = 1e9+7;

int main() {
	llong N;
	vector<llong> v;
	priority_queue<llong> negative;
	priority_queue<llong, vector<llong>, greater<llong> > positive;
	bool pos = false, neg = false;
	llong zero = 0;

	cin >> N;
	v.resize(N);
	for (int i = 0; i < N; ++i) {
		cin >> v[i];
		llong an = abs(v[i]);
		if (v[i] < 0) {
			negative.push(v[i]);
			neg = true;
		} else if (v[i] > 0) {
			positive.push(v[i]);
			pos = true;
		} else {
			zero++;
		}
	}

	vector<P> ans;

	while (zero > 1) {
		zero--;
		ans.push_back(P(0,0));
	}
	while(zero + positive.size() + negative.size() > 1) {
		if (negative.size() == 0) {
			if (positive.size() == 1) {
				zero--;
				llong p = positive.top();
				ans.push_back(P(p, 0));
			} else if (zero == 1) {
				zero--;
				llong p = positive.top();
				positive.pop();
				negative.push(-p);
				ans.push_back(P(0, p));
			} else {
				llong p1 = positive.top();
				positive.pop();
				llong p2 = positive.top();
				positive.pop();
				negative.push(p1 - p2);
				ans.push_back(P(p1, p2));
			}
		} else if (positive.size() == 0) {
			if (zero == 1) {
				zero--;
				llong n = negative.top();
				negative.pop();
				positive.push(-n);
				ans.push_back(P(0, n));
			} else {
				llong n1 = negative.top();
				negative.pop();
				llong n2 = negative.top();
				negative.pop();
				positive.push(n1 - n2);
				ans.push_back(P(n1, n2));
			}
		} else {
			llong p = positive.top();
			llong n = negative.top();
			positive.pop();
			negative.pop();
			if (positive.size() <= negative.size()) {
				positive.push(p - n);
				ans.push_back(P(p, n));
			} else {
				negative.push(n - p);
				ans.push_back(P(n, p));
			}
		}
	}

	cerr << positive.size() << " " << negative.size() << endl;

	if (positive.size() == 0)
		positive.push(0);

	cout << positive.top() << endl;
	for (auto o : ans) {
		cout << o.first << " " << o.second << endl;
	}

	return 0;
}

/*

どの順番でも絶対値は変わらない
どっちもあったら全部足す
どっちもなかったら

*/

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

int main() {
    int n;cin>>n;
    ll a[n];rep(i,n)cin>>a[i];

    ll tmp=0;
    ll pos=1;
    ll sum=a[0];
    if(a[0]<=0){
        tmp+=abs(a[0])+1;
        sum=1;
    }

    rep(i,n-1){
        sum+=a[i+1];
        if(sum*pos>=0){
            tmp+=abs(sum)+1;
            sum=-pos;
        }
        pos*=-1;
    }
    ll ans=tmp;

    tmp=0;
    pos=-1;
    sum=a[0];
    if(a[0]>=0){
        tmp+=abs(a[0])+1;
        sum=-1;
    }
    rep(i,n-1){
        sum+=a[i+1];
        if(sum*pos>=0){
            tmp+=abs(sum)+1;
            sum=-pos;
        }
        pos*=-1;
    }
    ans=min(ans,tmp);
    cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 4428
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16000000")
using namespace std;

typedef pair <int, int> ii;

const int Maxn = 100005;

int n, m;
vector <int> neigh[Maxn];
vector <ii> res;
int cur, tk[Maxn];
int my[Maxn];

int Solve(int v, int p = 0)
{
    tk[v] = ++cur;
    int my = 0;
    for (int i = 0; i < neigh[v].size(); i++) {
        int u = neigh[v][i];
        if (u == p) continue;
        if (!tk[u])
            if (Solve(u, v)) { my++; res.push_back(ii(v, u)); }
            else res.push_back(ii(u, v));
        else if (tk[u] < tk[v]) { my++; res.push_back(ii(v, u)); }
    }
    if (my % 2) return 0;
    return 1;
}

int main()
{
    scanf("%d %d", &n, &m);
    for (int i = 0; i < m; i++) {
        int a, b; scanf("%d %d", &a, &b);
        neigh[a].push_back(b);
        neigh[b].push_back(a);
    }
    if (Solve(1) == 0) printf("-1\n");
    else for (int i = 0; i < res.size(); i++)
            printf("%d %d\n", res[i].first, res[i].second);
    return 0;
}


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

    int xa = min(a, k);
    k -= xa;
    int xb = min(b, k);
    k -= xb;
    int xc = k;
    int ans = xa - xc;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3620
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include<math.h>
#include<iomanip>
#include<functional>
using namespace std;

#define ll long long
using vt = ll; //ここで数値の型を変えられる
#define rep(i, n) for (vt i = 0; i < (vt)(n); i++)
#define reps(i, s, n) for(vt i = (vt) (s); i < (vt) (n); i++) 
#define all(v) v.begin(), v.end()
#define P pair<int, int>
const ll  MOD = 1000000007;

int main() {
	ll n, d;
	cin >> n >> d;
	ll r = n % (1 + 2 * d);
	if (r > 0) cout << n / (1 + 2 * d) + 1;
	else cout << n / (1 + 2 * d);
	return 0;
}

Measured memory_bytes: 256
#include <queue>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <string>
#include <vector>
#include <map>
#include <functional>

#define rep(i, n) for(int i = 0; i < (n); i++)
#define MAX(a, b) (((a) < (b)) ? (b) : (a))
#define MIN(a, b) (((a) < (b)) ? (a) : (b))

using namespace std;
typedef long long int ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pint;
const ll inf = (1LL << 60);
const ll mod = 1000000007;
ll max(ll a, ll b) {
	if (a < b)
		return b;
	else
		return a;

}
ll min(ll a, ll b) {
	if (a < b)
		return a;
	else
		return b;

}

double max(double a, double b) {
	if (a < b) return b;

	return a;
}

double xs, ys, xt, yt;
ll N;

double cost[1005][1005];
ll vis[1005];
double ans[1005];
double dist(double x, double y, double u, double v) {

	return sqrt((x - u) * (x - u) + (y - v) * (y - v));
}

vector<pair<pair<double, double>, double>> d;

void solve(ll s) {

	ll ci = s;
	vis[ci] = 1;
	ans[ci] = 0;
	bool flag = true;

	priority_queue<pair<double, ll>> q;
	
	while (flag == true) {
		
		flag = false;
		rep(i, d.size()) {
			if(vis[i] == 0){
				q.push({-ans[ci]-cost[i][ci], i});
				flag = true;
			}
		}
		
		if (flag == false) { break; }

		while (vis[q.top().second] == 1) { q.pop();}
		
		
		ans[q.top().second] = -q.top().first;
		ci = q.top().second;
		q.pop();
		vis[ci] = 1;


	}


}


int main() {
	cin >> xs >> ys >> xt >> yt;

	cin >> N;
	
	
	double x, y, r;

	

	ll sindex = -1, tindex = -1;

	rep(i, N) {
		cin >> x >> y >> r;
		d.push_back({ {x, y},  r });
		if (dist(xs, ys, x, y) <= r) {
			sindex = i;
		}
		if(dist(xt, yt, x, y) <= r){
			tindex = i;
		}
	}


	if (sindex == -1) {
		d.push_back({ { xs, ys }, 0 });
		sindex = d.size() - 1;
	}

	if (tindex == -1) {
		d.push_back({ {xt, yt}, 0 });
		tindex = d.size() - 1;
	}


	double cx, cy, cr;
	rep(i, d.size()) {
		rep(j, d.size()) {
			cost[i][j] = max(0, dist(d[i].first.first, d[i].first.second, d[j].first.first, d[j].first.second) - d[j].second - d[i].second);
			cerr << dist(d[i].first.first, d[i].first.second, d[j].first.first, d[j].first.second) << endl;
		}
	}


	solve(tindex);

	printf("%.12f", ans[sindex]);

	return 0;
}

Measured memory_bytes: 18432
def main():
  n, k = input_list()
  a = list(input_list())
  kind = len(set(a[:]))
  if kind <= k:
    print(0)
    exit()
  need = kind - k
  ac = collections.Counter(list(a))
  ans = 0
  for v in sorted(ac.items(), key=lambda x: x[1]):
    if need == 0:
      break
    ans += v[1]
    need -= 1
  print(ans)
  
def input_list():
  return map(int, input().split())

def input_list_str():
  return map(str, input().split())

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

# 2で割り切れる回数
def divide_two(arg):
  c = 0
  while True:
    if c >= 2:
      break
    if arg % 2 != 0:
      break
    arg //= 2
    c += 1
  return c 

import math
import fractions
import collections
from functools import reduce
main()

Measured memory_bytes: 51972
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
#define Mod 1000000007
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;
#define INF 1ll<<59

int main(){
  ll i,j;
  ll n,m;
  cin>>n>>m;
  ll s[2020],t[2020];
  for(i=1;i<=n;i++) cin>>s[i];
  for(i=1;i<=m;i++) cin>>t[i];

  VVI dp(2020,VI(2020,0));
  for(i=0;i<2020;i++){
    dp[i][0]=1;
    dp[0][i]=1;
  }

  for(i=1;i<=n;i++){
    for(j=1;j<=m;j++){
      if(s[i]==t[j]) dp[i][j]=dp[i-1][j]+dp[i][j-1];
      else dp[i][j]=Mod+dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1];
      dp[i][j]%=Mod;
    }
  }
  
  cout<<dp[n][m]<<endl;
  return 0;
}

Measured memory_bytes: 32256