akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
const int N = 300 + 7;
const ll INF = (ll) 1e18;
int n, m, tank;
ll d[N][N];
int t[N], ans[N][N];

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

        cin >> n >> m >> tank;

        for (int i = 1; i <= n; i++)
                for (int j = 1; j <= n; j++)
                        d[i][j] = INF;

        for (int i = 1; i <= n; i++)
                d[i][i] = 0;


        for (int i = 1; i <= m; i++)
        {
                int a, b, c;
                cin >> a >> b >> c;
                d[a][b] = d[b][a] = c;
        }

        for (int k = 1; k <= n; k++)
                for (int i = 1; i <= n; i++)
                        for (int j = 1; j <= n; j++)
                                d[i][j] = d[j][i] = min(d[i][j], d[i][k] + d[k][j]);

        for (int i = 1; i <= n; i++)
                for (int j = 1; j <= n; j++)
                        if (d[i][j] <= tank)
                                ans[i][j] = 0;
                        else
                                ans[i][j] = (int) 1e9;

        for (int k = 1; k <= n; k++)
                for (int i = 1; i <= n; i++)
                        for (int j = 1; j <= n; j++)
                                ans[i][j] = ans[j][i] = min(ans[i][j], 1 + ans[i][k] + ans[k][j]);

        int q;
        cin >> q;

        while (q--)
        {
                int a, b;
                cin >> a >> b;
                if (ans[a][b] == (int) 1e9)
                        cout << "-1\n";
                else
                        cout << ans[a][b] << "\n";
        }

        return 0;
}


Measured memory_bytes: 1664
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int ans = 0;
		for(int i = 0; i < n; i++){
			int l = scanner.nextInt();
			int r = scanner.nextInt();
			ans += r - l + 1;
		}
		System.out.println(ans);
	}
}

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

const int MAXN = 110 * 110 * 2;
const int INF = std::numeric_limits<int>::max();
const int MAXM = MAXN * 110 * 10;
int head[MAXN], nxt[MAXM], to[MAXM], val[MAXM], tot = 1;
int S, T, idx;
void addedge(int b, int e, int v) {
	nxt[++tot] = head[b]; to[head[b] = tot] = e; val[tot] = v;
	nxt[++tot] = head[e]; to[head[e] = tot] = b; val[tot] = 0;
}
int dis[MAXN]; std::queue<int> q;
bool bfs() {
	memset(dis, 0, idx + 1 << 2);
	q.push(S); dis[S] = 1;
	while (!q.empty()) {
		int t = q.front(); q.pop();
		for (int i = head[t]; i; i = nxt[i])
			if (val[i] && !dis[to[i]]) {
				q.push(to[i]);
				dis[to[i]] = dis[t] + 1;
			}
	}
	return dis[T] > 0;
}
int dinic(int u, int minv) {
	if (!minv || u == T) return minv;
	int res = 0, t;
	for (int & i = head[u]; i; i = nxt[i])
		if (val[i] && dis[to[i]] == dis[u] + 1 && (t = dinic(to[i], std::min(minv, val[i])))) {
			val[i] -= t;
			val[i ^ 1] += t;
			res += t;
			minv -= t;
			if (!minv) break;
		}
	if (!res) dis[u] = -1;
	return res;
}
int tmp;
int flow() {
	static int te[MAXN];
	int ans = 0;
	memcpy(te, head, idx + 1 << 2);
	while (bfs()) {
		ans += dinic(S, INF);
		if (ans > tmp) break;
		memcpy(head, te, idx + 1 << 2);
	}
	return ans;
}
int in[110][110], out[110][110];
char mat[110][110];
int main() {
	std::ios_base::sync_with_stdio(false), std::cin.tie(0);
	int H, W; std::cin >> H >> W;
	S = idx, T = ++idx;
	for (int i = 1; i <= H; ++i) {
		std::cin >> mat[i] + 1;
		for (int j = 1; j <= W; ++j)
			if (mat[i][j] != '.') {
				in[i][j] = ++idx, out[i][j] = ++idx;
				addedge(in[i][j], out[i][j], mat[i][j] == 'o' ? 1 : INF);
				if (mat[i][j] == 'S') addedge(S, in[i][j], INF);
				if (mat[i][j] == 'T') addedge(out[i][j], T, INF);
				tmp += mat[i][j] == 'o';
			}
	}
	for (int i = 1; i <= H; ++i)
		for (int j = 1; j <= W; ++j) if (mat[i][j] != '.') {
			for (int k = 1; k <= W; ++k) if (mat[i][k] != '.')
				addedge(out[i][j], in[i][k], INF);
			for (int k = 1; k <= H; ++k) if (mat[k][j] != '.')
				addedge(out[i][j], in[k][j], INF);
		}
	int ans = flow(); if (ans > tmp) ans = -1;
	std::cout << ans << std::endl;
	return 0;
}


