akhauriyash/Code-Regression huggingface dataset:
# frozen_string_literal: true

x, y = gets.split.map(&:to_i)

if (2 * x - y) % 3 != 0 || (-x + 2 * y) % 3 != 0
  puts 0
  exit
end

n = (2 * x - y) / 3
m = (-x + 2 * y) / 3

MOD = 10**9 + 7
N = (n + m) * 3

def ncrmod(n, r)
  return 0 if r < 0 || r > n

  r = [r, n - r].min
  $g1[n] * $g2[r] * $g2[n - r] % MOD
end

$g1 = [1, 1]
$g2 = [1, 1]
$inverse = [0, 1]

2.upto(N + 1) do |i|
  $g1.push(($g1[-1] * i) % MOD)
  $inverse.push((-$inverse[MOD % i] * (MOD / i)) % MOD)
  $g2.push(($g2[-1] * $inverse[-1]) % MOD)
end

puts ncrmod(n + m, m)


Measured memory_bytes: 51916
#include <iostream>
//#include <fstream>
#include <vector>
#include <string>
//#include <cstdlib>
//#include <algorithm>
//#include <set>
//#include <conio.h>
using namespace std;

void Calc(int arrS,int arrE,int result[3]){
	result[2]=arrE-arrS;
	while(result[2]>=60){
		result[2] -=60;
		++result[1];
		if(result[1]>=60){
			++result[0];
			result[1] -= 60;
		}
	}
}

int main(){
	int tmp=0;
	int result[3][3];

	for(int i=0; i<3; ++i){
		for(int j=0; j<3; ++j){
			result[i][j] = 0;
		}
	}
	vector<int> a(6);
	vector<int> b(6);
	vector<int> c(6);
	for(int i=0; i<6; ++i){
		cin >> a[i];
	}
	for(int i=0; i<6; ++i){
		cin >> b[i];
	}
	for(int i=0; i<6; ++i){
		cin >> c[i];
	}
	int As=a[0]*3600+a[1]*60+a[2];
	int Ae=a[3]*3600+a[4]*60+a[5];

	int Bs=b[0]*3600+b[1]*60+b[2];
	int Be=b[3]*3600+b[4]*60+b[5];

	int Cs=c[0]*3600+c[1]*60+c[2];
	int Ce=c[3]*3600+c[4]*60+c[5];
	
	//cout <<As<<" "<<Ae<<" "<<Bs<<" "<<Be<<" "<<Cs<<" "<<Ce<<endl;
	
	Calc(As,Ae,result[0]);
	Calc(Bs,Be,result[1]);
	Calc(Cs,Ce,result[2]);

	for(int i=0; i<3; ++i){
		for(int j=0; j<3; ++j){
			cout << result[i][j];
			if(j!=2)cout << " ";
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 1196
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <string>
#include <sstream>
#include <cstring>
#include <cmath>

using namespace std;

#ifdef DEBUG
#define LOG(args) cout << args << "\n"
#define debug(x) x
#else
#define LOG(args)
#define debug(x)
#endif

#define vi vector<int>
#define ii pair<int, int>
#define vii vector< ii >
#define vvi vector< vi >
#define mp make_pair
#define pb push_back
#define ms(x, v) memset(x, v, sizeof(x))
#define all(x) x.begin(), x.end()
#define REP(x, n) for(int x = 0; x < n; x++)
#define REPV(x, v, n) for(int x = v; x < n; x++)
#define REVE(x, n) for(int x = n; x >= 0; x--)

typedef long long ll;

ll N, X, Y, D, ans = 0;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cin >> N >> D;
	D *= D;
	while(N--)
	{
		cin >> X >> Y;
		if((X * X + Y * Y) <= D)
			ans++;
	}
	cout << ans << "\n";
	return 0;
}


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

using namespace std;

int a,b;

int main()
{
    cin>>a>>b;
    for (int i=b*10;i<(b+1)*10;++i)
    {
        if ((i*2)/25==a)
        {
            cout<<i;
            return 0;
        }
    }
    cout<<-1;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define watch(x) cout<<"->"<<#x<<" : "<<x<<endl;
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c)) 
typedef long long ll;
typedef unsigned long long llu;
const double PI = 2*acos(0.0);
#define int long long
signed main()
{
	//freopen("","r",stdin);
	//freopen("","w",stdout);
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n,m;
	cin>>n>>m;
	int res;
	if(n==1&&m==1)
		res = 1;
	else if(n==1)
		res = m-2;
	else if(n==2)
		res = 0;
	else if(m==1)
		res = n-2;
	else if(m==2)
		res = 0;
	else
		res = (n*m) - 2*n - 2*(m-2);
	cout<<res<<endl;	
	return 0;
}

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

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

  vector<long long> a(n + 1), b(n + 1);
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    if (a[i] >= 0) b[i] = a[i];
  }

  for (int i = 1; i <= n; ++i) {
    a[i] += a[i - 1];
    b[i] += b[i - 1];
  }

  long long ans = 0;
  for (int i = 0; i < n - k + 1; ++i) {
    ans = max(ans, max(0ll, a[i + k] - a[i]) + b[i] - b[0] + b[n] - b[i + k]);
  }

  cout << ans << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
using namespace std;
int main()
{
  ll A, B, C, K;
  cin >> A >> B >> C >> K;
  if (A + B < K)
  {
    cout << A - 1 * (K - (A + B)) << endl;
  }
  else
  {
    cout << min(A, K) << endl;
  }
  return 0;
}

Measured memory_bytes: 3636
/*
ID: anonymo14
TASK: wormhole
LANG: C++                 
*/
#include<bits/stdc++.h>

using namespace std;

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

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

#define REP(i,a,b) for(int i=a; i<=b; i++)

#define MOD 1000000007

ull sol = 0;
char arr[5]={'M','A','R','C','H'};

void perm(unordered_map<char,ull> &ma, vector<char> &ch, int i=0) {
	if(ch.size()==3) {
		sol+=ma[ch[0]]*ma[ch[1]]*ma[ch[2]];
		return;
	}
	for(;i<5;i++) {
		if(ma[arr[i]]>0) {
			ch.PUB(arr[i]);
			perm(ma,ch, i+1);
			ch.POB();
		}
	}
}

