akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> bool cmax(T& a, U b) { if (a<b) {a = b; return true;} else return false; }
template<class T, class U> bool cmin(T& a, U b) { if (a>b) {a = b; return true;} else return false; }

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

  int n, k;
  cin >> n >> k;
  vi v(n);
  rep(i, n) {
    cin >> v[i];
  }

  int ans = 0;
  rep(i, n+1) {
    for (int j = 0; i+j <= n && i+j <= k; j++) {
      int cnt = 0;
      priority_queue<int> q;

      rep(ii, i) {
        cnt += v[ii];
        q.push(-v[ii]);
      }

      rep(ii, j) {
        cnt += v[n-1-ii];
        q.push(-v[n-1-ii]);
      }

      rep(ii, k-i-j) {
        if (q.size() && q.top() > 0) {
          cnt += q.top();
          q.pop();
        }
      }

      cmax(ans, cnt);
    }
  }

  cout << ans << endl;
}


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

using namespace std;

int main()
{
  while (1) {
    string str;
    int n, h;
    cin >> str;
    if (str == "-") break;
    cin >> n;
    while (n--) {
      cin >> h;
      str += str.substr(0, h);
      str.erase(0, h);
    }
    cout << str << endl;
  }
}



Measured memory_bytes: 3176
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <queue>
using namespace std;

int main(){
    int n;
    cin >> n;
    cout << 180*(n-2) << endl;
    return 0;
}


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

#define x first
#define y second

using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
typedef pair<ll,ll> pll;

const int mod=1000000000+7;

int addm(int& a,int b) {return (a+=b)<mod?a:a-=mod;}

template<class T,class U> bool smin(T& a,U b) {return a>b?(a=b,1):0;}
template<class T,class U> bool smax(T& a,U b) {return a<b?(a=b,1):0;}

int N,a[300000];
ll sum;

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

	cin >> N;
	for (int i=0;i<3*N;i++) cin >> a[i];
	sort(a,a+3*N);
	for (int i=3*N-2,j=0;j<i;i-=2,j++) sum+=a[i];
	cout << sum << endl;
}

Measured memory_bytes: 1408
# input
C = [list(map(int, input().split())) for i in range(3)]

# check
base = [C[0][0], C[1][1], C[2][2]]
case_AB = [
    1
    for a in range(base[0] + 1)
    for b in range(base[1] + 1)
    for c in range(base[2] + 1)
    if [
        [base[0], b + (base[0] - a), c + (base[0] - a)],
        [a + (base[1] - b), base[1], c + (base[1] - b)],
        [a + (base[2] - c), b + (base[2] - c), base[2]]
    ] == C
]

if case_AB:
    print("Yes")
else:
    print("No")

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

#define rep(i, n) for(int i=0; i < n; i++)
#define reps(i, n) for(int i=1; i <= n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()

using namespace std;
using ll=long long;



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

  if(S[K-1]=='A')S[K-1]='a';
  if(S[K-1]=='B')S[K-1]='b';
  if(S[K-1]=='C')S[K-1]='c';

  cout << S;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