Measured memory_bytes: 53632
/*Function Template*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int MAX = 510000;
const int MOD = 1000000007;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define Rep(i, n) for(ll i = 1; i < (n); i++)
#define ALL(a)  (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll fac[MAX], finv[MAX], inv[MAX];


template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }

}
ll Len(ll n) {
  ll s=0;
  while(n!=0) s++, n/=10;
  return s;
}


ll Sint(ll n) {
  ll m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(ll i=s-1;i>=0;i--) m+=n/((ll)pow(10,i))-(n/((ll)pow(10,i+1)))*10;
  return m;
}


ll Svec(vector<ll> v){
  ll n=0;
  for(ll i=0;i<v.size();i++) n+=v[i];
  return n;
}


ll GCD(ll a,ll b) {
  return b ? GCD(b,a%b) : a;
}


ll LCM(ll a,ll b){
  return a/GCD(a,b)*b;
}


ll Factorial(ll n){
  ll m=1;
  while(n>=1) m*=n,n--;
  return m;
}

vector<pair<char,ll>> runlength(string s,vector<pair<char,ll>> p){
  ll x=1;
  if(s.size()==1){
    p.push_back(pair<char,ll>(s[0],1));
    return p;
  }
  for(ll i=0;i<s.size()-1;i++){
    if(s[i]==s[i+1]){
      x++;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[i],x));
      }
    }else{
      p.push_back(pair<char,ll>(s[i],x));
      x=1;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[s.size()-1],x));
      }
    }
  }
  return p;
}


ll COM(ll n,ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

const int MAX_N=100010;
vector<bool> sieve_of_eratosthenes(){
  vector<bool> isPrime(MAX_N+1,true);
  for(int i=2;i<=MAX_N;i++){
    if(isPrime[i]){
      for(int j=2*i;j<=MAX_N;j+=i){
        isPrime[j]=false;
      }
    }
  }
  return isPrime;
}



/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
int main() {
  IOS;
  ll n,ans=MOD;
  ll cnt1=0,cnt2=0;
  string s;
  cin>>n>>s;
  cnt2=count(s.cbegin(),s.cend(),'.');
  chmin(ans,cnt1+cnt2);
  ll tmp=ans;
  rep(i,n){
    if(s[i]=='#'){
      cnt1++;
    }else if(s[i]=='.'){
      cnt2--;
    }
    ans=min(ans,cnt1+cnt2);
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 720
#include<stdio.h>

int selectionSort(int b[], int N){
  int i,j,t,sw=0,minj;
  for(i=0;i<N-1;i++){
    minj=i;
    for(j=i;j<N;j++){
      if(b[j]<b[minj]) minj=j;
    }
    t=b[i];
    b[i]=b[minj];
    b[minj]=t;
    if(i!=minj) sw++;
  }
  return sw;
}

int main(){
  int b[100],N,i,sw;
  
  
  scanf("%d",&N);
  for(i=0;i<N;i++) scanf("%d",&b[i]);
  
  sw=selectionSort(b,N);
  
  for(i=0;i<N;i++){
    if(i>0) printf(" ");
    printf("%d",b[i]);
  }
  printf("\n");
  printf("%d\n",sw);
  
  return 0;
}



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

#define MAX 100000

typedef struct {
  int p, k, dep;
  int *l;
} Node;

int main(){
  int i, j, n, id;
  Node T[MAX], tmp;

  scanf("%d",&n);
  for(i = 0; i < n; i++){
    T[i].p = -1;
    T[i].dep = 0;
  }
  for(i = 0; i < n; i++){
    scanf("%d",&id);
    scanf("%d",&T[id].k);
    T[id].l = (int *)malloc(sizeof(int) * T[id].k);
    for(j = 0; j < T[id].k; j++){
      scanf("%d",&T[id].l[j]);
      T[T[id].l[j]].p = id;
    }    
  }

  for(i = 0; i < n; i++){
    tmp = T[i];
    while(1){
      if(tmp.p == -1) break;
      T[i].dep++;
      tmp = T[tmp.p];
	}  
  }


  for(i = 0; i < n; i++){
    if(T[i].dep == 0){
      printf("node %d: parent = %d, depth = %d, root, [", i, T[i].p, T[i].dep);
      
      for(j = 0; j < T[i].k-1; j++){
	printf("%d, ", T[i].l[j]);
      }
 
      if(T[i].k != 0) printf("%d]\n",T[i].l[j]);
      else printf("]\n");
    }
    else if(T[i].k != 0 && T[i].p != -1){
      printf("node %d: parent = %d, depth = %d, internal node, [", i, T[i].p, T[i].dep);
      for(j = 0; j < T[i].k - 1; j++){
	printf("%d, ", T[i].l[j]);
      }
      printf("%d]\n",T[i].l[j]);
    }
    else if(T[i].k == 0){
      printf("node %d: parent = %d, depth = %d, leaf, []\n", i, T[i].p,  T[i].dep);
    }
  }

  return 0;

}

Measured memory_bytes: 6460
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <iostream>
using namespace std;
const int MaxN = 1e5 + 5;
struct NOOD {
	int x, y;
}a[MaxN];
bool cmp(NOOD a, NOOD b){
	if(a.y == b.y) return a.x > b.x;
	return a.y < b.y;
}
int main(){
	int n, m;
	cin>>n>>m;
	for(int i = 1; i <= m; i++){
		cin>>a[i].x>>a[i].y;
	}int ans = 1;
	int u, v;
	sort(a+1,a+1+m,cmp);
	u = a[1].x; v = a[1].y;
	for(int i = 2; i <= m; i++){
		if(a[i].x < v) continue;
		v = a[i].y;
		ans++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
using ll = long long;

int main()
{
	string s,t;
	cin >> s;
	int n = s.size();
	s.push_back('-');
	for(int i = 0;i<n;i++)
	{
		if(s[i]=='B'&&s[i+1]=='C')
		{
			t.push_back('D');
			i++;
		}
		else
		{
			t.push_back(s[i]);
		}
	}
	ll ans = 0;
	ll add = 0;
	for(int i =0;i<n;i++)
	{
		if(t[i]=='A')add++;
		else if(t[i]=='D')ans += add;
		else add = 0;


	}
	cout<<ans<<endl;
}

Measured memory_bytes: 3932
#include<cmath>
#include<bits/stdc++.h>
#define MAX(a,b) (a>b? a:b)
#define MIN(a,b) (a>b? b:a)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repr(i,n) for(lint i=(lint)(n);i>0;--i)
#define reps(i,a,b) for(lint i=a;i<=(lint)(b);i++)
typedef long long lint;
typedef long double ld;
using namespace std;
const ld PI = acos(-1.0);

int main(){
    string O, E;
    cin >> O >> E;
    rep(i,O.size()) {
        cout << O[i];
        if(i<E.size()) cout << E[i];
    }
	return 0;
}

Measured memory_bytes: 256
x = input().split()
A = int(x[0])
B = int(x[1])
C = int(x[2])

if A < B:
    if C in range(A, B):
        print("Yes")
    else:
        print("No")
else:
    if C in range(B, A):
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 3060
#define ll long long int
#include <iostream>
#include <map>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
	int n;
	cin >> n;
	vector <int> a(n);
	int l = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		l ^= a[i];
	}
	for (int i = 0; i < n; i++) {
		cout << (l^a[i]) << ' ';
	}
}

Measured memory_bytes: 4020
/*  -*- coding: utf-8 -*-
 *
 * h.cc: H - Grid 1
 */

#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_H = 1000;
const int MAX_W = 1000;
const int MOD = 1000000007;

/* typedef */

/* global variables */

char flds[MAX_H][MAX_W + 4];
int dp[MAX_H][MAX_W];

/* subroutines */

inline void addmod(int &a, int b) { a = (a + b) % MOD; }

/* main */

int main() {
  int h, w;
  scanf("%d%d", &h, &w);
  for (int y = 0; y < h; y++) scanf("%s", flds[y]);

  dp[0][0] = 1;
  for (int y = 0; y < h; y++)
    for (int x = 0; x < w; x++)
      if (flds[y][x] == '.') {
	if (x + 1 < w && flds[y][x + 1] == '.')
	  addmod(dp[y][x + 1], dp[y][x]);
	if (y + 1 < h && flds[y + 1][x] == '.')
	  addmod(dp[y + 1][x], dp[y][x]);
      }

  printf("%d\n", dp[h - 1][w - 1]);
  return 0;
}


Measured memory_bytes: 5120
n = int(input())
g = [[0 for _ in range(n)] for _ in range(n)]

for _ in range(n):
	a = list(map(int,input().split()))
	u = a.pop(0)
	a.pop(0)
	for v in a:
		g[u-1][v-1] = 1

for a in g:
	print(" ".join(map(str,a)))



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

