akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define pb push_back
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using vst=vector<string>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
//abba
//43376
int main() {
  string s;
  int k;
  cin>>s>>k;
  int n=s.size();
  vector<vst> cnt(5050,vst(5050,""));
  int len=1;
  map<string,int>moji;
  while(n-len>=0&&len<=6){
      rep(i,0,n+1-len){
        string v="";
        v=cnt[i][len-1]+s[i+len-1];
        cnt[i][len]=v;
        //cout<<v<<endl;
        moji[v]++;
        
      }
   len++;     
  }
  int u=0;
  for(auto v:moji){
    u++;
    if(u==k){
     cout<<v.first<<endl; 
      return 0;
    }
  }
  
  
}

Measured memory_bytes: 812800
#include <cstdio>
int main(){
    int in;
    int h,m,s;
    scanf("%d",&in);

    h = in / 3600;
    in %= 3600;

    m = in / 60;
    in %= 60;

    s = in;

    printf("%d:%d:%d\n",h,m,s);
}


Measured memory_bytes: 2716
#include <algorithm>
#include <iostream>
#include <vector>
#include <functional>
#include <string>
#include <cmath>  //sqrt 
#include <iomanip> //setprecision
using namespace std;

int main(){
    int n ; cin >> n;
    string s;  cin >>  s;
    int count=0;
    for (int i = 0; i < n-2; i++)
    {   
        if(s.substr(i,3)=="ABC") count++;
    }
    cout << count << endl;
    return 0;
}

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

int main(){
  long long int N, K;
  cin >> N >> K;
  
  vector<int> A(N), num(2001, 0);
  for (int i = 0; i < N; i++){
    cin >> A.at(i);
    num.at(A.at(i))++;
  }
  
  long long int base = 0;
  for (int i = 0; i < N - 1; i++){
    for (int j = i + 1; j < N; j++){
      if (A.at(i) > A.at(j)){
        base++;
      }
    }
  }
  
  long long int ruiseki = 0, ans = 0;
  ans = base * K;
  for (int i = 1; i <= 2000; i++){
    ans += num.at(i) * ruiseki * ((K * (K - 1) / 2) % 1000000007);
    ans %= 1000000007;
    ruiseki += num.at(i);
  }

  cout << ans << endl;
    
}

Measured memory_bytes: 3656
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate
    #from itertools import product
    from bisect import bisect_left,bisect_right
    import heapq
    from math import floor, ceil
    #from operator import itemgetter

    inf = 10**17
    #mod = 10**9 + 7

    N = int(input())
    def dijkstra_heap(start,edge):
        #始点から各頂点への最短距離(頂点番号:0~N-1)
        d = [inf]*N
        used = [False]*N
        d[start] = 0
        used[start] = True
        edgelist = []
        #a:重み(//), b:次の頂点(%)
        for a,b in edge[start]:
            heapq.heappush(edgelist,a*(10**6)+b)

        while len(edgelist):
            #まだ最短距離が決まっていない頂点の中から最小の距離のものを探す
            minedge = heapq.heappop(edgelist)
            if used[minedge%(10**6)]:
                continue
            node = minedge%(10**6)
            d[node] = minedge//(10**6)
            used[node] = True

            for e in edge[node]:
                if not used[e[1]]:
                    heapq.heappush(edgelist,(e[0]+d[node])*(10**6)+e[1])
        return d

    #N:頂点数   W:辺数
    edge = [[] for i in range(N)]
    #edge[i] : iから出る道の[重み,行先]の配列
    for _ in range(N-1):
        x,y,z = map(int,input().split())
        edge[x-1].append((z,y-1))
        edge[y-1].append((z,x-1))
    d = dijkstra_heap(0, edge)

    for i in range(N):
        if d[i]%2==0:
            print(0)
        else:
            print(1)


if __name__ == '__main__':
    main()

Measured memory_bytes: 82224
#include <iostream>
#include <cstdint>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <limits>

using namespace std;

int main() {

	int n;
	vector<int> v;
	int64_t sum = 0;
	int64_t acc = 0;
	int64_t delta = numeric_limits<int64_t>::max();

	cin >> n;
	v.resize(n);
	for (int i = 0; i < n; i++) {
		cin >> v[i];
		sum += v[i];
	}

	for (int i = 0; i < n - 1; i++) {
		acc += v[i];
		delta = min(delta, abs((sum - acc) - acc));
	}

	cout << delta << "\n";

	return 0;
}

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

int main()
{
	while (true)
	{
		int n;cin >> n;
		if (n==0) break;
		vector<int> time(86500,0);
		string start,stop;
		for (int i=0;i<n;i++)
		{
			cin >> start >> stop;
			int time1=((start[0]-'0')*10+(start[1]-'0'))*3600+((start[3]-'0')*10+(start[4]-'0'))*60+((start[6]-'0')*10+start[7]-'0');
			int time2=((stop[0]-'0')*10+(stop[1]-'0'))*3600+((stop[3]-'0')*10+(stop[4]-'0'))*60+((stop[6]-'0')*10+stop[7]-'0');
			time[time1]++;
			time[time2]--;
		}
		for (int i=0;i<86499;i++)
		{
			time[i+1]+=time[i];
		}
		int ans=0;
		for (int i=0;i<86500;i++) ans=max(ans,time[i]);
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 3400
# import math
# from collections import Counter

# N = int(input()) # 1行, 単数
# arg = list(map(int, input().split())) # 1行, 配列
# D = Counter(arg) # 出現数カウント

# print('Yes')
# print('No')
# print()

S = input() # 1行, 単数
T = input() # 1行, 単数

if S == T[:-1]:
  print('Yes')
else:
  print('No')


Measured memory_bytes: 61856
#include<cstdio>
#include<queue>
#include<algorithm>
#include<string.h>
#include<math.h>
#include<set>
#include<stack>
#include<queue>
#include<map>
using namespace std;
map<long long,int>m;
long long suan(char s[]){
	int i,l=strlen(s);
	long long ans=0;
	for(i=0;i<l;i++){
		ans=ans*27+s[i]-'a'+1;
	}
	return ans;
}
char s[200010][12];
int biao[200010];
long long zhi[200010];
bool cmp(int a,int b){
	return strcmp(s[a],s[b])<0;
}
int main(){
	int n,i;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		biao[i]=i;
		scanf("%s",s[i]);
		zhi[i]=suan(s[i]);
		m[zhi[i]]++;
	}
	int maxx=0;
	for(i=0;i<n;i++){
		maxx=max(maxx,m[zhi[i]]);
	}
	sort(biao,biao+n,cmp);
	for(i=0;i<n;i++){
		if(m[zhi[biao[i]]]==maxx){
			printf("%s\n",s[biao[i]]);
			m[zhi[biao[i]]]=0;
		}
	}
}

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

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	string s;
	cin >> s;
	int ans = 0;
	for (int i = 0; i < s.length(); i++)
	{
		int p = s[i] - '0';
		ans = ans + p;
		ans %= 9;
	}
	if (ans == 0)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0;
}

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

