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

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

bool can[200002];
int dp1[200002], dp2[200002];

void get(int i)
{
	if (!can[i])
		return;

	cout << i << '\n';
}

int32_t main()
{
	FIO;
	int n, k, c; cin >> n >> k >> c;

	string st; cin >> st;

	if (c == 0)
	{
		int tot = 0;

		for (int i = 0; i < n; ++i)
			if (st[i] == 'o')
				tot++;

		if (tot == k)
		{
			for (int i = 0; i < n; ++i)
				if (st[i] == 'o')
					cout << i + 1 << '\n';
		}

		return 0;
	}

	for (int i = 1; i <= n; ++i)
		if (st[i - 1] == 'o')
			can[i] = 1;
		else
			can[i] = 0;

	for (int i = 1; i <= n; ++i)
		if (!can[i])
			dp1[i] = dp1[i - 1];
		else
			dp1[i] = max(dp1[i - 1], 1 + dp1[max(0ll, i - c - 1)]);


	for (int i = n; i >= 1; --i)
		if (!can[i])
			dp2[i] = dp2[i + 1];
		else
			dp2[i] = max(dp2[i + 1], 1 + dp2[min(n + 1, i + c + 1)]);

	/*for (int i = 1; i <= n; ++i)
		cout << dp1[i] << ' ';
	cout << '\n';*/

	multiset<int> s;

	if (dp2[2] < k && can[1])
		cout << 1 << '\n';

	s.insert(dp1[1] + dp2[min(n + 1, 1 + c + 1)]);

	for (int i = 2; i <= c; ++i)
	{
		int cur = (*s.rbegin());
		cur = max(cur, dp2[i + 1]);

		if (cur < k)
			get(i);

		s.insert(dp1[i] + dp2[min(n + 1, i + c + 1)]);
	}

	for (int i = c + 1; i <= n; ++i)
	{
		int cur = (*s.rbegin());
		cur = max(cur, dp1[i - 1]);
		cur = max(cur, dp2[i + 1]);

		if (cur < k)
			get(i);

		s.erase(s.find(dp1[i - c] + dp2[min(n + 1, i - c + c + 1)]));
		s.insert(dp1[i] + dp2[min(n + 1, i + c + 1)]);
	}
	return 0;
}

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

string words[4]={"AC","WA","TLE","RE"};

int main(){
	int n;
	cin>>n;
	vector<int>v(4);
	for(int i =0;i<n;i++){
		string s;
		cin>>s;
		for(int id=0;id<4;id++){
			if(words[id]!=s)continue;

			v[id]++;
		}
	}
	for(int i=0;i<4;i++){
		cout<<words[i]<<" x "<<v[i]<<'\n';
	}

	return 0;
}

Measured memory_bytes: 3616
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        Scanner scn = new Scanner(System.in);
        String word = scn.nextLine();
        int ans = 0;

        while (scn.hasNext()) {
            String check = scn.next();

            check.replace(".","");
            check.replace("?","");
            check.replace("!","");
            if(check.equalsIgnoreCase(word)){
                ans +=1;
            }

        }
        System.out.println(ans);

        scn.close();


    }

}


Measured memory_bytes: 26540
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define faster ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
 
typedef vector<int> vi;;
typedef vector<ll> vll;

#define l() length()
#define sz() size()
 
#define b() begin()0
#define e() end()
#define all(x) x.begin(), x.end()
 
#define pb(i) push_back(i)
#define PB() pop_back()
 
 
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;
#define mp make_pair
#define Fi first
#define Se second
 
const int maxx=1e6+9;
 
// Happy Coding!


void solve(){

    int n,cand;
    cin>>n>>cand;
    vi arr(n,0);
    for(int i=0;i<n;i++){
        cin>>arr[i];
    }
    sort(all(arr));
    int cnt=0;
    for(int i=0;i<n;i++){
        if(cand<arr[i]){
            break;
        }
        if(i==n-1){
            arr[i]-=cand;
        }
        else{
            cand-=arr[i];
            arr[i]=0;
        }
        cnt+=arr[i]==0;
    }
    cout<<cnt<<endl;
}

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

Measured memory_bytes: 3640
MOD = 10**9 + 7