void solve(int test_case) {
	int n;
	cin>>n;
	unordered_map<char,ull> ma;
	while(n--) {
		string s;
		cin>>s;
		ma[s[0]]++;
	}
	vector<char> ch;
	perm(ma, ch);
	cout<<sol;
}

int main() {
	
	////// FILE BASED IO////
	//freopen("wormhole.in", "r", stdin);
	//freopen("wormhole.out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
	return 0;
}	


Measured memory_bytes: 3684
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)

int main(){
	ll x,k,d;
	scanf("%lld%lld%lld",&x,&k,&d);
	ll cnt=llabs(x)/d;
	if(cnt>=k){
		if(x<0)printf("%lld",llabs(x+k*d));
		else printf("%lld",llabs(x-k*d));
	}else{
		ll pos=x%d;
		if((k-cnt)%2)printf("%lld",llabs(pos<0?pos+d:pos-d));
		else printf("%lld",llabs(pos));
	}
}

Measured memory_bytes: 1736
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>

using namespace std;
typedef long long unsigned int ll;
typedef pair<int, int> P;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

// #define amari(x) ((x) % 1000000007)
#define amari(x) ((x) % 998244353)

#define fillInt(xs, x)        \
  for (int i = 0; i < (x); i++) \
    scanf("%d", &xs[i]);
#define fillLong(xs, x)       \
  for (int i = 0; i < (x); i++) \
    scanf("%ld", &xs[i]);
#define fillString(xs, x)       \
  for (int i = 0; i < (x); i++) \
    cin >> xs[i];
#define sortv(xs) sort(xs.begin(), xs.end())
#define sortvdi(xs) sort(xs.begin(), xs.end(), std::greater<int>())
#define lbv(xs, x) lower_bound(xs.begin(), xs.end(), x) - xs.begin()
#define ubv(xs, x) upper_bound(xs.begin(), xs.end(), x) - xs.begin()
#define bs(xs, x) binary_search(xs.begin(), xs.end(), x)

#define rep(i,n) for(long i=0; i<(n); i++)
#define isValidPoint(x, y, mx, my) x >= 0 && x  < mx && y >= 0 && y < my

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


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

  int n;
  cin >> n;

  vector<int> c(n), v(n);
  fillInt(v, n);
  fillInt(c, n);

  long cnt = 0;

  rep(i, n) {
    if (v[i] > c[i]) {
      cnt += v[i]-c[i];
    }
  }

  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

int cnt[101];

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int k, t; cin>>k>>t;
	for(int i = 0; i < t; i++)
	{
		cin >> cnt[i];
	}
	int prev = -1;
	int ans = 0;
	for(int i = 0; i < k; i++)
	{
		int mx = 0; int mxid = -1;
		for(int j = 0; j < t; j++)
		{
			if(j == prev) continue;
			if(cnt[j] > mx)
			{
				mxid = j;
				mx = cnt[j];
			}
		}
		if(mxid != -1)
		{
			cnt[mxid]--;
			prev = mxid;
			continue;
		}
		else
		{
			cnt[prev]--;
			ans++;
			continue;
		}
	}
	cout<<ans<<'\n';
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
  long n;
  int k;
  int t;
  std::cin>>n>>k;
  int i=0,count=0;
  for(i=0;i<n;i++)
  {
    std::cin>>t;
    if(t>=k)
      count+=1;
  }
  std::cout<<count;
  return 0;
}

Measured memory_bytes: 256
#![allow(unused_imports)]
use std::collections::BinaryHeap;
use std::collections::HashMap;
use std::collections::HashSet;
use std::collections::VecDeque;

#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($t:ty) =>
        (rl().parse::<$t>().unwrap());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    buf.trim_end().to_owned()
}

trait IteratorExt: Iterator + Sized {
    fn vec(self) -> Vec<Self::Item> {
        self.collect()
    }
}
impl<T: Iterator> IteratorExt for T {}

fn main() {
    let _n = read!(usize);
    let a = read!([usize]);

    let mut max = 0;
    let mut ans = 0;
    for i in a {
        if max > i {
            ans += max - i;
        } else {
            max = i;
        }
    }
    println!("{}", ans);
}


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

int getmd(int a,int b,int c,int d){
    return abs(a-c)+abs(b-d);
}

int main(){
    int n,ans(0),x(-1);
    cin >> n;
    int a[n],b[n],c[n-1];
    rep(i,n)    cin >> a[i];
    rep(i,n)    cin >> b[i];
    rep(i,n-1)  cin >> c[i];

    rep(i,n){
        ans += b[a[i]-1];
        if(a[i]==x){
            ans += c[a[i]-2];
            x = a[i]+1;
        }else{
            x = a[i]+1;
        }
    }
    cout << ans << endl;

    return 0;
}

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

int main()
{
	unsigned long long A, _B = 0;  
	string B ; 
	cin >> A >> B ; 



	for(int i = 0 ; i < B.length(); ++i)
	{
		if(B[i]>='0' && B[i]<='9')
		{
			_B = _B * 10ULL + (unsigned long long) (B[i]-'0');
		}
	}

	A = A*_B ; 
	A/= 100ULL ; 

	cout << A << "\n" ;
	 

	//printf("%0.lf\n",floor(A*B)) ; 

	//cout << "Hello World\n" ; 
	return 0 ; 
}

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

char M[14][14];
const int dx[4] = { 0, 0, 1, -1 };
const int dy[4] = { 1, -1, 0, 0 };

void fill( int x, int y )
{
	M[y][x] = '0';

	for ( int i = 0; i < 4; i++ )
	{
		int nx = x+dx[i];
		int ny = y+dy[i];
		if ( M[ny][nx] == '1' )
			fill( nx, ny );
	}
}

