akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.LinkedList;
import java.util.StringTokenizer;


public class Main {
	
	static class Scanner{
		BufferedReader br=null;
		StringTokenizer tk=null;
		public Scanner(){
			br=new BufferedReader(new InputStreamReader(System.in));
		}
		public String next() throws IOException{
			while(tk==null || !tk.hasMoreTokens()) {
				String cad = br.readLine();
				if (cad == null)
					return null;
				tk=new StringTokenizer(cad);
			}
			return tk.nextToken();
		}
		public int nextInt() throws NumberFormatException, IOException{
			return Integer.valueOf(next());
		}
		public long nextLong() throws NumberFormatException, IOException{
			return Long.valueOf(next());
		}
		public double nextDouble() throws NumberFormatException, IOException{
			return Double.valueOf(next());
		}
	}
	
	static class Node {
		int color;
		LinkedList<Integer> v;
		public Node() {
			color = -1;
			v = new LinkedList<Integer>();
		}
	}
	
	static boolean color(int index, int color) {
		if (array[index].color >= 0)
			return array[index].color == color;
		array[index].color = color;
		for(int e: array[index].v)
			if (!color(e, (color + 1) % 2))
				return false;
		return true;
	}
	
	static int N, M;
	static Node[] array;
	
	public static void main(String args[]) throws NumberFormatException, IOException {
		Scanner sc = new Scanner();
		N = sc.nextInt();
		M = sc.nextInt();
		array = new Node[N];
		for(int i = 0; i < N; i++)
			array[i] = new Node();
		for(int i = 0; i < M; i++) {
			int a = sc.nextInt() - 1;
			int b = sc.nextInt() - 1;
			array[a].v.add(b);
			array[b].v.add(a);
		}
		long ans;
		if (color(0, 0)) {
			long count[] = new long[2];
			for(Node e : array)
				count[e.color]++;
			ans = count[0] * count[1] - M;
		}
		else
			ans = (N * (N - 1L))/2 - M;
		System.out.println(ans);
		
	}

}


Measured memory_bytes: 57740
n, h = map(int, input().split())
a = [None for _ in range(n)]
b = [None for _ in range(n)]
ans = 0
for i in range(n):
    a[i], b[i] = map(int, input().split())
a_s = sorted(a)[::-1]
b_s = sorted(b)[::-1]
for i in range(n):
    if b_s[i] >= a_s[0]:
        h -= b_s[i]
        ans += 1
        if h <= 0:
            break
    else:
        break
if h > 0:
    ans += (h + a_s[0] - 1) // a_s[0]
print(ans)

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

long long count1(vector<long long> &vec,long long x)
{
    long long n=0;
    for(int i=0;i<vec.size();i++)
    {
        n+=(vec[i]-1)/x ;
    }
    return n ;
}
int main()
{
   ios_base::sync_with_stdio(false) ;
   cin.tie(NULL) ;
    
   long long int n ;
   long long int k ;
   
   cin>>n>>k ;
   vector<long long> vec(n) ;
   long long max1=0 ;
   
    for(int i=0 ;i<n ;i++)
    {
           cin>>vec[i] ;
           max1=max(max1,vec[i]) ;
    }
    long long l=1 ;
    long long r=max1 ;
    long long ans ;
    while(l<=r)
    {
        long long mid=(l+r)/2 ;
        if(count1(vec,mid) <= k)
        {
            ans=mid ;
            r=mid - 1 ;
        }
        else
        {
            l=mid+1 ;
        }
    }
    cout<<ans<<endl ;
    return 0 ;
}


Measured memory_bytes: 4728
N, M = map(int, input().split())
S = input()[::-1]

"""
スタートから貪欲に考えようとすると
「最短で行くために大きい目を出したい」と
「辞書順最小のために小さい目を出したい」が共存してやりづらい

ゴールから貪欲に考える（出来るだけ多く戻る）と考えると
「最短で行くために大きい目を出したい」と
「辞書順最小のために、最後の手を出来るだけ小さくしたい
 -> 後ろから考えて、大きい目を出せば良い」となり
貪欲に解ける
"""
# 出した目の値（逆順）
ans = []
# 現在の位置（ゴールを0、スタートをNとする）
now = 0

while True:
    # Mだとオーバーしてしまう場合(ちょうど終わる場合も含む)
    # 最後の目を記録して終了
    if now + M >= N:
        ans.append(N - now)
        break

    # Mマス進むと仮定する
    step = M
    # 行き先がゲームオーバーなら、stepをデクリメント
    while S[now + step] == '1':
        step -= 1
        # step = M,M-1,...,1がダメならこれ以上進めないので終了
        if step == 0:
            print(-1)
            exit()

    now += step
    ans.append(step)

print(*ans[::-1])


Measured memory_bytes: 83184
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <climits>
#include <math.h>
 
using namespace std;
typedef unsigned long ul;
typedef pair<long, int> P;

int bitCount(uint bits) {
    int cnt = 0;
    while( bits != 0 ) {
        ++cnt;
        bits &= bits - 1;
    }
    return cnt;
}

int main() {
	uint a[10],p[10];
	uint n,m,k,t;
	cin>>n>>m;
	for(int i=0;i<m;i++) {
		a[i]=0;
		cin>>k;
		for(;k>0;k--){
			cin>>t;
			a[i] |= 1<<(t-1);
		}
	}
	for(int i=0;i<m;i++) cin>>p[i];

	int cnt = 0;
	for(t=0;t<(1<<n);t++) {
		bool ok = true;
		for(int i=0;i<m;i++) {
			if(bitCount(a[i] & t) % 2 != p[i]) {
				ok = false;
				break;
			}
		}
		if(ok) cnt++;
	}
	cout<<cnt<<endl;
}

