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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;


int main() {
    li n, k;
    string s;
    cin >> n >> k >> s;
    k--;
    s[k] -= ('A' - 'a');
    cout << s << endl;


    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <algorithm>
#include <cassert>
#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;
  int a[110];
  cin >> n;
  rep(i,n){
    cin >> a[i];
  }

  bool ans = true;
  rep(i,n){
    if (a[i]%2==0) {
      if (a[i]%3!=0 && a[i]%5!=0) {
        ans = false;
        break;
      }
    }
  }
  cout << (ans?"APPROVED":"DENIED") << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cstdlib>
template<typename T>
void fin(T const& t){ std::cout << t << std::endl; exit(0); }

int const MAXA = 1e6;
int main() {
  std::cin.tie(0); std::ios::sync_with_stdio(false);
  int N; std::cin >> N;
  std::vector<int> c(MAXA+1, 0), c2(MAXA+1, 0);
  for(int i = 0; i < N; ++i) {
    int A; std::cin >> A;
    ++c[A]; ++c2[A];
  }
  for(int i = 2; i <= MAXA; ++i) {
    for(int j = 1; j*i <= MAXA; ++j) c[j*i] += c[j];
  }
  int ans = 0;
  for(int i = 1; i <= MAXA; ++i) if(c[i]==1 && c2[i] == 1) ++ans;
  fin(ans);
  return 0;
}


Measured memory_bytes: 11448
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int (i)=(m);(i)<(n);++(i))
#define rREP(i,m,n) for(int (i)=(n)-1;(i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;
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;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

int main() {
	init();

	int N, x; cin >> N >> x;
	vector<ll>vec(N);
	rep(i, 0, N)cin >> vec[i];
	ll ans = 0;
	rep(i, 0, N - 1) {
		if (vec[i] + vec[i + 1] > x) {
			if (vec[i] + vec[i + 1] - x > vec[i + 1]) {
				ans += vec[i + 1];
				vec[i + 1] = 0;
				ans += vec[i] - x;
			}
			else {
				ans += vec[i] + vec[i + 1] - x;

				vec[i + 1] -= vec[i] + vec[i + 1] - x;
			}
		}
	}
	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 1024
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel.Design;
using System.Globalization;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using System.Xml.Schema;
using static System.Console;

namespace ConsoleApp2
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<int> Slist() { return new List<int>(ReadLine().Split().Select(int.Parse)); }
        static void Main(string[] args)
        {
            var AV = Sarray();
            var BW = Sarray();
            var T = Sarray()[0];
            var D = Math.Abs(AV[0] - BW[0]);
            var D2 = (AV[1] - BW[1]) * T;
            WriteLine(D<=D2 ? "YES" : "NO");
            
        }
    }
}

Measured memory_bytes: 18844
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <tuple>
#include <stdio.h>
#include <bitset>
#include <limits.h>
#include <complex>
#include <deque>
#include <iomanip>
#include <list>
#include <cstring>
using namespace std;
#define pi pair<int,int>
#define pl pair<long long,long long>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define en cout << endl //セミコロンつけろ
//#define MM 1000000000
//#define MOD MM+7
typedef long long ll;
const int MM = 1e9;
const int MOD = MM+7;
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
// 'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122
template<typename T>
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
template<typename T>
T LCM(T x,T y){
    T gc = GCD(x,y);
    return x*y/gc;
}
const int COM_MAX = 500500;
long long fac[COM_MAX],finv[COM_MAX],inv[COM_MAX];
void init(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < COM_MAX; i++){
        fac[i] = fac[i-1]*i%MOD;
        inv[i] = MOD - inv[MOD%i]*(MOD/i)%MOD;
        finv[i] = finv[i-1]*inv[i]%MOD;
    }
}
long long COM(int n,int k){
    if(n < k || n < 0 || k < 0) return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}

void function(int x){
    if (x < 10) cout << "00000";
    else if (x < 100) cout << "0000";
    else if (x < 1000) cout << "000";
    else if (x < 10000) cout << "00";
    else if (x < 100000) cout << "0";
}

struct Txt {
    int y,index,num;
};
int main(){
    int N,M; cin >> N >> M;
    int city[100010];
    vector<vector<pair<int,int> > > Pre(100010);
    fill(city,city+100010,0);
    pair<int,int> a[100010];
    for (int i = 0; i < M; i++){
        ll P,Y; cin >> P >> Y;
        a[i] = {P,-1};
        Pre[P].push_back({Y,i});
    }
    for (int i = 0; i < 100010; i++){
        if (Pre[i].size()){
            sort(Pre[i].begin(),Pre[i].end());
            int index = 1;
            for (auto e : Pre[i]){
                a[e.second].second = index;
                index++;
            }
        }
    }
    for (int i = 0; i < M; i++){
        function(a[i].first);
        cout << a[i].first;
        function(a[i].second);
        cout << a[i].second << endl;
    }
}





Measured memory_bytes: 8192
#include<iostream>
#include<string>
#include<vector>
#include<cstdio>
#include<sstream>
#include<algorithm>
#include<cmath>
#include<map>
#include<functional>
#include<queue>
#include<stack>
#include<set>
using namespace std;
 char ta[100][100];
 
 string dp[100][100];
 bool ok(char n){
 	for(int i=0;i<10;i++)if(i+'0'==n)return 1;
 	return 0;
 }
 string maa(string a,string b){
 	while(a[0]=='0')a.erase(a.begin());
 	while(b[0]=='0')b.erase(b.begin());
 	if(a.size()>b.size())return a;
 	if(a.size()<b.size())return b;
 	for(int i=0;i<a.size();i++){
 		if(a[i]-'0'>b[i]-'0')return a;
 		else if(a[i]-'0'<b[i]-'0')return b;
 	}
 	return a;
 }
 
