akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric>
#include <cctype>
#include <tuple>
#include <climits>
#include <bitset>
#include <cassert>
#include <random>
#include <complex>

#ifdef _MSC_VER
#include <agents.h>
#endif

#define FOR(i, a, b) for(int i = (a); i < (int)(b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define REV(v) v.rbegin(), v.rend()
#define MEMSET(v, s) memset(v, s, sizeof(v))
#define UNIQUE(v) (v).erase(unique(ALL(v)), (v).end())
#define MP make_pair
#define MT make_tuple

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

int dist[1 << 16];

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

	int n;
	cin >> n;
	vector<int> h(n), w(n);
	rep(i, n) cin >> h[i] >> w[i];
	vector<string> board(4);
	rep(i, 4) cin >> board[i];

	set<P> x;
	rep(i, n) rep(r, 8) rep(c, 8) for(char col: string("RGB")){
		int mask = 0;
		int ok = 0;

		char b[12][12] = {};
		for (int j = r; j < r + h[i]; ++j){
			for (int k = c; k < c + w[i]; ++k){
				b[j][k] = col;
			}
		}
		for (int j = 4; j < 8; ++j){
			for (int k = 4; k < 8; ++k){
				if (!b[j][k]) continue;
				int y = 1 << ((j - 4) * 4 + k - 4);
				mask |= y;
				if (b[j][k] == board[j - 4][k - 4]) ok |= y;
			}
		}
		x.insert(MP(mask, ok));
	}

	queue<int> q;
	q.push(0);
	MEMSET(dist, -1);
	dist[0] = 0;
	while (!q.empty()){
		int s = q.front();
		q.pop();

		for (auto p : x){
			int nxt = (s&~p.first) | p.second;
			if (dist[nxt] >= 0) continue;
			dist[nxt] = dist[s] + 1;
			if (nxt + 1 == (1 << 16)){
				cout << dist[nxt] << endl;
				return 0;
			}
			q.push(nxt);
		}
	}
	cout << -1 << endl;
	
	return 0;
}

Measured memory_bytes: 1644
#include<bits/stdc++.h>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
#define endl  "\n"
#define ll long long
#define int long long
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cin.exceptions(cin.failbit);cout.tie(NULL);
using namespace std;
bool isPrime(int n)
{
    if (n <= 1)
        return false;
    if (n <= 3)
        return true;
    if (n % 2 == 0 || n % 3 == 0)
        return false;
    for (int i = 5; i * i <= n; i += 6)
    {
        if ((n % i == 0) || (n % (i + 2) == 0))
            return false;
    }
    return true;
}
int32_t main()
{
	int n,k;
	cin >> n >> k;
	int a[n];
	for(int i=0;i<n;i++)
	cin >> a[i];
	
	sort(a,a+n);
	int s=0;
	for(int i=0;i<k;i++)
	s+=a[i];
	
	cout << s;
}



Measured memory_bytes: 3604
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
    int n;
	cin>>n;
	int p[300030];
	for(int i=0; i<n; i++){
		cin>>p[i];
		p[i]--;
	}
	for(int i=0; i<n; i++){
		if((p[i]&1)!=(i&1)){
			cout<<"No"<<endl;
			return 0;
		}
	}
	set<int> st[2];
	for(int i=0; i<n; i++) st[i&1].insert(i);
	int x[2]={}, y[2]={};
	for(int i=0; i<n; i++){
		int a=*st[i&1].begin();
		if(p[i]==a){
			st[i&1].erase(st[i&1].begin());
			continue;
		}
		if(p[i]<x[i&1] || i<y[i&1]){
			cout<<"No"<<endl;
			return 0;
		}
		st[i&1].erase(p[i]);
		x[(i&1)^1]=max(x[(i&1)^1], p[i]+3);
		x[i&1]=max(x[i&1], p[i]+2);
		y[(i&1)^1]=max(y[(i&1)^1], p[i]+1);
	}
	cout<<"Yes"<<endl;
	return 0;
}


Measured memory_bytes: 15488
#include <bits/stdc++.h>
#define FLASH ios_base::sync_with_stdio(0);
#define ll long long
#define debt(x,y)cout<<"#x = "<<(x)<<" and "<<"#y = "<<(y)<<endl;
#define deb(x)cout<<"#x = "<<(x)<<endl;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define endl "\n"
#define arr(a,n) for(ll i=1;i<=n;i++) cout<<a[i]<<" "; cout << "\n";
#define vecc(a,n) for(ll i=0;i<n;i++) cout<<a[i]<<" "; cout << "\n";


using namespace std;

ll a,b,k;

int main(){
FLASH;
cin>>a>>b>>k;
ll raz=b-a+1;
if(raz<=k)
{
  for(ll i=a;i<=b;i++)cout<<i<<endl;	
}
else
{
  set<ll>el;
  for(ll i=a;i<a+k;i++)el.insert(i);
  for(ll i=b;i>=b-k+1;i--)el.insert(i);
  for(auto i:el)cout<<i<<endl;	
}







return 0;
} 


Measured memory_bytes: 3600
import math
from math import gcd,pi,sqrt
INF = float("inf")

import sys
sys.setrecursionlimit(10**6)
import itertools
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]

def main():
    a,b,x = i_map()
    if a*a*b<x*2:
        water_y = x/a**2
        left_y = b-water_y
        half_x = a/2
        d = math.degrees(math.atan(left_y/half_x))
        print(d)
    else:
        c = (x*2)/(a*b)
        c = math.degrees(math.atan(b/c))
        print(c)


if __name__=="__main__":
    main()


Measured memory_bytes: 9620
import javax.swing.*;
import javax.swing.plaf.synth.SynthSpinnerUI;
import java.sql.SQLOutput;
import java.util.Scanner;
import java.util.function.DoubleToIntFunction;

public class Main {

    public static void main(String[] args) {

        Scanner scan = new Scanner(System.in);
        int a = scan.nextInt();
        int b = scan.nextInt();
        int c = scan.nextInt();
        int x = 0;
        for(int i = a ; i <= b  ; i++){
            if(c % i == 0){
                x++;
            }else{
                continue;
            }
        }
        System.out.println(x);
    }
}


Measured memory_bytes: 26276
import re
from itertools import groupby
from itertools import groupby, combinations
import functools
import operator

