akhauriyash/Code-Regression huggingface dataset:
/***********************************************************
	When you are inspired by passion 
	and you want to live for the current moment

	When your every thought and action
	has the power to become the story of your future

	When difficulties stand to demolish your Glory
	Just remember that Life is a 'Golden adverse Story'

	Withstand it to acheive your passion and dreams
	more amazingly more easily.

	Why then? When writing the story of your Life
	You want to Let someone else hold your pen

					huzaifa242©

***********************************************************/
#include "bits/stdc++.h"
using namespace std;
#define int int64_t
#define MAX 100005
#define x first 
#define y second

int seed;
mt19937 rng(seed=chrono::steady_clock::now().time_since_epoch().count());
inline int rnd(int l = 0, int r = numeric_limits <int>::max())
{return uniform_int_distribution<int> (l, r)(rng);}

template <typename T, typename G>
ostream& operator << (ostream& out, const pair <T, G> &a) 
{return out << "( " << a.x << ", " << a.y << ")";}

template <typename T>
ostream& operator << (ostream& out, const vector <T> &a) 
{out << "[ "; for(const auto &i: a) out << i << ", "; return out << "]" << endl;}

template <typename T>
ostream& operator << (ostream& out, const set <T> &a) 
{out << "{ "; for(const auto &i: a) out << i << ", "; return out << "}" << endl;}

template <typename T, typename G>
ostream& operator << (ostream& out, const map <T, G> &a) 
{out << "< "; for(const auto &i: a) out << i << ", "; return out << ">" << endl;}

template <typename T, size_t N>
typename enable_if<!is_same <typename remove_cv <T>::type, char>::value,
ostream&>::type operator << (ostream& out, T (&a)[N])
{out << "[ "; for(const auto &i: a) out << i << ", "; return out << "]" << endl;}

void debug_out(){cerr << endl;} 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T)
{cerr << (H) << ' '; debug_out(T...);}
 
#ifdef LOCAL
#define debug(...) cerr << '#' << #__VA_ARGS__ << ":\n", debug_out(__VA_ARGS__)
#else
#define debug(...) 24
#endif

const int mod = 998244353;
int md(int x, int mdo = mod) {
	x %= mdo;
	return x < 0? x + mdo: x;
}

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	int n, k;
	cin >> n >> k;
	vector <pair <int,int> > segs(k);
	for (auto &seg : segs) 
		cin >> seg.x >> seg.y;
	vector <int> count(n + 1, 0), sum(n + 1, 0);
	count[1] = sum[1] = 1;
	for (int i = 2; i <= n; ++i) {
		for (auto &seg : segs) {
			int l = max(i - i + 1, i - seg.y);
			int r = max(i - i + 1, i - seg.x);
			if (i - seg.x <= 0)
				continue; 
			count[i] = md(count[i] + sum[r] - sum[l - 1]);
		}
		sum[i] = md(sum[i - 1] + count[i]);
	}
	cout << count[n] << '\n';
	return 0;
}


Measured memory_bytes: 6404
import java.util.*;

public class Main {

	static final int INF = Integer.MAX_VALUE;
	
	static int W, H, WW, HH, segH, segW;
	static int[][] data;
	static int[][] segTree;
	
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		for(;;){
			H = Integer.parseInt(in.next());
			W = Integer.parseInt(in.next());
			int Q = Integer.parseInt(in.next());
			
			if(H==0){
				return ;
			}
			
			data = new int[H][W];
			
			for(int i=0; i<H; i++){
				for(int j=0; j<W; j++){
					data[i][j] = Integer.parseInt(in.next());
				}
			}
			
			int logH = H == 1 ? 0 : 31 - Integer.numberOfLeadingZeros(H-1),
				logW = W == 1 ? 0 : 31 - Integer.numberOfLeadingZeros(W-1);
			HH = 1<<(logH+1);
			WW = 1<<(logW+1);
			segH = 2*HH-1;
			segW = 2*WW-1;
			
			segTree = new int[segH][segW];
			
			initializeH(0,0,HH);
			
			for(int i=0; i<Q; i++){
				int y1 = Integer.parseInt(in.next());
				int x1 = Integer.parseInt(in.next());
				int y2 = Integer.parseInt(in.next());
				int x2 = Integer.parseInt(in.next());
				System.out.println(query(y1, x1, y2+1, x2+1));
			}
		}
	}

	static void initializeW(int y, int cur, int lx, int rx){
		if(rx - lx <= 1){
			if(y < H && lx < W){
				segTree[y+HH-1][cur] = data[y][lx];
			}
			return ;
		}
		
		int mid = (lx + rx) / 2;
		
		initializeW(y, 2*cur+1, lx, mid);
		initializeW(y, cur*2+2, mid, rx);
		
		segTree[y+HH-1][cur] = Math.min(segTree[y+HH-1][2*cur+1], segTree[y+HH-1][2*cur+2]);
	}
	
	static int queryW(int nodeY, int fx, int tx, int cur, int lx, int rx){
		if(rx <= fx || tx <= lx){
			return INF;
		}
		
		if(fx<=lx&&rx<=tx){
			return segTree[nodeY][cur];
		}
		
		int mid = (lx+rx)/2;
		return Math.min(queryW(nodeY, fx, tx, cur*2+1, lx, mid), queryW(nodeY, fx, tx, cur*2+2, mid, rx));
	}
	
	static void initializeH(int cur, int ly, int ry){
		if(ry -ly <= 1){
			initializeW(ly, 0, 0, WW);
			return ;
		}
		
		int mid = (ly+ry)/2;
		
		initializeH(2*cur+1, ly, mid);
		initializeH(2*cur+2, mid, ry);
		
		for(int j=0; j<segW; j++){
			segTree[cur][j] = Math.min(segTree[2*cur+1][j], segTree[2*cur+2][j]);
		}
	}
	
	static int queryH(int fy, int ty, int fx, int tx, int cur, int ly, int ry){
		if(ry<=fy || ty<=ly){
			return INF;
		}
		if(fy <=ly && ry<=ty){
			return queryW(cur, fx, tx, 0, 0, WW);
		}
		
		int mid = (ly+ry)/2;
		return Math.min(queryH(fy, ty, fx, tx, cur*2+1, ly, mid), queryH(fy, ty, fx, tx, cur*2+2, mid, ry));
	}
	
	static int query(int y1, int x1, int y2, int x2){
		return queryH(y1, y2, x1, x2, 0, 0, HH);
	}
}

