akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;

class Program
{
    #region library
    static int n = 0;
    static int m = 0;
    static int r = 0;
    static int c = 0;
    static int x = 0;
    static int y = 0;
    static int[] arr;
    static string s = "";
    static string[] ss;
    static string alpha = "abcdefghijklmnopqrstuvwxyz";
    static long sum = 0;
    static long cnt = 0;
    static long max = -1;
    static long min = 2147483647;
    static bool flg = false;
    static bool flg2 = false;
    static char[,] map;
    static int[,] imap;
    static string rl()
    {
        return Console.ReadLine();
    }
    static string[] rls()
    {
        return Console.ReadLine().Split();
    }
    static void wl(object obj = null)
    {
        Console.WriteLine(obj);
    }
    static void w(object obj)
    {
        Console.Write(obj);
    }
    static int Int(string s)
    {
        return int.Parse(s);
    }
    static long Max(long a, long b)
    {
        return Math.Max(a, b);
    }
    static long Min(long a, long b)
    {
        return Math.Min(a, b);
    }
    static long Abs(long a)
    {
        return Math.Abs(a);
    }
    static void yes()
    {
        wl("YES");
    }
    static void no()
    {
        wl("NO");
    }
    static void Sum()
    {
        wl(sum);
    }
    static void Cnt()
    {
        wl(cnt);
    }
    static void setmap(char def = '@')
    {
        if (r == 0 && c == 0)
        {
            ss = rls();
            r = Int(ss[0]);
            c = Int(ss[1]);
        }
        map = new char[r, c];
        for (int i = 0; i < r; i++)
        {
            if (def == '@') s = rl();
            for (int j = 0; j < c; j++)
            {
                map[i, j] = (def == '@') ? s[j] : def;
            }
        }
    }
    static void setimap(int def = -1)
    {
        if (r == 0 && c == 0)
        {
            ss = rls();
            r = Int(ss[0]);
            c = Int(ss[1]);
        }
        imap = new int[r, c];
        for (int i = 0; i < r; i++)
        {
            if (def == -1) s = rl();
            for (int j = 0; j < c; j++)
            {
                imap[i, j] = (def == -1) ? Int(s[j].ToString()) : def;
            }
        }
    }
    #endregion

    static void Main(string[] args)
    {
        ss = rls();
        int a = Int(ss[0]);
        int b = Int(ss[1]);
        int c = Int(ss[2]);
        if(a + b + c > 21)
        {
            wl("bust");
        }
        else
        {
            wl("win");
        }
    }
}



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

struct Benri {
    Benri() {
        std::cin.tie(0); ios::sync_with_stdio(false);
        cout << fixed << setprecision(12);
    }
} benri;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vll = vector<long long>;
using pll = pair<ll, ll>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define MOD 1000000007
#define MOD2 998244353

const int MAXV = 1000005;

vi G[MAXV];
vi indeg(MAXV);
vi path(MAXV);
vi seen(MAXV);
vi finished(MAXV);

int dfs(int v) { //最長パスを求めつつサイクルがあったら-1として検出
    seen[v] = true;
    int &res = path[v];
    if (~res) return res;
    res = 1;

    for (auto next : G[v]) {
        if (seen[next] && !finished[next]) return -1;
        res = max (res, dfs(next) + 1);
    }
    finished[v] = true;
    return res;
}


int main() {
    int N; cin >> N;
    vvi A(N, vi(N - 1));
    indeg.assign(N * N, 0);
    path.assign(N * N, -1);
    seen.assign(N * N, false);
    finished.assign(N * N, false);

    rep(i, N) {
        rep(j, N - 1) {
            cin >> A[i][j];
            A[i][j]--;
        }
    }

    rep(i, N) {
        rep(j, N - 2) { //試合i-j(i<j)を頂点N*i+jとして持つことにする
            int a = i; int b = i;
            int c = A[i][j]; int d = A[i][j + 1];
            if (a > c) swap(a, c);
            if (b > d) swap(b, d);
            G[a * N + c].pb(b * N + d);
            indeg[b * N + d]++;
        }
    }

    bool negcycle = false;
    int ans = -1;

    rep(i, N) {
        rep(j, N) {
            if (i < j && indeg[i * N + j] == 0) {
                //cout << i << " " << j << endl;
                int a = dfs(i * N + j);
                if (a == -1) {
                    negcycle = true;
                    ans = -1;
                    break;
                }
                ans = max(ans, a);
            }
        }
        if (negcycle) break;
    }

    cout << ans << endl;
}





Measured memory_bytes: 59008
N,K=map(int,input().split())

res=0
for b in range(K+1,N+1):
    #print((N+1)//b*(b-K),(N+1)%b-K)
    res+=(N+1)//b*(b-K)+max(0,(N+1)%b-K)
if(K==0):
    res-=N
print(res)

Measured memory_bytes: 39792
#define _USE_MATH_DEFINES
#include <iostream>
#include <vector>
#include <math.h>
#include <string>
#include <string.h>
#include <stack>
#include <algorithm>
#include <stdio.h>
#include <functional>
using namespace std;

int main()
{
	//10000までの素数リスト作成
	//与えられた数がその素数リストの数（≦与えられた数の平方根）で割れるかどうか調べる

	bool checked[10001] = {}; //[]内の数字が素数かどうかチェックしたかどうかを示す
	int sosuu[10001];
	int sosuu_cnt = 0;

	checked[0] = true;
	checked[1] = true;
	for (int i = 2; i <= 100; i++)
	{
		if (checked[i] == true)
		{
			continue;
		}
		else
		{
			for (int j = 2; i * j <= 10000; j++)
			{
				checked[i * j] = true;
			}
		}
	}
	for (int i = 0; i <= 10000; i++)
	{
		if (checked[i] == false)
		{
			sosuu[sosuu_cnt] = i;
			sosuu_cnt++;
		}
	}

	int n;
	cin >> n;
	int cnt = 0; //合成数のカウント
	for (int i = 0; i < n; i++)
	{
		int input;
		cin >> input;
		for (int j = 0; j < sosuu_cnt; j++)
		{
			if (sosuu[j] > sqrt(input))
			{
				break;
			}
			else if (input % sosuu[j] == 0)
			{
				cnt++;
				break;
			}
		}
	}
	cout << n - cnt << endl; 
	return 0;
}