int main( void )
{
	while ( cin.eof() == false )
	{
		if ( cin.eof() ) break;

		for ( int i = 0; i < 14; i++ )
			for ( int j = 0; j < 14; j++ )
				M[i][j] = '0';

		for ( int i = 0; i < 12; i++ )
			for ( int j = 0; j < 12; j++ )
				cin >> M[i+1][j+1];

		if ( cin.eof() ) break;

		int kotae = 0;
		for ( int i = 0; i < 12; i++ ) for ( int j = 0; j < 12; j++ )
		{
			if ( M[i+1][j+1] == '1' )
			{
				fill( j+1, i+1 );
				kotae++;
			}
		}

		cout << kotae << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
typedef pair<int, int>P;
const int INF = 1e15;
const int MOD = 1e9 + 7;
const double PI = 3.14159265358979323846;

signed main() {
	string S, T;
	int A, B;
	string U;
	cin >> S >> T >> A >> B >> U;
	if (S == U)A--;
	else B--;
	cout << A << " " << B;
}

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

int main()
{
	int n, k;
	cin >> n >> k;
	auto m = vector<int>(20);
	int high = 0;
	for(auto i = 1; i <= min(n, k - 1); ++i){
		int t = i, cnt = 0;
		while(t < k){
			t <<= 1;
			++cnt;
		}
		++m[cnt];
		high = max(high, cnt);
	}
	long long int num = max(0, n - k + 1);
	for(auto i = 1; i <= high; ++i){
		num <<= 1;
		num += m[i];
	}
	double ans = num;
	int denomi = 1;
	while(high-- > 0) denomi <<= 1;
	cout << fixed << setprecision(12) << ans / (denomi * n) << endl;
	return 0;
}

Measured memory_bytes: 256
from math import factorial
N, A, B = map(int, input().split())
MOD = 10 ** 9 + 7

def calc(n):
    ret = 1
    for i in range(n):
        ret = ret * (N - i) % MOD
    return ret * pow(factorial(n), MOD - 2, MOD) % MOD

print(max(0, (pow(2, N, MOD) - ((calc(A) + calc(B)) % MOD) - 1) % MOD))

Measured memory_bytes: 5432
#include <iostream>
#include <vector>
using namespace std;
int main(){
  int n,k,d[10]={},tmp;
  vector <int> dl;
  cin>>n>>k;
  for(int i=0;i<k;i++){
    cin>>tmp;
    dl.push_back(tmp);
  }
  for(;;n++){
    int a=n;
    for(;a;a/=10) for(int i=0;i<dl.size();i++) if(dl[i]==a%10) goto end;
    cout<<n<<endl;
    return 0;
  end:;
    }

}








Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using vpsi=vector<pair<string,int>>;
using vi=vector<int>;

int kensaku(int i,int p,int q,int r,int s){
  int result;
  if(i==0) result=p+q+r+s;
  if(i==1) result=p+q+r-s;
  if(i==2) result=p+q-r+s;
  if(i==3) result=p+q-r-s;
  if(i==4) result=p-q+r+s;
  if(i==5) result=p-q+r-s;
  if(i==6) result=p-q-r+s;
  if(i==7) result=p-q-r-s;
  return result;
}

void syutsuryoku(int i,int p,int q,int r,int s){
  if(i==0) cout<<p<<"+"<<q<<"+"<<r<<"+"<<s<<"=7"<<endl;
  if(i==1) cout<<p<<"+"<<q<<"+"<<r<<"-"<<s<<"=7"<<endl;
  if(i==2) cout<<p<<"+"<<q<<"-"<<r<<"+"<<s<<"=7"<<endl;
  if(i==3) cout<<p<<"+"<<q<<"-"<<r<<"-"<<s<<"=7"<<endl;
  if(i==4) cout<<p<<"-"<<q<<"+"<<r<<"+"<<s<<"=7"<<endl;
  if(i==5) cout<<p<<"-"<<q<<"+"<<r<<"-"<<s<<"=7"<<endl;
  if(i==6) cout<<p<<"-"<<q<<"-"<<r<<"+"<<s<<"=7"<<endl;
  if(i==7) cout<<p<<"-"<<q<<"-"<<r<<"-"<<s<<"=7"<<endl;
  return;
}

int main() {
  int n,b,p,q,r,s;
  bool a=false;
  cin>>n;
  p=n/1000;
  q=n%1000/100;
  r=n%100/10;
  s=n%10;
  for(int i=0; i<8; i++){
    b=kensaku(i,p,q,r,s);
    if(b==7){
      syutsuryoku(i,p,q,r,s);
      break;
    }
  }
}

Measured memory_bytes: 256
from sys import stdin, stdout

def main():
    N = (int)(stdin.readline())
    graph = dict()
	
    if N == 1:
      print("First")
      return
    if N == 2:
      print("Second")
      return
    
    for i in range(N-1):
        edge = stdin.readline().split()
        ai = (int)(edge[0])
        bi = (int)(edge[1])

        if ai in graph.keys():
            graph[ai].append(bi)
        else:
            graph[ai] = [bi]
        
        if bi in graph.keys():
            graph[bi].append(ai)
        else:
            graph[bi] = [ai]

    mid_node = bfs(graph, 1)[0]
    
    longest_path = bfs(graph, mid_node)[1]
    
    if longest_path % 3 == 1:
        print("Second")
    else:
        print("First")

def bfs(graph, node):

    result = -1
    last_level = set()
    visited = set()

    last_level.add(node)
    visited.add(node)

    length = 0

    while len(last_level) > 0:
        
        new_level = set()

        length += 1

        for last_node in last_level:
            result = last_node
            for neighbor in graph[last_node]:
                if neighbor not in visited:
                    new_level.add(neighbor)
                    visited.add(neighbor)
        last_level = new_level
    
    return result, length - 1

if __name__ == "__main__":
    main()

Measured memory_bytes: 70428
n=int(input())
a=[int(input()) for _ in range(n)]

a0=a[0]
cnt=0
f=True

if a0==2:
  cnt=1
  f=False

for i in range(n):
  if f:
    a0=a[a0-1]
    cnt+=1
    if a0 == 2:
      cnt+=1
      break

if cnt==n:
  cnt=-1

print(cnt)

Measured memory_bytes: 13044
#include <stdio.h>

int main(void){
    int a, b, c, x;
    int cou = 0;
    scanf("%d %d %d", &a, &b, &c);
    x = a;
    for(; b >= x;){
        if( c % x == 0 )    cou++;
        x++;
    }
    printf("%d\n", cou);
    return 0;
}


Measured memory_bytes: 2140
#include <bits/stdc++.h>
typedef long long       ll;
#define PI                acos(-1)
#define pb                push_back
#define mp                make_pair
#define all(a)            (a).begin(), (a).end()
#define clr(a,h)          memset(a, (h), sizeof(a))
#define F first
#define S second
#define fore(i,b,e)		  for(int i=(int)b;i<(int)e;++i)
#define forr(i,b,e)		  for(int i=(int)b;i<(int)e;++i)
#define deb(x)			  cerr << "# " << (#x) << " = " << (x) << endl;
int faster_in(){int r=0,c;for(c=getchar();c<=32;c=getchar());if(c=='-') return -faster_in();for(;c>32;r=(r<<1)+(r<<3)+c-'0',c=getchar());return r;}

using namespace std;

typedef pair<int, int>  ii;
typedef vector<int>     vi;
typedef vector<ii>      vii;
typedef vector<ll>      vll;
const int INF = 1234567890;

int main()
{
    std::ios::sync_with_stdio(false); cin.tie(0);
    //freopen("","r",stdin);
    //freopen("","w",stdout);
    int n;
    cin >> n;
    int a[n];
    fore(i, 0, n) {
    	cin >> a[i];
    }
    int res = 0;
    fore(i, 0, n) {
    	if (a[i]%2 == 1 && i%2 == 0) {
    		res++;
    	}
    }
    cout << res << '\n';
    return 0;
}
// Dinosaurs are cool

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

using namespace std;

const int N = 1e5 + 100;

bool vis[N];
int cnt[N], n, m, x, y, res = 1;

int main (int argc, char const *argv[]) {
//    freopen("input.txt", "r", stdin);

    scanf("%d %d", &n, &m);
    for (int i = 1; i <= n; ++i) cnt[i] = 1;
    vis[1] = 1;

    while (m--) {
        scanf("%d %d", &x, &y);

        if (vis[x]) {
            if (cnt[x] == 1) vis[x] = 0, --res;
            if (not vis[y]) vis[y] = 1, ++res;
        }

        cnt[x]--, cnt[y]++;
    }

    printf("%d\n", res);
    return 0;
}



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

using namespace std;

using ll = long long;


int main(){
	int N;
	cin >> N;
	vector<string> s(N);
	vector<int> t(N);
	
	for (int i=0; i<N; i++){
		cin>>s[i];
		cin >> t[i];		
	}
	
	string X;
	cin >> X;
	
	auto it = find(s.begin(), s.end(), X);
	int idx = it - s.begin();
	int sum = accumulate(t.begin()+idx+1, t.end(), 0);
	
	cout<<sum;

	
	
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  int i,a,b,k,cnt=0;
  int u[50];
  scanf("%d %d %d",&a,&b,&k);
  for(i=1;i<=100;i++){
    if(a%i==0 && b%i==0){
      //printf("%d ",i);
      u[cnt]=i;
      cnt+=1;
    }
  }
  printf("%d",u[cnt-k]);
  return 0;
}

Measured memory_bytes: 128
l,r = map(int,input().split())

ans = 2018
if r - l >= 2019:
    ans = 0
else:
    for i in range(l,r):
        for j in range(i+1,r+1):
            temp = (i*j) % 2019
            if ans > temp:
                ans = temp

print(ans)

Measured memory_bytes: 3060
A, B = map(int, input().split())

grid = [["." for _ in range(100)] for _ in range(100)]

# 上半分（50*100）を黒で、下半分(50*100)を白で埋める
for r in range(50):
    for c in range(100):
        grid[r][c] = "#"

# 上の(49*100)において、A-1マスを白に塗り替える
cnt_w = 1
for r in range(0, 49, 2):
    for c in range(100):
        if cnt_w < A:
            if c % 2 == 0:
                grid[r][c] = "."
                cnt_w += 1

# 下の(49*100)において、B-1マスを黒に塗り替える
cnt_b = 1
for r in range(51, 100, 2):
    for c in range(100):
        if cnt_b < B:
            if c % 2 == 0:
                grid[r][c] = "#"
                cnt_b += 1

print(100, 100)
for r in range(100):
    print("".join(grid[r]))


Measured memory_bytes: 66044
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for(int i=0;i<(int)n;i++)
struct edge{int from, to;};

int main(){
    int k,s;
    cin>>k>>s;
    int count=0;
    for(int x=0;x<=k;x++){
        for(int y=0;y<=k;y++){
            if(0<=s-x-y && s-x-y<=k){
                count++;
            }
        }
    }
    cout<<count<<endl;
    return 0;
}

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

int main() {
  int n, k, x;
  int i;
  int sum;
  cin >> n >> k;
  
  sum = 0;
  for (i = 0; i < n; i++) {
    cin >> x;
    if (x < abs(k - x)) {
      sum += (2 * x);
    } else {
      sum += (2 * abs(k - x));
    }
  }
  cout << sum << endl;
}

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

using namespace std;

vector<int> Zalgorithm(auto S){
    vector<int> res(S.size());
    res[0] = S.size();
    int i = 1, j = 0;
    while (i < S.size()) {
        while (i+j < S.size() && S[j] == S[i+j]) ++j;
        res[i] = j;
        if (j == 0) { ++i; continue;}
        int k = 1;
        while (i+k < S.size() && k+res[k] < j) res[i+k] = res[k], ++k;
        i += k; j -= k;
    }
    return res;
}

int main(){
    string S;
    while(cin >> S){
        vector<int> z = Zalgorithm(S);
        int cycle = S.size();
        for(int i=1;i<S.size();i++){
            if(S.size()%i) continue;
            bool ok = true;
            for(int j=i;j<S.size();j+=i) if(z[j] != S.size() - j) ok = false;
            if(ok){
                cycle = i;
                break;
            }
        }
        if(cycle == 1 || cycle == S.size()){
            cout << S.size()/cycle << endl;
            cout << 1 << endl;
            continue;
        }
        cout << 2 << endl;
        vector<int> valid(S.size(), 1);
        valid[0] = 0;
        for(int i=1;i<S.size();i++){
            for(int j=2*i;j<S.size();j+=i){
                if(i + z[i] >= j) valid[j] = 0;
            }
        }
        auto T = S;
        reverse(T.begin(), T.end());
        vector<int> zr = Zalgorithm(T);
        for(int i=1;i<T.size();i++){
            for(int j=2*i;j<S.size();j+=i){
                if(i + zr[i] >= j) valid[S.size()-j] = 0;
            }
        }
        cout << accumulate(valid.begin(), valid.end(), 0) << endl;
    }
}

Measured memory_bytes: 7576
#include <bits/stdc++.h>
using namespace std;
#define PI 3.14159265359

int main()
{
  int a,b;
  char ope;
  cin >> a >> ope >> b;
  while (ope != '?')
  {
    switch(ope){
      case('+'):
        cout << a+b << endl;
        break;
      case('-'):
        cout << a-b << endl;
        break;
      case('*'):
        cout << a*b << endl;
        break;
      case('/'):
        cout << a/b << endl;
        break;
    }
    cin >> a >> ope >> b;
  }
  
}


Measured memory_bytes: 3116
#include<bits/stdc++.h>
#define ii pair<int,int>
#define iii pair<int,ii>
#define inf 1000000000
using namespace std;

long long n,e,r,dist[2*1003];
vector<iii>graph;
void init(){
    cin>>n>>e>>r;
    for(int i=0; i<e; i++){
        int u,v,w;
        cin>>u>>v>>w;
        graph.push_back(iii(w,ii(u,v)));
    }
}

bool bellman(int s){
    dist[s]=0;
    int len=graph.size();
    for(int i=0; i<n; i++){
        for(int j=0; j<len; j++){
            int u=graph[j].second.first,
                v=graph[j].second.second,
                w=graph[j].first;
            if(dist[u]+w<dist[v]){
                dist[v]=dist[u]+w;
            }
        }
    }
    for(int i=0; i<len; i++){
        int u=graph[i].second.first,
            v=graph[i].second.second,
            w=graph[i].first;
        if(dist[u]+w<dist[v] && dist[v]<100000)return true;
    }
    return false;
}

void Back(){
    for(int i=0; i<n+7; i++)dist[i]=inf;
}

int main(){
    init();
    Back();
    bool neg=bellman(r);
//    cout<<neg<<endl;
    if(neg)printf("NEGATIVE CYCLE\n");
    else{
        for(int i=0; i<n; i++){
            if(dist[i]>=100000)printf("INF\n");
            else printf("%lld\n",dist[i]);
        }
    }
return 0;
}




Measured memory_bytes: 3252
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>
using namespace std::literals;
using namespace std;

namespace xmaho
{
inline namespace input
{
template<typename T>
T get_value(std::istream& is = std::cin);
template<typename C>
C get_container(std::istream& is = std::cin, typename C::size_type length = std::numeric_limits<typename C::size_type>::max());
}
}
using namespace xmaho;

int main()
{
  std::vector<int> num(get_value<std::size_t>(), -1);
  for (auto i {get_value<int>()}; i != 0; --i) {
    auto index {get_value<int>() - 1};
    auto lim {get_value<int>()};
    if (num[index] == lim) {
      continue;
    }
    if (num[index] != -1) {
      std::cout << -1 << '\n';
      return 0;
    }
    num[index] = lim;
  }
  if (num.size() == 1 && (num.front() == 0 || num.front() == -1)) {
    std::cout << 0 << '\n';
    return 0;
  }
  if (num.front() == 0) {
    std::cout << -1 << '\n';
    return 0;
  }
  if (num.front() == -1) {
    num.front() = 1;
  }
  std::replace(num.begin(), num.end(), -1, 0);

  for (auto e : num) {
    std::cout << e;
  }
  std::cout.put('\n');
  return 0;
}

class initalization
{
  class custom_numpunct: public std::numpunct<char>
  {
  public:
    using numpunct::numpunct;
  protected:
    std::string do_truename() const override { return "Yes"; }
    std::string do_falsename() const override { return "No"; }
  };

public:
  initalization()
  {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cout.imbue(std::locale(std::cout.getloc(), new custom_numpunct{}));
    std::cout << std::boolalpha << std::fixed << std::setprecision(15);
  }
} initalize;

template<typename T>
T xmaho::input::get_value(std::istream& is)
{ T v {}; is >> v; return v; }

template<typename C>
C xmaho::input::get_container(std::istream& is, typename C::size_type length)
{
  C v {};
  if (length != std::numeric_limits<typename C::size_type>::max())
    v.reserve(length);
  typename C::value_type e {};
  for (auto i {length}; i != 0 && is >> e; --i)
    v.push_back(std::move_if_noexcept(e));
  return v;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i < n; i ++)
#define rep1(i, n) for (int i=1; i <= n; i ++)
#define _min(x, y) x = min(x, y)
#define _max(x, y) x = max(x, y)
using namespace std;


int main() {
  int N;
  vector<int> D(100005, 1e5+1);
  cin >> N;
  rep (i, N) {
    cin >> D[i];
  }
  sort(D.begin(), D.end());
  // rep (i, N) {
  //   cout << D[i] << " ";
  // }
  cout << D[N / 2] - D[N / 2 - 1] << endl;
  return 0;
}


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

class Program
{
    void Run()
    {
        var sc = new Scanner();
        string s = sc.NextString();
        for (int i = 1; i < 4; i++)
        {
            if (s[i - 1] == s[i])
            {
                Console.WriteLine("Bad");
                return;
            }
        }
        Console.WriteLine("Good");
    }
    
    static void Main(string[] args)
    {
        new Program().Run();
    }

    static long Gcd(long a, long b)

    {
        if (a < b) return Gcd(b, a);
        if (b == 0) return a;
        return Gcd(b, a % b);
    }
}

class Scanner
{
    int index = -1;
    string[] buf;

    public Scanner()
    {
    }

    public int NextInt()
    {
        CheckNext();
        return int.Parse(buf[index++]);
    }

    public long NextLong()
    {
        CheckNext();
        return long.Parse(buf[index++]);
    }

    public double NextDouble()
    {
        CheckNext();
        return double.Parse(buf[index++]);
    }

    public string NextString()
    {
        CheckNext();
        return buf[index++];
    }

    private void CheckNext()
    {
        if (index >= 0 && index < buf.Length) return;

        buf = Console.ReadLine().Split(' ');
        index = 0;
    }
}


Measured memory_bytes: 11092
from collections import deque
s = list(input())
s = deque(s)
n = int(input())
cnt = 0
for i in range(n):
    q = list(map(str,input().split()))
    if q[0] == '1':
        cnt += 1
    else:
        if cnt % 2 == 0:
            if q[1] == '1':
                s.appendleft(q[2])
            else:
                s.append(q[2])
        else:
            if q[1] == '1':
                s.append(q[2])
            else:
                s.appendleft(q[2])
    #print(q)
if cnt % 2 != 0:
    s.reverse()
print(''.join(list(s)))

Measured memory_bytes: 8676
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  sort(a.begin(), a.end());
  int max = a[n - 1];
  int ind = lower_bound(a.begin(), a.end(), (max + 1) >> 1) - a.begin();
  int mid = a[ind];
  if (mid > max - a[ind - 1]) mid = a[ind - 1];
  if (max == mid) mid = a[ind - 2];
  cout << max << ' ' << mid << '\n';
  return 0;
}

Measured memory_bytes: 640
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <functional>
#include <numeric>
#include <iostream>
#include <string>
#include <time.h>
#include <bitset>

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }

ll N, K;

int main() {

	cin >> N >> K;

	ll po = N % K, ne = K - po;

	cout << min(po, ne) << endl;


	return 0;
}


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

using namespace std;

int debug = 0;

int main(void){
	int i, j, k;
	int n, m;
	int tmp, maxi, cont;
	vector<int> intv, imax;

	while(cin >> n){
		if(n == 0) break;
		
		for(i=0;i<n;i++){
			cin >> m;
			intv.push_back(m);
		}

		cont = 0;
		maxi = 0;
		tmp = 0;
		for(i=0;i<intv.size();i++){
			cont = cont + intv[i];
			cont = max(0, cont);
			maxi = max(maxi, max(cont, intv[i]));
		}

		if(maxi != 0){
			cout << maxi << endl;
		}else{
			cout << *max_element(intv.begin(), intv.end()) << endl;
		}
		intv.clear();
	}

	return 0;
}

int b_main(void){
	int n, m, i, j, k;
	int tmp, max;
	bool first = 0, notAllMinus=0;
	vector<int> intv;

	while(cin >> n){
		if(n == 0){
			break;
		}else{
			//ÇÝÝ
			for(i=0;i<n;i++){
				cin >> m;
				intv.push_back(m);
				//if(debug) cout << "int[" << i << "] =" << intv[i] << endl; 
			}

			//SÌêÌ»è
			tmp = intv[0];
			for(i=0;i<intv.size();i++){
				if(intv[i] > 0){
					notAllMinus = 1;
					break;
				}else{
					if(tmp < intv[i]){
						tmp = intv[i];
					}
				}
			}

			if(notAllMinus == 0){
				cout << tmp << endl;
				intv.clear();
				continue;
			}

			//vfð¸ç·
			tmp=0;
			for(i=1;i<intv.size();i++){
				if(intv[tmp] > 0){
					if(intv[i] > 0){ //¯Èç
						intv[tmp] += intv[i];
						intv[i] = 0;
					}else{ //ÙÈç
						tmp = i;
					}
				}else if(intv[tmp] < 0){
					if(intv[i] < 0){
						intv[tmp] += intv[i];
						intv[i] = 0;
					}else{
						tmp = i;
					}
				}
			}
			
			if(debug){
				for(i=0;i<intv.size();i++){
					cout << intv[i] <<endl;
				}
				cout << "----------------------" << endl;
			}
			
			intv.erase( remove(intv.begin(), intv.end(), 0), intv.end());
			
			if(debug){
				for(i=0;i<intv.size();i++){
					cout << intv[i] <<endl;
				}
			}
			

			int vsize = intv.size();
			for(i=1;i<=vsize;i+=2){//i:Â
				if(debug) cout << "number = " << i << endl;
				for(j=0;j<=vsize-1-i+1;j++){ //j:JnÊu
					tmp = 0;
					for(k=0;k<i;k++){
						tmp += intv[j+k];
					}
					if(debug) cout << "tmp == " << tmp << endl;
					if(first == false){
						max = tmp;
						first = true;
					}else if(max < tmp){
						max = tmp;
					}
				}
			}
			cout << max << endl;
			intv.clear();
			first = false;
			notAllMinus = 0;
		}
	}
	return 0;
}