int main(){
	int h,w;
	string a,b;
	//cin>>a>>b;cout<<maa(a,b);
	while(cin>>w>>h,w+h){
	for(int i=0;i<h;i++)cin>>ta[i];
	for(int i=0;i<h;i++)for(int j=0;j<w;j++)if(ok(ta[i][j]))dp[i][j]=ta[i][j]; 
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			if(! ok(ta[i][j]))continue;
			string tmpa="",tmpb="";
			if(i>=1)tmpa=dp[i-1][j];
			if(j>=1)tmpb=dp[i][j-1];
			dp[i][j]=maa(tmpa,tmpb);
			//if(dp[i][j]=="0")dp[i][j]="";
			dp[i][j].push_back(ta[i][j]);
			//if(i&&j)cout<<i<<" "<<j<<" "<<dp[i-1][j]<<" "<<dp[i][j-1]<<" "<<min(dp[i-1][j],dp[i][j-1])<<endl;
		}
	}
	string ans;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
		//(dp[i][j].empty())? cout<<"N " : cout<<dp[i][j]<<" " ;
		ans=maa(ans,dp[i][j]);
		}
	}
	cout<<ans<<endl;
	for(int i=0;i<100;i++)for(int j=0;j<100;j++)dp[i][j]="",ta[i][j]=' ';
	}
	return 0;
}

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

int main() {
	
	while(true){
	int n,k;
	cin >> n >> k;
	if(n==0&&k==0)break;
	
	vector<int> s(n);
	for(int i=0;i<n;i++){
		cin >> s[i];
	}
	int sum=0;
	for(int i=0;i<k;i++){
		sum+=s[i];
	}
	int ans = sum;
	for(int i=0;i+k<n;i++){
		sum+=s[i+k]-s[i];
		if(sum>ans)ans=sum;
	}
	cout << ans << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1524
N, M = map(int, input().split())
A = list(map(int, input().split()))
dict = dict(zip([i for i in range(1, 10)], [2, 5, 5, 4, 5, 6, 3, 7, 6]))
INF = 10 ** (N // 2 + 1)
dp = [-INF for i in range(N + 21)]
for a in A:
    dp[dict[a]] = max(dp[dict[a]], a)
for i in range(N + 1):
    for j in range(1, 10):
        dp[i] = max(dp[i], dp[i - j] * 10 + dp[j], dp[j] * 10 + dp[i - j])
print(dp[N])

Measured memory_bytes: 26996
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include<math.h>
#define swap(type,a,b) do{type t=a;a=b;b=t;}while(0);
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define ll long long
#define INF 100000000
#define FOR(i,a,n) for(i=a;i<n;i++)
int comp(const void* a,const void* b){
	return *(int*)a-*(int*)b;
}
void fill(int a[],int b,int c){
	int i;
	FOR(i,0,b) a[i]=c;
	return;
}
int dp[10001];
int main(void)
{
    int n,s,i,j;
    scanf("%d",&n);
    dp[0]=1;
    FOR(i,0,n){
        scanf("%d",&s);
        for(j=10000;j>=0;j--){
            if(dp[j]) dp[j+s]=1; 
        }
    }
    for(i=10000;i>=0;i--){
        if(i%10!=0&&dp[i]){
            printf("%d\n",i);
            return 0;
        }
    }
    puts("0");
	return 0;
}


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

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new java.io.InputStreamReader(System.in));
        PrintWriter pw = new PrintWriter(System.out);
        StringTokenizer st = new StringTokenizer(br.readLine());

        int N = Integer.parseInt(st.nextToken());
        String[] input_str_array = br.readLine().split(" ");
        int[] input_array = new int[N];

        for(int i = 0; i < N; i++) {
            input_array[i] = Integer.parseInt(input_str_array[i]);
        }

        int[] dp = new int[N];
        dp[0] = 0;
        dp[1] = Math.abs(input_array[1] - input_array[0]);

        for(int i = 2; i < N; i++) {

            if(dp[i-2] + (Math.abs(input_array[i] - input_array[i-2])) > dp[i-1] + (Math.abs(input_array[i] - input_array[i-1]))) {
                dp[i] = dp[i-1] + (Math.abs(input_array[i] - input_array[i-1]));
            } else {
                dp[i] = dp[i-2] + (Math.abs(input_array[i] - input_array[i-2]));
            }
            
        }

        pw.println(dp[N-1]);
        
        pw.close();
        br.close();
    }
}


Measured memory_bytes: 43980
n=int(input())
t=[0 for i in range(n)]
x=[0 for i in range(n)]
y=[0 for i in range(n)]
count=1
for i in range(n):
    t[i],x[i],y[i]=[int(i) for i in input().split()]

x_a=abs(x[0])
y_a=abs(y[0])

if t[0]%2==(x_a+y_a)%2 and t[0]>=(x_a+y_a):
    for i in range(n-1):
        x_a=abs(x[i+1]-x[i])
        y_a=abs(y[i+1]-y[i])
        if (t[i+1]-t[i])%2==(x_a+y_a)%2 and (t[i+1]-t[i])>=(x_a+y_a):
            count=1
        else:
            count=0
            break