Measured memory_bytes: 1188
#include <iostream>
#include <unordered_set>

using namespace std;

const long long mod = 1000000007;

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

	unordered_set<int> a_i;

	for (int i = 0; i < m; i++)
	{
		int a;
		cin >> a;
		a_i.insert(a);
	}

	long long s[100001] = {};
	s[0] = 1;
	
	for (int i = 1; i <= n; i++)
	{
		if (a_i.find(i) != a_i.end()) s[i] = 0;
		else
		{
			if (i > 1)
			{
				if (a_i.find(i - 1) != a_i.end()) s[i] = s[i - 2];
				else s[i] = s[i - 1] + s[i - 2];
			}
			else s[i] = s[i - 1];
		}
		s[i] = s[i] % mod;
	}

	cout << s[n] << endl;

	return 0;
}

Measured memory_bytes: 5156
#include<stdio.h>
int main(void){
  int N,sum=0,T,count=0,flag;
  int A[100]={0};
  scanf("%d",&N);
  for(int i=0;i<N;i++){
    scanf("%d",&T);
    for(int j=0;j<count;j++){
      flag=0;
      if(T==A[j]){
        flag=1;
        break;
      }
    }
    if(flag==0){
      sum++;
      A[count]=T;
      count++;
    }
  }
  printf("%d\n",sum);
  return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<bitset>
#include<string>
#include<cmath>
#include<algorithm>
#include<stack>
#include<list>
#include<queue>
#include<map>
using namespace std;

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

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

using namespace std;
using ll=long long;
const ll mod = 1e9 + 7;
int dy[] = {1, -1, 0, 0};
int dx[] = {0, 0, 1, -1};

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

int main() {
    ll N,A,B;
    cin>>N>>A>>B;
    if(abs(A-B)%2==1) cout<<"Borys"<<endl;
    else cout<<"Alice"<<endl;
    return 0;
}


Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    K, N = LI()
    A = LI()
    ans = inf
    for i in range(len(A) - 1):
        dist = A[i+1] - A[i]
        ans = min(ans, K - dist)
    dist = A[0] + K - A[-1]
    ans = min(ans, K - dist)
    print(ans)

main()



Measured memory_bytes: 27408
#include "bits/stdc++.h"
using namespace std;
const int N = 5e5 + 1,M = 1e9 + 7;
mt19937 rng(std::chrono::system_clock::now().time_since_epoch().count());
int fact[N] = {1},inv[N],ans,n,m;
int power(int base,int to){
	int ret = 1;
	while(to){
		if(to&1)ret = ret*1LL*base%M;
		to>>=1;
		base = base*1LL*base%M;
	}
	return ret;
}
int choose(int n,int k){return (fact[n]*1LL*inv[k]%M)*1LL*inv[n - k]%M;}
void add(int &a,int b){
	a+=b;
	if(a >= M)a-=M;
}
int main(){
	scanf("%d%d",&n,&m);
	for(int i = 1;i < N;i++)fact[i] = fact[i - 1]*1LL*i%M;
	inv[N - 1] = power(fact[N - 1],M - 2);
	for(int i = N - 1;i >= 0;i--)inv[i - 1] = inv[i]*1LL*i%M;
	int pairs = fact[n]*1LL*choose(m,n)%M;
	for(int i = 0;i <= n;i++){
		int temp = (i&1) ? M - 1 : 1;
		temp = temp*1LL*choose(n,i)%M;
		temp = temp*1LL*choose(m - i,n - i)%M;
		temp = temp*1LL*fact[n - i]%M;
		add(ans,temp);
	}
	ans = ans*1LL*pairs%M;
	printf("%d\n",ans);
}

Measured memory_bytes: 7716
#include <bits/stdc++.h>
#define rep(i,s,n) for(int i=s;i<n;i++)
#define pb push_back
#define all(x) (x).begin(),(x).end()
using namespace std;
using P=pair<int,int>;
using G=vector<vector<int>>;
using ll=long long;

vector<bool> seen;
vector<int> d;
vector<int> f;
#define pi 3.141592653589793

vector<pair<int64_t,int64_t>> soinsuu(int64_t n){
    vector<pair<int64_t,int64_t>> ret;
    for(int64_t i=2;i*i<=n;i++){
        if(n%i !=0) continue;
        int64_t ex=0;
        while(n%i ==0){
            ex++;
            n /= i; //n変更することで、それ以降の約数で割り切れることはない
        }
        ret.push_back(make_pair(i,ex));
    }
    //nが素数だった場合
    if(n!=1) ret.push_back(make_pair(n,1));
    return ret;
}

int main(int argc,char **argv){
  int h,w; cin>>h>>w;
  int n; cin>>n;
  int a[n];
  rep(i,0,n) cin>>a[i];


  int grid[h][w];

  int key=0;
  for(int hi=0;hi<h;hi++){
    if(hi%2==0){
      for(int wi=0;wi<w;wi++){
      grid[hi][wi]=key+1;
      a[key]-=1;
      if(a[key]==0) key++;
    }
    }
    else{
      for(int wi=w-1;wi>=0;wi--){
      grid[hi][wi]=key+1;
      a[key]-=1;
      if(a[key]==0) key++;
    }
    }
  }

   for(int hi=0;hi<h;hi++){
    for(int wi=0;wi<w;wi++){
      cout<<grid[hi][wi]<<" ";
    }
    cout<<endl;
  }
  }

Measured memory_bytes: 384
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#include<cmath>


#define REP(i,n) for (int i = 0; (i) < (n); ++ (i))
#define FOR(i,n) for (int i = 1; (i) <= (n); ++ (i))
#define dump(x)  cout << #x << " = " << (x) << endl;
#define pb push_back
#define int long long
//#define lint long long

const int INF = 1e18;
const int MOD = 1e9+7;
//const lint LINF = 1e18;
const double eps = 0.000000001;//もとの値の10^(-16)まで

using namespace std;

//typedef pair<int, int> P;
//priority_queue< P, vector<P>, greater<P> > q;//ダイクストラの時、greaterで小さい順

signed main(){
  string s;
	int n;
	cin >> n >> s;
	REP(i,s.size()){
		char now = s[i];
		int t = (s[i]-'A'+n)%26;
		char k = 'A';
		k += t;
		cout << k;
	}
	cout << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include <iostream> 
#include <algorithm> 
#include<string>
#include<queue>
#include<utility>
#include<fstream>
#include<queue>
#include<set>
#include<stack>
#include<map>
//#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define I(a) scanf("%d",&a)
#define I2(a,b) scanf("%d%d",&a,&b)
#define I3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define L(a) scanf("%lld",&a)
#define L2(a,b) scanf("%lld%lld",&a,&b)
#define L3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define PI(a) printf("%d",a)
#define PL(a) printf("%lld",a)
#define PT(t) printf("Case %d: ",t)
#define PB push_back
#define x first
#define y second
#define xx first.first
#define xy first.second
#define yx second.first
#define yy second.second
#define SC scanf
#define PC printf
#define NL printf("\n")
#define SET(a) memset(a,0,sizeof a)
#define SETR(a) memset(a,-1,sizeof a)
#define SZ(a) ((int)a.size())-1
#define f(i,a,b) for(int i=a;i<=b; i++)
#define fr(i,a,b) for(int i=a;i<=b; i++)
#define frr(i,a,b) for(int i=a;i>=b; i--)
#define frv(i,a)  for(int i=0;i<a.size();i++)
#define pi 2.0*acos(0.0)
#define R(a) freopen(a, "r", stdin);
#define W(a) freopen(a, "w", stdout);
#define CB(x) __builtin_popcount(x)
#define STN(a) stringtonumber<ll>(a)
#define lol printf("BUG\n")
#define Endl "\n"
#define mk make_pair
using namespace std;
template <class T> inline T BM(T p, T e, T M)
{
    ll ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    }
    return (T)ret;
}
template <class T> inline T gcd(T a, T b)
{
    if(b == 0)return a;
    return gcd(b, a % b);
}
template <class T> inline T mdINV(T a, T M)
{
    return BM(a, M - 2, M);
}
template <class T> inline T PW(T p, T e)
{
    ll ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p);
        p = (p * p);
    }
    return (T)ret;
}
 
 
template <class T>bool ISLEFT(T a, T b, T c)
{
    if(((a.xx - b.xx) * (b.yy - c.yy) - (b.xx - c.xx) * (a.yy - b.yy)) < 0.0)return 1;  //Uporer dike //A,b,c, x okkher ordera sorted
    else return 0;
}
 
 
typedef pair<int,int >P;
//////////////////////////
/////////////////////////
int main(){
    int n;
    I(n);
    int gc;
    I(gc);
    for(int i = 2;i<=n;i++){
        int y;
        cin>>y;
        gc = gcd(gc, y);
    }
    cout<<gc<<endl;
    return 0;
}

