akhauriyash/Code-Regression huggingface dataset:
use proconio::input;

type Graph = Vec<Vec<usize>>;

fn dfs(v:usize,pre:usize,g:&Graph,sz:&mut Vec<usize>){
    for &to in &g[v] {
        if to==pre {
            continue;
        }
        sz[to] = sz[v]+1;
        dfs(to,v,&g,sz);
    }
}


fn main() {
    input!{
        n:usize,
        ab:[(usize,usize);n-1]
    };

    let mut g = vec![Vec::<usize>::new();n];
    for (a,b) in ab {
        g[a-1].push(b-1);
        g[b-1].push(a-1);
    }

    let mut sz = vec![0;n];
    dfs(0,n,&g,&mut sz);

    let mut oddcnt = 0;
    for &s in &sz {
        if s%2==1 {
            oddcnt+=1;
        }
    }
    let evcnt = n - oddcnt;

    let unb = |b:usize| {
        let mut rest_1 = (n+2)/3;
        let mut rest_2 = (n+1)/3;
        let mut ans = vec![0;n];
        for i in 0..n {
            if sz[i]%2==b {
                ans[i] = 3;
            }
            else {
                if rest_1>0 {
                    ans[i] = 1;
                    rest_1 -=1;
                }
                else if rest_2>0{
                    ans[i] = 2;
                    rest_2  -= 1;
                }
                else{
                    ans[i] = 3;
                }
            }
        }
        ans
    };
    let bal=||{
        let mut rest_1 = (n+2)/3;
        let mut rest_2 = (n+1)/3;
        let mut ans = vec![0;n];
        for i in 0..n {
            if sz[i]%2==0 {
                if rest_1>0 {
                    rest_1-=1;
                    ans[i] = 1;
                }
                else{
                    ans[i] = 3;
                }
            }
            else {
                if rest_2>0 {
                    rest_2-=1;
                    ans[i] = 2;
                }
                else{
                    ans[i] = 3;
                }
            }
        }
        ans
    };
    let transform = |ans:&mut Vec<usize>|  {
        let mut ary = [3,1,2];
        for x in ans {
            *x = ary[*x%3];
            ary[*x%3]+=3;
        }
    };

    let mut ans = 
        if oddcnt<=n/3 {
            unb(1)
        }
        else if evcnt<=n/3 {
            unb(0)
        }
        else{
            bal()
        };

    transform(&mut ans);
    
    println!("{}",ans.iter().map(|&x|x.to_string()).collect::<Vec<String>>().join(" "));
    
}



Measured memory_bytes: 33308
#include <bits/stdc++.h>
using namespace std;
int main() {
	string s;
	cin >> s;
	int num = s.length();
	int ans = 100000;
	for (int i = 0; i < num - 2; i++) {
		string x = s.substr(i, 3);
		int y = stoi(x);
		y = 753 - y;
		int res = abs(y);
		ans = min(ans, res);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;


int main(){
  ll X;
  cin >> X;
  
  for(ll x = -10000; x <= 10000; x++){
    for(ll y = -10000; y <= 10000; y++){
      double dx = x;
      double dy = y;
      if(abs(dx*dx*dx*dx*dx) > 1e15) continue;
      if(abs(dy*dy*dy*dy*dy) > 1e15) continue;
      
      ll A5 = x*x*x*x*x;
      ll B5 = y*y*y*y*y;

      if(A5 - B5 == X){
        cout << x << " " << y << endl;
        return 0;
      }
    }
  }
  
  return 0;
}


Measured memory_bytes: 3636
n,k = map(int, raw_input().split())
lis = map(int, raw_input().split())
if 0 in lis:
    k-=1
flag=0
#print lis
if k==0:
    print 0
    flag=1
if n==1 and flag==0:
    print abs(lis[0])
    flag=1
if flag==0:
    if lis[0]>0: # all positives
        print lis[k-1]
    elif lis[n-1]<0: #all negatives
        print abs(lis[n-k])
    else:
        idx = -1
        for i in range(0, n-1):
            if lis[i]<0 and lis[i+1]>=0:
                idx = i
                break
        #print idx
        lol =[]
        x=0
        lol.append(abs(lis[idx]))
        for i in range(idx-1,-1,-1):
            lol.append(lol[x]+abs(lis[i]))
            x+=1
        #print lol
        lol1=[]
        x=0
        lol1.append(lis[idx+1])
        for i in range(idx+2,n,1):
            lol1.append(lol1[x]+(lis[i]))
            x+=1
        #print lol1

        lol=lol[::-1]
        lol3=[]
        for i in lol:
            lol3.append(i)
        for i in lol1:
            lol3.append(i)
        #print lol3
        
        ans=10000000000000000000000000000000000000000000
        lol=lol[::-1]


        lol =[]
        x=0
        lol.append(abs(lis[idx]))
        for i in range(idx-1,-1,-1):
            lol.append(abs(lis[i]))
            x+=1
        #print lol
        lol1=[]
        x=0
        lol1.append(lis[idx+1])
        for i in range(idx+2,n,1):
            lol1.append((lis[i]))
            x+=1
        #print lol1
        #print lol
        if k<=len(lol):
            ans=min(ans, lol[k-1])
        if k<=len(lol1):
            ans=min(ans, lol1[k-1])
        for i in range(1,len(lol)+1):
            fromright=k-i
            if fromright>len(lol1):
                continue
            val=2*lol[i-1]
            val+=(lol1[fromright-1])
            #print "val=",val
            if val<ans:
                ans=val
        
        for i in range(1,len(lol1)+1):
            fromleft=k-i
            if fromleft>len(lol):
                continue
            val=2*lol1[i-1]
            val+=(lol[fromleft-1])
            #print "val=",val
            if val<ans:
                ans=val
        print ans


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

int main(void){

   long long a, b, c, k;
   cin >> a >> b >> c >> k;
   
   long long ans;
   if (k % 2 == 0){
      ans = a - b;
      if(abs(ans) > 10e18)
         cout << "Unfair" << endl;
      else cout << ans << endl;
      return 0;
   }
   ans = b - a;
   if (abs(ans) > 10e18)
      cout << "Unfair" << endl;
   else cout << ans << endl;
   return 0;

}

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

const int INF=1e9+5;

int main()
{
    int n;
    cin>>n;
    vector<int>h(n);
    for(int i=0;i<n;i++)
    {
        cin>>h[i];
    }
    vector<int>dp(n,INF);
    dp[0]=0;
  	dp[1]=abs(h[1]-h[0]);
    for(int i=2;i<n;i++)
    {
        dp[i]=min(dp[i-2]+abs(h[i]-h[i-2]),dp[i-1]+abs(h[i]-h[i-1]));
    }
    cout<<dp[n-1];
	return 0;
}

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

#define ll long long
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ld long double

#define Rep(i,n) for(int i = 0; i < (n); ++i)
#define Repd(i,n) for(int i = (n)-1; i >= 0; --i)
#define For(i,a,b) for(int i = (a); i <= (b); ++i)
#define Ford(i,a,b) for(int i = (a); i >= (b); --i)
#define Fit(i,v) for(__typeof((v).begin()) i = (v).begin(); i != (v).end(); ++i)
#define Fitd(i,v) for(__typeof((v).rbegin()) i = (v).rbegin(); i != (v).rend(); ++i)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define sz(a) ((int)(a).size())
#define all(a) (a).begin(), (a).end()
#define ms(a,x) memset(a, x, sizeof(a))

using namespace std;

#include <bits/stdc++.h>

using namespace std;

const int nm = 62;
const ll mod = 1000000007;
const int mm = 300010;

int n;
ll a[mm];
int cnt[nm][2];
ll powmod[nm];

int main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
#endif
    powmod[0] = 1;
    for (int i = 1; i < nm; ++i) {
    	powmod[i] = (powmod[i - 1] * 2) % mod;
    }
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) {
    	scanf("%lld", &a[i]);
    }
    for (int i = 1; i <= n; ++i) {
    	for (int j = 0; j < nm; ++j) {
    		cnt[j][(a[i] >> j) & 1]++;
    	}
    }
    ll res = 0;
    for (int i = 0; i < nm; ++i) {
    	ll tmp = ((ll) cnt[i][0] * cnt[i][1]) % mod;
    	tmp = (tmp * powmod[i]) % mod;
    	res = (res + tmp) % mod;
    }
    printf("%lld\n", res);
#ifdef LOCAL
    cout << (double) clock() / CLOCKS_PER_SEC << "\n";
#endif
}


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

