akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <cstring>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <math.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
const ll MOD = 1e9 + 7;

int main() {
  ll N, M; cin >> N >> M;
  if (N < M) swap(N, M);
  if (N - M > 1) {
    cout << 0 << endl;
    return 0;
  }
  ll n = 1, m = 1;
  for (ll i = 2; i <= N; i++) {
    (n *= i) %= MOD;
  }
  for (int i = 2; i <= M; i++) {
    (m *= i) %= MOD;
  }
  if (N == M)
    cout << 2 * n % MOD * m % MOD << endl;
  else
    cout << n * m % MOD << endl;
}



Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
	int r,g,b;
	cin>>r>>g>>b;
	int x=100*r+10*g+b;
	if (x%4==0){
		cout<<"YES"<<endl;
	}else{
		cout<<"NO"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
n = int(input())
ans = [0 for _ in range(n+1)]

def f(x,y,z):
  return x**2+y**2+z**2+x*y+y*z+z*x
import math

for i in range(1, math.ceil(math.sqrt(n))):
  for j in range(i, math.ceil(math.sqrt(n))):
    for k in range(j, math.ceil(math.sqrt(n))):
      tmp = f(i, j, k)
      if tmp > n:
        break
      else:
        if i == j and j == k:
          ans[tmp] += 1
        elif i == j or j == k:
          ans[tmp] += 3
        else:
          ans[tmp] += 6
        
for i in range(1, n+1):
  print(ans[i])

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

int main(){
  int n;
  string s;
  cin >>n >>s;
  int ans = 0;
  for(int i = 1; i<n; i++){
    int cnt = 0;
    for(char c = 'a'; c<='z'; c++){
      bool left = false, right = false;
      rep(j,i){
        if(s[j]==c) left=true;
      }
      for(int j = i; j<n; j++){
        if(s[j]==c) right=true;
      }
      if(left&&right) cnt++;
    }
    if(cnt>ans) ans = cnt;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define USE_LLONG_AS_INT
#ifdef USE_LLONG_AS_INT
#define int long long
#define inf (1ll<<60)
#else
#define inf (1<<30)
#endif
#define rep(i,n) for(int i=0;i<(n);i++)
#define Rep(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a,b) for(int i=(a);i<=(b);i++)
#define rev(i,n) for(int i=(n)-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define eb emplace_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;
const string sp=" ";

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    string s,t;
    cin>>s>>t;
    Yes(s==t.substr(0,s.length()));
}

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

using namespace std;

int main() {
	int n;
	cin >> n;
	vector<char> arr(n, 0);
	for (int i = 0; i < n; i++) {
		cin >> arr[i];
	}

	int r = n-1, l = 0;
	int cnt = 0;

	while(l < r) {
		while (r >= 0 && arr[r] != 'R') r--;
		while (l < n && arr[l] != 'W') l++;
		if (l > r) break;
		cnt++;
		arr[r] = 'W'; arr[l] = 'R';
	}

	cout << cnt << "\n";
	
}

Measured memory_bytes: 3568
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1LL<<61;


int main() {
  ll n;
  cin >> n;
  vec a(n);
  ll s=0;
  for(ll i=0;i<n;i++) {
    cin >> a[i];
    s+=a[i];
  }
  ll cnt=0;
  ll d=n*(n+1)/2;
  if(s%d) {
    cout << "NO" << endl;
    return 0;
  }
  else {
    cnt=s/d;
  }
  vec b(n);
  for(ll i=0;i<n;i++) {
    b[(i+1)%n]=a[(i+1)%n]-a[i];
  }
  for(ll i=0;i<n;i++) {
    b[i]-=cnt;
  }
  ll f=0;
  for(ll i=0;i<n;i++) {
    if(abs(b[i])%n) {
      cout << "NO" << endl;
      return 0;
    }
    f+=abs(b[i])/n;
  }
  if(f==cnt) {
    cout << "YES" << endl;
  }
  else {
    cout << "NO" << endl;
  }
}

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

int main(){
  int n;
  int m;
  scanf("%d",&n);
  scanf("%d",&m);
  int a[m+1];
  a[m]=0;
  int x[n+2];
  x[0]=0;
  x[1]=1;
  for (int i=0;i<m;i++) {
    scanf("%d",&a[i]);
    x[a[i]+1]=0;
  }
  int j=0;
  for (int i=2;i<n+2;i++){
    if (a[j]==i-1){
      j++;
    }else{
      x[i]=(x[i-1]%1000000007+x[i-2]%1000000007)%1000000007;
    }
  }
  printf("%d",x[n+1]);
}


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

const int maxn=1<<18|1;

int n,ALL;
int a[maxn];
int ans[maxn];

int main (){
	scanf("%d",&n);
	ALL=(1<<n)-1;
	for (int S=0;S<=ALL;S++)
		scanf("%d",&a[S]);
	for (int i=0;i<n;i++)
		for (int S=1;S<=ALL;S++)
			if (S>>i&1){
				ans[S]=std::max(ans[S],a[S]+a[S^(1<<i)]);
				a[S]=std::max(a[S],a[S^(1<<i)]);
			}
	for (int i=1;i<=ALL;i++)
		printf("%d\n",ans[i]=std::max(ans[i],ans[i-1]));
	return 0;
}


Measured memory_bytes: 5120
#include<bits/stdc++.h>
using namespace std;
int main(){
  unsigned long K, A, B;
  unsigned long count = 1;
  cin >> K >> A >> B;
  if ( A+2 >= B){
    count = K + 1;
  }else{
    while(K > 0){
      if(count >= A && K >=2){
        count += (B - A);
        K -= 2;
      }else{
        count++;
        K -= 1;
      }
    }
  }
  
  cout << count << endl;
}

Measured memory_bytes: 256
N, A, B, C, D = map(int, input().split())
A -= 1
B -= 1
C -= 1
D -= 1
S = list(input())
 
ans = 'Yes'
if C < D:
    for i in range(A , C):
        if S[i] == '#' and S[i + 1] == '#':
            ans = 'No'
            break
    for i in range(B, D):
        if S[i] == '#' and S[i + 1] == '#':
            ans = 'No'
            break
else:
    for i in range(A, C):
        if S[i] == '#' and S[i + 1] == '#':
            ans = 'No'
            break
    for i in range(B, D + 1):
        if S[i - 1] == '.' and S[i] == '.' and S[i + 1] == '.':
            break
    else:
        ans = 'No'
            
print(ans)

Measured memory_bytes: 61296
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define each(a, b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define pb push_back
#define show(x) cout <<#x<<" = "<<(x)<<endl
#define spair(p) cout <<#p<<": "<<p.fi<<" "<<p.se<<endl
#define svec(v) cout<<#v<<":";rep(kbrni,v.size())cout<<" "<<v[kbrni];cout<<endl
#define sset(s) cout<<#s<<":";each(kbrni,s)cout <<" "<<kbrni;cout<<endl

using namespace std;

typedef pair<int,int>P;

template<class V> class segtree {
private:
    int n;
    vector<V> node, lazy;
    vector<bool> lazyFlag;

public:
    segtree(vector<V> v) {
        int sz = (int)v.size();
        n = 1;
        while(n < sz){
            n *= 2;
        }
        node.resize(2*n-1);
        lazy.resize(2*n-1, 0);
        lazyFlag.resize(2*n-1,false);
        rep(i,sz){
            node[i+n-1] = v[i];
        }
        for(int i=n-2; i>=0; i--){
            node[i] = min(node[i*2+1],node[i*2+2]);
        }
    }
    void eval(int k, int l, int r) {
        if(lazyFlag[k]) {
            node[k] = lazy[k];
            if(r - l > 1) {
                lazy[k*2+1] = lazy[k*2+2] = lazy[k];
                lazyFlag[k*2+1] = lazyFlag[k*2+2] = true;
            }
            lazyFlag[k] = false;
        }
    }
    void range(int a, int b, V x, int k=0, int l=0, int r=-1) {
        if(r < 0) r = n;
        eval(k, l, r);
        if(b <= l || r <= a){
            return;
        }
        if(a <= l && r <= b) {
            lazy[k] = x;
            lazyFlag[k] = true;
            eval(k, l, r);
        }
        else {
            range(a, b, x, 2*k+1, l, (l+r)/2);
            range(a, b, x, 2*k+2, (l+r)/2, r);
            node[k] = min(node[2*k+1],node[2*k+2]);
        }
    }
    V query(int a, int b, int k=0, int l=0, int r=-1) {
        if(r < 0) r = n;
        eval(k, l, r);
        if(b <= l || r <= a){
            return INT_MAX;
        }
        if(a <= l && r <= b){
            return node[k];
        }
        V vl = query(a, b, 2*k+1, l, (l+r)/2);
        V vr = query(a, b, 2*k+2, (l+r)/2, r);
        return min(vl,vr);
    }
};

int main()
{
    int n,q;
    cin >> n >> q;
    segtree<int> sg(vector<int>(n,INT_MAX));
    rep(i,q){
        int k;
        cin >> k;
        if(k){
            int x;
            cin >> x;
            cout << sg.query(x,x+1) << "\n";
        }else{
            int x,y,z;
            cin >> x >> y >> z;
            sg.range(x,y+1,z);
        }
    }
}

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

using ll=long long; 

void solve(){
	int n,k;
	cin>>n>>k;
	vector<int> l(n);
	for(auto& e:l)cin>>e;
	sort(l.rbegin(), l.rend());
	int ans=0;
	for(int i=0; i<k; i++){
		ans+=l[i];
	}
	cout<<ans<<endl;	
}

signed main(){
	//while(1)
	solve();
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.stream.IntStream;

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

        int N = sc.nextInt();
        int[] V = new int[N];
        for (int i = 0; i < V.length; ++i) {
            V[i] = sc.nextInt();
        }
        int[] C = new int[N];
        for (int i = 0; i < C.length; ++i) {
            C[i] = sc.nextInt();
        }

        System.out.println(solve(V, C));

        sc.close();
    }

    static int solve(int[] V, int[] C) {
        return IntStream.range(0, V.length).map(i -> Math.max(0, V[i] - C[i])).sum();
    }
}

Measured memory_bytes: 36408
using System;
class Program
{
    public static void Main()
    {
        int[] t = Array.ConvertAll(System.Console.ReadLine().Split(' '),int.Parse);
        int a = t[0]; 
        int b = t[1];
        string s;
        
        if(a == b){
            s = "==";
        }
        else if(a > b){
            s = ">";
        }
        else{
            s = "<";
        }
        
        System.Console.WriteLine("a {0} b",s);
    }
}


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

using namespace std;

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

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

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

string S[105];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll H, W;
    cin >> H >> W;
    REP(i, H) {
        cin >> S[i];
    }

    REP(i, W + 2) {
        cout << '#';
    }
    cout << endl;
    REP(i, H) {
        cout << '#' << S[i] << '#' << endl;
    }
    REP(i, W + 2) {
        cout << '#';
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
import math

x = list(map(int,input().split(" ")))
a,b,h,m = x
angle = abs(6*m - 30*(h + m/60))
angle_cos = math.cos(math.radians(angle))
ans = (a**2 + b**2 - 2*a*b*angle_cos) ** 0.5
print(ans)

Measured memory_bytes: 9424
#include<iostream>
using namespace std;
int search(int x)
{
	int dd=0;
	for(int i=1;i<=x;i++){
		if(x%i==0){
				dd++;	
		}
	}	
	return dd;	
}
int main()
{
	int n;
	int cnt=0;
	scanf("%d",&n);
	for(int i=1;i<=n;i=i+2){
		if(search(i)==8){
			cnt++;
		}
	}	
	printf("%d",cnt);
}


Measured memory_bytes: 256
def solve():
  n,t = (int(i) for i in input().split())
  a = list(int(i) for i in input().split())
  query = [-1]
  querymax = -1
  minA = a[0]
  for i in range(1,n):
    if minA < a[i]:
      if querymax <= a[i]-minA:
        querymax = a[i]-minA
        query.append(a[i]-minA)
    
    
    minA = min(minA,a[i])
  print(query.count(max(query)))
    
solve()


Measured memory_bytes: 63088
N, P = map(int, input().split())
A = list(map(int, input().split()))
num_0 = 0
num_1 = 0
for i in range(N):
    if A[i] % 2 == 0:
        num_0 += 1
    else:
        num_1 += 1
if num_1 == 0:
    if P == 1:
        ans = 0
    else:
        ans = 2 ** N
else:
    ans = 2 ** (N-1)

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int N; cin >> N;
    string S; cin >> S;
    int Q; cin >> Q;
    for (int i = 0; i < Q; i++) {
        int k; cin >> k;
        int d = 0, m = 0;
        long long pat = 0, ans = 0;
        for (int l = 0, r = 0; r < S.size(); r++) {
            if (S[r] == 'D') d++;
            if (S[r] == 'M') m++, pat += d;
            if (S[r] == 'C') ans += pat;
            if (r - l != k-1) continue;
            if (S[l] == 'D') d--, pat -= m;
            if (S[l] == 'M') m--;
            l++;
        }
        cout << ans << '\n';
    }
    return 0;
}

Measured memory_bytes: 1412
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <utility>
#include <numeric>

using namespace std;

int main(){
    int n;
    while(cin >> n,n){
        int cnt = 0;
        for(int j=2; j<n; j++){
            for(int i=1; i+j-1<=n; i++){
                int sumj = ((i+j)*(i+j-1))/2, sumi = (i*(i-1))/2;
                if(sumj-sumi == n){
                    int a = 0;
                    cnt++;
                }
            }
        }
        cout << cnt <<  endl;
    }
    return 0;
}



Measured memory_bytes: 3052
while ((n,x = gets.split(" ").map(&:to_i)) != [0,0]) do
  max = 3*(n-1)
  if !((6..max).include?(x))
    puts 0
    next
  end
  count = 0
  catch(:stop) do
    n.downto(1) do |n1|
      (n1-1).downto(1) do |n2|
        n3 = x - n1 - n2
        count += 1 if (n3 < n2) && (n3 > 0)
        throw :stop if (n3 > n1)
        break if (n3 > n2)
      end
    end
  end
  puts count
end

Measured memory_bytes: 8596
h,w=map(int,input().split())
A=[]
for i in range(h):
    A.append(list(map(int,input().split())))
    
S=[]
for i in range(h):
    for j in range(w-1):
        if A[i][j]%2!=0:
            A[i][j]-=1
            A[i][j+1]+=1
            S.append([i+1,j+1,i+1,j+2])
for i in range(h-1):
    if A[i][-1]%2!=0:
        A[i][-1]-=1
        A[i+1][-1]+=1
        S.append([i+1,w,i+2,w])

print(len(S))
for s in S:
    print(*s)

Measured memory_bytes: 30276
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1e9
#define EPS 1e-9
#define MOD (1e9+7)
void get() {}template<class H, class...T>void get(H&h, T&...t) { cin >> h; get(t...); }
template<class T>void geti(T&a) { for (auto&_ : a)cin >> _; }
template<class T>void getii(T&a) { for (auto&_ : a)geti(_); }
void put(string d) {}template<class H, class...T>void put(string d, H&h, T&...t) { cout << h; if (sizeof...(t))cout << d; put(d, t...); }
template<class T>void puti(T&a, string d = " ") { bool f = 1; for (auto&_ : a)cout << (exchange(f, 0) ? "" : d) << _; cout << endl; }
template<class T>void putii(T&a, string d = " ") { for (auto&_ : a)puti(_, d); }
#define dcl(...) ll __VA_ARGS__;get(__VA_ARGS__)
#define dclt(t,...) t __VA_ARGS__;get(__VA_ARGS__)

int main() {
    int n;
    cin >> n;
    vi v(n, 0);
    geti(v);
    puti(v);
    range(i,1,n) {
        int j = i - 1;
        int t = v[i];
        while (j >= 0 && v[j] > t) {
            v[j + 1] = v[j];
            j--;
        }
        v[j + 1] = t;
        puti(v);
    }
}



Measured memory_bytes: 3136
#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
using namespace std;
const ll mod = (ll)1e9+7;
const int INF = 0x3f3f3f3f;
ll max(ll a, ll b){return a > b ? a : b;}
ll min(ll a, ll b){return a < b ? a : b;}

int mpow(int b, int e)
{
    int ret=1;
    for(int i=0; i<e; i++)
    {
        ret=ret*b%mod;
    }
    return ret;
}

int dp[3001][3001];
string s, t;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> s >> t;
    int tt=t.length(), ss=s.length();
    s = ' ' + s;
    t = ' ' + t;
    for(int i=1; i<=ss; i++)
    {
        for(int j=1; j<=tt; j++)
        {
            if(s[i]==t[j])
            {
                dp[i][j] = dp[i-1][j-1]+1;
            }
            else dp[i][j] = max(dp[i][j-1], dp[i-1][j]);
        }
    }
    string ans="";
    while(ss&&tt&&dp[ss][tt])
    {
        while(dp[ss][tt]==dp[ss][tt-1]) tt--;
        while(dp[ss][tt]==dp[ss-1][tt]) ss--;
        ans+=s[ss];
        tt--; ss--;
    }
    reverse(ans.begin(), ans.end());
    cout << ans;
}

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

int main() {
	string a, b;
	cin >> a >> b;
	if (a == "H") {
		cout << b;
	}
	else {
		if (b == "H") {
			cout << "D";
		}
		else {
			cout << "H";
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second

ll n,cnt,ans,a,b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};
map<char,ll> mp;

//-------------------------↓↓↓↓↓↓------------------------

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

    cin>>s;
    rep(i,Size(s))mp[s[i]]++;
    ans=Size(s)*(Size(s)-1)/2;
    ans++;
    rep(i,Size(s)){
        ans-=(mp[s[i]])*(mp[s[i]]-1)/2;
        mp[s[i]]=0;
    }
    Cout(ans);
    return 0;
}


Measured memory_bytes: 720
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);

        int a = s.nextInt();
        int b = s.nextInt();
        int c = Integer.valueOf(String.valueOf(a) + String.valueOf(b));

        if ((int) Math.sqrt(c) == Math.sqrt(c)) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }

}


