akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
     
#define fast { ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0); }
#define pb push_back
#define ll long long
#define ld long double
     
#define vi vector<int>
#define vl vector<long>
#define vll vector<long long>
     
#define infi INT_MAX
#define infl LONG_LONG_MAX
#define infd LDBL_MAX
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fi(i,a,b) for(ll i=(b-1);i>=a;i--)
#define F first
#define S second
#define G(a,b) get<a>(b)
#define MP make_pair
#define MT make_tuple
#define pll pair<ll,ll> 
#define endl "\n"
#define ALL(v) v.begin(),v.end()
#define nl cout<<"\n";
#define pr(x) cout<<x;
#define pr1(x) cout<<x<<" ";
#define pr2(x,y) cout<<x<<" "<<y;
#define deb printf("***************************************************************************************\n");
#define moshi printf("moshi moshi ! \n");
#define hi printf("hi ! \n");
#define bye printf("bye bye ! \n");
#define o_set(ll) tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define number_of_set_bits  __builtin_popcountll  
const ld PI=3.1415926535897932384626433; 

inline ll ceil(ll a,ll b)
{
   return (a+b-1)/b;
}

void func()
{ 
  ll a,b,v,w,t;
  cin>>a>>v>>b>>w>>t;

  if(a==b)
  {
    cout<<"YES\n";
    return;
  }

  else if(v<=w)
  {
    cout<<"NO\n";
    return;
  }

  ll req=ceil((ll)abs(a-b),v-w);
  if(t>=req)  cout<<"YES\n";
  else cout<<"NO\n";
}   
     
     
int main() 
{
    fast

    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif // ONLINE_JUDGE
        
     
    ll ntc=1;
    //cin>>ntc;
     
    f(i,1,ntc+1)
    {
      //cout<<"Case #"<<i<<": ";
      func();
    }     
    return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define  rep(i, n) for(int i = 0; i < n; i++) 
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair<ll, ll>
#define F first
#define S second
const int MOD = 1000000007;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }
//sort(all(x))とするとソートできるよ
// 10^x は pow(10,(x)) 
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main(){
    int H,W;cin >> H >> W;
    int N;cin >> N;
    vector<int> a(N);
    rep(i,N)cin >> a[i];

    vector<vector<int>> ans(H,vector<int>(W,0));
    int s = 0;
    int t = 0;  // (s,t)が現在地の座標になる。(行列表記)
    int dir = 0;    // dir は 0 → 1 ↓ 2 ← 3 ↑　とする
    int ct = 1; // 曲がった回数。これを4で割ると行き止まりの座標を取得可能

    // ぐるぐる回る
    rep(i,N){
        rep(j,a[i]){
            ans[s][t] = i+1;
            if(dir == 0){
                if(t != W-1 - ct/4)t++;
                else{
                    s++;
                    dir = 1;
                    ct++;
                }
            }     
            else if(dir == 1){
                if(s != H-1 - ct/4)s++;
                else{
                    t--;
                    dir = 2;
                    ct++;
                }
            }
            else if(dir == 2){
                if(t != 0 + ct/4)t--;
                else{
                    s--;
                    dir = 3;
                    ct++;
                }
            }
            else if(dir == 3){
                if(s != 0 + ct/4)s--;
                else{
                    t++;
                    dir = 0;
                    ct++;
                }
            }
        }
    }

    rep(i,H){
        rep(j,W)cout << ans[i][j] << " ";
        cout << endl;
    }
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
//define
#define int long long
#define vint vector<int>
#define rep(x,y) for(int i=x;i<y;i++)
#define REP(x,y) for(int j=x;j<y;j++)
#define all(x) x.begin(),x.end()
#define pb() push_back()
#define mod 100000007
#define elif else if
#define str string
//main
signed main(){
  int N,M,O,Q,count=0,count2=0,count3=0;
  cin>>N;
  vint L(N);
  rep(0,N)cin>>L[i];
  sort(all(L));
  rep(0,N-2){
    REP(i+1,N-1){
      for(int k=j+1;k<N;k++){
        if(i!=j||i!=k||j!=k){
          if(L[k]<L[i]+L[j])count+=1;
        }
      }
    }
  }
  cout<<count<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define pi 3.14159265359
#define all(i) i.begin(),i.end()
using namespace std;
const long long INF=1e9+7;
const string alp="abcdefghijklmnopqrstuvwxyz"; //26
const string ALP="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
//const ll MOD=998244353LL;
//const ll MOD=1777777777LL;


int main() {
  ll N,T,A;
  cin>>N>>T>>A;
  long double H[N];
  long double tem[N];
  long double ABS=INF;
  ll ans;
  rep(i,N){
    cin>>H[i];
    H[i]/=1000;
    H[i]*=6;
    tem[i]=T-H[i];
    if(ABS>abs(A-tem[i])){
      ABS=abs(A-tem[i]);
      ans=i+1;
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 3816
s, t = $<.map &:chomp

begin
  ss = s.dup
  r = t.gsub /./, '[?\0]'
  s[/.*(#{r})/, 1] = t
  ss[/#{r}/] = t
  puts [s, ss].map {|str| str.tr ??, ?a }.min
rescue
  puts 'UNRESTORABLE'
end

Measured memory_bytes: 3836
#include <iostream>
#include <fstream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <bitset>
#include <algorithm>
#include <iomanip>

using namespace std;

#define forn(i,n) for (int i = 0; i < int(n); i++)
#define ford(i,n) for (int i = int(n) - 1; i >= 0; i--)
#define fore(i,l,r) for (int i = int(l); i <= int(r); i++)
#define all(a) a.begin(), a.end()
#define sz(a) int(a.size())
#define mp make_pair
#define pb push_back
#define ft first
#define sc second
#define x first
#define y second

template<typename X> inline X abs(const X& a) { return a < 0 ? -a : a; }
template<typename X> inline X sqr(const X& a) { return a * a; }

typedef long long li;
typedef long double ld;
typedef pair<int, int> pt;

const int INF = int(1e9);
const li INF64 = li(1e18);
const ld EPS = 1e-9;
const ld PI = acosl(ld(-1));

li n, x;

inline bool read()
{
	if (!(cin >> n >> x))
		return false;

	return true;
}

li gcd (li a, li b)
{
	if (b == 0)
		return a;
		
	return gcd(b, a % b);
}

inline void solve()
{
	cout << 3 * (n - gcd(n, x)) << endl;
}

int main()
{
#ifdef SU2_PROJ
	assert(freopen("input.txt", "r", stdin));
	assert(freopen("output.txt", "w", stdout));
#endif

	cout << setprecision(25) << fixed;
	cerr << setprecision(10) << fixed;

	srand(int(time(NULL)));

	assert(read());
	solve();

#ifdef SU2_PROJ
	cerr << "TIME: " << clock() << endl;
#endif

	return 0;
}


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

int main() {
	int i, j, k;
	long long int l = 0;
	int m, g, n, q;
	long long int f;
	int h;
	int a;

	scanf("%d %d", &h, &a);

	m = h / a;

	if (h%a == 0) {

	}
	else {
		m = m + 1;
	}

	printf("%d", m);





	return 0;
}

Measured memory_bytes: 128
// Problem : A - Don't be late
// Contest : AtCoder - AtCoder Beginner Contest 177
// URL : https://atcoder.jp/contests/abc177/tasks/abc177_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define int long long
#define db double
#define mod 1000000007
#define pb push_back
#define pp pair<int,int>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repe(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=b;i>=a;i--)
#define maxn 200005
#define ss second
#define ff first
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
int inv(int a, int b){
 return 1<a ? b - inv(b%a,a)*b/a : 1;
}
void solve()
{
	db d,s,t;
	cin >> d >> s >>t;
	db tm = d/s;
	if(tm <= t)
		cout << "Yes" <<"\n";
	else cout << "No" <<"\n";
}
signed main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
    //cin >> t;
    while(t--)
    solve();
    return 0;
}


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

#define ll long long
#define rep(i,N) for(ll i=0; i<N; i++)
const int mx = 2e5;

int main(void){
  
  ll N,M;
  cin >> N >>M;
  ll H[N];
  rep(i,N) cin >> H[i];
  ll A[M], B[M];
  bool seen[N];
  rep(i,N) seen[i] = true;
  rep(i,M){
    cin >> A[i] >> B[i];
    if(H[A[i]-1]<H[B[i]-1]){
      seen[A[i]-1] = false;
    }else if(H[B[i]-1] < H[A[i]-1]){
      seen[B[i]-1] = false;
    }else{
      seen[A[i]-1] = false;
      seen[B[i]-1] = false;
    }
  }
      
  
  
  ll cnt=0;
  
  for(ll i=0; i<N; i++){
    if(seen[i]) cnt++;
    //cout << seen[i] << " ";
  }
  cout << cnt;
  
  return 0;
}


Measured memory_bytes: 6068
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define double long double
#define low lower_bound
#define upp upper_bound
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Rep(i, n) for (int i = (int)(n); i >= 0; i--)
#define all(vec) vec.begin(), vec.end()
#define rever(vec) reverse(all(vec));
#define cend cout << endl;
#define prique(T) priority_queue<T, vector<T>, greater<T>>
struct edge { int to, cost; };
using P = pair<int, int>;
using PP = pair<P, int>;
const int mod = 1e9 + 7, inf = 1e16, mod2 = 998244353;

int modpow(int x, int n) {
	int ans = 1;
	while (n > 0) {
		if (n & 1) {
			if (mod <= ans * x) ans = ans * x % mod;
			else ans *= x;
		}
		if (mod <= x * x) x = x * x % mod;
		else x *= x;
		n >>= 1;
	}
	return ans;
}

int fact_memo[114514];
int fact(int n) {
	int ans = 1;
	if (fact_memo[n]) return fact_memo[n];
	rep(i, n) {
		ans *= (i + 1);
		if (mod <= ans) ans %= mod;
		fact_memo[i + 1] = ans;
	}
	return (ans + mod) % mod;
}

int comb(int n, int r) {
	if (n < r) return 0;
	if (n - r < r) r = n - r;
	return (fact(n) * modpow(fact(n - r), mod - 2) % mod * modpow(fact(r), mod - 2) + mod) % mod;
}

int perm(int n, int r) {
	if (n < r) return 0;
	if (n - r < r) r = n - r;
	return (fact(n) * modpow(fact(n - r), mod - 2) % mod + mod) % mod;
}

int gcd(int a, int b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

int lcm(int a, int b) {
	return a * b / gcd(a, b);
}

bool pri(int p) {
	for (int i = 2; i * i <= p; i++) if (p % i == 0) return false;
	return p > 1;
}

map<int, int>factring(int n) {
	map<int, int>ans;
	for (int i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			n /= i;
			ans[i]++;
		}
	}
	if (n != 1) ans[n]++;
	return ans;
}

P operator+(const P& a, const P& b) {
	return P(a.first + b.first, a.second + b.second);
}
P operator-(const P& a, const P& b) {
	return P(a.first - b.first, a.second - b.second);
}

int ans;
signed main() {
	int n;
	cin >> n;
	rep(i, n + 1) {
		if (i == 0) continue;
		if ((int)ceil(log10(i + 0.1)) & 1) ans++;
	}
	cout << ans << endl;
}


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

int main(){

    int N;
    cin >>N;
    vector<long int> H(N);
    vector<long int> B(N,0);
    for(int i=0;i<N;i++){
      cin>>H.at(i);
    }

    string p="No";
int j=0;
while(j<10){
    int count=0;
    for(int i=0;i<N-1;i++){
      if((H.at(i)-H.at(i+1))>0){
        if((H.at(i)-H.at(i+1))>1)break;
        if(B.at(i)!=1){H.at(i)-=1;
        B.at(i)=1;}
      }else count++;
    }
    if(count==N-1){
      p="Yes";
      break;}
      j++;
    }

    cout<<p<<endl;
}


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

#define BOMB 1
#define EMPTY 0

using namespace std;

int field[50][50];
int deltas[8][2] = {{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}};
char result[50][50];

int main() {
  int h, w;
  cin >> h >> w;
  for (int i = 0; i < h; i++) {
    string line;
    cin >> line;
    for (int j = 0; j < w; j++) {
      if (line[j] == '#') field[i][j] = BOMB;
    }
  }
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (field[i][j] == EMPTY) {
        int counter = 0;
        for (auto d : deltas) {
          int ii = i + d[0];
          int jj = j + d[1];
          if (ii < 0 || jj < 0 || ii >= h || jj >= w) continue;
          if (field[ii][jj] == BOMB) counter++;
        }
        result[i][j] = counter + '0';
      } else {
        result[i][j] = '#';
      }
    }
  }
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cout << result[i][j];
    }
    cout << endl;
  }
  return 0;
}


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

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

int main() {
    ll N;
    string S;
    cin >> N >> S;
    ll ans = 0;
    REP(i, 1000) {
        ll index = 0;
        ll T[3] = {i / 100, (i % 100) / 10, (i % 10)};
        REP(n, N) {
            if (S[n] - '0' == T[index])
                index++;

            if (index == 3) {
                ans++;
                break;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
class Segmenttree_min():
    def __init__(self,number):
        n=1
        inf=(1<<31)-1
        while n<number:
            n*=2
        self.n=n
        self.list=[inf]*(2*n-1)
    
    def add(self,i,x):#0indexed ith add x
        i+=self.n-1
        self.list[i]=x
        while i>0:
            i=(i-1)//2
            self.list[i]=min(self.list[2*i+1],self.list[2*i+2])
        
    def search(self,a,b,k,l,r):#call as search(a,b,0,0,self.n) minimun in [a,b)
        if r<=a or b<=l:
            return (1<<31)-1
        elif a<=l and r<=b:
            return self.list[k]
        else:
            vl=self.search(a,b,2*k+1,l,(l+r)//2)
            vr=self.search(a,b,2*k+2,(l+r)//2,r)
            return min(vl,vr)

N,Q=map(int,input().split())
ans=[]
tree=Segmenttree_min(N)
for i in range(Q):
    c,x,y=map(int,input().split())
    if c==0:
        tree.add(x,y)
    else:
        ans.append(tree.search(x,y+1,0,0,tree.n))
print('\n'.join(map(str,ans)))


Measured memory_bytes: 12664
import * as fs from 'fs';

namespace AtCoder.abc135 {

    export class Program {
        args: string[];

        constructor(args: string[]) {
            this.args = args;
        }

        /**
         * in
         * 5
         * 5 2 3 4 1
         * out
         * Yes
         */
        main(): void {
            let p: number [] = this.args[1].split(' ').map(x => parseInt(x, 10));
            const sorted: number[] = this.args[1].split(' ').map(x => parseInt(x, 10))
                .sort((a: number, b: number) => a - b);
            let cnt: number = 0;
            for (let i = 0; i < p.length; i++) {
                if (p[i] !== sorted[i]) {
                    cnt++;
                }

                if (cnt > 2) {
                    console.log('NO');
                    return;
                }
            }
            console.log('YES');
        }
    }

}

const args = fs.readFileSync('/dev/stdin', 'utf8').trim().split('\n');
const prg = new AtCoder.abc135.Program(args);
prg.main();


Measured memory_bytes: 11468
using System.Collections.Generic;
using System;

public class Hello
{
    public static void Main()
    {
        var w = "yuiophjklnm";
        var hs = new HashSet<char>();
        for (int i = 0; i < w.Length; i++) hs.Add(w[i]);
        while (true)
        {
            var s = Console.ReadLine().Trim();
            if (s == "#") break;
            var count = 0;
            var r = hs.Contains(s[0]);
            for (int i = 1; i < s.Length; i++)
                if (hs.Contains(s[i]) != r) { count++; r = !r; }
            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 9920
S=input()
if S=='SUN':
  print('7')
if S=='MON':
  print('6')
if S=='TUE':
  print('5')
if S=='WED':
  print('4')
if S=='THU':
  print('3')
if S=='FRI':
  print('2')
if S=='SAT':
  print('1')

Measured memory_bytes: 3060
n = int(input())
h = [[] for _ in range(n)]
u = [[] for _ in range(n)]
for i in range(n):
    a = int(input())
    for _ in range(a):
        x, y = map(int, input().split())
        if y == 1:
            h[i].append(x)
        elif y == 0:
            u[i].append(x)

ans = 0
for i in range(2**n):
    hs, us = set(), set()
    honest, unkind = set(), set()
    for j in range(n):
        if i & (1 << j):
            hs |= set(h[j])
            us |= set(u[j])
            honest.add(j+1)
        else:
            unkind.add(j+1)
    if not hs <= honest:
        continue
    if not us <= unkind:
        continue
    ans = max(ans, len(honest))

print(ans)

Measured memory_bytes: 9120
#include<bits/stdc++.h>
using namespace std;
int N;
string S;
long long cnt;
struct Node
{
	int R, G, B;
}F[4005], B[4005];
int main()
{
	cin >> N >> S;
	F[0].R = 0;
	F[0].G = 0;
	F[0].B = 0;
	B[N - 1].R = 0;
	B[N - 1].G = 0;
	B[N - 1].B = 0;
	for (int i = 1; i < N; i++)
	{
		F[i] = F[i - 1];
		if (S[i - 1] == 'R')
		{
			F[i].R++;
		}
		else if (S[i - 1] == 'G')
		{
			F[i].G++;
		}
		else
		{
			F[i].B++;
		}
	}
	for (int i = N - 2; i >= 0; i--)
	{
		B[i] = B[i + 1];
		if (S[i + 1] == 'R')
		{
			B[i].R++;
		}
		else if (S[i + 1] == 'G')
		{
			B[i].G++;
		}
		else
		{
			B[i].B++;
		}
	}
	for (int i = 1; i < N; i++)
	{
		if (S[i] == 'R')
		{
			cnt += F[i].G * B[i].B + F[i].B * B[i].G;
		}
		else if (S[i] == 'G')
		{
			cnt += F[i].R * B[i].B + F[i].B * B[i].R;
		}
		else
		{
			cnt += F[i].G * B[i].R + F[i].R * B[i].G;
		}
	}
	for (int i = 0; i < N; i++)
	{
		for (int j = 1; i + 2 * j < N; j++)
		{
			if (S[i] != S[i + j] && S[i] != S[i + 2 * j] && S[i + j] != S[i + 2 * j])
			{
				cnt--;
			}
		}
	}
	cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 3740
#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
//template<typename key, typename val>
//using ordered_tree =
//  tree<key, val, greater<>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long int64;
typedef complex<double> comp;
const double pi = 3.14159265358979323846;
const int inf = (int)1e+9 + 2;
const int64 inf64 = (int64)1e+18 + 2;
const double dinf = 1e+20;
const int mod = 1'000'000'007;//998244353;
const int base = 2187;
const double eps = 1e-8;
const int N = 300'000;
const int LOGN = 19;

int n, m, k;

void solve(int test)
{
  int x, y;
  cin >> n >> m >> x >> y;
  cout.precision(11);
  cout.setf(ios::fixed);
  int ok = 0;
  if (x + x == n && y + y == m) {
    ok = 1;
  }
  cout << n * 1ll * m / 2. << ' ' << ok << '\n';
}

void precalc()
{
}

int main()
{
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  precalc();
  int test = 1;
  //cin >> test;
  //auto start = chrono::high_resolution_clock::now();
  for (int i = 1; i <= test; ++i)
    solve(i);
  //cerr << chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - start).count() << '\n';
  return 0;
}


Measured memory_bytes: 256
/* ＵＴＦ－８ */
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <array>
#include <queue>
#include <stack>
#include <algorithm>
#include <tuple>
#include <numeric>
#include <type_traits>
#include <limits>

#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>

#define USE_COLORED 1

#ifdef USE_COLORED
static const char stdout_pre[]  = "\033[1m"; // bold black
static const char stderr_pre[]  = "\033[31;1m"; // bold red
static const char stdxxx_post[] = "\033[m";

// 当然ながら GCC(g++)/libstdc++ 依存
#include <ext/stdio_filebuf.h>
using stdio_filebuf = __gnu_cxx::stdio_filebuf<char>;
class colored_stdio_filebuf : public stdio_filebuf {
private:
	const char* const pre_;
	const char* const post_;

public:
	colored_stdio_filebuf(FILE* fp, const char* pre, const char* post) : stdio_filebuf(fp, std::ios_base::out), pre_(pre), post_(post)
	{
	}

protected:
	std::streamsize xsputn(const char* s, std::streamsize count) override
	{
		stdio_filebuf::xsputn(pre_, strlen(pre_));
		auto ret = stdio_filebuf::xsputn(s, count);
		stdio_filebuf::xsputn(post_, strlen(post_));
		return ret;
	}
};
#endif

int main()
{
#ifdef USE_COLORED
	if (getenv("DEBUG")) {
		std::cout.rdbuf(new colored_stdio_filebuf(stdout, stdout_pre, stdxxx_post));
		std::cerr.rdbuf(new colored_stdio_filebuf(stderr, stderr_pre, stdxxx_post));
	} else
#endif
	{
		int fd = open("/dev/null", O_WRONLY);
		dup2(fd, 2);
		close(fd);
	}
	
	int N;
	std::cin >> N;

	int fN = 0;
	int m = N;
	while (m != 0) {
		fN += m % 10;
		m /= 10;
	}
	if (N % fN == 0) {
		std::cout << "Yes\n";
	} else {
		std::cout << "No\n";
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
//#define ll long long
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define all(x) (x).begin(),(x).end()
ll tmp1,tmp2,tmp3;
const ll mod = 998244353;
const int INF = 1e9;
const ll INFLONG = 1e18;
void swap(ll *x,ll *y){
  ll tmp;
  tmp = *x;
  *x = *y;
  *y = tmp;
}
int main(){
  ll n;
  cin >> n;
  vector<ll> d(n);
  rep(i,n){
    cin >> d[i];
  }
  vector<ll> dis(n,0);
  rep(i,n){
    dis[d[i]] ++;
  }
  ll ans = 1;
  for(ll i = 1;i<n;i++){
    if(dis[i] == 0){

    }else{
      rep(j,dis[i]){
        ans = (ans * dis[i-1]) % mod;
      }
    }
  }
  if(dis[0] != 1 || d[0] != 0){
    ans = 0;
  }
  cout << ans;
}


Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<cmath>
#include<tuple>
#include<string>
typedef unsigned long long ll;
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define F first
#define S second
using namespace std;
const ll INF = 1e12;
const int i_INF = 2147483647;

int main() {
  int a,b,c;
  cin>>a>>b>>c;
  cout<<max({a*10+b+c,a+b*10+c,a+b+c*10})<<endl;
}

Measured memory_bytes: 256
//
//  main.cpp
//  payment
//
//  Created by Bryan on 05/07/20.
//  Copyright © 2020 mac. All rights reserved.
//

#include <iostream>
#include <stdio.h>
using namespace std;

int main()
{
    int N;
    scanf ("%d", &N);
    int change = N%1000;
    if (change == 0)
        printf ("0\n");
    else
        printf ("%d\n",1000-change);
}


Measured memory_bytes: 3808
///A drunk man will find his way home, but a drunk bird may get lost forever...
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef long long ll;
typedef double dd;
typedef pair <int, int> pii;
#define pb push_back
#define pf push_front
#define f first
#define s second
#define sz(x) (int)x.size()
#define smin(x , y) x = min(x , y)
#define smax(x , y) x = max(x , y)
#define mp make_pair
const int mx = 1000 * 100 + 10;
bool b[mx + 10];
vector < int > v;
int32_t main(){		
	ios_base::sync_with_stdio(false);
    cin.tie(0);
	cout.tie(0);
	for(int i = 2; i * i <= mx; i++){
		for(int j = 2 * i; j <= mx; j += i){
			if(!b[j])
				b[j] = 1;
		}
	}
	for(int i = 2; i <= mx; i++)
		if(!b[i])
			v.pb(i);
	int x;
	cin >> x;
	cout << *(lower_bound(v.begin(), v.end(), x)) << endl;
	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define REP(i,n,N) for(int i=n;i<(int)N;i++)
#define p(S) cout<<(S)<<endl
#define ck(n,a,b) (a<=(n)&&(n)<=b)
using namespace std;
const int inf=1e9;

vector<string> ans;
string str;
bool used[26];
void esdfs(string s){
	unsigned int num=s.size();
	if(num == str.size()){
		ans.push_back(s);
		return;
	}
	if(str[num]=='a'|| used[str[num]-'a']){
		esdfs(s+str[num]);
	}
	if(str[num]!='z' && !used[str[num]-'a'+1]){
		used[str[num]-'a'+1]=true;
		esdfs(s+(char)(str[num]+1));
		used[str[num]-'a'+1]=false;
	}
	return;
}
int main(){
	while(cin>>str){
		ans.clear();
		REP(i,0,26) used[i]=false;
		if(str=="#") break;
		esdfs("");
		p(ans.size());
		REP(i,0,min<int>(ans.size(),5)){
			p(ans[i]);
		}
		REP(i,max<int>(ans.size()-5,5),ans.size()){
			p(ans[i]);
		}
	}
	return 0;
}

Measured memory_bytes: 4312
#include <cstdio>
#include <cctype>
#include <cstring>
#include <algorithm>
int read(){
	register int x = 0;
	register char f = 1, ch = getchar();
	for (; !isdigit(ch); ch = getchar()) if (ch == '-') f ^= 1;
	for (; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + (ch ^ '0');
	return f ? x : -x;
}
#define N 100005
char a[N << 1], b[N];
int n, m, nx[N << 1][26];
int main(){
	scanf("%s%s", a + 1, b + 1);
	n = strlen(a + 1), m = strlen(b + 1);
	for (register int i = 1; i <= n; ++i) a[n + i] = a[i];
	for (register int i = 0; i < 26; ++i) nx[n << 1][i] = -1;
	for (register int i = (n << 1) - 1; ~i; --i){
		for (register int j = 0; j < 26; ++j) nx[i][j] = nx[i + 1][j];
		nx[i][a[i + 1] - 'a'] = i % n + 1;
	}
	int k = 0, s = 0;
	for (register int i = 1; i <= m; ++i)
		if (~nx[k][b[i] - 'a']){
			if (nx[k][b[i] - 'a'] <= k) ++s;
			k = nx[k][b[i] - 'a'];
		}
		else return printf("-1\n"), 0;
	printf("%lld\n", 1ll * s * n + k);
}

Measured memory_bytes: 20736
#include<cstdio>
#include<memory.h>
bool flag[110][110];
char map[110][110];
int ans;
int w, h, ix, iy;
bool dfs(int x,int y,char c){
	if (flag[x][y] || (x < 0) || (x >= h) || (y < 0) || (y >= w) || (map[x][y] != c))
		return false;
	flag[x][y] = true;
	dfs(x-1, y, c);
	dfs(x+1, y, c);
	dfs(x, y+1, c);
	dfs(x, y-1, c);
	return true;
}

int main(){
	while((scanf("%d%d", &h, &w) != EOF) && w && h){
		char tc;
		tc = getchar();
		for(int i = 0; i < h; i++){
			for(int j = 0; j < w; j++){
				scanf("%c", &map[i][j]);
			}
			tc = getchar();
		}
		ans = 0;
		memset(flag,0,sizeof(flag));
		for(int i = 0; i < h; i++)
			for(int j = 0; j < w; j++)
				if(dfs(i, j, map[i][j]))ans++;
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 1372
import java.util.*;

public class Main {
    public void main(Scanner sc) {
        int a1 = sc.nextInt();
        int a2 = sc.nextInt();
        int a3 = sc.nextInt();

        int max = Math.max(a1, Math.max(a2, a3));
        int min = Math.min(a1, Math.min(a2, a3));

        System.out.println(max - min);
    }

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


Measured memory_bytes: 21972
// SeeAlso: 

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define MAX 100000
#define NIL -1
#define MOD 1000000007

typedef int _loop_int;
#define rep(i,n) for(int i = 0; i < n; i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define debug(x) cout<<#x<<": "<<x<<endl
#define debig_vec(v) cout<<#v<<":";rep(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

// 最大公約数
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
// 最小公倍数
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}

#define print2D(h, w, arr) rep(i, h) { rep(j, w) cout << arr[i][j] << " "; cout << endl; }
template<class T> void print(const T& x){cout << setprecision(12) << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }

int main() {
    ll n;
    map<ll, ll> a;
    cin >> n;
    rep(i, n) {
        ll b;
        cin >> b;
        try {
            auto temp = a.at(b);
            a.erase(b);
            a.insert(make_pair(b, temp+1));
        } 
        catch (std::out_of_range) {
            a.insert(make_pair(b, 1));
        }
    }
    ll ans = 0;

    for(auto it= a.begin();it!=a.end();it++) {
        auto p = *it;
        if (p.first > p.second) {
            ans += p.second;
        } else {
            ans += p.second - p.first;
        }
    }

    print(ans);
    return 0;
}


Measured memory_bytes: 6272
A,B,C,D = map(int, input())
ans = [str(A)]
for b in [B,-B]:
    for c in [C,-C]:
        for d in [D,-D]:
            if sum([A,b,c,d]) == 7:
                ans += ['+' + str(x) if x >= 0 else str(x) for x in [b,c,d]]
                print(''.join(ans) + '=7')
                exit(0)

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

ans = 0

for i in range(1, N+1):
    x = i
    judg = 0
    for ii in range(len(str(i))):
        judg += (x % 10)
        x = x // 10    
    if A<=judg and B>=judg:
        ans += i

print(ans)    




Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);
//const ll mod = 1000000007;

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll A, B;
    cin >> A >> B;
    cout << A*(A-1)/2 + B*(B-1)/2 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
#define repr(i, s, e) for(int i=s; i>=e; i--)
#define reps(i, s, e) for(int i=s; i<e; i++)
#define inf 1e18
#define vsort(v) sort(v.begin(), v.end())
#define vsortr(v) sort(v.begin(), v.end(), greater<ll>())
#define sz(x) x.size()
#define ceil(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T &a, T b){ if(a<b){ a=b; return true; } return false; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a){ a=b; return true; } return false; }
template<typename T> T gcd(T a, T b){ if(b==0) return a; return gcd(b, a%b); }
template<typename T> T lcm(T a, T b){ return a*b/gcd(a, b); }
template<typename T> void vdebug(vector<T> v){ for(auto vv : v){ cout << vv << " "; } cout << endl; }
template<typename T> void adebug(T arr[], int n){ rep(i, n){ cout << arr[i] << " "; } cout << endl; }
void ans(bool b){ if(b) cout << "Yes" << endl; else cout << "No" << endl; }
void ans2(bool b){ if(b) cout << "YES" << endl; else cout << "NO" << endl; }
int keta(ll num){ int k=0; while(num>0){ num/=10; k++; } return k; }
int dx[] = {1, -1, 0, 0, 1, -1, 1, -1};
int dy[] = {0, 0, 1, -1, 1, -1, -1, 1};


string s;
int len;

bool rec(ll e){
    if(s[e] == 'd'){
        if(e+5 == len && s.substr(e, 5) == "dream") return true;
        if(e+7 == len && s.substr(e, 7) == "dreamer") return true;
        if(e+5 > len) return false;
        else {
            bool b1=false, b2=false;
            if(s.substr(e, 5) == "dream") b1 = rec(e+5);
            if(s.substr(e, 7) == "dreamer") b2 = rec(e+7);
            return b1 || b2;
        }
    }else if(s[e] == 'e'){
        if(e+5 == len && s.substr(e, 5) == "erase") return true;
        if(e+6 == len && s.substr(e, 6) == "eraser") return true; 
        if(e+5 > len) return false;
        else {
            bool b1=false, b2=false;
            if(s.substr(e, 5) == "erase") b1 = rec(e+5);
            if(s.substr(e, 6) == "eraser") b2 = rec(e+6);
            return b1 || b2;
        }
    }
    return false;
}

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

    cin >> s;
    len = s.length();

    bool res = rec(0);
    ans2(res);

    return 0;
}


Measured memory_bytes: 2128
# ALDS1_2_C - Stable Sort
def main():
    N, *A = open(0).read().split()
    N = int(N)
    B = A.copy()
    # bubble sort
    for i in range(N):
        for j in range(N - 1, i, -1):
            if A[j][1] < A[j - 1][1]:
                A[j], A[j - 1] = A[j - 1], A[j]
    print(*A)
    print("Stable")

    # selection sort
    for i in range(N):
        mi = i
        for j in range(i, N):
            if B[j][1] < B[mi][1]:
                mi = j
        B[i], B[mi] = B[mi], B[i]
    print(*B)
    flg = B == A
    print("Stable" if flg else "Not stable")


if __name__ == "__main__":
    main()


Measured memory_bytes: 5612
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,a,b;
    cin>>n>>a>>b;
    if((b-a)%2==0)
        cout<<(b-a)/2<<endl;
    else
      cout<<min((a+(((b-a)-1)/2)),((n-b+1)+(b-a-1)/2))<<endl;
    return 0;
}


Measured memory_bytes: 3644
local a, b, k = io.read("*n", "*n", "*n")
local z = {}
local t = {}
for i = a, b do
  if i < a + k then
    table.insert(t, i)
    z[i] = true
  else
    break
  end
end
for i = b, a, -1 do
  if b < i + k then
    if not z[i] then table.insert(t, i) end
  else
    break
  end
end
table.sort(t)
print(table.concat(t, "\n"))


Measured memory_bytes: 880
import sys

input = sys.stdin.readline

def main():
    N = int(input())
    
    Id = {}
    
    cur = 0
    for i in range(1, N+1):
        for j in range(i+1, N+1):
            Id[(i,j)] = cur
            cur += 1
            
    G = [[] for i in range(N*(N-1)//2)]
    size = [0] * (N*(N-1)//2)
    
    for i in range(1, N+1):
        for idx, j in enumerate(list(map(int, input().split()))):
            if i < j: k = Id[(i, j)]
            else: k = Id[(j, i)]
            if idx: 
                G[par].append(k)
                size[k] += 1
            par = k
            
    g = [idx for idx, s in enumerate(size) if s == 0]
    
    ans = 0
    while g:
        ans += 1
        n_g = []
        
        for v in g:
            length = len(G[v])
            if not length: continue
            
            size[G[v][0]] -= 1
            if not size[G[v][0]]: n_g.append(G[v][0])
    
            if length == 2:
                size[G[v][1]] -= 1
                if not size[G[v][1]]: n_g.append(G[v][1])
        g = n_g
        
    for s in size:
        if s != 0:
            print(-1)
            sys.exit()
    print(ans)
            
if __name__ == '__main__':
    main()

Measured memory_bytes: 153060
import java.util.Scanner;


public class Main {


	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();

		boolean[] flgM = new boolean[N];
		int[] intN = new int[N];
		boolean NG = false;
		for(int i = 0; i < M; i++) {
			int s = sc.nextInt();
			int c = sc.nextInt();

			if(flgM[s-1] == false || intN[s-1] == c) {
				intN[s-1] = c;
				flgM[s-1] = true;
			} else {
				NG = true;
			}
		}
		if(NG) {
			System.out.println(-1);
		} else {
			int result = 0;
			int kakeru = 1;
			for(int i = N-1; i >= 0; i--) {
				result = result + intN[i] * kakeru;
				if(N > 1 && i == 0 && flgM[i] == false) result = result + 1 * kakeru;
				kakeru = kakeru * 10;
			}
			if(String.valueOf(result).length() != N) {
				result = -1;
			}
			System.out.println(result);
		}
	}

}

Measured memory_bytes: 22612
from collections import Counter
n = int(input())
v = list(map(int, input().split()))

a = Counter(v[::2]).most_common()
b = Counter(v[1::2]).most_common()
a.append([0,0])
b.append([0,0])
if a[0][0] != b[0][0]:
    print(n-(a[0][1] + b[0][1]))
else:
    print(min(n-(a[1][1] + b[0][1]), n-(a[0][1]+b[1][1])))

Measured memory_bytes: 20700
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
use std::collections::HashMap;
use std::cmp::{max,min};

fn main(){
    input!{
        n:i64,
    }
    let mut ans = 0;
    let d = vec![3,5,7];
    for &a in &d {
        ans += recv(a,&n);
    }
    println!("{}",ans);
}
fn recv(num:i64,n:&i64) -> i64 {
    let v = vec![3,5,7];
    if num > *n {return 0}
    let mut ans = if v.iter().all(|&j| num.to_string().chars().filter(|&c| c == std::char::from_digit(j as u32 ,10).unwrap()).count() != 0) {1} else {0};
    for &a in &v {
        let x = num*10 + a;
        ans +=  recv(x,n);
    }
    ans
} 

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //GCC5.4.1で配列の範囲外アクセスをエラーにする

//cmdで g++ test.cpp とするとコンパイルできる
//制限1秒なら10^6は余裕 10^7は多分間に合う 10^8はよほど単純でないと厳しい
// https://github.com/atcoder/live_library
// cppdbg: test.exeのterminalに標準入力を打てる

#define ALL(x) x.begin(),x.end()
#define get_tp(t,i) get<i>(t)
#define len(x) (ll)(x.size())
#define ub(a,x) (upper_bound(ALL(a),x)-a.begin())
#define lb(a,x) (lower_bound(ALL(a),x)-a.begin())
typedef long long ll; //long long
typedef pair<int,int> pii; //pair<int,int>
typedef pair<long long,long long> pllll; //pair<ll,ll>
typedef vector<int> vi; //vector<int>
typedef vector<vector<int>> vvi; //vector<vector<int>>
typedef vector<ll> vll; //vector<long long>
typedef vector<vector<ll>> vvll; //vector<vector<long long>>
typedef priority_queue<ll, vector<ll>, greater<ll> > gpq; //逆順priority_queue
typedef priority_queue<ll> pq;

//const int MOD=998244353;
const int MOD=1000000007; //10^9+7
const long double PI=3.1415926535897932;

int main(){
    int x,a,b;cin>>x>>a>>b;
    cout<<(x-a)%b<<endl;
}

Measured memory_bytes: 3556
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <numeric>
#include <complex>
#include <iomanip>
#include <cassert>
#include <random>


int main() {
    int n; std::cin >> n;
    std::vector<long long> x(n), y(n), u(n), v(n);
    for (int i = 0; i < n; i++) {
        std::cin >> x[i] >> y[i];
        u[i] = x[i] + y[i];
        v[i] = x[i] - y[i];
    }
    bool flag = true;
    for (int i = 0; i < n - 1; i++) {
        flag &= (u[i] & 1) == (u[i + 1] & 1);
    }
    if (!flag) {
        std::cout << -1 << std::endl;
        return 0;
    }

    std::vector<long long> d;
    for (int i = 0; i < 39; i++) d.push_back(1LL << i);
    long long dsum = std::accumulate(d.begin(), d.end(), 0LL);
    if (~u[0] & 1) d.push_back(1);

    std::cout << d.size() << std::endl;
    for (int i = 0; i < (int)d.size(); i++)
        std::cout << d[i] << " \n"[i == (int)d.size() - 1];

    std::vector<char> com = { 'L', 'U', 'D', 'R' };
    for (int t = 0; t < n; t++) {
        long long tu = (x[t] + y[t] + dsum) / 2;
        long long tv = (x[t] - y[t] + dsum) / 2;
        std::string ans = "";
        for (int i = 0; i < 39; i++) {
            bool uflag = (tu & d[i]) != 0;
            bool vflag = (tv & d[i]) != 0;
            ans += com[uflag + 2 * vflag];
        }
        if (~u[0] & 1) ans += 'R';
        std::cout << ans << std::endl;
    }
    return 0;
}

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

using namespace std;

#define all(c) (c).begin(), (c).end()
#define sz(c) (static_cast<int>(c.size()))
#define endl "\n"

using ld = long double;
using ll = long long;

template <typename T, typename Z> inline T power(T base, Z exponent)
{
    T ret = 1;
    for (; exponent > 0; exponent >>= 1, base *= base)
        if (exponent & 1) ret *= base;
    return ret;
}
template <typename Z> Z gcd(const Z& a, const Z& b)
{
    if (b == 0) return a;
    return gcd(b, a % b);
}
template <typename Z> Z extended_gcd(const Z& a, const Z& b, Z& x, Z& y)
{
    if (b == 0) return x = 1, y = 0, a;
    Z gcd = extended_gcd(b, a % b, y, x);
    y -= (a / b) * x;
    return gcd;
}
#ifdef DEBUG
template <typename... T>
void debug(T&&... args)
{
    ((cerr << args << " "), ..., (cerr << endl));
}
#else
template <typename... T> void debug(T&&... args) {}
#endif
#define vardump(...) #__VA_ARGS__":", (__VA_ARGS__)
// }}}

const ll INFL = numeric_limits<ll>::max() / 2;
const ll INF = numeric_limits<int>::max() / 2;
const ll MOD = 1e9+7;

const int N = 1e3 + 5;
const int W = 1e4 + 5;

int w[N], s[N], v[N];
int tw[N], ts[N], tv[N];
ll dp[W];

void solve()
{
    int n; cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> w[i] >> s[i] >> v[i];
    }
    vector<int> idx, loc;
    for (int i = 0; i < n; i++) idx.push_back(i);
    for (int i = 0; i < n; i++) loc.push_back(i);
    sort(all(idx), [](int i, int j) {
        return min(s[i]-w[j], s[j]) > min(s[j]-w[i], s[i]);
    });
    for (int i = 0; i < n; i++) tw[i] = w[idx[i]], ts[i] = s[idx[i]], tv[i] = v[idx[i]];
    for (int i = 0; i < n; i++) w[i] = tw[i], s[i] = ts[i], v[i] = tv[i];
    for (int i = 0; i < n; i++) {
        debug(w[i], s[i], v[i]);
    }
    for (int j = 0; j < W; j++) dp[j] = -INFL;
    ll ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < W; j++) {
            if (j-w[i] < 0) continue;
            int nw = min(j-w[i], s[i]);
            dp[nw] = max(dp[nw], dp[j] + v[i]);
            /* debug(i, dp[nw], nw); */
        }
        dp[s[i]] = max(dp[s[i]], (ll)v[i]);
        for (int j = 0; j < W; j++) {
            ans = max(ans, dp[j]);
        }
    }
    cout << ans << endl;
}

// main {{{
int main()
{
    cin.sync_with_stdio(0); cin.tie(NULL);
    solve();
    return 0;
}
// }}}



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

ll solve() {
    ll N;
    cin >> N;
    string S;
    cin >> S;

    map<char,ll> m = {{'R',0},{'G',1},{'B',2}};
    vector<ll> n(3);
    for ( char c : S) {
        n[m[c]]++;
    }
    ll ans = n[0]*n[1]*n[2];

    ll ng = 0;
    for ( int k = 1; k < 2001; k++ ) {
        for ( int i = 0; i < N; i++ ) {
            int i1 = i, i2 = i+k, i3 = i+2*k;
            if ( i3 >= N ) continue;
            if ( S[i1] != S[i2] && S[i1] != S[i3] && S[i2] != S[i3] ) ng++;
        }
    }
    ans -= ng;

    return ans;
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 3636
#include<stdio.h>
int main(){
  int unused __attribute__((unused));
  int X, A, B;
  unused = scanf("%d", &X);
  unused = scanf("%d", &A);
  unused = scanf("%d", &B);

  X = X - A;
  if(X > 0){
    do{
      X = X - B;
    }while(X >= B);
  }
  printf("%d", X);
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<string>str(n);
  for(int i=0;i<n;i++)cin>>str.at(i);
  sort(str.begin(),str.end());
  
  int counter=1;
  for(int i=1;i<n;i++){
    if(str.at(i)!=str.at(i-1))counter++;
  }
  cout<<counter<<endl;
}
  

Measured memory_bytes: 9544
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,-1,0,1},dy={1,0,-1,0};
bool inside(int y,int x,int h,int w){
	if(y<h && y>=0 && x<w && x>=0) return true;
	return false;
}





int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,k,q;cin >> n >> k >> q;
	vector<int> a(n);
	rep(i,q){
		int b;cin >> b;
		a.at(b-1)++;
	}
	rep(i,n){
		if(q - a.at(i) >= k) cout << "No" << endl;
		else cout << "Yes" << endl;
	}
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

int N, K;

bool check(double x, vector<int> A) {
    // x以下の長さに切ることが可能ならtrueを返す
    int cnt = 0;
    rep(i, N) {
        cnt += (A[i] + x - 1) / x - 1;
    }
    return cnt <= K;
}

int main() {
    // 二分探索
    cin >> N >> K;
    vector<int> A(N);
    rep(i, N) cin >> A[i];
    if (K == 0) {
        int x = 0;
        rep(i, N) x = max(x, A[i]);
        cout << x << '\n';
        return 0;
    }
    int ok = 1e9; int ng = 0;
    while (abs(ng - ok) > 1) {
        int mid = (ok + ng) / 2;
        if (check(mid, A)) ok = mid;
        else ng = mid;
    }
    cout << ok << '\n';
    return 0;
}


Measured memory_bytes: 4692
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
	public static void main(String[] args) {

		ALDS1_5_B();
	}
	//Merge Sort
	public static void ALDS1_5_B() {
		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();

		class MG{
			int cnt = 0;
			void MergeSort(int n, int A[], int left, int right) {
				if(left + 1 < right) {
					int mid = (left + right) / 2;
					MergeSort(n, A, left, mid);
					MergeSort(n, A, mid, right);
					Merge(n, A, left, mid, right);
				}
			}

			void Merge(int n, int[] A, int left, int mid, int right) {
				int[] L = new int[mid - left + 1];
				int[] R = new int[right - mid + 1];
				for(int i = 0; i < (mid - left); i++) {
					L[i] = A[(left + i)];
				}
				for(int i = 0; i < (right - mid); i++) {
					R[i] = A[(mid + i)];
				}
				L[mid - left] = Integer.MAX_VALUE;
				R[right - mid] = Integer.MAX_VALUE;
				int i = 0, j = 0;
				for(int k = left; k < right; k++) {
					cnt++;
					if(L[i] > R[j]) {
						A[k] = R[j++];
					}else {
						A[k] = L[i++];
					}
				}
			}
		}
		
		MG mg = new MG();
		mg.MergeSort(n, A, 0, n);
		for(int i = 0; i < n; i++) {
			if(i != 0)
				System.out.print(" ");
			System.out.print(A[i]);
		}
		System.out.println();
		System.out.println(mg.cnt);
	}
}


Measured memory_bytes: 169844
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define rep(i,n); for(long long i = 0;i < (n);i++)
using ll = long long;
using P = pair<long long,long long>;
template <class T> using vec = vector<T>;


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n; cin >> n;
    map<ll,ll> mp;
    ll sum = 0;
    rep(i,n){
        ll a; cin >> a;        
        mp[a]++;
        sum += a;
    }
    ll q; cin >> q;
    rep(i,q){
        ll b,c; cin >> b >> c;
        sum += (c - b) * mp[b];
        mp[c] += mp[b];
        mp[b] = 0;
        cout << sum << endl;
    }
}

Measured memory_bytes: 9460