#define llint long long int

using namespace std;

int main()
{
    int N, M;

    cin >> N >> M;

    vector<int> city(N + 1);

    for (int i = 1; i <= N; i++)
    {
        city[i] = -i;
    }
    for (int i = 0; i < M; i++)
    {
        int A, B;

        cin >> A >> B;

        int city_A = city[A];
        int city_B = city[B];

        while (city_A >= 0)
        {
            city_A = city[city_A];
        }
        while (city_B >= 0)
        {
            city_B = city[city_B];
        }
        if (-city_A < -city_B)
        {
            city[-city_B] = -city[-city_A];
        }
        else if (-city_B < -city_A)
        {
            city[-city_A] = -city[-city_B];
        }
    }
    int count = 0;

    for (int i = 1; i <= N; i++)
    {
        if (city[i] < 0)
        {
            count++;
        }
    }
    cout << count - 1 << endl;
}

Measured memory_bytes: 3788
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll MOD = 1000000007;
constexpr ll INF = 1ll<<60;


int main(int argc, char **argv)
{
	ll N, K; cin >> N >> K;
	vector<ll> A(N); for (ll i = 0; i < N; ++i) cin >> A[i];
	vector<ll> imo(2010, 0);
	for (ll i = 0; i < N; ++i)
		imo[A[i]]++;
	for (ll i = 2005; i >= 1; --i)
		imo[i] = imo[i] + imo[i+1];


	ll tmp1{0};
	for (ll i = 0; i < N; ++i)
	{
		for (ll j = 0; j < i; ++j)
		{
			if (A[j] > A[i])
				(++tmp1)%=MOD;
		}
	}

	ll tmp2{0};
	for (ll i = 0; i < N; ++i)
		(tmp2 += imo[A[i]+1])%=MOD;


	auto f = [](ll a, ll d, ll n)
			 {
				 return ((2*a+(n-1)*d)*n)/2;
			 };
	
	std::cout << ((f(1, 1, K-1)%MOD*tmp2)%MOD + (K*tmp1)%MOD)%MOD << std::endl;
}
 

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

using namespace std;

int dirs[4][2]={{-1,0},{1,0},{0,-1},{0,1}};
//int dirs[8][2]={{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}};


int main()
{
    ios::sync_with_stdio(false);
    //freopen("inp.in","r",stdin);
    //freopen("outp.out","w",stdout);
    vector<string> days;
    days.push_back("SUN");
    days.push_back("MON");
    days.push_back("TUE");
    days.push_back("WED");
    days.push_back("THU");
    days.push_back("FRI");
    days.push_back("SAT");
    string now;
    cin >> now;
    int idx=-1;
    for(int i=0; i<days.size(); i++)
    {
        if(days[i]==now) idx=i;
    }
    int ans=7-idx;
    cout << ans << endl;
    return 0;
}


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

#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define FORR(i,m,n) for(int i=m;i>=n;i--)
#define pb(x) push_back(x) 
#define SORT(x) sort((x).begin(),(x).end())
#define INF 999999999999999

using namespace std;

#define int long long

int32_t main(){
	int h, w;
	cin >> h >> w;
	string str[h];
	REP(i, h) cin >> str[i];
	
	REP(i, h-1){
		REP(j, w-1){
			bool flag=false;
			FOR(k, j+1, w){
				if(str[i][k]=='#') flag=true;
			}
			FOR(k, i+1, h){
				if(str[k][j]=='#' && flag){
					cout << "Impossible" << endl;
					return 0;
				}
			}
		}
	}
	
	cout << "Possible" << endl;
}