Measured memory_bytes: 256
# c = list(map(int, input().split()))
# a, b, c = map(int, input().split())
# a = [list(map(int, list(input()))) for i in range(n)]
import sys
n, m = map(int, input().split())
l = {}

ret = ['-1'] * n

for i in range(0, m):
    v = list(map(int, input().split()))
    if v[0] in l and l[v[0]] != v[1]:
        print(-1)
        sys.exit()
    
    if v[0] not in l or l[v[0]] > v[1]:
        l[v[0]] = v[1]

for j, k in l.items():
    ret[j - 1] = str(k)

for i in range(len(ret)):
    if ret[i] == '-1':
        if i == 0:
            if n == 1:
                ret[0] = '0'
            else:
                ret[0] = '1'
        else:
            ret[i] = '0'
if n != 1 and ret[0] == '0':
    print(-1)
else:
    print("".join(ret))


Measured memory_bytes: 3064
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <numeric>
#include <queue>

using namespace std;

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for (int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

struct hen {
    int x, y, length;
};

int main() {
    int v, e, s_tmp, t_tmp, w_tmp, ans = 0;
    cin >> v >> e;
    vector<vector<vector<int> > > g(v);
    vector<int> vtmp(2);
    vector<hen> ev;
    hen ev_tmp;
    for (int i = 0; i < e; ++i) {
        cin >> s_tmp >> t_tmp >> w_tmp;
        vtmp[0] = t_tmp;
        vtmp[1] = w_tmp;
        g[s_tmp].push_back(vtmp);
        vtmp[0] = s_tmp;
        g[t_tmp].push_back(vtmp);

        ev_tmp.x = s_tmp;
        ev_tmp.y = t_tmp;
        ev_tmp.length = w_tmp;
        ev.push_back(ev_tmp);
    }

    vector<vector<int> > kk(e, vector<int> (2));
    for (int i = 0; i < e; ++i) {
        kk[i][0] = ev[i].length;
        kk[i][1] = i;
    }
    sort(kk.begin(), kk.end());
    /*
    for (int i = 0; i <= e - 1; ++i) {
        for (int j = 1; j <= e - i - 1 ; ++j) {
            if (ev[j].length < ev[j - 1].length) {
                hen kari = ev[j];
                ev[j] = ev[j - 1];
                ev[j - 1] = kari;
            }
        }
    }
     */
    /*
   //printv3(&g);
   for (int i = 0; i < e; ++i) {
       cout << ev[i].length << endl;
   }
*/
    UnionFind V(v);
    for (int i = 0; i < e; ++i) {
        //cout << ev[i].x << " " << ev[i].y << " " << ev[i].length << endl;
        if (!V.same(ev[kk[i][1]].x, ev[kk[i][1]].y)) {
            V.unite(ev[kk[i][1]].x, ev[kk[i][1]].y);
            ans += kk[i][0];
        }
    }
    cout << ans << endl;
    return 0;
}
/*
6 5
0 1 1
1 2 1
2 3 1
3 4 1
4 5 1
 */



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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 998244353
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;

int main() {
    li h, w;
    cin >> h >> w;
    if (min(h, w) == 1) {
        puts("1");
    } else {
        cout << (h * w + 1) / 2 << endl;
    }


    return 0;
}

Measured memory_bytes: 256
import itertools
n, m = map(int, input().split())
ks = [list(map(int, input().split())) for _ in range(m)]
p = list(map(int, input().split()))

#%%
cnt = 0
for bits in itertools.product([0, 1], repeat=n):
    # ライトの配列の初期化
    lights = [0] * m

    # 電球ごとのONになってるスイッチの数をカウント
    # スイッチのindexでループを回す
    for i in range(n):
        if bits[i] == 1: #スイッチがONのとき
            sw = i + 1 # スイッチの番号
            for j in range(len(ks)): # 全部のlight-switchの配線を確認
                if sw in ks[j][1:]: # 配線がつながってるとき
                    lights[j] += 1 # そのlightに1を加算

    # カウント終了後条件判別
    # 一つもスイッチがONになってないとライトが付きもしない
    # if 0 not in lights:
        # 2で割ったあまり
    m_lights = [l%2 for l in lights]
    if m_lights == p:
        cnt += 1

print(cnt)


Measured memory_bytes: 44124
if __name__ == '__main__':

	n = int(input())

	for i in range(n):
		A = list(map(int,input().split()))

		tmp1 = [0]
		tmp2 = [0]

		Flg = True
		for j in A:
			if tmp1[-1] < j:
				tmp1.append(j)
			else:
				if tmp2[-1] < j:
					tmp2.append(j)
				else:
					Flg = False
					break

		if Flg:
			print("YES")
		else:
			print("NO")



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

int main() {
	int n,k;
	cin>>n>>k;
	int h[n],i,j,x=0;
	for(i=0;i<n;i++)
	{
		cin>>h[i];
		if(h[i]>=k)
		x++;
	}
	cout<<x;
	return 0;
}

Measured memory_bytes: 640
#include <stdio.h>

#define swap(X, Y) {long long temp = (X); (X) = (Y); (Y) = temp;}

long long gcd(long long n, long long m);
long long lcm(long long n, long long m);

int main()
{
    long long n;
    long long a[3005];
    long long ans = 0;
    int i, j;

    scanf("%lld", &n);
    for (i = 0; i < n; i++) {
        scanf("%lld", &a[i]);
        ans += a[i] - 1;
    }

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

    return 0;
}

long long gcd(long long n, long long m)
{
    if (m < n) {
        swap(n, m);
    }

    long long r;
     while (n != 0) {
        r = m % n;
        m = n;
        n = r;
    }

    return m;
}
        
long long lcm(long long n, long long m)
{
    return n * m / gcd(n, m);
}



Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
signed main()
{
    SPEED;
    int n,m;
    cin>>n>>m;
    int a[n],sum=0,cnt=0;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        sum+=a[i];
    }
    double chk=(double)sum/(4*m);
    for(int i=0;i<n;i++)
    {
        if(a[i]>=chk)
        {
            ++cnt;
        }
    }
    if(cnt>=m)
    {
        cout<<"Yes";
    }
    else
    cout<<"No";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define f(i,n) for(int i=0;i<n;i++)
#define P pair<int,int>
#define F first
#define S second
#define int long long
#define mod 1000000007
#define mmod 998244353
#define all(v) v.begin(), v.end()
#define INF LLONG_MAX/3
using namespace std;
int mypow(int a, int b, int c) {
	if (b == 0)return 1;
	if (b % 2)return mypow(a, b - 1, c)*a%c;
	int z = mypow(a, b / 2, c);
	return z * z%c;
}
signed main() {
	int a, b, c;
	cin >> a >> b >> c;
	cout << c << " " << a << " " << b << endl;
}

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

using ll = long long;
using G = vector<vector<int>>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const ll MOD = 1000000007;

ll GCD(ll x, ll y){
	return y ? GCD(y, x%y) : x;	
}

int main() {
	ll n, k; cin >> n >> k;
	ll a[200005];
	bool flag[20005];
	vector<pll> p;
	p.push_back(make_pair(0,0));
	for(ll i=1LL;i<=n;i++){
		cin >> a[i];
		flag[i] = true;
		p.push_back(make_pair(i, a[i]));
	}
	vector<ll> v;
	ll s;
	ll loop_s = 0;
	v.push_back(1);
	flag[1] = false;
	for(ll i=1;i<=n;i++){
		s = p[v.back()].second;
		if(flag[s]){
			v.push_back(s);
			flag[s] = false;
		}else{
			loop_s = s;
			break;
		}
	}
	ll idx = 0;
	int vs = int(v.size());
	for(int i=0;i<vs;i++){
		if(v[i]==loop_s){
			idx = i;
			break;
		}
	}
	if(k<=vs-1){
		cout << v[k] << endl;
		return 0;
	}
	ll ans = (k-idx)%(vs-idx)+idx;
	cout << v[ans] << endl;
	return 0;
}

Measured memory_bytes: 11552
#include<iostream>
#include<cstdio>
#include<queue>

typedef long long ll ;

using namespace std ;


int main()
{
    priority_queue <double> q ;

    int n , m ; scanf("%d%d",&n,&m) ;
    int i, x ;
    double y ;
    ll sum = 0 ;
    for ( i = 1 ; i <= n ; i++ )
    {
        scanf("%d",&x) ;
        q.push(x) ;
    }

    while(m--)
    {
        y = q.top() ;
        q.pop() ;
        y /= 2 ;
        q.push(y) ;
    }
    while(n--)
    {
        y = q.top() ;
        sum += (int) y ;
        q.pop() ;
    }

    cout << sum ;
    return 0 ;
}


Measured memory_bytes: 1400
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <numeric>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
using ll=long long;
#define int ll
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define SZ(x) ((int)x.size())
#define fi first
#define se second
const int INF = 1e15;
using namespace std;

template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;

using pi=pair<int,int>;
using vi=vc<int>;

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

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

    int X; cin >> X;
    int n=100;
    int cnt=0;
    while(n<X){
        cnt++;
        n+=n/100;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 3612
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#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() {
    ll n;
    cin >> n;

    vl a(n);
    rep(i, n) {
        cin >> a[i];
    }

    vvl dp(n+1, vl(n+1));  // dp[L][R] : a[L],…,a[R-1]の状態からはじめて2人が最適に行動したときのX-Yの値
    exrep(len, 1, n) {  // 区間の長さ
        for(ll L = 0; L + len <= n; L++) {  // 区間[L,R)の左
            ll R = L + len;  // 区間[L,R)の右
            if(len%2 == n%2) {  // 区間の長さともとの数列の長さの偶奇が等しいなら先手のターン
                dp[L][R] = max(dp[L+1][R] + a[L], dp[L][R-1] + a[R-1]);  // 先頭要素を取るか末尾要素を取るかの選択でより得点の大きい方を選ぶ
            }
            else {  // そうでなければ後手のターン
                dp[L][R] = min(dp[L+1][R] - a[L], dp[L][R-1] - a[R-1]);  // 先頭要素を取るか末尾要素を取るかの選択でより得点の小さい方を選ぶ
            }
        }
    }
    
    out(dp[0][n]);
    re0;
}

Measured memory_bytes: 70784
#[allow(unused_macros)]
macro_rules! input {
    ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } };
    ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } };
}
#[allow(unused_macros)]
macro_rules! input_inner {
    ( $ next : expr ) => { };
    ( $ next : expr , ) => { };
    ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } };
}
#[allow(unused_macros)]
macro_rules! read_value {
    ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) };
    ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) };
    ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) };
    ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 };
    ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) };
}

