akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define pb push_back
#define si(v) int(v.size())
#define len(v) int(v.length())
#define lob(v,n) lower_bound(all(v),n)
#define lobi(v,n) lower_bound(all(v),n) - v.begin()
#define upb(v,n) upper_bound(all(v),n)
#define upbi(v,n) upper_bound(all(v),n) - v.begin()
#define mod 1000000007
#define infi 1900000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vs = vector<string>;
using vc = vector<char>;
using vd = vector<double>;
using vvd = vector<vector<double>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vvp = vector<vector<pair<int,int>>>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;
template<typename T> bool chmax(T &a, T b) {if(a < b) {a = b;return 1;}return 0;}
template<typename T> bool chmin(T &a, T b) {if(a > b) {a = b;return 1;}return 0;}




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

    int N;
    ll K;
    cin >> N >> K;
    vi A(N);
    in(N,A);
    vi C(N+1,-1);
    int pos = 1;
    int t = 0;
    while (K > 0) {
        if(C[pos] == -1){
            C[pos] = t;
            t++;
            pos = A[pos-1];
            K--;
            
        }else{
            int roop = t - C[pos];
            K = K%(ll)roop;
            
            while (K > 0) {
                pos = A[pos-1];
                K--;
            }
        }
    }
    
    cout << pos << endl;
    
    

    return 0;
}


Measured memory_bytes: 4752
$s = gets.chomp.split("").map(&:to_i)
array = [$s.shift]
$answers = []
def dfs(array, digit)
  if digit == $s.size + 1
    $answers << array
    return
  end
  dfs([*array, $s[digit - 1]], digit + 1)
  dfs([*array[0..-2], array[-1] * 10 + $s[digit - 1]], digit + 1)
end
dfs(array, 1)
puts $answers.flatten.inject(:+)


Measured memory_bytes: 3836
import sys
from itertools import product

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]

def solve753(K):
    tmp = []
    for v in product('357', repeat=K):
        if len(set(v)) == 3:
            tmp.append(int(''.join(v)))
    return tmp


def main():
    N = ii()
    d = len(str(N))
    cnt = 0
    for i in range(1, d+1):
        for v in solve753(i):
            if v <= N:
                cnt += 1
    print(cnt)


if __name__ == '__main__':
    main()


Measured memory_bytes: 69360
//#pragma GCC optimize ("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")

#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/rope>
#define pb push_back
#define F first
#define S second
#define ins insert
#define mp make_pair
#define fo(i, n1, n, x) for(int i = n1; i <= n; i += x)
#define foo(i, n, n1, x) for(int i = n; i >= n1; i -= x)
#define bit __builtin_popcount
#define md (l + ((r - l) / 2))
#define all(x) x.begin(),x.end()
#define eb emplace_back
#define ub upper_bound
#define lb lower_bound
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)

using namespace std;
//using namespace __gnu_pbds;
//using namespace __gnu_cxx;


using ll = long long;

//#define int ll

using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;



const int N = 2e5 + 11, mod = 1e9 + 7, mod2 = 998244353;
const int MAX = 1e5 + 11;
const int INF1 = 2e9 + 11;
const ll INF2 = 6e18 + 11;
const double INF3 = 1e8 + 11;
const int base = 500;
const int P = 31;
const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
const int dy[] = {0, 0, 1, -1, 1, -1, 1, -1};
const double EPS = 1e-4;
const double PI = acos(-1.0);


//template<typename T> using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }


mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int n;
main() {
  file("threesum");
  ios;
  cin >> n;
  int x = n%10;
  if (x == 2 || x == 4 || x == 5 || x == 7 || x == 9) cout << "hon";
  else if (x == 0 || x == 1 || x == 6 || x == 8) cout << "pon";
  else cout << "bon";
  return 0;
}
/**

*/