Measured memory_bytes: 100000
#include <iostream>
using namespace std;
int main(void){
    
    int n;
    cin>>n;
    int a[100];
    int b[100];
    
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=0;i<n;i++){
        cin>>b[i];
    }
    
    int ans=0;
    for(int i=0;i<n;i++){
        ans+=max(0,a[i]-b[i]);
    }
    cout<<ans;
    return 0;
    
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int N, M;
int a[101], b[101], c[101], d[101];
int main()
{
    scanf("%d%d", &N, &M);
    for(int i=0; i<N; ++i) scanf("%d%d", a+i, b+i);
    for(int i=0; i<M; ++i) scanf("%d%d", c+i, d+i);
    for(int i=0; i<N; ++i)
    {
        int maxv = 1010101010;
        int ans = 0;
        for(int j=0; j<M; ++j)
        {
            int dist = abs(a[i]-c[j]) + abs(b[i]-d[j]);
            if(dist<maxv)
            {
                maxv=dist; ans = j;
            }
        }
        printf("%d\n", ans+1);
    }
    return 0;
}

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

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

	if (a < b) cout << "a < b" << endl;
	else if (a > b) cout << "a > b" << endl;
	else if (a == b) cout << "a == b" << endl;

	return 0;
}


Measured memory_bytes: 3068
#include <algorithm>
#include <iterator>
#include <iostream>
#include <sstream>
#include <bitset>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <time.h>
#include <limits>
#include <math.h>
#include <climits>
#include <numeric>
#include <utility>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <functional>
#include<unordered_map>
 
using namespace std;
const double pi=acos(-1.0);
//memset ( a , 0 , n * sizeof(ll) ) ;
 
#define 	boost  		ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); // don't use if small inpts
#define 	endl 		'\n'
#define 	sl(n) 		scanf("%lld",&n)
#define		mp 			make_pair
#define 	pb 			push_back
#define 	ppb 		pop_back
#define 	fi 			first
#define 	se 			second
#define 	ll 			long long
#define 	ull 		unsigned long long
#define 	pii 		pair<int, int>
#define 	f(i,a,b) 	for(ll i = (ll)(a); i < (ll)(b); i++)
#define 	rf(i,a,b) 	for(ll i = (ll)(a); i > (ll)(b); i--)
#define 	ms(a,b) 	memset((a),(b),sizeof(a))
#define 	max(a,b) 	((a>b)?(a):(b))
#define 	min(a,b) 	((a<b)?(a):(b))
#define 	vec(g1) 	int temp;cin>>temp;g1,push_back(temp);
#define 	abs(x) 		((x<0)?(-(x)):(x))
#define 	MAX 		1000005
#define 	inf 		LLONG_MAX
#define 	MIN 		INT_MIN
 
//typedef
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<int,int> MPII;
typedef set<int> SETI;
typedef multiset<int> MSETI;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int  uint64;
 
 
int mod = 1e9 + 7 ;
ll gcd(ll a , ll b){return b==0?a:gcd(b,a%b);}
ll powmod(ll a,ll b) {ll res=1;if(a>=mod)a%=mod;for(;b;b>>=1){if(b&1)res=res*a;if(res>=mod)res%=mod;a=a*a;if(a>=mod)a%=mod;}return res;}
uint32 setbits(ll n){uint32 count=0;while (n){n&=(n-1);count++;}return count; } 
int modInverse(int A,int M){return powmod(A,M-2);}
// ll fac[200005];
// ll inverse(ll n){return powmod(n, mod-2);}
// ll nCr(ll n, ll r){return (fac[n] * inverse(fac[r]) % mod * inverse(fac[n-r]) % mod) % mod;}
const int N= 10000000;int lp[N+1];vector<int> pr;void seive(){for (int i=2; i<=N; ++i) {if (lp[i] == 0) {lp[i] = i;pr.push_back (i);}for (int j=0; j<(int)pr.size() && pr[j]<=lp[i] && i*pr[j]<=N; ++j) lp[i * pr[j]] = pr[j]; }}
////****************************************************************************************************************************************************************************************************************////
 
