akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define ll long long
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define endl "\n"
#define pi 3.14159265358979323846264338327950288
#define MOD 1000000007
#define INF -100000000000000
#define ordered_set tree<pair< ll int ,ll  int>, null_type,less<pair<ll int, ll int>>, rb_tree_tag,tree_order_statistics_node_update> 
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
using namespace std;
#define lld long double
using namespace __gnu_pbds;
ll int countWays(vector<ll int>arr, ll int m,ll int N) 
{ 
    ll int count[N + 1]; 
    memset(count, 0, sizeof(count)); 
      
    // base case 
    count[0] = 1; 
      
    // count ways for all values up  
    // to 'N' and store the result 
    for (ll int i = 1; i <= N; i++) 
        for (ll int j = 0; j < m; j++) 
  
            // if i >= arr[j] then 
            // accumulate count for value 'i' as 
            // ways to form value 'i-arr[j]' 
            if (i >= arr[j]) 
                count[i] = (count[i]%MOD+count[i - arr[j]]%MOD)%MOD; 
      
    // required number of ways  
    return count[N];  
      
} 
int main()
{
    fast;
    ll int s;
    cin>>s;ll int i;
    vector<ll int> v;
    for(i=3;i<=s;i++)
    	v.PB(i);
    cout<<countWays(v,s-2,s);
}



Measured memory_bytes: 3656
#include<stdio.h>
int main() {
	long int N, K,i,ans1=0,ans2=0;
	scanf("%ld %ld", &N, &K);
	for (i = 1; i <= N; i++) {
		if (i%K == 0) {
			ans1++;
		}
		if (K % 2 == 0 && i%K == K / 2) {
			ans2++;
		}
	}

	printf("%ld\n", ans1*ans1*ans1+ans2*ans2*ans2);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(ll i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll n;
  cin >> n;
  deque<ll> q;
  rep(i, n) {
    ll a;
    cin >> a;
    if(i % 2)
      q.push_front(a);
    else
      q.push_back(a);
  }
  rep(i, n) {
    if(n % 2) {
      cout << q.back() << (i == n - 1 ? '\n' : ' ');
      q.pop_back();

    } else {
      cout << q.front() << (i == n - 1 ? '\n' : ' ');
      q.pop_front();
    }
  }
}

Measured memory_bytes: 5240
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
  input = input.split("\n")
  tmp0 = input[0].split(" ")
  A = Number(tmp0[0])
  B = Number(tmp0[1])
  K = Number(tmp0[2])

  var cnt=0
  var ans = []
  for(var i=1; i <= 100; i++){
    if(A%i===0 && B%i===0){
      ans.push(i)
    }
  }  
  console.log(ans[ans.length-K])

}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
// Main("100 50 4\n")

Measured memory_bytes: 7372
#include <cmath>
#include <functional>
#include <fstream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <list>
#include <time.h>
#include <math.h>
#include <random>
#include <deque>
#include <queue>
#include <cassert>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>
#include <sstream>
#include <chrono>
#include <cstring>

using namespace std;

typedef long long ll;

#ifdef iq
  mt19937 rnd(228);
#else
  mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
#endif

const int N = 300 + 1;
const int M = 998244353;

int mul(int a, int b) {
  return (a * (ll) b) % M;
}

int sum(int a, int b) {
  int c = a + b;
  if (c >= M) c -= M;
  if (c < 0) c += M;
  return c;
}

void add(int &a, int b) {
  a = sum(a ,b);
}

int dp[N][N][N];
int first_zero[N];

int main() {
#ifdef iq
  freopen("a.in", "r", stdin);
#endif
  ios::sync_with_stdio(0);
  cin.tie(0);
  string s;
  cin >> s;
  int k;
  cin >> k;
  int n = (int) s.size();
  reverse(s.begin(), s.end());
  for (int i = n; i >= 0; i--) {
    first_zero[i] = -1;
    if (i < n) {
      first_zero[i] = first_zero[i + 1];
      if (s[i] == '0') first_zero[i] = i;
    }
  }
  k = min(k, n);
  dp[0][0][0] = 1;
  for (int i = 0; i < n; i++) {
    for (int j = i; j <= n; j++) {
      for (int its = 0; its <= k; its++) {
        if (!dp[i][j][its]) continue;
        int gap = j - i;
        for (int t = 0; t < 2; t++) {
          if (t == 1) {
            if (j != n && s[j] == '1') {
              add(dp[i + 1][j + 1][its], dp[i][j][its]);
            } else {
              if (gap) {
                add(dp[i + 1][j][its], dp[i][j][its]);
              }
            }
          } else {
            int x = first_zero[j];
            if (x != -1) {
              add(dp[i + 1][x + 1][its + (x - j)], dp[i][j][its]);
            }
          }
        }
      }
    }
  }
  int ret = 0;
  for (int j = 0; j <= k; j++) {
    add(ret, dp[n][n][j]);
  }
  cout << ret << endl;
}


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

int main() {
	string input,output1,output2,output3;
	cin >> input;
	output1 = input.substr(0, 5);
	output2 = input.substr(6, 7);
	output3 = input.substr(14, 5);
	cout << output1 << " " << output2 << " " << output3 << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a = sc.nextInt();
        int[] nums = new int[n];
        for(int i = 0; i < n; i++){
            nums[i] = sc.nextInt();
        }
        int x = -1;
        for(int elm: nums){
            if(x < elm)
                x = elm;
        }
        x = Math.max(x, a);
        for(int i = 0; i < n; i++)
            nums[i] = nums[i] - a;
        long[][] dp = new long[n+1][2*n*x + 1];
        dp[0][n * x] = 1;
        for(int j = 1; j <= n; j++){
            for(int t = 0; t <= 2 * n * x; t++){
                if((t - nums[j - 1] < 0) || (t - nums[j - 1] > 2 * n * x))
                    dp[j][t] = dp[j - 1][t];
                else
                    dp[j][t] = dp[j - 1][t] + dp[j - 1][t - nums[j - 1]];
            }
        }
        System.out.println(dp[n][n * x] - 1);
    }
}


Measured memory_bytes: 25172
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int m = scanner.nextInt();
        int cN,cM;
        cN = (n>1)?(n*(n-1))/2:0;
        cM = (m>1)?(m*(m-1))/2:0;
      /*  if(n>1){
            cN = (n*(n-1))/2;
        }else{
            cN = 0;
        }

        if(m>1){
            cM = (m*(m-1))/2;
        }else {
            cM = 0;
        }*/
        System.out.println(cM+cN);


    }
}


Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int N, K, x;
    int l = 0;
    cin >> N >> K;
    for (int i = 0; i < N; i++){
        cin >> x;
        l += 2*min(x, abs(K-x));
    }
    cout << l << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  int num[31]={};
  for(int i=0;i<28;i++){
    int n;
    scanf("%d",&n);
    num[n]=1;
  }
  for(int i=1;i<31;i++){
    if(num[i]==0){
      printf("%d\n",i);
    }
  }
  return 0;
}


