akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define li          long
#define ll          long long
#define ull         unsigned long long
#define ff          first
#define ss          second
#define pii         pair<int,int>
#define pli         pair<li,li>
#define pll         pair<ll,ll>
#define pb          push_back
#define fo(i,k,n)   for(int i = k;i<n; i++)
#define ro(i,k,n)   for(int i = k; i>=n; i--)
#define tc          int t;cin>>t;while(t--)
#define all(v)      v.begin(),v.end()
#define inf         INT_MAX
#define ninf        INT_MIN
#define v(x)        vector<x>
#define int         long long
#define ar(x,y)     array<x,y>
const ll mod1 = 99844353;
const ll mod2 = 1e9+7;
/* template <class T>
using oset = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>; */

void fastio()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

int power(int x,int y){
	int res = 1;
	while(y > 0){
	 	if(y & 1) res *= x;
	 	y >>= 1;
	 	x *= x;
	}
	return res;
}

int power(int x,int y,int mod){
 	int res = 1;
 	x %= mod;
 	while(y > 0){
 	 	if(y & 1) res = (res * x) % mod;
 	 	y >>= 1;
 	 	x = (x * x) % mod;
 	}
 	return res;
}

class dsu{
	public:
		v(int) pr,sz;
		dsu(int n){
			pr = v(int)(n,-1);
			sz = v(int)(n,0);
		}
		void make(int x){
			pr[x] = x;
			sz[x] = 1;
		}
		int GetPar(int x){
			if(x == pr[x])
				return x;
			return pr[x] = GetPar(pr[x]);
		}
		void merge(int x,int y){
			x = GetPar(x);
			y = GetPar(y);
			if(x == y)
				return;
			if(sz[x]<sz[y])
				swap(x,y);
			pr[y] = x;
			sz[x] += sz[y];
			sz[y] = 0;
		}
};

class Template {
    int n,m;	    
 public:
    void solveOne(istream &in, ostream &out) {
	 in >> n >> m;
  	dsu *d = new dsu(n);
	for(int i = 0; i<n; i++){
		(*d).make(i);
	}
	for(int i = 0; i<m; i++){
		int u,v;
		in >> u >> v;
		u--,v--;
		(*d).merge(u,v);
	}
	int ans = -1;
	for(int x : (*d).sz){
		ans = max(ans,x);
	}
	out << ans << "\n";
    }
    
    void solve(istream &in, ostream &out) {
        int nt = 1;
        //in >> nt;
        for (int it = 0; it < nt; ++it) {
            solveOne(in, out);
        }
    }
};
 
 
signed main() {
  fastio();
  Template solver;
  istream& in(cin);
  ostream& out(cout);
  solver.solve(in, out);
  return 0;
}


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



int main()
{
int s;
cin>>s;
vector<long>a(10000000);
a[0]=0;
a[1]=s;
for(long i=1;i<10000000;i++)
{
if(a[i]%2==0){a[i+1]=a[i]/2;}
else{a[i+1]=3*a[i]+1;}
}
int kijun=0;
int answer=1;

while(kijun==0)
{
for(int i=0;i<answer;i++)
{if(a[answer]==a[i]){cout<<answer<<endl;kijun++;}}

answer++;

}


}


Measured memory_bytes: 78336
import math
A,B,H,M=map(int,input().split())
#Aの位置
Asin=(360*((H/12)+(1/12)*(M/60)))
x1=A*(math.cos(math.radians(Asin)))
y1=A*(math.sin(math.radians(Asin)))
#Bの位置
Bsin=(360*(M/60))
x2=B*(math.cos(math.radians(Bsin)))
y2=B*(math.sin(math.radians(Bsin)))

Z=((((x1)-(x2))**2)+(((y1)-(y2))**2))**(1/2)
print(Z)

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

class Program
{
	public static int Main(string[] args)
	{
        
		string str = Console.ReadLine();
        string s = str;
        List<int> s_list = new List<int>();
        for (int i = 0; i < s.Length;i++){
            s_list.Add(int.Parse(s[i].ToString()));
        }
        str = Console.ReadLine();
        long k = long.Parse(str);
        long min = new List<long> { s.Length, k }.Min();
        int answer = 1;
        for (int i = 0; i < min;i++){
            if(s_list[i]>1){
                answer = s_list[i];
                break;
            }
        }
        Console.WriteLine(answer);
		return 0;
	}
}


Measured memory_bytes: 13268
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
#include <random>
#include <string.h>
#include <cmath>
using namespace std;
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define int long long
#define P pair<int,int>
#define all(vec) vec.begin(),vec.end()

int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}

int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}

int n, m;
vector<int> vec[100010];
int cnt1, cnt2;
int cnt[100010];

bool dfs(int v, int p, int k) {
	cnt[v] = k;
	if (0 < k)cnt1++;
	else cnt2++;
	for (int i = 0; i < (int)vec[v].size(); i++) {
		if (vec[v][i] == p)continue;
		if (cnt[v] == cnt[vec[v][i]])return false;
		if (cnt[vec[v][i]] == 0 && !dfs(vec[v][i], v, -k))return false;
	}
	return true;
}

signed main() {
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int a, b; cin >> a >> b;
		vec[a].push_back(b);
		vec[b].push_back(a);
	}
	if (dfs(1, 0, 1))cout << cnt1 * cnt2 - m << endl;
	else cout << n * (n - 1) / 2 - m << endl;
}

Measured memory_bytes: 7552
import itertools

n = int(input())

d = {"M": 0, "A": 0, "R": 0, "C": 0, "H": 0}

for _ in range(n):
    s = input()
    if s[0] in d:
        d[s[0]] += 1

l = list(d.keys())
comb = list(itertools.combinations(l, 3))

ans = 0
for i in comb:
    temp = 1
    for j in i:
        temp *= d[j]

    ans += temp

print(ans)

Measured memory_bytes: 43496
#include<bits/stdc++.h>
using namespace std;
const int MAX_N = 110;

bool used[MAX_N];

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

    pair<int, int> r[n], b[n];
    for (int i = 0; i < n; i++){
        cin >> (r[i]).first >> (r[i]).second;
    }
    for (int i = 0; i < n; i++){
        cin >> (b[i]).first >> (b[i]).second;
    }

    sort(r, r + n);
    sort(b, b + n);

    int cnt = 0;
    for (int i = 0; i < n; i++){
        int maxy = -1;
        int index;
        for (int j = 0; (r[j]).first < (b[i]).first; j++){
            if ((r[j]).second < (b[i]).second && !used[j]){
                if ((r[j]).second > maxy){
                    maxy = (r[j]).second;
                    index = j;
                }
            }
        }
        if (maxy != -1){
            cnt++;
            used[index] = true;
        }
    }

    cout << cnt << endl;

    return 0;    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define Fst first
