akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll long long

using namespace std ;

//void countFrequency( unordered_map m , int n )
//{
//    unordered_map<string , int> mp ;
//vector<string> cases{ "AC" , "WA" , "TLE" , "RE" } ;
//
//    for( ll i = 0 ; i < n ; i++ )
//    {
//        mp[ verdict[ i ] ]++ ;
//    }
//
//    for( auto x : mp )
//    {
//        cout << x.first << " x " << x.second << endl ;
//    }
//}

int main()
{
// fast input output
    ios_base::sync_with_stdio( false ) ;
    cin.tie( NULL ) ;
    cout.tie( NULL ) ;

    unordered_map<string , int> m ;

    vector<string> cases{ "AC" , "WA" , "TLE" , "RE" } ;
    for( ll i = 0 ; i < cases.size() ; i++ )
    {
        m.insert( make_pair( cases[ i ] , 0 ) ) ;
    }

    ll n ;
    cin >> n ;

    string verdict ;
    for( ll i = 0 ; i < n ; i++ )
    {
        cin >> verdict ;

        auto it = m.find( verdict ) ;

        if( it != m.end() )
        {
            m[ verdict ]++ ;
        }
    }

    for( ll i = 0 ; i < cases.size() ; i++ )
    {
        cout << cases[ i ] << " x " << m[ cases[ i ] ] << endl ;
    }
//    for( auto x : m )
//    {
//        cout << x.first << " x " << x.second << endl ;
//    }

//    countFrequency( v , n ) ;

    return 0 ;
}



Measured memory_bytes: 3660
using System;

namespace N___Slimes
{
    class Program
    {
        static long[,] costs;
        static long[,] sizes;
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var slimes = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);

            costs = new long[N, N];
            for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) costs[i, j] = -1;
            for (int i = 0; i < N; i++) costs[i, i] = 0;

            sizes = new long[N, N];
            for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) sizes[i, j] = -1;
            for (int i = 0; i < N; i++) sizes[i, i] = slimes[i];
            for (int i = 0; i < N - 1; i++) for (int j = i + 1; j < N; j++) sizes[i, j] = sizes[i, j - 1] + sizes[j, j];


            Console.WriteLine(calcCost(0, N - 1));
        }
        static long calcCost(int start, int end)
        {
            if (costs[start, end] != -1) return costs[start, end];

            var result = long.MaxValue;
            for (int i = start; i + 1 <= end; i++)
            {
                result = Math.Min(result, calcCost(start, i) + calcCost(i + 1, end) + sizes[start, i] + sizes[i + 1, end]);
            }
            return costs[start, end] = result;
        }
    }
}


Measured memory_bytes: 14944
def main():
  N = int(input())
  A = list(map(int,input().split()))
  MOD = 1000000007
  c = [0] * (N+1)
  c[0] = 3
  ans = 1
  for i in range(N):
    if not c[A[i]]:
      print(0)
      exit()
    ans *= c[A[i]]
    ans %= MOD
    c[A[i]] -= 1
    c[A[i]+1] += 1
  print(ans)
main()  
           

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

bool even(vector<int> num) {
  for(int a : num) {
    if( a % 2 != 0) {
      return false;
    }
  }
  return true;
}

void half(vector<int> &num) {
  for(int i = 0; i < num.size(); i++) {
    num.at(i) /= 2;
  }
}


int main() {
  int N;
  cin >> N;
  vector<int> A(200);
  for(int i = 0; i < N; i++){
    cin >> A.at(i);
  }
  
  int count = 0;
  while(even(A)){
    half(A);
    count++;
  }  
  
  cout << count << endl;
}

Measured memory_bytes: 256
#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define ff first
#define ss second
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define int long long
#define all(a) a.begin(), a.end()
#define inf (1LL<<61)
#define print_time cerr << "Time elapsed: " << 1000.0 * clock() / CLOCKS_PER_SEC << "ms\n";
#define ull unsigned long long
#define debug1(x) cerr << #x << ": " << x <<'\n'
#define debug2(x, y) cerr << #x << ": " << x << '\t' << #y << ": " << y <<'\n'
#define debug3(x, y, z) cerr << #x << ": " << x << '\t' << #y << ": " << y << '\t' << #z << ": " << z <<'\n'
using namespace std;
//int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction
int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
int gcd(int x,int y)
{
    if(y==0)
        return x;
    else
        return gcd(y,x%y);
}
int expo(int n,int m,int p)   //modULAR EXPONENTIATION
{
    int r=1;
    n=n%p;
    while(m>0)
    {
        if(m%2)
            r=(r*n)%p;
        n=(n*n)%p;
        m=m/2;
    }
    return r%p;
}
bool isPrime(int n)
{
    // Corner cases
    if (n <= 1)  return false;
    if (n <= 3)  return true;
 
    // This is checked so that we can skip 
    // middle five numbers in below loop
    if (n%2 == 0 || n%3 == 0) return false;
 
    for (int i=5; i*i<=n; i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
           return false;
 
    return true;
}
vector<int> z_function(string s) {
    int n = (int) s.length();
    vector<int> z(n);
    for (int i = 1, l = 0, r = 0; i < n; ++i) {
        if (i <= r)
            z[i] = min (r - i + 1, z[i - l]);
        while (i + z[i] < n && s[z[i]] == s[i + z[i]])
            ++z[i];
        if (i + z[i] - 1 > r)
            l = i, r = i + z[i] - 1;
    }
    return z;
}
int32_t main()
{
   IOS;
 /*  #ifndef ONLINE_JUDGE
   freopen("input.txt","r",stdin); 
   freopen("output.txt","w",stdout);
   #endif
   /********************* Code starts here ***********************/	
   int d,n;
   cin>>d>>n;
   int c=0;
   for(int i=1;;i++)
   {
   	int j=i,k=0;
   	while(j)
   	{
   		if(j%100!=0)
   			break;
   		j=j/100;
   		k++;
   	}
   	if(k==d)
   		c++;
   	if(c==n)
   	{
   		cout<<i<<endl;
   		return 0;
   	}
   }
} 	

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int n;
	int a[101]={0};
	int i,j,minj;
	int cut=0;
	cin>>n;
	for(i=0;i<n;i++){
		cin>>a[i];
	}
	for(i=0;i<n;i++){
		minj=i;
		for(j=i;j<n;j++){
			if(a[j]<a[minj]){
				minj=j;
			}
		}
		if(minj!=i){
			swap(a[i],a[minj]);
			cut++;
		}
	}
	for(i=0;i<n;i++){
		if(i!=0)cout<<" ";
		cout<<a[i];
	}
	cout<<endl<<cut<<endl;
	return 0;
}
	