Measured memory_bytes: 2060
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        B_RedOrBlue solver = new B_RedOrBlue();
        solver.solve(1, in, out);
        out.close();
    }

    static class B_RedOrBlue {
        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            int[] a = new int[256];
            in.nextInt();
            for (char ch : in.next().toCharArray()) {
                ++a[ch];
            }
            out.println(a['R'] > a['B'] ? "Yes" : "No");
        }

    }

    static class FastScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public FastScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String rl = in.readLine();
                    if (rl == null) {
                        return null;
                    }
                    st = new StringTokenizer(rl);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 23636
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
answer = 0
if A[0] < B[0]:
    answer += A[0]
    tmp_B = B[0] - A[0]
else:
    answer += B[0]
    tmp_B = 0
tmp_A = A[1]
for i in range(N-1):
    if tmp_B >= tmp_A:
        answer += tmp_A
        tmp_B = B[i+1]
        tmp_A = A[i+2]
    else:
        answer += tmp_B
        tmp_A = tmp_A - tmp_B
        tmp_B = B[i+1]
        if tmp_A <= tmp_B:
            answer += tmp_A
            tmp_B = tmp_B - tmp_A
            tmp_A = A[i+2]
        else:
            answer += tmp_B
            tmp_B = 0
            tmp_A = A[i+2]
if tmp_A > tmp_B:
    answer += tmp_B
else:
    answer += tmp_A
print(answer)

Measured memory_bytes: 82020
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
class Solve
{
    enum LR
    {
        L, R
    }
    struct Point
    {
        public int x, y;
        public Point(int x, int y)
        {
            this.x = x;
            this.y = y;
        }
    }
    public static void Main()
    {
        int[] hw = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int h = hw[0], w = hw[1];
        int n = int.Parse(Console.ReadLine());
        int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();

        var b = new int[h, w];
        int s = h * w;
        LR lr = LR.R;
        Point p = new Point(0, 0);
        for (int i = 0; i < n; i++)
        {
            int color = i + 1;
            for (int j = 0; j < a[i]; j++)
            {
                b[p.y, p.x] = color;
                if (lr == LR.R)
                {
                    int newX = p.x + 1;
                    if (newX >= w)
                    {
                        p.y++;
                        lr = LR.L;
                    }
                    else
                    {
                        p.x = newX;
                    }
                }
                else
                {
                    int newX = p.x - 1;
                    if (newX < 0)
                    {
                        p.y++;
                        lr = LR.R;
                    }
                    else
                    {
                        p.x = newX;
                    }
                }

            }
        }

        for (int i = 0; i < h; i++)
        {
            for (int j = 0; j < w; j++)
            {            
                Console.Write(b[i,j]);
                if(j<(w-1))
                {
                    Console.Write(" ");
                }
            }
            Console.WriteLine();
        }
    }
}

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

// Numeric Constants
#define N 1000000007
#define maxs 200005
#define mins 3005
#define eps 1e-14
#define imax 2000000200
#define llmax 1000000002000000000ll
#define pi 3.141592653589793

// Others
#define ll long long
#define pb push_back
#define gc getchar_unlocked
#define iosbase ios_base::sync_with_stdio(false)
#define pii pair<ll,int>
#define pll pair<ll,ll>
#define ppi pair<pair<int,int>,int>
#define ppl pair<pll,ll>
#define vi vector<int>
#define sc scanf
#define pr printf
#define lld I64d
#define F first
#define S second
#define siter set<int>::iterator
#define p_pq priority_queue
#define ub upper_bound
#define lb lower_bound

ll minVal[mins][mins];
ll a[maxs];

