akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define ll long long
#define db long double
#define ii pair<int,int>
#define vi vector<int>
#define fi first
#define se second
#define sz(a) (int)(a).size()
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define FN(i, n) for (int i = 0; i < (int)(n); ++i)
#define FEN(i,n) for (int i = 1;i <= (int)(n); ++i)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repv(i,a,b) for(int i=b-1;i>=a;i--)
#define SET(A, val) memset(A, val, sizeof(A))
typedef tree<int ,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set ;
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the kth largest element.(0-based)
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
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 trace(...)
#endif
const int N=100005;
int a[N];
int main()
{
  std::ios::sync_with_stdio(false);
  cin.tie(NULL) ; cout.tie(NULL) ;
  int n;
  cin>>n;
  rep(i,1,n+1) cin>>a[i];
  int ans=0;
  rep(i,1,n+1)
    {
      if(a[i]==i)
	{
	  if(i<n)
	    swap(a[i],a[i+1]);
	  else
	    swap(a[i],a[i-1]);
	  ans++;
	}
    }
  cout<<ans<<endl;
  return 0 ;
}


Measured memory_bytes: 640
n = int(input())
a = list(input() for _ in range(n))

ad = []
for i in range(n):
    ad.append(dict())
    for c in a[i]:
        ad[i][c] = ad[i].get(c, 0) + 1#d[i]はS[i]の(各文字:文字数)の辞書
chrs = 'abcdefghijklmnopqrstuvwxyz'
d = dict()
for c in chrs:
    buf = float('inf')
    for i in range(n):
        buf = min(buf, ad[i].get(c, 0))
    d[c] = buf
d = list(tuple((k, v)) for k, v in d.items())
d = sorted(d, key=lambda x:x[0])
ans = ''
for k, v in d:
    ans += k * v
print(ans)       

Measured memory_bytes: 3064
function main( input ){

  input = input.split( /\s/ )

  var A = Number( input[0] ),
      B = Number( input[1] )

  if( ( A + B ) % 3 === 0 || A % 3 === 0 || B % 3 === 0 )
    console.log( 'Possible' )
  else
    console.log( 'Impossible' )

}

main(
  require( 'fs' )
    .readFileSync( '/dev/stdin', 'utf8' )
)


Measured memory_bytes: 21192
#include<stdio.h>

int main(void){

int h,w,i,j;

	while(1){
		scanf("%d %d",&h,&w);

		if(h==0 && w==0) break;
		for(i=0; i<h; i++){
			for(j=0; j<w; j++){
				printf("#");
			}puts("");
		}puts("");
	}
	return 0;
}

Measured memory_bytes: 588
#if __has_include("debug.h")
    #include "debug.h"
#else  
#include <bits/stdc++.h>
using namespace std;
#define d(...) 2;
#endif

#define int long long int
#define ld long double

#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"      

#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define ff first
#define ss second
#define eps 1e-10
#define PI acos(-1LL)

#define gcd(a,b)            __gcd((a),(b))
#define lcm(a,b)            ((a*b)/gcd(a,b))

void solve();

int32_t main()
{
    #ifdef DEBUG
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
    #endif 

    fast
    
    int t = 1;
	// cin>>t;
	
	while(t--)
	    solve();
	return 0;  
}

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

	vector<int>a(n);

	for(i=0;i<n;i++)
	{
		cin>>a[i];
		a[i]/=2;
	}

	int lc=1;

	for(i=0;i<n;i++)
	{
		lc=lcm(lc,a[i]);
	}

	 int flag=0;
    for(int i=0;i<n;i++){
        int temp=(lc)/a[i];
        if(temp%2==0){
            flag=1;
            break;
        }
    }


	d(lc);

	if(flag)
	{
		cout<<0<<endl;
		return ;
	}

	int multi=m/lc;

	d(multi);

	multi=ceil(multi/(long double)2);

	cout<<multi<<endl;

}

Measured memory_bytes: 3976
package main
import (
  "bufio"
  "os"
  "strconv"
  "strings"
  "fmt"
)

func Solve() {
  var H, W, M, h, w int
  var ok bool
  NextInt(&H, &W, &M)
  X := make([]int, H)
  Y := make([]int, W)
  B := make(map[int]map[int]struct{})
  for i := 0; i < M; i++ {
    NextInt(&h, &w)
    h--; w--
    X[h]++; Y[w]++
    if _, ok = B[h]; !ok { B[h] = make(map[int]struct{}) }
    B[h][w] = struct{}{}
  }
  mx := MaxInt(X...)
  MX := make([]int, 0)
  for i, x := range X { if x == mx { MX = append(MX, i) } }
  my := MaxInt(Y...)
  MY := make([]int, 0)
  for i, y := range Y { if y == my { MY = append(MY, i) } }
  E := mx + my - 1
  L: 
    for _, x := range MX {
      for _, y := range MY {
        if _, ok = B[x][y]; ok { continue }
        E++
        break L
      }
    }
  Write(E)
}

func main() {
  Solve()
  Output()
}

var reader = bufio.NewReaderSize(os.Stdin, 1000000)
var writer = bufio.NewWriter(os.Stdout)
func NextLine() string {
  buffer := make([]byte, 0)
  for true {
    line, isPrefix, err := reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer, line...)
    if !isPrefix { break }
  }
  return string(buffer)
}
func NextInt(A ...*int) {
  L := strings.Split(NextLine(), " ")
  for i, a := range A {
    *a, _ = strconv.Atoi(L[i])
  }
}
func NextIntSlice(A *[]int) {
  L := strings.Split(NextLine(), " ")
  if len(L) == 1 && L[0] == "" {
    (*A) = make([]int, 0)
    return
  }
  (*A) = make([]int, len(L))
  for i, l := range L {
    (*A)[i], _ = strconv.Atoi(l)
  }
}
func NextFloat(A ...*float64) {
  L := strings.Split(NextLine(), " ")
  for i, a := range A {
    *a, _ = strconv.ParseFloat(L[i], 64)
  }
}
func NextFloatSlice(A *[]float64) {
  L := strings.Split(NextLine(), " ")
  if len(L) == 1 && L[0] == "" {
    (*A) = make([]float64, 0)
    return
  }
  (*A) = make([]float64, len(L))
  for i, l := range L {
    (*A)[i], _ = strconv.ParseFloat(l, 64)
  }
}
func Write(S ...interface{}) {
  fmt.Fprintln(writer, S...)
}
func WriteIntSlice(A []int) {
  B := make([]interface{}, len(A))
  for i, a := range A { B[i] = a }
  fmt.Fprintln(writer, B...)
}
func Output() {
  _ = writer.Flush()
}
func MaxInt(A ...int) int {
  max := A[0]
  for _, a := range A {
    if max < a { max = a }
  }
  return max
}
func MinInt(A ...int) int {
  min := A[0]
  for _, a := range A {
    if a < min { min = a }
  }
  return min
}
func SumInt(A ...int) int {
  sum := 0
  for _, a := range A {
    sum += a
  }
  return sum
}