class Combination:
    def __init__(self, size):
        self.size = size + 2
        self.fact = [1, 1] + [0] * size
        self.factInv = [1, 1] + [0] * size
        self.inv = [0, 1] + [0] * size

        for i in range(2, self.size):
            self.fact[i] = self.fact[i - 1] * i % MOD
            self.inv[i] = -self.inv[MOD % i] * (MOD // i) % MOD
            self.factInv[i] = self.factInv[i - 1] * self.inv[i] % MOD

    def npr(self, n, r):
        if n < r or n < 0 or r < 0:
            return 0
        return self.fact[n] * self.factInv[n - r] % MOD

    def ncr(self, n, r):
        if n < r or n < 0 or r < 0:
            return 0
        return self.fact[n] * (self.factInv[r] * self.factInv[n - r] % MOD) % MOD

    def nhr(self, n, r):  # 重複組合せ: x_1 + ... + x_n = r
        return self.ncr(n + r - 1, n - 1)

N, M = map(int, input().split())
comb = Combination(N + 100)

def primeCount(N):
    R = int(N**(0.5)) + 1  # 素数の範囲
    primes = {}  # 素数のリスト
    n = N
    for num in range(2, R):
        primes[num] = 0
        while n % num == 0:
            n //= num
            primes[num] += 1
    if n > 1 :
        primes[n] = 1
    return { key : val for key, val in primes.items() if val > 0}  # フィルターをかける

ans = 1
for c in primeCount(M).values():
    ans *= comb.nhr(N, c)
    ans %= MOD
print(ans)


Measured memory_bytes: 18916
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
#include <functional>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
using namespace std;
using lint = int64_t;

int main() {
    lint n, s;
    cin >> n >> s;
    lint b = 2;
    while (n / b >= b) {
        lint res = 0, N = n;
        while (N) {
            res += N % b;
            N /= b;
        }
        if (res == s) {
            cout << b << "\n";
            return 0;
        }
        ++b;
    }
    for (lint i = b; i >= 1; --i) {
        if (i > s) continue;
        lint m = s - i;
        if ((n - m) % i == 0) {
            if (m < (n - m) / i && i < (n - m) / i) {
                cout << (n - m) / i << "\n";
                return 0;
            }
        }
    }
    if (n == s) {
        cout << n + 1 << "\n";
        return 0;
    }
    cout << -1 << "\n";
    return 0;
}


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

const int MOD = 10000;

int rec(int today,int pasta1,int pasta2);

int n;
int sch[128];//?????±?????\??????????????¢
int memo[128][4][4];

int main(void){

	memset(sch, 0, sizeof(sch));
	memset(memo, -1, sizeof(memo));

	int k, a, b;

	cin >> n >> k;

	for (int i = 0; i < k; i++){
		cin >> a >> b;
		sch[a] = b;
	}

	cout << rec(1,0,0) << endl;
}

int rec(int today,int pasta1,int pasta2){

	if (today > n)return 1;
	if (memo[today][pasta1][pasta2] != -1)return memo[today][pasta1][pasta2];
	if (sch[today] != 0){
		if (pasta1 == pasta2 && pasta1 == sch[today])return 0;
		else return rec(today+1, sch[today], pasta1) % MOD;
	}

	int cnt = 0;
	for (int i = 1; i <= 3; i++){
		if (pasta1 == pasta2 && pasta1 == i)continue;
		cnt += rec(today + 1, i, pasta1);
	}
	return memo[today][pasta1][pasta2] = cnt % MOD;
}

Measured memory_bytes: 3116
N,M = map(int,input().split())
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return divisors
div = sorted(make_divisors(M))
div = [i for i in div if M//i >= N]
print(div[-1])


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

long long dp[55][2505];

int main()
{
  int n,a,i;
  long long ans;

  scanf("%d%d",&n,&a);
  dp[0][0]=1;
  for(int c=1;c<=n;c++)
  {
    scanf("%d",&i);
    for(int c2=54;c2>0;c2--)
    for(int c3=2504;c3>=i;c3--)
    dp[c2][c3]+=dp[c2-1][c3-i];
  }
  ans=0;
  for(int c=1;c<55;c++)
  if (c*a>2500)break;
  else ans+=dp[c][c*a];
  printf("%lld\n",ans);
}


Measured memory_bytes: 1280
#include<iostream>
using namespace std;
#include<stdio.h>

int main() {
        char p[101], s[101];
        int pl, sl, i, j, r, sum;
        r = 0;
        for (sl = 0; sl < 101; sl++) {
                scanf("%c", &s[sl]);
                if (s[sl] == '\n') break;
        }
        for (pl = 0; pl < 101; pl++) {
                scanf("%c", &p[pl]);
                if (p[pl] == '\n') break;
        }
        for (i = 0; i < sl; i++) {
                for(j = 0; j < pl + 1; j++) {
                        if(s[(i + j) % sl] != p[j]) break;
                        if(j == pl - 1) r = 1;
                }

        }
        if (r == 1) cout << "Yes" << endl;
        else cout << "No" << endl;
        return 0;
}

Measured memory_bytes: 3216
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdint>
#include <limits>
using namespace std;



/**
* 10進数 v を base進数の文字列へ変換する。
* @param [in] v    10進数の整数
* @param [in] base 変換した 2~36 のN進数の値
* @return base進数へ変換した文字列
*/
template<typename TypeInt>
std::string Itoa(const TypeInt v, int base)
{
	static const char table[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	string ret;
	static numeric_limits<TypeInt> t;
	TypeInt n = v;
	if (t.is_signed) {
		if (v < 0) n *= -1;
	}

	while (n >= base) {
		ret += table[n%base];
		n /= base;
	}
	ret += table[n];
	if (t.is_signed) {
		if (v < 0 && base == 10) ret += '-';
	}
	// 文字列の順番を逆にする
	std::reverse(ret.begin(), ret.end());

	return ret;
}



int main(void)
{
    uint64_t n,t;
    cin >> n >> t;
    string s =Itoa(n,t);
    int ans = s.size();
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdint>

int main() {
  intmax_t N, A, B;
  scanf("%jd %jd %jd", &N, &A, &B);

  if (N == 1)
    return !printf("%d\n", A==B);

  if (A > B)
    return !printf("0\n");

  intmax_t max=B*(N-1)+A, min=A*(N-1)+B;
  printf("%jd\n", max-min+1);
  return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
int main(void){
    int i, n, t;
    char card;
    unsigned char x[4][13] = { 0 };
    scanf("%d\n", &n);
    for(i = 0; i < n; i++){
        scanf("%c %d\n", &card, &t);
        if(card == 'S') x[0][t-1] = 1;
        else if(card == 'H') x[1][t-1] = 1;
        else if(card == 'C') x[2][t-1] = 1;
        else if(card == 'D') x[3][t-1] = 1;
    }
    for(i = 0; i < 52; i++){
        if(x[i/13][i%13] == 0){
            if((i/13)==0) printf("S %d\n", i%13+1);
            else if((i/13) == 1) printf("H %d\n", i%13+1);
            else if((i/13) == 2) printf("C %d\n", i%13+1);
            else if((i/13) == 3) printf("D %d\n", i%13+1);
        }
    }
    return 0;
}


Measured memory_bytes: 600
def main():
    n = int(input())
    d, x = map(int, input().split())
    a = [int(input()) for _ in range(n)]

    ans = x
    for aa in a:
        if d % aa == 0:
            ans += d//aa
        else:
            ans += d//aa + 1

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include <numeric>
#include<map>
#include<unordered_map>
 
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;++i)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()
 
int main(){
    ll n, k;
    cin >> n >> k;
    ll ans  = 0;
    if(k==0){
        cout << n*n;
        return 0;
    }
    // for(int i = k+1; i <= n; ++i)ans += i-k + (n-i)/i*(i-k) + max((ll)0, (n-i)%i-k);
    for(int i = k+1; i <= n; ++i){
        // cout << i  << " : ";
        ans += n/i*(i-k);
        // cout << n/i*(i-k) << " + " << max((ll)0, (n-i*(n/i)+1)-k) << endl;
        ans += max((ll)0, (n-i*(n/i)+1)-k);
    }
    cout << ans << endl;
}


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

int32_t main()
{

    int n,cnt=0,a,b, flag=0;
    cin>>n;

    for(int i=0; i<n; i++){
        cin>>a>>b;

        if(a==b) cnt++;
        else cnt=0;

        if(cnt==3 and flag==0){
            flag = 1;
            cnt=0;
        }
    }
    if(flag==1) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;


    return 0;
}


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

using namespace std;
typedef long long ll;

string tostr(ll x){
    string s;
    while(x){
        s+='0'+(x%10);
        x/=10;
    }
    reverse(s.begin(), s.end());
    return s;
}
ll pw[12];
int sz(ll x){
    int k=0;
    while(x){
        k++;
        x/=10;
    }
    return k;
}

int gay(int x){

    int sz=0;
    for (int i=1; i<=x; i++){
        string s=tostr(i);
        sz+=s.size();
    }
    return sz;
}


void debug(ll n){
    ll x=0;
    ll ans=0;
    for (ll block=0; block<1e3; block++){
        int k=gay(block);
        if (ans+k<n){
            ans+=k;
        }
        else {
            x=block-1;
            break;
        }
    }
    cout<<"debug "<<x<<endl;
}

ll foo(ll x){
    if (x==0){
        return 0;
    }
    ll ans=0;
    ll k=sz(x);
    k--;
    ll t=x-pw[k]+1;
    ans+=((t+1)*t/2)*(k+1);
    k--;
    while(k>=0){
        t=pw[k+1]-1;
        ll tt=t-pw[k]+1;
        ans+=(tt+1)*(tt)/2*(k+1);
        ans+=(x-t)*(t-pw[k]+1)*(k+1);
        k--;
    }

    return ans;
}
ll foo1(ll x){
    if (x==0)
        return 0;
    ll ans=0;

    int k=sz(x);
    k--;
    ans+=(x-pw[k]+1)*(k+1);
    k--;
    while(k>=0){
        ans+=(pw[k+1]-1-pw[k]+1)*(k+1);
        k--;
    }
    return ans;


}

void de(int n){
    int r=0;
    for (int i=1; i<=1e3; i++){
        if (r+sz(i)<n){
            r+=sz(i);
        }
        else {
            cout<<"de "<<i-1<<endl;
            return;
        }
    }
}

void solve(){
    ll n;
    cin>>n;
    ll l=0, r=1e9;
    while(1){
        if (r-l<=1){
            ll x=l;
            if (foo(x)<n){
                l=x;
            }
            x=r;
            if (foo(x)<n){
                l=x;
            }
            break;
        }
        ll x=(l+r)>>1;
        if (foo(x)<n){
            l=x;
        }
        else {
            r=x;
        }
    }
    ll x=l;
   // cout<<x<<endl;
   // debug(n);
    n-=foo(x);
    l=0, r=x+1;
    while(1){
        if (r-l<=1){
            ll d=l;
            if (foo1(d)<n){
                l=d;
            }
            d=r;
            if (foo1(d)<n){
                l=d;
            }
            break;
        }
        ll d=(l+r)>>1;
        if (foo1(d)<n){
            l=d;
        }
        else {
            r=d;
        }
    }

    ll d=l;
    //cout<<d<<" "<<n<<" !"<<endl;
  //  de(n);
    n-=foo1(d);
   // cout<<d<<" !"<<endl;
    string s=tostr(d+1);
    cout<<s[n-1]<<endl;

}




int main(){


    //cout<<foo1(12)<<endl;
    int n;
    cin>>n;
    vector<int>a;
    for (int i=0; i<2*n; i++){
        int x;
        cin>>x;
        a.push_back(x);
    }
    sort(a.begin(), a.end());
    ll ans=0;
    for (int i=0; i<2*n; i+=2){
        ans+=a[i];
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int a[3005];
int main(){
	int n;
	scanf("%d", &n);
	int ans = 0;
	for(int i=1;i<=n;i++){
		scanf("%d", &a[i]);
		ans += a[i]-1;
	}
	printf("%d\n", ans);
}

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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;

int main() {

    string s;
    cin>>s;
    if(s=="hi"||s=="hihi"||s=="hihihi"||s=="hihihihi"||s=="hihihihihi"){
        puts("Yes");
    }else{
        puts("No");
    }

    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/ruby
#
# 1036.rb: Monster Factory
#

### main

loop do
  red = gets.strip
  break if red == '-'

  red = red.split('')
  green = gets.strip.split('')
  down = gets.strip.split('')
  #p [red, green, down]

  right = []
  c = green.shift

  while ! red.empty? || ! green.empty?
    if c == down.first
      c = red.shift
      down.shift
    else
      right << c
      c = green.shift
    end
  end

  right << c

  puts right.join
end

Measured memory_bytes: 6128
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
using namespace std;
#define MOD 1000000007

int N, K;
int a[100];
int dp[100001];

int dfs(int x){
    if(dp[x] != -1) return dp[x];

    for(int i=0; i<N; i++){
        if(x-a[i] < 0) continue;
        dp[x-a[i]] = dfs(x-a[i]);
        if(dp[x-a[i]] == 0){
            dp[x] = 1;
            return 1;
        }
    }
    dp[x] = 0;
    return 0;
}

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

    fill_n(dp, K+1, -1);
    for(int i=0; i<a[0]; i++)
        dp[i] = 0;

    cout << (dfs(K) ? "First" : "Second") << endl;
    return 0;
}

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

using namespace std;

using ll = long long;
constexpr int mo = 1e9+7;
constexpr int inf = 1<<30;
constexpr ll infl = 1ll<<60;

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    string s;
    cin>>s;
    s.reserve(100000);
    s.capacity();
    int n;
    cin>>n;
    int rev = 0;
    for(int i=0;i<n;++i){
        int t;cin>>t;
        switch(t){
            case 1 :
                rev = (rev +1)%2;
                break;
            case 2 :
                int f;string c;
                cin>>f>>c;
                if((f + rev)%2 == 0)s += c;
                else s.insert(0,c);
        }
    }
    if(rev)reverse(s.begin(),s.end());
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 936
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <cstring>
#include <cmath>
#include <queue>
#include <map>
#include <set>
using namespace std;

#define rep(i,n) for(int i=0; i<n; i++)
#define FOR(i,s,n) for(int i=s; i<n; i++)
#define ALL(x) x.begin(), x.end()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef pair<double,double> pdd;

const double pi = atan(1.0) * 4.0;
const double EPS = 1e-8;

double cross(pdd x, pdd y) {
	return x.first*y.second - x.second*y.first;
}

double dist(pdd x, pdd y) {
	return sqrt((x.first-y.first)*(x.first-y.first) + (x.second-y.second)*(x.second-y.second));
}

int main() {
	int N, M, L;
	while(scanf("%d %d %d", &N, &M, &L), N) {
		vector< vector<pdd> > star(N);
		rep(i, N) {
			int x, y, a, r;
			scanf("%d %d %d %d", &x, &y, &a, &r);
			rep(j, 5) {
				double ang = (72.0 * j + a) * pi / 180.0;
				pdd p(x-r*sin(ang), y+r*cos(ang));
				star[i].push_back(p);
			}
		}
		double cost[100][100];
		rep(i, N) {
			rep(j, N) {
				cost[i][j] = 1e9;
				if(i==j) cost[i][j] = 0.0;
				rep(ii, 5) {
					pdd v1 = pdd(star[i][ii].first - star[i][(ii+2)%5].first, star[i][ii].second - star[i][(ii+2)%5].second);
					rep(jj, 5) {
						pdd v2 = pdd(star[j][jj].first - star[j][(jj+2)%5].first, star[j][jj].second - star[j][(jj+2)%5].second);
						pdd u1 = pdd(star[i][ii].first - star[j][(jj+2)%5].first, star[i][ii].second - star[j][(jj+2)%5].second);
						pdd u2 = pdd(star[j][jj].first - star[i][(ii+2)%5].first, star[j][jj].second - star[i][(ii+2)%5].second);
						pdd w1 = pdd(star[i][ii].first - star[j][jj].first, star[i][ii].second - star[j][jj].second);
						pdd w2 = pdd(-w1.first, -w1.second);
						if( cross(v1,u1)*cross(v1,w1)<-EPS && cross(v2,u2)*cross(v2,w2)<-EPS ) {
							cost[i][j] = 0.0;
						}
					}
				}

				rep(ii, 5) {
					pdd s = star[i][ii];
					pdd t = star[i][(ii+2)%5];
					double alp = 0.0f;
					if( abs(t.first-s.first) < EPS ) {
						rep(jj, 5) {
							double miny = min(s.second, t.second);
							double maxy = max(s.second, t.second);
							if( miny <= star[j][jj].second && star[j][jj].second <= maxy ) {
								cost[i][j] = min(cost[i][j], abs(t.first - star[j][jj].first));
							}
						}
					} else {
						alp = (t.second-s.second)/(t.first-s.first);
						rep(jj, 5) {
							pdd p = star[j][jj];
							double qx = (p.first+alp*p.second-alp*s.second+alp*alp*s.first) / (alp*alp+1.0);
							double qy = alp*(qx-s.first) + s.second;
							pdd q = pdd(qx,qy);
							if( dist(q,s)<dist(t,s) && dist(q,t)<dist(t,s) ) {
								cost[i][j] = min(cost[i][j], dist(p,q));
							}
						}
					}
				}

				rep(ii, 5) {
					rep(jj, 5) {
						cost[i][j] = min(cost[i][j], dist(star[i][ii], star[j][jj]));
					}
				}
			}
		}
		rep(i, N) {
			rep(j, N) {
				cost[i][j] = cost[j][i] = min(cost[i][j], cost[j][i]);
			}
		}
		rep(k, N) {
			rep(i, N) {
				rep(j, N) {
					cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
				}
			}
		}
		printf("%.10lf\n", min(cost[M-1][L-1],cost[L-1][M-1]));
	}
	return 0;
}

Measured memory_bytes: 1172
N = int(input())
A = [list(map(int,input().split())) for _ in range(N)]
cnt = 0
for i in range(N):
    for j in range(N):
        cnt += A[i][j]
flg = 0
B = [[0 for _ in range(N)] for _ in range(N)]
for k in range(N):
    for i in range(N):
        for j in range(N):
            if A[i][j]>A[i][k]+A[k][j]:
                flg = -1
                break
            elif A[i][j]==A[i][k]+A[k][j] and A[i][k]*A[k][j]>0 and B[i][j]==0:
                cnt -= A[i][j]
                B[i][j]=1
        if flg==-1:break
    if flg==-1:break
if flg==-1:
    print(-1)
else:
    print(cnt//2)          

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

#ifndef LOCAL_
#define fprintf if( false ) fprintf
#endif // LOCAL_
#define dump() fprintf(stderr, "#%s.%d\n", __func__, __LINE__);
#define dumpl(x1) fprintf(stderr, "#%s.%d (%s) = (%ld)\n", __func__, __LINE__, #x1, x1);
#define dumpll(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%ld, %ld)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define dumplll(x1, x2, x3) fprintf(stderr, "#%s.%d (%s, %s, %s) = (%ld, %ld, %ld)\n", __func__, __LINE__, #x1, #x2, #x3, x1, x2, x3);
#define dumpd(x1) fprintf(stderr, "#%s.%d (%s) = (%lf)\n", __func__, __LINE__, #x1, x1);
#define dumpdd(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%lf, %lf)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define loop for(;;)
#define guard(x) if( not ( x ) ) continue;
typedef int64_t Int;
typedef std::vector<Int> LI;
const double pi = 3.14159265358979323846264338;
const Int mod = 1000000007;

template<typename T> void scan1(T& x) { fprintf(stderr, "unknown type\n"); }
template<> void scan1(Int& x) { if( scanf("%" PRId64, &x) < 0 ) exit(0); }
template<> void scan1(std::string& x) { if( not ( std::cin >> x ) ) exit(0); }
template<> void scan1(LI& xs) { for(Int &x : xs) scan1(x); }
void scan() {}
template<typename Head, typename... Tail>
void scan(Head& x, Tail&... xs) {
  scan1(x); scan(xs...);
}

struct Solver {
   Solver() { fprintf(stderr, "--------Solver begin--------\n"); }
   ~Solver() { fprintf(stderr, "--------Solver end--------\n"); }
   void solve() {
      Int x, y; scan(x, y);
      Int res = (x + y + 1) / 2;
      printf("%ld\n", res);
   }
};

int main() {
   loop std::unique_ptr<Solver>(new Solver())->solve();
}




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

const int N = 1e5 + 10;

long long a[N], b[N];

int main(){
	int n;
	long long sum;
	scanf("%d",&n);
	for (int i = 1; i <= n; i++) scanf("%lld %lld",&a[i],&b[i]);
	sum = 0;
	for (int i = n; i >= 1; i--){
		if ((a[i] + sum) % b[i]) sum += b[i] - (a[i] + sum) % b[i];
	}
	printf("%lld\n", sum);
	return 0;
}

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

char A[15];

int main() {
    scanf("%s", A+1);
    int n = strlen(A+1);
    bool st = true;
    if(A[1] != 'A') st = false;
    vector<int> posC;
    for(int i = 1; i <= n; ++i) {
        if(A[i] == 'C') posC.emplace_back(i);
    }
    if(posC.size() != 1) st = false;
    if(!st) return !printf("WA");
    if(!(posC[0] >= 3 && posC[0] < n)) st = false;
    A[1] = 'a', A[posC[0]] = 'c';
    for(int i = 1; i <= n; ++i) if(A[i] <= 'Z') st = false;
    puts(st ? "AC" : "WA");
}

Measured memory_bytes: 256
n = int(input())
arr = []
for i in range(n):
  arr.append("".join(sorted(input())))
arr1 = sorted(arr)
count = 0
b1 = arr1[0]
l = []
for i in range(n-1):
  b2 = arr1[i+1]
  if b2 == b1:
    count += 1
    if i == n-2:
      l.append(count)
  else:
    l.append(count)
    count = 0
  b1 = b2
sums = 0
for j in l:
  for k in range(1,j+1):
    sums += k
print(sums)
    

Measured memory_bytes: 12040
use std::io::prelude::*;
use std::io::stdin;
use std::str::FromStr;

fn main() {
    let ab: i32 = read();
    let bc: i32 = read();
    print!("{}", (ab * bc) / 2);
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|b| b.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


Measured memory_bytes: 4352
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>

using ll = long long;

using namespace std;

int main() {
    int k;
    cin >> k;
    queue<ll> q;
    for (int i=1; i<10; i++) q.push(i);
    ll ans;
    for (int i=0; i<k; i++) {
        ans = q.front(); q.pop();
        ll d = ans % 10;
        for (int j=max(d-1, 0ll); j<=d+1 && j<10; j++) q.push(ans * 10+ j);
    }
    cout << ans << '\n';
    return 0;
}

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

#define irep(i,n) for(int i = 0; i < (int)(n); i++)
#define irep2(i,a,n) for(int i = (int)(a); i <= (int)(n); i++)
#define lrep(i,n) for(long long  i = 0; i < (long long)(n); i++)
#define lrep2(i,a,n) for(long long i = (long long)(a); i <= (long long)(n); i++)
#define irrep(i,n) for(int i = (int)(n-1); i > -1; i--)
#define irrep2(i,a,n) for(int i = (int)(n); i >= (int)(a); i--)
#define fi first
#define se second

using ll = long long;
using v_int = std::vector<int>;
using v2_int = std::vector<v_int>;
using v_ll = std::vector<ll>;
using v2_ll = std::vector<v_ll>;
using v_string = std::vector<std::string>;
using v_bool = std::vector<bool>;
using v2_bool = std::vector<v_bool>;
using pii = std::pair<int, int>;
using pll = std::pair<ll, ll>;

const double PI = 3.1415926535897932;
const int INF = (int)1e9;
const ll LINF = (ll)1e18;
const ll MOD = 1000000007;
const int dr[4] = {1, 0, -1, 0};
const int dc[4] = {0, 1, 0, -1};

using namespace std; 

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

template<typename T, typename U, typename V> inline
ostream& operator<<(ostream &o, tuple<T,U,V> &p)
{
    return o << "{" << get<0>(p) << "," << get<1>(p) << "," << get<2>(p) << "}";
}

template<typename T> inline
istream& operator>>(istream &is, vector<T> &v)
{
    int len = (int)v.size();
    for(int i = 0; i < len; i++) {
        is >> v[i]; 
    }
    return is;
}

template<typename T> inline
ostream& operator<<(ostream &os, vector<T> &v)
{
    int len = (int)v.size();
    for(int i = 0; i < len; i++) { 
        os << v[i];
        if(i != len-1) { os << ","; } 
    } 
    return os;
}

template<typename T> inline
void chmin(T &a, T &b) { a = min(a, b); }

template<typename T> inline
void chmax(T &a, T &b) { a = max(a, b); }

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

    v_int a(n);
    cin >> a;

    sort(a.begin(), a.end());
    
    vector<pii> b; 
    irep(i, m) {
        int x, y;
        cin >> x >> y;
        b.push_back(pii(y,x)); 
    }

    sort(b.rbegin(), b.rend());

    v_int c(n);
    int cnt = 0;

    irep(i, m) {
        if(cnt >= n) { break; }
        irep(j, b[i].se) {
            if(cnt >= n) { break; }
            c[cnt++] = b[i].fi;
        }
    }
    
    ll sum = 0;
    irep(i, n) {
        sum += max(c[i], a[i]); 
    }
    cout << sum << endl;
    return 0;
}

/*atcoder*/


Measured memory_bytes: 4884
HN=input()
HN_list=HN.split()
H=int(HN_list[0])
N=int(HN_list[1])
A=input()
A_list=A.split()
aaa=map(int, A_list)
A_sum=sum(aaa)
if A_sum>=H:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 10528
#include<stdio.h>
#include<stdlib.h>
int N,M,A,i,a[1001][3],r[101];
int c(const void *a,const void *b)
{
	return ((int*)b)[0]-((int*)a)[0];
}
int main()
{
	for(;scanf("%d%d%d",&N,&M,&A),N;)
	{
		for(i=0;i<M;i++)
			scanf("%d%d%d",&a[i][0],&a[i][1],&a[i][2]);
		qsort(a,M,sizeof(int[3]),c);
		for(i=1;i<=N;i++)r[i]=i;
		for(i=0;i<M;i++)
			r[a[i][1]]^=r[a[i][2]]^=r[a[i][1]]^=r[a[i][2]];
		for(i=1;i<=N;i++)
			if(r[i]==A)
				printf("%d\n",i);
	}
	return 0;
}

Measured memory_bytes: 672
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
#include <algorithm>
#include <tuple>
#include <list>
#include <deque>
#include <stack>
#include <complex>
#include <functional>
#include <regex>
#include <map>
#include <numeric>

using namespace std;

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

const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1};
const int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

using ll = long long;
using ld = long double;
using ull = unsigned long long;

const int PI = acos(-1);
const int INF = numeric_limits<int>::infinity() / 2;
const ll INFLL = numeric_limits<ll>::infinity() / 2;

ll dp[100001][4];

const ll mod = 1000000007;

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

  dp[S.size()][3] = 1;
  rep(j, 3) dp[S.size()][j] = 0;

  ll m1, m2;
  for (int i = S.size() - 1; i >= 0; --i) {
    m1 = S[i] == '?' ? 3 : 1;
    dp[i][3] = (m1 * dp[i+1][3]) % mod;

    for (int j = 2; j >= 0; --j) {
      m2 = ((S[i] == '?' || (S[i] - 'A' == j)) ? 1 : 0);
      dp[i][j] = (m1 * dp[i+1][j] + m2 * dp[i+1][j+1]) % mod;
    }
  }

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

  return 0;
}


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


int main(){
    string s1,s2;
    cin>>s1>>s2;
    int n1,n2;
    cin>>n1>>n2;
    string s3;
    cin>>s3;
    if(s3==s1)
    cout<<n1-1<<" "<<n2;
    else
    cout<<n1<<" "<<n2-1;
    
    
  
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
long long dp[100010][13];

int main() {
    string s; cin >> s;
    dp[0][0] = 1;
    for (int i = 0; i < s.size(); i++) {
        char c = s[i];
        if (c == '?') {
            for (int j = 0; j < 13; j++) {
                for (int k = 0; k < 10; k++) {
                    dp[i+1][(j*10+k)%13] += dp[i][j];
                    dp[i+1][(j*10+k)%13] %= mod;
                }
            }
        } else {
            int t = c - '0';
            for (int j = 0; j < 13; j++) {
                dp[i+1][(j*10+t)%13] += dp[i][j];
                dp[i+1][(j*10+t)%13] %= mod;
            }
        }
    }
    cout << dp[s.size()][5] << endl;
    return 0;
}

Measured memory_bytes: 10624
#include<stdio.h>
int main()
{
    int i,c=0;
    float n,a;
    scanf("%f",&n);
    for(i=1;i<=n;i++)
    {
        if(i%2==0)
        {   c=c+0;   }
        else
        {
            c++;
        }
    }
    a = c/n;
    printf("%f",a);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll=long long int;
#define all(c) (c).begin(), (c).end()
#define rep( i, a, n ) for( int i=a; i<n; i++ )
#define repp( i, a, n, p ) for( int i=a; i<n; i+=p )
#define per( i, a, n ) for( int i=n-1; i>=a; i--)
#define pb push_back
#define mp make_pair
#define acc accumulate

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

    ll sum =0;
    sum += (n/500) * 1000;
    n %= 500;
    sum += (n/5) *5;

    cout << sum << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        if (a < b) {
            System.out.println("0");
        } else {
            System.out.println("10");
        }

    }

}

Measured memory_bytes: 21844
#include <cstdio>

const int MaxN = 1000000;

int N, K;
int A[MaxN + 5];

void init() {
  static char s[MaxN + 5];
  scanf("%d", &N);
  N--;
  scanf("%s", s + 1);
  for (int i = 1; i <= N; ++i)
    if (s[i] < s[i + 1]) A[i] = s[i + 1] - s[i];
    else A[i] = s[i] - s[i + 1];
}

void solve() {
  K = 1;
  for (int i = 1; i <= N; ++i)
    if (A[i] == 1) K = 0;
  for (int i = 1; i <= N; ++i)
    if (K == 1) A[i] >>= 1;
    else A[i] &= 1;
  int ans = 0;
  for (int i = 1; i <= N; ++i)
    if (A[i] == 1 && ((N - 1) & (i - 1)) == i - 1)
      ans ^= 1;
  printf("%d\n", ans << K);
}

int main() {
  init();
  solve();
  return 0;
}

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

template <typename T> T load() { T r; cin >> r; return r; }
template <typename T> vector<T> loadMany(int n) { vector<T> rs(n); generate(rs.begin(), rs.end(), &load<T>); return rs; }

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	auto n = load<int>();
	auto xs = loadMany<int>(n);
	auto dyn = vector<int>(n, 0);
	for (auto i=1; i<n; ++i)
		dyn[i] = min(dyn[i-1] + abs(xs[i]-xs[i-1]), i > 1 ? dyn[i-2] + abs(xs[i]-xs[i-2]) : numeric_limits<int>::max());
	cout << dyn[n-1] << '\n';
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
namespace mp = boost::multiprecision;
long long int gcd(long long int x, long long int y){
  return y!=0 ? gcd(y, x%y) : x;
}
long long int lcm(long long int x, long long int y){
  return x*y/gcd(x, y);
}
long long int factorial(long long int x){
  return x==0 ? 1 : x*factorial(x-1);
}
// mod. m での a の逆元 a^{-1} を計算する
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
int main(){
  int i, j, n, t;
  long long ans=0;
  cin >> n >> t;
  int tt[n];
  for(i=0; i<n; i++)
    cin >> tt[i];
  for(i=0; i<n-1; i++)
    if(tt[i+1]-tt[i]>t) ans+=t;
    else ans+=(tt[i+1]-tt[i]);
  cout << ans+t;
  return 0;
}


Measured memory_bytes: 1024
#!/usr/bin/env python
# -*- coding: utf-8 -*-

POSITIONS = ["top", "south", "east", "west", "north", "bottom"]


class Dice(object):

    def __init__(self, initial_faces):
        self.faces = {p: initial_faces[i] for i, p in enumerate(POSITIONS)}
        self.store_previous_faces()

    def store_previous_faces(self):
        self.previous_faces = self.faces.copy()

    def change_face(self, after, before):
        self.faces[after] = self.previous_faces[before]

    def change_faces(self, rotation):
        self.change_face(rotation[0], rotation[1])
        self.change_face(rotation[1], rotation[2])
        self.change_face(rotation[2], rotation[3])
        self.change_face(rotation[3], rotation[0])

    def roll(self, direction):
        self.store_previous_faces()
        if direction == "E":
            self.change_faces(["top", "west", "bottom", "east"])
        elif direction == "N":
            self.change_faces(["top", "south", "bottom", "north"])
        elif direction == "S":
            self.change_faces(["top", "north", "bottom", "south"])
        elif direction == "W":
            self.change_faces(["top", "east", "bottom", "west"])

    def rolls(self, directions):
        for d in directions:
            self.roll(d)


def main():
    dice = Dice(input().split())
    q = int(input())
    for x in range(q):
        [qtop, qsouth] = input().split()
        if qsouth == dice.faces["west"]:
            dice.roll("E")
        elif qsouth == dice.faces["east"]:
            dice.roll("W")
        while qsouth != dice.faces["south"]:
            dice.roll("N")
        while qtop != dice.faces["top"]:
            dice.roll("W")
        print(dice.faces["east"])

if __name__ == "__main__":
    main()

Measured memory_bytes: 7740
#include <stdio.h>
int main(void){
    // Here your code !
    int h,w;
    int i,j;
    while(1){
        scanf("%d %d\n", &h, &w);
        if( h == 0 && w == 0){
            break;
        }
        for( i = 0; i < h; ++i){
            for( j = 0; j < w; ++j){
                if( (i%2 == 0 && j%2 == 0) || ( i%2 == 1 && j%2 == 1) ){
                    printf("#");
                }else{
                    printf(".");
                }
            }
            printf("\n");
        }
        printf("\n");
    }
    return 0;
}

Measured memory_bytes: 576
#include <iostream>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include<cassert>
#include<cmath>
#include<climits>
#include<iomanip>
#include<bitset>
#include<unordered_map>

using namespace std;

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define rep(i,j,n) for(ll (i)=(j);(i)<(n);(i)++)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
#define en '\n'
typedef pair<ll, ll> P;
const long long INF = 1LL << 60;
const long long MOD = 1e9 + 7;
typedef vector<ll> Array;
typedef vector<Array> Matrix;
const int loose = 0;
const int tight = 1;

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

//グラフ関連
struct Edge {//グラフ
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
		to = _to; cap = _cap; rev = _rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

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

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

	Array a(m), b(m),c(m,0);
	REP(i, m) {
		cin >> a[i] >> b[i];
		REP(j, b[i]) {
			ll cc;
			cin >> cc;
			cc--;
			c[i] |= (1LL << cc);
		}
	}


	Matrix dp(m+1,Array(1LL << n, INF));
	dp[0][0] = 0;

	REP(i, m) {
		REP(bit, 1 << n) {
			if (dp[i][bit] == INF) continue;
			chmin(dp[i + 1][(bit | c[i])], dp[i][bit] + a[i]);//鍵を使う
			chmin(dp[i + 1][bit], dp[i][bit]);//鍵を使わない
		}
	}

	ll ans = dp[m][(1LL << n) - 1];
	cout << ((ans==INF)?-1:ans)<<en;

	return 0;
}


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

constexpr int inf = 0x3f3f3f3f;
constexpr ll linf = 0x3f3f3f3f3f3f3f3fLL;

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

    int n; cin >> n;
    vector<int> a(n);
    map<int, int> mp;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        mp[a[i]]++;
    }
    sort(a.begin(), a.end());
    a.erase(unique(a.begin(), a.end()), a.end());
    vector<bool> is(1000001, true);
    for (auto &e: a) {
        for (int i = e * 2; i <= 1000000; i += e) {
            is[i] = false;
        }
    }
    int ans = 0;
    for (auto &e: a) {
        if (mp[e] > 1) continue;
        if (is[e]) ans++;
    }
    cout << ans << endl;
    return 0;
}


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

int n;
int M[305][305];
int main()
{
   ios_base::sync_with_stdio(false);
   cin >> n;
   for (int i = 1; i <= n; i++)
      for (int j = 1; j <= n; j++)
         cin >> M[i][j];

   long long cost = 0;
   for (int i = 1; i <= n; i++)
      for (int j = i + 1; j <= n; j++)
      {
         bool ok = 0;
         for (int k = 1; k <= n; k++)
         {
            if (i == k || j == k)
               continue;
            if (M[i][k] + M[k][j] < M[i][j])
            {
               cout << -1;
               return 0;
            }
            if (M[i][k] + M[k][j] == M[i][j])
               ok = 1;
         }
         if (!ok) // nu avem intermediar
            cost += M[i][j];
      }
   cout << cost;
   return 0;
}


Measured memory_bytes: 640
#-------------------------------------------------------------------
import sys
def _p(*_a):
  _s=" ".join(map(str,_a))
  #print(_s)
  sys.stderr.write(_s+"\n")
#-------------------------------------------------------------------
import math

def factorize(n):
  ret, a = [], n
  for i in range(2, int(n**0.5)+1):
    if a%i>0: continue
    c=0
    while a%i==0:
      a//=i
      c+=1
    else:
      ret.append((i,c))
  if a!=1: ret.append((a,1))
  return ret


n = int(input())
N = factorize(n)

ans=0
for p,i in N:
  for j in range(i):
    a = pow(p,j+1)
    if n % a == 0:
      n /= a
      ans += 1

print(ans)



Measured memory_bytes: 9512
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
template<typename T, typename U> static void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> static void amax(T &x, U y) { if(x < y) x = y; }

int main() {
	char s[100001];
	while(~scanf("%s", s)) {
		int n = (int)strlen(s);
		pair<int, int> ans(-1, -1);
		rer(a, 'a', 'z') {
			int num = 0;
			pair<int, int> prev(0, 0), minPos(0, 0);
			rep(i, n) {
				if(s[i] == a) {
					++ num;
					if(i != 0 && 2 * num - (i + 1) > minPos.first) {
						ans = make_pair(minPos.second, i);
						break;
					}
				}
				amin(minPos, prev);
				prev = make_pair(num * 2 - (i + 1), i + 1);
			}
			if(ans.first != -1) break;
		}
		if(ans.first == -1)
			puts("-1 -1");
		else
			printf("%d %d\n", ans.first + 1, ans.second + 1);
	}
	return 0;
}


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

int gcd(int x,int y){return y?gcd(y,x%y):x;}

int array_gcd(int a[],int size){
	int x=a[0];
	for(int i=1;i<size;i++)x=gcd(x,a[i]);
	return x;
}

int main(void){
  int n;
  cin>>n;
  int a[n];
  for(int i=0;i<n;i++)cin>>a[i];
  cout<<array_gcd(a,n);
  return 0;
}

Measured memory_bytes: 1020
import sys
from collections import defaultdict
readline = sys.stdin.buffer.readline
#sys.setrecursionlimit(10**8)


def geta(fn=lambda s: s.decode()):
    return map(fn, readline().split())


def gete(fn=lambda s: s.decode()):
    return fn(readline().rstrip())


def main():
    a = gete(int)
    s = gete()

    if a < 3200:
        print('red')
    else:
        print(s)


if __name__ == "__main__":
    main()

Measured memory_bytes: 3436
#include <iostream>
#include <vector>
#include <utility>
#include <map>
using namespace std;

typedef pair<int,pair<int,int> > triple;

long MOD = 1000000007;

int n;
vector<int> A;
map<triple, int> mem;
long dp(int r, int b, int g){
	int prog = r+b+g;
	if(prog == n) return 1;
	triple c = pair<int, pair<int, int> >(r, pair<int,int>(b,g));
	if(mem.find(c) != mem.end()) return mem[c];
	int at = prog;
	long sm = 0;
	if(r == A[at]) sm += dp(r+1,b,g);
	if(b == A[at]) sm += dp(r,b+1,g);
	if(g == A[at]) sm += dp(r,b,g+1);
	return mem[c] = sm % MOD;
}

int main() {
	cin >> n;
	A = vector<int>(n);
	for(int i = 0; i < n; i++) cin >> A[i];
	cout << dp(0,0,0);
	return 0;
}

Measured memory_bytes: 47360
function Scanner(input) {
	var self = this;
	self.itemNo = 0;
	self.orgStr = input;
	self.splitedStrs = (function(target) {
		var result = [];
		var target = target.replace(/[\n \t]+/g, " ");
		var strs = target.split(" ");
		for (var i = 0, len = strs.length; i < len; i++) {
			result.push(strs[i]);
		}
		return result;
	}(input));

	self.next = function() {
		var result = self.splitedStrs[self.itemNo];
		self.itemNo++;
		return (result != null) ? result : null;
	}

	self.nextInt = function() {
		var result = self.splitedStrs[self.itemNo];
		self.itemNo++;
		return (result != null) ? parseInt(result) : null;
	}

	self.nextBigDecimal = function() {
		var result = self.splitedStrs[self.itemNo];
		self.itemNo++;
		return (result != null) ? parseFloat(result) : null;
	}
	
	self.nextByte = function() {
		var result = self.splitedStrs[self.itemNo];
		self.itemNo++;
		return (result != null) ? new Int8Array(result) : null;
	}

}

function Main(sc) {

	var N = sc.nextInt();
	
	var przs = {};
	var cnt = 0;
	for (var i = 0; i < N; i++) {
		var prz = sc.next();
		if (!przs[prz]) {
			przs[prz] = true;
			cnt++;
		}
	}
	 
	console.log(cnt);
}
Main(new Scanner(require("fs").readFileSync("/dev/stdin", "utf8")));
// Main(new Scanner("10 1 2 5 3 4 6 7 3 2 4 1 2 2 3 3 4 4 5 3 6 6 7 1 8 8 9 9 10"));

// var str1 = sc.next(); // Stringで取得
// var int1 = sc.nextInt(); // intで取得
// var bd1 = sc.nextBigDecimal(); // BigDecimalで取得
// var byte1 = sc.nextByte(); // byteで取得
// for (var i = 0; i < 1000000000; i++) var toDelay = "aaa"; // 1000msくらいの遅延
// console.log(wrtnNos); return;


Measured memory_bytes: 107108