typedef long lint;
typedef long long llint;
typedef pair<int, int> pint;
typedef pair<long long, long long> pllint;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const llint INF = 1<<21;
// static const llint MOD = 1e9 + 7;

bool compPair(const pint& arg1, const pint& arg2) { return arg1.first > arg2.first; }
template<class T> void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b) { if (a > b) { a = b; } }

int pow2(int a) {
    int ans = 1;
    for(int ia=0;ia<a;ia++) {
        ans *= 2;
    }
    return ans;
}

int main(void) {
    int h, w, k;
    cin >> h >> w >> k;

    vector<vector<char>> c(h, vector<char>(w));
    for(int ih=0;ih<h;ih++) {
        for(int iw=0;iw<w;iw++) {
            cin >> c[ih][iw];
        }
    }

    int hall, wall, know, ans = 0;
    hall = pow2(h);
    wall = pow2(w);
    vector<vector<char>> ctmp(h, vector<char>(w));
    
    for(int ih=0;ih<hall;ih++) {
        for(int iw=0;iw<wall;iw++) {
            know = 0;
            for(int jh=0;jh<h;jh++) {
                for(int jw=0;jw<w;jw++) {
                    ctmp[jh][jw] = c[jh][jw];
                }
            }
            for(int jh=0;jh<h;jh++) {
                for(int jw=0;jw<w;jw++) {
                    int iwtmp = iw, ihtmp = ih;
                    if(((iwtmp>>jw)&1)||((ihtmp>>jh)&1)) ctmp[jh][jw] = '$';
                }
            }
            for(int jh=0;jh<h;jh++) {
                for(int jw=0;jw<w;jw++) {
                    if(ctmp[jh][jw]=='#') know++;
                }
            }
            // cout << ih << " " << iw << endl;
            // for(int jh=0;jh<h;jh++) {
            //     for(int jw=0;jw<w;jw++) {
            //         cout << ctmp[jh][jw];
            //     }
            //     cout << endl;
            // }
            // cout << endl;
            // cout << know;
            if(know==k) ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


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

int main()
{
   int n;
   cin>>n;
   
   int v1[n][2];
   //cout<<1<<endl;
for (int i=0;i<n;i++)
{
  //cout<<2;
  cin>>v1[i][0];
  cin>>v1[i][1];
}

for (int i=0;i<n;i++)
{
    if(v1[i][0]==v1[i][1])
    {
      if(i+1<n && v1[i+1][1]==v1[i+1][0])
      {
          if(i+2<n && v1[i+2][1]==v1[i+2][0])
          {
             cout<<"Yes";
             return 0;

          }
       }
     
    }
}

cout<<"No";

}

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

#define MOD 1000000007
long long N, M;

int main() {
    cin >> N >> M;
    long long ans = min(N, M / 2);
    M -= 2 * ans;
    ans += M / 4;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>

using namespace std;



char s[105];
int b = 0;



int main()
{
	while(~scanf("%s",&s)){
		cout << s[0];
		//memset(s, 0, sizeof(s));
	}
	cout << endl;


	system("pause");

}

Measured memory_bytes: 504
#include <bits/stdc++.h>
#define INF (1 << 25)
using namespace std;

int w, h;
int mas[21][21];
int sx, sy, gx, gy;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};

int ans;

void backtrack(int x, int y, int cnt, int dir)
{
  if(cnt > 10){
    return;
  } else if(x == gx && y == gy){
    if(ans != -1) ans = min(ans, cnt);
    else ans = cnt;
    return;
  } else if(dir != -1){
    int nx = x + dx[dir], ny = y + dy[dir];
    if(nx < 0 || w <= nx || ny < 0 || h <= ny) return;
    if(mas[ny][nx] == 1){
      mas[ny][nx] = 0;
      backtrack(x, y, cnt, -1);
      mas[ny][nx] = 1;
    } else {
      backtrack(nx, ny, cnt, dir);
    }
  } else {
    for(int i = 0; i < 4; i++){
      int nx = x + dx[i], ny = y + dy[i];
      if(nx < 0 || w <= nx || ny < 0 || h <= ny) continue;
      if(mas[ny][nx] == 1) continue;
      backtrack(nx, ny, cnt+1, i);
    }
  }
  return;
}

int main()
{
  while(cin >> w >> h, w || h){
    for(int i = 0; i < h; i++){
      for(int j = 0; j < w; j++){
	cin >> mas[i][j];
	if(mas[i][j] == 2) sx = j, sy = i;
	if(mas[i][j] == 3) gx = j, gy = i;
      }
    }
    ans = -1;
    backtrack(sx, sy, 0, -1);
    cout << ans << endl;
  }
  return 0;
}

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

#ifdef LOCAL
#define DEBUG(...) debug(#__VA_ARGS__, __VA_ARGS__);
#else
#define DEBUG(...)
#endif

template<typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &p) {return os << "(" << p.first << ", " << p.second << ")";}
template<typename C, typename T = decay<decltype(*begin(declval<C>()))>, typename enable_if<!is_same<C, string>::value>::type* = nullptr>
ostream& operator << (ostream &os, const C &c) {bool f = true; os << "["; for (const auto &x : c) {if (!f) os << ", "; f = false; os << x;} return os << "]";}
template<typename T> void debug(string s, T x) {cerr << s << " = " << x << "\n";}
template<typename T, typename... Args> void debug(string s, T x, Args... args) {cerr << s.substr(0, s.find(',')) << " = " << x << " | "; debug(s.substr(s.find(',') + 2), args...);}

int h[100005];
bool bad[100005];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int n, m;
    cin >> n >> m;
    for (int i=1; i<=n; i++)
        cin >> h[i];
    for (int i=0; i<m; i++) {
        int a, b;
        cin >> a >> b;
        bad[a] |= (h[a] <= h[b]);
        bad[b] |= (h[b] <= h[a]);
    }

    int ret = 0;
    for (int i=1; i<=n; i++)
        ret += !bad[i];

    cout << ret << "\n";

    return 0;
}


Measured memory_bytes: 4144
#include<bits/stdc++.h>
#define ll long long int
#define IOS cin.tie(NULL);cout.tie(NULL)
#define F first
#define S second
#define pb push_back
using namespace std;

int main() {
	IOS;
	ll n,a,b,c,a1,b1,c1,x,y,z;
	cin>>n;
	for(ll i=0;i<n;i++){
		cin>>x>>y>>z;
		if(i==0)
		{
			a=x;b=y;c=z;
		}else{
			a1=x+max(b,c);
			b1=y+max(a,c);
			c1=z+max(a,b);
			a=a1;
			b=b1;
			c=c1;
		}
	}
	cout<<max(a,max(b,c));
	
}


Measured memory_bytes: 256
open Batteries
module EnumL = Enum.Labels
module ListL = List.Labels
module ArrayL = Array.Labels

let dbg0 x = Printf.eprintf "[debug]%s\n" @@ dump x
let dbg1 x = dbg0 x; x

let id = identity

let (++) n m = List.range n `To m
let (++-) n m = if n >= m then List.range n `Downto m else []
let (++^) n m = if n < m then List.range n `To (pred m) else []

let scan fmt = Scanf.sscanf (read_line ()) fmt

let scan_lines n fmt f =
  if n = 0 then []
  else List.map (fun _ -> scan fmt f) (1 ++ n)

let scan_list sep cnv =
  let line = read_line () in
  (match sep with
   | None -> List.map String.of_char @@ String.to_list line
   | Some sep -> String.split_on_char sep line)
  |> List.map cnv

let scan_array ?sep cnv = Array.of_list @@ scan_list sep cnv

let scan_matrix n m e ?sep conv =
  let arr = Array.make_matrix n m e in
  ListL.iter (0 ++^ n)
    ~f:(fun i -> arr.(i) <- Array.of_list @@ scan_list sep conv);
  arr

let rec powerset e =
  match Enum.get e with
  | None -> Enum.singleton @@ Enum.empty ()
  | Some v ->
    let f = powerset e in
    let g = Enum.clone f in
    EnumL.map f ~f:(fun x -> let y = Enum.clone x in push y v; y)
    |>  Enum.append g

let permutations l =
  let rec aux l =
    let rec interleave x = function
      | [] -> [[x]]
      | (hd::tl) as lst ->
        (x::lst) ::
        (ListL.map ~f:(List.cons hd)  @@ interleave x tl)
    in
    match l with
    | [] -> [[]]
    | hd::tl -> List.concat @@ List.map (interleave hd) @@ aux tl in
  let l = List.sort (List.compare Int.compare) @@ aux @@ List.of_enum l in
  List.enum % ListL.map ~f:List.enum @@ l

let intersection l =
  EnumL.filter ~f:(fun x -> EnumL.exists ~f:((=) x) @@ Enum.clone l)

let zip l m =
  let n = min (List.length l) (List.length m) in
  List.combine (List.take n l) (List.take n m)

let lower_bound n f =
  let rec aux l u =
    if u - l > 1 then
      let m = (l + u) / 2 in
      if f m then aux l m
      else aux m u
    else u in aux (-1) n

let between n x m = n <= x && x < m

let (n,m,q) = scan "%d %d %d" Tuple3.make

let () =
  let mat = Array.make_matrix (succ n) (succ n) 0 in
  ListL.iter (0 ++^ m) ~f:(fun _ ->
      let (l, r) = scan "%d %d" Tuple2.make in
      mat.(r).(l) <- mat.(r).(l) + 1);
  ListL.iter (1 ++ n) ~f:(fun i ->
      List.fold_left (fun p j ->
          let p = p + mat.(i).(j) in
          mat.(i).(j) <- p + mat.(pred i).(j); p
        ) 0 (1 ++ n) |> ignore);
  ListL.iter (0 ++^ q) ~f:(fun _ ->
      let (p,q) = scan "%d %d" Tuple2.make in
      mat.(q).(q) - mat.(q).(pred p) - mat.(pred p).(q) + mat.(pred p).(pred p)
      |> Printf.printf "%d\n"
    )


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

/* メモリ食い過ぎ注意 */
#define int long long

typedef long long ll;

/* define const */
const ll INF = (1ll << 60);
const ll MOD = (ll)1e9 + 7;
/* end defineing */

signed main()
{
    int h, w;
    int a[100][100];
    cin >> h >> w;
    for (int i = 0; i < h; i++)
    {
        string s;
        cin >> s;
        for (int j = 0; j < w; j++)
        {
            a[i][j] = (s)[j];
        }
    }

    set<int> hv;
    set<int> wv;
    for (int i = 0; i < h; i++)
    {
        bool f = true;
        for (int j = 0; j < w; j++)
        {
            if (a[i][j] != '.')
                f = false;
        }
        if (f)
        {
            // cout << "a" << endl;
            hv.insert(i);
        }
    }

    for (int i = 0; i < w; i++)
    {
        bool f = true;
        for (int j = 0; j < h; j++)
        {
            if (a[j][i] != '.')
                f = false;
        }
        if (f)
        {
            // cout << "b" << endl;
            wv.insert(i);
        }
    }
    /*
    for (auto it = hv.begin(); it != hv.end(); it++)
        cout << *it << " ";
    cout << endl;
    for (auto it = wv.begin(); it != wv.end(); it++)
        cout << *it << " ";
    cout << endl;
*/
    for (int i = 0; i < h; i++)
    {
        if (hv.find(i) != hv.end())
            continue;
        for (int j = 0; j < w; j++)
        {
            if (wv.find(j) != wv.end())
                continue;
            cout << (char)(a[i][j]);
        }
        cout << endl;
    L:
    {
    }
    }
}


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

int hamming[1000000+1];
bool is_hamming[1000000+1];

int make_ham(int n)
{
	for(int i=0;i<n;i++){
		is_hamming[i] = false;
	}
	is_hamming[1] = true;
	for(int i=1;i<n;i*=2){
		is_hamming[i] = true;
		for(int j=i;j<n;j*=3){
			is_hamming[j] = true;
			for(int k=j;k<n;k*=5){
				is_hamming[k] = true;
			}
		}
		for(int j=i;j<n;j*=5){
			is_hamming[j] = true;
		}
	}
	int h = 0;
	for(int i=0;i<n;i++){
		if(is_hamming[i])
			hamming[h++] = i;
	}
	return h;
}

int main()
{
	int m,n;
	while(cin >> m){
		if(m == 0)
			break;
		cin >> n;
		int count = 0;
		int h = make_ham(n+1);
		for(int i=0;i<h;i++){
			if(hamming[i] >= m)
				count++;
		}
		cout << count << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define m_p make_pair

int n, m;
vector<pair<int, int> > a;

int main()
{
    cin >> n >> m;
    for (int i = 0; i < m; ++i)
    {
        int l, r;
        cin >> l >> r;
        a.push_back(m_p(l, 1));
        a.push_back(m_p(r + 1, -1));
    }
    sort(a.begin(), a.end());
    int ans = 0;
    int x = 0;
    a.push_back(m_p(n + 1, 0));
    for (int i = 0; i < a.size() - 1; ++i)
    {
        x += a[i].second;
        if (x == m)
            ans += (a[i + 1].first - a[i].first);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 2420
import bisect
import os
from collections import Counter, deque
from fractions import gcd
from functools import lru_cache
from functools import reduce
import functools
import heapq
import itertools
import math
import numpy as np
import re
import string
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")

# X, A = list(map(int, sys.stdin.readline().split()))
# if X < A:
#
#     print(0)
# else:
#     print(10)


N, X = list(map(int, sys.stdin.readline().split()))
L = list(map(int, sys.stdin.readline().split()))
L = np.array(L)

cs = L.cumsum()
print((cs <= X).sum() + 1)


Measured memory_bytes: 13800
#include <stdio.h>
#define N 10000
#define Q 500

int main(){
  int i,j,n,q,con = 0;
  int s[N],t[Q];

  scanf("%d",&n);
  for(i = 0;i < n;i++){
    scanf("%d",&s[i]);
  }
  scanf("%d",&q);
  for(i = 0;i < q;i++){
    scanf("%d",&t[i]);
    for(j = 0;j < n;j++){
      if(t[i] == s[j]){
	con++;
	break;
      }
    }
  }
  printf("%d\n",con);
}



Measured memory_bytes: 2104
n=gets.to_i
lr=[]
n.times do |i|
  xx,ll=gets.split.map(&:to_i)
  lr[i]=[[xx-ll,0].max,xx+ll]
end
lr.sort!
c=0
t=0
lr.each do |l,r|
  if l>=t
    c+=1
    t=r
  elsif r<t
    t=r
  end
end
puts c


Measured memory_bytes: 12048
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
typedef pair<int,int> P;
vector<P> vc;
int main(){
	int N,M;
	cin>>N>>M;
	rep(i,M){
		int a,b;
		cin>>a>>b;
		vc.pb(P(a,b));
	}
	sort(all(vc));
	if(M==0){
		cout<<N+1<<endl;
		return 0;
	}
	int l=vc[0].fs,r=vc[0].sc;
	int ans=N+1;
	rep(i,M){
		if(r<vc[i].fs){
			ans+=2*(r-l);
			l=vc[i].fs,r=vc[i].sc;
		}else{
			chmax(r,vc[i].sc);
		}
	}
	ans+=2*(r-l);
	cout<<ans<<endl;
}

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

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

  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  sort(begin(A), end(A));
  cout << accumulate(begin(A), begin(A) + K, 0) << "\n";
  return 0;
}


Measured memory_bytes: 3648
/*  Author:  Hariom_Pandey
    Created: 3/1/2020 5:26:05 PM
*/
 
 
#include <bits/stdc++.h>
using namespace std;
#define All(a)          (a).begin(), (a).end()
#define Lwb             lower_bound
#define Upb             upper_bound
#define Sz(a)           int((a).size())
#define u_map           unordered_map
#define Exist(a, b)     (find(All(a), (b)) != (a).end())
#define Sort(x)         sort(All(x))
#define Gsort(x)        sort(All(x), greater<typeof(*((x).begin()))>())
#define Unique(v)       Sort(v); (v).resize(unique(ALL(v)) - (v).begin())
#define ooi             INT_MAX
#define ool             LLONG_MAX
#define ll              long long int
#define ull             unsigned ll
#define ld              long double
#define pii             pair<int,int>
#define pll             pair<ll,ll> 
#define mem(x,y)    memset(x,y,sizeof x )
int cnt[30];
int32_t main(){
    ll num,cnt=0; cin>>num;
    while(num>0){
        cnt++;
        num-=2;
    }
    cout<<cnt;
    }

    
    


Measured memory_bytes: 256
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <cstring>
#include <cstdlib>
#include <algorithm>

using namespace std;

#define mp make_pair
#define pb push_back
#define x first
#define y second

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vpii;

const int N=100010;

int a[N],b[N],c[N],delta[N];
bool v[N];

int main()
{
	int n;scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	int m;ll k;scanf("%d%lld",&m,&k);
	for (int i=1;i<=n;i++) b[i]=i;
	for (int i=1;i<=m;i++)
	{
		int x;scanf("%d",&x);
		swap(b[x-1],b[x]);
	}
	memset(v,0,sizeof(v));
	for (int i=1;i<=n;i++)
		if (!v[i])
		{
			int l=0,x=i;
			while (!v[x])
			{
				c[++l]=x;v[x]=1;
				x=abs(b[x]);
			}
			int p=k%l;
			for (int j=1;j<=l;j++)
			{
				int x=(j+p-1)%l+1;
				delta[c[j]]=a[c[x]+1]-a[c[x]];
			}
		}
	double ans=a[1];
	for (int i=1;i<=n;i++)
	{
		printf("%.1lf\n",ans);
		ans+=delta[i];
	}
	return 0;
}


Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;

/* short */
#define pb push_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)

/* REPmacro */
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define FORR(i, a, b) for(int i = (a); i >= (b); i--)
#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOREACH(x, a) for(auto x : a)

/* exchange */
#define CHMIN(a, b) (a) = min((ll)(a), (ll)(b))
#define CHMAX(a, b) (a) = max((ll)(a), (ll)(b))

/* function */
#define IN(x) cin >> x
#define DEBUG(x) cerr << (x) << " "
#define LN() cerr << "\n"
#define PRINT(x) cout << (x) << endl
#define BR cout << endl

/* const */
const int ARRAY = 100005;
const int INF = 1001001001; // 10^9
const ll LINF = 1001001001001001001; // 10^18
const int MOD = 1e9 + 7;

ll N = 0;
ll K;
ll ret = 0;
string s;
vector<vector<ll>> table(101, vector<ll>(100001, 0));
ll a[101];

int main(void){
  IN(N);
  IN(K);
  FOR(i, 1, N+1) {
    IN(a[i]);
  }
  table[0][0] = 1;
  FOR(n, 1, N+1) {
    FOR(k, 0, K+1) {
      if (k == 0) {
        table[n][k] = 1;
      } else {
        table[n][k] = table[n][k-1] + table[n-1][k];
        table[n][k] %= MOD;
        if (k-1-a[n] >= 0) table[n][k] -= table[n-1][k-1-a[n]];
        if (table[n][k] < 0) table[n][k] += MOD;
      }
      // DEBUG(table[n][k]);
    }
    // LN();
  }
  ret = table[N][K];
  PRINT(ret);

  

}


Measured memory_bytes: 80256
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<cstring>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
#include<time.h>

using namespace std;
typedef long long ll;
typedef long double ld;
#define all(a) (a).begin(),(a).end()
#define EPS (1e-5)
#define bit(n,k) ((n>>k)&1)
const ll Mod = 1000000007;
const ll mod = 998244353;
struct H {
	ll x, y;
	bool operator<(const H& b) const {
		if (x != b.x) return x < b.x;
		return y < b.y;
	}
	bool operator>(const H& b) const {
		if (x != b.x) return x > b.x;
		return y > b.y;
	}
	bool operator==(const H& b) const { return x == b.x && y == b.y; }
	bool operator!=(const H& b) const { return (*this) != b; }
};
struct P {
	ll pos, cost;
	bool operator<(const P& b) const { return cost < b.cost; }
	bool operator>(const P& b) const { return cost > b.cost; }
};
struct B {
	ll to, cost;
};
struct E {
	ll from, to, cost;
	bool operator<(const E& b) const { return cost < b.cost; }
	bool operator>(const E& b) const { return cost > b.cost; }
};
template<typename T, typename U>
void chmin(T& a, U b) {
	if (a > b) a = b;
}
template<typename T, typename U>
void chmax(T& a, U b) {
	if (a < b) a = b;
}
template<typename T>
T max_0(T a) {
	if (a < 0) return 0;
	return a;
}
template<typename T>
T min_0(T a) {
	if (a > 0) return 0;
	return a;
}
ll read() {
	ll u;
	ll k = scanf("%lld", &u);
	return u;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j % i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}//x^n%p
ll bitcount(ll x) {
	int sum = 0;
	for (int i = 0; i < 20; i++)
		if ((1ll << i) & x) sum++;
	return sum;
}
/*ll fact_[100000];
ll comb(ll x, ll y, ll mod = Mod) {
	if (!fact_[0]) {
		fact_[0] = 1;
		for (int i = 1; i < 1000000; i++) {
			fact_[i] = fact_[i - 1] * i % mod;
		}
	}
	if (x < y) return 0;
	return mod_pow(fact_[x], mod, mod) *
		mod_pow(fact_[x - y], mod - 2, mod) % mod *
		mod_pow(fact_[y], mod - 2, mod) % mod;
}//xCy*/
const ll Inf = 3023372036854775807;
const int inf = 1500000000;
#define int long long
//----------------------------------------------------
int n;
H a[2000];
signed main() {
	cin >> n;
	ld ans = 0;
	vector<int>v;
	for (int i = 0; i < n; i++) {
		v.push_back(i);
		cin >> a[i].x >> a[i].y;
	}
	int k = 1;
	do {
		for (int j = 1; j < n; j++) {
			ans += sqrt(pow(a[v[j]].x - a[v[j - 1]].x, 2) + pow(a[v[j]].y - a[v[j - 1]].y, 2));
		}
	} while (next_permutation(all(v)));
	for (int i = 1; i <= n; i++) {
		ans /= i;
	}
	printf("%.20LF\n", ans);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define MODADD(ADD_X,ADD_Y)  (ADD_X+ADD_Y)%MOD;
#define MODSUB(SUB_X,SUB_Y)  (SUB_X-SUB_Y)+MOD)%MOD;
#define MODMUL(MUL_X,MUL_Y)  (MUL_X*MUL_Y)%MOD;
#define LCM(LCM_X,LCM_Y) (LCM_X*LCM_Y)/__gcd(LCM_X,LCM_Y);
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e7;
int dx[]= {1,0,-1,0,1,-1,1,-1};
int dy[]= {0,1,0,-1,1,-1,-1,1};
bool mark[MAX];
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    ll a,b;
    cin>>a>>b;
    map<ll,int>mp;
    vector<ll>v;
    ll sq=sqrt(a);
    for(int i=1; i<=sq; i++)
    {
        if(a%i==0)
        {
            ll c=a/i;
            if(c!=i)
                mp[c]++;
            mp[i]++;
        }
    }
    sq=sqrt(b);
    for(int i=1; i<=sq; i++)
    {
        if(b%i==0)
        {
            ll c=b/i;
            if(c!=i && mp[c])
                v.push_back(c);
            if(mp[i])
                v.push_back(i);
        }
    }
    int ans=0,sz=v.size(),cnt=v.size();
    for(int i=0; i<sz; i++)
    {
       if(v[i]==1)
        continue;
        for(int j=0; j<sz; j++)
        {
            if(i==j || mark[j])
                continue;
            if(v[j]%v[i]==0)
                mark[j]=1,cnt--;
        }
    }
    cout<<cnt<<endl;

    return 0;
}


Measured memory_bytes: 4168
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(void)
{
  int n,k,c=0;
  cin>>n>>k;
  int h[n];
  for(int i = 0;i<n;i++) cin>>h[i];
  for(int i = 0;i<n;i++)
  {
      if(h[i] >= k) c++;
  }
  cout << c << endl;
  return 0;
}



Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, begin, end) for(ll i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(ll i=(begin)-1;i>=(end);i--)
#define IREP(i, n) IFOR(i,n,0)
#define SORT(a) sort(a.begin(), a.end())
#define ISORT(a) sort(a.begin(), a.end(),greater<ll>())
#define REVERSE(a) reverse(a.begin(), a.end())
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) cout << #v << "=(" << v[0]; FOR(i_debug, 1, v.size()){ cout << "," << v[i_debug]; } cout << ")" << endl;
#define mdebug(m) cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;}
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)

#define ll long long
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define INF 1000000000000000000

using vec = vector<ll>;
using mat = vector<vec>;
using Pii = pair<ll, ll>;
using PiP = pair<ll, Pii>;
using PPi = pair<Pii, ll>;
using bvec = vector<bool>;
using Pvec = vector<Pii>;


template<typename T> void readv(vector<T> &a) { REP(i, a.size()) cin >> a[i]; }
void readv_m1(vector<int> &a) { REP(i, a.size()) {cin >> a[i]; a[i]--;} }

ll mod = 1000000007;

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

	ll L;
	cin >> L;
	vec a(N);
	REP(i, N) {
		cin >> a[i];
	}

	ll ansi = -1;
	REP(i, N - 1) {
		if (a[i] + a[i + 1] >= L) {
			ansi = i;
			cout << "Possible" << endl;
			break;
		}
	}
	if (ansi == -1) {
		cout << "Impossible" << endl;
		return 0;
	}

	REP(i, ansi) {
		cout << i + 1 << endl;
	}
	IFOR(i, N - 1, ansi + 1) {
		cout << i + 1 << endl;
	}

	cout << ansi + 1 << endl;

	return 0;
}

Measured memory_bytes: 1664
while True:
    table = input().split()

    a = int(table[0])
    op = table[1]
    b = int(table[2])

    if op == '?':
        break

    if op == '+':
        print("%d"%(a+b))
    elif op == '-':
        print("%d"%(a-b))
    elif op == '/':
        print("%d"%(a/b))
    else:
        print("%d"%(a*b))


Measured memory_bytes: 5596
n, k = map(int, input().split())
h = [int(input()) for _ in range(n)]

sorted_trees = sorted(h, reverse=True)

minimum = float('inf')
for i in range(n-(k-1)):
    diff = sorted_trees[i] - sorted_trees[i+(k-1)]
    if diff < minimum:
        minimum = diff
print(minimum)

Measured memory_bytes: 51032
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>

using namespace std;
typedef long long ll;

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

    ll N;
    cin >> N;

    ll min_cap = -1;
    ll temp;
    for (int i = 0; i < 5; i++) {
        cin >> temp;
        min_cap = ((temp < min_cap) || (min_cap == -1)) ? temp : min_cap;
    }


    ll quot, remainder;
    ll minutes = 4;
    quot = N / min_cap;
    minutes += quot;
    remainder = N % min_cap;

    minutes += (remainder == 0) ? 0 : 1;

    cout << minutes << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<stack>

#define MAX 120
#define WHITE 0
#define GRAY 1
#define BLACK 2

using namespace std;

static const int N =120;

int n;//頂点数
int T;//時刻
int d[MAX];//発見時刻
int f[MAX];//終了時刻
int color[MAX];//判別
int M[N][N];

void dfs_v(int u){
   
    color[u] = GRAY;
    T++;
    d[u] = T;
    for(int v=0; v<n; v++){
        if(M[u][v]==0){
            continue;
        }
        if(color[v]==WHITE){
            dfs_v(v);
        }
    }
    
    color[u]= BLACK;
    T++;
    f[u] = T;
}

void dfs(){
    for(int j=0; j<n; j++){
        color[j] = WHITE;
        
    }
    T = 0;
    
    for(int j=0; j<n; j++){
        if(color[j] == WHITE){
            dfs_v(j);
        }
    }
    
    for(int j=0; j<n; j++){
        printf("%d %d %d\n", j+1, d[j], f[j]);
    }
}

int main(){
    
    
    //cin >> n;
    
    int Adj[MAX];
    int u, k, v;
    
    scanf("%d", &n);
    
    for(int b=0; b<n; b++){
        for(int i=0; i<n; i++){
        M[b][i] = 0;
        }
    }
    
    
    
    for(int j=0; j<n; j++){
        //cin >> u >>k;
        scanf("%d %d", &u, &k);
        u--;
        for(int a=0; a<k; a++){
            /*cin >> v;
            Adj[v] = 1;
            
            if(Adj[v] != 0){
            M[u][v] = 1;
            }*/
            
            scanf("%d", &v);
            v--;
            M[u][v] = 1;
        }
    }
    
    dfs();
    return 0;
}




Measured memory_bytes: 3268
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define PII pair<int,int>
#define VI vector<int>
#define VPII vector<pair<int,int> >
#define PLL pair<long long,long long>
#define VPLL vector<pair<long long,long long> >
#define F first
#define S second
typedef long long LL;
using namespace std;
const int MOD = 1e9+7;
const int SIZE = 1e6+10;
int input[SIZE][3];
int ma[SIZE],an[SIZE];
int bfs[SIZE];
VI e[SIZE];
void go(int in[]){
    int x=in[0]-1;
    int dd=in[1];
    int v=in[2];
    if(dd<=ma[x])return;
    ma[x]=dd;
    bfs[0]=x;
    int rr=1;
    REP(i,rr){
        int x=bfs[i];
        if(!an[x])an[x]=v;
        if(!ma[x])continue;
        REP(j,SZ(e[x])){
            int y=e[x][j];
            int nd=ma[x]-1;
            if(nd>ma[y]){
                ma[y]=nd;
                bfs[rr++]=y;
            }
        }
    }
}
int main(){
    DRII(N,M);
    REP(i,M){
        DRII(x,y);x--;y--;
        e[x].PB(y);
        e[y].PB(x);
    }
    DRI(Q);
    REP(i,Q)REP(j,3)RI(input[i][j]);
    MS1(ma);
    for(int i=Q-1;i>=0;i--){
        go(input[i]);
    }
    REP(i,N)printf("%d\n",an[i]);
    return 0;
}


Measured memory_bytes: 36856
#include <stdio.h>


int main(void)
{
	int n, m;
	int X, Y;
	int x[100], y[100];
	int z;
	int xmax=-100,ymin=100;

	scanf("%d %d", &n, &m);
	scanf("%d %d", &X, &Y);


	for (int i = 0; i < n; i++){
		scanf("%d", &x[i]);
		if (x[i]>xmax){
			xmax = x[i];
		}
	}

	for (int i = 0; i < m; i++){
		scanf("%d", &y[i]);
		if (y[i]<ymin){
			ymin = y[i];
		}
	}

	if (xmax < X){
		xmax = X;
	}

	if (ymin>Y){
		ymin = Y;
	}

	if ((ymin - xmax) > 0){
		printf("No War\n");
	}
	else{
		printf("War\n");
	}

	return 0;
}



Measured memory_bytes: 128
w, h, n = map(int, input().split())
x_y_a = [list(map(int, input().split())) for _ in range(n)]

minX, maxX, minY, maxY = 0, w, 0, h
for i in range(n):
    if x_y_a[i][2] == 1 and x_y_a[i][0] > minX: # paint x < xi
        minX = x_y_a[i][0]
    elif x_y_a[i][2] == 2 and x_y_a[i][0] < maxX: # paint x > xi
        maxX = x_y_a[i][0]
    elif x_y_a[i][2] == 3 and x_y_a[i][1] > minY: # paint y < yi
        minY = x_y_a[i][1]
    elif x_y_a[i][2] == 4 and x_y_a[i][1] < maxY: # paint y > yi
        maxY = x_y_a[i][1]

xl = maxX - minX
yl = maxY - minY
if xl > 0 and yl > 0:
    print(xl * yl)
else:
    print(0)


Measured memory_bytes: 38384
#include <iostream>
#define llint long long
#define inf 1000000000000000

using namespace std;

llint n, m;
llint a[1005], b[1005];
llint dp[1005][1005];

int main(void)
{
  while(1){
    cin >> n >> m;
    if(n == 0 && m == 0) break;

    for(int i = 1; i <= n; i++) cin >> a[i], a[i]--;
    for(int i = 1; i <= n; i++) cin >> b[i], b[i]--;
    for(int i = 1; i <= n; i++) a[i] = (b[i]-a[i]+m) % m;

    for(int i = 1; i <= n; i++){
      for(int j = 0; j <= n; j++){
        dp[i][j] = inf;
      }
    }
    dp[1][0] = a[1];

    for(int i = 1; i < n; i++){
      for(int j = 0; j <= n; j++){
        if(a[i]+j*m >= a[i+1]+j*m){
          dp[i+1][j] = min(dp[i+1][j], dp[i][j]);
          if(j+1 <= n) dp[i+1][j+1] = min(dp[i+1][j+1], dp[i][j] + (a[i+1]+(j+1)*m) - (a[i]+j*m));
        }
        else{
          if(j > 0) dp[i+1][j-1] = min(dp[i+1][j-1], dp[i][j]);
          dp[i+1][j] = min(dp[i+1][j], dp[i][j] + (a[i+1]+j*m) - (a[i]+j*m));
        }
      }
    }

    llint ans = inf;
    for(int i = 0; i <= n; i++) ans = min(ans, dp[n][i]);
    cout << ans << endl;
  }

  return 0;
}



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

using namespace std;

#define umap std::unordered_map
#define uset std::unordered_set
#define _all(container) std::begin(container), std::end(container)
#define _in(container, value) (std::find(_all(container), value) != std::end(container))
#define _in_if(container, predicate) (std::find_if(_all(container), predicate) != std::end(container))
#define _odd(value) (value & 1)
#define _even(value) !(value & 1)
#define _for(i, n) for (int i = 0; i < n; ++i)
#define _FOR(i, k, n) for (int i = k; i <= n; ++i)
#define _FORR(i, k, n) for (int i = n; i >= k; --i)

using Integer = long long;
using vint = vector<int>;
using pint = pair<int, int>;
using vpint = vector<pint>;
using vdouble = vector<double>;
using cint = const int;
using cdouble = const double;

/**
 * @brief Overloading the << operator to quickly print out the content of the containers.
 */
template <typename T, template <typename, typename = std::allocator<T>> class Container>
std::ostream& operator<<(std::ostream& os, const Container<T>& container)
{
    using ContainerType = Container<T>;
    for (typename ContainerType::const_iterator it = container.begin(); it != container.end(); ++it) {
        os << *it << " ";
    }

    return os;
}

void solve()
{
    int N;

    cin >> N;

    vint v(N);
    _for(i, N)
    {
        cin >> v[i];
    }

    int sum = std::accumulate(_all(v), 0);

    vint cumsum(N);
    std::partial_sum(_all(v), cumsum.begin());

    int min_sub = INT_MAX;
    _for(i, N - 1) {
      min_sub = std::min(min_sub, std::abs(sum - 2 * cumsum[i]));
    }

    cout << min_sub << "\n";
}

int main(int argc, char**)
{
    if (argc > 1) {
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    }
    ios::sync_with_stdio(false);
    cin.tie(0);

    solve();
}


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

int main() {
  int n, m, ans = 0;
  cin >> n >> m;
  int k[m], s[m][n], p[m];
  int sw[n+1];
  for ( int i = 0; i < m; i++ ) {
    cin >> k[i];
    for ( int j = 0; j < k[i]; j++ ) {
      cin >> s[i][j];
    }
  }
  for ( int i = 0; i < m; i++ ) {
    cin >> p[i];
  }

  for ( int z = 0; z < pow(2,n); z++ ) {
    int tmp = z;
    for ( int l = 1; l <= n; l++ ) {
      sw[l] = ( tmp%2 == 1 ) ? true : false;
      tmp >>= 1;
    }
    bool flag = true;
    for ( int i = 0; i < m; i++ ) {
      int ct = 0;
      for ( int j = 0; j < k[i]; j++ ) {
        ct += ( sw[s[i][j]] ) ? 1 :0;
      }
      if ( ct%2 != p[i] ) { flag = false; break; }
    }
    if ( flag ) { ans++; }
  }

  cout << ans;
  return 0;
}

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

using namespace std;

int main(void){
	int w, d, h[10], hd[10], i, b[20], c[20], e[20], ans;
	while(1){
		scanf("%d%d",&w,&d);
		if(w == 0 && d == 0) break;
		memset(b,0,sizeof(b));
		for(i = 0;i < w;i++){
			scanf("%d",&h[i]);
			b[h[i] - 1]++;
		}
		memset(c,0,sizeof(c));
		for(i = 0;i < d;i++){
			scanf("%d",&hd[i]);
			c[hd[i] - 1]++;
		}
		for(i = 0;i < 20;i++)
			e[i] = max(b[i],c[i]);
		ans = 0;
		for(i = 0;i < 20;i++)
			ans += e[i] * (i + 1);
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 1188
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll inf=1e9+7;
const ll mod=998244353;
int main(){
    ll n,k;cin>>n>>k;
    ll ans=0;
    while(n){
        ans++;
        n/=k;
    }
    cout<<ans<<endl;
}

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

const int maxn=1e5+6,mod=1e9+7;
long long dp[maxn][15];
string s;

int main()
{
	cin>>s;
	dp[0][0]=1;
	for(int i=0;i<s.size();++i) {
		if(s[i]=='?') {
			for(int r=0;r<13;++r)
				for(int j=0;j<=9;++j) {
					(dp[i+1][(r*10+j)%13]+=dp[i][r])%=mod;
				}
		}
		else {
			for(int r=0;r<13;++r) (dp[i+1][(r*10+s[i]-'0')%13]+=dp[i][r])%=mod;
		}
	}
	printf("%lld",dp[s.size()][5]);
}

Measured memory_bytes: 12160
import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws Exception {
        try (Scanner sc = new Scanner(System.in)) {
            int N = sc.nextInt();

            int ans = (int) Math.ceil(N / 1.08);

            int check = (int) (ans * 1.08);

            if (N != check) {
                System.out.println(":(");
            } else {
                System.out.println(ans);
            }
        }
    }

}


Measured memory_bytes: 21716
N = int(input())

if N % 2 == 0:
    ans = 0
    for x in range(1, 28):
        ans += N // (2*5**x)
    print(ans)

else:
    print(0)


def function(x):
    if x < 2:
        return 1
    else:
        return x * function(x - 2)



Measured memory_bytes: 38256
#include <bits/stdc++.h>
#define INF 2e9
#define MOD 1000000007
#define MOD9 998244353
#define intMAX 51000;
#define PI 3.14159265359
using namespace std;
typedef long long llong;
// typedef long double ldouble;

using Graph = vector<vector<int>>;

// int ctoi(const char c){
//   if('0' <= c && c <= '9') return (c-'0');
//   return -1;
// }

// int gcd(int a, int b){
//   int ma = max(a,b);
//   int mi = min(a,b);
//   if(mi == 0) return ma;

//   return gcd(mi, ma%mi);
// }

// llong POW(llong a, llong b){
//   if(b == 0) return 1;
//   else{
//     if(b%2 == 0) return POW(a * a % MOD, b / 2) % MOD;
//     else return a * POW(a * a % MOD, b / 2) % MOD;
//   }
// }

int main(){
  string S;
  cin >> S;
  if(S[0] == S[2]) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> bool cmax(T& a, U b) { if (a<b) {a = b; return true;} else return false; }
template<class T, class U> bool cmin(T& a, U b) { if (a>b) {a = b; return true;} else return false; }

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

  ll n;
  cin >> n;
  vl a(n);
  rep(i, n) cin >> a[i];

  vector<ll> sum(n);
  vector<vi> ind(n);

  rep(i, n) {
    for (int j = i+1; j <= n; j += (i+1)) {
      ind[j-1].push_back(i);
    }
  }


  vector<int> ans;
  for (int i = n-1; i >= 0; i--) {
    if (sum[i]%2 != a[i]) {
      for (auto&& j : ind[i]) {
        sum[j]++;
      }
      ans.push_back(i+1);
    }
  }

  cout << ans.size() << endl;
  for (auto&& i : ans) {
    cout << i << endl;
  }
}


Measured memory_bytes: 25980
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define rep(i,a,b) for(int i = a; i <= b; i++)
using namespace std;
const int N = 100010;
char s[N];
int main() {
	scanf("%s",s + 1); int n = strlen(s + 1), s0 = 0;
	rep(i,1,n) if (s[i] == 'p') s0--;
	cout <<s0 + n / 2<<endl;
}

Measured memory_bytes: 384
#!/usr/bin/env python3

import math, itertools, operator
from math import *
from math import factorial as fact
from functools import reduce
from statistics import mean, median, median_low, median_high, mode
# Before Python 3.5
from fractions import gcd
#import numpy
#import scipy, scipy.special
#from sympy import isprime, nextprime
#from sympy.ntheory import factorint

def lcm(a, b):
    return a * b // gcd(a,b)

def perm(a, b):
    import scipy.special
    return scipy.special.perm(a, b, exact = True)

def comb(a, b):
    import scipy.special
    return scipy.special.comb(a, b, exact = True)

def dfact(n):
    import scipy.special
    return scipy.special.factorial2(n, exact = True)

def prod(l):
    return reduce(operator.mul, l)

def input_ints(inp = input, sep = ' ', conv = int):
    return map(conv, inp().split(sep = sep))

################################################################################

A, B = input_ints()
if A == B:
    print(A*2)
else:
    print(max(A,B)*2 - 1)


Measured memory_bytes: 5376
#include<stdio.h>

int main(void)
{
	char dmy;
	int count, b, f, r, v;
	int Floor[4][3][10];
	char c, d;

	//初期化
	for (int i = 0; i < 4; i++)
	{
		for (int j = 0; j < 3; j++)
		{
			for (int z = 0; z < 10; z++)
			{
				Floor[i][j][z] = 0;
			}
		}
	}

	//読み込み処理
	scanf("%d", &count);
	scanf("c", &dmy);
	for (int i = 0; i < count; i++)
	{
		scanf("%d %d %d %d", &b, &f, &r, &v);
		Floor[b -1][f - 1][r - 1] += v;
	}

	//出力処理
	for (int i = 0; i < 4; i++)
	{
		if(i != 0)
		{
			printf("####################\n");
		}
		for (int j = 0; j < 3; j++)
		{
			for (int z = 0; z < 10; z++)
			{
				printf(" %d", Floor[i][j][z]);
			}
			printf("\n");
		}
	}
	return 0;
}


Measured memory_bytes: 2104
N = int(input())
nums = list(map(int, input().split(' ')))

res = 'Yes'

nums[0] -= 1
for i in range(N - 1):
    diff = nums[i + 1] - nums[i]
    if diff == 0:
        continue
    if diff >= 0:
        nums[i + 1] -= 1
    if diff < 0:
        res = 'No'
        break

print(res)

Measured memory_bytes: 15020
#ifndef __cplusplus
    cat << EOF
#endif
#include <bits/stdc++.h>
using namespace std;

#define rep(...) overload_rep(__VA_ARGS__, rep_1, rep_0)(__VA_ARGS__)
#define rep_0(i, end) for(int i = 0; i < (end); ++i)
#define rep_1(i, fr, ba) for(int i = (fr); i <= (ba); ++i)
#define overload_rep(arg0, arg1, arg2, name, ...) name
#define all(box) box.begin(), box.end()

template <class T, class U> inline bool chmax(T& lhs, const U& rhs) { if(lhs < rhs) { lhs = rhs; return 1; } return 0; }
template <class T, class U> inline bool chmin(T& lhs, const U& rhs) { if(lhs > rhs) { lhs = rhs; return 1; } return 0; }

int main() {

    int N, Q;
    cin >> N >> Q;
    vector<int> a(N);
    rep(i, N) cin >> a[i];
    sort(all(a));
    while(Q--) {
        int l, r;
        cin >> l >> r;
        cout << upper_bound(all(a), r) - lower_bound(all(a), l) << '\n';
    }

}



Measured memory_bytes: 3164
#include <iostream>
typedef long long ll;

using namespace std;

ll beki5(ll x){
	ll r = 1;
	for(ll i=0;i<5;i++){
		r *= x;
	}
	return r;
}

int main(){
	ll x,a,b;
	cin >> x;
	for(a=64;a>-1000;a--){
		for(b=a-1;b>-1000;b--){
			if(beki5(a)-beki5(b) == x)
				goto EXIT;
		}
	}
	EXIT: cout << a << ' ' << b << endl;
}


Measured memory_bytes: 3612
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>

using namespace std;

int main() {
	char x, y;
	cin >> x >> y;

	if (x == y) {
		cout << '=' << endl;
	} else {
		cout << (x < y ? '<' : '>') << endl;
	}
	return 0;
}


Measured memory_bytes: 256