fn main() {
    input! {
        n: usize, m: usize, q: usize,
        trains: [(usize1, usize1); m],
        queries: [(usize1, usize1); q]
    }

    let mut qt = vec![];
    qt.extend(trains.into_iter().map(|(l,r)| (l,r,None)));
    qt.extend(queries.into_iter().enumerate().map(|(i, (l,r))| (l,r,Some(i))));
    qt.sort_by_key(|&(_,r,qi)| (r, qi));

    let mut sq = SqDecomposition::new(n);
    let mut ret = vec![0u64;q];
    for i in 0..qt.len() {
        let (l,r,qi) = qt[i];
        if let Some(src) = qi {
            ret[src] = sq.sum(r+1) - sq.sum(l);
        } else {
            sq.all[l] += 1;
            sq.sq[l/sq.d] += 1;
        }
    }
    for i in 0..q {
        println!("{}", ret[i]);
    }
}

#[derive(Debug)]
#[allow(dead_code)]
struct SqDecomposition {
    all: Vec<u64>,
    sq: Vec<u64>,
    d: usize,
}
#[allow(dead_code)]
impl SqDecomposition {
    fn new(n: usize) -> SqDecomposition {
        let d = (n as f64).sqrt().ceil() as usize;
        SqDecomposition {
            all: vec![0; n],
            sq: vec![0; d],
            d: d,
        }
    }
    #[doc = " [0,n)"]
    fn sum(&self, n: usize) -> u64 {
        let mut ret = 0;
        for i in 0..n / self.d {
            ret += self.sq[i];
        }
        for i in 0..n % self.d {
            ret += self.all[n - n % self.d + i];
        }
        ret
    }
}