Measured memory_bytes: 0
fun main(args: Array<String>) {
    val (x1, y1, x2, y2) = readLine()!!.split(" ").map(String::toInt)

    val dx = x2 - x1
    val dy = y2 - y1

    val x3 = x2 - dy
    val y3 = y2 + dx

    val x4 = x3 - dx
    val y4 = y3 - dy

    println("$x3 $y3 $x4 $y4")
}

Measured memory_bytes: 37876
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#define ll long long int
#define mod 1000000007
using namespace std;
int main() 
{
 
	 string s;
	 cin>>s;
	 int j=s.size()-1;
	int count=0;
	 for(int i=0;i<j;i++,j--)
	 {
	 	if(s[i]!=s[j])
	 	{
	 		count++;
		 }
		 
	 }
	cout<<count;
	}
 
 
	



Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#define file(x) freopen(#x".in", "r", stdin), freopen(#x".out", "w", stdout)

const int N(3e5 + 10);
struct node { int x, y; } A[N];
int max[N << 2], lazy[N << 2], n, W, H, stk1[N], stk2[N], top1, top2, ans;
void puttag(int x, int v) { max[x] += v, lazy[x] += v; }
void Modify(int ql, int qr, int v, int x = 1, int l = 1, int r = n)
{
	if (ql <= l && r <= qr) return puttag(x, v);
	int mid = (l + r) >> 1, ls = x << 1, rs = ls | 1;
	puttag(ls, lazy[x]), puttag(rs, lazy[x]), lazy[x] = 0;
	if (ql <= mid) Modify(ql, qr, v, ls, l, mid);
	if (mid < qr) Modify(ql, qr, v, rs, mid + 1, r);
	max[x] = std::max(max[ls], max[rs]);
}

