akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define all(v) v.begin(),v.end()
#define mem(arr) memset(arr, 0, sizeof(arr))
#define ff first
#define ss second
#define int long long int
const int MOD = 1e9 + 7;
const int INF = 1e18;
const int N = 1e6 + 20;
vector<int> g[N];
vector<int> vis(N);
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int tc = 1;
    while(tc--){
        int n;
        cin >> n;
        for(int i = 0; i < n; i++){
            int x;
            cin >> x;
            if(x % 2){
                cout << "first\n";
                return 0;
            }
        }
        cout << "second\n";
    }
}

Measured memory_bytes: 31488
#include<iostream>
#include<string>
using namespace std;
int main(){
	string s;
	while(cin>>s){
		if(s=="-")
			break;
		int n,h,len=s.size();
		cin>>n;
		for(int i=0;i<n;i++){
			cin>>h;
			s=s.substr(h,len+1)+s.substr(0,h);
		}
		cout<<s<<endl;
	}
	return 0;
}


Measured memory_bytes: 3160
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;
import java.util.Set;
import java.util.HashSet;
import java.util.Map;
import java.util.HashMap;
import java.util.Queue;
import java.util.ArrayDeque;

import static java.lang.System.out;

public class Main {
    public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in)) {
            int n = in.nextInt();
            
            List<Set<Integer>> g = new ArrayList<>();
            for (int i = 0; i < n; i++)
                g.add(new HashSet<>());

            Queue<Integer> q = new ArrayDeque<>();
            Map<Integer, Integer> mm = new HashMap<>();
            for (int i = 0; i < n; i++)
                mm.put(i, 0);
            
            int m = in.nextInt();
            for (int i = 0; i < m; i++) {
                int f = in.nextInt();
                int t = in.nextInt();

                g.get(f).add(t);
                mm.replace(t, mm.get(t)+1);
            }

            for (Map.Entry<Integer, Integer> e : mm.entrySet()) {
                if (e.getValue() == 0)
                    q.add(e.getKey());
            }

            while (!q.isEmpty()) {
                int v = q.remove();
                out.printf("%d\n", v);

                for (int vv : g.get(v)) {
                    int d = mm.get(vv)-1;

                    if (d == 0)
                        q.add(vv);
                    mm.replace(vv, d);
                }
            }
        } 
            catch (Exception ex) {
            throw new RuntimeException(ex);
        }
    }
}



Measured memory_bytes: 82340
package main

import (
	"fmt"
	"sort"
)

func main() {
  var N int
  fmt.Scan(&N)
  
  ws := make(Ws, N)
  for i := 0; i < N; i++ {
    var a, b int
    fmt.Scan(&a, &b)
    ws[i].A = a
    ws[i].B = b
  }
  sort.Sort(ws)
  s := 0
  for _,w := range ws {
    s += w.A
    if s > w.B {
      fmt.Println("No")
      return
    }
  }
  fmt.Println("Yes")
}

type Work struct { A, B int }

type Ws []Work
func (a Ws) Len() int { return len(a) }
func (a Ws) Less(i, j int) bool { return a[i].B < a[j].B }
func (a Ws) Swap(i, j int) { a[i], a[j] = a[j], a[i] }



Measured memory_bytes: 9600
from heapq import heapify,heappush,heappop

def main():
    N,M = map(int,input().split())
    A = [ -x for x in map(int,input().split()) ]
    heapify(A)

    for i in range(M):
        #print(A)
        tmp = -heappop(A)
        #print(tmp)
        tmp = tmp//2
        #print(tmp)
        heappush(A,-tmp)


    ans = 0
    for i in range(N):
        ans += A[i]

    ans = abs(ans)
    return ans

print(main())


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


int main(){
    int a,b;
    cin >> a >> b;
    if(a+b==15)cout << "+" << endl;
    else if(a*b==15) cout << "*" << endl;
    else cout << "x" << endl;
    return 0;
}

Measured memory_bytes: 384
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <math.h>
#include <queue>
 
using namespace std;
 
int main(){
 
    int n,m,min_time[101][101],min_cost[101][101],from,to,cost,time,num,r;
 
    while(true){
        scanf("%d %d",&n,&m);
        if(n == 0 && m == 0)break;
 
        for(int i = 1; i <= m; i++){
            for(int k = 1; k <= m; k++){
                if(i != k){
                    min_time[i][k] = 2000000000;
                    min_cost[i][k] = 2000000000;
                }else{
                    min_time[i][k] = 0;
                    min_cost[i][k] = 0;
                }
            }
        }
 
        for(int i = 0; i < n; i++){
            scanf("%d %d %d %d",&from,&to,&cost,&time);
            min_time[from][to] = time;
            min_cost[from][to] = cost;
            min_time[to][from] = time;
            min_cost[to][from] = cost;
        }
 
        for(int k = 1; k <= m; k++){
            for(int i = 1; i <= m; i++){
                if(min_time[i][k] == 2000000000)continue;
                for(int p = 1; p <= m; p++){
                    if(min_time[k][p] == 2000000000)continue;
                    min_time[i][p] = min(min_time[i][p],min_time[i][k] + min_time[k][p]);
                }
            }
 
            for(int i = 1; i <= m; i++){
                if(min_cost[i][k] == 2000000000)continue;
                for(int p = 1; p <= m; p++){
                    if(min_cost[k][p] == 2000000000)continue;
                    min_cost[i][p] = min(min_cost[i][p],min_cost[i][k] + min_cost[k][p]);
                }
            }
        }
 
        scanf("%d",&num);
 
        for(int i = 0; i < num; i++){
            scanf("%d %d %d",&from,&to,&r);
            if(r == 1){
                printf("%d\n",min_time[from][to]);
            }else{
                printf("%d\n",min_cost[from][to]);
            }
        }
    }
 
    return 0;
}