Measured memory_bytes: 21716
n = int(input())
lst = [int(i) for i in input().split()]

b1 = 0
b2 = 0
b4 = 0

for i in range(n):
    if lst[i] % 2 != 0:
        b1 += 1
    elif lst[i] % 4 == 0:
        b4 += 1
    else:
        b2 += 1

flg = True
if b2 == 0:
    if b1 > b4 + 1:
        flg = False
else:
    if b1 > b4:
        flg = False

if flg:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 14252
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

struct UnionFindTree {
  std::vector<int> data;

  UnionFindTree(int size) : data(size, -1) { }
  bool Unite(int x, int y) {
    x = Root(x); y = Root(y);
    if (x != y) {
      if (data[y] < data[x]) std::swap(x, y);
      data[x] += data[y];
      data[y] = x;
    }
    return x != y;
  }
  bool IsSameRoot(int x, int y) {
    return Root(x) == Root(y);
  }
  int Root(int x) {
    return data[x] < 0 ? x : data[x] = Root(data[x]);
  }
  int Size(int x) { return -data[Root(x)]; }
};

int main() {
  int N, M; cin >> N >> M;
  UnionFindTree tree(N);
  for (int i = 0; i < M; ++i) {
    int A, B; cin >> A >> B; --A, --B;
    tree.Unite(A, B);
  }
  int cnt = 0;
  for (int i = 0; i < N; ++i) {
    if (tree.data[i] < 0) ++cnt;
  }
  cout << cnt-1 << endl;
}