Measured memory_bytes: 256
N,x=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
happy=0
for i in range(N-1):
    if a[i]<=x:
        x-=a[i]
        happy+=1
    else:
        break
if a[N-1]==x:
    happy+=1
print(happy)

Measured memory_bytes: 9048
import scala.io.{StdIn => in}

object Main extends App {
  val n = in.readInt

  def rec(acc:Int, i:Int):(Int, Int) = {
    if(acc >= n) (i-1, acc - n)
    else rec(acc+i, i+1)
  }

  val (num, rem) = rec(0, 1)

  val out = new java.io.PrintWriter(System.out)
  (1 to num).filter(_ != rem).foreach(out.println)
  out.flush
}

Measured memory_bytes: 27216
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int a,b;
  cin>>a>>b;
  int c=a+b;
  int d=a-b;
  int e=a*b;
  if(c>=d && c>=e)
  {
   cout<<c<<endl; 
  }
  else if(d>=e && d>=c)
  {
   cout<<d<<endl; 
  }
  else
  {
    cout<<e<<endl;
  }
}

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

#define each(i, c) for (auto& i : c)
#define mkp(a, b) make_pair(a, b)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> Pll;
const ll MOD = 1e9+7;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << ": " << p.second << ")"; return os; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ", "; os << ")"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; each (i, m) os << i << ", "; os << "}"; return os; }

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

  vector<ll> sum(s.size()+1);
  ll ten = 1;
  for (ll i = s.size()-1; i >= 0; --i) {
    ll n = s[i]-'0';
    sum[s.size()-i] = (ten * n) % 2019;
    ten = ten * 10 % 2019;
  }
  for (ll i = 1; i <= s.size(); ++i) {
    sum[i] += sum[i-1];
    sum[i] = sum[i] % 2019;
  }

  map<ll, ll> m;
  for (ll i = 0; i <= s.size(); ++i) {
    m[sum[i]]++;
  }

  ll ans = 0;
  each (i, m) {
    if (i.second >= 2) {
      ans += (i.second*(i.second-1))/2;
    }
  }

  cout << ans << endl;

  
  return 0;
}


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

using namespace std;
#define  ll long long
#define ld long double
#define f first
#define s second

ll a[2000005];

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

    ll n,k;
    cin >> n >> k;

    for(int i=1; i<=n; i++)
        cin >> a[i];

    sort(a+1 , a+n+1);
    ll mn = 1e18;
    for(int i=1; i+k-1<=n; i++)
    {
        mn = min(mn , a[i+k-1]-a[i]);
    }

    cout << mn << "\n";

    return 0;
}

Measured memory_bytes: 1024
N,M=map(int,input().split())
ac=0
wa=0
a=[0]*N
w=[0]*N
for i in range(M):
    P,S=input().split()
    P=int(P)
    if S=="WA":
        w[P-1]+=1
    else:
        if a[P-1]==0:
            a[P-1]+=1
            ac=ac+1
            wa+=w[P-1]
        else:
            pass
print(ac,wa)

Measured memory_bytes: 4596
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**6) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n,m = li()

INF = float("inf")
graph = [[] for _ in range(n)]

for _ in range(m):
    u,v,s = li()
    u -= 1
    v -= 1
    graph[u].append((v, s))
    graph[v].append((u, s))
    
a = [INF]*n
b = [INF]*n
a[0] = 1
b[0] = 0

def dfs(graph, cur, x):
    for nex, edge in graph[cur]:
        if a[nex] == INF:
            a[nex] = -a[cur]
            b[nex] = edge - b[cur]
            
            res, x = dfs(graph, nex, x)
            
            if not res:
                return False, None
            
        else:
            atemp = -a[cur]
            btemp = edge - b[cur]
            
            if atemp == a[nex]:
                if btemp != b[nex]:
                    return False, None
                
            else:
                if x is not None:
                    if (atemp * x + btemp != a[nex] * x + b[nex])\
                    or (atemp * x + btemp) <= 0:
                        return False, None
                    
                else:
                    if (btemp-b[nex])%(a[nex]-atemp) > 0\
                    or (btemp-b[nex])//(a[nex]-atemp) <= 0:
                        return False, None
                    
                    else:
                        x = (btemp-b[nex])//(a[nex]-atemp)

    return True, x

def find_range(a, b):
    upper = INF
    lower = -INF
    for ai, bi in zip(a,b):
        if ai < 0:
            upper = min(upper, bi)
        else:
            lower = max(lower, -bi)
            
    return max(0, upper-lower-1)

def confirm(a, b, x):
    for ai, bi in zip(a,b):
        if ai*x + bi <= 0:
            return 0
        
    return 1

res, x = dfs(graph, 0, None)

if not res:
    print(0)
    
elif x is not None:
    print(confirm(a,b,x))
    
else:
    print(find_range(a,b))

Measured memory_bytes: 138824
import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;

class Team implements Comparable<Team>{
	int id;
	int syo;
	int slove;
	int penalty;
	Team(int a,int b,int c,int d){
		id=a;
		syo=b;
		slove=c;
		penalty=d;
	}
	@Override
	public int compareTo(Team o) {
		if(o.slove < this.slove){
			return -1;
		}
		else if(o.slove > this.slove){
			return 1;
		}
		else{
			if(o.penalty > this.penalty){
				return -1;
			}
			else if(o.penalty < this.penalty){
				return 1;
			}
			else{
				if(o.id > this.id){
					return -1;
				}
				else if(o.id < this.id){
					return 1;
				}
			}
		}
		return 0;
	}
}