else:
    count=0


if count==1:
    print("Yes")
else:
    print("No")





Measured memory_bytes: 11824
N = int(input())
s = input().split()
ans = 0
odd_count = 0
s = [int(i) for i in s]
while True:
    for i in range(N):
        if s[i] % 2 == 1:
            odd_count = 1
        s[i] = s[i] / 2
    if odd_count == 1:
        break
    ans += 1
print(ans)


Measured memory_bytes: 3060
#include <stdio.h>

int main()
{
	int a, b, c, d;
	scanf("%d %d %d %d", &a, &b, &c, &d);
	
	int x, y;
	
	if ( a <= b){
	x = a;
	}
	
	else{
	x = b;
	}
	
	if ( c <= d){
	y = c;
	}
	
	else{
	y = d;
	}
	
	printf("%d\n", x + y);
	
	return 0;
	
}
	

Measured memory_bytes: 128
a = list(map(int, input().split()))
r = a[0]
g = a[1]
b = a[2]
n = a[3]
c = 0

for i in range(n+1):
    for j in range(n+1):
        k = (n - (r*i + g*j))//b
        if k >= 0:
            if n == r*i + g*j + b*k:
                c += 1
print(c)

Measured memory_bytes: 41196
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define per1(i,n) for(int i=n;i>0;i--)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
struct edge{int to,cost;};
typedef pair<ll,P> PP;
int H,W;
char S[1001][1001];
int d[1001][1001],INF=1e9;
int dx[4]={0,0,1,-1},dy[4]={1,-1,0,0};
int check(int x,int y){
    if(x<0||x>=H||y<0||y>=W||S[x][y]=='#') return 1;
    return 0;
}
void dijkstra(P s){
    priority_queue<PP,vector<PP>,greater<PP>> que;
    rep(i,H+1) fill(d[i],d[i]+W+1,INF);
    d[s.first][s.second]=0;
    que.push(make_pair(0,s));
    while(!que.empty()){
        PP p=que.top();que.pop();
        int x=p.second.first,y=p.second.second;
        if(d[x][y]<p.first) continue;
        rep(i,4){
            if(check(x+dx[i],y+dy[i])) continue;
            if(d[x+dx[i]][y+dy[i]]>d[x][y]) d[x+dx[i]][y+dy[i]]=d[x][y],que.push(make_pair(d[x+dx[i]][y+dy[i]],P(x+dx[i],y+dy[i])));
        }
        rep(i,5)rep(j,5){
            if(check(x+i-2,y+j-2)) continue;
            if(d[x+i-2][y+j-2]>d[x][y]+1) d[x+i-2][y+j-2]=d[x][y]+1,que.push(make_pair(d[x+i-2][y+j-2],P(x+i-2,y+j-2)));
        }
    }
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>H>>W;
    int sx,sy,gx,gy;
    cin>>sx>>sy>>gx>>gy;
    rep(i,H)rep(j,W) cin>>S[i][j];
    dijkstra(P(sx-1,sy-1));
    if(d[gx-1][gy-1]==INF) cout<<-1;
    else cout<<d[gx-1][gy-1];
}

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

const int mod = (int) 1e9 + 7;

long long fact[2000006], mmi[2000006];

long long power(long long N, long long expo)
{
    long long ans = 1;

    while(expo)
    {
        if(expo % 2)
            ans = ans * N % mod;
        
        N = N * N % mod;
        expo /= 2;
    }

    return ans;
}

long long nCr(int N, int r)
{
    if(N < r)
        return 0;
    
    return fact[N] * mmi[r] % mod * mmi[N-r] % mod;
}

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

    int r1, c1, r2, c2;
    cin >> r1 >> c1 >> r2 >> c2;

    fact[0] = mmi[0] = 1;

    for(int i=1; i<=2000001; i++)
    {
        fact[i] = fact[i-1] * i % mod;
        mmi[i] = power(fact[i], mod-2);
    }

    long long ans = 0;

    for(int r = r1; r <= r2; r++)
        ans += nCr(r+c2+1, r+1) + mod - nCr(r+c1, r+1);

    cout << ans % mod << "\n";
    return 0;
}


Measured memory_bytes: 31488
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll mod=1e9+7;
const int maxn=2e5+10;
ll inv[maxn];
ll fac[maxn];
ll power(ll base,ll n)
{
    ll r=1;
    while(n)
    {
        if(n&1) r=r*base%mod;
        base=base*base%mod;
        n/=2;
    }
    return r;

}
void init()
{
    fac[0]=1;
    for(int i=1;i<=2e5;i++)
    {
        fac[i]=fac[i-1]*i%mod;
    }
    inv[200000]=power(fac[200000],mod-2);
    for(int i=2e5;i>=1;i--)
    {
        inv[i-1]=inv[i]*i%mod;
    }


}
ll C(ll m,ll n)
{
    return fac[n]*inv[m]%mod*inv[n-m]%mod;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,k;
    cin>>n>>k;

    init();
    ll ans=0;
    for(int i=1;i<=n;i++)  //i个房间有人+隔板法
    {
         if(i>=n-k)
         {
             ans+=C(i,n)*C(i-1,n-1)%mod;
         }
    }
    cout<<ans%mod<<'\n';


}


Measured memory_bytes: 3328
package main

import "fmt"

