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

using namespace std;

#define FOR(i, j, k, in) for (int i=j ; i<k ; i+=in)
#define RFOR(i, j, k, in) for (int i=j ; i>=k ; i-=in)
#define REP(i, j) FOR(i, 0, j, 1)
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define MP make_pair
#define PB push_back
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
const double pi=acos(-1.0);
typedef pair<int, int> PII;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int  uint64;


#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long

#define int long long
tuple<int, int> dp[400][400];
int ar[400];
signed main()
{
	IOS
		int n;
	cin >> n;
	REP(i, n)
		cin >> ar[i];

	REP(i, n)
	{
		FOR(j, 0, n-i, 1)
		{
			dp[j][j+i] = make_tuple(0, LONG_LONG_MAX);
			if (i == 0)    dp[j][j] = make_tuple(ar[j], 0);
			else
			{
				FOR(l, j, j+i, 1)
				{

					if (get<1>(dp[j][i + j]) > get<1>(dp[j][l]) + get<1>(dp[l + 1][i + j]) + get<0>(dp[j][l]) + get<0>(dp[l + 1][j + i]))
						dp[j][i + j] = make_tuple(get<0>(dp[j][l]) + get<0>(dp[l + 1][j + i]), get<1>(dp[j][l]) + get<1>(dp[l + 1][i + j]) + get<0>(dp[j][l]) + get<0>(dp[l + 1][j + i]));
				}
			}

		}
	}
	cout << get<1>(dp[0][n - 1]) << "\n";
	//cout << getct(0, n - 1);

}

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

const string yes="Yes";
const string no = "No";
map<int,int> cnt;
set<int> has;
int num[3];
int main()
{
    int N;
    ios::sync_with_stdio(false);
    cin>>N;
    int a;
    for(int i=0;i<N;++i)
    {
        cin>>a;
        has.insert(a);
        if(cnt.count(a)==0) cnt[a]=0;
        cnt[a]++;
    }
    if(has.size()==1){
        if(*has.begin()==0)
            cout<<yes<<endl;
        else cout<<no<<endl;
        return 0;
    }
    if(N%3!=0)
    {
        cout<<no<<endl;
        return 0;
    }
    if(has.size()>3)
    {
        cout<<no<<endl;
        return 0;
    }
    if(has.size()==3)
    {
        int dd=0;
        for(auto x:has)
            num[dd++]=x;
        int A,B,C;
        A=num[0];   B=num[1];   C=num[2];
        if(cnt[A]!=cnt[B]||cnt[B]!=cnt[C])
        {
            cout<<no<<endl;
            return 0;
        }
        if((A^B)!=C)
        {
            cout<<no<<endl;
            return 0;
        }
        cout<<yes<<endl;
        return 0;
    }
    if(has.size()==2)
    {
        int A,B;
        A=*has.begin();
        B=*has.rbegin();
        if(A>B) swap(A,B);
        if(A!=0||cnt[A]*2!=cnt[B])
        {
            cout<<no<<endl;
        }else cout<<yes<<endl;
        return 0;
    }
    return 0;
}

Measured memory_bytes: 7552
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // int64_t

#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) > (b) ? (b) : (a))

int get_int2(int *a1, int *a2) {
  scanf("%d %d", a1, a2);
  return 0;
}

int main(void) {
    int num, m;
    get_int2(&num, &m);
    int ans = m * 1900 + (num-m)*100;

    // cnt
    while(m) {
        ans *= 2;
        m -= 1;
    }
    printf("%d\n", ans);
    return 0;
}

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

//#define int long long
#define reps(i,s,n) for(ll (i)=(s);(i)<(ll)(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) reps(i,0,((n)+1))
#define repst(i,s,n) reps(i,s,((n)+1))
#define reprt(i,n,t) for(ll (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(itr,v) for(auto (itr):(v))
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp(x,y) make_pair((x),(y))
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define dbg(x) cout<<#x" = "<<(x)<<ln
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ');}}

typedef long double ld;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<ld> vld;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

int h, w, a, b;
ll f[200200], fr[200200], r;

ll mpow(ll x, ll n, ll m) {
	ll res = 1;
	while (n>0) {
		if (n&1) res = res * x %m;
		x = x * x %m;
		n >>= 1;
	}
	return res;
}

ll comb(ll n, ll r) {
	return f[n]*fr[r] %mod *fr[n-r] %mod;
}

signed main() {
	cin >> h >> w >> a >> b;
	h--, w--;
	// テーブル
	f[0] = f[1] = 1;
	repst(i,2,200100) f[i] = f[i-1]*i %mod;
	fr[200100] = mpow(f[200100],mod-2,mod);
	repr(i,200100-1) fr[i] = fr[i+1]*(i+1) %mod;
	// 組み合わせ
	repst(wa,b,w) {
		ll ha = h-a, hb = a-1, wb = w-wa;
		(r += comb(ha+wa,ha)*comb(hb+wb,hb)) %= mod;
	}
	cout << r << ln;
}

Measured memory_bytes: 3328
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{

int n,ans=1;
cin>>n;
int a[111];
for(int i=0;i<n;i++) 
    cin>>a[i];
    
sort(a,a+n);
for(int i=1;i<n;i++) 
    if(a[i]!=a[i-1]) ans++;
cout<<ans;

system("pause");
return 0;
}


Measured memory_bytes: 504
s=input()
k=int(input())
if len(s)==1:
  print(k//2)
  exit()
c=1
ans=0
for i in range(1,len(s)):
  if s[i-1]==s[i]:
    c+=1
  else:
    ans+=c//2
    c=1
ans+=c//2
ans*=k
cl=0
i=0
while  i<len(s) and s[-1]==s[i]:
  cl+=1
  i+=1
if i<len(s) and cl%2==1 and c%2==1:
  ans+=k-1
elif cl%2==1 and c%2==1:
  ans+=k//2
print(ans)

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> ii;
typedef tuple<int, int, int> iii;

typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ld> vd;
typedef vector<ll> vl;

typedef set<int> si;
typedef set<ii> sii;
typedef set<ld> sd;
typedef set<ll> sl;

typedef map<int, int> mii;
typedef priority_queue<int> pqi;
typedef queue<int> qi;
 
#define mp make_pair
#define pb push_back
#define f first
#define s second

mt19937 rng((int) std::chrono::steady_clock::now().time_since_epoch().count());

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  
  int n, m, c;
  cin >> n >> m >> c;
  vi b(m); for (auto &x : b) cin >> x;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    vi d(m); for (auto &x : d) cin >> x;
    int res = c;
    for (int j = 0; j < m; j++) res += b[j] * d[j];
    if (res > 0) ans++;
  }
  cout << ans << endl;
}