int main(){
	boost;
	int n;
	cin>>n;
	ll x;
	cin>>x;
	ll a[n];
	f(i,0,n)cin>>a[i];
	ll ans=0;
	f(i,0,n-1){
		 if(a[i]+a[i+1] >x){
		 ll add= (a[i+1]+a[i])-x; 
		 	 ans+= (a[i+1]+a[i])-x;
		 	 if(add>a[i+1]){
		 	 	ll diff= add-a[i+1];
		 	 	 a[i+1]=0;
		 	 	 
		 	 	 a[i]=a[i]-diff;
		 	 }
		 	 else{
		 	 	 a[i+1]=a[i+1]-add;
		 	 }

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

Measured memory_bytes: 1024
S = int(input())
s, c = S, 1
result = [s]
while True:
    if s % 2 == 0:
        s = s // 2
    elif s % 2 == 1:
        s = s * 3 + 1

    result.append(s)
    c += 1
    if len(set(result)) < len(result):
        break

print(c)

Measured memory_bytes: 8848
import java.util.Arrays;
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		int[] alp = new int['z' - 'a' + 1];
		Arrays.fill(alp, 0);
		for(int i = 0; i < S.length(); i++) {
			alp[S.charAt(i) - 'a']++;
		}
		char c = '-';
		for(int i = 0; i < alp.length; i++) {
			if(alp[i] == 0 && c == '-') {
				c = (char)('a' + i);
			}
		}
		System.out.println(c == '-' ? "None" : c);
	}
}

Measured memory_bytes: 24448
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(0)
#define pb push_back
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define int long long
const int MOD=1e9+7;
const int N=3e5+10;
int32_t main()
{
	int n;
	cin>>n;
	set<int>s;
	for(int i=1;i*i<=n;i++)
	{
		if(n%i==0)
		{
			s.insert(n/i);
			s.insert(i);
		}
	}
	n-=1;
	for(int i=1;i*i<=n;i++)
	{
		if(n%i==0)
		{
			s.insert(i);
			s.insert(n/i);
		}
	}
	vector<int>vp;
	for(auto it:s)
	{
		if(it!=1)
		{
			vp.pb(it);
		}
	}
	n+=1;
	int cnt=0;
	for(int i=0;i<vp.size();i++)
	{
		int k=n;
		//cout<<vp[i]<<endl;
		while(k>=vp[i])
		{
			if(k%vp[i]==0)
			{
				while(k%vp[i]==0)
				{
					k/=vp[i];
				}
			}
			else
			{
				k%=vp[i];
			}
		}
		if(k==1)
		{
			//cout<<vp[i]<<endl;
			cnt++;
		}
	}
	cout<<cnt<<endl;
	
	
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define lli long long int
#define ulli unsigned long long int
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define pf pop_front()
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define loopl(i,a,b) for(lli i=a;i<b;i++) 
#define loop(i,a,b) for(int i=a;i<b;i++)
#define mod 1000000007
#define inf 1000000000000000000
#define lld long double
#define pll pair<long long int,long long int>
#define vll vector<lli>
#define eps 0.000001
#define endl '\n'
#define mo 998244353
 
using namespace std ;
 
#define MAXN 10000000 + 2
 
typedef tree<pll,null_type,less<pll>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;

int main()
{
////////////////////////////////////////////
    fastio;
    
    lli n,m;
    cin>>n>>m;

    lli pre[n+2] = {0};

    loopl(i,0,m)
    {
        lli l,r;
        cin>>l>>r;
        pre[l]++;
        pre[r+1]--;
    }

    loopl(i,1,n+2)
    pre[i]+=pre[i-1];

    lli cnt=0;

    loopl(i,1,n+1)
    {
        if(pre[i] == m) cnt++;
    }

    cout<<cnt<<endl;

}


Measured memory_bytes: 1152
input_string = gets.chomp.split("").map(&:to_s)
list=["A","C","G","T"]
tmp_string=[]
parts_string=[]

input_string.each{|char|
    if list.include?(char)
        tmp_string << char
        parts_string=tmp_string if tmp_string.length > parts_string.length 
    else
        tmp_string=[]
    end
}

puts parts_string.length

Measured memory_bytes: 1788
import sys


n,k = [int(_) for _ in input().split()]
l = [int(_) for _ in input().split()]
ans = 0
d = {}
for i in range(n):
    if l[i] in d:
        d[l[i]] += 1
    else:
        d[l[i]] = 1
d_sorted = sorted(d.items(), key = lambda x:x[1], reverse=True)
if len(d_sorted) <= k:
    ans = 0
    print(ans)
    sys.exit()
else:
    for j in range(k,len(d_sorted)):
        ans += d_sorted[j][1]
print(ans)

Measured memory_bytes: 39044
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
#define ALL(v) v.begin(), v.end()
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define chmax(x, a) x = max(x, a)
#define chmin(x, a) x = min(x, a)

int main() {
    int ti = clock();
    int D; cin >> D;
    vector<ll> c(26);
    rep(i, 26) cin >> c[i];
    vector<vector<ll>> s(D, vector<ll>(26));
    rep(i, D)rep(j, 26) cin >> s[i][j];
    vector<ll> t(D);
    rep(i, D) t[i] = 26-i%26;
    ll ans = 0;
    vector<ll> last(26);
    vector<ll> t_ans(ALL(t));
    for (int d = 1; d <= D; d++) {
        for (int i = 1; i <= 26; i++) {
            if (t[d-1] == i) {
                ans += s[d-1][i-1];
                last[i-1] = d;
            }
            else {
                ans -= c[i-1]*(d-last[i-1]);
            }
        }
    }
    ll tmp;
    while ((double)(clock() - ti)/CLOCKS_PER_SEC <= 1.97) {
        t[rand()%365] = rand()%26 + 1;
        last.clear();
        last.resize(26);
        tmp = 0;
        for (int d = 1; d <= D; d++) {
            for (int i = 1; i <= 26; i++) {
                if (t[d-1] == i) {
                    tmp += s[d-1][i-1];
                    last[i-1] = d;
                }
                else {
                    tmp -= c[i-1]*(d-last[i-1]);
                }
            }
        }
        if (tmp > ans) {
            swap(ans, tmp);
            rep(i, D) t_ans[i] = t[i];
        }
    }
    rep(i, D) cout << t_ans[i] << endl;
}


Measured memory_bytes: 3736
import sys
from collections import deque
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0
n = int(readline())
g = [[] for _ in range(n)] #隣接リスト
ab = []
for i in range(n-1):
    a,b = map(int,readline().split())
    a,b = a-1,b-1
    ab.append((a,b))
    g[a].append(b)
    g[b].append(a)

root = 0
parent = [0]*n
deq = deque([root])
order = [root]

color = [-1]*n
deq = deque([root])
while deq:
    fr = deq.pop()
    ng = color[fr]
    c = 0
    for go in g[fr]:
        if go == parent[fr]:
            continue
        if c == ng:
            c += 1
        parent[go] = fr
        color[go] = c
        c += 1
        deq.append(go)
        order.append(go)
rank = [0]*n
for i,j in enumerate(order):
    rank[j] = i
print(max(color)+1)
for a,b in ab:
    if rank[a] < rank[b]:
        print(color[b]+1)
    else:
        print(color[a]+1)

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

using namespace std;

//#define FILE_IO

typedef pair<int, int> pii;

int N, M, K;
map <pii, int> mp;

class disjointForest
{
public:
    int f[200005];

    disjointForest()
    {
        for(int i = 1; i <= N; i++)
            f[i] = i;
    }

    int fth(int x)
    {
        if(x == f[x])   return x;
        return f[x] = fth(f[x]);
    }

    void unite(int x, int y)
    {
        int f1 = fth(x);
        int f2 = fth(y);
        if(f1 == f2)    return;
        f[f1] = f2;
    }
};

int main()
{
    #ifdef FILE_IO
    freopen("1.in", "r", stdin);
    freopen("1.out", "w", stdout);
    #endif

    scanf("%d%d%d", &N, &M, &K);

    disjointForest froad;
    for(int i = 1; i <= M; i++)
    {
        int x, y;
        scanf("%d%d", &x, &y);
        froad.unite(x, y);
    }

    disjointForest frailway;
    for(int i = 1; i <= K; i++)
    {
        int x, y;
        scanf("%d%d", &x, &y);
        frailway.unite(x, y);
    }

    for(int i = 1; i <= N; i++)
        mp[ {froad.fth(i), frailway.fth(i)} ]++;

    for(int i = 1; i <= N; i++)
        printf("%d ", mp[ {froad.fth(i), frailway.fth(i)} ]);

    return 0;
}


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

int main(){

   int n;
   cin>>n;

   int w[n];
   for(int i=1;i<n+1;i++){
       cin>>w[i];
   }


   int s1=0;
   int s2=0;
   int ans=100000;

   for(int t=1;t<n;t++){
       s1=0;
       s2=0;
       for(int i=1;i<n+1;i++){
           if(i<=t){
               s1+=w[i];
           }else{
               s2+=w[i];
           }
           
       }
       ans=min(ans,abs(s1-s2));
   }

   cout<<ans<<endl;

return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint     = long long;
const lint inf = 1LL << 60;
const lint mod = 1000000007;

template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    vector<int> a(4);
    cin >> a[0] >> a[1] >> a[2] >> a[3];
    int tot = a[0] + a[1] + a[2] + a[3];
    int ret = tot;
    for (int i = 0; i < 3; ++i) {
        for (int j = i + 1; j < 4; ++j) {
            chmin(ret, abs(tot - 2 * a[i] - 2 * a[j]));
        }
    }
    cout << ret << "\n";
    return 0;
}


Measured memory_bytes: 3212
#include<bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define PB push_back
using namespace std;
typedef pair<int, int> P1;
typedef pair<int, pair<int, int> > P2;
static const int INF = 1ll<<60;
static const int dx[] = { 1, -1, 0, 0, };
static const int dy[] = { 0, 0, 1, -1 };
static const int mod = 1000000007;

int N;
int C[505],S[505],F[505];

signed main(){
    cin>>N;
    for(int i=0;i<N-1;++i)cin>>C[i]>>S[i]>>F[i];
    for(int i=0;i<N;++i){
        int T = 0;
        for(int j=i;j<N-1;++j){
            //cout<<T<<endl;
            if(T<S[j]){
                T = S[j] + C[j];
            }
            else{
                int cost = (T-S[j])/F[j];
                if(cost * F[j] < T - S[j])cost++;
                T = S[j] + F[j] * cost + C[j];
            }
        }
        cout<<T<<endl;
    }
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int) n; i++)
using ll = long long;
template <class T>
using vt = std::vector<T>;
using vvi = std::vector<vt<int>>;

int main(){
  double R;
  std::cin >> R;

  std::cout << std::fixed << std::setprecision(10) << '\n';
  double pi = 3.1415926535;
  std::cout << 2.0*R*pi << '\n';
  return 0;
}


Measured memory_bytes: 3812
#define _USE_MATH_DEFINES
#include <cmath>
#include <string>
#include <vector>
#include <utility>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <numeric>
#include <array>
#include <float.h>
#include <memory>
#include <iomanip>

using namespace std;

int main() {
  std::array<int, 11> arr{ 0 };
  for (int i = 0; i < 3; ++i) {
    int x;
    cin >> x;
    arr[x]++;
  }
  cout << (arr[5] == 2 && arr[7] == 1 ? "YES" : "NO") << endl;
 return  0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 2147483600
#define MOD 10000

int main(){
  int n,k;
  cin>>n>>k;
  vector<int> a(n,0);
  rep(i,k){
    int p,q;
    cin>>p>>q;
    a[p-1]=q;
  }

  vector<vector<long>> dp(n+1, vector<long>(7,0));
  dp[0][0]=1;
  rep(i,n){
    repl(j,1,4){
      if(a[i]==0 || a[i]==j){
        dp[i+1][j] = dp[i][0] - dp[i][j+3] - dp[i][j];
        dp[i+1][j+3] = dp[i][j];
        dp[i+1][0] += dp[i+1][j] + dp[i+1][j+3];
      }
    }
    dp[i+1][0]%=MOD;
  }
  while(dp[n][0]<0) dp[n][0]+=MOD;

  cout << dp[n][0] << endl;

  return 0;
}

Measured memory_bytes: 3156
#include <iostream>
#define MAXR 8
#define MAXN 200
#define MAXC 100000
using namespace std;
int N, M, R;
int r[MAXR];
int d[MAXN][MAXN];
int INF = MAXC * MAXN;
int answer;
bool used[MAXR];

void dfs(int count, int last, int distance) {
  if (count == R) {
    if (answer > distance) {
      answer = distance;
    }
    return;
  }
  for (int i = 0; i < R; i++) {
    if (!used[i]) {
      used[i] = true;
      if (last == -1) {
        dfs(count + 1, i, 0);
      } else {
        dfs(count + 1, i, distance + d[r[last]][r[i]]);
      }
      used[i] = false;
    }
  }
}
int main(void) {
  cin >> N >> M >> R;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      if (i != j) {
        d[i][j] = INF;
      }
    }
  }
  for (int i = 0; i < R; i++) {
    cin >> r[i];
    r[i]--;
  }
  for (int i = 0; i < M; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    a--;
    b--;
    d[a][b] = d[b][a] = c;
  }
  for (int k = 0; k < N; k++) {
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < N; j++) {
        if (d[i][j] > d[i][k] + d[k][j]) {
          d[i][j] = d[i][k] + d[k][j];
        }
      }
    }
  }
  answer = INF * 8;
  dfs(0, -1, 0);
  cout << answer << endl;
  return 0;
}

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