#define Snd second
#define RG register
#define mp make_pair
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long LL;
typedef long double LD;
typedef unsigned int UI;
typedef unsigned long long ULL;
template<typename T> inline void read(T& x) {
	char c = getchar();
	bool f = false;
	for (x = 0; !isdigit(c); c = getchar()) {
		if (c == '-') {
			f = true;
		}
	}
	for (; isdigit(c); c = getchar()) {
		x = x * 10 + c - '0';
	}
	if (f) {
		x = -x;
	}
}
template<typename T, typename... U> inline void read(T& x, U& ... y) {
	read(x), read(y...);
}
const int N=1e5+10;
int n,m,p,cnt;
int ID[N*5],head[N*5],X[N],Y[N];
bool vis[N*5];
map<int,int> S[410][2];
bitset<410> F[N*5],GG;
struct Edge {
  int to,last;
  Edge () {}
  Edge (int a,int b) :to(a),last(b) {}
}edge[N*10];
void ADD(int a,int b) {
  edge[++p]=Edge(b,head[a]); head[a]=p;
}
void DFS(int u) {
  if(vis[u]) return;
  vis[u]=true;
  if(ID[u]) F[u].set(ID[u]);
  for(int i=head[u];i;i=edge[i].last) {
    int v=edge[i].to;
    DFS(v);
    F[u]|=F[v];
  }
}
//#define rua
int main() {
//	ios::sync_with_stdio(false);
#ifdef rua
	freopen("GG.in","r",stdin);
#endif
  read(n,m);
  for(int i=1;i<=m;++i) {
    read(X[i],Y[i]);
    S[X[i]][0][i]=++cnt;
    S[X[i]][1][i]=++cnt;
    S[Y[i]][0][i]=++cnt;
    S[Y[i]][1][i]=++cnt;
  }
  for(int i=1;i<=n;++i) S[i][0][m+1]=++cnt,S[i][1][m+1]=++cnt;
  for(int i=1;i<=m;++i) {
    int x=X[i],y=Y[i];
    ADD(S[x][1][i],(*S[y][1].lower_bound(i+1)).Snd);
    ADD((*S[x][0].lower_bound(i+1)).Snd,(*S[y][1].lower_bound(i+1)).Snd);
    ADD((*S[x][0].lower_bound(i+1)).Snd,S[y][0][i]);
    ADD(S[y][1][i],(*S[x][1].lower_bound(i+1)).Snd);
    ADD((*S[y][0].lower_bound(i+1)).Snd,(*S[x][1].lower_bound(i+1)).Snd);
    ADD((*S[y][0].lower_bound(i+1)).Snd,S[x][0][i]);
  }
  for(int i=1;i<=n;++i) {
    ID[S[i][1][m+1]]=i;
    map<int,int> ::iterator a,b;
    a=S[i][0].begin(); b=a; ++b;
    while(b!=S[i][0].end()) {
      ADD((*b).Snd,(*a).Snd);
      a=b; ++b;
    }
    a=S[i][1].begin(); b=a; ++b;
    while(b!=S[i][1].end()) {
      ADD((*a).Snd,(*b).Snd);
      a=b; ++b;
    }
  }
  for(int i=1;i<=cnt;++i) if(!vis[i]) DFS(i);
  for(int i=1;i<=n;++i) {
    int u=S[i][0][m+1];
    if(F[u].test(i)) GG.set(i);
  }
  int res=0;
  for(int i=1;i<=n;++i) {
    int u=S[i][0][m+1];
    F[u]|=GG;
    if(F[u].test(i)) continue;
    res+=n-1-F[u].count();
  }
  printf("%d\n",res/2);
	return 0;
}


Measured memory_bytes: 57984
n, m = map(int, input().split())
dp = [1] + [-1] * n
for i in range(m):
    a = int(input())
    dp[a] = 0
if dp[1] != 0:
    dp[1] = 1
for i in range(2, n+1):
    if dp[i] != 0:
        dp[i] = (dp[i-1] + dp[i-2])%1000000007
print(dp[n])

Measured memory_bytes: 6884
#include <cstdio>
#include <cstring>
#include <algorithm>
#define MAX (2000000)
#define INF (1145141919)
using namespace std;

int dp[MAX + 1];

int main()
{
	dp[0] = 0;
	for (int i = 1; i <= MAX; i++){
		dp[i] = INF;
	}
	
	for (int i = MAX; i >= 0; i--){
		if (dp[i] < MAX){
			for (int x = 0; i + x <= MAX; x++){
				dp[i + x] = min(dp[i + x], dp[i] + x);
			}
		}
	}
	
	for (int i = MAX; i >= 0; i--){
		if (dp[i] < MAX){
			for (int y = 0; i + y * y <= MAX; y++){
				dp[i + y * y] = min(dp[i + y * y], dp[i] + y);
			}
		}
	}
	
	for (int i = MAX; i >= 0; i--){
		if (dp[i] < MAX){
			for (int z = 0; i + z * z * z <= MAX; z++){
				dp[i + z * z * z] = min(dp[i + z * z * z], dp[i] + z);
			}
		}
	}
	
	int e;
	while (scanf("%d", &e), e){
		printf("%d\n", dp[e]);
	}
	
	return 0;
}

