akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <iostream>
using namespace std;

int h, w;
int map[100][100];
int hn, wn;

void draw(int num, int n) {
  if (n == 0) return;
  map[hn][wn] = num;
  if (hn % 2 == 0) {
    if (wn == w-1) hn++;
    else wn++;
  } else {
    if (wn == 0) hn++;
    else wn--;
  }
  draw(num, n-1);
}

int main(){
  cin >> h >> w;
  int n;
  cin >> n;
  hn = 0; wn = 0;
  for (int i = 0; i < n; i++){
    int k;
    cin >> k;
    draw(i+1, k);
  }

  for (int i = 0; i < h; i++) {
    printf("%d", map[i][0]);
    for (int j = 1; j < w; j++) {
      printf(" %d", map[i][j]);
    }
    printf("\n");
  }
  return 0;
}

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

using namespace std;

int n, a[102];

int main(){
	cin >> n; int ans = 1e9;
	for(int i = 1; i <= n; ++i)
		cin >> a[i];
	for(int i = 0; i <= 100; ++i){
		int sum = 0;
		for(int j = 1; j <= n; ++j)
			sum += (a[j] - i) * (a[j] - i);
		ans = min(ans, sum);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

#define MAX_HEAP_SIZE   500001      /* 最大ヒープ領域(ヒープ配列を1オリジンで持つため500000+1) */

int HeapSize;
int HeapArray[MAX_HEAP_SIZE];       /* ヒープ配列(1オリジン) */

void
initVer( void )
{
    int i;
    
    for( i = 0; i < MAX_HEAP_SIZE; i++ )
    {
        HeapArray[i] = 0;
    }
}

void
inputVal( void )
{
    int i;
    
    scanf( "%d", &HeapSize );
    /* 要素数1から入力 */
    for( i = 1; i <= HeapSize; i++ )
    {
        scanf( "%d", &HeapArray[i]);
    }
}

/****************************************************************************/
/* 関数名   | maxHeapify                                                    */
/* 関数仕様 | Nodeを根とする部分木をmax-ヒープ木にする                      */
/****************************************************************************/
void
maxHeapify( int Node )
{
    int LeftNode;
    int RightNode;
    int LargetNode;
    int TmpHeapVal;
    
    /* ヒープ配列は、Nodeの要素数をnとすると、Nodeの子の要素数は左が2n、右が2n×1 */
    LeftNode = 2 * Node;
    RightNode = LeftNode + 1;
    
    /* NodeとNodeの子の中で、最大値の要素数を求める */
    if( ( LeftNode <= HeapSize )
    &&  ( HeapArray[LeftNode] > HeapArray[Node] ) )
    {
        LargetNode = LeftNode;
    }else{
        LargetNode = Node;
    }
    if( ( RightNode <= HeapSize )
    &&  ( HeapArray[RightNode] > HeapArray[LargetNode] ) )
    {
        LargetNode = RightNode;
    }
    
    /* Nodeに対しNodeの子の方が大きい場合、NodeとNodeの子の値を入れ替える */
    if( LargetNode != Node )
    {
        TmpHeapVal = HeapArray[Node];
        HeapArray[Node] = HeapArray[LargetNode];
        HeapArray[LargetNode] = TmpHeapVal;
        /* NodeとNodeの子の値を入れ替えたヒープ配列に対し、Nodeの子にmaxHeapifyを適用する */
        maxHeapify( LargetNode );
    }
}

/****************************************************************************/
/* 関数名   | buildMaxHeap                                                  */
/* 関数仕様 | 子を持つ節に対しボトムアップにmaxHeapifyを適用し              */
/*          | 配列をmax-ヒープに変換する                                    */
/****************************************************************************/
void buildMaxHeap(void){
    int i;
    
    /* 子を持つ節の中で最大の要素数がHeapSize/2 */
    /* 要素数がHeapSize/2節からボトムアップにmaxHeapifyを適用する */
    for( i = HeapSize / 2; i > 0; i-- )
    {
        maxHeapify( i );
    }
}

void outputVal(void){
    int i;
    /* 要素数1から出力 */
    for( i = 1; i <= HeapSize; i++ )
    {
        printf( " %d", HeapArray[i] );
    }
    printf( "\n" );
}

int main(void){
    initVer();
    /* 入力部 */
    inputVal();
    
    /* 制御部 */
    buildMaxHeap();
    
    /* 出力部 */
    outputVal();
}




Measured memory_bytes: 3696
def main():
    import fractions
    n = int(input())
    array = list(map(int, input().split()))
    lcm = array[0]
    for i in range(1, n):
        lcm = lcm * array[i] // fractions.gcd(lcm, array[i])

    total = 0
    for i,num in enumerate(array):
        total += lcm // num
    print(int(total%(10**9+7)))

if __name__ == '__main__':
    main()

Measured memory_bytes: 6200
#include <iostream>

int n;

bool x[8];

int cnt;

int main() {
    std::cin>>n;
    int a;
    for(int i=0;i<n;++i){
        std::cin>>a;
        if(a/400<8)
            x[a/400]=true;
        else if(a>=3200)
            ++cnt;
    }

    int ans=0;

    for(int i=0;i<8;++i){
        if(x[i])
            ++ans;
    }
    if(ans==0)
        std::cout<<1<<' '<<n<<std::endl;
    else
        std::cout<<ans<<' '<<ans+cnt<<std::endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdio.h>
 
using namespace std;
 
#define int long long
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(i, a) for (auto &i: (a))
#define sz(x) (int)(x).size()
#define all(v) (v).begin(), (v).end()
#define fr(i, a, b) for (int i = (a); i <= (b); ++i)

void solve();

signed main () {
    clock_t beg = clock();
    cout << fixed << setprecision(15);
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    #ifdef LOCAL
    freopen("input.txt", "r", stdin);
    #endif 
    int t = 1; 
    // cin >> t;    
    int tt = t;
    while (t--) {
        // cout << "Case #" << tt - t << ": "; 
        solve();
    }
    cerr << "\nExecution time: " << (clock() - beg) / 1000 << '\n';
    return 0;
}
const int N = 1e6 + 5;
int a[N];
int n;
int cnt[N] = {0};
void solve() {  
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
        cnt[a[i]]++;
    }
    int g = a[1];
    for (int i = 2; i <= n; ++i) {
        g = __gcd(g, a[i]);
    }
    if (g > 1) {
        cout << "not coprime\n";
        return;
    }
    for (int i = 1; i < N; ++i) {
        for (int j = 2 * i; j < N; j += i) {
            cnt[i] += cnt[j];
        }
    }
    for (int i = 2; i < N; ++i) {
        if (cnt[i] > 1) {
            cout << "setwise coprime\n";
            return;
        }
    }
    cout << "pairwise coprime\n";
}       

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

int main(){
    int counter[26]={};
    string str;
    while(getline(cin, str)){
        for (int i=0; i<str.size(); i++) {
            if (str[i] >= 'A' && str[i] <= 'Z') counter[str[i]-'A']++;
            if (str[i] >= 'a' && str[i] <= 'z') counter[str[i]-'a']++;
        }
    }
    for (int i=0; i<26; i++) cout << (char)('a'+i) << " : " << counter[i] << endl; 
    return 0;
}


Measured memory_bytes: 3096
N = int(input())
AB = []
for n in range(N):
  AB.append(list(map(int, input().split())))

AB = sorted(AB, key=lambda x: x[1])

a_sum = 0
out = 'Yes'
for ab in AB:
  a_sum += ab[0]
  if a_sum > ab[1]:
    out = 'No'
    break

print(out)

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

int main()
{
	string num_4;
	int num[5];

	cin >> num_4;

	for (int i = 0; i < 4; ++i)
	{
		num[i] = int(num_4[i] - int('0'));
	}

	if (num[0] + num[1] + num[2] + num[3] == 7 )
	{
		printf("%d+%d+%d+%d=7\n", num[0], num[1], num[2], num[3]);
	} else if (num[0] - num[1] + num[2] + num[3] == 7 ){
		printf("%d-%d+%d+%d=7\n", num[0], num[1], num[2], num[3]);
	} else if (num[0] + num[1] - num[2] + num[3] == 7 ){
		printf("%d+%d-%d+%d=7\n", num[0], num[1], num[2], num[3]);
	} else if (num[0] + num[1] + num[2] - num[3] == 7 ){
		printf("%d+%d+%d-%d=7\n", num[0], num[1], num[2], num[3]);
	} else if (num[0] - num[1] - num[2] + num[3] == 7 ){
		printf("%d-%d-%d+%d=7\n", num[0], num[1], num[2], num[3]);
	} else if (num[0] + num[1] - num[2] - num[3] == 7 ){
		printf("%d+%d-%d-%d=7\n", num[0], num[1], num[2], num[3]);
	} else if (num[0] - num[1] + num[2] - num[3] == 7 ){
		printf("%d-%d+%d-%d=7\n", num[0], num[1], num[2], num[3]);
	} else if (num[0] - num[1] - num[2] - num[3] == 7 ){
		printf("%d-%d-%d-%d=7\n", num[0], num[1], num[2], num[3]);
	}
	
	return 0;
}


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

#define INF 1e9
using namespace std;
typedef long long ll;

int main() {

    int n, y; cin >> n >> y;

    for (int i = 0; i <= n; ++i) {
        for (int j = 0; j <= n; ++j) {
            if (10000 * i + 5000 * j + 1000 * (n-i-j) == y && n-i-j >= 0) {
                cout << i << " " << j << " " << n-i-j << endl;
                return 0;
            }
        }
    }

    cout << "-1" << " " << "-1" << " " << "-1" << endl;
}

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

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

int main(){
int n;
cin>>n;
ll a[n];
ll sum=0;
rep(i,n){
  cin>>a[i];
  sum+=a[i];
}
ll ans=10000000007;
ll x=0;
rep(i,n-1){
x+=a[i];
sum-=a[i];
ans=min(ans,abs(x-sum));
}
cout<<ans<<endl;

  return 0;
}


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

using namespace std;

int n,a,b,ans;

bool check(int num){
    int dispo=0;
    while(num){
        dispo+=num%10;
        num/=10;
    }
    if(dispo>=a&&dispo<=b)return 1;
    else return 0;
}

int main(){
    cin>>n>>a>>b;
    for(int i=1;i<=n;i++)if(check(i))ans+=i;
    cout<<ans<<endl;
}


Measured memory_bytes: 256
/* ****mittal21**** */
#include<bits/stdc++.h>
#define ll          long long int 
#define ld          long double
#define pb          push_back
#define endl        '\n'
#define pii         pair<long long int,long long int>
#define vi          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll )x.size()
#define hell        1000000007
#define jell        998244353
#define rep(i,a,b)    for(ll int i=a;i<b;i++)
#define repr(i,a,b)   for(ll int i=a;i>=b;i--)
#define lbnd    lower_bound
#define ubnd        upper_bound
#define mp          make_pair
#define DEC(N)  cout << std::fixed; cout << setprecision(N);
using namespace std;
#define N  100005
ll dp[N];
ll vis[N];
std::vector<ll> a[N];
void dfs(ll node)
{
	vis[node]=1;
	for(auto i:a[node])
	{
		  if(!vis[i])
		  	dfs(i);
		  dp[node]=max(dp[node],dp[i]+1);
	}
}
void solve()
{
   ll n,m;
   cin>>n>>m;
   map<ll,ll>lol;
   for(int i=1;i<=m;i++)
   {
        ll x,y;
        cin>>x>>y;
        a[x].pb(y);
        lol[y]++;
   }
   for(int i=1;i<=n;i++)
   { 
       if(!vis[i])
       {
       	  dfs(i);
       }
   }
   ll ans=0;
   for(int i=1;i<=n;i++)
   {
   	ans=max(ans,dp[i]);
   }
   cout<<ans;
   return;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll testcase=1;
    //cin>>testcase;
    while(testcase--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 19532
N = int(input())
F = [list(map(int, input().split())) for _ in range(N)]
P = [list(map(int, input().split())) for _ in range(N)]

max_v = -(10 ** 10)
for i in range(1,2**10):

    S_cnt = [0] * N 
    for j in range(10):
        if i % 2 == 1:
            for k in range(N):
                if F[k][j] == 1:
                    S_cnt[k] += 1
        i //= 2

    tmp_v = 0
    for j in range(N):
        tmp_v += P[j][S_cnt[j]]
    max_v = max(max_v, tmp_v)

print(max_v)

Measured memory_bytes: 42224
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <stack> // s.top()
#include <bitset>
#include <queue> // s.front()
using namespace std;

typedef long long Int;
typedef pair<Int,Int> P;
#define print(x) cout<<(x)<<endl

#define INF10 10000000000
#define INF5 100000
#define EPS 1e-10
#define MOD 1000000007


int main() {
	int N; cin >> N;
	vector<int> A;
	for (int i = 0; i < N; i++) {
		int ps; cin >> ps;
		A.push_back(ps);
	}
	sort(A.begin(), A.end());
	while (A.size()!=1) {
		for (int i = 1; i < A.size(); i++) {
			A[i] = A[i] % A[0];
		}
		sort(A.begin(), A.end());
		while (A.front() == 0)A.erase(A.begin());
	}
	print(A[0]);





	return 0;
}

Measured memory_bytes: 892
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;

#define all(a) (a).begin(), (a).end()

int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

ll dp[110][4][4][4];

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

    int n; cin>>n;
    vector<string> base = {"A", "C", "G", "T"};
    
    for(int pp=0; pp<4; pp++){
        for(int p=0; p<4; p++){
            for(int c=0; c<4; c++){
                string cur = base[pp] + base[p] + base[c];
                if(cur == "AGC" || cur == "GAC" || cur == "ACG") continue;

                dp[3][c][p][pp] = 1;
            }
        }
    }

    for(int i=3; i<n; i++){
        for(int ppp=0; ppp<4; ppp++){
            for(int pp=0; pp<4; pp++){
                for(int p=0; p<4; p++){
                    for(int c=0; c<4; c++){
                        string cur = base[pp] + base[p] + base[c];
                        if(cur == "AGC" || cur == "GAC" || cur == "ACG") continue;
                        if(ppp == 0 && p == 2 && c == 3) continue;

                        dp[i+1][c][p][pp] += dp[i][p][pp][ppp];
                        dp[i+1][c][p][pp] %= MOD;
                    }
                }
            }
        }
    }

    ll ans = 0;
    for(int i=0; i<4; i++){
        for(int j=0; j<4; j++){
            for(int k=0; k<4; k++){
                ans += dp[n][k][j][i];
                ans %= MOD;
            }
        }
    }

    cout << ans << endl;

    return 0;
}

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

int main() {
  int N;
  string S;
  cin >> N >> S;
  int a = 0;
  
  for(int i = 0; i < N - 2; i++){
    if(S.at(i) == 'A' && S.at(i + 1) == 'B' && S.at(i + 2) == 'C'){
      a++;
    }
  }
  cout << a << endl;
}

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

int main(){
	int n, a, b, a_score = 0, b_score = 0;
	while(true){
		cin >> n;
		if(n == 0)
			break;
		for(int i = 0; i < n; ++i){
			cin >> a >> b;
			if(a < b)
				b_score += a + b;
			else if(a > b)
				a_score += a + b;
			else{
				a_score += a;
				b_score += b;
			}		
		}
		cout << a_score << " " << b_score << endl;
		a_score = b_score = 0;
	}
	return 0;
}

Measured memory_bytes: 1160
from math import *
n=int(input())
f=0
for i in range(n,100009):
    c=0
    for j in range(1,i+1):
        if(i%j==0):
            c=c+1
        if(c>=3):
            break
    if(c==2):
        print(i)
        f=1
        exit()


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

int arr[105];

int main()
{
	int x,n;
	cin>>x>>n;
	int p[n];
	for(int i=0;i<n;i++)
	{
		cin>>p[i];
		arr[p[i]]=1;
	}
	int ans=INT_MAX,res=0;
	for(int i=0;i<105;i++)
	{
		if(arr[i]==0 && abs(x-i)<ans)
		{
			ans=abs(x-i);
			res=i;
		}
	}
	cout<<res<<endl;
}




Measured memory_bytes: 3636
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!(
        a: i32,
        b: i32,
    );
    let kakaku =
        if a <= 5 {
            0
        } else if a <= 12 {
            b/2
        } else {
            b
        };

    println!("{}", kakaku);
}


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

vector<pair<long long, long long> > prime_factorize(long long N) {
	vector<pair<long long, long long> > res;
	for (long long a = 2; a * a <= N; ++a) {
		if (N % a != 0) continue;
		long long ex = 0; // 指数

		 // 割れる限り割り続ける
		while (N % a == 0) {
			++ex;
			N /= a;
		}

		// その結果を push
		res.push_back({ a, ex });
	}

	// 最後に残った数について
	if (N != 1) res.push_back({ N, 1 });
	return res;
}

int main() {

    ll n; cin >> n;
	vector<pair<long long, long long>> n_prime;  // a^x ならば { a, x }
	n_prime = prime_factorize(n);
	ll ans = 0;
	for (ll i = 0; i < n_prime.size() ; i++) {
		ll cnt = 1;
		ll tmp = n_prime[i].second;
		while (cnt <= tmp) {
			tmp -= cnt;
			cnt++;
			ans++;
		}
	}
	cout << ans << endl;
    return 0;
}

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

int main(){
  int a,b;
  cin>>a>>b;
  int i=1;
  while(i<1010){
    i++;
    if (i*8/100==a && i*10/100==b){
        break;
    }
  }
  if(i>=1010){
    i = -1;
  }
  cout<<i<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef complex<double> P;
  
namespace std{
  bool operator < (const P &a,const P &b){
    return (a.real()<b.real()||(a.real()==b.real() && a.imag()<b.imag()));
  }
}
  
double eps=1e-10;
  
double Sqrt(double x){
  return sqrt(max(0.0,x));
}
  
struct S{
  P p,q;
  S(P p,P q):p(p),q(q){}
};
  
struct C{
  P p;
  double r;
  C(P p,double r):p(p),r(r){}
  C(double x,double y,double r):p(P(x,y)),r(r){}
};
  
S getInTangent(C a,C b,double flg=1.0){
  P base=b.p-a.p;
  double w=a.r+b.r;
  double h=Sqrt(norm(base)-w*w);
  P k=base*P(w,h*flg)/norm(base);
  return S(a.p+k*a.r,b.p-k*b.r);
}
  
S getOutTangent(C a,C b,double flg=1.0){
  P base=b.p-a.p;
  double h=b.r-a.r;
  double w=Sqrt(norm(base)-h*h);
  P k=base*P(w,h*flg)/norm(base)*P(0,flg);
  return S(a.p+k*a.r,b.p+k*b.r);
}
  
vector<S> getTangent(C a,C b){
  vector<S> res;
  double dist=abs(a.p-b.p);
    
  if(dist>a.r+b.r+eps)
    res.push_back(getInTangent(a,b,1));
  
  if(dist>a.r+b.r-eps)
    res.push_back(getInTangent(a,b,-1));
  
  if(dist>abs(a.r-b.r)+eps)
    res.push_back(getOutTangent(a,b,1));
  
  if(dist>abs(a.r-b.r)-eps)
    res.push_back(getOutTangent(a,b,-1));
  
  return res;
}
  
  
  
void pr(P p){
  printf("%.10f %.10f\n",p.real(),p.imag());
}
  
int main(){
  double ax,ay,ar,bx,by,br;
  cin>>ax>>ay>>ar>>bx>>by>>br;
  vector<S> ans=getTangent(C(ax,ay,ar),C(bx,by,br));
  vector<P> vec;
  for(int i=0;i<(int)ans.size();i++)vec.push_back(ans[i].p);
  sort(vec.begin(),vec.end());
  for(int i=0;i<(int)vec.size();i++)pr(vec[i]);
  return 0;
}


Measured memory_bytes: 3352
// ARC101A.cpp
#include <bits/stdc++.h>

using namespace std;

const int MAX_N = 1e5 + 200;

typedef long long ll;

int n, k, ai[MAX_N];

int main()
{
    scanf("%d%d", &n, &k);
    for (int i = 1; i <= n; i++)
        scanf("%d", &ai[i]);
    ll gans = 1e18;
    for (int lft = 1; lft <= n - k + 1; lft++)
        if (ai[lft] <= 0 && ai[lft + k - 1] >= 0)
            gans = min(gans, 0LL + ai[lft + k - 1] - ai[lft] + min(abs(ai[lft + k - 1]), abs(ai[lft])));
    int zero_pt = 0;
    for (int i = 1; i <= n; i++)
    {
        if (ai[i] >= 0 && zero_pt == 0)
            zero_pt = i;
        if (ai[i] >= 0 && i - zero_pt + 1 == k)
            gans = min(gans, 0LL + ai[i]);
    }
    if (zero_pt == 0)
        zero_pt = n + 1;
    for (int i = 1; i <= n; i++)
        if (ai[i] <= 0 && zero_pt - i == k)
            gans = min(gans, 0LL - ai[i]);
    printf("%lld\n", gans);
    return 0;
}

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

#define _For(idx, from, to, inc, cmp) \
	for(auto idx=(from) ; idx cmp (to) ; inc idx)
#define For(idx, from, to) \
	_For(idx, from, to, ++, <)
using u64 = uint64_t;
using u64p = std::pair<u64, u64>;
using i64 = int64_t;
constexpr int NA = 50;
int main() {
	u64 n;
	std::cin >> n;

	const u64 div = n/NA;
	const u64 initial = (NA-1) + div;
	std::vector<u64> ret(NA, initial);
	n %= NA;
	For(i, 0, n) {
		ret[i] += NA;
		For(j, 0, NA) {
			if(j != i) {
				ret[j] -= 1;
			}
		}
	}
	std::cout << NA << std::endl;
	For(i, 0, NA) {
		if(i!=0)
			std::cout << ' ';
		std::cout << ret[i];
	}
	std::cout << std::endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define lli long long int
#define ulli unsigned long long int
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define loopl(i,a,b) for(lli i=a;i<b;i++) 
#define loop(i,a,b) for(int i=a;i<b;i++)
#define all(v) v.begin(), v.end()
#define mod 1000000007
#define mod2 1000000006
#define inf 1000000000000000000
#define lld long double
#define pll pair<long long int,long long int>
#define pii pair<int,int>
#define vll vector<lli>
#define vii vector<int>
#define is indexed_set
#define eps 0.000001
#define endl '\n'
#define mo 998244353
#define pi 3.141592653589793
#define FF first
#define SS second
using namespace std ;
 
const lli dx4[] = {-1, 0, 1, 0};
const lli dy4[] = {0, 1, 0, -1};
const lli dx8[] = {-1, 0, 1, 0, -1, -1, 1, 1};
const lli dy8[] = {0, 1, 0, -1, -1, 1, -1, 1};
 
typedef tree<pll,null_type,less<pll>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count()); // can give negative values too

#define N 1000001

void solve()
{
	lli x,y;
	cin>>x>>y;

	loopl(i,0,x+1)
	{
		if(2*i + 4*(x-i) == y)
		{
			cout<<"Yes";
			return ;
		}
	}

	cout<<"No";

}

int main()
{
/////////////////////////////////////
    fastio;
/////////////////////////////////////  

    lli t;
    t=1;
    while(t--)
    	solve();
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
const int INF=1001001000;
const int mINF=-1001001000;
const ll LINF=1010010010010010000;
template<class T> inline bool chmin(T& a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template<class T> inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
//グリッド：（典型）dp,dfs,bfs,最短経路,その他
const int mod = 1000000007;
struct mint {
ll x;
mint(ll x=0):x((x%mod+mod)%mod){}
mint operator-() const { return mint(-x);}
mint& operator+=(const mint a) {
if ((x += a.x) >= mod) x -= mod;
return *this;
}
mint& operator-=(const mint a) {
if ((x += mod-a.x) >= mod) x -= mod;
return *this;
}
mint& operator*=(const mint a) {
(x *= a.x) %= mod;
return *this;
}
mint operator+(const mint a) const {
mint res(*this);
return res+=a;
}
mint operator-(const mint a) const {
mint res(*this);
return res-=a;
}
mint operator*(const mint a) const {
mint res(*this);
return res*=a;
}
mint pow(ll t) const {
if (!t) return 1;
mint a = pow(t>>1);
a *= a;
if (t&1) a *= *this;
return a;
}
mint inv() const {
return pow(mod-2);
}
mint& operator/=(const mint a) {
return (*this) *= a.inv();
}
mint operator/(const mint a) const {
mint res(*this);
return res/=a;
}
};
mint dp[3300][3300];
mint dp_sum[3300][3300];
int main(){
    int n;cin >> n;
    string s;cin >> s;
    dp[0][0]=1;
    for(int i=1;i<n;i++){
        for(int j=0;j<=i-1;j++){
            dp_sum[i-1][j]=dp[i-1][j];
            if(j-1>=0) dp_sum[i-1][j]+=dp_sum[i-1][j-1];
        }
        for(int j=0;j<=i;j++){
            if(s[i-1]=='<'){
                if(j-1>=0) dp[i][j]=dp_sum[i-1][j-1];
            }
            else{
                dp[i][j]=dp_sum[i-1][i-1];
                if(i-1>=0) dp[i][j]-=dp_sum[i-1][j-1];
            }
        }
    }
    mint ans=0;
    rep(i,n) ans+=dp[n-1][i];
    cout << ans.x << endl;
    return 0;
}

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

#define dump(...) cout<<"# "<<#__VA_ARGS__<<'='<<(__VA_ARGS__)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

using uint=unsigned;
using ll=long long;
using ull=unsigned long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vd=vector<double>;
using vvd=vector<vd>;
using vs=vector<string>;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}

template<typename Tuple>
void print_tuple(ostream&,const Tuple&){}
template<typename Car,typename... Cdr,typename Tuple>
void print_tuple(ostream& os,const Tuple& t){
	print_tuple<Cdr...>(os,t);
	os<<(sizeof...(Cdr)?",":"")<<get<sizeof...(Cdr)>(t);
}
template<typename... Args>
ostream& operator<<(ostream& os,const tuple<Args...>& t){
	print_tuple<Args...>(os<<'(',t);
	return os<<')';
}

template<typename Ch,typename Tr,typename C>
basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){
	os<<'[';
	for(auto i=begin(c);i!=end(c);++i)
		os<<(i==begin(c)?"":" ")<<*i;
	return os<<']';
}

constexpr int INF=1e9;
constexpr int MOD=1e9+7;
constexpr double EPS=1e-9;

int ModInverse(int a,int m)
{
	int x=1;
	for(int b=m,u=0;b;){
		ll t=a/b;
		swap(a-=b*t,b);
		swap(x-=u*t,u);
	}
	return (x+m)%m;
}

int ModPow(int a,int r,int m)
{
	int x=1;
	for(;r;r>>=1){
		if(r&1) x=(ll)x*a%m;
		a=(ll)a*a%m;
	}
	return x;
}

int ModMul(int a,int b,int m)
{
	return ll(a)*b%m;
}

int ModMul(int a,int b,int c,int m)
{
	return ModMul(ModMul(a,b,m),c,m);
}

int ModDiv(int a,int b,int m)
{
	return ModMul(a,ModInverse(b,m),m);
}

vl xinv(1001),f(1001),finv(1001);

// m! / ((x!)^k * (m-k*x)! * k!)
int calc(int m,int k,int x)
{
	return ModDiv(f[m],ModMul(ModPow(f[x],k,MOD),f[m-k*x],f[k],MOD),MOD);
}

int main()
{
	f[0]=finv[0]=1;
	for(int i=1;i<=1000;i++){
		xinv[i]=ModInverse(i,MOD);
		f[i]=f[i-1]*i%MOD;
		finv[i]=ModInverse(f[i],MOD);
	}

	for(int n,a,b,c,d;cin>>n>>a>>b>>c>>d&&n|a|b|c|d;){
		vvl dp(b-a+2,vl(n+1));
		dp[0][0]=1;
		rep(i,b-a+1){
			int x=a+i;
			rep(j,n+1){
				(dp[i+1][j]+=dp[i][j])%=MOD;
				for(int k=c;k<=d&&j+k*x<=n;k++)
					(dp[i+1][j+k*x]+=dp[i][j]*calc(n-j,k,x))%=MOD;
			}
		}
		cout<<dp[b-a+1][n]<<endl;
	}
}


Measured memory_bytes: 8192
#include <bits/stdc++.h>
using namespace std;
 
#define lli long long int 
#define pb push_back 
#define im (int i = 0 ; i < m ; i++)
#define jx (int j = 0 ; j < x ; j++)
#define kn (int k = 0 ; k < n ; k++)
#define ln (int l = 0 ; l < n ; l++)
#define wq while (q--)


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

    double aux = n / 1.08 ;
    int aux2 = ceil(aux);

    if (floor ((double) aux2 * 1.08)  == n)
    {
        cout << aux2 << endl ;
    }
    else
    {
        cout << ":(" << endl ;
    }
    
      
    return 0 ;
}

Measured memory_bytes: 256
a=list(map(int,input().split()))
ans=0
a.sort()
while a[1]-a[0]>=2:
    a[0]+=2
    ans+=1

if a[1]!=a[0]:
    ans+=2
    
while a[2]-a[1]>0:
    a[1]+=1
    ans+=1

print(ans)

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

using namespace std;

typedef long long ll;

const ll MOD = 1000000007;
const ll INF = 1e-15;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    int n, k; cin >> n >> k;
    ll a[n+1];
    for(int i=1;i<=n;i++) cin >> a[i];
    // sum_i = a_1 + ... + a_i 
    ll sum[n+1];
    // sump_i = max(0, a_1) + ... + max(0, a_i)
    ll sump[n+1];
    sum[0] = 0, sump[0] = 0;
    for(int i=1;i<=n;i++){
        sum[i] = sum[i-1] + a[i];
        sump[i] = sump[i-1] + max(0LL, a[i]);
    }
    ll ans = -INF;
    for(int i=k;i<=n;i++){
        ll left = sump[i - k];
        ll mid = max(0LL, sum[i] - sum[i - k]);
        ll right = sump[n] - sump[i];
        // cout << left + mid + right << endl;
        ans = max(ans, left + mid + right);
    }
    cout << ans << endl;
}

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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
#define LINF 1e18
typedef long long ll;


int main() {
    int R,C,K; cin >> R >> C >> K;
    vector<vector<int>> G(R,vector<int>(C,0));
    REP(i,K){
        int r,c,v; cin >> r >> c >> v;
        r--;
        c--;
        G[r][c] = v;
    }
    vector<vector<vector<ll>>> dp(R+1,vector<vector<ll>>(C, vector<ll>(4,0)));
    REP(i,R){
        REP(j,C){
            REP(k,4){
                if(j!=C-1) dp[i][j+1][k] = max(dp[i][j+1][k], dp[i][j][k]);//取らずに右
                dp[i+1][j][0] = max(dp[i+1][j][0], dp[i][j][k]);//取らずに下
                if(k!=3){
                    if(j!=C-1) dp[i][j+1][k+1] = max(dp[i][j+1][k], dp[i][j][k]+G[i][j]);//取って右
                    dp[i+1][j][0] = max(dp[i+1][j][0], dp[i][j][k]+G[i][j]);//取って下
                }
            }
            
        }
    }
    ll ans = 0;
    REP(i,4){
        ans = max(ans,dp[R][C-1][i]);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 671212
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
const double PI = acos(-1);
const double EPS = 1e-15;
long long INF=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
bool prime(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd(b,a%b);
  }
}
 
long long lcm(long long x, long long y){
  return (x/gcd(x,y))*y;
}
 
class UnionFind {
    public:
    //各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。
    vector<int> Parent;
    
    //クラスを作るときは、Parentの値を全て-1にする。
    //以下のようにすると全てバラバラの頂点として解釈できる。
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }
    
    //Aがどのグループに属しているか調べる
    int root(int A) {
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }
    
    //自分のいるグループの頂点数を調べる
    int size(int A) {
        return -Parent[root(A)];//先祖をrootで取っておきたい。
    }
    
    //AとBをくっ付ける
    bool connect(int A, int B) {
        //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if (A == B) {
            //すでにくっついてるからくっ付けない
            return false;
        }
        
        //大きい方(A)に小さいほう(B)をくっ付けたい
        //大小が逆だったらAとBをひっくり返す。
        if (size(A) < size(B)) swap(A, B);
        
        //Aのサイズを更新する
        Parent[A] += Parent[B];
        //Bの親をAに変更する
        Parent[B] = A;
        
        return true;
    }
};

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