Measured memory_bytes: 3648
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<map>
#define il inline
#define re register
#define fo(i,j,k) for(register int i=j;i<=k;i++)
#define inf 0x7fffffff
typedef long long ll;
using namespace std;
il ll read()
{
	re ll x=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-') f=-1;c=getchar();}
	while(c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
	return f*x;	
}
ll n,ans; 
vector<ll> a;
int main()
{
	cin>>n;
	a.push_back(1);
	ll k=n-1;
	for(re ll i=2;i*i<=k;i++)
	{
		if(k%i==0)
		{
			a.push_back(i);
			if(i*i!=k)
			{
				a.push_back(k/i);
			}
		}
	}
	a.push_back(k);
	for(re ll i=2;i*i<=n;i++)
	{
		for(ll j=n;j>0&&(j%i==0);j/=i)
		{
			ll x=j/i-1;
			if(x%i==0)
			{
				a.push_back(i);
				break;
			}
		}
	}
	a.push_back(n);
	sort(a.begin(),a.end());
	a.erase(unique(a.begin(),a.end()),a.end());
	ans=a.size()-1;
	printf("%lld\n",ans);
	return 0;
}


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

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

  int ans = 0;

  for (int i = 0; i < N; i++) {
    set<char> s;
    for (int j = 0; j < i; j++) {
      for (int k = i; k < N; k++) {
        if (S[j] == S[k])
          s.insert(S[j]);
      }
    }
    ans = max(ans, static_cast<int>(s.size()));
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define all(v) v.begin(),v.end()
using namespace std;
int main(){
  long long n,m,b,ans=0;
  cin>>n;
  vector<int> a(n);
  for(int i=0;i<n;i++)cin>>a[i];
  sort(all(a));
  cin>>m;
  for(int i=0;i<m;i++){
    cin>>b;
    if(b==*lower_bound(all(a),b))ans++;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3132
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N;
  cin >> N;
  int a=N/2;
  vector<int> even(a);
  vector<int> odd(a);
  for(int i=0;i<a;i++){
    cin >> even.at(i);
    cin >> odd.at(i);
  }
  sort(even.begin(),even.end());
  sort(odd.begin(),odd.end());
  int C,c1,c2,M,m,m1,m2;C=m1=m2=c1=c2=M=0;
  for(int i=0;i<a;i++){
    m=even.at(i);
    if(m==M)
      C++;
    else{
      if(C>=c1){
        c2=c1;
        c1=C;
        m1=M;
      }else if(C>=c2){
        c2=C;
      }
      C=1;
    }
    M=m;
  }
  if(C>=c1){
    c2=c1;
    c1=C;
    m1=M;
  }else if(C>=c2){
    c2=C;
  }
  
  int D,d1,d2,L,l,l1,l2;D=l1=l2=d1=d2=L=0;
  for(int i=0;i<a;i++){
    l=odd.at(i);
    if(l==L)
      D++;
    else{
      if(D>=d1){
        d2=d1;
        d1=D;
        l1=L;
      }else if(D>=d2){
        d2=D;
      }
      D=1;
    }
    L=l;
  }
  if(D>=d1){
    d2=d1;
    d1=D;
    l1=L;
  }else if(D>=d2){
    d2=D;
  }
  if(m1==l1)
    cout << min(N-c1-d2,N-c2-d1);
  else
    cout << N-c1-d1;
}

Measured memory_bytes: 768
#include <iostream>
#include <iomanip>
using namespace std;
int main(){
  long long  W,H,x,y;
  cin >> W >> H >> x >> y;
  cout << fixed << (double)(W*H)/2.0 << " ";
  if(2*x == W && 2*y == H)
    cout << 1 << endl;
  else cout << 0 << endl;
  return 0;
}

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

int main(){
  int N,K;cin >> N >> K;
  int R,S,P;cin >> R >> S >> P;
  string T;cin >> T;
  int sum = 0;
  for(int i=0;i<K;i++){
    vector<char> X;
    for(int j=0;i+K*j<N;j++){
      X.push_back(T[i+K*j]);
    }
    int M = X.size();
    int k=0;
    for(int j=0;j<M;j++){
      if(j==M-1){
        int y = (j-k)/2+1;
        if(X[j]=='r'){
          sum += y*P;
        }else if(X[j]=='s'){
          sum += y*R;
        }else{
          sum += y*S;
        }
        //cout << i << " " << j << " " << k << " " << T[i] << endl;
        break;
      }
      if(X[j]!=X[j+1]){
        int y = (j-k)/2+1;
        if(X[j]=='r'){
          sum += y*P;
        }else if(X[j]=='s'){
          sum += y*R;
        }else{
          sum += y*S;
        }
        //cout << i << " " << j << " " << k << " " << T[i] << endl;
        k = j + 1;
      }
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 3688
N, M  = map(int, input().split())
X = list(map(int, input().split()))
X.sort()
xd = [X[i+1] - X[i] for i in range(M-1)]
xd.sort()

if M > N:
    mvcnt = M - N
    print(sum(xd[:mvcnt]))
else:
    print(0)

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

int main() {
	// your code goes here
	int k,a,b;
	cin>>k>>a>>b;
	bool flag = false;
	int i = 1;
	while(1){
	    int c = i*k;
	    if(c>=a&&c<=b){
	        flag = true;
	        break;
	    }
	    i++;
	    if(c>b){
	        break;
	    }
	}
	if(flag){
	    cout<<"OK"<<endl;
	}
	else{
	    cout<<"NG"<<endl;
	}
	return 0;
}


Measured memory_bytes: 3624
import math

N = int(input())

n = N / (1.08)

n0 = math.floor(n) - 1
n1 = math.floor(n)
n2 = math.ceil(n)

if int(n0 * 1.08) == N:
    print(n0)
elif int(n1 * 1.08) == N:
    print(n1)
elif int(n2 * 1.08) == N:
    print(n2)
else:
    print(":(")

Measured memory_bytes: 9080
// dfmt off
T lread(T=long)(){return readln.chomp.to!T;}T[] lreads(T=long)(long n){return iota(n).map!((_)=>lread!T).array;}
T[] aryread(T=long)(){return readln.split.to!(T[]);}void arywrite(T)(T a){a.map!text.join(' ').writeln;}
void scan(L...)(ref L A){auto l=readln.split;foreach(i,T;L){A[i]=l[i].to!T;}}alias sread=()=>readln.chomp();
void dprint(L...)(lazy L A){debug{auto l=new string[](L.length);static foreach(i,a;A)l[i]=a.text;arywrite(l);}}
static immutable MOD=10^^9+7;alias PQueue(T,alias l="b<a")=BinaryHeap!(Array!T,l);import std, core.bitop;
// dfmt on

void main()
{
    auto S = sread();
    writeln(max(S[0] - '0' - 1 + 9 * (S.length - 1), S.map!"a-'0'"().sum()));
}


Measured memory_bytes: 3572
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (true) {
            int n = sc.nextInt();
            if(n == 0){
                break;
            }
            int [] s = new int[n];
            double sum = 0;
            for(int i = 0; i < n; i++){
                s[i] = sc.nextInt();
                sum += s[i]; 
            }
            double m = (double) sum / n;
            sum = 0;
            for(int i = 0; i < n; i++){
                sum += (s[i] - m) * (s[i] - m);
            }
            double a = (double)sum / n;
            a = Math.pow(a, 0.5);
            System.out.printf("%.8f\n", a);
        }
        sc.close();
    }
}


Measured memory_bytes: 31624
h, w = gets.split.map(&:to_i)
a = h.times.map { gets.chomp }
s = a.join("")
cnt = {}
?a.upto(?z) { |c| cnt[c] = s.count(c) }

if w == 1
  if h.odd?
    puts cnt.values.select { |x| x.odd? }.size == 1 ? "Yes" : "No"
  else
    puts cnt.values.select { |x| x.odd? }.size == 0 ? "Yes" : "No"
  end
else
  if h.even? && w.even?
    puts cnt.values.select { |x| x % 4 != 0 }.size == 0 ? "Yes" : "No"
  elsif h.odd? && w.odd?
    ume = 0
    ?a.upto(?z) do |c|
      if cnt[c] >= 4 && (h - 1) * (w - 1) > ume
        ume += (cnt[c] / 4) * 4
        cnt[c] -= (cnt[c] / 4) * 4
        if (h - 1) * (w - 1) < ume
          cnt[c] += ume - (h - 1) * (w - 1)
          ume = (h - 1) * (w - 1)
        end
      end
    end
    if ume != (h - 1) * (w - 1)
      puts "No"
      exit
    end
    puts cnt.values.select { |x| x.odd? }.size == 1 ? "Yes" : "No"
  else
    ume = 0
    t = h.odd? ? w : h
    ?a.upto(?z) do |c|
      if cnt[c] >= 4 && h * w - t > ume
        ume += (cnt[c] / 4) * 4
        cnt[c] -= (cnt[c] / 4) * 4
        if h * w - t < ume
          cnt[c] += ume - h * w - t
          ume = h * w - t
        end
      end
    end
    if ume != h * w - t
      puts "No"
      exit
    end
    puts cnt.values.select { |x| x.odd? }.size == 0 ? "Yes" : "No"
  end
end


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


int a[100001];
long long int pre[100001];
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	sort(a+1,a+n+1);
	for(int i=1;i<=n;i++)
		pre[i]=pre[i-1]+a[i];
	int k;
	for(k=n-1;k>0;k--){
		if(pre[k]*2<a[k+1])
			break;
	}
	cout<<n-k<<endl;
}


Measured memory_bytes: 1408
H,W=map(int, input().split())
a=[list(input()) for i in range(H)]

WHITE='.'
print_row=[]
print_col=[]
for i in range(H):
    for j in range(W):
        if a[i][j] != WHITE:
            if i not in print_row:
                print_row.append(i)
            if j not in print_col:
                print_col.append(j)

for i in range(H):
    linefeed = False
    for j in range(W):
        if i in print_row and j in print_col:
            linefeed = True
            print(a[i][j], sep="", end="")
    if linefeed:
        print(sep="")


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

#define NAME "rewind"
#define show(x) cout << (#x) << " is " << (x) << endl
#define ll long long
#define ms(arr,val) memset(arr,val,sizeof(arr))
#define len length()

const int maxn = 2e5;
int n;
int a[3000];
ll dp[3000][3000];
ll cal(int l,int r){
    //cout<<l<<" "<<r<<endl;
    if (l==r) return a[l];
    if (dp[l][r]!=0) return dp[l][r];
    return dp[l][r] = max( a[l] - cal(l+1,r) , a[r] - cal(l,r-1)   );
}
int main(){
    //ifstream cin(NAME".inp");
    //ofstream cout(NAME".out");

    cin>>n;
    //show(n);
    for(int i=0;i<n;i++) cin>>a[i];
    cout<<cal(0,n-1);

}


Measured memory_bytes: 49904
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int A,B,C;
  cin>>A>>B>>C;
  int k=A%2+B%2+C%2,n=max({A,B,C});
  if(k==0)
    cout<<(n*3-(A+B+C))/2<<endl;
  else if(k==1){
    if(n%2==0)
      cout<<(((n+1)*3)-(A+B+C))/2<<endl;
    else
      cout<<(n*3-(A+B+C))/2<<endl;
  }else if(k==2){
    if(n%2==0)
      cout<<(n*3-(A+B+C))/2<<endl;
    else
      cout<<((n+1)*3-(A+B+C))/2<<endl;
  }else
    cout<<(n*3-(A+B+C))/2<<endl;
}

Measured memory_bytes: 3596
H, W = map(int, input().split())
a_list = [list(input()) for _ in range(H)]
dot_cnt = [sum([a == '.' for a in a_col]) for a_col in a_list]
exist_idx = [i for i, num in enumerate(dot_cnt) if num != W]

st = set(range(W))

for i in exist_idx:
    dot_idx = [i for i, a in enumerate(a_list[i]) if a == '.']
    st = st & set(dot_idx)

for i in exist_idx:
    print(''.join([a for i, a in enumerate(a_list[i]) if i not in st]))


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

using namespace std ; 

const int N = 2e5 + 7 ; 

int modd[N] ;

long long p1[N] ; 


int main(){
    ios_base::sync_with_stdio(0) ; 
    cin.tie(0); 
    //freopen("in.in" ,"r" , stdin) ; 
    p1[0] =1ll ;
    for(int i =1 ;i <N ;i++){
        p1[i] = (p1[i-1] * 10) %2019 ; 
    }
    int pre = 1  , now = 0 , ans = 0; 
    string s ; 
    cin>>s ;
    modd[0] = 1 ; 
    int n = s.size() ; 
    for(int i = 0 ;i < n ;i++){
        char u = s[i] ; 
        int x = u-'0'; 
        now = (now * 10 + x) ; 
        now%=2019 ; 
        int req = now * ( p1[n - i] ) ; 
        req%=2019 ; 
        ans+=modd[req]++;
    }
    cout<<ans; 
    return 0 ; 
}

Measured memory_bytes: 5316
s=input()

ll=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]

if len(s)!=26:
    l=list(s)
    for i in l:
        ll.remove(i)
    ll.sort()
    print(s+ll[0])
else:
    if s=="zyxwvutsrqponmlkjihgfedcba":
        print(-1)
    else:
        l=[]
        for i in range(1,27):
            for j in l:
                if s[-i]<j:
                    print(s[0:26-i]+j)
                    import sys
                    sys.exit()
            l.append(s[-i])
            l.sort()
            

Measured memory_bytes: 3064
using System;

namespace ABC132_C
{
    class Program
    {
        static void Main(string[] args) {
            int n = int.Parse(Console.ReadLine());
            string[] input = Console.ReadLine().Split();
            int[] numbers = new int[n];
            for(int i = 0; i < n; i++) {
                numbers[i] = int.Parse(input[i]);
            }
            Array.Sort(numbers);
            int underButtomIndex = n / 2;
            int upperButtomIndex = n / 2;
            if(n % 2 == 0) {
                underButtomIndex = n / 2 - 1;
                upperButtomIndex = n / 2;
            } else {
                if(numbers[underButtomIndex] == numbers[n / 2] || numbers[upperButtomIndex] == numbers[n / 2]) {
                    Console.WriteLine(0);
                    return;
                } else {
                    Console.WriteLine(1);
                    return;
                }
                underButtomIndex = n / 2 - 1;
                upperButtomIndex = n / 2 + 1;
            }

            long sumCount = numbers[upperButtomIndex] - numbers[underButtomIndex];

            Console.WriteLine(sumCount);
        }
    }
}

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


int main() {
  int n,m;
  cin >> n >> m;
  int list[n] = {};
  int wa_list[n] = {};
  int count_AC=0;
  for(int i=0;i<m;i++){
      int p;
      string s;
      cin >> p >> s;
      if(list[p-1]==0){
          if(s=="WA") wa_list[p-1]++;
          else{
              count_AC++;
              list[p-1]=1;
          }
      }
  }
  int count_WA =0;
  for(int i=0;i<n;i++){
      if(list[i]==1){
          count_WA += wa_list[i];
      }
  }
  cout << count_AC << " " << count_WA << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
typedef long long ll;
const ll MOD = 1e9+7;
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(int i=num, i##_len=(n); i<i##_len; ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};
#define print(x) (cout << (x) << endl)
#define pb push_back
#define mp make_pair
#define sz(x) int(x.size())
#define fs first
#define sc second


const int INF = 1e9;
const ll LLINF = 1e16;

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}
 
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
 
template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}
 
template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}
 
