akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define int				long long
#define FOR( i, m, n )  for( int (i) = (m); (i) < (n); (i)++ )
#define FORE( i, m, n ) FOR( i, m , n + 1 )
#define REP( i, n )     FOR( i, 0, n )
#define REPE( i, n )	FOR( i, 0, n + 1 )
#define FORR( i, m )	for( int (i) = (m); (i) >= 0; (i)-- )
#define REPONE( i, n )	FOR( i, 1, n + 1 );
#define ALL( a )        (a).begin(), (a).end()             
#define MP( a, b )		make_pair( (a), (b) )
#define fi				first
#define se				second

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

const int INF = 1e9;
const int MOD = 1e9 + 7;

int dp[101][10001] = {};

signed main() {
	string s;
	while( 1 ) {
		getline( cin, s );  if( s == "." ) break;
		stack<char> st;

		bool flag = true;
		REP( i, s.size()  ) {
			switch( s[i] ) {
				case '(':
					st.push( '(' );
					break;
				case '[':
					st.push( '[' );
					break;
				case ')':
					if( !st.empty() && st.top() == '(' ) st.pop();
					else								 flag = false;
					break;
				case ']':
					if( !st.empty() && st.top() == '[' ) st.pop();
					else								 flag = false;
					break;
				default:
					break;
			}
		}
		if( flag && st.empty() ) cout << "yes" << endl;
		else					 cout << "no" << endl;
	}
}


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

public class Program{
    public static void Main(){
        
        var n = int.Parse(Console.ReadLine());
        
        var s = Console.ReadLine();
        
        int[] cnt = new int[2];
        for(var i = 0; i < n; i++){
            if(s[i] =='.'){
                cnt[1]++;
            }
        }
        var min = cnt.Sum();
        
        //border:左側の右端の値
        for(var border = 0; border < n; border++){
            if(s[border] == '#'){
                cnt[0]++;
            }
            if(s[border] == '.'){
                cnt[1]--;
            }
            if(min > cnt.Sum()){
                min = cnt.Sum();
            }
        }
        
        Console.WriteLine("{0}",min);
    }
}


Measured memory_bytes: 17888
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author yosiiii
 */


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

class ASumOfTwoIntegers {
public:
	void solve(std::istream& in, std::ostream& out) {
        int n;
        in >> n;
        if(n%2==0){
            out << n/2-1 << endl;
        }else {
            out << n / 2 << endl;
        }
	}
};


int main() {
	ASumOfTwoIntegers solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

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

        if(S.length() <8){
            System.out.println("YES");
        }else{
            int lose =0;
            for (int i = 0; i < S.length(); i++) {
                if(S.charAt(i)=='x') lose++;
            }
            if(lose>=8){
                System.out.println("NO");
            }else{
                System.out.println("YES");
            }
        }


    }
}


Measured memory_bytes: 22100
#include <bits/stdc++.h>
typedef std::pair<int,int> P;
using namespace std;

int main(){
  int H,W,D;
  cin>>H>>W>>D;
  std::vector<P> v(H*W);
  int A;
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cin>>A;
      A--;
      v[A].first=i;
      v[A].second=j;
    }
  }
  std::vector<int> w(H*W);
  for(int i=0;i<D;i++){
    w[i]=0;
    for(int k=D;i+k<H*W;k+=D){
      w[i+k]=w[i+k-D]+abs(v[i+k].first-v[i+k-D].first)+abs(v[i+k].second-v[i+k-D].second);
    }
  }
  int Q;
  cin>>Q;
  std::vector<int> L(Q),R(Q);
  for(int i=0;i<Q;i++)cin>>L[i]>>R[i];
  for(int i=0;i<Q;i++)cout<<w[R[i]-1]-w[L[i]-1]<<endl;
}


Measured memory_bytes: 2944
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef pair<int, int> P;

class UnionFind{
public:
	vector<int> par,num;
 
	int find(int v){
		return (par[v]==v)? v: (par[v]=find(par[v]));
	}
	explicit UnionFind(int N):par(N),num(N,1){
		iota(par.begin(),par.end(),0);
	}
	void unite(int u,int v){
		u=find(u),v=find(v);
		if(u==v)return ;
		if(num[u]<num[v])swap(u,v);
		num[u] += num[v];
		par[v] = u;
	}
	bool same(int u,int v){
		return find(u) == find(v);
	}
	bool ispar(int v){
		return v=find(v);
	}
	int size(int v){
		return num[find(v)];
	}
};

int main()
{
    int n, k, l;
    cin >> n >> k >> l;
    int p[100002], q[100002], r[100001], s[100002];
    UnionFind u(n), t(n);
    for(int i = 0; i < k; i++){
        cin >> p[i] >> q[i];
        p[i]--;
        q[i]--;
        u.unite(p[i], q[i]);
    }
    for(int i = 0; i < l; i++){
        cin >> r[i] >> s[i];
        r[i]--;
        s[i]--;
        t.unite(r[i], s[i]);
    }
    map<P, int> mp;
    for(int i = 0; i < n; i++){
        mp[P(u.find(i), t.find(i))]++;
    }
    for(int i = 0; i < n; i++){
        cout << mp[P(u.find(i), t.find(i))] << endl;
    }
}


Measured memory_bytes: 16640
import sys

A = list(map(int, input().split()))

A = sorted(A)

cnt = 0
for i in range(2):
    tmp = int((A[2] - A[i]) / 2)
    A[i] += tmp * 2
    cnt += tmp

A = sorted(A)
if A[0] == A[1] and A[1] == A[2]:
    print(cnt)
    sys.exit()
elif A[0] == A[1]:
    A[0] += 1
    A[1] += 1
    cnt += 1
elif A[1] == A[2]:
    A[0] += 2
    A[1] += 1
    A[2] += 1
    cnt += 2

print(cnt)


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

const int mo=998244353;
int n,m,fac[1000010],ifac[1000010],ans;

