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

using namespace std;

typedef long long ll;

int max(int a, int b)
{ return (a > b) ? a : b; }

const int MAXN = 200031;
const ll INF = 10000000000000LL;
int a[MAXN];

vector<ll> p(31);

__int128 power(__int128 a, ll b)
{
    if (b == 0) return 1;
    if (a >= INF) return INF;
    __int128 res = power(a * a, b / 2);

    if (res >= INF) return INF;
    if (b % 2 == 1)
    {
        return a * res;
    }
    else return res;
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    ll n, p;
    cin >> n >> p;
    if (n == 1)
    {
        cout << p;
        exit(0);
    }
    ll ans = 1;
    for (int i = 2; i <= sqrt(p) + 1; i++)
    {
//        cerr << i << " " << (ll)power(i, n) << endl;

    ll t = (ll)power(i, n);
        if (t == INF) break;
//        if (i == 206) cerr << (ll)power(206, n) << " " << p << " " << p % (ll)power(i, n) << endl;
        if (p % t == 0) ans = i;
    }

    cout << ans;

    return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

func main() {
	sc := newScanner()
	sc.Scan()
	a, _ := strconv.ParseInt(sc.Text(), 10, 64)
	sc.Scan()
	b, _ := strconv.ParseFloat(sc.Text(), 64)
	ans := a * int64(math.Round(100*b)) / 100
	fmt.Println(ans)
}

func newScanner() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Buffer([]byte{}, math.MaxInt64)
	sc.Split(bufio.ScanWords)
	return sc
}


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

using namespace std;


int main()
{
	ios_base :: sync_with_stdio(false);
	string s;
	int k = 0;
	cin >> k;
	cin >> s;
	if (s.size() <= k) {
		cout << s;
		return 0;
	}
	for (int i = 0; i < k; i++) {
		cout << s[i];
	}
	cout << "...";
	return 0;
}

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

int main(){
	string s;

	while ( getline(cin,s) ){
		for (int i=0 ; i<s.size() ; i++){
			if ( s[i]>='a' && s[i]<='z'){
				s[i] = s[i] + ('A'-'a');
			}
		}
		cout << s << endl;
	}
}

Measured memory_bytes: 2956
#include <bits/stdc++.h>
#define rep2(i,m,n) for (int i = (int)(m); i < (int)(n); i++)
#define rep(i,n) rep2(i,0,n)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
using namespace std;
using ll = long long;
template <typename T>
T sq(T x){
  return x * x;
}

signed main (){
  int A ,B ,C;
  cin >> A >> B >> C;
  for(int i = 1 ;i <= B;i++){
    if(i * A % B == C){
      cout << "YES" << endl;
      return 0;
    }
  }

  cout << "NO" << endl;
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> P3;
typedef pair<P ,P> PP;
constexpr ll MOD = ll(1e9) + 7;
constexpr int IINF = INT_MAX;
constexpr ll LLINF = LLONG_MAX;
constexpr int MAX_N = int(1e6) + 5;
constexpr double EPS = 1e-9;
constexpr int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i > 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), (v).end()



int main() {
    ll l, r;
    cin >> l >> r;
    bool a[2100]{};
    for(ll i=l;i<=min(r,l+2019);i++){
        a[i%2019] = true;
    }
    ll ans = IINF;
    for(ll i=0;i<2019;i++){
        for(ll j=i+1;j<2019;j++){
            if(a[i] && a[j]){
                ans = min(ans, i*j%2019);
            }
        }
    }
    cout << ans << endl;
    return 0;
}


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


int main(){
  int N,K,x;
  cin >> N >> K;
  int i,sum;
  for(i=0;i<N;i++){
    cin >> x;
    if(x > K-x) sum += 2*(K-x);
    else sum += 2*x;
  }
  cout << sum << endl;
}
  


Measured memory_bytes: 256
N,C,K = gets.split.map(&:to_i)
ary = N.times.map{gets.to_i}.sort
passenger = 0
bus_from = 0
cnt = 0
ary.each do |t|
    if passenger == 0 || t - bus_from > K || passenger == C
        passenger = 0
        bus_from = t
        cnt += 1
    end
    passenger += 1
end
puts cnt

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


//      DEEP

using namespace std;
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define all(v) v.begin(),v.end()
#define pb push_back
#define endl '\n'
#define mp make_pair

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int,int> pi;
typedef pair<long long,long long> pll;
typedef set<int> si;


/*
typedef tree<int,null_type,less<int>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;
*/
/*
typedef tree<
pair<int, int>,
null_type,
less<pair<int, int>>,
rb_tree_tag,
tree_order_statistics_node_update> ordered_set;
*/

const ll mod = 1e9 + 7;
const ll modl=998244353;
const double pie=3.1415926535;
                                                    //power
ull power(ull x,ull y){
   if(y==0) return 1;
   else{
     if(y%2==0) return power(x*x,y/2);
     else return x*power(x*x,(y-1)/2);
   }
}

                        //                    Modular Exponentiation

ll mod_power(ll x, ll y, ll m)
{
    ll r = 1;     // Initialize result

    x = x % m; // Update x if it is more than or equal to m

    if (x == 0) return 0; // In case x is divisible by m;

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            r = (r*x) % m;

        // y must be even now
        y = y/2;
        x = (x*x) % m;
    }
    return r;
}

                                                      //GCD
ll gcd(ll x,ll y){
   if(y==0)return x;
   return gcd(y,x%y);
}
                                              // SIEVE

/*
bool isPrime[100001];
void sieve(int N) {

        for(int i = 0; i <= N;++i) {
            isPrime[i]=true;
        }
        isPrime[0]=false;
        isPrime[1]=false;

        for(int i = 2; i * i <= N; ++i) {
             if(isPrime[i] == true) {
                 for(int j = i * i; j <= N ;j += i)
                     isPrime[j] = false;
            }
        }
    }
*/



int main(){
    boost;
    int TESTS=1;
    //cin>>TESTS;
    while(TESTS--){
      double d,t,s;
      cin>>d>>t>>s;
      if(d/s<=t)cout<<"Yes"<<endl;
      else cout<<"No"<<endl;
      
    }
}












