akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<vector>
#include<algorithm>
#define MAXN 132005
using namespace std;
struct pr{
	long long in,out;
	pr(long long _i=0,long long _o=0){in=_i,out=_o;}
};
vector<pr> dp[MAXN],temp1,temp2;
vector<int> e[MAXN];
int n,fa[MAXN],dis[MAXN],son[MAXN][2],d[MAXN];
long long deep[MAXN],lim;
void insert(vector<pr>&v,const pr&i)
{
	int p=v.size()-1;
	if(!~p) v.push_back(i);
	else if(i.out<v[p].out) v.push_back(i);
}
void vector_merge(vector<pr>&v,vector<pr>&l,vector<pr>&r)
{
	v.clear();
	int x=l.size(),y=r.size(),p=0,q=0;
	if(!y) return;
	while(p!=x)
	{
		while(q!=y&&l[p].out+r[q].in<=lim) q++;
		if(q) q--;
		if(l[p].out+r[q].in<=lim) v.push_back(pr(l[p].in,r[q].out));
		p++; 
	}
}
void merge_sort(vector<pr>&v,vector<pr>&l,vector<pr>&r)
{
	v.clear();
	int x=l.size(),y=r.size(),p=0,q=0;
	while(p!=x||q!=y)
	{
		if(p==x) insert(v,r[q++]);
		else if(q==y) insert(v,l[p++]);
		else if(l[p].in<r[q].in) insert(v,l[p++]);
		else insert(v,r[q++]);
	}
}
void dfs(int x)
{
	if(!d[x])
	{
		dp[x].clear();
		dp[x].push_back(pr(deep[x],deep[x]));
		return;
	}
	int ls=son[x][0],rs=son[x][1];
	dfs(ls);
	dfs(rs);
	lim+=2*deep[x];
	vector_merge(temp1,dp[ls],dp[rs]);
	vector_merge(temp2,dp[rs],dp[ls]);
	merge_sort(dp[x],temp1,temp2);
	lim-=2*deep[x];
}
int main()
{
	scanf("%d",&n);
	for(int i=2;i<=n;i++)
	{
		scanf("%d%d",&fa[i],&dis[i]);
		deep[i]=deep[fa[i]]+dis[i];
		son[fa[i]][d[fa[i]]++]=i;
	}
	long long l=0,r=1E13,ans=(l+r)/2;
	while(l<r)
	{
		lim=ans,dfs(1);
		if(dp[1].size()) r=ans;
		else l=ans+1;
		ans=(l+r)/2;
	}
	printf("%lld",ans);
}

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

double dist(int x, int y){
    return sqrt(pow(x, 2)+pow(y, 2));
}

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

    int num=0;
    int x, y;
    for(int i=0; i<N; i++){
        cin >> x >> y;
        if(dist(x, y) <= D) num++;
    }

    cout << num << endl;
}

Measured memory_bytes: 3792
import sys, copy, math, collections, itertools

n, k = (int(i) for i in input().split())
hs = [int(input()) for i in range(n)]
hs.sort()
i=0
m=-1
l=len(hs)
while True:
    if l < (i+k):
        break
    # tmp = hs[i:i+k]
    cnd=hs[i+k-1] - hs[i]
    if m==-1:
        m=cnd
    else:
        if cnd < m:
            m=cnd
    i+=1
print(int(m))


Measured memory_bytes: 7896
#include <stdio.h>
#include <string.h>
  
int Dynamic(char X[], char Y[]) {
    int c[1005][1005], i, j, x, y, a;
    a = 0;
  
    x = strlen(X);
    y = strlen(Y);
      
    for ( i = 0; i <= x; i++ ) c[i][0] = 0;
    for ( j = 0; j <= y; j++ ) c[0][j] = 0;
      
    for ( i = 1; i <= x; i++ ) {
        for ( j = 1; j <= y; j++ ) {
            if ( X[i-1] == Y[j-1] ) {
                c[i][j] = c[i-1][j-1] + 1;
            }
            else{
                  
                if ( c[i-1][j] > c[i][j-1] ) {
                    c[i][j] = c[i-1][j];
                }
                else{
                    c[i][j] = c[i][j-1];
                }
            }
            if ( a < c[i][j] )
                a = c[i][j];
        }
    }
    return a;
}
  
  
int main() {
    int q, a, i, t[150];
    char X[1000], Y[1000];
    a = 0;
 
    scanf("%d", &q);
      
    for ( i = 0; i < q; i++ ) {
        scanf("%s", X);
        scanf("%s", Y);
        t[i] = Dynamic(X, Y);
    }
      
    for ( i = 0; i < q; i++ ) {
        printf("%d\n", t[i]);
    }
    return 0;
}

Measured memory_bytes: 5672
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,w[32],i=31;
	cin>>n;
	if(n==0) cout<<0;
	while(n!=0)
	{
		w[i]=n%(-2);
		n/=-2;
		if(w[i]<0){
			n++;
			w[i]-=-2;
		}
		i--;
	}
	for(int j=i+1;j<=31;j++) cout<<w[j];
	return 0;
} 

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
#define int long long
long long gcd(long long a, long long b) {
	if (a % b == 0) {
		return (b);
	}
	else {
		return (gcd(b, a % b));
	}
}
signed main() {
	int n;
	cin >> n;
	long long ans = 1;
	for (int i = 0; i < n; i++) {
		long long t;
		cin >> t;
		ans = ans / gcd(ans, t) * t;
	}
	cout << ans << endl;
	return 0;
}


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

template <typename T1, typename T2>
void func(T1& v, T2& a, int y, int x, int yy, int xx) {
	a[y - 1][x - 1]--;
	a[yy - 1][xx - 1]++;
	v[0].push_back(y);
	v[1].push_back(x);
	v[2].push_back(yy);
	v[3].push_back(xx);
}

int main() {
	int H, W; 
	cin >> H >> W;
	vector<vector<int>> a(H, vector<int>(W));
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			cin >> a[i][j];
		}
	}

	int N = 0;
	vector<vector<int>> res(4);
	for (int i = 0; i < H; i++) {

		if (i % 2 == 0) {
			for (int j = 0; j < W; j++) {
				if (a[i][j] % 2 == 0) continue;

				if (j == W - 1) {
					if (i == H - 1) continue;

					func(res, a, i + 1, j + 1, i + 2, j + 1);
					N++;
				} else {
					func(res, a, i + 1, j + 1, i + 1, j + 2);
					N++;
				}
			}
		} else {
			for (int j = W - 1; j >= 0; j--) {
				if (a[i][j] % 2 == 0) continue;

				if (j == 0) {
					if (i == H - 1) continue;

					func(res, a, i + 1, j + 1, i + 2, j + 1);
					N++;
				} else {
					func(res, a, i + 1, j + 1, i + 1, j);
					N++;
				}
			}
		}
	}
				
	cout << N << endl;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < 4; j++) {
			cout << res[j][i];
			if (j != 3) cout << " ";
		}
		cout << endl;
	}

	return 0;
}


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

