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

int main() {
	int q;
	long long n,i,k,j,sum=0,count=0,ans=0,m,w;
	cin>>n>>w;
	long long a[n],b[n];
	for(i=0;i<n;i++)
	cin>>a[i]>>b[i];
  long long	dp[n+1][w+1];
	
	for(i=0;i<=n;i++)
	{
	    for(j=0;j<=w;j++)
	    {
	       if(j==0 || i==0)
	       dp[i][j]=0;
	       else
	       {
	           if(a[i-1]<=j)
	           dp[i][j]=max(dp[i-1][j-a[i-1]]+b[i-1],dp[i-1][j]);
	           else
	           dp[i][j]=dp[i-1][j];
	           
	       }
	       
	    }
	    
	}
	cout<<dp[n][w];
	
	
	
	return 0;
}

Measured memory_bytes: 79104
#include<stdio.h>
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include<string>
#include<math.h>
using namespace std;

const int MAX = 15;

int main(){
    int N;
    vector<pair<int,int> > A[MAX];
    int ans = 0;

    cin >> N;

    for(int i = 0;i < N;i++){
        int n;
        cin >> n;
        for(int j = 0;j < n;j++){
            int x,y;
            cin >> x >> y;
            A[i].push_back(pair<int,int>(x - 1,y));
        }
    }

    for(int i = 0;i < 1 << N;i++){
        int cnt = 0;
        int list[MAX] = {0};
        bool f = true;

        for(int j = 0;j < N;j++){
            if(1 & (i >> j)){
                list[j] = 1;
                cnt++;
            }
        }

        for(int j = 0;j < N;j++){

            if(!list[j])continue;
            
            for(int k = 0;k < A[j].size();k++){
                if(list[A[j][k].first] == list[j] ^ A[j][k].second){
                    f = false;
                }
            }
        }

        if(f){
            ans = max(ans,cnt);
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
(function main() {
  let line = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('');
  let height_list = [0];
  let current_height = 0;

  // 初めの上昇と平坦を除去
  while (line.length > 0 && line[0] !== '\\') line.shift();
  // 終わりの下降と平坦を除去
  while (line.length > 0 && line[line.length - 1] !== '/') line.pop();

  line.forEach(function(e, i){
      if (e === '\\') current_height -= 1
      else if (e === '_') current_height += 0
      else current_height += 1
      height_list.push(current_height);
  });

  let sum = 0;
  let holes = [];
  for (;height_list.length > 1;) {
    let h = makeHole(height_list);
    if (h > 0) {
      sum += h;
      holes.push(h);
    }
  }

  console.log(sum);
  console.log(holes.length && holes.length + ' ' + holes.join(' '));
})();

function makeHole(list) {
    begin = list.shift();
    if (list[0] < begin && begin <= list.reduce((a, b) => Math.max(a, b), -100000)) {
    let area = 0;
      while (!(list.length === 0 || begin <= list[0])) area += begin - list.shift();
      return area;
    }
    return 0;
}



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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n,d; cin>>n>>d;
	vector<vector<int>>x(n,vector<int>(d));
	for(auto&&i:x)for(auto&&j:i)cin>>j;
	int ans=0;
	for(int i=0;i<n;++i){
		for(int j=i+1;j<n;++j){
			int sum=0;
			for(int k=0;k<d;++k){
				sum+=(x.at(i).at(k)-x.at(j).at(k))*(x.at(i).at(k)-x.at(j).at(k));
			}
			double cal=sqrt(sum);
			sum=sqrt(sum);
			if(cal==sum)++ans;
		}
	}
	cout<<ans<<"\n"s;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <math.h>
#include <algorithm>
#include <climits>
using namespace std;

#define ll long long

ll dp[100001];

ll solve(int i, int* h, int n) {
  
	if (i > n)
    	return INT_MAX;
	
	if (i == n) 
		return 0;
  
  	if (dp[i] != -1)
    	return dp[i];
  
  	dp[i] = min(abs(h[i] - h[i+2]) + solve(i+2, h, n), abs(h[i] - h[i+1]) + solve(i+1, h, n));
  	return dp[i];
}

int main() {

	int n;
	cin >> n;
	int h[n];
	for (int i = 0; i < n; ++i) {
		cin >> h[i];
	}
	memset(dp, -1, sizeof(dp));
	cout << solve(0, h, n-1);
	  	
	return 0; 
}


Measured memory_bytes: 9216
#include<stdio.h>
int main(void){
  int a, b, c;
  scanf("%d %d", &a, &b);
  c = a + b;
  if(a == 0 || b == 0 || c % 2 == 1) {
    puts("IMPOSSIBLE");
    return 0;
  }
  printf("%d\n", c / 2);
  return 0;
}

Measured memory_bytes: 128
// luogu-judger-enable-o2
#include <cstdio>
int n,t,a;
int main(){
//	freopen("a.in","r",stdin);
	scanf("%d%d",&n,&t);
	scanf("%d",&a);
	int min1=a,ans=0,maxc=0;
	for(int i=2;i<=n;++i){
		scanf("%d",&a);
		if(a-min1==maxc) ans++;
		if(a-min1>maxc) maxc=a-min1,ans=1;
		if(min1>a) min1=a;
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 128
n = int(input())
l = []
time = 0
for i in range(n):
  l.append(list(map(int,input().split())))
l.sort(key=lambda x: x[1])
for i in range(n):
  time += l[i][0]
  if time > l[i][1]:
    print("No")
    exit()
print("Yes")


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

int main(){
  ll h,n; cin >> h >> n;
  vector<ll> dp(h+1);
  ll INF = 10000000000;
  fill(dp.begin(),dp.end(),INF);
  vector<pair<ll,ll>> pairs(n);
  for(ll i=0; i<n; i++){
    ll a,b;cin >> a >> b;
    pairs.at(i) = make_pair(a,b);
  }
  dp.at(0) = 0;
  for(ll i=1; i<=h; i++){
    for(ll j=0; j<n; j++){
      ll A,B;
      //cout << "hoge" << endl;
      A = pairs.at(j).first; B = pairs.at(j).second;
      A = max((ll)0, i-A);
      dp.at(i) = min(dp.at(i), dp.at(A) + B);
    }
  }
  cout << dp.at(h) << endl;
}

Measured memory_bytes: 384
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{   int i;
    long long a[100001],n,ans,cnt=0;
    scanf("%lld",&n);
    for(i=0;i<n;i++){
        scanf("%lld",&a[i]);
        
    }
    for(i=0;i<n;i++){
        while(a[i]>=2){
            if(a[i]%2==0){
            a[i]=a[i]/2;
            cnt++;
            }else break;
        }
    }
    printf("%lld",cnt);
    return 0;
}


Measured memory_bytes: 256
import itertools

n = int(input())

al = [int(x) for x in input().split()]
bl = [int(x) for x in input().split()]
l = [int(x) for x in range(1, n+1)]

a, b, flag, i = 0, 0, 0, 0

for v in itertools.permutations(l):
    i += 1
    lv = list(v)
    if al == lv:
        a = i
        flag += 1
    if bl == lv:
        b = i
        flag += 1
    if flag == 2:
        break

print(abs(a-b))


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

typedef long long ll;
typedef long double ld;
typedef string str;

#define f(i, begin, end) for (auto i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define trav(v) for (auto &x : v)
#define dis(v) trav(v) cout << x << " ";
#define deb(x) cerr << #x << ":" << x << "\n"
#define debv(v) trav(v) cerr << x << " ";
#define all(v) v.begin(), v.end()
#define nl cout << "\n"

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll t = 1;
    // cin >> t;
    while (t--)
    {
        ll a, b, n, m, i, j, k;
        str s1, s2;
        ll ch1, ch2;
        // cin >> n;
        cin >> ch1 >> ch2;
        cout << ((ch1 * ch2) / gcd(ch1, ch2)) << "\n";
        //cout << 6 - (ch1 + ch2) << "\n";
        // cin >> n;
        // vector<ll> v(n);
        // f(i, 0, n) cin >> v[i];
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
int main(){
	int N;
	string S;
 
	cin >> N;
	cin >> S;
 
	int state=0;
	int out = 0;
 
	for(int i=0;i<N;i++){
//		cout << S[i] << endl;
		if(state==0){
			if(S[i]=='A'){
				state++;
			}
		}else if(state==1){
			if(S[i]=='B'){
				state++;
			}else{
				if(S[i]=='A'){
					state=1;
				}else{
					state=0;
				}
			}
		}else if(state==2){
			if(S[i]=='C'){
				state=0;
				out++;
			}else{
				if(S[i]=='A'){
					state=1;
				}else{
					state=0;
				}
			}
		}
	}
	cout << out;
	return 0;
}

Measured memory_bytes: 256
use proconio::{fastout, input};
use std::io::*;
use std::str::FromStr;

use std::cmp::{max, min};

fn main() {
    input! {
        x: i64,
        k: i64,
        d: i64,
    }

    let mut x = x;
    if x < 0 {
        x = -x;
    }

    if x / d > k {
        println!("{}", x - d * k);
        return;
    } else {
        if (k - (x / d)) % 2 == 0 {
            println!("{}", x % d);
        } else {
            println!("{}", d - (x % d));
        }
    }
}


Measured memory_bytes: 2156
"use strict";
var input=require("fs").readFileSync("/dev/stdin","utf8");
var cin=input.split(/ |\n/),cid=0;
function next(a){return a?cin[cid++]:+cin[cid++];}
function nexts(n,a){return a?cin.slice(cid,cid+=n):cin.slice(cid,cid+=n).map(a=>+a);}
function nextm(h,w,a){var r=[],i=0;if(a)for(;i<h;i++)r.push(cin.slice(cid,cid+=w));else for(;i<h;i++)r.push(cin.slice(cid,cid+=w).map(a=>+a));return r;}
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill().map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill().map(x=>"+r+")";return eval(r);}

var myOut = main();
if(myOut !== undefined)console.log(myOut);

function main(){
  var n = next(), m = next();
  var a = nexts(m);
  var r = n - a.reduce((a,b)=>a+b);
  return r < 0 ? -1 : r;
}

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

int main()
{
  int n, t, h;
  while (cin >> n, n){
    t = h = n;
    bool taro[2 * n + 5] = {false}, hana[2 * n + 5] = {false};
    for (int i = 0; i < n; i++) {
      int num;
      cin >> num;
      taro[num] = true;
    }
    for (int i = 1; i <= 2 * n; i++) if (!taro[i]) hana[i] = true;

    bool f;
    int field = 0;
    while (1){
      f = false;
      for (int i = field + 1; i <= 2 * n; i++){
        if (taro[i]){
          taro[i] = false;
          field = i;
          f = true;
          t--;
          break;
        }
      }
      if (t == 0 || h == 0){
        cout << h << '\n' << t << '\n';
        break;
      }
      if (!f)field = 0;
      else f = false;
      for (int i = field + 1; i <= 2 * n; i++){
        if (hana[i]){
          hana[i] = false;
          field = i;
          f = true;
          h--;
          break;
        }
      }
      if (!f) field = 0;
      else f = false;
      if (t == 0 || h == 0){
        cout << h << '\n' << t << '\n';
        break;
      }
    }
  }
}

Measured memory_bytes: 3072
import sys


if(__name__ == "__main__"):

    N = int(input().strip())

    AStr = input().strip().split()
    AList = [0] * N
    for i in range(N):
        AList[i] = int(AStr[i])

    N_odd = 0
    for i in range(0, N, 2):
        if(AList[i]%2!=0):
            N_odd+=1
    print(N_odd)


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

int main(){
    // Your code here!
    int a,b,c,d,e,k;
    
    cin>>a>>b>>c>>d>>e>>k;
    if (e-a<=k) {
        cout<<"Yay!"<<endl;
    }
    else {
        cout<<":("<<endl;
    }
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
ll num[233];
ll gcd(ll a,ll b){
	return b?gcd(b,a%b):a;
}
int main(){
	ll n;
	scanf("%lld",&n);
	for (int i=1;i<=n;i++)
	  scanf("%lld",&num[i]);
	ll ans=num[1];
	for (int i=1;i<n;i++)
		ans=ans/gcd(ans,num[i+1])*num[i+1];
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll n;
    cin>>n;
    vector<ll> a(n);
    vector<ll> pre(n);
    vector<ll> pos(n+1);
    pos[n] = 0;
    pre[0] = 0;
    for(int i=0; i<n; i++)
    {
        cin>>a[i];
        if(i>0)
            pre[i] = pre[i-1]^a[i-1];
    }
    pos[n-1] = a[n-1];
    for(int i=n-1; i>=0; i--)
        pos[i] = pos[i+1]^a[i];
    for(int i=0; i<n; i++)
    {
        cout<<(pre[i]^pos[i+1])<<" ";
    }
    return 0;
}

Measured memory_bytes: 7964
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int N=3e5+9;
int n,m,k,has,v[20];
char a[8][8],g[8][8];

void clean(){
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            a[i][j]=g[i][j];
        }
    }
}

void c(int r,int c){
    if(c!=-1){
        for(int i=0;i<n;i++){
            if(a[i][c]=='#')a[i][c]='.';
        }
     }
     if(r!=-1) {
        for(int i=0;i<m;i++){
            if(a[r][i]=='#')a[r][i]='.';
        }
    }
}

bool ok(){
    int has=0;
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            if(a[i][j]=='#')has++;
        }
    }
    return has==k;
}

int main()
{
/*#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif*/
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    vector<pair<int,int>>v;
    cin>>n>>m>>k;
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            cin>>g[i][j];
        }
    }
    int ans=0;
    int tot=n+m;
    for(int i=0;i<n;i++){
        v.push_back({0,i});
    }
    for(int i=0;i<m;i++){
        v.push_back({1,i});
    }
    for(int mask=0;mask<(1<<tot);mask++){
        clean();
        for(int i=0;i<tot;i++){
            if((mask>>i)&1){
                int rr=v[i].first;
                int who=v[i].second;
                if(rr==0){
                    c(who,-1);
                }
                else {
                    c(-1,who);
                }
            }
        }
        if(ok())ans++;
    }
    cout<<ans<<'\n';



    return 0;
}



Measured memory_bytes: 3596
import java.util.Scanner;
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        int a = 0;
        int b = 0;
        
        String[] sArray = new String[S.length()];
        for(int i = 0; i < S.length(); i++){
            String s2 = String.valueOf(S.charAt(i));
            sArray[i] = s2;
        }
        
        for(int i = 0; i < (S.length()-1)/2; i++){
            //System.out.print(i);
            if(sArray[i].equals(sArray[S.length() - (1+i)])){
                //続行
            }else{
                System.out.print("No");
                a++;
                b++;
                break;
            }
        }
        //System.out.print("a="+ a + " 長さ=" + (S.length()-1)/2);
        int N = S.length() - 1;
        if(a == 0){
            for(int i = 0; i < (S.length()-1)/4; i++){
                if(sArray[i].equals(sArray[(N / 2) - (1 + i)])){
                //続行
            }else{
                System.out.print("No");
                b++;
                break;
            }
            }
        }
        
        if(b == 0){
            System.out.print("Yes");
        }
    }
}