char s[100];
int mymap[100][105];
int main(){
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		cin>>s+1;
		for(int j=1;j<=m;j++){
			if(s[j]=='#'){
				mymap[i][j]=1;
			}
		}
	}
	int flag=0;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(mymap[i][j]){
				if(!mymap[i-1][j]&&!mymap[i+1][j]&&!mymap[i][j-1]&&!mymap[i][j+1]){
					flag=1;
				}
			}
		}
	}
	if(flag){
		cout<<"No"<<endl;
	}else{
		cout<<"Yes"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
class Main{
	public static void main(String[] args1) {
		Scanner s = new Scanner(System.in);
		String line = s.nextLine();
		String[] args = line.split(" ");
		int[] arr = new int[args.length];
		for(int i = 0;i < args.length;i++)
			arr[i] =  Integer.parseInt(args[i]);

		int count = 0;
		Arrays.sort(arr);
		for(int i = 0;i < arr.length-1;i++)
			count += Math.abs(arr[i] - arr[i+1]);

		System.out.println(count);


	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
//#define vi vector<int>
#define vb vector<bool>
#define pii pair<int, int>
#define mii map<int, int>
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define tr(container, it) for (typeof(container.begin()) it = container.begin(); it != container.end(); it++)
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) (a * b) / gcd(a, b)
#define inf (long long)1e18
#define F first
#define S second
#define SZ(x) ((int)(x).size())
//#define rep(i, n) for (int i = 0; i < n; i++)
//#define repd(i,n) for(int i=n-1;i>=0;i--)
//#define rep1(i,n) for(int i=1;i<=n;i++)
const int N = 1e9 + 7;

int pow(int x, int y)
{
    int res = 1;
    while (y > 0)
    {
        if (y & 1)
            res = ((res) * (x));
        res %= N;
        y = y >> 1;
        x = ((x) * (x));
    }
    return res;
}
ll powm(ll x, ll y, ll p)
{
    ll res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}

int gcd(int a, int b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
ll mxn(ll a, ll b)
{
    if (a > b)
        return a;
    else
    {
        return b;
    }
}
long long minl(long long a, long long b)
{
    if (a < b)
        return a;
    else
    {
        return b;
    }
}

void solve()
{
    string s;
    cin >> s;
    int k = s.length();
    if (s[k - 1] == 's')
    {
        s += 'e';
        s += 's';
    }
    else
    {
        s += 's';
    }
    cout << s;
}

int32_t main()

{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t;
    // cin >> t;
    // while (t--)
    // {
    solve();
    // }
}

Measured memory_bytes: 3660
#import<cstdio>
int main(){int a,c=3,r=1;for(char d[]="123546",s[9];a=scanf("%s",s),*s>60;r+=*d&7)*s%6-4?d[5]=d[a+=*s%5+*s%2*2+c&3],d[a]=*d,d[++a%4+1]=~*d,*d=~d[5]:c+=*s+3;~-r&&printf("%d\n",r);~a&&main();}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(i,a,b) for (int i=a; i<b; ++i)
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int N;
    cin >> N;
    vector <int> A(N), B(N), C(N);
    loop(i,0,N) cin >> A[i] >> B[i] >> C[i];
    vector < vector <int> > dp(N);
    loop(i,0,N) dp[i].resize(3);
    dp[0][0]=A[0];
    dp[0][1]=B[0];
    dp[0][2]=C[0];
    loop(i,1,N)
    {
        dp[i][0]=max(dp[i-1][1]+A[i], dp[i-1][2]+A[i]);
        dp[i][1]=max(dp[i-1][0]+B[i], dp[i-1][2]+B[i]);
        dp[i][2]=max(dp[i-1][1]+C[i], dp[i-1][0]+C[i]);
    }
    cout << max(dp[N-1][0], max(dp[N-1][1], dp[N-1][2])) << "\n";
    return 0;
}

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

unordered_map<int, int> m;
std::vector<unsigned short> a[3];

int d(int n, int c) {
  if (n == 0) return 0;
  int maxpoints = m[n * 3 + c];
  if (!maxpoints) {
    for (int k = 0; k < 3; ++k) {
      if (k == c) continue;
      maxpoints = max(maxpoints, d(n - 1, k) + a[c][n]);
    }
    m[n * 3 + c] = maxpoints;
  }
  return maxpoints;
}

int main() {
  int N;
  cin >> N;
  m.clear();
  for (int i = 0; i < 3; ++i) {
    a[i].clear();
    a[i].resize(N + 1);
  }
  for (int i = 1; i <= N; ++i) cin >> a[0][i] >> a[1][i] >> a[2][i];
  int maxpoints = max(d(N, 0), max(d(N, 1), d(N, 2)));
  cout << maxpoints << endl;
  return 0;
}


Measured memory_bytes: 24264
// Problem : C - Tsundoku
// Contest : AtCoder - AtCoder Beginner Contest 172
// URL : https://atcoder.jp/contests/abc172/tasks/abc172_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

//mst,pq,mp,st,q
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define all(x) begin(x),end(x)

int mod = 1e9+7;
int inf = 4e18;
const int N = 5e5+5;
		
signed main()
{
    io
    int tt = 1;
    //cin>>tt;
    while(tt--)
    {
		int n,m,k;
		cin>>n>>m>>k;
		int kk = k;
		int arr[n],brr[m];
		for(int i=0;i<n;++i)
		cin>>arr[i];
		for(int i=0;i<m;++i)
		cin>>brr[i];
		//int ct = 0;
		int pre1[n] = {};
		int pre2[m] = {};
		pre1[0] = arr[0];
		pre2[0] = brr[0];
		for(int i=1;i<n;++i)
		pre1[i] = pre1[i-1]+arr[i];
		for(int i=1;i<m;++i)
		pre2[i] = pre2[i-1]+brr[i];
		int maxx = 0,ct=0;
		for(int i=0;i<m;++i)
		{
			if(pre2[i]<=k)
			++ct;
		}
		maxx = ct;
		for(int i=0;i<n;++i)
		{
			if(k<pre1[i])
			break;
			int x = upper_bound(pre2,pre2+m,k-pre1[i]) - pre2;
			maxx = max(maxx,x+i+1);
		}
		cout<<maxx;
    }
    return 0;
}


Measured memory_bytes: 9856
n, m = map(int, input().split())
s = [set()] * m
for i in range(m):
    s[i] = set(list(map(lambda x: int(x)-1, input().split()))[1:])
p = list(map(int, input().split()))

ans = 0

for i in range(2 ** n):
    lights = set()
    for j in range(n):
        if ((i >> j) & 1):
            lights.add(j)
    
    for j in range(m):
        if len(s[j] & lights) % 2 != p[j]: break
    else: ans += 1

print(ans)


Measured memory_bytes: 3064
import std.stdio;
import std.c.stdio;
import std.range;
import std.array;
import std.functional;
import std.algorithm;
import std.conv;
import std.container;
import std.math;
import std.numeric;
import std.string;
import std.c.string;
import std.regex;
import std.typecons;

int[] 素数集合() {
    const nの最大値 = 1000000;
    auto 表 = new bool[nの最大値];
    表[] = true;
    表[0] = 表[1] = false;
    int[] 集合;
    for (int i = 2; i < nの最大値; i++) {
        if (表[i]) {
            集合 ~= i;
            for (int j = i + i; j < nの最大値; j += i) {
                表[j] = false;
            }
        }
    }
    return 集合;
}
 
void main() {
    int n;
    auto 集合 = 素数集合();
    while (~scanf("%d\n", &n)) {
        if (n < 2) {
            writeln(0);
            continue;
        }
        int 下限 = 0, 上限 = cast(int)集合.length;
        while (下限 + 1 < 上限) {
            int 中間 = (下限 + 上限) / 2;
            if (集合[中間] <= n) {
                下限 = 中間;
            } else {
                上限 = 中間;
            }
        }
        writeln(下限 + 1);
    }
}

Measured memory_bytes: 2300
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <cassert>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int,int> P;
#define rep(i,a,n) for(ll i = (a);i < (n);i++)
#define per(i,a,n) for(ll i = (a);i > (n);i--)
#define lep(i,a,n) for(ll i = (a);i <= (n);i++)
#define pel(i,a,n) for(ll i = (a);i >= (n);i--)
#define clr(a,b) memset((a),(b),sizeof(a))
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define sz size()
#define print(X) cout << (X) << endl
const ll INF = 1e+15+7;
ll n,m,l;
string s,t;
ll d[100000],dp[100][100];
ll a,b;
bool prime[100000];

void check(){
  prime[0] = prime[1] = true;
  for(int i = 2;i < 100000;i++){
    if(!prime[i]){
      for(int j = 2;i*j < 100000;j++){
        prime[i*j] = true;
      }
    }
  }
  for(int i = 3;i < 100000;i += 2){
    if(!prime[i] && !prime[(i+1)/2])d[i]++;
  }
  rep(i,0,100000){
    d[i] += d[i-1];
  }
}

int main(){
  check();
  cin >> n;
  rep(i,0,n){
    cin >> a >> b;
    print(d[b] - d[a-1]);
  }
  // rep(i,0,n)print(d[i]);
  return 0;
}


Measured memory_bytes: 1536
#include <iostream>
#include <algorithm>
using namespace std;
long long a[200000],h[200000];
long long f[200001],seg[800000];
int n;
void update(int h,long long val,int l,int r,int st){
    if (l==r) seg[st]=max(seg[st],val);
    else {
        int mid=(l+r)/2;
        if (h<=mid) update(h,val,l,mid,st*2);
        else update(h,val,mid+1,r,st*2+1);
        seg[st]=max(seg[st*2],seg[st*2+1]);
    }
}
long long take(int l,int r,int u,int v,int st){
    if (u<=l&&r<=v) return seg[st];
    else if (v<l||r<u) return 0;
    else{
            int mid=(l+r)/2;
            return max(take(l,mid,u,v,st*2),take(mid+1,r,u,v,st*2+1));
    }
}
int main()
{
    cin>>n;
    long long mx=0;
    for (int i=0;i<n;++i) {cin>>h[i]; mx=max(mx,h[i]);}
    for (int i=0;i<n;++i) cin>>a[i];
    for (int i=0;i<n;++i){
        if (h[i]==1) f[h[i]]=a[i];
        else
            f[h[i]]=take(1,mx,1,h[i]-1,1)+a[i];
        update(h[i],f[h[i]],1,mx,1);
    }
    long long w=0;
    for (int i=1;i<=mx;++i){
        w=max(w,f[i]);
    }
    cout<<w;
}


Measured memory_bytes: 11136
#include <bits/stdc++.h>
using namespace std;
 
 
#define FAST std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pi       acos(-1)
#define mp make_pair
#define pb push_back
#define int long long ////////////
#define MOD 1000000007    ////////
#define POD 998244353 ////////
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort(ALL(v))  
#define REVERSE(v) reverse(ALL(v))
#define maxc(v) max_element(all(v))
#define minc(v) min_element(all(v))
#define F first
#define S second
#define ppb pop_back
#define GCD(m,n) __gcd(m,n)
#define LCM(m,n) (m*n)/GCD(m,n)
#define inputarr(a,n) for(int i=0;i<n;++i) cin>>a[i]
#define initarr(a,n,x) for (int i=0;i<n;++i) a[i]=x
#define rep(i,a,n)  for(int i=a ; i<n ; i++)
#define repe(i,a,n) for(int i=a;i<=n;i++)
#define rev(i,a,b) for(int i=a;i>=b;i--)
//define ll long long
#define ld long double 
 
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<vvvi> vvvvi;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<vvc> vvvc;
typedef vector<pii > vpii;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef map<int,int> mii;
typedef unordered_map<int,int> umii;
typedef map<char,int> mci;
 
#define itv for(auto it= v.begin(); it != v.end(); ++it )
 
#define present(container, element) (container.find(element) != container.end())
#define cpresent(container, element) (find(ALL(container),element) != container.end())
//#define invect(data,n,commands) for(int i = 0;i<n;i++){int tmp;cin>>tmp;data.pb(tmp);commands}
//#define inset(data,n,commands) for(int i = 0;i<n;i++){int tmp;cin>>tmp;data.insert(tmp);commands}
//#define trav(a, x) for(auto& a : x)
//#define display(x) trav(a,x) cout<<a<<" ";cout<<endl
 
 
#define bs binary_search
#define  lb(v,val)  lower_bound(ALL(v), val); 
 
#define dbg1(a) cout<<" *"<<a<<" ";
#define dbg2(a,b) cout<<" *"<<a<<" **"<<b<<" "     /////
#define dbg cout<<"hi"
#define nl "\n";
#define sz(s)         (int)((s).size())
#define coutsp(k)   cout<<setprecision(k)  //set precision (total length k icluding decimal and non decimal)
#define coutfsp(k)   cout<<fixed<<setprecision(k)  //fixed set precision(after decimal fixing)
#define  INF   (int)2e18 
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define vin(v,n)   vi v(n); rep(i,0,n)  cin>>v[i];
//#define siz  (int)1e8
#define N 300000



void quickly_quickly_kro()
{
   int n; cin>>n;

   vi a(n+1),b(n+1),c(n+1);

   rep(i,1,n+1)
   {
    cin>>a[i]>>b[i]>>c[i];
   }


   int dp[n+1][3];

   dp[0][0]=0;
   dp[0][1]=0;
   dp[0][2]=0;

   rep(i,1,n+1)
   { 

     dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a[i];

     dp[i][1]=max(dp[i-1][0],dp[i-1][2])+b[i];

     dp[i][2]=max(dp[i-1][0],dp[i-1][1])+c[i];



   }

   cout<<Max(dp[n][0],dp[n][1],dp[n][2]);

 }
 
 
 
 
signed main()
{
 
     
 
 
   FAST
   
   int t; 
      t=1;              
  // cin>>t;
    while(t--)
    {
    
      quickly_quickly_kro();
      cout<<nl;
          
}
 
 
 

 
   return 0;
}

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

int main() {
  int H, W;
  char S;
  cin >> H >> W;
  
  vector<vector<int>> data(H+2, vector<int>(W+2));
  
  for (int i = 0; i < H+2; i++) {
    for (int j = 0; j < W+2; j++) {
      data.at(i).at(j) = 0;
    }
  }
  
  for (int i = 1; i < H+1; i++) {
    for (int j = 1; j < W+1; j++) {
      cin >> S;
      if (S == '#') {
        data.at(i).at(j) = 10;
        data.at(i-1).at(j-1)++;
        data.at(i-1).at(j)++;
        data.at(i-1).at(j+1)++;
        data.at(i).at(j-1)++;
        data.at(i).at(j+1)++;
        data.at(i+1).at(j-1)++;
        data.at(i+1).at(j)++;
        data.at(i+1).at(j+1)++;
      } 
    }
  }
  
  for (int i = 1; i < H+1; i++) {
    for (int j = 1; j < W+1; j++) {
      if (data.at(i).at(j) < 10) {
        cout << data.at(i).at(j);
      } else {
        cout << '#';
      }
    }
    cout << endl;
  }
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 100000000;
#define rep1(i, n) for (ll i=0; i<(n); i++) 
#define rep2(i, k, n) for (ll i=k; i<(n); i++)
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; }


int main() {
    ll n;
    cin >> n;
    vector<ll> a(n, 0);
    rep1(i, n) cin >> a[i];
    sort(a.begin(), a.end());
    ll ans = 0; 
    for (ll i=0; i<(n-1); i++){
        for (ll j=i+1; j<(n); j++){
            ll k = lower_bound(a.begin(), a.end(), a[i]+a[j]) - a.begin();
            ans += max(k-(j+1), (ll)0);
        }
    }
    cout << ans << endl;
    //printf("%.12f", ans);
}

Measured memory_bytes: 3632
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please


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


	int N;
	cin >> N;
	int A[16];
	int X[16][16], Y[16][16];
	rep1(i, N) {
		cin >> A[i];
		rep(j, A[i]) {
			cin >> X[i][j] >> Y[i][j];
		}
	}

	int K = 1 << N;
	int saidai = 0;
	rep(i, K) {
		bool OK = 1;
		rep(j, N) {
			if (i >> j & 1) {
				rep(k, A[j + 1]) {
					if ((i >> (X[j + 1][k] - 1) & 1) != Y[j + 1][k]) OK = 0;
				}
			}
		}
		if (OK) {
			chmax(saidai, __builtin_popcount(i));
		}
	}
	co(saidai);

	Would you please return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long x = sc.nextLong();
        long dist = 0;
        for (int i = 1; i <= x; i++) {
            dist += i;
            if (dist >= x) {
                System.out.println(i);
                return;
            }
        }
    }
}