/*
USE LONG LONG!!!!

:pray: :fishy15:
:pray: :summitosity:
:pray: :prodakcin:

          .=     ,        =.
  _  _   /'/    )\,/,/(_   \ \
   `//-.|  (  ,\\)\//\)\/_  ) |
   //___\   `\\\/\\/\/\\///'  /
,-"~`-._ `"--'_   `"""`  _ \`'"~-,_
\       `-.  '_`.      .'_` \ ,-"~`/
 `.__.-'`/   (-\        /-) |-.__,'
   ||   |     \O)  /^\ (O/  | .        <-  BESSIE THE COW
   `\\  |         /   `\    /
     \\  \       /      `\ /
      `\\ `-.  /' .---.--.\
        `\\/`~(, '()      ('
         /(O) \\   _,.-.,_)    
        //  \\ `\'`      /
       / |  ||   `""""~"`
     /'  |__||
           `o
*/

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

using namespace std;

typedef long long int ll;

const ll inf = 1e18;

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

  int n;
  cin >> n;
  vector < ll > a(n);
  for(int i = 0; i < n; i++){
    cin >> a[i];
    if(a[i] == 0){
      cout << 0 << endl;
      return 0;
    }
  }
  ll res = 1;
  for(int i = 0; i < n; i++){
    if(a[i] > (long double)inf / (long double)res){
      cout << -1 << '\n';
      return 0;
    }
    res = res * a[i];
  }
  cout << res << '\n';
}


Measured memory_bytes: 3992
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
int mod = 1000000007;
#define ll long long
string s;
int tens[220000]={0};
int temp[220000]={0};

void pre() {
    tens[0]=1;
    rep(i,210000){
        tens[i+1]=(tens[i]*10)%2019;
    }
}

void solve() {
    temp[0]=s[s.size()-1]-'0';
    rep(i,s.size()-1) {
        temp[i+1] =(temp[i]+tens[i+1]*(s[s.size()-i-2]-'0'))%2019;
    }
}

int main() {
    int ans=0,divi[2020]={0};
    cin>>s;
    pre();
    solve();
    rep(i,s.size()){
        divi[temp[i]]++;
    }
    rep(i,2020){
        if(divi[i]>1)ans+=divi[i]*(divi[i]-1)/2;
    }
    cout << ans+divi[0] <<endl;
    return 0;
}

Measured memory_bytes: 5332
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <sstream>

#define rep(i, n) for(int i = 0; i < n; i ++)
#define COUNT(i, n) for(int i = 1; i <= n; i ++)
#define ALL(T) T.begin(), T.end()
#define mp make_pair
#define pb push_back
#define ITER(c) __typeof((c).begin())
#define each(c, it) for(ITER(c) it = (c).begin(); it != (c).end(); it++)
#define X first
#define Y second
#define OUT first
#define IN second

using namespace std;

typedef pair<int, int> pii;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<string> vs;

const int INF = 1 << 24;

int main(void){
    for(int n, res; cin >> n, n; cout << res << endl){
        res = 0;
        vector<pii> t(n);
        rep(i, n){
            string out, in; cin >> out >> in;
            rep(j, 2) out.erase(out.find(":"), 1);
            rep(j, 2) in.erase(in.find(":"), 1);
            stringstream is;
            is << in; is >> t[i].IN;
            is.clear();
            is << out; is >> t[i].OUT;
        }
        sort(ALL(t));

        int wait = 0;
        priority_queue<int, vi, greater<int> > q;
        rep(i, n){
            //if(!q.empty()) cout << "q.top() = " << q.top() << endl;
            while(!q.empty() && q.top() <= t[i].OUT)
                wait++, q.pop();

            if(!wait) res++;
            else wait--;
            
            q.push(t[i].IN);
        }
    }

    return 0;
}

Measured memory_bytes: 1376
#include <bits/stdc++.h>
#define cout16 cout << setprecision(16) 
#define rep(i,n) for(int i=0;i<n;i++ )
#define rep2(i,f,n) for(int i=f;i<n;i++ )
#define SORT(A) sort(A.begin(),A.end())
#define REV(A) reverse(A.begin(),A.end())
typedef long long int ll;
using vi = std::vector<int>;
using vvi = std::vector<std::vector<int>>;
using vll = std::vector<ll>;
using vvll = std::vector<std::vector<ll>>;
using P = std::pair<int,int>;
using vp = std::vector<P>;
using namespace std;
#define INF 1001001001
#define LL_INF 1001001001001001001
#define fi first
#define se second

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




Measured memory_bytes: 256
fun main(args: Array<String>) {
    val n = readInt()
    val a = readIntList()

    val ans = MutableList(n) { 0 }
    a.forEachIndexed { index, v ->
        ans[v - 1] = index + 1
    }
    println(ans.joinToString(" "))
}

// Tools
fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)

Measured memory_bytes: 59472
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

//Gap
public class Main{

	String trans(){
		StringBuilder sb = new StringBuilder();
		for(int i=0;i<4;i++)for(int j=0;j<8;j++){
			sb.append(a[i][j]==0?"00":a[i][j]);
		}
		return sb.toString();
	}
	
	int min, INF = 1<<29;
	int[][] a;
	int[] pos;
	String g = "1112131415161700212223242526270031323334353637004142434445464700";
//	Set<String> set;
	Map<String, Integer> ref;
	