Measured memory_bytes: 3728
n = int(input())
hlist = list(map(int, input().split()))

dp = [0]*(n+1)

for i in range(2, n+1):
    dp[i] = min(dp[i-1] + abs(hlist[i-2] - hlist[i-1]), dp[i-2] + abs(hlist[i-3] - hlist[i-1]) if i>2 else 10**9)

print(dp[n])

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

#define _GLIBCXX_DEBUG

//vector<int> A(M), B(M);
//vector<vector<char>> answer(N, vector<char>(N, '-'));

int main() {
  int k, x;
  string ans;
  
  cin >> k >> x;
  
  if(500 * k >= x) ans = "Yes";
  else ans = "No";
    
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3568
#include<iostream>
#include<string.h>
#define loop(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,b) loop(i,0,b)
using namespace std;
int main(){
    int n,t;
    int c=0;
    int k=0;
    cin>>n;
    rep(i,n){
        cin>>t;
        if(t%2!=0){
            for(int x=3;x<=10000;x+=2){
                if(t%x==0&&t!=x){
                c=1;
                break;
                }
            }
        }
        else if(t==2) c=0;
        else c=1;
        if(c==0) k+=1;
        c=0;
    }
    cout<<k<<endl;
}


Measured memory_bytes: 3052
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <bitset>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <cassert>
#include <ctime>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define mod 1000000009
#define inf 0x3f3f3f3f
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pi acos(-1.0)
#define pii pair<int,int>
#define sys system("pause")
const int maxn=2e5+10;
const int N=2e5+10;
using namespace std;
ll gcd(ll p,ll q){return q==0?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=1;while(q){if(q&1)f=f*p%mod;p=p*p%mod;q>>=1;}return f;}
int n,m,k,t,a[maxn],b[maxn],id[maxn],ama,bma,ami=1e9,bmi=1e9;
multiset<int>dp;
bool cmp(int x,int y){return a[x]<a[y];}
int main()
{
    int i,j;
    scanf("%d",&n);
    rep(i,1,n)
    {
        scanf("%d%d",&a[i],&b[i]);
        if(a[i]>b[i])swap(a[i],b[i]);
        id[i]=i;
        ama=max(ama,a[i]);
        ami=min(ami,a[i]);
        bma=max(bma,b[i]);
        bmi=min(bmi,b[i]);
        dp.insert(a[i]);
    }
    ll ret=(ll)(ama-ami)*(bma-bmi);
    sort(id+1,id+n+1,cmp);
    rep(i,1,n)
    {
        dp.erase(dp.lower_bound(a[id[i]]));
        dp.insert(b[id[i]]);
        ret=min(ret,(ll)(*dp.rbegin()-*dp.begin())*(bma-ami));
    }
    printf("%lld\n",ret);
    return 0;
}


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

int main()
{
  int card[4][13];
  string c;
  int n,a;

  cin >> n; // maisuu

  // card initialize
  for(int i=0; i<4; i++)
    {
      for(int j=0; j<13; j++)
  	{card[i][j] = 0;}
    }
  
  // input
  for(int i=1; i <= n; i++)
    {
      cin >> c >> a;
      if(c == "S")
	{card[0][a-1] = 1;}
      if(c == "H")
	{card[1][a-1] = 1;}
      if(c == "C")
	{card[2][a-1] = 1;}
      if(c == "D")
	{card[3][a-1] = 1;}
    }

  // output

  for(int m=0; m<4; m++){
    for(int d=0; d < 13; d++){
      if(card[m][d] == 0){
	if(m == 0)
	  {cout << "S " << d+1 << endl;}
	if(m == 1)
	  {cout << "H " << d+1 << endl;}
	if(m == 2)
	  {cout << "C " << d+1 << endl;}
	if(m == 3)
	  {cout << "D " << d+1 << endl;}

      }
    }
  }
  return 0;
} 


Measured memory_bytes: 3112
n=int(input())
A=list(map(int,input().split()))

C=[0]*(10**5+1)
for a in A:
    C[a]+=1

ans=sum(A)
q=int(input())
for i in range(q):
    b,c=map(int,input().split())
    d=C[b]
    C[c]+=d
    C[b]=0
    ans+=d*(c-b)
    print(ans)

Measured memory_bytes: 21048
#include <iostream>
#include <algorithm>

using namespace std;

int n,k;
int h[111111];
int main(){
    scanf("%d %d", &n, &k);
    for(int i = 0; i < n; i++){
        scanf("%d", h+i);
    }

    sort(h, h+n);

    int best = 1<<30;
    for(int i = 0; i+k-1 < n; i++){
        best = min(best, h[i+k-1] - h[i]);
    }

    printf("%d\n", best);

}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"

int main() {
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin>>n;
    ll arr[n];
    map<ll,ll> mp;
    ll sum=0;
    for(ll i=0;i<n;i++)
    {
    	cin>>arr[i];
    	sum=sum+arr[i];
    	++mp[arr[i]];
    }
    ll q;
    cin>>q;
    for(ll i=0;i<q;i++)
    {
    	ll b,c;
    	cin>>b>>c;
    	sum=sum+(mp[b]*(c-b));
    	mp[c]=mp[c]+mp[b];
    	mp[b]=0;
    	cout<<sum<<endl;
    	//sum=sum;
    }
    
	return 0;
}

Measured memory_bytes: 10304
#include <stdio.h>
#include <math.h>
int main(void){
	double x1,x2,x3,y1,y2,y3;
	double a,b,c;
	double A,B,C;
	double R;
	double rcc[2];
	int n;
	
	scanf("%d",&n);
	for(;n > 0;n--){
		scanf("%lf %lf %lf %lf %lf %lf",&x1,&y1,&x2,&y2,&x3,&y3);
		a = sqrt(pow(x1-x2,2)+pow(y1-y2,2));
		b = sqrt(pow(x2-x3,2)+pow(y2-y3,2));
		c = sqrt(pow(x3-x1,2)+pow(y3-y1,2));
		
		A = a*a;
		B = b*b;
		C = c*c;
		
		rcc[0] = (A*(B+C-A)*x3+B*(C+A-B)*x1+C*(A+B-C)*x2)/(A*(B+C-A)+B*(C+A-B)+C*(A+B-C));
		rcc[1] = (A*(B+C-A)*y3+B*(C+A-B)*y1+C*(A+B-C)*y2)/(A*(B+C-A)+B*(C+A-B)+C*(A+B-C));
		R = a*b*c/sqrt((a+b+c)*(-a+b+c)*(a-b+c)*(a+b-c));
		
		printf("%.3lf %.3lf %.3lf\n",rcc[0],rcc[1],R);
	}

	return 0;
}

Measured memory_bytes: 664
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <string>
#include <set>
#include <bitset>
#include <unordered_map>
#include <cmath>
#include <functional>
#include <map>

using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
template <class T>
using Vvec = vector<vector<T> >;

template <class T>
void debug(T& v)
{
    for(auto& x: v) cout << x << " ";
    cout << endl;
}

int main()
{
    string S;
    cin >> S;
    if(S[2] == S[3] && S[4] == S[5]) cout << "Yes\n";
    else cout << "No\n";
}

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

from math import sqrt

n, d = map(int, input().strip().split(' '))
count = 0
for i in range(n):
	x, y = map(int, input().strip().split(' '))
	if sqrt(x * x + y * y) <= d:
		count += 1

print(count)


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

int main(){
  int n; cin>>n;
  vector<int> num(n);
  for(int i=0;i<n;i++){
    cin>>num[i];
  }
  sort(num.begin(),num.end());
  int now=-1,count=0;
  vector<long long> ans;
  for(int i=n-1;i>=0;i--){
    if(now!=num[i]){
      now=num[i];
      count=1;
    }else{
      count++;
      if(count==2||count==4){
        ans.push_back(now);
        if(ans.size()==2) break;
      }
    }if(i==0){
      cout<<0<<endl;
      return 0;
    }
  }
  cout<<ans[0]*ans[1]<<endl;
}


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

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i >= (b); i--)
#define rep(i,n) for(int i=0; i<n; i++)
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> P;
typedef map<int,int> mp;