Measured memory_bytes: 22868
PROGRAM-ID.                      ABC_042_B.
DATA                             DIVISION.
WORKING-STORAGE                  SECTION.
    01 INP     PIC X(7).
    01 N       PIC 9(3).
    01 L       PIC 9(3).
    01 S1.
        03 S11 OCCURS 100 DEPENDING ON N.
            05 S PIC X(100).
    01 ans     PIC X(10000).
    01 tmp     PIC X(100).
    01 i       PIC 9(3).
    01 j       PIC 9(3).
    01 st      PIC 9(3).
    01 p       PIC 9(5).

PROCEDURE                        DIVISION.
MAIN.
    ACCEPT INP.

    UNSTRING INP
    DELIMITED BY SPACE
    INTO N L.

    PERFORM VARYING i FROM 1 BY 1 UNTIL N < i
        ACCEPT S(i)
    END-PERFORM.

    SORT S11 ON ASCENDING KEY S.

    PERFORM VARYING i FROM 1 BY 1 UNTIL N < i
        COMPUTE p = L * (i - 1) + 1

        STRING
            S(i)(1:L)
            INTO ans WITH POINTER p
        END-STRING
    END-PERFORM.

    DISPLAY ans(1:FUNCTION STORED-CHAR-LENGTH(ans)).

    STOP RUN.


