akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
#include <set>
#include <math.h>
#include <queue>
#define rep(i,n) for (int i = 0; i < (n); ++i)
typedef long long ll;
using namespace std;

int main() {
    ll x, k, d;
    cin >> x >> k >> d;
    if(x>0) {
        ll y=x/d;
        if(y>k) {
            cout << x-k*d << endl;
            return 0;
        }
        x-=y*d;
        if((k-y)%2==1) x-=d; 
    }
    else {
        ll y=abs(x)/d;
        if(y>k) {
            cout << abs(x+k*d) << endl;
            return 0;
        }
        x+=y*d;
        if((k-y)%2==1) x+=d; 
    }
    cout << abs(x) << endl;
}

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

using namespace std;
using ll =long long;
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
#define leftunique(a) {sort((a).begin(),(a).end());(a).erase(unique((a).begin(),(a).end()),(a).end());}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
static const ll INF = 1LL << 60;
//Write From this Line

int main()
{
	// 差の最大公約数
	int n, x;
	cin >> n >> x;
	vector<ll> a(n+1);
	rep(i,n) cin >> a[i];
	a[n] = x;
	sort(a.begin(),a.end());
	vector<ll> div(n);
	rep(i,n){
		div[i] = a[i+1] - a[i];
	}
	// divの最大公約数を取る
	ll G = div[0];
	rep(i,n){
		G = __gcd(G,div[i]);
	}
	cout << G << endl;

}


Measured memory_bytes: 1792
def partition(A, p, r):
    x = A[r]
    i = p - 1
    for j in range(p, r):
        if A[j] <= x:
            i += 1
            A[i], A[j] = A[j], A[i]

    A[i + 1], A[r] = A[r], A[i + 1]
    return i + 1


n = int(input())
A = list(map(int, input().split()))
q = partition(A, 0, n - 1)

print(*A[:q], f"[{A[q]}]", *A[q + 1:])



Measured memory_bytes: 16396
//#define __USE_MINGW_ANSI_STDIO 0
#include <iostream>
#include <bits/stdc++.h>
using namespace std;

#define debug(x) cout<<#x<<" :: "<<x<<endl;
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<endl;

#define boost ios::sync_with_stdio(0); cin.tie(0)

#define fi first
#define se second

typedef long long ll;
typedef double ld;
typedef pair<int, int> pii;

const int N = 1e6 + 5;

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

int A[N], B[N];
vector<int> adj[N];
vector<pii> ord;

int par[N];
ll summ[N], DP[N];

int find(int i) {
	if(par[i] != i) par[i] = find(par[i]);
	return par[i];
} 

void Union(int a, int b) {
	a = find(a), b = find(b);
	if(a == b) return;
	par[b] = a;
}

set<int> S;
int done[N];

int main() {

	boost;
	int n, m; cin>>n>>m;
	for(int i=1; i<=n; i++) {
		cin>>A[i]>>B[i];
		ord.push_back(pii(max(A[i]-B[i], 0), i));
		par[i] = i;
	}
	for(int i=1; i<=m; i++) {
		int a, b; cin>>a>>b;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
	sort(ord.begin(), ord.end());

	int v;
	for(auto vv : ord) {
		v = vv.se;
		done[v] = 1;

		S.clear();
		for(auto it : adj[v]) if(done[it]) S.insert(find(it));

		summ[v] = B[v];
		for(auto it : S) summ[v] += summ[it];

		DP[v] = summ[v] + vv.fi;
		for(auto it : S) {
			DP[v] = min(DP[v], summ[v]-summ[it] + max(ll(vv.fi), DP[it]));
			Union(v, it);
		}
	}

	cout<<DP[v]<<"\n";
	return 0;
}

Measured memory_bytes: 45172
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
	return scanner
}
func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	cnt := 0
	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
		cnt = 12
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}
	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)
	solve(scanner, writer)
	for i := 0; i < cnt; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
	writer.Flush()
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	a := getNextInt64(scanner)
	b := getNextString(scanner)
	bb := strings.Split(b, ".")
	i, _ := strconv.ParseInt(bb[0], 10, 64)
	ans := a * i
	if len(bb) == 2 {
		ans += a * strtoi(bb[1]) / 100
	}

	fmt.Fprintln(writer, ans)
}

func strtoi(s string) int64 {
	a := int64(10)
	ans := int64(0)
	for i := 0; i < len(s); i++ {
		ans += a * int64(s[i]-'0')
		a /= 10
	}
	return ans
}


Measured memory_bytes: 1772
N = int(input())
D = list(map(int,input().split()))
CD = {}
for i in range(N):
    if D[i] not in CD:
        CD[D[i]] = 0
    CD[D[i]] += 1
M = int(input())
T = list(map(int,input().split()))
CT = {}
for i in range(M):
    if T[i] not in CT:
        CT[T[i]] = 0
    CT[T[i]] += 1
flag = 0
for t in CT:
    if t not in CD:
        flag = 1
        break
    if CT[t]>CD[t]:
        flag = 1
        break
if flag==1:
    print("NO")
else:
    print("YES")

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

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

    vector<int>a(n);
    rep(i,n) cin >> a[i];

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

    cout << a[n/2] - a[n/2-1] << endl;

    return 0;
}

Measured memory_bytes: 3768
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication15
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                var hw = Console.ReadLine().Split().Select(int.Parse).ToArray();
                int h = hw[0];
                int w = hw[1];
                if (h == 0 && w == 0)
                    break;
                for (int a = 0; a < h; ++a)
                {
                    for (int b = 0; b < w; ++b)
                    {
                        Console.Write("#");
                    }
                    Console.WriteLine();
                }
                Console.WriteLine();
                
            }
        }
    }
}

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