Measured memory_bytes: 100020
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i) = 0; (i) < (n); ++(i))
#define rrep(i,n) for(int (i) = (n) - 1; (i) >= 0; --(i)) //Reversi rep
#define nfor(i,a,b) for(int (i) = (a); (i) < (b); ++(i)) //Natural for
#define rfor(i,a,b) for(int (i) = (b); (i) >= (a); --(i)) //Reversi for
#define ll long long
#define mod (1000000007)
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;

int asc(const void *a, const void *b) {
    return *(int *)a - *(int *)b;
}

int desc(const void *a, const void *b) {
    return *(int *)b - *(int *)a;
}

int main()
{
    int n,l;
    cin >> n >> l;
    vector <string> s(n);
    rep(i, n)cin >> s.at(i);
    sort(s.begin(), s.end());
    rep(i, n)cout << s.at(i);
    cout << endl;
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
//#include<tr1/unordered_map>
#pragma GCC optimize ("Ofast")
#define ll long long
#define pll pair<long long,long long>
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define forn(i, n) for(int i=0; i<int(n); i++)
#define Forn(i, n) for(int i=1; i<=int(n); i++)

using namespace std;

/*#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> rbtree;*/

int n;
int a[30010];
bool ok1[10], ok2[10][10], ok3[10][10][10];

int main()
{
    cin.tie(0);ios_base::sync_with_stdio(false);
    cin >> n;
    Forn(i, n)
    {
        char x;
        cin >> x;
        a[i] = x - '0';
    }
    Forn(i, n)
    {
        forn(j, 10) forn(k, 10) if(ok2[j][k]) ok3[j][k][a[i]] = 1;
        forn(j, 10) if(ok1[j]) ok2[j][a[i]] = 1;
        ok1[a[i]] = 1;
    }
    int ans = 0;
    forn(i, 10) forn(j, 10) forn(k, 10) if(ok3[i][j][k])
    {
        //cout << i << j << k << endl;
        ans++;
    }
    cout << ans << endl;
}


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

int N; vector<int> a;


vector<int> DP;

vector<vector<int>> to;

void dfs(int v){ 
 
  if(to[v].empty()){ DP[v] = 1; return;}
  
  vector<int> res;
  
  for(auto p : to[v]){
    
    dfs(p);
    
    res.push_back(DP[p]);
    
  }
  
  sort(res.rbegin(),res.rend());
  
  int m = 0;
  
  for(int i = 0; i < (int)res.size(); i++){
    
    m = max(m, res[i]+i+1);
  }
  
  DP[v] = m;
  
  return;
  
}
    
int main(){
  
  cin >> N;
  
  to.resize(N); DP.resize(N);
 
  for(int i = 1; i < N; i++){
    int a; cin >> a; a--;
    //ノードは全て0-indexed,優勝するのは0
    
    to[a].push_back(i); //勝った方から負けた方へノードを張る
    
  } 
  
  dfs(0); //0を頂点として、木DPを行う
  
  cout << DP[0]-1 << endl;
  
  return 0;
}
  

Measured memory_bytes: 17024
import java.util.Scanner;

public class Main{ public static void main(String...args){
    Scanner sc = new Scanner(System.in);
    String S = sc.next();

    if(S.length() < 6) System.out.print("No");
  	else{
      if(S.charAt(2) == S.charAt(3) && S.charAt(4) == S.charAt(5)) System.out.print("Yes");
      else System.out.print("No");}
	}
}

Measured memory_bytes: 22996
import bisect

N=int(input())
A=list(map(int,input().split()))
A.sort()
B=list(map(int,input().split()))
B.sort()
C=list(map(int,input().split()))
C.sort()

ans=0
for i in range(N):
    a=bisect.bisect_right(A,B[i]-1)
    c=N-bisect.bisect_left(C,B[i]+1)
    ans+=a*c
print(ans)

Measured memory_bytes: 29332
import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        int a = scanner.nextInt();
        int b = scanner.nextInt();
        int H = scanner.nextInt();
        int M = scanner.nextInt();

        double aKakudo = (H + (M / 60.0)) * 30;
        double bKakudo = M * 6;

        double kakudo = Math.abs(aKakudo - bKakudo);
        if (kakudo > 180) {
            kakudo = 360 - kakudo;
        }

//        System.out.println("kakudo=" + kakudo);

        double cosC = Math.cos(Math.toRadians(kakudo));
//        System.out.println("cosC=" + cosC);

        double cc = a * a + b * b - 2 * a * b * cosC;
//        System.out.println("cc=" + cc);

        double c = Math.sqrt(cc);
        System.out.println(c);

    }
}


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

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

typedef pair<int, int> Pi;
typedef tuple<int, int, int> Ti;
typedef vector<int> vint;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

int H, N, P, M, K;
vint line;

vector<vint> amida;