const int MOD = 1e9 + 7;


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


    int n, m;
    cin >> n >> m;
    vector<pair<int, string> > ps(m);
    rep(i, m){
        cin >> ps[i].first >> ps[i].second;
    }

    vector<bool> a(n+1);
    vector<int> b(n+1);
    fill(all(a), false);
    fill(all(b), 0);

    rep(i, m){
        if(ps[i].second == "AC"){
            a[ps[i].first] = true;
        }else{
            if(!a[ps[i].first]){
                b[ps[i].first]++;
            }
        }
    }

    ll ans1 = 0, ans2 = 0;
    rep(i, n+1){
        ans1 += a[i];
        if(a[i]){
            ans2 += b[i];
        }
    }

    cout << ans1 << " " << ans2 << endl;

    return 0;
}



Measured memory_bytes: 6912
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <stack>
#include <map>
const int MOD = 1e9+7;
#define PI 3.14159265359
typedef long long ll;
using namespace std;


int main(){
	int ans = 0;
	string s;
	cin >> s;
	for (auto x : s){
		if (x == '-') ans --;
		else ans++;
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

ll P = 998244353;

struct range {
  ll l, r, v, sum;
};

bool operator<(const range &a, const range &b) {
  if (a.l == b.l) {
    if (a.r == b.r) {
      return a.v < b.v;
    }
    return a.r < b.r;
  }
  return a.l < b.l;
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n, q;
  cin >> n >> q;
  set<range> rs;
  vector<ll> s(n + 1, 0);
  s[0] = 0;
  ll val = 1;
  for (int i = 0; i < n; i++) {
    s[i + 1] = (s[i] + val) % P;
    val = (val * 10) % P;
  }
  rs.insert(range{0, n, 1, s[n]});
  ll ans = s[n];
  for (int i = 0; i < q; i++) {
    ll l_, r_, v;
    cin >> l_ >> r_ >> v;
    ll l = n - r_;
    ll r = n - l_;
    r++;
    auto it = rs.lower_bound(range{l, r, v, 0LL});
    while (it != rs.end() && r > it->l) {
      if (it->l < l && it->r > r) {
        ans = (ans + P - it->sum) % P;
        range new_r = *it;
        range new_r2 = *it;
        new_r.sum = (new_r.sum + P - ((s[r] - s[new_r.l]) * new_r.v) % P) % P;
        new_r2.sum = (new_r2.sum + P - ((s[new_r2.r] - s[l]) * new_r2.v) % P) % P;
        ans = (ans + new_r.sum) % P;
        ans = (ans + new_r2.sum) % P;
        rs.erase(it);
        rs.insert(new_r);
        rs.insert(new_r2);
      } else if (it->r > r) {
        range new_r = *it;
        ans = (ans + P - new_r.sum) % P;
        new_r.sum = (new_r.sum + P - ((s[r] - s[new_r.l]) * new_r.v) % P) % P;
        ans = (ans + new_r.sum) % P;
        new_r.l = r;
        rs.erase(it);
        rs.insert(new_r);
      } else {
        ans = (ans + P - it->sum) % P;
        rs.erase(it);
      }
      it = rs.lower_bound(range{l, r, v, 0LL});
    }
    it = rs.lower_bound(range{l, r, v, 0LL});
    if (it != rs.begin()) {
      it--;
      while (it != rs.end() && l < it->r) {
        if (it->l < l && it->r > r) {
          ans = (ans + P - it->sum) % P;
          range new_r = *it;
          range new_r2 = *it;
          new_r.sum = (new_r.sum + P - ((s[r] - s[new_r.l]) * new_r.v) % P) % P;
          new_r.l = r;
          new_r2.sum = (new_r2.sum + P - ((s[new_r2.r] - s[l]) * new_r2.v) % P) % P;
          new_r2.r = l;
          ans = (ans + new_r.sum) % P;
          ans = (ans + new_r2.sum) % P;
          rs.erase(it);
          rs.insert(new_r);
          rs.insert(new_r2);
        } else if (it->l < l) {
          range new_r = *it;
          ans = (ans + P - new_r.sum) % P;
          new_r.sum = (new_r.sum + P - ((s[new_r.r] - s[l]) * new_r.v) % P) % P;
          ans = (ans + new_r.sum) % P;
          new_r.r = l;
          rs.erase(it);
          rs.insert(new_r);
        } else {
          ans = (ans + P - it->sum) % P;
          rs.erase(it);
        }
        it = rs.lower_bound(range{l, r, v, 0LL});
        if (it == rs.begin()) break;
        it--;
      }
    }
    range new_r{l, r, v, (((P + s[r] - s[l]) % P) * v) % P};
    cout << (ans + new_r.sum) % P << endl;
    ans = (ans + new_r.sum) % P;
    rs.insert(new_r);
  }
  return 0;
}


Measured memory_bytes: 20392
#include<iostream>
#include<map>
#include<algorithm>
#include <iomanip>
#include <cmath>
#include <sstream>
#include <unordered_map>
#include <unordered_set>
#include <deque>
#include <vector>
#include <bitset>
#include <queue>
#include <set>
#include <stack>
#include <string>

using namespace std;

int main() {
	string s, t; cin >> s;
	t = "CODEFESTIVAL2016";
	int ans = 0;
	for (int i = 0; i < s.size(); i++) {
		if (t[i] != s[i]) { ans++; }
	}

	cout << ans << endl;

}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <tuple>
//#include <bits/stdc++.h>
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i,i0,n) for(int (i)=(i0);(i)<(n);(i)++)
#define FORR(i,i0,n) for(int (i)=(n)-1; (i)>=(i0);(i)--)
#define SORT(x) sort(x.begin(),x.end())
#define SORTR(x) sort(x.begin(),x.end(),greater<int>())
#define rn return
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#include <time.h>
typedef std::pair<int,int> P;
using namespace std;
using ll = long long;



int main(){
    int a,b,c;
    cin  >> a >> b >> c;
    cout <<  c << " "<< a << " " << b;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)n; i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long int ll;
typedef vector<int > vecint;
typedef vector<string > vecstr;
int main()
{
  int h, w;
  cin >> h >> w;
  vecstr c(h);
  REP(i,h){
    cin >> c[i];
  }
  REP(i,h){
    cout << c[i] << endl;
    cout << c[i] << endl;
  }
}


Measured memory_bytes: 256
import math

def cal_pattern(n):
  dp = [0]*(n+1)
  dp[0] = 1
  dp[1] = 1
  if n == 1: return dp[-1]
  dp[2] = 2
  for i in range(3, n+1):
    dp[i] = dp[i-1]+dp[i-2]+dp[i-3]
  return dp[-1]

def run(n):
  patterns = cal_pattern(n)
  days = math.ceil(patterns/10)
  print(math.ceil(days/365))
  
if __name__ == '__main__':
  while True:
    n = int(input())
    if n == 0: break
    run(n)


Measured memory_bytes: 5664
#include<stdio.h>
#include<iostream>
#include<fstream>
#include<string>
#include<math.h>
#include <vector>
#include <array>
using namespace std;

enum command {
	com_update = 0,		//update(i, x) : a_i???x????????´?????????
	com_find = 1		//find(s,t): a_s,a_{s+1},...,a_t???????°??????????????????????
};
const int INIT = 2147483647;// (1L << 31L) - 1L;
int main(){
	std::istream & c_in = cin;
	int n, q;
	c_in >> n >> q;
	array<int, 100000> A;
	A.fill(INIT);

	for (int j = 0; j < q; ++j)
	{
		int com, x, y;
		c_in >> com >> x >> y;
		if (com == com_update)
		{
			A[x] = y;
		}
		else if (com == com_find)
		{
			//
			int m = INIT;
			for (int i = x; i <= y; ++i)
			{
				if (A[i] < m)
				{
					m = A[i];
				}
			}
			cout << m << endl;
		}
	}
}

Measured memory_bytes: 3484
#include <stdio.h>

int main(){
  char A[12],B[12],C[12];
  scanf("%s %s %s",A,B,C);
  printf("%c%c%c\n",A[0]+'A'-'a',B[0]+'A'-'a',C[0]+'A'-'a');
  return 0;
}

Measured memory_bytes: 1732
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int INT_INF = 1 << 30;
const double PI = acos(-1.0);
#define MOD 998244353LL
#define endl "\n"



int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll A, B, C, D;
  cin >> A >> B >> C >> D;
  vvll num(C, vll(D, 0LL));
  for(ll i = B; i < D; i++){
    if(i == B) num.at(A-1).at(i) = A;
    else{
      num.at(A-1).at(i) = num.at(A-1).at(i-1) * A % MOD;
    }
  }
  for(ll i = A; i < C; i++){
    if(i == A) num.at(i).at(B-1) = B;
    else{
      num.at(i).at(B-1) = num.at(i-1).at(B-1) * B % MOD;
    }
  }
  num.at(A-1).at(B-1) = 1;
  for(ll i = A; i < C; i++){
    for(ll j = B; j < D; j++){
      num.at(i).at(j) = (num.at(i).at(j-1) * (i+1) % MOD + num.at(i-1).at(j) * (j+1) % MOD - num.at(i-1).at(j-1) * (i) * (j)) % MOD;
    }
  }
  
  cout << (num.at(C-1).at(D-1) + MOD) % MOD << endl;
  /*
  cout << num.at(C-2).at(D-1) << endl;
  cout << num.at(C-1).at(D-2) << endl;*/
  /*
  for(int i = C-1; i >= 0; i--){
    for(int j = 0; j < D; j++){
      cout << num.at(i).at(j) << ' ';
      if(j == D-1) cout << endl;
    }
  }*/
}