	void dfs(int d){
		String r = trans();
		if(min<=d||ref.containsKey(r)&&ref.get(r)<=d)return;
		if(r.equals(g)){
			min = d;return;
		}
		ref.put(r, d);
//		set.add(r);
		for(int i=0;i<4;i++)for(int j=1;j<8;j++){
			if(a[i][j]!=0||a[i][j-1]==0||a[i][j-1]%10==7)continue;
			int x = a[i][j-1]+1;
			int p = pos[x];
//			dump();
			a[p/8][p%8] = 0; a[i][j] = x;
			pos[x] = i*8+j;
//			dump();
			dfs(d+1);
			a[p/8][p%8] = x; a[i][j] = 0;
			pos[x] = p;
//			dump();
		}
	}
	
	void run(){
		Scanner sc = new Scanner(System.in);
		int T = sc.nextInt();
		while(T--!=0){
			min = INF;
			a = new int[4][8];
			for(int i=0;i<4;i++)for(int j=1;j<8;j++){
				a[i][j]=sc.nextInt();
			}
			for(int i=0;i<4;i++)for(int j=1;j<8;j++){
				if(a[i][j]%10==1){
					int t = a[i][j]/10-1;
					a[t][0] = a[i][j];
					a[i][j] = 0;
				}
			}
			pos = new int[48];
			for(int i=0;i<4;i++)for(int j=0;j<8;j++){
				if(a[i][j]==0)continue;
				pos[a[i][j]] = i*8+j;
			}
			ref = new HashMap<String, Integer>();
//			set = new HashSet<String>();
			dfs(0);
			System.out.println(min==INF?-1:min);
		}
	}
	
	void dump(){
		System.out.println();
		for(int i=0;i<4;i++){
			for(int j=0;j<8;j++)System.out.printf("%2d ", a[i][j]);
			System.out.println();
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 30000
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000000000000
#define MOD 1000000007
typedef pair<int, int> P;

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int mod_pow(int n, int p, int m) {
	if (p == 0) return 1;
	if (p % 2 == 0) {
		int t = mod_pow(n, p / 2, m);
		return (t * t) % m;
	}
	return n * mod_pow(n, p - 1, m) % m;
}
int extGCD(int a, int b, int& x, int& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}
int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
int digit(int x) {
	int cnt = 0;
	while (x > 0) {
		cnt += x % 10;
		x /= 10;
	}
	return cnt;
}
int read() {
	int tmp;
	cin >> tmp;
	return tmp;
}
int xor128() {
	static int x = 123456789, y = 362436069, z = 521288629, w = 88675123;
	int t = (x xor (x << 11));
	x = y; y = z; z = w;
	return (w = (w xor (w >> 19)) xor (t xor (t >> 8)));
}

signed main() {


	int n;
	cin >> n;
	int a[205][205];
	rep(i, n) {
		rep(j, n) {
			char c;
			cin >> c;
			a[i][j] = c - '0';
		}
	}

	int ans = -1;
	rep(i, n) {
		int nowcnt = 0;
		int dat[205];
		rep(j, n) dat[j] = -2;
		dat[i] = nowcnt;
		while (1) {
			rep(j, n) {
				if (dat[j] == nowcnt) {
					rep(k, n) {
						if (a[j][k] && dat[k] != nowcnt && dat[k] != nowcnt - 1&&dat[k]!=nowcnt+1) {
							if (dat[k] != -2) {
								goto bou;
							}
							dat[k] = nowcnt + 1;
						}
					}
				}
			}
			rep(j, n) {
				rep(k, n) {
					if (dat[j] == dat[k] && dat[j] != -2 && a[j][k]) {
						goto bou;
					}
				}
			}
			nowcnt++;
			bool finish = true;
			rep(j, n) {
				if (dat[j] == -2) {
					finish = false;
					break;
				}
			}
			if (finish) break;
		}
		ans = max(ans, nowcnt + 1);
	bou:;
	}
	printf("%d\n", ans);

	return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cassert>
#define ll long long
using namespace std;
inline ll read(){
    ll re=0,flag=1;char ch=getchar();
    while(ch>'9'||ch<'0'){
        if(ch=='-') flag=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9') re=(re<<1)+(re<<3)+ch-'0',ch=getchar();
    return re*flag;
}
ll n,K,cnt,a[200010],b[200010],tmp[500010],seg[500010],L[200010],R[200010],dp[200010],sum[200010];
void push(ll num){
    if(!seg[num]) return;
    seg[num<<1]=seg[num<<1|1]=seg[num];
    seg[num]=0;
}
void change(ll l,ll r,ll ql,ll qr,ll num,ll val){
    if(ql>qr) return;
    if(l>=ql&&r<=qr){seg[num]=val;return;}
    push(num);
    ll mid=(l+r)>>1;
    if(mid>=ql) change(l,mid,ql,qr,num<<1,val);
    if(mid<qr) change(mid+1,r,ql,qr,num<<1|1,val);
}
ll query(ll l,ll r,ll num,ll pos){
    if(l==r) return seg[num];
    push(num);
    ll mid=(l+r)>>1;
    if(mid>=pos) return query(l,mid,num<<1,pos);
    else return query(mid+1,r,num<<1|1,pos);
}
ll ask(ll pos){
    ll choose=query(1,cnt,1,pos);
    if(!choose) return 0;
    return (dp[choose]+(tmp[L[choose]]-tmp[pos]+K)%K);
}
ll erfen(ll val){
    ll l=1,r=cnt,mid;
    while(l<r){
        mid=(l+r)>>1;
        if(tmp[mid]>=val) r=mid;
        else l=mid+1;
    }
    assert(val==tmp[l]);
    return l;
}
int main(){
    n=read();K=read();ll i;
    for(i=1;i<=n;i++) {
        a[i]=read();b[i]=read();
        sum[i]=(sum[i-1]+a[i]);
        if(b[i]==2) continue;
        if(2*a[i]>K){
            puts("-1");return 0;
        }
    }
    for(i=n;i>=1;i--){
        if(b[i]==1){
            L[i]=(-2ll*sum[i-1]%K+K)%K;
            R[i]=(-2ll*sum[i]%K+K)%K;
        }
        else L[i]=0,R[i]=K-1;
        tmp[++cnt]=L[i],tmp[++cnt]=R[i];
    }
    sort(tmp+1,tmp+cnt+1);
    cnt=unique(tmp+1,tmp+cnt+1)-tmp-1;
//    for(int i=1;i<=cnt;i++)cout<<tmp[i]<<" "; puts("");
    for(i=n;i>=1;i--){
//    	cout<<L[i]<<" "<<R[i]<<endl;
        L[i]=erfen(L[i]);
        R[i]=erfen(R[i]);
//        cout<<L[i]<<" "<<R[i]<<endl; 
        dp[i]=ask(L[i]);
//        cout<<i<<" "<<dp[i]<<endl;
        if(L[i]>R[i]) change(1,cnt,R[i]+1,L[i]-1,1,i);
        else change(1,cnt,1,L[i]-1,1,i),change(1,cnt,R[i]+1,cnt,1,i);
    }
    ll ans=dp[1];
    for(i=cnt;i>=1;i--) ans=min(ans,ask(i));
    printf("%lld\n",ans+sum[n]*2ll);
}


Measured memory_bytes: 15872
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<ll, ll>;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }
struct FastIO {FastIO() { cin.tie(0); ios::sync_with_stdio(0); }}fastiofastio;
#ifdef DEBUG_ 
#include "../program_contest_library/memo/dump.hpp"
#else
#define dump(...)
#endif
const ll INF = 1LL<<60;

int main(void) {
    ll n, m, q;
    cin >> n >> m >> q;
    vector<ll> a(q);
    REP(i, q) cin >> a[i];

    ll period = 7 * m / __gcd(7LL, m);
    vector<int> col(period);
    REP(i, q) {
        for(ll j = a[i]; j<period; j+=m) {
            col[j] = 1;
        }
    }

    dump(period);
    dump(col);

    vector<bool> used(period);
    function<void(ll)> dfs = [&](ll v) {
        used[v] = true;
        for(auto to: {v-1, v+1, v-7, v+7}) {
            if(to == v-1 && v%7==0) continue;
            if(to == v+1 && v%7==6) continue;
            if(0<=to && to<used.size() && !used[to] && col[to%period]==0) {
                dfs(to);
            }
        }
    };
    ll num1 = 0;
    REP(i, period) {
        if(used[i] || col[i]==1) continue;
        num1++;
        dfs(i);
    }
    ll num2 = 0;
    used.assign(period*2, false);
    REP(i, period*2) {
        if(used[i] || col[i%period]==1) continue;
        num2++;
        dfs(i);
    }

    dump(num1, num2, 7 * n / period);

    cout << num1 * 7 * n / period - (7 * n / period - 1) * (num1*2 - num2) << endl;

    return 0;
}

Measured memory_bytes: 32000
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=303;
const ll INF=1LL<<50;
ll dis[MAX][MAX];
int N;
ll L;

void floyd(){
    for(int k=0;k<N;k++){
        for(int i=0;i<N;i++){
            for(int j=0;j<N;j++){
                dis[i][j]=min(dis[i][j],dis[i][k]+dis[k][j]);
            }
        }
    }
    
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            if(dis[i][j]==0) dis[i][j]=0;
            else if(dis[i][j]<=L) dis[i][j]=1;
            else dis[i][j]=INF;
        }
    }
    
    for(int k=0;k<N;k++){
        for(int i=0;i<N;i++){
            for(int j=0;j<N;j++){
                dis[i][j]=min(dis[i][j],dis[i][k]+dis[k][j]);
            }
        }
    }
}

int main(){
    
    int M;
    cin>>N>>M>>L;
    
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            dis[i][j]=INF;
        }
        dis[i][i]=0;
    }
    