pattern = r"^(M|A|R|C|H).*"
checker = re.compile(pattern)

N = int(input())
names = []
for i in range(N):
    name = input()
    if checker.match(name):
        names.append(name)
        
counts = {}
for group, item in groupby(names, lambda x:x[0]):
    counts[group] = counts[group]+(len(list(item))) if group in counts.keys() else (len(list(item)))
# print(counts)
total = 0
for comb in combinations(counts.keys(), 3):
    tmp = []
    for letter in comb:
        tmp.append(counts[letter])
#     print(comb)
    n_comb = functools.reduce(operator.mul, tmp)
    total += n_comb
    
print(total)

Measured memory_bytes: 11260
#include<bits/stdc++.h>
#define ll long long
#define pii pair<ll,ll>
#define piii pair<ll, pii>
#define MOD 1000000007
#define M 105
#define N 100005
#define inf 1000000001
using namespace std;
ll n,k;
ll arr[M], dp[N]; // k

void solve(){
    // 0 means 2nd player and 1 means 1st player
    // if there is no element in the pile , 1st player will have nothing to take
    // and 2nd player will always win

    for(ll i =0;i<k;i++){ // height of pile
        for(ll j = 1;j <=n;j++){ // no of element
            if(i+arr[j]<=k && !dp[i]) {
                dp[i+arr[j]] = 1;
            }
        }//cout<< endl;
    }
    if(dp[k]) cout << "First\n";
    else cout << "Second\n";
    //cout<< setprecision(10)<< ans<< endl;
}


int main(){
    //ll t; cin>> t; while(t--){
        cin>> n>>k;
        for(ll i =1;i<=n;i++){ // no of item
            cin>> arr[i];
        }
        solve();
}


Measured memory_bytes: 1024
from operator import mul
from functools import reduce
import sys
input = sys.stdin.readline


def cmb(n,r):
    r = min(n-r,r)
    if r < 0: return 0
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under


def main():
    N, K = map(int, input().split())

    for i in range(1, K+1):
        # a: 青いボールを i グループに分割する組合せ
        a = cmb(K-1, i-1)
        # b: 各グループを赤いボールの間(端もOK)に挿入する組合せ
        b = cmb(N-K+1, i)

        print(a*b % 1000000007)

 
if __name__ == '__main__':
    main()


Measured memory_bytes: 3944
#include<bits/stdc++.h>
using namespace std;
const int mxn=3333;
string f[mxn];
char s[mxn<<1];
int s1[mxn],s2[mxn],n,pos[mxn<<1],t1,t2;
int main(){
	scanf("%d%s",&n,s+1);
	for(int i=1;i<=n<<1;++i){
		if(s[i]=='a')s1[++t1]=i,pos[i]=t1;
		else s2[++t2]=i,pos[i]=t2;
	}
	string ans="";
	for(int i=n;i;--i){
		if(s1[i]<s2[i]){
			int k=i;
			for(int j=s1[i]+1;j<s2[i];++j)k=max(k,pos[j]);
			f[i]="ab"+f[k+1];
		}else{
			int k=i;
			while(k<n and s2[k+1]<s1[k])++k;
			for(int j=s2[i];j<=n<<1;++j)if(i<=pos[j] and pos[j]<=k)f[i]+=s[j];
			f[i]+=f[k+1];
		}
		f[i]=max(f[i],f[i+1]);
		ans=max(ans,f[i]);
	}
	printf("%s\n",ans.c_str());
}

Measured memory_bytes: 14592
typedef long unsigned int size_t;
extern int printf (const char *__restrict __format, ...);
extern int scanf (const char *__restrict __format, ...) ;
extern int getchar (void);
extern int putchar (int __c);
int nextInt(){int f=0;char s=0;char c=getchar();while((c<48)||(57<c)){if(c==45){s=1;c=getchar();break;}c=getchar();}while((48<=c)&&(c<=57)){f=f*10+(c-48);c=getchar();}return s?-f:f;}
char nextChar(){char f=0;char s=0;char c=getchar();while((c<48)||(57<c)){if(c==45){s=1;c=getchar();break;}c=getchar();}while((48<=c)&&(c<=57)){f=f*10+(c-48);c=getchar();}return s?-f:f;}
short int nextShort(){short f=0;char s=0;char c=getchar();while((c<48)||(57<c)){if(c==45){s=1;c=getchar();break;}c=getchar();}while((48<=c)&&(c<=57)){f=f*10+(c-48);c=getchar();}return s?-f:f;}
long long int nextLong(){long long int f=0;char s=0;char c=getchar();while((c<48)||(57<c)){if(c==45){s=1;c=getchar();break;}c=getchar();}while((48<=c)&&(c<=57)){f=f*10+(c-48);c=getchar();}return s?-f:f;}
void println(){putchar(10);}
void print(char *f){while(*f){putchar(*f);f++;}}
void printInt(int f){char c[10];if(!f){putchar(48);return;}if(f<0){f=-f;putchar(45);}char i=0;while(f){c[++i]=(f%10)+48;f/=10;}while(i){putchar(c[i--]);}}
void printLong(long long int f){char c[19];if(!f){putchar(48);return;}if(f<0){f=-f;putchar(45);}char i=0;while(f){c[++i]=(f%10)+48;f/=10;}while(i){putchar(c[i--]);}}
typedef int (*__compar_fn_t) (const void *, const void *);
extern void *bsearch (const void *__key, const void *__base, size_t __nmemb, size_t __size, __compar_fn_t __compar)__attribute__ ((__nonnull__ (1, 2, 5))) ;
extern void qsort (void *__base, size_t __nmemb, size_t __size, __compar_fn_t __compar) __attribute__ ((__nonnull__ (1, 4)));
int compare_int(const void *a, const void *b){return *(int*)a - *(int*)b;}
int compare_char(const void *a, const void *b){return *(char*)a - *(char*)b;}
int compare_short(const void *a, const void *b){return *(short*)a - *(short*)b;}
int compare_long(const void *a, const void *b){if(*(long long int*)a - *(long long int*)b < 0){return -1;}else if(*(long long int*)a - *(long long int*)b > 0){return 1;}else{return 0;}}
int min2(int a, int b){return a>b?b:a;}
char n, i;
char a[200], ans, j;
int min, now;
int main(){
 n = nextChar();
 for(i=0; i<n; i++){
  a[i] = nextChar();
 }
 min = 1073741824;
 for(j=-100; j<=100; j++){
  now = 0;
  for(i=0; i<n; i++){
   now += ((int)a[i]-j)*(a[i]-j);
  }
  if(now<min){min=now; ans=j;}
 }
 printInt(min);
 println();
}