Measured memory_bytes: 22612
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define SPEED ios_base::sync_with_stdio(false); cin.tie(NULL);
#define FOR(i, a, b) for (ll i = a; i < b; ++i)
#define RFOR(i, b, a) for (ll i = b; i >= a; --i)
#define ALL(x) x.begin(), x.end()
#define DEBUG(args...) { string _s = #args; replace(ALL(_s), ' ', '\0');\
replace(ALL(_s), ',', ' ');\
stringstream _ss(_s); istream_iterator<string> _it(_ss); _debug(_it, args);}
#define endl "\n"
#define F first
#define S second
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)

using namespace std;
using namespace __gnu_pbds;

template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

void _debug(istream_iterator<string>) {}
template<typename T, typename... Args>
void _debug(istream_iterator<string> it, T first, Args... args) {
    cerr << ">> " << *it << " : " << first << endl; _debug(++it, args...);
}
template <typename T1, typename T2>
inline ostream& operator << (ostream& out, const pair<T1, T2>& p) {
    return out << "(" << p.F << ", " << p.S << ")";
}
template<typename T>
inline ostream& operator << (ostream& out, const vector<T>& v) {
    if (v.empty()) return out << "[]";
    else { out << '['; for (auto& e : v) { out << e << ", "; } return out << "\b\b]"; }
}
template<typename T>
inline ostream& operator << (ostream& out, const set<T>& s) {
    if (s.empty()) return out << "{}";
    else { out << '{'; for (auto& e : s) { out << e << ", "; } return out << "\b\b}"; }
}
template<typename T>
inline ostream& operator << (ostream& out, const unordered_set<T>& s) {
    return out << set<T>(ALL(s));
}
template<typename T1, typename T2>
inline ostream& operator << (ostream& out, const map<T1, T2>& m) {
    if (m.empty()) return out << "{}";
    out << '{'; for (auto& p : m) { out << p << ", "; } return out << "\b\b}";
}
template<typename T1, typename T2>
inline ostream& operator << (ostream& out, const unordered_map<T1, T2>& m) {
    return out << map<T1, T2>(ALL(m));
}
template<typename T>
inline ostream& operator << (ostream& out, const ordered_set<T>& s) {
    return out << set<T>(ALL(s));
}

