akhauriyash/Code-Regression huggingface dataset:
N = int(input())
A = [0] + list(map(int, input().split()))
diff = []
for i in range(N):
  diff.append(abs(A[i]-A[i+1]))

diff.append(abs(A[-1]))

A += [0]
s = sum(diff)
for i in range(N):
  v = s - diff[i] - diff[i+1]
  v += abs(A[i] - A[i+2])
  print(v)

Measured memory_bytes: 14048
N = int(input())

d = [[0]*10 for i in range(10)]
for n in range(1,N+1):
    s = str(n)
    d[int(s[0])][int(s[-1])] += 1
ans = 0
for i in range(10):
    for j in range(10):
        ans += d[i][j] * d[j][i]
print(ans)

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

using namespace std;

const int maxn = 2e5 + 5;

vector <int> g[maxn];
int d[maxn];
bool vis[maxn];

void dfs(int u,int cnt) {
	vis[u] = 1;
	d[u] += cnt;
	for(int i = 0 ; i < g[u].size(); i++) {
		int v= g[u][i];
		if(!vis[v])dfs(v,d[u]);
	}
}



int main() {
	int n,q;
	ios::sync_with_stdio(0);
	cin >> n >> q;
	int t = n - 1;
	while(t--) {
		int u,v;
		cin >> u >> v;
		g[u].push_back(v);
	}
	while(q--) {
		int p,v;
		cin >> p >> v;
		d[p] += v;
	}
	dfs(1,0);
	for(int i = 1; i <= n; i++) {
		if(i > 1) cout << " ";
		cout << d[i];
	}
	return 0;
}

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

int main(){
  int N;
  cin >> N;
  vector<vector<int>> vec(N,vector<int>(2));
  for(int i=0; i<N; i++){
    for(int j=0; j<2; j++){
      cin >> vec.at(i).at(j);
    }
  }
  
  int ans = 0;
  
  for(int k=0; k<N; k++){
    ans = ans + vec.at(k).at(1) - vec.at(k).at(0) + 1;
  }
  
  cout << ans << endl;
    
}

Measured memory_bytes: 256
# coding: utf-8
# Your code here!

#n,l = [int(i) for i in input().split()]

n = int(input())
ab = [[int(i) for i in input().split()] for j in range(n)] 
ab.sort(key = lambda x: x[1])


now = 0
for a,b in ab:
    now += a
    if now > b:
        print("No")
        break
else: print("Yes")
    









Measured memory_bytes: 41180
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define MOD1 1000000007
#define MOD2 998244353
#define LIMIT1 200002
#define LIMIT2 500002
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(i=0;i<n;i++)
#define max(a,b) ((a)>(b) ? (a) : (b))
#define min(a,b) ((a)<(b) ? (a) : (b))
#define zt(a,b) (max(a,b)-min(a,b))
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll nPr(int n,int r){ll i,result=1;rep(i,r){result*=(ll)(n-i);}return result;}
ll nCr(int n,int r){ll i,result=1; rep(i,min(r,n-r)){result*=(ll)(n-i);result/=(ll)(i+1);}return result;}
#define fact(n) nPr((int)n,(int)n)
#define nHr(n,r) nCr((int)(n+r+1),(int)r)
#define sankaku(x) ((1+x)*x)/2
int dx[8]={1,0,-1,0,1,-1,-1,1};
int dy[8]={0,1,0,-1,1,1,-1,-1};
int upint(const void *a, const void *b) { return *(int *)a < *(int *)b ? -1 : *(int *)a > *(int *)b ? 1 : 0; }
int downint(const void *a, const void *b) { return *(int *)a < *(int *)b ? 1 : *(int *)a > *(int *)b ? -1 : 0; }
int upchar(const void* left, const void* right) {return strcmp((char *)left,(char *)right);}
int downchar(const void* left, const void* right) {return strcmp((char *)right,(char *)left);}
void initialize(){
  
}
void swap(ll *p,ll *q){
  ll tmp;
  tmp = *p;
  *p = *q;
  *q = tmp;
}
int main(void){
  initialize();
  ll n,m,i,j,result=0,sum=0;
  int a[LIMIT1];
  char s[LIMIT1];

  scanf("%lld %lld",&n,&m);
  rep(i,n){
    scanf("%d",&a[i]);
    sum+=a[i];
  }
  
  qsort(a,n,sizeof(int),downint);
  
  if(a[m-1] >= 1.0/(4.0*m)*sum) printf("Yes");
  else printf("No");

  return 0;
}



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

int main() {
    ios::sync_with_stdio(false);
    string s;
    int ans= 0;
    cin >> s;
    for (int i = 0; i < s.size(); i++)
        if (s[i] == '1')
            ans++;
    
    cout << ans << '\n';
    
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = (a); i <= (b); i++)
#define rng(a) a.begin(), a.end()
#define ina(n,a) cin >> n; for(int i = 1; i <= n; i++) cin >> a[i]
#define sz(x) (int)(x).size()
#define se second
#define fi first
#define prev            coyhhhhhhyoc    
#define next          sdNNNmNNNNNNNmds  
#define y0           hNNNNy_yNNNNNN_sNh
#define y1          mNNNNNdtdNNNNNNtsNNm
#define yn          mNNNNNNNNy___smNNNms
#define tm            oooooosyysooooot 
#define read               tyhyt        
#define rank              ytmNmo         
#define index              yyy
#define pb push_back
#define pcnt __builtin_popcountll
#define rrep(i,a,b) for(int i = (b); i >= (a); i--)
#define rall(x,a) for(auto x : a)
#define MOD 1000000007
#define endl "\n"
typedef long long ll;
using namespace std;

const int W = 1111;
int a[W][W], sum[W][W];
int h, w, k;

int getSum(int x1, int y1, int x2, int y2) {
    return sum[x2][y2] - sum[x1 - 1][y2] - sum[x2][y1 - 1] + sum[x1 - 1][y1 - 1];
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> h >> w >> k;
    rep(i, 1, h) {
        string s;
        cin >> s;
        rep(j, 1, w) {
            a[i][j] = s[j - 1] - '0';
            sum[i][j] = sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + a[i][j];
        }
    }
    int ans = 1e9;
    rep(mask, 0, (1 << (h - 1)) - 1) {
        int cnt = 0, left = 1;
        rep(j, 1, w) {
            int top = 1;
            bool ok = true;
            rep(i, 1, h) {
                if(mask & (1 << (i - 1))) {
                    if(getSum(top, left, i, j) > k) {
                        ok = false;
                        break;
                    }
                    top = i + 1;
                }
            }
            if(getSum(top, left, h, j) > k) {
                ok = false;
            }
            if(!ok) {
                if(left == j) {
                    cnt = -1;
                    break;
                }
                left = j;
                cnt++;
                j--;
            }
        }
        if(cnt != -1) {
            ans = min(ans, cnt + pcnt(mask));
        }
    }
    cout << ans << endl;
    return 0;
}


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