Measured memory_bytes: 3084
import java.util.*;

// さっき提出したのはTLEになったが、おかげでひらめいた。
// 答えが必ず1000未満になるってことは、1000通り試せばいいんじゃね？
public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		String s = sc.next();

		int result = 0;
		for (int i = 000; i <= 999; i++) {

			int a = i / 100;
			int b = (i / 10) % 10;
			int c = i % 10;

			int point = 0;
			for (int j = 0; j < n; j++) {

				if (point == 0 && s.substring(j, j + 1).equals(a + "")) {
					point = 1;
				} else if (point == 1 && s.substring(j, j + 1).equals(b + "")) {
					point = 2;
				} else if (point == 2 && s.substring(j, j + 1).equals(c + "")) {
					point = 3;
				}
			}

			if (point == 3) {
				result++;
			}
		}

		System.out.println(result);

	}
}


Measured memory_bytes: 57900
// УЛЬЯНА САМАЯ ЛУЧШАЯ В МИРЕ!!!!!!!!!!!!!

#include <bits/stdc++.h>

using std::cin;
using std::cout;
using std::cerr;

using std::abs;
using std::min;
using std::max;
using std::swap;

using std::map;
using std::pair;
using std::set;
using std::string;
using std::vector;

using std::sort;
using std::reverse;

using ll = long long;

#define forn(i, n) for (ll i = 0; i < (ll) n; ++i)
#define sz(a) static_cast<int>(a.size())
#define endl '\n'

struct __init {
    __init() {
        cin.tie(nullptr);
        std::iostream::sync_with_stdio(false);
        cout << std::fixed << std::setprecision(10);
        cerr << std::fixed << std::setprecision(5);
        std::mt19937 rand(300);
    }

    ~__init() {
        #ifdef SEREZHKA
            cerr << "Time elapsed: " << static_cast<double>(clock()) / CLOCKS_PER_SEC << endl;
        #endif
    }
} init;

const ll inf = (ll) 1e9 + 7ll;
const int maxn = (int) 1e6 + 17;

int n, a, b;

bool read() {
    if (!(cin >> n >> a >> b))
        return false;

    return true;
}

int lis(vector<int> v) {
    int n = sz(v);
    vector<int> dp(n + 1, inf);
    dp[0] = -inf;

    forn (i, n) {
        int j = upper_bound(dp.begin(), dp.end(), v[i]) - dp.begin();

        if (dp[j - 1] < v[i] && v[i] < dp[j])
            dp[j] = v[i];
    }

    int res = 0;

    forn (i, n + 1)
        if (dp[i] != inf)
            res = i;

    return res;
}

int lds(vector<int> v) {
    forn (i, sz(v))
        v[i] *= -1;

    return lis(v);
}

void solve() {
    if (a > n || b > n) {
        cout << -1 << endl;
        return ;
    }

    vector<int> ans;
    int t = 1;

    for (int i = n - a + 1; i <= n; ++i) {
        ans.push_back(i);

        for (int j = min(t + b - 2, n - a); j >= t; --j)
            ans.push_back(j);

        t = min(t + b - 2, n - a) + 1;
    }

    if (sz(ans) != n || lis(ans) != a || lds(ans) != b) {
        cout << -1 << endl;
        return ;
    }

    for (auto i : ans)
        cout << i << ' ';

    cout << endl;
}

int main() {
#if SEREZHKA
    freopen("file.in", "r", stdin);
#endif

    while (read())
        solve();

    return 0;
}


Measured memory_bytes: 6108
#include <bits/stdc++.h>
#define LL long long
using namespace std;
LL N, x;

inline LL gcd(LL a, LL b)
{
	return !b ? a : gcd(b, a % b);
}

int main()
{
#ifdef hk_cnyali
	freopen("B.in", "r", stdin);
	freopen("B.out", "w", stdout);
#endif
	scanf("%lld%lld", &N, &x);
	/*
	if (N & 1ll)
	{
		if (!(N % x))
			cout<<
		else cout<<(N - 1ll) * 3ll<<endl;
		return 0;
	}
	cout<<abs(x - N / 2ll) * 3ll + N / 2ll * 3ll<<endl;
	*/
	cout<<(N - gcd(N, x)) * 3<<endl;
	return 0;
}

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

using namespace std;

typedef long long ll;

const ll mod=1e9+7;

ll fact[200010];//階乗の値を保存
ll rfact[200010];//逆元の値を保存

ll mod_pow(ll x, ll p){
        ll res=1;
        while(p){
                if(p&1){
                        res=res*x%mod;
                }
                x=x*x%mod;
                p/=2;
        }
        return res;
}

ll nCr(ll n, ll r){
        return fact[n]*rfact[r]%mod*rfact[n-r]%mod;
}

int main(){
        fact[0]=1;
        rfact[0]=1;
        for(int i=1;i<200010;i++){
                fact[i]=i*fact[i-1]%mod;
                rfact[i]=mod_pow(fact[i], mod-2);
        }
        ll H, W, A, B;
        cin>>H>>W>>A>>B;
        ll ans=0;
        //行けるところを到達した時のx座標で場合分けしている。
        for(int i=B+1;i<=W;i++){
                //1, 1→　H-A, i
                int h=H-A-1, w=i-1;
                ll tmp=nCr(h+w, h);
                //cout<<h+w<<"C"<<h<<"="<<tmp<<endl;
                //H-A+1, i→　H, W
                h=A-1, w=W-i;
                tmp*=nCr(h+w, w);
                //cout<<"tmp*"<<h+w<<"C"<<w<<"="<<tmp<<endl;
                ans+=tmp%mod;
        }
        cout<<ans%mod<<endl;

}