typedef long long ll;
typedef long double ld;
typedef vector<long long> vll;
typedef pair<ll, ll> pll;
typedef vector<pair<ll, ll>> vpll;
typedef unordered_map<ll, ll> STll;
/************************************** MAIN PROGRAM ********************************************/

int main()
{
    //freopen("input.txt", "r", stdin);
    SPEED
    string s, t;
    cin >> s >> t;
    int a, b;
    cin >> a >> b;
    string u;
    cin >> u;
    if (u == s) a--;
    else if (u == t) b--;
    cout << a << ' ' << b;
}
/************************************** END OF PROGRAM ******************************************/
/** Stuff you should look for:
 * int overflow, array bounds, over-counting, graph is not a tree/connected
 * special cases (n=1?), set/unordered_set TLE, multi-set/set error
 * do something instead of nothing and stay organized
 */


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <climits>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    vector<pair<int, int>> cd;
    FOR(i, 1, m) {
        if(i > m / i) break;
        if(m % i == 0) cd.push_back(make_pair(i, m / i));
    }
    
    int cd_size = cd.size();
    FORR(i, cd_size - 1, 0)
        cd.push_back(make_pair(cd[i].second, cd[i].first));

    auto it = upper_bound(ALL(cd), make_pair(n, 0));
    cout << it->second << endl;
    return 0;
}


Measured memory_bytes: 256
#include "iostream"
#include "algorithm"
#include "string"
#include "vector"
#include "cmath"
using namespace std;
int main() {
	string s1("CODEFESTIVAL2016");
	string s2;
	int cnt = 0;
	cin >> s2;
	for (int i = 0; i < 16; i++) {
		if (s1[i] != s2[i])cnt++;
	}
	cout << cnt << endl;
}

Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
const int maxn = 200000 + 10;
const int N = 1000000 + 10;
const int MOD = 998244353;

inline int inc(int a, int b) { return (a + b >= MOD) ? (a + b - MOD) : (a + b); }
inline int dec(int a, int b) { return (a >= b) ? (a - b) : (a + MOD - b); }
inline int mul(int a, int b) { return 1LL * a * b % MOD; }