Measured memory_bytes: 3772
s = input()
cnt1 = 0
cnt2 = 0
for i in range(len(s)):
    if i%2 == 0:
        if s[i] == "0":
            cnt1 += 1
        else:
            cnt2 += 1
    else:
        if s[i] == "1":
            cnt1 += 1
        else:
            cnt2 += 1
print(min(cnt1,cnt2))

Measured memory_bytes: 3188
#include<cstdio>

int main(){
    int n, y;
    scanf("%d%d", &n, &y);
    y/=1000;
    for(int i=0; i<=n; i++){
        for(int j=0; i+j<=n; j++){
            if((10*i + 5*j + n-i-j) == y){
                printf("%d %d %d\n", i, j, n-i-j);
                return 0;
            }
        }
    }

    printf("-1 -1 -1\n");
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(true){
            int n = sc.nextInt();
            if(n==0){
                break;
            }
            int[] score = new int[n];
            int max=0,min=1000;
            for(int i=0;i<n;i++){
                score[i] = sc.nextInt();
                if(max<score[i]){
                    max=score[i];
                }
                if(min>score[i]){
                    min=score[i];
                }
            }

            int count_max=0,count_min=0,sum=0,ans=0;
            for(int i=0;i<n;i++){
                if(score[i]==max && count_max==0){
                    count_max++;
                }else if(score[i]==min && count_min==0){
                    count_min++;
                }else if((score[i]!=max && score[i]!=min) || count_max!=0 ||count_min!=0){
                    sum += score[i];
                }
            }
            ans = sum / (n-2);
            System.out.println(ans);
        }     
    }
}