public class Main {
	public static void main(String[] args) {
		new Main().run();
	}
	void run(){
		Scanner sc=new Scanner(System.in);
		while(true){
			int n=sc.nextInt();
			if(n==0) break;
			Team t[]=new Team[n];
			for(int i=0; i<n; i++){
				t[i]=new Team(sc.nextInt(),sc.nextInt(),sc.nextInt(),sc.nextInt());
			}
			Arrays.sort(t);
			
//			for(int i=0; i<n; i++){
//				System.err.println(t[i].id);
//			}
			
			int senbatsu[]=new int[n];
			HashMap<Integer, Integer> h=new HashMap<Integer, Integer>();
			int count=0;
			for(int i=0; i<n; i++){
				if(count<10){
					if(!h.containsKey(t[i].syo)){
						h.put(t[i].syo, 1);
						senbatsu[count]=t[i].id;
						count++;
					}
					else if(h.get(t[i].syo) < 3){
						int temp=h.get(t[i].syo);
						h.put(t[i].syo, temp+1);
						senbatsu[count]=t[i].id;
						count++;
					}
				}
				else if(count<20){
					if(!h.containsKey(t[i].syo)){
						h.put(t[i].syo, 1);
						senbatsu[count]=t[i].id;
						count++;
					}
					else if(h.get(t[i].syo) < 2){
						int temp=h.get(t[i].syo);
						h.put(t[i].syo, temp+1);
						senbatsu[count]=t[i].id;
						count++;
					}
				}
				else if(count<26){
					if(!h.containsKey(t[i].syo)){
						h.put(t[i].syo, 1);
						senbatsu[count]=t[i].id;
						count++;
					}
				}
			}
			//Arrays.sort(senbatsu, 0, count);
			for(int i=0; i<count; i++){
				System.out.println(senbatsu[i]);
			}
		}
	}

}

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

int main(){
  int n,m,x;
  cin >> n >> m >> x;
  vector<int> a(m);
  rep(i,m) cin >> a[i];
  int left=0;
  int right=0;
  rep(i,m){
    if(a[i]<x) left++;
    else right++;
  }
  if(left>=right) cout << right << endl;
  else cout << left << endl;
}

Measured memory_bytes: 256
#pragma region
#include <assert.h>
#include <math.h>

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#define pb push_back
#define f(i, a, b) for (int i = a; i < b; i++)
#define revf(i, b, a) for (int i = b; i >= a; i--)
#define all(v) v.begin(), v.end()
#define srt(v) sort(v.begin(), v.end())
#define revsrt(v) sort(v.rbegin(), v.rend())
#define sp << ' ' <<
#define en << '\n'
#define precision(x) cout << fixed << setprecision(x);

using namespace std;

template <typename T, typename U>
ostream &operator<<(ostream &os, pair<T, U> &v) {
  os << "{" << v.first << ", " << v.second << "}" en;
  return os;
}

template <typename T> ostream &operator<<(ostream &os, set<T> &v) {
  for (T t : v)
    os << t << " ";
  os en;
  return os;
}

template <typename T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (T t : v)
    os << t << " ";
  os en;
  return os;
}

template <typename T> istream &operator>>(istream &is, vector<T> &v) {
  int n = v.size();
  for (int i = 0; i < n; i++)
    is >> v[i];
  return is;
}

#define int long long
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef vector<vpii> vvpii;
#pragma endregion

int mod = 1e9 + 7; // 998244353;
const int MAX = 1e5 + 5;

int power(int e, int n) {
  int x = 1, p = e;
  while (n) {
    if (n & 1)
      x = (x * p) % mod;
    p = (p * p) % mod;
    n >>= 1;
  }
  return x;
}

void preprocessing() {}

void solvetestcase() {
  int n;
  cin >> n;
  if (n == 1) {
    cout << 0 en;
    return;
  }
  int ans = power(10, n);
  ans = (ans - 2 * power(9, n)) % mod;
  ans += mod;
  ans %= mod;
  ans += power(8, n);
  ans %= mod;
  cout << ans << endl;
}

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

  preprocessing();

  int t = 1;
  // UNCOMMENT FOR TESTCASES	\
	cin >> t;

  f(T, 1, t + 1) {
    // UNCOMMENT FOR CODEJAM,HACKERCUP	\
		cout << "Case #" << T << ": ";
    solvetestcase();
    cout.flush();
  }

  return 0;
};

/*
    AUTHOR:     KUNAL TAWATIA
    EDUCATION:  INDIAN INSTITUTE OF TECHNOLOGY, JODHPUR
*/


Measured memory_bytes: 3620
#include <iostream>
#include <stdlib.h>
#include <iomanip>
using namespace std;
 
int main() {
    int n;
    cin >> n;
    int cards[4][13];
    for (int i = 0; i < 4; ++i){
        for (int j = 0; j < 13; ++j){
            cards[i][j] = 0;
        }
    }

    char str;
    int num;
    for (int k = 0; k < n; ++k)
    {
        cin >> str >> num;
        if (str == 'S')
         {
             cards[0][num-1] = 1;
         } 
        else if (str == 'H')
         {
             cards[1][num-1] = 1;
         } 
        else if (str == 'C')
         {
             cards[2][num-1] = 1;
         } 
        else if (str == 'D')
         {
             cards[3][num-1] = 1;
         } 
    }

    for (int i = 0; i < 4; ++i){
        for (int j = 0; j < 13; ++j){
            if(cards[i][j] == 0) {
                if (i == 0){
                cout << "S " << j+1 << endl;
            } 
                else if (i == 1){
                cout << "H " << j+1 << endl;
            } 
                else if (i == 2){
                cout << "C " << j+1 << endl;
            } 
                else if (i == 3){
                cout << "D " << j+1 << endl;
            }  
            }
        }
    }

    return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define pb push_back
#define all(x) begin(x), end(x)

using namespace std;
using ll = long long int;
const int MOD = 1e9 + 7;

int main()
{
	ios::sync_with_stdio(0); cin.tie(0);
	int m; cin >> m;
	vector<array<ll, 2>> v(m);
	ll tot = 0, len = 0;
	for (int i = 0; i < m; ++i)
	{
		cin >> v[i][0] >> v[i][1];
		tot += 1LL * v[i][0] * v[i][1];
		len += v[i][1];
	}
	cout << len - 1 + (tot-1)/9;
}

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

namespace ABC127
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(' ');
            int[] n = s.Select(x => int.Parse(x)).ToArray();

            int RR = n[0];
            int LL = 1;
            int L, R = 1;

            for (int i = 0; i < n[1]; i++)
            {
                s = Console.ReadLine().Split(' ');
                L = int.Parse(s[0]);
                R = int.Parse(s[1]);

                if (LL > R || RR < L)
                {
                    Console.WriteLine(0);
                    return;
                }

                if (LL < L)
                {
                    LL = L;
                }
                if (R < RR)
                {
                    RR = R;
                }
            }
            Console.WriteLine(RR - LL + 1);
        }
    }
}