double dp[2][128][128];

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  cin >> H >> N >> P >> M >> K;
  --P;

  resz(line, H, -1);
  rep(i, M) {
    int a, b;
    cin >> a >> b;
    line[H-a] = --b;
  }

  memset(dp, 0, sizeof(dp));

  double (*curr)[128] = dp[0];
  double (*next)[128] = dp[1];

  curr[0][P] = 1;

  rep(i, H) {
    rep(k, K+1) rep(j, N) next[k][j] = 0;
    if(~line[i]) { // ???????????????????????????????????????????¢???????swap
      rep(k, K+1) rep(j, N) next[k][j] = curr[k][j];
      rep(k, K+1) {
	next[k][line[i]] = curr[k][line[i]+1];
	next[k][line[i]+1] = curr[k][line[i]];
      }
      swap(curr, next);
      continue;
    }
    int cnt = 0; // ??????????????????????±??????£???????????????????????°
    reps(j, i, H) if(line[j] == -1) cnt++;
    if(cnt == 0) {
      rep(k, K+1) rep(j, N) next[k][j] += curr[k][j];
      continue;
    }
    rep(k, K+1) {
      double p = (double)(K-k)/cnt; // ??????cnt?????????????????????(K-k)????????¬???????????°??????
      rep(j, N) next[k][j] += curr[k][j]*(1-p); // ??????i????????°??????????????°??????????????????
    }
    rep(k, K) {
      double p = (double)(K-k)/cnt; // ??????cnt?????????????????????(K-k)????????¬???????????°??????
      rep(j, N) {
	double x = 0;
	if(j > 0) {
	  next[k+1][j-1] += curr[k][j]*p/(N-1); // ??????i????????°????????????????£?j-1&j????????????????¢???????p*1/(N-1)
	  x += 1.0/(N-1);
	}
	if(j < N-1) {
	  next[k+1][j+1] += curr[k][j]*p/(N-1); // ?£?j&j+1
	  x += 1.0/(N-1);
	}
	next[k+1][j] += curr[k][j]*p*(1-x); // ??????i????????°?????????(1-x)????¢??????§?£?j????????¢??????????????????????????????
      }
    }
    swap(curr, next);
  }
  /*
  rep(i, H+1) {
    rep(k, K+1) {
      rep(j, N) cout<<dp[i][k][j]<<" ";
      cout<<endl;
    }
    cout<<endl;
  }
  */
  double ans = 0;
  rep(i, N) chmax(ans, curr[K][i]);
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3548
#include <stdio.h>
int main (){
  int a,b,sum=0;
  scanf ("%d%d",&a,&b);
  for (int i=0;i<a;i++){
  sum=sum+b+i;
  }
  if (b>-1){
  sum=sum-b;
  }
  else if (b<0 && b+a>0){
  sum=sum;
  }
  else{
  sum=sum-(b+a-1);
  }
 printf ("%d",sum);
return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
using namespace std;

const int N = 1e6 + 100;
bool pr[500001];
vector<int>v;
void sieve()
{

    for(int i = 2; i<=1e5; i++)
    {
        if(pr[i]==0)
        {
            for(int j = i+i; j<=1e4; j+=i)
                pr[j] = 1;
        }
    }
    for(int i = 2; i<=1e5; i++)
    {
        if(pr[i]==0)
        {
            v.pb(i);

        }
    }

}


int main()
{

    // freopen("in.txt", "r", stdin);
    // sieve();
    int t=1;

   // cin >> t;
    while(t--)
    {

        int n;
        cin >> n;
        cout << n+n*n+n*n*n << endl;
    }


    return 0;
}


Measured memory_bytes: 3600
from heapq import heappush, heappop
N, M = map(int, input().split())
dic = {i:[] for i in range(1,N+1)}
ans = [0]*M
for i in range(M):
  p, y = map(int, input().split())
  heappush(dic[p], (y,i))

for k in dic.keys():
  count = 1
  p = str(k)
  while len(p)<6:
    p = '0'+p
  while dic[k]:
    y, i = heappop(dic[k])
    a = str(count)
    while len(a)<6:
      a = '0'+a
    ans[i] = p+a
    count += 1
for a in ans:
  print(a)

Measured memory_bytes: 92772
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;

#define INF 1e9
#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

ll N, b, ans, th = 0;
vll A;
double mean = 0.0;
map<int, int> MP;

ll calc_abs(int b){
    ll buff = 0;
    rep(i,N)
        buff += abs(A[i] - b);
    return buff;
}

void solve(){
    if(N % 2 == 0)
        b = (A[N/2 - 1] + A[N/2])/2.0;
    else
        b = A[N/2] * 1.0;

    cout << calc_abs(b) << endl;
}

int main(){
    cin >> N;
    A.resize(N);
    rep(i,N){
        cin >> A[i];
        A[i] -= i+1;
    }

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

    solve();
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
#define RF(x) freopen(x,"r",stdin)
#define WF(x) freopen(x,"w",stdout)
typedef long long LL;
using namespace std;
typedef pair<LL,LL> PLL;
typedef pair<int,int> PII;
const LL MOD = (LL)1e9+7;
const int SIZE = 2e5+5;
const LL INF = 1LL<<60;
const double eps = 1e-4;
const double PI=3.1415926535897932;

int h[100009];

int main(){
	DRII(n,k);
	REP(i,n)RI(h[i]);
	int bmax=1<<n;
	LL ans=INF;
	REP(bm,bmax){
		int bc=0;
		LL cost=0;
		int chm=0;
		REP(i,n){
			if(bm&(1<<i)){//pick building!
				int nh=max(h[i],chm+1);
				cost+=nh-h[i];
				chm=nh;
				bc++;
			}
			else{
				chm=max(chm,h[i]);
			}
		}
		if(bc==k)ans=min(ans,cost);
	}
	printf("%lld\n",ans);
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cstdio>
using namespace std;
using ll = long long;
int main(){
  int n,r;
  cin >> n >> r;
  if(n>=10){
    cout << r << "\n";
  }else{
    cout << r + 100 * (10 - n) << "\n";
  }
  return 0;
}

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

using namespace std;

int main()
{
    int a , b , c;
    cin >> a >> b >> c;
    set<int>st;
    st.insert(a);
    st.insert(b);
    st.insert(c);
    if(st.size() == 2){
        cout << "Yes\n";
    }else{
        cout << "No\n";
    }


}


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

int main(){
    while(1){
        int n,l,r;
        cin >> n >> l >> r;
        if(n==0) break;

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

        int ans = 0;
        for(int i=l; i<=r; i++){
            int minj = n;
            for(int j=0; j<n; j++){
                if(i%a[j] == 0){
                    minj = j;
                    break;
                }
            }
            if(minj%2==0) ans++;
        }
        cout << ans << endl;
    }
    return 0;
}



Measured memory_bytes: 3092
#include "math.h"
#include <algorithm>
#include <complex>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define ifor(i, a, b) for (int i = (a); i < (b); i++)
#define rfor(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
using namespace std;
typedef long double ld;
typedef long long int lli;
const double eps = 1e-11;
int vex[4] = {1, 0, -1, 0};
int vey[4] = {0, 1, 0, -1};
lli MOD = 1000000007;
#define UF_MAX 200005
struct UFind {
    int par[UF_MAX];
    int rank[UF_MAX];
    int count[UF_MAX];
    UFind(int n)
    {
        rep(i, n)
        {
            par[i] = i;
            rank[i] = 0;
            count[i] = 1;
        }
    }
    int find(int x)
    {
        if (par[x] == x) {
            return x;
        } else {
            return par[x] = find(par[x]);
        }
    }
    void unite(int x, int y)
    {
        x = find(x);
        y = find(y);
        if (x == y)
            return;
        if (rank[x] < rank[y]) {
            par[x] = y;
            count[y] += count[x];
        } else {
            par[y] = x;
            count[x] += count[y];
            if (rank[x] == rank[y])
                rank[x]++;
        }
    }
    bool same(int x, int y)
    {
        return find(x) == find(y);
    }
};

int main()
{
    int n, k, l;
    cin >> n >> k >> l;
    UFind r(n), t(n), B(n);
    int a, b;
    rep(i, k)
    {
        cin >> a >> b;
        a--, b--;
        r.unite(a, b);
    }
    rep(i, l)
    {
        cin >> a >> b;
        a--, b--;
        t.unite(a, b);
    }
    map<int, set<int>> sr;
    map<int, set<int>> sb;
    rep(i, n)
    {
        sr[r.find(i)].insert(i);
        sb[t.find(i)].insert(i);
    }
    bool used[200005] = {};
    int anser[200005] = {};
    rep(i, n)
    {
        if (used[i])
            continue;
        set<int> ans;
        if (sr[r.find(i)].size() < sb[t.find(i)].size()) {
            for (auto s : sr[r.find(i)]) {
                if (sb[t.find(i)].find(s) != sb[t.find(i)].end()) {
                    ans.insert(s);
                    used[s] = true;
                }
            }
        } else {
            for (auto s : sb[t.find(i)]) {
                if (sr[r.find(i)].find(s) != sr[r.find(i)].end()) {
                    ans.insert(s);
                    used[s] = true;
                }
            }
        }
        for (auto s : ans) {
            anser[s] = ans.size();
        }
    }
    rep(i, n)
    {
        cout << anser[i] << ' ';
    }
    cout << endl;
}


Measured memory_bytes: 58624
fn main() {
    let mode = "b";
    if mode == "a" {
        a::answer();
    } else if mode == "b" {
        b::answer();
    }
}

mod b {
    use std;
    use std::io::Read;

    pub fn answer() {
        let mut buf = String::new();
        std::io::stdin().read_to_string(&mut buf).unwrap();
        let mut ite = buf.split_whitespace();
        let k = ite.next().unwrap().parse::<i32>().unwrap();
        let x = ite.next().unwrap().parse::<i32>().unwrap();
        let res = calc(k, x);
        let text = res
            .iter()
            .fold(String::new(), |acc, &num| acc + &num.to_string() + " ");
        println!("{}", text);
    }

    fn calc(k: i32, x: i32) -> Vec<i32> {
        let left = std::cmp::max(x - (k - 1), -1000000);
        let right = x + (k - 1);

        (left..(right + 1)).map(i32::from).collect::<Vec<_>>()
    }

    #[cfg(test)]
    mod tests {
        use super::*;
        #[test]
        fn test1() {
            assert_eq!(calc(3, 7), vec![5, 6, 7, 8, 9]);
        }
        #[test]
        fn test2() {
            assert_eq!(calc(4, 0), vec![-3, -2, -1, 0, 1, 2, 3]);
        }
        #[test]
        fn test3() {
            assert_eq!(calc(1, 100), vec![100]);
        }
    }
}

mod a {
    use std;
    use std::io::Read;

    pub fn answer() {
        let mut buf = String::new();
        std::io::stdin().read_to_string(&mut buf).unwrap();

        let mut ite = buf.split_whitespace();
        let a = ite.next().unwrap().parse::<i32>().unwrap();
        let b = ite.next().unwrap().parse::<i32>().unwrap();

        let res = calc(a, b);
        println!("{}", res);
    }
    fn calc(a: i32, b: i32) -> i32 {
        let tasu = a + b;
        let hiku = a - b;
        let kakeru = a * b;
        std::cmp::max(tasu, std::cmp::max(hiku, kakeru))
    }

    #[cfg(test)]
    mod tests {
        use super::*;
        #[test]
        fn test1() {
            assert_eq!(calc(-13, 3), -10);
        }
        #[test]
        fn test2() {
            assert_eq!(calc(1, -33), 34);
        }
        #[test]
        fn test3() {
            assert_eq!(calc(13, 3), 39);
        }
    }

}


Measured memory_bytes: 4352
#include <iostream>
#include <vector>

using namespace std;

typedef struct {
	int num;
	int index;
} NwI;

void msort(vector<NwI> &vec, int left, int right);
void merge(vector<NwI> &vec, int left, int mid, int right);


int main() {
	int N;
	vector<NwI> input;
	vector<int> medians;

	cin >> N;
	medians.resize(N);
	input.resize(N);

	for (int i = 0; i < N; i++) {
		cin >> input[i].num;
		input[i].index = i;
	}

	msort(input, 0, N - 1);

	for (int i = 0; i < N; i++) {
		if (i < N / 2) {
			medians[input[i].index] = input[N / 2].num;
		} else {
			medians[input[i].index] = input[N / 2 - 1].num;
		}
	}

	for (int i = 0; i < N; i++) {
		cout << medians[i] << "\n";
	}
	cout << flush;

	return 0;
}

void msort(vector<NwI> &vec, int left, int right) {
	if (left < right) {
		int m = (left + right) / 2;

		if (m >= left) msort(vec, left, m);
		if (m+1 <= right) msort(vec, m+1, right);

		merge(vec, left, m, right);
	}
}

void merge(vector<NwI> &vec, int left, int mid, int right) {
	vector<NwI> v;
	int i, j;

	i = left;
	j = mid + 1;

	while (i <= mid and j <= right) {
		if (vec[i].num < vec[j].num) {
			v.push_back(vec[i]);
			i++;
		} else {
			v.push_back(vec[j]);
			j++;
		}
	}

	if (i <= mid) {
		while (i <= mid) {
			v.push_back(vec[i]);
			i++;
		}
	}

	if (j <= right) {
		while(j <= right) {
			v.push_back(vec[j]);
			j++;
		}
	}

	for (int c = 0; c <= (right - left); c++) {
		vec[left + c] = v[c];
	}
}


Measured memory_bytes: 5656
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i, x, n) for(int i = x; i < (int)(n); ++i)
 
char s[302];
int dp[302][302][301];
 
int main(){
	int k;
	scanf("%s%d", s + 1, &k);
	int n = strlen(s + 1);
	f(i, 1, n + 1)for (int j = n; j > 0; --j)f(w, 0, k + 1){
		if (s[i] == s[j])dp[i][j][w] = 1 + dp[i - 1][j + 1][w];
		else {
			dp[i][j][w] = max(dp[i - 1][j][w], dp[i][j + 1][w]);
			if (w)dp[i][j][w] = max(dp[i][j][w], 1 + dp[i - 1][j + 1][w - 1]);
		}
	}
	int an = 1;
	f(i, 1, n){
		int nv = dp[i][i + 1][k];
		an = max(an, nv << 1);
	}
	f(i, 1, n - 1){
		int nv = dp[i][i + 2][k];
		an = max(an, nv << 1 | 1);
	}
	printf("%d\n", an);
}

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

int main(void) {
    string S,T; cin >> S >> T;
    int A,B; cin >> A >> B;
    string U; cin >> U;
    if(S==U) A--;
    else B--;
    cout << A  << " " << B << endl;
}

Measured memory_bytes: 3636
a = [1,3,5,7,8,10,12]
b = [4,6,9,11]
c = [2]
x, y = map(int, input().split())
if a.count(x) == 1 and a.count(y) == 1:
  print('Yes')
  exit()
elif b.count(x) == 1 and b.count(y) == 1:
  print('Yes')
  exit()
elif c.count(x) == 1 and c.count(y) == 1:
  print('Yes')
  exit()
else:
  print('No')


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

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
      n: usize,
      ss: [chars; n],
    }

    let mut letters = vec![vec![0; n]; 26];
    for i in 0..n {
        for &s in &ss[i] {
            letters[s as usize - 'a' as usize][i] += 1;
        }
    }
    let mut ans = String::new();
    for i in 0..26 {
        let c = ('a' as u8 + i) as char;
        let mut min_value = letters[i as usize][0];
        for &v in letters[i as usize].iter() {
            min_value = min(v, min_value);
        }
        for _ in 0..min_value {
            ans = ans + &c.to_string();
        }
    }
    println!("{}", ans);
}


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