Measured memory_bytes: 384
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <unordered_map>
#include <string>
#include <cmath>
#include <set>
#include <cmath>
using namespace std;


const int N = 10000 + 1;
const int M = 100 + 1;

long long dp[N][M][2] = { 0 };

const long long mod = 1e+9 + 7;

void solve()
{
	string s;
	cin >> s;

	int d;
	cin >> d;

	int n = (int)s.length();

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

	for (int i = 0; i < n; i++)
	{
		for (int k = 0; k < d; k++)
		{
			for (int j = 0; j < 2; j++)
			{
				int digit = 9;

				if (j == 0)
				{
					digit = s[i] - '0';
				}

				for (int x = 0; x <= digit; x++)
				{
					int y = j;

					if (x < s[i] - '0')
					{
						y = 1;
					}

					dp[i + 1][(k + x) % d][y] += dp[i][k][j];
					dp[i + 1][(k + x) % d][y] %= mod;
				}
			}
		}
	}

	long long ans = (dp[n][0][0] + dp[n][0][1]) % mod;
	ans = (ans + mod - 1) % mod;
	cout << ans;
}


int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	//freopen("file.in", "r", stdin);//freopen("file.out", "w", stdout);

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

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

using namespace std;

int main()
{
int n; cin>>n;
vector<int> v(n);
for (int i = 0; i < n; i++)
{
	v[i] = i + 1;
}
map<vector<int>,int> mp;
int cnt = 1;
do
{
	mp[v] = cnt++;
} while (next_permutation(v.begin(),v.end()));

vector<int> a(n);
vector<int> b(n);
for(auto &x : a) cin>>x;
for(auto &x : b) cin>>x;

cout<<abs(mp[a] - mp[b]);
	
return 0;
}


Measured memory_bytes: 5248
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <ctype.h>
#include <ios> 
#include <iomanip>
using namespace std;

#define N_MAX   (100000)
#define LL_MAX_NUM (1LL<<60)
#define INF 1e7

typedef long long ll;
typedef long long int lli;

int main() {
	int a; string s; cin >> a >> s;
    cout << (a>=3200?s:"red") << endl;
	return 0;
}

Measured memory_bytes: 256
import sys

#+++++
		
def main():
	a = int(input())
	aa=len([v for v in range(1,a+1) if v % 2 ==1])

	print(aa/a)
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)

if __name__ == "__main__":
	if sys.platform =='ios':
		sys.stdin=open('inputFile.txt')
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

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

bool solve();

int main()
{
    if (solve()) printf("POSSIBLE\n");
    else printf("IMPOSSIBLE\n");
}