Measured memory_bytes: 73576
#include<bits/stdc++.h>
#define rep(i,N) for(ll i=0; i<N; i++)
using namespace std;
using ll = long long;
const ll MOD = 1000000007;

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

    ll cnt = 0;
    for(ll i = min(a,b); i >= 1; i--){
        if(a % i == 0 && b % i == 0){
            cnt++;
        }if(cnt == k){
            cout << i << endl;
            break;
        }
    }
}

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

int main()
{
   int n;
   cin>>n;
   string s,t;
   cin>>s>>t;
   int cnt=0;
   for(int i=1;i<=n;i++){
        if(s.substr(n-i)==t.substr(0,i))cnt=i;
   }
   cout<<2*n-cnt;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
// 省略
#define ll long long
#define ld long double
// for
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Repp(i, a, b) for (int i = a; i <= (int)(b); i++)
#define Repm(i, a, b) for (int i = a; i <= (int)(b); i—-)
// 入力
#define IN(x) int x; cin >> x;
#define inll(x) ll x; cin >> x;
#define ind(x) double x; cin >> x;
#define inc(x) char x; cin >> x;
#define ins(x) string x; cin >> x;
// 出力
#define co(x) cout << x;
#define ce cout << endl;
#define cs cout << “ “;
#define keta(x) cout << fixed << setprecision(x);
// 配列
#define Sort(x) sort(x.begin(), x.end()) // 小順
#define Rev(x) reverse(x.begin(), x.end())

int main() {
  inc(al)
  vector<char> a = {'Z', 'a', '0'};
  a[2] = al;
  Sort(a);
  if(a[1] == 'Z')co("A")
    else co("a")
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double PI = acos(-1);
 
int main() {
  cout << fixed << setprecision(20);
  double A,B,H,M;
  cin >> A >> B >> H >> M;
  double RA = ((H * 60 + M) / 2);
  double TA = RA * (PI / 180);
  double AX = A * sin(TA);
  double AY = A * cos(TA);
  double RB = M * 6;
  double TB = RB * (PI / 180); 
  double BX = B * sin(TB);
  double BY = B * cos(TB);
  cout << sqrt((AX-BX) * (AX-BX) + (AY-BY) * (AY-BY)) << endl;
}

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

using namespace std;

const int N = 1e5 + 5;

bool dp[N];
int n, a[N], k;

int main(){
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> n >> k;
    for (int i = 1; i <= n; i++) cin >> a[i];
    for (int i = 1; i <= k; i++) {
        for (int j = 1; j <= n; j++) {
            if (i >= a[j]) dp[i] |= (!dp[i - a[j]]);
        }
    }
    
    cout << (dp[k] ? "First" : "Second");
    return 0;
}

Measured memory_bytes: 384
import sys
stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

N=int(input())
S=list(ns())
ans=0
for i in range(N-2):
    if(S[i]=='A' and S[i+1]=='B' and S[i+2]=='C'):
        ans+=1

print(ans)

Measured memory_bytes: 3188
# -*- using:utf-8 -*-
from itertools import combinations

class main:
  def T(array):
    cnt = 0
    for i in array:
      a, b, c = i
      if a != b and a != c and b != c and a < b + c:
        cnt += 1
    print(cnt)

  def Sort(array):
    for i in range(len(array)):
      array[i] = sorted(array[i], reverse=True)
    return array

if __name__ == "__main__":
  n = int(input())
  l = list(map(int, input().split()))
  array = list(combinations(l, 3))
  array = main.Sort(array)
  main.T(array)
      

Measured memory_bytes: 100368
#define _USE_MATH_DEFINES
#include <math.h>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <numeric>
#include <stdio.h>
#include <vector>
#include <map>
#include <queue>

using namespace std;
typedef long long ll;
using Graph = vector<vector<ll>>;

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

int main() {
    string S;
    cin >> S;
    string out = "NO";
    rep(i,8){
        string s = S;
        s.erase(i,S.length()-7);
        if(s=="keyence"){
            out = "YES";
            break;
        }
    }
    cout << out << endl;
    return 0;
}



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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define ld long double
#define pb push_back
#define eb emplace_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define llbidx(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y) // 二要素間の距離
#define deg2rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad2deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)
#define Find(set, element) set.find(element) != set.end()
#define Decimal(x) printf("%.10f\n", x) // 小数点を10桁まで表示
// debug用
#define PrintVec(x) for (auto elementPrintVec: x) { cout << elementPrintVec << " "; } cout << "\n";
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define endl "\n"
// gcj print用
#define Case(x) printf("Case #%d: ", x);

typedef pair<int, int> PI;
typedef pair<ll, ll> PLL;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<int>>> vvvl;
typedef vector<PI> vpi;
typedef vector<vector<PI>> vvpi;
typedef vector<vector<vector<PI>>> vvvpi;
typedef vector<PLL> vpl;
typedef vector<vector<PLL>> vvpl;
typedef vector<vector<vector<PLL>>> vvvpl;

int POWINT(int x, int n) {
  int ret = 1;
  while (n > 0) {
    if (n & 1) ret *= x;
    x *= x;
    n >>= 1;
  }
  return ret;
};

ll POWLL(ll x, int n) {
  ll ret = 1;
  while (n > 0) {
    if (n & 1) ret *= x;
    x *= x;
    n >>= 1;
  }
  return ret;
};

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

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

void print() {
  cout << endl;
}

template <class T>
void print(vector<T> &vec) {
  for (auto& a : vec) {
    cout << a;
    if (&a != &vec.back()) cout << " ";
  }
  cout << endl;
}

template <class T>
void print(vector<T> &vec, ll k){
   ll n = vec.size();
   k = min(k, n);
   rep(i, 0, k-1) cout << vec[i] << " ";
   cout << vec[k-1] << endl;
}

template <class T>
void print(vector<vector<T>> &df) {
  for (auto& vec : df) {
    print(vec);
  }
}

template<class T, class U>
void print(pair<T,U> &p){
  cout << p.first << " " << p.second << "\n";
}

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

  int n, k; cin >> n >> k;
  int ans = 1e9+7;

  rep(i, 0, 1 << n) {
    int tmp = 1;
    rep(j, 0, n) {
      if ((i >> j)&1) {
        tmp += k;
      } else {
        tmp *= 2;
      }
    }
    chmin(ans, tmp);
  }

  cout << ans << endl;

  return 0;
};


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep( i, n ) for (long long i = 0; i < ( long long )(n); i++)

using namespace std;
typedef long long ll;
typedef pair< int , int > P;
typedef tuple<int, int, int> T;


int main(){
    int a,b,h,m;
    double ans;
    const double pi =3.14159265359;
    cin>>a>>b>>h>>m;
    
    double rh = pi*h/6+pi*m/(12*30);
    double rm = pi*m/30;
    double sh = abs(rh-rm);
    if (sh>=pi) sh=2*pi-sh;
    double d=a*a+b*b-2*a*b*cos(sh);
    cout << fixed << setprecision(15);
    cout<<sqrt(d);
}





Measured memory_bytes: 4136
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  string S;
  cin>>S;
  if(S=="Sunny"s)cout<<"Cloudy"<<endl;
  if(S=="Cloudy"s)cout<<"Rainy"<<endl;
  if(S=="Rainy"s)cout<<"Sunny"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;

#define pll pair<ll,ll>
#define ff first
#define snd second
#define pb push_back
#define vll vector<ll>
#define vpll vector<pll>
#define endl "\n"
#define MOD 1000000007
using namespace std;

ll const N = 1e5+1;


void solve()
{
   string s;
   cin>>s;
   
   if(s[2]!=s[3] || s[4]!=s[5])
   {
           cout<<"No";
           return;
   }
   
   cout<<"Yes";
}
 
int main() {
            ios_base::sync_with_stdio(false);
            cin.tie(NULL);
	    int t=1;
	    //cin>>t;
	    while(t--)
	    {
	            solve();
	    }
	    return 0;
}

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

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

#define mp make_pair
typedef pair<int,int> pii;

const int M_MAX = 1000010;
const int N = 4000;

pii fill(vector<vector<int>> &maze, int x, int y, int dir, int k, int s) {
  for (int i = 0; i < k; i++) {
    maze[y + i * dy[dir]][x + i * dx[dir]] = s++;
  }
  return mp(x + k * dx[dir], y + k * dy[dir]);
}

void make(vector<vector<int>> &maze) {
  pii now = mp(N / 2, N / 2);
  int k = 1;
  int num = 1;
  while(num <= M_MAX) {
    now = fill(maze, now.first, now.second, 0, k, num); num += k;
    now = fill(maze, now.first, now.second, 1, k, num); num += k;
    k++;
    now = fill(maze, now.first, now.second, 2, k, num); num += k;
    now = fill(maze, now.first, now.second, 3, k, num); num += k;
    k++;
  }
}

char isprime[M_MAX];

void era() {
  for (int i = 0; i < M_MAX; i++) {
    isprime[i] = 1;
  }
  isprime[0] = isprime[1] = 0;
  for (int i = 2; i < M_MAX; i++) {
    if (isprime[i]) {
      for (int j = i + i; j < M_MAX; j += i) {
        isprime[j] = 0;
      }
    }
  }
}

void solve(vector<vector<int>> &maze, int m, int n) {
  int sx, sy;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      if (maze[i][j] == n) {
        sx = j, sy = i;
      }
    }
  }
  vector<vector<int>> dp(N, vector<int>(N, -1));
  dp[sy][sx] = isprime[maze[sy][sx]];
  for (int i = 0; i < N - 1; i++) {
    for (int j = 0; j < N; j++) {
      if (maze[i][j] > m) continue;
      if (dp[i][j] == -1) continue;
      if (j >= 1) dp[i + 1][j - 1] = max(dp[i + 1][j - 1], dp[i][j] + isprime[maze[i + 1][j - 1]]);
      dp[i + 1][j] = max(dp[i + 1][j], dp[i][j] + isprime[maze[i + 1][j]]);
      if (j < N - 1) dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + isprime[maze[i + 1][j + 1]]);
    }
  }
  int ma = 0;
  int ma_ind = 0;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      if (maze[i][j] > m) continue;
      if (ma <= dp[i][j] && isprime[maze[i][j]]) {
        if (ma < dp[i][j]) {
          ma = dp[i][j];
          ma_ind = maze[i][j];
        } else {
          if (ma_ind < maze[i][j]) ma_ind = maze[i][j];
        }
      }
    }
  }
  if (ma == 0) {
    cout << "0 0" << endl;
  } else {
    cout << ma << " " << ma_ind << endl;
  }
}