template<typename T>
T gcd(T a,T b){return b?gcd(b,a%b):a;}

template<typename T>
T ngcd(vector<T> a){
    T res;
    res = a[0];
    for(int i = 1; i < a.size() && res != 1; i++) {
        res = gcd(a[i], res);
    }
    return res;
}
 
template<typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

template<typename T>
T nlcm(vector<T> numbers) {
    T res;
    res = numbers[0];
    for (int i = 1; i < numbers.size(); i++) {
        res = lcm(res, numbers[i]);
    }
    return res;
}

// 約数列挙
template<typename T>
vector<T> calc_divisor(T n) {
   vector<T> res;
   for (T i = 1LL; i*i <= n; ++i) {
       if (n % i == 0) {
           res.push_back(i);
           T j = n / i;
           if (j != i) res.push_back(j);
       }
   }
   sort(res.begin(), res.end());
   return res;
}

// 素数判定
template<typename T>
bool isPrime(T x){
    T i;
    if(x < 2)return 0;
    else if(x == 2) return 1;
    if(x%2 == 0) return 0;
    for(i = 3; i*i <= x; i += 2) if(x%i == 0) return 0;
    return 1;
}

// 桁和
template<typename T>
T digsum(T n) {
    T res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

// 指定した文字cが文字列に何文字入ってるか
ll stringcount(string s, char c) {
    return count(s.cbegin(), s.cend(), c);
}


// 割り算の切り上げ処理
template<typename T>
T rp(T a, T b) {
  return (a + b - 1) / b;
}


using pint = pair<int, int>;
using pll = pair<ll, ll>;


int main(void)
{
    cout.tie(0);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    int n,m;
    cin >> n >> m;
    int ans1 = n * (n - 1) / 2;
    int ans2 = m * (m - 1) / 2;
    int ans = ans1 + ans2;
    print(ans);
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define sz(x) (int)(x).size()
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define ii pair<int,int>
#define INF 1000000000
#define M 1000000007ll
#define INFLL 1000000000000000010ll
#define UQ(x) (x).resize(distance((x).begin(),unique(all((x)))))
#define mid(x,y) (((x)+(y))>>1)

int n,x[100005];
vector<ii> v;
int main() {
	scanf("%d",&n);
	for (int i=0;i<n;i++) {
		scanf("%d",&x[i]);
	}
	int cur=1;
	for (int i=0;i<n;i++) {
		if (x[i]>=cur) {
			x[i]=cur;
			cur+=2;
		} else {
			if (v.empty() || v.back().second<i-1) v.pb(mp(i-1,i));
			else v.back().second=i;
			cur=x[i]+2;
		}
	}
	ll ans=1ll;
	int a,b,d,rem=0;
	bool yay=0;
	for (int i=0;i<sz(v);i++) {
		a=v[i].first,b=v[i].second;
		if (yay) a++;
		d=b-a+1;
		int cnt=a+2-rem;
		yay=0;
		while(d>1) {
			ans*=(ll)cnt;
			ans%=M;
			cnt++;
			rem++;
			if (d==2) yay=1;
			d-=2;
		}
	}
	for (int i=1;i<=n-rem;i++) {
		ans*=(ll)i;
		ans%=M;
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rrep(i, n) for(int i=n-1; i>=0; i--)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
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; }

int main() {
    string s; cin >> s;
    rep(i, s.size()) cout << "x";
    cout << endl;
}


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

ll n, k, ans;
ull a, b;

inline ll read(){
	ull s = 0, w = 1;
	char ch = getchar();
	for (; ch < '0' || ch > '9'; ch = getchar()) w *= ch == '-' ? -1 : 1;
	for (; ch >= '0' && ch <= '9'; ch = getchar()) s = s * 10 + ch - '0';
	return s * w;
}

inline void work(){
	n = read(), k = read();
	REP(i, k, n + 1){
		a = (i - 1) * i >> 1, b = (n + n - i + 1) * i >> 1;
		ans += (b - a + 1) % 1000000007;
		ans %= 1000000007;
	}
	printf("%lld\n", ans);
}

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

Measured memory_bytes: 3764
while True:
    C=0
    n=int(input())
    if n==0:
        break
    for i in range(n-1):
        A=i
        B=0
        while True:
            A=A+1
            B=B+A
            if B==n:
                C=C+1
            if B>=n:
                break
    print(C)


Measured memory_bytes: 5584
#include <iostream>
using namespace std;
int main(void){
    int H, W;
    while (true) {
        cin >> H >> W;
        if (H == 0 && W == 0) break;
        for (int y = 0; y < H; y++) {
            for (int x = 0; x < W; x++) {
                if (x == 0 || x == W - 1 || y == 0 || y == H - 1) {
                    cout << '#';
                } else {
                    cout << '.';
                }
            }
            cout << endl;
        }
        cout << endl;
    }
    return 0;
}

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

int main() {
  string A,B;
  cin >> A >> B;
  if(A.size() < B.size()){
    cout << "LESS" << endl;
    return 0;
  }
  else if(A.size() > B.size()){
    cout << "GREATER" << endl;
    return 0;
  }
  else{
    for(int i=0; i<A.size();i++){
      if(A[i] < B[i]){
        cout << "LESS" << endl;
        return 0;
      }
      else if(A[i] > B[i]){
        cout << "GREATER" << endl;
        return 0;
      }
    }
      cout << "EQUAL" << endl;
  }
}


Measured memory_bytes: 3588
#include <stdio.h>

int main(void) {
	int N;
	int sumipe;
	if (scanf("%d", &N) != 1) return 1;
	for (sumipe = 0; 4 * sumipe <= N; sumipe++) {
		if ((N - 4 * sumipe) % 7 == 0) {
			puts("Yes");
			return 0;
		}
	}
	puts("No");
	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
#define rREP(i,m,n) for(int (i)=(n)-1; (i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;

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;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

int main() {
	init();

	int N; cin >> N;
	vector<int>a(N);
	rep(i, 0, N)cin >> a[i];
	vector<int>vec(8, 0);
	int cnt = 0;
	rep(i, 0, N) {
		int x = a[i] / 400;
		if (x >= 8)++cnt;
		else vec[x]++;
	}
	int mn = 0, mx = 0;
	rep(i, 0, 8) {
		if (vec[i] == 0)mx++;
		else mn++;
	}
	cout << max(mn, 1) << " " << mn + cnt << "\n";

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <limits>
#include <ctype.h> 
#include <stdio.h> 
#include <set> 
#include <iomanip>
#include <vector>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
#define L(ID) ((ID*2)+1)
#define R(ID) ((ID*2)+2)
#define M(L,R) ((L+R)/2)
#define forr(start,end) for(int i = start; i < end; i++)
#define gap ' '


const int MAXN = 1e5;
char a[MAXN];   
int n = 0;

int factorial(){
    for(int i = n-1; i > 0; --i){
        n = n * i;
    }
    return n;
}


int main() {
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    s.erase(unique(s.begin(), s.end()), s.end());
    if(s.size() == 2){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    

    return 0;
} 


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <complex>

using namespace std;

typedef long long ll;
typedef vector<int> Array;
typedef vector<Array> Mat;
typedef pair<int,int> P;

const int UNDEF = -1;
const int INF = 99999999;
const double EPS = 1e-9;

#define pb push_back
#define rep(i,n) for(int i=0; i<(n); ++i)
#define REP(i,j,k) for(int i=j;	i<(k); ++i)
#define foreach(T,v,i) for(T::iterator i=v.begin(); i!=v.end(); ++i)
#define ALL(c) (c).begin(),(c).end()
inline bool EQ(double a,double b) {return abs(a-b) < EPS;}
#define priority_queue_greater(T) priority_queue< T, vector<T>, greater<T> >

typedef priority_queue_greater(int) PQ;

int w, h;
P start;


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

void dfs(Mat map, PQ &queue,int x,int y,int cnt)
{
	cnt++;
	if(cnt > 10) return;
	if(!queue.empty() && cnt >= queue.top()) return;
	rep(i, 4){
		int nx = x + dx[i];
		int ny = y + dy[i];
		if(nx < 0 || ny < 0 || nx >= w || ny >= h ){ continue; }
		if(map[ny][nx] == 1){ continue; }
		if(map[ny][nx] == 3){
			queue.push(cnt);
			return;
		}
        if(map[ny][nx] == 0){
			while(1){
				if(map[ny][nx]==3){
					queue.push(cnt);
					break;
				}
				nx += dx[i];
				ny += dy[i];
				if(nx < 0 || ny < 0 || nx >= w || ny >= h ){ break; }
                if(map[ny][nx] == 1){
					map[ny][nx]=0;
					dfs(map, queue,nx-dx[i],ny-dy[i],cnt);
					map[ny][nx]=1;
					break;
				}
			}
		}
	}
}
		
int main(void)
{
	while(cin >> w >> h){
		if(w == 0) break; 
		
		int cnt = 0;
		Mat map(h,vector<int> (w));
		PQ queue;
		
		rep(i, h){
			rep(j, w){
				int k;
				cin >> k;
				map[i][j] = k;
				if(k == 2){
					start.first = j;
					start.second = i;
					map[i][j]=0;
				}
			}
		}
    
		dfs(map, queue,start.first,start.second,cnt);
		if(queue.size())
			cout << queue.top() << endl;
		else
			cout << -1 << endl;
	}
	
	return 0;
}

Measured memory_bytes: 960
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
//#pragma GCC optimization ("unroll-loops")

#include "bits/stdc++.h"
//#include "ext/pb_ds/assoc_container.hpp" 
//#include "ext/pb_ds/tree_policy.hpp" 
using namespace std;
//using namespace __gnu_pbds;
#define ff first
#define ss second
#define ld long double
#define ll long long int
#define ull unsigned ll
#define ins insert
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vi>
#define vvll vector<vll>
#define pii pair<int,int> 
#define pll pair<ll , ll>
#define sz(a) (ll) a.size()
#define all(a) a.begin(), a.end()
#define fo(i,a,b) for(i=a; i<b; ++i)
#define foe(i,a,b) for(i=a; i<=b; ++i)
#define rep(i,n) for(i=0;i<n;i++)
#define rep1(i,n) for(i=1;i<=n;i++)
#define per(i,n) for(i=n-1;i>=0;i--)
#define per1(i,n) for(i=n;i>=1;i--)
#define mod 1000000007
#define pi 3.141592653589793238460
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0)
//#define pbds tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>

#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;
        //use cerr if u want to display at the bottom
    }
    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


int main(){
    fast;
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    ll t, i, j;
    t=1;
    while(t--){
        ll n, k;
        cin>>n;
        vll a(n);
        rep(i,n) cin>>a[i];
        ll lh = a[0];
        ll ans = 0;
        for(i=1; i<n; i++){
            if(a[i] < lh) ans+=(lh-a[i]);
            else{
                lh=a[i];
            }
        }
        cout<<ans<<'\n';
        
    }
    return 0;
}







Measured memory_bytes: 4776
# coding: utf-8
import math
import copy
import itertools
n = int(input())
flg=False
for i in range(int(math.sqrt(n))+1, 0,-1):
    #print(i)
    if n%i==0:
        a=i
        b=n//a
        flg=True
        break
if flg:
    print(max(len(str(a)), len(str(b))))
else:
    print(len(str(n)))

Measured memory_bytes: 9360
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <iomanip> 

using ll = long long;
using ull = unsigned long long;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i = 0;(i) < ((int)(n));++(i))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

const int INF = 1e9+7;
const ll INFL = 9*1e18;

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

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

ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;} // 桁数
template<typename T>inline void print(T&& x){cout<<x<<endl;}// 改行付き出力
template<typename T>inline T SUM(vector<T> vec){return accumulate(all(vec),(T)0);} // vectorの中身を全部足す
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);} // 最大公約数
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;} // 最小公倍数
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;} // 累乗
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; }
int ctoi(char c){return c-'0';}