int qpow(int a,int b)
{
	int x=a;  a=1;
	while (b)
		{
			if (b&1)  a=1LL*a*x%mo;
			x=1LL*x*x%mo,b>>=1;
		}
	return a;
}

int C(int n,int m){return 1LL*fac[n]*ifac[m]%mo*ifac[n-m]%mo;}

void work()
{
	scanf("%d %d",&n,&m),fac[0]=1;
	if (n<m)  swap(n,m);
	for (int i=1; i<=n+m; i++)  fac[i]=1LL*fac[i-1]*i%mo;
	ifac[n+m]=qpow(fac[n+m],mo-2);
	for (int i=n+m; i; i--)  ifac[i-1]=1LL*ifac[i]*i%mo;
	for (int i=1; i<=m; i++)  ans=(ans+1LL*C(2*i,i)*C(n+m-2*i,n-i))%mo;
	printf("%d",int((1LL*ans*qpow(2*C(n+m,n)%mo,mo-2)+n)%mo));
}

int main()
{
	work();
	return 0;
}


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

int main(){
    long long n, k;
    cin >> n >> k;
    long long ans = 0;
    while(true) {
        if(n/k > 0) {
            n = n / k;
            ans++;
        }
        else break;
    }
    cout << ans+1 << endl;
}

Measured memory_bytes: 3636
import sys
from bisect import bisect_left,bisect_right


def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり


N = I()
A,B,C = LI(),LI(),LI()
A.sort()
C.sort()

print(sum(bisect_left(A,b)*(N-bisect_right(C,b)) for b in B))