Measured memory_bytes: 2700
#include <cstdio>
#include<iostream>
#include<map>
#include<algorithm>
#include<vector>
#include <cmath>
#include <iomanip>
#include <regex>
#include <bits/stdc++.h>
#include <string>
using namespace std;
using ll = long long;
const ll MOD = 1000000007; 

int main(){  
     
    ll A,B,C,D,E,F;
    cin>>A>>B>>C>>D>>E>>F;
    vector<ll> x;
    vector<ll> y;
    for(auto i=0;i*100*A<=F;i++){
        for(auto j=0;;j++){
            if(i*100*A+B*100*j<=F){
                x.push_back(i*100*A+B*100*j);
            }else break;
        }
    }
    for(auto i=0;i<=F;i++){
        for(auto j=0;j*C<=i;j++){
            if((i-j*C)%D==0){
                y.push_back(i);
                continue;
            }
        }
    }
    double _max=-1,max_x=0,max_y=0;
    // cout<<y.size()<<endl;
    for(auto i=0;i<x.size();i++){
        for(auto j=0;j<y.size();j++){
            // cout<<"i:"<<i<<", j:"<<j<<":::"<<x[i]+y[i]<<endl;
            if(x[i]+y[j]<=F&&(double)x[i]*(double)(E)/100.0>=y[j]){
                double dence = (double)y[j]/((double)x[i]+(double)y[j]);
                if(_max<dence){
                    _max = dence;
                    max_x = x[i];
                    max_y = y[j];
                }
            }
        }
    }
    cout<<max_x+max_y<<" "<<max_y<<endl; 
}


Measured memory_bytes: 2420
#include <bits/stdc++.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iostream>
#include <bitset>
#include <cassert>
#include <queue>
#include <random>
#include <stack>
#include <iomanip>
#include <math.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define repf(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define repr(i, a, b) for (ll i = (ll)a; i > (ll)b; i--)
#define repv(x, arr) for (auto &x : arr)
#define all(v) (v).begin(), (v).end()
#define vec(name, num) vector<ll> name((num), 0);
#define mp(a, b) make_pair(a, b)
#define F first
#define S second
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int> vii;
typedef vector<vii> vvii;
const ll mod = 1e9 + 7;
const int infi = 2147483600;
const ll infl = 1e17;

struct point{
    long double x, y;
};

long double sq(long double x){
    return x * x;
}
long double sqr(long double d){
    if (d==0)
        return 0;
    long double x = sqrtl(d);
    rep(i,20){
        x = (x + d / x) / 2.0;
    }
    return x;
}

int main()
{
    std::cout << std::fixed;
    ll n;
    point s, t;
    cin >> s.x >> s.y >> t.x >> t.y >> n;
    vector<pair<point, long double>> circle(n+2);
    circle[0] = mp(s, 0);
    circle[n + 1] = mp(t, 0);
    rep(i,n){
        long double x, y, r;
        point p;
        cin >> x >> y >> r;
        p.x = x;
        p.y = y;
        circle[i+1] = mp(p, r);
    }
    vector<vector<long double>> edges(n+2, vector<long double>(n+2));
    rep(i,n+2){
        rep(j,n+2){
            ld d = sq(circle[i].F.x - circle[j].F.x) + sq(circle[i].F.y - circle[j].F.y);
            edges[i][j] = max((long double)0,sqr(d)-circle[i].S-circle[j].S);
        }
    }
    vector<long double> dist(n + 2,(ld)infl);
    dist[0] = (long double)0;
    set<int> check;
    check.insert(0);
    while (!(check.empty())){
        int now = *check.begin();
        check.erase(now);
        rep(nex,n+2){
            if (dist[now]+edges[now][nex]<dist[nex]){
                dist[nex] = dist[now] + edges[now][nex];
                check.insert(nex);
            }
        }
    }
    cout << setprecision(10) << dist[n + 1] <<  endl;
}


Measured memory_bytes: 17920
def sub_a(x, y)
  ret = []
  3.times {|i| ret << x[i] - y[i]}
  ret
end

def eq3(x, y, z)
  x == y && y == z && x == z ? true : false
end

c = []
comp = []
3.times{c << gets.split.map(&:to_i)}
comp << sub_a(c[0], c[1])
comp << sub_a(c[0], c[2])
comp << sub_a(c[1], c[2])
d = c.transpose
comp << sub_a(d[0], d[1])
comp << sub_a(d[0], d[2])
comp << sub_a(d[1], d[2])
comp.each do |x|
  unless eq3(x[0], x[1], x[2])
    puts "No"
    exit
  end
end
puts "Yes"

Measured memory_bytes: 1788
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) v.erase(unique(v.begin(), v.end()), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

#define MAX_V 1000000

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

  int n, W;
  cin >> n >> W;
  int v[n], w[n];
  rep(i, 0, n) cin >> v[i] >> w[i];

  int dp[n + 1][W + 1];
  memset(dp, 0, sizeof(dp));

  rep(i, 0, n) {
    rep(j, 0, W + 1) {
      if(j - w[i] >= 0) {
        dp[i + 1][j] = max(dp[i][j], dp[i + 1][j - w[i]] + v[i]);
      } else {
        dp[i + 1][j] = dp[i][j];
      }
    }
  }

  cout << dp[n][W] << endl;
}



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