// TODO: write
int main() {
  int n;cin>>n;
  print((n >= 30)? "Yes" : "No");
  return 0;
}

Measured memory_bytes: 3608
import copy
import sys
H,W,K = list(map(int, input().split()))
if  W == 1:
  print(1)
  sys.exit()
D = [0 for i in range(W)]
T = copy.deepcopy(D)
D[0] = 1
F = [1, 1, 2, 3, 5, 8, 13, 21]
for i in range(H):
  T[0] = D[1] * F[W-2] + D[0] * F[W-1]
  T[W-1] = D[W-2] * F[W-2] + D[W-1] * F[W-1]
  for j in range(1, W-1):
    T[j] = D[j-1] * F[j-1] * F[W-j-1] \
             + D[j+1] * F[j] * F[W-j-2]\
             + D[j] * F[j] * F[W-j-1]
  D = copy.deepcopy(T)
print(D[K-1] % 1000000007)

Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr long long MOD = 1000000007;
constexpr long long INF = 1LL << 60;
const long double PI = acosl(-1.0);
constexpr long double EPS = 1e-11;
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;
}
int main(){
ll n;
cin>>n;
vector<vector<pair<ll,ll>>> testify(n);
for(ll i=0;i<n;i++){
    ll a;
    cin>>a;
    testify[i].resize(a);
    for(ll j=0;j<a;j++){
        ll x,y;
        cin >> x >> y;
        x--;
        testify[i][j].first = x;
        testify[i][j].second = y;
    }
}
int ans = 0;
for (ll bit = 0; bit < (1 << n); bit++){
    bool flag = true;
    for (ll i = 0; i < n; i++) {
        if (!(bit & (1 << i))) continue;
        for(auto k:testify[i]){
            if (k.second && !(bit & (1 << k.first))) flag = false;
            if (!(k.second) && (bit & (1 << k.first))) flag = false;
        }
    }
    if (flag)chmax(ans, __builtin_popcountl(bit));
}
cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cstring>
#include<map>
#include<cmath>
#define sp system("pause");
using namespace std;
bool prime(int x)
{
	for(int i=2;i<=sqrt(x);i++)
		if(x%i==0)
			return false;
	return true;
}
int main()
{
	int cnt,n,i;
	cin>>n;
	for(i=2,cnt=0;cnt<n;i++)
		if(prime(i)&&i%5==1)
			cout<<i<<' ',cnt++;
	return 0;
}

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

#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

typedef long long ll;

int main() {
    int n;cin>>n;
    int a[n];
    
    rep(i,n) cin>>a[i];
    
    int ans = 0;
    int y;
//    int cc = 0;
    int sum=0;
    rep(i,n)sum+=a[i];
    if(sum==0){
        cout<<0<<endl;
        return 0;
    }

    while(true){
        int x;
        rep(i,n)if(a[i]>0){
            x = i;
            break;
        }
//        int x = lower_bound(a, a + n, 1) - a;
        for(int j = 0; j + x < n; ++j){
            if(a[x+j]==0){
                y = x+j-1;
                break;
            }
            if(j + x == n-1 && a[n-1]>0) {
              y = n-1;
              break;
            }
        }
//        cout<<x<<" "<<y<<endl;
      
        ++ans;
        for(int i = x; i<= y;++i){
         --a[i];   
        }
        
//        rep(i,n)cout<<a[i]<<" ";
//        cout<<endl;

        sum=0;
        rep(i,n) sum+=a[i];
        if(sum==0)break;
    }
    cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < (int)(n); i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
using ll = long long;

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

    int cur = 0;
    for (int i = (int)N.size() - 1; i >= 0; i--) {
        cur = cur * 10 + (N[i] - '0');
        cur %= 9;
    }
    if (cur % 9 == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3748
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define __ ios_base::sync_with_stdio(0);cin.tie(0);
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(),x.end()
#define forn(i,a,n) for(int i=a; i < n; i++)
typedef long long int lli;
typedef long double Double;
typedef pair<int,int> pii;
typedef pair<lli,lli> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
const int mod = 1e9+7;

int main(){__
	int n;
	cin >> n;
	lli d;
	cin >> d;
	int ans =0;
	for(int i=0; i < n; i++){
		lli x,y;
		cin >> x >> y;
		lli dist = x*x + y*y;
		if(dist <= d*d){
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 3584
N = int(input())
A = list(map(int, input().split()))
cnt = [0]*(N+1)
for a in A:
  cnt[a] += 1
comb = [a*(a-1)/2 for a in cnt]
m = sum(comb)
for i in range(N):
  print(int(m - (cnt[A[i]] - 1)))

Measured memory_bytes: 24748
#66
while True:
    m,f,r=map(int,input().split())
    if (m,f,r)==(-1,-1,-1):
        break
    a=m+f
    if m==-1 or f==-1 or a==-2:
        print('F')
    elif 80<=a:
        print('A')
    elif 65<=a<80:
        print('B')
    elif 50<=a<65:
        print('C')
    elif 30<=a<50:
            if 50<=r:
                print('C')
            else:
                print('D')
    elif a<30:
        print('F')
        


Measured memory_bytes: 5596
using System;

public class Hello
{
    public const double ToRad = Math.PI / 180d;
    public const double AR = 6378.1;
    public static void Main()
    {
        while (true)
        {
            string[] line = Console.ReadLine().Trim().Split(' ');
            var a = double.Parse(line[0]);
            var b = double.Parse(line[1]);
            var c = double.Parse(line[2]);
            var d = double.Parse(line[3]);
            if (a == -1 && b == -1 && c == -1 && d == -1) break;
            a *= ToRad; b *= ToRad; c *= ToRad; d *= ToRad;
            var cost = Math.Cos(a) * Math.Cos(c) * Math.Cos(b - d) + Math.Sin(a) * Math.Sin(c);
            var ret = Math.Round(AR * Math.Acos(cost), 0, MidpointRounding.AwayFromZero);
            Console.WriteLine(ret);
        }
    }
}



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

struct StNumCnt
{
  StNumCnt() : m_nNum(0), m_nCnt(0) { }

  int m_nNum;
  int m_nCnt;

  static bool greater_nCnt(const StNumCnt& lhs, const StNumCnt& rhs)
  {
    return lhs.m_nCnt > rhs.m_nCnt;
  }

  //bool operator<(const StNumCnt& rhs) const
  //{
  //  return rhs.m_nCnt < m_nCnt;
  //}
};

void fnInput(vector<int>& rvnNum)
{
  int nNumSiz;
  cin >> nNumSiz;
  rvnNum.resize(nNumSiz);

  for (int& rnNum : rvnNum)
    cin >> rnNum;
}

int fnMinChangeCnt(const vector<int>& cnrvnNum)
{
  map<int, int> mpNumCntEvn, mpNumCntOdd;

  for (int i = 0; i < cnrvnNum.size(); ++i)
    if ( i % 2 == 0 )
      mpNumCntEvn[ cnrvnNum[i] ]++;
    else
      mpNumCntOdd[ cnrvnNum[i] ]++;

  vector<StNumCnt> voNumCntEvn( mpNumCntEvn.size() ),
                   voNumCntOdd( mpNumCntOdd.size() );

  int n = 0;
  for (pair<int, int> PNumCnt : mpNumCntEvn)
  {
    voNumCntEvn[n].m_nNum   = PNumCnt.first;
    voNumCntEvn[n++].m_nCnt = PNumCnt.second;
  }

  n = 0;
  for (pair<int, int> PNumCnt : mpNumCntOdd)
  {
    voNumCntOdd[n].m_nNum   = PNumCnt.first;
    voNumCntOdd[n++].m_nCnt = PNumCnt.second;
  }

  sort(begin(voNumCntEvn), end(voNumCntEvn), StNumCnt::greater_nCnt);
  sort(begin(voNumCntOdd), end(voNumCntOdd), StNumCnt::greater_nCnt);

  int nMinChangeCnt = INT_MAX;

  for (int i = 0; i < 2; ++i)
    for (int j = 0; j < 2; ++j)
      if (voNumCntEvn[i].m_nNum != voNumCntOdd[j].m_nNum)
        nMinChangeCnt = 
          min(nMinChangeCnt, (int)cnrvnNum.size() - voNumCntEvn[i].m_nCnt - voNumCntOdd[j].m_nCnt);

  return nMinChangeCnt;
}
  
int main()
{
  vector<int> vnNum;
  
  fnInput(vnNum);
  cout << fnMinChangeCnt(vnNum) << endl;

  return 0;
}

Measured memory_bytes: 8972
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.NoSuchElementException;

public class Main {
	public static void main(String[] args) {
		new Main().run();
	}
	
	void run() {
		FastScanner sc=new FastScanner();
		long N=sc.nextInt();
		int M=sc.nextInt();
		long sum=0;
		for (int i=0;i<M;++i) {
			sum+=sc.nextLong();
		}
		long ans=Math.max(-1,N-sum);
		System.out.println(ans);
	}
	
	void tr(Object...objects) {System.out.println(Arrays.deepToString(objects));}
}




class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}

Measured memory_bytes: 33196
#include <bits/stdc++.h>
#define _overload3(_1,_2,_3,name,...)name
#define _rep(i,n)repi(i,0,n)
#define repi(i,a,b)for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; using ll = long long; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

int main() {
    int X, Y;
    cin >> X >> Y;
    write(2 * X <= Y && Y <= 4 * X && Y % 2 == 0 ? "Yes" : "No");
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define loop(n) for (int ngtkana_is_a_genius = 0; ngtkana_is_a_genius < int(n); ngtkana_is_a_genius++)
#define rep(i, begin, end) for (int i = int(begin); (i) < int(end); i++)
#define all(v) v.begin(), v.end()
#define rand(l, r) std::uniform_int_distribution<>(l, r)(mt)
using lint = long long;
auto mt = std::mt19937_64(std::random_device{}());
auto cmn = [](auto& a, auto b){ if (a > b) {a = b; return true;} return false; };
auto cmx = [](auto& a, auto b){ if (a < b) {a = b; return true;} return false; };
void debug_impl() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail) { std::cerr << " " << head; debug_impl(tail...); }
#ifndef STOPIT
#define debug(...)\
  do {\
    std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\
    debug_impl(__VA_ARGS__);\
    std::cerr << std::noboolalpha;\
  } while (false)
#else
#define debug(...) 0;
#endif

int main() {
  std::cin.tie(0); std::cin.sync_with_stdio(false);
  lint n; std::cin >> n;
  lint a = 1, b = 1;
  loop(n) {
    lint p, q; std::cin >> p >> q;
    lint x = std::max((p+a-1)/p, (q+b-1)/q);
    // debug(p,q,x);
    a = p*x;
    b = q*x;
    // debug(a,b);
  }
  lint ans = a + b;
  std::cout << ans << std::endl;
  return 0;
}

Measured memory_bytes: 256
n = int(input())
I = [list(map(int, input().split())) for _ in range(n)]
cands = [[x, y] for x in range(101) for y in range(101)]
for cand in cands:
    h = 0
    flag = 0
    list = []
    for i in I:
        if i[2] == 0:
            list.append(i)
            continue
        ch = i[2] + abs(i[0] - cand[0]) + abs(i[1] - cand[1])
        if h == 0:
            flag = 1
            h = ch
            continue
        if h != 0:
            if h != ch:
                flag = 0
                break
    for item in list:
        if h -  abs(item[0] - cand[0]) - abs(item[1] - cand[1]) > 0:
            flag = 0
            break
    if flag == 1:
        print(cand[0], cand[1], h)
        break


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

using namespace std;

int main(){
    int N;
    cin >> N;
    
    vector<int> buttons(N);
    for(int i=0; i < N; i++){
        cin >> buttons.at(i);
    }

    int count = 0;
    int next = 1;
    while(count < N){
        next = buttons.at(next-1);
        count++;
        if(next == 2){
            break;
        }
    }
    if(count >= N){
        cout << -1 << endl;
    } else {
        cout << count << endl;
    }
}


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

int main(){
  int N;
  cin>>N;
  vector<int> a(N);
  for(int &i:a){
    int j;
    cin>>j;
    i=j-1;
  }
  int j=0;
  for(int i=0;i<N;i++)
    if(i==a[a[i]])
      j++;
  cout<<j/2<<endl;
}

Measured memory_bytes: 640
#include <iostream>

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define INF 100000

int main(){
  int n, t;
  cin >> n >> t;

  int c, tt, ans = INF;
  rep(i, n) {
    cin >> c >> tt;
    if (tt <= t) {
      ans = min(ans, c);
    }
  }
  if (ans == INF) {
    cout << "TLE" << endl;
  } else {
    cout << ans << endl;
  }
}

Measured memory_bytes: 256