void solve()
{
	std::sort(A + 1, A + n + 1, [](const node &l, const node &r) { return l.x < r.x; });
	memset(max, 0, sizeof max), memset(lazy, 0, sizeof lazy), Modify(1, n, H);
	stk1[top1 = 0] = stk2[top2 = 0] = 1;
	for (int i = 2; i <= n; i++)
	{
		Modify(1, i - 1, A[i].x - A[i - 1].x), ans = std::max(ans, max[1]);
		if (A[i].y >= H >> 1)
		{
			Modify(stk1[top1], i - 1, A[i].y - H);
			while (top1 && A[stk1[top1]].y > A[i].y)
				Modify(stk1[top1 - 1], stk1[top1] - 1, A[i].y - A[stk1[top1]].y), --top1;
			stk1[++top1] = i;
		}
		else
		{
			Modify(stk2[top2], i - 1, -A[i].y);
			while (top2 && A[stk2[top2]].y < A[i].y)
				Modify(stk2[top2 - 1], stk2[top2] - 1, A[stk2[top2]].y - A[i].y), --top2;
			stk2[++top2] = i;
		}
	}
}

int main()
{
	scanf("%d%d%d", &W, &H, &n), ++n, ans = std::max(W, H) + 1;
	for (int i = 2; i <= n; i++) scanf("%d%d", &A[i].x, &A[i].y);
	A[++n] = (node) {W, H}, solve(), std::swap(W, H);
	for (int i = 1; i <= n; i++) std::swap(A[i].x, A[i].y);
	solve(); printf("%d\n", ans << 1);
	return 0;
}