    for(int i=0;i<M;i++){
        int a,b;
        ll c;cin>>a>>b>>c;
        a--;b--;
        dis[a][b]=c;
        dis[b][a]=c;
    }
    
    floyd();
    
    int Q;cin>>Q;
    
    for(int i=0;i<Q;i++){
        int s,t;cin>>s>>t;
        s--;t--;
        if(dis[s][t]==INF) cout<<-1<<endl;
        else cout<<dis[s][t]-1<<endl;
    }
    
}



Measured memory_bytes: 1280
n, m = [int(i) for i in input().split(' ')]
x_list = [int(i) for i in input().split(' ')]
y_list = [int(i) for i in input().split(' ')]

x_res = 0
for i in range(n):
    x_res += (i-(n-i-1))*x_list[i]
y_res = 0
for j in range(m):
    y_res += (j-(m-j-1))*y_list[j]
print((x_res*y_res) % (10**9+7))

Measured memory_bytes: 19580
col,row = [int(x) for x in input().split()]
map_list = [[0] * (row+2)]
for i in range(col):
    map_list.append(["0"] + list(input()) + ["0"])
map_list.append(map_list[0])
#print(map_list)

def check(x,y):
    lands = [[x,y]]
    #print(lands)
    area = 0
    sealine = 0
    while lands:
        #print(area)
        #print(lands)
        x,y = lands.pop()
        #print(x,y)
        area += 1
        map_list[y][x] = "2"
        if map_list[y+1][x] == "#":
            lands.append([x,y+1])
        elif not map_list[y+1][x] == "2":
            sealine += 1
        if map_list[y][x+1] == "#":
            lands.append([x+1,y])
        elif not map_list[y][x+1] == "2":
            sealine += 1
        if map_list[y-1][x] == "#":
            lands.append([x,y-1])
        elif not map_list[y-1][x] == "2":
            sealine += 1
        if map_list[y][x-1] == "#":
            lands.append([x-1,y])
        elif not map_list[y][x-1] == "2":
            sealine += 1
        lands = list(map(tuple,lands))
        lands = list(set(lands))
        #print(lands)
    return area

res = "Yes"
for i in range(1,col+1):
    for j in range(1,row+1):
        if map_list[i][j] == "#":
            if check(j,i) == 1:
              res = "No"
print(res)

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

