akhauriyash/Code-Regression huggingface dataset:
import collections
from functools import lru_cache
import bisect

INF = float("inf")
ZERO = 0
ONE = 1


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


def readInt():
    return int(input().strip())


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


def solve(N, arr):
    ans = 0
    MOD = 10**9 + 7
    prefixSums = [0]

    for num in arr:
        prefixSums.append(prefixSums[-1] + num)

    for i, num in enumerate(arr):
        ans = (ans + num * (prefixSums[-1] - prefixSums[i+1])) % MOD

    return ans % MOD


N = readInt()
arr = readList()

print(solve(N, arr))


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

int main(){
  int a1,a2,a3;
  cin >> a1 >> a2 >> a3;
  if(a1+a2+a3>=22){
    cout<< "bust" << endl;
  }
  else{
    cout << "win" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
using namespace std;
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define INF 1145141919364364
#define int long long
#define all(vec) vec.begin(),vec.end()
#define P pair<int,int>
#define S second
#define F first

int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}

int n, a, b;

signed main() {
	cin >> n >> a >> b;
	if (n % (a + b) <= a)cout << a * (n / (a + b)) + n % (a + b) << endl;
	else cout << a * (n / (a + b)) + a << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
using ll = long long;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define rep2(i, s, n) for(ll i = s; i < n; i++)
using namespace std;

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  int b1 = 0;
  rep(i, n){
    cin >> a[i];
    if (i % 2 == 0) b1 += a[i];
    else b1 -= a[i];
  }
  cout << b1 << ' ';
  int b = b1;
  rep(i, n-1){
    b = 2 * a[i] - b;
    if (i == n-2) cout << b << endl;
    else cout << b << ' ';
  }
  
  return 0;
}

Measured memory_bytes: 3768
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>

using namespace std;
#define i64  long long
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(),(x).end()
// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return;std::cout << e << std::endl;}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class X> void DEBUG(X d, T e){if(DEBUG_OUT == false)return;std::cout <<d<<" ";DEBUG(e);};
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

//BELOW
//-----CODE------//
int calc_gcd(int a, int b) { return b == 0 ? a : calc_gcd(b, a % b); }
 
long long calc_lcm(int a, int b) { return (long long)a * b / calc_gcd(a, b); }
 

void solve(void)
{
  int N, M;
  cin >> N >> M;
  vector<int> vec(N);

  vector<int> vec2(N);
  for (int i = 0; i < N; i++)
  {
    cin >> vec[i];
    vec[i] /= 2;
    int A = vec[i];
    while(A%2 == 0)
    {
      vec2[i]++;
      A /=2;
    }
  }

  for (int i = 0; i < N-1; i++)
  {
    if(vec2[i] != vec2[i+1])
    {
      cout<<0<<endl;
      return;
    }
  }
  bool check = 1;
  int V_LCM = 1;
  for (int i = 0; i < N; i++)
  {
    V_LCM = calc_lcm(V_LCM,vec[i]);
  }
  
  int ANS = M/V_LCM - M/V_LCM/2;

  if(check == 0)
  {
    cout<<0<<endl;
  }
  else
  {
    cout<<ANS<<endl;//ANS
  }
  
  return;
}

int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();

  return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <list>
#include <string>
#include <numeric>
#include <math.h>
#include <set>
#include <map>
#include <fstream>
#include <sstream>
#include <iterator>
#include <complex>
using namespace std;

int main()
{
	int N;
	string S;
	cin>>N>>S;
	char pos = '0';
	int result = 0;
	for(int i=0; i<N; i++)
	{
		if(pos != S[i])
		{
			result++;
		}
		pos = S[i];
	}
	cout<<result<<endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;cin>>n;
	map<long long,int>mp;
	long long b[n+1]={0},a,ans=0;
	for(int i=1;i<=n;i++){
		cin>>a;
		b[i]=b[i-1]+a;
	}
	for(int i=0;i<=n;i++)mp[b[i]]++;
	for(map<long long,int>::iterator iiit=mp.begin();iiit!=mp.end();iiit++){
		long long temp=iiit->second;
		ans+=temp*(temp-1)/2;
	}
	cout<<ans;
	return 0;
}
/*
6
1 3 -4 2 2 -2
5
1 -2 3 -4 5
*/

Measured memory_bytes: 14336
n=int(input())
a=list(map(int,input().split()))
b=[]
if n % 2 == 1:
    for i in range(n-1,-1,-2):
        b.append(a[i])
    for i in range(1,n,2):
        b.append(a[i])
else:
    for i in range(n-1,0,-2):
        b.append(a[i])
    for i in range(0,n,2):
        b.append(a[i])
ans=""
for i in range(n):
    ans+=str(b[i]) + " "
print(ans)

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

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

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
typedef priority_queue<int> HEAP;
typedef priority_queue<int, vector<int>, greater<int> > RHEAP;

const int N = 100010, M = 1010, mod = 1e9 + 7;

int n;
char s[N];

int qp(int a, int b)
{
	int res = 1;
	while (b)
	{
		if (b & 1) res = (LL)res * a % mod;
		a = (LL)a * a % mod;
		b >>= 1;
	}
	return res;
}

int main()
{
	scanf("%s", s + 1);
	n = strlen(s + 1);
	
	int res = 0, cnt = 0;
	for (int i = 1; i <= n; i ++ )
		if (s[i] == '1')
		{
			res = (res + (LL)qp(2, cnt) * qp(3, n - i) % mod) % mod;
			cnt ++ ;
		}
	res = (res + qp(2, cnt)) % mod;
	
	printf("%d\n", res);
	return 0;
}

Measured memory_bytes: 384
l = list(map(int, input().split()))

l.sort()

ans = 0

if (l[2] - l[0]) % 2 == 1:
    ans += (l[2] - l[0]) // 2
    l[0] = l[2] - 1
else:
    ans += (l[2] - l[0]) // 2
    l[0] = l[2]

if (l[2] - l[1]) % 2 == 1:
    ans += (l[2] - l[1]) // 2
    l[1] = l[2] - 1
else:
    ans += (l[2] - l[1]) // 2
    l[1] = l[2]

if l[0] == l[1] == l[2] - 1:
    print(ans + 1)
elif l[0] == l[1] == l[2]:
    print(ans)
else:
    print(ans + 2)

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

int main()
{
	string s;
	cin >> s;
	string datas[] = { "SUN","MON","TUE","WED","THU","FRI","SAT" };
	for (int i = 0; i < 7; i++) {
		if (datas[i] == s) { cout << (7 - i); }
	}
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<string>

using namespace std;

int main(){

	string inp;
	string base = ("0123456789abcdef" );
	string scol[8] = { "black", "blue", "lime", "aqua", "red", "fuchsia", "yellow", "white" };
	int icol[8][3] = { { 0, 0, 0 }, { 0, 0, 255 }, { 0, 255, 0 }, { 0, 255, 255 }, { 255, 0, 0 }, { 255, 0, 255 }, { 255, 255, 0 }, { 255, 255, 255 } };
	int r, g, b;
	int ans;
	double ansnum;

	while (1){

		cin >> inp;
		if (inp == "0") break;

		r = base.find(inp[2]) * 1 + base.find(inp[1]) * 16;
		g = base.find(inp[4]) * 1 + base.find(inp[3]) * 16;
		b = base.find(inp[6]) * 1 + base.find(inp[5]) * 16;

		ans = 0;
		ansnum = pow(r - icol[0][0], 2.0) + pow(g - icol[0][1], 2.0) + pow(b - icol[0][2], 2.0);
		for (int i = 1; i < 8; i++){
			if (ansnum>pow(r - icol[i][0], 2.0) + pow(g - icol[i][1], 2.0) + pow(b - icol[i][2], 2.0)){
				ans = i;
				ansnum = pow(r - icol[i][0], 2.0) + pow(g - icol[i][1], 2.0) + pow(b - icol[i][2], 2.0);
			}
		}

		cout << scol[ans] << endl;

	}
}

Measured memory_bytes: 1188
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
  private static class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
      reader = new BufferedReader(new InputStreamReader(in));
      tokenizer = null;
    }

    public String next() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          tokenizer = new StringTokenizer(reader.readLine());
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
      return tokenizer.nextToken();
    }

    public String nextLine() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          return reader.readLine();
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }

      return tokenizer.nextToken("\n");
    }

    public long nextLong() {
      return Long.parseLong(next());
    }

    public int nextInt() {
      return Integer.parseInt(next());
    }

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

    public int[] nextIntArray(int n) {
      int[] a = new int[n];
      for (int i = 0; i < n; i++)
        a[i] = nextInt();
      return a;
    }

    public long[] nextLongArray(int n) {
      long[] a = new long[n];
      for (int i = 0; i < n; i++)
        a[i] = nextLong();
      return a;
    }
  }

  public static void main(String[] args) {
    FastScanner sc = new FastScanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    int d = sc.nextInt();
    boolean turn = true;
    while (a > 0 && c > 0) {
      if (turn) c -= b;
      else a -= d;
      turn = !turn;
    }
    System.out.println(a > 0 ? "Yes" : "No");
  }
}