type point struct {
	x, y, h int
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func max(a, b int) int {
	if a >= b {
		return a
	}
	return b
}
func main() {
	var n int
	fmt.Scan(&n)
	p := make([]point, n)
	var t point
	for i := range p {
		fmt.Scan(&p[i].x)
		fmt.Scan(&p[i].y)
		fmt.Scan(&p[i].h)
		if p[i].h > 0 {
			t = p[i]
		}
	}
	var H int
	var ok bool
	for cx := 0; cx <= 100; cx++ {
		for cy := 0; cy <= 100; cy++ {
			H = t.h + abs(cx-t.x) + abs(cy-t.y)
			ok = true
			for i := range p {
				if max(H-(abs(cx-p[i].x)+abs(cy-p[i].y)), 0) != p[i].h {
					ok = false
					break
				}
			}
			if ok {
				fmt.Println(cx, cy, H)
				return
			}
		}
	}
}


Measured memory_bytes: 512
#include<iostream>
using namespace std;
int main(){
    int m,f,r;
    cin >>m >>f >>r;
    char i;
    while(m!=-1||f!=-1||r!=-1){
        if(m==-1||f==-1) i='F';
        else if(m+f>=80) i='A';
        else if(m+f>=65) i= 'B';
        else if(m+f>=50) i='C';
        else if(m+f>=30)
          if(r>=50) i='C';
          else i='D';
        else i='F';
        
        cout << i << endl;
        cin >>m >>f >>r;
    }
    return 0;
}


Measured memory_bytes: 3080
#include "vector"
#include "set"
#include "map"
#include "unordered_set"
#include "unordered_map"
#include "string"
#include "iostream"
#include "algorithm"
#include "queue"

using namespace std;

#define ll long long
#define INF 2e9
//#define MOD 1000000007
#define MOD 998244353
#define MAX_SIZE 1000000000

typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;

template<typename T>
ostream& operator<<(ostream& os, const vector<T>& v) { bool first = true; for (const auto& j: v) { if (!first) { os << " "; } first = false; os <<j; } os << "\n"; return os; }
template<typename T>
istream& operator>>(istream& is, vector<T>& v) { for (auto& elem : v) { is >> elem; } return is; }


void solve() {
    int n, m;
    cin >> n >> m;

    cout << (n <= m ? "unsafe" : "safe");
}


int main() {
    //ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);

    if (0) {
        int tests;
        cin >> tests;
        for (int t = 1; t <= tests; t++) {
            //cout << "Case #" << t << ": ";
            solve();
            cout << "\n";
        }
    } else {
        solve();
        cout << endl;
    }

    return 0;
}

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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

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

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

// ------------------------------------------------------------------------------------------

int main() {
   string s;
   int a;
   cin >> s >> a;
   rep (i, s.size()) {
      if (i % a == 0) cout << s[i];
   }
   cout << endl;

   return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
 
int E[6] = {3,0,-2,2,0,-3};
int W[6] = {2,0,3,-3,0,-2};
int S[6] = {4,-1,0,0,1,-4};
int N[6] = {1,4,0,0,-4,-1};
 
 
void DICE(char a,int d[],int d2[]){
 
int i;
    if(a == 'E'){
    for(i = 0;i < 6; i++){
        d2[i] = d[i + E[i]];
        }
        }   
    if(a == 'N'){
    for(i = 0;i < 6; i++){
        d2[i] = d[i + N[i]];
        }
        }   
    if(a == 'S'){
    for(i = 0;i < 6; i++){
        d2[i] = d[i + S[i]];
        }
        }   
    if(a == 'W'){
    for(i = 0;i < 6; i++){
        d2[i] = d[i + W[i]];
        }
        }   
}
 
int main(void){
    int d[6], d2[6],i,count;
    char x;
    char mark[128];
     
    for(i = 0; i < 6; i++){
    scanf("%d",&d[i]);
}
 
scanf("%s",mark);
 
for(i = 0,count = 0;mark[i] != '\0' ;i++){
 
    if(i % 2 == 0)
DICE(mark[i],d,d2);
    if(i % 2 == 1)
        DICE(mark[i],d2,d);
     
count++;
}
 
if(count % 2 == 1)
    memcpy(d,d2,6);
 
printf("%d\n",d[0]);
 
 
return 0;
}



Measured memory_bytes: 2052
#include <iostream>
#include<string>
using namespace std;
int main(){
	int n;
	string s, t,a;
	a.erase();
	cin >>n>> s >> t;
	for (int i = 0; i < n; i++){
		a += s[i];
		a += t[i];
    }
	cout << a;
}

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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

const int MAX_N = (int)(5e2 + 5);
const int MAX_C = (int)(3e1 + 5);

int n, c;
int diff[MAX_C][MAX_C];
int grid[MAX_N][MAX_N];

int cnt[3][MAX_C];

ll ans;

int main(void) {
  // Here your code !
  scanf("%d %d", &n, &c);

  for (int i = 1; i <= c; ++i) {
    for (int j = 1; j <= c; ++j) {
      scanf("%d", &(diff[i][j]));
    }
  }

  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      scanf("%d", &(grid[i][j]));
    }
  }

  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      cnt[(i + j) % 3][grid[i][j]] += 1;
    }
  }

  ans = INF;

  for (int i = c; i >= 1; --i) {
    for (int j = c; j >= 1; --j) {
      if (i == j) continue;
      for (int k = c; k >= 1; --k) {
        if (i == k || j == k) continue;

        ll tmp = 0LL;

        for (int col = 1; col <= c; ++col) {
          tmp += cnt[0][col] * diff[col][i];
          tmp += cnt[1][col] * diff[col][j];
          tmp += cnt[2][col] * diff[col][k];
        }

        ans = min(ans, tmp);
      }
    }
  }

  printf("%lld\n", ans);

  return 0;
}