Measured memory_bytes: 3328
#include<iostream>
using namespace std;
const long long mod = 1000000007;
long long fact[300000], x[300000], n, r, a[300000], b[300000], c[300000], ans;
void add(long long T, long long U) { while (T <= n) { x[T] += U; T += T&-T; } }
long long sum(long long T) { long long cnt = 0; while (T >= 1) { cnt += x[T]; T -= T&-T; }return cnt; }
int main() {
	while (true) {
		fact[0] = 1; for (int i = 1; i < 300000; i++)fact[i] = fact[i - 1] * i%mod;
		for (int i = 0; i < 300000; i++) { x[i] = 0; c[i] = i; }ans = 0;
		cin >> n; if (n == 0)break; cin >> r; for (int i = 0; i < r; i++) { cin >> a[i] >> b[i]; swap(c[a[i]], c[b[i]]); }
		for (int i = 1; i <= n; i++) { add(i, 1); }
		for (int i = 1; i <= n; i++) { ans += (sum(c[i]) - 1)*fact[n - i]; ans %= mod; add(c[i], -1); }
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 10128
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int a[210001],ans,i,j,k,n,m,f[210001],g[210001],h[210001];
int sgn(int x){
	if (x>0) return 1;
	return (x==0)?0:-1;
}
int main(){
	scanf("%d",&n);
	for (i=1;i<=n;i++) scanf("%d",&a[i]);
	for (i=2,f[1]=1;i<=n;i++) f[i]=(a[i]>=a[i-1])?f[i-1]:i;
	for (i=2,f[1]=1;i<=n;i++) g[i]=(a[i]<=a[i-1])?g[i-1]:i;
	for (i=1,h[0]=0;i<=n;i++) h[i]=min(h[f[i]-1],h[g[i]-1])+1;
	printf("%d\n",h[n]);
	return 0;
}

Measured memory_bytes: 1664
using System;

class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine(FavoriteSound());
    }

    private static int FavoriteSound()
    {
        int A = 0, B = 0, C = 0;

        readData(ref A, ref B, ref C);

        int num = B / A;

        return (num > C) ? C : num;
    }

    /// <summary>
    /// データを読み込む
    /// </summary>
    private static void readData(ref int A, ref int B, ref int C)
    {
        int[] line = Array.ConvertAll<string, int>(Console.ReadLine().Split(' '), int.Parse);
        A = line[0];
        B = line[1];
        C = line[2];
    }
}




Measured memory_bytes: 11092
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<bitset>
using namespace std;
int main(){
    int n;
    while(cin>>n,n){
        int s[1000];
        for(int i=0;i<n;i++)cin>>s[i];
        bool endFlag=false;
        int c=0;
        while(!endFlag){
            endFlag=true;
            int cnt[1000]={0};
            for(int i=0;i<n;i++)cnt[s[i]]++;
            for(int i=0;i<n;i++){
                if(s[i]!=cnt[s[i]]){
                    s[i]=cnt[s[i]];
                    endFlag=false;
                }
            }
            if(!endFlag)c++;
        }
        cout<<c<<endl;
        for(int i=0;i<n;i++){
            if(i!=0)cout<<" ";
            cout<<s[i];
        }
        cout<<endl;
    }
}

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

typedef long long int ll;
#define rep(i,n) for(int i = 0; i < n; i++)
#define MOD 1000000007

int main() {
  ll k;
  cin >> k;
  ll a = 0;
  rep(i,k) {
    a = 10*a+7;
    if (a%k == 0) {
      cout << i+1 << endl;
      exit(EXIT_SUCCESS);
    }
    else a = a%k;
  }
  cout << -1 << endl;
}

Measured memory_bytes: 3624
[N, K, S] = [int(i) for i in input().split()]

ans = [str(S)]*N

if S != 10**9:
    for i in range(K, N):
        ans[i] = str(S+1)
else:
    for i in range(K, N):
        ans[i] = str(1)
    
print(' '.join(ans))

Measured memory_bytes: 12916
#include <bits/stdc++.h>
#define int long long
#define pb       push_back
#define io    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define all(a)      (a).begin(),(a).end()
#define endl        '\n'
#define F    first
#define S second
#define mod 1000000007 
#define N 105
#define pii pair<int,int>
using namespace std;
int n,val;
int dp[105][100005];
vector<int> w(N),v(N);
int fun(int i,int weight)
{
    if(i==0 || weight==0)
        return 0 ;
    
    if(dp[i][weight]!= -1)
        return dp[i][weight];
        
    if(weight<w[i-1])
        dp[i][weight]=fun(i-1,weight);
    else
        dp[i][weight]=max( fun(i-1,weight), v[i-1]+fun(i-1,weight-w[i-1]));
    
    return dp[i][weight];
    
}
void solve()
{
    cin>>n>>val;
    for(int i=0;i<=n;i++)
        for(int j=0;j<=val;j++)
            dp[i][j]=-1;
            
            
    for(int i=0;i<n;i++)
        cin>>w[i]>>v[i];
        
    cout<<fun(n,val);
}

signed main(){
    io;
    int t=1;
    //cin>>t;
    while(t--){
      solve();
    }
    return 0;
}

Measured memory_bytes: 80256
import java.io.*;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		try {
			BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
			String line = new String(in.readLine());
			String[] input1 = new String[2];//空白ごとに値をスプリット
			input1 = line.split(" ");
			line = new String(in.readLine());
			String[] input2 = new String[4];//空白ごとに値をスプリット
			input2 = line.split(" ");
			int num2 = Integer.parseInt(input2[0].trim());
			int num3 = Integer.parseInt(input2[1].trim());
			line = new String(in.readLine());
			//System.out.println(input1[0] + input1[1] + input2[0] + input2[1] + " " + line);
			if(line.equals(input1[0])) {//Sならば
				num2 = num2 - 1;
			}else {
				num3 = num3 - 1;
			}
			System.out.println(num2 + " " + num3);
			
		} catch (IOException e) {
			System.out.print(e);
		}
	}

}


Measured memory_bytes: 23252
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int (i)=(m);(i)<(n);++(i))
#define rREP(i,m,n) for(int (i)=(n)-1;(i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;
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;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

int main() {
	init();

	int N; cin >> N;
	vector<int>a(N);
	int num = 0;
	rep(i, 0, N) {
		cin >> a[i];
		if (i != N - 1)num ^= a[i];
	}
	vector<int>ans(N);
	ans[N - 1] = num;
	rREP(i, 0, N - 1) {
		int x = a[i] ^ a[i + 1];
		ans[i] = x ^ ans[i + 1];
	}
	rep(i, 0, N) {
		cout << ans[i];
		if (i != N - 1)cout << " ";
		else cout << "\n";
	}


	return 0;
}

Measured memory_bytes: 4712
#include <bits/stdc++.h>
#define MAX_V 10005
using namespace std;
typedef long long lint;
typedef pair<int,int> P;
const int INF=(int)1e9;
const int MOD=(int)1e9+7;
struct Accelerate_Cin{
    Accelerate_Cin(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);
    };
};

//Ｏ(|E|log|V|)
vector<P> G[MAX_V]; //G[v]=P(w,i):=頂点ｖとiの間の辺の重さがｗ
bool used[MAX_V];   //used[i]=:頂点iをすでに通ったかどうか