Measured memory_bytes: 28908
#include<bits/stdc++.h>
#define ll long long

int main(){
	ll x;
	scanf("%lld", &x);
	ll moder = x % 11, ans = x / 11;
	if (moder > 6){
		ans = 2 * ans + 2;
	}
	else if (!moder){
		ans *= 2;
	}
	else{
		ans = 2 * ans + 1;
	}
	return printf("%lld\n", ans), 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn=3000+10;
ll quick_pow(ll base,ll n,ll mod) {
	ll ans=1;
	while(n) {
		if(n&1)
			ans=ans*base%mod;
		base=base*base%mod;
		n>>=1;
	}
	return ans;
}
ll c[maxn][maxn];
ll g[maxn][maxn];
int main() {
	ll n,mod;
	scanf("%lld%lld",&n,&mod);
	for(int i=1; i<=n; i++) {
		c[i][0]=1;
		c[i][i]=1;
		for(int j=1; j<i; j++)
			c[i][j]=(c[i-1][j-1]+c[i-1][j])%mod;
	}
	for(int i=0; i<=n; i++) {
		g[i][0]=1;
		for(int j=1; j<=i; j++)
			g[i][j]=(g[i-1][j-1]+g[i-1][j]*(j+1)%mod)%mod;
	}
	ll ans=0;
	for(int i=0; i<=n; i++) {
		ll k=c[n][i];
		if(i&1)
			k=(mod-k)%mod;
		ll kind=quick_pow(2,n-i,mod);
		ll x=quick_pow(2,n-i,mod-1);
		x=quick_pow(2,x,mod);
		ll cnt=0,y=1;
		for(int j=0; j<=i; j++) {
			cnt=(cnt+(g[i][j]*y%mod))%mod;
			y=kind*y%mod;
		}
		ans=(ans+(k*cnt%mod*x%mod))%mod;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 139904
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <bitset>
using namespace std;

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define index(xs, x) (int)(lower_bound(all(xs), x) - xs.begin())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007

int N, X;
vector<int> G[100000];
int dp[100000];
P rooted[100000];

int solve(vector<int> &A, int except) {
  int r = A.size()-1, c = 0;
  rep(l, A.size()) if (l != except) {
    while (l < r && (r == except || A[l]+A[r] > X)) r--;
    if (l >= r) break;
    c++, r--;
  }
  //cout<<"solve({";rep(i, A.size()) if (i!=except)cout<<A[i]<<",";cout<<"}, X="<<X<<") = "<<c<<"\n";
  return c;
}

void dfs(int x, int p) {
  for (int t : G[x]) if (t != p) dfs(t, x);
  int sum = 0;
  vector<int> ds;
  for (int t : G[x]) if (t != p) sum += rooted[t]._1, ds.pb(rooted[t]._2);
  sort(all(ds));
  int m = solve(ds, -1);
  dp[x] = sum-m;
  rooted[x] = P(dp[x]+1, 1);
  if (ds.size() == 0) return;

  int r = ds.size()-1;
  while (r >= 0 && ds[r]+1 > X) r--;
  if (r < 0) return;
  int best = solve(ds, r);
  int lo = -1, hi = r;
  while (hi - lo > 1) {
    int mid = (lo + hi) / 2;
    if (solve(ds, mid) == best) hi = mid;
    else lo = mid;
  }
  rooted[x] = min(rooted[x], P(sum-best, ds[hi]+1));
}

signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> N;
  rep(i, N-1) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    G[a].pb(b);
    G[b].pb(a);
  }
  X = N;
  dfs(0, -1);
  int best = dp[0];
  int lo = 0, hi = N;
  while (hi - lo > 1) {
    int mid = (lo + hi) / 2;
    X = mid;
    dfs(0, -1);
    if (dp[0] == best) hi = mid;
    else lo = mid;
  }
  cout << best << " " << hi << "\n";
  //for (X=1; X<=N; X++) { dfs(0, -1);cout<<"X="<<X<<": "<<dp[0]<<"\n"; }
  return 0;
}


Measured memory_bytes: 17536
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ll long long
#define MOD 1000000007
#define MAX 100010
#define aout(a) REP(i,sizeof(a)) cout << a[i] << " "; cout << endl;
#define vout(v) REP(i,v,size()) cout << v[i] << " "; cout << endl;
using namespace std;
using Graph = vector<vector<int>>;
#define PI 3.1415926535897932384
 
int main(){
  int N; cin>>N;
  int val[10101010], f[10101010];
  FOR(i,1,N+1) val[i] = i, f[i] = 1;
  FOR(p,2,N+1) for(int x=p; x<=N; x+=p){
    int c = 0;
    while (val[x]%p == 0) val[x] /= p, c++;
    f[x] *= c + 1;
  }

  ll ans = 0;
  FOR(i,1,N+1) ans += 1LL * i * f[i];
  cout << ans;
}

Measured memory_bytes: 81732
import functools

import os

INF = float('inf')


def inp():
    return int(input())


def inpf():
    return float(input())


def inps():
    return input()


def inl():
    return list(map(int, input().split()))


def inlf():
    return list(map(float, input().split()))


def inls():
    return input().split()


def inpm(line):
    return [inp() for _ in range(line)]


def inpfm(line):
    return [inpf() for _ in range(line)]


def inpsm(line):
    return [inps() for _ in range(line)]


def inlm(line):
    return [inl() for _ in range(line)]


def inlfm(line):
    return [inlf() for _ in range(line)]


def inlsm(line):
    return [inls() for _ in range(line)]


def debug(fn):
    if not os.getenv('LOCAL'):
        return fn

    @functools.wraps(fn)
    def wrapper(*args, **kwargs):
        print('DEBUG: {}({}) -> '.format(
            fn.__name__,
            ', '.join(
                list(map(str, args)) +
                ['{}={}'.format(k, str(v)) for k, v in kwargs.items()]
            )
        ), end='')
        ret = fn(*args, **kwargs)
        print(ret)
        return ret

    return wrapper


a, b, c = inls()

print((a[0] + b[0]+c[0]).upper())


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

#define GO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int

const int maxr = 1e5 + 5;


int32_t main()
{
	GO;
	int n, x, t;
	cin >> n >> x >> t;
	int ans = (ceil(n / (x * 1.0)) * t);
	cout << ans << endl;
	return 0;
}

//!

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define long long long
#define MOD 1000000007
long remain[100001][13] = {}; 
string ddaor(string s){
	long len = s.length();
	string ans = "";
	for(long i = len - 1; i >= 0; i--) ans += s[i];
	return ans;
}
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	string number; cin >> number;
	
	long len = number.length();
	number = ddaor(number); //cout << number << '\n';
	
	if (number[0] != '?') remain[0][number[0] - '0'] = 1;
	else
		for(long i = 0; i < 10; i++) remain[0][i] = 1;

	long power = 1;
	for(long ind = 1; ind < len; ind++){
		char dig = number[ind];
		// cout << number[ind];
		power *= 10, power %= 13;
		if (dig != '?'){
			// cout << "?" << endl;
			long add = power * (dig - '0'); add %= 13;
			for(long i = 0; i < 13; i++)
				remain[ind][(i + add) % 13] += remain[ind - 1][i], remain[ind][(i + add) % 13] %= MOD;
		}
		else{
			// cout <<"/" << endl;
			for(long i = 0; i < 13; i++)
				for(long j = 0; j < 10; j++){
					remain[ind][(i + (j * power % 13)) % 13] += remain[ind - 1][i], remain[ind][(i + (j * power % 13)) % 13] %= MOD;
				}
		}
	}
	cout << remain[len - 1][5];
}

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