Measured memory_bytes: 8840
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define Per(i,sta,n) for(int i=n-1;i>=sta;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;

int n;
LDP vec[110];
vector<ld> ang_={(ld)0,pi,-pi},ang={(ld)0,pi,-pi};

void solve(){
    cin >> n;
    rep(i,n){
        int x,y;
        cin >> x >> y;
        vec[i]=P(x,y);
    }
    rep(i,n){
        ld a1,a2;
        a1=atan2(vec[i].second,vec[i].first)+pi/2;
        a2=atan2(vec[i].second,vec[i].first)-pi/2;
        if (a1>pi) a1-=pi;
        if (a2<-pi) a2+=pi;
        ang_.push_back(a1);
        ang_.push_back(a2);
        ang_.push_back(atan2(vec[i].second,vec[i].first));
        ang.push_back(a1);
        ang.push_back(a2);
        ang.push_back(atan2(vec[i].second,vec[i].first));
    }
    sort(ang_.begin(),ang_.end());
    rep(i,(int)ang_.size()-1){
        ang.push_back((ang_[i]+ang_[i+1])/2);
    }
    sort(ang.begin(),ang.end());
    ld ans=0;
    rep(i,ang.size()){
        ld a=ang[i];
        ld p=cos(a),q=sin(a);
        //cout << p << " " << q << endl;
        ld x=0,y=0;
        rep(k,n){
            //cout << p*vec[k].first+q*vec[k].second << endl;
            if (p*vec[k].first+q*vec[k].second>=0) {
                x+=vec[k].first;
                y+=vec[k].second;
            }
        }
        //cout << x << " " << y << endl;
        ans=max(ans,sqrt(x*x+y*y));
    }

    cout << ans << endl;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(50);
    solve();
}

Measured memory_bytes: 384
#include <iostream>
#include <map>
#include <cstdio>
#include <cstring>
#include <cmath>

using namespace std;

typedef unsigned long long ull;

int main()
{
    int N, x;
    
    cin >> N >> x;
    
    int a[N];
    
    for (int i = 0; i < N; i++)
    {
        cin >> a[i];
    }

    ull num = 0;

    for (int i = 0; i < N; i++)
    {
        if (a[i] > x)
        {
            int diff = a[i] - x;
            num += diff;
            a[i] -= diff;
        }
    }
    
    for (int i = 0; i < N - 1; i++)
    {
        if (a[i] + a[i+1] > x)
        {
            int diff = a[i] + a[i+1] - x;
            num += diff;
            a[i+1] -= diff;
        }
    }

#if 0
    printf("num=%d\n", num);
    for (int i = 0; i < N; i++)
    {
        printf("%d ", a[i]);
    }
    printf("\n");
#endif
    
    printf("%lld\n", num);
    
    return 0;
}


Measured memory_bytes: 640
num_list=input().split()
num_list[0]=int(num_list[0])
num_list[1]=int(num_list[1])
num_list[2]=int(num_list[2])

def sort(num_list):
    for i in range(0,len(num_list)-1):
        for j in range(0,len(num_list)-1):
            if num_list[j]>num_list[j+1]:
                num=num_list[j]
                num_list[j]=num_list[j+1]
                num_list[j+1]=num

sort(num_list)
print(num_list[0],num_list[1],num_list[2])
    

Measured memory_bytes: 7736
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Diagnostics;

class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }

    Scanner cin;
    Func cin2;
    void calc()
    {
        cin = new Scanner();
        cin2 = new Func();
        int H=cin.nextInt();
        int W=cin.nextInt();
        int N=cin.nextInt();
        int ans=0;
        if(H>W)ans=(int)Math.Ceiling((double)N/(double)H);
        else ans=(int)Math.Ceiling((double)N/(double)W);
        Console.WriteLine(ans);
    }
}



class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

class Answer
{
    public void Int2DArrayAns(int[,]x,char c)
    {
        for(int i=0;i<x.GetLength(0);i++)
        {
            for(int j=0;j<x.GetLength(1)-1;j++)
            {
                Console.Write(x[i,j]);
                Console.Write(c);
            }
            Console.WriteLine(x[i,x.GetLength(1)-1]);
        }
    }
    public void Char2DArrayAns(char[,]x,char c)
    {
        for(int i=0;i<x.GetLength(0);i++)
        {
            for(int j=0;j<x.GetLength(1)-1;j++)
            {
                Console.Write(x[i,j]);
                Console.Write(c);
            }
            Console.WriteLine(x[i,x.GetLength(1)-1]);
        }
    }
}

class Func
{
    public long GCDLong(long a, long b)
    {
        while(a!=0)
        {
          long t=a;
          a=b%a;
          b= t;
        }
      
        return b;        
    }
}

Measured memory_bytes: 11092
#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;

#define dbg(x) cerr << #x"=" << x << endl;
typedef long long LL;
const int MAX_N = 110;
LL d[MAX_N];
LL l[MAX_N];

int main(){
	//freopen("in.txt", "r", stdin);
    int n,x;
    cin >> n >> x;
    for(int i = 1; i <= n; ++i) cin >> l[i];
    d[1] = 0;
    int cnt = 1;
    for(int i = 2; i <= n+1; i++){
        d[i] = d[i-1]+l[i-1];
        if(d[i] <= x) ++cnt;
        else break;
    }
    cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 256
from math import *

a, b, x = map(int, input().split())

if a*a*b/2 >= x:
    theta = 90 - degrees(atan(2*x / (a*b*b)))
else:
    theta = degrees(atan((2*a*a*b - 2*x) / (a*a*a)))

print(theta)

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

#define PI 3.14159265358979323846264338327950288419

using namespace std;

const int mod = 998244353;
int n, m;
int fact[2000005], inv_fact[2000005];

int expo(int a, int b){
	int c = 1, d = a;
	while(b){
		if(b & 1){
			c = 1LL * c * d % mod;
		}
		d = 1LL * d * d % mod;
		b >>= 1;
	}
	return c;
}

int inv(int a){
	return expo(a, mod - 2);
}

int ncr(int _n, int _r){
	if(_n < 0 || _r < 0 || _r > _n){
		return 0;
	}
	int ret = fact[_n];
	ret = 1LL * ret * inv_fact[_r] % mod;
	ret = 1LL * ret * inv_fact[_n - _r] % mod;
	return ret;
}
	

int main(){
	fact[0] = inv_fact[0] = 1;
	for(int i = 1; i <= 2000000; i++){
		fact[i] = 1LL * fact[i - 1] * i % mod;
		inv_fact[i] = inv(fact[i]);
	}
	
	scanf("%d %d", &n, &m);
	int ans = 0;
	for(int odd = m; odd >= 0; odd -= 2){
		// ways to assign odds?
		if(odd > n){
			continue;
		}
		int combin_pt1 = ncr(n, odd);
		int remain = (3 * m - odd) / 2;
		
		// first assume we assign randomly
		int combin_pt2 = ncr(remain + n - 1, n - 1);
		
		// fail case 1: an odd number gets >= m out of remain
		combin_pt2 = (combin_pt2 - 1LL * odd * ncr(remain - m + n - 1, n - 1)) % mod;
		
		// fail case 2: an even number gets > m + 1 out of remaining
		combin_pt2 = (combin_pt2 - 1LL * (n - odd) * ncr(remain - (m + 1) + n - 1, n - 1)) % mod;
		
		ans = (ans + 1LL * combin_pt1 * combin_pt2) % mod;
	}
	if(ans < 0){
		ans += mod;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 15872
#include <bits/stdc++.h>
using namespace std;
int main () {
  int A, B, K;
  cin  >> K >> A >> B;
  int flag = 0;
  for(int i = A; i <= B; i++){
    if(i % K == 0)flag = 1;
  }
  cout << (flag ? "OK": "NG") << endl;
  return 0;
}

Measured memory_bytes: 3624
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		BigDecimal a = new BigDecimal(sc.next());
		BigDecimal b = new BigDecimal(sc.next());
		BigDecimal ans = a.multiply(b);
		ans = ans.setScale(0, RoundingMode.DOWN);

		System.out.println(ans);
	}

}


Measured memory_bytes: 35944
N, K = map(int,input().split())
if K > (N-1)*(N-2)//2:
    print(-1)
    exit()
M = N-1
cnt = (N-1)*(N-2)//2
edges = []
for i in range(2, N+1):
    edges.append((1, i))
for i in range(2, N+1):
    for j in range(i+1, N+1):
        if cnt == K:
            break
        edges.append((i, j))
        cnt -= 1
        M += 1
    if cnt == K:
        break
print(M)
for u, v in edges:
    print(u, v)


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

int main() {
    int a,b,c;
    cin >> a >> b >> c;
    cout << min(b/a,c) << endl;
}

Measured memory_bytes: 256
N = int(input())
L = [list(map(int, input().split())) for _ in range(N)]
t1 = x1 = y1 = 0
for t2, x2, y2 in L:
    t = t2 - t1
    x = abs(x2 - x1)
    y = abs(y2 - y1)
    if x + y > t:
        print("No")
        break
    if (t - (x + y)) % 2 != 0:
        print("No")
        break
    t1 = t2
    x1 = x2
    y1 = y2
else:
    print("Yes")


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

const int MAX = 1000010;
const ll MOD = 1000000007;

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

void init() {
    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;
    }
}