bool solve()
{
    int n, m, land[200000]{};
    scanf("%d%d", &n, &m);
    for (int i = 0; i < m; i++)
    {
        int a, b;
        scanf("%d%d", &a, &b);
        a--; b--;
        if (a > b) std::swap(a, b);
        if (a != 0 && b != n - 1) continue;
        if (a == 0)
        {
            if (land[b] == 1) return true;
            else land[b] = -1;
        }
        else
        {
            if (land[a] == -1) return true;
            else land[a] = 1;
        }
    }
    return false;
}

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

#define rep(n) for(int i=0;i<n;i++)
#define repp(j, n) for(int j=0;j<n;j++)
#define reppp(i, m, n) for(int i=m;i<n;i++)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define debug(x) cerr << #x << ": " << x << endl;

using namespace std;

typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pii;

vector<int> used(100000);
vector<ll> stones(100000);
vector<int> tree[100000];

int root = 0;

ll dfs(int node){
    used[node] = 1;

    int n = (int)tree[node].size();

    if(node != root && n == 1) return stones[node];

    vector<ll> edges(n+1, 0);
    ll total = 0;
    rep(n){
        if(used[tree[node][i]]) continue;
        edges[i] = dfs(tree[node][i]);
        total += edges[i];
        if(edges[i] == LLONG_MAX) return LLONG_MAX;
        // cerr << node+1 << "->" << tree[node][i]+1 << ": " << edges[i] << endl;
    }
    edges[n] = (stones[node]*2-total);
    if(edges[n] < 0) return LLONG_MAX;
    total += edges[n];
    for(ll edge: edges){
        if(edge > total/2) return LLONG_MAX;
    }
    return edges[n];
}

int main(){
    std::ios::sync_with_stdio(0); cin.tie(0);
    int n;
    cin >> n;
    rep(n) cin >> stones[i];
    rep(n-1){
        int a,b;
        cin >> a >> b;
        a--; b--;
        tree[a].emplace_back(b);
        tree[b].emplace_back(a);
    }

    while(tree[root].size() > 1) root++;
    ll ret = dfs(root);
    cout << (ret==LLONG_MAX?"NO":"YES") << endl;
    return 0;
}


Measured memory_bytes: 17792
#include<bits/stdc++.h>
using namespace std;
long long a[1000005];
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;++i)scanf("%lld",&a[i]);
	long long l=2,r=2;
	for(int i=n;i>=1;--i)
	{
		l=(l-1)/a[i]+1,r=r/a[i];
		if(l>r)return !printf("-1\n");
		l*=a[i];
		r=r*a[i]+a[i]-1;
	}
	printf("%lld %lld\n",l,r);
	return 0;
}

Measured memory_bytes: 1024
//define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <x86intrin.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define chmin(x,y) x = min(x, y)
#define chmax(x,y) x = max(x, y)
#define V vector
V<int> dx = {-1, 1,  0, 0, -1, -1,  1, 1};
V<int> dy = { 0, 0, -1, 1, -1,  1, -1, 1};


int main () {
    int r, c, k; cin >> r >> c >> k;
    int v[r][c];
    memset(v, -1, sizeof(v));
    rep(i, k) {
        int R, C; cin >> R >> C; R--; C--;
        cin >> v[R][C];
    }
    V<V<V<ll>>> dp(3030, V<V<ll>> (3030, V<ll> (4, 0)));
    if (v[0][0] != -1) dp[0][0][2] = v[0][0];
    rep(i, r) {
        rep(j, c) {
            rep(p, 4) {
                //拾わない
                if (i!=0) chmax(dp[i][j][3], dp[i-1][j][p]);//上から
                if (j!=0) chmax(dp[i][j][p], dp[i][j-1][p]);//左から
                if (v[i][j] == -1) continue;

                //拾う
                if (i!=0) chmax(dp[i][j][2], dp[i-1][j][p] + v[i][j]);//上から
                if (j!=0 && p!=0) chmax(dp[i][j][p-1], dp[i][j-1][p] + v[i][j]);//左から
            }
        }
    }
    ll ans = 0;
    rep(p, 4) chmax(ans, dp[r-1][c-1][p]);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 684128
#include <iostream>
#include <deque>
 
using namespace std;
 
#define MAX_H 100
#define MAX_W 100
#define MAX_A 10
 
struct State{
    int m,x,y,p,q,d;
    State(int m,int x,int y,int p,int q,int d) :
	m(m),x(x),y(y),p(p),q(q),d(d) {}
};
 
int H,W,A;
char field[MAX_H][MAX_W];
const int dx[4] = {-1,0,1,0};
const int dy[4] = {0,-1,0,1};
bool visited[MAX_H][MAX_W][MAX_A][MAX_A][4];
 
inline bool canMove(int x,int y,int d){
    if(0 <= x && x < W && 0 <= y && y < H){
	if(field[y][x] == 'S' && d == 1){
	    return false;
	}else if(field[y][x] != '#'){
	    return true;
	}
    }
    return false;
}
 
int bfs(int sx,int sy,int gx,int gy){
    deque<State> Q;
    Q.push_back(State(0,sx,sy,A,A,3));
    visited[sy][sx][A][A][3] = true;
   
    while(!Q.empty()){
	State s = Q.front(); Q.pop_front();
	int x = s.x, y = s.y;
	if(x == gx && y == gy) return s.m;
	int nx = x+dx[s.d], ny = y+dy[s.d];
	if(canMove(nx,ny,s.d) && !visited[ny][nx][s.p][s.q][s.d]){
	    visited[ny][nx][s.p][s.q][s.d] = true;
	    Q.push_front(State(s.m,nx,ny,s.p,s.q,s.d));
	}
	if(s.p > 0 && field[y][x] == '.'){
	    int ndir = (s.d & 1 ? s.d+3 : s.d+1)%4;
	    if(!visited[y][x][s.p-1][s.q][ndir]){
		visited[y][x][s.p-1][s.q][ndir] = true;
		Q.push_back(State(s.m+1,x,y,s.p-1,s.q,ndir));
	    }
	}
	if(s.q > 0 && field[y][x] == '.'){
	    int ndir = (s.d & 1 ? s.d+1 : s.d+3)%4;
	    if(!visited[y][x][s.p][s.q-1][ndir]){
		visited[y][x][s.p][s.q-1][ndir] = true;
		Q.push_back(State(s.m+1,x,y,s.p,s.q-1,ndir));
	    }
	}
    }
    return -1;
}
 
int main(){
    int sx,sy,gx,gy;
    cin >> H >> W >> A;
    for(int i = 0 ; i < H ; i++){
	for(int j = 0 ; j < W ; j++){
	    cin >> field[i][j];
	    if(field[i][j] == 'S'){
		sx = j; sy = i;
	    }else if(field[i][j] == 'G'){
		gx = j; gy = i;
	    }
	}
    }
    cout << bfs(sx,sy,gx,gy) << endl;
    return 0;
}

Measured memory_bytes: 5064
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9
#define PI 3.14159265359
#define MOD 1000000007
#define ALL(v) v.begin(),v.end()
#define ALLR(v) v.rbegin(),v.rend()
typedef long long ll;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//isPrime
//modpow modinv
//getDigit
int main() {
  cout << fixed << setprecision(10);
  vector<string> a(3);
  rep(i,3)cin >> a.at(i);
  int turn = 0;
  vector<int> m(3,0);
  while(true){
    if(a.at(turn).size()==m.at(turn)){
      cout << (char)('A'+turn) << endl;
      return 0;
    }
    int temp = turn;
    turn=a.at(turn).at(m.at(turn))-'a';
    m.at(temp)++;
  }
}


Measured memory_bytes: 256
if __name__ == '__main__':
    n = int(input())
    l = list(map(int, input().split(' ')))
    min_cost = float('inf')
    for b in range(-100, 101, 1):
        cost = 0
        for elem in l:
            diff = abs(elem - b) ** 2
            cost += diff
        min_cost = int(min(min_cost, cost))
    print(min_cost)

Measured memory_bytes: 3064
n = gets.to_i
x = gets.split.map &:to_i
y = x.sort

mid0 = y[n/2-1]
mid1 = y[n/2]

n0 = 0
n1 = 0
for a in x
  if a<=mid0
    puts mid1
  else
    puts mid0
  end
end


Measured memory_bytes: 23396
# 枚数を取得
A,B = map(int,input().split())
Total = A + B

# いずれかのパターンで3分割均等にできるかを判定後メッセージを出力
if A % 3 == 0 \
or B % 3 == 0 \
or Total % 3 == 0:
    print("Possible")
else:
    print("Impossible")

Measured memory_bytes: 9032
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <queue>
#include <stack>
#include <list>
#include <functional>
#include <numeric>
#include <iostream>

using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); ++i)