using namespace std;

// マクロ&定数&関数 ================================================
typedef unsigned int uint;
typedef long long ll;

typedef pair<ll, ll> pll;

typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<bool> vbool;
typedef vector<string> vstring;

typedef vector<pair<int, int>> vpint;
typedef vector<pair<ll, ll>> vpll;
typedef vector<pair<double, double>> vpdouble;

typedef vector<vector<int>> vvint;
typedef vector<vector<ll>> vvll;
typedef vector<vpint> vvpint;
typedef vector<vpll> vvpll;
typedef vector<vector<double>> vvdouble;
typedef vector<vector<string>> vvstring;
typedef vector<vector<bool>> vvbool;

typedef vector<vector<vector<ll>>> vvvll;

const int INF = 1e9 + 1;
const ll LLINF = 1e17 + 1;
const int DX[9] = { 0,  0, 1, -1, 1,  1, -1, -1, 0 }; // 4;４近傍
const int DY[9] = { 1, -1, 0,  0, 1, -1,  1, -1, 0 }; // 8:８近傍 9:(0,0)を含む
const double PI = 3.14159265358979323846264338327950288;

//VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV

const ll MOD = 1000000007; //10^9 + 7

//VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV


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




int main() {

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


	/*
	～思いついたことはとりあえず絶対メモする！！～



	*/




	ll N, K;
	cin >> N >> K;

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


	if (K == 0)
	{
		ll ans = 0;
		for (int i = 0; i < N; i++)
		{
			chmax(ans, A[i]);
		}
		cout << ans;
		return 0;
	}


	ll start = 0;
	ll last = LLINF;
	ll mid = (start + last) / 2;


	while (last - start > 1 && (start + last) / 2 > 0)
	{
		mid = (start + last) / 2;


		// mid以下にできるか？
		ll count = 0;

		for (int i = 0; i < N; i++)
		{
			count += (A[i] - 1) / mid;
		}

		if (count <= K)
		{
			last = mid;
		}
		else
		{
			start = mid;
		}
	}

	// mid以下にできるか？
	ll c = 0;
	if (start > 0)
	{
		mid = start;
	}
	for (int i = 0; i < N; i++)
	{
		c += (A[i] - 1) / mid;
	}

	if (c <= K)
	{
		cout << mid << endl;;
		return 0;
	}
	else
	{
		cout << mid + 1 << endl;
		return 0;
	}








}