Measured memory_bytes: 105772
#include<stdio.h>
int main()
{
    int a,b,c,d,e,f;
    scanf("%d %d",&a,&b);
    c=a+b;
    d=a-b;
    e=a*b;
    if(c>=d && c>=e)
    {
        printf("%d\n",c);
    }
    else if(d>=c && d>=e)
    {
        printf("%d\n",d);
    }
    else if(e>=c && e>=d)
    {
        printf("%d\n",e);
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define vi vector<int>
#define ff first
#define ss second
#define file_se_input  freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define pp long long int
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define pb push_back
#define mp make_pair
#define pi 3.141592653589793238
#define eb emplace_back
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define zip(i,a,b) for(int i=a;i<b;i++)
#define rzip(i,a,b) for(int i=a;i>=b;i--)
#define ll unsigned long long int
#define test int t;cin>>t; while(t--)
#define um unordered_map
#define en '\n'
#define us unordered_set
typedef pair<int, int>     pii;
typedef pair<char, int>    pci;
typedef pair<char, char>   pcc;
typedef vector<pii>       vii;
typedef long double ld;
#define all(v) v.begin(), v.end()
#define INF (1e18+5)
#define inf (1e9+5)
#define mod 1000000007


bool check_prime(long long n)
{
	int flag = 0;
	for (long long i = 2; i * i <= n; i++)
	{
		if (n % i == 0)
		{
			flag = 1;
			break;
		}
	}
	if (n == 1)
		return false;
	else if (flag == 0 || n == 2 || n == 3)
	{
		return true;
	}
	else
	{
		return false;
	}

}

int BE(int x, int n, int m) //function to calculate x raise to power n modulo m
{
	int result = 1;
	while (n > 0)
	{
		if (n % 2 == 1)
			result = result * x % m;
		x = x * x % m;
		n = n / 2;
	}
	return result;
}

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(0);
#ifndef ONLINE_JUDGE
	if (fopen("input.txt", "r"))
	{
		freopen ("input.txt" , "r" , stdin);
		freopen ("output.txt" , "w" , stdout);
	}
#endif
	//_______________________________-code starts-_______________________________________________

	int h, w;
	cin >> h >> w;
	char a[h][w];
	zip(i, 0, h)
	{
		zip(j, 0, w)
		{
			cin >> a[i][j];
		}
	}
	map<int, int>m1, m2;

	zip(i, 0, h)
	{
		zip(j, 0, w)
		{
			if (a[i][j] == '.')
			{
				if (j == w - 1)
				{
					m1[i]++;
					break;
				}
			}
			else
			{
				break;
			}
		}
	}
	zip(i, 0, w)
	{
		zip(j, 0, h)
		{
			if (a[j][i] == '.')
			{
				if (j == h - 1)
				{
					m2[i]++;
					break;
				}
			}
			else
			{
				break;
			}
		}
	}
	zip(i, 0, h)
	{
		zip(j, 0, w)
		{
			if (m1[i] == 0 && m2[j] == 0)
			{
				cout << a[i][j];
			}
		}
		if (m1[i] == 0)
		{
			cout << en;
		}
	}


	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <vector>

int main(int argc, char** argv)
{
	//std::string cmdLine;
	//std::getline(std::cin, cmdLine);
	//std::cout << cmdLine << std::endl;

	std::string str;
	std::cin >> str;

	int count = 0;
	std::cin >> count;

	std::cin.ignore();

	for (int i = 0; i < count; ++i)
	{
		std::string cmdLine;
		std::getline(std::cin, cmdLine);

		std::istringstream stream(cmdLine);

		std::vector <std::string> param;
		std::string cmd;
		stream >> cmd;

		if (cmd == "replace")
		{
			int a, b;
			std::string p;
			stream >> a >> b >> p;

			for (int pos = 0; pos <= (b - a); ++pos)
			{
				str[a + pos] = p[pos];
			}
		}
		else if (cmd == "reverse")
		{
			int a, b;
			stream >> a >> b;

			if ((b - a) > 0)
			{
				int top = a;
				int btm = b;
				while (true)
				{
					if (a >= b)
					{
						break;
					}

					char tmp = str[a];
					str[a] = str[b];
					str[b] = tmp;

					++a;
					--b;
				}
			}
		}
		else if (cmd == "print")
		{
			int a, b;
			stream >> a >> b;

			std::cout << str.substr(a, b - a + 1) << std::endl;
		}
	}
}


Measured memory_bytes: 3212
S=gets.chomp

if S.match(/^keyence/)
  puts "YES"
elsif S.match(/keyence$/)
  puts "YES"
elsif S.match(/^k.*eyence$/)
  puts "YES"
elsif S.match(/^ke.*yence$/)
  puts "YES"
elsif S.match(/^key.*ence$/)
  puts "YES"
elsif S.match(/^keye.*nce$/)
  puts "YES"
elsif S.match(/^keyen.*ce$/)
  puts "YES"
elsif S.match(/^keyenc.*e$/)
  puts "YES"
else
  puts "NO"
end


Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int result = 0;
int n,m,q;
vector<int> a(50),b(50),c(50),d(50),A(10);

void dfs(int part, int ball){
    //終了判定
    if(part == n){
        //point test
        int temp=0;
        rep(i,q)if(A.at(b.at(i))-A.at(a.at(i)) == c.at(i)) temp+= d.at(i);
        if(temp > result)result = temp;
    }

    //分岐
    //ボールを増やす
    if(ball < m-1){
        dfs(part,ball+1);
    }
    //仕切りを増やす
    if(part < n){
        A.at(part)=ball+1;
        dfs(part+1,ball);
    }

}

int main() {
    cin >> n >> m >> q;
    rep(i,q){
        cin >> a.at(i) >> b.at(i) >> c.at(i) >> d.at(i);
        a.at(i)--;
        b.at(i)--;
    }
    dfs(0,0);
    cout << result << endl;
}

Measured memory_bytes: 3632
n = int(input())
X_list = [int(x) for x in input().split()]

min_cost = 1e10
for i in range(1, 101):
    cost = 0
    for x in X_list:
        cost += (x - i)**2
    if cost <= min_cost:
        min_cost = cost
print(min_cost)


Measured memory_bytes: 2940
#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars};
use proconio::{fastout, input};
#[fastout]
fn main() {
    input! {
        n: usize,
        s: Chars,
    }
    let mut ans = 0;
    for i in 0..n {
        let mut a = std::collections::HashSet::new();
        for j in 0..i {
            a.insert(s[j]);
        }
        let mut b = std::collections::HashSet::new();
        for j in i..n {
            b.insert(s[j]);
        }
        let c = a.iter().filter(|&x| b.contains(x)).count();
        ans = std::cmp::max(ans, c);
    }
    println!("{}", ans);
}


Measured memory_bytes: 2212
/*
START BY THE NAME OF ALMIGHTY ALLAH
THIS WONT BE ACCEPTED
STOP_GIVING_UP
*/
#include<bits/stdc++.h>
#define l(i,a,n)for(int i=a;i<n;i++)
#define PB push_back
#define IN insert
#define MP make_pair
#define LW(v) sort(v.begin(),v.end());
#define HI(v) sort(v.begin(),v.end(),greater<long long>());
using namespace std;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    long long t,r=1,r1=0,r2=0,k=0,a,b,c=1,m,d=0,n,e,f,x=0,g,p=0,q=0,y=0,z=0;
    vector<long long>v;
    vector<long long>u;
    set<long long>s;
    std::vector<int>::iterator it;
    string  s1,s2,s3,s4;
    cin>>n>>m;
//cin>>s1;
l(i,0,m)
{
    cin>>k;
    l(j,0,k)
    {
        cin>>a;
        s.IN(a);
    }
}
cout<<n-s.size()<<endl;




}


Measured memory_bytes: 3656
def solve(x,y):
    lx=len(x)
    ly=len(y)
    dp=[0]*(ly+1)
    for i in range(lx):
        bef=dp[:]
        for j in range(ly): 
            #print(str(i)+" "+str(j))
            if x[i]==y[j]:
                dp[j+1]=bef[j]+1
            elif dp[j+1]<dp[j]:
                dp[j+1]=dp[j]
    print(dp[ly])
q=int(input())
for i in range(q):
    x=list(input())
    y=list(input())
    solve(x,y)


Measured memory_bytes: 5640
#include <iostream>
using namespace std;
 
    
    
int main(){
    int m,n;
    cin>>m>>n;
    if (m==1)
    {
        m=0;
    }
    else
    {
        m=m*(m-1)/2;
    }
    
     if (n==1)
    {
        n=0;
    }
    else
    {
        n=n*(n-1)/2;
    }
    cout<<m+n<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <string.h>
#include <iostream>
#include <stdio.h>
#include <string>

using namespace std;

typedef long long ll;
typedef double db;
int n;
const int N = 1e5 + 10;
ll a[N];

int main() {
	cin >> n;
	bool f = false;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (a[i] == 0) {
			f = true;
		}
	}

	if (f) {
		cout << "0" << endl;
		return 0;
	}

	ll x = 1;
	for (int i = 0; i < n; i++) {
		if ((1e18 + 1e-9) * 1.0 / x < a[i]) {
			cout << "-1" << endl;
			return 0;
		}
		x *= a[i];
		if (x > (ll)1e18) {
			cout << "-1" << endl;
			return 0;
		}
	}

	cout << x << endl;

	return 0;
}

Measured memory_bytes: 4344
from decimal import*
from fractions import*
import math
import functools


import sys
sys.setrecursionlimit(10 ** 7)
read = sys.stdin.buffer.read 
#input = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines 

s=input()
n=len(s)
s="x"*n
print(s)

Measured memory_bytes: 5460
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100100;
vector<int> e[maxn];
int vis[maxn], par[maxn], nxt[2][maxn];
int dfs(int rt, int pk){
	vis[rt] = 1;
	for(int i = 0; i < pk; i++){
		for(int go : e[rt]){
			if(!vis[go]){
				nxt[i][rt] = go;
				dfs(go, 1);
				break;	
			}
		}
	}
	return 0;
}
int main(){
	int n, m; cin >> n >> m;
	for(int i = 0; i < m; i++){
		int x, y; cin >> x >> y;
		e[x].push_back(y);
		e[y].push_back(x);
	}
	memset(nxt, -1, sizeof(nxt));
	int tk = -1, nd = 1;
	for(int i = 1; i <= n; i++) if(e[i].size() == 1) tk = i;
	if(tk == -1) tk = 1, nd = 2;
	dfs(tk, nd);
	vector<int> a, b;
	if(nd == 1){
		int ck = tk;
		a.push_back(tk);
		while(nxt[0][ck] != -1) a.push_back(nxt[0][ck]), ck = nxt[0][ck];
	} else {
		int ck = tk;
		while(nxt[0][ck] != -1) a.push_back(nxt[0][ck]), ck = nxt[0][ck];
		reverse(a.begin(), a.end());
		a.push_back(tk);
		ck = tk;
		swap(nxt[1][ck], nxt[0][ck]);
		while(nxt[0][ck] != -1) a.push_back(nxt[0][ck]), ck = nxt[0][ck];
	}
	cout << a.size() << endl;
	for(int v : a) cout << v << " "; cout << endl;
	return 0;
}



Measured memory_bytes: 11128
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long a = Long.parseLong(sc.next());
		String t = sc.next();
		long b = Long.parseLong(sc.next());
		//int c = Integer.parseInt(sc.next());
		//int n = Integer.parseInt(sc.next());
		//long res=n;
		//int l = Integer.parseInt(sc.next());
		//int sum=0;
		//String s = sc.next();
		//String t = sc.next();
		//String b = sc.next();
		//int a = Integer.parseInt(sc.next());
		//String t = sc.next();

		if(t.equals("+")) {//a、e、i、o、u
			System.out.println(a+b);
		}else {
			System.out.println(a-b);
		}
		//System.out.println("A"+t.substring(0,1)+"C");
	}
}