Measured memory_bytes: 256
n=int(input())
alist=list(map(int,input().split()))
adic={}
for i in range(n):
	adic[alist[i]]=i+1
out=[]
for i in range(1,n+1):
	if i == n:
		out.append(str(adic[i]))
	else:
		out.append(str(adic[i]) + " ")
print("".join(out))

Measured memory_bytes: 24924
#include <ios>
#include <iomanip>
#include <iostream>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>

using namespace std;
typedef long long int ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1e9)
#define PI (acos(-1))
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl

ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
typedef pair <ll,ll> P;

int main()
{
    ll N;
    cin >> N;
    ll n = floor(sqrt(N));
    print(n*n);
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define df 0
int c(const void* a,const void* b){
  int x=*((int*)a);int y=*((int*)b);
  return y-x;
}
int n;
int a[100000];
long int even();
long  int odd();

int main(){
  scanf("%d",&n);
  int i;
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  qsort(a,n,sizeof(int),c);
  if(df){
    for(i=0;i<n;i++)
      printf(" %d",a[i]);
    printf("\n");
  }

  long int s;
  if(n%2)s=odd();
  else s=even();

  printf("%ld",s);
  return 0;
}


long  int odd(){
  long int s=0;
  int i;
  for(i=0;i<n/2;i++){
    s+=2*a[i];
  }
  s-=a[i++];
  s-=a[i++];
  for(;i<n;i++){
    s-=2*a[i];
  }
  int m=n/2,x=2*a[m]-a[m-1]-a[m+1];
  if(x>0)s+=x;
  return s;
}

long int even(){
  long int s=0;
  int i;
  for(i=0;i<n/2-1;i++){
    s+=2*a[i];
  }
  s+=a[i++];
  s-=a[i++];
  for(;i<n;i++){
    s-=2*a[i];
  }
  return s;
}



/// confirm df==0 ///


Measured memory_bytes: 1020
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
const int MOD = 1e9+7,MAX = 1e5;

int main()
{
	while(1)
	{
		int a,b;
		cin >> a >> b;
		if(a==0&&b==0)break;
		if(a>b)swap(a,b);
		cout<<a<<' '<<b<<endl;
	}
	return 0;
}



Measured memory_bytes: 3056
#include "bits/stdc++.h"
using namespace std;

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(i = 0; i < n; i++)

const int inf = (int)1e9 + 7;
const long long INF = 1LL << 60;

typedef long long ll;

// 4,8方向に探索する際に用いる配列
//int dx[4] = { 0,  0, 1, -1 };
//int dy[4] = { 1, -1, 0,  0 };
//int dx[8] = { 1, 0, -1,  0, 1, -1, -1,  1 };
//int dy[8] = { 0, 1,  0, -1, 1,  1, -1, -1 };

int main() 
{
	int x[5];
	int i;
	rep(i, 5) cin >> x[i];
	int k; cin >> k;

	for (int i = 0; i < 5; i++)
	{
		for (int j = 0; j < 4; j++)
		{
			if(i == j) {}
			else
			{
				if (abs(x[i] - x[j]) > k)
				{
					cout << ":(" << endl;
					return 0;
				}
			}
		}
	}
	cout << "Yay!" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long X, K, D;
  
  cin >> X >> K >> D;

  long long n_x_100;
  
  n_x_100 = 50*K - 50*X /D + 50;
  
  long long n;
  n = n_x_100 / 100;
  
  if(n < 0) n = 0;
  if(n > K) n = K;
  
  long long ans;
  ans = abs(X + 2*n*D - K*D);
  
  //cout << n_x_100 << n << endl;
  
  cout << ans << endl;
    
    
}

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

char a[55], b[55];
int lena, lenb;

bool chk(int k) {
    rep(i, 0, lenb) {
        if (a[k + i] != '?' && a[k + i] != b[i]) return false;
    }
    return true;
}

int main() {
    scanf("%s%s", a, b);
    lena = strlen(a);
    lenb = strlen(b);
    int p = -1;
    for (int i = lena - lenb; i >= 0 && p < 0; i--) {
        if (chk(i)) p = i;
    }
    if (p < 0) puts("UNRESTORABLE");
    else {
        rep(i, 0, lenb) {
            a[p + i] = b[i];
        }
        rep(i, 0, lena) {
            if (a[i] == '?') a[i] = 'a';
        }
        printf("%s\n", a);
    }
}

Measured memory_bytes: 256
k, n = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
a_ = a+[a[0]+k]
p = []
for i in range(len(a_)-1):
  p.append(a_[i+1]-a_[i])

#print(p)
max_value = max(p)
max_index = p.index(max_value)
#print(max_index)

i=1
j=0
ans =0
while True:

  try:
    ans += a_[max_index+i+1] - a_[max_index+i] 
    i += 1
    #print(ans)
  except:
    if j+1 == max_index+1:
      break
    ans += a_[j+1]-a_[j]
    j+=1
    #print(ans)

print(ans)

Measured memory_bytes: 26804
import sys

def i2s():
    return sys.stdin.readline()

def ii2ss(n):
    return [sys.stdin.readline() for _ in range(n)]

def sp2nn(sp, sep=' '):
    return [int(s) for s in sp.split(sep)]

def ss2nn(ss):
    return [int(s) for s in list(ss)]

def main(S):
    S = S.rstrip()
    c0 = 0
    c1 = 0
    for i, s in enumerate(S):
        if (i % 2) == int(s):
            c0 += 1
        else:
            c1 += 1
    cmin = min(c0, c1)
    print(cmin)

main(i2s())

Measured memory_bytes: 3188
/*模範解答*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using st = string;
using P = pair<int, int>;
#define mrep(i, m, n) for(int i = m; i < n; i++)
#define rep(i, n) mrep(i, 0, n)
#define chmax(x, y) { x = max(x, y); }
#define chmin(x, y) { x = min(x, y); }

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a.at(i);
    sort(a.begin(), a.end());
    reverse(a.begin(), a.end());
    ll ans = 0;
    int t = n - 1;
    rep(i, n){
        int lim = 2;
        if(i == 0) lim = 1;
        rep(j, lim){
            if(t > 0){
                ans += a.at(i);
                t--;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4004
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N;
    double T,A;
    cin>>N>>T>>A;
    double m=1000000;
    double M;
    int count;
    double H;
    for(int i=1;i<=N;i++){
        cin>>H;
        M=abs(T-H*0.006-A);
        if(M<m){
            count = i;
            m=M;
        }
    }
    cout<<count<<endl;
}

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

bool table[1000100];

int main() {
	for(int i = 0; i < 1000100; i++)
		table[i] = true;
	table[0] = table[1] = false;
	for(int i = 2; i < 1000100; i++) {
		if(table[i]) {
			for(int j = 2; i * j < 1000100; j++) {
				table[i*j] = false;
			}
		}
	}
	int a, d, n;
	while(cin >> a >> d >> n, a || d || n) {
		int i = 0;
		int cnt = 0;
		while(1) {
			if(table[a + d * i]) {
				cnt++;
			}
			if(cnt == n) {
				cout << a + d * i << endl;
				break;
			}
			i++;
		}
	}
}

Measured memory_bytes: 2136
n=int(input())
l=[int(input()) for _ in range(n)]
ans=0
if l[0]!=0:
  print(-1)
  exit()
for i in range(n-1):
  if l[i+1]-l[i]>1:
    print(-1)
    exit()
  elif (l[i]+1==l[i+1]):
    ans+=1
  else:
    ans+=l[i+1]
print(ans)


Measured memory_bytes: 17064
import itertools
import math
n = int(input())
xy = [list(map(int, input().split())) for _ in range(n)]

ans = 0
for p in itertools.permutations(xy, n):
    for i in range(n-1):
        ans += math.sqrt((p[i][0]-p[i+1][0])**2 + (p[i][1]-p[i+1][1])**2)
print(ans/math.factorial(n))


Measured memory_bytes: 3188
#include <iostream>
#include <string>
#include <set>
#include <vector>

using namespace std;
typedef unsigned long long ull;
const ull HASH_BASE = 1000000007;

int main(){
	ios_base::sync_with_stdio(false);
	int n, m;
	string s;
	cin >> n >> m >> s;
	vector<ull> hash_pow(n + 1);
	hash_pow[0] = 1;
	for(int i = 1; i <= n; ++i){ hash_pow[i] = hash_pow[i - 1] * HASH_BASE; }
	vector<ull> integral(n + 1);
	for(int i = 0; i < n; ++i){
		integral[i + 1] = integral[i] * HASH_BASE + s[i];
	}
	set<ull> st;
	int left = 0, right = 1;
	while(m--){
		string q;
		cin >> q;
		if(q == "L++"){
			++left;
		}else if(q == "L--"){
			--left;
		}else if(q == "R++"){
			++right;
		}else if(q == "R--"){
			--right;
		}
		st.insert(integral[right] - integral[left] * hash_pow[right - left]);
	}
	cout << st.size() << endl;
	return 0;
}

Measured memory_bytes: 20228
#include<bits/stdc++.h>
 using namespace std;
 
 
 int main()
 {
 	int g[4][4];
 	
 	for(int i=1;i<=3;i++)
 	{
 	   for(int j=1;j<=3;j++)
		{
			cin>>g[i][j];
		}	
	}
	
	//for(int i=0;i<=100;i++)
	{
		int a1=0;	
		int b1=(g[1][1])-a1;
		int a2=(g[1][2]-b1);
		int a3=g[1][3]-b1;		
		int b2=(g[2][1])-a1;
		int b3=g[3][1]-a1;
		int ok=0;
		if(g[1][1]!=a1+b1)ok=1;
		if(g[1][2]!=a2+b1)ok=1;
		if(g[1][3]!=a3+b1)ok=1;
		if(g[2][1]!=b2+a1)ok=1;
		if(g[2][2]!=b2+a2)ok=1;
		if(g[2][3]!=b2+a3)ok=1;
		if(g[3][1]!=b3+a1)ok=1;
		if(g[3][2]!=b3+a2)ok=1;
		if(g[3][3]!=b3+a3)ok=1;
		if(ok==0)
		{
			cout<<"Yes\n";
			return 0;
		}
		
	}
	cout<<"No\n";
 }

Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, s, n) for (int i = (s); i < (n); ++i)
#define rrep(i, n, g) for (int i = (n)-1; i >= (g); --i)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define len(x) (int)(x).size()
#define dup(x, y) (((x) + (y)-1) / (y))
#define pb push_back
#define Field(T) vector<vector<T>>
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int a, b;
  cin >> a >> b;
  int d = 1;
  int ans = 0;
  while (d < b) {
    ans++;
    d += a - 1;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >>s;
  int tmp=s.size();
  if(s.at(tmp-1)=='3')
    cout <<"bon"<<endl;
  else if(s.at(tmp-1)=='0'||s.at(tmp-1)=='1'||s.at(tmp-1)=='6'||s.at(tmp-1)=='8')
    cout <<"pon"<<endl;
  else
    cout <<"hon"<<endl;
}

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

using ll = long long;
using pii = pair<int, int>;
constexpr int M = 1e9 + 7;
constexpr int INF = 1e9;

int main() {
    int N, M;
    cin >> N >> M;
    double r = 1 - pow(0.5, M);
    double res = (100 * (N - M) + 1900 * M) / (1 - r);
    int res2 = (int)(res + 0.1);
    cout << res2 << endl;
}


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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)

typedef long long ll;
typedef pair<ll,ll> P;

int mp[111111];

int main(){
	
	int n;cin >> n;
	REP(i, n){
		int tmp;cin >> tmp;
		mp[tmp]++;
	}
	
	ll now = 0;
	ll ans = 1;
	if(n % 2 == 0)now++;
	else{
		ans = (mp[0] == 1);
		now += 2;
	}
	
	for(;now < n;now += 2)ans = ans * 2 * (mp[now] == 2) % MOD;
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <string>
#include <stdio.h>
#include <cmath>
#include <queue>
#include <stack>
#include <algorithm>
using namespace std;
int n,a[100];
void syuturyoku(){
	for(int i=0;i<n;i++){
		if(i==n-1)cout<<a[i]<<endl;
		else cout<<a[i]<<" ";
	}
}
int main(){
	cin>>n;
	for(int i=0;i<n;i++)cin>>a[i];
	syuturyoku();
	for(int i=1;i<n;i++){
		int v=a[i];
		int j=i-1;
		while(j>=0&&a[j]>v){
			a[j+1]=a[j];
			j--;
			a[j+1]=v;
		}
		syuturyoku();
	}
	return 0;
}

Measured memory_bytes: 3068
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define mod 1000000007
#define MAX 1000000000000000
#define all(v) v.begin(),v.end()
#define rep(i,a,b) for(i=(ll)a;i<(ll)b;i++)
#define revrep(i,a,b) for(i=(ll)a;i>=(ll)b;i--)
#define ii pair<ll,ll>
#define MP make_pair
#define pb push_back
#define f first
#define se second
#define ll long long int
#define vi vector<ll>
ll modexp(ll a,ll b){ ll res = 1; while(b > 0){  if(b & 1) res = (res * a)%mod;  a = (a * a)%mod;  b/=2;  }  return res; }
#define rs resize
typedef tree< ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update > OST;
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif

const ll N = 100009;
ll i,a,n,m,ans;
map<ll,ll> mp;
ll s[N];
int main()
{
    std::ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin>>n>>m;
    rep(i,1,n + 1){
        cin>>a;
        s[i] = (s[i - 1] + a) % m;
    }
    mp[0] = 1;
    rep(i,1,n + 1){
        ans += mp[s[i]];
        mp[s[i]] += 1;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 4992
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for _ in range(n)]
def LIR(n):
    return [LI() for _ in range(n)]
def SR(n):
    return [S() for _ in range(n)]
def LSR(n):
    return [LS() for _ in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    x = I()
    print(1-x)
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 65436
#include <iostream>
#include <string>
using namespace std;
 
int main() {
    int n;
    int result = 0;
    int* d;
    cin >> n;
    d=new int[n];
    for(int i=0;i<n;i++){
        cin >> d[i];
    }
    for(int i=0;i<n-1;i++){
        for(int j=i+1;j<n;j++){
            result+=d[i]*d[j];
        }
    }
    cout << result << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>

int main(){
   int N;
   std::cin >> N;
   std::vector<long long> S(N+1);
   S[0] = 0;
   long long A;
   for(int i=0; i<N; ++i){
      std::cin >> A;
      S[i+1] = S[i] + A;
   }
   std::sort(S.begin(),S.end());

   long long count = 0;
   long long same = 1;
   for(int i=0; i<N; ++i){
      if(S[i]==S[i+1]) ++same;
      else{
	 count += same * (same-1) / 2;
	 same = 1;
      }
   }
   count += same * (same-1)/2;
   std::cout << count << std::endl;
   return 0;

}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define int long long
#define ld long double
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define all(x) x.begin(),x.end()
#define LOL cout << '\n';
#define sz(x) ((int)x.size())
#define INF LONG_LONG_MAX
#define NINF LONG_LONG_MIN
#define deb(x) cout << "[" << (#x) << "=" << x << "]" << '\n';
#define deb2(x,y) cout << "[" << (#x) << "=" << x << "] [" << (#y) << "=" << y << "]" << '\n';
#define deb3(x,y,z) cout << "[" << (#x) << "=" << x << "] [" << (#y) << "=" << y << "] [" << (#z) << "=" << z << "]" << '\n';

const int M=1e9+7;

void solve(){
  int n; cin>>n;
  if(n<3){
    cout<<0;LOL
    return;
  }
  int a[n+10];
  a[0]=0;
  a[1]=0;
  a[2]=0;
  a[3]=1;
  for(int i=4 ; i<=n ; i++){
    a[i]=1;
    for(int j=i-3 ; j>=3 ; j--){
      a[i]=(a[i]+a[j])%M;
    }
  }
    cout<<a[n];LOL
}

signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
  int _ = 1; //cin >> _;
  for(int i = 1 ; i <= _ ; i++){
    //cout << "Case #" << i << ": ";
    solve();
  }
  return 0;
}

Measured memory_bytes: 3632