Measured memory_bytes: 17480
#include<iostream>
#include<unordered_map>
#include<algorithm>
#include<vector>
#include<string>
#include<string.h>


using namespace std;

long long modexp(long long x, long long n, long long mod)
{
    if (n == 0) {
        return 1;
    }

    if (n % 2 == 0) {
        return (modexp(x, n / 2, mod) * modexp(x, n / 2, mod)) % mod;
    }
    return (modexp(x, n / 2, mod) * modexp(x, n / 2, mod) * x) % mod;
}



int main()
{
    int sx,sy,tx,ty;
    cin >> sx >> sy >> tx >> ty;
    string str;
    int i;
    
    int curr_x = sx, curr_y = sy;
    while (curr_y < ty) {
        str.push_back('U');
        curr_y++;
    }

    while (curr_x < tx) {

        str.push_back('R');
        curr_x++;
    }

    while (curr_y > sy) {
        str.push_back('D');
        curr_y--;
    }
    while (curr_x > sx) {
        str.push_back('L');
        curr_x--;
    }

    str.push_back('L');
    curr_x--;
    while (curr_y < ty+1) {
        str.push_back('U');
        curr_y++;
    }
    while (curr_x < tx ) {

        str.push_back('R');
        curr_x++;
    }
    str.push_back('D');
    curr_y--;
    str.push_back('R');
    curr_x++;
    while (curr_y > sy-1) {
        str.push_back('D');
        curr_y--;
    }
    while (curr_x > sx) {
        str.push_back('L');
        curr_x--;
    }
    str.push_back('U');
    cout << str;



    
}


Measured memory_bytes: 256
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.List;
import java.util.StringJoiner;
import java.util.stream.Collectors;

@SuppressWarnings("ALL")
public class Main {

    public static void main(String[] args) {
        List<Integer> values = IO.readLineAsIntList();
        int x = values.get(0);
        int y = values.get(1);
        int z = values.get(2);

        int n = x / y;
        for (; n >=0; n--) {
            if( n * y + (n + 1) * z <= x ) {
                break;
            }
        }
        IO.writeLine("" + n);
    }

    public static class IO {

        private static BufferedReader br;

        private static BufferedReader br() {
            if( br == null ) {
                br = new BufferedReader( new InputStreamReader(new BufferedInputStream(System.in), StandardCharsets.UTF_8) );
            }
            return br;
        }

        public static String readLine() {
            try {
                return br().readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        public static int readLineAsInt() {
            return Integer.parseInt(readLine());
        }

        public static List<String> readLineAsList() {
            return Arrays.asList( readLine().split(" "));
        }

        public static List<Integer> readLineAsIntList() {
            return readLineAsList().stream()
                    .map( Integer::parseInt )
                    .collect(Collectors.toList());
        }

        public static void writeLine(String line) {
            System.out.println( line );
        }

        public static void writeLine(List<Integer> values) {
            StringJoiner j = new StringJoiner(" ");
            values.forEach(i -> j.add(String.valueOf(i)) );
            writeLine(j.toString());
        }

        public static void writeLines(List<String> lines) {
            lines.forEach(System.out::println);
        }
    }
}


Measured memory_bytes: 28756
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip>
#include <unordered_map>
#include <list>
using namespace std;
const long long int mod1=1000000007;
const long long int mod2 = 998244353;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
#define pp pop_back
#define ff first
#define ss second
#define ll long long int
#define ull unsigned long long int
#define all(x) x.begin(),x.end()
#define sz(x) x.size()
#define FOR(i, a, b) for (int i = (a), _##i = (b); i <= _##i; ++i)
#define FORD(i, a, b) for (int i = (a), _##i = (b); i >= _##i; --i)
#define REP(i, a) for (int i = 0, _##i = (a); i < _##i; ++i)
#define REPD(i,n) for(int i = (n)-1; i >= 0; --i)
#define pll pair<ll, ll>
#define ln endl
ll gcd(ll a, ll b){
    ll c;
     while(b){
        c = b;
        b = a % b;
        a = c;
     }
     return a;
}
ll lcm(ll a, ll b){
    return (a * b) / gcd(a, b);
 }
ll power1(ll a, ll b){
     ll out = 1;
     while(b){
        if(b & 1){
            out *= a;
        }
        b >>= 1;
        a *= a;
     }
     return out;
}
ll power2(ll a, ll b, ll m){
     a %= m;
     ll out = 1;
     while(b){
        if(b & 1){
            out *= a;
            out %= m;
        }
        b >>= 1;
        a = (a * a) % m;
     }
     return out;
}
ll modi(ll x, ll p){
    return power2(x, mod1 - 2, mod1);
}
int main(){
    fast;
    ll tt = 1;
    //cin >> tt;
    while(tt--){
        ll a, b;
        cin >> a >> b;
        cout << a*b;  
    }
}

Measured memory_bytes: 3652
#include<cstdio>
#include<algorithm>
using namespace std;
int h[100005];
int main(void)
{
    int n,cnt=0,mx=0;
    scanf("%d" ,&n);
    for(int i=1;i<=n;i++)
        scanf("%d" ,&h[i]);
    for(int i=n-1;i>=1;i--)
    {
        if(h[i]>=h[i+1])
        {
            cnt++;
            mx=max(mx,cnt);
        }
        else cnt=0;
    }
    printf("%d" ,mx);
    return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
using namespace std;
int n,a[300000];
int main()
{
	scanf("%d",&n);
	for (int i=0;i<(1<<n);i++) scanf("%d",&a[i]);
	int ans=0;
	for (int i=0;i<(1<<n);i++)
	{
		int Max=a[0],Max1=0;
		for (int s=i;s;s=(s-1)&i)
		{
			if (a[s]>Max) Max1=Max,Max=a[s];
				else Max1=max(Max1,a[s]);
		}
		ans=max(ans,Max+Max1);
		if (i) printf("%d\n",ans);
	}
	return 0;
}


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

int main () {
	queue<int> qptime;
	queue<string> qpname;
	queue<int> qfptime;
	queue<string> qfpname;
	int n, q, ptime, timer = 0;
	string pname;
	cin >> n >> q;
	for (int i = 0; i < n; i++) {
		cin >> pname;
		qpname.push(pname);
		cin >> ptime;
		qptime.push(ptime);
	}
	while (!qpname.empty()) {
		for (int i = 0; i < qpname.size(); i++) {
			pname = qpname.front();
			qpname.pop();
			ptime = qptime.front();
			qptime.pop();
			ptime = ptime - q;
			if (ptime <= 0) {
				ptime = ptime + q + timer;
				qfpname.push(pname);
				qfptime.push(ptime);
				timer = ptime;
			}
			else {
				qpname.push(pname);
				qptime.push(ptime);
				timer += q;
			}
		}
	}
	for (int i = 0; i < n; i++) {
		pname = qfpname.front();
		qfpname.pop();
		ptime = qfptime.front();
		qfptime.pop();
		cout << pname << ' ';
		cout << ptime << endl;
	}	
	return 0;
}

Measured memory_bytes: 5716
import re

while True:
    a = input()
    
    if a == "END OF INPUT":
        break
    
    a = re.split('[ ]',a)



    ans = []

    for i in a:
       ans.append(len(i))
   
    ans = [str(i) for i in ans]
    ans = "".join(ans)
    print(ans)


Measured memory_bytes: 6492
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i) = 0; (i) < (n); (i)++)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }


int main() {
    int n, m;
    string s;
    cin >> n >> m >> s;
    vector<int> dp(n+1, 0);
    int r = n;
    for(int i = n-1; i >= 0; i--){
        if(s[i] == '1'){
            dp[i] = -1;
            continue;
        }
        while(r > i + m) r--;
        while(dp[r] == -1) r--;
        if(r == i){
            cout << -1 << endl;
            return 0;
        }
        dp[i] = dp[r] + 1;
    }
    /*
  	for(auto t : dp){
        cout << t << " ";
    }
    cout << endl;
	*/
    int now = 0;
    for(int i = 0; i < n+1; i++){
        if(dp[i] == -1) continue;
        if(dp[i] != dp[now]){
            cout << i-now << " ";
            now = i;
        }
    }
    cout << endl;
}


Measured memory_bytes: 1024
import java.util.Scanner;

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

        if (a>9 || b>9){
            System.out.println("-1");
        } else{
            System.out.println(a*b);
        }
    }
}

Measured memory_bytes: 21972
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define dunk(a) cout << (a) << "\n"
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n; cin >> n;
	ll a, b; cin >> a >> b;
	ll ans = a + b * (n - 1) - a * (n - 1) - b + 1;
	dunk(max(ans, 0ll));
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <vector>
#include <queue>
#include <stack>
#include <array>
#include <algorithm>
#include <numeric>
#include <limits>
#include <string>
#include <regex>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;

int main()
{
    int a, b;
    cin >> a >> b;
    int ans = 0;
    for (int i = 0; i < 2; i++) {
        if (a > b) ans += a--;
        else       ans += b--;
    }
    cout << ans << endl;
    return 0;
}


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


#define ONSPEED ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define f(i,x,n) for(i=x;i<n;i++)
#define rf(i,x,n) for(i=n;i>x;i--)
#define ll long long
#define GCD(a,b) __gcd(a,b)
#define ff first
#define ss second
#define adios return 0;

/*
tacet aquilae
*/

int main()
{
    ONSPEED;
    ll t,n,k,a,b,c,d,s=0,i,j,flag;
    string x,y;
    cin>>t;
    map<ll,ll>mp;
    while(t--)
    {
        cin>>n;
        if(mp[n]==0) mp[n]++;
        else mp[n]=0;
    }

    for(auto it: mp)
    {
    	if(it.ss==1) s++;
    }
    cout<<s;





    adios;
}
	


Measured memory_bytes: 9784
#define _USE_NATH_DEFINES
#include<cstdio>
#include <iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include <string>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
#include <random>

using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
#define EPS 1e-9
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const int MINF = -1e9;