ll N, Q, S, T;
ll D[212345], Deg, prevDeg = 0;

int main() {

	scanf("%lld%lld%lld%lld", &N, &Q, &S, &T);

	scanf("%*d");

	rep(i, N) {
		static ll prevA = 0;
		ll A;
		scanf("%lld", &A);
		D[i] = A - prevA;
		prevDeg -= D[i] > 0 ? S * D[i] : T * D[i];
		prevA = A;
	}

	rep(i, Q) {
		ll L, R, X;
		scanf("%lld%lld%lld", &L, &R, &X);
		ll ld = D[L - 1], rd = D[R];
		D[L - 1] += X;
		if(R < N) D[R] -= X;
		Deg = prevDeg;
		if ((ld < 0 ? 1 : 0) ^ (D[L - 1] < 0 ? 1 : 0)) {
			if (X > 0) {
				Deg += T * ld;
				Deg -= S * D[L - 1];
			}
			else {
				Deg += S * ld;
				Deg -= T * D[L - 1];
			}
		}
		else{
			if (ld > 0 || (ld == 0 && X > 0)) {
				Deg -= S * X;
			}
			else {
				Deg -= T * X;
			}
		}

		if (R < N) {
			if ((rd < 0 ? 1 : 0) ^ (D[R] < 0 ? 1 : 0)) {
				if (X > 0) {
					Deg += S * rd;
					Deg -= T * D[R];
				}
				else {
					Deg += T * rd;
					Deg -= S * D[R];
				}
			}
			else {
				if (rd > 0 || (rd == 0 && X < 0)) {
					Deg += S * X;
				}
				else {
					Deg += T * X;
				}
			}
		}

		printf("%lld\n", Deg);

		prevDeg = Deg;
	}

	return 0;
}



Measured memory_bytes: 4780
#include <iostream>
#include <string>
using namespace std;
using ll = long long;
#define REP(i,s,N) for(ll i=s;i<N;++i)