int main() {
    string s;
    cin >> s;

    bool r = false;
    sort(s.begin(), s.end());
    for (int i = 1; i < s.size(); i++) {
        if (s.at(i-1) == s.at(i)) r = true;
    }
    
    if (r) {
        cout << "no" << endl;
    } else {
        cout << "yes" << endl;
    }

    return 0;
}


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

int main()
{
    int n;
    long long sum = 0;
    cin >> n;
    for(int i = 1; i <= n; i++)
    {
        if(i % 3 == 0 || i % 5 == 0)
            continue;
        sum += i;
    }
    cout << sum;
    return 0;
}

Measured memory_bytes: 3596
n, m = map(int, input().split())

a = [list(sorted(map(int, input().split()))) for i in range(m)]
a.sort()

x = 0
li_a = []

while x < m and a[x][0]== 1:
    li_a.append(a[x][1])
    x += 1

a.sort(reverse=True, key=lambda x: x[1])

x = 0
li_b = []

while x < m and a[x][1] == n:
    li_b.append(a[x][0])
    x += 1

print("POSSIBLE" if set(li_a) & set(li_b) else "IMPOSSIBLE")

Measured memory_bytes: 57628
#include <stdio.h>

int main(void) {
	int a;
	int b;
	while(1) {
		scanf("%d %d", &a, &b);
		if ((a == 0) && (b == 0)) {
			break;
		}
		if (a < b) {
			printf("%d %d\n", a, b);
		} else {
			printf("%d %d\n", b, a);
		}
	}
	return 0;
}

