akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>

int main(){
	int n,m;
	int **a,*b,*c;
	
	scanf("%d %d",&n,&m);
	
	a=(int**)malloc(n*sizeof(int*));
	b=(int*)malloc(m*sizeof(int));
	c=(int*)malloc(n*sizeof(int));

	for(int i=0;i<n;i++){
		a[i]=(int*)malloc(m*sizeof(int));
		for(int j=0;j<m;j++){
			scanf("%d",&a[i][j]);
		}
	}
	//printf("////////////////////////////////////");
	for(int i=0;i<m;i++){
		scanf("%d",&b[i]);
	}
	//printf("////////////////////////////////////");
	for(int i=0;i<n;i++){
		c[i]=0;
		for(int j=0;j<m;j++){
			c[i]+=(a[i][j]*b[j]);
		}
	}
	//printf("////////////////////////////////////");
	for(int i=0;i<n;i++){
		printf("%d\n",c[i]);
	}

	return 0;
}


Measured memory_bytes: 2056
#include<bits/stdc++.h>
#include <queue>
#include <cstring>

#define mp make_pair
#define pb push_back
#define p push

#define FOR(a, c) for(int a = 0;a<c;a++)
#define ll long long int

#define getI(a) scanf("%d",&a)
#define getII(a, b) scanf("%d%d",&a,&b)
#define getIII(a, b, c) scanf("%d%d%d",&a,&b,&c)
#define getL(a) scanf("%lld",&a)
#define getLL(a, b) scanf("%lld%lld",&a,&b)
#define getLLL(a, b, c) scanf("%lld%lld%lld",&a,&b,&c)
#define BEND(c) (c).begin(),(c).end()
#define BEND2(c) (c).rbegin(),(c).rend()
#define fi first
#define se second
#define pi 3.1415926535897932384626
#define getS(a) scanf("%s",a)
#define pfi(a) printf("%d",a);
#define pfii(a, b) printf("%d%d",a,b);
#define pfl(a) printf("%lld",a);
#define pfll(a, b) printf("%lld%lld",a,b);
#define pfd(a) printf("%lf",a);
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);

#define sag (sol|1)
#define sol (root<<1)
#define ort (bas+son)/2
#define SIZE  ( int)(1e9 + 7)
#define MAXN (ll) (1e5+5)

using namespace std;

typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector <vector<int>> vvi;
typedef vector<long long> vl;
typedef vector <pair<int, int>> vpi;
typedef vector <pair<long long, long long>> vpl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector <vi> graph;

int k = 5;

int main (){
    IOS
   ll n,m;
    cin >>n>>m;
    ll k = m*n;
    ll t = __gcd(m,n);
    cout <<(k/t);
    return 0;
}

Measured memory_bytes: 256
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var arr=input.trim().split("\n");
var n=arr.shift()-0;
var p=arr.shift().split(" ").map(Number);
var t=arr.shift().split(" ").map(Number);
var s=[];
for(var i=0;i<=200;i++)s[i]=Infinity;
s[0]=0;
for(var i=0;i<=100;i++){
   if(s[i]==Infinity)continue; 
   s[i+t[0]]=Math.min(s[i]+p[0],s[i+t[0]]);
   s[i+t[1]]=Math.min(s[i]+p[1],s[i+t[1]]);
   s[i+t[2]]=Math.min(s[i]+p[2],s[i+t[2]]);
   s[i+t[3]]=Math.min(s[i]+p[3],s[i+t[3]]);
}
var min=Infinity;
for(var i=n;i<=200;i++)min=Math.min(min,s[i]);
console.log(min);


Measured memory_bytes: 15484
import sys

N=int(input())
W=[list(input()) for i in range(N)]
for i in range(N):
    for j in range(i+1,N):
        if W[i]==W[j]:
            print("No")
            sys.exit()
for i in range(1,N):
    if W[i][0]==W[i-1][-1]:
        continue
    else:
        print("No")
        break
else:
    print("Yes")

Measured memory_bytes: 38768
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

const int MAXN=1000000;
const int MOD=1000000007;

int n;

int go(int pos) {
	if(pos==n-1) return n;
	int ret=go(pos+1);
	FORE(i,2,n) {
		ret+=n-1;
		if(pos+1+i>=n) ret++; else ret+=go(pos+1+i);
	}
	return ret;
}

int dp[MAXN];


void run() {
	scanf("%d",&n);
	dp[n-1]=n;
	int sum=0;
	for(int i=n-2;i>=0;--i) {
		if(i+3<n) sum=(sum+dp[i+3])%MOD;
		dp[i]=(dp[i+1]+(ll)(n-1)*(n-1)+(n-(n-i-1)+1-(i==n-2?1:0))+sum)%MOD;
		//printf("dp[%d]=%d\n",i,dp[i]);
	}
	printf("%d\n",dp[0]);
	//{ int ret=go(0); printf("rec=%d\n",ret); }
}

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


Measured memory_bytes: 4096
let rec dig_sum x = if x <= 0 then 0 else x mod 10 + dig_sum (x / 10)
let n = Scanf.scanf "%d" (fun x -> x)
let () =
  Array.init (n-1) (fun i ->
    let a, b = i+1, n-1-i in
    dig_sum a + dig_sum b)
  |> Array.fold_left min 1010
  |> Printf.printf "%d\n"


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