int main(){
	long long int  n;
	cin>>n;
	map<string,long long int >mp;
	for(long long int  i=0;i<n;i++)
   {
       string s;
       while(!s.size())
       {
           cin>>s;
       }
       sort(s.begin(),s.end());
       if(mp.find(s)!=mp.end())
       {
       //    cout<<"incrementing ="<<s<<endl;
           mp[s]++;
       }
       else
       { // cout<<"inserting s="<<s<<endl;
           mp.insert(make_pair(s,0));
       }
   }
   long long int val=0;
   for(auto s:mp)
   {
       val+=(s.second*(s.second+1)*.5);
   }
   cout<<val<<endl;
}
/*
1
5
3 2 1 2 10
2 3 5 5 5
*/


Measured memory_bytes: 11136
#include <stdio.h>

int main(void){
	int n = 0;
	int i = 0;
	int a[200]={0};
	int f = 0;
	int ans = 0;
	scanf("%d", &n);
	

	for(i = 0; i < n; i++){
		scanf("%d", &a[i]);
		//printf("%d", i);
	}
while(1){
	for(i = 0; i < n; i++){
		if(a[i] % 2 == 0){
			a[i] /= 2;
		}else{
			f = 1;
			break;
		}
	}
	
	if(f == 1){
		break;
	}else{
		ans++;
	}
}

	printf("%d", ans);
	
	return 0;

}

Measured memory_bytes: 128
// Math = ♥
// Sometimes it is people that no one imagines anything of who do things that no one can imagine
// After all this time? Always

#include <bits/stdc++.h>                        // uncomment before submission
//#include <ext/pb_ds/assoc_container.hpp>		// uncomment before submission
//#include <ext/pb_ds/tree_policy.hpp>			// uncomment before submission
//using namespace __gnu_pbds;					// uncomment before submission
using namespace std;
//<---------------------------------------------------Template----------------------------------------------------------->
#define int long long
#define ll long long
#define ld long double
const int INF = 1e15 + 7;
const int MAX = 1e5 + 7;
const int MOD = 1e9 + 7;
typedef pair<ll, ll> ii;
typedef vector<ll> vi;                  // Vector of long long
typedef vector<vi> vvi;                 // Vector of vi
typedef vector<ii> vii;                 // Vector of pairs
typedef vector<vii> vvii;               // Vector of Vector of pairs
typedef vector<bool> vb;                // Vector of bool
#define pq priority_queue               // Max heap (To convert to min heap, use negative sign before every value)
#define ff first                        // For pairs
#define ss second                       // For pairs
#define pb push_back                    // Pushback to vector
#define mp make_pair                    // Makes pairs to be stored as pair
#define all(c) (c).begin(), (c).end()   // Mainly used by me in sorting
// ordered_set adds two new functions to set - (set).find_by_order([kth element based on zero indexing]) and order_of_key()
// order_of_key returns number of elements less that parameter. If element exists, that order is its index
#define ordered_set tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
//<----------------------------------------------------------------------------------------------------------------------->

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin >> s;

    int n = s.length();
    int a = (n - 1) / 2;
    int b = (n + 3) / 2 - 1;

    string s1, s2;
    s1 = s.substr(0, a), s2 = s.substr(b, n);

    string str1 = s1;
    reverse(all(s1));
    string str2 = s2;
    reverse(all(s2));
    string str = s;
    reverse(all(s));

    if (str1 == s1 && str2 == s2 && str == s)
        cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
N = int(input())
a_list = list(map(int, input().split()))

is_even = True
exists_zero = False
min_a = 10 ** 9
for i, a in enumerate(a_list):
    if a == 0:
        exists_zero = True
    else:
        is_even = is_even ^ (a < 0)
    if min_a > abs(a):
        min_a = abs(a)
    a_list[i] = abs(a)

all_plus = is_even | exists_zero
if all_plus:
    print(sum(a_list))
else:
    print(sum(a_list) - min_a * 2)


Measured memory_bytes: 14284
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <cstdlib>
using namespace std;

#define REP(i,n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> pint;
template <class T> inline void chmax(T &a, const T b) { a = max(a, b); }
template <class T> inline void chmin(T &a, const T b) { a = min(a, b); }
template <class T> void pp(T v, int n) { REP(i,n) cout<<v[i]<< ' '; cout << endl; }

void inline TorF(bool tf, const string &trueMessage, const string &falseMessage) { 
  cout << (tf ? trueMessage : falseMessage) << endl;
}
void inline YESNO(bool tf) { TorF(tf, "YES", "NO"); }
void inline YesNo(bool tf) { TorF(tf, "Yes", "No"); }

int main() {
  int N; cin>>N;
  vector<ll> a(N), ans(N);
  ll v = 0;
  REP(i,N) {
    cin>>a[i];
    v ^= a[i];
  }
  REP(i,N) {
    ans[i] = (a[i] ^ v);
  }
  //  pp(a, N);
  //  cout << v << endl;
  pp(ans, N);
  return 0;
}


Measured memory_bytes: 7516
#include <bits/stdc++.h>
#define int long long 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define re(x) cout<<(#x)<<" is "<<(x)<<"\n"; 
#define gif(a,b) ((a)/(b)+((a)%(b)?1:0))
using namespace std;

int Prime(int n)
{
	if(n < 2)
		return 0;
	if(n < 4)
		return 1;
	if(n % 2 == 0 or n % 3 == 0)
		return 0;
	for(int i = 5; i*i <= n; i += 6)
		if(n % i == 0 or n % (i+2) == 0)
			return 0;
	return 1;
}

int32_t main()
{
	IOS
	int T = 1; 
	//cin >> T;  
	for (int t = 0; t < T; ++t)
	{
		int k;
		cin >> k;
		int flag = 0;
		int val = 7;
		for (int i = 1; i <= k ; ++i)
		{
			if(val%k == 0)
			{
				cout << i;
				flag = 1;
				break;
			}
			val = (val*10 + 7)%k;
		}
		if(!flag)
			cout << -1;
	}
	return 0;
}
//if not working? go ahead.


Measured memory_bytes: 3648
import java.io.*;
import java.util.*;

public class Main{
    static MyReader in = new MyReader();
    static PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));

    public static void main(String[] args){
        int N, M; {int[] a = in.ii(); N = a[0]; M = a[1];}
        
        ArrayList<int[]> city = new ArrayList<>(M);
        for(int i = 0; i < M; i++){
            int[] a = in.ii();
            city.add(new int[]{i, a[0], a[1]});
        }
        
        city.sort((x, y) -> {
            int d = x[1]-y[1];
            if(d != 0) return d;
            else return x[2]-y[2];
        });
        
        String[] number = new String[M];
        
        int[] c = city.get(0);
        for(int i = 0; i < M; ){
            int tmp = c[1];
            int j = 1;
            do {
                number[c[0]] = String.format("%06d%06d", tmp, j++);
            } while(++i < M && (c = city.get(i))[1] == tmp);    
        }
        
        for(int i = 0; i < M; i++)
            out.println(number[i]);        
        
        out.flush();
    }

    static class MyReader extends BufferedReader{
        MyReader(){
            super(new InputStreamReader(System.in));
        }

        String s(){
            try{return readLine();}catch(IOException e){return "";}
        }

        String[] ss(){
            return s().split(" ");
        }

        int i(){
            return Integer.parseInt(s());
        }

        int[] ii(){
            String[] ss = ss();
            int[] ii = new int[ss.length];
            for(int j = 0; j < ss.length; j++) ii[j] = Integer.parseInt(ss[j]);
            return ii;
        }

        long l(){
            return Long.parseLong(s());
        }

        long[] ll(){
            String[] ss = ss();
            long[] ll = new long[ss.length];
            for(int j = 0; j < ss.length; j++) ll[j] = Long.parseLong(ss[j]);
            return ll;
        }
    }
}


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