Measured memory_bytes: 596
import sys

N, M = map(int,input().split())
vote_list = list(map(int, input().split()))
mysum = sum(vote_list)
#print(mysum)
mycnt = 0
for v in vote_list:
    #print(v, 1/(4*M))
    if v >= mysum * (1/(4*M)):
        mycnt += 1
        if mycnt >= M:
            print('Yes')
            sys.exit()
print('No')

Measured memory_bytes: 3060
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a, b;   //a,bは新しい予約の開始時刻と終了時刻
    int n;      //元々ある予約の個数
    int s, f;
    
    //while(true){
        cin >> a >> b;
        cin >> n;
        
        int c = 0; //予約が重複する回数
        for(int i = 1; i <= n; i++){
            cin >> s >> f;
            if((s <= a && a < f) || (s < b && b <= f) || (a <= s && f <= b)) c++;
        }
        
        if(c == 0)
            cout << "0" << endl;
        else
            cout << "1" << endl;
    //}    
}



Measured memory_bytes: 3104
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n=int(input())
    P=[int(_) for _ in input().split()]
    count=0
    min_p=10**6
    for i in range(n):
        if min_p>P[i]:
            count+=1
            min_p=P[i]
    print(count)

if __name__=='__main__':
    main()

Measured memory_bytes: 25768
N, M = map(int, input().split())
ACflags = [False] * N
WAcounts = [0] * N
for _ in range(M):
    p, s = input().split()
    p = int(p) - 1
    if ACflags[p]:
        continue
    if s == 'AC':
        ACflags[p] = True
    else:
        WAcounts[p] += 1

ansAC = 0
ansWA = 0
for i in range(N):
    if ACflags[i]:
        ansAC += 1
        ansWA += WAcounts[i]
print(ansAC, ansWA)

Measured memory_bytes: 4596
#include <stdio.h>

int main() {
  int A,B,C;
  scanf("%d %d %d",&A,&B,&C);
  if(A == B) 
    printf("%d\n",C);
  if(B == C) 
    printf("%d\n",A);
  if(A == C) 
    printf("%d\n",B);
  

  return 0;
}

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

int main(){
  int R,G,B,N;
  std::cin >> R>>G>>B>>N;
  int rm = N/R;
  int gm = N/G;
  int bm = N/B;
  int cnt=0;
  for(int i=0;i<=rm;i++){
    for(int j=0;j<=(N-i*R)/G;j++){
      if((N-i*R-j*G)%B==0){
        cnt++;
      }
    }
  }

  std::cout << cnt << '\n';
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define range(i,l,h) for(int i=l;i<h;i++)
#define endl '\n'
#define I INT_MAX
#define L INT_MIN
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define vt vector
using namespace std;
using std::ios;
constexpr int MOD=1e9+7;
constexpr int mod=998244353;
const int mxn=10000005;

int main()
{
  fastio;
  
  
 string s,t;
 cin>>s>>t;
 int n=s.size(),m=t.size();
 int ans=I;
 for(int i=0;i<n-m+1;i++)
 {
  int c=0;
  for(int j=0;j<m;j++)
  {
    if(s[i+j]!=t[j])
    {
      c++;
    }
  }
  ans=min(ans,c);
 }
 cout<<ans;
  
}


Measured memory_bytes: 3612
N, A, B = list(map(int, input().split()))
if A == B:
    print(1)
    exit()
if B < A:
    print(0)
    exit()

if N == 1:
    if A == B:
        print(1)
    else:
        print(0)
    exit()

min_val = (N - 1) * A + B
max_val = (N - 1) * B + A
print(max_val - min_val + 1)

Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

namespace PaizaTest
{
    class Program
    {
        static void Main(string[] args)
        {
            var str = Console.ReadLine();
            var centerIndex = str.Length / 2;
            // 6 / 2 = 3
            // 012345
            // abcabc
            // 7 / 2 = 3
            // 0123456
            // abcdcba
            var diffCount = 0;
            for (int i = 0; i < centerIndex; i++)
            {
                if (str[i] != str[str.Length - 1 - i])
                {
                    diffCount++;
                }
            }
            Console.WriteLine(diffCount);

        }
    }
}



Measured memory_bytes: 13140
#include <stdio.h>

int main(){
    int yen;
    scanf("%d", &yen);
    int flag = 0;
    int c=1000;
    
    if (yen <= c){
        printf("%d\n", c-yen);
    }
    else{
        while (flag == 0){
            c+=1000;
            if (yen<=c){
                printf("%d\n", c-yen);
                break;
            }
        }
    }
    
    return 0;
}


Measured memory_bytes: 1712
#include <bits/stdc++.h>
#define ll long long
#define rep(X,N) for(ll X = 0; X < (N); X++)
#define PI (acos(-1.0))
#define sorta(V) sort(V.begin(), V.end())
#define pback push_back
#define mpair make_pair
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end() 

using namespace std;

int main(){

    ll n,m;
    cin >> n >> m;

    ll ans = min(n, m / 2);

    m = m - ans * 2;

    if(m > 0){
        ans = ans + m / 4;
    }

    cout << ans << endl;

    return 0;
}

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

int main() {
  string s;
  int K;
  cin >> s >> K;
  char ans = '1';
  
  for (int i = 0; i < s.size(); i++){
    if ((s.at(i) != '1') && (i < K)) {
      ans = s.at(i);
      break;
    }
  }
  cout << ans << endl;
}

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

#define REP(i,n) for(int i = 0; i < n; i++)
#define PER(i,n) for(int i = n-1; i >= 0; i--)
#define FOR(i,l,r) for(int i = l; i <= r; i++)
#define ROF(i,l,r) for(int i = r; i >= l; i--)
#define DEBUG(x) cout << #x << "=" << x << endl;
#define SHOW1(A,n) { REP(i,n) cout<<A[i]<<(i==n-1?'\n':' '); }
#define SHOW2(A,m,n) { REP(j,m) SHOW1(A[j],n) }
#define pb push_back
#define fi first
#define se second
#define ALL(x) x.begin(),x.end()
#define SZ(x) (int)((x).size())
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
const int INF = 0x3f3f3f3f, MOD = 998244353;
const double PI = acos(-1), EPS = 1e-15;
const int MAXN = 4e5+9, MAXM = 2e5+9;

int to[MAXN],f[MAXN],nxt[MAXN],tot;
void init(){ tot=0; memset(f,-1,sizeof(f)); }
void add(int u, int v)
{
    to[tot]=v;
    nxt[tot]=f[u];
    f[u]=tot++;
}
int n,vis[MAXN];
pii bfs(int s)
{
    queue<pii> Q;
    Q.push({s,1});
    memset(vis,0,sizeof(vis));
    vis[s]=1;
    pii now;
    while (!Q.empty()) {
        now=Q.front(); Q.pop();
        int u=now.fi, t=now.se;
        for (int i=f[u]; ~i; i=nxt[i]) {
            int v=to[i];
            if (!vis[v]) {
                vis[v]=1;
                Q.push({v,t+1});
            }
        }
    }
    return now;
}

int main()
{
#ifdef LOCAL
    //freopen("i.txt", "r", stdin);
    //freopen("o.txt", "w", stdout);
#endif //LOCAL

    while (scanf("%d", &n)==1) {
        if (n==1) { puts("First"); continue; }
        init();
        REP(i,n-1) {
            int x,y; scanf("%d%d", &x,&y);
            add(x,y);
            add(y,x);
        }
        pii now=bfs(1);
        now=bfs(now.fi);
        int len=now.se;
        if (len%3==2) puts("Second");
        else puts("First");
    }

    return 0;
}






























Measured memory_bytes: 8192
import java.util.*;
 
public class Main {
	
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	int N = sc.nextInt();
    	int count = 0;
    	for (int i = 1; i <= N; i++) {
    		if (Integer.toString(i).length()%2 != 0) {
    			count++;
    		}
    	}
    	System.out.println(count);
    }
}