int main() {
  vector<vector<int>> maze(N, vector<int>(N, 0));
  make(maze);
  era();

  int n, m;
  while(cin >> m >> n, m != 0) {
    solve(maze, m, n);
  }
  
  return 0;
}



Measured memory_bytes: 129032
from collections import defaultdict

N = int(input())
A = [int(s) for s in input().split()]
Q = int(input())
B = []
C = []
for _ in range(Q):
    b, c = [int(s) for s in input().split()]
    B.append(b)
    C.append(c)

A_dict = defaultdict(int)
for a in A:
    A_dict[a] += 1

A_sum = sum(A)
for b, c in zip(B, C):
    n = A_dict[b]
    A_dict[b] = 0
    A_dict[c] += n
    A_sum += (c - b) * n
    print(A_sum)


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

int dp[1001][1001] = {{0}};

int LCS(string X, string Y){
    auto len_x = X.length();
    auto len_y = Y.length();
    for (int i = 0; i != len_x; ++i){
        for (int j = 0; j != len_y; ++j){
            if (X[i] == Y[j]){
                dp[i + 1][j + 1] = dp[i][j] + 1;
            }else{
                dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j]);
            }
        }
    }
    return dp[len_x][len_y];
}

int main()
{
    ios::sync_with_stdio(false);
    
    int q = 0;
    cin >> q;
    
    string X;
    string Y;
    while (q--){
        cin >> X;
        cin >> Y;
        cout << LCS(X, Y) << endl;
    }
    return 0;
}

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