int main() {
  int K;
  cin >> K;
  if(K == 1){
    cout << 1 << endl;
  }
  if(K == 2){
    cout << 1 << endl;
  }
  if(K == 3){
    cout << 1 << endl;
  }
  if(K == 4){
    cout << 2 << endl;
  }
  if(K == 5){
    cout << 1 << endl;
  }
  if(K == 6){
    cout << 2 << endl;
  }
  if(K == 7){
    cout << 1 << endl;
  }
  if(K == 8){
    cout << 5 << endl;
  }
  if(K == 9){
    cout << 2 << endl;
  }
  if(K == 10){
    cout << 2 << endl;
  }
  if(K == 11){
    cout << 1 << endl;
  }
  if(K == 12){
    cout << 5 << endl;
  }
  if(K == 13){
    cout << 1 << endl;
  }
  if(K == 14){
    cout << 2 << endl;
  }
  if(K == 15){
    cout << 1 << endl;
  }
  if(K ==16){
    cout << 14 << endl;
  }
  if(K == 17){
    cout << 1 << endl;
  }
  if(K == 18){
    cout << 5 << endl;
  }
  if(K == 19){
    cout << 1 << endl;
  }
  if(K == 20){
    cout << 5 << endl;
  }
  if(K == 21){
    cout << 2 << endl;
  }
  if(K == 22){
    cout << 2 << endl;
  }
  if(K == 23){
    cout << 1 << endl;
  }
  if(K == 24){
    cout << 15 << endl;
  }
  if(K == 25){
    cout << 2 << endl;
  }
  if(K == 26){
    cout << 2 << endl;
  }
  if(K == 27){
    cout << 5 << endl;
  }
  if(K == 28){
    cout << 4 << endl;
  }
  if(K == 29){
    cout << 1 << endl;
  }
  if(K == 30){
    cout << 4 << endl;
  }
  if(K == 31){
    cout << 1 << endl;
  }
  if(K == 32){
    cout << 51 << endl;
  }
}

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

int main() {
  long long n;
  cin >> n;
  
  vector<int> cij;
  for (int i = 0; i <= 9; i++) {
    for (int j = 0; j <= 9; j++) {
      int count = 0;
      for (int k = 1; k <= n; k++) {
        long long bottom = k % 10;
        if (j != bottom) continue;
        long long top = k;
        while(top >= 10) { top /= 10; }
        if (i != top) continue;
        count++;
      }
      cij.push_back(count);
    }
  }
  
  int count = 0;
  for (int i = 0; i <= 9; i++) {
    for (int j = 0; j <= 9; j++) {
      count += cij[i*10+j] * cij[j*10+i];
    }
  }
  
  cout << count << endl;
  return 0;
}

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

using namespace std;

int arr[3003];

/*void pre(int n){
	for(int i = 2; i<=n; ++i){
    	arr[i]+=arr[i-1];
    }
}

int getscore(int l, int r){
	return arr[r]-arr[l-1];
}*/

long long dp[3003][3003];
int vis[3003][3003];

long long solve(int i, int j){
	if(i==j){
      	return dp[i][j] = arr[i];
    }
  	if(i>j)return 0;
  	if(vis[i][j])return dp[i][j];
  	
  	vis[i][j] = 1;
  
    long long x1 = arr[i];
  	long long x1y1 = arr[i+1];
  	long long ret1 = (x1-x1y1)+solve(i+2,j);
  	long long x1y2 = arr[j];
  	long long ret2 = (x1-x1y2)+solve(i+1,j-1);
  //cout<<"ret1: "<<ret1<<" ret2: "<<ret2<<"\n";
  	long long r1 = min(ret1,ret2);
  //cout<<"r1: "<<r1<<"\n";
  	
    long long x2 = arr[j];
  	long long x2y1 = arr[i];
  	ret1 = (x2-x2y1)+solve(i+1,j-1);
  	long long x2y2 = arr[j-1];
  	ret2 = (x2-x2y2)+solve(i,j-2);
  // cout<<"ret1: "<<ret1<<" ret2: "<<ret2<<"\n";
  	long long r2 = min(ret1,ret2);
   // cout<<"r2: "<<r2<<"\n";
  	return dp[i][j] = max(r1,r2);
  	
}

int main(){
	int n;
  	scanf("%d",&n);
  	for(int i = 1; i<=n; ++i)
      	scanf("%d",&arr[i]);
  	//pre(n);
  	memset(vis,0,sizeof(vis));
    long long ans = solve(1,n);
  	printf("%lld\n",ans);
  	return 0;
}

Measured memory_bytes: 105088
def root(x):
  while p[x]>=0:x=p[x]
  return x
def unite(a,b):
  a,b=root(a),root(b)
  if a!=b:
    if p[a]>p[b]:a,b=b,a
    p[a]+=p[b]
    p[b]=a
n,m,*t=map(int,open(0).read().split())
p=[-1]*n
c=[0]*n
for a,b in zip(*[iter(t)]*2):
  a-=1
  b-=1
  unite(a,b)
  c[a]+=1
  c[b]+=1
a=root(0),root(1)
f=p[a[0]]<p[a[1]]
t=[0,0]
for i in range(n):
  j=root(i)
  if j==a[f]:
    t[f]+=c[i]
  else:
    t[f^1]+=c[i]
    unite(a[f^1],j)
r=0
for i in(0,1):
  n=-p[root(i)]
  r+=n*(n-1)-t[i]>>1
print(r)

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

using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)

int count_light[2001][2001];
int count_light2[2001][2001];