int prim(){
  int res=0;        //res=:最小全域木の辺の重さの総和
  priority_queue<P,vector<P>,greater<P> > q;
  memset(used,0,sizeof(used));

  q.push(P(0,0));
  while(!q.empty()){
    P p=q.top();q.pop();
    int d=p.first,v=p.second;    //first:辺の重さ、second:次の頂点
    if(used[v]) continue;
    used[v]=1;
    res+=d;
    for(int i=0;i<(int)G[v].size();i++){
      q.push(G[v][i]);
    }
  }
  return res;
}


int main(){
  int V,E;
  cin>>V>>E;
  for(int i=0;i<E;i++){
    int s,t,w;
    cin>>s>>t>>w;
    G[s].push_back(P(w,t));
    G[t].push_back(P(w,s));
  }

 cout<<prim()<<endl;
 return 0;
}



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

int main() {
  int N, R;
  cin >> N >> R;
  
  if (N < 10) {
    int S = 100 * (10 - N);
    
    cout << R + S << endl;
  } else {
    cout << R << endl;
  }
}

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

typedef long long s64;

inline int getint()
{
	static char c;
	while ((c = getchar()) < '0' || c > '9');

	int res = c - '0';
	while ((c = getchar()) >= '0' && c <= '9')
		res = res * 10 + c - '0';
	return res;
}

const int MaxN = 100000;
const int M = 1000000007;

inline int modpow(int a, const int &n)
{
	int res = 1;
	for (int i = n; i; i >>= 1)
	{
		if (i & 1)
			res = (s64)res * a % M;
		a = (s64)a * a % M;
	}
	return res;
}

int n;
int link[MaxN + 1];

int fact[MaxN + 1];
int rfact[MaxN + 1];

int prePow[MaxN + 1];

inline int binom(const int &n, const int &m)
{
	return (s64)fact[n] * rfact[m] % M * rfact[n - m] % M;
}

int dep[MaxN + 1];

int deg[MaxN + 1];
int ori[MaxN + 1];

int q_n, q[MaxN];

bool vis[MaxN + 1];

int cir_l, cir[MaxN + 1];

int sum[MaxN + 1];

int main()
{
	cin >> n;

	prePow[0] = 1;
	for (int i = 1; i <= n; ++i)
		prePow[i] = prePow[i - 1] * 2 % M;

	fact[0] = 1;
	for (int i = 1; i <= n; ++i)
		fact[i] = (s64)fact[i - 1] * i % M;
	rfact[n] = modpow(fact[n], M - 2);
	for (int i = n; i; --i)
		rfact[i - 1] = (s64)rfact[i] * i % M;

	for (int u = 1; u <= n; ++u)
	{
		int v = getint();
		++deg[link[u] = v];
		++ori[v];
	}

	q_n = 0;
	for (int u = 1; u <= n; ++u)
		if (!deg[u])
			q[q_n++] = u;
	for (int i = 0; i < q_n; ++i)
	{
		int u = q[i];
		dep[link[u]] = dep[u] + 1;

		if (!--deg[link[u]])
			q[q_n++] = link[u];
	}

	for (int u = 1; u <= n; ++u)
		if (ori[u] - deg[u] > 1)
		{
			cout << 0 << endl;
			return 0;
		}

	int res = 1;
	for (int u = 1; u <= n; ++u)
		if (!vis[u] && deg[u])
		{
			cir_l = 0;

			int sv = u;
			bool is_single = true;
			while (!vis[sv])
			{
				if (dep[sv] > 0)
					is_single = false;

				vis[sv] = true;
				cir[++cir_l] = sv;
				sv = link[sv];
			}

			if (is_single)
			{
				++sum[cir_l];
				continue;
			}

			for (int i = 1; i <= cir_l; ++i)
			{
				int sv = cir[i];
				if (dep[sv] > 0)
				{
					int pos = i, len = 0;
					for (int k = 1; ; ++k)
					{
						pos = pos == 1 ? cir_l : pos - 1;
						if (dep[cir[pos]] > 0)
						{
							len = k;
							break;
						}
					}

					if (len > dep[sv])
						res = res * 2 % M;
					else if (len < dep[sv])
					{
						cout << 0 << endl;
						return 0;
					}
				}
			}
		}

	for (int l = 1; l <= n; ++l)
		if (sum[l] > 0)
		{
			s64 p = 1, r = 0;
			for (int i = 0; i <= sum[l] / 2; ++i)
			{
				s64 ways = (s64)p * fact[i] % M;
				ways = (s64)ways * binom(sum[l], i * 2) % M;
				ways = (s64)ways * binom(i * 2, i) % M;
				ways = (s64)ways * modpow(prePow[i], M - 2) % M;
				if (l > 1 && (l & 1))
					ways = (s64)ways * prePow[sum[l] - i * 2] % M;

				r = (r + ways) % M;
				p = (s64)p * l % M;
			}

			res = (s64)res * r % M;
		}

	cout << res << endl;

	return 0;
}

Measured memory_bytes: 3456
n, l = map(int, input().split())
taste = (l - 1) * (n - 1)
if n + l - 1 < 0:
    taste += (1 + n - 1) * (n - 1) // 2
elif l > 0:
    taste += (2 + n) * (n - 1) // 2
else:
    taste += (1 + n) * n // 2
    taste -= -l + 1
print(taste)

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

#define int long long
#define ffor(i,n) for(int i = 0;i < (n); ++i)
#define all(v) v.begin(),v.end()
#define vi vector<int>
#define vvi vector<vi>
#define INF 1e18
signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    int n,w;
    cin >> n >> w;
    vi wt(n),v(n);
    int s = 0;
    ffor(i,n){
        cin >> wt[i] >> v[i];
    }

    s = accumulate(all(v),0LL);
    // dp -> min weight i can make for a given value
    vvi dp(s + 1,vi(n + 1,INF));
    ffor(i,n + 1){
        dp[0][i] = 0;
    }
    for(int i = 1;i <= s; ++i){
        for(int j = 1;j <= n; ++j){
            dp[i][j] = dp[i][j - 1];
            if(i - v[j - 1] >= 0){
                dp[i][j] = min(dp[i][j],dp[i - v[j - 1]][j - 1] + wt[j - 1]);
            }
        }
    }

    
    int ans = 0;
    ffor(i,s + 1){
        ffor(j,n + 1){
            // cout << dp[i][j] << ' ';
            if(dp[i][j] <= w){
                ans = max(ans,i);
            }
        }
        // cout << '\n';
    }

    cout << ans;
}

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