int main()
{
    long long int n,k;
    cin >> n >> k;
    int a[n+1];
    for(int i=1; i<=n; i++){
        cin >> a[i];
        //cout << a[i] << ",";
    }
    
    int now = 1;
    int next = 0;
    long long int cnt = 0;
    
    std:map<int, int> mp;
    for(int i=1; i<=n; i++){
        mp[i] = 0;
    }
    bool isloop = false;
    int loopcnt = 0;

// 1.
if(k <= n){
    for(int i=1; i<=n; i++){
        mp[now] = i;
        cnt++;
        next = a[now];
        if(cnt == k){
            cout << a[now] << endl;
            return 0;
        }
        now = next;   
    }
    return 0;
}    
    
// 2.
if(k > n){
    //cout << now << " - ";
    for(int i=1; i<=n; i++){
        if(mp[now] != 0){
            // ループ発見
            isloop = true;
            loopcnt = i - mp[now];
            break;
        }
        mp[now] = i;
        cnt++;
        next = a[now];
        now = next;   
        //cout << now << " - ";
    }
    //cout << endl;
    //cout << "loop:" << loopcnt << "," << cnt << endl;
    k -= (cnt-loopcnt);
    long long int tmp = k / loopcnt;
    long long int kk = k - loopcnt*tmp;
    {
        //cout << now << " - ";
        for(long long int i=0; i<kk; i++){
            next = a[now];
            now = next;
            //cout << now << " - ";
        }
        //cout << endl;
        cout << now << endl;
    }
}

}

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

int main()
{
    int k,a,b;
    cin>>k>>a>>b;
    if(a%k==0) printf("OK");
    else if(b-((a/k)+1)*k>=0) printf("OK");
    else printf("NG");



    return 0;
}

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

typedef long long   ll;
const ll mod = 1e9 + 7;

#define speedup_IO      ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define forn(i,a,n)     for(ll i = a; i < n; i++)
#define ford(i,n,a)     for(ll i = n-1; i >= a; i--)
#define pb              push_back
#define lb              lower_bound
#define ub              upper_bound
#define pll             pair<ll,ll>
#define all(a)          (a).begin(),(a).end()
#define reset(a,x)      memset(a,x,sizeof(a))

ll mypow(ll base, ll exp) {ll res = 1; while (exp) {if (exp & 1) res = (res * base) % mod; exp >>= 1, base = (base * base) % mod;} return res;}
ll gcd(ll a, ll b)  { return b ? gcd(b, a % b) : a;            }
ll mult(ll a, ll b) { if (a < 0) {a += mod;} if (b < 0) {b += mod;} return ((a % mod) * (b % mod)) % mod; }
ll add(ll a, ll b)  { if (a < 0) {a += mod;} if (b < 0) {b += mod;} return (a % mod + b % mod) % mod;        }
ll sub(ll a, ll b)  { if (a < 0) {a += mod;} if (b < 0) {b += mod;} return (a % mod + mod - b % mod) % mod;  }

const ll inf = 1e18;
const int nax = 1e5 + 5;

// ll fact[nax], invfact[nax];

// void pre()
// {
// 	fact[0] = 1;
// 	forn(i, 1, nax)
// 	{
// 		fact[i] = mult(fact[i - 1], i);
// 	}

// 	invfact[nax - 1] = mypow(fact[nax - 1], mod - 2);

// 	ford(i, nax, 1)
// 	{
// 		invfact[i - 1] = mult(invfact[i], i);
// 	}
// }

// ll ncr(ll n, ll r)
// {
// 	if (r > n)
// 		return 0;

// 	ll ans = mult(fact[n], mult(invfact[n - r], invfact[r]));

// 	return ans;
// }