Measured memory_bytes: 24020
#include <stdio.h>
int main(){
	long long n,a,b,c,d,B;
	scanf("%lld%lld%lld",&n,&a,&b);
	c=n%(a+b);
	d=n/(a+b);
	if (0<c&&c<=a)
	{
		B=d*a+c;
	}
	if (a<c&&c<(a+b))
	{
		B=d*a+a;
	}
	if (c==0)
	{
		B=d*a;
	}
	printf("%lld",B);
	return 0;
}

Measured memory_bytes: 128
n,k,q = map(int,input().split())
l = [0 for i in range(n)]
#print(l)
for i in range(q):
 a = int(input())-1
 l[a] += 1

#print(l)

for i in range(n):
 if k-(q-l[i]) > 0:
  print("Yes")
 else:
  print("No")






Measured memory_bytes: 4732
# https://atcoder.jp/contests/dp/tasks/dp_c

N = int(input())
a, b, c = [0]*N, [0]*N, [0]*N
for i in range(N):
    a[i], b[i], c[i] = [int(x) for x in input().split()]

dp = []
for i in range(N):
    dp.append([- float('inf')] * 3)

dp[0] = [a[0], b[0], c[0]]

for i in range(1, N):
    dp[i][0] = max(dp[i - 1][1] + a[i], dp[i - 1][2] + a[i])
    dp[i][1] = max(dp[i - 1][0] + b[i], dp[i - 1][2] + b[i])
    dp[i][2] = max(dp[i - 1][0] + c[i], dp[i - 1][1] + c[i])

print(max(dp[N - 1]))

Measured memory_bytes: 34580
#include<bits/stdc++.h>
#define mod 1000000007
using namespace std;
int main(){
    string n;
    int d;
    cin >> n;
    cin >> d;
    long long int ans[n.size()+1][d];
    memset(ans, 0, sizeof(ans));
    for(int i=0;i<10; i++){
        ans[1][i%d]++;
    }
    for(int i=2; i<=n.size(); i++){
        for(int j=0; j<d; j++){
            for(int k=0; k<10; k++){
                ans[i][(j+k)%d] = (ans[i][(j+k)%d] + ans[i-1][j%d])%mod;
            }
        }
    }
    long long int res = 0, x = 0, index = 0;
    long long int counter = 0;
    for(int i=n.size(); i>1; i--,index++){
        for(int j=0; j<n[index]-'0'; j++){
            counter = (counter + ans[i-1][(d-(res + j)%d)%d])%mod;
        }
        res = (res + n[index] -'0')%d;
    }
    for(int i=0;i<=n[index]-'0'; i++){
        if((res+i)%d == 0)
            counter = (counter+1)%mod;
    }
    cout << ((counter - 1)%mod+mod)%mod;
}


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