Measured memory_bytes: 12800
#include<stdio.h>
int div(int n)
{
  int i;
  int ans=0;
  for (i=1;i*i<=n;i++){
    if (n%i==0){
	    ans+=1;
    if (i != n/i)
      ans+=1;
    }
  }
  return ans;
}
int main(){
  int s,a,j;
  scanf("%d\n",&s);
  a=1;
  for (j=2;j<s;j++){
    a+=div(j);
  }
  printf("%d",a);
}

Measured memory_bytes: 1720
K_meter, N_ken = map(int, input().split())
A = list(map(int, input().split()))

diff = []

for i in range(N_ken - 1):
    d = A[i + 1] - A[i]
    diff.append(d)

diff.append(K_meter - A[N_ken - 1] + A[0])

summ = sum(diff)

ans = summ - max(diff)

print(ans)

Measured memory_bytes: 26100
import java.util.Scanner;

public class Main {
	public static void main(String[]args) {
		try(Scanner scan = new Scanner(System.in)){
			
			int N = scan.nextInt();
			int K = scan.nextInt();
			COMinit();
			
			for(int i = 1;i<=K;i++) {
				long goukei = 0;
				
				goukei = (COM(N-K+1,i)*COM(K-1,i-1))%MOD;
				
				System.out.println(goukei);
				
			}
			
			
			
			
		}
	}
	
	
	//拡張ユークリッドでの逆元の求め方でnCkをつくる、前処理必須。
	
	static  int MAX = 510000;
	static  int MOD = 1000000007;

	 static long[] fac = new long[MAX]; 
	 static long[] finv = new long[MAX]; 
	 static long[] inv = new long[MAX]; 

	// テーブルを作る前処理
	static void COMinit() {
	    fac[0] = fac[1] = 1;
	    finv[0] = finv[1] = 1;
	    inv[1] = 1;
	    for (int 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;
	    }
	}

	// 二項係数計算
	static long COM(int n, int k){
	    if (n < k) return 0;
	    if (n < 0 || k < 0) return 0;
	    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
	}
}


Measured memory_bytes: 36692
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define enter putchar('\n')
#define space putchar(' ')
//#define ivorysi
#define MAXN 200005
typedef long long int64;
using namespace std;
template<class T>
void read(T &res) {
    res = 0;char c = getchar();T f = 1;
    while(c < '0' || c > '9') {
        if(c == '-') f = -1;
        c = getchar();
    }
    while(c >= '0' && c <= '9') {
        res = res * 10 + c - '0';
        c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
        out(x / 10);
    }
    putchar('0' + x % 10);
}
int N;
int64 a[MAXN],sum[MAXN];
int64 get_abs(int l1,int r1,int l2,int r2) {
    return abs((sum[r1] - sum[l1 - 1]) - (sum[r2] - sum[l2 - 1]));
}
void Solve() {
    read(N);
    for(int i = 1 ; i <= N ; ++i) {
        read(a[i]);sum[i] = sum[i - 1] + a[i];
    }
    int l = 1,p = 2,r = p + 1;
    int64 ans = sum[N];
    while(p <= N - 2) {
        while(l + 1 < p && get_abs(1,l,l + 1,p) > get_abs(1,l + 1,l + 2,p)) ++l;
        r = max(r,p + 1);
        while(r + 1 < N && get_abs(p + 1,r,r + 1,N) > get_abs(p + 1,r + 1,r + 2,N)) ++r;
        int64 m[] = {sum[l],sum[p] - sum[l],sum[r] - sum[p],sum[N] - sum[r]};
        int64 tmp = 0;
        for(int i = 0 ; i <= 3 ; ++i) {
            for(int j = i + 1 ; j <= 3 ; ++j) {
                tmp = max(tmp,abs(m[j] - m[i]));
            }
        }
        ans = min(ans,tmp);
        ++p;
    }
    out(ans);enter;
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
    return 0;
}