Measured memory_bytes: 22692
import java.util.Scanner;
public class Main{
    public static void main(String args[]){
        Scanner scan=new Scanner(System.in);
        int N=scan.nextInt();
        int[] a=new int[N];
        int flag=0;
        int i;
        int count=0;
        for(i=0;i<N;i++){
            a[i]=scan.nextInt();
            if(a[i]%2==1){
                flag++;
            }
        }
        if(flag!=0){
            System.out.println("0");
            return;
        }
        else{
            flag=0;
            while(flag==0){
                for(i=0;i<N;i++){
                    if(a[i]%2==1){
                        flag++;
                        break;
                    }
                    a[i]/=2;
                    //System.out.println(a[i]+":");
                }
                if(flag==0){
                    count++;
                }
            }
        }
        System.out.println(count);

    }
}

Measured memory_bytes: 21716
// @flow

const main = (input /*: string */) => {
  const r = reader(input)
  const [m1, d1] = r.ns()
  // const [m2, d2] = r.ns()
  console.log(
    Number(
      {
        [1]: 31,
        [2]: 28,
        [3]: 31,
        [4]: 30,
        [5]: 31,
        [6]: 30,
        [7]: 31,
        [8]: 31,
        [9]: 30,
        [10]: 31,
        [11]: 30,
        [12]: 31,
      }[m1] === d1
    )
  )
}