int main() {
	int n, x, t;
	cin >> n >> x >> t;
	int ans = 0;
	while (n > 0) {
		n -= x;
		ans += t;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3628
#include<stdio.h>
#define N 8
#define M 4

int CalcurateInteger(int);
double CalcurateDecimal(double);

int Integer[N], Decimal[M];

int main(){
  int i, x, integer;
  double n, y, decimal;

  while(1){
    scanf("%lf", &n);
    if(n < 0) break;

    integer = (int)n;
    decimal = n - (double)integer;

    for(i=0; i<N; i++) Integer[i] = 0;
    for(i=0; i<M; i++) Decimal[i] = 0;

    x = CalcurateInteger(integer);
    y = CalcurateDecimal(decimal);

    if(x == 0 && y == 0){
      for(i=N-1; i>=0; i--)
	printf("%d", Integer[i]);
      printf(".");
      for(i=0; i<M; i++)
	printf("%d", Decimal[i]);
      printf("\n");
    }else{
      printf("NA\n");
    }
  }

  return 0;
}

int CalcurateInteger(int n){
  int i, j, m;

  for(i=0, j=2; i<N; i++, j*=2){
    if(n == 0) break;
    m = n % j;
    Integer[i] = m * 2 / j;
    n -= m;
  }
  return n;
}

double CalcurateDecimal(double n){
  int i;
  double j, m;

  for(i=0, j=0.5; i<M; i++, j/=2){
    if(n == 0) break;
    m = n - j;
    if(m >= 0){
      Decimal[i] = 1;
      n = m;
    }
  }
  return n;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
 
using namespace std;
 
#define ss second
#define ff first
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define all(a) (a).begin(),(a).end()
#define rep(i,a,b) for(int (i) = (a); (i) < (b); (i)++)
#define debug(x) cout << #x << " = " << x << endl
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using ll = long long;
using ii = pair<int,int>;
using vi = vector<int>;
using vll = vector<ll>;
using vii = vector<pair<int,int>>;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3fLL;
const int maxn = 1e3+10;


int main(int argc,const char** argv){

	fastio;

	int mat[3][3];
	vi a(3,0),b(3,0);

	rep(i,0,3){
		rep(j,0,3){
			cin >> mat[i][j];
		}
	}

	rep(i,0,3){
		rep(j,0,3){
			if(i == 0) b[j] = mat[i][j];
			else a[i] = mat[i][j] - b[j];
		}
	}

	bool rigth = true;

	rep(i,0,3){
		rep(j,0,3){
			if(a[i] + b[j] != mat[i][j]) rigth = false;
		}
	}

	cout << (rigth ? "Yes" : "No") << '\n';

	return 0;
}

Measured memory_bytes: 256
n = int(input())
xs = []
zs = []
for i in range(n):
    x,y,h = list(map(int,input().split()))
    if h == 0:
        zs.append((x,y,h))
    else:
        xs.append((x,y,h))

for i in range(101):
    for j in range(101):
        top = -1
        ans = True
        for x,y,h in xs:
            if top == -1:
                top = h + abs(x-i) + abs(y-j)
            if top != h + abs(x-i) + abs(y-j):
                ans = False
                break
        for x,y,h in zs:
            if top - abs(x-i) - abs(y-j) > 0:
                ans = False
                break
        if ans:
            break
    if ans:
        break
if top == -1:
    top = 1
print(i,j,top)


Measured memory_bytes: 43632
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
  ll n;
  cin>>n;
  ll i,a[n],d,sum=0;
  for(i=0;i<n;i++) cin>>a[i];
  sort(a,a+n);
  
  if(a[0]>=0)
  {
    for(i=1;i<n;i++) sum+=a[i];  
    sum-=a[0];
    cout<<sum<<endl;
    if(n==2)
    {
        cout<<a[1]<<" "<<a[0]<<endl;
        return 0;
    }
    cout<<a[0]<<" "<<a[1]<<endl; 
    d=a[0]-a[1];
    for(i=2;i<n-1;i++)
    {
        cout<<d<<" "<<a[i]<<endl;
        d-=a[i];
    }
    cout<<a[n-1]<<" "<<d<<endl; 
  }
  else if(a[n-1]<=0)
  {
    for(i=0;i<n-1;i++) sum-=a[i];
    sum+=a[n-1];
    cout<<sum<<endl;
    cout<<a[n-1]<<" "<<a[n-2]<<endl;
    d=a[n-1]-a[n-2];
    for(i=n-3;i>=0;i--)
    {
      cout<<d<<" "<<a[i]<<endl;
      d=d-a[i];
    }
  }
  else
  {
      for(i=0;i<n;i++)
      {
          if(a[i]<0) sum-=a[i];
          else sum+=a[i];
      }
      cout<<sum<<endl;
      ll j=0;
      while(a[j]<0) j++;
      if(j==n-1)
      {
        cout<<a[n-1]<<" "<<a[n-2]<<endl;
        d=a[n-1]-a[n-2];
        for(i=n-3;i>=0;i--)
        {
            cout<<d<<" "<<a[i]<<endl;
            d-=a[i];
        }
        return 0;
      }
      cout<<a[0]<<" "<<a[j]<<endl;
      d=a[0]-a[j];
      for(i=j+1;i<n-1;i++)
      {
          cout<<d<<" "<<a[i]<<endl;
          d-=a[i];
      }
      cout<<a[n-1]<<" "<<d<<endl;
      d=a[n-1]-d;
      j=1;
      while(a[j]<0)
      {
          cout<<d<<" "<<a[j]<<endl;
          d-=a[j];
          j++;
      }
  }
 return 0;
}


Measured memory_bytes: 2688
N=int(input())
*A,=map(int,input().split())
M=max(A)
B=[1]*(M+1)
B[0]=B[1]=1
i=2
while i<=M:
    if B[i]:
        j=2
        while i*j<=M:
            B[i*j]=0
            j+=1
    i+=1

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

from math import*
now=A[0]
for a in A:
    now=gcd(now,a)
if now==1:
    ans='pairwise coprime'
    i=2
    while i<=M:
        if B[i]:
            count=0
            j=1
            while i*j<=M:
                count+=C[i*j]
                j+=1
            if count>1:
                ans='setwise coprime' 
        i+=1
    print(ans)
else:
    print('not coprime')

Measured memory_bytes: 127432
#include <iostream>

using namespace std;

int n, m, ans, table[9][9];

int chack(){
	int res=1;
	for(int i=0; i<n; i++){
		int tmp=0;
		for(int j=0; j<n; j++){
			tmp += table[i][j];
		}
		if(tmp){
			res = 0;
			break;
		}
	}
	return res;
}


void solve(int x, int y){
	if(y < n-1) y++;
	else if(x < n-1){
		y=0;
		x++;
	} else {
		ans += chack();
		return;
	}
	
	if(y==0 && 0<x){
		int tmp =0;
		for(int i=0; i<n; i++) tmp +=table[x-1][i];
		if(tmp) return;
	}
	

	if(table[x][y] == 0 && x != y){
		table[x][y] = 1;
		table[y][x] = -1;

		solve(x, y);

		table[x][y] = -1;
		table[y][x] = 1;
		solve(x, y);

		table[x][y] = table[y][x] = 0;
	} else solve(x, y);
}


int main(void) {
	while(1) {
		cin >> n;
		if(!n) break;
		fill(table[0], table[8], 0);
		cin >> m;
		for(int i=0; i<m; i++){
			int x, y; cin >> x >> y;
			x--; y--;
			table[x][y] = 1;
			table[y][x] = -1;
		}

		int x, y;
		for(int i=0; i<n; i++){
			for(int j=0; j<n; j++){
				if(table[i][j]==0 && i != j){
					x = i;
					y = j-1;
					goto AA;
				}
			}
		}
	AA:

		ans = 0;
		solve(x, y);
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 3064
import java.util.*;
public class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		String ans = "No";
		if(A == B && A != C || A == C && A != B || C == B && C != A){
			ans = "Yes";
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 21844
#include<iostream>
using namespace std;
int main(){
    int n;
    cin>>n;
    int c=n+1,d=0,a,f,ff,ans=0;
    for(int i=0;i<n;i++){
        cin>>a;
        if(a>c){
            if(f){
                ans++;
            }
            else f=1;
        }
        else f=0;
        c=a;
        if(a<d){
            if(ff){
                ans++;
            }
            else ff=1;
        }
        else ff=0;
        d=a;
    }
    cout<<ans<<endl;
    return 0;
}


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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define sf scanf
#define pf printf
#define pb push_back
#define mp make_pair
#define PI ( acos(-1.0) )
#define mod 1000000007LL
#define maxn 100005
#define IN freopen("C.in","r",stdin)
#define OUT freopen("output.txt","w",stdout)
#define FOR(i,a,b) for(i=a ; i<=b ; i++)
#define DBG pf("Hi\n")
#define INF 1000000000
#define i64 long long int
#define eps (1e-8)
#define xx first
#define yy second
#define ln 17
#define off 2

using namespace __gnu_pbds;
using namespace std ;

typedef tree< i64, null_type, less<i64>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

int main()
{
    i64 a , b , c , d , n ;

    scanf("%lld %lld %lld %lld",&a,&b,&c,&d) ;
    scanf("%lld",&n) ;

    b = min(a*2,b) ;
    c = min(c,b*2) ;
    d = min(d,c*2) ;

    printf("%lld\n", (n/2)*d + (n%2)*c ) ;

    return 0 ;
}


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

typedef long long ll;

using namespace std;

ll MAX = 1e9+1;
const int MOD = 1e9 + 7;

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

    vector< vector<int> > graph(n, vector<int>(n));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            int x;
            cin >> x;
            graph[i][j] = x;
        }
    }

    vector<int> dp(1 << n); // dp[mask] denotes the number of ways to match [mask] subset
    dp[0] = 1; // 1 way to match when no women are paired
    // mask denotes the subset of women who are available. 0 means not paired

    for (int mask = 0; mask < (1 << n)-1; mask++) {
        int man = __builtin_popcount(mask);
        for (int woman = 0; woman < n; woman++) {
            if ((graph[man][woman]) && !(mask & (1 << woman))) {
                // man and woman are compatible and woman is free
                int mask2 = mask ^ (1 << woman);
                dp[mask2] += dp[mask];
                if (dp[mask2] >= MOD)
                    dp[mask2] -= MOD;
            }
        }
    }

    cout.precision(20);
    cout << dp[(1<<n) - 1]%MOD << endl;
}


int main() {
    solve();
	return 0;
}




Measured memory_bytes: 8448
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <list>
#include <stack>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#include <functional>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi   vector<int> 
#define   co(x)  cout << x << '\n' 
#define   dbg(x)  cerr << #x << " = " << x << '\n' 
#define   bitcount(x)  (int)__builtin_popcount(x) 
#define   sz(x)  (int)x.size()
#define   all(a) a.begin(),a.end() 
#define   ff   first
#define   ss   second
#define   pii  pair<int,int> 
#define   lcm(a,b) (a*b)/__gcd(a,b) 
using namespace std;

inline void solve(){ 
    map <int,int> pref ; 
    int  n, d, distroy, ans = 0 ; 
    cin >> n >> d >> distroy ; 
    int x[n],h[n];
    vector <pii> v(n);
    for (int i=0;i<n;i++) { 
    	cin >> v[i].ff >> v[i].ss ; 
    	pref[v[i].ff] = 0 ; 
    } 
    sort(all(v));
    for (int i=0;i<n;i++){
    	x[i] = v[i].ff;
    	h[i] = v[i].ss;
    }
    for (int i=0;i<n;i++) { 
    	h[i] -= pref[x[i]]; 
    	if (h[i]>0){
    		int c = (h[i]+distroy-1)/distroy ; 
    		int r = x[i] + d + d +1 ; 
    		pref[x[i]] += c * distroy ; 
    		pref[r] -= c * distroy ; 
    		h[i] = 0 ; 
    		ans += c ; 
    		//cout << "ans = "<<ans << " health " << h[i] <<endl;
    	}
    	int pre = -1 ; 
    	for (auto &it: pref){ 
    		if (pre != -1){
    			pref[it.ff] += pref[pre] ; 
    			pref.erase(pre) ; 
    			if (i == n-1 or it.ff >= x[i+1]) break ; 
    		} 
    		pre = it.ff ; 
    		//cout << it.ff << " " << it.ss << endl;
    	}
    }
    co ( ans ) ; 
}

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


Measured memory_bytes: 21940
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,s,e) for(int i=s;i<e;i++)
#define reple(i,s,e) for(int i=s;i<=e;i++)
#define revrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()

const int MAX = 510000;

vector<ll> 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;
        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;
}


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

    COMinit();

    ll ans = 0;

    rep(i, min(N, K + 1))
    {
        ll tmp = 0;
        tmp += COM(N, i) * COM(N - 1, N - i - 1);
        tmp %= MOD;

        ans += tmp;
        ans %= MOD;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 12288
#include <iostream>

using namespace std;

int main()
{
	int N, M;
	string s[100];
	string t[100];
	int YEN[100] = {0};
	int count_T[100] = {0};
	int max = 0;

	cin >> N;	
	for (int i = 0; i < N; i++) {
		string tmp;
		cin >> tmp;
		s[i] = tmp;
	}	

	cin >> M;	
	for (int i = 0; i < M; i++) {
		string tmp;
		cin >> tmp;
		t[i] = tmp;
	}

	for (int i = 0; i < N; i++) {
		for (int j =0; j < N; j++) {
			if (s[i] == s[j]) {
				YEN[i]++;
			}
		}
	}

	for (int i = 0; i < M; i++) {
		for (int j =0; j < M; j++) {
			if (t[i] == t[j]) {
				count_T[i]++;
			}
		}
	}

	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++) {
			if (s[i] == t[j]) {
				YEN[i]--;	
			}
		}
	}
	for (int i = 0; i < N; i++) {
		// cout << s[i] << "の値段" << YEN[i] << "円\n";
		if (YEN[i]	> max) 
			max = YEN[i];
	}
	cout << max << '\n';
}