Measured memory_bytes: 3456
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x ,n) for(int i = x; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main(){
    int n,r,l;
    cin >> n;
    int ans=0;
    rep(i,n){
        cin >> r >> l;
        ans+=l-r+1;
    }
    cout << ans;
	return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
#define pb push_back
#define pf push_front
#define eb emplace_back
using namespace std;
typedef long long ll;
template<class t,class u> bool chmax(t&a,u b){if(a<b){a=b; return true;} return false;}
template<class t,class u> bool chmin(t&a,u b){if(a>b){a=b; return true;} return false;}
template<class t,class u> t MAX(t a,u b){if(a>=b) return a; return b;}
template<class t,class u> t MIN(t a,u b){if(a<=b) return a; return b;}
template<class t> int SIZE(t s){return (int)s.size();}
template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;
using vvi=vc<vc<int>>;
using pi=pair<int,int>;
using vi=vc<int>;
void yes(){ cout << "Yes" << endl; }
void no(){ cout << "No" << endl; }
const long long INF = 1LL << 60;

int main(){
    cout << fixed << setprecision(20);
    ll n,k; cin >> n >> k;
    vc<bool> ch(n,false);
    vc<ll> to(n);
    rep(i,n){
        int x; cin >> x;
        x--;
        to[i] = x;
    }
    ll cur = 0, cnt = 0;
    vc<ll> ansf;
    while(!ch[cur]){
        //cout << cur << endl;
        ansf.eb(cur+1);
        ch[cur] = true;
        cur = to[cur];
        cnt++;
    }
    ll cur2 = cur,cnt2 = 0;
    vc<ll> ans;
    while(ch[cur2]){
        ans.eb(cur2+1);
        //cout << cur2 << endl;
        ch[cur2] = false;
        cur2 = to[cur2];
        cnt2++;
    }
    //cout << cnt << " " << cnt2 << endl;
    
    if(k <= cnt-1) cout << ansf[k] << endl;
    else {
        k -= (cnt-cnt2);
        cout << ans[k%cnt2] << endl;
    }
    return 0;
}


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

typedef long long ll;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define dump(x)  cout << #x << " = " << (x) << endl;	//debug
#define SZ(x) ((ll)(x).size())
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define RFOR(i, a, b) for (ll i = (a); i >= (b); i--)
#define ps(s) cout << #s << endl;
#define pv(v) cout << (v) << endl;
#define pvd(v) cout << setprecision(16) << (v) << endl;
#define ALL(a)  (a).begin(),(a).end()
#define RANGE(a, start_index, num)  (a).begin()+(start_index),(a).begin()+(num)

using Graph = vector<vector<int>>;

int main() {
	int N,Q;
	cin >> N >> Q;
	Graph G(N + 1);

	FOR(i, 1, N-1) {
		int a, b;
		cin >> a >> b;
		G[a].push_back(b);
		G[b].push_back(a);
	}

	vector<int> x(N + 1);
	FOR(i, 1, Q) {
		int p, val;
		cin >> p >> val;
		x[p] += val;
	}

	vector<int> dist(N + 1, -1); // 全頂点を「未訪問」に初期化
	queue<int> que;

	// 初期条件 (頂点 1 を初期ノードとする)
	dist[1] = x[1];
	que.push(1);

	while (!que.empty()) {
		int v = que.front(); // キューから先頭頂点を取り出す
		que.pop();

		for (int nv : G[v]) { //nvはvと隣り合う全てのノード
			if (dist[nv] != -1) continue; // すでに発見済みの頂点は探索しない

										  // nvへの距離を更新してnvをキューに追加する
			dist[nv] = dist[v] + x[nv];
			que.push(nv);
		}
	}

	// 結果出力 (各頂点の頂点 1 からの距離を見る)
	FOR(i, 1, N) {
		pv(dist[i]);
	}
}

Measured memory_bytes: 16372
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <bitset>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef tuple<ll, ll, ll> tl3;



const int BIG_NUM = 1e9;
const ll INF = 1000000000000000000;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;



int main() {
	int n;
	cin >> n;
	vector<pii> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i].first;
		a[i].second = i;
	}

	sort(a.begin(), a.end());

	int cnt = 0;
	for (int i = 0; i < n; i++) {
		if (abs(i - a[i].second) % 2 != 0) {
			cnt++;
		}
	}

	cout << cnt / 2 << endl;
}

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

int main()
{
  int n;
  cin >> n;
  vector<pair<int, int>> tasks(n);
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    tasks.at(i) = make_pair(b, a);
  }
  sort(tasks.begin(), tasks.end());
  long time = 0;
  for (int i = 0; i < n; i++) {
    time += tasks.at(i).second;
    if (time > tasks.at(i).first) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}


Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		// 入力値の取得
		String C = sc.next();
		char c = (char) (C.toCharArray()[0] + 1);

		// 結果の出力
		System.out.println(c);

		sc.close();
	}

}


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


int main(){
  ll n;
  cin >> n;
  //map<ll,int> mp;
  vector<ll> mp(n+1,0);
  ll ans=0;
  for(int i=1;i<=n;++i){
    for(int j=i;j<=n;j=j+i){
      mp[j]++;
    }
    ans+=i*mp[i];
  }
  cout << ans << endl;
  return 0;
}


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

#define ld long double
#define ll long long int
#define ull unsigned long long int
#define vi vector<int>
#define vl vector<ll>
#define vvi vector< vector<int> >
#define vvl vector< vector<ll> >
#define repd(i, a, b) for (int i=(a);i<(b);i++)
#define rep(i, n) repd(i,0,n)
#define ALL(v) v.begin(), v.end()
#define INF 1e9

using namespace std;

/**
 * calculate GCD(greatest common divisor)
 * @param a
 * @param b
 * @return
 */
unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

/**
 * change minimum
 * @tparam T
 * @param a
 * @param b
 * @return bool
 */
template<class T>
inline bool changeMinimum(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

/**
 * change maximum
 * @tparam T
 * @param a
 * @param b
 * @return bool
 */
template<class T>
inline bool changeMaximum(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

/**
 * output answer
 * @tparam T
 * @param answer
 * @return
 */
template<typename T>
T output(T answer) {
    cout << answer << endl;
    return 0;
}

/** ----from here ---------------------------------------------------------- */

int main() {

    int N;
    cin >> N;
    vector<int> a(N);
    for (int i = 0; i < N; ++i) {
        cin >> a.at(i);
    }
    map<int, int> s;
    for (int i = 0; i < N; ++i) {
        s[a[i]] += 1;
    }
    int ans = 0;
    for (pair<int, int> p:s) {
        int key = p.first;
        int val = p.second;
        if (key > val) {
            ans += val;
        }
        if (key < val) {
            ans += val - key;
        }
        // cout << p.first << " " << p.second << endl;
    }
    cout << ans << endl;
}

Measured memory_bytes: 5120
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;

#define CIN_ONLY if(1)
struct cww{cww(){
    CIN_ONLY{
        ios::sync_with_stdio(false);cin.tie(0);
    }
}}star;
#define fin "\n"
#define FOR(i,bg,ed) for(int i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
#define pb push_back
#define DEBUG if(0)
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l,T r)
{bool a=l>r;if(a)l=r;return a;}
template <typename T>inline bool chmax(T &l,T r)
{bool a=l<r;if(a)l=r;return a;}
template <typename T>
istream& operator>>(istream &is,vector<T> &v){
    for(auto &it:v)is>>it;
    return is;
}
    
int main(){
    int N;string S;
    cin>>N>>S;
    int a=0,b=0;
    int st=0;
    REP(i,N){
        if(S[i]=='('){
            st++;
        }
        else{
            if(st==0)a++;
            else st--;
        }
    }
    b=st;
    REP(i,a)cout<<"(";
    cout<<S;
    REP(i,b)cout<<")";
    cout<<endl;
    return 0;
}


Measured memory_bytes: 256