inline int power(int x, int k) {
	int tmp = 1;
	while(k) {
		if(k & 1) tmp = mul(tmp,x);
		x = mul(x,x);
		k >>= 1;
	}
	return tmp;
}

int n, a[maxn], Mx, p[maxn], pcnt, f[N], inv[N], fp[N], num[N], val[N], Val[N];
int mu[N];
bool isp[N];

inline void prepare(int n) {
	inv[0] = 0; inv[1] = 1;
	for(int i = 2;i <= n;i ++) inv[i] = mul(dec(MOD,MOD / i),inv[MOD % i]);
	isp[0] = isp[1] = 1;
	f[0] = 0; f[1] = 1;
	mu[1] = 1;
	for(int i = 2;i <= n;i ++) {
		if(!isp[i]) {
			p[++ pcnt] = i;
			fp[i] = i; num[i] = 1;
			f[i] = mul(dec(1,i),inv[i]);
			mu[i] = dec(MOD,1);
		}
		for(int j = 1;j <= pcnt && i * p[j] <= n;j ++) {
			isp[i * p[j]] = 1;
			if(i % p[j] == 0) {
				mu[i * p[j]] = 0;
				fp[i * p[j]] = fp[i] * p[j];
				num[i * p[j]] = num[i] + 1;
				f[i * p[j]] = mul(f[i / fp[i]],mul(dec(1,p[j]),power(power(p[j],num[i] + 1),MOD - 2)));
				break;
			}
			mu[i * p[j]] = dec(MOD,mu[i]);
			fp[i * p[j]] = p[j];
			num[i * p[j]] = 1;
			f[i * p[j]] = mul(f[i],f[p[j]]);
		}
	}
}

inline void debug() {
	for(int T = 1;T <= Mx;T ++) {
		int real = 0;
		for(int d = 1;d <= T;d ++) {
			if(T % d != 0) continue;
			real = inc(real,mul(mu[T / d],inv[d]));
		}
		cout << T << endl;
	  cout << "real " << real << " f " << f[T] << endl;
	}
}

int main() {
  scanf("%d", &n); Mx = 0;
	for(int i = 1;i <= n;i ++) scanf("%d", &a[i]), Mx = max(Mx,a[i]);
	prepare(Mx);
	for(int i = 1;i <= n;i ++) Val[a[i]] = inc(Val[a[i]],a[i]);
	for(int i = 1;i <= Mx;i ++) {
		val[i] = 0;
		for(int j = i;j <= Mx;j += i) val[i] = inc(val[i],Val[j]);
	}
	//debug();
	int Ans = 0;
	for(int i = 1;i <= Mx;i ++) {
//		cout << i << ' ' << val[i] << ' ' << f[i] << endl;
    int now = mul(mul(val[i],val[i]),f[i]);
		Ans = inc(Ans,now);
	}
	for(int i = 1;i <= n;i ++) Ans = dec(Ans,a[i]);
	Ans = mul(Ans,power(2,MOD - 2));
	printf("%d\n", Ans);
	return 0;
}


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

int32_t main() {
	ios::sync_with_stdio(0);cin.tie(0);
	int p, x = 100;
	cin >> p;
	for(int i=1;; i++) {
		x += (int)(0.01*x);
		if(x >= p)
			return !(cout << i);
	}
}

Measured memory_bytes: 3652
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

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



int main() {
    ll n, x;
    cin >> n >> x;
    
    if(x == 1 || x == 2 * n - 1){
        cout << "No" << endl;
        return 0;
    }
    
    vector<ll> ans(2 * n - 1);
    if(n == 2){
        ans[0] = 1;
        ans[1] = 2;
        ans[2] = 3;
    }
    else if(x == 2){
        ans[n - 1] = x;
        ans[n] = x - 1;
        ans[n - 2] = x + 1;
        ans[n + 1] = x + 2;
        
        ll t = 1;
        REP(i, n - 2){
            if(t == x - 1){
                t = x + 3;
            }
            ans[i] = t++;
        }
        for(ll i = n + 2; i < 2 * n - 1; i++){
            if(t == x - 1){
                t = x + 3;
            }
            ans[i] = t++;
        }
    }
    else{
        ans[n - 1] = x;
        ans[n] = x + 1;
        ans[n - 2] = x - 1;
        ans[n + 1] = x - 2;
        
        ll t = 1;
        REP(i, n - 2){
            if(t == x - 2){
                t = x + 2;
            }
            ans[i] = t++;
        }
        for(ll i = n + 2; i < 2 * n - 1; i++){
            if(t == x - 2){
                t = x + 2;
            }
            ans[i] = t++;
        }
    }
    
    cout << "Yes" << endl;
    REP(i, 2 * n - 1){
        cout << ans[i] << '\n';
    }
}

Measured memory_bytes: 3072
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;
vector<int> v;
int wa(int n){
  if(n<0) return -n;
  else return n;
}
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long a=0,b,c,d=0,e=0,f=0,g=0,i;
  string s;
  cin >>a;
  for(int n=0;n<a*3;n++){
    cin >>b;
    v.push_back(b);
  }
  sort(v.begin(),v.end(),greater<int>());
  for(int n=1;n<a*2;n+=2){
    d+=v[n];
  }
  cout <<d<<'\n';
  return (0);
}


Measured memory_bytes: 2420
N, P = map(int,input().split())
A = list(map(int,input().split()))
odd = 0
eve = 0
for a in A:
  if a%2 == 0: eve += 1
  else: odd += 1

if odd == 0:
  if P: ans = 0
  else: ans = 2**N
else:
  ans = 2**(N-1)
print(ans)

Measured memory_bytes: 38384
#include<iostream>
#include<stack>
#include <algorithm>
#include <cstdio>

using namespace std;