int main()
{
	ll n,i,j,k,x;
	sc("%lld %lld",&n,&x);
	for(i=0;i<n;i++){
		sc("%lld",&a[i]);
	}
	for(i=0;i<n;i++){
		ll d=0;
		ll val=a[i];
		for(j=(i-1+n)%n;j!=i;j=(j-1+n)%n){
			minVal[i][d]=val;
			val=min(val,a[j]);
			d++;
		}
		minVal[i][d]=val;
	}
	ll ans=llmax;
	for(i=0;i<n;i++){
		ll temp=0;
		for(j=0;j<n;j++){
			temp+=minVal[j][i];
		}
		ans=min(ans,temp+i*x);
	}
	pr("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 39424
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = pow(10, 9) + 7;
//const ll MOD = 998244353;
//const ll MOD = ;
ll mod(ll A, ll M) {return (A % M + M) % M;}
const ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll divCeil(ll A, ll B) {return (A + (B - 1)) / B;}
ll myctoi(char C) {return C - '0';}
char myitoc(ll N) {return '0' + N;}
#define FINALANS(A) {cout << (A) << endl; exit(0);}

int main()
{
  ll H, W;
  cin >> H >> W;

  ll B = 0;
  vector<vector<char>> S(H + 2, vector<char>(W + 2, '#'));
  for (ll i = 1; i < H + 1; i++)
  {
    for (ll j = 1; j < W + 1; j++)
    {
      cin >> S.at(i).at(j);
      if (S.at(i).at(j) == '#')
        B++;
    }
  }

  vector<vector<ll>> mv = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
  vector<vector<ll>> L(H + 2, vector<ll>(W + 2, -1));
  queue<pair<ll, ll>> Q;
  Q.push(make_pair(1, 1));
  L.at(1).at(1) = 0;
  while (!Q.empty())
  {
    ll Y = Q.front().first;
    ll X = Q.front().second;
    //cerr << X << " " << Y << endl;
    if (Y == H && X == W)
      break;
    Q.pop();
    for (ll i = 0; i < 4; i++)
    {
      ll y = Y + mv.at(i).at(0);
      ll x = X + mv.at(i).at(1);
      if (S.at(y).at(x) != '#' && L.at(y).at(x) == -1)
      {
        Q.push(make_pair(y, x));
        L.at(y).at(x) = L.at(Y).at(X) + 1;
      }
    }
  }

  ll ans = (Q.empty()) ? -1 : H * W - L.at(H).at(W) - 1 - B;
  cout << ans << endl;

  /*
  for (ll i = 1; i < H + 1; i++)
  {
    for (ll j = 1; j < W + 1; j++)
    {
      cerr << L.at(i).at(j) << " ";
    }
    cerr << endl;
  }
  */
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int n, m, a[505][505], cnt;
struct node
{
	int x1, y1, x2, y2;
}q[500005];

int main()
{
	cin >> n >> m;
	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <= m; j++)
		{
			cin >> a[i][j];
		}
	}
	for (int xx = 1; xx <= 200; xx++)
	{
		for (int i = 1; i <= n; i++)
		{
			for (int j = 1; j <= m; j++)
			{
				if (a[i][j] % 2 == 1)
				{
					if (i < n && a[i + 1][j] % 2 == 1)
					{
						q[++cnt] = {i, j, i + 1, j};
						a[i][j]--;
						a[i + 1][j]++;
						continue;
					}
					if (j < m && a[i][j + 1] % 2 == 1)
					{
						q[++cnt] = {i, j, i, j + 1};
						a[i][j]--;
						a[i][j + 1]++;
						continue;
					}
					if (i < n)
					{
						q[++cnt] = {i, j, i + 1, j};
						a[i][j]--;
						a[i + 1][j]++;
					}
					else if (j < m)
					{
						q[++cnt] = {i, j, i, j + 1};
						a[i][j]--;
						a[i][j + 1]++;
					}
				}
			}
		}
	}
	cout << cnt << endl;
	for (int i = 1; i <= cnt; i++)
	{
		cout << q[i].x1 << " " << q[i].y1 << " " << q[i].x2 << " " << q[i].y2 << endl;
	}
	return 0;
}

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

int main(){
	char s[10000+4];
	int i=0;
while(scanf("%s",&s)!=EOF){
i=0;
	int Jc=0,Ic=0;
	while(s[i+2]!='\0'){
		if(s[i]=='J'&&s[i+1]=='O'&&s[i+2]=='I')Jc++;
		if(s[i]=='I'&&s[i+1]=='O'&&s[i+2]=='I')Ic++;
		i++;
	}
	printf("%d\n%d\n",Jc,Ic);
}
}

Measured memory_bytes: 1136
/*  -*- coding: utf-8 -*-
 *
 * f.cc: F - Fork in the Road
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 600;

/* typedef */

typedef vector<int> vi;

/* global variables */

vi nbrs[MAX_N];
bool rcs[MAX_N];
double dp[MAX_N], maxdpjs[MAX_N], tdp[MAX_N];

/* subroutines */

/* main */

int main() {
  int n, m;
  scanf("%d%d", &n, &m);

  for (int i = 0; i < m; i++) {
    int s, t;
    scanf("%d%d", &s, &t);
    s--, t--;
    nbrs[s].push_back(t);
  }

  rcs[0] = true;
  for (int i = 0; i < n; i++)
    if (rcs[i]) {
      vi &nbri = nbrs[i];
      for (vi::iterator vit = nbri.begin(); vit != nbri.end(); vit++) {
	int &j = *vit;
	rcs[j] = true;
      }
    }
  
  dp[n - 1] = 1.0;
  for (int i = n - 2; i >= 0; i--)
    if (rcs[i]) {
      vi &nbri = nbrs[i];
      int sz = nbri.size();

      dp[i] = 0.0;
      maxdpjs[i] = -1.0;
      for (vi::iterator vit = nbri.begin(); vit != nbri.end(); vit++) {
	int &j = *vit;
	dp[i] += (1.0 + dp[j]);
	if (maxdpjs[i] < dp[j]) maxdpjs[i] = dp[j];
      }
      dp[i] /= sz;
      //printf("%d: maxdpjs=%lf, sz=%d\n", i, maxdpjs[i], sz);
    }
  //for (int i = 0; i < n; i++) printf("%lf ", dp[i]); putchar('\n');
  //printf("%lf\n", dp[0]);
  double mind = dp[0];
  
  for (int i = n - 2; i >= 0; i--)
    if (rcs[i] && nbrs[i].size() > 1) {
      copy(dp, dp + n, tdp);

      int szi = nbrs[i].size();
      tdp[i] = (dp[i] * szi - (1.0 + maxdpjs[i])) / (szi - 1);

      for (int j = i - 1; j >= 0; j--)
	if (rcs[j]) {
	  vi &nbrj = nbrs[j];
	  int szj = nbrj.size();
	  tdp[j] = 0.0;

	  for (vi::iterator vit = nbrj.begin(); vit != nbrj.end(); vit++) {
	    int &jj = *vit;
	    tdp[j] += (1.0 + tdp[jj]);
	  }
	  tdp[j] /= szj;
	}

      if (tdp[0] > 0.0 && mind > tdp[0]) mind = tdp[0];
      //printf("%d: %lf\n", i, tdp[0]);
    }

  printf("%.10lf\n", mind - 1.0);
  return 0;
}


Measured memory_bytes: 1408
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String c = br.readLine();
		
		if (c.equals("a") || c.equals("i") ||c.equals("u")||c.equals("e")||c.equals("o")) {
			System.out.println("vowel");
		}
		
		else{
			System.out.println("consonant");
		}

	}

}


Measured memory_bytes: 8148
x, n = gets.split.map(&:to_i)
ps = gets.split.map(&:to_i).sort!

if n == 0
  puts x
  exit 0
end

ans = diff = x

101.downto(0) do |i|
  next if ps.include?(i)

  abs = (x - i).abs
  if abs <= diff
    ans = i
    diff = abs
  end
end

puts ans


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