Measured memory_bytes: 3612
#include <stdio.h>
#include <math.h>

int main(){
  long long int n,k,tmp;
  scanf("%lld",&n);
  long long int min=n+2;
  long long int i,j;
  for(i=1;i<=sqrt(n);i++){
    if(n%i==0){
      k=n/i;
      tmp=k+i;
      if(min>tmp){
        min=tmp;
      }
    }
  }
  printf("%lld\n",min-2);
  return 0;
}


Measured memory_bytes: 128
#include<iostream>
using namespace std;
int main() {
	int n, m;
	while (cin >> n >> m, n, m) {
		pair<int, int>p[10010];
		bool b1[510], b2[510];
		for (int i = 1; i <= n; i++) { b1[i] = false; b2[i] = false; }
		for (int i = 0; i < m; i++)cin >> p[i].first >> p[i].second;
		for (int i = 0; i < m; i++) {
			if (p[i].first == 1)b1[p[i].second] = true;
			if (p[i].second == 1)b1[p[i].first] = true;
		}
		for (int i = 0; i < m; i++) {
			if (b1[p[i].first])b2[p[i].second] = true;
			if (b1[p[i].second])b2[p[i].first] = true;
		}
		int cnt = 0;
		for (int i = 2; i <= n; i++)if (b1[i] || b2[i])cnt++;
		cout << cnt << endl;
	}
}