Measured memory_bytes: 1280
/* Great things never come from comfort zones,
"whatever the mind of a man can conceive and believe,it can achieve." */
 
#include <bits/stdc++.h>
#define ll long long
#define scf(n) scanf("%d",&n)
#define lscf(n) scanf("%lld",&n)
#define lpri(n) printf("%lld ",n)
#define pri(n) printf("%d ",(int)n)
#define prin(n) printf("%d\n",(int)n)
#define lprin(n) printf("%lld\n",n)
#define rep(i,ini,n) for(int i=ini;i<(int)n;i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x)     x.begin(),x.end()
#define tc   int tt; scf(tt); while(tt--)
#define inf INT_MAX
#define ninf INT_MIN
#define gcd __gcd
#define bitcount(n) __builtin_popcount(n)
typedef double dd;
using namespace std;
const ll mod =1e6+7;
const int N = 1e5+7;


void my_dbg() { cout << endl; }
template<typename Arg, typename... Args> void my_dbg(Arg A, Args... B) 
{ cout << ' ' << A; my_dbg(B...); }
#define dbg(...) cout << "(" << #__VA_ARGS__ << "):", my_dbg(__VA_ARGS__)

    
int main()
{
    
        int n,k,l=0;
        scf(n),scf(k);

        ll a[n];

        rep(i,0,n)
        lscf(a[i]);
  

        for(int i=0;i+k<n;i++)
        {
            if(a[i]<a[i+k])
            printf("Yes\n");
            
            else
            printf("No\n");
            
        
            
        }
          
  
      
}
    

Measured memory_bytes: 5244
#include<bits/stdc++.h>
 
using namespace std;
using S = set<long long>;
using D = deque<long long>;
using L = vector<long long>;
using M = map<int,long long>;
using A = vector<vector<long long>>;
using Q = priority_queue<long long>;
using U = unordered_map<int,long long>; //mapとの違いはkeyの順番を保持していない

#define sorted(vector) sort(vector.begin(),vector.end()) //O(nlongn)
#define vmin(vector) *min_element(vector.begin(),vector.end()) //O(N)
#define vmax(vector) *max_element(vector.begin(),vector.end()) //O(N)
#define vsum(vector) accumulate(vector.begin(),vector.end(),0) //O(N)
#define vcount(vector,a) count(vector.begin(), vector.end(),a) //O(N)
#define bisect_left(vector,a) (lower_bound(vector.begin(),vector.end(),a)-vector.begin())
#define bisect_right(vector,a) (upper_bound(vector.begin(),vector.end(),a)-vector.begin())
#define vfind(vector,a) find(vector.begin(), vector.end(), a) != vector.end() //遅いからあんまり使うな
//存在確認はmap!!!!!!!!!!!!!か配列に埋め込んでcontinueで回避
//__gcd(a,b)はコンパイラがGCC時のみ

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    string s;
    cin>>s;
    int f=0;
    vector<char> a={'R','D','U'};
    vector<char> b={'L','D','U'};
    for(int i=0  ;i<s.size()  ;i+=2){
        if (not (vfind(a,s[i]))){
            f=1;
        }
    }
    for(int i=1  ;i<s.size()  ;i+=2){
        if (not (vfind(b,s[i]))){
            f=1;
        }
    }
    
    if (f==0){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
//vector<vector<ll>> data(3, vector<ll>(4));
//vector<ll> data(N);
//str s = to_string(i);
//int i = c - '0'
//sort(data.begin(), data.end());
//reverse(data.begin(), data.end());
//data.erase(unique(data.begin(), data.end()), data.end());
//str.substr(n)//n番以降スライス
//str.substr(n,m)//n番以降m文字スライス
//str.erase(n)//n番以降削除
//str.erase(n,m)//n番以降m文字削除
typedef long long ll;
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
#define PB push_back
using namespace std;

bool judge(ll num, vector<ll> start, vector<ll> end) {
	if (num >= (abs(start.at(0) - end.at(0))+ abs(start.at(1) - end.at(1)))
		&& (num - (abs(start.at(0) - end.at(0)) + abs(start.at(1) - end.at(1)))) % 2 == 0) return true;
	else return false;
}
int main() {
	ll a, b, c, d, xy;
	cin >> a >> b >> c >> d;
	xy = max(max(max(a * c, a * d), b * c), b * d);
	cout << xy << endl;
}

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

using namespace std;
using ll = long long;
using ull = unsigned long long;

typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
typedef pair<P, P> PPP;

const ll MOD = 1e9 + 7;
const ll INF = 9e18;
const double DINF = 5e14;
const double eps = 1e-10;
const int di[4] = { 1,0,-1,0 }, dj[4] = { 0,1,0,-1 };

#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define pb push_back
#define eb emplace_back
#define fr first
#define sc second


int n, a[2010], sum;
bitset<4000001>dp;

int main() {
	cin >> n;
	for (int i = 0;i < n;i++) {
		cin >> a[i];
		sum += a[i];
	}
	dp.set(0);
	for (int i = 0;i < n;i++) {
		bitset<4000001>nex;
		nex |= dp;
		nex |= dp << a[i];
		dp = nex;
	}
	for (int i = (sum + 1) / 2;i <= sum;i++) {
		if (dp[i]) {
			cout << i << endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 2304
import java.util.*;
import java.io.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        FastScanner sc = new FastScanner(System.in);
        int n = sc.nextInt();
        int y = sc.nextInt();
        for(int i = 0; i <= n; i++){
            for(int j = 0; j <= n-i; j++){
                int z = n-i-j;
                int zy = y-10000*i-5000*j;
                if((z == 0 && zy == 0) || (z != 0 && zy % z == 0 && zy/z == 1000)){
                    System.out.println(i + " " + j + " " + z);
                    return;
                }
            }
        }
        System.out.println("-1 -1 -1");
    }
    
    public static int beamSearch(long[] arr, long target){
        int left = 0;
        int right = arr.length;
        while(right-left > 1){
            int mid = (left+right)/2;
            if(arr[mid] > target){
                right = mid;
            }else{
                left = mid;
            }
        }
        return left;
    }
}

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;
    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken("\n");
    }

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

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

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

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    } 
}