Measured memory_bytes: 29780
n=int(input())
h=list(map(int,input().split()))

bef=h[0]
ans=0
m=0
for i in range(1,n):
      if bef>=h[i]:
            m+=1
            ans=max(m,ans)
      else:
            m=0
      bef=h[i]
print(ans)


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

#define si(x)	scanf("%d",&x)
#define sl(x)	scanf("%lld",&x)
#define ss(s)	scanf("%s",s)
#define pi(x)	printf("%d\n",x)
#define pl(x)	printf("%lld ",x)
#define ps(s)	printf("s")
#define f(i,a,b) for(ll i=a;i<b;i++)
#define PI 3.1415926535897932384626
typedef vector<int>		vi;
typedef vector<ll>		vl;


int main() 
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());
	// your code goes here
	ll n;
	sl(n);
	f(i,0,n)printf("ACL");
	return 0;
}


Measured memory_bytes: 3148
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); ++(i))
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef pair<int, int> pii;
typedef pair<lint, int> pli;
typedef complex<double> xy_t;

const lint mod = 1e9 + 7;

int main(){
    int n;
    scanf("%d", &n);
    pii p[n];
    rep(i, n){
        int a;
        scanf("%d", &a);
        p[i] = pii(a, i+1);
    }
    sort(p, p+n);
    rep(i, n) printf("%d ", p[i].se);
}

Measured memory_bytes: 1536
import sys
input = sys.stdin.readline

N, A, B = map(int, input().split())
X = list(map(int, input().split()))

if A >= B:
    print(B*(N-1))
else:
    ans = 0
    for i in range(N-1):
        ans += min(A*(X[i+1]-X[i]), B)
    print(ans)

Measured memory_bytes: 14172
using System;
using System.Text;

namespace ConsoleApp1
{
    class Program
    {
        public static long res = long.MinValue;
        static void Main(string[] args)
        {
            var input = Console.ReadLine();
            StringBuilder sb = new StringBuilder(input);

            if (sb[0] == '?')
            {
                if (sb.Length == 1)
                    sb[0] = 'D';
                else
                {
                    if (sb[1] == 'P')
                        sb[0] = 'D';
                    else
                        sb[0] = 'P';
                }
            }

            for (int i = 1; i < sb.Length - 1; i++)
            {
                if (sb[i] == '?')
                {
                    if (sb[i - 1] == 'P')
                        sb[i] = 'D';
                    else if (sb[i + 1] == 'P')
                        sb[i] = 'D';
                    else
                        sb[i] = 'P';
                }
            }

            if (sb[sb.Length - 1] == '?')
                sb[sb.Length - 1] = 'D';


            Console.WriteLine(sb.ToString());
        }

    }
}



Measured memory_bytes: 27260
#include<bits/stdc++.h> 
using namespace std;
int main()
{
  	int n;
  	cin >> n;
  	long long ans = 0;
  	for(int i = 1 ; i <= n ; i++)
    {
  	  	long long a , b;
      	cin >> a >> b;
      	ans += (b - a + 1);
    }
  	cout << ans << endl;
  return 0; 
}

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

int main(void){

  int data_num;
  int input;
  int i;

  int min;
  int max;
  long int sum;

  min =  1000000;
  max = -1000000;
  sum = 0;

  cin >> data_num;

  for (i = 0 ; i < data_num ; i++){
    cin >> input;

    if ( input < min){
      min = input;
    }

    if(input > max){
      max = input;
    }

    sum += input;

  }

  cout << min << " " << max << " " << sum << endl;

  return 0;

}

Measured memory_bytes: 3092
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()
ll MOD = 1000000007;
const ll INF = 1LL << 62;

int main() {
  //
  ll n;
  cin >> n;
  vl a(n);
  ll m = INT_MAX, M = INT_MIN;
  ll mi = -1, Mi = -1;
  rep(i, n) {
    cin >> a[i];
    if (m > a[i]) {
      m = a[i], mi = i;
    }
    if (M < a[i]) {
      M = a[i], Mi = i;
    }
  }
  vector<pll> op;
  if (M < 0) {
    for (int i = n - 1; i > 0; i--) {
      if (a[i - 1] > a[i]) {
        a[i - 1] += a[i];
        op.push_back({i, i - 1});
      }
    }
  } else if (m > 0) {
    rep(i, n - 1) {
      if (a[i] > a[i + 1]) {
        a[i + 1] += a[i];
        op.push_back({i, i + 1});
      }
    }
  } else {
    //
    if (abs(m) > abs(M)) {
      rep(i, n) {
        a[i] += a[mi];
        op.push_back({mi, i});
      }
      for (int i = n - 1; i > 0; i--) {
        if (a[i - 1] > a[i]) {
          a[i - 1] += a[i];
          op.push_back({i, i - 1});
        }
      }
    } else {
      rep(i, n) {
        a[i] += a[Mi];
        op.push_back({Mi, i});
      }
      rep(i, n - 1) {
        if (a[i] > a[i + 1]) {
          a[i + 1] += a[i];
          op.push_back({i, i + 1});
        }
      }
    }
  }

  cout << op.size() << endl;
  for (auto& o : op) {
    cout << o.first + 1 << " " << o.second + 1 << endl;
  }
  return 0;
}