Measured memory_bytes: 256
sub f{my$r=$u["@_"]=1;$u[$_]||($r+=f($_))for@{$G["@_"]};$r}($n,$m)=glob<>;/ /,push@{$G[$`]},$'+!push@{$G[$']},$`for<>;$a=f 1;$a-=$-=$a- f(2);print$n*($n-1)/2-$a*($n-$a)-$m

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

int main() {

  string S;
  cin >> S;

  int max = 0;
  int tmp = 0;

  for(int i = 0; i < 3; i++){
    if(S[i] == 'R'){
      tmp++;
      if(tmp > max){
        max = tmp;
      }
    }else{
      tmp = 0;
    }
  }
  
  cout << max << endl;
}


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

typedef long long ll;
const int MAX_N = 100030;    // Change as necessary

void check1(ll b,ll n,ll s){
  while(n){
    s -= n % b;
    n /= b;
  }
  
  if(s) return;
  
  cout << b << endl;
  exit(0);
}

bool check2(ll a1,ll n,ll s){
  n -= s;
  if(n <= 0) return 0;
  
  return (n % a1 == 0);
}

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  
  ll n,s; cin >> n >> s;
  for(ll b=2;b<=1000000;b++)
    check1(b,n,s);
  
  vector<ll> poss;
  for(ll a1=1;a1<=1000000;a1++)
    if(check2(a1,n,s)){
      ll b = (n-s)/a1+1;
      ll a2 = s - a1;
      if(!(0 <= a2 && a2 < b)) continue;
      if(!(0 <= a1 && a1 < b)) continue;
      if(b > 1000000)
        poss.push_back(b);
    }
  
  if(n == s) poss.push_back(n+1);
  
  if(poss.empty())
    cout << -1 << endl;
  else
    cout << *min_element(poss.begin(),poss.end()) << endl;
  
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.util.stream.*;

class Main{
	public static void main(String[] $){
		Scanner s=new Scanner(System.in);
		int n=s.nextInt(),qa=s.nextInt(),qb=s.nextInt();
		UF ua=new UF(n),ub=new UF(n);
		for(int q=0;q<qa;++q)
			ua.connect(s.nextInt()-1,s.nextInt()-1);
		for(int q=0;q<qb;++q)
			ub.connect(s.nextInt()-1,s.nextInt()-1);
		
		int[]r=new int[n];
		
		HashMap<Integer,HashSet<Integer>>ma=new HashMap<>(),mb=new HashMap<>();
		for(int i=0;i<n;++i) {
			ma.computeIfAbsent(ua.root(i),o->new HashSet<>()).add(i);
			mb.computeIfAbsent(ub.root(i),o->new HashSet<>()).add(i);
		}
		
		for(int i=0;i<n;++i) {
			if(r[i]!=0)
				continue;
			Collection<Integer> sa=ma.get(ua.root(i)),sb=mb.get(ub.root(i)),tmp;
			if(sa.size()>sb.size()) {
				tmp=sa;
				sa=sb;
				sb=tmp;
			}
			int v=0;
			for(Integer j:sa) {
				if(sb.contains(j)) {
					r[j]=~i;
					++v;
				}
			}
			r[i]=v;
			
		}
		System.out.println(
				Arrays.stream(r).map(i->i<0?r[~i]:i)
				.mapToObj(String::valueOf)
				.collect(Collectors.joining(" ")));
	}
}

class UF{
	public int[] uni;
	public UF(int size){
		Arrays.fill(uni=new int[size],-1);
	}
	public int root(int t){
		return uni[t]<0?t:(uni[t]=root(uni[t]));
	}
	public boolean connect(int p,int c){
		p=root(p);
		c=root(c);
		if(p==c)
			return false;
		if(uni[p]>uni[c]){
			int buf=c;
			c=p;
			p=buf;
		}
		uni[p]+=uni[c];
		uni[c]=p;
		return true;
	}
	public boolean isConnected(int a,int b){
		return root(a)==root(b);
	}
	public int groupSize(int t){
		return -uni[root(t)];
	}
}


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

int main()
{
  int a,b;
  char x;

  while(true)
    {
      int k = 0;
      
      cin >> a >> x >> b;
      
      if(x == '+')
	{
	  k = a + b;
	}
	  if(x == '-')
	{
	  k = a - b;
	}
      if(x == '*')
	{
	  k = a * b;
	}
      if(x == '/')
	{
	  k = a / b;
	}
      if(x == '?')
	{
	  break;
	}
      cout << k << endl;
    }

  return 0;
}



Measured memory_bytes: 3100
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

struct P {
  double x;
  double y;
  P(double x, double y) : x(x) , y(y) {
  };
};

static inline void printP(P& p) {
  cout << fixed << p.x << " " << p.y << endl; 
}

static inline double toRadian(double degree) {
  return degree / 180 * M_PI;
}

static inline void koch(int d, P p1, P p2) {
  if (d == 0) {
    return;
  }
  
  P s(p1.x + (p2.x - p1.x) / 3, p1.y + (p2.y - p1.y) / 3);
  P t(p1.x + 2 * ((p2.x - p1.x) / 3), p1.y + 2 * ((p2.y - p1.y) / 3));
  P u(
    (t.x - s.x) * cos(toRadian(60.0)) - (t.y - s.y) * sin(toRadian(60.0)) + s.x,
    (t.x - s.x) * sin(toRadian(60.0)) + (t.y - s.y) * cos(toRadian(60.0)) + s.y);
 
  koch(d - 1, p1, s);
  printP(s);
  koch(d - 1, s, u);
  printP(u);
  koch(d - 1, u, t);
  printP(t);
  koch(d - 1, t, p2);
}

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

  P p1(0.0, 0.0), p2(100.0, 0);

  printP(p1);
  koch(n, p1, p2);
  printP(p2);
  
  return 0;
}



Measured memory_bytes: 3136
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

struct UnionFind {
  vector<int> d;
  UnionFind(int n) : d(n, -1) {}
  int root(int x) {
    if(d[x] < 0) return x;
    return d[x] = root(d[x]);
  }
  bool unite(int x, int y) {
    x = root(x);
    y = root(y);
    if(x == y) return false;
    if(d[x] > d[y]) swap(x, y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x, int y) { return root(x) == root(y); }
  int size(int x) { return -d[root(x)]; }
};

int main() {
  int n, m;
  cin >> n >> m;
  vi p(n);
  rep(i, n) {
    cin >> p[i];
    p[i]--;
  }
  UnionFind uf(n);
  rep(i, m) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    uf.unite(x, y);
  }
  int ans = 0;
  rep(i, n) if(uf.same(i, p[i])) ans++;
  cout << ans << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int N;
    cin>>N;
    vector<int>A(N);
    for(int i=0;i<N;i++)
        cin>>A[i];

    unordered_map<int,pair<int,bool>>M;

    int extra = 0;
    for(int i=0;i<N;i++)
    {
        if(M[A[i]].first < A[i])
        {
            M[A[i]].first++;
            if(M[A[i]].first == A[i])
            {
                M[A[i]].second = true;
            }
        }
        else
        {
            extra++;
        }
    }


    for(auto i:M)
    {
        if(i.second.second == false)
            extra += i.second.first;        
    }

    cout<<extra<<endl;

}

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

using namespace std;

#define fstinpt     ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define ll          long long
#define sn          1010
#define bn          10000007
#define M           1000000007
#define iii(i)      cin>>i
#define ooo(i)      cout<<i
#define sss         cout<<" "
#define nnn         cout<<"\n"

ll b[bn],a[bn];


int main()
{
        ll n; iii(n);
        for(ll i = 1; i <= n; i++)
        {
                for(ll j = i; j <= n; j += i)
                {
                        b[j]++;
                }
        }
        for(ll i = 1; i <= n; i++)
        {
                b[i] *= i; b[i] += b[i-1];
        }
        ooo(b[n]);
        return 0;
}



/*













*/






















/**/


Measured memory_bytes: 81728
N = int(input())
a = list(input().split())
A = [int(a[i])for i in range(N)]
frag = [0 for i in range(60)]
mod = 10 ** 9 + 7
ans = 0

for i in range(60):
    j = 1 << i
    cnt = sum((k & j) >> i for k in A)
    ans += (cnt * (N - cnt)) << i
    ans %= mod
    
print(ans)

Measured memory_bytes: 50720
import java.util.*;

public class Main {
	  public static void main(String args[]){
      	Scanner scan = new Scanner(System.in);
            
        String before_s = scan.next();
        String s        = scan.next();
        String after_s  = scan.next();
            
        System.out.println(before_s.substring(0,1) + s.substring(0,1) + after_s.substring(0,1));
	  }
}

Measured memory_bytes: 21204
#include<bits/stdc++.h>
using namespace std;
#define maxn 100005
int cnt[3];
int col[maxn];
vector<int>v[maxn];
int n;

void bfs(){
    queue<int>Q;
//    cout<<Q.size()<<endl;
    Q.push(1);
    Q.push(n);
    col[1]=1,col[n]=2;
    while(!Q.empty()){
        int now = Q.front();
        Q.pop();
        cnt[col[now]] ++;
        for(int i=0;i<v[now].size();i++){
            int to = v[now][i];
            if(col[to])continue;
            col[to] = col[now];
            Q.push(to);
        }
    }
}


int main(){
    int x,y;
    while(~scanf("%d",&n)){
        memset(cnt,0,sizeof(cnt));
        memset(col,0,sizeof(col));
        memset(v,0,sizeof(v));
//        cout<<cnt[1]<<" "<<cnt[2]<<endl;
        for(int i=1;i<n;i++){
            scanf("%d %d",&x,&y);
            v[x].push_back(y);
            v[y].push_back(x);
        }
        bfs();
//        cout<<cnt[1]<<" "<<cnt[2]<<endl;
        if(cnt[1]<=cnt[2])puts("Snuke");
        else puts("Fennec");
    }
    return 0;
}


Measured memory_bytes: 6272
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    n , m = f()

    cons = [f() for i in range(m)]
    p = f()

    ans = 0
    for i in range(1<<n):
        on = [0] * n
        for j in range(n):
            if i&(1<<j):
                on[j] = 1
        
        cnt_on = [0] * m
        for j in range(m):
            for k in range(1, len(cons[j])):
                if on[cons[j][k]-1]:
                    cnt_on[j] += 1
        
        ok = 1
        for j in range(m):
            if (cnt_on[j] + p[j])%2 != 0:
                ok = 0
        if ok:
            ans += 1
    
    print(ans)

            



solve()


Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;

int main(void)
{
	char a[1000]={0},b[1000]={0};
	int n,flag,count1,count2,count3,daisyo=0,miss=0;
	cin>>n;

	for (int i=0; i<n; i++) 
	{
		flag=0;
		daisyo=0;
		miss=0;

		cin>>a>>b;
		count1= strlen(a);
		count2= strlen(b);
		
		if (count1>80||count2>80) {
			flag=1;
		}
		count3=count1-count2;
		
		if(count2>count1)
		{
			count3*=-1;
			daisyo=1;
		}
		
		if(daisyo==0)
		{
			if(!(count1==count2))
			for(int j=0;j<=count2;j++)
			{
				b[count2-j+count3]=b[count2-j];
			}
			for (int j=0; j<count3; j++) {
				b[j]='0';
			}
			
			for (int j=1; j<=count1; j++) {
				a[count1-j]+=b[count1-j]-48;
				if (((int)a[count1-j])-48>9) 
				{
					if (j>=80) {
						flag=1;
						break;
					}
					a[count1-j]=(a[count1-j]-48)%10+48;
					if ((count1-j)==0) {
						miss=1;
					}
					else {
							a[count1-j-1]=a[count1-j-1]+1;

						
					}
				}
			}
		}
		
		else
		{
			for(int j=0;j<=count1;j++)
			{
				a[count1-j+count3]=a[count1-j];
			}
			for (int j=0; j<count3; j++) {
				a[j]='0';
			}
			
			for (int j=1; j<=count2; j++) {
				b[count2-j]+=a[count2-j]-48;
				if (((int)b[count2-j]-48)>9) 
				{
					if (j>=80) {
						flag=1;
						break;
					}
					b[count2-j]=(b[count2-j]-48)%10+48;
					if ((count2-j)==0) {
						miss=1;
					}
					else {
						b[count2-j-1]=b[count2-j-1]+1;
					}
				}
			}
		}
		
		if(flag==1)
		{
			cout << "overflow" << endl;
		}
		
		else 
		{
			if (miss==1) {
				cout << '1';
			}
			if(daisyo==0) 
			{
				for (int j=0; j<count1; j++) 
				{
					cout << (int)a[j]-48;
				}
			}
			
			else 
			{
				for (int j=0; j<count2; j++) 
				{
					cout << (int)b[j]-48;
				}
			}
			cout << endl;

		}
		
		
	}
		
		
	
	return (0);
}

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

 
int main() {
    string S;
    cin >>S;
    bool T =false;
    if(S.at(1)!=S.at(0)||S.at(1)!=S.at(2)) T=true;
    if(T) cout << "Yes" << endl;
    else cout << "No" << endl;

    }


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

using namespace std;

using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;

using _loop_int = int;
#define REP(i,n) for(_loop_int i=0; i<(_loop_int)(n); i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a); i<(_loop_int)(b); i++)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1; i>=(_loop_int)(a); i--)

#define CHMIN(a,b) (a)=min((a),(b))
#define CHMAX(a,b) (a)=max((a),(b))
#define ALL(v) (v).begin(),(v).end()

#define DEBUG(x) cerr<<#x<<": "<<(x)<<endl
#define DEBUG_VEC(v) cerr<<#v<<": ";REP(__i,(v).size())cerr<<((v)[__i])<<", ";cerr<<endl

const ll MOD = 1000000007ll;

int n;
int a[1252][1252];
int enemy[1252];
int head[1252];

int main(){
    scanf("%d",&n);
    REP(i,n)REP(j,n-1)scanf("%d",&a[i][j]),a[i][j]--;
    int ans = 0;
    vi alive(n);
    REP(i,n)alive[i]=i;
    while(true){
        ans++;
        for(int id : alive){
            enemy[id] = a[id][head[id]];
        }
        bool upd = false;
        vi nalive;
        for(int id : alive)if(enemy[enemy[id]]==id){
            head[id]++;
            upd = true;
            if(head[id] != n-1){
                nalive.push_back(id);
            }
        }else{
            nalive.push_back(id);
        }
        if(!upd){
            puts("-1");
            return 0;
        }
        alive = nalive;
        if(alive.size()==0){
            break;
        }
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 6400
#include <iostream>
#include <iomanip>
#include <cmath>
double PI= 3.1415926535897932384626433832;
using namespace std;
int main()
{
    double a,b,C;
    cin>>a>>b>>C;
    cout<<setiosflags(ios::fixed)<<setprecision(10)<<0.5*a*b*sin(C*PI/180)<<endl<<a+b+sqrt(a*a+b*b-2*a*b*cos(C*PI/180))<<endl<<b*sin(C*PI/180)<<endl;
    return 0;
}


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

#define rep(i, a) for (int i = 0; i < (a); i++ )
#define FOR(i, m, n) for(int i = m; i < n; i++)

typedef pair<int,int> P;
typedef long long ll;
const int INF = 1001001001;
const int MOD = 1000000007;
const double PI=acos(-1);

int main(){
    int N;
    cin >> N;
    map<ll,ll> S;
    ll a_max = 0;
    bool t = true;
    rep(i,N) {
        ll a;
        cin >> a;
        a_max = max(a,a_max);
        S[a]++;
        if (i==0 && a!=0) {
          t = false;
        }
    }
    ll ans = 1;
    ll p = 1;

    if (S[0]!=1) {
        cout << 0 << endl;
    }
    else if (!t) {
      cout << 0 << endl;
    }
    else {
        for (ll i = 1; i<=a_max; i++) {
            if (S[i]==0) {
                ans = 0;
                break;
            }
            else {
                ll tmp=1;
                rep(j,S[i]) {
                    tmp*=p;
                    tmp%=998244353;
                }
                ans *= tmp;
                ans %= 998244353;
                p = S[i];   
            }
        }
        cout << ans << endl;
    }
    
}


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

int main(){
    int N;
    cin >> N;
    int array[N];
    for(int i = 0; i < N; i++) cin >> array[i];

    int count = 0;
    for(int i = 0; i < N; i++){
        if(array[i] != i + 1) count++;
    }

    if(count == 0 || count == 2) cout << "YES";
    else cout << "NO";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define ALL(a) (a).begin(), (a).end()
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;

int main()
{
    cin >> N;
    vector<int> A(4);

    A[0] = N / 1000;
    A[1] = (N % 1000) / 100;
    A[2] = (N % 100) / 10;
    A[3] = N % 10;

    for(int temp=0;temp<(1<<3);temp++)
    {
        bitset<3> s(temp);
    
        int sum = A[0];
        for (int i = 1; i <= 3; i++) {
            if (s.test(i-1)) {
            sum += A.at(i);
            }
            else
            {
                sum -= A.at(i);
            }
        }
        

        if (sum == 7)
        {
            cout << A[0] << (s.test(0) ? "+" : "-") << A[1] << (s.test(1) ? "+" : "-") << A[2] << (s.test(2) ? "+" : "-") << A[3] << "=7";
            break;
        }
        
    }
    
return 0;
}

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

int main() {
  int X, Y;
  cin >> X >> Y;
  for (int i = 0; i <= X; i++) {
    if (2 * i + 4 * (X-i) == Y) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  
  cout << "No" << endl;
}

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

int64_t gcd(int64_t p, int64_t q)
{

    if (p < q)
        swap(p, q);

    if (p % q == 0)
        return q;
    else
        return gcd(q, p % q);
}

int main()
{
    int64_t A, B, C, D;
    cin >> A >> B >> C >> D;

    A--;

    int64_t lcm = C * D / gcd(C, D);

    int64_t min = A - A / C - A / D + A / lcm;
    int64_t max = B - B / C - B / D + B / lcm;

    cout << max - min;
}

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

int main(){
    int sx,sy,tx,ty;
    cin >> sx >> sy >> tx >> ty;

    for(int i = sy;i <ty; i++){
        cout << "U";
    }
    for(int i = sx;i <tx; i++){
        cout << "R";
    }
    for(int i = ty;sy < i; i--){
        cout << "D";
    }
    for(int i = tx;sx < i; i--){
        cout << "L";
    }
    cout << "L";

    for(int i = sy;i <=ty; i++){
        cout << "U";
    }
    for(int i = sx;i <=tx; i++){
        cout << "R";
    }
    cout << "D";
    cout << "R";
    for(int i = ty;sy <= i; i--){
        cout << "D";
    }
    for(int i = tx;sx <= i; i--){
        cout << "L";
    }
    cout << "U" << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;


// ?????????????????????????????????????????????????????????
public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = 2;
		boolean same = true; 
		Dice[] dice = new Dice[n];
		int[] temarray = new int[6 + 1];
		int[] tararray = new int[6 + 1];
		temarray[0] = 0;
		for (int i = 0; i < n; i++) {
			for (int j = 1; j < 7; j++) {
				temarray[j] = scan.nextInt();
			}
			dice[i] = new Dice(temarray);
		}
		/*
		temarray = dice[0].getNum();
		tararray = dice[1].check(temarray[1], temarray[2]);
		for (int i = 1; i < 7; i++) {
			if (temarray[i] != tararray[i]) {
				same = false;
			}
		}
		scan.close();*/
		temarray = dice[0].getNum();
		if (dice[1].check(temarray)) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}
	

class Dice {
	private int[] num = new int[6 + 1];
	Dice() {
	}

	Dice(int[] array) {
		for (int i = 0; i < array.length; i++) {
			this.num[i] = array[i];
		}
	}
	
	public int[] getNum() {
		return this.num;
	}
	
	public int getNumber(int i) {
		return this.num[i];
	}
	
	// ??????????????¢??????????????????
	public int[] roll(int[]ary, String order) {
		int now_1 = 1;	int now_2 = 2;	int now_3 = 3;	int tmp;
		int[] array = ary;
		char[] check = {'N', 'E', 'S', 'W'};
		for (int i = 0; i < order.length(); i++) {
			for (int j = 0; j < check.length; j++) {
				if (order.charAt(i) == check[j]) {
					switch (j + 1) {
						case 1:
							tmp = now_1;
							now_1 = now_2;
							now_2 = 7 - tmp;
							break;
						case 2:
							tmp = now_1;
							now_1 = 7 - now_3;
							now_3 = tmp;
							break;
						case 3:
							tmp = now_1;
							now_1 = 7 - now_2;
							now_2 = tmp;
							break;
						case 4:
							tmp = now_1;
							now_1 = now_3;
							now_3 = 7 - tmp;
							break;
					}
				}
			}
		}
		int[] cp_array = new int[array.length];
		cp_array[1] = array[now_1]; cp_array[2] = array[now_2];
		cp_array[3] = array[now_3]; cp_array[4] = array[7 - now_3];
		cp_array[5] = array[7 - now_2]; cp_array[6] = array[7 -now_1];
		return cp_array;
	}
	
	
	// ??????????????????????????????????????????
	public boolean check(int[] tarary) {
		int[] ary = tarary;
		String[] str = {"null", "N", "N", "N", "E", "WW"};
		int sum = 0;
		int[] array = new int[this.num.length];
		for (int i = 0; i < this.num.length; i++) {
			array[i] = this.num[i];
		}
		boolean decision = false;
		for (int i = 0; i < str.length; i++) {
			array = this.roll(array, str[i]);
			for (int j = 0; j < 4; j++) {
				if (array[1] == ary[1]) {
					if (array[2] == ary[2]) {
						for (int k = 3; k < ary.length; k++) {
							
							if (array[k] != ary[k]) {
								decision = false;
								break;
							}
							decision = true;
						}
					}
					if (decision) {
						break;
					} else {
						array = this.roll(array, "NWS");
					}
				} else {
					break;
				}
			}
			if (decision) break;
		}
		

		return decision;
	}
}

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

using namespace std;

#define int long long
#define ALL(x) (x).begin(),(x).end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

typedef pair<int,int> PI;
typedef pair<int,pair<int,int>> PII;
static const int INF=1010000000000000017LL;
static const double eps=1e-12;
static const double pi=3.14159265358979323846;
static const int dx[4]={1,-1,0,0};
static const int dy[4]={0,0,1,-1};
static const int ddx[8]={1,-1,0,0,1,1,-1,-1};
static const int ddy[8]={0,0,1,-1,1,-1,1,-1};

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

int L,R;
int d;
int ans;

signed main(){
    cin>>L>>R>>d;
    for(int i=L;i<=R;++i){
        if(i%d==0)ans++;
    }
    cout<<ans<<endl;
}

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

#define rp(i,n) for(int i=0;i<n;i++)
#define rep(i,m,n) for(int i=m;i<=n;i++)
#define llrp(i,n) for(long long i=0;i<n;i++)
#define llrep(i,m,n) for(long long i=m;i<=n;i++)
#define sort(a) sort(a.begin(),a.end())
#define reverse(a) reverse(a.begin(),a.end())
#define pb push_back
#define elif else if
#define vcin(a); rp(i,a.size()){cin>>a[i];}
#define vcout(a); rp(i,a.size()){cout<<a[i]<<endl;}
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<char> vc;
typedef long long ll;
typedef string S;
typedef pair<int,int> P;

bool isOK(int index, int key,vi a) {
    if (a[index] >= key) return true;
    else return false;
}

int binary_search(int key,vi a) {
    int left = -1;
    int right = (int)a.size();
    while (right - left > 1) {
        int mid = left + (right - left) / 2;
        
        if (isOK(mid, key,a)) right = mid;
        else left = mid;
    }
    return right;
}

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vi l(2*n);
    vcin(l);
    sort(l);
    int ans=0;
    rp(i,2*n){
        ans += (i%2?0:l[i]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
int main()
{
    int n,j,sum=0;
    scanf("%d",&n);
    j=n;
    while(n>0)
    {
   sum+=n%10;
     n/=10;
    }

    if(j%sum==0){
    printf("Yes");
    }
    else {
    printf("No");
    }
   return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <deque>
#include <utility>
using namespace std;
typedef long long ll;
#define for1(i,n) for (ll i=0;i<(n);i++)
#define for2(i,m,n) for (ll i=(m);i<(n);i++)
#define for3(i,m,n,d) for (ll i=(m);i<(n);i+=(d))

void solve()
{
    ll N;
    cin >> N;
    vector<vector<ll>> to(N);
    for1(i,N-1) {
        ll a,b;
        cin >> a >> b;
        --a; --b;
        to[a].push_back(b);
        to[b].push_back(a);
    }
    vector<ll> color(N, 0);
    vector<ll> sc(3, 0);
    deque<pair<ll,ll>> q;

    q.push_back(make_pair(0,1));
    q.push_back(make_pair(N-1,2));
    while (!q.empty()) {
        auto item = q.front();
        q.pop_front();
        ll loc = item.first;
        ll col = item.second;
        //cout << loc << " " << col << endl;
        if (color[loc] != 0) {
            continue;
        }
        color[loc] = col;
        sc[col] += 1;
        for (ll l2: to[loc]) {
            q.push_back(make_pair(l2,col));
        }
    }
    if (sc[1] > sc[2]) {
        cout << "Fennec" << endl;
    } else {
        cout << "Snuke" << endl;
    }
}

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


Measured memory_bytes: 7680
#include <iostream>

using namespace std;

bool inRange(int x, int y, int maxX, int maxY)
{
  return 0 <= x && x <= maxX && 0 <= y && y <= maxY;
}

int main()
{
  int W, H, x, y, r;
  cin >> W >> H >> x >> y >> r;
  if (r <= x && x <= W - r && r <= y && y <= H - r)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3100
from math import sqrt

n = int(input())
maximum = int(sqrt(n))
f = [0] * (n + 1)

for x in range(1, maximum):
  for y in range(1, maximum):
    for z in range(1, maximum):
      value = x*x + y*y + z*z + x*y + y*z + z*x
      if value <= n:
        f[value] += 1
for f_i in f[1:]:
  print(f_i)

Measured memory_bytes: 9324
import java.util.*;
public class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong();
		String ans = "NO";
		Set<Long> set = new HashSet<>();
		for(long i = 0;i < N;i++){
			set.add(sc.nextLong());
		}
		if(N == set.size()){
			ans = "YES";
		}
		System.out.println(ans);
	}
}

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

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

bool isOK(string s){
	for(int i = 0;i < s.size();i++){
		if(s[i] != s[s.size()-i-1]){
			return false;
		}
	}
	return true;
}

signed main(){
	string s;
	cin >> s;
	int n = s.size();

	if(isOK(s) && isOK(s.substr(0, (n-1)/2)) && isOK(s.substr((n+3)/2-1, (n-1)/2))){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cstdint>
#include <cmath>
#include <functional>
#include <limits>
#include <cassert>
#include <bitset>

using namespace std;

/* template */

using ll = long long;

void debug_out() { std::cout << std::endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cout << "debug: "; debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif

#define rep(i, a, n) for (int i = (int)(a); i < (int)(n); i++)
#define rrep(i, a, n) for (int i = ((int)(n-1)); i >= (int)(a); i--)
#define Rep(i, a, n) for (long long i = (long long)(a); i< (long long)(n); i++)
#define RRep(i, a, n) for (long long i = ((long long)(n-1ll)); i>=(long long)(a); i--)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}

struct Edge{
    int to;
    ll weight;
    Edge(int t, ll w) : to(t), weight(w){ }
};

struct edge{
    int from;
    int to;
    ll weight;
    edge(int f,int t,ll w) : from(f), to(t), weight(w){ }
};


using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;
using edges = vector<edge>;

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

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

template <class T>
T lcm(T a, T b){
    return (a*b)/gcd(a,b);
}

ll ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}

constexpr ll LNF = 1LL<<50;

constexpr int INF = 1e9+7;

const long double PI=3.14159265358979323846;


vector<int> dx = {1,0,-1,1,-1,0};
vector<int> dy = {1,1,1,0,0,-1};

/* template */

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll n; cin >> n;
    ll ans = 0;
    Rep(i,1,n+1){
        ll res = n/i;
        ans += i*res*(res+1)/2;
    }
    cout << ans << endl;
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,M;
string S;
ll dp[202020][2][2];
ll mo=1000000007;

ll dp2[202020];
ll dps[202020];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>M>>S;
	if(S[0]=='B') {
		FORR(c,S) c='R'+'B'-c;
	}
	if(count(ALL(S),'B')==0) {
		dp[0][0][0]=dp[0][1][1]=1;
		for(i=1;i<N;i++) {
			(dp[i][0][0]=dp[i-1][0][0]+dp[i-1][0][1])%=mo;
			(dp[i][0][1]=dp[i-1][0][0])%=mo;
			(dp[i][1][0]=dp[i-1][1][0]+dp[i-1][1][1])%=mo;
			(dp[i][1][1]=dp[i-1][1][0])%=mo;
		}
		cout<<(dp[N-1][0][0]+dp[N-1][0][1]+dp[N-1][1][0])%mo<<endl;
		return;
	}
	
	vector<int> V;
	V.push_back(0);
	FORR(c,S) {
		if(c=='R') V.back()++;
		else V.push_back(0);
	}
	V.pop_back();
	
	int L=1<<20;
	if(V[0]%2==0) V[0]++;
	FORR(v,V) if(v%2) L=min(L,v);
	
	
	dp2[0]=dps[0]=1;
	for(i=2;i<=N;i+=2) {
		dp2[i]=dps[i-2];
		if(i-(L+1)>0) (dp2[i]+=mo-dps[i-(L+1)-2])%=mo;
		dps[i]=(dps[i-2]+dp2[i])%mo;
		//cout<<i<<" "<<dp2[i]<<endl;
	}
	
	ll ret=0;
	for(i=1;i<=min(L,N-1);i+=2) {
		//cout<<i<<" "<<(i+1)<<"*"<<dp2[N-(i+1)]<<endl;
		(ret+=(i+1)*dp2[N-(i+1)])%=mo;
	}
	cout<<ret%mo<<endl;
	
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 7956
#include <iostream>
#include <cmath>
using namespace std;
long long x,y,maks;
int main() {
cin>>x>>y;
for(long long i=1;i<100;i++) {
	maks=pow(2,i-1)*x;
	if(maks>y) {
		cout<<i-1<<endl;
		break;
	}
}
}

Measured memory_bytes: 3932
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <map>
using namespace std;

long long N, F[1000][10], V[1000][11], maxn = -(1 << 30);

int main() {
	cin >> N;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < 10; j++) cin >> F[i][j];
	}
	for (int i = 0; i < N; i++) {
		for (int j = 0; j <= 10; j++) cin >> V[i][j];
	}
	for (int i = 1; i < (1 << 10); i++) {
		long long cnt = 0;
		for (int j = 0; j < N; j++) {
			int ret = 0;
			for (int k = 0; k < 10; k++) {
				if ((i / (1 << k)) % 2 == 1 && F[j][k] == 1) ret++;
			}
			cnt += V[j][ret];
		}
		maxn = max(maxn, cnt);
	}
	cout << maxn << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
	int a=0,b=0,c=0;
	int ans=0;
	int ans2=0;

	scanf("%d%d%d",&a,&b,&c);


	if(a-b >= c){
		ans = 0;
	}else{
		ans = c-(a-b);
	}

	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 128
# -*- coding: utf-8 -*-
 
import math
import itertools
import sys
import copy
 
# 入力
#N, L = map(int, input().split())
A = str(input())
B = str(input())
C = str(input())


temp = A[0]

while (1) :
  if temp == "a" :
    if len(A) != 0 :
      temp = A[0]
      A = A[1:]
    else :
      print("A")
      exit()
  elif temp == "b" :
    if len(B) != 0 :
      temp = B[0]
      B = B[1:]
    else :
      print("B")
      exit()
  else :
    if len(C) != 0 :
      temp = C[0]
      C = C[1:]
    else :
      print("C")
      exit()




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

int main() {
	int N,M;
  	cin >> N >> M;
  	int A[M];
  	int sum=0;
  	for(int i=0;i<M;i++){
     	cin>>A[i]; 
      	sum+=A[i];
    }
  	
  	if(N<sum){
     	cout<<-1<<endl; 
    }
  	else{
     	cout<<N-sum<<endl; 
    }
  	
  	
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define INT long long int
using namespace std;
INT n, a[10];

INT solve(INT x, INT y)
{
    if( x == n ) return y%2==0?1:0;
    return solve(x+1, y*(a[x]-1)) + solve(x+1, y*a[x]) + solve(x+1, y*(a[x]+1));
}

int main()
{
    ios::sync_with_stdio(false);
    cin>>n;
    for(int i = 0 ; i < n ; i++ ) cin>>a[i];
    cout<<solve(0, 1)<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>

#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef vector<int> vec;
typedef vector<vector<int>> mat;
using P = pair<ll, ll>;

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

const ll mod = 1000000007;
const int INF = 1<<29;

class Radix {
private:
  const char* s;
  int a[128];
public:
  Radix(const char* s = "0123456789ABCDEF") : s(s) {
    int i;
    for(i = 0; s[i]; ++i)
      a[(int)s[i]] = i;
  }
  std::string to(long long p, int q) {
    int i;
    if(!p)
      return "0";
    char t[64] = { };
    for(i = 62; p; --i) {
      t[i] = s[p % q];
      p /= q;
    }
    return std::string(t + i + 1);
  }
  std::string to(const std::string& t, int p, int q) {
    return to(to(t, p), q);
  }
  long long to(const std::string& t, int p) {
    int i;
    long long sm = a[(int)t[0]];
    for(i = 1; i < (int)t.length(); ++i)
      sm = sm * p + a[(int)t[i]];
    return sm;
  }
};

int main(){
  int N, K; cin >> N >> K;
  Radix r;
  string res = r.to(N, K);
  cout << res.size() << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(){
  int a,b;
  scanf("%d %d",&a,&b);
  if(b<0){//引き算か掛け算
    if(a-b<a*b){
    printf("%d",a*b);
      return 0;
    }
    else{
      printf("%d",a-b);
      return 0;
    }
  }
  else{
    if(a+b<a*b){
     printf("%d",a*b);
      return 0;
    }
  else{
    printf("%d",a+b);
      return 0;
  }
  }
  return 0;
}
    
    


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

#define INF 1LL << 61
#define MAX (1LL << 31) -1
#define MOD 1000000007

typedef long long ll;
typedef pair<int,int> pi;
//typedef pair<pair<int,int>,ll> p;
#define bit(n, k) ((n >> k) & 1) /*nのk bit目*/
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)
template<class T,class U>bool inline chmin(T&a,const U&b){if(a<=b)return false;a=b;return true;}
template<class T,class U>bool inline chmax(T&a,const U&b){if(a>=b)return false;a=b;return true;}
//__builtin_popcount(S);
//C.erase(unique(C.begin(),C.end()),C.end());
//#define int ll
int dx[]={1,-1,0,0},dy[]={0,0,-1,1};

int pena[55][11];
pi kekka[51];

signed main(){
    while(true){
        int M,T,P,R;
        cin>>M>>T>>P>>R;
        if(M==0 && T==0 && P==0 && R==0) return 0;
        vector<vector<int>> pena(T+1,vector<int>(P+1,0));
        vector<pi> kekka(T+1,pi(0,0));
        while(R--){
            int m,t,p,j;
            cin>>m>>t>>p>>j;
            if(j==0){
                kekka[t].first++;
                kekka[t].second+=m+pena[t][p]*20;
            }else{
                pena[t][p]++;
            }
        }
        vector< tuple<int,int,int> > ans;
        for(int i=1;i<=T;i++){
            ans.emplace_back(-kekka[i].first,kekka[i].second,-i);
        }
        sort(ans.begin(),ans.end());
        for(int i=0;i<T;i++){
            cout<<-get<2>(ans[i]);
            if(i!=T-1){
                if(get<0>(ans[i])==get<0>(ans[i+1]) && get<1>(ans[i])==get<1>(ans[i+1]) ){
                    cout<<"=";
                }else cout<<",";
            }
        }
        cout<<endl;
    }
}


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

ll n,K;
ll a[300000];


ll C(ll t){
	ll cnt=0;
	rep(i,n){
		if(a[i]<0){
			if(t<0){
				int it=lower_bound(a,a+n,(-t-a[i]-1)/(-a[i]))-a;
				cnt+=n-it;
			}
			else if(t==0){
				int it=lower_bound(a,a+n,0)-a;
				cnt+=n-it;
			}
			else if(t>0){
				int it=lower_bound(a,a+n,-(t/(-a[i])))-a;
				cnt+=n-it;
			}
		}
		else if(a[i]==0){
			if(t<0){
				
			}
			else if(t==0){
				cnt+=n;
			}
			else if(t>0){
				cnt+=n;
			}
		}
		else if(a[i]>0){
			if(t<0){
				int it=upper_bound(a,a+n,-((-t+a[i]-1)/a[i]))-a;
				cnt+=it;
			}
			else if(t==0){
				int it=upper_bound(a,a+n,0)-a;
				cnt+=it;
			}
			else if(t>0){
				int it=upper_bound(a,a+n,t/a[i])-a;
				cnt+=it;
			}
		}
		if(a[i]*a[i]<=t)cnt--;
	}
	return cnt/2;
}

int main(){
	cin>>n>>K;
	rep(i,n)scanf("%lld",&a[i]);
	sort(a,a+n);
	ll ok=ll(1e18),ng=ll(-1e18)-1;
	while(ok-ng>1){
		ll t=(ok+ng)/2;
		if(C(t)>=K)ok=t;
		else ng=t;
	}
	cout<<ok<<endl;
}

Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;
struct char_cont{char ch; int num;};

string S;

int main(){
	vector<char_cont> va;
	cin >> S;
	for(int i = 0; i < S.length(); i++){
		if(i == 0){
			va.push_back((char_cont){S[i], 1});
		}else{
			if(va.back().ch == S[i]){
				va.back().num++;
			}else{
				va.push_back((char_cont){S[i], 1});
			}
		}
	}
	int ans = 0;
	for(int i = 0; i < va.size() - 2; i++){
		if(i + 2 > va.size()) break;
		if(va[i].ch == 'J' && va[i + 1].ch == 'O' && va[i + 2].ch == 'I'){
			if(va[i].num < va[i + 1].num || va[i + 1].num > va[i + 2].num) continue;
			ans = max(ans, va[i + 1].num);
		}
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 12612
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e5+10;
const ll inf = 1e9+7;
ll a[maxn];
int main() {
    ios::sync_with_stdio(0);
    int n;
    cin>>n;
    map<ll,ll>p;
    ll ans =0;
    for(int i=1;i<=n;i++)
        cin>>a[i],p[i-a[i]]++;
    for(int i=1;i<=n;i++){
        int q = i+a[i];
        p[i-a[i]]--;
        ans+=p[q];
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 27884
//競技プログラミング用のテンプレート
#include <iomanip>
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <math.h>
#include <stack>
#include <limits>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define repr(i, n) for(int i = n - 1; i >= 0; i--)

using namespace std;
//エイリアス
using ll = long long int;
using p = pair<int, int>;
using pl = pair<ll, ll>;
using v = vector<int>;
using vd = vector<double>;
using vs = vector<string>;
using vl = vector<ll>;

//定数
const int intmax = numeric_limits<int>::max();
const ll llmax = numeric_limits<ll>::max();
const ll mod = 1e9 + 7;
const double pi = M_PI;

int main()
{
  int a, b, h, m;
  cin >> a >> b >> h >> m;
  double aarg = 30 * h + 0.5 * m;
  double barg = 6 * m;
  double x = aarg - barg;
  double arg = (double)  (x) * pi / 180.0;
  double result = sqrt(a * a + b * b - 2 * a * b * cos(arg));
  cout << fixed;
  cout << setprecision(9) << result << endl;
}


Measured memory_bytes: 4224
def gcd(a,b):
    if b==0:
        return a
    return gcd(b,a%b)

a,b=map(int,input().split())
g=gcd(a,b)
m=g
c=1
i=2
while i*i<=g:
    if m%i==0:
        c+=1
    while m%i==0:
        m=m//i
    i+=1
if m>1:
    c+=1
print(c)

Measured memory_bytes: 3060
#include <cstdio>
#include <algorithm>


int main() {
    long long n, l;
    std::scanf("%lld %lld", &n, &l);

    long long ort = (l + l + n - 1) * n / 2;
    long long dlt = l > 0 ? l
                          : std::min(l + n - 1, 0LL);

    std::printf("%lld", ort - dlt);
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
long long int mod = (long long int)1000000007;
using namespace std;

void solve()
{
    ll i,j,k,n;
    std::cout.precision(10);
    int yes=0;
    ll a,b;
    cin>>a>>b;
    for(i=1;i<=1000000;i++)
    {
        if(int(i*(0.08))==a && int(i*(0.1))==b)
        {
            cout<<i;
            return;
        }
    }
    cout<<"-1";
}

int main()
{
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
    int i,j,k;
    int t;
    std::cout.precision(10);
    t=1;
    while(t--)
    {
        solve();
        cout<<"\n";
    }
}

Measured memory_bytes: 3652
N = int(input())
pairs = []
min_F = 100000
for i in range(1, int(N**0.5)+1):
    if N % i == 0:
        pairs.append((i,N//i))
for v in pairs:
    if min_F > len(str(max(v))):
        min_F = len(str(max(v)))
print(min_F)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define endl '\n'
#define all(x) (x).begin(),(x).end()
const int INF=1000000000+5;
const int N=1e6+5;
const ll oo=1e18+5;
const ll mod=1e9+7;

int main(){
	ios::sync_with_stdio(0); cin.tie(0);
	int x;
	cin>>x;
	cout<<(x^1)<<endl;
	return 0;
}


Measured memory_bytes: 3588
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <map>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <utility>

#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; i++)

typedef long long ll;
using namespace std;

int main() {
    
    int n;
    cin >> n;
    REP(i, n) {
        int a;
        cin >> a;
        if (a % 2) {
            cout << "first" << endl;
            return 0;
        }
    }
    
    cout << "second" << endl;
    
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int main(){
  int n,m;
  cin>>n>>m;
  cout<<(n-1)*(m-1)<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define MOD 998244353
#define ADD(X,Y) ((X) = ((X) + (Y)%MOD) % MOD)
typedef long long i64; typedef vector<int> ivec; typedef vector<string> svec;

char S[2020];
int N;

int dp[4040][4040];

int main()
{
	scanf("%s", S);
	N = strlen(S);

	int nb = 0;
	for (int i = 0; i < N; ++i) nb += S[i] - '0';

	dp[0][0] = 1;
	int rmax = 0, bmax = 0;
	for (int i = 0; i < 2 * N; ++i) {
		if (i < N) {
			rmax += 2 - (S[i] - '0');
			bmax += (S[i] - '0');
		}
		for (int b = 0; b <= bmax; ++b) {
			if ((i - b) + 1 <= rmax) ADD(dp[i + 1][b], dp[i][b]);
			if (b + 1 <= bmax) ADD(dp[i + 1][b + 1], dp[i][b]);
		}
	}
	printf("%d\n", dp[2 * N][nb]);

	return 0;
}


Measured memory_bytes: 62208