Measured memory_bytes: 23636
from collections import OrderedDict, deque


def main():
    n = int(input())
    edges = [tuple(map(int, input().split())) for _ in range(n - 1)]
    tree = [[] for _ in range(n)]  # こうしないとすべて同じリストObjになる.
    coloring = OrderedDict()
    for e in edges:
        a, b = e[0] - 1, e[1] - 1
        tree[a].append(b)
        # どうせ左から見ていくので, 辺を右から左へ考える必要は無い.
        # tree[b].append(a)
        coloring[(a, b)] = 0

    q = deque()
    q_append = q.append
    q_popleft = q.popleft
    seen = [False] * n
    q_append(0)
    col_count_by_v = [set() for _ in range(n)]
    while len(q):
        new_v = q_popleft()
        seen[new_v] = True
        color_i = 1  # One-based index.
        for adj in tree[new_v]:
            if seen[adj]:
                continue
            q_append(adj)
            while color_i in col_count_by_v[new_v]:
                color_i += 1
            coloring[(new_v, adj)] = color_i
            col_count_by_v[new_v].add(color_i)
            col_count_by_v[adj].add(color_i)

    print(len(set(coloring.values())))
    for c in coloring.values():
        print(c)


if __name__ == '__main__':
    main()

# なんでか分からないが, こうして main() に仕舞ってあげたほうが少し早い.


Measured memory_bytes: 92696
using System;

namespace B
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int A = int.Parse(input[0]);
            int B = int.Parse(input[1]);
            double cnt = Math.Ceiling((double)(B - 1) / (A - 1));
            Console.WriteLine(cnt);
            Console.Read();
        }
    }
}


Measured memory_bytes: 11092
X,K,D = map(int, input().split())

if abs(X) > K*D:
    X = abs(X) - K*D
else:
    # とりあえず同方向に移動できるところまでいく
    # 移動回数
    T = abs(X)//D
    # 移動先の座標
    Y = abs(X)%D
    
    # 残りは往復の2択
    X = abs(Y - ((K-T)%2)*D)   
    
print(X)

Measured memory_bytes: 9144
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;

public class Main {
	static int n, m;
	static char[] s;
	static List<List<Integer>> list;
	static boolean[][] ng;

	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		n = Integer.parseInt(sa[0]);
		m = Integer.parseInt(sa[1]);
		s = br.readLine().toCharArray();
		list = new ArrayList<>(n);
		for (int i = 0; i < n; i++) {
			list.add(new ArrayList<>());
		}
		for (int i = 0; i < m; i++) {
			sa = br.readLine().split(" ");
			int a = Integer.parseInt(sa[0]) - 1;
			int b = Integer.parseInt(sa[1]) - 1;
			list.get(a).add(b);
			if (a != b) {
				list.get(b).add(a);
			}
		}
		br.close();

		ng = new boolean[n][2];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < 2; j++) {
				if (!ng[i][j]) {
					if (dfs(i * 10 + j, new LinkedHashSet<>())) {
						System.out.println("Yes");
						return;
					}
				}
			}
		}
		System.out.println("No");
	}

	static boolean dfs(int x, LinkedHashSet<Integer> his) {
		int cur = x / 10;
		int t = x % 10;
		char nc = s[cur];
		if (t == 1) {
			nc = (char) ('A' + 'B' - s[cur]);
		}
		int nt = 1 - t;
		for (int next : list.get(cur)) {
			if (s[next] == nc) {
				int nx = next * 10 + nt;
				if (his.contains(nx)) {
					return true;
				}
				if (!ng[next][nt]) {
					his.add(nx);
					if (dfs(nx, his)) {
						return true;
					}
					his.remove(nx);
				}
			}
		}
		ng[cur][t] = true;
		return false;
	}
}