Measured memory_bytes: 256
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n = sc.nextInt()
  val e = List.fill(n-1)((sc.nextInt()-1, sc.nextInt()-1))
  val adj = Array.fill(n)(List[Int]())
  for ((a, b) <- e) {
    adj(a) ::= b
    adj(b) ::= a
  }
  val visited = Array.fill(n)(false)
  var count1 = 0
  var count2 = 0
  var s1Old = List[Int]()
  var s1New = List(0)
  var s2Old = List[Int]()
  var s2New = List(n-1)
  while (s1New.nonEmpty || s2New.nonEmpty) {
    s1Old = s1New
    s1New = Nil
    for (u <- s1Old if !visited(u)) {
      visited(u) = true
      count1 += 1
      for (v <- adj(u)) {
        s1New ::= v
      }
    }

    s2Old = s2New
    s2New = Nil
    for (u <- s2Old if !visited(u)) {
      visited(u) = true
      count2 += 1
      for (v <- adj(u)) {
        s2New ::= v
      }
    }
  }

  println(if (count1 > count2) "Fennec" else "Snuke")
}


Measured memory_bytes: 74744
#include <algorithm>
#include <iostream>
#include <cstring>
#include <vector>
#include <set>
using namespace std;

typedef long long ll;
typedef pair <ll, ll> pii;

const ll MAX_N = 1e3 + 3, MOD = 1e9 + 7;
ll A, B, K;
string S, T;

int main() {
    ios::sync_with_stdio(false), cin.tie(0);
    cin >> A >> B >> K;
    if (K <= A)
        A -= K;
    else {
        K -= A;
        A = 0;
        B = max(0LL, B - K);
    }

    cout << A << " " << B << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
#define maxN 200005
#define mod 1000000007
#define pi 3.14159265358979323846264338327950

void solve()
{
    map<ll, ll> all;
    ll n, q;
    ll sum = 0;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        ll temp;
        cin >> temp;
        sum += temp;
        all[temp]++;
    }
    cin >> q;
    for (int i = 0; i < q; i++)
    {
        ll origin, replace;
        cin >> origin >> replace;
        if (all[origin] == 0)
        {
            cout << sum << endl;
            continue;
        }
        else
        {
            sum -= origin * all[origin];
            sum += replace * all[origin];
            all[replace] += all[origin];
            all[origin] = 0;
            cout << sum << endl;
        }
    }
}

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

Measured memory_bytes: 9316
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <string>
#define shosu(x) fixed<<setprecision(x)
using namespace std;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,P> pip;
typedef long long ll;
const int inf=1<<30;
const double pi=acos(-1);

int n;

