akhauriyash/Code-Regression huggingface dataset:
N, M = map(int, input().split())
AB = [[int(x) for x in input().split()] for _ in range(M)]
root = list(range(N+1))
con = [1] * (N+1)

def get_root(x):
    rx = root[x]
    if rx == x:
        return x
    z =  get_root(rx)
    root[x] = z
    return z

def merge(a,b):
  ra = get_root(a)
  rb = get_root(b)
  if ra == rb:
    return 0
  ca = con[ra]
  cb = con[rb]
  if ca > cb:
    root[rb] = ra
    con[ra] += cb
  else:
    root[ra] = rb
    con[rb] += ca
  return ca * cb

def main():
    answer = []
    x = N*(N-1)//2
    for a,b in AB[::-1]:
        answer.append(x)
        x -= merge(a,b)
    for a in answer[::-1]:
        print(a)

if __name__ == '__main__':
    main()

Measured memory_bytes: 28744
#include "bits/stdc++.h"

#define REP(i, n ,N) for(ll i = (n); i < (N); i++)
#define RREP(i, n ,N) for(ll i = (N-1); i >= (n); i--)
#define p(s) cout<<(s)<<endl
#define p2(a, b) cout<<(a)<<" "<<(b)<<endl
using namespace std;
typedef long long ll;
ll mod = 1e9+7;
ll inf = 1e18;

ll N;
string s, t, ans;
int main(){
	cin >> N;
	cin >> s >> t;
	ans = "";
	REP(i,0,N){
		ans += s[i];
		ans += t[i];
	}
	p(ans);
	return 0;
}

Measured memory_bytes: 256
q=[]

k=int(input())

for i in range(1,10):
    q.append(i)

#print(q)
#Perform operations k times

if(k<10):
    print(q[k-1])
    exit()

ops=0
t=[]
while(ops<k):

    x = q.pop(0)
    t.append(x)
    if(x%10!=0):
        ops+=1
        q.append(10*x + x%10 -1)
    q.append(10*x+ x%10)
    ops+=1

    if(x%10!=9):
        q.append(10*x + x%10 + 1)
        ops+=1
final = t+q
#print(final)
print(final[k-1])


Measured memory_bytes: 7972
h,w,k = map(int,input().split())
c=[]
ans = 0
for i in range(h):
    c.append(input())

for maskR in range(1<<h):
    for maskC in range(1<<w):
        black = 0
        for i in range(h):
            for j in range(w):
                if maskR >> i & 1 == 1 and maskC >> j & 1== 1 and c[i][j]=='#':
                    black += 1


        if black ==k:
            ans += 1

print(ans)

Measured memory_bytes: 9232
using System;
using System.Collections.Generic;
using System.Linq;

class Program {
  static void Main(string[] args) {
    Solve();
  }

  static void Solve() {
    string[] inp = Console.ReadLine().Split(' ');
    int H = int.Parse(inp[0]);
    int W = int.Parse(inp[1]);
    if (H + W == 0) return;

    for(int y = 0; y < H; y++) {
      for(int x = 0; x < W; x++) {
        Console.Write((x + y) % 2 == 0 ? '#' : '.');
      }
      Console.WriteLine();
    }
    Console.WriteLine();

    Solve();
  }
}

Measured memory_bytes: 5296
import java.io.*;
import java.util.*;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner inputs = new Scanner(System.in);
		int val = inputs.nextInt();
		int hap = 0;
		while(val>0) {
			val-=500;
			hap+=1000;
		}
		if(val!=0) {
			val+=500;
			hap-=1000;
		}
		while(val>0) {
			val-=5;
			hap+=5;
		}
		if(val<0) {
			val+=5;
			hap-=5;
		}
		System.out.println(hap);
	}

}


Measured memory_bytes: 21844
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;