using namespace std;

int main() {
    int N;

    scanf("%d", &N);
    vector<double> ps(N + 1);
    vector<vector<double>> dp(N + 1, vector<double>(N + 1));

    for (int i = 1; i <= N; i++)
        scanf("%lf", &ps[i]);

    dp[1][1] = ps[1];
    dp[1][0] = 1 - ps[1];

    for (int i = 2; i <= N; i++)
       for (int j = 0; j <= i; j++) {
            dp[i][j] += dp[i - 1][j] * (1 - ps[i]);
            if (j)
                dp[i][j] += dp[i - 1][j - 1] * ps[i];
       }

    double ans = 0;
    for (int i = (N + 1) / 2; i <= N; i++)
        ans += dp[N][i];

    printf("%.10lf\n", ans);

    return 0;
}

Measured memory_bytes: 72448
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,k=1;
  cin>>n;
  for (int  i = 0; i < 10; i++) {
    if(k<=n && n<k*2){
      cout<<k;
      return 0;
    }
    k *=2;
  }
}


Measured memory_bytes: 256
"use strict";

const main = arg => {
    // 標準入力の不要な空白と改行を削除し、配列に格納する
    const inputLength = arg.trim().length;
    const letter = "x";
    const answer = letter.repeat(inputLength).trim().replace(/\r?\n/g, '');
    
    console.log(answer);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));  