int main(){
    string s;
    cin >> s;
    stack<char> st;
    int cnt = 0;
    for (int i = 0; i < s.size(); i++)
    {
        if(!st.empty() && st.top()!=s[i])
        {
            st.pop();
            cnt += 2;
        }
        else
        {
            st.push(s[i]);
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 512
from itertools import product

n = int(input())

a = []
xy = []

for _ in range(n):
    a_tmp = int(input())
    a.append(a_tmp)
    xy_tmp = []
    for _ in range(a_tmp):
        xy_tmp.append(list(map(int, input().split())))
    xy.append(xy_tmp)

ans = 0
for pat in product([1, 0], repeat=n):
    sat = True
    for i, bl in enumerate(pat):
        if bl:
            for x, y in xy[i]:
                x -= 1
                if pat[x] != y:
                    sat = False

    if sat:
        cnt = sum(pat)
        ans = max(ans, cnt)

print(ans)


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

int main(void)
{
    int r,g,b;
    cin >> r >> g >> b;
    if((g * 10 + b) % 4 == 0){cout << "YES" << endl;}
    else{cout << "NO" << endl;}
    return 0;
}

Measured memory_bytes: 256
# coding: utf-8
# Your code here!

N,K = map(int,input().split())
str = input()
str_list = list(str)

if str_list[K-1] == 'A':
    str_list[K-1] = 'a'
elif str_list[K-1] == 'B':
    str_list[K-1] = 'b'
if str_list[K-1] == 'C':
    str_list[K-1] = 'c'

str_changed = "".join(str_list)
print(str_changed)

Measured memory_bytes: 3060
#include <iostream>

using namespace std;
using ll = long long;

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

int main() {
  int x, a;
  cin >> x >> a;

  cout << ((x < a) ? 0 : 10) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int ans[1000000];

int main()
{
	int n;
	int i,j;
	int an;
	while(scanf("%d",&n) != EOF){
		for(i = 0; i <= n; i++){
			ans[i] = 1;
		}
		for(i = 2; i <= 1000 && i <= n; i++){
			if(ans[i]){
				for(j = 2; i * j <= n; j++){
					ans[i * j] = 0;
				}
			}
		}
		an = 0;
		for(i = 2; i <= n; i++){
			if(ans[i]){
				an++;
			}
		}
		printf("%d\n",an);
	}
	return 0;
}

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

int main(void) {
	const string W[7] = { "SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT" };
	string S;
	cin >> S;

	int id;
	for (id = 0; id < 7; ++id) {
		if (W[id] == S)
			break;
	}

	int ans = 7 - id;
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 256
var
	N,i:Longint;
	p,A,T:int64;
begin
	read(N,p);
	T:=1000;
	for i:=2 to N do begin
		read(A);
		if p<A then begin
			T:=T mod p+T div p*A;
		end;
		p:=A;
	end;
	writeln(T);
end.

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

int main() {
  ll n;
  string s;
  cin >> n >> s;
  map<char,ll> cnt;
  for(ll i=0;i<n;i++) {
    cnt[s[i]]++;
  }
  ll ans=1;
  ll tmp=0;
  for(auto p:cnt) {
    ans*=p.second;
    tmp++;
  }
  if(tmp!=3) {
    cout << 0 << endl;
    return 0;
  }
  for(ll i=1;i<n;i++) {
    for(ll j=0;j+2*i<n;j++) {
      if(s[j]!=s[j+i]&&s[j]!=s[j+i*2]&&s[j+i]!=s[j+2*i]) ans--;
    }
  }
  cout << ans << endl;
}

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

long long mod(long long val, long long m) {
  long long res = val % m;
  if (res < 0) res += m;
  return res;
}

bool is_prime(long long N) {
    if (N == 1) return false;
    for (long long i = 2; i * i <= N; ++i) {
        if (N % i == 0) return false;
    }
    return true;
}

vector<pair<long long, long long> > prime_factorize(long long N) {
    vector<pair<long long, long long> > res;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0;
        while (N % a == 0) {
            ++ex;
            N /= a;
        }
        res.push_back({a, ex});
    }
    if (N != 1) res.push_back({N, 1});
    return res;
}

int main() {
  string S,ans="Yes";
  cin >> S;
  rep(i,S.length()){
    if(i%2!=0 && S[i]=='R') ans = "No";
    if(i%2==0 && S[i]=='L') ans = "No";
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>

using namespace std;
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(),(x).end()
// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return;std::cout << e << std::endl;}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class X> void DEBUG(X d, T e){if(DEBUG_OUT == false)return;std::cout <<d<<" ";DEBUG(e);};
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
template< typename T > using matrix = vector< vector< T > >;

//FUNCTION  


void solve(void)
{
  int N;
  cin>>N;
  vector<vector<pair<int,int> > > DATA(N);
  for (int i = 0; i < N; i++)
  {
    int A;
    cin>>A;
    for (int j = 0; j < A; j++)
    {
      pair<int,int> p;
      cin>>p.first>>p.second;
      p.first--;
      DATA[i].push_back(p);
    }
  }
  int ANS = 0;

  for (int b = 0; b < 1<<N; b++)
  {
    bool check = 1;
    vector<int> v(N);
    int COUNT = 0;
    for (int i = 0; i < N; i++)
    {
      v[i] = (b>>i)&1;
      if((b>>i)&1) COUNT++;
    }
    // DEBUG(v);
    
    for (int j = 0; j < N; j++)
    {
      if((b>>j)&1)
      {
        int S = DATA[j].size();
        for (int k = 0; k < S; k++)
        {
          int X = DATA[j][k].first;
          int Y = DATA[j][k].second;
          if(v[X] != Y)check = 0;
          
        }
        
      }
    }
    if(check == 1)chmax(ANS,COUNT);
        
  }
  cout<<ANS<<endl;
  
  
  return;
}

int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();

  return 0;
}


Measured memory_bytes: 256
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

// vectorの重複削除
// std::sort(test.begin(), test.end());
// test.erase(std::unique(test.begin(), test.end()), test.end());

using namespace std;
using ll = long long;
using P = pair<int, int>; // vector<P> ba(n); みたいな感じですぐ使える ba[i] = P(a, b); make_pairをしなくてもいい
// typedef vector<int> v;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}
#define rep(i, c) for(int i = 0; i < int(c); i++)
#define ALL(x) (x).begin(), (x).end() //sort(ALL(obj))みたいな
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値
#define pb push_back //
// const int MOD = 1000000007;
// string alpha="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
// printf("%.20f\n", ans); あれ
// const double PI = 3.141592653589793238462643383;

int main() {
  rep(i,5) {
    int num; cin>>num;
    if (num == 0) {
      cout << i+1 << endl;
      return 0;
    }
  }
}


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

typedef long long ll;
const ll MOD = 1e9 + 7;
const ll inf = 1LL<<60;
const double eps = 1e-9;

typedef pair<ll, ll> P;

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 main()
{
    ll N, M;
    cin >> N >> M;
    if (N > M) swap(N, M);

    if (N == 1) {
        if (M == 1) cout << 1 << endl;
        else cout << M - 2 << endl;
    } else cout << (N-2)*(M-2) << endl;

    return 0;
}



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

//g++ -g -o yourexe yourfile.cpp
//./yourexe < yourinput.in > youroutput.out

#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

#define M 998244353ll

#define ll long long
#define ld long double
#define vi vector<ll>
#define pi pair<ll, ll>
#define vii vector<pi>
#define vvi vector<vi>
#define pb push_back
#define endl "\n"

#define REP(i, s, e) for (ll i = s; i < e; i++)
#define RREP(i, s, e) for (ll i = s; i > e; i--)

#define all(v) v.begin(), v.end()
#define part(v, s, e) v.begin() + s, v.begin() + e
#define print(v) for (auto i: v) cout << i << " ";

int main() {
    fast;
    ll n, x;
    cin >> n >> x;
    vi arr(n+1);
    REP(i, 1, n+1)
        cin >> arr[i];
    ll c = 1, m = 0;
    REP(i, 1, n+1) {
        m += arr[i];
        if (m > x)
            break;
        c++;
    }
    cout << c << endl;
    return 0;
}


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

int main(void){
    int a, b;
    cin >> a >> b;
    
    int dif = b - a;
    int i, sum = 0;
    for(i = 1; i < dif; i++){
        sum += i;
    }
    
    cout << sum - a << endl;
    
    return 0;
}


Measured memory_bytes: 256
/*input
1 100000
1
*/

#include <functional>
#include <algorithm>
#include <iostream>
#include <string.h>
#include <utility> 
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <map>
#include <set>

using namespace std;

using ll = long long;
using ld = long double;

const int SINF = 1000000009;
const ll INF =  1000000000000000018;

#define sp          cout << " "
#define nl          cout << "\n"
#define all(c)      (c).begin(),(c).end()
#define prec(n)     cout << fixed << setprecision(n)
#define PI          3.14159265358979323846264338327951
#define ifalse      ios_base::sync_with_stdio(false), cin.tie(NULL)

template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << p.first << " " << p.second;
  return os;
}

template <typename T, typename U>
istream &operator>>(istream &is, pair<T, U> &p) {
  is >> p.first >> p.second;
  return is;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  for(auto x: v) {
  	os << x << " ";
  }
  return os;
}

template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
  for (auto &x : v) is >> x;
  return is;
}

/******************************** START *********************************/
const int N = 100005;

int main()
{
  ifalse;
  int n, k;
  cin >> n >> k;
  vector < int > v(n);
  for(auto &x: v) {
  	cin >> x;
  }

  bool dp[k + 1] = {0};

  for(int i = 0; i <= k; i ++) {
  	for(auto x: v) {
  		if(i >= x and !dp[i - x]) {
  			dp[i] = true;
  			break;
  		}
  	}
  }

  if(dp[k]) {
  	cout << "First";
  } else {
  	cout << "Second";
  }
  return 0;
}

Measured memory_bytes: 384
import sys
import math
ns = lambda: sys.stdin.readline().rstrip()
ni = lambda: int(ns())
nm = lambda: map(int, sys.stdin.readline().split())
nl = lambda: list(nm())
nsl = lambda: map(str, sys.stdin.readline().split())

n = ni()
m = math.ceil(math.sqrt(n))
for i in range(m, -1, -1):
    if n % i == 0:
        print(max(len(str(i)), len(str(n // i))))
        exit()


Measured memory_bytes: 3060
#include <bitset>
#include <iostream>
using namespace std;
using lint = long long;
const int MOD = 1000000007;

int getCountOfPair(bitset<64> l, bitset<64> r) {
    bool flag = false, diff = false, both = false;
    int i = 63;
    lint count[3] = {l != r, 0, 1};
    do {
        flag |= l[i];
        diff |= l[i] != r[i];
    } while (!r[i--]);
    for (; i >= 0; i--) {
        count[1] =
            (count[1] * 3 + (count[0] * !l[i] + count[2] * r[i]) * diff) % MOD;
        count[0] =
            ((count[0] << (!l[i] * flag * diff)) + both * !l[i] * r[i]) % MOD;
        count[2] = ((count[2] << (r[i] * diff)) + both * !l[i] * r[i]) % MOD;
        flag |= l[i];
        bool check = diff;
        diff |= l[i] != r[i];
        check ^= diff;
        both = (both * (!l[i] | r[i])) | check;
    }
    return int((count[0] + count[1] + count[2] + both) % MOD);
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int answer;
    lint l, r;
    cin >> l >> r;
    answer = getCountOfPair(l, r);
    cout << answer;
    return 0;
}

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

using ll = int64_t;
#define int ll

#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, b) FOR(i, 0, b)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(), x.end()

using pi = pair<int, int>;
using vi = vector<int>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  REP(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

ll read() {
  ll i;
  scanf("%" SCNd64, &i);
  return i;
}

void printSpace() { printf(" "); }

void printEoln() { printf("\n"); }

void print(ll x, int suc = 1) {
  printf("%" PRId64, x);
  if (suc == 1)
    printEoln();
  if (suc == 2)
    printSpace();
}

string readString() {
  static char buf[3341000];
  scanf("%s", buf);
  return string(buf);
}

char *readCharArray() {
  static char buf[3341000];
  static int bufUsed = 0;
  char *ret = buf + bufUsed;
  scanf("%s", ret);
  bufUsed += strlen(ret) + 1;
  return ret;
}

template <class T, class U> void chmax(T &a, U b) {
  if (a < b)
    a = b;
}

template <class T, class U> void chmin(T &a, U b) {
  if (b < a)
    a = b;
}

template <class T> T Sq(const T &t) { return t * t; }

const int mod = 1e9 + 7;
int value[4];

int calc(int ope) {
  auto _calc = [](int a, int b, int ope) {
    if (ope)
      return a + b;
    else
      return a - b;
  };
  int ret = 0;
  ret = _calc(value[0], value[1], ope & 1);
  ret = _calc(ret, value[2], ope & 10);
  ret = _calc(ret, value[3], ope & 100);
  return ret;
}

signed main() {
  int n = read(), i = 3;
  while (n != 0) {
    value[i--] = n % 10;
    n /= 10;
  }
  for (int i = 0; i < 1 << 3; i++) {
    if (calc(i) == 7) {
      std::cout << value[0];
      std::cout << ((i & 1) ? "+" : "-");
      std::cout << value[1];
      std::cout << ((i & 10) ? "+" : "-");
      std::cout << value[2];
      std::cout << ((i & 100) ? "+" : "-");
      std::cout << value[3];
      std::cout << "=7" << std::endl;
      break;
    }
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
string s,t;
void check()
{
    int pos=-1,i,j,num=0;
    for(i=s.size()-1;i>=t.size()-1;--i)
    {
        for(j=t.size()-1;j>=0;--j)
        {
            if(s[i-num]!=t[j]&&s[i-num]!='?')
            {
                break;
            }
            ++num;
        }
        if(j<0)
        {
            pos=i-t.size()+1;
            break;
        }
        num=0;
    }
    if(pos==-1)
    {
        cout<<"UNRESTORABLE"<<endl;
    }
    else
    {
        s.replace(pos,t.size(),t);
        for(i=0;i<s.size();++i)
        {
            if(s[i]=='?'){s[i]='a';}
        }
        cout<<s<<endl;
    }
}
int main()
{
    while(cin>>s>>t)
    {
        int i;
        if(s.find(t)!=string::npos)
        {
            for(i=0;i<s.size();++i)
            {
                if(s[i]=='?'){s[i]='a';}
            }
            cout<<s<<endl;
        }
        else{check();}
    }
    return 0;
}


Measured memory_bytes: 256
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
  input = input.split("\n");
  
  //スペース区切り　input[0] が tmp[0], tmp[1],...
	tmp = input[0].split(" ");
  
  //この時点では全部文字列（数値に変換しないといけない）

	//文字列から10進数に変換するときはparseIntを使います
    var charactores =  ['a','b','c','d','e','f','g', 'h','i', 'j','k', 'l', 'm','n', 'o', 'p', 'q','r','s','t', 'u','v', 'w','x','y','z'];
	var a = tmp[0];
    index = charactores.indexOf(a);
    var s = charactores[parseInt(index)+1]
  console.log('%s', s);
  //%は符号付き10進数, %sは文字列
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
import java.util.*;

public class Main
{
    Main(){
	Scanner sc = new Scanner(System.in);
	int n;
	Stack<Integer> stack = new Stack<Integer>();

	while(sc.hasNext()){
	    n = sc.nextInt();

	    if(n == 0){
		if(!stack.empty()) System.out.println(stack.pop().toString());
	    } else {
		stack.push(new Integer(n));
	    }
	}
    }

    public static void main(String[] args){
	new Main();
    }
}

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

int main() {
    int64_t X;
    std::cin >> X;

    int64_t m = 100;
    for (int64_t i = 0; i < 100000000000; ++i) {
        if (m >= X) {
            std::cout << i << std::endl;
            return 0;
        }

        m = (int64_t)(m * 1.01);
    }

    return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"

struct BinomialCoefficient  {
    BinomialCoefficient() {}
    BinomialCoefficient(int n) : fac(n + 2), finv(n + 2), inv(n + 2) {
        initialize(n, false);
    }
    
    void initialize(int n, bool resize = true) {
        if (resize) {
            fac.resize(n + 2);
            finv.resize(n + 2);
            inv.resize(n + 2);
        }
        fac[0] = fac[1] = 1;
        finv[0] = finv[1] = 1;
        inv[1] = 1;
        for (int i = 2; i <= n; i++) {
            fac[i] = fac[i - 1] * i % mod;
            inv[i] = mod - inv[mod % i] * (mod / i) % mod;
            finv[i] = finv[i - 1] * inv[i] % mod;
        }
    }
    
    ll factorial(int n) {
        return fac[n];
    }
    
    ll combination(int n, int r) {
        if ((n < r) || (n < 0) || (r < 0)) return 0;
        return fac[n] * (finv[r] * finv[n - r] % mod) % mod;
    }
    
    ll permutation(int n, int r) {
        if ((n < r) || (n < 0) || (r < 0)) return 0;
        return fac[n] * finv[n - r] % mod;
    }
    
private:
    int mod = 1e9 + 7;
    vector<ll> fac, finv, inv;
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    const ll mod = 1e9 + 7;
    ll n, k;
    cin >> n >> k;
    BinomialCoefficient bc(n);
    reps(i, 1, k + 1) {
        ll a = bc.combination(n - k + 1, i);
        ll b = bc.combination(k - 1, i - 1);
        cout << (a * b % mod) << endl;
    }
    return 0;
}


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

long N;

int main(){
    cin>>N;

    long k=1;
    long i,j;
    long ans=100100100100100100;
    while(k<=1000000){
        if(N%k==0){
            i=k;
            j=N/k;
            if(i+j<ans){
                ans=i+j;
            }
        }
        k++;
    }

    ans-=2;

    cout<<ans<<endl;
}

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


using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define fore(i,a) for(auto &i:a)

typedef pair <int, int> P;
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
const int  INF = 1 << 30;
const ll INFL = 1LL<<60;
const ll mod = 1000000007;		





int main() {
	int n;
	cin >> n;
	VLL a(n);
	REP(i, n)cin >> a[i];
	
	ll ans = 0;


	while (true) {
		ll res = 0;
		VLL b(n);
		REP(i, n) {
			res += a[i] / n;
			b[i] = a[i] / n;
		}
		if (res == 0)break;
		REP(i, n) {
			a[i] = a[i] - n * b[i] + (res - b[i]);
		}
		ans += res;
	}


	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <iomanip>
#include <sstream>

#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#define _USE_MATH_DEFINES
#define elif else if
typedef long long ll;
using namespace std;
const int INF = 1e8;
//const double EPS = 1e-15;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	//freopen ("auxiliary.in", "w", stdin);
	//freopen ("auxiliary.out", "r", stdout);

	//ifstream fin;
	//fin.open(".in");
	//ofstream fout(".out");

	string s;
	cin >> s;
	ll ans = 0, cur = 0;
	for (int i = s.size() - 1; i >= 0; --i) {
		if (s[i] == 'W')
			++cur;
		else
			ans += cur;
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 720
#include<bits/stdc++.h>
using namespace std;
const int INF=1001001001;
string S,T;
int dp[1001][1001];
 
int main(){
    cin>>S>>T;
    for(int i=0;i<=S.size();i++)for(int j=0;j<=T.size();j++)dp[i][j]=INF;
 
    for(int i=0;i<=T.size();i++)dp[0][i]=i;
    for(int i=0;i<=S.size();i++)dp[i][0]=i;
 
    for(int i=0;i<S.size();i++){
        for(int j=0;j<T.size();j++){
            dp[i+1][j+1]=min(dp[i][j],min(dp[i+1][j],dp[i][j+1]))+1;
 
            if(S[i]==T[j])dp[i+1][j+1]=min(dp[i+1][j+1],dp[i][j]);
 
        }
    }
 
 
    cout<<dp[S.size()][T.size()]<<endl;
    return 0;
}


Measured memory_bytes: 7072
#include<stdio.h>

int main() {

	int n, S[13], H[13], C[13], D[13],i,number;
	char a,c;

	for (i = 0; i < 13; i++) {
		S[i] = H[i] = C[i] = D[i] = 0;
	}

	scanf("%d", &n);

	for(i=0;i<n;i++){
		scanf("%c%c%d", &a,&c,&number);

		if (c == 'S')S[number - 1] = 1;
		else if (c == 'H')H[number - 1] = 1;
		else if (c == 'C')C[number - 1] = 1;
		else if (c == 'D')D[number - 1] = 1;
	}

	for (i = 0; i < 13; i++) {
		if (S[i] == 0) printf("S %d\n", i + 1);
	}
	for (i = 0; i < 13; i++) {
		if (H[i] == 0) printf("H %d\n", i + 1);
	}
	for (i = 0; i < 13; i++) {
		if (C[i] == 0) printf("C %d\n", i + 1);
	}
	for (i = 0; i < 13; i++) {
		if (D[i] == 0) printf("D %d\n", i + 1);
	}

	return 0;
}


Measured memory_bytes: 2116
import java.util.*;
import java.io.*;
import java.math.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();
		int min = Integer.MAX_VALUE;
		for(int i = n; i >= 1; i--) {
			int[] y = new int[4];
			int[] x = new int[4];
			int[][] map = new int[(n/i) + ((n % i != 0)?1:0)][i];
			int nowx = 0;
			int nowy = 0;
			for(int j = 0; j < n; j++) {
				if(j+1 == a) {
					y[0] = nowy;
					x[0] = nowx;
				}
				if(j+1 == b) {
					y[1] = nowy;
					x[1] = nowx;
				}
				if(j+1 == c) {
					y[2] = nowy;
					x[2] = nowx;
				}
				if(j+1 == d) {
					y[3] = nowy;
					x[3] = nowx;
				}
				nowx++;
				if(nowx == i) {
					nowx = 0;
					nowy = nowy+1;
				}
			}
			min = Math.min(min, Math.abs(x[0] - x[1]) + Math.abs(y[0] - y[1]) + Math.abs(x[2] - x[3]) + Math.abs(y[2] - y[3]) );
			
			
			
			
			
		}
		System.out.println(min);
		
	}
}

Measured memory_bytes: 17320
#include <bits/stdc++.h>
using namespace std;
int main(){
  int64_t N,i,j,count=0;
  cin>>N;
  for(i=1;i<N;i++){
    for(j=i;j<N;j++){
      if(N-i*j<=0){
      break;
      }else if(i==j){
        count++;
      }else{
        count+=2;
      }
    };
  }
  cout<<count<<endl;
}

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

int n,m,q;
int a[50],b[50],c[50],d[50];
int ans = 0;

void dfs(vector<int> A){
    if(A.size()==n){
        int tmp = 0;
        for(int i=0;i<q;i++){
            if(A[b[i]]-A[a[i]]==c[i])  tmp += d[i]; 
        }
        ans = max(ans,tmp);

    }else{
        int back = 1;
        if(A.size()>0) back = A.back(); 
        for(int i=back;i<=m;i++){
            A.push_back(i);
            dfs(A);
            A.pop_back();
        }
    }
}

int main(void){
    cin >> n >> m >> q;

    for(int i=0;i<q;i++) cin >> a[i] >> b[i] >> c[i] >> d[i];
    for(int i=0;i<q;i++){a[i]--; b[i]--;}
    dfs({});
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3644
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        String s = sc.next();

        System.out.println(s.substring(0, k-1) + s.substring(k-1, k).toLowerCase() + s.substring(k, n));
        sc.close();

    }

}


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

using namespace std;
typedef long long ll;

int main()
{
    string s , t ;
    cin>> s >>t;
    int x=1e9 , cnt;
    for(int i = 0 ; i < t.size() ; i++)
    {
        for(int j = 0 ; j <s.size() ; j++)
        {
            if( t[i]==s[j] && j-i >=0 && j-i+t.size()-1 < s.size())
            {
                cnt=0;
                //cout << j-i << " " << j-i+t.size() << " : ";
                for(int k = j-i ; k < j-i+t.size() ; k++ )
                {
                    if(s[k]!=t[k-j+i])
                        cnt++;
                }
                //cout << cnt << "\n";
                x=min(x , cnt);
            }
        }
    }
    if(x==1e9)
        x=t.size();
    cout << x << "\n";
    return 0;
}


Measured memory_bytes: 3628
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args){

		Scanner sc=new Scanner(System.in);

		String[] str=(sc.next()).split("");

		sc.close();

		List<String> list=new ArrayList<String>();

		int cnt=0;

		for(int i=0;i<4;i++){
			if(list.contains(str[i])){
				cnt++;
			}else{
				list.add(str[i]);
			}
		}

		if(list.size()>2){
			System.out.println("No");
		}else{
			if(cnt==2){
				System.out.println("Yes");
			}else{
				System.out.println("No");
			}
		}


	}
}


Measured memory_bytes: 23252