using namespace std;

int ok[100001];

int main()
{
	int n;
	cin >> n;
	int money[12] = {1,6,9,36,81,216,729,1296,6561,7776,46656,59049};
	queue<pair<long long, int>> que;
	for(int i = 0; i < 12; i++)
	{
		que.push(pair<long long, int>(money[i], 1));
		ok[money[i]] = 1;

	}
	while(que.size())
	{
		pair<long long, int> p = que.front(); que.pop();
		for(int i = 0; i < 12; i++)
		{
			if(p.first + money[i] <= n && ok[p.first + money[i]] == 0)
			{
				ok[p.first + money[i]] = p.second + 1;
				que.push(pair<long long, int>(p.first + money[i], p.second + 1));
			}
		}
	}
	cout << ok[n] << endl;

	return 0;
}


Measured memory_bytes: 1024
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
use {
    proconio::{marker::*, *},
    std::{cmp::*, collections::*, mem::*},
};
fn main() {
    input! {//
        n:usize,m:usize,
        ab:[(Usize1,Usize1);m],
    }
    let mut cnts = vec![0i64; n];
    for &(a, b) in ab.iter() {
        cnts[a] += 1;
        cnts[b] += 1;
    }
    yn(cnts.iter().all(|&x| x % 2 == 0));
}
pub fn yn(ans: bool) {
    if ans {
        println!("YES");
    } else {
        println!("NO");
    }
}