int main()
{
    int h, w;
    cin >> h >> w;
    vector<string> s(h);
    REP(i, h) { cin >> s[i]; }
    int ans=0;
    int light = 0;

    REP(i,h){
        REP(j,w){
            char c = s[i][j];
            if(c=='#'){
                light = 0;
                count_light[i][j] = 0;
            }else{
                light++;
                count_light[i][j] = light;
            }
        }
        light = 0;
    }
    REP(i, h)
    {
        IREP(j, w)
        {
            int c = count_light[i][j];
            if (c == 0)light = 0;
            else
            {
                light=max(light,c);
                count_light[i][j] = light;
            }
        }
        light = 0;
    }
    //縦も見る
    
    REP(j, w)
    {
        REP(i, h)
        {
            char c = s[i][j];
            if (c == '#')
            {
                light = 0;
                count_light2[i][j] = 0;
            }
            else
            {
                light++;
                count_light2[i][j] = light;
            }
        }
        light = 0;
    }

    REP(j, w)
    {
        IREP(i, h)
        {
            int c = count_light2[i][j];
            if (c == 0)
                light = 0;
            else
            {
                light = max(light, c);
                count_light2[i][j] = light;
            }
        }
        light = 0;
    }
    REP(i, h)
    {
        REP(j, w){
            int sum_light = count_light[i][j] + count_light2[i][j];
            ans = max(ans, sum_light);
        }
    }
    /*
    REP(i, h){
        REP(j, w)
            cout << count_light[i][j];
            cout <<  "\n";
    }
    cout << "\n";

    REP(i, h)
    {
        REP(j, w)
        cout << count_light2[i][j];
        cout << "\n";
    }
    */
    cout << ans-1 <<"\n";

    return 0;
}

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

#define name ""
#define ini freopen(name".inp","r",stdin); freopen(name".out","w",stdout)
#define long long long
#define db double
#define pii pair <int, int>
#define pll pair <long, long>
#define all(c) c.begin(), c.end()
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
template <class T> inline void chmin(T &a, const T& val) { if (a > val) a = val; }
template <class T> inline void chmax(T &a, const T& val) { if (a < val) a = val; }
template <class T> long sqr(T a) { return 1ll * a * a; }
template <class T> void compress(T &a){
  sort(all(a)); a.resize(unique(all(a)) - a.begin());  
}

const db pi = acos(-1.00);
const db eps = 1e-6;
const int INF = 1e9;
const int MOD = 1e9+7;
const int dx[4] = {0, 0, -1, 1};
const int dy[4] = {-1, 1, 0, 0};

int main()
{
  fastio;
  int n, cur = 0; cin >> n;
  vector <int> a(n);
  for (int &x : a){
    cin >> x; cur ^= x;
  }
  for (int x : a) cout << (cur ^ x) << ' ';
  return 0;
}

Measured memory_bytes: 3988
#include <bits/stdc++.h> 
#include<cmath>
#define pb push_back
#define ll long long
#define ull unsigned long long
#define deb(x) cerr<<#x<<" "<<x<<"\n"
#define debi cerr<<"hey sparky\n"
#define x first
#define y second
#define nax (int)1e5+2
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define newline cout<<"\n"
#define yes cout<<"YES"<<"\n"
#define no cout<<"NO"<<"\n" 
#define INF (int)1e9
#define eps (long double)1e-9
//#define int long long
using namespace std;
// sequences with only one 2 should not be included	
int main(){
	
	ll k;
	cin>>k;
	queue<ll> val;
	//string ans = "";
	//int cnt = 0;
	for(ll i=1;i<=9;i++){
		//char a = '0'+i;
		//string temp = "0"+i;
		val.push(i);
	}
	//int cnt = 1;
	for(ll i=1;i<k;i++){
		ll temp = val.front();
		val.pop();
		ll a = temp%10;
		if(a>0){
			ll temp1 = temp*10+(a-1ll);
			val.push(temp1);
		}
		
		ll temp1 = temp*10 + a;
		val.push(temp1);
		if(a<9){
			ll temp2 = temp*10 + (a+1ll);
			val.push(temp2);
		}
	}
	cout<<val.front();
	return 0;
}
	


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

int main(){
  long long n,k,s;
  cin>>n>>k>>s;
  if(n==k){
    for(int i=0;i<n;i++) cout<<s<<" ";
    cout<<endl;
  }
  else{
    if(s==1){
      for(int i=0;i<k;i++){
        cout<<1;
        if(i!=n-1) cout<<" ";
        else cout<<endl;
      }
      for(int i=k;i<n;i++){
        cout<<s+1;
      	if(i!=n-1) cout<<" ";
      	else {cout<<endl; return 0;}
      }
    }
    else{
      for(int i=0;i<k+1;i++){
        if(i%2==0) cout<<s/2;
        else cout<<(s+1)/2;
        if(i!=n-1) cout<<" ";
        else cout<<endl;
      }
    }
    if(s==1e9){
      for(int i=k+1;i<n;i++){
        cout<<1;
        if(i!=n-1) cout<<" ";
        else cout<<endl;
      }
    }
    else{
      for(int i=k+1;i<n;i++){
        cout<<s+1;
      	if(i!=n-1) cout<<" ";
      	else cout<<endl;
      }
    }
  }
}
    
      

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n;
    cin >> n;
    vector<int> h(n);
    for(int i = 0; i < n; i++)  cin >> h[i];
    vector<int> a{0};
    for(int i = 0; i < n; i++){
        if(a.back() <= h[i]) a.push_back(h[i]);
    }
    cout << a.size()-1;
}


Measured memory_bytes: 256
#include <iostream>
#include <queue>