int main(){
    int n;
    int ans[100005];
    cin>>n;
    for (int i = 1;i<=n;i++){
        cin>>ans[i];
    }
    int l = 0;
    int k = 1;
    while(ans[k]!=2&&l<=n+1){
        k = ans[k];
        l++;
    }
    if (l == n+2){
        cout<<-1<<endl;
    }
    else{
        cout<<l+1<<endl;
    }
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
/************************************************/
#define rep(i,n) for(int i=0;i<n;i++)
#define m_p make_pair
#define pb push_back
#define fr first
#define se second
#define forn(i,a,n) for(int i=a;i<n;i++)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define sz(s) s.size()
#define all(s) s.begin(),s.end()
#define zero(x) memset(x,0,sizeof(x))
#define vii vector<pair<int,int> >
#define mpis map<int,string>
#define mpii map<int,int>
#define mpsi map<string,int>
#define re return
#define mod 1000000007
/************************************************/
using namespace std;

long long get(){
	char c=getchar();
	long long x=0LL;
	while(c<'0'||c>'9')
	c=getchar();
	while(c>='0'&&c<='9'){
		x*=10LL;
		x+=(c-'0');
		c=getchar();
	}
	return x;
}
string s;
bool f[26];
int main(){
	ios::sync_with_stdio(0);
	cin>>s;
	rep(i,3)
	f[s[i]-'A']=true;
	if(f[0]&&f[1])
	cout<<"Yes\n";
	else
	cout<<"No\n";
	re 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<sstream>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<complex>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cassert>

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf = (int)1e9;
const double INF = 1e12, EPS = 1e-9;

int n, u, v, m;
int a[500][500], b[500][500], pa[1000001], pb[1000001];
int ra[500], ca[500], da[2], rb[500], cb[500], db[2];

int ck(int num, int a[500][500], int *p, int *r, int *c, int *d){
	if(p[num] < 0) return 0;
	int y = p[num] / n, x = p[num] % n, res = 0;
	if(a[y][x] < 0) return 0;
	if(n == 1) return 1;
	
	a[y][x] = -1;
	if(y == x) if(++d[0] == n) res++;
	if(y == n - x - 1) if(++d[1] == n) res++;
	if(++r[y] == n) res++;
	if(++c[x] == n) res++;
	return res;
}

int main(){
	scanf("%d%d%d%d", &n, &u, &v, &m);
	memset(pa, -1, sizeof(pa));
	memset(pb, -1, sizeof(pb));
	rep(i, n) rep(j, n) scanf("%d", a[i] + j), pa[a[i][j]] = i * n + j;
	rep(i, n) rep(j, n) scanf("%d", b[i] + j), pb[b[i][j]] = i * n + j;
	
	int aa = 0, bb = 0;
	
	rep(i, m){
		int t;
		scanf("%d", &t);
		aa += ck(t, a, pa, ra, ca, da);
		bb += ck(t, b, pb, rb, cb, db);
		if(aa >= u && bb < v){
			cout << "USAGI" << endl;
			return 0;
		}
		if(aa < u && bb >= v){
			cout << "NEKO" << endl;
			return 0;
		}
	}
	cout << "DRAW" << endl;
	
	return 0;
}

Measured memory_bytes: 10520
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <cfloat>

using std::cerr;
using std::cin;
using std::cout;
using std::endl;

using namespace std;
typedef int64_t int64;

int main(){
  cout << std::fixed << std::setprecision(16);
  cin.tie(nullptr);
  std::ios::sync_with_stdio(false);

  int n;
  cin>>n;
  vector<int64> a(n);
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  if(a[0]!=0){
    cout<<-1<<endl;
    return 0;
  }
  int64 result=0;
  for(int i=1;i<n;i++){
    if(a[i]-a[i-1]>=2){
      cout<<-1<<endl;
      return 0;
    }else if(a[i]-a[i-1]==1){
      result++;
    }else{
      result+=a[i];
    }
  }
  cout<<result<<endl;



  return 0;
}

Measured memory_bytes: 1920
#include <iostream>

using namespace std;

int main(){
  int n;cin>>n;
  long long num1=2, num2=1, ans=1;
  for(int i=0;i<n-1;i++){
    ans = num1 + num2;
    num1 = num2;
    num2 = ans;
  }
  cout<<ans<<endl;
}

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

int main()
{
    int n;
    string s;
    while(cin>>n>>s)
    {
        if(s.size()>n)
        {
            for(int i=0; i<n; i++)cout<<s[i];
            cout<<"...";
        }
        else cout<<s;
        cout<<endl;
    }
}


Measured memory_bytes: 3632
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<n;++i)
#define rep1(i,n) for(ll i=1;i<=n;++i)
int main(){
  int m1,d1,m2,d2;
  cin>>m1>>d1;
  cin>>m2>>d2;
  int ans=0;
  if(m1+1==m2&&d2==1){
    if(d1==30){
      if(m1==4||m1==6)ans=1;
      if(m1==9||m1==11)ans=1;
    }
    if(d1==28&&m1==2)ans=1;
    if(d1==31){
      if(m1==1||m1==3)ans=1;
      if(m1==5||m1==7)ans=1;
      if(m1==8||m1==10)ans=1;
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
//競技プログラミング用のテンプレート
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <math.h>
#include <stack>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define repr(i, n) for(int i = n - 1; i >= 0; i--)

using namespace std;
using ll = long long int;
using p = pair<int, int>;
using pl = pair<ll, ll>;
using v = vector<int>;
using vd = vector<double>;
using vs = vector<string>;
using vl = vector<ll>;

int n;
ll a[2 * 100000];
ll dp[2 * 100000 + 1];

int main()
{
  cin >> n;
  rep(i, n) {
    cin >> a[i];
  }
  map<ll, ll> m;
  for(ll i = 1; i <= n; i++) {
    ll want = i - a[i - 1];
    m[i + a[i - 1]]++;
    dp[i] = m.count(want) == 0 ? dp[i - 1] : dp[i - 1] + m[want];
  }
  cout << dp[n] << endl;
}


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

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

int main() {
    int N,a,c;
    cin >> N;

    rep(i,N) {
        cin >> a;
        while(!(a%2)) {
            a /= 2;
            c++;
        }
    }

    cout << c << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <queue>
#include <vector>

#define testin freopen("1.txt","r",stdin);
#define testout freopen("out.txt","w",stdout);
#define ll long long

using namespace std;

int main(){
    int k,x;
    cin>>k>>x;
    for(int i=x-k+1;i<x+k;i++){
        cout<<i<<" ";
    }
    cout<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip> // fixed, setprecision 
#include <math.h> // double sqrt
#define rep(i,n) for(int i=0;i<(n);++i)
#define ll long long
using namespace std;
int main(){
    int a;
    cin>>a;
    cout<<a+pow(a,2)+pow(a,3);
    return 0;
}

Measured memory_bytes: 3616
import java.util.*;
public class Main {
   public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);

      int k = sc.nextInt();
      int x = sc.nextInt();

      if (500*k>=x) {
         System.out.println("Yes");
      }
      else {
         System.out.println("No");
      }
   }
}

Measured memory_bytes: 23764
#include <iostream>
#include <vector>

using namespace std;

int main()
{
    int n ;
    int x ;
    cin >> n >> x;
    vector<int> l(n);

    for (int i = 0; i < n; i++)
    {
        cin >> l[i];
    }
    int d=0;
    int i=0;
    for(i = 0; i < n; i++)
    {
        d=d+l[i];
        if (d>x) {
            break;
        }
        
    }
    cout << i+1;
    
}

Measured memory_bytes: 256
import java.util.*

fun main(args:Array<String>){
    val n = readLine()!!.toInt()
    val h = readLine()!!.split(" ").map{it.toInt()}
    var ans = 1
    var k = h[0]
    for(i in 1 until n){
        if(h[i] >= k){
            ans++
            k = h[i]
        }
    }
    println(ans)
}


Measured memory_bytes: 37744
#include <iostream>

using namespace std;
constexpr int64_t MOD = 1'000'000'007;
constexpr int     MAX =       1'000'005;

int64_t fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
int64_t COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(void) {
    int X, Y;
    cin >> X >> Y;
    COMinit();

    if((-X+2*Y)%3 != 0 || (2*X-Y)%3 != 0) {
        cout << 0 << endl;
    } else {
        int p = (-X+2*Y) / 3;
        int q = (2*X-Y) / 3;
        cout << COM(p+q, p) << endl;
    }
    return 0;
}


Measured memory_bytes: 23680
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
#define all(x) (x).begin(), (x).end()
#define fsp(x) cout << fixed << setprecision(x)
const ll inf = LLONG_MAX;
const long double pi = acos(-1);
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

//モジュラ逆数
long long modinv(long long n, long long p) {
	long long a = p, u = 1, v = 0;
	while (a) {
		long long t = n / a;
		n -= t * a;
		std::swap(n, a);
		u -= t * v;
		std::swap(u, v);
	}
	u %= p;
	if (u < 0) u += p;
	return u;
}

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

	ll n, k, p = 1e9 + 7;
	cin >> n >> k;

	//0人部屋の数をmとする
	//C(n, m) -------- 0人部屋の選び方
	//C((n - m) + (m - 1), n - m - 1) -------- 0人部屋からの移動先の選び方

	ll ans = 0, a = 1, b = 1;
	ans += a * b;
	for (ll i = 1; i < min(n, k + 1); i++) {
		a *= n + 1 - i;
		a %= p;
		a *= modinv(i, p);
		a %= p;
		b *= n - i;
		b %= p;
		b *= modinv(i, p);
		b %= p;
		ans += a * b % p;
		ans %= p;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
map<string, int> dic;
void insert(string str) {
	dic[str]++;
}
bool find(string str) {
	if (dic[str]!=0) {
		return true;
	}
	return false;
}


int main() {
	int n;
	string tmp1, tmp2;
	vector<string> ans;

	cin >> n;
	for (int i=0; i < n; i++) {
		cin >> tmp1;
		cin >> tmp2;
		
		if (tmp1 == "insert") {
			insert(tmp2);
		}
		else {
			if (find(tmp2)) {
				ans.push_back("yes");
			}
			else {
				ans.push_back("no");
			}
		}
		
	}
	for (int i = 0; i < ans.size();i++) {
		cout << ans[i]<<endl;
		
	}
	
	
	return 0;
}



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

Measured memory_bytes: 4784
#include<bits/stdc++.h>
using namespace std;
const double pi=3.14159265358979323846;
int main()
{
	double a,b,h,m,anm,anh,ans;
	cin>>a>>b>>h>>m;
	anm=360*m/60;
	anh=360*h/12;
	ans=anm-anh-anm/12;
	if(ans<0)
		ans+=360;
	cout<<fixed<<setprecision(10)<<sqrt(a*a+b*b-2*a*b*cos(ans/180*pi));
	return 0;
}

Measured memory_bytes: 4216
(function main() {
  const lines = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n');
  const n = Number(lines.shift());
  const res = Array.from(Array(n), () => Array.from(Array(n), () => 0));

  lines.forEach((l, i) => l.split(' ').splice(2).forEach(e => res[i][e-1] = 1));
  console.log(res.map(r => r.join(' ')).join('\n'));
})();



Measured memory_bytes: 17116
# AtCoder Beginner Contest 133
# C - Remainder Minimization 2019
L,R=map(int,input().split())

mod=2019
ans=10**18+7


for i in range (L,min(R,L+mod)):
    for j in range (L+1,min(R+1,L+mod+1)):
        tempans=(i%mod)*(j%mod)
        tempans%=mod
        # print(i,j,tempans)
        if tempans<ans:
            ans=tempans
print(ans)

Measured memory_bytes: 9180
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <cstdint>
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <bitset>

using namespace std;

using ll =  long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;

constexpr ll MOD = 1000000007;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

int main() {
    std::ios::sync_with_stdio(0); cin.tie(0);
    int n, k;
    cin >> n >> k;

    vector<Pii> edges;

    for(int v=2;v<=n;++v) {
        edges.emplace_back(1, v);
    }
    int cnt = (n-1) * (n-2) / 2;
    if(cnt > k) {
        for(int u=2;u<=n-1;++u) {
            for(int v=u+1;v<=n;++v) {
                edges.emplace_back(u, v);
                --cnt;
                if(cnt == k) {
                    u = n;
                    v = n+1;
                }
            }
        }
    }

    if(cnt != k) {
        cout << -1 << endl;
        return 0;
    }

    cout << int(edges.size()) << endl;
    for(Pii e: edges) {
        cout << e.first << " " << e.second << endl;
    }
}


Measured memory_bytes: 384
# -*- coding: utf-8 -*-
import copy
import math

# 整数の入力
n = int(input())

capa = []

capa=[int(input()) for i in range(5)]

# 各交通機関のうち、運べる人数が一番少ないものをベースとする
capa_min = min(capa)

ans = n//capa_min 

# if n <= capa_min:
#     amari = 0
# else:
amari = n % capa_min

# 人数が割り切れたら
if amari != 0:
    ans += 5
else:
    ans += 4
    
print (str(ans))



# 以下の処理だとタイムオーバーになるからNG
# toshi = [n,0,0,0,0,0]
# next_toshi = copy.deepcopy(toshi)
# time = 0

# while toshi[5] != n:
#     # print("toshi[0]:{},[1]:{},[2]:{},[3]:{},[4]:{},[5]:{}".format(toshi[0],toshi[1],toshi[2],toshi[3],toshi[4],toshi[5]))
#     time += 1
#     for i in range(len(toshi)-1):
#         if toshi[i] != 0:
#             if toshi[i] > capa[i]:
#                 next_toshi[i] = next_toshi[i] - capa[i]
#                 next_toshi[i+1] = toshi[i+1]  + capa[i]
#             else:
#                 next_toshi[i] = next_toshi[i] - toshi[i]
#                 next_toshi[i+1] = toshi[i+1] + toshi[i] 
#         # print("toshi[{}]:{},toshi[{}]:{}".format(i,next_toshi[i],i+1,next_toshi[i+1]))
#     toshi = copy.deepcopy(next_toshi)
#     # print("next_toshi[0]:{},[1]:{},[2]:{},[3]:{},[4]:{},[5]:{}".format(next_toshi[0],next_toshi[1],next_toshi[2],next_toshi[3],next_toshi[4],next_toshi[5]))
        
# print(str(time))


Measured memory_bytes: 3444
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000000LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
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; }

struct route{
    int pos; //現在地
    vector<bool> seen; //訪問済みフラグ
    set<int> passed;  //通過済みのノード

    route(int n, vector<bool> b, set<int> st){
        pos = n; 
        seen = b;
        passed = st;
    }
};

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> G[n];
    rep(i, m){
        int a, b; cin >> a >> b; a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    queue<route> que;
    vector<bool> vc(n); set<int> st;
    fill(all(vc), false);
    vc[0] = true; st.insert(0); //始点を訪問済みにする
    route r(0, vc, st);
    que.push(r);

    int cnt = 0;
    while(!que.empty()){
        route r = que.front(); que.pop();
        int p = r.pos;
        
        bool next = false; //移動可能な地点の有無を調べる
        rep(i, G[p].size()){
            int to = G[p][i];
            if(r.seen[to]) continue; //既に訪問済みならスルー
            route nr(to, r.seen, r.passed);
            //訪問済みフラグを立てる
            nr.seen[to] = true; nr.passed.insert(to);
            que.push(nr);
            next = true;
        }
        //移動可能な地点がもうない場合、全ての地点を通ってきたか調べる
        if(!next){
            if(r.passed.size() == n) cnt++;
        }
    }

    cout << cnt << ln;
}
    

Measured memory_bytes: 2816
N,M=map(int,input().split())
G=[[] for _ in range(N+1)]
for i in range(M):
  a,b=map(int,input().split())
  G[a].append(b)
  G[b].append(a)

ans=[0]*(N+1)
d=[1]
while d:
  c=d.pop(0)
  for g in G[c]:
    if not ans[g]:
      d.append(g)
      ans[g]=c

print('Yes')
for i in range(2, N+1):
  print(ans[i])

Measured memory_bytes: 33580
#include<iostream>

using namespace std;

int main(){
	int W, H, x, y, r;

	cin >> W >> H >> x >> y >> r;

	if (x - r >= 0 && y - r >= 0 && x + r <= W && y + r <= H) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

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

int main() {
	int a[100],n;
	cin >> n;
	
	for (int i = 0; i < n; i++){
		cin >> a[i];
	}
	
	for (int i = n-1; i >= 0; i--){
		cout << a[i];
		if (i != 0){
			cout << " ";
		} else {
			cout << endl;
		}
	}
	
	return 0;
}


Measured memory_bytes: 3096
import java.util.*;

class Main {

    public static void main(String[] args) {

        Scanner cin = new Scanner(System.in);

        int n = cin.nextInt();

        for(int i = 1; i <= 9; i++) {
            for(int j = 1; j <= 9; j++) {
                if(i*j == n) {
                    System.out.println("Yes");
                    return;
                }
            }
        }
        
        System.out.println("No");
    }

}

Measured memory_bytes: 23764
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>
#define int long long int
#define mod(x) ((x % MOD) + MOD) % MOD
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);--i)

#define ALL(a) (a).begin(),(a).end()
#define SIZE(a) (int)((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

using namespace std;

typedef pair<int,int> P;
struct edge {
  int to, cost;
};

const int INF = 1e18;
const int MOD = 1e9+7;

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


signed main()
{
  int N, K; cin >> N >> K;
  vector<int> num(N);
  rep(i, 0, N) {
    int a; cin >> a;
    num[a-1]++;
  }

  SORT(num);

  int ans = 0;
  rep(i, 0, N - K) {
    ans += num[i];
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1792
#include<stdio.h>
int abs(int a)
{
	if (a < 0)
		a *= -1;
	return a;
}
int main()
{
	int n;
	scanf("%d", &n);
	int i;
	int w[102];
	for (i = 0; i < n; i++)
		scanf("%d", &w[i]);
	int s1, s2;
	int min = 1000;
	int j;
	for (i = 0; i < n - 1; i++)
	{
		s1 = s2 = 0;
		for (j = 0; j <= i; j++)
			s1 += w[j];
		for (j = i + 1; j < n; j++)
			s2 += w[j];
		if (min > abs(s1 - s2))
			min = abs(s1 - s2);
	}
	printf("%d\n", min);
	return 0;
}

Measured memory_bytes: 128