using namespace std;
#define ll long long int

int main(){
    ll n , w;
    cin >> n >> w;
    ll weight[n] , value[n];
    for(int i =0 ; i < n ; i ++)
    {
        cin >> weight[i] >> value[i];
    }
    ll dp[n + 1][100001];
    for(int i =0 ; i<= 100000 ; i ++)
    dp[0][i] = 1000 * (ll)INT_MAX;
    for(int j = 0 ; j <=n ; j ++)
    dp[j][0] = 0;
    ll ans = 0;
    for(int i = 1; i <=n ; i ++)
    {
        for(int j = 1; j <=100000 ; j ++)
        {
            if(j >= value[i - 1])
            {
                dp[i][j] = min(dp[i - 1][j] , weight[ i- 1 ] + dp[i - 1][j - value[ i - 1]]);
            }
            else
            dp[i][j] = dp[i - 1][j];
            
        }
    }
    for(int i = 0; i<= 100000;i++)
    {
        if(dp[n][i] <= w && dp[n][i] !=0)
        ans = i;
    }
    cout << ans << endl;
    //cout << dp[n][w] << endl;

}

Measured memory_bytes: 79104
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a, b;
ll f(ll a, ll b) {
	ll sum = 0;
	for (ll i = a; i <= b; i ++) sum ^= i;
	return sum;
}
int main() {
	cin >> a >> b;
	ll x = f(b - b % 4, b);
	ll y = f(a - 1 - (a - 1) % 4, a - 1);
	cout << (x ^ y) << endl;
}

Measured memory_bytes: 3628
import Data.List