using ll=long long;
const ll z=0;

int main() {
  ll N,C;
  cin >> N >> C;
  vector<ll> x(N+2,0),v(N+2,0);
  x[N+1]=C;
  for(int i=1;i<N+1;i++){
    cin >> x[i] >> v[i];
  }
  vector<ll> R(N+2,0),r(N+2,0);//右回り
  R[0]=z;
  for(ll i=1;i<=N+1;i++){
    R[i]=R[i-1]+v[i]-x[i]+x[i-1];
    r[i]=max(r[i-1],R[i]);
  }
  vector<ll> L(N+2,0),l(N+2,0);//左回り
  L[N+1]=z;
  for(ll i=N;i>=0;i--){
    L[i]=L[i+1]+v[i]+x[i]-x[i+1];
    l[i]=max(l[i+1],L[i]);
  }
  //往復右回り
  vector<ll> RD(N+2,0);
  RD[0]=z;
  for(ll i=1;i<=N;i++){
    RD[i]=max(RD[i-1],R[i]-x[i]);
  }
  //往復左回り
  vector<ll>LD(N+2,0);
  LD[N+1]=z;
  for(ll i=N;i>=1;i--){
    LD[i]=max(LD[i+1],L[i]-C+x[i]);
  }
  ll ans=z;
  ans=max(l[N+1],r[N+1]);
  for(ll i=1;i<N;i++){
    ans=max(ans,r[i]+LD[i+1]);
  }
  for(ll i=1;i<N;i++){
    ans=max(ans,RD[i-1]+l[i]);
  }
  
  cout << ans << endl;

}


Measured memory_bytes: 6528
N,M = map(int,input().split())

li = [ [int(it) for it in input().split()] for i in range(N) ]
lj = [ [int(it) for it in input().split()] for i in range(M) ]

for a,b in li:
  mi = 100000000000
  kk = -1
  k = 0
  for c,d in lj:
    if ( mi > abs(a-c)+abs(b-d) ):
      mi = abs(a-c)+abs(b-d)
      kk = k 
    k += 1
  print ( kk+1 )
  




Measured memory_bytes: 39536
a,b,c=gets.split.map(&:to_i)

a_half=0
b_half=0
c_half=0
count=0
while a%2==0 && b%2==0 && c%2==0
    count+=1
    a_half=a/2
    b_half=b/2
    c_half=c/2
    a=b_half+c_half
    b=c_half+a_half
    c=a_half+b_half
    if count>10**7
        puts -1
        return
    end
end
puts count


Measured memory_bytes: 14328
#define _GLIBCXX_DEBUG //エラーを出すためのおまじない
#include <bits/stdc++.h>
#include <algorithm>
//#include <cstdlib>  // abs() for integer
#include <cmath>    // abs() for float, and fabs()
#include <math.h>
using namespace std;
#define coYES cout << "YES" << endl
#define coNO cout << "NO" << endl
#define coYes cout << "Yes" << endl
#define coNo cout << "No" << endl
#define coyes cout << "yes" << endl
#define cono cout << "no" << endl
//#define cocount cout << count << endl;
#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 Cinint(n) int n;\
cin >> n;
#define Cinvecint(a, n) vector<int> a(n);\
for (int i = 0; i < (int)(n); i++) {\
  int num;\
  cin >> num;\
  a.at(i) = num;\
}
#define Cinstring(s) string s;\
cin >>s;

  

int main() {
  int n;
  cin >> n;
  vector<string> s(n);
  rep(i, n) {
    string ss;
    cin >> ss;
    s.at(i) = ss;
  }
  int countAC, countWA, countTLE, countRE;
  countAC = 0;
  countWA = 0;
  countTLE = 0;
  countRE = 0;
  rep(i, n) {
    if (s.at(i) == "AC") {
      countAC++;
    }
    else if (s.at(i) == "WA") {
      countWA++;
    }
    else if (s.at(i) == "TLE") {
      countTLE++;
    }
    else {
      countRE++;
    }
  }
  cout << "AC" << " " << "x" << " " << countAC << endl;
  cout << "WA" << " " << "x" << " " << countWA << endl;
  cout << "TLE" << " " << "x" << " " << countTLE << endl;  
  cout << "RE" << " " << "x" << " " << countRE << endl;
}


Measured memory_bytes: 6424
#include <algorithm>
#include <string.h>
#include <iostream>
#include <stdio.h>
#include <string>
#include <map>
using namespace std;

typedef long long LL;
typedef map<int, int> MII;
const int N = 2e5 + 10;
int a[N];
MII m;
LL res, n, p;
string s;

int main() {
	cin >> n >> p >> s;
	for (int i = 0; i < n; i++)
		a[i] = s[i] - '0';

	if (p == 2) {
		for (int i = 0; i < n; i++)
			if (a[i] % 2 == 0)
				res += i + 1;
	}
	else if (p == 5) {
		for (int i = 0; i < n; i++)
			if (a[i] % 5 == 0)
				res += i + 1;
	}
	else {
		m[0] = 1;
		int x = 0, t = 1;
		for (int i = n - 1; i >= 0; i--) {
			x = (x + a[i] * t) % p;
			res += m[x];
			m[x]++;
			t = t * 10 % p;
		}
	}

	cout << res << endl;

	return 0;
}

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