// const values = obj => Object.keys(obj).map(e => obj[e]);

const reader = (str /*: string*/) => {
  const lines = str.trim().split('\n')
  const s = () => lines.shift() || ''
  const n = () => Number(s())

  const ss = () => s().split(' ')
  const ns = () => ss().map(v => Number(v))
  return { lines, s, n, ss, ns }
}

const getInput = () => require('fs').readFileSync('/dev/stdin', 'utf8')
main(getInput())


Measured memory_bytes: 11468
/*	MASTER HAS FAILED MORE TIMES
	THAN BEGINNER HAS EVER TRIED
*/

#include <bits/stdc++.h>

using namespace std;

#define endl            '\n'
#define mem(a, n)       memset(a, n, sizeof(a))
#define repeat(n)       for(int i=0; i<n; i++)
#define Unique(n)       (n).erase(unique(all(n)), (n).end())
#define isPowerOfTwo(n) (n && !(n & (n - 1)))
#define NumofDigits(n)  ((int)log10(n)+1)
#define all(a)          a.begin(), a.end()

long long gcd(long long a, long long b){ return a%b ? gcd(b, a%b) : b; }
long long lcm(long long a, long long b){ return a*b/gcd(a, b); }

void quicken(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); }

/*
    Special functions:
        find_by_order(k) --> returns iterator to the kth largest element counting from 0
        order_of_key(val) --> returns the number of items in a set that are strictly smaller than our item
*/

int main(){
    quicken();

    int w, h, n, x, y, a, lw, lh, rw, rh;
    cin >> w >> h >> n;
    lw = rh = 0, rw = w, lh = h;

    while(n--){
        cin >> x >> y >> a;
        switch(a){
            case 1: lw = max(lw, x); continue;
            case 2: rw = min(rw, x); continue;
            case 3: rh = max(rh, y); continue;
            case 4: lh = min(lh, y); continue;
        }
    }
    if(lw<rw && lh>rh) cout << (rw-lw)*(lh-rh);
    else cout << 0;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep1(i,n) for(int i=1; i<=(n); ++i)
#define repi(i,a,b) for(int i=a; i<=(b); ++i)
#define rrep(i,n) for(int i=(n-1); i>=0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define pb push_back
#define mp make_pair
#define to_s to_string
#define sz(v) (int)v.size()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define pr(x) cout<<(x)<<'\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
#define yes "Yes"
#define no "No"
using namespace std;
using ll = long long;
using Edge = pair<int,long long>;
using Graph = vector<vector<Edge>>;
typedef pair<int,int> P;
struct aaa{aaa(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}aaaaaaa;
int MOD = 1e9 + 7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return (a*b)/gcd(a,b);}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};


int main(){
    int N,K,Q;
    cin >> N >> K >> Q;
    vector<int> A(1000000);
    rep(i,Q){
        int ans;
        cin >> ans;
        A[ans-1]++;
    }
    rep(i,N){
        if(Q-A[i] >= K) pr("No");
        else pr("Yes");
    }
    
    
}

Measured memory_bytes: 4608
#pragma region RegionDefs
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include "boost/multi_array.hpp"
#define rep(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define reps(i,j,n) for(int i=(j),i##_len=(n);i<i##_len;++i)
#define repr(i,n) for(int i=(n);i>=0;--i)
#define all(x) begin(x),end(x)
using namespace std;
const int INF = 1e9;
template<class T=int> using P  = pair<T, T>;
template<class T=int> using V  = vector<T>;
template<class T=int> using PQ = priority_queue<T>;
template<class T=int> using PQG = priority_queue<T, V<T>, greater<T>>;
typedef long long ll;
const ll MOD = 1000000007LL;
void in() {}
template<class Head, class... Tail>
void in(Head&& head, Tail&&... tail)
{
    cin >> head;
    in(move(tail)...);
}
#define IN(...) ll __VA_ARGS__; in(__VA_ARGS__)