const int MAX_QUEUE = 100000;

template <typename T> class Queue {
  T q[MAX_QUEUE];
  int head = 0, tail = 0;

public:
  void push(T v) {
    q[tail++] = v;
    if (tail >= MAX_QUEUE)
      tail = 0;
  }
  bool empty() { return head == tail; }
  T front() { return q[head]; }
  void pop() {
    if (empty())
      return;
    if (++head >= MAX_QUEUE)
      head = 0;
  }
};

typedef struct Process {
  std::string name;
  int time;
} P;

int main() {
  Queue<P> que;

  int n, q;
  std::cin >> n >> q;
  for (int i = 0; i < n; ++i) {
    P p;
    std::cin >> p.name >> p.time;
    que.push(p);
  }

  int total = 0;
  while (!que.empty()) {
    P p = que.front();
    que.pop();
    p.time -= q;
    if (p.time > 0) {
      que.push(p);
      total += q;
    } else {
      total += q + p.time;
      std::cout << p.name << " " << total << std::endl;
    }
  }
}



Measured memory_bytes: 7076
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		String t = sc.next();
		int cn = 0;
		for (int i = 0; i < s.length(); i++) {
			if (s.substring(i, i + 1).equals(t.substring(i, i + 1))) {

			} else {
				cn++;
			}

		}
		System.out.println(cn);
		sc.close();
	}

}

Measured memory_bytes: 56220
////////////////////////////////////////////////////////////////////
// This source code is for Visual C++ 2010 Express
////////////////////////////////////////////////////////////////////
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <stack>
#include <functional>
#include <iomanip>
#include <string>
#include <cstring>
#include <deque>
#include <math.h>

#define	numberof(a)	(sizeof(a) / sizeof(a[0]))
#define	INF		(1000000)
#define Rep(i,n) for(int i = 0; i < (n); i++ )

using namespace std;

typedef vector< vector<int> > mat;
typedef pair<int, int> P;
typedef long long ll;
struct Point{
	ll x;
	ll y;
	Point() {};
	Point( ll xx, ll yy ) : x(xx), y(yy) {};
};

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int main()
{
	ll M = 0;
	ll N = 0;
	ll ret = 0;
	cin >> N >> M;

	vector< pair<ll, ll> > AB(N);
	Rep(i, N){
		cin >> AB[i].first >> AB[i].second;
	}
	sort(AB.begin(), AB.end());

	ll buy = 0;
	ll cnt = 0;
	Rep(i, N){
		buy = min(AB[i].second, M - cnt);
		ret += buy * AB[i].first;
		cnt += buy;
		if( cnt >= M ) break;
	}

	cout << ret << endl;

	return 0;
}





Measured memory_bytes: 1792
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <numeric>
typedef long long Int;
#define rep(i,a,b) for(Int i=a;i<b;++i)
#define rrep(i,a,b) for(Int i=a;i>=b;--i)
using namespace std;

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

    int N, M; cin >> N >> M;
    vector<int> cities(N, 0);
  
    rep(i, 0, M) {
      int a, b; cin >> a >> b;
      --a; --b;
      cities[a]++; cities[b]++;
    }
  
    rep(i, 0, N) {
      cout << cities[i] << endl;
    }
}


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



void trace(int A[], int N){
  int i;
  REP(i,N){
    if(i > 0)cout << " ";
    cout << A[i];
  }
  cout << endl;
}

int bubblesort(int A[], int N){
  int sw;
  sw =0;
  bool flag =1;
  for(int i =0; flag;i++){
    flag =0;
    FORR(j,N-1,i+1){
      if (A[j-1] > A[j]){
        swap(A[j-1],A[j]);
        flag =1;
        sw++;
      }
    }
  }
  return sw;
}

int main(){
int N,sw;
cin >> N;
int A[100];
REP(i,N) cin >> A[i];
sw = bubblesort(A,N);

REP(i,N){
  if(i) cout << " ";
  cout << A[i];
}
cout << endl;
cout << sw <<endl;

return 0;
}



Measured memory_bytes: 3108
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) {
		FastReader sc = new FastReader();
		PrintWriter out = new PrintWriter(System.out);
		String n = sc.next();
		for (int i=0;i<n.length();i++) {
			out.print(n.charAt(i) == '9' ? '1' : '9');
		}
		out.flush();

	}

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

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

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}
}


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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
  for (auto val : array)
    std::cout << val << ", ";
  std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << std::setprecision(10);

  int x; std::cin >> x;
  int remain = x % 500;
  int ans = (x / 500) * 1000;
  ans += (remain / 5) * 5;
  std::cout << ans << "\n";
}


Measured memory_bytes: 256
from collections import deque
import sys
input = sys.stdin.readline
n = int(input())
child = [[] for _ in range(n)]
edge_order = []
for i in range(n-1):
    a, b = map(int, input().split())
    a, b = a-1, b-1 #リストに入れるために数字を1ずつ下げる
    child[a].append((i, b))
    edge_order.append(b)
#aを親として、（辺番号、子ども)この時、aを親に持つ辺はすべてchild[a]に入れられる
queue = deque([0])
color = [0] * n
while queue:
    v = queue.popleft()
    c = 1 #色の初期は位置からスタート
    for i, u in child[v]: #aを親に持つ子頂点すべてを探索する
        if c == color[v]: #親と色が同じとき
            c += 1
        color[u] = c
        c += 1
        queue.append(u)
#子頂点を親頂点としてqueueに突っ込む（a-bとb-aはないのでこれで全探索できる）
print(max(color))
for i in edge_order:
    print(color[i])