Measured memory_bytes: 4708
#include <iostream>
#include <vector>
#include<algorithm>
#include<iomanip>
#include<queue>
#include<map>
#include<bitset>
#include<math.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
typedef pair<int,int> pint;
typedef long long ll;
const int inf   = 1e9+7;
const ll  longinf = 1LL<<60;
const int mod=1e9+7;
int dx[4]={1,0,-1,0}, dy[4]={0,1,0,-1};

int main(){
  string s;
  cin>>s;
  int n=s.size();
  map<char,int> mp;
  if(n!=26){
    rep(i,n)mp[s[i]]++;
    cout<<s;
    rep(i,26){
      if(mp['a'+i]==0){
        cout<<(char)('a'+i)<<endl;
        return 0;
        }
      }
    }
  if(s=="zyxwvutsrqponmlkjihgfedcba"){
    cout<<-1<<endl;
    return 0;
    }
  string t=s;
  next_permutation(t.begin(),t.end());
  cout<<t[0];
  rep(i,n){
    if(t[i]==s[i])cout<<t[i+1];
    else break;
    }
    
  return 0;
  }

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 2e9
#define MOD 1000000007
using namespace std;
typedef long long llong;
typedef long double ldouble;

using Graph = vector<vector<int>>;

// int ctoi(const char c){
//   if('0' <= c && c <= '9') return (c-'0');
//   return -1;
// }

// int gcd(int a, int b){
//   int ma = max(a,b);
//   int mi = min(a,b);
//   if(mi == 0) return ma;

//   return gcd(mi, ma%mi);
// }

int main(){
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  int takahashi, aoki;
  if(C%B == 0) takahashi = C/B;
  else takahashi = C/B + 1;
  if(A%D == 0) aoki = A/D;
  else aoki = A/D + 1;
  if(takahashi <= aoki) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3624
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <math.h>
#include <utility>
#include <algorithm>
#include <functional>
#include <vector>
#include <numeric>
#include <bits/stdc++.h>

#define int long long

struct edge {
    int to;
    int cost;
};

using namespace std;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vb = vector<bool>;
using qi = queue<int>;
using P = pair<int, int>;
using graph = vector<vector<edge>>;
// using graph = vector<vector<int>>;


#define FOR(i, a, b) for (int i = a; i < (b); i++)
#define REP(i,n) for(int i=0;i<n;i++)
#define delim(i, n) cout << (i == n-1 ? "\n" : " ");

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

const int inf = 1LL << 60;
// const int inf = 100000000;
const int mod = 1000000007;

const int maxn =  200;
double a, b, x;

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

    cin >> a >> b >> x;
    
    x /= a;
    double y = x - a*b/2;
    double ret;
    if (y >= 0) {
        double l = 2*y/a;
        ret = atan2(a, b-l);
    } else{
        double l = 2*x/b;
        ret = atan2(l, b);
    }
    ret = 90 - ret*180/M_PI;

    cout << std::fixed << std::setprecision(10) << ret << "\n";
}

Measured memory_bytes: 4076
#include<bits/stdc++.h>
using namespace std; 
typedef long long int ll;
const long long int m=pow(10,9)+7;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin>>n;
    n*=3;
    ll c=0;
    ll a[n];
    for(int i=0;i<n;i++)
        cin>>a[i];
    unsigned long long int s=0;
    sort(a,a+n,greater<int>());
    for(int i=0;i<n;i++)
    {
        if(c==n/3)break;
        if(i%2==1)
        {s+=a[i];
        c++;}
    }
    cout<<s<<endl;
    return 0;
}

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