int main()
{
	speedup_IO;

	int t = 1;
	//cin >> t;
	while (t--)
	{
		ll n;
		cin>>n;

		ll a[n];
		forn(i,0,n)
		{
			cin>>a[i];
		}

		bool ok = 1;
		forn(i,0,n)
		{
			if(a[i]%2 == 0)
			{
				if((a[i]%3) ==0 || (a[i]%5) == 0)
				{
					continue;
				}
				else
				{
					ok = 0;
				}
			}
		}

		if(ok)
		{
			cout<<"APPROVED";
		}
		else
		{
			cout<<"DENIED";
		}
	}

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <algorithm>
#include <vector>
#include <queue>
#define INF 1LL<<60
typedef long long ll;
using namespace std;
#define max(a,b) ((a)>(b) ? (a) : (b))
#define min(a,b) ((a)<(b) ? (a) : (b))
int main(){
  ll v,e,r,i,j;
  ll s,t,d;
  ll c;
  ll a,amax=0;
  vector<pair<pair<ll,ll> ,ll> > st[100010];
  priority_queue<pair<ll,pair<ll,ll>>,vector<pair<ll,pair<ll,ll>>>,greater<pair<ll,pair<ll,ll>>>> mm;
  ll result[110][2600],exc[100][2];
  
  cin >> v >> e >> c;
  auto n=v;
  r=0;
  for(i=0;i<e;i++){
    cin >> s >> t >> a >> d;
    s--;t--;
    amax = max(amax,a);
    st[s].push_back(make_pair(make_pair(d,a),t));
    st[t].push_back(make_pair(make_pair(d,a),s));
  }
  for(i=0;i<n;i++){
    for(j=0;j<=(n-1)*amax;j++){
      result[i][j]=INF;
    }
  }
  c = min(c,(n-1)*amax);
  result[r][c] = 0;
  for(i=0;i<n;i++){
    cin >> exc[i][0] >> exc[i][1];
  }
  mm.push(make_pair(0,make_pair(r,c)));
  while(!mm.empty()){
    auto k = mm.top();
    mm.pop();
    auto posi = k.second.first;
    auto dist = k.first;
    auto coin = k.second.second;
	coin = min(coin,(n-1)*amax);
    if(result[posi][coin] < dist) continue;
    
    auto newCoin = min(coin+exc[posi][0],(n-1)*amax);
    if(coin+exc[posi][0]<=(n-1)*amax && result[posi][newCoin] > result[posi][coin]+exc[posi][1]){
      result[posi][newCoin] = result[posi][coin]+exc[posi][1];
      mm.push(make_pair(result[posi][newCoin],make_pair(posi,newCoin)));
    }
    for(i=0;i<(ll)st[posi].size();i++){
      auto l = st[posi][i];//first: (distance,cost), second: destination
      coin = k.second.second;
      coin = min(coin,(n-1)*amax);
      if(coin-l.first.second>=0 && result[l.second][coin-l.first.second] > result[posi][coin]+l.first.first){
        result[l.second][coin-l.first.second] = result[posi][coin]+l.first.first;
        mm.push(make_pair(result[l.second][coin-l.first.second],make_pair(l.second,coin-l.first.second)));
      }
    }
  }
  for(i=1;i<n;i++){
    auto mini = result[i][0];
    for(j=1;j<=(n-1)*amax;j++){
      //if(result[i][j] != 1LL<<60) cout << result[i][j] << " ";
      //else cout << "INF ";
      mini = min(mini,result[i][j]);
    }
    //cout << "\n";
    if(mini == 1LL<<60) cout << "INF" << endl;
    else cout << mini << endl;
  }
  return 0;
}

Measured memory_bytes: 9724
#include <bits/stdc++.h>
using namespace std;
 
const int MOD = 1e9 + 7;
 
char mat[3][60];
 
int dp[60][3][3];
 
int main( void ) {
    
    int n;
    cin >> n;
    cin >> (mat[1] + 1) >> (mat[2] + 1);
    
    int st;
    if (mat[1][1] == mat[2][1]) {
        dp[1][0][0] = dp[1][1][1] = dp[1][2][2] = 1;
        st = 2;
    }
    else {
        dp[2][0][1] = dp[2][0][2] = dp[2][1][0] = dp[2][1][2] = dp[2][2][0] = dp[2][2][1] = 1;
        st = 3;
    }
    
    for (int i = st; i <= n; ++i) {
        if (mat[1][i] == mat[1][i + 1])
            continue;
        
        if (mat[1][i] == mat[2][i]) {
            for (int k = 0; k <= 2; ++k) {
                for (int p1 = 0; p1 <= 2; ++p1)
                for (int p2 = 0; p2 <= 2; ++p2)
                    if (k != p1 && k != p2)
                        dp[i][k][k] = (dp[i][k][k] + dp[i - 1][p1][p2]) % MOD;
            }
        } else {
            for (int p1 = 0; p1 <= 2; ++p1)
            for (int p2 = 0; p2 <= 2; ++p2)
            for (int q1 = 0; q1 <= 2; ++q1)
            for (int q2 = 0; q2 <= 2; ++q2)
                if (p1 != p2 && p1 != q1 && p2 != q2)
                    dp[i][p1][p2] = (dp[i][p1][p2] + dp[i - 2][q1][q2]) % MOD;
        }
    }
    
    int ans = 0;
    for (int p1 = 0; p1 <= 2; ++p1)
    for (int p2 = 0; p2 <= 2; ++p2)
        ans = (ans + dp[n][p1][p2]) % MOD;
    
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#ifdef _DEBUG_
	#define debug(...) printf(__VA_ARGS__)
#else
	#define debug(...) (void)0
#endif
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;

int main() {
	ll t;
	scanf("%lld", &t);
	if(t<4) {
		printf("%lld\n", t);
		return 0;
	}
	vector<ll> pw;
	pw.PB(1);
	while(pw.back() < (1ll<<50))
		pw.PB(pw.back()*3);
	ll sum=1;
	ll ans=t;
	for(int i=0; sum<=t; i++) {
		ll remain=t-sum, tmp=2*i+1;
		int idx=i+1;
		while(remain>0) {
			tmp += remain/pw[idx];
			remain %= pw[idx];
			idx--;
		}
		ans = min(ans, tmp);
		sum += pw[i+1]*2;
	}
	printf("%lld\n", ans);
	return 0;
}



Measured memory_bytes: 3268
from functools import reduce
from operator import add

N = int(input())
AB = []
for i in range(N):
    AB.append(tuple([int(x) for x in input().split(' ')]))

AB.sort(key=(lambda x: x[1]))

total = 0
f = True
for a, b in AB:
    total += a
    if total > b:
        f = False
        break

if f:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 32412
#include <cstdio>
#include <set>
#include <algorithm>
#include <cstring>

#define INF 1000000
using namespace std;

struct edge
{
  int to, nxt, w;
};

edge E[500005];
int head[10005], cnt = 0, dist[10005];
void add_edge(int u, int v, int w)
{
  E[cnt].to = v;
  E[cnt].w = w;
  E[cnt].nxt = head[u];
  head[u] = cnt++;
}

void dijkstra(int src)
{
  set <pair <int, int> > setds;
  for (int i = 0; i < 10005; i++)
  {
    dist[i] = INF;
  }
  setds.insert(make_pair(0, src));
  dist[src] = 0;
  while (!setds.empty())
  {
    pair<int, int> tmp = *(setds.begin());
    setds.erase(setds.begin());
    int u = tmp.second;
    for (int e = head[u]; ~e; e = E[e].nxt)
    {
      int v = E[e].to;
      int w = E[e].w;
      if (dist[v] > dist[u] + w)
      {
        if (dist[v] != INF)
        {
          setds.erase(setds.find(make_pair(dist[v], v)));
        }
        dist[v] = dist[u] + w;
        setds.insert(make_pair(dist[v], v));
      }
    }
  }
}

int main()
{
  memset(head, -1, sizeof(head));

  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++)
  {
    int v, deg;
    scanf("%d%d", &v, &deg);
    for (int j = 0; j < deg; j++)
    {
      int to, cost;
      scanf("%d%d", &to, &cost);
      add_edge(v, to, cost);
    }
  }
  dijkstra(0);
  for (int i = 0; i < n; i++)
  {
    printf("%d %d\n", i, dist[i]);
  }
}



Measured memory_bytes: 2908
#include <bits/stdc++.h>
using namespace std;
const int N=2005;
int n,m;
int g[N][N];
int dp[N],e[N],vis[N],x,y,f=0;
void dfs(int p,int t){
	if (vis[p]){
		if (vis[p]!=t+1)
			f=1;
		return;
	}
	vis[p]=t+1;
	if (t)
		x++;
	else
		y++;
	for (int i=1;i<=n;i++)
		if (i!=p&&!g[p][i])
			dfs(i,t^1);
}
int calc(int x){
	return x*(x-1)/2;
}
int main(){
	scanf("%d%d",&n,&m);
	for (int i=1,a,b;i<=m;i++){
		scanf("%d%d",&a,&b);
		g[a][b]=g[b][a]=1;
	}
	memset(dp,0,sizeof dp);
	dp[0]=1;
	for (int i=1;i<=n;i++){
		if (vis[i])
			continue;
		x=0,y=0;
		dfs(i,0);
		memset(e,0,sizeof e);
		for (int j=n;j>=0;j--)
			e[j+x]|=dp[j],e[j+y]|=dp[j];
		for (int j=0;j<=n;j++)
			dp[j]=e[j];
	}
	if (f){
		puts("-1");
		return 0;
	}
	int ans=n*n*2;
	for (int i=0;i<=n;i++)
		if (dp[i])
			ans=min(ans,calc(i)+calc(n-i));
	printf("%d",ans);
	return 0;
}

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

int main() {
  long n,m; cin >>n >>m;
  long ans=1;
  long dividor = 1000000007;
  if ((n-m)*(n-m)>1) ans=0;
  else{
    //n!*m!になるはず
    for (int i=0; i<n; i++){
      ans = ans * (i+1) % dividor;
    }
    for (int i=0; i<m; i++){
      ans = ans * (i+1) % dividor;
    }
  }
  if (n==m){
    ans = ans * 2 % dividor;
  }
  
  cout <<ans <<endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
 
typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2

using namespace std;

int MOD = 1000000007;

signed main(){
    int n,k;
    cin >> n >> k;
    int ans = 1000000000;
    int h[100010] = {0};
    rep(i,n) cin >> h[i];
    sort(h,h+n);
    for(int i = 0;i <= n-k;i++){
        ans = min(ans, h[i+k-1]-h[i]);
    }
    cout << ans << endl;
    
    return 0;
}
// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl 

Measured memory_bytes: 1024
class Heruistics:
    allpref = [] #allpref[day][contest]
    donelist = [0]*26
    resultlist = []
    contestlist = []

    def __init__(self,days):
        self.days = days
        self.clast = list(map(int,input().split()))
        for i in range(days):
            self.allpref.append(list(map(int,input().split())))

    def scoring(self,contlist):
        result = 0
        for i in range(self.days):
            cont = contlist[i]
            self.donelist[cont-1] = i+1
            zanen = sum([self.clast[j]*((i+1)-self.donelist[j]) for j in range(26)])

            result += self.allpref[i][cont-1] - zanen
            self.resultlist.append(result)

b_heru = Heruistics(int(input()))
for i in range(b_heru.days):
    b_heru.contestlist.append(int(input()))

b_heru.scoring(b_heru.contestlist)

for result in b_heru.resultlist:
    print(result)


Measured memory_bytes: 9416
#include <stdio.h>
#include <string.h>

void op_print(char *str, int a, int b)
{
	for(int i = a; i <= b; ++i)
	{
		putchar(str[i]);
	}
	putchar('\n');
}

void op_replace(char *str, int a, int b, char *p)
{
	for(int i = a; i <= b; ++i)
	{
		str[i] = p[i - a];
	}
}

void op_reverse(char *str, int a, int b)
{
	for(; a < b; ++a, --b)
	{
		char temp;
		temp   = str[a];
		str[a] = str[b];
		str[b] = temp;		
	}
}

int main()
{
	int q, a, b;
	char str[1024], p[1024], op[16];

	scanf("%s %d", str, &q);
	for(int i = 0; i < q; ++i)
	{
		scanf("%s %d %d", op, &a, &b);

		if(strcmp(op, "print") == 0)
		{
			op_print(str, a, b);
		}
		if(strcmp(op, "reverse") == 0)
		{
			op_reverse(str, a, b);
		}
		if(strcmp(op, "replace") == 0)
		{
			scanf("%s", p);
			op_replace(str, a, b, p);
		}
	}
	return 0;
}


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

#define rep(i, n) for(int i=0; i<n; ++i)
#define repit(it, li) for(auto it=li.begin(); it!=li.end(); it++)
#define ll long long int

int main(){
    int n;
    cin>>n; n++;
    ll a[100001];
    rep(i, n) cin>>a[i];

    bool ng=true;
    rep(i, n) if(a[i]!=0) ng=false;
    if(ng){   
        cout<<(-1)<<endl;
        return 0;
    }

    ll mx[100001];
    mx[0]=1;
    rep(i, n){
        if(mx[i]<a[i]){
            cout<<(-1)<<endl;
            return 0;
        }
        if(i<n-1){
            mx[i+1]=(mx[i]-a[i])*2;
            mx[i+1]=min(mx[i+1], LLONG_MAX/4);
        }
    }

    ll ans=0;
    ll cmx=0;
    for(int i=n-1; i>=0; i--){
        ll cmx=min(mx[i], cmx+a[i]);
        ans+=cmx;
    }

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


Measured memory_bytes: 5104
n = int(input())
x = [0]*n
u = [0]*n
total = [0]*n
for i in range(n):
    x[i], u[i] = input().split()
    
for i in range(n):
    if u[i] == 'JPY':
        total[i] = float(x[i])
    else:
        total[i] = 380000*float(x[i])
        
print(sum(total))

Measured memory_bytes: 3064
Nf,Af,Bf = (input().split(' '))
N = int(Nf)
A = int(Af)
B = int(Bf)
a = N % (A + B)
b = N // (A + B)

if a < A + 1:
  print(A*b+a)
else:
  print(A*b+A)

Measured memory_bytes: 3060
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
    char S[3];
    scanf("%c %c %c",&S[0],&S[1],&S[2]);

    int y=700;

    if(S[0]=='o') y+=100;
    if(S[1]=='o') y+=100;
    if(S[2]=='o') y+=100;
    printf("%d\n",y);

    return 0;
}

Measured memory_bytes: 128
N = 10 ** 6
sieve = map(lambda x:False, range(2, N + 1))
for i in range(2, N + 1):
    if sieve[i - 2]:
        continue
    for j in range(i * 2, N + 1, i):
        sieve[j - 2] = True
while True:
    try:
        n = int(raw_input())
    except EOFError:
        break
    print sieve[:n - 1].count(False)

Measured memory_bytes: 59500
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
const ll mod =1000000007;
int main(){
   int  n;
   cin>>n;
   double nn=n;
   if(n%2==1){
       nn++;
   }
   cout << fixed << setprecision(10);
   cout<<(nn/2)/n<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define ll long long
using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;
typedef  long long ui64;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }
int main()
{

i64 n,ans=0,k;
// vi64 v;
cin>>n;
i64 cp[100000][3],dp[10000][3];
forn(i,n)
{
	forn(j,3)
	{
		cin>>cp[i][j];
	}
}
forn(i,n)
{
	forn(j,3)
	{
		forn(k,3)
		{
			if(j!=k)
			{
				dp[i+1][k]=max(dp[i+1][k],dp[i][j]+cp[i][k]);
			}
		}
	}
}
forn(i,3)
{
	ans=max(ans,dp[n][i]);
}
cout<<ans<<"\n";

	return 0;
}


Measured memory_bytes: 2816
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        int j = 1;
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
            if (j == a[i]) {
                j++;
            }
        }
        if (j == 1) {
            System.out.println(-1);
            return;
        }
        System.out.println(n - j + 1);
    }

}