int main(){
	while(1){
		cin>>n;
		if(!n) break;
		int ans=0;
		for(int i=5;i<=n;i*=5){
			for(int j=1;i*j<=n;j++) ans++;
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 1160
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <climits>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <sstream>
#include <vector>
#include <map>
#include <set>
#include <complex>
#include <functional>
#include <utility>
#include <iterator>

#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, m, n) for(int i = (m); i < (int)(n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define INF 2000000000

#ifdef LOCAL
  #define dprintf(...) fprintf(stdout, __VA_ARGS__)
#else
  #define dprintf(...) 0
#endif

using namespace std;

int main() {
  int a, b, c, d, e, k;
  cin >> a >> b >> c >> d >> e >> k;

  if(e - a <= k) {
    cout << "Yay!" << '\n';
  }
  else {
    cout << ":(" << '\n';
  }

  return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;
typedef long long ll;
ll mod = 1000000007,dp[30][1<<22] = {},a[30][30];
int main(){
	int i,j,k,n;
	cin >> n;
	for(i=0;i<n;i++){
		for(j=0;j<n;j++){
			cin >> a[i][j];
		}
	}
	dp[0][0] = 1;
	for(i=1;i<=n;i++){
		for(j=0;j<(1<<n);j++){
			if(__builtin_popcount(j)!=i-1) continue;
			for(k=0;k<n;k++){
				if((1<<k) & j) continue;
				if(!a[i-1][k]) continue;
				(dp[i][j|(1<<k)] += dp[i-1][j]) %= mod;
			}
		}
	}
	cout << dp[n][(1<<n)-1] << endl;
}

Measured memory_bytes: 323840
#include<bits/stdc++.h>
        using namespace std;
        #define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
        #define pb push_back
        #define ff first
        #define ss second
        #define sz size()
        #define mp make_pair
        #define p(x) cout<< x << " ";
        #define pe(x) cout<< x << endl ;
        #define int long long
        #define double long double
        #define FOR(i,a,b) for(int i=a;i<b;i++)
        #define ROR(i,a,b) for(int i=a;i>=b;i--)
        const int N = 1e7 + 1;
        #define MOD 1000000007
        
        int32_t main()
        {
            FAST
            int n,a,b;
            cin>>n>>a>>b;
            cout<<(int)min(n*a,b);
            
        }

Measured memory_bytes: 256
#include<iostream>

using namespace std;
int prime[100000];

int main(){

   for(int i=0; i<100000; i++) prime[i]=1;
   prime[0]=prime[1]=0;
   for(int i=2; i*i<=100000; i++){
      for(int j=2; i*j<100000; j++){
         if(prime[i]){
            prime[i*j]=0;
         }
      }
   }

   while(1){
      int m, a, b;
      cin>> m>> a>> b;
      if(!m) break;

      for(int M=m; M>0; M--){
         for(int p=2; p*p<=M; p++){
            if(prime[p]&&(M%p==0)){
               int q=M/p;
               if(a*q<=b*p&&p<=q&&prime[q]){
                  cout<< p<< " "<< q<< endl;
                  goto next;
               }
            }
         }
      }

      next:;
   }

   return 0;
}

Measured memory_bytes: 3452
gets.to_i.times do
  n = gets.split.map(&:to_i)
  c = gets.split
  color = {}
  color["R"] = [0]*9
  color["G"] = [0]*9
  color["B"] = [0]*9
  9.times{ |i| color[c[i]][n[i]-1] += 1 }
  ret = 0
  ["R", "G", "B"].each do |s|
    7.times do |i|
      if color[s][i,3].all?{ |v| v >= 1 }
        while color[s][i,3].all?{ |v| v >= 1 }
          3.times{ |j| color[s][i+j] -= 1}
          ret += 1
        end
      end
    end
    9.times do |i|
      if color[s][i] >= 3
        ret += color[s][i] / 3
      end
    end
  end
  if ret == 3 then puts 1
  else puts 0
  end
end

Measured memory_bytes: 8744
n = gets.chomp.to_i
facts = gets.chomp.split(' ').map(&:to_i)

facts.sort!
value = 0
(1..(facts.length - 1)).each do |i|
  if i == 1
    value = ((facts[0] + facts[i])/2.0).to_f
  else
    value = ((value + facts[i])/2.0).to_f
  end
end
puts "#{value}"


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

int main() {
	int N;
	cin >> N;
	string S;
	cin >> S;

	int cnt = 0;
	rep(i, N - 2) {
		if(S[i] == 'A' && S[i + 1] == 'B' && S[i + 2] == 'C')
			cnt++;
	}

	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define lli long long int
#define REP(i,s,l) for(lli i=s;i<l;i++)
#define DEBUG 0
#define INF (1LL<<50)

signed main(){

	lli n,k;
	string s;
	cin>>n>>k;
	cin>>s;

	/*飛ばし飛ばしで技をつかうのはありえない*/
	/*連続で使うとどれだけ伸びるか？*/
	/*配列に白黒白黒・・・白の連続長を入れる*/
	/*端に白がない場合は0を入力する*/
	vector<lli> data;
	lli length=0;
	char before = '1';
	REP(i,0,n){
		if(s[i] != before){
			data.push_back(length);
			length=0;
		}
		length++;
		
		before = s[i];
	}
	data.push_back(length);
	if(s[n-1]=='0')data.push_back(0);

	if(DEBUG){
		REP(i,0,data.size())cout<<data[i]<<endl;
	}

	lli ans= data[0];
	lli sum = data[0];
	lli cnt=0;
	for(lli i=1;i<data.size();i+=2){
		sum += (data[i]+data[i+1]);
		if(cnt>=k){
			sum -= (data[i-2*k-1]+data[i-2*k]);
		}
		cnt++;
		ans = max(ans,sum);
	}
	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 1528
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
using namespace std;

#define max(a,b) ((a>b)?(a):(b))
#define min(a,b) ((a<b)?(a):(b))

int main(){
  int n,m;
  cin >> n >> m;
  vector<int> ok(n),kosuu(n);
  for(int i=0;i<n;i++){
    ok[i]=0;
    kosuu[i]=1;
  }
  ok[0]=1;

  int x,y;
  for(int i=0;i<m;i++){
      cin >> x >> y;
      x--;
      y--;
      kosuu[x]--;
      kosuu[y]++;
      if(ok[x]){
        ok[y]=1;
      }
      if(!kosuu[x]){
        ok[x]=0;
      }
  }
  int ans=0;
  for(int i=0;i<n;i++){
    if(ok[i]){
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1152
def main()
  n = gets.chomp.to_i
  dic = Hash.new(0)
  ans = 0
  for i in 0..n-1 do
    x = gets.chomp.to_i
    if dic[x] == 0
      dic[x] = 1
    else
      dic[x] = 0
    end
  end

  dic.each_value{|t|
  ans = ans + 1 if t == 1
  }
  puts ans
end

main()

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

#include <iostream>
#include <fstream>

#include <iostream>
#include <vector>
#include <set>

class MinimumSum {
public:
	void solve(std::istream& in, std::ostream& out) {
		int n;
		in >> n;
		std::vector<int> permutation(n);
		for (int i = 0; i < n; i++) {
			in >> permutation[i];
			--permutation[i];
		}
		std::set<int> used_indeces;
		std::vector<int> reversed(n);
		for (int i = 0; i < n; i++)
			reversed[permutation[i]] = i;
		long long result = 0;
		for (int i = 0; i < n; i++) {
			int current_index = reversed[i];
			auto right_it = used_indeces.lower_bound(current_index);
			long long left_index = 0, right_index = n - 1;
			if (right_it != used_indeces.end()) {
				right_index = *right_it - 1;
			}
			if (right_it != used_indeces.begin()) {
				--right_it;
				left_index = *right_it + 1;
			}
			used_indeces.insert(current_index);
			long long count = (right_index - current_index + 1) * (current_index - left_index + 1);
			//out << i << " " << left_index << " " << right_index << " " << count << " " << result << "\n";
			result += (i + 1) * count;
		}
		out << result << "\n";
	}
};


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


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

int main() {
    
    int n;
    int min = 1000000;
    int max = -1000000;
    long long sum = 0;
    
    cin >> n;

for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    
    if (x < min) {
        min = x;
        
    }
    
    if (x > max) {
        max = x;
        
    }
    
    sum += x;
}
    cout << min << " " << max << " " << sum << endl;
    return 0;
}



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

const int N = 2e5 + 5;
const int K = 3;

int dp[N][K + 1];

bool eq(string & s, int pos, int t1, int t2)
{
    if (t1 != t2) return false;
    if (pos + 1 < t1 + t2) return false;
    for (int i = 0; i < t1; ++i)
        if (s[pos - t1 + 1 + i] != s[pos - t1 - t2 + 1 + i])
            return false;
    return true;
}

int main()
{
    //freopen("input.txt", "r", stdin);

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

    if (n == 1)
    {
        cout << 1;
        return 0;
    }

    for (int t = 1; t <= K; ++t)
        dp[0][t] = 0;

    for (int i = 0; i < n; ++i)
    {
        for (int t1 = 1; t1 <= K; ++t1)
        {
            dp[i + 1][t1] = -N;
            if (i + 1 < t1) continue;
            for (int t2 = 1; t2 <= K; ++t2)
            {
                if (!eq(s, i, t1, t2))
                {
                    dp[i + 1][t1] = max(dp[i + 1][t1], 1 + dp[i + 1 - t1][t2]);
                }
            }
        }
    }

    int ans = 0;
    for (int t = 1; t <= K; ++t)
        ans = max(ans, dp[n][t]);
    cout << ans;
}


Measured memory_bytes: 3716