//ビット演算を用いる方法
int main() {
  string s,t;
  int64_t n,i,j,ans=0;
  cin>>s;
  n=s.length();
  for(i=0;i<(1<<(n-1));i++) {
    bitset<9> b(i);
    t=s.at(0);
    for(j=0;j<n-1;j++) {
      if (b.test(j)) {
        ans+=stoll(t);
        t="";
      }
      t+=s.at(j+1);
    }
    ans+=stoll(t);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>

void swap(double *x,double *y)
{
    double tmp = *x;
    *x = *y;
    *y = tmp;
}

void s_sort(double data[],int size)
{
    int i, j;
    for (i = 0; i < size-1;i++)
    {
        for (j = 0; j < size - 1-i;j++)
        {
            if(data[j]<data[j+1])
            {
                swap(&data[j], &data[j + 1]);
            }
        }
    }
}

int main()
{
    int i, j, k, n;
    double v[1000],val = 0;
    scanf("%d", &n);
    for (i = 0; i < n;i++)
    {
        scanf("%lf", &v[i]);
    }
    s_sort(v, n);
    // for (i = 0; i < n; i++)
    // {
    //     printf(" %.0lf", v[i]);
    // }
    val = v[n - 1];
    for (i = n-2; i >= 0;i--)
    {
        val = (val + v[i]) / 2;
    }
    printf("%lf", val);
    return 0;
}

Measured memory_bytes: 128
//package april2020;

import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;

public class Main {
	static long[] dp;
	static int n;
	static long MOD = (long)1e9+7,k;
//	static ArrayList<Integer>[] graph;
//	static HashSet<Integer> visited;
//	static long[][] dp;
//	@SuppressWarnings("unchecked")
	public static void main(String[] args) throws IOException {
		FastReader scn = new FastReader();
		OutputStream out = new BufferedOutputStream ( System.out );
		n = scn.nextInt();
		k=scn.nextLong();
		dp = new long[n];
		Arrays.fill(dp, 1);
		long[][] can = new long[n][n]; 
		for(int i=0;i<n;i++) {
			for(int j=0;j<n;j++) {
				can[i][j]= scn.nextLong();
			}
		}
		M ans = new M();
		
		for(int i =0;i<n;i++) {
			ans.t[i][i]=1;
		}
		
		M m = new M();
		
		m.t =can;
		
		while(k>0) {
			if(k%2==1) {
				ans = ans.mul(m);
			}
			m = m.mul(m);
			k/=2;
		}
		long total=0;
		for(int i=0;i<n;i++) {
			for(int j=0;j<n;j++) {
				total= (total+ans.t[i][j])%MOD;
			}
		}
		out.write((total+"\n").getBytes());
//		for(long step = 0;step<k;step++) {
//			long[] new_dp = new long[n];
//			
//			for(int i=0;i<n;i++) {
//				for(int j=0;j<n;j++) {
//					if(can[i][j]) {
//						new_dp[j]=(new_dp[j]+dp[i])%MOD;
//					}
//				}
//			}
//			dp=new_dp;
//		}
//		long ans=0;
//		for(int i =0;i<n;i++) {
//			ans=(ans+dp[i])%MOD;
//		}
//		out.write((ans+"\n").getBytes());
		out.close();
	}
	static class M{
		long[][] t;
		public M() {
			this.t = new long[n][n];
		}
		M mul(M o) {
			M c = new M();
			for(int i =0;i<n;i++) {
				for(int j=0;j<n;j++) {
					for(int k=0;k<n;k++) {
						c.t[i][k] = (c.t[i][k]+this.t[i][j]*o.t[j][k]%MOD)%MOD;
					}
				}
			}
			return c;
		}
	}
	static class FastReader 
    { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader() 
        { 
            br = new BufferedReader(new
                     InputStreamReader(System.in)); 
        } 
  
        String next() 
        { 
            while (st == null || !st.hasMoreElements()) 
            { 
                try
                { 
                    st = new StringTokenizer(br.readLine()); 
                } 
                catch (IOException  e) 
                { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 
  
        int nextInt() 
        { 
            return Integer.parseInt(next()); 
        } 
  
        long nextLong() 
        { 
            return Long.parseLong(next()); 
        } 
  
        double nextDouble() 
        { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() 
        { 
            String str = ""; 
            try
            { 
                str = br.readLine(); 
            } 
            catch (IOException e) 
            { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
    }
}


Measured memory_bytes: 24020
import itertools
C = []
for i in range(5):
    C.append(int(input()))

ans = float("inf")
for order in itertools.permutations(C, 5):
    total = 0
    for c in order:
        if total % 10 != 0:
            total = (total // 10 + 1) * 10
        total += c

    ans = min(total, ans)

print(ans)


Measured memory_bytes: 3060
#include<stdio.h>

#define N 20
#define Q 200

int solve(int, int);

int a[N];
int m[Q];
int n;

int main(){
int i, q;
  scanf("%d",&n);
  for(i=0 ; i<n ; i++) scanf("%d", &a[i]);

  scanf("%d", &q);
  for(i=0 ; i<q ; i++){
     scanf("%d", &m[i]);
     if(solve(0,m[i])>=1) printf("yes\n");
     else printf("no\n");
   }
   return 0;
}

int solve(int i, int k){
  int res;

  if(k == 0) return 1;
  else if(i >= n) return 0;
  res = solve(i+1, k) + solve(i+1, k-a[i]);
  return res;
}

Measured memory_bytes: 580
#include <map>
#include <set>
#include <list>
#include <cstdio>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <cctype>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

#define fr first
#define sc second
#define mp make_pair

typedef long long int64;
typedef pair< int, int > iP;
typedef pair< iP, int > iiP;

const int INF = 2 << 28;
const double EPS = 1e-10;

#define MAX 123456 * 2 + 1

vector< bool > p(MAX, true);

int main() {

    p[0] = p[1] = false;
    for(int i = 2; i * i < MAX; i++)
        for(int j = i + i; j < MAX; j += i)
            p[j] = false;

    int n;
    while(cin >> n, n) {
        int cnt = 0;
        for(int i = n + 1; i <= n + n; i++) {
            if(p[i]) cnt++;
        }
        cout << cnt << endl;
    }
}

Measured memory_bytes: 1224
#define first f
#define second s
#define ll long long
#define mp make_pair
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#include <bits/stdc++.h>
#define pii pair<int,int>
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
const int maxn=2e5+5;
const double PI=acos(-1);
const double e=2.718281828459;

map<string,int>MP;
string s[maxn];
map<string,bool>p;
int main()
{
    int n,x,num=0,t=0;
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d",&x);
        if(x%2==0){
            t++;
            if(x%3==0||x%5==0){num++;}
        }
    }
    if(num==t){
        printf("APPROVED");
    }
    else{
        printf("DENIED");
    }
    return 0;
}


Measured memory_bytes: 1792
X = int(input())

def is_prime(n):
  if n == 2:
    return True
  elif n == 1 or n%2 ==0:
    return False
  else:
    m = 3
    while m*m <= n:
      if n % m == 0:
        return False
      else:
        m += 2
    return True

while 1:
  if is_prime(X):
    print(X)
    break
  X += 1

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define loop(i,l,r) for(int i=(l);i<=(r);i++)
typedef long long ll;
const int maxn=2e5+5;
int a[105];
int vis[105][105];
struct node
{
    int a;
    int b;
    node(int x,int y)
    {
        a=x,b=y;
    }
};
vector<node>v;
int main()
{
    int n,k;
    scanf("%d%d",&n,&k);
    int m=n-2;
    m=m*(m+1)/2;
    if(k==0&&n==2)
    {
        printf("1\n");
        printf("1 2\n");
    }
    else if(k>m) printf("-1\n");
    else
    {
        a[0]=1;
        loop(i,1,n-2) a[i]=2+i;
        int cnt=m-k;
        loop(i,0,n-2)
        loop(j,i+1,n-2)
        {
            if(a[i]==1)
            {
                if(!vis[1][2]) v.push_back(node(1,2)),vis[1][2]=1;
            }
            else
            {
                if(!vis[2][a[i]]) v.push_back(node(2,a[i])),vis[2][a[i]]=1;
            }
            if(!vis[2][a[j]]) v.push_back(node(2,a[j])),vis[2][a[j]]=1;
            if(cnt>0)
            {
                if(!vis[a[i]][a[j]]) v.push_back(node(a[i],a[j])),vis[a[i]][a[j]]=1;
                cnt--;
            }
        }
        printf("%d\n",v.size());
        for(int i=0;i<v.size();i++)
            printf("%d %d\n",v[i].a,v[i].b);
    }
}


Measured memory_bytes: 384
#include"bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp> 
using namespace __gnu_pbds; 
using namespace std;

#define double long double
#define int long long
#define pb push_back 
#define Z(c) (int)(c).size()
#define L(c) c[Z(c)-1]
#define F first
#define S second
#define nl "\n"
#define mii map<int,int> 
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define rep(i,iv,n) for(int (i)=(iv);(i)<(n);++(i))
#define FO fflush(stdout) 
#define D1(x) cerr <<"At line "<<__LINE__<<" "<<#x<<"="<<x<<nl
#define D2(x,y) cerr <<"At line "<<__LINE__<<" "<<#x<<"="<<x<<" "<<#y<<"="<<y<<nl
#define D3(x,y,z) cerr <<"At line "<<__LINE__<<" "<<#x<<"="<<x<<" "<<#y<<"="<<y<<" "<<#z<<"="<<z<<nl
#define tr(it,ct) for(auto &(it) : (ct))
#define pi acos(-1)
#define prt(ct) for(auto &(it) : (ct)) cerr<<it<<" "; cerr<<nl
#define prtp(ct) for(auto &(it) : (ct)) cerr<<it.F<<" "<<it.S<<nl; cerr<<nl

typedef vector< int > vi;
typedef vector< vi > vvi;
typedef pair< int,int > pii;
typedef vector< pii > vp;
typedef tree<int, null_type, less<int>, rb_tree_tag, 
             tree_order_statistics_node_update> baap;

void swap(char &a,char &b)
{ auto tm=a; a=b; b=tm; }
                                   
 
  const int mod=1000000007;
  const int mod2=998244353;
  const int INF=1e16+18;
  const int N=2e5+25;
  const int M=2e4;
  
 
 void fft()           
 { 
   string s; cin>>s; bool f=true;
   if(s[2]!=s[3]) f=false;
   if(s[4]!=s[5]) f=false;

   if(f) cout<<"Yes";
   else cout<<"No";
 }

signed main()
{ 
   ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

  
   
   int tc=1;                         
 //  cin>>tc;

  rep(i,1,tc+1)
  { // cout<<"Case #"<<i<<": ";
   fft();
   if(i<tc)
   cout<<nl;
  }
  

 return 0; 
}

Measured memory_bytes: 256
import java.lang.*;
import java.io.*;
import java.util.*;

class Main{
	public static void main(String args[]) throws FileNotFoundException{
		FScanner fs=new FScanner();
		//Scanner sc=new Scanner(System.in);
		
		String[] s=fs.readStringL();
		long k=fs.readLong();
		int head=0;
		
		for(int i=0; i<s.length && s[i].equals("1"); i++){
			head++;
		}
		
		if(k<=head){
			System.out.println("1");
		}else{
			System.out.println(s[head]);
		}
	}
	
	static void solver(){
		
	}

	static void disp(int[] data){
		for(int i=0; i<data.length; i++){
				System.out.printf("%d ",data[i]);
		}
			System.out.println();
	}
	
	static class FScanner{
		Scanner sc;
		FScanner() throws FileNotFoundException{
			sc=new Scanner(System.in);
		}
		boolean hasNextLine(){
			boolean has=true;
			if(!sc.hasNextLine()){
				has=false;
			}
			return has;
		}
		int readInt(){
			int i=Integer.parseInt(sc.nextLine());
			return i;
		}
		long readLong(){
			long i=Long.parseLong(sc.nextLine());
			return i;
		}
		int[] readIntL(){
			String[] buf=sc.nextLine().split(" ");
			int[] num=new int[buf.length];
			for(int i=0; i<buf.length; i++){
				num[i]=Integer.parseInt(buf[i]);
			}
			return num;
		}
		
		String readString(){
			return sc.nextLine();
		}
		String[] readStringL(){
			String[] s=sc.nextLine().split("");
			return s;
		}
	}
}


Measured memory_bytes: 21588
<?php
fscanf(STDIN,"%s",$s);

for($i=1;$i<=strlen($s);$i++){
	$arr[$i]=substr($s,$i-1,1);
}

$hantei=true;
for($i=1;$i<=strlen($s);$i++){
	$a=$arr[$i];
	if($a<>"L" && $a<>"R" && $a<>"U" && $a<>"D"){
			$hantei=false;
			break;
	}else{
		if(($i % 2)==0){
			if($a=="R"){
				$hantei=false;
				break;
			}
		}else{
			if($a=="L"){
				$hantei=false;
				break;
			}
		}
	}
}

//print_r($arr);

if($hantei){
	echo "Yes";
}else{
	echo "No";
}
//print_r($arr);

?>

Measured memory_bytes: 3828
n=int(input())
l=[]
for i in range(1,n+1):
    x=i
    if (x%3)==0:
        l.append(str(i))
    else:
        while(1):
            if x==0:
                break
            elif (x%10)==3:
                l.append(str(i))
                break
            else:
                x=x//10    
l=' '.join(l)
print(' '+l)


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

int main(){
	int n;
	cin >> n;
	string s;
	cin >> s;
	if(n%2) {cout << "No"; return 0;
	}
	else{
		for(int i=0;i<n/2;i++)
		{
			if(s[i]!=s[i+n/2])
			{
				cout << "No"; return 0;
			}
		}
	}
	cout << "Yes";
	return 0;	
}

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

struct edge {
    int to;
    int cost;
};
using P = pair<int, int>;
vector<vector<edge>> G;
vector<int> d;
vector<int> prever;
void dijkstra(int s) {
    priority_queue<P, vector<P>, greater<P>> que;
    fill(d.begin(), d.end(), INF);
    fill(prever.begin(), prever.end(), -1);
    d[s] = 0;

    que.push(P(0, s));
    while (!que.empty()) {
        P p = que.top();
        que.pop();
        int v = p.second;
        if (d[v] < p.first)
            continue;
        rep(i, G[v].size()) {
            edge e = G[v][i];
            if (d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                prever[e.to] = v;
                que.push(P(d[e.to], e.to));
            }
        }
    }
}

vector<int> get_path(int t) {
    vector<int> path;
    int cnt = 0;
    for (; t != -1 && cnt != 2; t = prever[t]) {
        path.push_back(t);
        ++cnt;
    }
    return path;
}

int main() {
    int n, m;
    cin >> n >> m;
    G.resize(n);
    d.resize(n);
    prever.resize(n);

    rep(i, m) {
        int a, b;
        cin >> a >> b;
        --a, --b;

        G[a].push_back({b, 1});
        G[b].push_back({a, 1});
    }

    dijkstra(0);
    vector<int> ans(n);
    bool flag = true;
    rep(i, n) {
        if (d[i] == INF) {
            flag = false;
            break;
        } else {
            vector<int> tmp = get_path(i);
            ans[i] = tmp[1] + 1;
        }
    }

    if (flag) {
        cout << "Yes" << endl;
        rep(i, n - 1) cout << ans[i + 1] << "\n";
    } else {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 13724
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i];if(i<len-1) s<<" ";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i]<<endl;
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){
	s<<"{ ";
	for(auto itr=v.begin();itr!=v.end();++itr) {
		if (itr!=v.begin()) {s<< ", ";}
		s<<(*itr);
	}
	s<<" }";
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){
	s<<"{"<<endl;
	for(auto itr=m.begin();itr!=m.end();++itr){
		s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;
	}
	s<<"}"<<endl;
	return s;
}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,a,b;
	cin>>n>>a>>b;
	string s;
	cin>>s;
	int now=0,cnt=0;
	vector<bool> ans(n,false);
	rep(i,n){
		if(s[i]=='a'){
			if(now<a+b){
				cout<<"Yes"<<endl;
				now++;
				continue;
			}
		}if(s[i]=='b'){
			if(cnt<b && now<a+b){
				cout<<"Yes"<<endl;
				now++;
				cnt++;
				continue;
			}
		}
		cout<<"No"<<endl;
	}
}

Measured memory_bytes: 848
//#include <bits/stdc++.h>
#include <string>
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>

using namespace std;


int main(){
    string str;
    cin >> str;
    int n = str.length();
    vector<string> vs(n);
    for(int i=0;i<n;i++){
        vs[i] = str.substr(i,1);
    }

    long int total = 0;
    long int sum = 0;
    string ssum;

    for(int i=0;i<(1<<(n-1));i++){
        sum = 0;
        ssum = vs[0];
        for(int j=0;j<n-1;j++){
            if((i>>j)%2){
                sum += stol(ssum);
                ssum = "";
            }
            ssum += vs[j+1];
        }
        sum += stol(ssum);
        total += sum;
    }
    cout << total << endl;


    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) // rep(i, 1, 5) --> {1,2,3,4} // rep(i, 5, 1) --> {4,3,2,1} // rep(it, end(v), begin(v)) --> *it

using namespace std;

int m, n;
set<vector<int>> s;

void dfs(vector<int> y, int i)
{
    if (y.size() == n)
    {
        s.insert(y);
        return; // VOID FUNCTION MUST RETURN;
    }
    y.push_back(i);
    for (int j = i; j <= m; j++)
        dfs(y, j);
}

int main()
{
    int q;
    cin >> n >> m >> q;
    int v[q][4];
    rep(i, 0, q)
        cin >> v[i][0] >> v[i][1] >> v[i][2] >> v[i][3];
    rep(i, 1, m + 1)
        dfs({}, i);
    ll res = 0;
    for (auto x:s)
    {
        ll sum = 0;
        rep(i, 0, q)
        {
            int a = v[i][0];
            int b = v[i][1];
            int c = v[i][2];
            int d = v[i][3];
            // cout << a << b << c << d << endl;
            if (x[b-1] - x[a-1] == c)
                sum += d;
        }
        res = max(res, sum);
    }
    cout << res;
    return 0;
}

Measured memory_bytes: 13696
#include <iostream>
#include <vector>
using namespace std;
int n;
int main() {
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    while (a[i] % 2 == 0) {
      a[i] /= 2;
      cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}

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

#define ll long long
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define MOD 1000000007

using namespace std;


int main(){

       long double n,a,b,max,x;
       cin >> a>> b>> n;
       if (n >= b)
         x = b-1;
         else x = n;
      max = floor ((a*x)/b) - a*floor(x/b);
      cout << max;
}


Measured memory_bytes: 3792
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
typedef unsigned int uint;
using namespace std;

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

  //全部行く場合の金額sum
  ll sum = 0LL;
  for(int i=0;i<=N;i++){
    sum += abs(a[i+1] - a[i]);
  }

  ll ans;
  for(int i=1;i<=N;i++){
    if(a[i-1]<=a[i] && a[i]<=a[i+1]) ans = sum;
    else if(a[i-1]<=a[i+1] && a[i+1]<=a[i]) ans = sum - 2*(a[i]-a[i+1]);
    else if(a[i+1]<=a[i-1] && a[i-1]<=a[i]) ans = sum - 2*(a[i]-a[i-1]);
    else if(a[i]<=a[i-1] && a[i-1]<=a[i+1]) ans = sum - 2*(a[i-1]-a[i]);
    else if(a[i]<=a[i+1] && a[i+1]<=a[i-1]) ans = sum - 2*(a[i+1]-a[i]);
    else if(a[i+1]<=a[i] && a[i]<=a[i-1]) ans = sum;
    cout << ans << endl;
  }
  return 0;
}

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

int main(){
    int a, b;
    cin >> a >> b;
    rep(i, 10000){
        if (i * 8 / 100 == a && i * 10 / 100 == b){
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <array>
#include <queue>
#include <deque>
#include <set>
#include <unordered_set>
#include <list>
#include <map>
#include <stack>
#include <utility>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <climits>
#include <bitset>
#include <random>
#include <functional>
#include <sstream>
#include <iomanip>

using namespace std;

#define _CRT_SECURE_NO_WARNINGS
#define rep(i, n) for(int i=0; i<(n); i++)
#define FOR(i, m, n) for(int i=(m);i<(n);i++)
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define REVE(x) reverse((x).begin(),(x).end())
#define mp make_pair
#define pb push_back
#define F first
#define S second

typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
typedef long long LL;

//最大公約数
LL gcd(LL n, LL m) {
	if (m == 0)return n;
	return gcd(m, n%m);
}

//最小公倍数
LL lcm(LL n, LL m) {
	LL g = gcd(n, m);
	return n / g * m;
}
int main() {
	LL n;
	cin >> n;
	vector<LL> a(n);
	rep(i, n)cin >> a[i];
	LL ans = lcm(a[0], a[1]);
	for (int i = 2; i < n; i++) {
		ans = lcm(ans, a[i]);
	}
	cout << ans << endl;
}


Measured memory_bytes: 3104
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+5;
const int inf=0x3f3f3f3f;
int n,ans=0;
map<int,int> mp;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		int x;
		cin>>x;
		mp[x]++;
	}
	map<int,int>::iterator it;
	for(it=mp.begin();it!=mp.end();it++)
	{
		if((it->first)!=(it->second))
		{
			if((it->first)<(it->second))
				ans+=(it->second)-(it->first);
			else
				ans+=(it->second);
		}
	}
	cout<<ans<<endl;
	return 0;
}




Measured memory_bytes: 4736
#include <stdio.h>

int main(){
  int a[5000],i,j,m,n,s;
  while(scanf("%d",&n)){
    if(n==0) break;
    for(i=0;i<n;i++) scanf("%d",&a[i]);
    m=a[0];
    for(i=0;i<n;i++){
      s=0;
      for(j=i;j<n;j++){
        s+=a[j];
        if(s>m) m=s;
      }
    }
    printf("%d\n",m);
  }
  return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
#include <stdlib.h>
#define ll long long
#define rep(i,l,r)for(ll i=l;i<r;i++)
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))

ll tate[110],yoko[110];
ll a[110];
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}

int main(){
	ll n,w,h;
	while(scanf("%lld%lld%lld",&n,&w,&h),h){
		tate[0]=w;
		yoko[0]=h;
		rep(i,0,n){
			ll p,s;
			scanf("%lld%lld",&p,&s);
			p--;
			s%=tate[p]+yoko[p];
			if(s<tate[p]){
				//tate
				tate[i+1]=min(s,tate[p]-s);
				tate[i+2]=max(s,tate[p]-s);
				yoko[i+1]=yoko[p];
				yoko[i+2]=yoko[p];
			}else{
				//yoko
				s-=tate[p];
				tate[i+1]=tate[p];
				tate[i+2]=tate[p];
				yoko[i+1]=min(s,yoko[p]-s);
				yoko[i+2]=max(s,yoko[p]-s);
			}
			rep(j,p,i+2){
				tate[j]=tate[j+1];
				yoko[j]=yoko[j+1];
			}
		}
		rep(i,0,n+1)a[i]=tate[i]*yoko[i];
		sortup(a,n+1);
		rep(i,0,n+1)printf("%lld%c",a[i],i==n?'\n':' ');
	}
}


Measured memory_bytes: 2044
#include <algorithm>

namespace rika
{
  template <typename T>
  class edge
  {
  public:
    int to;
    T cost;
    
    edge() = default;
    edge(const edge<T>&) = default;
    edge(edge<T>&&) = default;
    edge& operator =(const edge<T>&) = default;
    edge& operator =(edge<T>&&) = default;

    ~edge() = default;

    edge(int _to, T _cost) : to(_to), cost(_cost) {}
  };
}
  int N;

#include<bits/stdc++.h>
using namespace std;
using namespace rika;
namespace rika
{
  namespace internal
  {
    template <typename TValue, typename TGraph>
    std::pair<TValue, int> visit(int from, int v, const TGraph &g)
    {
      if(v >= N)
        throw "test";
      auto r = std::make_pair(TValue(), v);
      try{
      for(auto it = g[v].begin(); it != g[v].end(); ++it)
      {
        if(it->to == from)
          continue;
        auto r2 = visit<TValue>(v, it->to, g);
        if(r2.first + it->cost >= r.first)
          r = std::make_pair(r2.first + it->cost, r2.second);
      }
      }catch(const std::out_of_range &e){}
      return r;
    }
  }

  template <typename TValue, typename TGraph>
  TValue tree_diameter(const TGraph &g)
  {
    using namespace internal;
    auto r1 = visit<TValue>(-1, 0, g);
    auto r2 = visit<TValue>(-1, r1.second, g);
    return r2.first;
  }
}

#include<bits/stdc++.h>
using namespace std;
using namespace rika;
int main()
{
  cin >> N;
  vector<vector<edge<int>>> g(N * 10);
  for(int i = 0; i < N - 1; i++)
  {
    int s, t, w;
    cin >> s >> t >> w;
    g[s].push_back(edge<int>(t, w));
    g[t].push_back(edge<int>(s, w));
  }
  cout << tree_diameter<int>(g) << endl;
}

Measured memory_bytes: 35356
#include<iostream>
#include<math.h>
#include<cmath>
#include<iomanip>
#include<string.h>
#include<stdio.h>
#include<algorithm>
using namespace std;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    string a;
    cin>>a;
    int i,j,k;
    int x,y;
    x=0;
    y=0;
    for(i=0;i<a.length();i++){
    	if(a[i]=='0'){
    		x++;
		}
		else{
			y++;
		}
	}
	if(x>=y){
		cout<<y*2<<endl;
	}
	else{
		cout<<x*2<<endl;
	}
    return 0;
}



Measured memory_bytes: 512