Measured memory_bytes: 66316
A, B, C, X = int(input()), int(input()), int(input()), int(input())

count = 0

for i in range(A+1):
    for j in range(B+1):
        for k in range(C+1):
            if 500*i+100*j+50*k==X:
                count+=1

print(count)

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

int main(){
    ll n,k,q; cin >> n >> k >> q;
    map<ll,ll> mp;
    rep(i,q){
        ll a; cin >> a;
        --a;
        mp[a]++;
    }
    rep(i,n){
        if(k-(q-mp[i])>0) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 7040
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define rep2(i,n) for(int i = 1; i <= (n); ++i)
#define rrep2(i,n) for(int i = (n); i > 0; --i)
#define srep(i,s,n) for(int i = s; i < (n); ++i)
#define rsrep(i,s,n) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { int n = (__VA_ARGS__).size(); rep(i, n) printf("%d%s", (__VA_ARGS__)[i], i != n-1 ? " " : "\n"); }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;


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

    ll ans = k;
    srep(i, 1, n) {
        ans *= k-1;
    }

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

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

template<long long mod>
class modint{
private:
  long long a;
public:
  constexpr modint(const long long x = 0) noexcept : a(x%mod) {}
  constexpr long long& value() noexcept { return a; }
  constexpr const long long& value() const noexcept { return a; }
  constexpr modint operator+(const modint rhs) const noexcept {
    return modint(*this) += rhs;
  }
  constexpr modint operator-(const modint rhs) const noexcept {
    return modint(*this) -= rhs;
  }
  constexpr modint operator*(const modint rhs) const noexcept {
    return modint(*this) *= rhs;
  }
  constexpr modint operator/(const modint rhs) const noexcept {
    return modint(*this) /= rhs;
  }
  constexpr modint& operator+=(const modint rhs) noexcept {
    a += rhs.a;
    if(a >= mod) a -= mod;
    return *this;
  }
  constexpr modint &operator-=(const modint rhs) noexcept {
    if(a < rhs.a) a += mod;
    a -= rhs.a;
    return *this;
  }
  constexpr modint& operator*=(const modint rhs) noexcept {
    a = a*rhs.a%mod;
    return *this;
  }
  constexpr modint& operator/=(modint rhs) noexcept {
    long long k = mod-2;
    while(k > 0){
      if(k&1){
        *this *= rhs;
      }
      rhs *= rhs;
      k /= 2;
    }
    return *this;
  }
  friend ostream& operator<<(ostream &os, const modint &X){
    return os << X.a;
  }
  friend istream& operator>>(istream &is, modint &X){
    is >> X.a;
    X.a %= mod;
    if(X.a < 0) X.a += mod;
    return is;
  }
};

int main(){
  using mint = modint<998244353>;
  int N, K;
  cin >> N >> K;
  vector<int> L(K), R(K);
  for(int i = 0; i < K; ++i){
    cin >> L[i] >> R[i];
    ++R[i];
  }
  vector<mint> dp(N+2,0), s(N+2,0);
  dp[0] = 1;
  for(int i = 0; i < N; ++i){
    dp[i] += s[i];
    for(int j = 0; j < K; ++j){
      if(i+L[j] <= N){
        s[i+L[j]] += dp[i];
        s[min(i+R[j],N+1)] -= dp[i];
      }
    }
    s[i+1] += s[i];
  }
  cout << dp[N-1] << endl;
}


Measured memory_bytes: 6424
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;

const int inf = 99999999;
const ll linf = 999999999999999999;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.end(), v.begin());
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

///////////////////////////////////////////////////////////////////////////



int main(){
	int n,m;
	cin >> n >> m;
   
   P((n-1)*(m-1));
    
	return  0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.*;
public class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
      int a = sc.nextInt();
      int b = sc.nextInt();
      int ma = Math.max(a+b,a-b);
      System.out.println(Math.max(ma,a*b));
    }
}


Measured memory_bytes: 21844
n = int(input())
s = input()

dp = [[0] * (n+1) for _ in range(n+1)]
ans = 0

for i in range(n-1, -1, -1):
    for j in range(i, -1, -1):
        if s[i] == s[j]:
             dp[i][j] = dp[i+1][j+1] + 1
             ans = max(ans, min(i-j, dp[i][j]))
        
print(ans)


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

c = 1
able = True
if not 0 in A:
  for a in A:
    c = c * a
    if c > 1e18:
      able = False
      break
else:
  c = 0

if able:
  print(c)
else:
  print(-1)

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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl;

int main()
{
    int n, m;
    cin >> n >> m;
    int a[n][m];
    int b[m];

    int ans[n] = {};
    rep(i, n)
    {
        rep(j, m)
        {
            cin >> a[i][j];
        }
    }
    rep(i, m)
    {
        cin >> b[i];
    }
    rep(i, n)
    {
        rep(j, m)
        {
            ans[i] += a[i][j] * b[j];
        }
    }

    rep(i, n)
    {
        OP(ans[i])
    }

    return 0;
}


Measured memory_bytes: 3140