Measured memory_bytes: 128
using System;

class main
{
    static void Main(String[] args)
    {
        while (true)
        {
            string s = Console.ReadLine();           
            if (s != null)
            {
                int q = 0;
                int n = int.Parse(s);
                for (int a = 0; a < 10; a++)
                {
                    for (int b = 0; b < 10; b++)
                    {
                        for (int c = 0; c < 10; c++)
                        {
                            for (int d = 0; d < 10; d++)
                            {
                                if (a + b + c + d == n)
                                {
                                    q++;
                                }
                            }
                        }
                    }
                }
                Console.WriteLine(q);
            }
            if (s == null)
            {
                break;
            }
        }
        Console.ReadKey();
    }
}

Measured memory_bytes: 5608
from collections import Counter

n,k=map(int,input().split())
l=[int(i) for i in input().split()]
c=Counter(l).most_common()
if len(c)<=k:
    ans=0
else:
    sum=0
    for i in range(0,k):
        sum+=c[i][1]
        ans=n-sum

print(ans)


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

#define rep(i,a,b) for(long long int i=a; i<b; i++ )
#define REP(i,n) rep(i,0,n)

int judge(string s)
{
  int out = 1;
  int n = s.size();
  REP(i, n){
    if( s[i] != s[(2*n-1-i)%n] ){
      out = 0; break;
    }
  }
  return out;
}

int main()
{
  string S1; cin >> S1;
  int N = S1.size();
  string S2 = S1.substr( 0, (N-1)/2);
  string S3 = S1.substr( (N+3)/2-1, N - (N+3)/2 + 1);

  if( judge(S1) == 1 && judge(S2) == 1 && judge(S3) == 1 ){ cout << "Yes" << endl; }
  else{ cout << "No" << endl; }
  return 0;
}

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

#define NIL -1
int a[11][101][11];

int dp(int n,int s,int t){
    if(a[n][s][t]== NIL ){
        if(t==10 || (n==1 && (s<t ||9<s))){
            a[n][s][t]=0;
        }else if(n==1){
            a[n][s][t]=1;
        }else{
            a[n][s][t]=dp(n-1,s-t,t+1)+dp(n,s,t+1);
        }
    }
    return a[n][s][t];
}

int main(){
    int n,s;
    scanf("%d %d",&n,&s);
    while(n!=0 || s!=0){
        for(int i=0;i<=10;i++)for(int j=0;j<=100;j++)for(int k=0;k<=10;k++)a[i][j][k]=NIL;
        printf("%d\n",dp(n,s,0));
        scanf("%d %d",&n,&s);
    }
    
    return 0;
}

Measured memory_bytes: 2768
#include <iostream>
#include <string>

int main(){
  std::string S;
  std::cin >> S;
  if(S[2] == S[3]){
    if(S[4] == S[5]){
      std::cout << "Yes" << std::endl;
      return 0;
    }
  }
  std::cout << "No" << std::endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main(){int N; cin >> N;
           vector<int> A(N);
           for(int i = 0; i < N; i++){ cin >> A[i];}
           sort(A.begin(),A.end());
          cout << A[A.size() - 1] - A[0] << endl;}
           

Measured memory_bytes: 256
n = int(input())
ans = float("inf")
for n_nine in range(0, n//9 + 1):
    s = n - 9 * n_nine
    n_six = s // 6
    n_one = s - 6 * n_six
    n_nine2 = 0
    n_six2 = 0
    pow_nine = 5
    pow_six = 6
    
    while n_nine >= 9:
        if n_nine >= 9 ** (pow_nine - 1):
            n_nine -= 9 ** (pow_nine - 1)
            n_nine2 += 1
        else:
          pow_nine -= 1

    while n_six >= 6:
        if n_six >= 6 ** (pow_six - 1):
            n_six -= 6 ** (pow_six - 1)
            n_six2 += 1
        else:
          pow_six -= 1          
          
    ans = min(ans, n_nine2 + n_nine + n_six2 + n_six + n_one)
          
print(ans)

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

#define dump(...) cout<<"# "<<#__VA_ARGS__<<'='<<(__VA_ARGS__)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}

template<typename Tuple>
void print_tuple(ostream&,const Tuple&){}
template<typename Car,typename... Cdr,typename Tuple>
void print_tuple(ostream& os,const Tuple& t){
	print_tuple<Cdr...>(os,t);
	os<<(sizeof...(Cdr)?",":"")<<get<sizeof...(Cdr)>(t);
}
template<typename... Args>
ostream& operator<<(ostream& os,const tuple<Args...>& t){
	print_tuple<Args...>(os<<'(',t);
	return os<<')';
}

template<typename Ch,typename Tr,typename C>
basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){
	os<<'[';
	for(auto i=begin(c);i!=end(c);++i)
		os<<(i==begin(c)?"":" ")<<*i;
	return os<<']';
}

constexpr int INF=1e9;
constexpr int MOD=1e9+7;
constexpr double EPS=1e-9;

const string mamoru="mamoru";
const string tameru="tameru";
const string kougekida="kougekida";

const string winner[2]={"Isono-kun","Nakajima-kun"};
const string hikiwake="Hikiwake-kun";

string solve(vector<vs> hs)
{
	vi ps(2);
	rep(i,hs[0].size()){
		rep(j,2){
			if(hs[j][i]==kougekida && ps[j]==0)
				if(!(ps[!j]==0 && hs[!j][i]==kougekida))
					return winner[!j];
		}
		rep(j,2){
			if(hs[j][i]==tameru){
				if(hs[!j][i]==kougekida)
					return winner[!j];
			}
			if(hs[j][i]==mamoru){
				if(hs[!j][i]==kougekida && ps[!j]==5)
					return winner[!j];
			}
			if(hs[j][i]==kougekida){
				if(hs[!j][i]==kougekida){
					if(ps[j]>ps[!j])
						return winner[j];
					if(ps[j]<ps[!j])
						return winner[!j];
				}
			}
		}
		rep(j,2){
			if(hs[j][i]==tameru) ps[j]=min(ps[j]+1,5);
			if(hs[j][i]==kougekida) ps[j]=0;
		}
	}
	return hikiwake;
}

int main()
{
	for(int k;cin>>k && k;){
		vector<vs> hs(2,vs(k));
		rep(i,2) rep(j,k) cin>>hs[i][j];
		cout<<solve(hs)<<endl;
	}
}

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

#define debug(x) cout << #x << "=" << x << '\n'
#define debug2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << '\n'
#define forn(i, a, b) for(int i = int(a); i < int(b); i++)
#define forn_r(i, b, a) for(int i = int(b); i > int(a); i--)
#define printArray(arr, len) for(int i = 0; i < len; i++) cout << arr[i] << (i == len - 1 ? '\n' : ' ')

void test_case() {
    long long n, d;
    cin >> n >> d;
    
    long long x, y;
    int cnt = 0;
    while(n--) {
    	cin >> x >> y;
	    if((x * x) + (y * y) <= (d * d)) {
	    	cnt++;
	    }
    }
	cout << cnt << '\n';

    return;
}

int main() {
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);

    // int t;
    // cin >> t;

    // while(t--) {
        test_case();
    // }
    
    return 0;
}


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