Measured memory_bytes: 28092
#include<iostream>
#include<string>
#include<algorithm>


using namespace std;

int main(void){
    string s;
    cin >> s;

    int n = s.size();

    bool flag = true;

    //at(0)
    if (s.at(0) != 'A') flag = false;

    //at(1)
    if (!('a' <= s.at(1) && s.at(1) <= 'z'))flag = false;

    int cnt = 0;

    //at(2) ~ at.(s.size()-2)
    for (int i = 2; i <= n-2; i++){
      if(s.at(i) == 'C'){
        cnt++;
      }
      else {
        if(!('a' <= s.at(i) && s.at(i) <= 'z')) {
          flag = false;
          break;
        }
      }
    }
    if(cnt != 1) flag = false;


    //last
    if (!('a' <= s.at(n-1) && s.at(n-1) <= 'z')) flag = false;

    if(flag){
        cout << "AC" << endl;
    }
    else{
        cout << "WA" << endl;
    }



}

Measured memory_bytes: 256
#include <iostream>

int main()
{
    int32_t ones, zeros, m_ones, k;
    std::cin >> ones >> zeros >> m_ones >> k;

    int32_t diff = k;
    int32_t result = 0;

    if (diff <= ones)
    {
        std::cout << k;
        return 0;
    }

    diff -= ones;
    result += ones;


    if (diff <= zeros)
    {
        std::cout << result;
        return 0;
    }

    diff -= zeros;
    result -= diff;

    std::cout << result;
}

Measured memory_bytes: 3168
a=[list(map(int,input().split())) for _ in range(3)]
a = sum(a,[])
n=int(input())
flag = [0]*9
for _ in range(n):
    b = int(input())
    if b in set(a):
        a_index = a.index(b)
        flag[a_index] = 1
w = [sum(flag[j*3+i] for i in range(3)) for j in range(3)]
h = [sum(flag[j+i*3] for i in range(3)) for j in range(3)]
d = [flag[0]+flag[4]+flag[8],flag[2]+flag[4]+flag[6]]
count = w+h+d
print('Yes' if max(count) == 3 else 'No')    

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,x,n) for(int i=x; i<(n); i++)
#define INF 99999999
#define M 1000000007
#define x first
#define y second

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

int main(){
	string s;
	ll dp[100001][5] = {0};
	cin >> s;
	dp[0][0] = 1;
	rep(i,s.size()){
		rep(j,4){
			dp[i][j] %= M;
			if(s[i] == '?'){
				dp[i+1][j+1] += dp[i][j];
				dp[i+1][j] += (dp[i][j] * 3)%M;
			}
			else{
				if(j == s[i] - 'A'){
					dp[i+1][j+1] += dp[i][j];
				}
				dp[i+1][j] += dp[i][j];
			}
		}
	}
	cout << dp[s.size()][3] % M << endl;
	return 0;
}




Measured memory_bytes: 4352
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	scanInit()

	s := nextStr()

	cnt10 := 0
	cnt01 := 0
	for i := 0; i < len(s); i++ {
		if (i)%2 == 0 {
			if s[i] == '1' {
				cnt01++
			} else {
				cnt10++
			}
		} else {
			if s[i] == '1' {
				cnt10++
			} else {
				cnt01++
			}
		}
	}

	fmt.Println(min(cnt10, cnt01))

}
func min(a, b int) int {
	if a > b {
		return b
	}
	return a
}

// ---- readfunc
func scanInit() {
	const cap = 100 * 1024
	var buf = make([]byte, cap)
	sc.Buffer(buf, cap)
	sc.Split(bufio.ScanWords)
	return
}
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 1976
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
int n;
long long a[60];

bool F(long long k){
	long long cnt=0;
	for(int i=0;i<n;i++){
		long long b=a[i]-n+1+k;
		cnt+=b/(n+1);
		if(b%(n+1)>0)cnt++;
		if(cnt>k)return false;
	}
	if(cnt<=k)return true;
	return false;
}

int main(){
	cin>>n;
	for(int i=0;i<n;i++)cin>>a[i];
	long long left=0,right=600000000000000000,mid;
	long long ret=914514114514114514;
	while(left<right){
		mid=(left+right)/2;
		bool ok=false;
		for(int i=0;i<51;i++){
			if(F(i+mid)){
				ok=true;
				if(ret>i+mid)ret=i+mid;
			}
		}
		if(ok){
			right=mid;
		}
		else left=mid+1;
	}
	bool ok=true;
	for(int i=0;i<n;i++)if(a[i]>=n)ok=false;
	if(ok)ret=0;
	cout<<ret<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define ggr getchar();getchar();return 0;
#define prique priority_queue
constexpr auto mod = 1000000007;
#define inf 1e15
#define key 1e9
using namespace std;
typedef pair<int, int>P;
template<class T> inline void chmax(T& a, T b) {
	a = std::max(a, b);
}
template<class T> inline void chmin(T& a, T b) {
	a = std::min(a, b);
}
//combination(Nが小さい時はこれを使う)
const int MAX = 330000;
int fac[MAX], finv[MAX], inv[MAX];
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;
	}
}
int COMB(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;
}

bool prime(int n) {
	int cnt = 0;
	for (int i = 1; i <= sqrt(n); i++) {
		if (n % i == 0)cnt++;
	}
	if (cnt != 1)return false;
	else return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}