Measured memory_bytes: 131188
#include <set>
#include <queue>
#include <vector>
#include <iostream>
#include <algorithm>
#pragma warning(disable : 4996)
using namespace std;
struct edge {
	int to, id;
};
bool operator<(const edge& e1, const edge& e2) {
	if (e1.to != e2.to) return e1.to < e2.to;
	return e1.id < e2.id;
}
int N, M, Q, a[200009], b[200009], dist[100009], r[200009], ans[200009];
vector<int> g[100009]; set<edge> G[100009];
bool ok[200009], vis[200009];
int main() {
	scanf("%d%d%d", &N, &M, &Q);
	for (int i = 0; i < M; i++) {
		scanf("%d%d", &a[i], &b[i]); a[i]--, b[i]--;
		g[a[i]].push_back(b[i]);
		g[b[i]].push_back(a[i]);
	}
	fill(dist + 1, dist + N, 999999999);
	queue<int> que; que.push(0);
	while (!que.empty()) {
		int u = que.front(); que.pop();
		for (int i : g[u]) {
			if (dist[i] == 999999999) {
				dist[i] = dist[u] + 1;
				que.push(i);
			}
		}
	}
	fill(ok, ok + M, true);
	for (int i = 0; i < Q; i++) scanf("%d", &r[i]), ok[--r[i]] = false; r[Q] = M;
	for (int i = 0; i < M; i++) {
		if (dist[a[i]] > dist[b[i]]) swap(a[i], b[i]);
		if (dist[a[i]] != dist[b[i]] && ok[i]) {
			G[a[i]].insert(edge{ b[i], i });
		}
	}
	int sum = 1;
	fill(ok, ok + N, false); ok[0] = true;
	for (int i = Q - 1; i >= 0; i--) {
		if (ok[a[r[i + 1]]]) {
			queue<int> que2; que2.push(a[r[i + 1]]);
			while (!que2.empty()) {
				int u = que2.front(); que2.pop();
				if (!ok[u]) ok[u] = true, sum++;
				vector<int> l;
				for (edge e : G[u]) {
					if (!vis[e.id]) {
						vis[e.id] = true; l.push_back(e.id);
						que2.push(e.to);
					}
				}
				for (int i : l) {
					G[u].erase(edge{ b[i], i });
				}
			}
		}
		ans[i] = sum;
		if (dist[a[r[i]]] != dist[b[r[i]]]) {
			G[a[r[i]]].insert(edge{ b[r[i]], r[i] });
		}
	}
	for (int i = 0; i < Q; i++) printf("%d\n", N - ans[i]);
	return 0;
}

Measured memory_bytes: 25792
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i < (n+1); ++i)
using namespace std;
using ll = long long;
const ll INF = +10010010000;

typedef pair<ll,ll> P;
const ll MO = 1000000007;

int main(){
    int n;
    cin >> n;
    vector<ll> c(n),s(n),f(n),ans(n);
    rep(i,n-1){
        cin >> c[i] >>s[i]>> f[i];
    }
    rep(i,n-1){
        int cnt = s[i];cnt+=c[i];
        for(int j = i+1; j<n-1;++j){
            if(cnt<s[j]){
                cnt=s[j];
            }else if(cnt%f[j]==0);
            else{
                cnt+=f[j] - cnt%f[j];
            }
            cnt+=c[j];
        }
        ans[i] = cnt;
    }
    rep(i,n){
        cout << ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
A = [list(input()) for _ in range(N)]
B = [list(input()) for _ in range(M)]


for i in range(N-M+1):
    for j in range(N-M+1):
        if A[i][j] == B[0][0]:
            for x in range(M):
                ta = A[i][j:j+M:]
                if ta != B[x]:
                    break
                i += 1
            else:
                print('Yes')
                exit()
print('No')

Measured memory_bytes: 3064
#include <stdio.h>

int main(){
  int i,n,m,sum=0,count=0;
  scanf("%d %d",&n,&m);
  int a[n];
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
    sum+=a[i];
  }
  for(i=0;i<n;i++){
    if(a[i]>=sum*0.25/m){
      count++;
    }
  }
  if(count>=m){
    printf("Yes\n");
  }else{
    printf("No\n");
  }
  return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iostream>
#include <sstream>
#include <climits>
#include <cfloat>
#include <complex>


typedef long long ll;
const double Eps = 1e-5;

using namespace std;

int main()
{
	char pat[8][9];
	for (int i = 0; i < 8; ++i)
		cin.getline(pat[i], sizeof(pat[i]));
	for (int rotate = 1; rotate <= 3; ++rotate)
	{
		char copy[8][9];
		memcpy(copy, pat, sizeof(copy));
		for (int i = 0; i < 8; ++i)
		{
			for (int j = 0; j < 8; ++j)
			{
				int x = j < 4 ? j-4 : j-3;
				int y = i < 4 ? i-4 : i-3;
				int dx = -y;
				int dy = x;
				int dj = dx < 0 ? dx+4 : dx+3;
				int di = dy < 0 ? dy+4 : dy+3;
				copy[di][dj] = pat[i][j];
			}
		}
		memcpy(pat, copy, sizeof(pat));

		printf("%d\n", rotate*90);
		for (int i = 0; i < 8; ++i)
			puts(pat[i]);
	}

	return 0;
}

Measured memory_bytes: 0
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;

#[allow(dead_code)]
struct Scanner<'a> {
    cin: StdinLock<'a>,
}
#[allow(dead_code)]
impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }

    fn read<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }

    fn input<T: FromStr>(&mut self) -> T {
        self.read().unwrap()
    }

    fn vec<T: FromStr>(&mut self, len: usize) -> Vec<T> {
        (0..len).map(|_| self.input()).collect()
    }

    fn mat<T: FromStr>(&mut self, row: usize, col: usize) -> Vec<Vec<T>> {
        (0..row).map(|_| self.vec(col)).collect()
    }
}