int main()
{

	int v,e;
	cin >> v >> e;

	const int infinity=65536*32766;
	vector<vector<int>> dp(v,vector<int>(v));
	for (int i=0;i<v;++i)
	{
		for (int j=0;j<v;++j)
		{
			if (i==j)
			{
				dp[i][j]=0;
			}
			else
			{
				dp[i][j]=infinity;
			}
		}
	}

	for (int i=0;i<e;++i)
	{
		int s,t,d;
		cin >> s >> t >> d;
		dp[s][t]=d;
	}

	for (int k=0;k<v;++k)
	{
		for (int i=0;i<v;++i)
		{
			for (int j=0;j<v;++j)
			{
				if ((dp[i][k]==infinity)||(dp[k][j]==infinity))
				{
					continue;
				}
				dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j]);
			}
		}
	}

	// check negative cycle
	for (int i=0;i<v;++i)
	{
		if (dp[i][i]<0)
		{
			cout << "NEGATIVE CYCLE" << endl;
			return 0;
		}
	}

	for (int i=0;i<v;++i)
	{
		for (int j=0;j<v;++j)
		{
			if (j>0)
			{
				cout << " ";
			}
			if (dp[i][j]!=infinity)
			{
				cout << dp[i][j];
			}
			else
			{
				cout << "INF";
			}
		}
		cout << endl;
	}
}




Measured memory_bytes: 3192
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    int n;
    cin >> n;
    vector<pair<int, int>> edge(n - 1);
    for (auto &i : edge) {
        int u, v;
        cin >> u >> v;
        if (u > v) swap(u, v);
        i = {u - 1, v - 1};
    }
    
    ll V = 0;   
    for (int i = 0; i < n; i++)
        V += (ll)(i + 1) * (n - i);
    ll E = 0; 
    for (auto e : edge) {
        int u = e.first, v = e.second;
        E += (ll)(u + 1) * (n - v);
    }
    cout << V - E;
}

Measured memory_bytes: 4784
import sys
from collections import defaultdict


def input():
    return sys.stdin.readline().strip()


sys.setrecursionlimit(20000000)


def main():
    H, W, D = map(int, input().split())
    A = [list(map(int, input().split())) for _ in range(H)]
    M = defaultdict(list)
    for h in range(H):
        for w in range(W):
            M[A[h][w]] = [h, w]
    P = defaultdict(list)
    for d in range(1, D + 1):
        a = d
        while a <= H * W - D:
            p = abs(M[a][0] - M[a + D][0]) + abs(M[a][1] - M[a + D][1])
            if P[d]:
                P[d].append(P[d][-1] + p)
            else:
                P[d] = [0, p]
            a += D
    # print(P)
    Q = int(input())
    for i in range(Q):
        L, R = map(int, input().split())
        d = L % D
        l = L // D
        r = R // D
        if d == 0:
            d = D
            if len(P[d]) > 0:
                print(P[d][r - 1] - P[d][l - 1])
            else:
                print(0)
        else:
            if len(P[d])>0:
                print(P[d][r] - P[d][l])
            else:
                print(0)


if __name__ == "__main__":
    main()