int main() {
	string S;
	cin >> S;
	ll ans = 0;
	for (ll i=0;i<S.size();++i) {
		ans += (S[i] == '+') ? 1 : -1;
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 256
#include<map>
#include<iostream>
#include<deque>
#include<algorithm>
#include<string>
#include<cctype>
#include<iomanip>
#include<vector>
#include<queue>
 
using namespace std;
#define REP(i,b,e) for(ll i=(ll)b;i<(ll)e;i++)
#define rep0(i,n) REP(i,0ll,n)
#define rep1(i,n) REP(i,1ll,n+1)
 
#define shosu setprecision(13)
 
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> Q;
//ll longinf=1ll<<60;
int inf=1<<29;
int dn[4]={-1,1,0,0};
int dm[4]={0,0,-1,1};
ll longinf=(1ll<<60);

int main(){
      ll N,T,A;
      cin>>N>>T>>A;
      ll H[N];
      rep0(i,N) cin>>H[i];
      ll ans=-1;
      ll temp=longinf;
      rep0(i,N){
            if(abs(1000*A-(1000*T-6*H[i]))<=temp){
                  ans=i+1;
                  temp=abs(1000*A-(1000*T-6*H[i]));
            }
      }
      cout<<ans<<endl;

      return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int selectionSort(int A[],int N){
    int count=0,j;
    for(int i=0;i<N;i++){
        int minj = i;
        for(j = i+1;j<N;j++){
            if(A[j]<A[minj])minj = j;
        }
        if(minj !=i){
            swap(A[minj],A[i]);
            count++;
        }
        
    }
    return count;
}

int main(int argc, const char * argv[]) {
    int A[100],N;cin>>N;
    for(int i=0;i<N;i++)cin>>A[i];
    
    int count = selectionSort(A,N);
    
    for(int i=0;i<N;i++){
        if(i)cout<<' ';
        cout<<A[i];
    }
    cout<<endl;
    cout<<count<<endl;
    return 0;
}



Measured memory_bytes: 3120
#include <iostream>
#include <limits>
#include <queue>
#include <vector>

template <class Cap, bool isDirect>
class MaxFlow {
    struct Edge {
        int from, to;
        Cap cap;
        int rev;
        Edge(int from, int to, Cap cap, int rev)
            : from(from), to(to), cap(cap), rev(rev){};
    };

    class Graph {
    public:
        int size;
        std::vector<std::vector<Edge>> path;

        explicit Graph(int N = 0) : size(N), path(size) {}
        void span(int u, int v, Cap cap, int rev) {
            path[u].push_back(Edge(u, v, cap, rev));
        }
        std::vector<Edge>& operator[](int v) { return path[v]; }
    };

private:
    Graph graph;
    std::vector<int> dist, iter;

    void bfs(int s) {
        std::fill(dist.begin(), dist.end(), -1);
        dist[s] = 0;
        std::queue<int> que;
        que.push(s);

        while (!que.empty()) {
            int v = que.front();
            que.pop();

            for (const auto& e : graph[v]) {
                if (e.cap > 0 && dist[e.to] < 0) {
                    dist[e.to] = dist[v] + 1;
                    que.push(e.to);
                }
            }
        }
    }

    int dfs(int v, int g, Cap f) {
        if (v == g) return f;

        // iterで事前にどこまで探索したかをセーブ
        for (int& itr = iter[v]; itr < graph[v].size(); ++itr) {
            auto e = graph[v][itr];
            if (e.cap > 0 && dist[v] < dist[e.to]) {
                Cap df = dfs(e.to, g, std::min(f, e.cap));

                // 流せるなら流す
                if (df > 0) {
                    graph[v][itr].cap -= df;
                    graph[e.to][e.rev].cap += df;
                    return df;
                }
            }
        }
        return 0;
    }

public:
    explicit MaxFlow(int size)
        : graph(size), dist(size, -1), iter(size) {}

    void span(int u, int v, Cap cap) {
        graph.span(u, v, cap, graph[v].size());
        graph.span(v, u, (isDirect ? 0 : cap), graph[u].size() - 1);
    }

    Cap exec(int s, int g) {
        const Cap INF = std::numeric_limits<Cap>::max();

        Cap ret = 0;
        while (true) {
            bfs(s);
            if (dist[g] < 0) return ret;

            std::fill(iter.begin(), iter.end(), 0);
            Cap flow;
            while (true) {
                flow = dfs(s, g, INF);
                if (flow == 0) break;
                ret += flow;
            }
        }
    }
};

int main() {
    int X, Y, M;
    std::cin >> X >> Y >> M;

    MaxFlow<int, true> mf(X + Y + 2);
    for (int x = 0; x < X; ++x) {
        mf.span(X + Y, x, 1);
    }
    for (int i = 0; i < M; ++i) {
        int x, y;
        std::cin >> x >> y;
        mf.span(x, y + X, 1);
    }
    for (int y = 0; y < Y; ++y) {
        mf.span(y + X, X + Y + 1, 1);
    }

    std::cout << mf.exec(X + Y, X + Y + 1) << std::endl;
    return 0;
}



Measured memory_bytes: 3368
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define len(v) ll(v.size())
#define fi first
#define se second

template <class T>
void cout_vec(const vector<T> &vec){
  for(auto itr:vec) cout<<itr<<' ';
  cout<<endl;
}

typedef pair<ll,ll> P;
const ll mod=1e9+7;
const ll inf=1e15;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n,m;
  cin>>n>>m;
  vector<int> a(m),c(m);
  rep(i,m){
    cin>>a[i];
    int b;
    cin>>b;
    int now=0;
    rep(j,b){
      int c;
      cin>>c;
      c--;
      now|=(1<<c);
    }
    c[i]=now;
  }
  vector<vector<int>> dp(m+1,vector<int>((1<<n),1e9));
  dp[0][0]=0;
  rep(i,m)rep(j,1<<n){
    dp[i+1][j|c[i]]=min(dp[i+1][j|c[i]],dp[i][j]+a[i]);
    dp[i+1][j]=min(dp[i+1][j],dp[i][j]);
  }
  if(dp[m][(1<<n)-1]==1e9) dp[m][(1<<n)-1]=-1;
  cout<<dp[m][(1<<n)-1]<<endl;
}

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

const ll MAX = 200010;
const ll MOD = 1000000007LL;

long long 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;
    }
}

long long 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;
}

long long pow_mod(long long x, long long n) {
    long long a = 1, x2n = x;
    x2n %= MOD;
    while (n!=0) {
        if (n&1==1) {
            a *= x2n;
            a %= MOD;
        }
        x2n *= x2n;
        x2n %= MOD;
        n >>= 1;
    }
    return a;
}

ll mod_inv(ll a, ll m) {
    ll b = m, x = 1, y = 0, s, t;
    while ( b != 0 ) {
        s = y;
        y = x - ( a / b ) * y;
        x = s;
        t = b;
        b = a % b;
        a = t;
    }
    return (x % m + m) % m;
}

int main() {
    ll N, A, B, C;
    cin >> N >> A >> B >> C;

    COMinit();
    ll a = A * mod_inv(A+B, MOD) % MOD;
    ll b = B * mod_inv(A+B, MOD) % MOD;
    ll an = pow_mod(a, N);
    ll bn = pow_mod(b, N);
    ll ak = 1, bk = 1;
    ll sum =  0;
    for ( int i = 0; i < N; i++ ) {
        ll x = COM(N-1+i, N-1) * bk % MOD;
        x = x * an % MOD;
        x = x * (N+i) % MOD;
        sum += x;
        sum %= MOD;
        bk = bk * b % MOD;
    }
    for ( int i = 0; i < N; i++ ) {
        ll x = COM(N-1+i, N-1) * ak % MOD;
        x = x * bn % MOD;
        x = x * (N+i) % MOD;
        sum += x;
        sum %= MOD;
        ak = ak * a % MOD;
    }
    sum = sum * 100 % MOD;
    sum = sum * mod_inv(100-C, MOD) % MOD;
    ll ans = sum;
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 4992
#!/usr/bin/env python3.4

# abc126_c

import math
from fractions import Fraction

def main():
    # input
    n, k = [int(s) for s in input().split()]
    # get ans
    sum = Fraction(0, 1)
    for i in range(1, n+1):
        mult = math.log2(k/i)
        mult = math.ceil(mult) if mult>0 else 0
        sum += Fraction(1, 2**mult)
    sum *= Fraction(1, n)
    ans = float(sum)
    # output
    print(ans)

if __name__ == '__main__':
    main()



Measured memory_bytes: 5728
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int tmp = sc.nextInt(); 
		double h;
		String[] cnt = {"", "", "", "", "", ""};
		for(int i = 0; i < tmp; i++) {
			h = sc.nextDouble();
			
			if(h >= 185)	cnt[5] += "*";
			else if(h >= 180)	cnt[4] += "*";
			else if(h >= 175)	cnt[3] += "*";
			else if(h >= 170)	cnt[2] += "*";
			else if(h >= 165)	cnt[1] += "*";
			else				cnt[0] += "*";
		}
		
		for(int i = 0; i < 6; i++) {
			System.out.println(i + 1 + ":" + cnt[i]);
		}
	}
}