ans' _ _ [] = []
ans' n [] b =
  let v = head b
  in
    v:(ans' n [head b,0] (tail b))

ans' n a b =
  let ad = n - (head a)
      bd = head b
      v  = minimum [ad*2+bd, ad+bd*2]
  in
    v:(ans' n ((head b):a) (tail b))

ans p n d =
  let d1 = sort $ map (\i -> (i+n-p) `mod` n) d
      d2 = if 0 == (head d1) then d1 else (0:d1)
      d3 = reverse d2
  in
    100 * (minimum $ ans' n [] d3)

main = do
  l <- getLine
  c <- getContents
  let [n,m,p] = map read $ words l :: [Int]
      d = map read $ lines c :: [Int]
      o = ans p n d
  print o



Measured memory_bytes: 8484
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, N) for(int i=0; i<N; i++)
typedef long long ll;
#define dump(x) cerr<<#x<<"="<<x<<endl
using P = pair<int, int>;

int main() {
    int h, w; cin >> h >> w;
    vector<vector<char>> s(h+2, vector<char>(w+2, '.'));
    rep(i, h) rep(j, w) {
        cin >> s.at(i+1).at(j+1);
    }

    vector<int> vx = {1, 0, -1, 0};
    vector<int> vy = {0, 1, 0, -1};
    rep(i, h) rep(j , w){
        if(s.at(i+1).at(j+1)=='#'){
           for(int k=0; k<4; k++){
               if(s.at(i+1+vy.at(k)).at(j+1+vx.at(k))=='#') break;
               if(k==3){
                   cout << "No" << endl;
                   return 0;
               }
           } 
        }
    }

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


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

int main() {
    long q, h, s, d, n;
    cin >> q >> h >> s >> d >> n;
    q *= 4;
    h *= 2;
    s = min(q, min(s, h));
    if (s * 2 > d) {
        cout << (n / 2) * d + (n % 2) * s << endl;;
    } else {
        cout << n * s << endl;;
    }
    return 0;
}


Measured memory_bytes: 256
main = do
    (k:a:b:_)<-map read.words<$>getLine::IO [Int]
    print $ f k a b
f k a b
    | b-a<=2 = k+1
    | k < a+1 = k+1
    | otherwise = b + ((k-(a+1))`div`2) * (b-a) + ((k-(a+1))`mod`2)

Measured memory_bytes: 508
#include<stdio.h>
int main()
{
    int t,i,temp,n,amount=100000;
    scanf("%d",&n);
    for(i=1;i<=n;i++){
        t=amount*0.05;
        if(t%1000!=0){
            temp=t/1000;
            temp++;
            t=temp*1000;
        }
        amount+=t;


    }printf("%d\n",amount);
    return 0;
}

Measured memory_bytes: 592
/*
*/
#define _CRT_SECURE_NO_WARNINGS

//#pragma comment(linker, "/STACK:16777216")
#include <fstream>
#include <iostream>
#include <string>
#include <complex>
#include <math.h>
#include <set>
#include <vector>
#include <map>  
#include <queue>
#include <stdio.h>
#include <stack>
#include <algorithm>
#include <list>
#include <ctime>
#include <memory.h>
#include <ctime>
#include <assert.h>

#define y0 sdkfaslhagaklsldk
#define y1 aasdfasdfasdf
#define yn askfhwqriuperikldjk
#define j1 assdgsdgasghsf
#define tm sdfjahlfasfh
#define lr asgasgash

#define eps 1e-10
#define M_PI 3.141592653589793
#define bs 1000000007;
#define bsize 512

const int N = 233031;

using namespace std;

int n, ar[N];
vector<int > v[5];

multiset<int> S[10];
multiset<int>::iterator it;
int bad[1000];

int main(){
	//freopen("beavers.in","r",stdin);
	//freopen("beavers.out","w",stdout);
	//freopen("F:/in.txt","r",stdin);
	//freopen("F:/output.txt","w",stdout);
	ios_base::sync_with_stdio(0);
	//cin.tie(0);

	cin >> n;
	for (int i = 1; i <= n; i++)
	{
		cin >> ar[i];
		v[i % 2].push_back(ar[i]);
	}

	for (int i = 0; i <= 1; i++)
	{
		sort(v[i].begin(), v[i].end());
		reverse(v[i].begin(), v[i].end());
	}
	for (int i = 1; i <= n; i++)
	{
		ar[i] = v[i % 2].back();
		v[i % 2].pop_back();
	}

	for (int i = 1; i <= n; i++)
	{
		S[i % 2].insert(ar[i]);
	}

	sort(ar + 1, ar + n + 1);
	for (int i = 1; i <= n; i++)
	{
		it = S[i % 2].lower_bound(ar[i]);
		if (it == S[i % 2].end())
		{
			bad[i % 2]++;
			continue;
		}
		int val = (*it);
		if (val != ar[i])
		{
			bad[i % 2]++;
			continue;
		}
		S[i % 2].erase(it);
	}

	cout << max(bad[0], bad[1]) << endl;

	cin.get(); cin.get();
	return 0;
}

Measured memory_bytes: 5756
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i, n) for (int i=0; i<n; ++i)
#define all(obj) (obj).begin(),(obj).end()
using namespace std;
typedef long long ll;
long long GCD(long long x, long long y) { return y ? GCD(y, x%y) : x; }

int main(){
    ll a, b, c, d, A, B, C;
    cin >> a >> b >> c >> d;
    a--;
    A = a - (a/c + a/d);
    B = b - (b/c + b/d);
    C = c/GCD(c, d)*d;
    cout << B-A+b/C-a/C << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mo 1000000007
using namespace std;
long long read(){
    long long xx=0,flagg=1;
    char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-')
        ch=getchar();
    if(ch=='-'){
        flagg=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        xx=xx*10+ch-'0';
        ch=getchar();
    }
    return xx*flagg;
}
void pus(long long xx,long long flagg){
    if(xx<0){
        putchar('-');
        xx=-xx;
    }
    if(xx>=10)
        pus(xx/10,0);
    putchar(xx%10+'0');
    if(flagg==1)
        putchar(' ');
    if(flagg==2)
        putchar('\n');
    return;
}
long long ksm(long long u,long long v){
	long long o=1;
	while(v){
		if(v&1)
			o=o*u%mo;
		u=u*u%mo;
		v>>=1;
	}
	return o;
}
long long n,l,t,i,x[100005],d[100005],cnt,sum;
int main(){
    //freopen(".in","r",stdin);
    //freopen(".out","w",stdout);
   	n=read();l=read();t=read();
   	for(i=1;i<=n;i++){
   		x[i]=read();
   		d[i]=read();
   		if(d[i]==2)
   			d[i]=-1;
   	}
   	for(i=1;i<=n;i++){
   		sum=x[i]+d[i]*t;
   		if(sum>=0)
   			cnt=(cnt+sum/l)%n;
   		else
   			cnt=(cnt+(sum+1)/l-1+n)%n;
   		x[i]=(sum%l+l)%l;
	}
	sort(x+1,x+n+1);
	for(i=cnt+1;i<=n;i++)
		pus(x[i],2);
	for(i=1;i<=cnt;i++)
		pus(x[i],2);
    return 0;
}

Measured memory_bytes: 2816
#include<bits/stdc++.h>
#define ll long long 
#define ld long double
#define pb push_back
#define vl vector
#define ff first
#define ss second
using namespace std;
int main()
{
    ll a,b,i,j,n,t,c;
    cin>>a>>b;
    if((a+b)%2) cout<<"IMPOSSIBLE";
    else cout<<(a+b)/2;
}

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

int main(){

	int n,m;
	cin >> n >> m;

	vector<int> p(n);
	vector<int> q(n);
	for(int i=0;i<n;i++){
		p[i] = 1;
		q[i] = 0;
	}

	q[0] = 1;

	int x,y;
	for(int i=0;i<m;i++){
		cin >> x >> y;
		x--;
		y--;
		if(p[x] == 1 && q[x] == 1){
			q[x]=0;
			q[y]=1;
		}else if(p[x] >= 2 && q[x] == 1){
			q[y]=1;
		}

		p[x]--;
		p[y]++;


	}

	int cnt=0;
	for(int i=0;i<n;i++){
		cnt += q[i];
	}

	cout << cnt << endl;


	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int main(void){
  int N;
  cin >> N;
  int a[N];
  int ave = 0;
  for(int i = 0; i < N; ++i){
    cin >> a[i];
    ave += a[i];
  }
  ave /= N;
  int cost1 = 0;
  for(int i = 0; i < N; ++i){
    cost1 += (a[i] - ave) * (a[i] - ave);
  }
  ++ave;
  int cost2 = 0;
  for(int i = 0; i < N; ++i){
    cost2 += (a[i] - ave) * (a[i] - ave);
  }
  int cost;
  cost = min(cost1, cost2);
  cout << cost << endl;
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp::{min,max};
#[allow(unused_imports)]
use std::collections::BTreeMap;
#[allow(unused_imports)]
use std::ops::*;
#[allow(unused_imports)]
use std::collections::BinaryHeap;

fn main() {
    let (a,b) = {
        let xs = read_vec_i64();
        (xs[0] as usize, xs[1] as usize)
    };
    let mut xs = vec![0; 1000];
    for i in 1..999+1 {
        xs[i] = xs[i-1] + i;
    }
    for i in 1..999 {
        if xs[i+1] - xs[i] == b - a {
            println!("{}", xs[i] - a);
            return;
        }
    }
}

#[allow(dead_code)]
fn read_line() -> String {
    let mut ret = String::new();
    std::io::stdin().read_line(&mut ret).ok();
    ret.pop();
    return ret;
}

#[allow(dead_code)]
fn read_i64() -> i64 {
    let ss = read_line();
    return ss.parse::<i64>().unwrap();
}

#[allow(dead_code)]
fn read_vec_i64() -> Vec<i64> {
    let mut res = vec![];
    let ss = read_line();
    for ts in ss.split_whitespace() {
        let x = ts.parse::<i64>().unwrap();
        res.push(x);
    }
    return res;
}

use std::fmt::Display;
#[allow(dead_code)]
fn write_vec<T: Display>(xs: &Vec<T>) {
    if xs.len() == 0 {
        println!("");
        return;
    }
    print!("{}", xs[0]);
    for i in 1..xs.len() {
        print!(" {}", xs[i]);
    }
    println!("");
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int D;
  cin >> D;
  
  vector<int> c(26);
  for (int i = 0; i < 26; i++) {
    cin >> c.at(i);
  }
  
  vector<vector<int>> s(D, vector<int>(26));
 
  // 入力 (2重ループを用いる)
  for (int i = 0; i < D; i++) {
    for (int j = 0; j < 26; j++) {
      cin >> s.at(i).at(j);
    }
  }

  vector<int> last(26,0);
  //int score = 0;
  for(int i=0; i<D; i++){
    int kaisai = 0;
    int tmp = INT_MIN;
    for(int k=0; k<26; k++){ // i日目にk thの問題
      int add = s.at(i).at(k);
      int before = last.at(k);
      last.at(k) = i+1;
      for(int j=0; j<26; j++){
        add -= c.at(j)*(1 + i - last.at(j));
      }
      last.at(k) = before;
      if(tmp < add){
        tmp = add;
        kaisai = k;
      }
	}
    
    //score += tmp;
    last.at(kaisai) = i+1;
    //cout << kaisai+1 << ", score: " << score << endl;
    cout << kaisai+1 << endl;
  }
  
  return 0; 
}


Measured memory_bytes: 3664
N = int(input())
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())

if N % min(A,B,C,D,E) == 0:
    rissoku = N//(min(A,B,C,D,E))-1
else:
    rissoku = N//(min(A,B,C,D,E))
print(5 + rissoku)

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<queue>
#include<cmath>
#include <numeric>
#include<iomanip>
#include <cstdint>
#include<deque>
#include<stdio.h>
typedef long long ll;

using namespace std;

int main() {
	ll n, m;
	cin >> n >> m;
	vector<pair<pair<ll, ll>, ll>>pyi;
	vector<pair<ll, ll>>ans(100000);
	vector<ll>count(100005);
	for (ll i = 0; i < m; i++) {
		ll p, y;
		cin >> p >> y;
		pyi.emplace_back(make_pair(y, p), i);
	}
	sort(pyi.begin(), pyi.end());
	for (ll i = 0; i < m; i++) {
		count[pyi[i].first.second]++;
		ans[pyi[i].second] = make_pair(pyi[i].first.second, count[pyi[i].first.second]);
	}
	for (ll i = 0; i < m; i++) {
		cout << setfill('0') << right << setw(6) << ans[i].first << setfill('0') << right << setw(6) << ans[i].second << endl;
	}
}

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

int student[10001][822]; //imos法のための配列

int main(){
	while(1){
		int N, M; //pc数，学生数
		
		scanf(" %d %d", &N, &M);
		if(N==0) break;
		
		for(int i=1; i<=M; ++i)
		for(int j=0; j<=821; ++j)
		student[i][j]=0;
		
		int r;
		scanf(" %d", &r);
		for(int i=0; i<r; ++i){
			int t, n, m, s;
			scanf(" %d %d %d %d", &t, &n, &m, &s);
			if(s==0) student[m][t-540+1]--;
			else student[m][t-540+1]++;	
		}

		for(int i=1; i<=M; ++i)
		for(int j=0; j<821; ++j)
		student[i][j+1] += student[i][j];
		
		//for(int j=0; j<820; ++j) printf("student[%d] = %d\n", j, student[1][j]);
		
		
		int q;
		scanf(" %d", &q);
		for(int i=0; i<q; ++i){
			int ts, te, m;
			scanf(" %d %d %d", &ts, &te, &m);
			
			int count=0;
			for(int j=ts+1; j<=te; ++j) if(student[m][j-540]>0) ++count;
			printf("%d\n", count);
		} 
	
	}
	return 0;
}

Measured memory_bytes: 32288
#include <stdlib.h>
#include <iostream>
#include <vector>
#include <string>
#include <math.h>

#define MAX(a,b) ((a)<(b) ? (a) : (b))
#define MIN(a,b) ((a)>(b) ? (a) : (b))
#define ABS(a) ((a)>0 ? (a) : (a * -1))

using namespace std;
long long func(long long a) {
	if (a == 1) return 1;
	if (a > (pow(10, 9) + 7)) a = a / (pow(10, 9) + 7);
	return a * func(a - 1);
}

int main(){
	long long n, p, ans;
	cin >> n;
	p = 1;
	for (int i = 1; i <= n; i++) {
		p = p * i;
		if (p > (1000000000 + 7)) p = p % (1000000000 + 7);
	}

	cout << p << endl;
}



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

int main(){
    int n, cards[n];
    cin >> n;
    for(int i=0; i<n; i++) cin >> cards[i];
    sort(cards, cards+n, greater<int>());

    int alice = 0;
    int bob = 0;
    for(int i=0; i<n; i++){
        if(i%2 == 0) alice += cards[i];
        else bob += cards[i];
    }

    int ans = alice - bob;
    cout << ans << endl;
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{
    int N; cin>>N;
    vint a(N);
    REP(i,N) cin>>a[i];

    sort(ALL(a));

    vint v;
    while(!a.empty() and v.size()<2){
        int b=a.back();
        a.pop_back();
        if(a.back()==b){
            v.push_back(b);
            a.pop_back();
        }
    }
    int ans=0;
    if(v.size()>=2) ans=v[0]*v[1];
    cout<<ans<<endl;

}

Measured memory_bytes: 1024
H,W,D = map(int,input().split())
A = [list(map(int,input().split())) for _ in [0]*H]
Q = int(input())
LR = [list(map(int,input().split())) for _ in [0]*Q]

n_xy = [0]*(H*W)
for i,row in enumerate(A):
    for j,a in enumerate(row):
        n_xy[a-1] = [i,j]
S = [0]*(H*W)
for i in range(D,H*W):
    S[i] = S[i-D] + abs(n_xy[i][0] - n_xy[i-D][0]) + abs(n_xy[i][1] - n_xy[i-D][1])
for L,R in LR:
    print(S[R-1]-S[L-1])

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

ll dp[51][51][10000] = {};
ll mod = 1e9 + 7;
inline void add(ll &a, ll b) {
    a = (a + b) % mod;
}

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

    int n, k;
    cin >> n >> k;

    dp[0][0][0] = 1;
    rep(i, 0, n) rep(j, 0, n) rep(l, 0, k + 1) {
        if (dp[i][j][l] == 0)
            continue;
        add(dp[i + 1][j + 1][l + 2 * (j + 1)], dp[i][j][l]);
        add(dp[i + 1][j][l + 2 * j], dp[i][j][l]);
        if (j)
            add(dp[i + 1][j - 1][l + 2 * (j - 1)], dp[i][j][l] * j * j);
        add(dp[i + 1][j][l + 2 * j], dp[i][j][l] * 2 * j);
    }
    cout << dp[n][0][k] << endl;
    return 0;
}

Measured memory_bytes: 166144
package main

import (
	"fmt"
	"strings"
)

func main() {
	var n int
	var s string
	fmt.Scan(&n, &s)

	ans := 0
	for i := 1; i < n; i++ {
		first := s[:i]
		second := s[i:]

		chars := classifiedChars(first)
		count := 0
		for char := range chars {
			if strings.Contains(second, char) {
				count++
			}
		}
		if ans < count {
			ans = count
		}
	}
	fmt.Println(ans)
}

func classifiedChars(str string) map[string]int {
	table := make(map[string]int)
	arr := strings.Split(str, "")
	for _, s := range arr {
		table[s] += 1
	}
	return table
}


Measured memory_bytes: 1024
require 'pp'
$DEBUG ? define_method(:dpp){|e|pp e} : define_method(:dpp){|e|}

# 空白区切の入力値を数値の配列で返却する
def gets_i_list()
  gets.chomp.split(" ").map(&:to_i)
end

N, M = gets_i_list

# list = gets_i_list

boxes = Array.new(N).map{ {count: 1, red: false}}
boxes[0][:red] = true

M.times do
  x, y = gets_i_list
  x = x - 1
  y = y - 1

  boxes[y][:count] += 1
  boxes[y][:red] = boxes[x][:red] || boxes[y][:red]

  boxes[x][:count] -= 1
  if boxes[x][:count] == 0
    boxes[x][:red] = false
  end
end

count = 0
boxes.each do |h|
  count += 1 if h[:red]
end

puts count

Measured memory_bytes: 32252
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <vector>
#include <cstring>
#include <queue>
#include <map>
#include <set>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef vector<vector<int>> Graph;
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};
template<class T> inline bool chmax(T &a,T& b){if(a < b){a = b; return true;} else return false;}
template<class T> inline bool chmin(T &a,T& b){if(a > b){a = b; return true;} else return false;}
//struct area

//function area

//main area
int main(){
    int n, k;
    cin >> n >> k;
    int h[n];
    rep(i,n) cin >> h[i];
    sort(h,h+n);
    int ans = 1000000001;
    rep(i,n-k+1){
        ans = min(ans, h[i+k-1] - h[i]);
    }
    cout << ans << endl;
}
/*



*/

Measured memory_bytes: 3988
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

pub fn read_n<T: FromStr>(n: usize) -> Vec<T> {
    read_n_logic::<T>(n, vec![])
}

pub fn read_n_logic<T: FromStr>(n: usize, mut a: Vec<T>) -> Vec<T> {
    match n {
        0 => a,
        _ => {
            a.push(read::<T>());
            read_n_logic(n - 1, a)
        }
    }
}
use std::cmp::{max, min};

fn main() {
    let n: f64 = read();
    println!("{}", n * 2.0 * std::f64::consts::PI);
}


Measured memory_bytes: 2220
/**********************************************************
 * ×÷??£?zxf
 * ????£?2017/8/10
 * ±???£?Miscalculation
 * ????£?Gym 100803B
 * ×??????¨£?
 * ????£?
 * Time used£?
 * Memory used£?
 **********************************************************/
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define LL long long
#define pb push_back
#define pob pop_back
#define mp make_pair
#define FILL(a,v) memset((void*)a,v,sizeof(a))
#define FILL0(a) FILL(a,0)
#define FILL1(a) FILL(a,-1)
#define ALL(a) (a).begin(),(a).end()
#define Inf 1e9
#define Mod 1000000007
#define foreach(it,x) for(typeof(x.begin()) it=x.begin();it!=x.end();it++)
#define FOR(i,x) for(int i=0;i<x;i++)
#define RFOR(i,x) for(int i=x-1;i>=0;i--)
#define FFOR(i,a,b) for(int i=a;i<b;i++)
#define FRFOR(i,a,b) for(int i=a-1;i>=b;i--)
#define SZ(a) ((int)(a).size())
#define FI first
#define SE second
#define OVER(a) return puts(a),0
#define fastio ios::sync_with_stdio(0)
#define filei(f) freopen(f,"r",stdin)
#define fileo(f) freopen(f,"w",stdout)
using namespace std;
typedef pair<int,int> pii;
typedef unsigned long long UINT;
typedef unsigned int Uint;
typedef long long INT;
typedef pair<INT,INT> PII;
typedef stringstream sst;
typedef istringstream iss;
typedef vector<int> vint;
typedef vector<INT> VINT;
typedef vector<pii> vpii;
typedef vector<PII> VPII;
typedef priority_queue<int> pqi;
typedef priority_queue<INT> PQI;
typedef priority_queue<pii> pqp;
typedef priority_queue<PII> PQP;
typedef priority_queue<int,vint,greater<int> > xqi;
typedef priority_queue<INT,VINT,greater<INT> > XQI;
typedef priority_queue<pii,vpii,greater<pii> > xqp;
typedef priority_queue<PII,VPII,greater<PII> > XQP;

vector<pair<INT,INT> > cal,cal2;
string sns;
INT ans1,ans2,ans;

int main()
{
	cin>>sns;
	INT a=0,b=0;
	for(int i=0;i<SZ(sns);i++)
		if(isdigit(sns[i]))
			a=a*10+sns[i]-'0';
		else
		{
			if(sns[i]=='+') b=1;
			else b=2;
			cal.push_back(mp(a,b));
			a=0;
		}
	cal.push_back(mp(a,1));
	a=1;
	int chenging=0;
	for(int i=0;i<SZ(cal);i++)
	{
		if(chenging)a*=cal[i].first;
		if(chenging&&cal[i].second==1)
		{
			cal2.push_back(mp(a,1));
			chenging=0;
		}
		else if(!chenging&&cal[i].second==2)
			chenging=1,a=cal[i].first;
		else if(!chenging)cal2.push_back(mp(cal[i].first,1));
	}
	ans1=0;
	for(int i=0;i<SZ(cal2);i++)
	{
		ans1+=cal2[i].first;
	}
	ans2=cal[0].first;
	for(int i=0;i<SZ(cal)-1;i++)
	{
		if(cal[i].second==1)ans2+=cal[i+1].first;
		else ans2*=cal[i+1].first;
	}
	cin>>ans;
	if(ans==ans1&&ans==ans2)OVER("U");
	if(ans==ans1)OVER("M");
	if(ans==ans2)OVER("L");
	OVER("I");
}

Measured memory_bytes: 3228
#include<cstdio>
#include<iostream>

#define MAX 5000

using namespace std;

int main(void){

	int n,a[5000];
	int wa,max;

	while(1){
		cin>>n;
		if(n==0) break;
		wa=0;
		cin>>a[0];
		max=a[0];
		for(int i=1;i<n;i++){
			cin>>a[i];
			if(max<a[i]) max=a[i];
		}
		if(max>=0){
			for(int i=n-1;i>=0;i--){
				wa+=a[i];
				if(wa<0) wa=0;
				if(wa>max) max=wa;
			}
		}
		cout<<max<<endl;
	}
	return 0;
}

Measured memory_bytes: 1176
#include <bits/stdc++.h>
#ifdef HIRO
#define d(f_, ...) printf((f_), ##__VA_ARGS__)
#else
#define d(f_, ...)
#endif

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef queue<int> qi;
typedef queue< pair<int, int> > qp;
#define mp make_pair
#define pi 3.14159265358979323846
#define MAX max_element
#define MIN min_element
#define all(v) v.begin(), v.end()
#define gt(T) greater<T>()
#define sum(v) accumulate(v.begin(), v.end(), 0)
#define uni(v) do{ \
  sort(v.begin(), v.end()); \
  decltype(v)::iterator result = unique(v.begin(), v.end()); \
  v.erase(result, v.end()); \
}while(0)
#define fi(init, n) for(int i = init; i < n; ++i)
#define fj(init, n) for(int j = init; j < n; ++j)
#define fk(init, n) for(int k = init; k < n; ++k)
#define zero(x) memset(x, 0, sizeof(x))
#define negative(x) memset(x, ~0, sizeof(x))
const ll MOD = 1e9 + 7;
const int INF = 1e9;
const int di[] = { 0, 1, 0, -1 };
const int dj[] = { 1, 0, -1, 0 };

template<typename T>
T gcd(T a, T b) {
	return b ? gcd(b, a % b) : a;
}
template<typename T>
T lcm(T a, T b) {
	return a * b / gcd(a, b);
}
template<typename T>
int finder(vector<T> vec, T number) {
	auto itr = find(vec.begin(), vec.end(), number);
	size_t index = distance(vec.begin(), itr);
	if (index != vec.size()) return 1;
	else return 0;
}
ll frac(ll n){
	if (n == 0) return 1;
	return (n * frac(n - 1)) % MOD;
}

int main(int argc, char** argv) {
#ifdef HIRO
  string quiz(argv[1]);
  string id(argv[2]);
  string filename("input/" + quiz + "/" + id + ".txt");
  ifstream fin(filename);
  if (fin.peek() == ifstream::traits_type::eof()) {
    cout << "No input.";
    return 0;
  }
  ifstream cin(filename);
  std::cin.rdbuf(cin.rdbuf());
#endif
  ll ans = 0;
  string s,s2;
  cin>>s;
  ll n;
  cin >> n;
  // ll n, m;
  // cin >> n >> m;
  // ll n, m, k;
  // cin >> n >> m >> k;
  int di = 0; //0: normal, 1:reverse
  int t, f;
  char c;
  fi(0,n){
    cin >> t;
    if(t==1)di^=1;
    else if(t==2){
      cin>>f>>c;
      if((di==0&&f==2) || (di==1&&f==1)) s+=c;
      // else s=c+s;
      else s.insert(0,1,c);
    }
  }
  if(di)reverse(all(s));
  cout << s <<endl;
  // cout << ans << endl;
  return 0;
}



Measured memory_bytes: 900
'''
Created on 2020/02/17

@author: fanta
'''

N = int(input())
nums = [int(x) for x in input().split()]
state = 0

for n in range(N):
    if (nums[n]%2 == 0):
        if ((nums[n]%3 == 0)or(nums[n]%5 == 0)):
            state += 1
    else:
        state += 1
        
if state == N:
    print("APPROVED")
else:
    print("DENIED")
        

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <cassert>
using namespace std;
using ll = long long;

int gcd(int a, int b) {
	if (a%b == 0) return b;
	return gcd(b, a%b);
}

int main() {
	int n; cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) cin >> a[i];
	vector<int> g(n + 2), h(n + 2);
	g[0] = a[0];
	h[n - 1] = a[n - 1];
	for (int i = 1; i < n; i++) g[i] = gcd(g[i - 1], a[i]);
	for (int i = n - 2; i >= 0; i--) h[i] = gcd(h[i + 1], a[i]);
	int ans = max(g[n - 2], h[1]);
	for (int i = 1; i < n - 1; i++) {
		ans = max(ans, gcd(g[i - 1], h[i + 1]));
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1408
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define in(x) cin >> x
#define out(str) cout << str << endl

#define mod 1000000007

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

int N,M,res;

int main(){
    cin>>N>>M;
    res=M/N;
    for(int i=res;i>=1;i--){
        if(M%i==0){
            out(i);
            return 0;
        }
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll s,l;
main()
{
	scanf("%lld",&s);
	l=sqrt(s);if(l*l<s)l++;
	printf("0 0 %lld 1 %lld %lld",l,l*l-s,l);
	return 0;
}

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

#define ll long long
#define ld long double 
#define endl "\n"
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(a) (int)(a.size())
#define fr(i,n) for(i=1;i<=n;i++)

typedef pair<int, int> II;
typedef vector< II > VII;
typedef vector<int> VI;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    ll n,k;
    cin>>n>>k;
    cout<<min(n%k, 1ll)<<endl;
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define FR(var, max) for(int var = 0; i < (max); ++i)
using namespace std;
using ll = long long;
using l = long;
using vi = vector<int>;
using vl = vector<l>;
using vll = vector<ll>;
using vvl = vector<vector<l>>;
using vvll = vector<vector<ll>>;
using pll = pair<ll, ll>;

int main()
{
    int r, d, x, nxt; cin >> r >> d >> x;
    nxt = r * x - d;
    for (int i = 0; i < 10; ++i) {
        cout << nxt << endl;
        nxt = r * nxt - d;
    }
    
    return 0;
}


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

#define int long long
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)

const unsigned int mod = 1e9 + 7;

using namespace std;

int32_t main() {
	fastio;

	int n, m;
	cin >> n >> m;
	int tot = 0;
	while(m--) {
		int x;
		cin >> x;
		tot += x;
	}
	if(tot <= n)
		cout << n - tot;
	else
		cout << -1;

	return 0;
}

/*
B - Homework / 
Time Limit: 2 sec / Memory Limit: 1024 MB

Score : 
200
 points

Problem Statement
Takahashi has 
N
 days of summer vacation.

His teacher gave him 
M
 summer assignments. It will take 
A
i
 days for him to do the 
i
-th assignment.

He cannot do multiple assignments on the same day, or hang out on a day he does an assignment.

What is the maximum number of days Takahashi can hang out during the vacation if he finishes all the assignments during this vacation?

If Takahashi cannot finish all the assignments during the vacation, print -1 instead.

Constraints
1
≤
N
≤
10
6
1
≤
M
≤
10
4
1
≤
A
i
≤
10
4
Input
Input is given from Standard Input in the following format:

N
 
M

A
1
 
.
.
.
 
A
M

Output
Print the maximum number of days Takahashi can hang out during the vacation, or -1.

Sample Input 1 
Copy
41 2
5 6
Sample Output 1 
Copy
30
For example, he can do the first assignment on the first 
5
 days, hang out on the next 
30
 days, and do the second assignment on the last 
6
 days of the vacation. In this way, he can safely spend 
30
 days hanging out.

Sample Input 2 
Copy
10 2
5 6
Sample Output 2 
Copy
-1
He cannot finish his assignments.

Sample Input 3 
Copy
11 2
5 6
Sample Output 3 
Copy
0
He can finish his assignments, but he will have no time to hang out.

Sample Input 4 
Copy
314 15
9 26 5 35 8 9 79 3 23 8 46 2 6 43 3
Sample Output 4 
Copy
9
*/


Measured memory_bytes: 3620
# 入力
candle_num, set_fire_num = list(map(int, input().split()))
candle_list = list(map(int, input().split()))

answer_time = 10 ** 15


def check_time(current_time):
    global answer_time
    if current_time < answer_time:
        answer_time = current_time


# 一番左をl, 一番右をrとおく(要素はL,Rとする)
for l in range(candle_num - set_fire_num + 1):
    r = l + set_fire_num - 1

    # L >= 0 のとき
    if candle_list[l] >= 0:
        check_time(candle_list[r])
        continue

    # L < 0 のとき
    # R < 0 のとき
    if candle_list[r] <= 0:
        check_time(abs(candle_list[l]))
        continue
    else:
        if abs(candle_list[l]) >= abs(candle_list[r]):
            check_time(candle_list[r]*2 + abs(candle_list[l]))
            continue
        else:
            check_time(abs(candle_list[l])*2 + candle_list[r])
            continue

# 最後に最速タイムを出力
print(answer_time)


Measured memory_bytes: 14224
n,m = map(int, input().split())
# abl = []
# cl = []

dp = [ [10**9]*(2**n) for _ in range(m+1) ]
dp[0][0] = 0
for i in range(m):
    a,b = map(int, input().split())
    cl = list(map(int, input().split()))
    cbit = 0
    for c in cl:
        cbit += 2**(c-1)
    
    for j in range(2**n):
        if dp[i][j] == 10**9:
            continue
        dp[i+1][j] = min(dp[i][j], dp[i+1][j])
        dp[i+1][j|cbit] = min(dp[i][j]+a, dp[i][j|cbit], dp[i+1][j|cbit])

ans = dp[m][2**n-1]
if ans >= 10**9:
    ans = -1

print(ans)

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

using namespace std;

using lint=int64_t;
using uint=uint32_t;
using ulint=uint64_t;

template<class T>
using vector2d=vector<vector<T>>;

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

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

template <class T>
void OutVec(const vector<T>& vec){
  for(int i = 0; i < vec.size() - 1; ++i){
    cout<<vec[i]<<" ";
  }
  cout<<vec.back()<<endl;
}

template <class T>
void OutVec2d(const vector2d<T>& vec){
  for(auto v:vec){
    OutVec(v);
  }
}

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

  string s,t;
  cin>>s>>t;
  int res=0;
  for(int i=0;i<s.size();i++){
    if(s[i]!=t[i]){
      res++;
    }
  }
  cout<<res<<endl;


  return 0;
}




Measured memory_bytes: 3884
#include<iostream>

using namespace std;

int main(){

	int K,S;
	int ans=0;

	cin >> K >> S;



	for(int k=0; k<=K; k++){
		for(int j=0; j<=K; j++){
			
			int sum=0;

			int x=S-k-j;

			int left=0, right=K;

			while(left <= right&& x>=0){

				
				//cout << left <<" "<<right <<" "<<ans<<endl;

				int i=(right +left)/2;
			
				//	cout <<k<<" " <<j <<" " <<i <<endl;
				if(x==i){
					
					ans++;
					break;
				
				}
				else if(x < i) right = i;

				else left= i+1;
				


			}


		}
	}

	cout <<ans<<endl;
}

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


int main() {
  ll x;
  cin >> x;
  ll ans = 100;
  int count = 0;
  while(ans<x){
    ans = ans+ans/100;
    ++count;
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;

int main(){
    vector<string> days = {"SUN","MON","TUE","WED","THU","FRI","SAT"};
    string today; cin >> today;
    rep(i,7){
        if(days[i]==today){
            cout << 7 - i << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
#include <string>
#include <iostream>
using namespace std;
int main(){
	int a, b;
	int coin = 0;
	cin >> a >> b;
	if(a > b){
		coin = a * 2 - 1;
	}else if(b > a){
		coin = b * 2 - 1;
	}else{
		coin = a + b;
	}
	cout << coin << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

	int m0=0,m1=0,i0=0,i1=0;

	for(int i=0; i<N; i++){
		int t;
		cin >> t;
		if(t>m0){
			m1=m0; i1=i0;
			m0=t;  i0=i;
		}else if(t>m1){
			m1=t;  i1=i;
		}
	}

	for(int i=0; i<N; i++){
		if(i==i0) cout << m1 << endl;
		else cout << m0 << endl;
	}

	return 0;

}



Measured memory_bytes: 1664
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define sim template <class c
#define ris return *this
#define dor > debug &operator<<
#define eni(x)                                                                    \
	sim > typename enable_if<sizeof dud<c>(0) x 1, debug &>::type operator<<(c i) \
	{
sim > struct rge
{
	c b, e;
};
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c *x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug
{
#ifndef LOCAL
	~debug()
	{
		cerr << endl;
	}
	eni(!=) cerr << boolalpha << i;
	ris;
} eni(==) ris << range(begin(i), end(i));
}
sim, class b dor(pair<b, c> d)
{
	ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d)
{
	*this << "[";
	for (auto it = d.b; it != d.e; ++it)
		*this << ", " + 2 * (it == d.b) << *it;
	ris << "]";
}
#else
	sim dor(const c &)
	{
		ris;
	}
#endif
}
;
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
template <typename T>
using indexed_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
void solve()
{
	int n, m;
	cin >> n >> m;
	int a[n][m];
	for (int i = 0; i < n; ++i)
		for (int j = 0; j < m; ++j)
			cin >> a[i][j];
	int ans = 0;
	for (int i = 0; i < n; ++i)
	{
		for (int j = i + 1; j < n; ++j)
		{
			if (i != j)
			{
				long double d = 0;
				for (int k = 0; k < m; ++k)
				{
					d += (a[i][k] - a[j][k]) * (a[i][k] - a[j][k]);
				}
				if (sqrt(d) == (int)(sqrt(d)))
					ans++;
			}
		}
	}
	cout << ans << "\n";
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int t = 1;
	// cin >> t;
	while (t--)
	{
		solve();
	}
	return 0;
}


Measured memory_bytes: 3716
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <complex>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
#include <assert.h>
#include <array>
#include <cstdio>
#include <cstring>
#include <random>
#include <functional>
#include <numeric>
#include <bitset>
#include <fstream>

using namespace std;

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

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { cout << #a << " = " << a << endl; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }

typedef long long ll;
int const inf = 1<<29;

struct state {
  int cost, use, pos;
  state(int c, int u, int p) : cost(c), use(u), pos(p){}
};

vector<int> bfs(vector<vector<pair<int, bool>>>& G, int s, int t, int& shortestLen) {
  vector<int> dist(G.size(), inf), d2cnt(G.size()+1);
  dist[s] = 0;

  queue<state> q;
  q.emplace(0, 0, s);

  while(!q.empty()) {
    const state s = q.front(); q.pop();
    d2cnt[s.cost]++;
    for(auto& e: G[s.pos]) {
      const int next = e.first;
      if(dist[next] > s.cost + 1) {
        dist[next] = s.cost + 1;
        q.emplace(dist[next], 0, next);
      }
    }
  }

  shortestLen = dist[t];
  return d2cnt;
}

int main() {

  int N, M, s, t; cin >> N >> M >> s >> t; s--, t--;
  vector<vector<pair<int, bool>>> G(N);
  rep(i, M) {
    int x, y; cin >> x >> y;
    G[x-1].emplace_back(y-1, false);
    G[y-1].emplace_back(x-1, false);
  }

  int shortestLen;
  auto d2cnt1 = bfs(G, s, t, shortestLen);
  auto d2cnt2 = bfs(G, t, s, shortestLen);

  ll ans = 0;

  rep(i, N) {
    if(shortestLen-i-2 >= 0)
      ans += (ll)d2cnt1[i] * d2cnt2[shortestLen-i-2];
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 11796
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;

int n, K, a[100000], b[100000];
ll ans = 0;

int main() {
	cin >> n >> K;

	for (int i = 0; i < n; i++) {
		cin >> a[i] >> b[i];
	}

	for (int i = 0; i < n; i++) {
		bool flag = true;

		for (int j = 0; j < 30; j++) {
			if (((K >> j) & 1) == 0 && ((a[i] >> j) & 1) == 1)flag = false;
		}
		if (flag) {
			ans += b[i];
		}
	}

	for (int i = 0; i < 30; i++) {
		ll costsum = 0;

		if ((K >> i) & 1 == 1) {//(i+1)桁目を0にしたことのみを考える

			for (int j = 0; j < n; j++) {
				bool flag = true;
				for (int k = i; k < 30; k++) {
					if ((((K >> k) & 1) == 0 || k == i) && ((a[j] >> k) & 1) == 1) {
						flag = false;
					}
				}
				if (flag) {
					costsum += b[j];
				}
			}
		}

		ans = max(ans, costsum);
	}

	cout << ans << endl;
}

Measured memory_bytes: 1152
n,m=map(int,input().split())

p = 10 ** 9 + 7
N = 10 ** 5  # N は必要分だけ用意する
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用

for i in range(2, N + 1):
	fact.append((fact[-1] * i) % p)
	inv.append((-inv[p % i] * (p // i)) % p)
	factinv.append((factinv[-1] * inv[-1]) % p)

if n==m:
	#2つ交互にならべる
	#oxoxoxoxoxox...ox これを2倍したのが答え.
	print(fact[n]*fact[n]*2 % p)
elif n+1==m:
	#犬が1匹多い
	#oxoxoxoxox....oxo.
	print(fact[n]*fact[m] % p)
elif n==m+1:
	print(fact[n]*fact[m] % p)
else:
	print(0)

Measured memory_bytes: 15276
#include<bits/stdc++.h>
#include<math.h>
#define rep(i,k,n) for(int i=k;i<n;i++)
#define ll long long
#define MOD 1000000007ll
#define ROD 1000000009ll
#define INF 1e18
#define MIN(a,b) (a>b?b:a)
using namespace std;
#define mp make_pair
#define pb push_back
#define  piii pair<pair<ll,ll>,ll>
#define pii pair<ll,ll>
#define fi first
#define se second
#define MAXN 1000055

int main()
{
	ll n;
	scanf("%lld",&n);
	//cout<<(1&3)<<" ";
	if(__builtin_popcount(n)==1||n<3)
	{
		printf("No\n");
	}
	else if((n&3)==3)
	{
		printf("Yes\n");
		cout<<"1 2\n"<<"2 3\n"<<"3 "<<n+1<<"\n"<<n+1<<" "<<n+2<<"\n"<<n+2<<" "<<n+3<<"\n";
		ll pos=3;
		while(n!=pos)
		{
			cout<<n+pos<<" "<<pos+1<<"\n";
			cout<<pos+1<<" "<<pos+2<<"\n";

			cout<<pos+2<<" "<<pos+3<<"\n";
			cout<<pos+3<<" "<<pos+4<<"\n";
			cout<<pos+4<<" "<<n+pos+1<<"\n";
			cout<<n+pos+1<<" "<<n+pos+2<<"\n";
			cout<<n+pos+2<<" "<<n+pos+3<<"\n";
			cout<<n+pos+3<<" "<<n+pos+4<<"\n";
			pos+=4;
		}
	}
	else if((n&3)==0)
	{
		printf("Yes\n");
		cout<<"1 2\n"<<"2 3\n"<<"3 "<<n+1<<"\n"<<n+1<<" "<<n+2<<"\n"<<n+2<<" "<<n+3<<"\n";
		ll pos=3;
		while(n-1!=pos)
		{
			cout<<n+pos<<" "<<pos+1<<"\n";
			cout<<pos+1<<" "<<pos+2<<"\n";

			cout<<pos+2<<" "<<pos+3<<"\n";
			cout<<pos+3<<" "<<pos+4<<"\n";
			cout<<pos+4<<" "<<n+pos+1<<"\n";
			cout<<n+pos+1<<" "<<n+pos+2<<"\n";
			cout<<n+pos+2<<" "<<n+pos+3<<"\n";
			cout<<n+pos+3<<" "<<n+pos+4<<"\n";
			pos+=4;
		}

		ll low=(n&-n);
		ll high=n^(n&-n);
		low=n+low+1;
		cout<<n<<" "<<low<<"\n";
		cout<<high<<" "<<2*n<<"\n";
		
	}
	else if((n&3)==1)
	{
		printf("Yes\n");
		cout<<"1 2\n"<<"2 3\n"<<"3 "<<n+1<<"\n"<<n+1<<" "<<n+2<<"\n"<<n+2<<" "<<n+3<<"\n";
		ll pos=3;
		while(n-2!=pos)
		{
			cout<<n+pos<<" "<<pos+1<<"\n";
			cout<<pos+1<<" "<<pos+2<<"\n";

			cout<<pos+2<<" "<<pos+3<<"\n";
			cout<<pos+3<<" "<<pos+4<<"\n";
			cout<<pos+4<<" "<<n+pos+1<<"\n";
			cout<<n+pos+1<<" "<<n+pos+2<<"\n";
			cout<<n+pos+2<<" "<<n+pos+3<<"\n";
			cout<<n+pos+3<<" "<<n+pos+4<<"\n";
			pos+=4;
		}
		cout<<n-1<<" "<<n<<"\n";
		cout<<n<<" "<<1<<"\n";
		cout<<1<<" "<<n+n-1<<"\n";
		cout<<n+n-1<<" "<<n+n<<"\n";
	}
	else if((n&3)==2)
	{
		printf("Yes\n");
		cout<<"1 2\n"<<"2 3\n"<<"3 "<<n+1<<"\n"<<n+1<<" "<<n+2<<"\n"<<n+2<<" "<<n+3<<"\n";
		ll pos=3;
		while(n-3!=pos)
		{
			cout<<n+pos<<" "<<pos+1<<"\n";
			cout<<pos+1<<" "<<pos+2<<"\n";

			cout<<pos+2<<" "<<pos+3<<"\n";
			cout<<pos+3<<" "<<pos+4<<"\n";
			cout<<pos+4<<" "<<n+pos+1<<"\n";
			cout<<n+pos+1<<" "<<n+pos+2<<"\n";
			cout<<n+pos+2<<" "<<n+pos+3<<"\n";
			cout<<n+pos+3<<" "<<n+pos+4<<"\n";
			pos+=4;
		}
		
		cout<<n-1-1<<" "<<n-1<<"\n";
		cout<<n-1<<" "<<1<<"\n";
		cout<<1<<" "<<n+n-1-1<<"\n";
		cout<<n+n-1-1<<" "<<n+n-1<<"\n";
		
		cout<<n<<" "<<n-1<<"\n";
		cout<<2<<" "<<2*n<<"\n";
	}
}


Measured memory_bytes: 3672
#include <bits/stdc++.h>
#define int long long int
#define endl "\n"
using namespace std;
void solve()
{
	//Enter your code here Tanmay:)
	int n,a;
	cin>>n>>a;
	int arr[a];
	int sum=0;
	for(int i=0;i<a;i++)
	{
		cin>>arr[i];
		sum+=arr[i];
	}
	
	
	if(sum>=n)
		cout<<"Yes";
	else
		cout<<"No";
}
signed main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t=1;
	//cin>>t;
	while(t--)
	{
		solve();
	}
	return 0;
}
/*
int eulortotent(int n)
     {
    //Enter your code here Tanmay:)
    int total=n;
        for(int p=2;p*p<=n;p++)
        {
            if (n%p==0)
        {
            total /= p;
            total *= (p-1);
            while ( n % p == 0 ) 
                n /= p;
        }
    }

    if(n>1)
    {
        total/=n;
        total*=(n-1);
    }

  return total;
}
*/

Measured memory_bytes: 1024