//繰り返し二乗法（Nが大きい時の場合のcombination)
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= (i % mod); res %= mod;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}
//UnionFind
class UnionFind {
protected:
	int* par, * rank, * size;
public:
	UnionFind(unsigned int size) {
		par = new int[size];
		rank = new int[size];
		this->size = new int[size];
		rep(i, size) {
			par[i] = i;
			rank[i] = 0;
			this->size[i] = 1;
		}
	}
	int find(int n) {
		if (par[n] == n)return n;
		return par[n] = find(par[n]);
	}
	void unite(int n, int m) {
		n = find(n);
		m = find(m);
		if (n == m)return;
		if (rank[n] < rank[m]) {
			par[n] = m;
			size[m] += size[n];
		}
		else {
			par[m] = n;
			size[n] += size[m];
			if (rank[n] == rank[m])rank[n]++;
		}
	}
	bool same(int n, int m) {
		return find(n) == find(m);
	}
	int getsize(int n) {
		return size[find(n)];
	}
};
int dight_sum(int n) {
	int sum = 0;
	rep(i, 20)sum += (n % (int)pow(10, i + 1)) / (pow(10, i));
	return sum;
}
int x;
signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin >> x;
	for (int i = 1; i <= sqrt(x); i++) {
		if (x % i == 0) {
			for (int j = 0; j <= 200; j++) {
				if (x == pow(j, 5) - pow(j - i, 5)) {
					cout << j << " " << j - i << endl;
					break;
				}
			}
		}
	}
	ggr
}


Measured memory_bytes: 4124
#include <cstdio>
#include <vector>
#include <algorithm>
#define repeat(i,n) for (int i = 0; (i) < int(n); ++(i))
using ll = long long;
using namespace std;
template <class T> inline void setmin(T & a, T const & b) { a = min(a, b); }
constexpr ll inf = ll(1e18)+9;
ll solve(vector<ll> const & a, ll initial) {
    int n = a.size();
    ll cnt = llabs(initial);
    ll acc = a[0] + initial;
    repeat (i,n-1) {
        ll nacc = acc + a[i+1];
        if (acc > 0 and nacc >= 0) {
            cnt += nacc+1;
            nacc = -1;
        }
        if (acc < 0 and nacc <= 0) {
            cnt += -nacc+1;
            nacc = +1;
        }
        acc = nacc;
    }
    return cnt;
}
int main() {
    int n; scanf("%d", &n);
    vector<ll> a(n); repeat (i,n) scanf("%lld", &a[i]);
    ll result = inf;
    if (a[0] != 0) setmin(result, solve(a, 0));
    if (a[0] >= 0) setmin(result, solve(a, -a[0]-1));
    if (a[0] <= 0) setmin(result, solve(a, -a[0]+1));
    printf("%lld\n", result);
    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
// kurikazu
#include<vector>
#include<queue>
#include<set>
#include<algorithm>
// #include<unordered_set>
using namespace std;
typedef pair<int, int> pii;
int main(){
  int n, m;
  std::cin >> n >> m;
  vector<vector<pii> > g(n);
  set<pii> s;
  for (int i = 0; i < m; i++) {
    int a, b, c;
    std::cin >> a >> b >> c;
    a--, b--;
    g[a].push_back(pii(b, c));
    g[b].push_back(pii(a, c));
  }
  
  for (int i = 0; i < n; ++i) sort(g[i].begin(), g[i].end());
  priority_queue<pii, vector<pii>, greater<pii> > que;
 
  for (int i = 0; i < n; i++) {
    vector<int> cost(n, 1e9);
    vector<int> parent(n, -1);
    que.push(pii(0, i));
    while(not que.empty()){
      int v = que.top().second;
      int c = que.top().first;
      que.pop();
      for (int i = 0; i < g[v].size(); i++) {
        int to = g[v][i].first;
        if(cost[to] > c + g[v][i].second){
          cost[to] = c + g[v][i].second;
          que.push(pii(cost[to], to));
          parent[to] = v;
        }
      }
    }
    for (int j = 0; j < n; j++) {
      if(i == j)continue;
      s.insert(pii(j, parent[j]));
      s.insert(pii(parent[j], j));
    }
  }
  std::cout << m - s.size()/2 << std::endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(i, n) for(int i=0; i<=n; i++)
#define repr(i, n) for(int i=n; i>0; i--)
#define REPR(i, n) for(int i=n; i>=0; i--)
const ll INF = 1e18;
const int INT_INF = 1e9;
const ll MOD = 1e9+7;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;

int N, D;

int main() {
    cin >> N >> D;
    int range = 2 * D + 1;
    int ans = N / range;
    if (N % range != 0) ans++;
    cout << ans << endl;
}


Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <climits>
#include <iomanip>
#include <stack>
#include <bitset>

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define ROF(i, j, k) for(int i = (int)(j); i >= (int)(k); --i)
#define FORLL(i, n, m) for(long long i = n; i < (long long)(m); i++)
#define SORT(v, n) sort(v, v+n)
#define REVERSE(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;
const ll MOD=1000000007LL;
typedef pair<int, int> P;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }

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

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

  int n, m, a, b, x;
  string s;
  cin >> s;
  bool f = false;
  REP(i, s.size()-1){
    if(s[i+1] == s[i]) f = true;
  }
  
  if(f) cout << "Bad" << endl;
  else cout << "Good" << endl;
  
  return 0;
}