Measured memory_bytes: 28092
n = int(input())
a = list(map(int, input().split()))
e = True
count = 0

for num in a:
	if (num % 2) != 0:
		e = False


while e:
	for i in range(len(a)):
		if (a[i] % 2) == 1:
			e = False
		else:
			a[i] /= 2
	if e:
		count += 1


print(count)

Measured memory_bytes: 3188
#include<bits/stdc++.h>
#define long long long
using namespace std;
long a,b,c;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin>>a>>b;
    c=a*b;
    if(c%2==0)cout<<"Even"<<endl;
    else cout<<"Odd"<<endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

		int n = sc.nextInt();
		sc.nextLine();

		String[] datastr = sc.nextLine().split(" ");
		int[] a = new int[n];
		for (int i=0; i < n; i++) {
			a[i] = Integer.parseInt(datastr[i]);
		}

		int count = 0;
		for (int i=0; i < n; i++) {

			int minj = i;
			for ( int j=i; j < n; j++) {
				if (a[minj] > a[j]) {
					minj = j;
				}
			}

			// swap( a[i], a[minj] )
			// temp <- a[i] <- a[minj] <- temp
			if (minj != i) {
				int temp = a[i];
				a[i] = a[minj];
				a[minj] = temp;
				count++;
			}

		}

		for (int i=0; i < n-1; i++) {
			System.out.print(a[i] + " ");
		}
		System.out.println(a[n-1]);
		System.out.println(count);
	}

}

Measured memory_bytes: 26088
N = gets.chomp.to_i

#N!を素因数分解したときの素因数の個数(1-index)
#ex. N=3のとき p_nums=[0,0,1,1,0,...,0]
p_nums = Array.new(101, 0)

#N!を素因数分解する
#各i=2,3,...,Nに対する素因数分解の結果を用いる
for i in 2..N do
  cur = i
  for j in 2..i do
    while cur%j == 0 do
      p_nums[j] +=1
      cur /= j
    end
  end
end

#指数が74,24,14,4,2以上となる素因数の個数を求める
exp = Hash.new(0)

p_nums.each do |e|
  [74,24,14,4,2].each do |i|
    exp[i] += 1 if e >= i
  end
end

#答えを出力
puts exp[74] + exp[24] * (exp[2] - 1) + exp[14] * (exp[4] -1 ) + (exp[4] * (exp[4] -1 ) * (exp[2] - 2 ))/2


Measured memory_bytes: 1788
#include<algorithm>
#include<iostream>
#include<set>
#include<string>
#include<math.h>

using namespace std;

class zahyo{
	public:
	int x;
	int y;
	zahyo(){
		x=0;
		y=0;
	}
	zahyo(int x_,int y_){
		x=x_;
		y=y_;
	}
	void print(){
		cout<<x<<" "<<y;
	}
	zahyo operator+(zahyo add){
		add.x=this->x+add.x;
		add.y=this->y+add.y;
		return add;
	}
	zahyo operator-(zahyo add){
		add.x=this->x-add.x;
		add.y=this->y-add.y;
		return add;
	}
	bool operator==(const zahyo add) const{
		if(add.x==this->x and add.y==this->y){return true;}
		else{return false;}
	}
	bool operator!=(const zahyo add) const{
		if(add.x==this->x or add.y==this->y){return false;}
		else{return true;}
	}
	bool operator<(const zahyo add) const{
		if(this->x<add.x){return true;}
		else if(this->x==add.x and this->y<add.y){return true;}
		else{return false;}
	}
	bool operator>(const zahyo add) const{
		if(this->x>add.x){return true;}
		else if(this->x==add.x and this->y>add.y){return true;}
		else{return false;}
	}
	void input(){
		cin>>x>>y;
	}
};

int main(){
	int n,m;
	cin>>n>>m;
	int s[10];
	for(int i=0;i<m;i++){
		int k;cin>>k;
		s[i]=0;
		for(int j=0;j<k;j++){
			int s_;
			cin>>s_;
			s_--;
			s[i]=s[i]|(1<<s_);
		}
	}
	int p[10];
	for(int i=0;i<m;i++){
		cin>>p[i];
	}
	int ans=0;
	for(int i=0;i<(1<<n);i++){
		bool ok=true;
		for(int j=0;j<m;j++){
			int temp=i&s[j];
			int check=0;
			while(temp){
				check+=temp%2;
				temp=temp>>1;
			}
			if(check%2!=p[j]){
				ok=false;
			}
		}
		if(ok){ans++;}
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define EPS (1e-7)
#define INF (1e9)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
const double PI = acos(-1);
const ll MOD = 1000000007;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
 
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
/////////////////////////////////////////////

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

  map<string, int> dic;
  int left = 0;
  int right = N;
  while (left + 1 < right) {
    int mid = left + (right - left) / 2;
    bool flag = false;
    for (int i = 0; i <= N - mid; i++) {
      string t = S.substr(i,mid);
      if (dic.count(t)){
        if (dic[t] < i) flag = true; 
      }
      else dic[t] = i + mid - 1; 
    }
    if (flag) left = mid;
    else right = mid; 
  }

  cout << left << endl;
}

Measured memory_bytes: 77696
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
template <class T> void corner(bool flg, T hoge) {
    if (flg) {
        cout << hoge << endl;
        exit(0);
    }
}
#define all(v) v.begin(), v.end()
#define inputv(v, n)                                                           \
    vl v;                                                                      \
    rep(i, n) {                                                                \
        ll x;                                                                  \
        cin >> x;                                                              \
        v.push_back(x);                                                        \
    }
const ll INF = 999999999999999;
const ll MOD = 1000000007;
const ll MAX_N = 500010;
ll a, b, c, d, e, f, p, t, x, y, z, q, m, n, r, h, k, w, l, ans;
int main() {
    cin >> h >> a;
    cout << (h - 1) / a + 1 << endl;
}

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

const ll MAXN = 200000;
const ll INF = 1001001001;

ll N, M, Q, tmp=0;
vector<vector<ll>> T, R, A;

signed main(){
    cin >> N >> M >> Q;
    T.resize(N);
    R.resize(N);
    A.resize(N);
    for(int i=0;i<T.size();i++) {
        T[i].resize(N,0);
        R[i].resize(N,0);
        A[i].resize(N,0);
    }
    for(int i=0;i<M;i++) {
        ll l, r;
        cin >> l >> r;
        l--;
        r--;
        T[l][r]++;
    }
    for(int i=0;i<N;i++) {
        for(int j=i;j<N;j++) {
            if(j>0) R[i][j] = R[i][j-1]+T[i][j];
            else R[i][j] = T[i][j];
        }
    }
    for(int i=0;i<N;i++) {
        for(int j=i;j>=0;j--) {
            if(j==i) A[j][i] = R[j][i];
            else A[j][i] = A[j+1][i]+R[j][i];
        }
    }
    for(int i=0;i<Q;i++) {
        ll p, q;
        cin >> p >> q;
        p--;
        q--;
        cout << A[p][q] << endl;
    }
    return 0;
}

Measured memory_bytes: 6784
package main

import (
	"bufio"
	"fmt"
	"os"
)

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1e7), 1e7)
}