Measured memory_bytes: 7372
require 'bigdecimal'
require 'bigdecimal/util'
a1,b1 = gets.strip.split(" ")
a = a1.to_i
b = b1.to_d
c = a*b
if a == 0
  puts 0
elsif b ==0
  puts 0
else
  puts (c.to_i)
end


Measured memory_bytes: 14516
import java.util.Scanner;
import java.util.Arrays;

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

    for ( int i = 0; i < sequence.length; i++ ) {
      sequence[i] = sc.nextInt();
    }
    System.out.println(findLISLen(sequence));
  }

  public static int findLISLen(int[] sequence) {
      
    // lens[i] refers among all subsequences with len i
    // the index of smallest ending value of them
    int maxLen = 0, newL = 0;
    int[] lens = new int[sequence.length+1];

    for ( int i = 0; i < sequence.length; i++ ) {
        
        // binary search
        int lo = 1, hi = maxLen;
        while ( lo <= hi ) {
          int mid = lo+(hi-lo)/2;
          if ( sequence[lens[mid]] < sequence[i] ) {
            lo = mid+1; 
          } else {
            hi = mid-1;
          }
        }

        newL = lo;
        lens[newL] = i;
        maxLen = Math.max(maxLen, newL);
    }
    return maxLen;
  }
  
} 

Measured memory_bytes: 64208
#include <iostream>
#include <algorithm>
#include <string>
#include <queue>


using namespace std;
using ll = long long;

int N;
int d[100000];

int main()
{
	cin >> N;
	for (int i = 0; i < N; i++)
	{
		cin >> d[i];
	}
	sort(d, d + N);
	int K = 0;
	K = d[N / 2] - d[N / 2 - 1];
	cout << K << endl;
	return 0;
}

Measured memory_bytes: 640
#include <stdio.h>

int main() {
   unsigned long x1[200], x2[200];
   int i=0, j;
   while (scanf("%ld %ld",&x1[i], &x2[i]) != EOF) { ++i; }
   for (j=0; j<i; ++j) {
      unsigned long y = x1[j]+x2[j];
      int h = 1;
      while (1) {
         y /= 10;
         if (y == 0) { break; }
         else { ++h; }
      }
      printf("%d\n", h);
   }
   return 0;
}