Measured memory_bytes: 5456
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
//using namespace boost::multiprecision;
typedef long long int ll;
typedef long double ld;
#define PI 3.141592653589793
#define MOD 1000000007
#define ALL(obj) (obj).begin(),(obj).end()
template<class T>inline bool chmax(T& a,T b){if (a<b){a=b;return 1;}return 0;}
template<class T>inline bool chmin(T& a,T b){if (a>b){a=b;return 1;}return 0;}
const ll INF = 1LL << 56;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
bool pairCompareSecond(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.second < secondElof.second;
}
//四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

struct edge{//グラフに使うヤツ
    ll from,to,cost;
};

typedef vector<vector<edge> > G;
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}

vector<pair<long long, long long> > prime_factorize(long long N) {
    vector<pair<long long, long long> > res;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0;
        while (N % a == 0) {
            ++ex;
            N /= a;
        }
        res.push_back({a, ex});
    }
    if (N != 1) res.push_back({N, 1});
    return res;
}

int main(){
    ll a,b;
    cin >> a >> b;
    auto pf=prime_factorize(gcd(a,b));
    cout << pf.size()+1 << endl;
    return 0;
}


Measured memory_bytes: 3644
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto nk = readln.split.to!(int[]);
    auto N = nk[0];
    auto K = nk[1];

    writeln((N+1) / 2 >= K ? "YES" : "NO");
}

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