int main(){
    ll X,Y;cin>>X>>Y;
    if(X>Y)swap(X,Y);
    ll nn=Y-X,sq;
    if((X-nn)%3!=0||(X-nn)<0){
        cout<<0<<endl;
        return 0;
    }
    sq=(X-nn)/3;
    init();
    ll ans=(((fac[2*sq+nn]*finv[sq])%MOD)*finv[sq+nn])%MOD;

    cout<<ans<<endl;
}







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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int  ,int > pii;

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

const ll maxn  = 3000;
const ll mod =1e9+7;
const ld PI = acos((ld)-1);

#define pb push_back
#define endl '\n'
#define dokme(x) return(cout << x , 0);
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ms(x , y) memset(x , y , sizeof x);
#define file_init freopen("input.txt", "r+", stdin); freopen("output.txt", "w+", stdout);
ll pw(ll a, ll b, ll md = mod){ll res = 1;while(b){if(b&1){res=(a*res)%md;}a=(a*a)%md;b>>=1;}return(res);}

string s[maxn];
int prt[maxn][maxn];
int n , m;
stack < int > stk;

int main(){
    migmig
    cin >> n >> m;
    for(int i =0 ; i < n ; i ++)
		cin >> s[i];
	for(int i = 1 ; i < n ; i ++){
		for(int j = m-2 ; j >= 0 ; j --){
			int sum = 0;
			if(s[i][j] == '#')sum++;
			if(s[i][j+1] == '#')sum++;
			if(s[i-1][j] == '#')sum++;
			if(s[i-1][j+1] == '#')sum++;
			if(sum != 1 and sum!=3){
				prt[i][j]=prt[i][j+1]+1; 
			}
		}
	}
    for(int i = 1 ; i < n ; i ++)
		for(int j = 0 ; j < m ; j ++)
			prt[i][j]++;
	int ans = 0;
	for(int j = m-1 ; j >= 0 ; j --){
		while(stk.size())stk.pop();
		stk.push(0);
		for(int i = 1 ; i <= n ; i ++){
			while(stk.size() and prt[stk.top()][j] > prt[i][j]){
				int v = prt[stk.top()][j];
				stk.pop();
				ans = max(ans , v * (i - stk.top()));
			}
			stk.push(i);
		}
	}
	ans = max(ans , n);
	ans = max(ans , m);
    cout << ans;
    return(0);
}

