akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
struct frac {
	// p/q
	ll p;
	ll q;
};
ll gcd(ll x, ll y) {
	ll r;
	while ((r = x % y) != 0) {
		x = y;
		y = r;
	}
	return y;
}
ll lcm(ll x, ll y) {
	return (x / gcd(x, y) * y);
}
int main() {
	ll n;
	cin >> n;
	frac num = {4, n};
	for (ll a = 1; a <= 3500; a++) {
		for (ll b = 1; b <= 3500; b++) {
			frac x;
			ll l = lcm(n, lcm(a, b));
			x.q = l;
			x.p = num.p * l / num.q - l / a - l / b;
			if (x.p <= 0 || x.q / x.p < 0) {
				continue;
			}
			if (x.q % x.p == 0) {
				cout << a << " " << b << " " << x.q / x.p << endl;
				return 0;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 3604
#include <iostream>
#include <vector>
#include <map>
#include <list>
#include <queue>
#include <algorithm>
#include <cassert>
#include <string>
#include <climits>
#include <numeric>

#define all(x) begin(x),end(x)

using namespace std;
using ll = long long;

int main()
{
	char c;
	cin >> c;
	c++;
	cout << c << endl;
}



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

public class Main {
    public static void main(String[] args) throws IOException {
        InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
        BufferedReader in = new BufferedReader(reader);
        String[] str = in.readLine().split(" ");
        long d = Long.parseLong(str[0]);
        long t = Long.parseLong(str[1]);
        long s = Long.parseLong(str[2]);

        if(d > t*s) {
            System.out.println("No");
        }else {
            System.out.println("Yes");
        }
    }
}

Measured memory_bytes: 32632
#include <iostream>
#include <iomanip>
// std::cout << std::setprecision(2) << 3.141; // "3.1"
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <map>
// #include <bits/stdc++.h> all

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;

static const int giga = pow(10,9);
// double pi = 3.141592653589793238463;

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

  int flag = 0;
  for(int i = 0; i < s.size(); i++){
    if(i%2 == 0){
      if(s[i] == 'R' || s[i] == 'U' || s[i] == 'D'){
	
      } else {
	cout << "No" << endl;
	return 0;
      }
    } else {
      if(s[i] == 'L' || s[i] == 'U' || s[i] == 'D'){
	
      } else {
	cout << "No" << endl;
	return 0;
      }
    }
  }
  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int A,B,C,count=0;
  cin>>A>>B>>C;
  while(1){
    count+=1;
    C = C - A;
    if(count%7==0) C = C - B;
    if(C <= 0) break;
    }
  cout<<count<<endl;
  return 0;
}



Measured memory_bytes: 3100
def numf(a):
  c = 0
  for i in range(1, a+1):
    c += (a % i == 0)
  return c
 
n = int(input())
 
c = 0
for i in range(1, n+1, 2):
  if numf(i) == 8:
      c+=1
print(c)

Measured memory_bytes: 2940
n = int(input())
C = [c for c in input()]
Red = []
White = []
len_Red = 0
len_White = 0
for i in range(n):
    if C[i] == 'R':
        Red.append(i)
        len_Red += 1
    else:
        White.append(i)
        len_White += 1

ans = 0
cnt = 0
w = 0
r = len_Red - 1
while True:
    if w < len_White:
        cnt = White[w]
        w += 1
    else:
        print(ans)
        exit()
    if r >= 0 and cnt < Red[r]:
        C[cnt], C[r] = C[r], C[cnt]
        ans += 1
        r -= 1
    else:
        print(ans)
        exit()

Measured memory_bytes: 18800
n, a, b = map(int, input().split())
#nは10000以下
#1以上N以下の整数のうち、10進法での各桁の和がA以上B以下であるものの総和

elemtotal = []
elem = 0
for elem in range(1, n+1):
    n10000 = elem // 10000
    n1000 = (elem - 10000 * n10000) // 1000
    n100 = (elem - 10000 * n10000 - 1000 * n1000) // 100
    n10 = (elem - 10000 * n10000 - 1000 * n1000 - 100 * n100) // 10
    n1 = elem - 10000 * n10000 - 1000 * n1000 - 100 * n100 - 10 * n10
    ketatotal = n10000 + n1000 + n100 + n10 + n1
    if ketatotal >= a and ketatotal <= b:
        elemtotal.append(elem)

ans= sum(elemtotal)
print(ans)


Measured memory_bytes: 9340
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
ll n;ll dat[2000005];
void init(ll n_){
n=1;
  while(n<=n_)n*=2;
}
void update(ll k,ll a){
k+=n-1;
  dat[k]=a;
  while(0<k){
  k=(k-1)/2;
    dat[k]=(dat[2*k+1]+dat[2*k+2]);
  }
}
ll query(ll a,ll b,ll k,ll l,ll r){
if(a<=l && r<=b)
  return dat[k];
  else if(r<=a || b<=l)
    return 0;
  else{
  ll val=query(a,b,2*k+1,l,(l+r)/2);
    ll var=query(a,b,2*k+2,(l+r)/2,r);
    return (val+var);
  }
}
ll N,Q;
int main(){
  cin>>N>>Q;init(N+2);
  vector<ll>c(N);
  for(int i=0;i<N;i++)
    cin>>c.at(i);
  vector<pair<P,ll>>A(Q);
  for(int i=0;i<Q;i++){
  ll l,r;cin>>l>>r;
    P p(r,l);
    pair<P,ll>p1(p,i);
    A[i]=p1;
  }sort(A.begin(),A.end());
  vector<ll>ans(Q);
  map<ll,ll>M;ll I=0;
  for(int i=0;i<N;i++){
  if(!M.count(c[i])){
    M[c[i]]=i;update(i,1);
  }else{
  update(M.at(c[i]),0);M.at(c[i])=i;update(i,1);
  }
     while(A[I].first.first==i+1){
     ll l=A[I].first.second;
       ll r=A[I].first.first;
       ll j=A[I].second;
       ll a=query(l-1,r,0,0,n);
       ans[j]=a;I++;
     
     }
  }for(int i=0;i<Q;i++)
     printf("%u\n",ans[i]);
   return 0;
}

Measured memory_bytes: 62480
import sys
import bisect
from functools import lru_cache
from collections import defaultdict
inf = float('inf')
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**6)
def input(): return sys.stdin.readline().rstrip()
def read():
  return int(readline())
def reads():
  return map(int, readline().split())
d=read()
d%=1000
if d==0:
  print(0)
else:
  print(1000-d)

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

using namespace std;

#define all(x) x.begin(), x.end()
typedef vector <int> vi;
typedef pair<int,int> ii;
typedef long long ll;

const int MOD = 1e9 + 7;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	int n;
	cin >> n;
	multiset <int> mst;
	vector <int> v;
	for(int i = 0; i < n; i++){
		int x;
		cin >> x;
		v.push_back(x);
		mst.insert(x);
	}
	sort(v.rbegin(), v.rend());
	int res = 0;
	for(int i = 0; i < n; i++){
		if(mst.find(v[i]) == mst.end()) continue;
		mst.erase(mst.find(v[i]));
		int next = (1 << (32 - __builtin_clz(v[i]))) - v[i];
		if(mst.find(next) != mst.end()){
			res++;
			mst.erase(mst.find(next));
		}
	}
	cout << res;
}

Measured memory_bytes: 10484
#include <stdio.h>

int main(void){
	int N;
	int stu[100000];
	int i;
	int tmp;
	scanf("%d",&N);
	for(i=1; i<=N; i++){
		scanf("%d",&tmp);
		stu[tmp-1] = i;
	}

	for(i=0; i<N; i++)
		printf("%d ",stu[i]);
	putchar('\n');
}

Measured memory_bytes: 1152
#include<iostream>
#include<vector>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

ll modpow(ll a, ll b, ll p = 1e9+7){
    if(b == 0)  return 1;

    if(b % 2 == 0){
        ll d = modpow(a, b/2, p);
        return (d*d) % p;
    }else{
        return (a%p * modpow(a, b-1, p)) % p;
    }
}

int main(){
    int n, x;
    ll d;
    while(cin >> n >> d >> x, n){
        ll ans = 0, tmp = 1;
        vector<vector<ll>> dp(n+1, vector<ll>(n+1, 0));
        for(int j = 0; j <= n; j++) dp[0][j] = 1;
        for(int i = 1; i <= n; i++){
            if(i > d)   break;
            tmp *= (d-i+1)%mod;
            tmp %= mod;
            tmp *= modpow(i, mod-2, mod);
            tmp %= mod;
            for(int j = 1; j <= n; j++){
                dp[i][j] = (dp[i-1][j-1] - (j-x < 0 ? 0 : dp[i-1][j-x]) + mod)%mod;
            }

            if(dp[i][n]){
                ans += tmp * dp[i][n];
                ans %= mod;
            }
            for(int j = 1; j <= n; j++){
                dp[i][j] += dp[i][j-1];
                dp[i][j] %= mod;
            }
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 34192
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>
#include <cassert>
#include <functional>
#include <set>
#include <deque>
#include <list>
using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
#define LNF __LONG_LONG_MAX__
const ll MOD = 1000000007;
const int MAX = 200000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// 法mでのaの逆元を計算
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//最大公約数
long long gcd(long long x, long long y){
    if(y==0) return x;
    else return gcd(y,x%y);
}
//最小公倍数
long long lcm(long long x, long long y){
    return x / gcd(x, y) * y;
}
// nが大きく,kが10^7程度の時の二項係数
long long com[200005];
void combination(long long n,long long k){
    com[0] = 1;
    for(int i=1;i<=k;i++){
        com[i] = (com[i-1]*(n-i+1)%MOD)*modinv(i,MOD)%MOD;
    }
}

int main(){
    int A,B,C; cin >> A >> B >> C;
    if(A<=C && C<=B) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3612
PROGRAM-ID.                      ABC_049_B.
DATA                             DIVISION.
WORKING-STORAGE                  SECTION.
    01 INP     PIC X(7).
    01 H       PIC 9(3).
    01 W       PIC 9(3).
    01 C       PIC X(100).
    01 i       PIC 9(3).

PROCEDURE                        DIVISION.
    ACCEPT INP.

    UNSTRING INP
    DELIMITED BY SPACE
    INTO H W.

    PERFORM VARYING i FROM 1 BY 1 UNTIL H < i
        ACCEPT C
        DISPLAY C(1:FUNCTION STORED-CHAR-LENGTH(C))
        DISPLAY C(1:FUNCTION STORED-CHAR-LENGTH(C))
    END-PERFORM.

    STOP RUN.


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mp make_pair
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
//Some custom functions for quick use(fast_power,nCr,lcm,gcd)
ll power(ll a, ll b)
{
  if(b == 0)
   {
      return 1;
   }
   else if(b % 2 == 0)
   {
      return power(a*a, b/2);
   }
   else
   {
      return a * power(a*a, b/2);
   }
}
long long int nChoosek( long long int n, long long int k )
{
if (k > n) return 0;
if (k * 2 > n) k = n-k;
if (k == 0) return 1;
    int result = n;
for( int i = 2; i <= k; ++i )
{
        result *= (n-i+1);
        result /= i;
}
    return result;
}

long long int lcm(long long int a,long long int b)
{
    long long int m,n;
    m=a;
    n=b;
    while(m!=n)
    {
        if(m < n)
        {
            m=m+a;
        }
        else
        {
            n=n+b;
        }
    }
    return m;
}

long long int gcd(long long int a,long long int b)
{ 
if (a == 0) 
return b; 
return gcd(b % a, a);
}
/* Basic DFS Boilerplate */ 
vector<ll> adj[10005]; // graph is stored as adjacency list
bool visited[10005];
void dfs(ll s)  //given node s
{
    if(visited[s])
        return;
    visited[s]=true;
    //the process on node 's'
    for(auto u : adj[s])
    {
        dfs(u);
    }    
}
/* Basic BFS Boilerplate */
ll x;   // given node
queue<ll>q;
bool vis[10005];
ll dist[10005];
//
void bfs(ll x)
{
    vis[x]=true;
    dist[x]=0LL;
    q.push(x);
    while (!q.empty())
    {
        ll s=q.front();
        q.pop();
        //the process
        //on node x
        for(auto u :adj[x])
        {
            if(vis[u]==true)
                continue;
            vis[u]=true;
            dist[u]=dist[x]+1;
            q.push(u);
        }
    }
    
}
int main()
{
    fastio
    
    ll k;
    cin>>k;
    string s;
    cin>>s;
    if(s.length()<=k)
    {
        cout<<s<<'\n';
    }
    else
    {
        for (ll i = 0; i < k; i++)
        {
            cout<<s[i];
        }
        cout<<"..."<<'\n';
    }
    return 0;
}


Measured memory_bytes: 3888
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

std::vector<int> enum_div(int n)//nの約数を列挙
{
	std::vector<int> ret;
	for(int i=1 ; i*i<=n ; ++i)
	{
		if(n%i == 0)
		{
			ret.push_back(i);
			if(i*i!=n)
			{
				ret.push_back(n/i);
			}
		}
	}
    sort(ret.begin(), ret.end(), greater<int>());
	return ret;
}

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

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

    sort(A.begin(), A.end());
    
    int result0 = A[0];
    vector <int> EA0 = enum_div(A[0]);
    int j = 0;

    while(result0 > 0){
        int count = 0;
        result0 = EA0[j];
        for(int i = 0; i < N; i++){
            if (A[i] % result0 != 0) {
                count += 1;
                if (count >= 2) {
                    break;
                }   
            }
        }
        if (count <= 1) {
            break;
        }else{
            j += 1;
        }
    }

    int result1 = A[1];
    vector <int> EA = enum_div(A[1]);
    j = 0;
    while(result1 > 0){
        int count = 0;
        result1 = EA[j];
        for(int i = 0; i < N; i++){
            if (A[i] % result1 != 0) {
                count += 1;
            }
        }
        if (count <= 1) {
            break;
        }else{
            j += 1;
        }
    }

    if (result0 >= result1) {
        cout << result0 << endl;
    }else{
        cout << result1 << endl;
    }
    
    
    

    return 0;
}

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

int main(void){
  int k,i,slen;
  char s[101];

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

  slen = strlen(s);
  for(i = 0; i < slen && i < k; i++){
    printf("%c", s[i]);
  }

  if(slen > k){
    printf("...\n");
  }else{
    printf("\n");
  }
}


Measured memory_bytes: 1660
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define in(x) cin >> x
#define out(str) cout << str << endl

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

int N,res=0,now=0;

int main(){
    cin>>N;
    int a[N];
    rep(i,N){
        cin>>a[i];
        a[i]--;
    }
    while(res<=N){
        now=a[now];
        res+=1;
        if(now==1){
            out(res);
            return 0;
        }
    }
    out(-1);
    return 0;
}

Measured memory_bytes: 640
N,X = list(map(int,input().split()))
X_=list(map(int,input().split()))

X_.append(X)
X_.sort()

X_diff=[]
for x_idx in range(1,len(X_)):
    x =X_[x_idx-1]
    x_=X_[x_idx]
    X_diff.append(x_-x)
    
import math
gcd_=X_diff[0]

for x_diff in  X_diff[1:]:
    gcd_=math.gcd(gcd_,x_diff)
    
print(gcd_)

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

int main() {
    int n; 
    int t; 
    cin >> n >> t; 
    int ns[110];
    int ts[110];
    int min = INT_MAX; 
    for (int i = 0; i < n; i++) {
        cin >> ns[i]; 
        cin >> ts[i]; 

        if (ts[i] <= t) {
            if (ns[i] < min) min = ns[i]; 
        }
    }

    if (min == INT_MAX) cout << "TLE\n";
    else cout << min << endl; 


}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<stack>
#include<queue>
#include<list>
#include<vector>
#include<set>
#include<map>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<ctime>
#define ll long long
#define db double
#define inf 100009
#define INF (int)1e9
#define pi acos(-1)
#define rd(n) {n=0;char ch;int f=0;do{ch=getchar();if(ch=='-'){f=1;}}while(ch<'0'||ch>'9');while('0'<=ch&&ch<='9'){n=(n<<1)+(n<<3)+ch-48;ch=getchar();}if(f)n=-n;}
using namespace std;
int n,m;
 
struct edge{
    int y,nxt;
    edge(){}
    edge(int yy,int nn){
        y=yy,nxt=nn;
    }
}e[inf*2];
int head[inf],ecnt;
 
void addedge(int x,int y){
    ecnt++;
    e[ecnt]=edge(y,head[x]);
    head[x]=ecnt;
    return;
}
 
int vis[inf],w[inf],w2[inf];
int X,Y,P;
 
void dfs1(int u,int last){
    vis[u]=1;
    for (int i=head[u];i;i=e[i].nxt){
        int v=e[i].y;
        if (v!=last){
            if (vis[v]){
                X=u,Y=v;
            }
            else{
                w[v]=-w[u];
                dfs1(v,u);
            }
        }
    }
    return;
}
 
void dfs2(int u,int last){
    for (int i=head[u];i;i=e[i].nxt){
        int v=e[i].y;
        if (v!=last && ((u!=X || v!=Y) && (u!=Y || v!=X))){
            dfs2(v,u);
            w[u]+=w[v];
            w2[u]+=w2[v];
        }
    }
    return;
}
 
int sta[inf],top;
 
int main(){
    rd(n) rd(m)
    int x,y;
    for (int i=1;i<=m;i++){
        rd(x) rd(y)
        addedge(x,y);
        addedge(y,x);
    }
    w[1]=1;
    dfs1(1,0);
    if (n==m && w[X]==w[Y]){
        P=1;
    }
    int cnt=0,ans=0;
    for (int i=1;i<=n;i++){
        cnt+=w[i];
    }
    if (n!=m && cnt){
        puts("-1");
        return 0;
    }
    else if (n==m){
        if (P==1){
            if (cnt&1){
                puts("-1");
                return 0;
            }
            ans=abs(cnt)/2;
            w[X]-=cnt/2;
            w[Y]-=cnt/2;
        }
        else{
            if (cnt){
                puts("-1");
                return 0;
            }
            w2[X]=1,w2[Y]=-1;
        }
    }
    dfs2(1,0);
    for (int i=1;i<=n;i++){
        if (!w2[i]){
            ans+=abs(w[i]);
        }
        else{
            if (w2[i]){
                w[i]=-w[i];
            }
            sta[++top]=w[i];
        }
    }
    sta[++top]=0;
    sort(sta+1,sta+top+1);
    int tmp=sta[(top+1)/2];
    for (int i=1;i<=top;i++){
        ans+=abs(sta[i]-tmp);
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 8448
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/stack:512000000")
#include<utility>
#include<iostream>
#include<fstream>
#include<vector>
#include<array>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<functional>
#include<random>
#include<climits>
#include<queue>
#include<stack>
#include<deque>
#include<bitset>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<cassert>
#include<ccomplex>

//4Head

#define all(x) x.begin(), x.end()
#define mp make_pair
#define X first
#define Y second

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
mt19937_64 gen(time(NULL));

ll const mod = 1e9 + 7;

namespace {
	ll mul(ll a, ll b) {
		ll val = a * b - (ll)((ld)a * b / mod) * mod;
		if (val < 0) val += mod;
		if (val >= mod) val -= mod;
		return val;
	}

	ll poww(ll a, ll b) {
		ll val = 1;
		a %= mod;
		while (b > 0) {
			if (b % 2) val = mul(a, val);
			a = mul(a, a);
			b >>= 1;
		}
		return val % mod;
	}

	ll inv(ll a) {
		return poww(a, mod - 2);
	}
}

ll const maxn = 3e5 + 5;

vector<int>g[maxn], gg[maxn];
int used[maxn];
int comp = 1;
int sz[maxn];

void dfs(int u) {
	used[u] = comp;
	sz[comp]++;
	for (int v : g[u]) {
		if (used[v]) continue;
		dfs(v);
	}
}

int ans[maxn];

signed main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n, m, k; cin >> n >> m >> k;
	for (int i = 0; i < m; i++) {
		int u, v; cin >> u >> v;
		g[u].push_back(v); g[v].push_back(u);
	}
	for (int i = 0; i < k; i++) {
		int u, v; cin >> u >> v;
		gg[u].push_back(v); gg[v].push_back(u);
	}
	for (int i = 1; i <= n; i++) {
		if (!used[i]) dfs(i), comp++;
	}

	for (int i = 1; i <= n; i++) {
		ans[i] = sz[used[i]] - 1;
		unordered_set<int>st;
		for (int v : g[i]) st.insert(v);
		for (int v : gg[i]) st.insert(v);
		for (auto x : st) {
			if (used[x] == used[i]) {
				ans[i]--;
			}
		}
		cout << ans[i] << " ";
	}

	return 0;
}

/*


*/

Measured memory_bytes: 26512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
const int inf = 0x3f3f3f3f;
#define Rep(i,a,b) for(register int i=(a);i<=int(b);++i)
#define Dep(i,a,b) for(register int i=(a);i>=int(b);--i)
#define rep(i,a,b) for(register int i=(a);i<int(b);++i)
#define mem(x,v) memset(x,v,sizeof(x))
#define pc putchar
#define gc getchar
inline ll read(){
	register ll x=0,f=1;register char c=gc();
	for(;!isdigit(c);c=gc())if(c=='-')f=-1;
	for(;isdigit(c);c=gc())x=(x<<1)+(x<<3)+(c^48);
	return x*f;
}
void write(ll x){if(x<0)x=-x,pc('-');if(x>=10)write(x/10);putchar(x%10+'0');}
void wri(ll x){write(x),pc(' ');}
void writeln(ll x){write(x);pc('\n');}
int a[100035],n,l,t,x,cnt;
int main(){
	n = read(),l = read(),t = read();
	Rep(i,1,n){
		a[i] = read();x = read();
		a[i] += x==1 ? t : -t;
		cnt += a[i] / l;
		if(a[i] % l < 0) cnt--;
		((a[i]%=l)+=l)%=l;
	}sort(a+1,a+1+n);
	((cnt%=n)+=n)%=n;
	Rep(i,cnt+1,n) writeln(a[i]);
	Rep(i,1,cnt) writeln(a[i]);
	return 0;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
typedef long long int lint;

#define PI acos(-1)
#define INF64 1LL << 60
#define INF32 1 << 29
#define LIMIT(d_in, d_min, d_max) max(d_min, min(d_max, d_in))
#define all(a) (a).begin(), (a).end()
#define INV ((long long int)1000000007)

using namespace std;

void execute()
{
	int N;
	lint M;
	cin >> N >> M;
	vector<pair<lint, lint>> data(N);

	for (int i = 0; i < N; i++)
	{
		lint a, b;
		cin >> a >> b;
		data[i] = make_pair(a, b);
	}
	sort(all(data));
	lint copy_M = M;
	lint ans = 0;
	for (int i = 0; 0 < copy_M; i++)
	{
		lint count = min(data[i].second, copy_M);
		ans += data[i].first * count;
		copy_M -= count;
	}
	cout << ans << endl;
	return;
}

int main()
{
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	execute();

	int stop;
	cin >> stop;

	return 0;
}

Measured memory_bytes: 1792
#include<iostream>

using namespace std;

void swaporiginal(int* a, int* b) {
	int tmp = *a;
	*a = *b;
	*b = tmp;
	return;
}

int main() {
	int i = 1;

	while (1) {
		int	x, y;
		cin >> x >> y;
		if (x == 0 && y == 0) break;

		if (x > y) {
			swaporiginal(&x, &y);			
		}

		cout << x << " " << y << "\n";
		i++;
	}
	return 0;
}

Measured memory_bytes: 3096
#include <stdio.h>

int main(){

  int num;
  int a,b,c,d;
  while(scanf("%d",&num) != EOF){
    int i=0;
    for(a=0;a<10;a++){
      for(b=0;b<10;b++){
        for(c=0;c<10;c++){
          for(d=0;d<10;d++){
            if (a+b+c+d == num){
              i++;
            }
          }
        }
      }
    }
    printf("%d\n",i);
  }

  return 0;
}

Measured memory_bytes: 592
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.LineNumberReader;
import java.util.*;
public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
       char c[]=sc.next().toCharArray();
       int sum=0;
       for (char i:c){
           sum+=i-'0';
       }
        System.out.println(sum%9==0?"Yes":"No");


    }




    static void sort(int[] a) {
        ArrayList<Integer> l=new ArrayList<>();
        for (int i:a) l.add(i);
        Collections.sort(l);
        for (int i=0; i<a.length; i++) a[i]=l.get(i);
    }
    static void sortReverse(long[] a) {
        ArrayList<Long> l=new ArrayList<>();
        for (long i:a) l.add(i);
//        Collections.sort.(l);
        Collections.sort(l,Collections.reverseOrder());
        for (int i=0; i<a.length; i++) a[i]=l.get(i);
    }

    static class FastScanner {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st=new StringTokenizer("");
        String next() {
            while (!st.hasMoreTokens())
                try {
                    st=new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }
        int[] readArray(int n) {
            int[] a=new int[n];
            for (int i=0; i<n; i++) a[i]=nextInt();
            return a;
        }
        long nextLong() {
            return Long.parseLong(next());
        }
    }


}

Measured memory_bytes: 40976
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define sp ' '
#define nyan "(=^・ω・^=)"
#define mkp make_pair
#define intmax 2147483647
#define llmax 9223372036854775807
#define lP pair<ll,ll>
#define iP pair<int,int>
typedef long long ll;
using namespace std;
const int mod = 1000000007;

int main() {
	int N, MAX, x;
	string s;
	cin >> N >> s;
	x = MAX = 0;
	for (int i = 0; i != N; ++i) {
		if (s[i] == 'I')++x;
		else --x;
		MAX = max(MAX, x);
	}
	cout << MAX << endl;
	return 0;
}

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

const int inf = 1e9;
const ll linf = 1e18;
const ll mod = 1e9 + 7;

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

    string ans;

    if (S / 100 >= 1 && S / 100 <= 12)
    {
        if (S % 100 >= 1 && S % 100 <= 12)
        {
            ans = "AMBIGUOUS";
        }
        else
        {
            ans = "MMYY";
        }
        
    }
    else
    {
        if (S % 100 >= 1 && S % 100 <= 12)
        {
            ans = "YYMM";
        }
        else
        {
            ans = "NA";
        }
        
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
// AOJ 1075: High and Low Cube
// 2017.11.21 bal4u@uu

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

char buf[21][60];
int pos[6][2] = {{0,7},{7,0},{7,7},{7,14},{7,21},{14,7}};
char dice[2][6][7][7];
int a[2][6];
int digit[10] = { 0, 0x80084, 0x4084804, 0x4084084, 0x884080, 0x4804084, 0x4804884,
				     0x4080080, 0x4884884, 0x4884084 };

void lr(int k, int i)
{
	int r, c;
	char buf[7];
	for (r = 0; r < 7; r++) {
		memcpy(buf, dice[k][i][r], 7);
		for (c = 0; c < 7; c++) dice[k][i][r][c] = buf[6-c];
	}
}

void ud(int k, int i)
{
	int r, c;
	char buf[7];
	for (c = 0; c < 7; c++) {
		for (r = 0; r < 7; r++) buf[r] = dice[k][i][r][c];
		for (r = 0; r < 7; r++) dice[k][i][r][c] = buf[6-r];
	}
}

void rot(int k, int i)
{
	int r, c;
	char t, buf[7][7];
	for (r = 0; r < 7; r++) for (c = 0; c < 7; c++) {
		t = dice[k][i][r][c];
		if      (t == '|') t = '-';
		else if (t == '-') t = '|';
		buf[c][6-r] = t;
	}
	for (r = 0; r < 7; r++) memcpy(dice[k][i][r], buf[r], 7);
}

int parse(int k, int i)
{
	int j, r, c, s;
	for (s = 0, r = 1; r < 6; r++) for (c = 2; c < 5; c++) {
		s <<= 2;
		if      (dice[k][i][r][c] == '-') s |= 1;
		else if (dice[k][i][r][c] == '|') s |= 2;
	}
	for (j = 1; j < 10; j++) if (digit[j] == s) break;
	return j;
}

int main()
{
	int i, j, k, r, x, ans;

	while (fgets(buf[0], 60, stdin) && *buf[0] != '0') {
		for (i = 1; i < 21; i++) fgets(buf[i], 60, stdin);
		for (x = 0, k = 0; k < 2; k++, x = 29) {
			for (i = 0; i < 6; i++) for (r = 0; r < 7; r++)
				memcpy(dice[k][i][r], &buf[r+pos[i][0]][x+pos[i][1]], 7);
		}

		for (k = 0; k < 2; k++) {
			for (i = 0; i < 6; i++) {
				if (i == 0 || i == 2 || i == 4) lr(k, i);
				else if (i == 1) rot(k, i), lr(k, i);
				else if (i == 3) rot(k, i), rot(k, i), rot(k, i), lr(k, i);
				else if (i == 5) lr(k, i), ud(k, i);
				a[k][i] = parse(k, i);
			}
		}

		ans = 0;
		for (i = 0; i < 6; i++) for (j = 0; j < 6; j++) {
			if      (a[0][i] > a[1][j]) ans++;
			else if (a[0][i] < a[1][j]) ans--;
		}
		puts(ans < 0 ? "LOW" : "HIGH");
	}
	return 0;
}

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

using namespace std;

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

int H,W;
string S[55];

int main(){
	cin >> H >> W;
	repp(i,0,H) cin >> S[i];
	repp(i,0,H){
		repp(j,0,W){
			if(S[i][j] == '#') continue;
			int z = 0;
			repp(x,-1,2){
				repp(y,-1,2){
					if(i+x < 0 || i+x >= H || j+y < 0 || j+y >= W) continue;
					if(S[i+x][j+y] == '#') ++z;
				}
			}
			S[i][j] = '0' + z;
		}
	}
	repp(i,0,H) cout << S[i] << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
int main()
{
	int a,b,c,d;
	
	cin>>a>>b>>c>>d;
	
	if(a+b>c+d)   cout<<"Left"<<endl;
	if(a+b<c+d)   cout<<"Right"<<endl;
	if(a+b==c+d)   cout<<"Balanced"<<endl;
	
	return 0;
}

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

typedef long long ll;
// const int INF = 1e8;
const ll INF = 1LL << 60;
typedef pair<int, int> P;

ll N, A, B;

int main() {
    cin >> N >> A >> B;

    ll group = N / (A + B);
    ll tmp = group * (A + B);
    ll ans = group * A;
    if (N - tmp > 0) {
        ans += min(N - tmp, A);
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
//
//  abc_117_b_hanaoka.cpp
//  Competitive
//
//  Created by HosonoHiroaki on 2019/02/08.
//  Copyright © 2019年 HosonoHiroaki. All rights reserved.
//

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int abc117_c(){
  // 入力
  int n,m,e;
  cin >> n >> m;
  vector<int> v;
  for (int i = 0; i < m; ++i) {
    cin >> e;
    v.push_back(e);
  }
  
  sort(v.begin(), v.end());
  vector<int> diff;
  for (int i = 1; i < v.size(); ++i) {
    diff.push_back(v[i] - v[i-1]);
  }
  sort(diff.begin(), diff.end());
  int ret = 0;
  for (int i = 0; i < m - n ; ++i) {
    ret += diff[i];
  }
  cout <<ret<<endl;
  
  return 0;
}

int main() {
  abc117_c();
}


Measured memory_bytes: 1400
using System;

public class Test
{
	public static void Main()
	{
		while(true) {
			string[] s = Console.ReadLine().Split(' ');
			
			var H = int.Parse(s[0]);
			var W = int.Parse(s[1]);
			
			if( (H == 0) && (W == 0) )	break;
			
			string line1 = "";
			string line2 = "";
			
			for(int i = 0; i < W; i++) {
				if( (i%2) == 0 ) {
					line1 += "#";
					line2 += ".";
				} else {
					line1 += ".";
					line2 += "#";
				}
			}
			
			for(int i = 0; i < H; i++) {
				if( (i%2) == 0 ) {
					Console.WriteLine(line1);
				} else {
					Console.WriteLine(line2);
				}
			}
			
			Console.WriteLine();
		}
	}
}

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

using namespace std;

#define ll long long 
#define ld long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mkp make_pair
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define ff first
#define ss second
#define endl "\n"
#define MOD 1000000007
#define MOD1 998244353
#define inf 1e18

ll GCD(ll x,ll y){if(y==0)return x;return GCD(y,x%y);}
ll LCM(ll x,ll y){return (x*y)/(GCD(x,y));}
ll LOGK(ll x,ll k){if(x>=k)return 1+LOGK(x/k,k);return 0;}
ll MPOW( ll a, ll b, ll m) { if(b==0) return 1; ll x=MPOW(a,b/2,m); x=(x*x)%m; if(b%2==1) x=(x*a)%m; return x;}
ll MINV(ll a,ll m) {return MPOW(a,m-2,m);}

class pnc{
  ll FACT_MAX,MODU;
  vector<ll> fact;
public:
  pnc( ll n, ll m) { FACT_MAX = n; fact.resize(FACT_MAX); MODU = m; MFACT_INIT(MODU);}
  void MFACT_INIT( ll m) { fact[0]=1; for(ll i=1;i<FACT_MAX;++i) fact[i]=(i*fact[i-1])%MODU;}
  ll MFACT( ll n) { return fact[n];}
  ll PERM( ll n, ll r) { return (fact[n]*::MINV(fact[n-r],MODU))%MODU;}
  ll COMB( ll n , ll r) { return (PERM(n,r)*::MINV(fact[r],MODU))%MODU;}
};

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

    ll test=1;
    // cin>>test;
    while(test--)
    {
        ll n;
        cin>>n;

        string str;
        cin>>str;

        ll ans=0;

        ll i=0,j=n-1;

        while(i<j)
        {
            while(str[i]=='R' && i<n)
            i++;

            while(str[j]=='W' && j>0)
            j--;

            if(i<j)
            {
                ans++;
                i++;
                j--;
            }
        }

        cout<<ans;
    }
}

Measured memory_bytes: 3768
#include<iostream>
#include<vector>
#include<string>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= (int)end; --i)
#define all(x) (x).begin(), (x).end()
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 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    char a;
    cin >> a;
    if (a >= 'a' && a <= 'z') {
        cout << "a" << endl;
    } else {
        cout << "A" << endl;
    }
    return 0;
}

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

int main(){
  long long n, m; cin >> n >> m;
  long long ans = 0;
  if(n == 1){
    if(m == 1) ans = 1;
    else ans = m - 2;
  }else if(m == 1) ans = n - 2;
  else ans = (n-2) * (m-2);
  
  cout << ans << endl;
}

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

using namespace std;


int main() {
	int n, p, d1, d2, max, id;

	while (cin >> n, n) {
		max = 0;
		for (int i = 0; i < n; ++i) {
			cin >> p >> d1 >> d2;
			if ((d1 + d2) > max) {
				max = d1 + d2;
				id = p;
			}
		}
		cout << id << " " << max << endl;
	}

	return 0;
}


Measured memory_bytes: 3088
#include <iostream>
#include <string>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <list>
#include <iomanip>
#include <vector>
#include <functional>
#include <algorithm>
#include <cstdio>
#include <random>
#include <ctime>
#include <cstdlib>
#include <unordered_map>
#include <string.h>
#include <iostream>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(begin, i, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main()
{
    int N;
    cin >> N;
    map<P, int> mp;
    int a;
    rep(0, i, N)
    {
        cin >> a;
        a--;
        mp[make_pair(min(i, a), max(i, a))]++;
    }
    int ans = 0;
    for (auto m : mp)
    {
        ans += m.second / 2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 6528
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.IntStream;

/**
 * 解説通りに作成したソースコード
 */
public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt(), m = scanner.nextInt(), q = scanner.nextInt();
			int[][] x = new int[n + 1][n + 1], c = new int[n + 1][n + 1];
			IntStream.range(0, n + 1).forEach(i -> Arrays.fill(x[i], 0));
			IntStream.range(0, m).forEach(i -> x[scanner.nextInt()][scanner.nextInt()]++);
			Arrays.fill(c[0], 0);
			IntStream.rangeClosed(1, n).forEach(i -> c[i][0] = 0);
			IntStream.rangeClosed(1, n)
					.forEach(i -> IntStream.rangeClosed(1, n).forEach(j -> c[i][j] = c[i][j - 1] + x[i][j]));
			IntStream.range(0, q).forEach(i -> {
				int l = scanner.nextInt(), r = scanner.nextInt();
				System.out.println(IntStream.rangeClosed(l, r).map(j -> c[j][r] - c[j][l - 1]).sum());
			});
		}
	}
}


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

#define TRACE(x) x
#define WATCH(x) TRACE(cout << #x" = " << x << endl)
#define WATCHR(a, b) TRACE(for (auto it=a; it!=b;) cout << *(it++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end());})

#define all(x) (x).begin(), (x).end()

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

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

    int N;
    cin >> N;

    vvi adj(N);
    for (int i = 0; i < N - 1; i++) {
        int u, v;
        cin >> u >> v;
        adj[u-1].push_back(v-1);
        adj[v-1].push_back(u-1);
    }

    auto dist = [&](int rt) {
        vi res(N, -1);
        res[rt] = 0;
        queue<int> bfs({ rt });
        while (!bfs.empty()) {
            int loc = bfs.front();
            bfs.pop();
            for (int nbr : adj[loc]) {
                if (res[nbr] == -1) {
                    res[nbr] = res[loc] + 1;
                    bfs.push(nbr);
                }
            }
        }
        return res;
    };

    vi dist0 = dist(0);
    int x = 0;
    for (int i = 1; i < N; i++) {
        if (dist0[i] > dist0[x])
            x = i;
    }

    vi distX = dist(x);
    int mx = 0;
    for (int v : distX)
        mx = max(mx, v);
    mx++;

    vb win(mx + 1);
    win[0] = false;
    win[1] = true;
    win[2] = false;
    for (int d = 3; d <= mx; d++) {
        win[d] = (!win[d-1]) | (!win[d-2]);
    }

    cout << (win.back() ? "First" : "Second") << endl;

    return 0;
}



Measured memory_bytes: 14324
#include<iostream>
#include <string>
using namespace std;
int main() {
	int K = 0, S = 0,count=0;
	//Sが合計値、Kはそれより小さく
	cin >> K >> S;
	for (int i = 0; i <= K; i++) {
		for (int j = 0; j <= K; j++) {
			if (i + j <= S&&S-i-j<=K) {
				
					count++;
				
			}
		}
	}
	cout << count;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll                      long long int
#define fi                      first
#define se                      second
#define pb                      push_back
#define pbb                     pop_back
#define mp                      make_pair
#define pii     	            pair<int,int>
#define all(x)                  x.begin(), x.end()
#define mem(array, value)       memset(array, value, sizeof(array))
#define endl                    "\n"
#define fastRead 	            ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define pi      	            (2 * acos(0.0))
#ifdef Lollipop
    #define line                    cout << "\n===================\n"
    #define trace(...)              __f( #__VA_ARGS__ , __VA_ARGS__ )
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cerr << name << " = " << arg1 << "\n";
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ',');
        cerr.write(names, comma - names) << " = " << arg1 << " , ";
    __f(comma + 1, args...);
    }
#else
    #define line
    #define trace(...)
#endif


int main ()
{
    #ifdef Lollipop
        //freopen ("input.txt", "r", stdin);
        //freopen ("output.txt", "w", stdout);
    #endif
    fastRead;
    double r;
    cin >> r;
    cout << fixed << setprecision(15) << 2 * pi * r << endl;
    return 0;
}




Measured memory_bytes: 3792
#include <bits/stdc++.h>
  using namespace std;
  #define FASTIO std::ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);


  int main () {
    long long int n, k, c, d;
    cin >> n >> k;
    c = n / k;
    n -= c * k;
    d = abs(n - k);
    cout << min(n, d) << endl;
  }


Measured memory_bytes: 256
n,k = map(int, input().split())
hito = []
for i in range(k):
  d = int(input())
  x = list(map(int, input().split()))
  for j in range(d):
    hito.append(x[j])
a = list(set(hito))
ans = n
for i in range(n):
  if i+1 in a:
    ans -= 1
print(ans)

Measured memory_bytes: 9112
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <queue>
#include <algorithm>
#include<iostream>
#include<vector>
#include<map>
#include<string>
#include <iomanip>
#include<deque>
#include<stack>
#include<set>

using namespace std;
typedef unsigned int uint;
typedef long long ll;
//typedef pair<int, int> P;
const int INF = 111111111;
const ll LLINF = 1e17 + 1;
const int DX[9] = { 0,0,1,-1, 1, 1, -1, -1, 0 }; // 4;４近傍
const int DY[9] = { 1,-1,0,0, 1, -1, 1, -1, 0 }; // 8:８近傍 9:(0,0)を含む
const int DIV = 1000000007; //10^9 + 7
const double PI = 3.14159265358979323846264338327950288;



int main() {

	//==================================
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	//==================================

	int N, K;
	string S;
	cin >> N >> K >> S;

	int happy = 0;
	for (int i = 0; i < N; i++) {
		if (i != N-1 && S[i] == 'R' && S[i + 1]== 'R') {
			happy++;
		}
		else if (i!=0 && S[i] == 'L' && S[i - 1] == 'L') {
			happy++;
		}
	}

	for (int i = 0; i < K; i++) {
		if (happy == N - 1) {
			break;
		}
		else if (happy == N - 2) {
			happy = N - 1;
		}
		else {
			happy += 2;
		}

	}

	cout << happy;

}



Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <cstdio>
#include <cstdlib>

#ifdef _MSC_VER
#include <Windows.h>
#else
#include <unistd.h>
#endif

using namespace std;

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

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

//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())

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

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD=(LL)1e9+7;
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

#define INF 1LL << 50

struct UnionFind
{
    vector<int> par;
    vector<int> sizes;

    UnionFind(int n) : par(n), sizes(n, 1) {
        REP(i,n) par[i] = i;
    }

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

    void unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y) return;
        if (sizes[x] < sizes[y]) swap(x, y);
        par[y] = x;
        sizes[x] += sizes[y];
    }

    bool same(int x, int y) {
        return find(x) == find(y);
    }
    int size(int x) {
        return sizes[find(x)];
    }
};
vector<LL>L[(int)1e5+2];
int main(){
    int N,M;
    cin>>N>>M;
    
    REP(i,N){
        int K;
        cin>>K;
        REP(j,K){
            int l;
            cin>>l;l--;
            L[l].PB(i);
        }
    }
    UnionFind uf(N);
    REP(i,M)FOR(j,1,SZ(L[i])){
        uf.unite(L[i][j],L[i][0]);
    }
    if(uf.size(0)==N){
        cout<<"YES"<<endl;
    }else{
        cout<<"NO"<<endl;
    }
    return 0;
}


Measured memory_bytes: 4992
#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()
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

string solve(string s, int k) {
	int n = s.size();
	vector<string> v;
	map<string, int> mp;
	for (int i = 0; i < n; i++) {
		for (int j = 1; j <= 5; j++) {
			if (i + j - 1 > n) continue;
			string t = s.substr(i, j);
			if (mp[t]) continue;
			mp[t]++;
			v.push_back(t);
		}
	}
	sort(ALL(v));
	return v[k - 1];
}

int main() {
	string s;
	cin >> s;
	int k;
	cin >> k;
	cout << solve(s, k) << endl;
}

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

int main(){
    int H,W;
    
    while(1){
        cin >> H >> W;
        if(H==0 && W==0)break;

        for(int i=0;i<H ; i++){
            for(int j=0 ; j<W ; j++){
                if((i+j)%2 == 0){
                    cout <<"#";
                }else{
                    cout <<".";
                }
             }
             cout << "\n";
            }
            cout << endl;
    }

    return 0;
}


Measured memory_bytes: 3088
#include<bits/stdc++.h>
using namespace std;
#define REP(i,st,ed) for(int i=(int)(st),i##end=(int)(ed);i<=i##end;++i)
#define DREP(i,st,ed) for(int i=(int)(st),i##end=(int)(ed);i>=i##end;--i)
template<typename T>bool chkmin(T &x,const T &y){return x>y?x=y,1:0;}
template<typename T>bool chkmax(T &x,const T &y){return x<y?x=y,1:0;}
#ifdef __linux__
#define getchar getchar_unlocked
#define putchar putchar_unlocked
#endif
template<typename T>T read(){
	T x=0,f=1;
	char c=getchar();
	while((c<'0')||(c>'9')){if(c=='-')f=-1;c=getchar();}
	while((c>='0')&&(c<='9'))x=(x<<1)+(x<<3)+(c^48),c=getchar();
	return x*f;
}
#define read() read<int>()
template<typename T>void write(T x,char c){
	static char t[25];
	static int tlen;
	t[tlen=1]=c;
	if(x<0)putchar('-'),x=-x;
	do t[++tlen]=(x%10)^48;
	while(x/=10);
	while(tlen)putchar(t[tlen--]);
}
#define pb push_back
typedef long long ll;
typedef double lf;
int n,A,B;
int main(){
	n=read(),A=read(),B=read();
	if(A+B-1>n)return puts("-1"),0;
	else if(1ll*A*B<n)return puts("-1"),0;
	int now=n;
	DREP(i,B,1){
		printf("%d ",i);
		REP(j,max(A+B,now-A+2),now)printf("%d ",j);
		now=max(A+B-1,now-A+1);
	}
	REP(i,B+1,B+A-1)printf("%d%c",i,i==B+A-1?'\n':' ');
	return 0;
}

Measured memory_bytes: 2176
import java.io.*;
import java.math.*;
import java.util.*;

public class Main {
    private static boolean debug = false;
    private static boolean elapsed = false;

    private static PrintWriter _out = new PrintWriter(System.out);
    private static PrintWriter _err = new PrintWriter(System.err);

    private void solve(Scanner sc) {
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();

        _out.println(Math.min(a + b, Math.min(b + c, c + a)));
    }
    private static BigInteger C(long n, long r) {
        BigInteger res = BigInteger.ONE;
        for (long i = n; i > n - r; --i) {
            res = res.multiply(BigInteger.valueOf(i));
        }
        for (long i = r; i > 1; --i) {
            res = res.divide(BigInteger.valueOf(i));
        }
        return res;
    }
    private static BigInteger P(long n, long r) {
        BigInteger res = BigInteger.ONE;
        for (long i = n; i > n - r; --i) {
            res = res.multiply(BigInteger.valueOf(i));
        }
        return res;
    }
    /*
     * 10^10 > Integer.MAX_VALUE = 2147483647 > 10^9
     * 10^19 > Long.MAX_VALUE = 9223372036854775807L > 10^18
     */
    public static void main(String[] args) {
        long S = System.currentTimeMillis();

        Scanner sc = new Scanner(System.in);
        new Main().solve(sc);
        _out.flush();

        long G = System.currentTimeMillis();
        if (elapsed) {
            _err.println((G - S) + "ms");
        }
        _err.flush();
    }
}

Measured memory_bytes: 21588
#include <iostream>
#include <string>
#include <unordered_map>
#include <stdio.h>
#include <list>
#include <vector>
#include <algorithm>
#include <stack>
#include <climits>
#include <cmath>
#include <map>
#include <queue>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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

int main()
{
	ll a,b;cin >> a >> b;
	ll foo = gcd(a,b);
	cout<<a*b/foo<<endl;
	return 0;
}

Measured memory_bytes: 256