//時間が厳しいとき使う
#define INI(...) int __VA_ARGS__; in(__VA_ARGS__)
#define INS(T, ...) T __VA_ARGS__; in(__VA_ARGS__)
#define VIN(T, v, n) V<T> v(n); for(auto& _elem:v)cin>>_elem
template<class T>bool chmax(T &a, const T &b) {if (a<b) {a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) {if (a>b) {a=b; return 1;} return 0;}
#define y0 y__0
#define y1 y__1
#define j0 j__0
#define j1 j__1
#pragma endregion RegionDefs

void solve()
{
    string s; cin >> s;
    rep(i, s.size())
    {
        cout << 'x';
    }
    cout << endl;
}

int main()
{
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(numeric_limits<double>::max_digits10);

    solve();

    return 0;
}

Measured memory_bytes: 256
from collections import Counter
N = int(input())
A = list(map(int,input().split()))
c = 0
A_ = [0]
for i in range(0,N):
  A_.append(A_[i]+A[i])
ans = 0
A_set = (Counter(A_))
print(sum(v*(v-1)//2 for v in A_set.values()))




Measured memory_bytes: 41716
# -*- coding: utf-8 -*-
n = int(input())
a = []
for i in range(n):
    a.append(str(input()))

if len(set(a)) != n:
    print("No")
else:
    for i in range(n-1):
        if a[i][-1] != a[i+1][0]:
            print("No")
            exit()
    print("Yes")


Measured memory_bytes: 2940
s = list(input())
K = int(input())

for i, c in enumerate(s):
	if K <= 0:
		break
	diff = (123 - ord(c)) % 26
	if diff <= K:
		s[i] = 'a'
		K -= diff
s[-1] = chr(97 + (ord(s[-1]) - 97 + K) % 26)
print(''.join(s))


Measured memory_bytes: 4152
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;

int main(){
	
	char s[101], p[101], loop[201];  /* loopは語尾から先頭に戻る文字列を考える */
	scanf("%s", s);
	scanf("%s", p);
	scanf("%s", loop);

	/* loopは語尾から先頭に戻る文字列を作る */
	strcpy(loop, s);
	strcat(loop, s);

	/* loopした文字列の中に文字列pがあるか探す */
	if( strstr(loop, p) == NULL ) printf("No\n");
	else printf("Yes\n");

	return 0;
}

/********************************************************************************************************************/

//ここからstrcpy(char ○, char △)とstcat(char ○, char △)について説明
// A={xyz},B={abcdef} 
// strcpy(A, B) 文字列A={xyz}の中にB={abcdef} の文字列をコピーする ⇒ A={abcdef} になる。
// stcat(A, B) 文字列A={xyz}の中にB={abcdef} の文字列を連結する ⇒ A={xyzabcdef} になる。

//ここからstrstr(char ○, char △)について説明
// strstr(B, abc) 文字列B={abcdef}の中にabcから始まる文字列を探し出力する ⇒ abcdefを出力。
// strstr(B, a) 文字列B={abcdef}の中にaから始まる文字列を探し出力する ⇒ abcdefを出力。
// strstr(B, af) 文字列B={abcdef}の中にafから始まる文字列を探し出力する ⇒ NULLを出力。 ※見つからい場合はNULLを出力
// strstr(B, 123) 文字列B={abcdef}の中に123から始まる文字列を探し出力する ⇒ NULLを出力。 ※見つからい場合はNULLを出力

/********************************************************************************************************************/


Measured memory_bytes: 3168
#include<bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
const lint mod=1e9+7;

int main()
{
  lint k,s;
  cin >> k >> s;

  lint cnt = 0;
  REP(i,k+1){
    REP(j,k+1){
      if(i+j+k >= s && i+j <= s) cnt++;
    }
  }

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


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

int main(){
  int N;
  cin>>N;
  string s;
  long long M=0LL,A=0LL,R=0LL,C=0LL,H=0LL;

  int count=0;

  for(int i=0;i<N;i++){
    cin>>s;
    switch (s[0]) {
      case 'M':
        M++;
        break;
      case 'A':
        A++;
        break;
      case 'R':
        R++;
        break;
      case 'C':
        C++;
        break;
      case 'H':
        H++;
        break;
      default:
        break;
    }
  }

  cout<<M*A*R+M*A*C+M*A*H+M*R*C+M*R*H+M*C*H+A*R*C+A*R*H+A*C*H+R*C*H;


}


Measured memory_bytes: 256
;;; Utils

(defmacro read-numbers-to-list ()
  `(read-from-string
    (concatenate 'string "(" (read-line) ")")))


(defmacro read-line-to-array (dimension)
  (if (< dimension 0)
      (error "invalid arguments for dimension.")
      `(make-array ,dimension :initial-contents (read-numbers-to-list))))

(defmacro read-line-to--char-list ()
  `(concatenate 'list (read-line)))

(defmethod make-cumlative-sum ((sequence list))
  (labels ((inner (sequence &optional (acc '(0)))
             (if (null sequence)
                 (reverse acc)
                 (inner (rest sequence) (cons (+ (first sequence)
                                                 (first acc))
                                              acc)))))
    (inner sequence)))





(defmethod princ-for-each-line ((sequence list))
  (labels ((inner (sequence)
             (if (null sequence)
                 nil
                 (progn
                   (fresh-line)
                   (princ (first sequence))
                   (inner (rest sequence))))))
    (inner sequence)))

(defmethod princ-for-each-line ((sequence array))
  (dotimes (i (length sequence))
    (fresh-line)
    (princ (aref sequence i))))




;;; Write code here

(defun solve (n m queries)
  (declare (optimize debug))
  (let ((parents (make-array n :initial-element -1)))
    (labels ((find-parents (x)
               (if (< (aref parents x) 0)
                   x
                   (progn
                     ;; memoize
                     (setf (aref parents x) (find-parents (aref parents x)))
                     (aref parents x))))
             (get-size-of-tree (x)
               (abs (aref parents (find-parents x)))))
      
      (loop repeat m
         do
           (progn
             (let ((x (find-parents (first (first queries))))
                   (y (find-parents (rest (first queries)))))
               (if (> x y)
                   (rotatef x y))
               (unless (= x y)
                 (incf (aref parents x) (aref parents y))
                 (setf (aref parents y) x)))
             (pop queries)))
      (reduce #'max
              (mapcar #'get-size-of-tree (loop for i from 0 below n collect i))))))


(defun main ()
  (let ((n (read))
        (m (read))
        (queries nil))
    (loop repeat m
       do (progn
            (push (cons
                   (1- (read))
                   (1- (read)))
                  queries)))
    (format t "~a~%" (solve n m queries))))

(main)


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

int digitSum(int n)
{
  int res = 0;
  while (0 < n)
  {
    res += n % 10;
    n /= 10;
  }
  return res;
}

int main()
{
  int N, A, B;
  cin >> N >> A >> B;
  int ans = 0;
  for (int i = 1; i <= N; i++)
  {
    if (A <= digitSum(i) && digitSum(i) <= B)
      ans += i;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int i,j;
  char s[10005];
  while(scanf("%s",s)!=EOF){
    int ni=0,nj=0;
    rep(i,strlen(s))
      if(strncmp("JOI",&s[i],3)==0)nj++;
      else if(strncmp("IOI",&s[i],3)==0)ni++;
    cout<<nj<<endl;
    cout<<ni<<endl;
  }
}

Measured memory_bytes: 3064
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;
char ch[1001010];
int a[1001010];
int main(){
    int cnt = 0;
    scanf("%s",ch);
    for(int i = 0; ch[i] != '\0'; i ++){
        a[ch[i] - 'a'] ++;
        cnt = i + 1;
    }
    
    long long int ans = 1;
    for(int i = 0; i < cnt; i ++){
        ans = ans + cnt - i - a[ch[i]-'a'];
        a[ch[i] - 'a'] --;
    }
    printf("%lld",ans);
    return 0;
}

Measured memory_bytes: 2176
def calc(n, d)
    if d == 0
        return n
    end
    hoge = [(n - d) - (d + 1) + 1, 0].max
    return n + hoge
end

n, m, d = gets.split.map(&:to_i)

p ((m - 1) * calc(n, d)).to_f / (n*n)

Measured memory_bytes: 1788
#include <iostream>
#include <fstream>
#include <cstdio>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <cassert>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <list>
#include <forward_list>
#include <array>
#include <cstring>
#include <cmath>
#include <tuple>
#include <complex>
#include <bitset>
#include <climits>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
using LD = long double;
using pii = pair<int, int>;
using pll = pair<LL, LL>;
using pld = pair<LD, LD>;


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

    int N;
    cin >> N;

    unordered_map<string, int> items;
    items.reserve(4 * N);
    items.max_load_factor(0.25);

    while (N--)
    {
        string item;
        cin >> item;

        ++items[item];
    }

    cout << items.size();
}


Measured memory_bytes: 22196
#include<iostream>
#include<cstring>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;
int main()
{
	int a,b,t;
	while(scanf("%d%d%d",&a,&b,&t)==3){
		printf("%d",t/a*b);
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int n, m;
  cin >> n >> m;
  int one = -1, two = -1, thr = -1;

  rep(i, 0, m) {
    int s, c;
    cin >> s >> c;
    if (s == 1) {
      if ((one != -1 && one != c) || (n != 1 && c == 0)) {
        cout << -1 << endl;
        return 0;
      }
      one = c;
    } else if (s == 2) {
      if (n < s || (two != -1 && two != c)) {
        cout << -1 << endl;
        return 0;
      }
      two = c;
    } else {
      if (n < s || (thr != -1 && thr != c)) {
        cout << -1 << endl;
        return 0;
      }
      thr = c;
    }
  }

  if (n == 1) {
    cout << max(0, one) << endl;
  } else if (n == 2) {
    if (one != -1)
      cout << one;
    else
      cout << 1;
    if (two != -1)
      cout << two;
    else
      cout << 0;
    cout << endl;
  } else {
    if (one != -1)
      cout << one;
    else
      cout << 1;
    if (two != -1)
      cout << two;
    else
      cout << 0;
    if (thr != -1)
      cout << thr;
    else
      cout << 0;
    cout << endl;
  }
}


Measured memory_bytes: 3596
#include<bits/stdc++.h>
#define F first
#define S second
#define REP(i, a, b, c) for(int i = a; i <= b; i+=c)
#define pb push_back
#define int long long int
#define MOD 1000000007
using namespace std;

int32_t main()
{
  ios :: sync_with_stdio(false); cin.tie(0);
  int t = 1;

  for (int i9 = 1; i9 <= t; i9++)
  {
    int n, k;
    cin >> n >> k;
    int a[n];
    for (int i = 0; i < n; i++)
    {
      cin >> a[i];
    }
    int dp[k + 1] = {0};
    for (int i = 1; i <= k; i++)
    {
      for (int j = 0; j < n; j++)
      {
        if (i - a[j] >= 0 and !dp[i - a[j]])
        {
          dp[i] = 1;
        }
      }
    }
    puts(dp[k] ? "First" : "Second");
  }
}



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

using namespace std;

int main() {
    int a, b, c; cin >> a >> b >> c;
    int count = 0;
    while(1) {
        if(a == b && b == c) break;
        if(a == b) {
            if(c > b) {
                a++; b++;
            }
            else {
                c += 2;
            }
        }
        else if(b == c) {
            if(a > b) {
                b++; c++;
            }
            else {
                a += 2;
            }
        }
        else if(a == c) {
            if(b > a) {
                a++; c++;
            }
            else {
                b += 2;
            }
        }
        else {
            int hoge = max({a, b, c});
            if(hoge != a) a++;
            if(hoge != b) b++;
            if(hoge != c) c++; 
        }
        count++;
    } 
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 256
import heapq


def solve(string):
    n, m, *ab = map(int, string.split())
    ab = sorted([(a, b) for a, b in zip(*[iter(ab)] * 2)])
    hq, index, cap, count, ans = [], 0, 1, m, 0
    while index < n:
        _a, _b = ab[index]
        if _a > m:
            break
        if _a <= cap:
            heapq.heappush(hq, -_b)
            index += 1
        else:
            ans += -heapq.heappop(hq) if len(hq) > 0 else 0
            count -= 1
            cap += 1
    ans += sum([-heapq.heappop(hq) if len(hq) > 0 else 0 for _ in range(count)])
    return str(ans)


if __name__ == '__main__':
    n, m = map(int, input().split())
    print(solve('{} {}\n'.format(n, m) + '\n'.join([input() for _ in range(n)])))


Measured memory_bytes: 25840
#include <iostream>
#include <cstdio>
using namespace std;
char c;
int a,b;
int ans;
bool check()
{
    return c=='+';
}
void solve()
{
    if (check())
    ans = a+b;
    else
    ans=a-b;
    return;
}
main()
{
    cin.tie(0);
    ios::sync_with_stdio(0);
    cin >>a>>c>>b;
    solve();
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256