int main() {
  long long n, m;
  cin >> n >> m;
  long long ans;
  if (n == 1 && m == 1) {
    ans = 1;
  }
  else if (n == 1 || m == 1) {
    ans = max(n - 2, m - 2);
  }
  else {
    ans = (n - 2)*(m - 2);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define _GLIBCXX_DEBUG
const int MOD = 1000000007;

int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<char>> C(H, vector<char>(W));
  for (int i=0; i<H; i++) {
    for (int j=0; j<W; j++) cin >> C[i][j];
  }
  for (int i=0; i<H; i++) {
    for (int j=0; j<W; j++) {
      if (j!=W-1) cout << C[i][j];
      else cout << C[i][j] << endl;
    }
    for (int j=0; j<W; j++) {
      if (j!=W-1) cout << C[i][j];
      else cout << C[i][j] << endl;
    }
  }
}

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

using ll = long long;
using namespace std;
const int INFint = 2e9+1;
const ll INFll = 2e18+1;
ll MOD=1e9+7;


int main(){
  int N,K;
  cin>>N>>K;
  if (K > (N-1)*(N-2)/2){
    cout << -1 << endl;
    return 0;
  }
  int tmp = (N-1)*(N-2)/2 - K;
  cout << tmp + N-1 << endl;
  for(int i(2);i<=N;i++){
    cout << 1 << " " << i << endl;
  }
  for(int i(2);i<=N;i++){
    for(int j(i+1);j<=N;j++){
      if(tmp==0)break;
      tmp--;
      cout << i << " " << j << endl;
    }
  }
  return 0;
}



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

int main(){
  int a,b,c;
  cin>>a>>b>>c;
  if(a!=b&&a!=c)
    cout<<a<<endl;
  if(b!=a&&b!=c)
    cout<<b<<endl;
  if(c!=a&&c!=b)
    cout<<c<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
using namespace std;
using ll = long long;
int main() {
	string S; cin >> S;
	int a = -1, z = 0;
	for (int i = 0; i < S.size(); i++) {
		if (S[i] == 'A' && a == -1) a = i;
		else if (S[i] == 'Z') z = i;
	}
	cout << z-a+1 << endl;
	//system("pause");
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;
using ll = long long;

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int n, d;
    cin >> n >> d;
    d = 2 * d + 1;
    cout << (n + d - 1) / d << endl;    
}

Measured memory_bytes: 256
using System;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using static System.Math;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;

public static class P
{
    public static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        var s = Console.ReadLine();
        int curMaxLength = 0;
        var hash = new RollingHash(s);
        for (int i = 0; i < s.Length; i++)
            for (int j = i; j < s.Length; j++)
                while (curMaxLength < j - i && j + curMaxLength < n && hash.Slice(i, curMaxLength + 1) == hash.Slice(j, curMaxLength + 1)) curMaxLength++;
        Console.WriteLine(curMaxLength);
    }
}

class RollingHash
{
    const ulong MASK30 = (1UL << 30) - 1;
    const ulong MASK31 = (1UL << 31) - 1;
    const ulong MOD = (1UL << 61) - 1;
    const ulong POSITIVIZER = MOD * ((1UL << 3) - 1);
    static uint Base;
    static ulong[] powMemo = new ulong[5000 + 1];
    static RollingHash()
    {
        Base = (uint)new Random().Next(129, int.MaxValue);
        powMemo[0] = 1;
        for (int i = 1; i < powMemo.Length; i++)
            powMemo[i] = CalcMod(Mul(powMemo[i - 1], Base));
    }

    ulong[] hash;

    public RollingHash(string s)
    {
        hash = new ulong[s.Length + 1];
        for (int i = 0; i < s.Length; i++)
            hash[i + 1] = CalcMod(Mul(hash[i], Base) + s[i]);
    }

    public ulong Slice(int begin, int length)
    {
        return CalcMod(hash[begin + length] + POSITIVIZER - Mul(hash[begin], powMemo[length]));
    }

    private static ulong Mul(ulong l, ulong r)
    {
        var lu = l >> 31;
        var ld = l & MASK31;
        var ru = r >> 31;
        var rd = r & MASK31;
        var middleBit = ld * ru + lu * rd;
        return ((lu * ru) << 1) + ld * rd + ((middleBit & MASK30) << 31) + (middleBit >> 30);
    }

    private static ulong Mul(ulong l, uint r)
    {
        var lu = l >> 31;
        var rd = r & MASK31;
        var middleBit = lu * rd;
        return  (l & MASK31) * rd + ((middleBit & MASK30) << 31) + (middleBit >> 30);
    }

    private static ulong CalcMod(ulong val)
    {
        val = (val & MOD) + (val >> 61);
        if (val > MOD) val -= MOD;
        return val;
    }
}


Measured memory_bytes: 13264
n = gets.chomp.to_i
raw_as = gets.chomp.split.map(&:to_i)
Q = gets.chomp.to_i
bs = []
cs = []
ss = []
Q.times do
  b, c = gets.chomp.split.map(&:to_i)
  bs << b; cs << c
end


a_sum = raw_as.inject(:+)
as = {}
raw_as.each do |a|
  as[a] ||= 0
  as[a] += 1
end

bs.each_with_index do |bi, i|
  a_sum += as[bi].nil? ? 0 : ((cs[i] - bi) * as[bi])
  ss << a_sum
  as[cs[i]] ||= 0
  as[cs[i]] += as[bi] || 0
  as[bi] = 0
end

puts ss



Measured memory_bytes: 30280
#include<iostream>
#include<algorithm>
using namespace std;
int o(int a,int b)
{
	return a>b;
}
int main()
{
	int n,k;
	cin>>n>>k;
	int a[n+1];
	for(int i=1;i<=n;i++) cin>>a[i];
	sort(a+1,a+n+1,o);
	int t=0;
	for(int i=1;i<=k;i++) t+=a[i];
	cout<<t;
	return 0;
 } 

Measured memory_bytes: 256
k, n = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
for i in range(n-1):
    A = a[i+1] - a[i]
    if A > ans:
        ans = A
A = a[0] + k - a[n-1]
if A > ans:
    ans = A
print(k - ans)

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

int main(){
    int n;
    cin >> n;
    vector<int> a(n), b(n),c(n-1);

    for(int i=0;i<n;i++)
        cin >> a.at(i);
    for(int i=0;i<n;i++)
        cin >> b.at(i);
    for(int i=0;i<n-1;i++)
        cin >> c.at(i);

    int res=0;
    int prev = -2;
    for(int i=0;i<n;i++){
        int idx = a.at(i)-1;
        res += b.at(idx);
        if(prev+1 == idx)
            res+=c.at(prev);
        prev = idx;
    }
    cout << res;
    return 0;
}

Measured memory_bytes: 256
#1行目の数値を入力
a = int(input())
#2行目の文字列を入力
s = str(input())
#数値が3200以上ならsを出力
if a >= 3200:
    print(s)
#それ以外（3200未満）なら「red」を出力
else:
    print("red")


Measured memory_bytes: 38420
import fractions
n=int(input())
a = list(map(int, input().split()))
ans = a[0]
for i in range(1, n):
    ans = ans * a[i] // fractions.gcd(ans, a[i])

count=0
for i in range(n):
  count+=(ans//a[i])
print(count%(10**9+7))
  


Measured memory_bytes: 6072
#!/usr/bin/python3
# -*- coding:utf-8 -*-

# @profile
def calc_lcs(s, t):
  dp = [[0 for _ in range(len(t)+1)] for _ in range(len(s)+1)]
  # dp = numpy.zeros((len(s)+1, len(t)+1))
  for i, si in enumerate(s, 1):
    for j, tj in enumerate(t, 1):
      dp[i][j] = max((dp[i-1][j-1] + 1) if si==tj else 0, dp[i-1][j], dp[i][j-1])

  lcs = ''
  i, j = len(s), len(t)
  while i > 0 and j > 0:
    if dp[i][j] == dp[i-1][j]:
      i -= 1
    elif dp[i][j] == dp[i][j-1]:
      j -= 1
    else:
      lcs = s[i-1] + lcs
      i -= 1
      j -= 1
  return lcs

def main():
  s = input().strip()
  t = input().strip()
  print(calc_lcs(s, t))


if __name__=='__main__':
  main()

Measured memory_bytes: 120412
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define Rep(n) for (ll _ = 0; _ < (ll)(n); _++)

template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
ll min(int a,ll b){return min((ll)a,b);} ll min(ll a,int b){return min(a,(ll)b);}
template <class S> void print(vector<S> &v){for(ll i=0; i<(ll)v.size(); i++){cerr << v[i] << ' ';}cerr << endl;}
template <class S> void print(vector<vector<S>> &v) {for (ll i = 0; i < (ll)v.size(); i++) {for (ll j = 0; j < (ll)v[i].size(); j++) {cerr << v[i][j] << ' ';}cerr << endl;}}

void Main();

int main(){
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	Main();
	return 0;
}

void Main(){
	int a; string s;
	cin >> a >> s;
	cout << (a >= 3200 ? s : "red") << endl;
}

Measured memory_bytes: 3572
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    int dp[31];
    dp[1] = 1;
    dp[2] = 2;
    dp[3] = 4;
    while(cin >> n,n){
        if(n == 1 || n == 2 || n == 3)
            cout << 1 << endl;
        else{
            for(int i = 4; i <= n; i++)
                dp[i] = dp[i-1] + dp[i-2] + dp[i-3];
            cout << dp[n] / 10 / 365 + 1 << endl;
        }
    }
}

Measured memory_bytes: 3088
#include<stdio.h>
#define N 100000
#define NIL -1

struct Node{
  int p, l, r;
};

struct Node T[N];
int n, H, D[N];

int getDepth(int);
void print(int);

int main(){
  int i, j, d, v, c, l;
  
  scanf("%d", &n);
  
  for ( i = 0; i < n; i++ ){
    T[i].p = NIL;
    T[i].l = NIL;
    T[i].r = NIL;
  }
  for ( i = 0; i < n; i++ ){
    scanf("%d %d", &v, &d);
    for ( j = 0; j < d; j++ ){
      scanf("%d", &c);
      if ( j == 0 ){
	T[v].l = c;
      }
      else{
	T[l].r = c;
      }
      l = c;
      T[c].p = v;      
    }
  }
  
  H = 0;
  for ( i = 0; i < n; i++ ){
    D[i] = getDepth(i);
    if ( D[i] > H ){
      H = D[i];
    }
  }  
  for ( i = 0; i < n; i++ ){
    print(i);
  }
  return 0;
}

int getDepth(int u){
  int d = 0;
  while(1){
    u = T[u].p;
    if ( u == NIL ) break;
    d++;
  }
  return d;
}


void print(int u){
  int i, c;
  printf("node %d: ", u);
  printf("parent = %d, ", T[u].p);
  printf("depth = %d, ", D[u]);

  if ( T[u].p == NIL ){
    printf("root, ");
  }
  else if ( T[u].l == NIL ){
    printf("leaf, ");
  }
  else{
    printf("internal node, ");
  }

  printf("[");
  for(i = 0, c = T[u].l; c != NIL; i++, c = T[c].r){
    if (i) printf(", ");
    printf("%d", c);
  }
  printf("]\n");
}

Measured memory_bytes: 2176
#include<queue>
#include<stack>
#include<math.h>
#include<cmath>
#include<bitset>
#include<stdio.h>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<iostream>
#include<utility>
#include<functional>
#include<deque>
#include<ctime>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
unsigned int randxor()
{
    static unsigned int x=123456789,y=362436069,z=521288629,w=88675123;
    unsigned int t;
    t=(x^(x<<11));x=y;y=z;z=w; return( w=(w^(w>>19))^(t^(t>>8)) );
}
int d=365;
vector<int> ans(d);
vector<int> ans1(d);
vector<int> c(26);
vector<vector<int> > s(d);
int score=-1000000000;
int keisan(){
  int cost=0,i,j;
  vector<int> x(26,-1);
  for(i=0;i<d;i++){
    cost+=s[i][ans1[i]];
    x[ans1[i]]=i;
    for(j=0;j<26;j++){
      cost=cost-c[j]*(i-x[j]);
    }
  }
  return cost;
}
void solve(){
  int i;
  if(score<keisan()){
    for(i=0;i<d;i++){
      ans[i]=ans1[i];
    }
    score=keisan();
  }
  for(i=0;i<d;i++){
    ans1[i]=randxor()%26;
  }
}
int main(){
  int i,j;
  int ti=clock();
  cin >> d;
  for(i=0;i<26;i++){
    scanf("%d",&c[i]);
  }
  for(i=0;i<d;i++){
    for(j=0;j<26;j++){
      int a;
      scanf("%d",&a);
      s[i].push_back(a);
    }
  }
  for(i=0;i<d;i++){
    ans1[i]=randxor()%26;
    ans[i]=ans1[i];
  }
  while(clock()-ti<197.4*CLOCKS_PER_SEC/100){
    solve();
  }
  for(i=0;i<d;i++){
    printf("%d\n",ans[i]+1);
  }
  return 0;
}

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

int main() {
  int n;
  cin >>n;
  int a=n%10;
  n/=10;
  int b=n%10;
  n/=10;
  int c=n%10;
  if(a==7||b==7||c==7){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  return 0;
}

Measured memory_bytes: 3636
#include <iostream>

using namespace std;

int i,j,n,p;
string str;

int main(){
  cin >> n >> p;
  long long dp[2]={1,0};
  for(i = 0;i < n;i++){
    cin >> j;
    if(!(j%2)){
      dp[0] += dp[0];
      dp[1] += dp[1];
    }
    else{long long a=dp[0];
      dp[0] += dp[1];
      dp[1] += a;
    }
  }
  cout << dp[p] << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <chrono>
 
using namespace __gnu_pbds;
using namespace std;
 
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the kth largest element.(0-based)
 
#define ll long long int
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define pi pair<ll,ll>
#define pii pair<ll,pi >
#define ppi pair<pi,ll>
#define ppp pair<pi,pi >
#define ex(str,a,b) str.substr((int)(a),min((int)str.size()-a,(int)(b-a+1))) 
#define all(X) X.begin(),X.end()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
// for pair comparison function(ascending order) use return (i1.ff < i2.ff);
 
/* string operations :
   str.substr (x,y) : returns a substring str[x],str[x+1],...str[x+y-1]
   __builtin_popcount(n) : no. of set bits in n.
*/
 
const int M = (1<<20)+5;
const int md = 1e9+7;
 
priority_queue<ll,vector<ll >,greater<ll > > pq;
 
ll pwr(ll a,ll n,ll m)
{
	ll p=1;
	while(n>0)
	{
		if(n%2==1)
			p=(p*a)%m;
		a=(a*a)%m;
		n=n/2;
	}
	return p;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll n,p;
	cin >> n;
	if(n == 1)
		cout << 0 << endl;
	else if(n == 2)
		cout << 2 << endl;
	else
	{
		p = pwr(10,n,md);
		p = (p + md - pwr(9,n,md))%md;
		p = (p + md - pwr(9,n,md))%md;
		p = (p + pwr(8,n,md))%md;
		cout << p << endl;
	}
}

Measured memory_bytes: 3624
#include <iostream>

using namespace std;

int main(){
  long long H;
  int N;
  cin >> H >> N;
  int A[100010];
  for(int i=0; i<N; i++) cin >> A[i];
  long long sum=0;
  for(int i=0; i<N; i++) sum+=A[i];
  if(sum>=H) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}

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

struct node_t {
	int key;
	struct node_t *next;
};
typedef struct node_t Node;

Node *enqueue(Node *node, int key) {
	Node *p, *q;

	if (node == NULL) {
		node = malloc(sizeof(Node));
		node->key = key;
		node->next = NULL;
		return node;
	}

	for (p = node; p != NULL; p = p->next) {
		q = p;
	}
	q->next = malloc(sizeof(Node));
	q->next->key = key;
	q->next->next = NULL;
	return node;
}

Node *dequeue(Node *node, int *key) {
	Node *p;

	if (node != NULL) {
		*key = node->key;
		p = node->next;
		free(node);
		return p;
	}
	return NULL;
}

int main(void) {
	int num, i, j, k, u;
	int wayto[101][101] = {{0}};
	int d[101];
	Node *q = NULL;

	scanf("%d", &num);
	for (i = 0; i < num; i++) {
		scanf("%d %d", &u, &k);
		for (j = 0; j < k; j++) {
			scanf("%d", &wayto[u-1][j]);
		}
	}

	d[0] = 0;
	for (i = 1; i < num; i++) {
		d[i] = -1;
	}
	q = enqueue(q, 0);

	while (q != NULL) {
		q = dequeue(q, &u);
		for (i = 0; i < num; i++) {
			k = wayto[u][i] - 1;
			if (d[k] < 0) {
				d[k] = d[u] + 1;
				q = enqueue(q, k);
			}
		}
	}

	for (i = 0; i < num; i++) {
		printf("%d %d\n", i+1, d[i]);
	}
	return 0;
}



Measured memory_bytes: 2132
//I read the news today, oh boy
//About a lucky man who made the grade
 
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz(x) ll((x).size())
#define all(v) (v).begin(),(v).end()
#define trace(x) cerr << #x << " = " << x << endl
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define For(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
#define roF(i,a,b) for(ll i = ll(a); i >= ll(b); i--)
using namespace std;

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;

const ll N=1e6;

ll a[N], acum[N];

int main(){
	fastio;
	int n; cin>>n;
	For(i,1,n+1) cin>>a[i];
	For(i,1,n+1) acum[i]=acum[i-1]+a[i];
	ll best = 1e18;
	For(i,2,n-1){
		ll lo = 1, hi = i;
		while(lo+1<hi){
			ll mid = (lo+hi)>>1;
			if(2*acum[mid]<=acum[i]) lo = mid;
			else hi = mid;
		}
		if(lo+1<i && acum[lo+1]<(acum[i]-acum[lo])) lo++;
		ll j = lo;
		lo = i+1, hi=n;
		while(lo+1<hi){
			ll mid = (lo+hi)>>1;
			if(2*acum[mid]<=(acum[n]+acum[i])) lo=mid;
			else hi = mid;
		}
		if(lo+1<n && (acum[lo+1]-acum[i]-(acum[n]-acum[lo+1]))<(acum[n]-acum[lo]-(acum[lo]-acum[i]))) lo++;
		ll k = lo;
		ll men = 1e18;
		ll may = 0;
		men = min(min(acum[j],acum[i]-acum[j]),min(acum[k]-acum[i],acum[n]-acum[k]));
		may = max(max(acum[j],acum[i]-acum[j]),max(acum[k]-acum[i],acum[n]-acum[k]));
		best = min(best,may-men);
	}
	cout << best << endl;
	return 0;
}



Measured memory_bytes: 6752
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
using namespace std;

template<typename A, typename B> bool chmin(A &a, const B &b){ return b < a && (a = b, true); }
template<typename A, typename B> bool chmax(A &a, const B &b){ return a < b && (a = b, true); }

int main(){
  int n;
  cin >> n;
  int a[n-1],cnt[n+1] = {};
  for (int i = 0; i < n-1; i++){
    cin >> a[i];
    cnt[a[i]]++;
  }
  for (int i = 1; i <= n; i++){
    cout << cnt[i] << '\n';
  }
  return 0;
}

Measured memory_bytes: 5204
///
// File:  1167.cpp
// Author: ymiyamoto
//
// Created on Sat Dec  2 18:27:58 2017
//

#include <algorithm>
#include <array>
#include <cstdint>
#include <iostream>
#include <vector>

using namespace std;

uint32_t polloc(uint32_t n)
{
  return n * (n + 1) * (n + 2) / 6;
}

static array<int32_t, 1000001> dp;
static array<int32_t, 1000001> odddp;

int32_t main()
{
  for (uint32_t i = 0; i < dp.size(); i++) {
    dp[i] = odddp[i] = i;
  }

  vector<int64_t> pollocs;
  for (uint32_t i = 0; i <= 181; i++) {
    pollocs.push_back(polloc(i));
  }

  for (int64_t i = 0; i < (int64_t)dp.size(); i++) {
    for (int64_t j = 0; j < (int64_t)pollocs.size(); j++) {
      if (i - pollocs[j] >= 0) {
        dp[i] = min(dp[i], dp[i - pollocs[j]] + 1);
        if (pollocs[j] % 2 == 1) {
          odddp[i] = min(odddp[i], odddp[i - pollocs[j]] + 1);
        }
      }
    }
  }

  while (true) {
    uint32_t n;
    cin >> n;
    if (n == 0) break;
    cout << dp[n] << " " << odddp[n] << endl;
  }

  return 0;
}

Measured memory_bytes: 10840
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i=0;i<n;i++)
#define repn(i, n) for(int i=1;i<=n;i++)
typedef pair<ll,ll> P;
#define fi first
#define sc second
#define pb push_back
#define mp make_pair
#define all(x) x.begin(), x.end()
#define POSL(v, x) lower_bound(v.begin(), v.end(), x) - v.begin()

struct FFT{
	const double PI = acos(-1.);
	struct cp{
		double x, y; 
		cp(double x = 0, double y = 0) : x(x), y(y) {}
		cp operator + (const cp & a) { return cp(x+a.x, y+a.y); }
		cp operator - (const cp & a) { return cp(x-a.x, y-a.y); }
		cp operator * (const cp & a) { return cp(x*a.x-y*a.y, x*a.y+y*a.x); }
	};
	cp g[1<<17];
	void FFTMakeG(int n){
		rep(i, n){
			double th = PI * 2.0 * i / n;
			g[i] = cp(cos(th), sin(th));
		}
	}
	void fft( vector<cp>&z ){
		int n = z.size();
		int i, j, k, l, m;
		for(i = 1, j = 0; i < n; ++i){
			for(int k=n>>1;(j^=k) < k ; k >>= 1);
			if(i < j) swap(z[i], z[j]);
		}
		for(l = k = 1, m = __builtin_ctz(n); m--; l |= k <<= 1){
			for(i = 0;i<n;i++) if(i < (j=i^k)){
				cp t = z[j] * g[(i & l) << m];
				z[j] = z[i] - t;
				z[i] = z[i] + t;
			}
		}
	}
	vector<double>conv (vector<double>a){
		int n = a.size() + a.size();
		int t = 1;
		while(t < n) t <<= 1;
		FFTMakeG(t);
		vector<cp>fa, fb;
		rep(i, t){
			if(i < a.size()) fa.pb(cp(a[i]));
			else fa.pb(cp());
			
			//if(i < a.size()) fb.pb(cp(a[i]));
			//else fb.pb(cp());
		}
		fft(fa); //fft(fb);
		rep(i, t) fa[i] = fa[i] * fa[i];
		for(int l=1,r=t-1;l<r;l++,r--) swap(g[l], g[r]);
		fft(fa);
		vector<double>ret;
		rep(i, t) ret.pb(fa[i].x / (double)t);
		return ret;
	}
}kaede;

double dp[30005][105];


int main(){
	rep(j, 105){
		dp[0][j] = 1.;
	}
	repn(j, 104){
		dp[1][j] = 1.;
	}
	for(int j=2;j<105;j++){
		{
			vector<double>a;
			rep(c, 30005) a.pb(dp[c][j-1]);
			auto b = kaede.conv(a);
			rep(c, 30003) dp[c+1][j] = b[c] / (double)(c+1);
		}
	}
	int n; cin >> n;
	repn(i, n){
		if(i <= 100) printf("%.12f\n", dp[n][i]-dp[n][i-1]);
		else puts("0");
	}
}



Measured memory_bytes: 32384
#include <iostream>

using namespace std;


//*********************************************************
// 最大公約数（Greatest Common Divisor）を返す。
// 引数に０がある場合は０を返す。
//*********************************************************
unsigned long long int gcd(unsigned long long int m, unsigned long long int n)
{ 
	unsigned long long tmp;
	if (m<n) {
		tmp = m;
		m = n;
		n = tmp;
	}

	/* ユークリッドの互除法 */
	unsigned long long r = m % n;
	while (r != 0) {
		m = n;
		n = r;
		r = m % n;
	}

	return n;
}//gcd

//*********************************************************
// 最小公倍数（Least Common Multiple）を返す。
// 引数に０がある場合は０を返す。
//*********************************************************
unsigned long long int lcm(unsigned long long int m, unsigned long long int n)
{
	if (m == n) {
		return m;
	}

	return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}//lcm

int main(void) {


	//std::ios::sync_with_stdio(false);
	//std::cin.tie(0);

	int n;
	unsigned long long int t[100];
	unsigned long long int result;
	cin >> n;

	for (int i = 0; i < n; i++) {
		cin >> t[i];
	}

	result = t[0];

	for (int j = 1; j < n; j++) {
		result = lcm(result, t[j]);
	}

	cout << result << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FOR(i,s,e) for(int i=(s);i<=(e);i++)
#define FORD(i,s,e) for(int i=(s);i>=(e);i--)
#define eb emplace_back
#define MAXN 1000009
#define MOD 1000000007
#define mp(x, y) make_pair(x,y)
#define all(v) (v).begin(),(v).end()
#define pb(x) push_back(x)
#define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++)
#define ff first
#define ss second

using namespace std;

typedef unsigned long long LLU;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
const bool print=false;
typedef long long ll;

template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}

int n;
int a[MAXN];
int main()
{
    a[0] = -1;
    scanf("%d", &n);
    for(int i = 1; i <= n; i ++){
    	scanf("%d", a + i);
    	if(a[i] - a[i - 1] > 1)
    		return puts("-1") * 0;
    	}
	ll ans = 0;
	a[0] = 0;
    for(int i = 1; i <= n; i ++)
    	if(a[i - 1] + 1 == a[i])
    		ans ++;
    	else
    		ans += a[i];
    printf("%lld\n", ans);
}



Measured memory_bytes: 1152
use std::io;
use std::cmp;

// read a line(without line feed)
fn read_line() -> String {
    let mut in_str = String::new();
    io::stdin().read_line(&mut in_str).unwrap();
    return in_str.trim().to_string();
}

// read wods on a line
pub fn read_words_in_line() -> Vec<String> {
    let s = read_line();
    return s.split_whitespace().map(|x| x.to_string()).collect::<Vec<String>>()
}

// read type t on a line
pub fn read_t_in_line<T : std::str::FromStr>() -> Vec<T> {
    let mut v : Vec<T> = Vec::new();
    for e in read_words_in_line().iter().map(|x| x.parse::<T>()) {
        if let Ok(r) = e {
            v.push(r);
        }
        else{
            return Vec::new();
        }
    }
    return v;
}

// sort slice
pub fn sort<T : std::cmp::Ord>(slice : &mut [T]) {
    slice.sort();
}
// sort slice by reverse order
pub fn sort_rev<T : std::cmp::Ord>(slice : &mut [T]) {
    slice.sort_by(|x, y| y.cmp(x));
}

pub fn min<T : std::cmp::Ord>(a : T, b : T) -> T{
    return cmp::min(a, b);
}

pub fn max<T : std::cmp::Ord>(a : T, b : T) -> T{
    return cmp::max(a, b);
}



fn main() {

    let mut cs = vec![vec![0 ; 10] ; 10];

    let h_w = read_t_in_line::<i32>();
    let(h, w) = (h_w[0] as usize, h_w[1] as usize);

    let mut a = vec![vec![0 ; w] ; h];

    for i in 0..10 {
        let c_vec = read_t_in_line::<i32>();
        for j in 0..10 {
            cs[i][j] = c_vec[j];
        }
    }
    
    for i in 0..h {
        let a_vec = read_t_in_line::<i32>();
        for j in 0..w {
            a[i][j] = a_vec[j];
        }
    }

    // warshall floydでi -> jへ推移するコストの最小値を計算
    for k in 0..10 {
        for i in 0..10 {
            for j in 0..10 {
                cs[i][j] = min(cs[i][j], cs[i][k] + cs[k][j]);
            }
        }
    }

    let mut cost = 0;
    for i in 0..h {
        for j in 0..w {
            let t = a[i][j];
            if t != -1 {
                cost += cs[t as usize][1];
            }
        }
    }
    println!("{}", cost);

}


Measured memory_bytes: 4352