use std::collections::BTreeMap;
fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);

    let n: usize = sc.input();
    let arr: Vec<usize> = sc.vec(n);
    let q: usize = sc.input();

    let mut map = BTreeMap::<usize, usize>::new();

    for &a in &arr {
        *map.entry(a).or_insert(0) += 1;
    }

    let mut sum = map.iter().map(|(k, v)| *k * *v).sum::<usize>();

    for _ in 0..q {
        let b: usize = sc.input();
        let c: usize = sc.input();

        if let Some(cnt) = map.get(&b) {
            sum += (c - b) * cnt;
        }

        if let Some(cnt) = map.remove(&b) {
            *map.entry(c).or_insert(0) += cnt;
        }
        println!("{}", sum);

    }
}


Measured memory_bytes: 4696
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>



#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define all(x) (x).begin(),(x).end()

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

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,k;cin>>n>>k;
  vector<ll>x(n),y(n);
  rep(i,n)
  {
    cin>>x[i]>>y[i];
  }
  auto yy=y,xx=x;
  sort(all(yy));
  sort(all(xx));
  ll res=5e18;
  rep(ixl,n)repi(ixh,ixl,n)rep(iyl,n)
  {
    ll ok=n;
    ll ng=iyl-1;
    while(ok-ng>1)
    {
      ll nn=(ok+ng)/2;
      bool check=[&](ll a){
        ll cnt=0;
        if(a<0)return false;
        rep(i,n)
        {
          if(y[i]<=yy[a]&&xx[ixl]<=x[i]&&xx[ixh]>=x[i]&&y[i]>=yy[iyl])cnt++;
        }
        return cnt>=k;
      }(nn);
      if(check)ok=nn;
      else ng=nn;
    }
    if(ok==n)continue;
    if(yy[ok]-yy[iyl]<0)continue;
    chmin(res,(ll)(xx[ixh]-xx[ixl])*(yy[ok]-yy[iyl]));
  //  cout<<ok<<res<<endl;
  }
  cout<<res<<endl;

  return 0;

}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
using namespace std;


int main()
{
    int N;
    cin >> N;
    
    if (N % 2 == 0) {
        cout << N << endl;
    }else{
        cout << 2 * N << endl;
    }
}

Measured memory_bytes: 256
program main
  implicit none
  integer :: k, n, res
  integer, allocatable :: a(:)
  read (*, *) k, n
  allocate (a(0:n))
  read (*, *) a(1:n)
  a(0) = a(n) - k
  res = k - maxval(a(1:n) - a(0:n - 1))
  write (*, "(i0)") res
end program main


Measured memory_bytes: 1536
/*input
3 0
3 4 5
*/

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

const double EPS = 1e-9;

int n, k;
vector<double> a;

bool C(double t) {
  ll res = 0;
  rep(i, n) {
    res += (ll)(ceil(a[i]/t)+EPS)-1;
    if (res > k) return false;
  }
  return true;
}

int main() {
  cin >> n >> k;
  a.resize(n);
  rep(i, n) cin >> a[i];
  double lb = 0, ub = 1e9;
  rep(i, 100) {
    double mid = (lb+ub)/2.0;
    if (C(mid)) ub = mid;
    else lb = mid;
  }
  cout << (ll)(ceil(lb)+EPS) << endl;
}

Measured memory_bytes: 4716
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

int main(void){
    int N, result;
    scanf("%d", &N);

    vector<int> D(N);

    for(int i = 0; i < N; i++)
        scanf("%d", &D[i]);

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

    result = D[N / 2] - D[(N / 2) - 1];

    cout << result << endl;

}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
//NOT TO SUBMIT IN WRONG PLACE OR BY WRONG COMPILER
//ABC 168, task a, 2020/05/17
//ms,
/*
*/

int main(void){
  int N;
  cin >>N;
  switch(N%10){
    case 0:
    case 1:
    case 6:
    case 8:
      cout <<"pon" <<endl;
      break;
    case 2:
    case 4:
    case 5:
    case 7:
    case 9:
      cout <<"hon"<<endl;
      break;
    case 3:
      cout <<"bon"<<endl;
      break;
  }
  return 0;
}
/*
*/


Measured memory_bytes: 3624
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <array>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x*x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

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

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;


int x[100000 + 1];
int y[100000 + 1];
int X[100000 + 1];
int Y[100000 + 1];

int main(void) {

	LL n,m;
	
	std::cin >> n >> m;
	
	for (int i = 0; i < n; i++) {
		std::cin >> x[i];
	}
	for (int i = 0; i < m; i++) {
		std::cin >> y[i];
	}
	

	LL xsum = 0;
	for (LL j = 1; j < (n); j++) {
		LL tx = x[j] - x[j - 1];
		xsum += (n - j)*j * tx;
		xsum %= 1000000007;
	}

	LL ysum = 0;
	for (LL j = 1; j < (m); j++) {
		LL ty = y[j] - y[j - 1];
		ysum += ((m - j)*j * ty);
		ysum %= 1000000007;
	}
	

	std::cout << (xsum * ysum)%1000000007  << std::endl;

	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#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 it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
  string s;
  cin>>s;
  char q[2]={'A','Z'};
  int to=0;
  bool out=false;
  bool h=false;
  while(to<s.size()){
    if(q[h]==s[to]){
      if(h){
	cout<<"AZ";
	h=false;
	out=true;
      }else h=true;
    }
    to++;
  }
  if(out)
    cout<<endl;
  else cout<<-1<<endl;
}

Measured memory_bytes: 1184