int main() {
	int n,k;
	cin >> n >> k;
	vector<int> h(n);
	rep(i, n) {
		int x;
		cin >> x;
		h[i] = x;
	}
	sort(h.begin(), h.end());

	int ans = INF;
	rep(i, n - k+1) {
		int buff = h[i + k-1] - h[i];
		if (buff < ans) ans = buff;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using V = vector<int>;
using VV = vector<V>;
using VVV = vector<VV>;
using VL = vector<ll>;
using VVL = vector<VL>;
using VVVL = vector<VVL>;
template<class T> using VE = vector<T>;
template<class T> using P = pair<T, T>;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define REP(i,k,n) for(int i=(k);i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define output(x,y) cout << fixed << setprecision(y) << x << endl;
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; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
ll upper = MOD + MOD;
ll under = -upper;
ll UPPER = MOD * MOD;
ll UNDER = -UPPER;
const long double pi = 3.141592653589793;
const long double eps = 1e-14;
int main() {
	long double a, b, c;
	cin >> a >> b >> c;
	if (sqrt(a) + sqrt(b) + eps < sqrt(c)) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 3792
#include <stdio.h>

int main(){
    int n;
    int k;
    char s[50];

    scanf("%d",&n);
    scanf("%d",&k);
    scanf("%s",s);

    if(s[k-1]=='A'){
        s[k-1]='a';
    }
    if(s[k-1]=='B'){
        s[k-1]='b';
    }
    if(s[k-1]=='C'){
        s[k-1]='c';
    }

    printf("%s",s);
    
    }

Measured memory_bytes: 128
#include <bits/stdc++.h>
#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>;
struct Edge
{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w) {}
};
// using Graph = vector<vector<Edge>>;
using Graph = vector<vector<int>>;

const long long INF = 1LL << 60;
const int INT_INF = 1000000000;

int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
// int dx[8] = {-1, -1, -1, 0, 0, 1, 1, 1}, dy[8] = {-1, 0, 1, 1, -1, 1, 0, -1};

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

  Graph G(n);
  vector<int> in(n, 0);

  for (int i = 0; i < m; i++)
  {
    int a, b;
    cin >> a >> b;
    a--, b--;
    G[a].push_back(b);
    in[b]++;
  }

  queue<int> que;

  for (int i = 0; i < n; i++)
    if (in[i] == 0)
      que.push(i);

  bool multi = false;

  vector<int> ans;

  while (!que.empty())
  {
    int v = que.front();
    que.pop();
    if (que.size() > 0)
      multi = true;
    ans.push_back(v);
    for (auto u : G[v])
    {
      in[u]--;
      if (in[u] == 0)
        que.push(u);
    }
  }

  for (int i = 0; i < n; i++)
    cout << ans[i] + 1 << endl;
  cout << multi << endl;
  return 0;
}


Measured memory_bytes: 3884
#include <iostream>
#include <cmath>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <string>

using namespace std;

typedef long long LL;
typedef unsigned int UI;

#define rSort(a) 		sort(a.rbegin(),a.rend())
#define Sort(a) 		sort(a.begin(),a.end())
#define Reverse(a) 		reverse(a.begin(),a.end())
#define Sum(a)  		accumulate(a.begin(), a.end(), 0)
#define REP(i, n) 		for(UI i = 0;i < n;i++)
#define REPR(i, n) 		for(UI i = n;i >= 0;i--)
#define FOR(i, m, n) 	for(UI i = m;i < n;i++)
#define pb(i) 			push_back(i)

#define MOD  			(LL)1e9 + 7;
#define INF  			(LL)1 << 62;


int main(int argc, const char * argv[]) {

	cin.tie(0);
	ios::sync_with_stdio(false);

	vector<pair<string,pair<int,int>> >vec;
	int n;

	cin >> n;

	for(int i=1;i<=n;i++){
		string s; int a; cin>>s>>a;
		vec.push_back(make_pair(s,make_pair(-a,i)));
	}

	sort(vec.begin(),vec.end());    // 第２キー、第２キー 、、、の順にソートされる

	for(int i=0;i<n;i++) cout << vec[i].second.second << endl;

	return 0;

}




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

using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#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--)
//xにはvectorなどのコンテナ
#define ALL(x) x.begin(),x.end() //sortなどの引数を省略したい
#define SIZE(x) ll(x.size()) //sizeをsize_tからllに直しておく
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB emplace_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define Umap unordered_map
#define Uset unordered_set

int main(){
    ll n, k;
    cin >> n >> k;
    double ans = 0;
    REP(i, n){
        ll j = i + 1;
        while(j < k) j *= 2;
        ans += 1 / (double(j) / double(i+1));
    }
    cout << fixed << setprecision(11) << ans / double(n);
    return 0;
}

Measured memory_bytes: 3788
G = {}
N = int(input())
for _ in range(N):
    L = list(map(int, input().split()))
    G[L[0]] = L[2:]

# print(G)
d = [-1] * N
f = [-1] * N
q = [1]
visited = [False] * N

time = 1


def dfs(v):
    global time
    visited[v-1] = True

    for nv in G[v]:
        if d[nv-1] < 0:
            d[nv-1] = time
            time += 1
        if not visited[nv-1]:
            dfs(nv)

    f[v-1] = time
    time += 1


for i in range(1, N+1):
    if not visited[i-1]:
        d[i-1] = time
        time += 1
        dfs(i)

for i in range(N):
    print(i+1, d[i], f[i])



Measured memory_bytes: 5660
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
//#define f(i,a,n) for(ll i=a;i<n;i++)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
 
int main() 
{
    fast;
    ll t=1;
    //cin>>t;
    while(t--)
    {
        ll n,m;
        cin>>n>>m;
        cout<<((n*(n-1))/2)+((m*(m-1))/2);
        
    }
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using lint = long long;
#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 cend printf("\n");
#define prique(T) priority_queue<T, vector<T>, greater<T>>
#define prique2(T) priority_queue<T>

struct edge { int to; double cost; };
using P = pair<lint, lint>;
using D = pair<double, double>;
using DI = pair<double, int>;
//const lint mod = 998244353LL;
const lint mod = 1000000007LL;
const lint inf = 3LL * mod * mod;

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;
}

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

lint fact[1000000];
void f_init(lint n) {
	if (1000000 <= n) return;
	fact[0] = fact[1] = 1;
	for (lint i = 2; i <= n; ++i) {
		fact[i] = i * fact[i - 1];
		if (mod <= fact[i]) fact[i] %= mod;
	}
	return;
}

lint inver[1000000]; bool inve[100000];
lint inv(lint x) {
	if (x == 0) return 0;
	else if (inve[x]) return inver[x];
	else {
		inve[x] = true;
		return inver[x] = modpow(x, mod - 2, mod);
	}
}

lint comb(lint n, lint r) {
	if (n < r) return 0;
	if (n == r) return 1;
	lint ans = fact[n] * inv(fact[n - r]) % mod * inv(fact[r]) % mod;
	if (ans < 0) return ans + mod;
	return ans;
}

lint nck[1010][1010];
void comb(lint n) {
	rep(i, n + 1) {
		rep(j, i + 1) {
			if (j == 0 || i == j) nck[i][j] = 1;
			else nck[i][j] = nck[i - 1][j - 1] + nck[i - 1][j];
		}
	}
}

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

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

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

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

double dis(D a, D b) { return sqrt((a.first - b.first) * (a.first - b.first) + (a.second - b.second) * (a.second - b.second)); }

lint a, b;
int main() {
	cin >> a >> b;
	cout << lcm(a, b) << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String s = in.next();
		if (s.equals("SUN")) {
			System.out.println(7);
		} else if (s.equals("MON")) {
			System.out.println(6);
		} else if (s.equals("TUE")) {
			System.out.println(5);
		} else if (s.equals("WED")) {
			System.out.println(4);
		} else if (s.equals("THU")) {
			System.out.println(3);
		} else if (s.equals("FRI")) {
			System.out.println(2);
		} else if (s.equals("SAT")) {
			System.out.println(1);
		}
		in.close();
	}
}

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

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

    string s;
    int c[26]{51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51};
    for (int i = 0; i < n; i++) {
        cin >> s;
        for (int j = 0; j < 26; j++) {
            if (c[j] > 0) {
                int t = 0;
                for (int k = 0; k < s.size(); k++) {
                    t += (s[k] == (char)('a' + j) ? 1 : 0);
                }
                c[j] = min(c[j], t);
            }
        }
    }

    for (int i = 0; i < 26; i++) {
        for (int j = 0; j < c[i]; j++) {
            cout << (char)('a' + i);
        }
    }
    cout << endl;
}