vector<int>q[100010];
int color[100010],n;

void dfs(int r ,int id){
	color[r]=id;
	stack<int>s;
	s.push(r);
	while(!s.empty()){
		int u=s.top();s.pop();
		for(int i=0;i<q[u].size();i++){
			int v=q[u][i];
			if(color[v]==-1){
				color[v]=id;
				s.push(v);
			}
		}
	}
}
void paint(){
	int id=1;
	for(int i=0;i<n;i++){
		if(color[i]==-1){
			dfs(i,id);
			id++;
		}
	}
}

int main() {
	int m;
	cin>>n>>m;
	for(int i=0;i<m;i++){
		int s,t;
		cin>>s>>t;
		q[s].push_back(t);
		q[t].push_back(s);
	}
	for(int i=0;i<n;i++){
		color[i]=-1;
	}
	paint();
	int k;
	cin>>k;
	for(int i=0;i<k;i++){
		int s,t;
		cin>>s>>t;
		cout<< (color[s]==color[t]? "yes":"no");
		cout<<endl;
	}
	return 0;
}


Measured memory_bytes: 8904
import sys;sys.setrecursionlimit(10**9)
class u():#UnionFind f-根探し u-連結 s-連結? c-要素数
  def __init__(self,n):self.n,self.r=[-1]*n,[0]*n
  def f(self,x):
    if self.n[x]<0:return x
    else:self.n[x]=self.f(self.n[x]);return self.n[x]
  def u(self,x,y):
    x,y=self.f(x),self.f(y)
    if x==y:return
    elif self.r[x]>self.r[y]:self.n[x]+=self.n[y];self.n[y]=x
    else:self.n[y]+=self.n[x];self.n[x]=y;self.r[y]+=self.r[x]==self.r[y]
  def s(self,x,y):return self.f(x)==self.f(y)
  def c(self,x):return -self.n[self.f(x)]
n,m=map(int,input().split());u=u(n)
for i in range(m):
  a,b,c=map(int,input().split());a-=1;b-=1
  if not(u.s(a,b)):n-=1;u.u(a,b)
print(n)