using namespace std;

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

	cin >> N >> S >> K;
	K--;

	for (int i = 0; i < N; i++)
	{
		if (S[i] == S[K])
		{
			cout << S[i];
		}
		else
		{
			cout << '*';
		}
	}
	cout << endl;

	return 0;
}

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

int main(){
  int n,x;
  int sum=0;
  cin >> n >> x;
  vector<int> m(n);
  for(int i=0;i<n;i++){
    cin >> m[i];
    sum += m[i];
  }
  sort(m.begin(),m.end());
  int count = (x-sum)/m[0];
    cout << count+n << endl;
}

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

int main() {
  string A;
  cin >> A;
  if (A=="a"||A=="b"||A=="c"||A=="d"||A=="e"||A=="f"||A=="g"||A=="h"||A=="i"||A=="j"||A=="k"||A=="l"||A=="m"||A=="n"||A=="o"||A=="p"||A=="q"||A=="r"||A=="s"||A=="t"||A=="u"||A=="v"||A=="w"||A=="x"||A=="y"||A=="z") {
    cout << "a" << endl;
  }
  else {
    cout << "A" << endl;
  }
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
/*
1005/1036..
给定两个矩阵，分别代表两种矿石的分布情况，
然后修铁路，每个位置可以有且只能有一个轨道，
第一个矩阵 A 矿石都被送到地图西(只能被向西的矿车开采)，
第二个矩阵 B 矿石被运到地图北边（只能被向北的矿车开采），
而且中途不停轨道不交叉，问最多能获得多少矿石。
*/

int main()
{
    priority_queue<int, vector<int>, greater<int> >q;
    int n,x,y;
    scanf("%d",&n);
    for(int i=1;i<=2*n;i++)
    {
        scanf("%d",&x);
        q.push(x);
    }
    int ans=0;
    while(!q.empty())
    {
        x=q.top();q.pop();
        y=q.top();q.pop();
        ans+=min(x,y);
    }
    printf("%d\n",ans);
    return 0;
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
#define repz(i, z, n) for (decltype(n) i = (z); i < (n); i++)
#define rep(i, n) for (decltype(n) i = 0; i < (n); i++)

#define REPZ(i, z, n) for (decltype(n) i = (z); i <= (n); i++)
#define REP(i, n) for (decltype(n) i = 0; i <= (n); i++)
#define ALL(v) v.begin(), v.end()
#define SIZE(v) ((ll)(v).size())
#define MAX(v) (*max_element(ALL(v)))
#define MIN(v) (*min_element(ALL(v)))
#define INF 1000000000000  // 1E+12

// 略
#define PB push_back
#define F first
#define S second
#define MP make_pair
#define READ cin >>
#define PRINT cout <<
#define PYES cout << "Yes" << endl;
#define POK cout << "OK" << endl;
#define PNO cout << "No" << endl;
#define PNG cout << "NG" << endl;

using namespace std;

// デバッグ用
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}

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

#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

// typedef
typedef long long ll;
typedef unsigned long long ul;
typedef long double ld;
typedef pair<ll, ll> pl;

// const
// 円周率
const ld pi = acos(-1);
// mod用
// 1E+9 +7
const ll mod = (int)1e+9 + 7;
// 1s間で可能なループ回数2E+8回
// int        最大値2147483647         〜2E+9
// long long  最大値9223372036854775807〜9E+18
// 総和accumulate
// 単純リストvector<type> push_back
// 連想配列map<key,value> insert,
// 集合set<type>
// pair キーとバリューを格納 firstとsecondでアクセス
// 小数点指定 cout << fixed << setprecision(15) << endl;
// to_string<->stoi
// stoll(longlong)
// stod(double)
// deep copy v1->v2 copy(v1.begin(), v1.end(), back_inserter(v2) );
// 大文字65-90(-32)
// 小文字97-122(+32)
//  priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>>
//  ba;
signed main() {
  // faster
  // C言語流の入出力は使用できない
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  int n;
  string s;
  cin >> n >> s;
  rep(i, SIZE(s)) s[i] += n;
  rep(i, SIZE(s)) if (s[i] > 90) s[i] = s[i] - 91 + 65;
  cout << s << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

typedef long long ll;

int func(ll x) {
		if (x < 10) return 1;
		return func(x/10) + 1;
}

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

		int ans = 1e9;
		for (ll i = 1; i * i <= N; i++) {
				if (N % i == 0) {
						ll j = N / i;
						ans = min(ans, func(j));
				}
		}

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


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception {
	    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

	    int resultCount = 0;
	    while (true) {
		    String[] line = br.readLine().split(" ");

		    int n = Integer.parseInt(line[0]);
		    int x = Integer.parseInt(line[1]);

		    if (n == 0 && x == 0) break;

		    for (int i = 1; i <= n; i++) {
		    	for (int j = i + 1; j <= n; j++) {
		    		for (int k = j + 1; k <= n; k++) {

		    			if (i + j + k == x) {
		    				resultCount++;
		    			}
		    		}
		    	}
		    }
		    System.out.println(resultCount);
		    resultCount = 0;
	    }
	}
}

Measured memory_bytes: 24928
import re
s = input()
keyence = 'keyence'
for i in range(7):
    fs, es = keyence[:i], keyence[i:]
    # print(fs, es)
    fsis = [m.start() for m in re.finditer(fs, s)]
    esis = [m.start() for m in re.finditer(es, s)]
    for fsi in fsis:
        for esi in esis:
            # print(fsi, esi)
            if fsi + len(fs) <= esi:
                if es == 'keyence' and (esi == 0 or esi + len(es) == len(s)):
                    print('YES')
                    exit()
                elif fsi == 0 and esi + len(es) == len(s):
                    print('YES')
                    exit()
print('NO')

Measured memory_bytes: 3188
#include<time.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
using namespace std;
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

template<typename ...Ts>
void show(Ts... ts){
  cout<<"#:";
  auto print=[](auto v){cout<<v<<" ";};
  initializer_list<int>{(void(print(ts)),0)...};
  cout<<endl;
}

int main(void){
    int a,b,c,x,y;
    int ans=1e9,alt;
    cin>>a>>b>>c>>x>>y;
    
    rep(i,max(x,y)*2+1){
        alt=i*c;
        alt+=max(0,(2*x-i+1)/2)*a;
        alt+=max(0,(2*y-i+1)/2)*b;
        ans=min(ans,alt);
    }
    
    cout<<ans;
}




Measured memory_bytes: 256
#include <iostream>
using namespace std;
#include <string>
#include <vector>
#include <algorithm>
#include <map>
typedef long long ll;
#include <cmath>

int main(int argc, char *argv[])
{
	int n,k;
	cin >>n>>k;
	int ret=0;
	while (n>0)
	{
		n/=k;
		ret++;
	}
	
	cout<< ret<< endl;
	return 0;
}


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

public class Main{
	public static void main(String[] args) {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		int n = 0;
		try {
			line = br.readLine();
			n = Integer.parseInt(line);
		} catch (IOException e) {
			e.getStackTrace();
		}
		int p[] = new int [n];
		String in[] = new String [n];
		try {
			line = br.readLine();
			in = line.split(" ");
		} catch (IOException e) {
			e.getStackTrace();
		}
		int count = 0;
		for(int i = 0; i < n; i++) {
			p[i] =  Integer.parseInt(in[i]);
			if(p[i] != i+1) count++;
		}
		
		if(count <= 2) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}
}

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

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

int main(int argc, char **argv) {
#ifdef LOCAL
  freopen("in.txt", "r", stdin);
#endif

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

  int n; cin >> n;
  for(int i=1; i<=9; i++) {
    if(n%i == 0 && n/i <= 9) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;


  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef pair<P,int> T;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
int main(){
	int A,B,C;
	cin >> A >> B >> C;
	cout << max(0,C-(A-B)) << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(void){
    string s;
    cin>>s;
    sort(s.begin(),s.end());
    string t;
    cin>>t;
    sort(t.rbegin(),t.rend());
    if(s<t)
    cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define max(a, b) ((a) > (b) ? (a) : (b))

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

int main(void)
{
    int ans = 0;
    int n, l[2000];

    scanf("%d", &n);
    rep(i, n)
        scanf("%d", &l[i]);

    qsort(l, n, sizeof(int), compare_int);
    /*rep(i, n)
        printf("%d ", l[i]);
    putchar('\n');*/

    for (int a = 0; a < n; a++)
        for (int b = a; b < n; b++)
        {
            if (a != b)
            {
                int ok = b, ng = n, mid = b;
                int sum = l[a] + l[b];
                //printf("a:%d b:%d\n", l[a], l[b]);
                while (ng - ok > 1)
                {
                    mid = (ok + ng) / 2;
                    if (l[mid] < sum)
                        ok = mid;
                    else
                        ng = mid;
                    ///printf("ok=%d mid=%d ng=%d\n", ok + 1, mid + 1, ng + 1);
                }
                ans += max(0, ok - b);
                //putchar('\n');
            }
        }

    printf("%d\n", ans);

    return 0;
}

Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace task3
{
    class Program
    {
        static void Main(string[] args)
        {
            Int64[] input = Console.ReadLine().Split(' ').Select(Int64.Parse).ToArray();
            Int64 N = input[0];
            Int64 K = input[1];
            Console.WriteLine(Math.Min(N % K, K - (N % K)));
        }
    }
}


Measured memory_bytes: 11348
L = int(input())

digit = L.bit_length()  # 必要なビット数(頂点数)

if 2**digit > L :
    digit -= 1

ans = []
for i in range(1, digit+1) :
    ans.append([i, i+1, 0])
    ans.append([i, i+1, 2**(i-1)])

L = L - 2**digit  # 残り本数

tmp = 0
for i in range(digit, 0, -1) :
    if L - 2**(i - 1) >= 0 :
        ans.append([i, digit+1, 2**digit + tmp])
        L -= 2**(i - 1)
        tmp += 2**(i - 1)

print(digit+1, len(ans))
for a in ans :
    print(*a)

Measured memory_bytes: 3064
/* include c++ libraries */
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <map>
#include <queue>
#include <set>

/* include c-lang libraries */
#include <climits>
#include <cmath>

/* include my libraries */
//#include <show_vec.hh>

using namespace std;

#define LINE DEBUG{ printf("LINE : %d\n", __LINE__); }
#define DEBUG if(false)

using ll = long long;
template<class T> using vec = vector<T>;

const int MOD = 1000000007;

int main(){
  int N, M;
  cin >> N >> M;
  int sum = 0;
  for(int i = 0; i < M; i++){
    int t;
    cin >> t;
    sum += t;
  }
  int Ans = (N<sum)?-1:N-sum;
  cout << Ans << endl;

  return 0;
}


Measured memory_bytes: 3588
import java.util.Scanner;

public class Main {
    static int k[] = new int[45];
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        k[0]=1;
        k[1]=1;
        for (int i = 2; i < k.length; i++) {
            k[i]=k[i-2]+k[i-1];
        }
        System.out.println(k[n]);
    }
}


Measured memory_bytes: 26248
X, K, D = map(int, input().split())
if X > 0 and X - K * D >= 0:
  print(X - K * D)
elif X < 0 and X + K * D <= 0:
  print(abs(X + K * D))
elif K % 2:
  print(min((X+D) % (2*D), abs((X+D) % (2*D)-2*D)))
else:
  print(min(X % (2*D), abs(X % (2*D)-2*D)))

Measured memory_bytes: 61676