Measured memory_bytes: 32696
import sys
input = sys.stdin.readline
from itertools import accumulate
N, K = map(int, input().split())
A = list(map(int, input().split()))
B = accumulate([0]+ A)
C = [(b-i)%K for i, b in enumerate(B)]
cnt = dict()
cnt[C[0]] = 1
res = 0
for i in range(1, N+1):
    if i >= K:
        cnt[C[i-K]] = cnt.get(C[i-K],0) - 1
    res += cnt.get(C[i], 0)
    cnt[C[i]] = cnt.get(C[i],0) + 1
print(res)


Measured memory_bytes: 126228
#define _USE_MATH_DEFINES
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <map>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#define speed ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define eps 1e-7
#define inf 0x3f3f3f3f
#define mod 1000000007ll
using namespace std;

int main() {
	speed;
	int a, b, c;
	cin >> a >> b >> c;
	return cout << (b - a == c - b ? "YES" : "NO"), 0;
}

Measured memory_bytes: 256
import bisect

X, N = map(int, input().split())
if N > 0:
  Ps = list(map(int, input().split()))
else:
  Ps = []

Pst = set(Ps)

ab = 200
tmp = 200
rlt = -1
for i in range(102):
  if i in Pst:
    continue
  else:
    tmp = abs(i-X)
    if ab > tmp:
      ab = tmp
      rlt = i
      
print(rlt)

Measured memory_bytes: 62112
N = int(input())
S = input()

import numpy as np

al = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

S_index = np.array([al.index(i) for i in S])
T_index = S_index + N

T = [al[i%26] for i in T_index]

T = "".join(T)

print(T)

Measured memory_bytes: 12368
n = int(input())
ans = [0] * 10050
for i in range(1,101):
  for j in range(1,101):
    for k in range(1,101):
      v = i*i+j*j+k*k+i*j+j*k+k*i
      if v<10050:
        ans[v]+=1
for i in range(n):
  print(ans[i+1])

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

int H, W;
vector<string> grid;
int hl[2002][2002] = {};
int hr[2002][2002] = {};
int wu[2002][2002] = {};
int wd[2002][2002] = {};

void init() {
    for(int i=1; i<=H; ++i) {
        for(int j=1; j<=W; ++j) {
            if(grid[i - 1][j - 1] == '.') {
                hl[i][j] = hl[i][j - 1] + 1;
            } else {
                hl[i][j] = 0;
            }
        }
        for(int j=W; j>0; --j) {
            if(grid[i - 1][j - 1] == '.') {
                hr[i][j] = hr[i][j + 1] + 1;
            } else {
                hr[i][j] = 0;
            }
        }
    }

    for(int j=1; j<=W; ++j) {
        for(int i=1; i<=H; ++i) {
            if(grid[i - 1][j - 1] == '.') {
                wu[i][j] = wu[i - 1][j] + 1;
            } else {
                wu[i][j] = 0;
            }
        }
        for(int i=H; i>0; --i) {
            if(grid[i - 1][j - 1] == '.') {
                wd[i][j] = wd[i + 1][j] + 1;
            } else {
                wu[i][j] = 0;
            }
        }
    }
}