Measured memory_bytes: 7700
#include<stdio.h>
int main(void)
{
	int n,m,a,b,c[50],i;
	scanf("%d %d",&n,&m);
	for(i=0;i<n;i++){
		c[i]=0;
	}
	for(i=0;i<m;i++){
		scanf("%d %d",&a,&b);
		c[a-1]++;
		c[b-1]++;
	}
	for(i=0;i<n;i++){
		printf("%d\n",c[i]);
	}
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

const long long HASH_BASE = 1e3 + 7;
const long long HASH_MOD = 1e9 + 7;
vector<long long> hash_val;
vector<long long> hash_pow;

void init_hash(string& s)
{
	hash_val.resize(s.size() + 1);
	hash_pow.resize(s.size() + 1);

	hash_val[0] = 0;
	hash_pow[0] = 1;
	for(int i = 0; i < s.size(); ++i)
	{
		hash_val[i + 1] = (hash_val[i] * HASH_BASE + s[i]) % HASH_MOD;
		hash_pow[i + 1] = (hash_pow[i] * HASH_BASE) % HASH_MOD;
	}
}

// [from, to)
long long get_hash(int from, int to)
{
	return ((hash_val[to] - hash_val[from] * hash_pow[to - from]) % HASH_MOD + HASH_MOD) % HASH_MOD;
}

int rolling_hash(string& s, string& t)
{
	int index = 0;

	long long t_hash = 0;
	for(int i = 0; i < t.size(); ++i)
	{
		t_hash = (t_hash * HASH_BASE + t[i]) % HASH_MOD;
	}

	for(int i = 0; i < s.size() - t.size() + 1; ++i)
	{
		if(get_hash(i, i + t.size()) == t_hash)
		{
			index = i;
		}
	}

	return index;
}

bool check(string& s, int len)
{
	for(int i = 0; i < s.size() - len; ++i)
	{
		string t = s.substr(i, len);
		if(rolling_hash(s, t) >= i + len)
		{
			return true;
		}
	}

	return false;
}

int main()
{
	int n;
	string s, t;

	cin >> n >> s;

	init_hash(s);

	int l = 0, r = s.size();
	while(r - l > 1)
	{
		int m = (l + r) / 2;
		if(check(s, m))
		{
			l = m;
		}
		else
		{
			r = m - 1;
		}
	}

	cout << (check(s, l + 1) ? l + 1 : l) << endl;

	return 0;
}

Measured memory_bytes: 384
n = gets.to_i
b = gets.split(' ').map{|x| x.to_i}
a = Array.new(n, 0)
(n-1).times do |i|
  if i == 0
    a[i] = a[i+1] = b[i]
  else
    if a[i] > b[i]
      a[i] = b[i]
    end
    a[i+1] = b[i]
  end
end
p a.reduce(:+)

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

int D, T, S;

int main(){
  cin >> D >> T >> S;
  double arrive;
  arrive = (double)D / S;

  if( arrive <= T){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 3636
// A - Biscuits
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define rep(i, m, n) for (lli i = m; i < (n); i++)
#define repe(i, m, n) for (lli i = m; i <= (n); i++)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((lli)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define _GLIBCXX_DEBUG
const lli INF = 2147483647;
const lli MINF = -2147483648;
const lli LINF = 9223372036854775807;
const lli MOD = 1000000007; //10^9+7
const double PI = acos(-1);
#define SORT(n) sort(n.begin(), n.end())
#define SORTR(n) sort(n.begin(), n.end(), greater<int>())
#define REV(n) reverse(n.begin(), n.end())
#define pb push_back
#define eb emplace_back
#define mp make_pair
#pragma GCC optimize("Ofast")
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vlli = vector<lli>;
using vvli = vector<vlli>;
using vs = vector<string>;
using vvs = vector<vs>;
using vb = vector<bool>;
using vvb = vector<vb>;
using ll = long long;
// vector入力
template <typename T>
istream &operator>>(istream &is, vector<T> &vec)
{
  for (T &x : vec)
    is >> x;
  return is;
}
// vector出力
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec)
{
  // os << '{';
  for (int i = 0; i < vec.size(); i++)
  {
    os << vec[i] << (i + 1 == vec.size() ? "" : "");
  }
  // os << '}';
  return os;
}
// aよりもbが大きいならばaをbで更新する(更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T &b)
{
  if (a < b)
  {
    a = b; // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する(更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T &b)
{
  if (a > b)
  {
    a = b; // aをbで更新
    return true;
  }
  return false;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli a, b, c, h, n, p, w, ans = 0, count = 0, odd = 0, even = 0;
  string s, t;
  vector<pair<string, pair<lli, lli>>> pr;
  cin >> n >> p;
  vlli d(n);
  rep(i, 0, n)
  {
    cin >> d[i];
    if (d[i] % 2 == 1)
      odd++;
    else
      even++;
  }
  if (n == 1 && even == 1 && p == 1)
  {
    cout << 0 << endl;
  }
  else if (n == 1 && even == 1 && p == 0)
  {
    cout << 2 << endl;
  }
  else if (n == 1 && odd == 1 && p == 0)
  {
    cout << 1 << endl;
  }
  else if (n == 1 && odd == 1 && p == 1)
  {
    cout << 1 << endl;
  }
  else if (even == n && p == 1)
  {
    cout << 0 << endl;
  }
  else if (even == n && p == 0)
  {
    count = pow(2, n);
    cout << count << endl;
  }
  else
  {
    count = pow(2, n - 1);
    cout << count << endl;
  }

  // 17592186044416
  // 35184372088832
  // 70368744177664
  // 8796093022208
}

Measured memory_bytes: 4044
#include <bits/stdc++.h>
#define va first
#define vb second
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

const ll mod = 998244353;
int n, arr[101010], brr[101010], crr[101010];
ll ans=1;
vector<int> r, g, b;
string s;

int main() {
	cin >> n >> s;
	for (int i=0; i<s.size(); i++) {
		if (s[i] == 'R') r.push_back(i);
		if (s[i] == 'G') g.push_back(i); 
		if (s[i] == 'B') b.push_back(i);
	}

	for (int i=0; i<n; i++) {
		arr[i] = min({r[i], g[i], b[i]});
		crr[i] = max({r[i], g[i], b[i]});
		brr[i] = r[i]+g[i]+b[i]-arr[i]-crr[i];
	}

	int cur=0;
	for (int i=0; i<n; i++) {
		while (cur+1 != n && arr[cur+1]<brr[i]) ++cur;
		ans = (ans*(cur-i+1))%mod;
	}

	cur=n-1;
	for (int i=n-1; i>=0; i--) {
		while (cur!=0 && crr[cur-1]>brr[i]) --cur;
		ans = (ans*(i-cur+1))%mod;
	}

	for (int i=1; i<=n; i++) {
		ans = (ans*i)%mod;
	}

	cout << ans;
}

Measured memory_bytes: 3324
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int n, d, cnt = 0;
	cin >> n >> d;
	vector<int> x(n);
	vector<int> y(n);
	for (int i = 0; i < n; i++) {
		cin >> x[i];
		cin >> y[i];
	}
	for (int i = 0; i < n; i++ ) {
		double l = sqrt(pow(x[i], 2) + pow(y[i], 2));
		if (l <= d) {
			cnt++;
		}
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 4840
n = int(input())
def dfs(s):
  if int(s)>n:
    return 0
  if all(s.count(c)>0 for c in '753'):
    ret = 1
  else:
    ret = 0
  for c in '753':
    ret += dfs(s+c)
  return ret

print(dfs('0'))

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

int main() {
  int N,K;
  string S;
  cin >> N >> K >> S;
  
  for (int i = 0; i < N; i++) {
    if (i + 1 == K) {
      if (S[i] == 'A') cout << 'a';
      else if (S[i] == 'B') cout << 'b';
      else if (S[i] == 'C') cout << 'c';
    } else {
      cout << S[i];
    }
  }
}


Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <climits> // INT_MAX, LONG_MAX, LLONG_MAX, UINT_MAX, ULONG_MAX, ULLONG_MAX
#include <cmath>
#include <cstdint>
#include <cstring> // memset
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>

#define ALL(x) (x).begin(), (x).end()
#define INF 1e9
#define LOG(x) cout << #x << " = " << (x) << endl
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)

using namespace std;

int main() {
    ios::sync_with_stdio(false);

    string s;
    cin >> s;

    string result;
    REP(i, s.size()) {
        if (s[i] == 'B') {
            if (result.size() > 0)
                result.pop_back();
        } else
            result.push_back(s[i]);
    }

    cout << result << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
const int N = 1e5 + 5;
#define int long long int
 
int32_t main() {
    IOS ;
    int n ; cin >> n ; 
    int arr[n] ; for(int i=0; i<n; i++) cin >> arr[i] ; 
    int dp[n] ; dp[0] = 0, dp[1] = abs(arr[1] - arr[0]) ; 
    for(int i=2; i<n; i++) {
        int x = abs(arr[i] - arr[i-1]) + dp[i-1] ; 
        int y = abs(arr[i] - arr[i-2]) + dp[i-2] ; 
        dp[i] = min(x, y) ;
    }

    cout << dp[n-1] ;

    return 0 ;
}

Measured memory_bytes: 5164
import bisect

def main():
	n = int(input())
	s = list(map(int,input().split()))
	q = int(input())
	t = list(map(int,input().split()))
	ans = 0
	for i in t:
		temp = bisect.bisect_left(s,i)
		if temp == n:
			continue
		if s[temp] == i:
			ans += 1
	print(ans)

main()


Measured memory_bytes: 16744
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define N 200000
#define mod1 1000000007
#define mod2 1000000009
#define mod3 998244353
#define endl '\n'
#define IO ios_base::sync_with_stdio(false);cin.tie(NULL);
void Google(ll tt){
    cout<<"Case #"<<tt<<": ";
}

int main()
{
    IO
	clock_t begin = clock();
    int n;
    cin>>n;
    if(n>=30)
    	cout<<"Yes\n";
    else
    	cout<<"No\n";
    // cout<<double(clock() - begin)/CLOCKS_PER_SEC<<endl;
    return 0;
}

Measured memory_bytes: 3628
ans_list = []

def calc(i0=0):
    if S[i0][-1] == "+":
        res = 0
        for i in range(i0+1,n):
            if len(S[i]) == len(S[i0]) + 1:
                res += calc(i)
            elif len(S[i]) <= len(S[i0]):
                return res
    elif S[i0][-1] == "*":
        res = 1
        for i in range(i0+1,n):
            if len(S[i]) == len(S[i0]) + 1:
                res *= calc(i)
            elif len(S[i]) <= len(S[i0]):
                return res
    else:
        res = int(S[i0][-1])
    return res

while True:
    n = int(input())
    if n == 0:
        break
    S = [input() for _ in range(n)]

    ans = calc()
    ans_list.append(ans)

for ans in ans_list:
    print(ans)


Measured memory_bytes: 5628
<?php
 fscanf(STDIN,"%d",$n);
 $l = explode(" ",trim(fgets(STDIN)));
 rsort($l);
 $max = $l[0];
 $sum = 0;
 for($i=1;$i<$n;$i++){
   $sum += $l[$i];
 }
 if($sum>$max){
   echo "Yes";
 }else{
   echo "No";
 }
 

Measured memory_bytes: 16212
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //ai>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //ai>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(),x.end())) //reverse
#define TO(x,t,f) ((x)?(t):(f))
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define FILV(x,a) fill(x.begin(),x.end(),a)
#define FILA(ar,N,a) fill(ar,ar+N,a)
#define NEXTP(x) next_permutation(x.begin(),x.end())
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;else return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define pb push_back
#define pri(aa) cout<<(aa)<<endl

const ll INF=1e9+7;
const ll N = 100002;
ll a,b,c,d,e,f;
bool w[31],s[3001];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>a>>b>>c>>d>>e>>f;
	FOR(i,0,31)w[i]=false;
	FOR(i,0,3001){
		s[i]=false;
	}
	w[0]=true;
	s[0]=true;
	FOR(i,0,f/100+1){
		if(w[i]==true){
			if(i+a<=30)w[i+a]=true;
			if(i+b<=30)w[i+b]=true;
		}
	}
	FOR(i,0,f+1){
		if(s[i]==true){
			if(i+c<=3000)s[i+c]=true;
			if(i+d<=3000)s[i+d]=true;
		}
	}	
	ll anss=0,answ=min(a,b)*100;
	double nou=0,ee;
	ee=100*(double)e/(100+double(e));
	FOR(i,0,31){
		if(w[i]==false)continue;
		FOR(j,0,3001){
			if(s[j]){
				double l;
				l=100*(double)j/((double)i*100+(double)j);
				if((nou<=l)&&l<=ee&&(i*100+j)<=f){
					nou=l;
					anss=j;
					answ=i*100;
				}
			}
		}
	}
	cout<<(anss+answ)<<" "<<anss<<endl;
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define MOD (1000000007)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()

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

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

const ll INF = 1LL << 60;

int main(){
  ll n; cin >> n;
  vector<ll> v(5); rep(i, 5) cin >> v[i];
  sort(all(v));

  // a,b,c,d,e のうち最も小さいものが、ボトルネックとなる
  // そいつで無駄が何分生じるかを数えればよい
  ll neck = v[0];

  // ans = (n÷nech を切り上げたもの) + 4
  ll ans = (n+neck-1)/neck + 4;

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


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (n, m, k) = readIntegerList()
    val friendOrBlock = Array(n) { hashSetOf<Int>() }
    val unionFind = UnionFind(n)
    repeat(m) {
        val (a, b) = readIntegerList().map { it - 1 }
        friendOrBlock[a].add(b)
        friendOrBlock[b].add(a)
        unionFind.unite(a, b)
    }

    repeat(k) {
        val (a, b) = readIntegerList().map { it - 1 }
        if (unionFind.sameRoot(a, b)) {
            friendOrBlock[a].add(b)
            friendOrBlock[b].add(a)
        }
    }

    val ans = IntArray(n)
    repeat(n) {
        ans[it] = unionFind.getSize(it) - 1 - friendOrBlock[it].filter { true }.size
    }
    println(ans.joinToString(" "))
}

/**　Union find 0 ~ (n - 1)　*/
class UnionFind(n: Int) {
    val parent = IntArray(n) { it }
    val rank = IntArray(n)
    val size = IntArray(n) { 1 }

    /** O(α(n)) */
    fun findRoot(x: Int): Int {
        if (parent[x] == x) return x

        parent[x] = findRoot(parent[x])
        return parent[x]
    }

    /** O(α(n)) */
    fun sameRoot(x: Int, y: Int) = findRoot(x) == findRoot(y)

    /** O(α(n)) */
    fun unite(x: Int, y: Int) {
        val x = findRoot(x)
        val y = findRoot(y)
        if (x == y) return

        if (rank[x] < rank[y]) {
            parent[x] = y
            size[y] += size[x]
        } else {
            parent[y] = x
            if (rank[x] == rank[y]) rank[x]++

            size[x] += size[y]
        }
    }

    /** O(α(n)) */
    fun getSize(x: Int) = size[findRoot(x)]
}

fun readInteger() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntegerList() = readStringList().map(String::toInt)
fun readLongList() = readStringList().map(String::toLong)
fun readDoubleList() = readStringList().map(String::toDouble)


Measured memory_bytes: 136596
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>

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

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

    cout << a * b << endl;

    return 0;
}

Measured memory_bytes: 3164
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
int menor(const void * x, const void * y){
	int a = *((int *) x), b = *((int *) y);
 
	if (a<b)
		return -1;
	if (a>b)
		return 1;
 
	return 0;
 
}


int main(){
    int n, k, menv = 0;
    scanf("%d%d", &n, &k);
    int vet[n];
    for(int i = 0; i < n; ++i){
        scanf("%d", &vet[i]);
    }
    qsort(vet, n, sizeof(vet[0]), menor);
    for(int x = 0; x < k; ++x){
        menv += vet[x];
    }
    printf("%d\n", menv);
    

    return 0;
}


Measured memory_bytes: 1744
#include <bits/stdc++.h>
     
    using namespace std;
    int main()
    {
        int n;
        cin >> n;
        long long int sum = 0;
        for (int i = 1; i <= n; i++)
        {
            for (int j = 1; j <= n; j++)
            {
                for (int k = 1; k <= n; k++)
                {
                    sum += __gcd(k, __gcd(i, j));
                }
            }
        }
        cout << sum << "\n";
        return 0;
    }
 

Measured memory_bytes: 3636
#include <iostream>
using namespace std;
static const int BUILDING = 4;
static const int FLOOR = 3;
static const int ROOM = 10;

int main()
{
    int n, b, f, r, v;
    cin >> n;
    int residant[BUILDING][FLOOR][ROOM] = {};
    for (int i = 0; i < n; i++)
    {
        cin >> b >> f >> r >> v;
        residant[b - 1][f - 1][r - 1] += v;
    }
    for (int i = 0; i < BUILDING; i++)
    {
        for (int j = 0; j < FLOOR; j++)
        {
            for (int k = 0; k < ROOM; k++)
            {
                cout << " " << residant[i][j][k];
            }
            cout << endl;
        }
        if (i != BUILDING - 1)
        {
            cout << "####################" << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3076
#include <bits/stdc++.h>
using namespace std;
pair<int, int> d[]{{-1, 0}, {-1, -1}, {0, -1}, {1, -1}, {1, 0}, {1, 1}, {0, 1}, {-1, 1}};
int main()
  {int H, W; cin >> H >> W;
  string S[H]; for (auto &s: S) cin >> s;
  for (int i{}; i < H; ++i)
    {for (int j{}; j < W; ++j)
      {if (S[i][j] == '#') {cout << "#"; continue;}
      int c{}; for (auto [a, b] : d) {int y{i + a}, x{j + b}; c += 0 <= y and y < H and 0 <= x and x < W and S[y][x] == '#';}
      cout << c;}
    puts("");}}

Measured memory_bytes: 3576
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <cmath>
#include <functional>
#include <queue>
#define REP(i,n) for(ll i=0;i<n;i++)
#define FOR(i,n1,n2) for(ll i=n1;i<n2;i++)
#define put(a) cout<<a<<endl;
using namespace std;
typedef long long ll;
const ll INF = 9223372036854775807-1;
const int inf = 2147483647-1;

int n;
int sosuu5[55] = {11,31,41,61,71,101,131,151,181,191,211,241,251,271,281,311,331,401,421,431,461,491,521,541,571,601,631,641,661,691,701,751,761,811,821,881,911,941,971,991,1021,1031,1051,1061,1091,1151,1171,1181,1201,1231,1291,1301,1321,1361,1381};
int main() {
    cin >> n;
    REP(i,n-1){
        cout << sosuu5[i] << " ";
    }
    cout << sosuu5[n-1] << endl;
    //put(res);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 1e9
#define endl '\n'
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); --i)
#define FORE(i, a, b) for (int i = (a), e = (b); i < e; ++i)
#define RFORE(i, a, b) for (int i = (b)-1, e = (a); i >= e; --i)
#define ALL(x) (x).begin(), (x).end()
#define SORT(c) sort((c).begin(), (c).end())
#define SORTR(c) sort((c).begin(), (c).end(), greater<int>())
using namespace std;
typedef long long ll;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int N;
    cin >> N;
    int         ans = 0;
    vector<int> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A.at(i);
    }
    FOR(i, 0, N) {
        while (i + 1 < N && A.at(i) == A.at(i + 1)) {
            ++i;
        }
        if (i + 1 < N && A.at(i) <= A.at(i + 1)) {
            while (i + 1 < N && A.at(i) <= A.at(i + 1)) {
                ++i;
            }
        } else if (i + 1 < N && A.at(i) >= A.at(i + 1)) {
            while (i + 1 < N && A.at(i) >= A.at(i + 1)) {
                ++i;
            }
        }
        ++ans;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rp(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////
const ll MOD=998244353;
ll dp[3020][3020];
ll pow(ll x,ll y,ll mod){
    if(y==0) return 1;
    if(y&1) return x*pow(x,y-1,mod)%mod;
    ll p=pow(x,y/2,mod);
    return p*p%mod;
}

void solve(){
    ll n,s;
    cin >> n >> s;
    dp[0][0]=1;
    rp(i,n){
        ll a;
        cin >> a;
        rp(j,s+1){
            if(j>=a){
                dp[i+1][j]=(dp[i][j]*2+dp[i][j-a])%MOD;
            }
            else{
                dp[i+1][j]=dp[i][j]*2%MOD;
            }
        }
    }
    print(dp[n][s]);
}
int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    solve();
    return 0;
}

Measured memory_bytes: 74420
#include <cstdlib>
#include <iostream>
#include <utility>


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

  std::pair<int, int> pairX(0, 0);
  std::pair<int, int> pairY(0, 0);
  int n;
  std::cin >> pairX.second >> pairY.second >> n;
  for (int i = 0; i < n; i++) {
    int x, y, a;
    std::cin >> x >> y >> a;
    switch (a) {
      case 1:
        pairX.first = std::max(pairX.first, x);
        break;
      case 2:
        pairX.second = std::min(pairX.second, x);
        break;
      case 3:
        pairY.first = std::max(pairY.first, y);
        break;
      case 4:
        pairY.second = std::min(pairY.second, y);
        break;
    }
  }
  std::cout << ((pairX.second <= pairX.first || pairY.second <= pairY.first) ? 0
      : (pairX.second - pairX.first) * (pairY.second - pairY.first)) << std::endl;

  return EXIT_SUCCESS;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
class WeightedUnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n
        self.weight = [0] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            px = self.find(self.parents[x])
            self.weight[x] += self.weight[self.parents[x]]
            self.parents[x] = px
            return px

    def union(self, x, y, w):
        w += self.weight[x] - self.weight[y]
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y, w = y, x, -w
        self.parents[x] += self.parents[y]
        self.parents[y] = x
        self.weight[y] = w
        return

    def weig(self, x):
        self.find(x)
        return self.weight[x]

    def diff(self, x, y):
        return self.weig(y) - self.weig(x)
    
    def same(self, x, y):
        return self.find(x) == self.find(y)

(n, m), *q = [[*map(int, o.split())] for o in open(0)]
UF = WeightedUnionFind(n + 1)
for l, r, d in q:
    if UF.same(l, r):
        if d != abs(UF.diff(l, r)):
            print("No"); exit()
    else:
        UF.union(l, r, d)
print("Yes")

Measured memory_bytes: 52000
N = int(input())
A = list(map(int, input().split()))
MOD = 10**9 + 7

xyz = [[0]*3 for _ in range(N+1)]

ans = 1
for i in range(1, N+1):
    plus_flg = True
    tmp = 0
    for j in range(3):
        xyz[i][j] = xyz[i-1][j]
        if xyz[i-1][j] == A[i-1]:
            tmp += 1
            if plus_flg:
                xyz[i][j] = xyz[i-1][j] + 1
                plus_flg = False
    ans *= tmp
    ans %= MOD

print(ans)

Measured memory_bytes: 20772
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
//ranker
using namespace std;

#define REPS(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) REPS(i, 0, n)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (int i = (a); i >= n; --i)
#define DEP(i, n) DEPS(i, n, 0)

using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using pis = pair<int, string>;
using psi = pair<string, int>;
using D = double;


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
    int n,p,data[50],i,d,result;
    while(1){
      cin >> n >> p;
      d=p;
      if(n==0&&p==0) break;
      for(i=0;i<n;i++) data[i]=0;
      i=0;
      while(1){
        if(p>0){
      p--;
          data[i]++;
      if(data[i]==d){
        result=i;
        break;
      }
        }else if(p==0){
          p=data[i];
          data[i]=0;
        }
        if(i+1==n) i=0;
        else i++;
      }
      cout << result << endl;
    }
    return 0;
  }

Measured memory_bytes: 3028
/*
    Problem 38
    https://onlinejudge.u-aizu.ac.jp/problems/ALDS1_10_C
*/
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 1005;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
vector<vector<int>> dp(MAX, vector<int>(MAX));
/* function */
void calc(string s, string t) {
    int S = s.size(), T = t.size();
    // init
    for (int i = 0; i < S; i++) for (int j = 0; j < T; j++) dp[i][j] = 0;
    for (int i = 0; i < S; i++) {
        for (int j = 0; j < T; j++) {
            dp[i+1][j+1] = max(dp[i+1][j], dp[i][j+1]);
            if (s[i] == t[j]) dp[i+1][j+1] = dp[i][j] + 1;
        }
    }
    cout << dp[S][T] << '\n';
}
/* main */
int main(){
    int n;
    cin >> n;
    string s, t;
    for (int i = 0; i < n; i++) {
        cin >> s >> t;
        calc(s, t);
    }
}


Measured memory_bytes: 6688
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define MP make_pair
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define PLI pair<ll, int>
#define PIL pair<int, ll>
#define STR string
#define Fst first
#define Snd second
#define SHN 1e9
#define LSHN 1e18
using namespace std;
ll n,m;
ll sum;
ll a[100010];
int main()
{
	cin >>m>>n;
	for (int i=0;i<n;i++) cin >>a[i],sum+=a[i];
	cout <<(m<=sum ? "Yes" : "No");
	return 0;
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;
int N, c[4]; double dp[301][301][301];
double fun(int c1, int c2, int c3){
    if(c1 == 0 && c2 == 0 && c3 == 0) return 0;
    if(dp[c1][c2][c3] > 0.0) return dp[c1][c2][c3];
    double & ret = dp[c1][c2][c3]; int t = c1 + c2 + c3;
    ret = 1.0 * N / t;
    if(c1 > 0) ret += 1.0*c1 / t * fun(c1-1, c2, c3);
    if(c2 > 0) ret += 1.0*c2 / t * fun(c1+1, c2-1, c3);
    if(c3 > 0) ret += 1.0*c3 / t * fun(c1, c2+1, c3-1);
    return ret;
}
int main(){
    scanf("%d", &N);
    for(int i=1, x; i<=N; i++){
        scanf("%d", &x); c[x]++;
    }
    printf("%.9lf\n", fun(c[1], c[2], c[3]));
}

Measured memory_bytes: 213248
#include <bits/stdc++.h>
using namespace std;
#define int long long

const int MAXN = 2e6 + 5; 
const int MOD = 1e9 + 7; 

int pow_mod (int a, int b){
    if(b==0)return 1; 
    
    int x = pow_mod(a,b/2); 
    x=(x*x)%MOD; 
    if(b&1) x=(x*a)%MOD; 
    
    return x; 
}
inline int get_inv (int x){
    return pow_mod (x, MOD - 2);
}

int fact [MAXN]; 
main(){
    ios_base::sync_with_stdio(0); 
    fact[0]=1;
    for (int i=1;i<MAXN;i++) fact[i]=(i*fact[i-1])%MOD; 
    
    int K; cin>>K; 
    string s; cin >> s; 
    
    int N = s.length(); 
    int ans = 0; 
    
    for (int end=0; end<=K; end++){
        int cnt = (pow_mod(26, end) * pow_mod (25, K - end)) % MOD;
        // (K - end + N - 1, N - 1)
        int num = fact[K - end + N - 1]; 
        int denom = (fact[K - end] * fact[N - 1]) % MOD;
        num = (num * get_inv(denom)) % MOD; 
        cnt = (cnt * num) % MOD; 
        ans = (ans + cnt) % MOD; 
    }
    cout << ans << '\n'; 
    return 0; 
}

Measured memory_bytes: 19872