int main(void){
    int n, a[101];
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    sort(a,a+n);
    int s = a[0],ans = 0;
    for(int i=1;i<n;i++){
        if(a[i] == a[i-1]){
            continue;
        }
        ans += (a[i] - a[i-1]);
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n)　for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
#define Eunique(v) v.erace(unique(all(v)),v.end())
#define pvec(v)　rep(i,v.size()){cout << v[i] << " ";}
#define INF 0x3f3f3f3f
#define mset(m,v) memset(m,v,sezeof(m))
#define mod 1e9 +7;

const double pi = acos(-1.0);

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef deque<ll> dll;
typedef pair<ll,ll> P;
ll dx[4] = {1,0,-1,0},dy[4] = {0,1,0,-1};

ll gcd(ll x,ll y)
{
    ll r;
    while((r = x % y) != 0)
    {
        x = y;
        y = r;
    }
    return y;
}

ll lcm(ll x,ll y)
{
    x /= gcd(x,y);
    y /= gcd(x,y);
    return (x*y);
}

int main()
{
    string s;
    cin >> s;
    rep(i,SIZE(s)){
        if(s[i] == ',')cout << " ";
        else cout << s[i];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
import collections

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

c = collections.Counter(A)
cs = sorted(c.items(), key=lambda x:x[0])
cnt = 0
for i in range(len(cs)):
    if(cs[i][0] != cs[i][1]):
        if(cs[i][0] < cs[i][1]):
            cnt += cs[i][1]-cs[i][0]
        else:
            cnt += cs[i][1]
print(cnt)

Measured memory_bytes: 21744
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
using namespace std;

int main(){
    char flame[200][200];
    rep(i,200) rep(j,200) flame[i][j] = '#';

    int h, w;
    cin >> h >> w;
    rep(i,h){
        rep(j,w){
            cin >>  flame[i + 1][j + 1];
        }
    }
    rep(i,h + 2){
        rep(j,w + 2){
            cout << flame[i][j];
        }
        cout << endl;
    }
    cout << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl "\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using ll = long long;
const int INF = 0x3f3f3f3f;
using namespace std;
const double PI = acos(-1);
const int N = 1e5+1;

int n, m, dp[2][1001], M = 1e9+7;
string arr[1001];
int main() {
    //freopen("lazy.in", "r", stdin);
    IOS
    cin >> n >> m;
    for (int i = 0; i < n; ++i) {
        cin >> arr[i];
    }
    dp[0][1]= 1;
    int r = 0;
    for (int i = 1; i <= n; ++i) {
        r ^= 1;
        for (int j = 1; j <= m; ++j) {
            if (arr[i-1][j-1] == '.') {
                dp[r][j] = dp[r^1][j] + dp[r][j-1];
                if (dp[r][j] >= M) {
                    dp[r][j] -= M;
                }
            } else {
                dp[r][j] = 0;
            }
        }
    }
    cout << dp[r][m] << endl;
    return 0;


}


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

int main(void){
    int n;
    while(cin>>n, n){
        vector<int> a(n);
        rep(i,n){
            cin>>a[i];
        }
        int ave = accumulate(all(a), 0)/n;
        int cnt = 0;
        rep(i,n){
            if(a[i] <= ave) cnt++;
        }
        cout<<cnt<<endl;
    }  
    return 0;
}



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

int main() {
	int a,b,c;
	int k;
	cin >> a >> b >> c >> k;
	int min_i = min(a, min(b, c));
	int max_i = max(a, max(b, c));
	int m = a + b + c - min_i - max_i;
	
	for(int i = 0; i < k; i++)
	{
		max_i *= 2;
	}
	cout << min_i + max_i + m << endl;
	return 0;
}


Measured memory_bytes: 256
/*

Coded by peyha X

*/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int KMAX=1e5+1,NMAX=1e2+1,MOD=1e9+7;
int ways[2][KMAX],prefix[2][KMAX],a[NMAX],n,k;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	cin >> n >> k;
	
	for(int i=1;i<=n;i++){
		cin >> a[i];
	}
	
	
	ways[0][0]=1;
	
	for(int i=1;i<=n;i++){
		int actuel=i%2,before=(i-1)%2;
		
		for(int j=0;j<=k;j++) prefix[before][j]=0;
		prefix[before][0]=ways[before][0];
		for(int j=1;j<=k;j++) prefix[before][j]=(ways[before][j]+prefix[before][j-1])%MOD;
		
		for(int j=0;j<=k;j++){

			if(j<=a[i]){
				ways[actuel][j]=prefix[before][j];
			}
			else{
				ways[actuel][j]=(prefix[before][j]-prefix[before][j-a[i]-1])%MOD;
			}
		}
	}
	int ans=ways[n%2][k];
	while(ans<0) ans+=MOD;
	
	cout << ans << endl;

}



Measured memory_bytes: 1792
#include <iostream>
#include<set>
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL)
#define fo(i,n) for(int i=1;i<=n;i++)
#define fo1(i,n) for(int i=0;i<n;i++)
#define lli long long int
#define llu unsigned long long int
#define vi vector <int>
#define vii vector <long long int>
#define pb push_back
#define eb emplace_back
#define pi pair<int,int>
#define mk make_pair
#define mpp map<int,int>
#define ff first
#define ss second
#define mod 1000000007

using namespace std;

int main()
{
	int x,y;
	cin>>x>>y;
	if(y%2==0 && y<=4*x && y>=2*x)
		cout<<"Yes\n";
	else
		cout<<"No\n";
}


Measured memory_bytes: 3036
L, R = list(map(int, str(input()).split()))

# L と Rの差が十分に大きければ、答えは0になる
# それ以外の状況であれば愚直に計算しても大した計算量ではない。

MOD = 2019
ouput = 2020 * 2020
for i in range(L, R + 1):
    for j in range(L, R + 1):
        if j > i and ouput > (i * j) % MOD:
            ouput = (i * j) % MOD
            if ouput == 0:
                print(ouput)
                exit()

print(ouput)


Measured memory_bytes: 2940
# AtCoder
from collections import defaultdict
N = int(input())
A = list(map(int, input().split()))

d = defaultdict(int)
for i in range(1, N+1):
    d[i] = 0

for i in range(N-1):
    d[A[i]] += 1

for i in d.values():
    print(i)


Measured memory_bytes: 40528
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define erep(i, n) for (ll i = 0; i <= (ll)(n); ++i)
#define FOR(i,a,b) for (ll i = (a); i < (ll)(b); ++i)
#define EFOR(i,a,b) for (ll i = (a); i <= (ll)(b); ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } }

typedef pair<int, int> P;
ll modnum = 1e9+7;

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int main() {
    int n; cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    ll ans = 0;
    rep(i, 60) {
        ll one = 0;
        // a[j]のi桁目が1の個数をカウントする
        rep(j, n) if(a[j]>>i&1) one++;
        // 1か0しかないので、残りが0
        ll zero = n - one;
        // i桁目の1と0の組み合わせ数(1の個数×0の個数)だけi桁目に1ができる
        ll now = one*zero%modnum;
        // i桁目の1は2^iに値する, それらの和になる
        ll digit = modpow(2, i, modnum);
        ans += now * digit % modnum;
        ans %= modnum;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
#include<cmath>
#include<cstring>
#include<climits>
#define int long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
#define asc(a,n) sort(a,a+n);
#define dsc(a,n) sort(a,a+n,comp);
#define fo(i,x,y) for(int i=x;i<y;i++)
#define inarr(x) int n; cin>>n; int x[n]; fo(i,0,n){cin>>x[i];}
#define test int t; cin>>t; while(t--)
using namespace std;

int basic(){freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);return 0;}
bool comp(int a,int b){return a>b;}



int32_t main()
{ //basic(); 
  fast;
  int a,b;
  cin>>a>>b;
  if(a<=b){cout<<"unsafe";}
  else{cout<<"safe";}
  
}





//

Measured memory_bytes: 3612
n = int(input())
a = [list(map(int, input().split())) for i in range(n)]
dp = [[0 for i in range(3)] for j in range(n)]
dp[0]= a[0]

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

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

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

#define llint long long int

bool is_pi_center(int a, int b, int c){
  if(a<b && b<c) return true;
  if(c<b && b<a) return true;
  return false;
}

int main(void){

  int n;
  std::cin >> n;
  std::vector<int> p(n);

  for(int i=0; i<n; i++){
    std::cin >> p[i];
  }

  int count = 0;
  for(int i=1; i<n-1; i++){
    if(is_pi_center(p[i-1], p[i], p[i+1])){
      count++;
    }
  }
  std::cout << count << std::endl;
  return 0;
}





Measured memory_bytes: 256
#!python3

# input
L = input()

MOD = 10 ** 9 + 7
MAX = 10 ** 5 + 5
p3 = [None] * MAX


def p3_init():
    p3[0] = 1
    for i in range(1, MAX):
        p3[i] = 3 * p3[i - 1] % MOD


def main():
    p3_init()
    n = len(L)
    w = 1
    ans = 0
    for i in range(n):
        if L[i] == "1":
            # 両方0にする場合
            ans = (ans + w * p3[n - i - 1]) % MOD
            # 片方1にする場合
            w = 2 * w % MOD
    ans = (ans + w) % MOD
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 12928
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <complex>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;


#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 100010

/* UnionFind */

struct UnionFind{
  vector<int> data, tree_size;
  UnionFind(int s):data(s,-1),tree_size(s,1) {}
  
  int root(int x){
    if(data[x]==-1) return x;
    return data[x]=root(data[x]);
  }
  
  bool set(int x,int y){
    x=root(x);
    y=root(y);
    if(x==y) return false;
    data[y]=x;
    tree_size[x] += tree_size[y];
    tree_size[y] = 0;
    return true;
  }
  
  bool check(int x,int y){
    x=root(x);
    y=root(y);
    return x==y;
  }
  
  int size(int x){
    return tree_size[root(x)];
  }
  
};

int main(){
  int n, m;
  int a[SIZE], b[SIZE];
  vector<pair<pair<int,int> ,int> > vec;
  vector<int> g[SIZE];
  pair<ll,ll> dp[SIZE];
  
  scanf("%d%d", &n, &m);
  
  for(int i=0;i<n;i++){
    scanf("%d%d", a+i, b+i);
    vec.push_back({{a[i], -b[i]}, i});
  }

  sort(vec.begin(), vec.end());

  for(int i=0;i<m;i++){
    int u, v;
    scanf("%d%d", &u,&v);
    u--; v--;
    g[u].push_back(v);
    g[v].push_back(u);
  }

  UnionFind uf(n);

  bool used[SIZE] = {};
  
  for(int i=0;i<n;i++){
    int p = vec[i].second;
    vector<int> uni;
    
    for(int j=0;j<g[p].size();j++){
      if (used[g[p][j]])
        uni.push_back(uf.root(g[p][j]));
    }
    used[p] = true;

    sort(uni.begin(), uni.end());
    uni.erase(unique(uni.begin(), uni.end()), uni.end());
    
    ll sum = 0;

    for(int j=0;j<uni.size();j++){
      sum += dp[uni[j]].second;
    }
    sum += b[p];

    pair<ll,ll> calc = {LLINF, LLINF};
    
    for(int j=0;j<uni.size();j++){
      int q = uni[j];
      ll nowcost = dp[q].first;

      nowcost += b[p];
      nowcost = max(nowcost, (ll)a[p]);
      nowcost += sum - (dp[q].second + b[p]);

      calc = min(calc, make_pair(nowcost, sum));
    }

    calc = min(calc, make_pair(max(a[p], b[p]) + (sum - b[p]), sum));
    
    for(int j=0;j<uni.size();j++){
      uf.set(p, uni[j]);
      //assert(p == uf.root(uni[j]));
    }

    dp[uf.root(p)] = calc;
    //assert(p == uf.root(p));

    //debug(uf.root(p));
    //debug(calc.first);
  }
  
  printf("%lld\n", dp[uf.root(0)].first);
  
  return 0;
}



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

int main() {
  // input
  int N,A,B;
  cin >> N >> A >> B;
  
  int ans= 0;

  for(int i=1; i<N+1; i++){ // loop in [1,N]
    int sum_digit= 0;
    int buf= i;
    while( buf>0 ){
      sum_digit += buf%10;
      buf /= 10;
    }
    
  	if( A<=sum_digit && sum_digit<=B ){
      ans += i;
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <random>
#include <cstdio>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int) n; i++)
#define all(v) v.begin(),v.end()

int main() {
    int n,k;
    cin >> n >> k;
    vector<int> cnt(200000);
    rep(i,n) {
        int a;
        cin >> a;
        cnt[a-1]++;
    }
    sort(all(cnt), greater<int>());
    int sum = 0;
    rep(i,k) {
        sum += cnt[i];
    }
    cout << n-sum << endl;
    return 0;
}

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

int main() {
    cin.tie(0)->sync_with_stdio(false);

    ll a, b;
    cin >> a >> b;

    if (a * b == 0) {
        cout << "Zero" << '\n';
        return 0;
    } else if (a * b < 0) {
        cout << "Zero" << '\n';
        return 0;
    } else if (a > 0 && b > 0) {
        cout << "Positive" << '\n';
    } else {
        ll cnt = abs(a - b) + 1;
        if (cnt % 2) cout << "Negative" << '\n';
        else cout << "Positive" << '\n';
        return 0;
    }
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
#define DBG(X) cout << #X << "=" << (X) << '\n';
#define SAY(X) cout << (X) << '\n';
#else
#define DBG(X)
#define SAY(X)
#endif

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);

const int NIL = -1;
static mt19937 _g(time(nullptr));

std::string pad(int num)
{
    char buffer[4];
    std::snprintf(buffer, sizeof(buffer), "%03d", num);
    return buffer;
}

inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline T fetch() { T ret; cin >> ret; return ret; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

#ifdef _MSC_VER
#  include <intrin.h>
#  define __builtin_popcount __popcnt
#endif

ll solve()
{
    int red, green, r, g, c;

    std::cin >> red >> green >> r >> g >> c;

    vector<int> redDel = fetch_vec<int>(r);
    vector<int> greenDel = fetch_vec<int>(g);
    vector<int> nocDel = fetch_vec<int>(c);

    std::sort(redDel.begin(), redDel.end(), std::greater<int>());
    std::sort(greenDel.begin(), greenDel.end(), std::greater<int>());
    std::sort(nocDel.begin(), nocDel.end(), std::greater<int>());

    vector<int> glob;

    for (int i = 0; i < red; ++i)
        glob.push_back(redDel[i]);

    for (int i = 0; i < green; ++i)
        glob.push_back(greenDel[i]);

    std::sort(glob.begin(), glob.end());

    for (int i = 0; i < nocDel.size() && i < glob.size(); ++i) {
        if (nocDel[i] > glob[i])
            glob[i] = nocDel[i];
        else
            break;
    }

    ll sum = std::accumulate(glob.begin(), glob.end(), 0ll);

    return sum;
}

int main()
{
    std::cout << solve() << std::endl;
//    solve();

    return 0;
}

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

#define LEN 100005

using namespace std;

typedef struct pp{
  char name[100];
  int t;
}P;

P Q[LEN];
int head,tail,n;

void enqueue(P x){
  Q[tail]=x;
  tail=(tail+1)%LEN;
}

P dequeue(){
  P x=Q[head];
  head = (head +1)%LEN;
  return x;
}

int MIN(int a, int b){
  return a<b ? a : b;
}

int main(){
int elaps=0,c;
int i,q;
P u;

cin >> n >> q;

for(i=1;i<=n;i++){
  cin >> Q[i].name >> Q[i].t;
}

head=1;
tail=n+1;

while (head!=tail) {
  u=dequeue();
  c=MIN(q,u.t);
  u.t-=c;
  elaps+=c;

  if(u.t>0){
    enqueue(u);
  }else {
    cout << u.name << " " << elaps << endl;
  }
}


return 0;
}



Measured memory_bytes: 13260
#include<stdio.h>
#include<stdlib.h>

int main(void) {
	int A[20][6];
	int a[20];
	int L;
	int i,j;
	int cnt;
	int tmp;
	int ans;
	int sub;

	while (1) {
		for (i = 0; i < 20; i++) {
			for (j = 0; j < 6; j++) {
				A[i][j] = 0;
			}
		}
		scanf("%d", &a[0]);
		scanf("%d", &L);

		if (a[0] == 0 && L == 0) {
			break;
		}

		sub = a[0];
		for (i = 0; i < L; i++) {
			A[0][L - i-1] = sub % 10;
			sub = sub / 10;
		}
		/*
		for (i = 0; i < L; i++) {
			printf("%d ", A[0][i]);
		}
		*/

		cnt = 0;
		ans = 0;
		while (1) {
			int max[6] = {};
			int min[6] = {};
			int big = 0, small = 0;


			for (i = 0; i < L; i++) {
				max[i] = A[cnt][i];
				min[i] = A[cnt][i];
			}

			for (i = 0; i < L; ++i) {
				for (j = i + 1; j < L; ++j) {
					if (max[i] < max[j]) {
						tmp = max[i];
						max[i] = max[j];
						max[j] = tmp;
					}
				}
			}
			for (i = 0; i < L; ++i) {
				for (j = i + 1; j < L; ++j) {
					if (min[i] > min[j]) {
						tmp = min[i];
						min[i] = min[j];
						min[j] = tmp;
					}
				}
			}
			/*
			for (i = 0; i < L; i++) {
				printf("%d ", max[i]);
			}
			*/
			for (i = 0; i < L; i++) {
				big = big * 10 + max[i];
				small = small * 10 + min[i];
			}
			/*
			printf("\n%d %d\n", big,small);
			*/

			cnt++;
			a[cnt] = big - small;
			sub = a[cnt];
			for (i = 0; i < L; i++) {
				A[cnt][L - i-1] = sub % 10;
				sub = sub / 10;
			}
			/*
			for (i = 0; i < L; i++) {
				printf("%d ", A[cnt][i]);
			}
			*/
			for (i = 0; i < cnt; i++) {
				if (a[cnt] == a[i]) {
					printf("%d %d %d\n", i, a[cnt], cnt - i);
					ans = 1;
					break;
				}
			}
			if (ans == 1) {
				ans = 0;
				break;
			}
		}



	}
	return 0;
}


Measured memory_bytes: 2104
S = input()
if S == "SUN" :
    print("7")
elif S == "MON" :
    print("6")
elif S == "TUE" :
    print("5")
elif S == "WED" :
    print("4")
elif S == "THU" :
    print("3")
elif S == "FRI" :
    print("2")
elif S == "SAT" :
    print("1")

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

using namespace std;

#define _for(i,j,N) for(int i = (j);i < (N);i++)
#define LL long long

LL A[5];

const LL INF = 1000000000000005;

LL get_min(){
    LL ret_val = INF;
    _for(i,0,5){
        ret_val = min(ret_val,A[i]);
    }
    return ret_val;
}

int main()
{
    LL N;
    scanf("%lld %lld %lld %lld %lld %lld",&N,&A[0],&A[1],&A[2],&A[3],&A[4]);
    LL min_flow = get_min();

    LL plu = (N%min_flow)?(N/min_flow):(N/min_flow)-1;

    plu = max(plu,(LL)0);

    //printf("%lld\n",N/min_flow));

    printf("%lld\n",plu+5);

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
#include <random>
#include <string.h>
#include <cmath>
#include <unordered_map>
#include <cstdio>
using namespace std;
#define pie 3.141592653589793238462643383279
#define mod 998244353
#define int long long
#define P pair<int,int>
#define all(vec) vec.begin(),vec.end()

int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}

int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}

string s;
int ans;
bool bl;

signed main() {
	cin >> s;
	for (int i = 0; i < (int)s.size(); i++) {
		if (s[i] == 'P')cout << 'P';
		else cout << 'D';
	}
	cout << endl;
}

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

long long n,ans,mod=1e9+7ll,cont;
string s;
int main(){

	cin>>n>>s;
	ans=1;
	if(s[0]=='W' || s[2*n-1]=='W'){
		cout<<0<<endl;
		return 0;
	}
	
	for(int i=0;i<s.size();i++){
		if(int(s[i]=='W')==(i%2))cont++;
		else{
			
			if(cont==0){
				cout<<0<<endl;
				return 0;
			}
			
			ans*=cont;
			cont--;
			ans%=mod;
		}
	}
	
	if(cont!=0){
		cout<<0<<endl;
		return 0;
	}
	
	for(int i=1;i<=n;i++){
		ans*=i;
		ans%=mod;
	}
	
	cout<<ans<<endl;

return 0;
}


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

a=0
b=0

while True:
    hantei_p=(X+b**5)**0.2
    hantei_n=(X-b**5)**0.2

    if abs(int(hantei_p)-hantei_p)<1:
       a=int(hantei_p)
       if a**5-b**5==X:
           print("{} {}".format(a,b))
           break
    if isinstance(hantei_n**0.2,float):
        if abs(int(hantei_n)-hantei_n)<1:
            a=int(hantei_n)
            if a**5+b**5==X:
                print("{} {}".format(a,-b))
                break
    
    b +=1




Measured memory_bytes: 9476
# -*- coding: utf-8 -*-
sieve = [0, 1, 0, 0, 0, 0, 1]*42858

for i in range(2, len(sieve)):
    if sieve[i] == 1:
        for j in range(2*i, len(sieve), i):
            sieve[j] = 0

smP = [i for i, s in enumerate(sieve) if s][1:]

N = int(input())
while N != 1:
    ans = []
    for p in smP:
        if N%p == 0:
            ans.append(p)
    print("{}: {}".format(N, " ".join(map(str, ans))))
    N = int(input())


Measured memory_bytes: 9524
import math

K=int(input())

f=[]

for i in range(1,K+1):
  for j in range(1,K+1):
    s=math.gcd(i, j)
    f.append(s)

S=0
for i in range(1,K+1):
  for j in f:
    S+=math.gcd(i,j)

print(S)

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

int main(){
  int l;
  cin>>l;
  int n=0;
  rep(bit,25){
    if(l&(1<<bit))n=max(n,bit+1);
  }
  vector<int>u,v,w;
  rep(i,n-1){
    u.push_back(i);
    v.push_back(i+1);
    w.push_back(0);
    u.push_back(i);
    v.push_back(i+1);
    w.push_back(1<<i);
  }
  int x=1<<(n-1);
  rep(bit,n-1){
    if(l&(1<<bit)){
      u.push_back(bit);
      v.push_back(n-1);
      w.push_back(x);
      x+=(1<<bit);
    }
  }
  int m=u.size();
  cout<<n<<" "<<m<<endl;
  rep(i,m){
    cout<<u[i]+1<<" "<<v[i]+1<<" "<<w[i]<<endl;
  }
}

Measured memory_bytes: 3640
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
using namespace std;
#define inf 1000000007

int main(void){
    int n;
    cin >> n;
    int ans;
    if(n<10) ans=n;
    else if(n>=10&&n<100) ans = 9;
    else if(n>=100&&n<1000) ans = n-90;
    else if(n>=1000&&n<10000) ans = 909;
    else if(n>=10000&&n<100000) ans = n-9090;
    else if(n==100000) ans = 90909;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
//
//AtCoder Beginner Contest 131
//B - Bite Eating
//

#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <functional>
#include <cassert>

using namespace std;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define SIZE(x) (int)(x).size()
#define SIZEL(x) (ll)(x).size()
#define MSG(a) cout << #a << " " << a << endl;

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

const double PI = 3.14159265358979323846;

ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }    //最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }            //最小公倍数

int main()
{
    int n, l;
    cin >> n >> l;

    int m = 99999999;
    int idx = -1;
    REP(i, n){
        m = min(m, abs(l+(int)i));
        if (m == abs(l+(int)i)) idx = i;
    }

    int ans = 0;
    REP(i, n){
        if (i==idx) continue;
        ans += (l+i);
    }

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


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

using namespace std;
typedef pair<int, int> pint;
typedef vector<int> vint;
typedef long long ll;
#define ALL(c) (c).begin(),(c).end()
#define RALL(c) (c).rbegin(),(c).rend()
#define SORT(c) sort(ALL(c))
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define NEXTP(c) next_permutation(ALL(c))
#define SUM(c) accumulate(ALL(c),0)
#define MP( a, b ) make_pair( ( a ), ( b ) )
#define ANS(x) cout << (x) << endl;
#define DUMP(x) cerr << #x << " = " << (x) << endl;
#define INF 1000000000 // 10^9
const double EPS = 1e-10;

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

    int like[N];
    int ret = 0;

    REP(i, N){
        cin >> like[i];
    }
    REP(i, N){
        if(i+1 == like[like[i]-1]) ret++;
    }
    cout << ret/2 << endl;
    return 0;
}

Measured memory_bytes: 640
// https://atcoder.jp/contests/

#include <bits/stdc++.h>
#define REP(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define REPR(i, n) for (int(i) = (n); (i) >= 0; (i)--)
#define FOR(i, m, n) for (int(i) = (m); (i) < (n); i++)
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;

int main()
{
  int A, B;
  cin >> A >> B;

  if (13 <= A)
    cout << B << '\n';
  else if (6 <= A)
    cout << B / 2 << '\n';
  else
    cout << 0 << '\n';

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int a = scan.nextInt();
        int b = scan.nextInt();
        char[] entry = scan.next().toCharArray();
        int count = 0;
        int nm = 0;

        for (int i = 0; i < entry.length; i++){
            switch (entry[i]){
                case 'a':
                    if ((a+b) > count) {
                        System.out.println("Yes");
                        count++;
                    }else {
                        System.out.println("No");
                    }
                    break;
                case 'b':
                    if ((a+b) > count && b > nm){
                        System.out.println("Yes");
                        count++;
                        nm++;
                    }else {
                        System.out.println("No");
                    }
                    break;
                case 'c':
                    System.out.println("No");
                    break;
            }
        }
    }
}


Measured memory_bytes: 23908
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int n,K;
char s[101010],an[101010];
int main()
{
	scanf("%d%d",&n,&K);
	scanf("%s",s+1);
	char mi='z';
	for(int i=1;i<=n;i++) s[n+n-i+1]=s[i],mi=min(mi,s[i]);
	//cout<<s+1<<endl;
	if(K>=14||pow(2,K-1)>=n)
	{
		for(int i=1;i<=n;i++) putchar(mi); puts("");
		return 0;
	}
	int ml=pow(2,K-1),mal=0;
	for(int i=1;i<=n+n;i++)
	if(s[i]==mi)
	{
		int r;
		for(r=i;r<=n+n;r++)
		if(s[r]!=mi) break;
	//	cout<<i<<" "<<r<<endl;
		if(r<=n+1){ i=r;continue;}
		if((r-i)*ml>=n)
		{
			for(int j=1;j<=n;j++) putchar(mi); puts("");
			return 0;
		}
		if(r-i>mal)
		{
			mal=r-i;
			for(int j=1;j<=n-mal*ml;j++)
			an[j]=s[i-j];
		}
		else if(r-i==mal)
		{
			for(int j=1;j<=n-mal*ml;j++)
			if(an[j]^s[i-j])
			{
				if(an[j]>s[i-j])
					for(int k=j;k<=n-mal*ml;k++)
					an[k]=s[i-k];
				break;
			}
		}
		i=r;
	}
	for(int i=1;i<=mal*ml;i++) putchar(mi);
	for(int j=1;j<=n-mal*ml;j++) printf("%c",an[j]);
	puts("");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
using namespace std;
using ll = long long int;
using Matrix = vector< vector<ll> >;
const ll MOD = 1000000009;

Matrix mul(const Matrix &A, const Matrix &B) {
    int H = A.size(), W = B[0].size(), C = B.size();
    Matrix res(H, vector<ll>(W));
    for(int i=0; i<H; i++) {
        for(int j=0; j<W; j++) {
            for(int k=0; k<C; k++) {
                (res[i][j] += A[i][k] * B[k][j] % MOD) %= MOD;
            }
        }
    }
    return res;
}

Matrix pow(Matrix A, ll k) {
    int N = A.size();
    Matrix res(N, vector<ll>(N));
    for(int i=0; i<N; i++) res[i][i] = 1;

    for(; k>0; k>>=1) {
        if(k & 1) res = mul(res, A);
        A = mul(A, A);
    }
    return res;
}

int solve_testcase(int case_num) {
    ll W, H, N; cin >> W >> H >> N;
    if(W == 0) return 1;
    
    map< ll, vector<int> > rows;
    for(int i=0; i<N; i++) {
        ll r, c; cin >> c >> r; r--; c--;
        rows[r].emplace_back(c);
    }
    rows[0], rows[H-1];

    Matrix A(W, vector<ll>(W));
    for(int i=0; i<W; i++) {
        for(int dx=-1; dx<=1; dx++) {
            int ni = i + dx;
            if(ni < 0 or ni >= W) continue;
            A[i][ni] = 1;
        }
    }

    Matrix vec(W, vector<ll>(1)); vec[0][0] = 1;
    for(auto itr=rows.begin(); next(itr)!=rows.end(); itr++) {
        ll r1 = itr->first, r2 = next(itr)->first;

        // r2 - r1 - 1 分だけ進める
        Matrix P = pow(A, r2 - r1 - 1);
        vec = mul(P, vec);

        // r2 に移動
        vector<bool> ok(W, true);
        auto& cols = next(itr)->second;
        for(auto w : cols) ok[w] = false;

        Matrix nvec(W, vector<ll>(1));
        for(int i=0; i<W; i++) {
            for(int dx=-1; dx<=1; dx++) {
                int ni = i + dx;
                if(ni < 0 or ni >= W or !ok[ni]) continue;
                (nvec[ni][0] += vec[i][0]) %= MOD;
            }
        }
        swap(vec, nvec);
    }

    cout << "Case " << case_num << ": " << vec[W-1][0] << endl;
    return 0;
}

int main() {
    int case_num = 0;
    while(!solve_testcase(++case_num));
    return 0;
}



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

int main() {
	ios_base::sync_with_stdio(false);
	int n; cin >> n;
	int x = sqrt(8 * n + 1);
	x = (x + 1) / 2;
	if (x * (x - 1) != n + n) return cout << "No" << '\n',0;
	cout << "Yes" << '\n';
	int cur = 0;
	vector<vector<int>> res(x, vector<int>());
	for (int i = 0; i < x; ++i) {
		for (int j = i + 1; j < x; ++j) {
			++cur;
			res[i].push_back(cur);
			res[j].push_back(cur);
		}
	}
	cout << x << '\n';
	for (int i = 0; i < x; ++i) {
		cout << res[i].size() << ' ';
		for (int j : res[i]) cout << j << ' ';
		cout << '\n';
	} 
}


Measured memory_bytes: 2304
#include<stdio.h>
int main(){
int a,b,c;
scanf("%d %d %d",&a,&b,&c);
if(a<b){
if(b<c){
printf("Yes\n");
}
else{
printf("No\n");
}
}
else{
printf("No\n");
}
return 0;
}

Measured memory_bytes: 580
#include <bits/stdc++.h>
#define loop(n) for (int ngtkana_is_genius = 0; ngtkana_is_genius < int(n); ngtkana_is_genius++)
#define rep(i, begin, end) for(int i = int(begin); i < int(end); i++)
#define lint long long
auto cmn = [](auto& a, auto b){if (a > b) {a = b; return true;} return false;};
auto cmx = [](auto& a, auto b){if (a < b) {a = b; return true;} return false;};
void debug_impl() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail){
  std::cerr << " " << head;
  debug_impl(tail...);
}
#define debug(...) std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\
  debug_impl(__VA_ARGS__);\
  std::cerr << std::noboolalpha;

int main() {
  std::cin.tie(0); std::cin.sync_with_stdio(false);
  lint n; std::cin >> n;
  std::cout << n * (n - 1) / 2 << std::endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long                                    // long long省略
#define pb push_back                                    // push_back省略
#define mp make_pair                                    // make_pair省略
#define fi first                                        // first省略
#define se second                                       // second省略
#define itn int                                         // int誤字保険
#define count cout                                      // cout誤字保険
#define vecotr vector                                   // vector誤字保険
#define ednl endl                                       // endl誤字保険
#define opt() cin.tie(0); ios::sync_with_stdio(false)   // 入出力速度改善

#define rep(i,l,r) for(ll i=(l);i<(r);i++)               // 範囲[l, r)で刻み1のfor文(順方向)
#define repp(i,l,r,k) for(ll i=(l);i<(r);i+=(k))         // 範囲[l, r)で刻みkのfor文(順方向)
#define rrep(i,l,r) for(ll i=(r-1);i>=(l);i--)           // 範囲[l, r)で刻み1のfor文(逆方向)
#define rrepp(i,l,r,k) for(ll i=(r-1);i>=(l);i-=(k))     // 範囲[l, r)で刻みkのfor文(逆方向)
#define all(x) (x).begin(), (x).end()                   // vectorのポインタ位置指定用
#define max(p,q)((p)>(q)?(p):(q))                       // max拡張
#define min(p,q)((p)<(q)?(p):(q))                       // min拡張
#define bit(n,m)(((n)>>(m))&1)                          // 変数nのm番目のbitを取り出す

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

int dy[]={0, 1, 0, -1};                                 // 4方向近傍
int dx[]={1, 0, -1, 0};                                 // 4方向近傍

//union-find
const int N_MAX = 10000;
ll par[N_MAX];
ll rnk[N_MAX];
void init(ll n){ rep(i,0,n){ par[i] = i; rnk[i] = 1;} }
ll find(ll x){ if(x == par[x]) return x; return par[x] = find(par[x]); }
void unite(ll x, ll y){
    x = find(x); y = find(y);
    if(rnk[x] < rnk[y]){
        par[x] = y;
    }else{
        par[y] = x;
        if(rnk[x] == rnk[y]) rnk[x]++;
    }
}
bool same(ll x, ll y){ return find(x) == find(y); }
int main(){
    ll x, y; cin>>x>>y; x--; y--;
    init(12);
    unite(0,2); unite(2,4); unite(4,6); unite(6,7); unite(7,9); unite(9,11);
    unite(3,5); unite(5,8); unite(8,10);
    cout << (same(x,y) ? "Yes" : "No") << ednl;
}



Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;


public class B
{
	public static void Main()
	{
		string[] args = Console.ReadLine().Split(' ');
		int D = Int32.Parse(args[0]);
		int N = Int32.Parse(args[1]);

		int ans = 0;
		int counter = 0;
		do
		{
			ans++;
			if((ans % 100) != 0)
				counter++;
		} while (counter < N);
		ans *= (int)Math.Pow(100,D);

		Console.WriteLine(ans);
	}	
}





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

int main(){
  std::string s;
  int  border=2019004030;
  cin >> s;
  s[4] = '0';
  s[7] = '0';

  int a =atoi(s.c_str());
  if(a > border){
    cout << "TBD" << endl;
  }else{
    cout << "Heisei" << endl;
  }
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std ;
template < class R > inline void Readin( R &K ) {bool F=K=0;char C=getchar();while(C<'0'||C>'9')
{if(C=='-')F=1;C=getchar();}while(C<='9'&&C>='0')K=(K<<1)+(K<<3)+C-'0',C=getchar();if(F)K=-K;}
template < class R > inline bool Checkmax( R &A , R B ) { return A < B ? A = B , 1 : 0 ; }
template < class R > inline bool Checkmin( R &A , R B ) { return A > B ? A = B , 1 : 0 ; }
const int MaxN = 4000 + 10 ;
int N ;
long long A[MaxN] , X ;
long long Minans = 1ll << 60 ;
long long Min[MaxN][MaxN] ;
int main() {
	Readin( N ) ;
	Readin( X ) ;
	for(register int i = 0 ; ++i <= N ; ) {
		Readin( A[i] ) ;
		A[i+N] = A[i] ;
	}
	for(register int L = 0 ; ++L <= N + N ; ) {
		Min[L][L] = A[L] ;
		for(register int R = L ; ++R <= N + N ; )
			Min[L][R] = min( Min[L][R-1] , A[R] ) ;
	}
	for(register int i = 0 ; i <= N ; ++i ) {
		register long long Now = X * i ;
		for(register int j = N ; ++j <= N + N ; )
			Now += Min[j-i][j] ;
		Checkmin( Minans , Now ) ;
	}
	cout << Minans << endl ;
	return 0 ;
}

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

using namespace std;

int main(){
    int N,M,ans=0;
    cin >> N >> M;
    int graph[N][N];
    memset(graph,0,sizeof(graph));
    vector<int> ab(N-1);

    for(int i=0;i<N-1;i++){
        ab[i] = i+1;
    }

    for(int i=0;i<M;i++){
        int k,j;
        cin >> k >> j;
        k--;
        j--;
        graph[k][j] = 1; 
        graph[j][k] = 1;
    }

    do{
        if(graph[0][ab[0]]==1){
            for(int i=1;i<N-1;i++){
                if(graph[ab[i]][ab[i-1]]!=1){
                    break;
                }
                if(i==N-2){
                    ans++;
                }
            }
        }
    }while(next_permutation(ab.begin(),ab.end()));

    if(N==2 && M!=0){
        cout << 1 << endl;
    }else{
        cout << ans << endl;
    }
}

Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
#from decimal import *

R, G, B, N = MAP()
ans = 0

for i in range(3001):
	r = i
	for j in range(3001):
		g = j
		b = (N-r*R-g*G)/B
		if 0 <= b and b == b//1:
			ans +=1

print(ans)

Measured memory_bytes: 62824
#include <stdio.h>


int main(void) {
	long unsigned int a;
	unsigned int b;

	scanf("%lu", &a);

	char temp[5];
	scanf("%s", temp);
	b = (temp[0] - '0') * 100 + (temp[2] - '0') * 10 + (temp[3] - '0');

	printf("%lu\n", a * b / 100);

	return 0;
}


Measured memory_bytes: 1736
#include<bits/stdc++.h>
using namespace std ;
#define Next( i, x ) for( register int i = head[x]; i; i = e[i].next )
#define rep( i, s, t ) for( register int i = (s); i <= (t); ++ i )
#define drep( i, s, t ) for( register int i = (t); i >= (s); -- i )
#define re register
#define int long long
int gi() {
	char cc = getchar() ; int cn = 0, flus = 1 ;
	while( cc < '0' || cc > '9' ) {  if( cc == '-' ) flus = - flus ; cc = getchar() ; }
	while( cc >= '0' && cc <= '9' )  cn = cn * 10 + cc - '0', cc = getchar() ;
	return cn * flus ;
}
const int N = 300 + 5 ; 
int n, K, P, dp[N][N], g[N][N], C[N][N] ;  
signed main()
{
	n = gi(), K = gi(), P = gi() ; C[0][0] = 1 ; 
	++ n ;  
	rep( i, 1, n ) rep( j, 0, n ) C[i][j] = (!j) ? 1 : ( C[i - 1][j - 1] + C[i - 1][j] ) % P ;  
	for( re int i = K; i >= 0; -- i ) {
		dp[i][1] = 1 ; 
		for( re int j = 2; j <= n; ++ j ) {
			for( re int k = 1; k < j; ++ k ) 
				dp[i][j] = ( dp[i][j] + dp[i][j - k] * C[j - 2][k - 1] % P * g[i + 1][k] % P ) % P ; 
		}
		rep( j, 1, n ) g[i][j] = ( g[i + 1][j] + dp[i][j] ) % P ;
	}
	printf("%lld\n", dp[0][n] ) ; 
	return 0 ;
}

Measured memory_bytes: 5860
#include<iostream>
#include<algorithm>
using namespace std;
const int l[16] = { 1,4,1,4,1,2,1,2,1,4,1,4,1,2,1,2 };
const int p[8] = { 1,3,7,5,0,2,6,4 };
int main() {
	int c[8];
	while (cin >> c[0]){
		for (int i = 1; i < 8; i++)cin >> c[i];
		int ans = 0, val = 114514;
		for (int i = 0; i < 8; i++){
			int q = p[i];
			int cnt = 0;
			for (int j = 0; j < 8; j++)
				cnt += max(0, c[j] - l[q + j]);
			if (val >= cnt) {
				val = cnt;
				ans = q;
			}
		}
		for (int i = 0; i < 8; i++){
			if (i)cout << ' ';
			cout << l[ans + i];
		}
		cout << endl;
	}
}

Measured memory_bytes: 3080
import numpy as np
import sys
import math
from collections import defaultdict

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

ha = defaultdict(int)
ans = defaultdict(int)
s = set()
s.add(1)
ss = set()
mod = 0
mod2 = 0
next = 0
ind = 0
flag = 0
while  True:
    if A[next] in s and flag == 0:
        flag = 1
        ha[0] = A[next]
        ans[0] = A[next]
        ss.add(A[next])
        ind = 0
        mod += 1
        continue
        # next = A[next] - 1 
    elif flag == 1:
        next = A[next] - 1
        ans[ind+1] = A[next]
        mod2 += 1
        if A[next] in ss :
            break
        ss.add(A[next])
        ind += 1
        continue

    ha[ind+1] = A[next]
    s.add(A[next])
    next = A[next] - 1
    mod += 1
    ind += 1

if mod >= K :
    print(ha[K % mod])
else:
    print(ans[(K-mod)%mod2])

#print(ha)
#print(ans)

Measured memory_bytes: 90008
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,l,i;
  cin>>n;
  vector<string> w(n);
  for(i=0;i<n;i++) cin>>w.at(i);
  for(i=1;i<n;i++){
    l=w.at(i-1).length();
    if(w.at(i-1).at(l-1)!=w.at(i).at(0)) break;
  }
  if(i<n) cout<<"No"<<endl;
  else{
    sort(w.begin(),w.end());
    for(i=1;i<n;i++) if(w.at(i-1)==w.at(i)) break;
    if(i<n) cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
  }
}

Measured memory_bytes: 3596