Measured memory_bytes: 29184
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep1(n) rep2(i,n)
#define rep2(i,n) rep3(i,0,n)
#define rep3(i,a,b) for(ll i=a;i<b;++i)
int main(){
    int n;
    cin>>n;
    string s;
    cin>>s;
    int a,count=0;
    a=s.size();
    for(int i=0;i<a;i++){
        if(s[i]=='R')count++;
    }
    if(count>n-count)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

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

using ll = long long;
using P = pair<int, int>;

const int MAX = 1e5 + 10;
const int INF = 1e9;
const int MOD = 1e9 + 7;

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

int N;
int a[MAX];
int sum;
int ans[MAX];

int main() {
  // 入力
  cin >> N;
  for (int i = 1; i <= N; i++) cin >> a[i];

  for (int i = 1; i <= N + 1; i++) sum += abs(a[i] - a[i-1]);

  for (int i = 1; i <= N; i++) ans[i] = abs(a[i+1] - a[i-1]) - abs(a[i] - a[i-1]) - abs(a[i+1] - a[i]);

  // 解答
  for (int i = 1; i <= N; i++) cout << ans[i] + sum << endl;

  return 0;
}


Measured memory_bytes: 2048
#include<cstdio>
#include<cstring>
#include<iomanip>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<bitset>
#include<stack>
#include<cassert>
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define mem(x,y) memset(x,y,sizeof x)
#define sqr(x) ((x)*(x))
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ll,int> pli;
const int INF=2e9;
const db eps=1e-12;
template<typename T>
inline void read(T &x) {
	x=0; int f=1; char ch=getchar();
	while( (ch<'0' || ch>'9') && ch!='-') ch=getchar(); if(ch=='-') {f=-1; ch=getchar();}
	while(ch>='0' && ch <='9') x=x*10+ch-'0',ch=getchar();
	x*=f;
}
//==========================head template==========================
const int N=100010;
int n;
int a[N];
int cnt[2][N];
int Ma[2],id[2];
int Se[2],iid[2];
signed main() {
  read(n);
  for(int i=1;i<=n;i++) {
    read(a[i]);
    ++cnt[i&1][a[i]];
  }
  for(int i=1;i<=100000;i++) {
    for(int j=0;j<2;j++)
      if(Ma[j]<cnt[j][i]) {
	Ma[j]=cnt[j][i];
	id[j]=i;
      }
  }
  if(id[0]!=id[1]) {
    printf("%d\n",n-Ma[0]-Ma[1]);
    return 0;
  }
  for(int i=1;i<=100000;i++) {
    for(int j=0;j<2;j++)
      if(Se[j]<cnt[j][i] && id[j]!=i && id[j^1]!=i) {
	Se[j]=cnt[j][i];
	iid[j]=i;
      }
  }
  printf("%d\n",min(n-Ma[0]-Se[1],n-Ma[1]-Se[0]));
  return 0;
}


Measured memory_bytes: 1408
#include "bits/stdc++.h"
using namespace std;
int main()
{
    int n, inf = 1000000000;
    scanf("%d", &n);
    vector<vector<int>> a(n, vector<int>(n, inf));
    for (int i = 0, u, k; i < n; i++)
    {
        scanf("%d %d", &u, &k);
        for (int j = 0, v, c; j < k; j++)
        {
            scanf("%d %d", &v, &c);
            a[u][v] = c;
        }
    }
    vector<int> cost(n, inf);
    vector<bool> vis(n, false);
    cost[0] = 0;
    for (int mi = inf, tip = 0; ; mi = inf)
    {
        for (int i = 0; i < n; i++)
        {
            if (!vis[i] && cost[i] < mi)
            {
                mi = cost[i];
                tip = i;
            }
        }
        
        if (mi == inf)
        {
            break;
        }
        vis[tip] = true;
        for (int i = 0; i < n; i++)
        {
            
            if (!vis[i] && a[tip][i] != inf)
            {
                
                if (cost[tip] + a[tip][i] < cost[i])
                {
                    cost[i] = cost[tip] + a[tip][i];
                }
            }
        }
    }
    
    for (int i = 0; i < n; i++)
    {
        printf("%d %d\n", i, cost[i]);
    }
}


Measured memory_bytes: 3272
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iostream>
#include <numeric>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <vector>

using namespace std;

#define debug(x) (cout << # x ": " << x << endl)
#define int long long int
#define repeat(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(), (x).end()

signed main() {
    int k;
    cin >> k;

    queue<int> q;

    repeat(i, 9) {
        q.push(i + 1);
    }

    int n;
    for (int c = 0; c < k; ++c) {
        n = q.front();
        q.pop();

        int l = n % 10;
        if (l > 0) {
            q.push(n * 10 + l - 1);
        }
        q.push(n * 10 + l);
        if (l < 9) {
            q.push(n * 10 + l + 1);
        }
    }

    cout << n;
    
    return 0;
}

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

int main() {
    string s; cin >> s;
    bool h_flg = false;
    bool ans = false;
    rep(i, s.size()) {
        if (i % 2 == 0 && s[i] == 'h') {
            ans = false;
        }
        else if (i %2 == 1 && s[i] == 'i') {
            ans = true;
        }
        else {
            puts("No");
            return 0;
        }
    }
    if (ans) puts("Yes");
    else  puts("No");
#if 0
    if (s.find("hi") != string::npos) {
        puts("Yes");
    }
    else puts("No");
#endif
}


Measured memory_bytes: 256
#include <stdio.h>
int main(){
  int i,j,N,k,key,A[100];
  scanf("%d",&N);
  for(i = 0; i < N; i++){
    scanf("%d",&A[i]);
  }
  for(i = 0; i < N; i++){
    key =  A[i];
    j = i - 1;
    while(j >= 0 && A[j] > key){
      A[j+1] = A[j];
      j--;
      A[j+1] = key;
    }
    for(k = 0; k < N-1; k++){
      printf("%d ",A[k]);
    }
    printf("%d\n",A[k]);
  }
  return 0;
}

Measured memory_bytes: 600
import java.util.Scanner;

public class Main
{
  static final double TSUBO = 3.305785;

  public static void main(String[] args)
  {
    try (Scanner scanner = new Scanner(System.in);)
    {
      while (scanner.hasNextLine())
      {
        String[] strArray = scanner.nextLine().split(" ");
        double a = Double.valueOf(strArray[0]);
        double b = Double.valueOf(strArray[1]);
        solver(a, b);
      }
    }
  }

  private static void solver(double a, double b)
  {
    System.out.printf("%.6f\n" ,(a * b) / TSUBO);
  }
}



Measured memory_bytes: 26396
#include <bits/stdc++.h>
using namespace std;
template <typename T>
struct range_add_range_sum{
	int N;
	vector<T> ST;
	vector<T> lazy;
	range_add_range_sum(int n){
		N = 1;
		while (N < n){
			N *= 2;
		}
		ST = vector<T>(N * 2 - 1, 0);
		lazy = vector<T>(N * 2 - 1, 0);
	}
	range_add_range_sum(vector<T> &a){
		int n = a.size();
		N = 1;
		while (N < n){
			N *= 2;
		}
		ST = vector<T>(N * 2 - 1, 0);
		lazy = vector<T>(N * 2 - 1, 0);
		for (int i = 0; i < n; i++){
			ST[N - 1 + i] = a[i];
		}
		for (int i = N - 2; i >= 0; i--){
			ST[i] = ST[i * 2 + 1] + ST[i * 2 + 2];
		}
	}
	void eval(int i){
		if (i < N - 1){
			lazy[i * 2 + 1] += lazy[i] / 2;
			lazy[i * 2 + 2] += lazy[i] / 2;
		}
		ST[i] += lazy[i];
		lazy[i] = 0;
	}
	void range_add(int L, int R, T x, int i, int l, int r){
		eval(i);
		if (R <= l || r <= L){
			return;
		} else if (L <= l && r <= R){
			lazy[i] += (r - l) * x;
			eval(i);
		} else {
			int m = (l + r) / 2;
			range_add(L, R, x, i * 2 + 1, l, m);
			range_add(L, R, x, i * 2 + 2, m, r);
			ST[i] = ST[i * 2 + 1] + ST[i * 2 + 2];
		}
	}
	void range_add(int L, int R, T x){
	  range_add(L, R, x, 0, 0, N);
	}
	T range_sum(int L, int R, int i, int l, int r){
		eval(i);
		if (R <= l || r <= L){
			return 0;
		} else if (L <= l && r <= R){
			return ST[i];
		} else {
			int m = (l + r) / 2;
			return range_sum(L, R, i * 2 + 1, l, m) + range_sum(L, R, i * 2 + 2, m, r);
		}
	}
	T range_sum(int L, int R){
	  return range_sum(L, R, 0, 0, N);
	}
};
int main(){
  int n, q;
  cin >> n >> q;
  range_add_range_sum<long long> a(n);
  for (int i = 0; i < q; i++){
    int T;
    cin >> T;
    if (T == 0){
      int s, t, x;
      cin >> s >> t >> x;
      a.range_add(s - 1, t, x);
    }
    if (T == 1){
      int s, t;
      cin >> s >> t;
      cout << a.range_sum(s - 1, t) << endl;
    }
  }
}


Measured memory_bytes: 7004
#!/usr/bin/env python3
import sys, math,bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**8)
inf = float('inf')
ans=count=0