#define int long long
#define rep(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define reps(i, n) for (int (i) = 1; (i) <= (n); (i)++)
#define all(x) (x).begin(), (x).end()
#define bit(n) (1LL << (n))
typedef vector<int> vint;
typedef pair<int, int> pint;
constexpr double PI = 3.1415926535897932384626433832795028;
constexpr int DY[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int DX[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
template<typename T, typename U> inline bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> inline bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
struct SetUp {
    SetUp() {
        cout << fixed << setprecision(20);
        cerr << fixed << setprecision(20);
    };
} setUp;

int N, K;
vint G[110000];
int mod = 1e9 + 7;

int dfs(int idx, int par) {
    int ret = 1;
    int p = idx == 1 ? 1 : 2;
    int k = 0;
    rep(i, G[idx].size()) {
        if (G[idx][i] == par) { continue; }
        (ret *= max(K - k - p, 0LL) * dfs(G[idx][i], idx) % mod) %= mod;
        k++;
    }
    return ret;
}

signed main() {
    cin >> N >> K;
    rep(i, N - 1) {
        int a, b;
        cin >> a >> b;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    cout << dfs(1, 0) * K % mod << endl;
}

Measured memory_bytes: 12928
n,m=gets.chomp.split.map(&:to_i)
cities = {}
(1..n).map{|value| cities.store(value,0)}
m.times do
  a,b=gets.chomp.split.map(&:to_i)
  cities[a]+=1
  cities[b]+=1
end
cities.map{|key,value| puts value}

Measured memory_bytes: 1788
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

const int MAXN=15;

int n,m;
int e[MAXN][MAXN];

int sum[1<<MAXN];
int mem[1<<MAXN][MAXN];

int go(int left,int at) {
	if(at==n-1) return sum[left|(1<<at)];
	int &ret=mem[left][at];
	if(ret==-1) {
		ret=INT_MIN;
		REP(to,n) if(left&(1<<to)) if(e[at][to]!=-1) {
			int mask=(1<<n)-1-(left-(1<<to));
			for(int g=0;g<(1<<n);g=(g+mask+1)&~mask) {
				assert(((left-(1<<to))&g)==g); assert((g&(1<<to))==0); assert((g&(1<<at))==0); assert(at!=to);
				int cur=go(left-(1<<to)-g,to);
				if(cur==INT_MIN) continue;
				cur+=sum[(1<<at)+g];
				cur+=e[at][to];
				//printf("%x %d: %d->%d g=%x keep=%d (%d,%d)\n",left,at,at+1,to+1,g,cur,sum[(1<<at)+g],e[at][to]);
				if(cur>ret) {
					ret=cur;
				}
			}
		}
		//printf("%x %d: keep=%d\n",left,at,ret);
	}
	return ret;
}

void run() {
	scanf("%d%d",&n,&m);
	REP(i,n) REP(j,n) e[i][j]=-1;
	REP(i,m) { int a,b,c; scanf("%d%d%d",&a,&b,&c); --a,--b; e[a][b]=e[b][a]=c; }

	REP(i,1<<n) {
		sum[i]=0;
		REP(j,n) FOR(k,j+1,n) if((i&(1<<j))&&(i&(1<<k))&&(e[j][k]!=-1)) sum[i]+=e[j][k];
	}
	memset(mem,-1,sizeof(mem));
	int keep=go((1<<n)-1-(1<<0),0);
	int tot=0; REP(i,n) FOR(j,i+1,n) if(e[i][j]!=-1) tot+=e[i][j];
	//printf("tot=%d\n",tot);
	int ret=tot-keep; printf("%d\n",ret);
}

int main() {
	run();
	return 0;
}


Measured memory_bytes: 2304
#include <bits/stdc++.h>
#define ALL(x) (x).begin(),(x).end()
#define PB push_back
#define MP make_pair
#define Mod 998244353
#define MOD 1000000007
using namespace std;
using lint = long long;
using vi = vector<lint>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<lint, lint>;

// cout << fixed << setprecision(12)

lint modpow(lint a, lint n, lint m = MOD){
  lint ans = 1;
  while(n>0){
    if(n%2==1) ans *= a; 
    ans %= m;
    a *= a; 
    a %= m;
    n /= 2;
  }
  return ans;
}

lint inv(lint a, lint m = MOD){
  return modpow(a, m-2, m);
}

///////////////////////////////////

int main(){
  lint A,B,C,K; cin>>A>>B>>C>>K;
  while(A>=B){
    B *= 2;
    K--;
  }
  while(B>=C){
    C *= 2;
    K--;
  }
  if(K>=0) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3668
#include <stdio.h>
#include<stdlib.h>
#define NIL NULL

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};

typedef struct node * Node;
Node root;

void insert(int);
void inorder(Node);
void preorder(Node);

int main(){

  int m,i,a;
  char str[10];

  scanf("%d",&m);
  for(i=0;i<m;i++){
    scanf("%s",str);
    if(str[0]=='i'){
      scanf("%d",&a);
      insert(a);
    }
    else if(str[0]=='p'){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }
  
  return 0;
  
}

void inorder(Node x){
  if(x!=NIL){
    inorder(x->left);
    printf(" %d",x->key);
    inorder(x->right);
  }
}

void preorder(Node x){
  if(x!=NIL){
    printf(" %d",x->key);
    preorder(x->left);
    preorder(x->right);
  }
}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x!=NIL){
    y=x;
    if(z->key<x->key){
      x=x->left;
    }
    else{
      x=x->right;
    }
  }
  z->parent=y;
  if(y==NIL){
    root=z;
  }
  else if(z->key<y->key){
    y->left=z;
      }
  else{
    y->right=z;
  }
}

Measured memory_bytes: 24040
from collections import deque

if __name__ == "__main__":

    n = int(input())
    queue = deque()

    for _ in range(n):
        param = input().split(" ")

        if param[0] == "0":
            if param[1] == "0":
                queue.appendleft(param[2])
            else:
                queue.append(param[2])

        elif param[0] == "1":
            print(queue[int(param[1])])

        elif param[0] == "2":
            if param[1] == "0":
                queue.popleft()
            else:
                queue.pop()



Measured memory_bytes: 34652
#include<iostream>
using namespace std;
int main(){
	int X,Y; cin>>X>>Y;
	bool flag = false;
	for(int i=0;i<=X;i++){
		if((2*i+4*(X-i))==Y){
			flag = true;
			break;
		}
	}
	if(flag){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
}


Measured memory_bytes: 3620
#include <iostream>
#include <vector>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
using ll = long long;

int bird = 2;
int tatol = 4;

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

    if (y % bird != 0) {
        cout << "No" << endl;
        return 0;
    }
    if (x * bird > y || x * tatol < y) {
        cout << "No" << endl;
        return 0;
    }

    cout << "Yes" << endl;
    return 0;
}

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

using ll = long long;
#define repi(n) for (int i = 0; i < n; i++)
#define repj(n) for (int j = 0; j < n; j++)
#define repk(n) for (int k = 0; j < n; k++)
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, a, b) for (auto i = a; i < b; i++)
#define repv(itr) for (auto&& v : itr)
const int dx[] = {-1, 0, 0, 1, -1, -1, 1, 1};
const int dy[] = {0, -1, 1, 0, -1, 1, -1, 1};
template <typename T>
T minptr(T begin, T end) {
  T re = begin;
  for (T i = begin + 1; i != end; i++) {
    if (*i < *re) re = i;
  }
  return re;
}
template <typename T>
T maxptr(T begin, T end) {
  T re = begin;
  for (T i = begin + 1; i != end; i++) {
    if (*i > *re) re = i;
  }
  return re;
}
int __vmax(int x) {
  return INT_MAX;
}
double __vmax(double x) {
  return 1e+300;
}
ll __vmax(ll x) {
  return LLONG_MAX;
}
int __vmin(int x) {
  return INT_MIN;
}
double __vmin(double x) {
  return -1e+300;
}
ll __vmin(ll x) {
  return LLONG_MIN;
}
template <typename T>
vector<T> lis(T begin, T end, bool allowequal = false, bool lds = false) {
  using V = typename iterator_traits<T>::value_type;
  int n = end - begin;
  vector<V> a(n, lds ? __vmin(*begin) : __vmax(*begin));
  vector<int> id(n);
  if (lds && allowequal) {
    for (int i = 0; i < n; i++) {
      id[i] = n - 1 -
              (lower_bound(a.rbegin(), a.rend(), begin[i]) - 1 - a.rbegin());
      a[id[i]] = begin[i];
    }
  } else if (lds) {
    for (int i = 0; i < n; i++) {
      id[i] = n - 1 -
              (upper_bound(a.rbegin(), a.rend(), begin[i]) - 1 - a.rbegin());
      a[id[i]] = begin[i];
    }
  } else if (allowequal) {
    for (int i = 0; i < n; i++) {
      id[i] = upper_bound(a.begin(), a.end(), begin[i]) - a.begin();
      a[id[i]] = begin[i];
    }
  } else {
    for (int i = 0; i < n; i++) {
      id[i] = lower_bound(a.begin(), a.end(), begin[i]) - a.begin();
      a[id[i]] = begin[i];
    }
  }
  int m = *maxptr(id.begin(), id.end());
  vector<T> re(m + 1);
  for (int i = n - 1; i >= 0; i--) {
    if (id[i] == m) re[m--] = begin + i;
  }
  return re;
}
template <typename T>
T gcd(T a, T b) {
  return b ? gcd(b, a % b) : a;
}

int main() {
  int n;
  cin >> n;
  int re = 0;
  repr(i, 1, n + 1) if ((int)(floor(log10(i))) % 2 == 0) re++;
  cout << re << endl;
}


Measured memory_bytes: 512
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>

#define MAX_N (100000L)
#define MAX_Q (100000L)
#define INF (1000000000000000000L)

using namespace std;

int main() {
  // read inputs
  long N, Q, as[MAX_N], xs[MAX_Q];
  scanf("%ld %ld", &N, &Q);
  for (long i = 0; i < N; i++) {
    scanf("%ld", &as[i]);
  }
  for (long q = 0; q < Q; q++) {
    scanf("%ld", &xs[q]);
  }

  // pre-calculation
  long acceos[MAX_N + 2] = {}, accs[MAX_N + 1] = {};
  for (long i = 0; i < N; i++) {
    acceos[i + 2] = acceos[i] + as[i];
  }
  for (long i = 0; i < N; i++) {
    accs[i + 1] = accs[i] + as[i];
  }

  // solve
  for (long q = 0; q < Q; q++) {
    const long x = xs[q];
    long le = 0, re = N + 1;
    while (re - le > 1) {
      const long m = (re + le) / 2;
      const long d = abs(as[N - m] - x);
      // count the number of elements (excluding as[N - m]) as[i] that satisfy
      // |as[i] - x| <= |as[N - m] - x| = d
      const long min_i = lower_bound(as, as + N, x - d) - as, max_i = N - m - 1;
      const long md = max_i - min_i + 1;
    //   printf("le = %ld, re = %ld, m = %ld, min_i = %ld, max_i = %ld\n", le, re,
    //          m, min_i, max_i);
      if (md == m || md == m - 1) {
        le = m - 1;
        re = m + 1;
        break;
      } else if (md < m - 1) {
        re = m;
      } else {
        le = m;
      }
    }
    const long K = (le + re) / 2;
    const long ans = accs[N] - accs[N - K] + acceos[N - 2 * K + 1] -
                     acceos[(N - 2 * K + 1) % 2];
    // printf("x = %ld, K = %ld\n", x, K);
    printf("%ld\n", ans);
  }
}

Measured memory_bytes: 4736
/*ANKON GHOSH
  KUET,ECE 2K16*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1e18
#define MAX 1000000
#define mod 1000000007
#define sf(a) scanf("%lld",&a)
#define sff(a,b) scanf("%lld %lld",&a,&b)
#define sfff(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define Case(i) cout<<"Case #"<<i<<": "
#define pf(a) printf("%lld\n",a)
#define pfsn printf("NO\n")
#define pfs  printf("YES\n")
#define pff(a,b) printf("%lld %lld\n",a,b)
#define pfff(a,b,c) printf("%lld %lld %lld\n",a,b,c)
#define pffff(a,b,c,d) printf("%lld %lld %lld %lld\n",a,b,c,d)
#define FOR(i,n) for(ll i=0;i<n;i++)
#define FOR1(i,n) for(ll i=1;i<=n;i++)
#define LOOP(x,y) for(ll r=x;r<=y;r++)
#define RFOR(i,n) for(ll i=n-1;i>=0;i--)
#define RFOR1(i,n) for(ll i=n;i>0;i--)
#define RLOOP(x,y) for(ll i=y;i>=x;i--)
#define m_p(a,b) make_pair(a,b)
#define p_b(a) push_back(a)
#define ff first
#define ss second
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL)
map<ll,ll>mp1,mp;
vector<pair<ll,pair<ll,ll> > >vpp,vpp1;
vector<pair<ll,ll> >v,vp,fin;
vector<ll>v1,v2,dummy;
map<pair<ll,ll>,bool>mbb;
map<ll,bool>mb;
ll n,k,a,b,c,d,ta,sum=0,cnt=0,m,l,req,sz,maxi;
bool sortbysec(const pair<pair<ll,ll>,ll> &a,const pair<pair<ll,ll>,ll> &b)
{
    return (a.second < b.second);
}
vector<ll>adj[MAX+10];
bool visited[MAX+10];
ll dep[MAX+10];
ll arr[MAX+10];
void reset()
{
   FOR(i,MAX)
   {
       visited[i]=0;
       dep[i]=0;
       adj[i].clear();
   }
   mp.clear();
   mp1.clear();
}
void solve()
{
    memset(arr,0,sizeof arr);
    FOR1(i,1000000LL)
    {
        if(i%3==0 or i%5==0)
        {
            continue;
        }
        else arr[i]=i;
    }
    FOR1(i,1000000LL) arr[i]+=arr[i-1];
}
void calc(ll k)
{
    ll sum=0;
    for(ll i=1;i<=k;i++)
    {
        for(ll j=1;j<=k;j++)
        {
            for(ll x=1;x<=k;x++)
            {
                sum+=__gcd(i,__gcd(j,x));
            }
        }
    }
    cout<<sum<<endl;
}
int main()
{
    fast;
    ///cin>>ta;
    //FOR(test,ta)
    //{
    ///solve();
       cin>>n;
       calc(n);
    return 0;
}


Measured memory_bytes: 27088
#include <bits/stdc++.h>
using namespace std;
#define fastIO ios::sync_with_stdio(0), cin.tie(0)
#define endl '\n'
#define ft first
#define sd second
#define pb push_back
#define pob pop_back()
#define pf push_front
#define pof pop_front()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin, (x).rend()
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<char,char> pcc;
typedef pair<double,double> pdd;
typedef pair<long long,long long> pll;
// scanf("%d %d %d %d",&w,&b,&d,&s); %lld
// printf("%d\n" ,points);
// const double PI=acos(-1);

const int L=105;
const int MAX=1e5+5;
const ll oo=1e13;
ll dp[L][MAX];
int w[L],v[L];
int n,W;

int main(){
    cin >> n >> W;
    int lim=0,rta;
    ll aux;
    for(int i=0;i<n;i++){
        cin >> w[i] >> v[i];
        lim+=v[i];
    }
    for(int i=1;i<=lim;i++){
        dp[0][i]=oo;
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=lim;j++){
            if(j-v[i-1]<0) aux=oo;
            else aux=dp[i-1][j-v[i-1]]+w[i-1];
            dp[i][j]=min(aux,dp[i-1][j]);
        }
    }
    for(int i=0;i<=lim;i++){
        if(dp[n][i]<=W) rta=i;
    }
    cout << rta << endl;
    return 0;
}


Measured memory_bytes: 82392
#include<iostream>
#include<cstdio>
#include<algorithm>
/*
容易知道，每一轮T一定是能走就走。因为如果T不走，那么A就可以通过不走来强迫游戏结束。 
并且，如果P经过了一个障碍上方，游戏就结束了。所以A一定会尽可能地让P走到一个障碍上方。 
*/
struct data{
	int x;int y;
	inline bool operator<(const data &B){
		return x==B.x?y<B.y:x<B.x;
	}
	inline void init(int X,int Y){
		x=X,y=Y;
	}
}a[200005];
int n,h,w;
void init(){
	scanf("%d%d%d",&h,&w,&n);
	int x,y;
	for(int i=1;i<=n;++i){
		scanf("%d%d",&x,&y);
		a[i].init(x,y);
	}
	std::sort(a+1,a+1+n);
	int nw=0;
	for(int i=1;i<=n;++i){
		if(a[i].x-nw==a[i].y){
			++nw;
		}
		if(a[i].x-nw>a[i].y){
			printf("%d\n",a[i].x-1);
			return;
		}
	}
	printf("%d\n",h);
}

int main(){
	init();
	return 0;
}

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

using namespace std;

long long N, A[200000], ans = 0;

int main(){
	cin >> N;
	for(int i = 0; i < N; ++i){
		cin >> A[i];
		A[i] -= i + 1;
	}
	sort(A, A + N);
	for(int i = 0; i < N; ++i) ans += abs(A[i] - A[N / 2]);
	cout << ans << endl;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long  a, b, c, res;
    cin>>a>>b>>c;
    res = c*a-b;
    cout<<res<<endl;
    for(int i=1; i<10;i++)
    {
       res = res*a-b;
       cout<<res<<endl;

    }
}


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

#define int long long

int main(){
	int K, i, N = 50;
	scanf("%lld", &K);
	int *a = (int *)malloc(sizeof(int) * N);
	for(i = 0; i < N; i++){
		a[i] = N - 1 + K / N;
	}
	for(i = 0; i < K % N; i++){
		a[i] += N - K % N + 1;
	}
	for(i = K % N; i < N; i++){
		a[i] -= K % N;
	}
	printf("%lld\n", N);
	for(i = 0; i < N; i++){
		printf("%lld ", a[i]);
	}
	printf("\n");
	return 0;
}

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

int main() {
    int N;
    std::cin >> N;
    std::vector<int> v(N);
    for (auto& e : v) std::cin >> e;

    int Q;
    std::cin >> Q;
    for (int q = 0; q < Q; ++q) {
        int l, r, t;
        std::cin >> l >> r >> t;
        std::swap_ranges(v.begin() + l, v.begin() + r, v.begin() + t);
    }

    for (int i = 0; i < v.size(); ++i) {
        std::cout << v[i] << " \n"[i == v.size() - 1];
    }
}



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

int main()
{
    string N;
    cin >> N;
    int j=0;

    for (int i = 0; i < 3; ++i) {
        if (N[i] == '7') { ++j; }
    }

    if (j > 0) { cout << "Yes" << endl; }
    else { cout << "No" << endl; }

}

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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  char x, y;
  cin >> x >> y;
  if (x > y) {
    cout << ">" << endl;
  } else if (x == y) {
    cout << "=" << endl;
  } else {
    cout << "<" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#define fori(x, y) for(int i = x; i<y; i++)
using namespace std;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    char input[4];
    int cont =0;
    fori(0, 4) {
        cin >> input[i];
        if(input[i]=='2') cont++;
    }
    cout << cont << "\n";
    return 0;
}


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

#define debug(x) cout << '[' << #x << " is: " << x << "] " <<"\n";
#define imod(a , n) (a % n + n ) % n

#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
#define inF freopen("fike.txt","r",stdin );
#define outF freopen("cbs.out" , "w" , stdout ) ;
#define sum(a)a * (a + 1 ) / 2
#define ll long long

const double eps = 1e-9 , PI = acos(-1) ;
const int N = 1e5 + 6, oo = 1e9 , M = 4 * N, mod = 2004 , K = 12;
int n , m , vis[N] , dp[N] ;
vector<int>adj[N];
int dfs(int u){
    vis[u] ++;
    if(adj[u].empty())
        return 0 ;

    int &ret = dp[u];
    if(~ret)
        return ret ;
    for(auto v : adj[u]){

            ret = max(ret , 1 + dfs(v) );
    }
    return ret ;


}
int32_t main(){

    //inF;
    // Dont Forget memset
    memset(dp , -1 , sizeof dp);
    //calculate constraints please!!!
    fastio;
   cin >> n >> m;
   while(m--){
     int u , v ;
     cin >> u >> v ;
     adj[u].push_back(v);
     //adj[v].push_back(u);
   }
   int ans = 0 ;
   for(int i = 1 ; i <= n ; i++){
        if(!vis[i])
            ans = max(ans , dfs(i));
   }
   cout << ans ;
   return 0 ;
}



Measured memory_bytes: 11888
#include <stdio.h>

int main() {
    int i, j, h, w;
    
    while(1){
        scanf("%d %d",&h ,&w);
        if((h+w)==0) break;
        for(i=1; i<=h; i++){
            for(j=1; j<=w; j++){
                if(i>1&&i<h&&j<w&&j>1){
                    printf(".");
                } else {
                    printf("#");
                }
            }
            printf("\n");
        }
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 2104
n = int(input())
h = list(map(int, input().split()))[::-1]
ans = "Yes"
for i in range(n-1):
    if h[i] >= h[i+1]: continue
    if h[i] >= h[i+1]-1:
        h[i+1] -= 1
    else:
        ans = "No"
        break
print(ans)

Measured memory_bytes: 20448
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <map>
#include <unordered_map>
#include <chrono>
#include <numeric>
using namespace std;
using ll = long long;
const ll INF = (ll)1e18+1;
const ll DIV = 1000000007;
//#define TEST

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
#ifdef TEST
    chrono::system_clock::time_point start, end;
    start = chrono::system_clock::now();
#endif
    long N;
    cin >> N;
    ll count = 0;
    for(size_t i=1;i<=N; i++)
    {
        //1, 10 , 100, 1000 , 10000, 100000
        if(i < 10) count++;
        if(i >=100 && i < 1000) count++;
        if(i >= 10000 && i < 100000) count++;
    }
    cout << count << endl;
#ifdef TEST
    end = chrono::system_clock::now();
    cerr << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000.0) << "[ms]" << endl;
#endif
    return 0;
}

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

using namespace std;

typedef long long int ll;

const ll INF = 1e9;

int main()
{
	int n;
	cin>>n;
	vector<ll> a(n),b(n);
	for(int i = 0; i < n; i++){
		cin>>a[i]>>b[i];
	}
	if(a==b){
		cout<<0<<endl;
		return 0;
	}
	ll sum = 0,min_b =INF;
	for(int i = 0; i < n; i++){
		sum+=a[i];
		if(a[i]>b[i])
			min_b = min(min_b,b[i]);
	}
	cout<<sum-min_b<<endl;

	return 0;
}


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

#define ll long long int

int main()
{
	int n;
	cin >> n;
	ll ans = 1, temp = 1;
	vector<ll> v(n);
	bool flag = false;
	for(int i=0;i<n;i++)
	{
		cin >> v[i];
	}
	for(int i=0;i<n;i++)
	{
		ans *= v[i];
		if(v[i]!=0 && ans < temp)	
		{
			for(int j=i+1;j<n;j++)
			{
				if(v[j]==0)
				{
					cout << 0 << endl;
					flag = true;
					break;
				}
			}
			if(flag)	break;
			else
			{
				cout << -1 << endl;
				flag = true;
				break;
			}
		}	
		temp = ans;
	}
	if(!flag)
	{
		if(ans > 1000000000000000000) cout << -1 << endl;
		else cout << ans << endl;
	}
	return 0;
}

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

#ifdef TESTING
  #include "dump.hpp"
#else
  #define DUMP(...)
  #define DEBUG(...)
#endif

typedef unsigned int ui;
typedef long long ll;
typedef unsigned long long ull;
#define SZ(a) int((a).size())
#define _REP(_1,_2,_3,_4,name,...) name
#define _REP4(i,b,e,s) for(decltype(e) _b=(b),_e=(e),i=_b+(0<(s)?0:(s));(0<(s)?i<_e:_e<=i);i+=(s))
#define _REP3(i,b,e) for(decltype(e) _b=(b),_e=(e),i=(_b<_e?_b:_b-1);(_b<_e?i<_e:_e<=i);(_b<_e?i++:i--))
#define _REP2(i,n) for(decltype(n) i=0,_n=(n);i<_n;i++)
#define _REP1(n) for(decltype(n) _i=0,_n=(n);_i<_n;_i++)
#define REP(...) _REP(__VA_ARGS__,_REP4,_REP3,_REP2,_REP1)(__VA_ARGS__)
#define FOR(it,c) for(auto&& it=begin(c);it!=end(c);it++)
#define ROF(it,c) for(auto&& it=rbegin(c);it!=rend(c);it++)
#define EB emplace_back
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define INT(n) int n;assert(0<scanf("%d",&n))

static const int MAXP = 100000;
vector<int> ps, fs;
void init(){
  fs.reserve(1 + MAXP);
  for(int i = 0; i <= MAXP; i++){fs.push_back(i);}
  for(int i = 2; i <= MAXP; i++){
    if (fs[i] == i){
      ps.push_back(i);
      for (int j = i; j <= MAXP; j += i){
        fs[j] = min(fs[j], i);
      }
    }
  }
}
bool isprime(const long long& n){
  if (n <= MAXP){
    return (1 < n && fs[n] == n);
  } else {
    for(int p: ps){
      if (n % p == 0){return false;}
    }
    return true;
  }
}

int main(){
  init();
  INT(n); INT(m);
  int ans = 1;
  if (!isprime(m)){
    REP(i, n, m + 1){
      if (m % i == 0){
        ans = m / i;
        break;
      }
    }
  }
  printf("%d\n", ans);
  return 0;
}

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

char ch;
int n,m,a,b,q;
map< char , vector<int> > mp;
vector<int> tmp;
string s;
int p,len;

vector<int> add(const vector<int> &a,const vector<int> &b){
  vector<int> res(n);
  for(int i=0;i<n;i++)res[i]=b[a[i]];  
  return res;
}

vector<int> mul(const vector<int> &a,int b){
  if(b==0)return tmp;
  vector<int> res=mul( add(a,a) , b/2);  
  if(b%2==1)res=add(res,a);
  return res; 
}

vector<int>  calc();

vector<int> getNum(){
  vector<int> res;
  int num=0,flg=0;
  while('0'<=s[p]&&s[p]<='9'){
    num=num*10+(s[p]-'0');
    p++;
    flg=1;
  }
  if(flg==0)num=1;
  if(s[p]=='(')p++,res=calc();
  else res=mp[s[p]];
  p++;
  res=mul(res,num);
  return res;
}

vector<int> calc(){
  vector<int> res=getNum();
  while(1){
    if(p>=len||s[p]==')')break;
    char x=s[p++];
    vector<int> num=getNum();
    if(x=='+')res=add(res,num);
  }
  return res;
}

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

  cin>>n>>m;
  tmp.clear();
  tmp.resize(n);
  for(int i=0;i<n;i++)tmp[i]=i;
  
  for(int i=0;i<m;i++){
    vector<int> v=tmp,w(n);
    cin>>ch>>a;
    while(--a){
      for(int j=0;j+1<n;j++){
        cin>>b;
        if(b==1)swap(v[j],v[j+1]);
      }
    }
    for(int i=0;i<n;i++)w[v[i]]=i;
    mp[ch]=w;
  }
  cin>>q;
  while(q--){
    cin>>s;
    len=s.size();
    p=0;
    vector<int> ans=calc();
    vector<int> ans2(n);
    for(int i=0;i<n;i++){
      ans2[ans[i]]=i;
    }
    for(int i=0;i<n;i++){
      if(i)cout<<' ';
      cout<<ans2[i]+1;
    }
    cout<<endl;
  }
  return 0;
}