Measured memory_bytes: 256
import math

def getPrimes(X):
    primes = []
    limit = math.sqrt(X)
    data = [i + 1 for i in range(1, X)]
    while True:
        p = data[0]
        if limit <= p:
            return primes + data
        primes.append(p)
        data = [d for d in data if d % p != 0]

def getNextPrime(primes, X):
    while True:
        if any([X % p == 0 for p in primes]):
            if primes[-1] == X:
                return X
            X += 1
        else:
            return X
        
        
X = int(input())
primes = getPrimes(X)
print(getNextPrime(primes, X))

Measured memory_bytes: 7448
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <complex>
#include <algorithm>
#include <cstring>
#include <map>
#include <set>
#include <cstdio>
#include <queue>
#include <cmath>
#include <cstdlib>

using namespace std;
typedef long long ll;
typedef ll li;
typedef pair<int,int> PI;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define REP(i, n) rep (i, n)
#define F first
#define S second
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define SZ(a) (int)((a).size())
#define ALL(a) (a).begin(),(a).end()
#define FLL(a,b) memset((a),b,sizeof(a))
#define CLR(a) memset((a),0,sizeof(a))
#define FOR(it,a) for(__typeof(a.begin())it=a.begin();it!=a.end();++it)
#define FORR(it,a) for(__typeof(a.rbegin())it=a.rbegin();it!=a.rend();++it)
template<typename T,typename U> ostream& operator<< (ostream& out, const pair<T,U>& val){return out << "(" << val.F << ", " << val.S << ")";}
template<class T> ostream& operator<< (ostream& out, const vector<T>& val){out << "{";rep(i,SZ(val)) out << (i?", ":"") << val[i];return out << "}";}
#define EPS (1e-6)
#define declare(a,it) __typeof(a) it=a

typedef vector<long double> arr;
typedef vector<arr> mat;

arr sol(mat A,arr y){//Ax=y, return x
  int n = A.size();
  mat B(n,arr(n));
  for(int i = 0; i < n; ++i)
    B[i][i] = 1;
  
  for(int i = 0; i < n; ++i){
    for(int j=i+1;j < n; ++j){
      if(abs(A[j][i]) > abs(A[i][i])){
         swap(A[j],A[i]);
         swap(B[j],B[i]);
      }
    }
    long double d = A[i][i];
    for(int j = 0; j < n; ++j){
      A[i][j] /= d;
      B[i][j] /= d;
    }

    for(int j = 0; j < n; ++j){
      if(i==j) continue;
      long double m = A[j][i];
      for(int k = 0; k < n; ++k){
        A[j][k] -= A[i][k] * m;
        B[j][k] -= B[i][k] * m;
      }
    }
  }
  
  arr ret(n);
  for(int i = 0; i < n; ++i)
    for(int j = 0; j < n; ++j)
      ret[i] += B[i][j] * y[j];
  
  return ret;
}

int main()
{
  int a,m,b,n;
  while(cin >> a >> m >> b >> n && a){
    arr p(n*m);
    p[0] = 1;
    mat A(n*m,arr(n*m));
    for(int i = n*m-1; i >= 0; --i){
      for(int j = 0; j < n*m; ++j)
        A[j][i] = p[j];
      arr np(n*m);
      for(int j = 0; j < n*m; ++j){
        int an = j % m;
        int bn = j / m;
        long pp = p[j];
        if(an == m-1) np[bn*m] += pp * a;
        else np[bn*m+an+1] += pp;
        
        if(bn == n-1) np[an] += pp * b;
        else np[(bn+1)*m+an] += pp;
      }
      p = np;
    }
    for(auto & i : p) i = -i;
    auto ans = sol(A, p);
    cout << 1;
    for(auto p : ans) printf(" %.0Lf", abs(p)<EPS?0.0:p);
    cout << endl;
  }
}

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

typedef long long ll;
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define REP(i,n) for (int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
 
using namespace std;

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

    vector<pair<int, int> > pairs(m);
    REP(i,m){
        int a,b;
        cin >>a >>b;
        pairs[i] = MP(a,b);
    }
    sort(pairs.begin(), pairs.end());

    int ans = 0;
    int c = -1;
    REP(i,m){
        if(pairs[i].fi >= c){
            ans++;
            c = pairs[i].se;
        }else{
            if(pairs[i].se < c) c = pairs[i].se;
        }
    }
cout << ans << endl;

}


Measured memory_bytes: 1024