int main(){
    int64_t S;
    cin >> S;
    vector<int> S_v;
    while(S != 0){
        S_v.push_back(S % 10);
        S /= 10;
    }
    reverse(S_v.begin(), S_v.end());
    int ans = 1000;
    for (int i = 0; i < S_v.size() - 2; i++){
        int a;
        a = S_v.at(i) * 100 + S_v.at(i + 1) * 10 + S_v.at(i + 2);
        if (abs(a - 753) < ans){
            ans = abs(a - 753);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using i64 = long long;

int main() {
    constexpr i64 mod = 1000000007;
    i64 n, k;
    std::cin >> n >> k;
    std::deque<i64> d;
    for (i64 i = 1; i * i <= n; i++) {
        d.push_back(i);
        d.push_back(n / i);
    }
    std::sort(d.begin(), d.end());

    std::deque<i64> c { 1 };
    for (int i = 1; i < d.size(); i++) if (d[i] != d[i - 1]) c.push_back(d[i] - d[i - 1]);
    auto cnt(c);

    for (int i = 1; i < k; i++) {
        std::deque<i64> nxt;
        i64 sum = 0;
        for (int j = 0; j < c.size(); j++) {
            sum = (sum + c[j]) % mod;
            nxt.push_front(sum * cnt[c.size() - j - 1] % mod);
        }
        std::swap(nxt, c);
    }

    i64 ret = 0;
    for (auto e : c) ret = (ret + e) % mod;
    std::cout << ret << std::endl;

    return 0;
}


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

const int mod=1e9+7;

#define ll long long
int n, k, u[666], v[666], f[666][666], g[666], usd[666], cc[666][666];

int fix(int x){
    return x==-1? 665: x;
}

int main(){
    cin>>n>>k;
    for (int i=1;i<=k;++i){
        cin>>u[i]>>v[i];
        usd[u[i]]=v[i]; usd[v[i]]=u[i];
    }
    g[0]=1;
    for (int i=2;i<=n*2;i+=2)
        g[i]=(ll)g[i-2]*(i-1)%mod;
    int ans=0, all=n*2-k*2;
    for (int len=1;len<n*2;++len)
        for (int i=1;i+len<=n*2;++i){
            int j=i+len;
            int fl=1;
            for (int k=i;k<=j;++k){
                if (usd[k]&&(usd[k]<i||usd[k]>j)) fl=0;
                cc[i][j]+=!usd[k];
            }
            if (cc[i][j]&1) fl=0;
            if (!fl){
                cc[i][j]=-1;
                continue;
            }
            f[i][j]=g[cc[i][j]];
            ll dec=0;
            for (int k=i+1;k<j;++k){
                dec=(dec+f[i][k]*(ll)g[fix(cc[k+1][j])])%mod;
            }
            f[i][j]=(f[i][j]-dec+mod)%mod;
            ans=(ans+(ll)f[i][j]*g[all-cc[i][j]])%mod;
        }
    cout<<ans<<endl;
}

Measured memory_bytes: 3328
#include <iostream>
#include <iomanip>
#include <ios> 
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define sz(c) ((int)(c).size())

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
//const int MAX=;



int main(){
	int N;
	cin>>N;
	int S[105];
	S[0]=0;
	rep1(i,N){
		int w;
		cin>>w;
		S[i]=S[i-1]+w;
	}
	int all=S[N];
	int ans=100000000;
	rep1(i,N-1){
		ans=min(ans, abs(all-2*S[i]));
	}
	cout<<ans<<endl;
}

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

inline int read(){
	re int ans = 0;re bool f = 1;re char ch = getchar();
	while(ch<'0'||ch>'9'){if (ch=='-')f = 0;ch = getchar();}
	while(ch>='0'&&ch<='9'){
		ans = ans*10+(ch^48);
		ch = getchar();
	}
	return f?ans:~(ans-1);
}

signed main(void){
	int n = read();
	int m = read();
	for(re int i=1;i<=m;++i){
		n-=read();
	}
	if(n<0)printf("-1\n");
	else printf("%d\n",n);
	return 0;
}
  

Measured memory_bytes: 3768
#[allow(unused_imports)]
use std::cmp::{Ordering};

#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};

#[allow(unused_imports)]
use std::iter::FromIterator;

#[allow(unused_macros)]
macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::min($x, min!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::max($x, max!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! get { 
    ([$t: ty]) => { 
        { 
            let mut line = String::new(); 
            stdin().read_line(&mut line).unwrap(); 
            line.split_whitespace().map(|t|t.parse::<$t>().unwrap()).collect::<Vec<_>>()
        }
    };
    ([$t: ty];$n: expr) => {
        (0..$n).map(|_|get!([$t])).collect::<Vec<_>>()
    };
    ($t: ty) => {
        {
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t: ty),*) => {
        { 
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*)
        }
    };
    ($t: ty; $n: expr) => {
        (0..$n).map(|_|get!($t)).collect::<Vec<_>>()
    };
    ($($t: ty),*; $n: expr) => {
        (0..$n).map(|_|get!($($t),*)).collect::<Vec<_>>()
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*).unwrap();
    }
}

const BIG_STACK_SIZE: bool = true;

#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}

fn solve() {
    let n = get!(usize);
    let a = get!([usize]);

    if a.into_iter().all(|e| e%2==1 || (e%3==0) || (e%5==0)) {
        println!("APPROVED");
    } else {
        println!("DENIED");
    }
}


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

// o(n^2 * V) ナップサック問題

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

const ll INF = 1LL << 60;

const int MAX_N = 110;
const int MAX_V = 100100;

// 入力
int n;
ll W, weight[MAX_N],
    value[MAX_N];  // 品物の個数は 100 個なので少し余裕持たせてサイズ 110 に

// DPテーブル
ll dp[MAX_N][MAX_V];

int main() {
  cin >> n >> W;
  rep(i, n) cin >> weight[i] >> value[i];

  // 初期化
  rep(i, MAX_N) rep(j, MAX_V) dp[i][j] = INF;

  // 初期条件
  dp[0][0] = 0;

  // DPループ
  for (int i = 0; i < n; ++i) {
    for (int sum_v = 0; sum_v < MAX_V; ++sum_v) {
      // i 番目の品物を選ぶ場合
      if (sum_v - value[i] >= 0)
        chmin(dp[i + 1][sum_v], dp[i][sum_v - value[i]] + weight[i]);

      // i 番目の品物を選ばない場合
      chmin(dp[i + 1][sum_v], dp[i][sum_v]);
    }
  }

  // 最適値の出力
  ll res = 0;
  rep(sum_v, MAX_V) {
    if (dp[n][sum_v] <= W) res = sum_v;
  }
  cout << res << endl;
}

Measured memory_bytes: 89616
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define SORT(x) sort(x.begin(), x.end())
#define RS(x) rsort(x.begin(),x,end()))
#define REVE(x) reverse(x.begin(), x.end())
#define ALL(x) (x).begin(), (x).end()
int INF = 1e9 + 1;
int MOD = 1e9+7;
struct initon
{
    initon()
    {
        cin.tie(0);
        ios::sync_with_stdio(false);
    };
};
signed main()
{
  int y, m, d;
  char c1, c2;
  cin >> y >> c1 >> m >> c2 >> d;
  cout << (m <= 4 ? "Heisei" : "TBD") << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#include<list>
#include<unordered_map>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define INF (1 << 30) - 1
#define LLINF (1LL << 61) - 1
// #define int ll
using namespace std;
const int MOD = 1000000007;
const int MAX = 510000;

int main(){
    ll m,d,ans=0;
    cin>>m>>d;
    rep2(i,1,m+1){
        rep2(j,1,d+1){
            if((j%10)>=2 && (j/10)>=2 && ((j%10)*(j/10))==i) ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main()
{
	char a[51], b[51];
	scanf("%s %s", a,b);
	int i,l=strlen(b);
	for(i=0; i<l; i++)
		printf("%c%c", a[i], b[i]);
	if(strlen(a)==l+1)
		printf("%c", a[i]);
	return 0;
}

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

using namespace std;

int P[110];
pair<int,int> bridge[10010];

void init(int N){
  for(int i = 0;i<N;i++){
    P[i] = i;
  }
}

int root(int a){
  if(P[a] == a){
    return a;
  }
  return(P[a] = root(P[a]));
}

bool is_same_set(int a,int b){
  return root(a) == root(b);
}

void unite(int a,int b){
  P[root(a)] = root(b);
}

int main(){
  int n,a[10010],b[10010],w,count = 0,result = 0,x,y;
  cin >>n;
  init(n);
  for(int i=0;i<n;i++){
    for(int k=0;k<n;k++){
      cin >> w;
      if(w >= 0){
        bridge[count].first = w;
        a[count] = i;
        b[count] = k;
        bridge[count].second = count;
        count ++;
      }
    }
  }
  sort(bridge,bridge+count);
  for(int i=0;i<count;i++){
    x = a[bridge[i].second];
    y = b[bridge[i].second];
    if(!is_same_set(x,y)){
      unite(x,y);
      result += bridge[i].first;
      //cout << x <<" " << y << " " << bridge[i].first << endl;
    }
  }
  cout << result << endl;
}



Measured memory_bytes: 3236
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);

		while(true){
			int n=sc.nextInt();
			boolean f = false,f2=true;
			if(n==0)break;
			int count = 0,sum =0;

			for(int i=0;i<n;i++){
				int data = sc.nextInt();
				if(data<2)f=true;
				if(data>=2)f2=false;

				if(data==0)count++;
				sum +=data;
			}
			if(f&&f2)System.out.println("NA");
			else System.out.println((n+1-count));

		}

		sc.close();

	}

}



Measured memory_bytes: 163052
#include<iostream>
using namespace std;
int main()
{
	int n,k;
	char s[55];
	cin>>n>>k;
	for(int i=1;i<=n;i++)
	    cin>>s[i];
	if(s[k]=='A')
	    s[k]='a';
	else if(s[k]=='B')
	    s[k]='b';
	else if(s[k]=='C')
	    s[k]='c';
	for(int i=1;i<=n;i++)
	    cout<<s[i];
	return 0;
}

Measured memory_bytes: 256