Measured memory_bytes: 600
unittest
{
	assert( [ "2 3", "0 1 1", "1 0 1", "1 4 0", "1 2", "3 3" ].parse.expand.solve == 3 );
	assert( [ "4 3", "0 12 71", "81 0 53", "14 92 0", "1 1 2 1", "2 1 1 2", "2 2 1 3", "1 1 2 2" ].parse.expand.solve == 428 );
	
	assert( [ "2 4", "100 100 100 100", "100 0 1 1", "100 1 0 1", "100 1 4 0", "2 3", "4 4" ].parse.expand.solve == 3 );		// 追加ケース
}



import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto nc = input.front.split.to!( long[] );
	auto dss = new long[][]( nc[ 1 ], nc[ 1 ] );
	foreach( ref ds; dss )
	{
		input.popFront;
		ds = input.front.split.to!( long[] );
	}
	auto css = new long[][]( nc[ 0 ], nc[ 0 ] );
	foreach( ref cs; css )
	{
		input.popFront;
		cs = input.front.split.to!( long[] );
		cs[] -= 1;
	}
	return tuple( nc[ 1 ], dss, css );
}

auto solve( long cn, long[][] dss, long[][] css )
{
	// 各色・各マスごとの、塗り替えた後の違和感の合計を集計
	auto kss = new long[][]( 3, cn );
	foreach( y, cs; css )
	{
		foreach( x, c; cs )
		{
			foreach( t; 0L .. cn )
			{
				kss[ ( x + y ) % 3 ][ t ] += dss[ c ][ t ];
			}
		}
	}
	
	// 違和感の少ない順に色を並べ替え
	auto sss = new Tuple!( long, long )[][]( 3, cn );
	foreach( i, ks; kss )
	{
		auto ss = zip( ks, iota( 0L, cn ) ).array;
		ss.sort();
		sss[ i ] = ss.take( 3 );
	}
	
	// 違和感の少ない順に3色使ったときの最小値を検索
	auto ans = long.max;
	foreach( s1; sss[ 0 ] )
	{
		foreach( s2; sss[ 1 ] )
		{
			if( s1[ 1 ] == s2[ 1 ] ) continue;
			foreach( s3; sss[ 2 ] )
			{
				if( s1[ 1 ] == s3[ 1 ] || s2[ 1 ] == s3[ 1 ] ) continue;
				ans = min( ans, s1[ 0 ] + s2[ 0 ] + s3[ 0 ] );
			}
		}
	}
	return ans;
}


Measured memory_bytes: 5372
#配るDP
#Hの添字は1-indexに変更
n=int(input())
H=[0]+list(map(int,input().split()))
dp=[10**10]*(n+1)
dp[1]=0
for i in range(1,n):
    if i+2<=n:
        dp[i+2]=min(dp[i]+abs(H[i]-H[i+2]), dp[i+2])
    dp[i+1]=min(dp[i]+abs(H[i]-H[i+1]), dp[i+1])
print(dp[n])

Measured memory_bytes: 13976
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


# 初項s, 交差dのn個の数列の和
def sum_of_arithmetic_progression(s, d, n):
    return n * (2 * s + (n - 1) * d) // 2


# aとbの最大公約数
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


# aとbの最小公倍数
def lcm(a, b):
    g = gcd(a, b)
    return a / g * b


def main():
    N, A, B = map(int, input().split())
    print(min(N * A, B))


if __name__ == '__main__':
    main()


Measured memory_bytes: 4072
#include <bits/stdc++.h>
#include <vector>
#include <numeric>
#define PI 3.14159265358979323846
#define MAXINF 1e18L
#define INF 1e9L
#define EPS 1e-9
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define pb push_back
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
typedef long long ll;
typedef pair<int, int> pii;

int main(void)
{
    int a,b,c;
    cin >> a >> b >> c;
    int d;
    cin >> d;
    if(a+b == c+d) pr("Balanced");
    else pr(a+b>c+d?"Left":"Right");
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
    
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
    int i=scanner.nextInt();
    int b=scanner.nextInt();
    int c=i*b;
    int d=(i+b)*2;
    System.out.println(c+" "+d );
    }
}

Measured memory_bytes: 25868
#!/usr/bin/env python3
import sys


def solve(N: int, K: int):
    print(((K-1) ** (N -1)) * K)
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(N, K)

if __name__ == '__main__':
    main()


Measured memory_bytes: 61664
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int) (n); i++)
#define pb push_back
#define mp make_pair
#define maximize(a, b) ((a)<(b)?(a)=(b),1:0)
#define minimize(a, b) ((a)>(b)?(a)=(b),1:0)
void MAIN();
int main() {
//    freopen("input.txt", "r", stdin);

    MAIN();
    return 0;
}

const int N = 100032;
int n, a[3*N];

void MAIN() {
    scanf("%d", &n);
    REP(i, 3*n) scanf("%d", a+i);
    sort(a, a+3*n);
    long long ans = 0;
    REP(i, n) {
        ans += a[3*n - i*2 - 2];
    }
    cout << ans << endl;
}


Measured memory_bytes: 1408
N,M = list(map(int,input().split()))
A = list(map(int,input().split()))
A.sort(reverse=True)
B = [0]
b=  0
for i in range(N):
    b+=A[i]
    B.append(b)