//double dp[100][100][100][100];
int dist[3][500][500];
pair <int, int> ba_pair[100000];
string c[500];
int move_x[4] = {-1, 1, 0, 0};
int move_y[4] = {0, 0, -1, 1};
int main(){
    string S;
    cin >> S;
    
    //int white_num = 0;
    int black_num = 0;
    long long ans = 0;
    for(int i = 0; i < S.size(); i++){
        if(S[i] == 'W'){
            ans += black_num;
        }
        if(S[i] == 'B'){
            black_num ++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<cmath>
using namespace std;
#define size 21
typedef long long int ll;

ll dp[2][size];

int main() {
	int n;
	cin >> n;
	
	for(int i = 0; i < size; i++) {
		dp[0][i] = dp[1][i] = 0;
	}
	
	int fst;
	cin >> fst;
	dp[0][fst] = 1;
	for(int i = 1; i < n - 1; i++) {
		int num;
		cin >> num;
		for(int j = 0; j < size; j++) {
			if(j+num < size) dp[i%2][j+num] += dp[(i-1)%2][j];
			if(j-num >= 0) dp[i%2][j-num] += dp[(i-1)%2][j];
		}
		for(int j = 0; j < size; j++) {
			dp[(i-1)%2][j] = 0;
		}
	}
	int res;
	cin >> res;
	cout << dp[n%2][res] << endl;
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define INF 100000007
#define rep(i, N) for(ll i = 0; i < N; i++)
#define rep2(i, j, k) for(ll i = j; i < k; i++)
#define chmax(x, y) x = max(x, y)
#define print(x) cout << x << "\n"
#define printv(vec) rep(i, vec.size()) cout << vec[i] << " "
#define ALL(v) v.begin(), v.end()
#define SUM(v) accumulate(ALL(v), 0)
#define MAX(v) *max_element(ALL(v))
#define MIN(v) *min_element(ALL(v))
#define SORT(v) sort(ALL(v))
#define REV(v) reverse(ALL(v))
typedef long long ll;
using namespace std;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vs = vector<string>;
using vvs = vector<vector<string>>;

void solve(){
	
	ll N, K;
	ll ans = 0;
	cin >> N >> K;
	vvl nxt(60, vl(N));
	rep(i, N) cin >> nxt[0][i];
	rep(i, N) nxt[0][i]--;
	rep2(i, 1, 60) rep(j, N) nxt[i][j] = nxt[i - 1][nxt[i - 1][j]];
	rep(i, 60) if(K & (1LL << i)) ans = nxt[i][ans];
	print(ans + 1);
	
}	

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


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

int main(void){
    string s,t;
    cin>>s>>t;
    int flag=0;
    for(int i=s.size()-t.size();i>=0;i--){
        for(int j=0;j<t.size();j++){
            if(s[i+j]!='?' && s[i+j]!=t[j]) break;
            if(j==t.size()-1){
                s.replace(i,t.size(),t);
                flag = 1;
            }
        }
        if(flag==1) break;
    }
    replace(s.begin(),s.end(),'?','a');
    cout<<(flag==1?s:"UNRESTORABLE")<<endl;
}

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

using namespace std;

int main()
{
    int n;
    while( cin >> n ) {
        int const nn = n % 39;
        cout << "3C" << setw(2) << setfill('0') << ( nn == 0 ? 39 : nn ) << endl;
    }
}

Measured memory_bytes: 1168
package main

import (
	"bufio"
	"fmt"

	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func Scanner() string {
	sc.Scan()
	return sc.Text()
}

func intScanner() int {
	n, _ := strconv.Atoi(Scanner())
	return n
}

func floatScanner() float64 {
	n, _ := strconv.ParseFloat(Scanner(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}

var mod int

func main() {
	mod = 1000000007
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	n := intScanner()
	m := intScanner()
	ns := make([][]int, n)
	for i := 0; i < m; i++ {
		a := intScanner() - 1
		b := intScanner() - 1
		ns[a] = append(ns[a], b)
		ns[b] = append(ns[b], a)
	}
	q := make([]int, 1, n)
	searched := make([]int, n)
	for i := 1; i < n; i++ {
		searched[i] = -1
	}
	for len(q) != 0 {
		idx := q[0]
		q = q[1:]
		for _, v := range ns[idx] {
			if searched[v] == -1 {
				searched[v] = idx
				q = append(q, v)
			}
		}
	}
	fmt.Println("Yes")
	for i := 1; i < n; i++ {
		fmt.Println(searched[i] + 1)
	}
}


Measured memory_bytes: 15496
#include <iostream>
#include <cstdio>
#define N 100005
using namespace std;
typedef long long ll;

ll n, k, ans, M=1e9+7, c[N];

ll pow(ll p, ll q) {
	ll re = 1;
	while(q) {
		if(q&1) re = re * p % M;
		p = p * p % M;
		q >>= 1;
	}
	return re;
}

int main() {
	ll i, j;
	cin >> n >> k;
	for(i=k; i; i--) {
		c[i] = pow(k/i, n);
		for(j=2*i; j<=k; j+=i) c[i] = (c[i] - c[j] + M) % M;
		ans = (ans + c[i] * i) % M;
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 4364
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	k, _ := strconv.Atoi(nextLine())
	s := nextLine()
	length := len(s)
	if length <= k {
		fmt.Println(s)
	} else {
		fmt.Printf("%v...\n", s[0:k])
	}
}


Measured memory_bytes: 1776
#include<cstdio>
#include<iostream>
using namespace std;
const long long mod=998244353;
long long c[4005][4005];
void init(long long n)
{
	c[0][0]=1;
	for(long long i=1;i<=n;i++)
	{
		c[i][0]=1;
		for(long long j=1;j<=i;j++)
		{
			c[i][j]=(c[i-1][j]+c[i-1][j-1])%mod;
		}
	 } 
}
long long ksm(long long u,long long p)
{
	long long ans=1;
	while(p)
	{
		if(p&1) ans=(ans*u)%mod;
		u=(u*u)%mod;
		p>>=1;
	}
	return ans;
}
long long f(long long x,long long y,long long z)
{
	long long ans=0;
	for(long long p=0;p<=x;p++)
	{
		if(p+y-1<=p+y-1&&p+y-1>=0) 
			ans=(ans+c[x][p]*ksm(2,p)%mod*c[z+y-1][y+p-1])%mod;
	}
	return ans;
}
int main()
{
	long long n,m,cnt,ans=0;
	scanf("%lld%lld",&m,&n);
	init(n+m+1);
	for(long long i=2;i<=2*m;i++)
	{
		cnt=ans=0;
		for(long long j=1;j<=m;j++)
		{
			if(i-j>=1&&i-j<=m)
			{
				cnt++;
			}
		}
	//	cout<<cnt<<"  ff"<<endl;
		if(i%2==1)
		{
			ans=f(cnt>>1,m-cnt,n);
		}
		else
		{
			ans=f((cnt-1)>>1,m-cnt,n-1);
//			cout<<" dd"<<ans<<endl;
			ans+=f((cnt-1)>>1,m-cnt,n);
		}
		printf("%lld\n",ans%mod);
	}
	
	
	return 0;
} 

Measured memory_bytes: 123776
while True:
	a,b,c = input().split()
	a = int(a)
	c = int(c)
	if b == "?":
		break
	if b == "+":
		print(a + c)
	if b == "-":
		print(a - c)
	if b == "*":
		print(a * c)
	if b == "/":
		print(a // c)


Measured memory_bytes: 5596
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, N) for(int i=0; i<N; i++)
typedef long long ll;
#define dump(x) cerr<<#x<<"="<<x<<endl
using P = pair<int, int>;

int main() {
    int n; cin >> n;
    int y = n/15;

    cout << 800 * n - 200 * y << endl;
    return 0;
}


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

using namespace std;

#define FOR(i,s,e) for(int i=(s);(i)<(int)(e);(i)++)
#define REP(i,e) FOR(i,0,e)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp make_pair
#define mt make_tuple
#define t0(t) get<0>((t))
#define t1(t) get<1>((t))
#define t2(t) get<2>((t))

typedef long long ll;

int main() {
  int x, a;
  fscanf(stdin, "%d%d ", &x, &a);
  puts(x<a ? "0" : "10");
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define pb push_back
#define eb emplace_back
template<class T>void chmax(T &a,T b){if(a<b)a=b;}
template<class T>void chmin(T &a,T b){if(a>b)a=b;}
constexpr int INF=1000000000000000000;
constexpr int mod=1000000007;
constexpr double eps=1e-8;
const double pi=acos(-1);
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int Random(int mi,int ma){
    random_device rnd;
    mt19937 mt(rnd());//32bit
    //[mi,ma]
    uniform_int_distribution<int>engine(mi,ma);
    return engine(mt);
}
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
int modpow(int a,int b){
    if(b==0)return 1;
    if(b%2)return modpow(a,b-1)*a%mod;
    int memo=modpow(a,b/2);
    return memo*memo%mod;
}
vector<int>kaijo,invkaijo;
void init_fact(int n){
    kaijo.resize(n+1);
    invkaijo.resize(n+1);
    kaijo[0]=1;
    for(int i=1;i<=n;i++){
        kaijo[i]=kaijo[i-1]*i;
        kaijo[i]%=mod;
    }
    rep(i,n+1)invkaijo[i]=modpow(kaijo[i],mod-2);
}
int comb(int a,int b){
    if(a<b)return 0;
    if(a<0||b<0)return 0;
    return kaijo[a]*invkaijo[a-b]%mod*invkaijo[b]%mod;
}
int inv(int x){
    x=modpow(x,mod-2);
    return x;
}
vector<int>G[100010];
int color[100010];
vector<int>H[100010];
void dfs(int x){
    for(int i:H[x]){
        if(color[i]==-1){
            color[i]=1-color[x];
            dfs(i);
        }
    }
}
void solve(){
    int n,m,d[100010],p[100010],a[200010],b[200010];
    map<P,int>mp;
    cin>>n>>m;
    rep(i,n){
        cin>>d[i];
        color[i]=-1;
    }
    rep(i,m){
        cin>>a[i]>>b[i];
        a[i]--,b[i]--;
        G[a[i]].pb(b[i]);
        G[b[i]].pb(a[i]);
    }
    rep(i,n){
        P mi={INF,-1};
        for(int j:G[i]){
            chmin(mi,P{d[j],j});
        }
        p[i]=mi.se;
        if(d[i]<mi.fi){
            puts("-1");
            return;
        }
    }
    rep(i,n){
        H[i].pb(p[i]);
        H[p[i]].pb(i);
        P c={i,p[i]};
        if(c.fi>c.se)swap(c.fi,c.se);
        mp[c]=d[i];
    }
    rep(i,n){
        if(color[i]==-1){
            color[i]=0;
            dfs(i);
        }
    }
    rep(i,n)cout<<(color[i]?'W':'B');
    cout<<endl;
    rep(i,m){
        P c={a[i],b[i]};
        if(c.fi>c.se)swap(c.fi,c.se);
        if(mp.find(c)!=mp.end())cout<<mp[c]<<endl;
        else cout<<1000000000<<endl;
    }
}
signed main(){
    cin.tie(0);ios::sync_with_stdio(false);
    //int t;cin>>t;while(t--)
    solve();
    return 0;
}

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

ll rec(int left, int right, vector<vector<ll> > &dp, vector<int> &R, vector<int> &C) {
    int N = dp.size();
    if (dp.at(left).at(right) != LLONG_MAX) {
        return dp.at(left).at(right);
    }
    if (left == right) {
        return dp.at(left).at(right) = 0;
    }
    ll res = LLONG_MAX;
    for (int i = left; i < right; ++i) {
        res = min(res, rec(left, i, dp, R, C) + rec(i + 1, right, dp, R, C) + 1LL * R.at(left) * C.at(i) * C.at(right));
    }
    return dp.at(left).at(right) = res;
}

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

    int N;
    cin >> N;
    vector<int> R(N), C(N);
    for (int i = 0; i < N; ++i) {
        cin >> R.at(i) >> C.at(i);
    }

    vector<vector<ll> > dp(N, vector<ll>(N, LLONG_MAX));

    cout << rec(0, N - 1, dp, R, C) << endl;

    return 0;
}


Measured memory_bytes: 3316
n = int(input())
S = [int(input()) for i in range(n)]

ans = sum(S)
sort_S = sorted(S)
if ans % 10 != 0:
    print(ans)
    exit()
else:
    for s in sort_S:
        if s % 10 != 0:
            ans -= s
            print(ans)
            exit()
print(0)

Measured memory_bytes: 9144
#include <bits/stdc++.h>
#include <stdarg.h>
#include <assert.h>
#include <ctype.h>
#include <boost/iostreams/filtering_stream.hpp>
#include <boost/iostreams/filter/gzip.hpp>
#include <boost/iostreams/device/file_descriptor.hpp>

using namespace std;
typedef long long int lli;
typedef vector<int> iv;
typedef vector<bool> bv;
typedef vector<string> sv;
typedef vector<long long int> llv;
typedef vector<double> dv;

#define sor_(vec) sort(vec.begin(),vec.end())
#define rev_(vec) reverse(vec.begin(),vec.end())
#define rep(i,n) for(int i=0;i<static_cast<int>(n);i++)
#define reps(i,n,s) for(int i=static_cast<int>(s);i<static_cast<int>(n);i++)
#define isposi(num) if(num>0)
const long long mod = 1000000007;

template<typename TypeInt>
std::string Itoa(const TypeInt v, int base)
{
    static const char table[] = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
    string ret;
    static numeric_limits<TypeInt> t;
    TypeInt n = v;
    if (t.is_signed) {
        if (v < 0) n *= -1;
    }

    while (n >= base) {
        ret += table[n%base];
        n /= base;
    }
    ret += table[n];
    if (t.is_signed) {
        if (v < 0 && base == 10) ret += '-';
    }
    std::reverse(ret.begin(), ret.end());

    return ret;
}

int upf(double num){
    if(num-(int)num>0)return (int)num+1;
    else return num;
}

void printm(char const *format,...){
    va_list arguments;
    va_start(arguments,format);
    unsigned index=0;
    while (format[index]!='\0') {
        if(format[index]=='%'){
            index++;
            if(format[index]=='d')printf("%d",va_arg(arguments, int));
            else if(format[index]=='c')printf("%c",va_arg(arguments, int));
            else if(format[index]=='x')printf("%x",va_arg(arguments,int));
            else if(format[index]=='o')printf("%o",va_arg(arguments,int));
            else if(format[index]=='f')printf("%f",va_arg(arguments, double));
            else if(format[index]=='s')printf("%s",va_arg(arguments, char const *));
            else if(format[index]=='p')printf("%p",va_arg(arguments,void*));
            else if(format[index]=='y')printf("Yes");
            else if(format[index]=='n')printf("No");
            else if(format[index]=='%')printf("%%");
            else assert(!"Unknown format with %.");
        }
        else printf("%c",format[index]);
        index++;
    }
    va_end(arguments);
    return;
}

struct Chara{
    int hp;
    int sp;
};
bool pairCompare(const pair<int,int>& firstElof, const pair<int,int>& secondElof)
{
    return firstElof.second > secondElof.second;
}

int main(void){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    string str;
    cin>>str;
    reverse(str.begin(),str.end());
    if(str[0]=='2'||str[0]=='4'||str[0]=='5'||str[0]=='7'||str[0]=='9')cout<<"hon";
    if(str[0]=='0'||str[0]=='1'||str[0]=='6'||str[0]=='8')cout<<"pon";
    if(str[0]=='3')cout<<"bon";
    return 0;
}


Measured memory_bytes: 3656
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split("\n");
	firstList = input[0].split(" ").map( str => parseInt(str, 10));
	personNum = firstList[0];
	menuNum = firstList[1];
	fistPersonFavList = input[1].split(" ").map(str => parseInt(str, 10));
	if(personNum === 1) {
		 console.log(fistPersonFavList.length - 1);
		 return;
	}
	result = 0;
	for (var i = 1; i <= fistPersonFavList[0]; i++) {
		target = fistPersonFavList[i];
		sameCount = 0;
		for (var j = 1; j <= personNum - 1; j++) {
			hasFav = input[j + 1].split(" ").map(str => parseInt(str, 10)).slice(1).indexOf(target) != -1;
			if(hasFav) {
              sameCount++;
            }
		}
		if(sameCount == personNum - 1) {
			result++;
		}
	}
	console.log(result);
}

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




Measured memory_bytes: 9548
#define _DEBUG 1

#include <bits/stdc++.h>
using namespace std;

using ll = long long;

#ifdef _DEBUG
#define dump(x) cerr << #x << "=" << x << endl
#define dump2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define check(s) cerr << s << endl
#else
#define dump(x)
#define dump2(x, y)
#define check(s)
#endif

#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define unique(v) v.erase(unique(v.begin(), v.end()), v.end());

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

void yes() { cout << "Yes" << endl; }
void no() { cout << "No" << endl; }
void yesOrNo(bool flg) {
  if (flg)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

void solve(std::string S) {
  string h = "hi";

  bool result;

  while (!S.empty()) {
    if (S.size() == 1) {
      result = false;
      break;
    }
    if (S.at(0) == 'h' && S.at(1) == 'i') {
      S.erase(0, 2);
      result = true;
      continue;
    } else {
      result = false;
      break;
    }
  }

  yesOrNo(result);

  return;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You
// use the default template now. You can remove this line by using your custom
// template)
int main() {
  std::string S;
  std::cin >> S;
  solve(S);
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
 
        int n = sc.nextInt();
        int[] a = new int[n];
        for(int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }

        int ans = 0;
        boolean flag = true;
        while(flag) {
            flag = false;
            for(int j = n - 1; j >= 1; j--) {
                if(a[j] < a[j - 1]) {
                    int tmp = a[j];
                    a[j] = a[j - 1];
                    a[j - 1] = tmp;
                    ans++;
                    flag = true;
                }
            }
        }

        printArray(a, n);
        System.out.println(ans);
    }

    private static void printArray(int[] a, int n) {
        StringBuilder sb = new StringBuilder();
        for(int i = 0; i < n; i++) {
            if(i != 0) sb.append(" ");
            sb.append(a[i]);
        }
        System.out.println(sb);
    }
}


Measured memory_bytes: 26264
#include <iostream>
#include <numeric>
#include <cmath>
#include <limits>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
ll Max(ll(a), ll(b), ll(c)) {
	return max(max(a, b), c);
}
ll Min(ll(a), ll(b), ll(c)) {
	return min(min(a, b), c);
}





int main() {

	ll N;
	cin >> N;

	while (N > 0) {
		N -= 1000;
	}

	cout << N *(-1) << endl;


}

Measured memory_bytes: 3532
import sys
input = sys.stdin.readline
enum = enumerate

def linput(ty=int, cvt=list):
	return cvt(map(ty,input().split()))

def vinput(rep=1, ty=int, cvt=list):
	return cvt(ty(input().rstrip()) for _ in "*"*rep)

def gcd(a: int, b: int):
	while b: a, b = b, a%b
	return a

def lcm(a: int, b: int):
	return a * b // gcd(a, b)

def main():
	N,C,K = linput()
	vA = vinput(N)
	vA.sort()
	#vA.reverse()
	
	res = 0
	i = 0   #..N
	cnt = 0 #..C
	x = 0   #(T-x)..K
	while i<len(vA):
		if not cnt:
			cnt += 1
			x = vA[i]+K
			i += 1
			res += 1
		elif cnt<C:
			if vA[i]<=x:
				cnt += 1
				i += 1
			else:
				cnt = 1
				x = vA[i]+K
				res += 1
				i += 1
		else:
			cnt = 1
			x = vA[i]+K
			res += 1
			i += 1
	
	#sT = "No Yes".split()
	#print(sT[res])
	print(res)

if __name__ == "__main__":
	main()


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

int main(){

  int k, a, b, c;
  int answer = 0;
  cin >> a >> b >> c >> k;

  if(k <= a) answer = k;
  else if(k <= a+b) answer = a;
  else answer = 2*a + b - k;

  cout << answer << endl;

  return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define ll int
int const MOD = 1e9 + 7;
#define fastIO                        \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL)
using namespace std;
ll sum;
ll cache[700][2001];
ll dp(int i, int s)
{
    if (s > sum)
        return 0;
    if (s == sum)
        return 1;
    ll &ans = cache[i][s];
    if (ans != -1)
        return ans;
    ans = 0;
    for (int j = 3; j <= sum-s; j++)
        ans += dp(i + 1, s + j), ans %= MOD;
    return ans % MOD;
}
int32_t main()
{
    fastIO;
    memset(cache, -1, sizeof(cache));
    cin >> sum;
    ll ans = 0;
    for (int i = 3; i <= sum; i++)
        ans += dp(0, i), ans %= MOD;
    cout << ans;

    return 0;
}

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

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

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

    int min = R[0];
    int profit = R[1]-R[0];

    for(int i=0; i<n-1; i++){
        if(min<R[i]) continue;
        else min=R[i];
        for(int j=i+1; j<n; j++){
            if(profit<R[j]-min){
                profit=R[j]-min;
            }
        }
    }

    cout << profit << endl;

    return 0;
}


Measured memory_bytes: 3876
#include<bits/stdc++.h>
using namespace std;
#define int long long 

int row[110],column[110];

int dp[110][110];

const int inf = 1LL << 60;

int dfs(int left, int right){ 
  
  if( dp[left][right] != inf ){ return dp[left][right];} // メモ化再帰
  
  int res = inf;
  for(int i = left; i < right; i++){ 
    res = min(res, dfs(left,i)+dfs(i+1,right)+row[left]*column[i]*column[right]);
  }
  
  return dp[left][right] = res;
}

signed main(void){
  
  int n; cin >> n;
  for(int i = 1; i <= n; i++){ 
    cin >> row[i] >> column[i];
  }
  
  for(int i = 0; i < 110; i++){ 
    for(int j = 0; j < 110; j++){ 
      dp[i][j] = inf;
    }
  }

  for(int i = 1; i <= n; i++){
    dp[i][i] = 0;
  }
  
  for(int i = 1; i < n; i++){ 
    // Mi*M(i+1);
    dp[i][i+1] = row[i]*column[i]*column[i+1];
  }
  
  cout << dfs(1,n) << endl;
  
  return 0;
}


Measured memory_bytes: 3208
//#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<cstdio>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<utility>
#include<algorithm>
#include<cstring>
#include<sstream>
#include <iomanip>

using namespace std;

typedef long long ll ;
typedef double db;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector< pair<int,int> > vii;
const double pi = 2*acos(0) ;

#define pf		  	printf
#define sf			  scanf
#define pb(a)         push_back(a)
#define mp			make_pair
#define fi			 first
#define se			 second
#define for0(i,n)        for(ll i=0;i<n;i++)
#define for1(i,n)        for(int i=1;i<=n;i++)
#define forab(i,a,b)       for(int i=a;i<=b;i++)
#define lcm(a, b)     ((a)*((b)/gcd(a,b)))
#define sq(a)		   (a)*(a)
#define nw				"\n"
#define abs(x)		fabs(x)
#define pcase(z,x)    cout<<"Case "<<z<<": "<<x<<"\n"
int main()
{
	ll n,p,t;
	cin>>n;
	map<ll,ll>m;
	for0(i,n){
		cin>>p;
		m[p]++;
		}
	ll x=0,y=0;
	for(auto it:m){
		if(it.se>=2){t=it.fi ; x = max(x,t); }
		}
	m[x] -= 2;
	for(auto it:m){
		if(it.se>=2){t=it.fi; y = max(y,t);}
		}
	ll ans = x*y;
	cout<<ans<<nw;
	
	return 0;
}

Measured memory_bytes: 6528
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <set>
#define lowbit(x) (x&(-x))
#define MAX(a,b) (a<b?b:a)
#define MIN(a,b) (a<b?a:b)
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
const int N = 1e5;
const int maxn = 3e5 + 5;
ll mod = 1e9 + 7;

int n;
int cnt[maxn][50];

int check(int l, int r)
{
	for (int j = 0; j < 30; j++)
	{
		if (cnt[r][j] - cnt[l-1][j] > 1) return 0;
	}
	return 1;
}

int main()
{
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)
	{
		int x;
		scanf("%d", &x);
		for (int j = 0; j < 30; j++)
		{
			cnt[i][j] = cnt[i - 1][j] + ((x >> j) & 1);
		}
	}

	ll ans = 0;
	for (int i = 1; i <= n; i++)
	{
		int l = i, r = n, mid;
		while (l < r)
		{
			mid = ((l + r) >> 1) + 1;
			if (check(i,mid)) l = mid;
			else r = mid - 1;
		}
		ans += r - i + 1;
	}
	printf("%lld", ans);
}

Measured memory_bytes: 41216
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <string>
#include <list>
#include <math.h>
#include <string.h>
using namespace std;

typedef pair<int, int> P;
#define INF (1LL<<60)
#define int long long
#define ll long long
#define mod 1000000007



signed main(){

	int N;
	vector<int> a;
	int max_abs=-1, idx;
	vector<P> ans;

	cin >> N;
	for (int i = 0; i < N; i++){
		int t;
		cin >> t;
		a.push_back(t);
		if (abs(t) > max_abs){
			max_abs = abs(t);
			idx = i;
		}
	}
	
	int sign = (a[idx] >= 0 ? 1 : -1);

	for (int i = 0; i < N; i++){
		a[i] += a[idx];
		ans.push_back(P(idx + 1, i + 1));
	}

	if (sign > 0)
		for (int i = 0; i < N - 1; i++){
			a[i+1] += a[i];
			ans.push_back(P(i + 1, i + 2));
		}
	else
		for (int i = N - 1; i >= 1; i--){
			a[i-1] += a[i];
			ans.push_back(P(i + 1, i));
		}
	
	cout << ans.size() << endl;
	for (auto i = ans.begin(); i != ans.end(); i++)
		cout << i->first << " " << i->second << endl;

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

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    // Your code here!
    int N,A;
    scanf("%d %d",&N,&A);
    while(N>=500){
        N = N - 500;
    }
    if(N<=A){
        printf("Yes");
    }
    else{
        printf("No");
    }
    
    return 0;
}

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

int main()
{
    string a, b, c;
    cin >> a >> b >> c;
    int aidx, bidx, cidx;
    aidx = bidx = cidx = 0;
    char curr = 'a';
    while(aidx <= a.size() && bidx <= b.size() && cidx <= c.size())
    {
        if (curr == 'a')
        {
            curr = a[aidx++];
        }
        else if (curr == 'b')
        {
            curr = b[bidx++];
        }
        else 
        {
            curr = c[cidx++];
        }
    }
 
    if (aidx > a.size()) cout << 'A' << '\n';
    else if (bidx > b.size()) cout << 'B' << '\n';
    else cout << 'C' << '\n';
 
 
    return 0;
}

Measured memory_bytes: 256
import sys

def ed(s1, s2):
    m, n = len(s1), len(s2)
    dp = [[0 for j in range(n + 1)] for i in range(m + 1)]
    
    for i in range(m + 1): dp[i][0] = i
    for j in range(n + 1): dp[0][j] = j
    
    for i in range(1, m + 1):
        for j in range(1, n + 1):
            if s1[i - 1] == s2[j - 1]:
                dp[i][j] = dp[i - 1][j - 1]
            else:
                dp[i][j] = min(dp[i - 1][j - 1], dp[i -1][j], dp[i][j - 1]) + 1
    return dp[m][n]
    
    
if __name__ == '__main__':
    s1 = sys.stdin.readline()
    s2 = sys.stdin.readline()
    
    sys.stdout.write(str(ed(s1, s2)))
    sys.stdout.write('\n')
    

Measured memory_bytes: 34592
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
const int inf=1e9;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
int main(){
	int n,m;
	while(cin>>n>>m,n){
		vvi in(n,vi(n));
		vvi pic(m,vi(m));
		rep(i,n)rep(j,n)cin>>in[i][j];
		rep(i,m)rep(j,m)cin>>pic[i][j];
		pii out(inf,inf);
		rep(e,4){
			rep(i,n-m+1)rep(j,n-m+1){
				pii t(inf,inf);
				rep(k,m)rep(l,m)
					if(pic[k][l]!=-1&&in[i+k][j+l]!=pic[k][l])goto en;
					else if(pic[k][l]!=-1)t=min(t,pii(i+k,j+l));
				out=min(out,t);
				goto end;
				en:;
			}
			end:;
			vvi tmp=pic;
			rep(i,m)rep(j,m)pic[i][j]=tmp[j][m-i-1];
		}
		if(out.first==inf)cout<<"NA"<<endl;
		else cout<<out.second+1<<" "<<out.first+1<<endl;
	}
}

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


int main()
{
  int X,Y;
  cin>>X>>Y;
  for(int a=0;a<=X;a++)
  {
    int b=X-a;
    if(Y==(2*a)+(4*b))
    {
      cout<<"Yes";
     return 0;
    }
  
  }
  cout<<"No";
}

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

// 約数の列挙O(√n)
vector<ll> enum_divisors(ll n){
    vector<ll> res;
    for(ll i=1;i*i<=n;i++){
        if(n%i==0){
            res.push_back(i);
            // 重複しないならばiの相方であるN/iもpush
            if(i!=n/i) res.push_back(n/i);
        }
    }
    // 小さい順に並び替える
    sort(res.begin(), res.end());
    return res;
}


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

    auto ed=enum_divisors(n);

    ll ans=0;
    for(auto e : ed){
        ll m=e-1;
        if(m<=0) continue;
        if(n/m==n%m) ans+=m;
    }

    cout<<ans<<endl;
} 


Measured memory_bytes: 3740
// C - Otoshidama
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(s);i<(e);++i)

int main(){
	int N,Y; cin>>N>>Y; Y /= 1000;
	int minZ = max(0, N-(Y-N)/4);
	int maxZ = max(0, N-(Y-N)/(5+4));
	rp(z, minZ, maxZ+1){
		int y = max(0, (10*N-Y-9*z)/5);
		int x = N - y - z;
		if(x*10 + y*5 + z != Y) continue;
		printf("%d %d %d\n", x, y, z);
		return 0;
	}
	puts("-1 -1 -1");
}

Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n,k=map(int,input().split())
    if k%2==0:
        print((n//k)**3+((n+k//2)//k)**3)
    else:
        print((n//k)**3)
    
            

if __name__=='__main__':
    main()

Measured memory_bytes: 38384
#-*-coding:utf-8-*-
from collections import Counter
import math

def prime_factors(n):
    i = 2
    factors = []
    while i * i <= n:
        if n % i:
            i += 1
        else:
            n //= i
            factors.append(i)
    if n > 1:
        factors.append(n)
    return factors

def main():
    n = int(input())
    arry = prime_factors(math.factorial(n))
    counter = Counter(arry)
    ans = 1
    for i in set(arry):
        ans *= (counter[i] + 1)
    print(ans % (10 ** 9 + 7))

if __name__ == '__main__':
    main()

Measured memory_bytes: 3316
N = int(input())
A = list(map(int, input().split()))
even = []
odd = []

for i in range(len(A)):
    if A[i] % 2 == 0:
        even.append(A[i])

    else:
        odd.append(A[i])

if len(odd) % 2 == 1:
    print("NO")

else:
    print("YES")


Measured memory_bytes: 14108
using System;
using System.Linq;

namespace CSharp
{
    class Program
    {
        static void Main()
        {
            var N = int.Parse(Console.ReadLine());
            var P = Console.ReadLine().Split().Select(int.Parse).ToArray();

            var min_value = N + 1;
            var result = 0;
            for (int i = 0; i < N; i++)
            {
                if (P[i] < min_value)
                {
                    result++;
                    min_value = P[i];
                }
                if (min_value == 1)
                {
                    break;
                }
            }
            Console.WriteLine(result);
        }
    }
}


Measured memory_bytes: 35676
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll INFF = 1e18;

const int num[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};

string dp[2][10010];

bool cmp(const string& s, const string& t) {
	if (t == "#") return true;
	if (s.size() != t.size()) {
		return (s.size() > t.size()) ? true : false;
	}
	int size = s.size();
	rep(i, size) {
		if (s[i] != t[i]) {
			return (s[i] > t[i]) ? true : false;
		}
	} 
}
int main(int argc, char const *argv[])
{
	int n, m; cin >> n >> m;
	vector<int> a(m); rep(i, m) cin >> a[i];
	rep(i, 2)rep(j, 10010) dp[i][j] = "#";
	dp[0][0] = "";
	rep(i, n) {
		rep(j, 10010) dp[(i + 1) % 2][j] = dp[i % 2][j];
		rep(j, m) {
			if (dp[i % 2][i] == "#") continue;
			if (i + num[a[j]] > n) continue;
			if (cmp(dp[i % 2][i] + to_string(a[j]), dp[(i + 1) % 2][i + num[a[j]]])) {
				dp[(i + 1) % 2][i + num[a[j]]] = dp[i % 2][i] + to_string(a[j]);
			}
		}
	}
	cout << dp[n % 2][n] << endl;
	return 0;
}


Measured memory_bytes: 32896
//***Wherever you are, and whatever you do, be in love.***
 
#include<bits/stdc++.h>
using namespace std;
 
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define ll long long 
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i,n) for(i=0;i<n;i++)
#define forn(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define for1(i, n) for (ll i = 1; i <= (ll)(n); ++i)
#define ford(i, n) for (ll i = (ll)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (ll i = (ll)(a); i <= (ll)(b); ++i)
#define fora(it,x) for(auto it:x)
#define PI 3.14159265
#define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define endl "\n"
 
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef long double ld;
 
template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

int main(){
    long double a,b;
    cin>>a>>b;
    cout<<(ll)(a*b);
}

Measured memory_bytes: 3776
import java.util.Scanner;

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

        int[] a = new int[n];
        int tot = 0;
        for(int i=0;i<n;i++){
            a[i] = in.nextInt();
            tot += a[i];
        }

        int best = Integer.MAX_VALUE, cur = 0;
        for(int i=0;i<n-1;i++){
            cur += a[i];
            best = Math.min(Math.abs(tot-2*cur),best);
        }

        System.out.println(best);
        in.close();
    }
}

Measured memory_bytes: 21716
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int n;
int combination[128];

int main(){

  combination[0] = 1;
  
    for (int i = 1; i <= 32; ++i)
    {
      combination[i] = combination[i-1];
      if(i>1) combination[i] += combination[i-2];
      if(i>2) combination[i] += combination[i-3];
    }

while(cin >> n && n){
    cout << ((combination[n]+9)/10+364)/365 << endl;

  }


return 0;

}

Measured memory_bytes: 1160
import java.util.Scanner;

public class Main {

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

		long t025 = sc.nextLong();
		long t05 = sc.nextLong();
		long t1 = sc.nextLong();
		long t2 = sc.nextLong();

		long n = sc.nextLong();

		long one = Math.min(t1, t025 * 4);
		one = Math.min(one, t05 * 2);

		long two = Math.min(one * 2, t2);

		System.out.println(n % 2 * one + n / 2 * two);

	}

}


Measured memory_bytes: 23636
s = input()
t = input()
dic = {}
n = len(s)
for i in range(n):
    if s[i] in dic:
        if dic[s[i]] != t[i]:
            print("No")
            exit()
    else:
        dic[s[i]] = t[i]
if len(dic.values()) != len(set(dic.values())):
    print("No")
else:
    print("Yes")

Measured memory_bytes: 3632
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.util.*

data class Point(val x: Int, val y: Int)

fun main(args: Array<String>) {
    val sc = FastScanner(System.`in`)

    val h = sc.nextInt()
    val w = sc.nextInt()

    val grid = Array(h) { sc.next() }

    var max = 0
    for (x1 in 0 until w) {
        for (y1 in 0 until h) {
            if(grid[y1][x1] =='#') continue


            val c = LinkedList<Pair<Point, Int>>()
            c.add(Point(x1, y1) to 0)
            val reached = HashSet<Point>()

            while (c.size > 0) {
                val x = c.poll()
                val u = x.first
                val dist = x.second
                reached.add(u)

                if (max < dist) max = dist

                val dx = listOf(1, -1, 0, 0)
                val dy = listOf(0, 0, 1, -1)

                for (i in 0..3) {
                    val nx = u.x + dx[i]
                    val ny = u.y + dy[i]

                    if (reached.contains(Point(nx, ny))) continue

                    if (nx in 0 until grid[0].length && ny in 0 until grid.size && grid[ny][nx] == '.') {
                        reached.add(Point(nx, ny))
                        c.add(Point(nx, ny) to dist + 1)
                    }
                }
            }
        }
    }
    println(max)
}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}


Measured memory_bytes: 47084
// abc085_a
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    string S;
    cin >> S;
    S.replace(0, 4, "2018");

    print(S);


    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    for(int i=0;i<s.length();i++)
    {
        if(s[i]!=',')
        {
            cout<<s[i];
        }
        else
        {
            cout<<" ";
        }
    }
}

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

int n;
int c[9];

main(){
    cin >> n;
    for (int i = 0; i < n; i++){
        int a;
        cin >> a;
        if (a < 400)c[0]++;
        else if (a < 800)c[1]++;
        else if (a < 1200)c[2]++;
        else if (a < 1600)c[3]++;
        else if (a < 2000)c[4]++;
        else if (a < 2400)c[5]++;
        else if (a < 2800)c[6]++;
        else if (a < 3200)c[7]++;
        else c[8]++;
    }
    int flag = 0;
    for (int i = 0; i < 8; i++)flag += ( c[i] > 0 ? 1 : 0);
    int maxx = flag + c[8], minn = flag;
    if (c[8] == n) minn = 1;
    cout << minn << " " << maxx << endl;
}

Measured memory_bytes: 256
pre = [
    ((0, 1, 2), (1, 0, 1), (2, 1, 0)),
    ((3, 2, 2), (2, 1, 1), (2, 1, 1)),
    ((1, 1, 2), (1, 1, 2), (2, 2, 3)),
    ((3, 2, 2), (2, 2, 2), (2, 2, 3)),
]

q = int(input())
for _ in range(q):
    n = int(input())
    books = [c == 'Y' for c in input()]
    books = [(False, False)] + list(map(lambda u, l: (u, l), books[:2 * n], books[2 * n:])) + [(False, False)]
    shelves = [int(u1 or u2) * 2 + int(l1 or l2) for (u1, l1), (u2, l2) in zip(*[iter(books)] * 2)]
    ans = [0, 1, 2]
    for key in shelves:
        new_ans = [min(a + c for a, c in zip(ans, costs)) for costs in pre[key]]
        ans = new_ans
    print(ans[0] + n)

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

int a[200005];

int main() {
    int n;
    scanf("%d", &n);
    for(int i = 0; i < n; ++i)
        scanf("%d", &a[i]);
    sort(a, a+n);
    LL sum = a[n-1];
    for(int i = 2; i < n; ++i)
        sum += a[n-1-i/2];
    printf("%lld\n", sum);
    return 0;
}

Measured memory_bytes: 4584
#include<bits/stdc++.h>
#define ll long long
#define db double
#define lowbit(p) (p&(-p))
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define A first
#define B second
using namespace std;
void read(int &x){
	x=0; char c=getchar(); int p=1;
	for (;c<48;c=getchar())if (c=='-')p=-1;
	for (;c>47;c=getchar())x=(x<<1)+(x<<3)+(c^48);
	x*=p;
}
void read(ll &x){
	x=0; char c=getchar(); int p=1;
	for (;c<48;c=getchar())if (c=='-')p=-1;
	for (;c>47;c=getchar())x=(x<<1)+(x<<3)+(c^48);
	x*=p;
}
void Min(int &x,int y){
	if (x>y)x=y;
}
void Max(int &x,int y){
	if (x<y)x=y;
}
void Min(ll &x,ll y){
	if (x>y)x=y;
}
void Max(ll &x,ll y){
	if (x<y)x=y;
}
ll ksm(ll a,int b){
	return a*a*a;
}
int main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
//	freopen("1.in","r",stdin);
	int n,i,k,t;
	ll res=0;
	read(n); read(k);
	t=n/k;
	if (k&1){
    	res=ksm(t,3);
    }
    else {
        res=ksm(t,3);
        t=t+(n%k>=k/2);
        res+=ksm(t,3);
    }
	printf("%lld\n",res);
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
  int card[50],next[50];
  int n,r;
  int p,c;
  int i,j;

  while(1){
    scanf("%d%d",&n,&r);
    if(n==0 && r==0)break;
    
    for(i=0;i<n;i++){
      card[i]=n-i;
      next[i]=n-i;
    }
    
       for(j=0;j<r;j++){
	 scanf("%d%d",&p,&c);
	  for(i=0;i<c;i++){
	      next[i]=card[p+i-1];
	  }
	  for(i=c;i<c+p-1;i++){
	    next[i]=card[i-c];
	  }
      
	  for(i=0;i<n;i++){
	    card[i]=next[i];
	 }
       }
       printf("%d\n",card[0]);
  }
  return 0;
}

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

int main() {
	
	int m, f, r;
	cin >> m >> f >> r;
	
	while (true) {
		if ((m == -1)&&(f == -1)&&(r == -1)) break;
		
		if ((m == -1)||(f == -1)) {
			cout << "F\n";
			
		} else if ((m + f) >= 80) {
			cout << "A\n";
			
		} else if (((m + f) >= 65)&&((m + f) < 80)) {
			cout << "B\n";
			
		} else if ((m + f >= 50)&&(m + f < 65)) {
			cout << "C\n";
			
		} else if ((m + f >= 30)&&(m + f < 50)&&(r >= 50)) {
			cout << "C\n";
			
		} else if ((m + f >= 30)&&(m + f < 50)) {
			cout << "D\n";
			
		} else if (m + f < 30) {
			cout << "F\n";
		}
		cin >> m >> f >> r;
	}
	
	return 0;
}


Measured memory_bytes: 3036
#include<iostream>
using namespace std;
int main() {

	//C
	int x, n;
	cin >> x >> n;
	if (n == 0) {
		cout << x << endl;
		return 0;
	}
	int i, p[100], j;
	for (i = 0; i < n; i++) {
		cin >> p[i];
	}
	int flag;
	for (i = 0; i < 100; i++) {
		flag = 0;
		for (j = 0; j < n; j++) {
			if (p[j] == x - i) {
				flag = 1;
				break;
			}
		}
		if (flag == 0) {
			cout << x - i << endl;
			return 0;
		}
		flag = 0;
		for (j = 0; j < n; j++) {
			if (p[j] == x + i) {
				flag = 1;
				break;
			}
		}
		if (flag == 0) {
			cout << x + i << endl;
			return 0;
		}
	}


	//B
	/*int x, y;
	cin >> x >> y;
	if ((y % 2 == 0) && (y - 2 * x >= 0) && (4 * x - y >= 0)) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
	*/

	//A
	/*int n;
	int i;
	for (i = 0; i < 4; i++) {
		cin >> n;
		if (n == 0)cout << i + 1 << endl;
	}
	return 0;
	*/
}

Measured memory_bytes: 3612