func ri() (n int) {
	sc.Scan()
	for _, v := range sc.Bytes() {
		n = n*10 + int(v-48)
	}
	return
}

func rb() []byte {
	sc.Scan()
	return sc.Bytes()
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func main() {
	h, w, _ := ri(), ri(), ri()
	sr, sc := ri()-1, ri()-1
	s, t := rb(), rb()
	lft, rgt := 0, w-1
	top, btm := 0, h-1
	for i := len(s) - 1; i >= 0; i-- {
		switch t[i] {
		case 'L':
			rgt = min(rgt+1, w-1)
		case 'R':
			lft = max(lft-1, 0)
		case 'U':
			btm = min(btm+1, h-1)
		case 'D':
			top = max(top-1, 0)
		}
		switch s[i] {
		case 'L':
			lft++
		case 'R':
			rgt--
		case 'U':
			top++
		case 'D':
			btm--
		}
		if lft > rgt || top > btm {
			fmt.Println("NO")
			return
		}
	}
	if lft <= sc && sc <= rgt && top <= sr && sr <= btm {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}


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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;

#define F first
#define S second
#define PB push_back
#define MP make_pair

void solve() {
	int x;
	cin >> x;
	int num = lcm(x, 360);
	cout << num / x << endl;
}

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

Measured memory_bytes: 3608
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {
	public static void main(String[] args) {
		FastScanner scan = new FastScanner();
		try (PrintWriter out = new PrintWriter(System.out);) {

			long n = scan.nextLong();


			out.println(solve(n));
			out.flush();
		}
	}

	private static long solve(long n) {
		for (long i = (long) (Math.pow(n, 0.5) + 1); i > 1; i--) {
			if (n % i == 0) {
				return n / i + i - 2;
			}
		}

		return n - 1;

	}

}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}


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

int main(){
	string str;
	cin >> str;
	transform(str.begin(), str.end(), str.begin(), ::tolower);
	
	int count=0;
	while(1){
		string tmp;
		cin >> tmp;
		if(tmp=="END_OF_TEXT") break;
		transform(tmp.begin(), tmp.end(), tmp.begin(), ::tolower);
		if(str==tmp) count++;
	}
	cout << count << endl;
	return 0;
}

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

int main(){
  int h,w;

  while(1){
    cin>>h>>w;

    if (h==0 && w==0) break;

    for(int i=0;i<h;i++){
      for (int j=0;j<w;j++){
        if (i==0||i==h-1||j==0||j==w-1) cout<<"#";
        else cout<<".";
      }
      cout<<endl;
    }
    cout<<endl;
  }
  return 0;
}


Measured memory_bytes: 3084
import bisect

while True:
    n, m = map(int, input().split())
    if n == 0:
        break
    a = sorted(map(int, input().split()))
    index = bisect.bisect_left(a, m) - 1
    if index <= 0:
        print("NONE")
        continue
    ans = 0
    for i in range(index, 0, -1):
        for j in range(i-1, -1, -1):
            if a[i] + a[j] <= m:
                ans = max(ans, a[i] + a[j])
    if ans:
        print(ans)
    else:
        print("NONE")


Measured memory_bytes: 5660
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include <numeric>
#include<map>
#include<unordered_map>
#include <queue>
 
using namespace std;
using ll=long long;
#define rep(i,n) for(ll i=0;i<n;++i)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()
 
int main(){
    ll n, m;
    cin >> n >> m;
    vector<ll> a(n);
    rep(i, n)cin >> a[i];
    sort(ALL(a));

    if(n == 1){
        a[0]/= pow(2, m);
        cout << a[0];
        return 0;
    }
    priority_queue<ll> q;
    rep(i, n)q.push(a[i]);
    rep(i, m){
        ll tmp = q.top();
        tmp /= 2;
        q.pop();
        q.push(tmp);
    }
    ll res =  0;
    rep(i, n){
        res += q.top();
        q.pop();
    }
    cout << res;
}

Measured memory_bytes: 2168
N = int(input())
A = input().split()
A = list(map(int, A))
min_num = A[0]
max_num = A[0]
for data in A:
    if min_num > data:
        min_num = data

    if max_num < data:
        max_num = data

print(max_num - min_num)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
using Int = long long;
const char newl = '\n';


struct Precision{
  Precision(){
    cout<<fixed<<setprecision(12);
  }
}precision_beet;

//INSERT ABOVE HERE
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);

  using D = double;
  D a,b,h,m;
  cin>>a>>b>>h>>m;

  const D pi = asin(1) * 2;

  D t1=(h*60+m)/720*(2*pi);
  D t2=m/60*(2*pi);

  D x1=a*cos(t1),y1=a*sin(t1);
  D x2=b*cos(t2),y2=b*sin(t2);

  //cout<<t1<<':'<<x1<<' '<<y1<<endl;
  //cout<<t2<<':'<<x2<<' '<<y2<<endl;

  cout<<hypot(x1-x2,y1-y2)<<newl;

  return 0;
}


Measured memory_bytes: 4088