def bisect1(x,i):
    l = 0
    r = N-1
    if A[i]+A[l]<=x:
        return 0
    if A[i]+A[r]>x:
        return N
    while r-l>1:
        if A[i]+A[(l+r)//2]>x:
            l = (l+r)//2
        else:
            r = (l+r)//2
    return r

def bisect2():
    l=-1
    r = 2*A[0]
    while r-l>1:
        s = 0
        for i in range(N):
            s += bisect1((l+r)//2,i)
        if s>M:
            l = (l+r)//2
        else:
            r = (l+r)//2
    return r

minv = bisect2()
s = 0
ans = 0
for i in range(N):
    j = bisect1(minv,i)
    ans += j*A[i] + B[j]
    s += j

ans += (M-s)*minv

print(ans)


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

int straw_count[303];
int num=0;
char c[303][303];
int a[303][303];
int h,w,k;

void divide(int u, int d)
{
	vector<int> S;
	
	//Find S on the matrix 
	for(int i=u; i <= d; i++)
	{
		for(int j=1;j<=w;j++)
		{
			if(c[i][j]=='#')
				S.push_back(j);
		}
	}
	
	sort(S.begin(),S.end());
	
	//Fill row rectangle
	for(int i=0;i<S.size();i++)
	{
		int l = 1, r = w;
		if (i >= 1) 
			l = S[i - 1] + 1;
		if (i < S.size() - 1) 
			r = S[i];
 
		++num;
		for (int j = u; j <= d; j++) {
			for (int z = l; z <= r; z++) a[j][z] = num;
		}
	}
}

int main()
{
	cin>>h>>w>>k;
	for(int i=1;i<=h;i++)
	{
		for(int j=1;j<=w;j++)
		{
			cin>>c[i][j];
			
			if(c[i][j]=='#')
				straw_count[i]++;
		}
	}
	vector<int> v;
	
	//Find the count of S on each row
	for(int i=1;i<=h;i++)
	{
		if(straw_count[i] >= 1)
			v.push_back(i);
	}
	
	//sort(v.begin(),v.end());
	
	//Solve for straws...
	for(int i=0;i<v.size();i++)
	{
		int u = 1, d = h;
		if(i >=1 ) 
			u = v[i-1]+1;
		if(i < v.size()-1) 
			d = v[i];
		
		divide(u,d);
	}
	
	//Print
	for(int i=1;i<=h;i++)
	{
		for(int j=1;j<=w;j++)
		{
			cout<<a[i][j]<<" ";
		}
		cout<<endl;
	}
	return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
    int main(){
        int N;cin>>N;
        int X[N];
        for(int i=0;i<N;i++)cin>>X[i];
        long long sum=100000000;
        for(int i=1;i<=100;i++){
            long long  a=0;
            for(int j=0;j<N;j++){
                int p=pow(abs(X[j]-i),2);
                a+=p;
            }
            sum=min(sum,a);
        }
        cout<<sum<<endl;
    }






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

const int MAXN = 1005;
const int MAXM = 200005;

vector<int> G[MAXN];

int D[MAXN][MAXN][2], Dn[MAXN][MAXN];

bitset<MAXN> C[MAXN];

int A[MAXM], B[MAXM];

int N, M;

void dfs(int i, bitset<MAXN> &chk) {
	chk[i] = true;
	for(int v : G[i]) if(!chk[v])
		dfs(v, chk);
}

void f(int i, int ri, int c) {
	if(2 == Dn[ri][i]) return;
	if(1 == Dn[ri][i] && D[ri][i][0] == c) return;
	D[ri][i][Dn[ri][i]++] = c;
	for(int v : G[i]) f(v, ri, c);
}

int main() {
	ios::sync_with_stdio(false);

	cin >> N >> M;
	for(int i = 1; i <= M; i++) {
		cin >> A[i] >> B[i];
		G[A[i]].eb(B[i]);
	}

	for(int i = 1; i <= N; i++) dfs(i, C[i]);
	for(int i = 1; i <= N; i++) {
		Dn[i][i] = 2;
		for(int v : G[i]) f(v, i, v);
	}

	for(int i = 1, a, b; i <= M; i++) {
		a = A[i]; b = B[i];

		bool flag = false;
		if(1 == Dn[a][b]) {
			if(b != D[a][b][0]) flag = true;
		} else if(2 == Dn[a][b]) {
			if(b != D[a][b][0]) flag = true;
			if(b != D[a][b][1]) flag = true;
		}

		puts((flag == C[b][a]) ? "same" : "diff");
	}
	return 0;
}

Measured memory_bytes: 16256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define faster ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define ll long long
#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define vi vector<int>
#define pii pair<int,int>
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define REP(i,a,b) for(ll i = a; i < b; i++)
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) (a * b) / gcd(a, b)
#define bins(v, x) binary_search(v.begin(), v.end(), x)
#define pi 2*acos(0.0)
const int INF = 1e7;
const int mod = 1e9 + 7;

ll modExp(ll base, ll exp, ll mod) {
   ll res = 1;
   while (exp > 0) {
    	if (exp % 2 == 1) {
        	res= (res * base) % mod;
		}
      exp = exp >> 1;
      base = (base * base) % mod;
   }
   return res;
}

ll nCr(ll n, ll k){ 
   ll C[n + 1][k + 1]; 
   
   REP(i,0,n+1){ 
      REP(j,0,min(i,k)+1) {
         if(j==0 || j==i) {
            C[i][j] = 1;  
         } else {
            C[i][j] = C[i-1][j-1] + C[i-1][j]; 
         }
      } 
   }
   return C[n][k]; 
}

int main(){
   faster;
   //freopen("input.txt","r",stdin);
   //freopen("output.txt","w",stdout);
   
   int n;
   cin >> n;
   int a[n], dp[n+1] = {0};

   REP(i,0,n) cin >> a[i];
   dp[2] = abs(a[1]-a[0]);
   for(int i = 3; i <= n; i++) {
      dp[i] = min(dp[i-2] + abs(a[i-1] - a[i-3]), dp[i-1] + abs(a[i-1] - a[i-2]));
   }
   cout << dp[n];
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define sz(arr) (int)arr.size()
#define all(arr) arr.begin(), arr.end()

using namespace std;

void _cin() {}
template <class Head, class... Tail>
void _cin(Head&& head, Tail&&... tail) {
  cin >> head;
  _cin(forward<Tail>(tail)...);
}

#define Cin(T, ...) \
  T __VA_ARGS__;    \
  _cin(__VA_ARGS__)

int main() {
  Cin(int, n, a, b);

  cout << min(n * a, b) << endl;

  return 0;
}

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

int main() {
    int n;
    cin >> n;
    vector<int> d(n);
    rep(i, n) cin >> d[i];
    sort(d.begin(), d.end());

    int midl = d[n/2-1];
    int midr = d[n/2];
    int ans = midr - midl;

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
def abc153_b():
    H,N=map(int,input().split())
    A=list(map(int,input().split()))
    attack=0
    for a in A:
        if attack>=H:
            print("Yes")
            return
        else:
            attack+=a
    if attack >= H:
        print("Yes")
        return
    else:
        print("No")
        return
        
abc153_b()

Measured memory_bytes: 13964
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef stack<int> st;
int n;
st A[301];
int idx[301];
int h[301];

//aテ」ツつ鍛テ」ツ?ョテ、ツクツ甘」ツ?ォテ」ツ?甘」ツ??
void sim(int a,int b){
  int i = idx[a],j=b<0? a:idx[b];
  if(b==-1&&i==a) return;
  if(i==j && h[a]>h[b])return;
  
  while(A[i].top()!=a){
    int t = A[i].top();
    idx[t] = t;
    A[t].push(t);
    h[t] = 1;
    A[i].pop();
  }
  j=b<0? a:idx[b];
  A[i].pop();
  A[j].push(a);
  idx[a] = j;
  h[a] = A[j].size();
}

signed main(){
  while(cin>>n,n){
    for(int i=0;i<301;i++)while(!A[i].empty())A[i].pop();
    for(int i=0;i<n;i++) A[i].push(i),idx[i]=i,h[i]=1;
    
    while(1){
      int i,j;
      cin>>i>>j;
      if(i==0&&j==0)break;
      if(i==j)continue;
      sim(i-1,j-1);
    }

    vector<int> ans;
    for(int i=0;i<n;i++)if(!A[i].empty())ans.push_back(A[i].size());
    sort(ans.begin(),ans.end());
    for(int i=0;i<ans.size();i++)cout<<ans[i]<<endl;
    cout<<"end"<<endl;
    
  }    
  return 0;
}

Measured memory_bytes: 3232
#include<stdio.h>

int main(){
  int i, N, K, P;
  scanf("%d", &N);
  for ( int i = 0; i < N; i++ ){
    scanf("%d %d", &K, &P);
    printf("%d\n", (K-1)%P + 1);
  }
  return 0;
}


Measured memory_bytes: 2108
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;

class Main{
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        
        int[] data = new int[101]; // data[0]は使わない
        for(int i = 0; i < 101; i++){
            data[i] = 0;
        }

        String input;
        while((input = br.readLine()) != null){
            data[Integer.parseInt(input)]++;
        }

        int max = 0;
        for(int i = 0; i < 101; i++){
            if(data[i] > max){
                max = data[i];
            }
        }

        for(int i = 0; i < 101; i++){
            if(data[i] == max){
                System.out.println(i);
            }
        }
    }
}


Measured memory_bytes: 24196
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int t=sc.nextInt();
		int[][] dp=new int[n+1][t+3001];
		State[] ss=new State[n];
		for(int i=0; i<n; i++){
			ss[i]=new State(sc.nextInt(),sc.nextInt());
		}
		Arrays.sort(ss);
		for(int i=1; i<=n; i++){
			for(int j=1; j<=t+3000; j++){
				if(j-ss[i-1].a>=t){
					break;
				}
				if(j<ss[i-1].a){
					dp[i][j]=dp[i-1][j];
					continue;
				}
				dp[i][j]=Math.max(dp[i-1][j],dp[i-1][j-ss[i-1].a]+ss[i-1].b);
			}
		}
		long ans=0;
		for(int i=0; i<=t+3000; i++){
			ans=Math.max(ans,dp[n][i]);
		}
		System.out.println(ans);
	}
	static class State implements Comparable<State>{
		int a,b;
		State(int a,int b){
			this.a=a;
			this.b=b;
		}
		@Override
 		 public int compareTo(State s){
    		return this.a - s.a;
  		}
	}
}


Measured memory_bytes: 130408
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

template <typename TYPE>
void print_vec(const vector<TYPE>& v){
	for(int i=0; i<v.size(); i++){
		cout << v[i] << " ";
	}
	cout << endl;
}

template <typename TYPE>
void print_vec2(const vector<vector<TYPE>>& v){
  cout << endl; cout << "       ";
  for(int i=0; i<v[0].size(); i++) cout << i << "   "; 
  cout << endl;
	for(int i=0; i<v.size(); i++){
		cout << "i=" << i << ":   ";
		for(int j=0; j<v[i].size(); j++){
			if(v[i][j] == 0) cout << "\x1B[0m" << v[i][j] << "   ";
      else cout << "\x1B[31m" << v[i][j] << "   ";//https://stackoverrun.com/ja/q/12618775
		}
		cout << "\x1B[0m" << endl;
	}
}

int main(){
	int N, K;
	cin >> N >> K;
	string S;
	cin >> S;

	vector<int> A;
	char group = S[0];//'0'のグループか '1'のグループかを格納
	int cnt = 0;
	for(int i=0; i<N; i++){
		if(S[i] == group) cnt++;
		else{
			A.push_back(cnt);
			group = S[i];
			cnt = 1;
		}
	}
	A.push_back(cnt);

	// if(A.size() == 1){ 
		// ここ入れないと 入力が 1 1 0　のとき，2K回ループするところで範囲外参照起こす
		// もう A.size()を intにキャストすることで解決したので　ここはコメントアウト
	// 	cout << N << endl;
	// 	return 0;
	// }
	vector<int> wa;
	wa.push_back(0);
	for(int i=0; i<A.size(); i++) wa.push_back(wa.back()+A[i]);
	// cout << " A: "; print_vec(A);

	int ans = 0;
	if(S[0] == '0'){
		int tmp = 0;
		for(int i=0; i<2*K; i++){
			if(i<A.size()) tmp += A[i];
		}
		ans = max(ans, tmp);	
	}
	if(S.back() == '0'){
		int tmp = 0;
		for(int i=0; i<2*K; i++){
			if(int(A.size())-1 - i >= 0) tmp += A[A.size()-1 - i];// A.size()をintにキャストしないと， A.size()-1が範囲外参照的な感じで壊れた値になる
			// cout << " i : " << i << "     A.size(): " << A.size() <<  "   index: " << (int)A.size() - 1 - i <<  "    tmp: " << tmp << endl;
		}
		ans = max(ans, tmp);
	}
	// cout << "1 A.size() = " << A.size() << "    wa.size() = " << wa.size() << endl;
	if(S[0] == '0'){
		reverse(wa.begin(), wa.end());
		wa.pop_back();
		reverse(wa.begin(), wa.end());
	}
	// cout << "2 A.size() = " << A.size() << "    wa.size() = " << wa.size() << endl;
	if(S.back() == '0') wa.pop_back();
	// cout << "3 A.size() = " << A.size() << "    wa.size() = " << wa.size()<< endl;

	int range = 2*K + 1;
	for(int left = 0; left<wa.size(); left +=2){
		int right = left + range;
		if(right > wa.size()-1) right = wa.size() - 1;
		if(right < left) continue;
		ans = max(ans, wa[right]-wa[left]);
	}

	cout << ans << endl;
	
	


}



Measured memory_bytes: 4332