Measured memory_bytes: 256
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")
#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 ll long long
#define pb push_back
#define mem(a,x) memset(a,x,sizeof(a))
#define nl "\n"
#define fout(x) fixed<<setprecision(x)
#define one(x) __builtin_popcountll(x)
#define F first
#define S second
#define or_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// find_by_order(), order_of_key()

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << fout(10)<<x;}
void __print(double x) {cerr << fout(10)<<x;}
void __print(long double x) {cerr << fout(10)<<x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

const int mod=1e9+7;
const double eps=1e-9;
const double PI=acos(-1.0);

ll qpow(ll n,ll k){ll ans=1;assert(k>=0);n%=mod;while(k>0){if(k&1)ans=(ans*n)%mod;n=(n*n)%mod;k>>=1;}return ans%mod;}


// ****************************************************

int arr[200010];

int main()
{
    int n, p;
    cin>>n>>p;
    ll pre=0, post=0, ans=0;
    for(int i=0, j=n, k=1; i<=n; i++, j--, k++){
        pre+=i;
        post+=j;
        if(k>=p){
            ans+=(post-pre+1);
            ans%=mod;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3636
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<stack>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

int N,M,s[99][2],c[99][2],x,y;
int f(int p,int q)
{
	return(abs(s[p][0]-c[q][0])+abs(s[p][1]-c[q][1]));
}

int main()
{
	scanf("%d%d",&N,&M);
	for(int i=0;i<N;i++)scanf("%d%d",&s[i][0],&s[i][1]);
	for(int i=0;i<M;i++)scanf("%d%d",&c[i][0],&c[i][1]);
	for(int i=0;i<N;i++)
	{
		x=0;
		for(int j=0;j<M;j++)
		{
			if(f(i,x)>f(i,j))
			{
				x=j;
			}
		}
		printf("%d\n",x+1);
	}
	return 0;
}


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

/*
 //C
 int main(void) {
 int n, k, i, cou=0, tmp;
 int a,b,c,d,e,f;
 scanf(" %d %d %d %d %d %d", &a,&b,&c,&d,&e,&f);
 for(i=0; i < n; i++){

 }

 }
 */

//B
int main(void) {
  int n, k, i, cou=0, tmp;
  scanf(" %d %d", &n, &k);

  if(n * k % 2 == 0) printf("Even");
  else printf("Odd");
  return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;

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

  ll ans = 0;
  for (ll i = 1; i <= k; ++i) {
    for (ll j = i+1; j <= k; ++j) {
      if (i % 2 == 0 && j % 2 != 0) ans++;
      else if (i % 2 != 0 && j % 2 == 0) ans++;
    }
  }

  cout << ans;

  return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        int n = sc.nextInt();

        int sum = 0;
        int max = 0;
        for (int i = 0; i < n; i++) {
            int price = sc.nextInt();
            sum += price;
            max = Math.max(max, price);
        }
        System.out.println(sum - (max/2));
    }
}

Measured memory_bytes: 21588
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            var A = cin.ReadInt;
            var B = cin.ReadInt;
            var ans = 6 - A - B;
            Console.WriteLine(ans);
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); }}
        public int ReadInt { get { return int.Parse(Read); }}
        public long ReadLong { get { return long.Parse(Read); }}
        public double ReadDouble { get { return double.Parse(Read); }}
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret;}
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret;}
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret;}
    }
}


Measured memory_bytes: 11220
#include<bits/stdc++.h>
using namespace std;
/////////////////// TYPES & MACROS ///////////////////////////////
#define INFLL 0x3fffffffffffffffLL
#define INF 0x3fffffff
#define mp make_pair
#define eb emplace_back
#define pb push_back
#define all(x) x.begin(),x.end()
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD=1e9+7;
/////////////////// DEBUG MODE ///////////////////////////////////
#define D(x) cerr<<"\nDEBUG: "<<#x<<" is: "<<x<<'\n'
#define error(args...) {string _s=#args; replace(all(_s),',',' ');\
stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args);}
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}
/////////////////// GLOBAL VARIABLES /////////////////////////////
vector<vector<int>> adj; vector<bool> vis; vector<int> color;
bool pos=true;
#define red 1
#define blue 2
/////////////////// FUNCTIONS ////////////////////////////////////
template<class T>
T maxx(T a, T b) {return a>b?a:b;}
template<typename T, typename... Args>
T maxx(T a, T b, Args... args){return maxx(a>b?a:b, args...);}
ll mexp(ll x, ll n, ll m){
  ll res=1;  while(n){if(n&1) res=(res*x)%m;n>>=1; x=((x%m)*(x%m))%m;}
  return res;
}
double pow(double a, int n) {
  if(n == 0) return 1;if(n == 1) return a;
  double t = pow(a, n/2);return t * t * pow(a, n%2);
}
void DFS(ll u){
	vis[u]=true;
	for(auto v: adj[u]){
		if(vis[v]){
			if(color[v]==color[u]) pos=false;
		}
		else{
			if(color[u]==red) color[v]=blue; else color[v]=red;
			DFS(v);
		}
	}
}
/////////////////// MAIN STARTS //////////////////////////////////
int main(){
  ios::sync_with_stdio(0);  cin.tie(0);   cout<<fixed; cerr<<fixed;
  cout<<setprecision(3); cerr<<setprecision(3);
  #ifdef DEBUG
  freopen("ip.txt","r",stdin); //freopen("op.txt","w",stdout);
  clock_t tStart = clock();
  #endif

	ll a,b,c,d; cin>>a>>b>>c>>d;
	if(a+b>c+d) cout<<"Left\n";
	else if(a+b==c+d) cout<<"Balanced\n";
	else cout<<"Right\n";

	#ifdef DEBUG
	cerr<<"\nExecution time: "<<(((double)clock() - tStart)/CLOCKS_PER_SEC)*1000<<"ms.\n";
	#endif
  return 0;
}


Measured memory_bytes: 256