Measured memory_bytes: 34112
#include <iostream>
using namespace std;
int main(){
  int D;
  cin >> D;
  if(D==25) cout << "Christmas" << endl;
  else if(D==24) cout << "Christmas Eve" << endl;
  else if(D==23) cout << "Christmas Eve Eve" << endl;
  else cout << "Christmas Eve Eve Eve" << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
    int i,j,k,x=0,l,n=5,a[6];
        scanf("%d %d %d %d %d",&a[0],&a[1],&a[2],&a[3],&a[4]);
    for(j=0;j<5;j++){
        for(k=0;k<5;k++){
            if(a[j]>a[k]){
                x=a[j];
                a[j]=a[k];
                a[k]=x;
            }
        }
    }
    printf("%d %d %d %d %d\n",a[0],a[1],a[2],a[3],a[4]);
    return 0;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>                                                                          
using namespace std;
int main()
{
  int N,M;
  cin >> N >> M;
  vector<int> a(N),b(N),c(M),d(M);
  for(int i=0; i<N; i++){
    cin >> a.at(i) >> b.at(i);
  }
  for(int i=0; i<M; i++){
    cin >> c.at(i) >> d.at(i);
  }
  vector<int> point(N);
  for(int i=0; i<N; i++){
    int min=abs(a.at(i)-c.at(0))+abs(b.at(i)-d.at(0));
    point.at(i)=1;
    for(int j=1; j<M; j++){
      int dx=abs(a.at(i)-c.at(j))+abs(b.at(i)-d.at(j));
      if(min>dx){
        min=dx;
        point.at(i)=j+1;
      }
    }
  }
  for(int i=0; i<N; i++){
    cout << point.at(i) << endl;
  }
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
 
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define replrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) replrev(i,0,n)
#define repi(itr,ds) for(auto itr = ds.begin(); itr != ds.end(); ++itr)
#define mp make_pair
#define INF 1000000000
#define MOD 1000000007
#define PI 3.1415926536
typedef long long ll;
typedef pair<int, int> P;
 
int main() {
	int N, Ma, Mb;
	cin >> N >> Ma >> Mb;
	vector<int> c(N), d(N);
	rep(i, N) {
		int a, b;
		cin >> a >> b >> c[i];
		d[i] = Ma*b - Mb*a;
	}
	vector<int> plus(4001, INF), minus(4001, INF);
	plus[0] = 0;
	minus[0] = 0;
	int ans = INF;
	rep(i, N) {
		if (d[i] > 0) {
			reprev(j, 4001 - d[i]) {
				plus[j + d[i]] = min(plus[j + d[i]], plus[j] + c[i]);
			}
		}
		else if (d[i] < 0) {
			reprev(j, 4001 + d[i]) {
				minus[j - d[i]] = min(minus[j - d[i]], minus[j] + c[i]);
			}
		}
		else {
			ans = min(ans, c[i]);
		}
	}
	rep(i, 4001) {
		if (plus[i] != 0 && minus[i] != 0)
			ans = min(ans, plus[i] + minus[i]);
	}
 
	if (ans == INF) {
		cout << -1 << endl;
	}
	else {
		cout << ans << endl;
	}
 
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
 
const int N = 2e5 + 5, MOD = 1e9 + 7;

int A[N];

int mult(int a, int b){
	ll ret = (a * 1LL * b) % MOD;
	return ret;
}

int main(){
	int n, cntr = 0, ans = 1;
	cin>>n;

	A[0] = -1;
	for(int i = 1; i <= n; i++)	cin>>A[i];

	for(int i = 1; i <= n; i++){
		A[i] = min(A[i - 1] + 2, A[i]);
		if(A[i] - A[i - 1] == 1){
			A[i]--;
			ans = mult(ans, cntr + 1);
		}
		else{
			cntr++;
		}
	}

	while(cntr){
		ans = mult(ans, cntr);
		cntr--;
	}

	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
//#include <cassert>
//#include <array>
//#include <queue>
//#include <stack>
//#include <vector>
//#include <map>
//#include <set>
#include <unordered_map>
//#include <unordered_set>

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REP1(i, n) for (int i = 1; i <= (int)(n); i++)

#define MAX 1000000007

using namespace std;

int combination(int n, int r) {
	if (r * 2 > n) r = n - r;
	int dividend = 1;
	int divisor = 1;
	long long ans = 1;
	for (unsigned int i = 1; i <= r; ++i) {
		ans *= (n - i + 1) % MAX;
		//divisor i
		while (ans % i != 0) {
			ans += MAX;
		}
		ans /= i;
		ans %= MAX;
	}
	return ans;
}

int N, M;
unordered_map<int, int> um;

void solve() {
	cin >> N >> M;

	int factor_max = floor(sqrt(M));
	for (int factor = 2; factor <= factor_max; factor++)
	{
		if (M%factor == 0) {
			um[factor]++;
			M /= factor;
			if (M == 1) {
				break;
			}
			else {
				factor--;
			}
		}
	}
	if (M != 1) {
		um[M]++;
	}

	unsigned long long ans=1;
	for (const auto &e : um) {
		ans *= combination(N - 1 + e.second,e.second);
		ans %= MAX;
	}

	cout << ans << endl;

	return;
}

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


Measured memory_bytes: 256
/// Bismillahir Rahmanir Rahim
/* Mohammad Morsalin
   Dept of ICE, NSTU
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ll long long
#define pb push_back
#define mp make_pair
#define endl "\n"
#define int long long
#define f0(n) for(int i=0;i<n;i++)
#define ms(x) memset(x,0,sizeof(x))
#define ms2d(x,m,n) memset(x, 0, sizeof(x[0][0]) * m * n)
#define uniq(vec) vec.resize(distance(vec.begin(),unique(vec.begin(),vec.end())))
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define pi pair<int,int>
#define tc(t) int t;cin>>t;while(t--)
#define bits(n) __builtin_popcount(n)
#define maxpq priority_queue<int>
#define minpq priority_queue<int, vector<int>, greater<int> >
#define ins insert
#define ALL(v) v.begin(),v.end()
#define highest(x) numeric_limits<x>::max()
#define lowest(x) numeric_limits<x>::min()
#define Inf INFINITY
#define minv(v) *min_element(v.begin(),v.end())
#define maxv(v) *max_element(v.begin(),v.end())
#define fi first
#define se second
#define PI acos(-1)
#define sz(a) (int)a.size();
#define IOS ios::sync_with_stdio(false);
using namespace std;
int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a);}
typedef tree<pair<int, int>,null_type,less<pair<int, int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};
const long long MOD = 1000000007;
double sq(double x) {return x*x;}
template<typename T>inline T Bigmod(T base, T power, T MOD){
    T ret=1;
    while(power)
    {
        if(power & 1)ret=(ret*base)%MOD;
        base=(base*base)%MOD;
        power>>=1;
    }
    return ret;
}

bool sortinrev(const pair<int,int> &a,
               const pair<int,int> &b)
{
       return (a.first > b.first);
}
signed main()
{
    IOS
    int arr[5];
    int ans;
    for(int i=0;i<5;i++){cin>>arr[i];if(arr[i]==0)ans=i+1;}
    cout << ans << endl;
    return 0;
}
///Alhamdulillah


Measured memory_bytes: 3660
#include<bits/stdc++.h>
using namespace std;
string z;
long long int a,M,A,R,C,H;
int main(){
    cin>>a;
    while(cin>>z){
        switch(z[0]){
            case 'M':M++;break;
            case 'A':A++;break;
            case 'R':R++;break;
            case 'C':C++;break;
            case 'H':H++;break;
        }
    }
    //a=(M*A*R)+(M*A*C)+(M*A*H)+(M*R*C)+(M*R*H)+(M*C*H)+(A*R*C)+(A*R*H)+(A*C*H)+(R*C*H);
    //式変形
    int x=C+H,y=A+R,v=A*R,t=C*H;
    cout<<v*(M+x)+t*(M+y)+(M*x*y)<<endl;
}


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

int a[6], st[2], temp;
string s;

int main(){
    for (int i=0; i<6; i++) cin >> a[i];
    cin >> s;
    st[0] = 1; st[1] = 2;
    for (int i=0; i<s.length(); i++) {
        if (s[i] == 'E') {
            if (st[1] == 1) {
                if (st[0] == 5) st[0] = 4;
                else if (st[0] == 4) st[0] = 2;
                else if (st[0] == 2) st[0] = 3;
                else st[0] = 5;
            }
            if (st[1] == 2) {
                if (st[0] == 1) st[0] = 4;
                else if (st[0] == 4) st[0] = 6;
                else if (st[0] == 6) st[0] = 3;
                else st[0] = 1;
            }
            if (st[1] == 3) {
                if (st[0] == 1) st[0] = 2;
                else if (st[0] == 2) st[0] = 6;
                else if (st[0] == 6) st[0] = 5;
                else st[0] = 1;
            }
            if (st[1] == 4) {
                if (st[0] == 1) st[0] = 5;
                else if (st[0] == 5) st[0] = 6;
                else if (st[0] == 6) st[0] = 2;
                else st[0] = 1;
            }
            if (st[1] == 5) {
                if (st[0] == 1) st[0] = 3;
                else if (st[0] == 3) st[0] = 6;
                else if (st[0] == 6) st[0] = 4;
                else st[0] = 1;
            }
            if (st[1] == 6) {
                if (st[0] == 2) st[0] = 4;
                else if (st[0] == 4) st[0] = 5;
                else if (st[0] == 5) st[0] = 3;
                else st[0] = 2;
            }
        }
        if (s[i] == 'N') {
            temp = st[0];
            st[0] = st[1];
            st[1] = 7 - temp;
        }
        if (s[i] == 'W') {
            if (st[1] == 6) {
                if (st[0] == 5) st[0] = 4;
                else if (st[0] == 4) st[0] = 2;
                else if (st[0] == 2) st[0] = 3;
                else st[0] = 5;
            }
            if (st[1] == 5) {
                if (st[0] == 1) st[0] = 4;
                else if (st[0] == 4) st[0] = 6;
                else if (st[0] == 6) st[0] = 3;
                else st[0] = 1;
            }
            if (st[1] == 4) {
                if (st[0] == 1) st[0] = 2;
                else if (st[0] == 2) st[0] = 6;
                else if (st[0] == 6) st[0] = 5;
                else st[0] = 1;
            }
            if (st[1] == 3) {
                if (st[0] == 1) st[0] = 5;
                else if (st[0] == 5) st[0] = 6;
                else if (st[0] == 6) st[0] = 2;
                else st[0] = 1;
            }
            if (st[1] == 2) {
                if (st[0] == 1) st[0] = 3;
                else if (st[0] == 3) st[0] = 6;
                else if (st[0] == 6) st[0] = 4;
                else st[0] = 1;
            }
            if (st[1] == 1) {
                if (st[0] == 2) st[0] = 4;
                else if (st[0] == 4) st[0] = 5;
                else if (st[0] == 5) st[0] = 3;
                else st[0] = 2;
            }
        }
        if (s[i] == 'S') {
            temp = st[1];
            st[1] = st[0];
            st[0] = 7 - temp;
        }
    }
    cout << a[st[0]-1] << endl;
}


Measured memory_bytes: 3176
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(x) x.begin(), x.end()
#define mod 1000000007
typedef long long ll;

vector<vector<pair<int, int>>> vec;
vector<int> edge;
vector<bool> vis;

void dfs(int node, int color){
  vis[node] = true;
  int c = 1;
  for(auto p : vec[node]){
    if(c == color) c++;
    if(vis[p.first]) continue;
    edge[p.second] = c;
    dfs(p.first, c);
    c++;
  }
} 

int main(){
  int n;
  cin >> n;
  rep(i, n) vec.push_back(vector<pair<int, int>>());
  rep(i, n-1) edge.push_back(0);
  rep(i, n) vis.push_back(false);
  rep(i, n-1){
    int a, b;
    cin >> a >> b;
    a--; b--;
    vec[a].push_back(make_pair(b, i));
    vec[b].push_back(make_pair(a, i));
  }
  int k = 0;
  rep(i, n){
    k = max(k, (int)vec[i].size());
  }
  dfs(0, 1000000000);
  cout << k << endl;
  rep(i, n-1) cout << edge[i] << endl;
  return 0;
}

Measured memory_bytes: 9740
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#include <list>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream& operator<<(ostream& os, pair<T, S> a) {
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (auto x : v) os << x << ' ';
    return os;
}
void debug() {
    cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
    cerr << a;
    if (sizeof...(b)) cerr << ", ";
    debug(b...);
}
int main(){
    int h, n;
    cin >> h >> n;
    vector<int>dp(h + 1, INT_MAX / 2);
    dp[0] = 0;
    for(int i = 0; i < n; i++){
        int a, b;
        cin >> a >> b;
        for(int j = 0; j < h; j++){
            dp[min(j + a, h)] = min(dp[min(j + a, h)], dp[j] + b);
        }
    }
    cout << dp[h] << endl;
}


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

int main() {
  
  vector<int> t(3);
  rep(i,3) cin >> t[i];
  
  sort(t.begin(), t.end());
  
  int sum = 3;
  
  if(t[0] == t[1] && t[0] == t[2]) sum -= 2;
  else if(t[0] == t[1] || t[1] == t[2]) sum -= 1;
  
  cout << sum << endl;
  
}


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

long long calc(long long A){
    // 10^12　2進数だと40桁くらい
    long long ans = 0;
    if(A <= 0) return 0;
    // 4のときは、見るべき整数は0, 1, 2, 3, 4なので、
    // 5つの整数から見なければいけない.1たす
    A++;
    //i桁目の偶奇を調べる
    for (int i=0;i<50;i++)
    {
        // 0桁目・・周期2
        // 1桁め・・周期4
        // 2桁め・・周期8
        // なので、周期＝loopは1LLをbitshiftしたらもとまる
        long long loop = (1LL << (i + 1));
        // loopする回数*1が出てくる回数
        // 0からAで考えるので、Aまで並べたら、loopはA/loopぶん通過数
        //その中で、1周期でloop/2個1はでる(書いたらわかる)
        // 周期/2ぶん1は残るため
        // ちょうどループ回数に収まるところまで
        long long cnt = (A / loop) * (loop / 2);
        // 端数を考える。ただし、0の連続があるので、
        // -(loop/2)・・・0の個数ぶん引く
        cnt += max(0LL, (A % loop) - (loop / 2));
        if (cnt % 2 == 1){
            ans += 1LL << i;
        }
    }
    return ans;
}

int main() {
    long long A, B;cin>>A>>B;
    long long ans = calc(B) ^ calc(A-1);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define R register
#define ll long long
#define mp make_pair
#define pii pair<int, int>
using namespace std;
const int N = 210000;

int n, a[N], b[N], s[N << 1], t[N], nxt[N], abl[N], ans[N];

template <class T>
inline void read(T &x) {
    x = 0;
    char ch = getchar(), w = 0;
    while (!isdigit(ch)) w = ch == '-', ch = getchar();
    while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
    x = w ? -x : x;
    return;
}

int main() {
    read(n);
    for (R int i = 1; i <= n; ++i) read(a[i]);
    for (R int i = 1; i <= n; ++i) read(b[i]);
    for (R int i = 29; ~i; --i) {
        for (R int j = 1; j <= n; ++j)
            s[j] = s[j + n] = a[j] & (1 << i), t[j] = b[j] & (1 << i);
        for (R int j = 1, k = 0; j < n; ++j) {
            while (k && t[j + 1] != t[k + 1]) k = nxt[k];
            if (t[j + 1] == t[k + 1]) ++k;
            nxt[j + 1] = k;
        }
        for (R int j = 0; j < n; ++j) abl[j] = -1;
        for (R int j = 0, k = 0; j < (n << 1) - 1; ++j) {
            while (k && s[j + 1] != t[k + 1]) k = nxt[k];
            if (s[j + 1] == t[k + 1]) ++k;
            if (k == n && j >= n - 1) abl[j + 1 - n] = 0, k = nxt[k];
        }
        for (R int j = 1; j <= n; ++j) s[j] = s[j + n] = ~a[j] & (1 << i);
        for (R int j = 0, k = 0; j < (n << 1) - 1; ++j) {
            while (k && s[j + 1] != t[k + 1]) k = nxt[k];
            if (s[j + 1] == t[k + 1]) ++k;
            if (k == n && j >= n - 1) abl[j + 1 - n] = 1, k = nxt[k];
        }
        for (R int j = 0; j < n; ++j) {
            if (abl[j] == -1 || ans[j] == -1) ans[j] = -1;
            else ans[j] ^= abl[j] << i;
        }
    }
    for (R int j = 0; j < n; ++j)
        if (ans[j] != -1) printf("%d %d\n", j, ans[j]);
    return 0;
}

Measured memory_bytes: 9856
import java.util.Scanner;
public class Main{
    public static void main(String[]args){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int a,flag;
        flag=1;
        for(int i=0;i<n;i++){
            a=scan.nextInt();
            if(a%2==0){
                if(a%3==0||a%5==0){
                    flag=1;
                }
                else flag = 0;
                if(flag==0) break;
            }
        }
        if(flag==0) System.out.println("DENIED");
        else System.out.println("APPROVED");
    }
}

Measured memory_bytes: 23764
#include <stdio.h>

int table[7][6] = { {0},
					{1, 2, 3, 5, 4, 6},// 1
					{2, 6, 3, 1, 4, 5},// 2
					{3, 6, 5, 1, 2, 4},// 3
					{4, 6, 2, 1, 5, 3},// 4
					{5, 6, 4, 1, 3, 2},// 5
					{6, 5, 3, 2, 4, 1} // 6
};

int match_dice(int *dice1, int *dice);
int match_face(int *face1, int *face2);

int main(void)
{
	int dice[100][7];
	int n;
	int i, j;
	int count;
	
	scanf("%d", &n);

	for (i = 0; i < n; i++){
		for (j = 1; j <= 6; j++){
			scanf("%d", &dice[i][j]);
		}
	}
	
	count = 0;
	for (i = 0; i < n - 1; i++){
		for (j = i + 1; j < n; j++){
//printf("<%d, %d=%d>", i, j, match_dice(dice[i], dice[j]));
			count += match_dice(dice[i], dice[j]);
		}
	}
	if (count == 0){
		printf("Yes\n");
	}
	else {
		printf("No\n");
	}
	
	return (0);
}
	
int match_dice(int *dice1, int *dice2)
{	
	int face1[5], face2[5];
	int i, j;

	for (i = 0; i < 5; i++){
		face1[i] = dice1[table[1][i + 1]];
	}

	for (i = 1; i <= 6; i++){
		if (dice1[1] == dice2[i]){
			for (j = 0; j < 5; j++){
				face2[j] = dice2[table[i][j + 1]];
			}
			if (match_face(face1, face2) == 1){
				return (1);
			}
		}
	}
	
	return (0);
}

int match_face(int *face1, int *face2)
{
	int i, j, k;
	
	if (face1[4] != face2[4]){
		return (0);
	}
	for (i = 0; i < 4; i++){
		if (face1[0] == face2[i]){
			for (j = 0; j < 4; j++){
				if (face1[j] != face2[(i + j) % 4]){
					break;
				}
			}
			if (j == 4){
				return (1);
			}
		}
	}
	
	return (0);
}



Measured memory_bytes: 2100
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;


int main(){
    string N;
    cin >> N;
    int size = N.size();
    int ans = 0;
    for (int i=size-1; i>=0; i--) {
        char s = N[i];
        if (s<'5' || (s=='5'&&i==0) ||(s=='5'&&i!=0&&N[i-1]<'5')) {
            ans += (s-'0');
        }
        else {
            ans += ('9'- s+1);
            int j = i;
            bool flag = false;
            while (!flag) {
                if (N[j-1]<'9') {
                    N[j-1]++;
                    flag = true;
                }
                else {
                    N[j-1] = '0';
                    j--;
                }
                if (j==0) {
                    ans ++;
                    break;
                }
            }
        }
    }
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 1540
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cstring>
#include <utility>
#include <numeric>

using namespace std;

const long long INF = (1LL << 60);

int N;
int a[16][16];
vector<long long> maxScore;
vector<long long> plusScore;

int main(){

    cin >> N;
    for(int i = 0; i < N; i++){
        for(int j = 0; j < N; j++){
            cin >> a[i][j];
        }
    }

    int cnt2 = (int)pow(2.0, N);
    maxScore.assign(cnt2, -INF);
    maxScore[0] = 0;
    plusScore.resize(cnt2);
    
    for(int i = 0; i < cnt2; i++){
        long long score = 0;
        for(int j = 0; j < N; j++){
            for(int k = j + 1; k < N; k++){
                if(i & (1 << j)){
                    if(i & (1 << k)){
                        score += a[j][k];
                    }
                }
            }
        }

        plusScore[i] = score;
    }

    for(int i = 1; i < cnt2; i++){
        vector<int> used;
        for(int j = 0; j < N; j++){
            if(i & (1 << j)){
                used.push_back(j);
            }
        }

        int com = (int)pow(2.0, (int)used.size());
        for(int j = 1; j < com; j++){
            int temp = 0;
            for(int k = 0; k < (int)used.size(); k++){
                if(j & (1 << k)){
                    temp += (1 << used[k]);
                }
            }

            int beforeState = i - temp;
            maxScore[i] = max(maxScore[i], maxScore[beforeState] + plusScore[temp]);
        }
    }

    cout << maxScore[cnt2 - 1] << endl;

    return 0;
}

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

// const int N=2e3+10;


const int inf=2e9;
using ll=long long;
const int N=3000+10;
const int mod=998244353;

int dp[N][N];
// int ans[N][N];
int a,b,c,d;
ll memo(int x,int y)
{
	if(x<0 or y<0) return 0;
	if(dp[x][y]!=-1) return dp[x][y];
	if(x<a and y>=b) return dp[x][y]=0;
	if(y<b and x>=a) return dp[x][y]=0;
	ll ans=0;
	if(x>a)ans+=(1ll*memo(x-1,y)*y)%mod;ans%=mod;
	if(y>b)ans+=(1ll*memo(x,y-1)*x)%mod;ans%=mod;
	if(x>a and y>b)ans+=(-(1ll*memo(x-1,y-1)*((x-1)*(y-1)))%mod)%mod;ans%=mod;ans+=mod;ans%=mod;
	dp[x][y]=ans;
	return ans;


}

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    cin.exceptions(cin.failbit);
    memset(dp,-1,sizeof(dp));

    cin>>a>>b>>c>>d;
    for(int i=0;i<=a;i++)
    	for(int j=0;j<=b;j++)
    		dp[i][j]=1;    

    cout<<memo(c,d)<<endl;


}

Measured memory_bytes: 39360
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;

//RollingHash<ll,mod,1777771>
template<typename T,T MOD,T B>
struct RollingHash{
  vector<T> hash,p;
  RollingHash(){}
  RollingHash(const string &s){
    ll n=s.size();
    hash.assign(n+1,0);
    p.assign(n+1,1);
    for(ll i=0;i<n;i++){
      hash[i+1]=(hash[i]*B+s[i])%MOD;
      p[i+1]=p[i]*B%MOD;
    }
  }
  //S[l, r)
  T find(ll l,ll r){
    T res=hash[r]+MOD-hash[l]*p[r-l]%MOD;
    return res>=MOD?res-MOD:res;
  }
};

int main() {
  ll n;
  string s,t;
  cin >> n >> s >> t;
  RollingHash<ll,mod,1777771> rs(s);
  RollingHash<ll,mod,1777771> rt(t);
  for(ll i=0;i<n;i++) {
    if(rs.find(i,n)==rt.find(0,n-i)) {
      cout << n+i << endl;
      return 0;
    }
  }
  cout << 2*n << endl;
}

Measured memory_bytes: 256
#include<cmath>
#include<cstdio>
using namespace std;
typedef long long LL;
LL a[10000+10],b[10000+10];
int n;
LL cnt=0;
int main(){
	scanf("%d",&n);
	for (int f1=1;f1<=n;f1++)scanf("%lld",&a[f1]);
	for (int f1=1;f1<=n;f1++)scanf("%lld",&b[f1]);
	for (int f1=1; f1<=n;f1++){
		if (a[f1]<b[f1]){
			cnt+=(b[f1]-a[f1]+1)/2;
			a[f1]+=(b[f1]-a[f1]+1)/2*2;
		}
		cnt-=(a[f1]-b[f1]);
		//printf("%lld\n",cnt);
	}
	if (cnt>=0) printf("Yes\n");
	else printf("No\n");
	
}
//

Measured memory_bytes: 256
mod io{
    use std::io::*;
    pub fn read<T: ::std::str::FromStr>()->T{
        let stdin=stdin();
        let ret=stdin.lock().bytes().map(|c|c.unwrap()as char)
        .skip_while(|c|c.is_whitespace())
        .take_while(|c|!c.is_whitespace())
        .collect::<String>().parse().ok().unwrap();
        ret
    }
}
use io::read;
fn main(){
    let a=read::<i32>();
    let b=read::<String>();
    let c=read::<i32>();
    println!("{}",if b=="+"{a+c}else{a-c})
}

Measured memory_bytes: 4352
import java.util.Scanner;
public class Main {
    Scanner sc = new Scanner(System.in);

    public static void main(String[] arg){
        Main m = new Main();
        m.run();
    }

    void run(){
        for(;;){
            int n = sc.nextInt();
            if(n == 0){
                break;
            }
            int a[] = new int[n];

            int sum = 0;
            for(int i = 0 ; i< n ;i++){
                a[i] = sc.nextInt();
                sum += a[i];
            }

            int res = 0;
            for(int i = 0; i < n ; i++){
                if(a[i] * n <= sum){
                    res ++;
                }
            }
            System.out.println(res);
        }

    }
}



Measured memory_bytes: 59200
let five_variables pair = match pair with
  (x1, x2, x3, x4, x5) ->
    if x1 = 0 then 1
    else if x2 = 0 then 2
    else if x3 = 0 then 3
    else if x4 = 0 then 4
    else 5

let n_pair = Scanf.sscanf (read_line ()) "%d %d %d %d %d" (fun a b c d e -> (a,b,c,d,e))
let ans = five_variables n_pair
let () = print_endline (string_of_int ans)

Measured memory_bytes: 3856
#!/usr/bin/env python3
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right

def main():
    N = int(input())
    S = input()
    B = []
    W = []
    i = 0
    fin = None
    while i < N:
        if S[i] == '#':
            if i == N-1:
                B.append(1)
                fin = True
            else:
                tmp = 1
                while S[i+1] == '#':
                    tmp += 1
                    i += 1
                    if i == N-1:
                        fin = True
                        break
                B.append(tmp)
        else:
            if i == N-1:
                W.append(1)
                fin = False
            else:
                tmp = 1
                while S[i+1] == '.':
                    tmp += 1
                    i += 1
                    if i == N-1:
                        fin = False
                        break
                W.append(tmp)
        i += 1

    ans = sum(B)
    L = len(B)+len(W)
    B = B[::-1]
    W = W[::-1]
    now = ans
    if fin:
        for i in range(L):
            if i % 2 == 0:
                now -= B[i//2]
            else:
                now += W[i//2]
            ans = min(ans,now)
    else:
        for i in range(L):
            if i % 2 == 1:
                now -= B[i//2]
            else:
                now += W[i//2]
            ans = min(ans,now)
    print(ans)



    

if __name__ == "__main__":
    main()


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

const int n_MAX = 100,m_MAX = 100,l_MAX=100;
int a[n_MAX][m_MAX], b[m_MAX][l_MAX];
long int c[n_MAX][l_MAX];

void input(int n,int m,int l){
	for (int i1 = 0; i1 < n; i1++){
		for (int i2 = 0; i2 < m; i2++){
			cin >> a[i1][i2];
		}
	}
	for (int i1 = 0; i1 < m; i1++){
		for (int i2 = 0; i2 < l; i2++){
			cin >> b[i1][i2];
		}
	}
}

void matrix(int n,int m,int l){
	for (int i1 = 0; i1 < n; i1++){
		for (int i3 = 0;; i3++){
			c[i1][i3] = 0;
			for (int i2 = 0; i2 < m; i2++){
				c[i1][i3] += a[i1][i2] * b[i2][i3];
			}
			cout << c[i1][i3];
			if (i3 + 1 == l)break;
			cout << ' ';
		}
		cout << endl;
	}
}

int main(){

	int n, m, l;
	cin >> n >> m >> l;

	input(n, m, l);

	matrix(n, m, l);

	return 0;
}


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

char s[100005];

int main()
{
	scanf("%s",s);
	int n = strlen(s);
	for(int i = 1; i < n; i++)
	{
		if(s[i] == s[i-1])
		{
			printf("%d %d\n",i,i+1);
			return 0;
		}
	}
	
	for(int i = 2; i < n; i++)
	{
		if(s[i] == s[i-2])
		{
			printf("%d %d\n",i-1,i+1);
			return 0;
		}
	}
	puts("-1 -1");

	return 0;
}


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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i, n) for(int i = (int)(n); i >= 0; i--)
#define repm(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define repmr(i, m, n) for(int i = (int)(n); i >= (int)(m); i--)
#define inf 2e9

using namespace std;
typedef long long int lli;
typedef long long ll;

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

    int cnt = 0;
    rep( i, k+1 ){
        rep( j, k+1 ){
            if( s-(i+j) <= k && s-(i+j) >= 0 ){
                cnt++;
            }
        }
    }

    cout << cnt << endl;
}

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




int main() {
  
 int N, hikakumoto, hikakusaki, count0, count1;
 N = 0;
 hikakumoto = 0;
 hikakusaki = 0;
 count0 = 0;
 count1 = 0;
  
 bool flag = false;
 
  
 cin >> N;
  
 vector<int> array0(N);
  
 for(int soezi0 = 0; soezi0 < N; soezi0++) {
   
   cin >> array0.at(soezi0);
   
 }
  
 for(int soezi1 = 0; soezi1 < N - 1; soezi1++) {
   
   hikakumoto = array0.at(soezi1);
   hikakusaki = array0.at(soezi1 + 1);
   
   if(hikakumoto > hikakusaki) {
     
     count0++;
     
   }
   
 }
 
  
 for(int soezi2 = 0; soezi2 < N; soezi2++) {
   
   if(soezi2 + 1 != array0.at(soezi2)) {
     
     count1++;
     
   }
   
 }
  
 if(count0 == 0 || count1 == 2) {
   
   cout << "YES" << endl;
   
 } else {
   
   cout << "NO" << endl;
   
 }
 //cout << count0 << count1 << endl;
  
 
}

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

public class Main{
	public static void main(String[] args)throws IOException{
		InputStreamReader isr = new InputStreamReader(System.in);
		BufferedReader reader = new BufferedReader(isr);
		String string;
		int n;
		boolean[] primes = new boolean[10001];
		
		for(int i = 2; i < 10001; i++){
			primes[i] = true;
			for(int j = 2; j <= Math.sqrt(i); j++){
				if(i % j == 0){
					primes[i] = false;
					break;
				}
			}
		}
		while((string = reader.readLine()) != null){
			n = Integer.parseInt(string);
			
			int count = 0;
			for(int i = 1; i <= n; i++){
				if(primes[i] && primes[n - i + 1]){
					count++;
				}
			}
			System.out.println(count);
		}
		reader.close();
	}
}

Measured memory_bytes: 25556
#include <bits/stdc++.h>
#include <stdio.h>
#include <math.h>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
#define rep(i, n) for(int i=0;i<n;i++)

int main(){
  int n1,n2;
  cin >>n1 >>n2;
  int diff=n2-n1;
  ll sum=0;
  rep(i,diff){
    sum+=i;
  }
  cout << sum-n1 << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;

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

    int a,b,c,temp=0;
    cin>>a>>b>>c;
    temp=a;
    a=b;
    b=temp;
    temp=a;
    a=c;
    c=temp;
    cout<<a<<" "<<b<<" "<<c;

}


Measured memory_bytes: 256
#coding: utf-8

S = input()
K = int(input())

# find not one
pos = None

for i in range(len(S)):
    if S[i] != "1":
        pos = i
        break

#print("pos=%d" % pos)

if pos == None:
    print("1")
else:
    if K <= pos:
        print("1")
    else:
        print(S[i])



Measured memory_bytes: 9072
import java.util.*;
 
public class Main {
    public static void main(String[] args) {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        
        String strf = s.substring(0,2);
        String strb = s.substring(2); 
        
        int sf = Integer.parseInt(strf);
        int sb = Integer.parseInt(strb);
        
        String ans = "NA";
        
        if(1 <= sf && sf <= 12 && 1 <= sb && sb <= 12){
            ans = "AMBIGUOUS";
        }else if(1 <= sf && sf <= 12){
            ans = "MMYY";
        }else if(1 <= sb && sb <= 12){
            ans = "YYMM";    
        }
        System.out.println(ans);  
       
    }
}

Measured memory_bytes: 23636
import java.util.*;

/**
 * Created by mizuk on 2017/07/26.
 */
public class Main {
    private static final int N = 50;
    private static long K;
    private static long a[] = new long[N];

    public static void input(){
        Scanner scan = new Scanner(System.in);
        K = scan.nextLong();
    }

    public static void main(String args[]){
        //入力
        input();

        for (int i=0;i<N;i++){
            a[i] = i;
        }

        long quotient = K / N;
        long remainder = K % N;

        for (int i=0;i<N;i++){
            a[i] += quotient;
        }

        for (int i=0;i<remainder;i++){
            a[i] = a[i] + N - ((int)remainder - 1);   //ひかれる数が一回少ない
        }
        for (int i=(int)remainder;i<N;i++){
            a[i] -= remainder;
        }

        System.out.println(N);
        for (int i=0;i<N;i++){
            System.out.print(a[i] + " ");
        }

    }
}

Measured memory_bytes: 23636
#include <stdio.h>
#include <string.h>

int main(int argc, char const *argv[]) {
	int n, num;
	int equalnum;
	int i;
	char str[201];

	scanf("%d",&n);
	for(num = 0; num < n; num++) {
		scanf("%s", str);
		if(strlen(str) < 2 || str[0] != '>') {
			puts("NA");
			continue;
		}
		// 一文字目が'のとき
		if(str[1]=='\'') {
			equalnum = 0;
			i = 2;
            // str[i]が=の間繰り返す
			while(str[i]=='=') {
				i++;
				equalnum++;
			}
			// =の次が#でない、あるいは=が0以下のとき
			if(str[i] != '#' || equalnum <= 0)
				puts("NA");
			else {
				i++;
				// str[i]が=の間繰り返す
				while(str[i]=='=') {
					i++;
					// equalnumをデクリメント, 0にならなかったらNA
					equalnum--;
				}
				if(equalnum != 0)
                	puts("NA");
				// =の次が~でない、あるいは文字の終わりでないとき
				else if(str[i] != '~' || str[i+1] != '\0')
				puts("NA");
				else
                	puts("A");
			}
		// 一文字目が^のとき
		} else if(str[1] == '^') {
			i = 2;
			// 文字配列がQ=のセットのとき
			while(str[i] == 'Q' && str[i+1] == '=') {
            	i = i + 2;
			}
			// whileループが一度も実行されないとき
			if(i == 2)
				puts("NA");
			// Q=の次が~~でないとき、あるいは文字の終わりでないとき
			else if(str[i] != '~' || str[i+1] != '~' || str[i+2] != '\0')
				puts("NA");
			else
				puts("B");
		} else 
			puts("NA");
	}
	return 0;
}

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

    typedef long long ll;
    typedef long double ld;
    ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
    ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
    #define endl '\n'
    #define max3(a,b,c) max(a,max(b,c))
    #define FOR(i,a,n,j) for(int i=a;i<n;i+=j)

    const int INF = 1e9+9;




    int main()
    {
        int n;
        cin>>n;
        int dp[n+5];
        vector<int> v(n);
        FOR(i,0,n,1){
            cin>>v[i];
            dp[i] = INF;
        }
        v.push_back(INF);
        dp[0] = 0;
        FOR(i,0,n,1){
            dp[i+1]= min(dp[i+1], dp[i]+abs(v[i]-v[i+1]));
            dp[i+2]= min(dp[i+2], dp[i]+abs(v[i]-v[i+2]));
        }

        cout<< dp[n-1] <<endl;

        return 0;
    }
        // gotcha;


Measured memory_bytes: 1536
/*
      author  : nishi5451
      created : 15.08.2020 13:34:37
*/

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
typedef long long ll;


int main(){
    ll a,b,k;
    cin >> a >> b >> k;
    if(a>=k){
        cout << a-k << " " << b << endl; 
    }
    else{
        cout << 0 << " " << max((ll)0,b-(k-a)) << endl;
    }
    return 0;
}

Measured memory_bytes: 3608
import java.util.*;

public class Main{
	
	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			int h = sc.nextInt();
			int w = sc.nextInt();
			int n = sc.nextInt();
			char [][] data = new char[h][w];
			for(int i = 0; i < h; i++){
				data[i] = sc.next().toCharArray();
			}
			boolean flg = false;
			for(int i = 0; i < h; i++){
				for(int j = 0; j < w-1; j++){
					if(data[i][j] == data[i][j + 1])continue;
					
					char c = data[i][j];
					data[i][j] = data[i][j +1];
					data[i][j + 1] = c;
					
					boolean res = check(data,w,h,n);
					if(res){
						flg = true;
					}
					
					c = data[i][j];
					data[i][j] = data[i][j +1];
					data[i][j + 1] = c;
				}
			}
			System.out.println(flg ? "YES" : "NO");
		}
	}
	
	private boolean check(char[][] data, int w, int h, int n) {
		char [][] work = new char[h][w];
		for(int i = 0; i < h; i++){
			for(int j = 0; j < w; j++){
				work[i][j] = data[i][j];
			}
		}
		boolean update = true;
		while(update){
			update = false;
			boolean [][] iserase = new boolean[h][w];
			
			for(int i = 0; i < w; i++){
				int ind = h-1;
				for(int j = h-1; j >= 0; j--){
					if(work[j][i] != '.'){
						work[ind][i] = work[j][i];
						ind--;
					}
				}
				for(; ind >= 0; ind--){
					work[ind][i] = '.';
				}
			}
			
			for(int i = 0; i < h; i++){
				for(int j = 0; j < w; j++){
					if(work[i][j] == '.') continue;
					int count = 0;
					for(int k = j; k < w; k++){
						if(work[i][j] == work[i][k]){
							count++;
						}
						else{
							break;
						}
					}
					if(count >= n){
						for(int k = j; k < w; k++){
							if(work[i][j] == work[i][k]){
								iserase[i][k] = true;
							}
							else{
								break;
							}
						}
					}
					
					count = 0;
					for(int k = i; k < h; k++){
						if(work[i][j] == work[k][j]){
							count++;
						}
						else{
							break;
						}
					}
					if(count >= n){
						for(int k = i; k < h; k++){
							if(work[i][j] == work[k][j]){
								iserase[k][j] = true;
							}
							else{
								break;
							}
						}
					}
				}
			}
			
			for(int i = 0; i < h; i++){
				for(int j = 0; j < w; j++){
					if(iserase[i][j]){
						update = true;
						work[i][j] = '.';
					}
				}
			}
			
			
		}
		for(int i = 0; i < h; i++){
			for(int j = 0; j < w; j++){
				if(work[i][j] != '.') return false;
			}
		}
		
		return true;
	}

	private void debug(Object... o) {
		System.out.println("debug = " + Arrays.deepToString(o));
	}

	public static void main(String[] args) {
		new Main().doit();
	}
}

Measured memory_bytes: 27072