Measured memory_bytes: 1272
#include <iostream>

using namespace std;

#define MAX_NUM 100001

typedef struct {
	int num;
	int cnt;
} info;

int allcnt[MAX_NUM] = { 0 };


int main()
{
	int n;

	info fmax1 = { 0 };
	info smax1 = { 0 };
	info fmax2 = { 0 };
	info smax2 = { 0 };

	int ret = 0;

	// INPUT
	cin >> n;

	int* v = new int[n];
	for (int i = 0; i < n; i++) cin >> v[i];


	// START
	for (int i = 0; i < n; i = i + 2) {
		allcnt[v[i]]++;
		if (fmax1.num == v[i]) fmax1.cnt++;
		else if (fmax1.cnt < allcnt[v[i]]) {
			smax1.cnt = fmax1.cnt;
			smax1.num = fmax1.num;
			fmax1.cnt = allcnt[v[i]];
			fmax1.num = v[i];
		}
		else if (smax1.cnt < allcnt[v[i]]) {
			smax1.cnt = allcnt[v[i]];
			smax1.num = v[i];
		}
	}

	for (int i = 0; i < MAX_NUM; i++) allcnt[i] = 0;

	for (int i = 1; i < n; i = i + 2) {
		allcnt[v[i]]++;
		if (fmax2.num == v[i]) fmax2.cnt++;
		else if (fmax2.cnt < allcnt[v[i]]) {
			smax2.cnt = fmax2.cnt;
			smax2.num = fmax2.num;
			fmax2.cnt = allcnt[v[i]];
			fmax2.num = v[i];
		}
		else if (smax2.cnt < allcnt[v[i]]) {
			smax2.cnt = allcnt[v[i]];
			smax2.num = v[i];
		}
	}

	delete[] v;

	if (fmax1.num == fmax2.num) {
		if (fmax1.cnt + smax2.cnt > smax1.cnt + fmax2.cnt) {
			ret = n - fmax1.cnt - smax2.cnt;
		}
		else {
			ret = n - smax1.cnt - fmax2.cnt;
		}


	}
	else {
		ret = n - fmax1.cnt - fmax2.cnt;
	}

	cout << ret << endl;

	return 0;
}