n=int(input())
A=[int(input()) for i in range(n)]
dp=[inf]*(n+10)
dp[0]=A[0]
length=1
for i in range(1,n):
    if dp[length-1]<A[i]:
        dp[length]=A[i]
        length+=1
    else:
        # print(bisect.bisect_left(dp, A[i]),i)
        dp[bisect.bisect_left(dp,A[i])]=A[i]
print(length)




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

int main() {
  int n, m;
  cin >> n >> m;
  
  vector<int> result(n, 0);
  
  for (int i = 0; i < m; i++) {
    int from, to;
    cin >> from >> to;
    result.at(from - 1) += 1;
    result.at(to - 1) += 1;
  }
  
  for (int i = 0; i < n; i++) {
    cout << result.at(i) << endl;
  }
}


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

int main(){
    string S;
    cin >> S;
    int ans = 0;
    vector<string> a = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
    for (int i = 0; i < 7; i++) {
        if (a[i] == S) {
            ans = 7-i;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
import math
from fractions import gcd
# import queue
# from collections import Counter
from itertools import accumulate
# from functools import reduce
# from itertools import accumulate
def lcm(a, b):
    return a * b // gcd(a, b)

def combination_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

big_prime = 1000000007

"""
# 標準入力取得
## 文字列
 =  sys.stdin.readline().rstrip()
 =  list(sys.stdin.readline().rstrip())

## 数値
 =  int(sys.stdin.readline())
 =  map(int, sys.stdin.readline().split())
 =  list(map(int, sys.stdin.readline().split()))
 =  [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
"""


N =  int(sys.stdin.readline())
L =  list(map(int, sys.stdin.readline().split()))

"""
for i in range(N - 2, 0, -1):
    if L[i] < L[i -1]:
        L[i - 1] = L[i]
print(L)
X = accumulate(L)
print(list(X)[-1] + L[0])
"""

X = [L[0]]

for l1, l2 in zip(L, L[1::]):
    X.append(min(l1, l2))
X.append(L[-1])
print(sum(X))

Measured memory_bytes: 66028
//To debug :  g++ -g file.cpp -o code
//to flush output : fflush(stdout) or cout.flush()
//cout<<setprecision(p)<<fixed<<var
//use 1LL<<i to for 64 bit shifting , (ll)2 because by default 2 is ll
 
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,a,n) for(i=a;i<n;++i)
#define irep(i,n,a) for(i=n;i>a;--i)
#define mod 1000000007
#define pb push_back
#define big 9223372036854775807
#define big1 LONG_MAX
#define big2 ll_MAX
#define big3 1000000000
#define sma1 LONG_MIN
#define sma2 ll_MIN
#define sma3 -1000000000
#define mp make_pair
#define dub double
#define ivec vector<ll>
#define lvec vector<long long>
#define cvec vector<char>
#define svec vector<string>
#define mt make_tuple
#define MOD 998244353
#define pi acos(-1.0)

#define SZ(x)  (ll)(x.size())
/*
#define ss second.second
#define ff first.first
#define f first
#define s second
#define sf second.first
#define fs first.second*/
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)

int main()
{

    int n,k,i;

    cin>>n>>k;

    int a[n+1];

    rep(i,1,n+1)
        cin>>a[i];

        sort(a+1,a+1+n);


    int sum=0;

    rep(i,1,k+1)
    {
        sum+=a[i];
    }

    cout<<sum<<"\n";


    return 0;
}

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

using namespace std;

int main(){
    int N, K;
    cin >> N >> K;
    vector<int> H(N);
    for (int i = 0; i < N; i++) {
        cin >> H[i];
    }
    sort(H.begin(), H.end());
    int ans = 1000000000;
    for (int i = 0; i <= N - K; i++) {
        ans = min(ans, H[i + K - 1] - H[i]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
const int maxn=2e5+10;
typedef long long ll;
ll valL[maxn],valR[maxn],tvalL[maxn],tvalR[maxn];

#define inf 0x3f3f3f3f3f3f3f3f
ll dpL[maxn][2],dpR[maxn][2];
ll presum[maxn],sufsum[maxn];
int main()
{
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		int x;cin>>x;
		tvalR[i]=tvalL[i+1]=x;
		if(x!=0)x=(x%2?1:2);
		valR[i]=valL[i+1]=x;
	}
	dpL[0][0]=inf;
	dpL[0][1]=0;
	for(int i=1;i<=n;i++)
	{
		presum[i]=presum[i-1]+tvalL[i];
		if(valL[i]==0)
		{
			dpL[i][0]=min(dpL[i-1][0],dpL[i-1][1])+1;
			dpL[i][1]=min(dpL[i-1][1]+2,presum[i-1]);
		}
		else if(valL[i]==1)
		{
			dpL[i][0]=min(dpL[i-1][0],dpL[i-1][1]);
			dpL[i][1]=dpL[i-1][1]+1;
		}
		else
		{
			dpL[i][0]=min(dpL[i-1][0],dpL[i-1][1])+1;
			dpL[i][1]=dpL[i-1][1];
		}
	//	cout<<i<<" "<<dpL[i][0]<<" "<<dpL[i][1]<<endl;
	}
	
	dpR[n][0]=inf;
	dpR[n][1]=0;
	for(int i=n-1;i>=0;i--)
	{
		sufsum[i]=sufsum[i+1]+tvalR[i];
		if(valR[i]==0)
		{
			dpR[i][0]=min(dpR[i+1][0],dpR[i+1][1])+1;
			dpR[i][1]=min(dpR[i+1][1]+2,sufsum[i+1]);
		//	cout<<dpR[i+1][0]<<" "<<dpR[i+1][1]<<" "<<sufsum[i+1]<<endl;
		}
		else if(valR[i]==1)
		{
			dpR[i][0]=min(dpR[i+1][0],dpR[i+1][1]);
			dpR[i][1]=dpR[i+1][1]+1;
		}
		else
		{
			dpR[i][0]=min(dpR[i+1][0],dpR[i+1][1])+1;
			dpR[i][1]=dpR[i+1][1];
		}
	//	cout<<i<<" "<<valR[i]<<" "<<dpR[i][0]<<" "<<dpR[i][1]<<endl;
	//	system("pause");
	}
	
	ll ans=inf;
	for(int i=0;i<=n;i++)
	{
		ans=min(ans,dpL[i][0]+sufsum[i]);
		ans=min(ans,dpL[i][1]+dpR[i][0]);
		ans=min(ans,dpL[i][1]+dpR[i][1]);
		ans=min(ans,presum[i]+dpR[i][0]);
		ans=min(ans,dpL[i][0]+dpR[i][1]);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 15872
#include<iostream>
using namespace std;
int main(){
  char input;
  cin >> input;
  switch(input){
    case 'A':cout << 'T' <<endl ; break;
    case 'G':cout << 'C' <<endl; break;
    case 'T':cout << 'A' <<endl ; break;
    case 'C':cout << 'G' <<endl; break; 
  }
  return 0;
}

Measured memory_bytes: 256
def judge(num)
  a = num / 10000
  b = num / 1000 % 10
  c = num / 10 % 10
  d = num % 10
  a == d && b == c
end

a, b = gets.split(' ').map(&:to_i)
ret = 0
(a..b).each do |num|
  ret += 1 if judge(num)
end
puts ret


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

using namespace std;
using ll = long long;

#define INF (1LL << 60)

#define REP(i,m,n) for(ll (i)=(m),i##_len=(n);(i)<(i##_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define _PR(x) cout << (x) << endl
#define _PS(x) cout << (x) << " "
#define SZ(x) ((int)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define pb push_back

int main()
{
    ll N, K;
    cin >> N >> K;

    ll d = 0;
    while(N > 0) {
        N /= K;
        ++d;
    }

    _PR(d);

    return 0;
}

/*



*/

Measured memory_bytes: 384
#include <bits/stdc++.h>
 
using namespace std;
 
#define H 19
#define W 15
 
struct State{
    int x,y,S;
    State(int x,int y,int S) : x(x),y(y),S(S) {}
   
    bool operator < (const State &s)const{
	if(x != s.x){
	    return x < s.x;
	}else if(y != s.y){
	    return y < s.y;
	}else{
	    return S < s.S;
	}
    }
};
 
int num[H][W];
char field[H][W];
map<State,int> step;
const int dx[8] = {-1,-1,-1,0,0,1,1,1};
const int dy[8] = {-1,0,1,-1,1,-1,0,1};
 
inline bool inH(int y){
    return (0 <= y && y < H);
}
 
inline bool inW(int x){
    return (0 <= x && x < W);
}
 
inline bool inField(int x,int y){
    return (inH(y) && inW(x));
}
 
int bfs(int sx,int sy){
    queue<State> Q;
    Q.push(State(sx,sy,0));
    step[State(sx,sy,0)] = 0;
 
    while(!Q.empty()){
	State s = Q.front(); Q.pop();
	int x = s.x,y = s.y,S = s.S;
	if(y >= H){
	    return step[s];
	}
	for(int i = 0 ; i < 8 ; i++){
	    int nx = x+dx[i], ny = y+dy[i], nS = S;
	    if(!inField(nx,ny)) continue;
	    if(field[ny][nx] != 'X') continue;
	    if(num[ny][nx] >= 0 && !(S >> num[ny][nx] & 1)){
		bool can = true;
		nS |= (1<<num[ny][nx]);
		while(true){
		    nx += dx[i]; ny += dy[i];
		    if(ny >= H || (ny == H-1 && inW(nx))){
			return step[s]+1;
		    }
		    if(!inW(nx) || ny < 0){ can = false; break; }
		    if(field[ny][nx] != 'X') break; 
		    if(nS >> num[ny][nx] & 1) break; 
		    nS |= (1<<num[ny][nx]);
		}
		if(can && step.find(State(nx,ny,nS)) == step.end()){
		    step[State(nx,ny,nS)] = step[s]+1;
		    Q.push(State(nx,ny,nS));
		}
	    }
	}
    }
    return -1;
}
 
int main(){
    int x,y,n = 0;
    memset(num,-1,sizeof(num));
    for(int i = 0 ; i < H ; i++){
	for(int j = 0 ; j < W ; j++){
	    cin >> field[i][j];
	    if(field[i][j] == 'O'){
		x = j; y = i;
	    }else if(field[i][j] == 'X'){
		num[i][j] = n++;
	    }
	}
    }
    cout << bfs(x,y) << endl;
    return 0;
}

Measured memory_bytes: 8324
#include "bits/stdc++.h"
using namespace std;

#define ll long long

int main() {
	string s, t;
	int count = 0;
	cin >> s;
	cin >> t;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == t[i])continue;
		else count++;
	}
	cout << count;
	return 0;
}

Measured memory_bytes: 3900
import java.util.Scanner;

public class Main {

	static boolean[][] connect;
	static boolean[] visited;
	static int total_paths;

	static int N;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		N = sc.nextInt();
		int M = sc.nextInt();
		int[][] lines = new int[M][2];
		for (int i = 0; i < M; i++) {
			int[] temp = new int[2];
			temp[0] = sc.nextInt();
			temp[1] = sc.nextInt();
			lines[i] = temp;
		}
		// つながりを作成
		connect = new boolean[N][N];
		for (int i = 0; i < M; i++) {
			// 無向グラフだから双方のパスを作成する
			connect[lines[i][0] - 1][lines[i][1] - 1] = true;
			connect[lines[i][1] - 1][lines[i][0] - 1] = true;
		}

		// visitedを初期化
		visited = new boolean[N];
		for (int i = 0; i < N; i++) {
			visited[i] = false;
		}
		int ret = dfs(0, 0);
		System.out.println(ret);
	}

	public static int dfs(int now, int depth) {
		// 訪問済みならこのルートはあり得ないので返却
		if (visited[now]) {
			return 0;
		}
		// 最深部まで探索した場合
		if (depth == N - 1) {
			return 1;
		}
		// 探索済みにする
		visited[now] = true;
		total_paths = 0;
		// 経路を検索し現在のノードからの道があれば再帰する
		for (int i = 0; i < N; i++) {
			if (connect[now][i]) {
				total_paths += dfs(i, depth + 1);
			}
		}
		// 経路が存在しなければfalseにする
		visited[now] = false;
		// 返却
		return total_paths;
	}

}

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

using namespace std;
typedef long long ll;

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

    ll s;
    if(n == 0){
        cout << 0 << endl;
        return 0;
    }else if(n < 0){
        for(s = 1; abs(n) > 1LL << s; s += 2){}
        if(abs(n) == 1 << s){
            cout << 1;
            for(int i = 0; i < s; ++i){ cout << 0; }
            cout << endl;
            return 0;
        }
        n += 1LL << s;
    }else{
        s = -1;
    }

    vector<int> bits;
    for(int i = 0; n > 0; ++i){
        if(n % 2){
            bits.push_back(1);
        }else{
            bits.push_back(0);
        }
        n /= 2;
    }

    vector<int> out(max((ll)bits.size() + 3, s + 1));
    if(s > 0){ out.at(s) = 1; }
    for(int i = 0; i < bits.size(); ++i){
        if(i % 2 == 0 && bits.at(i)){
            out.at(i) += 1;
        }else if(bits.at(i)){
            out.at(i) += 1;
            out.at(i + 1) += 1;
        }
        if(out.at(i) == 2){
            if(out.at(i + 1)){
                out.at(i) = 0;
                out.at(i + 1) -= 1;
            }else{
                out.at(i) = 0;
                out.at(i + 1) = 1;
                out.at(i + 2) = 1;
            }
        }
    }

    reverse(out.begin(), out.end());
    bool start_flg = false;
    for(int i = 0; i < out.size(); ++i){
        start_flg |= (out.at(i) != 0);
        if(start_flg){
            cout << out.at(i);
        }
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 504
N, M = gets.split.map(&:to_i)

edges = M.times.map do
  u, v, c = gets.split.map(&:to_i)
  u -= 1
  v -= 1
  [u, v, c]
end
graph = Array.new(N) { [] }
reversed_graph = Array.new(N) { [] }
edges.each do |u, v, c|
  graph[u].push([v, c])
  reversed_graph[v].push([u, c])
end

def reachable_vertexes(graph, s)
  visited = Set.new
  queue = [s]
  visited.add(s)
  while !queue.empty?
    u = queue.shift
    graph[u].each do |(v, _)|
      next if visited.include?(v)
      visited.add(v)
      queue.push(v)
    end
  end
  visited
end

def bellman_ford(edges, s, v_size, init)
  d = Array.new(N, init)
  d[s] = 0
  c = 0
  loop do
    is_update = false
    edges.each do |(u, v, w)|
      if d[u] != init && d[u] + w > d[v]
        d[v] = d[u] + w
        is_update = true
      end
    end
    return d if !is_update
    c += 1
    return nil if c == v_size
  end
end

require 'set'
reachable_from_1 = reachable_vertexes(graph, 0)
reachable_to_n = reachable_vertexes(reversed_graph, N - 1)
v_set = Set.new
N.times do |v|
  v_set.add(v) if reachable_from_1.include?(v) && reachable_to_n.include?(v)
end
new_edges = edges.select do |(u, v, _)|
  v_set.include?(u) && v_set.include?(v)
end
ans = bellman_ford(new_edges, 0, v_set.size, -(1 << 60))
puts(ans.nil? ? 'inf' : ans[N - 1])

Measured memory_bytes: 2556
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
int main() {
    string s;
    cin >> s;
    ll n = s.size();

    ll ans = 0;
    rep(i, n) {
        if(i%2 == 0 && s[i] == 'p') {
            ans--;
        }
        else if(i%2 == 1 && s[i] == 'g') {
            ans++;
        }
    }
    
    out(ans);
    re0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define PI 3.1415926535897
using namespace std;
typedef long long ll;
const int INF = 1000000000;
const ll LINF = 1000000000000000000; //1e18
const double EPS = 1e-10;

int main(void)
{
    int N;
    cin >> N;
    vector<bool> color(9, false);
    int red = 0;

    vector<int> a(N);
    for (int i = 0; i < N; i++)
    {
        cin >> a[i];
        if (a[i] <= 399)
        {
            color[0] = true;
        }
        else if (a[i] >= 400 && a[i] <= 799)
        {
            color[1] = true;
        }
        else if (a[i] >= 800 && a[i] <= 1199)
        {
            color[2] = true;
        }
        else if (a[i] >= 1200 && a[i] <= 1599)
        {
            color[3] = true;
        }
        else if (a[i] >= 1600 && a[i] <= 1999)
        {
            color[4] = true;
        }
        else if (a[i] >= 2000 && a[i] <= 2399)
        {
            color[5] = true;
        }
        else if (a[i] >= 2400 && a[i] <= 2799)
        {
            color[6] = true;
        }
        else if (a[i] >= 2800 && a[i] <= 3199)
        {
            color[7] = true;
        }
        else
        {
            color[8] = true;
            red++;
        }
    }

    int basic = 0;
    for (int i = 0; i < 8; i++)
    {
        if (color[i] == true)
        {
            basic++;
        }
    }

    int mn = basic;
    if (basic == 0 && red > 0)
    {
        mn = 1;
    }
    int mx = basic + red;
    cout << mn << " " << mx << "\n";
    return (0);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
int main()
{
    int n;
    cin >> n;
    vector<int> p(n);
    rep(i, n) cin >> p[i];
    int cnt=0;
    rep(i, n) if (p[i] != (i + 1)) cnt++;
    if(cnt<3)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}

Measured memory_bytes: 256
import java.util.*;
import java.awt.geom.*;
public class Main {
	
	private void doit(){
		Scanner sc =new Scanner(System.in);
		boolean isfirst = true;
		while(true){
			int start = sc.nextInt();
			int end = sc.nextInt();
			if((start|end)== 0) break;
			
			if(! isfirst){
				System.out.println();
			}
			isfirst = false;
			boolean flg = false;
			for(int i = start; i <= end; i++){
				if(isleapYear(i)){
					System.out.println(i);
					flg = true;
				}
			}
			if(! flg){
				System.out.println("NA");
			}
		}
	}

	private boolean isleapYear(int i) {
		if(i % 4 != 0){
			return false;
		}
		else if(i % 400 == 0){
			return true;
		}
		else if(i % 100 == 0){
			return false;
		}
		else{
			return true;
		}
	}

	public static void main(String[] args) {
		Main obj = new Main();
		obj.doit();
	}
}

Measured memory_bytes: 12000
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		int c = scan.nextInt();
		scan.close();
		System.out.println((c-(a-b)<0)? "0":c-(a-b));
	}
}

Measured memory_bytes: 21844