Measured memory_bytes: 3128
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;
using ll = long long;

int main()
{
  string S; cin >> S;
  cout << (S.find("AC") != string::npos ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(W, H, P, Q):
    ans = sum(P) + sum(Q)

    P.sort()
    Q.sort()
    for q in Q:
        i = bisect.bisect_left(P, q)
        ans += q * (len(P)-i)
    for p in P:
        i = bisect.bisect_right(Q, p)
        ans += p * (len(Q)-i)

    return ans


def main():
    W, H = read_int_n()
    P = [read_int() for _ in range(W)]
    Q = [read_int() for _ in range(H)]
    print(slv(W, H, P, Q))


if __name__ == '__main__':
    main()


Measured memory_bytes: 14048
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define rep(i,n); for(long long i = 0;i < (n);i++)
using ll = long long;
using P = pair<long long,long long>;
template <class T> using vec = vector<T>;
const ll mod = 1e9+7;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n,k; cin >> n >> k;
    vec<ll> a(n); rep(i,n)cin >> a[i];
    ll res = 1;
    if(n == k){
        rep(i,n){
            res *= a[i];
            res %= mod;
        }
        cout << (res+mod)%mod << endl;
        return 0;
    }
    sort(a.begin(),a.end());
    if(a[n-1] <= 0){
        if(k%2== 1)reverse(a.begin(),a.end());
        rep(i,k){
            res *= a[i];
            res %= mod;
        }
        cout << (res+mod)%mod << endl;
        return 0;
    }
    vec<ll> a_p,a_m;
    rep(i,n){
        if(a[i] < 0)a_m.emplace_back(-a[i]);
        else if(a[i] > 0)a_p.emplace_back(a[i]);
    }
    reverse(a_p.begin(),a_p.end());
    if(k%2 == 0){
        vec<ll> b;
        for(ll i = 1;i < a_p.size();i += 2)b.emplace_back(a_p[i-1] * a_p[i]);
        for(ll i = 1;i < a_m.size();i += 2)b.emplace_back(a_m[i-1] * a_m[i]);
        sort(b.rbegin(),b.rend());
        if(b.size() < k/2){
            cout << 0 << endl;
            return 0;
        }
        rep(i,k/2){
            res *= b[i]%mod;
            res %= mod;
        }
    }
    else {
        res *= a_p[0];
        vec<ll> b;
        for(ll i = 2;i < a_p.size();i += 2)b.emplace_back(a_p[i-1] * a_p[i]);
        for(ll i = 1;i < a_m.size();i += 2)b.emplace_back(a_m[i-1] * a_m[i]);
        sort(b.rbegin(),b.rend());
        if(b.size() < k/2){
            cout << 0 << endl;
            return 0;
        }
        rep(i,k/2){
            res *= b[i]%mod;
            res %= mod;
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 8180
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>

using namespace std;

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

	vector<int> a(N, 0);
	for (int i = 0; i < N; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end());

	int n = a.back();

	int diff2 = n*2;

	int r = a[0];
	for (auto x : a) {
		if (abs(2*x - n) < abs(2*r - n)) {
			r = x;
		}
	}
	cout << n << " " << r << endl;
	return 0;
}


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

void string_reverse(char s[]){

#if 0
    const size_t len = strlen(s);
    char tmp = {0};
    int i = 0;
    for(int j = len - 1; j > (len - 1) / 2; --j){
        tmp = s[j];
        s[j] = s[i];
        s[i] = tmp;
        i++;
    }
#endif

#if 1
	int size = strlen(s);
	int i,j;
	char tmp = {0};

	for(i = 0, j = size - 1; i < size / 2; i++, j--){
		tmp = s[i];
		s[i] = s[j];
		s[j] = tmp;
	}
#endif

}

int main(){
    char s[100005];
    //size_t len = sizeof(s) / sizeof(s[0]);
    char a[] = "maerd", b[] = "remaerd", c[] = "esare", d[] = "resare";

    scanf("%s", s);

#if 0
    int size = 0;
    while(s[size] != '\0'){
        size++;
    }
    char s_rev[100005];
    int i = 0;
    for(int j = size - 1; j >= 0; --j){
        s_rev[i] = s[j];
        i++;
    }
    s_rev[i] = '\0';
#endif

    size_t len = strlen(s);

    string_reverse(s);

    int j = 0;
    int flag = 0;
    while(s[j] != '\0'){
        int k = 0;
        flag = 0;
        if(s[j] != '\0' && flag == 0){
            while(a[k] != '\0'){
                if(s[j + k] == a[k]){
                    flag = 1;
                    k++;
                }else{
                    flag = 0;
                    k = 0;
                    break;
                }
            }
            if(flag == 1){
                j += k;
                k = 0;
            }
        }
        if(s[j] != '\0' && flag == 0){
            while(b[k] != '\0'){
                if(s[j + k] == b[k]){
                    flag = 1;
                    k++;
                }else{
                    flag = 0;
                    k = 0;
                    break;
                }
            }
            if(flag == 1){
                j += k;
                k = 0;
            }
        }
        if(s[j] != '\0' && flag == 0){
            while(c[k] != '\0'){
                if(s[j + k] == c[k]){
                    flag = 1;
                    k++;
                }else{
                    flag = 0;
                    k = 0;
                    break;
                }
            }
            if(flag == 1){
                j += k;
                k = 0;
            }
        }
        if(s[j] != '\0' && flag == 0){
            while(d[k] != '\0'){
                if(s[j + k] == d[k]){
                    flag = 1;
                    k++;
                }else{
                    flag = 0;
                    k = 0;
                    break;
                }
            }
            if(flag == 1){
                j += k;
                k = 0;
            }
        }
        if(flag == 0) break;
    }

    if(flag == 1) puts("YES");
    else puts("NO");

    return 0;
}

Measured memory_bytes: 1720
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll ,ll>;
using T = tuple<ll, ll, ll>;
const ll INF = 1LL<<61LL;
const ll MOD = 1e9+7;

int main(){
  ll N, L;
  cin >> N >> L;
  vector<ll> a(N);
  for(int i=0;i<N;i++)
    cin >> a[i];
  for(int i=0;i<N-1;i++){
    ll now = a[i] + a[i+1];
    if(now >= L){
      cout << "Possible" << endl;
      for(int j=0;j<i;j++)
	cout << j+1 << endl;
      for(int j=N-2;j>=i+1;j--)
	cout << j+1 << endl;
      cout << i+1 << endl;
      return 0;
    }
  }
  cout << "Impossible" << endl;
}


Measured memory_bytes: 1664
#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#include<ctime>
#include<set>
#include<map>
#include<queue>
#include<stack>
#define sqr(x) ((x)*(x))
#define fz1(i,n) for ((i)=1;(i)<=(n);(i)++)
#define fd1(i,n) for ((i)=(n);(i)>=1;(i)--)
#define fz0g(i,n) for ((i)=0;(i)<=(n);(i)++)
#define fd0g(i,n) for ((i)=(n);(i)>=0;(i)--)
#define fz0k(i,n) for ((i)=0;(i)<(n);(i)++)
#define fd0k(i,n) for ((i)=(long long)((n)-1);(i)>=0;(i)--)
#define fz(i,x,y) for ((i)=(x);(i)<=(y);(i)++)
#define fd(i,y,x) for ((i)=(y);(i)>=(x);(i)--)
#define fzin fz1(i,n)
#define fzim fz1(i,m)
#define fzjn fz1(j,n)
#define fzjm fz1(j,m)
#define ff(c,itr) for (__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define rdst(st,len){static char ss[len];scanf(" %s",ss);(st)=ss;}
#define inc(x,y) {x+=(y);if(x>=mod)x-=mod;}
#define dec(x,y) {x-=(y);if(x<0)x+=mod;}
using namespace std;
int n,m,a,b,i,j;
int main()
{
	scanf("%d%d%d%d",&n,&m,&b,&a);
	fz1(i,n){
		fz1(j,m){
			putchar('0'+((i<=a)^(j<=b)));
		}
		puts("");
	}
	return 0;
}

Measured memory_bytes: 1280
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int i,j;
  int n;
  int a;
  vi v(2,0);
  cin>>n;
  rep(i,n){
    cin>>a;
    v[a%2]++;
  }
  if(v[1]%2)cout<<"NO"<<endl;
  else cout<<"YES"<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define P(x) cout << x << endl
#define D(x) P(#x << ": " << x)
#define F(i,n) for (int i=0; i<(int)(n); i++)
#define DEC(i,n) for (int i=(int)(n); --i>=0;)
#define pb push_back
#define all(v) v.begin(), v.end()
using namespace std;
void MI(int &a, int v) {a = min(a,v);}
void MA(int &a, int v) {a = max(a,v);}

deque<int> seq(int n) {
    if (n == 1) return {};
    if (n % 2) {
        deque<int> res = seq(n-1);
        res.push_front(res.size());
        return res;
    } else {
        deque<int> res = seq(n/2);
        res.push_back(res.size());
        return res;
    }
}

signed main() {
    int n; cin>>n;
    deque<int> res = seq(n+1);
    int l = res.size();
    DEC(i,l) res.push_front(i);
    P(2*l);
    F(i,2*l) cout<<res[i]+1<<" \n"[i==2*l-1];
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int W, H, x, y, r;
    cin >> W >> H >> x >> y >> r;
    
    if(0 <= x-r && 0 <= y-r && W >= x+r && H >= y+r ){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    
}



Measured memory_bytes: 3100
#include<bits/stdc++.h>
#define ll long long
#define Test int t;cin>>t;while(t--)
#define PI acos(-1)
#define endl "\n"
#define fx(x) fixed<<setprecision(x)
#define sz(s) s.size()
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
const double eps=1e-9;
const int mod=1e9+7;
int dx[]={-1,-1,-1,0,0,1,1,1};
int dy[]={-1,0,1,-1,1,-1,0,1};
ll gcd(ll x,ll y) {return(!y)?x:gcd(y,x%y);}
ll lcm(ll x,ll y) {return((x/gcd(x,y))*y);}
using namespace std;
void fast(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}
int dp[100001],a[100001];
int main()
{
    int n,k;
    cin>>n>>k;
    for(int i=0;i<n;i++){
        cin>>a[i];
        dp[i]=1e9;
    }
    dp[0]=0;
    for(int i=0;i<n;i++){
        for(int j=1;j<=k;j++){
            if(i+j<n){
                dp[i+j]=min(dp[i+j],dp[i]+abs(a[i+j]-a[i]));
            }
        }
    }
    cout<<dp[n-1];
    return 0;
}


Measured memory_bytes: 4388
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
  ll n;
  cin >> n;
  vector<ll> d1(n),d2(n);
  vector<bool> is(n,false);
  rep(i,n){
    cin >> d1.at(i) >> d2.at(i);
    if(d1.at(i)==d2.at(i)){
      is.at(i)=true;
    }
  }
  string ans="No";
  rep(i,n-2){
    if(is.at(i)==is.at(i+1) && is.at(i+1)==is.at(i+2) && is.at(i)==true){
      ans="Yes";
    }
  }
  cout << ans;
}

Measured memory_bytes: 3644
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>

using namespace std;

void search(int i);

int n, m;
vector<int> a, b;
vector<set<int> > to;
vector<int> list;

int main(){
	cin >> n >> m;
	if(n==2){
		cout << 1 << endl;
		return 0;
	}
	a.resize(m);
	b.resize(m);
	for(int i=0; i<m; i++) cin >> a[i] >> b[i];
	
	to.resize(n);
	for(int i=0; i<m; i++){
		to[a[i]-1].insert(b[i]-1);
		to[b[i]-1].insert(a[i]-1);
	}
	
	list.resize(n-1);
	for(int i=0; i<list.size(); i++) list[i]=i+1;
	int ans=0;
	bool flag;
	do{
		flag=1;
		if(to[0].count(list[0])==0) flag=0;
		for(int i=0; i<list.size()-1; i++){
			if(to[list[i]].count(list[i+1])==0) flag=0;
		}
		
		if(flag) ans+=1;
	}while(next_permutation(list.begin(), list.end()));
	
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MAXN	100005
#define INF	1e9
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
struct info {int pos, home; };
bool operator < (info x, info y) {return x.pos < y.pos; }
int point[MAXN][2], pr[MAXN];
int n, tot, total, root, mx, mn;
int x[MAXN], y[MAXN];
int lc[MAXN], rc[MAXN];
int timer, low[MAXN], dfn[MAXN];
int top, cnt, s[MAXN], belong[MAXN];
bool instack[MAXN];
info b[MAXN];
vector <int> a[MAXN];
void print() {
	for (int i = 1; i <= total; i++) {
		cout << i << ':';
		for (unsigned j = 0; j < a[i].size(); j++)
			cout << a[i][j] << ' ';
		cout << endl;
	}
}
void tarjan(int pos) {
	low[pos] = dfn[pos] = ++timer;
	instack[pos] = true;
	s[++top] = pos;
	for (unsigned i = 0; i < a[pos].size(); i++)
		if (dfn[a[pos][i]] == 0) {
			tarjan(a[pos][i]);
			low[pos] = min(low[pos], low[a[pos][i]]);
		} else if (instack[a[pos][i]]) low[pos] = min(low[pos], dfn[a[pos][i]]);
	if (low[pos] == dfn[pos]) {
		int tmp = s[top--];
		instack[tmp] = false;
		belong[tmp] = ++cnt;
		while (tmp != pos) {
			tmp = s[top--];
			instack[tmp] = false;
			belong[tmp] = cnt;
		}
	}
}
void query(int root, int l, int r, int ql, int qr, int dest) {
	if (l == ql && r == qr) {
		a[dest].push_back(root);
		return;
	}
	int mid = (l + r) / 2;
	if (mid >= ql) query(lc[root], l, mid, ql, min(mid, qr), dest);
	if (mid + 1 <= qr) query(rc[root], mid + 1, r, max(mid + 1, ql), qr, dest);
}
bool check(int d) {
	for (int i = 1; i <= tot; i++)
		a[i].clear();
	int pos = 1;
	for (int i = 1; i <= tot; i++) {
		while (pos <= tot && b[i].pos - b[pos].pos >= d) pos++;
		if (i > pos) query(root, 1, tot, pos, i - 1, pr[b[i].home]);
	}
	pos = tot;
	for (int i = tot; i >= 1; i--) {
		while (pos >= 1 && b[pos].pos - b[i].pos >= d) pos--;
		if (pos > i) query(root, 1, tot, i + 1, pos, pr[b[i].home]);
	}
	timer = cnt = 0;
	memset(low, 0, sizeof(low));
	memset(dfn, 0, sizeof(dfn));
	memset(belong, 0, sizeof(belong));
	for (int i = 1; i <= total; i++)
		if (dfn[i] == 0) tarjan(i);
	for (int i = 1; i <= n; i++)
		if (belong[point[i][0]] == belong[point[i][1]]) return false;
	return true;
}
void build(int root, int l, int r) {
	if (l == r) {
		a[root].push_back(b[l].home);
		return;
	}
	int mid = (l + r) / 2;
	lc[root] = ++total;
	a[root].push_back(lc[root]);
	build(lc[root], l, mid);
	rc[root] = ++total;
	a[root].push_back(rc[root]);
	build(rc[root], mid + 1, r);
}
int main() {
	read(n);
	mx = 0, mn = INF;
	for (int i = 1; i <= n; i++) {
		read(x[i]), read(y[i]);
		mx = max(mx, x[i]);
		mn = min(mn, x[i]);
		mx = max(mx, y[i]);
		mn = min(mn, y[i]);
		point[i][0] = ++tot;
		pr[tot] = tot + 1;
		b[tot] = (info) {x[i], tot + 1};
		point[i][1] = ++tot;
		pr[tot] = tot - 1;
		b[tot] = (info) {y[i], tot - 1};
	}
	sort(b + 1, b + tot + 1);
	total = tot; build(root = ++total, 1, tot);
	int l = 0, r = mx - mn;
	while (l < r) {
		int mid = (l + r + 1) / 2;
		if (check(mid)) l = mid;
		else r = mid - 1;
	}
	cout << l << endl;
	return 0;
}

Measured memory_bytes: 16128
#pragma GCC optimize("Ofast,inline,unroll-loops,fast-math")
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <map>
using namespace std;

map<int, vector<pair<long long, bool> > > f;

int main(void)
{
    int n;
    long long x, d;
    int i, v;
    long long l, r, o;
    map<int, vector<pair<long long, bool> > >::iterator t;

    cin >> n >> x >> d;
    if(!d)
    {
        if(!x)
            cout << 1 << endl;
        else
            cout << n + 1 << endl;

        return 0;
    }

    for(i = 0; i <= n; i ++)
    {
        l = (long long)i * (i - 1) / 2;
        r = (long long)i * ((n - 1) * 2 - i + 1) / 2;
        if(!f.count(i * x % d))
            f[i * x % d] = vector<pair<long long, bool> >();
        f[i * x % d].push_back(make_pair((i * x / d) + l, true));
        f[i * x % d].push_back(make_pair((i * x / d) + r + 1, false));
    }

    for(t = f.begin(), o = 0; t != f.end(); ++ t)
    {
        sort(t -> second.begin(), t -> second.end());
        // for(pair<int,bool> xx:t->second)printf("[%d,%d] ",xx.first,xx.second);puts("");
        for(i = v = 0; i < (signed)t -> second.size(); i ++)
        {
            if(v)
                o += (t -> second[i].first - 1) - (t -> second[i - 1].first + 1) + 1;

            if(t -> second[i].second)
                v ++;
            else
                v --;

            if(v)
                o ++;
        }
    }
    cout << o << endl;

    return 0;
}


Measured memory_bytes: 25216
#include<iostream>
using namespace std;
int main (void)
{
	int t[101];
	int p[101]={0};
	int n,pre;
	int ba[4];
	cin >> n;
	pre=n*(n-1)/2;
	for(int i=0;i<pre;i++)
	{
		cin >> ba[0] >> ba[1] >> ba[2] >> ba[3];
		if(ba[2]==ba[3])
		{
			p[ba[0]]++;
			p[ba[1]]++;
		}
		else if(ba[2]>ba[3])
		{
			p[ba[0]]+=3;
		}
		else
		{
			p[ba[1]]+=3;
		}
	}
	for(int i=1;i<=n;i++)
	{
		t[i]=1;
		for(int j=1;j<=n;j++)
		{
			if(i!=j)
			{
				if(p[i]<p[j])
				{
					t[i]++;
				}
			}
		}
			cout << t[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 3088
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 1e9+7;

int main()
{
	int n;
   cin >> n;
   vector<ll> t(n),a(n),b(n);
   for(int i = 0;i<n;i++)cin >> t[i];
   for(int i = 0;i<n;i++)cin >> a[i];
   vector<bool> is(n,true);

   is.front() = false;
   is.back() = false;
   if(n==1)
   {
      if(a[0]!=t[0])
      {
         cout<<0<<endl;
         return 0;
      }
   }
   for(int i = 0;i<n-1;i++)
   {
      if(t[i]!=t[i+1])
      {
         b[i+1] = t[i+1];
         is [i+1] = false;
         
      }
   }

   for(int i = 0;i<n-1;i++)
   {
      if(a[i]!=a[i+1])
      {
         
         b[i]=a[i];
         is [i] = false;
         
      }
   }
   ll mx = 0;
   for(int i = 0;i<n;i++)
   {
      mx = max(mx,b[i]);
      if(mx>t[i])
      {
         cout<<0<<endl;
         return 0;
      }
   }
   mx = 0;
   for(int i = n-1;i>=0;i--)
   {
      mx = max(mx,b[i]);
      if(mx>a[i])
      {
         cout<<0<<endl;
         return 0;
      }
   }
   ll ans = 1;
   for(int i = 0;i<n;i++)
   {
      if(is[i])
      {
         //cout<<i<<endl;
         (ans *= min(t[i],a[i]))%=MOD;
      }
   }
   cout<<ans<<endl;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const long long INF = 1LL << 60;

int main(){
    ll N, K;
    cin >> N >> K;
    ll min_value = N;
    if(N >= K) {
        N = N % K;
        min_value = min(min_value, N);
    }
    if (N <= K ) {
        N = K - N;
        min_value = min(min_value, N);
    }
    cout << min_value << endl;
}

Measured memory_bytes: 3624
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
using namespace std;
#define ll int64_t
const long MOD = 1e9 + 7;
const long LINF = 1e13;
const long LLINF = 1e18;
const long ALPHABET = 26;

template <class T>
void Swap(T& r, T& l) {
  T tmp = r;
  r = l;
  l = tmp;
}




int main() {

  long a,b,c;

  cin >> a >> b >>c;
  // vector<long> a(n);

  long d = a+b;


  long ans = 0;

  if (d >= c - 1){
    ans = c + b;
  }else{
    ans = b + (d + 1);
  }





  



  // cout << "YES" <<endl;
  cout << ans << endl;


}




















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

using namespace std;

int N,T[105],M,P,X,temp,ans,sum;

int main(){

    scanf("%d",&N);

    for (int i=0;i<N;i++){
        scanf("%d",&T[i]);
        sum += T[i];
    }

    scanf("%d",&M);

    for (int i=0;i<M;i++){
        scanf("%d%d",&P,&X);
        ans = sum-T[P-1]+X;
        printf("%d\n",ans);
    }
}


Measured memory_bytes: 256
a=int(input())
b=int(input())
c=int(input())
X=int(input())

0<=a,b,c<=50
a+b+c>=1
count=0
for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            if(500*i)+(100*j)+(50*k)==X:
                count+=1
print(count)

Measured memory_bytes: 3064
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include<math.h>

int main(){

    int N[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int K;
    
    scanf("%d",&K);
    printf("%d",N[K-1]);

    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std; 
int main() {
  int a, b, c, d, e; 
	cin >> a >> b >> c >> d >> e; 
  if (a==0)
    cout << 1; 
  if (b == 0) cout << 2; if (c ==0) cout << 3; if (d == 0) cout << 4; 
  if (e == 0) cout << 5; return 0; 
}

Measured memory_bytes: 3592
//              +-- -- --++-- +-In the name of ALLAH-+ --++-- -- --+              \\

#include <bits/stdc++.h>

#define int ll

#define F first
#define S second
#define _sz(x) (int)x.size()
#define pb push_back

#define error(x) cout << #x << " = " << x << endl

using namespace std ;
using ll = long long ;
using ld = long double ;
using pii = pair <int , int> ;

const int C = 100 + 10;
int n, a[C], dp[C], sum;

int32_t main()
{
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);

	cin >> n;

	if (n <= 100)
	{
		cout << 2 * n << '\n';
		for (int i = 0; i < n; i++) cout << i + 1 << ' ';
		for (int i = 0; i < n; i++) cout << n - i << ' ';
		cout << '\n';
		return 0;
	}


	sum = 100;

	for (int i = 0; i < 100; i ++)
	{
		dp[i] = 1;

		vector <pii> vec;

		for (int j = 0; j < i; j++) vec.pb({a[j], dp[j]});

		sort(vec.begin(), vec.end());

		int p = 1;
		for (int j = 0; j < i; j++)
		{
			if (sum + vec[j].S > n) break;
			p++;
			dp[i] += vec[j].S;
			sum += vec[j].S;
		}

		a[i] = p;
		for (int j = 0; j < i; j++)
			if (a[j] >= p) a[j]++;
	}

	cout << "200\n";
	for (int i = 0; i < 100; i++) cout << i + 1 << ' ';
	for (int i = 0; i < 100; i++) cout << a[i] << ' ';
	cout << '\n';
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long  ll ;
typedef double db;
const double pi = 3.141592654;
#define pb         push_back
#define forab(i,a,b)       for(int i=(a);i<=(b);i++)
#define CIN	ios_base::sync_with_stdio(0); cin.tie(0)
#define pcase(z,x)     printf("Case %ld: %lld\n",z,x)
#define nw	 "\n"

int main(void)
{
	CIN;
	ll tc,l,k,sum=0,x=0,y,z=0,m=1,n=0,ans=0,cnt=0;
	cin>>n>>m;
	x=n+2,y=m+2;
	char c;
	char a[x][y];
	for(ll i=0;i<x;i++)
		for(ll j=0;j<y;j++)
			a[i][j]='#';
	for(ll i=1;i<=n;i++){
		for(ll j=1;j<=m;j++){
			cin>>a[i][j];
		}
	}
	for(ll i=0;i<x;i++){
		for(ll j=0;j<y;j++)
			cout<<a[i][j];
		cout<<nw;
	}
		

}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int number,res,rem,pos=0,pos1=0,cnt=0;
    cin>>number;
    res=number/100;
    rem=number%100;
    if(res<=12 && res!=0)
    {
        if(rem>=0){
            pos=1;
        }
    }
    if(res>=0){
        if(rem<=12 && rem!=0){
            pos1=1;
        }
    }
    if(pos==1 && pos1==0) cout<<"MMYY"<<endl;
    if(pos1==1 && pos==0) cout<<"YYMM"<<endl;
    if(pos==1 && pos1==1) cnt=1;
    if(cnt==1) cout<<"AMBIGUOUS"<<endl;
    if(pos==0 && pos1==0) cout<<"NA"<<endl;



    return 0;
}


Measured memory_bytes: 256
from itertools import accumulate
n = int(input())
A = list(map(int, input().split()))
MOD = 10**9+7
Acum = list(accumulate(A))

ans = 0
for i, a in enumerate(reversed(A[1:])):
    ans += Acum[n-i-2]*a
    ans %= MOD
print(ans)

Measured memory_bytes: 31164
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <utility>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <istream>
#include <ostream>

#include <cstdlib>
#include <cmath>
#include <cstdio>

using namespace std;

#define fi first
#define se second
#define mkp make_pair
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define rep(i,n) for(ll i=0; i < (n); ++i)
#define rrep(i,n) for(ll i=((n)-1); i >= 0; --i)

#define OPLT(T) bool operator<(const T & lop_, const T & rop_)
#define OPEQ(T) bool operator==(const T & lop_, const T & rop_)

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

istream& operator>>(istream& istr, __float128& obj) { double d; istr >> d; obj = d; return istr; };
ostream& operator<<(ostream& ostr, __float128& obj) { ostr << static_cast<double>(obj); return ostr; };

int main() {
	ll N;
	vector<ll> A;
	cin >> N;
	A.resize(N);
	rep(i,N) cin >> A[i];
	bool update = true;
	ll sum = 0;
	for(int i = 0; i < N; i++) sum += A[i];
	if(sum % (N*(N+1)/2)) {
		cout << "NO" << endl;
		return 0;
	}
	ll num = sum / (N*(N+1)/2);
	ll c = 0;
	for(int i = 0; i < N; i++) {
		if((A[(i-1+N)%N] - A[i] + num) % N) {
			cout << "NO" << endl;
			return 0;
		}
		else {
			ll a, b;
			a = (A[(i-1+N)%N] - A[i] + num) / N;
			b = num-a;
			if(a < 0 || b < 0) {
				cout << "NO" << endl;
				return 0;
			}
			c += a;
		}
	}
	if(num == c)
		cout << "YES" << endl;
	else 
		cout << "NO" << endl;
	return 0;
}


Measured memory_bytes: 1024
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
class Main{
	static Map<Integer, Integer> map = new HashMap<Integer, Integer>();
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		Main app = new Main();
		for(int i = 1 ; i <= 6 ; i++){
			map.put(i, sc.nextInt());
		}
		char temp [] = sc.next().toCharArray();
		for(int i = 0; i < temp.length; i++){
			app.rotate(String.valueOf(temp[i]));
		}
		System.out.println(map.get(1));
	}
	void rotate(String temp){
		Map <Integer,Integer> memo =  new HashMap<Integer,Integer>(map);
		
		switch(temp){
		case "E":
			map.put(1, memo.get(4));
			map.put(3, memo.get(1));
			map.put(6, memo.get(3));
			map.put(4, memo.get(6));
			break;
		case "W":
			map.put(1, memo.get(3));
			map.put(3, memo.get(6));
			map.put(6, memo.get(4));
			map.put(4, memo.get(1));
			break;
		case "N":
			map.put(1, memo.get(2));
			map.put(2, memo.get(6));
			map.put(6, memo.get(5));
			map.put(5, memo.get(1));
			break;
		case "S":
			map.put(1, memo.get(5));
			map.put(2, memo.get(1));
			map.put(6, memo.get(2));
			map.put(5, memo.get(6));
			break;
		}
	}
}

Measured memory_bytes: 26376