Measured memory_bytes: 1024
def max(a,b); a > b ? a : b; end
  
N, M= gets.split.map(&:to_i)
S = gets.chomp
smin = Array.new(N + 1, N)

(0 .. N).reverse_each.inject(N) do |m,i|
  if i + M < m
    puts -1
    exit
  end
  smin[i] = S[i] == '0' ? i : m
end

ANS = []
N.times.inject(N) do |pos,i|
  break if pos.zero?
  smin[max(pos - M, 0)].tap do |j|
    ANS << pos - j
  end
end
puts ANS.reverse * ' '


Measured memory_bytes: 5628
#include<bits/stdc++.h>
//#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    long long a,s[300005];
    map<long ,long>mp;
    //mp[0]=1;
    for(int i=1;i<=n;i++)
    {
        cin>>a;
        s[i]=s[i-1]+a;

    }
    for(int i=0;i<=n;i++)++mp[s[i]];
        long long ans=0;
    for(auto t:mp)
    {
        ans+=(t.second*(t.second-1))/2;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 14976
package main

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

const (
	maxBufferSize = 1048576
)

type Scanner struct {
	lineScanner *bufio.Scanner
	wordScanner *bufio.Scanner
}

var Stdin *Scanner

func init() {
	Stdin = NewScanner()
	Stdin.lineScanner.Buffer(make([]byte, 0), maxBufferSize)
	Stdin.wordScanner.Buffer(make([]byte, 0), maxBufferSize)
}

func NewScanner() *Scanner {
	scanner := &Scanner{
		lineScanner: bufio.NewScanner(os.Stdin),
		wordScanner: bufio.NewScanner(os.Stdin),
	}
	scanner.lineScanner.Split(bufio.ScanLines)
	scanner.wordScanner.Split(bufio.ScanWords)
	return scanner
}

func (sc *Scanner) NextLine() string {
	Stdin.lineScanner.Scan()
	return Stdin.lineScanner.Text()
}

func (sc *Scanner) Next() string {
	Stdin.wordScanner.Scan()
	return Stdin.wordScanner.Text()
}

func (sc *Scanner) NextInt() int {
	Stdin.wordScanner.Scan()
	ret, err := strconv.Atoi(Stdin.wordScanner.Text())
	if err != nil {
		panic(err)
	}
	return ret
}

func (sc *Scanner) NextNInts(N int) []int {
	ints := make([]int, N)
	for i := 0; i < N; i++ {
		ints[i] = sc.NextInt()
	}
	return ints
}

func (sc *Scanner) NextInt64() int64 {
	Stdin.wordScanner.Scan()
	ret, err := strconv.ParseInt(Stdin.wordScanner.Text(), 10, 64)
	if err != nil {
		panic(err)
	}
	return ret
}

func (sc *Scanner) NextFloat() float64 {
	Stdin.wordScanner.Scan()
	ret, err := strconv.ParseFloat(Stdin.wordScanner.Text(), 64)
	if err != nil {
		panic(err)
	}
	return ret
}



func main() {
	R := Stdin.NextInt()
	G := Stdin.NextInt()

	fmt.Println(2 * G - R)
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;


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


int main() {
    int n; cin >> n;
    vector<int> h(n);
    REP(i,n) cin >> h[i];
    vector<int> dp(n);
    dp[0] = 0;
    dp[1] = abs(h[1]-h[0]);
    FOR(i,2,n) {
        dp[i] = min(abs(h[i]-h[i-1]) + dp[i-1], abs(h[i]-h[i-2]) + dp[i-2]);
    }
    cout << dp[n-1] <<endl;
}


Measured memory_bytes: 1024