int main() {
    cin >> H >> W;
    grid.resize(H);
    for(int i=0; i<H; ++i) cin >> grid[i];
    init();

    int res = 0;
    for(int i=1; i<=H; ++i) {
        for(int j=1; j<=W; ++j) {
            if(grid[i - 1][j - 1] == '#') continue;
            res = max(res, hl[i][j] + hr[i][j] + wu[i][j] + wd[i][j] - 3);
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 66944
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
typedef long long int ll;
void swap(ll *x,ll *y){ll temp;temp=*x;*x=*y;*y=temp;}
ll compare_asc(const void *a,const void *b){return *(ll*)a-*(ll*)b;}
ll compare_desc(const void *a,const void *b){return *(ll*)b-*(ll*)a;}
ll max(ll x,ll y){return x>y?x:y;}
ll min(ll x,ll y){return x>y?y:x;}
/*void qsort(配列のアドレス,配列のサイズ,sizeof(配列の型),比較関数(昇順or降順)) */

int main(){
    int n,a[200];
    int min=9999,max=-1;
    
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
        if(min>a[i])min=a[i];
        if(max<a[i])max=a[i];
    }
    printf("%d\n",max-min);
    return 0;
    
}

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

int main() {
  int N;
  cin >> N;
  vector<int> L(N);
  for(int i=0;i<N;i++){
    cin >> L.at(i);
  }
  long long ans = 0;
  std::sort(L.begin(), L.end());
  for(int i=0;i<N;i++){
    for(int j=i+1;j<N;j++){
      for(int k=j+1;k<N;k++){
        int c = L.at(i);
        int a = L.at(j);
        int b = L.at(k);
        if(b - a >= c){
          break;
        }
        if(c < a + b){
          ans++;
        }
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define endl '\n';
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr double INFD = 1e100;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ios::sync_with_stdio(false);
// cin.tie(nullptr);
// ---------------------------------------------------------------------------

int main(){
  int N;
  cin >> N;
  string S;
  cin >> S;
  // ss
  for(int t1=0; t1<2; t1++){
    for(int t2=0; t2<2; t2++){
      vector<int> per(N,0);
      per[0] = (t1 ? 1 : -1);
      per[1] = (t2 ? 1 : -1);
      for(int i=2; i<N; i++){
        if(per[i-1] == 1){
          if((S[i-1] == 'x' and per[i-2] == 1) or (S[i-1] == 'o' and per[i-2] == -1)){
            per[i] = -1;
          }else{
            per[i] = 1;
          }
        }else{
          if((S[i-1] == 'x' and per[i-2] == -1) or (S[i-1] == 'o' and per[i-2] == 1)){
            per[i] = -1;
          }else{
            per[i] = 1;
          }
        }
      }
      bool can = true;
      for(int i=0; i<N; i++){
        if(per[i] == 1){
          if(S[i] == 'o'){
            if(per[(i-1+N)%N] != per[(i+1)%N]){
              can = false;
            }
          }else{
            if(per[(i-1+N)%N] == per[(i+1)%N]){
              can = false;
            }

          }
        }else{
          if(S[i] == 'o'){
            if(per[(i-1+N)%N] == per[(i+1)%N]){
              can = false;
            }        
          }else{
            if(per[(i-1+N)%N] != per[(i+1)%N]){
              can = false;
            }
          }
        }
      }
      if(can){
        for(int i=0; i<N; i++){
          if(per[i] == 1){
            cout << 'S';
          }else{
            cout << 'W';
          }
        }
        cout << endl;
        return 0;
      }
    }
  }
  cout << -1 << endl;
  return 0;
}

Measured memory_bytes: 1016
#include<stdio.h>
int MIN(int a,int b){return a<b?a:b;}
int ta[1010],to[1000010],nt[1000010],co[1000010],F[1010];
int MF(int s,int t,int e,int min){
  if(s==t||min==0)return min;
  int i,r;
  F[s]=1;
  for(i=ta[s];i+1;i=nt[i]){
    if(F[to[i]])continue;
    r=MF(to[i],t,e,MIN(min,co[i]));
    co[i]-=r;
    co[(i+e)%(2*e)]+=r;
    if(r)return r;
  }
  return 0;
}
int Flow(int s,int t,int v,int e,int min){
  while(v--)F[v]=0;
  return MF(s,t,e,min);
}
int maxf(int s,int t,int v,int e){
  int f,r;
  for(f=0;r=Flow(s,t,v,e,1e9);f+=r);
  return f;
}
int main(){
  int n,m,q,l,ans,e,r=0,i,a,b,k;
  scanf("%d %d %d",&n,&m,&q);
  e=m+q;
  for(i=0;i<=n;i++)ta[i]=-1;
  for(i=0;i<m;i++){
    scanf("%d %d",&a,&b);
    nt[r  ]=ta[to[r+e]=a];
    nt[r+e]=ta[to[r  ]=b];
    co[ta[b]=r+e]=co[ta[a]=r]=1;
    r++;
  }/*printf("a\n");
  for(i=0;i<=n;i++){printf("%d:",i);
    for(k=ta[i];k+1;k=nt[k])printf(" %d",to[k]);
    printf("\n");
    }//*/
  ans=maxf(1,n,n+1,e);//printf("%d\n",ans);
  while(q--){
    scanf("%d %d %d",&k,&a,&b);
    if(k==1){
      for(i=ta[a];i+1;i=nt[i]){
	if(to[i]==b)break;
      }
      if(i==-1){
	nt[r  ]=ta[to[r+e]=a];
	nt[r+e]=ta[to[r  ]=b];
	co[ta[b]=r+e]=co[ta[a]=r]=1;
	r++;
      }
      else co[i]=co[(i+e)%(2*e)]=1;
      ans+=Flow(1,n,n+1,e,1);
    }
    else{
      for(k=ta[a];to[k]-b;k=nt[k]);
      if(co[k]==2){
	i=a;
	a=b;
	b=i;
	k=(k+e)%(2*e);
      }
      if(co[k]==1);//co[i]=co[(i+e)%(2*e)]=0;
      else if(Flow(a,b,n+1,e,1)==0){
	Flow(n,b,n+1,e,1);
	Flow(a,1,n+1,e,1);
	ans--;
      }
      co[k]=co[(k+e)%(2*e)]=0;
    }
    printf("%d\n",ans);
  }
  return 0;
}



Measured memory_bytes: 2272
#include <bits/stdc++.h>
#define rep(i,m,n) for(int i=m;i<n;i++)
#define c(n) cin>>n
#define co(n) cout<<n<<endl
using namespace std;

int main(){
  long a,b,c=0,d=1,e,f,g,h,n,m,mx=0,x,y,ans=0;
  cin>>n;
  int aa[n];
  rep(i,0,n) cin>>aa[i];
  sort(aa,aa+n);
  rep(i,0,n-1) if(aa[i]!=aa[i+1]) d++;
  co(d);
    
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
	ll x;
	cin>>x;
	map<ll,ll> map;
	map[0]=0;
	for(ll i=1;;i++){
		ll y=pow(i,5);
		if(y>1e18){
			break;
		}
		map[y]=i;
		map[-y]=-i;
	}
	
	std::map<ll,ll> ::iterator it,it2;
	for(ll i=-3981;;i++){
		ll y=pow(i,5);
		ll z=y-x;
		it=map.find(y);
		it2=map.find(z);
		if(it!=map.end()&&it2!=map.end()){
			ll a=map[y];
			ll b=map[z];
			
			ll p1=pow(a,5)-pow(b,5);
			if(p1==x)
				cout<<a<<" "<<b<<endl;
			else
				cout<<b<<" "<<a<<endl;
			return 0;
		}
	}
}

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

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
void tostr(ll x,string& res){while(x)res+=('0'+(x%10)),x/=10; reverse(ALL(res)); return;}
template<class T> inline bool chmax(T& a,T b){ if(a<b){a=b;return 1;}return 0; }
template<class T> inline bool chmin(T& a,T b){ if(a>b){a=b;return 1;}return 0; }
//end

template<unsigned mod=1000000007>struct mint {
   unsigned val;
   static unsigned get_mod(){return mod;}
   unsigned inv() const{
      int tmp,a=val,b=mod,x=1,y=0;
      while(b)tmp=a/b,a-=tmp*b,swap(a,b),x-=tmp*y,swap(x,y);
      if(x<0)x+=mod; return x;
   }
   mint():val(0){}
   mint(ll x):val(x>=0?x%mod:mod+(x%mod)){}
   mint pow(ll t){mint res=1,b=*this; while(t){if(t&1)res*=b;b*=b;t>>=1;}return res;}
   mint& operator+=(const mint& x){if((val+=x.val)>=mod)val-=mod;return *this;}
   mint& operator-=(const mint& x){if((val+=mod-x.val)>=mod)val-=mod; return *this;}
   mint& operator*=(const mint& x){val=ll(val)*x.val%mod; return *this;}
   mint& operator/=(const mint& x){val=ll(val)*x.inv()%mod; return *this;}
   mint operator+(const mint& x)const{return mint(*this)+=x;}
   mint operator-(const mint& x)const{return mint(*this)-=x;}
   mint operator*(const mint& x)const{return mint(*this)*=x;}
   mint operator/(const mint& x)const{return mint(*this)/=x;}
   bool operator==(const mint& x)const{return val==x.val;}
   bool operator!=(const mint& x)const{return val!=x.val;}
}; using Mint=mint<>;
struct factorial {
   vector<Mint> Fact,Finv,Inv;
   factorial(int maxx){
      Fact.resize(maxx); Finv.resize(maxx); Inv.resize(maxx);
      Fact[0]=Fact[1]=Finv[0]=Finv[1]=Inv[1]=1; unsigned mod=Mint::get_mod();
      rep(i,2,maxx){
         Fact[i]=Fact[i-1]*i;
         Inv[i]=Inv[mod%i]*(mod-mod/i);
         Finv[i]=Finv[i-1]*Inv[i];
      }
   }
   Mint fact(int n,bool inv=0){if(inv)return Finv[n];else return Fact[n];}
   Mint inv(int n){return Inv[n];}
   Mint nPr(int n,int r){if(n<0||n<r||r<0)return Mint(0);else return Fact[n]*Finv[n-r];}
   Mint nCr(int n,int r){if(n<0||n<r||r<0)return Mint(0);else return Fact[n]*Finv[r]*Finv[n-r];}
};

int main(){
   int n,k; cin>>n>>k;
   vector<Mint> tmp(k+1);
   Mint res;
   rrep(i,k,0){
      tmp[i]=Mint(k/i).pow(n);
      for(int j=2*i;j<=k;j+=i)tmp[i]-=tmp[j];
      res+=tmp[i]*i;
   } printf("%d\n",res.val);
   return 0;
}

Measured memory_bytes: 3788
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
int N,C,K;
int T[100001];
int ans=0;
using namespace std;
int main(){
  cin >>  N >> C >> K;
  for(int i=0;i<N;i++)cin >> T[i];
  sort(T,T+N);
  int x=T[0]+K,c=0;
  for(int i=0;i<N-1;i++){
    if(T[i]<=x && x<=T[i]+K){
      c++;
      if(c==C){ans++;x=T[i+1]+K;c=0;}
    }
    else {
      x=T[i]+K;
      ans++;
      c=1;
    }
  }
  if(T[N-1]<=x && x<=T[N-1]+K){
    c++;
    ans++;
  }
  else ans+=2;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 640
INF = 10 ** 9
N = int(input())
h = [int(x) for x in input().split()]

dp = [INF] * N
dp[0] = 0

for i in range(N - 1):
    for j in range(1, 3):
        if i + j < N:
            dp[i + j] = min(dp[i + j], dp[i] + abs(h[i + j] - h[i]))

print(dp[N - 1])


Measured memory_bytes: 13712
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <map>
#include <vector>
#include <deque>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <iterator>

using namespace std;

#if 1
#define PRINT(x) { cout << #x << ": " << (x) << endl; }
#define PRINT_CONTAINER(x)  { cout << #x << ": ";                       \
        for (size_t ix = 0; ix < (x).size(); ++ix) cout << (x)[ix] << ", "; \
        cout << endl; }
#else
#define PRINT(x)
#define PRINT_CONTAINER(x)
#endif

int c[501];
int s[501];
int f[501];
int m[501];

int main(int argc, char *argv[])
{
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n - 1; ++i)
    {
        scanf("%d %d %d", &c[i], &s[i], &f[i]);
        m[i] = s[i] / f[i];
    }

    for (int i = 0; i < n - 1; ++i)
    {
        int t = s[i] + c[i];
        for (int j = i + 1; j < n - 1; ++j)
        {
            int k = max<int>(0, ceil((t - s[j]) / (double)f[j]));
            t = s[j] + f[j] * k + c[j];
        }
        printf("%d\n", t);
   }
    printf("0\n");
}


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

ll v[105], dp[105][100005];
ll pref[105][100005];
ll mod = 1e9+7;

int main(){
    ll n, k; cin >> n >> k;
    for(int i = 1; i <= n; i++)
        cin >> v[i];
    
    for(int j = 0; j <= k; j++){
        if(j <= v[1])
            dp[1][j] = 1;
        pref[1][j] = ((pref[1][j]%mod+pref[1][max(0, j-1)]%mod)%mod + (dp[1][j]))%mod;
    }
    
    for(int i = 2; i <= n; i++){
        for(int j = 0; j <= k; j++){
            if(j-v[i]-1 >= 0)
                dp[i][j] = (dp[i][j] + pref[i-1][j] - pref[i-1][j-v[i]-1] + mod)%mod;
            else
                dp[i][j] = (dp[i][j] + pref[i-1][j]%mod)%mod;
            pref[i][j] = (pref[i][j-1]%mod + dp[i][j]%mod)%mod;
        }
    }
    cout << dp[n][k] << endl;
    return 0;
}

Measured memory_bytes: 159232
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp14
{
    class Class2
    {
        static void Main()
        {
            var I = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int ans = I[0] / I[1];
            if (I[0] % I[1] != 0)
                ans++;
            Console.WriteLine(ans);

        }
    }
}


Measured memory_bytes: 13268
package main

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

var rdr = bufio.NewReaderSize(os.Stdin, 1000000)

func readLine() string {
	buf := make([]byte, 0, 1000000)
	for {
		l, p, e := rdr.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

/*******************************************************************/

var s string

func main() {
	s = readLine()
	runes := []rune(s)
	head, tail := -1, 0
	for i, r := range runes {
		if head == -1 && r == 'A' {
			head = i
		}
		if r == 'Z' {
			tail = i
		}
	}
	fmt.Println(tail - head + 1)
}


Measured memory_bytes: 2176
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
bool compare(int a,int b){
    return a>b;
}
int main() {
  int n,m;
  cin>>n>>m;
  int a[n];
  long long sum=0;
  for(int i=0;i<n;i++){
    cin>>a[i];
   sum+=a[i];
  }
  //cout<<sum<<endl;
  float x=(float)sum/(4*m);
  //cout<<x<<" ";
  sort(a,a+n,compare);
  if(a[m-1]<x){
      cout<<"No";
      return 0;
  }
  else
  cout<<"Yes";
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>

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

    string s;
    cin >> s;

    int n = s.length();
    string s0 = "";
    string s1 = "";
    for(int i=0;i<n;++i) (i%2==1) ? s0 += '0' : s0 += '1';
    for(int i=0;i<n;++i) (i%2==1) ? s1 += '1' : s1 += '0';

    int ans0 = 0;
    int ans1 = 0;
    for(int i=0;i<n;++i){
        if(s0[i]!=s[i])++ans0;
        if(s1[i]!=s[i])++ans1;
    }
    int ans = (ans0>ans1) ? ans1 : ans0;
    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 720
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1e9;
const ll MOD = 1e9 + 7;

int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;

    rep(i, s.size()){
        int m = s[i] - 'A';
        char ans = 'A' + m + n;
        if(m+n >= 26){
            m = (m+n-26);
            ans = 'A' + m;
        }
        cout << ans;
    }
    cout << endl;
}

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

struct Closed_Section {
    bool valid;
    int64_t begin;
    int64_t end;
    Closed_Section(bool _valid, int64_t _begin, int64_t _end) {
        valid = _valid; begin = _begin; end = _end;
    }
    Closed_Section() {
        valid = false, begin = 0; end = -1; //配列を定義するためにデフォルトコンストラクタが必要。
    }
    int64_t size() { return valid ? end - begin + 1 : 0; }
    void dump() { std::cout << "valid:" << valid << " begin:" << begin << " end:" << end << std::endl; }
};

Closed_Section binary_search(const int64_t L, const int64_t R, std::function<bool(int64_t)> func) {
    if (R < L) { return Closed_Section(false, L, R); }
    const bool res_L = func(L);
    const bool res_R = func(R);
    if (res_L && res_R) {
        return Closed_Section(true, L, R);
    } else if (!res_L && !res_R) {
        return Closed_Section(false, 0, -1);
    } else {
        int64_t lb = L;
        int64_t ub = R;
        while (lb + 1 < ub) {
            int64_t mid = (lb + ub) / 2;
            if (res_L == func(mid)) {
                lb = mid;
            } else {
                ub = mid;
            }
        }
        return res_L ? Closed_Section(true, L, lb) : Closed_Section(true, ub, R);
    }
}

Closed_Section binary_search(const Closed_Section& cs, std::function<bool(int64_t)> func) {
    return cs.valid ? binary_search(cs.begin, cs.end, func) : cs;
}

// end of template

int64_t N;

int main(int argc, char **argv) {
    std::cin >> N;
    std::vector<int64_t> L(N+1);
    for (int i = 1; i <= N; i++) {
        std::cin >> L[i];
    }
    std::sort(L.begin(), L.end());
    int64_t ret = 0;
    for (int64_t i = 1; i <= N; i++) {
        for (int64_t j = i+1; j <= N; j++) {
            auto cs = binary_search(j+1, N, [&](int64_t k){
                return L[k] < L[i] + L[j];
            });
            ret += cs.size();
        }
    }
    std::cout << ret << std::endl;
}

Measured memory_bytes: 256
from sys import stdin, stdout
from collections import defaultdict
def readLine_int_list():return list(map(int, stdin.readline().split()))
def main():
    d = defaultdict(lambda: 0)
    t = defaultdict(lambda: 0)
    
    n=int(input())
    _d=readLine_int_list()
    for i in _d:
        d[i] += 1
        
    m = int(input())
    _t = readLine_int_list()
    
    for i in _t:
        t[i] += 1
    
    ans = "YES"
    for i in t:
        if i in d:
            if t[i] - d[i] > 0:
                ans = "NO"
                break
        else:
            ans = "NO"
            break
    print(ans)
if __name__ == "__main__":
    main()

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

const int MAX = 510000;
const int MOD = 1000000007;
const long long INF = 1LL << 60;

const ll MAXINDx = 3000;
const ll MAXINDy = 3000;

double dp[MAXINDx][MAXINDy] = {0};

vector<vector<int>> edges;

ll R, B, x, y;

bool check(ll mid)
{
    if (mid > R || mid > B)
        return false;
    ll num = (R - mid) / (x - 1) + (B - mid) / (y - 1);
    return (num >= mid);
}

bool comp(const pair<int, int> a, const pair<int, int> b)
{
    return a.second < b.second;
}

int main()
{
    int N, M;

    cin >> N >> M;

    vector<pair<int, int>> list;

    for (int i = 0; i < M; i++)
    {
        int s, g;
        cin >> s >> g;
        list.push_back(make_pair(s, g));
    }

    sort(list.begin(), list.end(), comp);
    int lasB = -1;
    int ans = 0;
    for (auto req : list)
    {
        if (req.first <= lasB)
            continue;
        lasB = req.second - 1;
        ans++;
    }
    cout << ans << endl;
    return 0;
}

/*Syakutori
cout << fixed << setprecision(10) << ans << endl;
while(cin >>b && b)){
      ll t = 1;
      long long int ansS = 1,ansT=0;
      long long int sum = 0;

      for(ll s = 1;s < 50000000;s++){

        while(t <  50000000 && sum+Rsum[t] < b){
          sum += Rsum[t];
          t++;
        }
        if(b == sum+Rsum[t]){
          if(ansT - ansS < t-s){
            ansS = s;
            ansT = t;
          }
          cout <<ansS<<" "<<ansT-ansS + 1<<endl;
          break;
        }
        if(t == s)++t;
        else sum -= Rsum[s];
        }
    }

//priority_queue<long long int,vector<long long int>, greater<long long int>> PQ;
//priority_queue<long long int> PQ1;



ll gcd(ll a,ll b){
  if(a%b == 0){
    return b;
  }else{
    return gcd(b,a%b);
  }
}
/*
int rec(int v){
    int res = 0;

    if(dp[v] > -1)return dp[v];

    for(auto nv: edges[v]){
        res = max(res, rec(nv) + 1);
    }
    return dp[v] = res;
}
*/


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

int main()
{
    int n,t,x=0;
    cin>>n>>t;
    vector<int> v(n),sell(n);
    for(int i=0;i<n;i++)    cin>>v[i];
    for(int i=n-1;i>=0;i--)
    {
        if(v[i]>x)
            x=v[i];
        sell[i]=x;
    }
    for(int i=0;i<n;i++)
        v[i]=sell[i]-v[i];
    cout<<count(v.begin(),v.end(),*max_element(v.begin(),v.end()));
    return 0;
}



Measured memory_bytes: 3972
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop
from itertools import permutations, accumulate
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce
#from fractions import gcd
#from math import gcd
import sys
def I(): return int(input())  # '123' -> 123
def Is(): return map(int, input().split())  # '123 456' -> 123, 456
def LI(): return list(map(int, input().split()))  # '123 456' -> [123, 456]
def TI(): return tuple(map(int, input().split()))  # '123 456' -> (123, 456)
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()  # 'aa bb' -> 'aa','bb' or ['aa','bb']
def LS(): return list(input())  # 'abc123' -> ['a','b','c','1','2','3']
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(1000000)
MOD = 1000000007
INF = float('inf')

n = I()
A = LI()

ans = 0
i = 1
for a in A:
    if a != i:
        ans += 1
    else:
        i += 1

if i == 1:
    print("-1")
else:
    print(ans)

Measured memory_bytes: 78192
n = int(input())

c = 0

def check(a, n):
  if a == 0:
    return False
  d = n // a
  m = n % a
  return d == m

for i in range(1, n):
  ii = i*i
  if ii > n:
    break
  if n % i == 0:
    r = i - 1
    if check(r, n):
      c += i
    if ii != n:
      r = n // i - 1
      if check(r, n):
        c += r

print(c)

Measured memory_bytes: 40556
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
    char str[15];
    char c[15];
    int pos = 0;
    scanf("%s",str);
    int len = strlen(str);
    for(int i=0;i<len;i++)
    {
        if(str[i]=='0')
            c[pos++] = '0';
        else if(str[i]=='1')
            c[pos++] = '1';
        else if(pos>0)
            pos--;
    }
    for(int i=0;i<pos;i++)
    {
        printf("%c",c[i]);
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline

N,M=map(int,input().split())
D=list(map(int,input().split()))
EDGE=[tuple(sorted(map(int,input().split()))) for i in range(M)]
DICE=dict()

for i in range(M):
    DICE[EDGE[i]]=i
    
E=[[] for i in range(N+1)]

for x,y in EDGE:
    E[x].append(y)
    E[y].append(x)

P=[(x,ind+1) for ind,x in enumerate(D)]
P.sort()
D=[0]+D

DECIDED=[""]*(N+1)
DIS=[-1]*M

for x,po in P:
    flag=0
     
    for to in E[po]:
        if DECIDED[to]!="":
            flag=1
            break

    if flag==0:
        for to in E[po]:
            if D[to]==x:
                DIS[DICE[tuple(sorted([po,to]))]]=x
                DECIDED[po]="B"
                DECIDED[to]="W"
                break
        else:
            print(-1)
            sys.exit()

    else:            
        for to in E[po]:
            if DECIDED[to]!="" and DECIDED[po]=="":
                if DECIDED[to]=="B":
                    DECIDED[po]="W"
                else:
                    DECIDED[po]="B"
                    
                DIS[DICE[tuple(sorted([po,to]))]]=x
                break

            elif DECIDED[to]!="" and DECIDED[po]==DECIDED[to]:
                if x<=D[to]:
                    continue
                    
                DIS[DICE[tuple(sorted([po,to]))]]=x-D[to]
                break

            elif DECIDED[to]!="" and DECIDED[po]!=DECIDED[to]:
                if x<=D[to]:
                    continue
                    
                DIS[DICE[tuple(sorted([po,to]))]]=x
                break
        
print("".join(DECIDED[1:]))
for d in DIS:
    if d==-1:
        print(10**9)
    else:
        print(d)
        

    
            
    
    



Measured memory_bytes: 128612
#include <cstdio>
#include <iostream>
#include <string>
using namespace std;
long long ans,a[100],f=1,tmp,l;
int vis[100];
string s;
void calc()
{
	long long tmp=0;
	for(int i=1;i<=l;i++)
	{
		tmp=tmp*10+a[i];
		if(vis[i])ans+=tmp,tmp=0;
	}
	ans+=tmp;
}
void dfs(int pos)
{
	if(pos==l)
	{
		calc();
		return;
	}
	vis[pos]=1;dfs(pos+1);
	vis[pos]=0;dfs(pos+1);
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	cin>>s;l=s.length();
	for(int i=0;i<l;i++)a[i+1]=s[i]-48;
	dfs(1);
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

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

const ll mod=1e9+7;

vector<vector<ll>> G;
ll ans[100100][2];

ll dfs(ll v,ll p=-1,ll c=0){ //c==0 is black, c==1 is white
    ll res=1;
    if(ans[v][c]!=0) return ans[v][c];
    if(c==0){
        for(auto x:G[v]){
            if(x==p) continue;
            res*=dfs(x,v,1);
            res%=mod;
        }
    }
    else{
        for(auto x:G[v]){
            if(x==p) continue;
            res*=((dfs(x,v,0)+dfs(x,v,1))%mod);
            res%=mod;
        }
    }
    return ans[v][c]=res;
}

int main()
{
    ll n;
    cin >> n;
    G.resize(n);
    rep(i,n-1){
        ll x,y;
        cin >> x >> y;
        x--;
        y--;
        G[x].push_back(y);
        G[y].push_back(x);
    }
    ll anss=dfs(0,-1,0)+dfs(0,-1,1);
    anss%=mod;
    cout << anss << endl;
    return 0;
} 

Measured memory_bytes: 11392
n = int(input())
a = input().split()
#print("input",a)

ans = []
count = 0
x = 1
for i in a:
    if x == int(i):
        x += 1
        ans.append(i)
    else:
        count += 1

#print("ans",' '.join(ans))
if count != n:
    print(count)
else:
    print(-1)

Measured memory_bytes: 20568
#include<bits/stdc++.h>
void debug_impl(){std::cerr<<std::endl;}
template<class Head,class...Tail>void debug_impl(Head head, Tail... tail){std::cerr << " " << head;debug_impl(tail...);}
    template<class Container,class Value=typename Container::value_type,std::enable_if_t<!std::is_same<Container,std::string>::value,std::nullptr_t> = nullptr>
std::ostream&operator<<(std::ostream&os,Container const&v)
{os<<"{";for(auto it=v.begin();it!=v.end();it++){os<<(it!=v.begin()?",":"")<<*it;}return os<<"}";}
    template<template<class...>class Tuple,class...Args,std::size_t...Inds,std::size_t=std::tuple_size<Tuple<Args...>>::value>
std::ostream&tuple_output_impl(std::ostream&os,const Tuple<Args...>&tuple,std::integer_sequence<std::size_t,Inds...>)
{os<<"(";(void)std::initializer_list<int>{((void)(os<<(Inds>0?",":"")<<std::get<Inds>(tuple)),0)...};return os<<")";}
    template<template<class...>class Tuple,class...Args,std::size_t=std::tuple_size<Tuple<Args...>>::value>
std::ostream&operator<<(std::ostream&os,const Tuple<Args...>&tuple)
{return tuple_output_impl(os,tuple,std::index_sequence_for<Args...>());}
#define DEBUG 1
#if DEBUG
#define debug(...)do{std::cerr<<std::boolalpha<<"["<<#__VA_ARGS__<<"]:";debug_impl(__VA_ARGS__);std::cerr<<std::noboolalpha;}while(false)
#else
#define debug(...) {}
#endif
int main(){
    int n;std::cin>>n;
    std::vector<long long>a(n);
    for(int i=0;i<n;i++){
        long long x;std::cin>>x;
        a.at(i)-=x;
    }
    for(int i=0;i<n;i++){
        long long x;std::cin>>x;
        a.at(i)+=x;
    }
    long long time=0,sub=0;
    for(int i=0;i<n;i++){
        time+=a.at(i);
        if(a.at(i)<0)sub-=a.at(i);
        else sub+=a.at(i)%2;
    }
    debug(time,sub);
    std::cout<<(sub<=time?"Yes":"No")<<std::endl;
}



Measured memory_bytes: 384
N, Y = map(int, input().split())
ans = 0
a = 0
b = 0
c = 0
for a in range(N+1):
    for b in range(N-a+1):
        c = N - a - b
        if (a*10000 + b*5000 + c*1000) == Y:
            ans = 1
            x = a
            y = b
            z = c
            break
if ans == 1:
    print(x,y,z)
else:
    print( '-1 -1 -1')

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

typedef pair<int, int> pii;

const int MN = 3010;

int N;
string S;
int chk[MN << 1], inva[MN << 1], invb[MN << 1];
vector<pii> seg;

bool cmp(string &a, string &b) {
    int n = a.size();
    for(int i = 0; i < b.size(); i++) {
        if(a[i % n] != b[i]) return a[i % n] > b[i];
    }
    return true;
}

int main() {
    std::ios::sync_with_stdio(false);

    cin >> N >> S;

    int cnt1 = 0;
    int cnt2 = 0;
    for(int i = 0; i < 2 * N; i++) {
        if(S[i] == 'a') chk[i] = cnt1++, inva[ chk[i] ] = i;
        else chk[i] = cnt2++, invb[ chk[i] ] = i;
    }

    int sum = 0, st = 0;
    for(int i = 0; i < 2 * N; i++) {
        if(S[i] == 'a') sum++;
        else sum--;
        if(sum == 0) {
            seg.push_back({st, i});
            st = i + 1;
        }
    }
    seg.push_back({st, 2 * N - 1});

    string ans;
    for(int i = (int)seg.size() - 1; i >= 0; i--) {
        int l = seg[i].first;
        int r = seg[i].second;

        if(S[l] == 'a') {
            string tmp;
            for(int j = l; j <= r; j++) {
                if(S[j] == 'a') {
                    tmp.push_back('a');
                    tmp.push_back('b');
                    j = invb[ chk[j] ];
                }
            }
            if(cmp(tmp, ans)) ans = tmp + ans;
        }
        else {
            int ll = chk[l];
            int rr = chk[r];

            string mx;
            for(int j = rr; j >= ll; j--) {
                string tmp;
                for(int k = l; k <= r; k++) {
                    if(chk[k] >= j) tmp.push_back(S[k]);
                }
                if(mx < tmp) mx = tmp;
            }
            if(cmp(mx, ans)) ans = mx + ans;
        }
    }
    cout << ans;
}


Measured memory_bytes: 384
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int K,S;
    cin>>K>>S;
    
    int cnt=0;
    for(int X=0;X<=K;X++){
        for(int Y=0;Y<=K;Y++){
            if(S-(X+Y)<=K&&S-(X+Y)>=0){
                cnt++;
            }
        }
    }
    
    cout<<cnt<<endl;
    
}


Measured memory_bytes: 256
#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;
typedef long long ll;




int main()
{

    int x,y;
    cin >> x >> y;
    cout << x+y/2 << endl;
    
    
    return 0;
}


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

int main() {
  int H, W; cin >> H >> W;
  char S[H+2][W+2];
  for (int i = 0; i < W+2; i++) {
    S[0][i] = '.'; S[H+1][i] = '.';
  }
  for (int i  = 1; i < H+1; i++) {
    for (int j = 1; j < W+1; j++)
      cin >> S[i][j];
  }
  for (int i  = 1; i < H+1; i++) {
    for (int j = 1; j < W+1; j++) {
      if (!(S[i][j] == '#')) {
        int c = 0;
        for (int k = -1; k <= 1; k++) {
          for (int l = -1; l <= 1; l++) {
            if(!(k == 0 && l == 0) && S[i+k][j+l] == '#')
              c++;
          }
        }
        S[i][j] = '0' + c;
      }
      cout << S[i][j];
    }
    cout << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <set>
using namespace std;
typedef long long ll;
int a[200005];
bool compare(int a,int b){
    return a>b;
}
int main(){
    ios::sync_with_stdio(0);
    int n,k,x;
    cin>>n>>k;
    memset(a,0,sizeof(a));
    for(int i=0;i<n;i++){
        cin>>x;
        a[x]++;
    }
    int ans=0;
    sort(a,a+n,compare);
    for(int i=k;i<=n;i++){
        ans+=a[i];
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1024
N,M = map(int,input().split())
a = [int(input()) for _ in range(M)]
booli = [False]*(N+1)
for i in a:
    booli[i] = True
mod = 1000000007
INF = -1
dp = [INF]*(N+1)
dp[0] = 1
if booli[1]:
    dp[1] = 0
else:
    dp[1] = 1
def solve():
    for i in range(2,N+1):
        if booli[i]:
            dp[i] = 0
        else:
            dp[i] = dp[i-1]+dp[i-2]
    return dp[N]%mod
print(solve())

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

#define INF 1e9
#define LLINF 1e18
#define pi 3.14159265358979323
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;

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


int main() {
    int a, b, c;
    cin >> a >> b >> c;
    if ((a < c && c < b) || (b < c && c < a)) {
        cout << "Yes" << endl;
    }
    else cout << "No" << endl;
}

Measured memory_bytes: 3632
#!/usr/bin/env python3
import sys
INF = float("inf")


def solve(N: int):
    print((N+1)//2)
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
from collections import Counter
import math


def nCr(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


n = int(input())
s = []
for i in range(n):
    s.append("".join(sorted(input())))
c = Counter(s).most_common()
ans = 0
for i in c:
    if i[1] > 1:
        ans += nCr(i[1], 2)
print(ans)

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

// https://onlinejudge.u-aizu.ac.jp/problems/ALDS1_7_D

int n;
vector<int> preorder, inorder, inorder_rev, postorder;
vector<pair<int, int>> tree;

int make_tree(int left, int right) {  // preorderでの左端と右端
  if (left == right) return -1;
  int top_ltree = left + 1, top_rtree = left + 1;
  int iroot = inorder_rev[preorder[left]];
  for (int i = left + 1; i < right; i++) {
    if (iroot < inorder_rev[preorder[i]]) {
      top_rtree = i;
      break;
    }
  }
  tree[preorder[left]].first = make_tree(top_ltree, top_rtree);
  tree[preorder[left]].second = make_tree(top_rtree, right);
  return preorder[left];
}

void make_postorder(int p) {
  if (p < 0) return;
  make_postorder(tree[p].first);
  make_postorder(tree[p].second);
  postorder.push_back(p);
  return;
}

int main() {
  cin >> n;
  preorder.resize(n);
  inorder.resize(n);
  inorder_rev.resize(n);
  tree.resize(n, make_pair(-1, -1));
  for (int i = 0; i < n; i++) {
    cin >> preorder[i];
    preorder[i]--;
  }
  for (int i = 0; i < n; i++) {
    cin >> inorder[i];
    inorder[i]--;
    inorder_rev[inorder[i]] = i;
  }
  int root = make_tree(0, n);

  postorder.resize(0);
  make_postorder(root);

  for (int i = 0; i < n; i++) {
    cout << postorder[i] + 1 << (i == n - 1 ? "" : " ");
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 3156