akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

template<typename S, typename T>
ostream& operator<<(ostream& out, const pair<S, T> p) {
    out << "(" << p.first << "," << p.second << ")";
    return out;
}

template<typename T>
ostream& operator<<(ostream& out, const vector<T>& v) {
    for (auto a: v)
        out << a << " ";
    return out;
}

template<typename T>
ostream& operator<<(ostream& out, const set<T>& S) {
    for (auto a: S)
        cout << a << " ";
    return out;
}

template<typename T>
ostream& operator<<(ostream& out, const multiset<T>& S) {
    for (auto a: S)
        cout << a << " ";
    return out;
}

template<typename S, typename T>
ostream& operator<<(ostream& out, const map<S, T>& M) {
    for (auto m: M)
        cout << "(" << m.first << "->" << m.second << ") ";
    return out;
}

template<typename S, typename T>
pair<S, T> operator+(pair<S, T> a, pair<S, T> b) {
    return make_pair(a.first + b.first, a.second + b.second);
}

template<typename S, typename T>
pair<S, T> operator-(pair<S, T> a, pair<S, T> b) {
    return make_pair(a.first - b.first, a.second - b.second);
}

void query_prefix(string&str, vector<int>& A) {
    int n = str.size()  + 1;
    A.resize(n, 0);
    for (int i = 1; i < n; i++) {
        if (str[i-1] == '<') {
            A[i] = A[i-1] + 1;
        }
    }
}

void query_suffix(string&str, vector<int>& A) {
    int n = str.size() + 1;
    A.resize(n, 0);
    for (int i = n - 2; i >= 0; i--) {
        if (str[i] == '>') {
            A[i] = A[i+1] + 1;
        }
    }
}

vector<int> A, B, C;

long long solve(string& str) {
    int n = str.size() + 1;
    query_prefix(str, A);
    query_suffix(str, B);
    C.resize(n);
    for (int i = 0; i < n; i++)
        C[i] = max(A[i], B[i]);
    /*
    cout << "n: " << n << endl;
    cout << "str: " << str << endl;
    cout << "A: " << A << endl;
    cout << "B: " << B << endl;
    cout << "C: " << C << endl;
    */
    long long ans = 0;
    for (auto c: C)
        ans += c;
    return ans;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    string str;
    cin >> str;
    long long ans = solve(str);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 6684
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i = 0; i < (ll)(n); i++)
#define inf 1000000000000000000
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(x) (x).begin(),(x).end()
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

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

  ll N; cin >> N;
  vector<ll> A(N);
  rep(i, N) cin >> A[i];

  map<ll, ll> Counter;
  vector<bool> ans(1000001, true);
  for (auto i : A) {
    Counter[i]++;
    if (Counter[i] > 1) continue;
    for (ll j = 2 * i; j < 1000001; j += i) {
      ans[j] = false;
    }
  }

  ll cnt = 0;
  for (auto i : A) {
    if (ans[i] && Counter[i] == 1) cnt++;
  }

  cout << cnt << endl;
}


Measured memory_bytes: 17476
n, y = map(int, input().split(" "))

found = False

for i in range(0, n + 1):
    for j in range(0, n + 1 - i):
        sum = 10000 * i + 5000 * j + 1000 * (n - i - j)
        if sum == y:
            found = True
            print(str(i) + " " + str(j) + " " + str(n - i - j))
            break
    if found:
        break

if found is False:
    print("-1 -1 -1")


Measured memory_bytes: 3060
n,m,c = gets.chomp.split(" ").map(&:to_i)
b = gets.chomp.split(" ").map(&:to_i)

o = 0

n.times do |x|
  t = 0
  a = gets.chomp.split(" ").map(&:to_i)
  m.times do |y|
    s = a[y]*b[y]
    t += s
  end
  t += c
  o += 1 if ( t > 0 )
end

p o

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

int main(){
  int n;
  int count=0;
  cin>>n;
  vector<int> a(n);
  for(int i=0;i<n;i++){
    cin>>a.at(i);
  }
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());
  bool finish=false;
  for(int i=0;i<512;i++){
    for(int j=0;j<n;j++){
      if(a.at(j)%2==1){
        finish=true;
        break;
      }
      else{
        a.at(j)=a.at(j)/2;
      }
    }
    if(finish==true){
      break;
    }
    else{
      count++;
    }
  }
  cout<<count<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 100000 + 5, P = 1e9 + 7; 
int n, m, x[N], y[N];
int main() {
    scanf("%d%d", &n, &m);
    ll ans = 0, psum = 0;
    for (int i = 1; i <= n; ++i) {
        scanf ("%d", &x[i]);
        ans += 1ll * (i - 1) * x[i] - psum;
        ans %= P;
        psum += x[i];
    }
    ll ans1 = 0;
    psum = 0;
    for (int i = 1; i <= m; ++i) {
        scanf ("%d", &y[i]);
        ans1 += 1ll * (i - 1) * y[i] - psum;
        ans1 %= P;
        psum += y[i];
    }
    cout << (ll)ans1 * ans % P << '\n';
    return 0; 
}

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

int main()
{
    int n,t;
    cin >> n >> t;
    vector<int> a(n),b(n);
    bool flag = false;
    int min = 10000000;
    for(int i = 0;i < n;i++){
        cin >> a[i] >> b[i];
        if(b[i] <= t && a[i] < min){
            min = a[i];
            flag = true;
        }
    }
    if(flag) cout << min << endl;
    else cout << "TLE" << endl;
}


Measured memory_bytes: 256
#!/usr/bin/ruby
#
# 1035.rb: Sleeping Cats
#

### main

loop do
  w, q = gets.split.map(&:to_i)
  break if w == 0 && q == 0

  fence = [false] * w
  cats = []
 
  q.times do
    op, id, wc = gets.split
    id = id.to_i
    #p [op, id, wc]

    case op
    when 's'
      wc = wc.to_i
      ng = true

      for b in (0..(w - wc))
        if fence[b, wc].select{|f| f}.length == 0
          ng = false
          break
        end
      end

      if ng
        puts 'impossible'
      else
        fence[b, wc] = [true] * wc
        cats[id] = [b, wc]
        puts b
      end
    when 'w'
      b, wc = cats[id]
      fence[b, wc] = [false] * wc
      cats[id] = nil
    end
    #p fence
    #p cats
  end

  puts 'END'
end

Measured memory_bytes: 6132
#include <algorithm>
#include <iostream>
#define REP(i,n) for(i=0;i<n;i++)
const int K=1024,N=331;
int B[]={1,2,4,8,16,32,64,128,256,512},C[K]={0},D[K][N]={0};
int init(){
	int i,tmp,tmp2,n,dp,i2,j,k;
	REP(i,K){
		REP(j,N)D[i][j]=0;
		tmp=i,tmp2=0,n=0;
		while(tmp){
			n+=tmp&1;
			tmp2++;
			tmp/=2;
		}
		C[i]=n;
		if(n==1)D[i][std::find(B,B+10,i)-B]=1;
		else{
			tmp=i;
			REP(j,tmp2){
				if(tmp&1){
					dp=n*j,i2=i-B[j];
					REP(k,N-dp)D[i][k+dp]+=D[i2][k];
				}
				tmp/=2;
			}
		}
	}
	return 0;
}
int main(){
	init();
	int n,s,i,x;
	while(1){
		std::cin>>n>>s;
		if(std::cin.eof())break;
		x=0;
		if(s<N)
			REP(i,K)if(C[i]==n)x+=D[i][s];
		std::cout<<x<<'\n';
	}
}

Measured memory_bytes: 2488
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

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

    vector<int> a(N);
    for( int i = 0; i < N; ++i )
        cin >> a[i];

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

    int ans = 0;
    for( int i = 0; i < N-1; ++i )
        ans += a[i+1] - a[i];

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <list>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;
 
int main(void)
{
    int A,B,T;
 
    cin >> A >> B >> T;

    int res = 0;
    for (int i = A; i <= T; i = i + A)
    {
        res += B;
    }
 

    cout << res << endl;
    

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string str1,str2 = "",str3 = "",str,st;
    int n,m,i;
    cin>>str1;
    str = str1;
    n = str1.size();
    reverse(str.begin(),str.end());

    if(str==str1)
    {
        m = (n-1)/2;
        for(i = 0;i < m;i++)
            str2+=str1[i];
        str = str2;
        reverse(str.begin(),str.end());
        i = ((n+3)/2) - 1;
        for(;i < n;i++)
            str3+=str1[i];
        st = str3;
        reverse(st.begin(),st.end());
        if(str==str2 && st==str3)
            cout<<"Yes\n";
        else
            cout<<"No\n";
    }
    else
        cout<<"No\n";
    return 0;
}



Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <climits>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <string>
#include <list>
#include <bitset>
#include <vector>
using namespace std;

#define I64d_OJ

//#ifdef I64d_OJ
//#define LL __int64
//#endif // I64d_OJ
#ifdef I64d_OJ
#define LL long long
#endif // I64d_OJ

typedef unsigned LL ULL;
typedef unsigned uint;
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
typedef pair<LL,LL> pLL;
typedef vector<int> vi;

inline int read(){
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-') f=-f; ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}
    return x*f;
}

#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define ls rt<<1
#define rs rt<<1|1
#define MID(a,b) (((LL)(a)+(LL)(b))>>1)
#define absx(a) ((a)<0?-(a):(a))
#define MK(a,b) make_pair(a,b)
#define PB(a) push_back(a)
#define lowbit(x) ((x)&-(x))

#define lc c[x][0]
#define rc c[x][1]

template< typename T >
inline void Max(T &a,T &b){if(a<b) a=b;}
template< typename T>
inline void Min(T &a,T &b){if(a>b) a=b;}

const double pi=(double)acos(-1.0);
const double eps=(double)1e-8;
const int INF = (int) 0x3f3f3f3f;
const int MOD = (int) 1e9+7;
const int MAXN =(int) 2e5+10;
const int MAXM = (int) 3e6+10;

///--------------------START-------------------------
int N,K,C;
char s[MAXN];
int dp[MAXN][2];
map<int,int> mp1,mp2;

void work(){
    scanf("%d%d%d",&N,&K,&C);
    scanf("%s",s+1);
    int pre=-C;
    int mx1=0,mx2=0;
    for(int i=1;i<=N;i++){
        if(s[i]=='o'&&pre+C<i){
            pre=i;
            mp1[i]=1;
//            printf("%d ",i);
            mx1++;
        }
    }
//    printf("\n");
    int nxt=C+N+1;
    for(int i=N;i>=1;i--){
        if(s[i]=='o'&&i+C<nxt){
            nxt=i;
            mp2[i]=1;
            mx2++;
//            printf("%d ",i);
        }
    }
//    printf("\n");
    if(mx1>K||mx2>K){
        return;
    }
    for(int i=1;i<=N;i++){
        if(mp1[i]>0&&mp2[i]>0) printf("%d\n",i);
    }
}

///--------------------END-------------------------
int main(){
#ifdef NNever
//freopen("data.in","r",stdin);
///freopen("out.txt","w",stdout);
#endif // NNever
    work();
    return 0;
}






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


int main(){
	
	long long int K, amari = 0, ba;

	std::cin >> K;

	if(K%2 == 0){
		cout << -1;
	}else{
		long long int i = 0;		
		while(1){
			i++;
			ba = amari;
			amari = (amari*10 + 7)%K;
			if(amari == 0){
				cout << i << endl;
				break;
			}
			if(amari == ba){
				cout << -1 << endl;
				break;
			}
			if(i > K+10){
				cout << -1 << endl;
				break;
			}
		}
	}

	return 0;
}

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

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

    string s;
    cin >> s;
    sort(s.begin(), s.end());
    cout << (s[0] == s[1] && s[2] == s[3] && s[1] != s[2] ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define N 200005
using namespace std;
int bitcount(int S) {
	int ret = 0;
	while(S) ret ++, S -= (S & (-S));
	return ret;
}
int check(int S) {
	int ret = 0;
	for(int i = 0; i < 15; i ++) if(S & (1 << i)) ret ^= (i + 1);
	return ret;
}
int n, d[N], cnt[N], f[N];
int main() {
	scanf("%d", &n);
	for(int i = 1; i < n; i ++) {
		int u, v, c;
		scanf("%d%d%d", &u, &v, &c);
		d[u] ^= c, d[v] ^= c;
	}
	for(int i = 0; i < n; i ++) cnt[d[i]] ++;
	int ans = 0, sta = 0;
	for(int i = 1; i < 16; i ++) ans += cnt[i] / 2, sta |= (cnt[i]&1) << (i - 1);
	memset(f, 0x3f, sizeof f);
	f[0] = 0;
	for(int S = 1; S < (1 << 15); S ++) { 
		if((sta & S) != S || check(S)) continue;
		f[S] = bitcount(S) - 1;
		for(int SS = S; SS; SS = (SS - 1) & S) if(!check(SS)){ 
			f[S] = min(f[S], f[SS] + f[S ^ SS]);
		}
	}
	int ret = 0;
	printf("%d", ans + f[sta]);
	return 0;
} 

Measured memory_bytes: 1408
#include <iostream>

int main()
{
    long long N, L;
    std::cin >> N >> L;
    long long taste = L*N + N*(N-1)/2;
    if(L > 0) taste -= L;
    else if(L+N-1 < 0) taste -= L+N-1;
    std::cout << taste << std::endl;
}

Measured memory_bytes: 256
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    L=I()
    print((L/3)**3)
if __name__ == '__main__':
    main()

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

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    int g = a[0];
    rep(i,n) {
        cin >> a[i];
        g = __gcd(g, a[i]);
    }
    sort(all(a));
    if(k > a[n-1]){ cout << "IMPOSSIBLE" << endl; return 0;}
    if(k%g==0) cout << "POSSIBLE" << endl;
    else cout << "IMPOSSIBLE" << endl;
    return 0;
}

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

int main()
{
	int n, i = 1, ans = 0;
	cin >> n;
	while (n)
	{
		int a = n % 10;
		n /= 10;
		if(a == 1)ans += 9 * i;
		if(a == 9)ans += i;
		i *= 10;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) (y<0||x<0||y>=h||x>=w)
#define dump(...)
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
#define INF (1001001001)
#define INFLL (1001001001001001001ll)
template<class T> ostream& operator << (ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v)) os<<*i<<(i==end(v)-1?"":" "); return os; }
template<class T> istream& operator >> (istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i; return is; }
template<class T> istream& operator >> (istream &is, pair<T,T> &p) {
    is>>p.first>>p.second; return is; }
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> using heap = priority_queue<T,vector<T>,greater<T>>;
//------------------------------------------------------------------------------
struct before_main_function {
    before_main_function() {
        #ifdef int
            #undef INF
            #define INF INFLL
            #define stoi stoll
        #endif
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
        #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    int n,K;
    cin>>n>>K;
    vector<int> a(n);
    cin>>a;
    sort(ALL(a));

    int L=-1,R=n;
    while(R-L>1) {
        int M=(L+R)/2;
        vector<bool> dp(5001,false);
        dp[0]=1;
        REP(i,n) {
            if(i==M) continue;
            REPR(j,5000) {
                if(dp[j]) {
                    if(j+a[i]<=5000) dp[j+a[i]]=1;
                }
            } 
        }
        bool ok=0;
        REP(j,5001) {
            if(!dp[j]) continue;
            if(j<K && j+a[M]>=K) {
                ok=1;
            }
        }
        if(ok) {
            R=M;
        } else {
            L=M;
        }
    }
    cout<<R<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.math.BigDecimal;
import java.util.Arrays;
import java.util.Scanner;

class Main {


    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] arr = new int[n];
        for (int i = 0; i<n; i++){
            arr[i] = scanner.nextInt();
        }

        Arrays.sort(arr);
         long sum = 0;
        for (int i= 0; i< arr.length; i++){
            sum+= arr[i];
        }
        
       System.out.println(arr[0] + " " + arr[n-1] + " " + sum);
    }
}



Measured memory_bytes: 40916
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int n;
    ll a[300005] = {}, c = 0, d[300005] = {}, e[300005] = {}, z = -mod * 890328ll;
    multiset<ll> m;
    cin >> n;
    for (int i = 1; i <= n + n + n; i++) cin >> a[i];
    for (int i = 1; i <= n; i++) m.insert(a[i]), c += a[i];
    d[n] = c;
    for (int i = n + 1; i <= n + n + n; i++) {
        m.insert(a[i]);
        c += a[i] - *m.begin();
        m.erase(m.begin());
        d[i] = c;
    }
    m.clear(); c = 0;
    for (int i = n + n + n; i > n + n; i--) m.insert(a[i]), c += a[i];
    e[n + n + 1] = c;
    for (int i = n + n; i; i--) {
        m.insert(a[i]);
        c += a[i] - *m.rbegin();
        m.erase(m.find(*m.rbegin()));
        e[i] = c;
    }
    for (int i = n; i <= n + n; i++) z = max(z, d[i] - e[i + 1]);
    cout << z << '\n';
}


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

int main() {
	string S;
	int N, A;
	while (1) {
		cin >> S;
		if (S == "-") break;
		cin >> N;
		for (int i = 0; i < N; i++) {
			cin >> A;
			S = S.substr(A, S.size() - A) + S.substr(0, A);
		}
		cout << S << endl;
	}
}


Measured memory_bytes: 3148
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_map>
#include<climits>
#include<cstdlib>
#include<cmath>
#include<string>
#include<iomanip>
#include<bitset>
#include<list>

using namespace std;

#define ll long long int

ll const MOD = 1000003;
ll const INF = (long long int)1 << 61;

class Combination{
    long long int maxn;
    long long int mod;
    std::vector<long long int> factorial;
    std::vector<long long int> inverse;

    public:

    Combination(long long int n,long long int m):maxn(n),mod(m){
        factorial.push_back(1);
        inverse.push_back(1);

        for(long long int i = 1; i <= n; i++){
            factorial.push_back((factorial.back()*i)%mod);
            inverse.push_back([&](long long int x,long long int n) -> long long int{
                long long int ret = 1;
                while(n > 0){
                    if(n&1)ret = (ret*x)%mod;
                    x = (x*x)%mod;
                    n >>= 1;
                }
                return ret;
            }(factorial.back(),mod-2));
        }
    }

    long long int getFactorial(int idx){
        if(idx > maxn || idx < 0)return -1;
        return factorial[idx];
    }

    long long int getInverse(int idx){
        if(idx > maxn || idx < 0)return -1;
        return inverse[idx];
    }

    long long int comb(long long int n,long long int r){
        return (((factorial[n]*inverse[n-r])%mod)*inverse[r])%mod;
    }
};

ll mypow(ll x,ll n){
    ll ret = 1;
    while(n > 0){
        if(n&1){
            ret = (ret*x)%MOD;
        }
        x = (x*x)%MOD;
        n >>= 1;
    }
    return ret;
}

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

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

    Combination cb(1000002,1000003);

    for(int i = 0; i < q; i++){
        ll a = (x[i]*mypow(d[i],MOD-2))%MOD;
        if(d[i] == 0){
            cout << mypow(x[i],n[i]) << endl;
            continue;
        }else if(a + n[i] - 1 >= MOD){
            cout << 0 << endl;
            continue;
        }else if(x[i] == 0){
            cout << 0 << endl;
            continue;
        } 
        ll ans = cb.getFactorial(a + n[i] - 1);
        ans *= cb.getInverse(a - 1);
        ans %= MOD;
        ans *= mypow(d[i],n[i]);
        ans %= MOD;
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 19284
#include<iostream>
using namespace std;
int main()
{
int A,B;
cin>>A>>B;
A=(A+11)%13;
B=(B+11)%13;
if (A>B)
cout<<"Alice";
else if (A<B)
cout<<"Bob";
else 
cout<<"Draw";
system("pause");
return 0;
} 

Measured memory_bytes: 504
import sys
input = sys.stdin.buffer.readline
N, K = map(int, input().split())
A = [-1] + list(map(int, input().split()))

I = [-1] * (N + 1)
S = []
idx = 1
while I[idx] == -1:
    S.append(idx)
    I[idx] = len(S)
    idx = A[idx]
# print(f'{S=}, {idx=}, {I[idx]=}')

start_idx = I[idx] - 1
num_circles = len(S) - start_idx
# print(f'{start_idx=}, {num_circles=}')

if K < len(S) - 1:
    ans = S[K]
else:
    K -= start_idx
    div, mod = divmod(K, num_circles)
    ans = S[start_idx + mod]
print(ans)


Measured memory_bytes: 27796
#include<algorithm>
#include<cstring>
#include<cstdio>
using namespace std;

int sx, sy, gx, gy;
int dx[5][1111], dy[5][1111], dn[5];
int memo[5][5][1111];
int a, b;
int u;

int solve(int k, int t, int q){

  if(k == 4) return abs(dx[t][q]-gx) + abs(dy[t][q]-gy);
  if(memo[k][t][q]) return memo[k][t][q];

  int ans = 1<<28, s, d = (t+1)%5;

  for(int i=0;i<dn[d];i++){
    if(!k) s = abs(sx-dx[d][i]) + abs(sy-dy[d][i]);
    else s = abs(dx[t][q]-dx[d][i]) + abs(dy[t][q]-dy[d][i]);
    ans = min(ans, solve(k+1, d, i) + s);
  }

  return memo[k][t][q] = ans;
}

int main(){

  int w,h;
  char c;

  while(true){
    scanf("%d %d", &w, &h);
    if(!w && !h) break;

    memset(dn, 0, sizeof(dn));

    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	scanf(" %c", &c);
	if(c == 'S') sx = j, sy = i;
	else if(c == 'G') gx = j, gy = i;
	else if(c != '.') u = c-'1', dx[u][dn[u]] = j, dy[u][dn[u]] = i, dn[u]++;
      }
    }
    
    int h = -1;
    for(int i=0;i<5;i++) if(!dn[i]) h++;

    b = 1<<28;
    for(int i=0;i<5&&h<1;i++){
      memset(memo, 0, sizeof(memo));
      if(b > solve(0,i,0)) a = i, b = memo[0][i][0];
    }

    if(b == 1<<28) printf("NA\n");
    else printf("%d %d\n", a+1, b);

  }
}

Measured memory_bytes: 1188
#import pysnooper
#import numpy
#import os,re,sys,operator
#from collections import Counter,deque
#from operator import itemgetter,mul
#from itertools import accumulate,combinations,groupby,combinations_with_replacement,permutations
from sys import stdin,setrecursionlimit
#from bisect import bisect_left,bisect_right
#from copy import deepcopy
#import heapq
#import math
#import string
#from time import time
#from functools import lru_cache,reduce
#from math import factorial,hypot
#import sys
#from fractions import gcd
setrecursionlimit(10**6+1)
input=stdin.readline

n,m=map(int,input().split())
a=[list(map(int,input().split())) for _ in range(m)]
for i in range(1000):
    now=str(i)
    if len(now)!=n:
        continue
    ch=True
    for j in range(m):
        #print(now[a[j][0]-1],a[j][1])
        if int(now[a[j][0]-1])!=a[j][1]:
            ch=False
            break
    if ch:
        print(i)
        exit()
print(-1)

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

int main(){
  int i,j;
  int n,m;
  int a,b,c,d;
  int x1,x2,y1,y2;
  int ans;
  int rout[21][21];
  int dis1[21],dis2[21];
  int flag;

  while(scanf("%d",&n)!=EOF){
    cin >> m;

    for(i=1;i<=n;i++){
      for(j=1;j<=n;j++){
	rout[i][j] = -1;
      }
    }

    for(i=0;i<m;i++){
      scanf("%d,%d,%d,%d ",&a,&b,&c,&d);
      rout[a][b] = c;
      rout[b][a] = d;
    }
    scanf("%d,%d,%d,%d ",&x1,&x2,&y1,&y2);

    for(i=1;i<=n;i++)dis1[i] = -1;
    for(i=1;i<=n;i++)dis2[i] = -1;
    dis1[x1] = 0;
    dis2[x2] = 0;

    while(1){
      flag = 0;

      for(i=1;i<=n;i++){
	if(dis1[i]>=0){
	  for(j=1;j<=n;j++){
	    if(rout[i][j]>=0){
	      if(dis1[j]<0){
		dis1[j] = dis1[i] + rout[i][j];
		flag = 1;
	      }else if(dis1[i]+rout[i][j] < dis1[j]){
		dis1[j] = dis1[i]+rout[i][j];
		flag = 1;
	      }
	    }
	  }
	}
	if(dis2[i]>=0){
	  for(j=1;j<=n;j++){
	    if(rout[i][j]>=0){
	      if(dis2[j]<0){
		dis2[j] = dis2[i] + rout[i][j];
		flag = 1;
	      }else if(dis2[i]+rout[i][j] < dis2[j]){
		dis2[j] = dis2[i]+rout[i][j];
		flag = 1;
	      }
	    }
	  }
	}
      }
      if(!flag)break;
    }
  
    ans = y1 - y2 -dis1[x2] - dis2[x1];
    cout << ans << endl;
  }
}

Measured memory_bytes: 0
A, B, K = [int(x) for x in input().split()]

numbers = []

for i in range(K):
  n, m = A + i, B - i
  
  if A <= n <= B and n not in numbers:
    numbers.append(n)
  if A <= m <= B and m not in numbers:
    numbers.append(m)

numbers.sort()

for n in numbers:
  print(n)
  

Measured memory_bytes: 38384
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
#include <sstream>
#include <iomanip>
#include <set>
#include <stack>
#include <cassert>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vvb> vvvb;
typedef vector<vvvb> vvvvb;
typedef vector<string> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<P> vp;
typedef vector<PL> vpl;
typedef vector<vector<P>> vvp;
typedef vector<vector<PL>> vvpl;
const int INF = 1001001001;
const ll LINF = 1e17;
const double pi = 3.1415926535897932;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define RFOR(i, a, b) for(ll i = (a); i > b; i--)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define RREP(i, n) for(ll i = n-1; i > -1; i--)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second
#define pb push_back
#define epb emplace_back

template <typename T>
T gcd(T a, T b) {
    return (a == 0) ? b : gcd(b%a, a);
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

bool p_comp_fs(const PL p1, const PL p2){ return p1.first < p2.first;};
bool p_comp_fg(const PL p1, const PL p2){ return p1.first > p2.first;};
bool p_comp_ss(const PL p1, const PL p2){ return p1.second < p2.second;};
bool p_comp_sg(const PL p1, const PL p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}


int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    ll x, a; cin >> x >> a;
    if(x < a) cout << 0 << endstr;
    else cout << 10 << endstr;
    return 0;
}


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

int main() {
	string s;
	int a, b;
	cin >> s;
	a = 10*(s[0]-'0') + s[1]-'0';
	b = 10*(s[2]-'0') + s[3]-'0';
	if(a > 0 && a < 13) {
		if(b > 0 && b < 13)
			cout << "AMBIGUOUS" << endl;
		else cout << "MMYY" << endl;
	} else {
		if(b > 0 && b < 13)
			cout << "YYMM" << endl;
		else cout << "NA" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
use std::io::*;
use std::str::*;

fn read<T: FromStr>() -> Option<T> {
    let stdin = stdin();
    let s = stdin
        .bytes()
        .map(|c| c.unwrap() as char)
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().ok()
}

fn read_nums(limit_num: usize) -> Vec<i32> {
    let mut vec: Vec<i32> = Vec::new();
    while let Some(n) = read() {
        vec.push(n);
        if vec.len() == limit_num {
            break;
        }
    }
    return vec;
}

fn main() {
    let n: usize = read().unwrap();
    let x_list = read_nums(n);
    let mut sorted = x_list.clone();
    sorted.sort_by(|a, b| a.cmp(b));
    let half = (n as f32 / 2.0).floor() as usize;
    for i in 0..n {
        if sorted.binary_search(&x_list[i]).unwrap() <= half - 1 {
            println!("{}", sorted[half]);
        } else {
            println!("{}", sorted[half - 1]);
        }
    }
}


Measured memory_bytes: 8316
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
      	
		// 1段目の宝石数
		int n = sc.nextInt();
      
      	int[] calcList = new int[n];
     
        // 2段目のvの数値
      	for (int i=0; i < n; i++) {
          calcList[i] = sc.nextInt();
        }
      
        // 3段目のvの数値
		for (int i=0; i < n; i++) {
           calcList[i] = calcList[i] - sc.nextInt();
        }
      
        int max = 0;
		for (int calcNum : calcList) {
          if (calcNum > 0) {
            max += calcNum;
          }
        }
      
        System.out.println(max);
	}
}

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

int main(){

  ll N,M;
  
  cin>>N>>M;
  
 
  if(M%2!=0){

    rep(i,M/2){
      
      cout<<i+1<<" "<<M-i<<endl;
      
    }
    rep(i,M/2+1){

      cout<<M+1+i<<" "<<2*M+1-i<<endl;
      
    }
    
  }
  else{

     rep(i,M/2){
      
      cout<<i+1<<" "<<M+1-i<<endl;
      
    }
    rep(i,M/2){

      cout<<M+2+i<<" "<<2*M+1-i<<endl;
      
    }
    

  }
  
  

}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
#define tri pair<pii,int>
#define mp make_pair
#define pb push_back
const int N=3011;

string s,t;
int nxt[N][27];
int dp[N][N];
tri p[N][N];
vector<char> ans;
void chmax(int x,int y,int z,int w,bool P)
{
	if(dp[x][y]>=dp[z][w]+P) return;
	dp[x][y]=dp[z][w]+P;
	p[x][y]=mp(mp(z,w),P);
}

int main()
{
	
	cin>>s>>t;
	memset(nxt,-1,sizeof(nxt));
	for(int i=0,x=-1;i<26;i++,x=-1)
	for(int j=t.size()-1;j>=0;j--)
	{
		if(t[j]=='a'+i) x=j;
		nxt[j][i]=x;
	}
	for(int i=0;i<=s.size();i++)
	for(int j=0;j<=t.size();j++)
	{
		chmax(i+1,j,i,j,0);
		chmax(i,j+1,i,j,0);
		if(nxt[j][s[i]-'a']!=-1) chmax(i+1,nxt[j][s[i]-'a']+1,i,j,1);
	}
	int a=s.size(),b=t.size();
	int c=dp[s.size()][t.size()];
	while(dp[a][b])
	{
		int aa=p[a][b].first.first,bb=p[a][b].first.second,cc=p[a][b].second;
		if(cc) ans.pb(s[aa]);
		a=aa,b=bb,c=cc;
	}
	reverse(ans.begin(),ans.end());
	for(int i=0;i<ans.size();i++)
		cout<<ans[i];cout<<'\n';
	
	return 0;
}

Measured memory_bytes: 142080
#include <bits/stdc++.h>
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;
}
typedef long long int ll;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define endl "\n"
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------
using P = pair<ll, ll>;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, m, l;
    cin >> n >> m >> l;
    vector<vector<ll>> g(n, vector<ll>(n, LLINF));
    for (ll i = 0; i < m; i++)
    {
        ll a, b, c;
        cin >> a >> b >> c;
        a--;
        b--;
        g[a][b] = c;
        g[b][a] = c;
    }
    vector<vector<P>> d(n, vector<P>(n, P(LLINF, LLINF)));
    for (ll s = 0; s < n; s++)
    {
        d[s][s] = P(0, 0);
        priority_queue<pair<P, int>, vector<pair<P, int>>, greater<pair<P, int>>> que;
        que.push(make_pair(P(0, 0), s));
        while (que.size())
        {
            auto now = que.top();
            que.pop();
            if (now.first > d[s][now.second])
            {
                continue;
            }
            for (ll next = 0; next < n; next++)
            {
                if (next == now.second)
                {
                    continue;
                }
                if (g[now.second][next] > l)
                {
                    continue;
                }
                ll nu = now.first.second + g[now.second][next];
                P np;
                if (nu > l)
                {
                    np = P(now.first.first + 1, g[now.second][next]);
                }
                else
                {
                    np = P(now.first.first, nu);
                }
                if (chmin(d[s][next], np))
                {
                    que.push(make_pair(np, next));
                }
            }
        }
    }

    ll q;
    cin >> q;
    while (q--)
    {
        ll s, t;
        cin >> s >> t;
        s--;
        t--;
        ll ans = d[s][t].first;
        cout << (ans == LLINF ? -1 : ans) << endl;
    }
}

Measured memory_bytes: 3904
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define ALL(container) (container).begin(), (container).end()
#define RALL(container) (container).rbegin(), (container).rend()
#define SZ(container) ((int)container.size())
#define mp(a,b) make_pair(a, b)
#define pb push_back
#define eb emplace_back
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define __builtin_popcount __builtin_popcountll

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 (a>b) { a=b; return 1; } return 0; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
    os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
    os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const map<S, T> &t) {
    os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class S, class T> pair<S,T> operator+(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first+t.first, s.second+t.second);}
template<class S, class T> pair<S,T> operator-(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first-t.first, s.second-t.second);}

const int INF = 1<<28;
const double EPS = 1e-8;
const int MOD = 1000000007;


ll T, n, m;

int main(int argc, char *argv[]){
    ios::sync_with_stdio(false);
    cin >> m;
    n = 20;
    vector<tuple<int, int, int>> e;
    REP(i, 18) {
        e.emplace_back(i + 1, i, 0);
        e.emplace_back(i + 1, i, 1 << i);
    }
    ll sum = 0;
    RREP(i, 20) {
        if ((m >> i) & 1) {
            if (i < 19) {
                e.emplace_back(19, i, sum);
            } else {
                e.emplace_back(19, 18, 0);
                e.emplace_back(19, 18, 1 << 18);
            }

            sum += 1 << i;
        }
    }
    cout << 20 << " " << e.size() << endl;
    for(auto it : e) {
        int u, v, w; tie(u, v, w) = it;
        cout << 20 - u << " " << 20 - v << " " << w << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
using namespace std;
int main(void){
	int w,h,c,i,wh,m,min;
	cin>>w>>h>>c;
	wh=w*h;
	min=2147483647;
	for(i=1;i*i<=wh;i++){
		if(wh%(i*i)==0&&w%i==0&&h%i==0){
			m=(wh/(i*i))*c;
			if(min>m) min=m;
		}
	}
	cout<<min<<endl;
	return 0;
}

Measured memory_bytes: 3128
#!/usr/bin/env python3
from itertools import accumulate


def rfind(x):
    return csr[x] - csr[x + 1] == 1


def cfind(x):
    return csc[x] - csc[x + 1] == 1


MOD = 10 ** 9 + 7

N, M = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

if len(set(A)) < N or len(set(B)) < M:
    print(0)
    exit()

r = [0] * (N * M + 1)
for x in sorted(A):
    r[x] = 1
csr = list(accumulate(r[::-1]))[::-1] + [0]

c = [0] * (N * M + 1)
for x in sorted(B):
    c[x] = 1
csc = list(accumulate(c[::-1]))[::-1] + [0]

ans = 1
for i in range(1, N * M + 1)[::-1]:
    if rfind(i) and cfind(i):
        ans *= 1
    elif rfind(i):
        ans *= csc[i]
    elif cfind(i):
        ans *= csr[i]
    else:
        ans *= csc[i] * csr[i] - (N * M - i)
    ans %= MOD
print(ans)


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

int main() {
    string s;
    cin >> s;
    int n = s.size();
    int c0 = 0, c1 = 0;
    rep(i, n) {
        if (s[i] == '0') c0++;
        if (s[i] == '1') c1++;
    }
    cout << 2 * min(c0, c1) << endl;
}

Measured memory_bytes: 3736
#include<stdio.h>
int main(void){

  int i;
  for(i=1;i<10;i++){
    printf("%dx1=%d\n",i,i*1);
    printf("%dx2=%d\n",i,i*2);
    printf("%dx3=%d\n",i,i*3);
    printf("%dx4=%d\n",i,i*4);
    printf("%dx5=%d\n",i,i*5);
    printf("%dx6=%d\n",i,i*6);
    printf("%dx7=%d\n",i,i*7);
    printf("%dx8=%d\n",i,i*8);
    printf("%dx9=%d\n",i,i*9);

  }


  return 0;
}

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

#define FOR(i,a,b) for(int i=(a);i<(int)(b);i++)
#define rep(i,n) FOR(i,0,n)
#define SZ(x) (int)(x).size()

void solve(int n, int k, int s) {
    vector<int> v(n);
    rep(i,n) v[i] = i+1;

    int ans = 0;
    rep(mask, 1<<n) {
        int sum = 0, cnt = 0;
        rep(i,n) if(mask&(1<<i)) {
            sum += i+1;
            ++cnt;
        }
        if(cnt == k and sum == s) ++ans;
    }

    cout << ans << "\n";
}

int main() {
    int n,k,s;
    while(cin>>n>>k>>s, n) solve(n,k,s);
    return 0;
}

Measured memory_bytes: 2980
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
#include <map>
#include <stack>
using namespace std;
typedef long long int lli;
#define urept(soeji, start, n) for (int soeji = start; soeji < n; soeji++)
#define drept(soeji, start, n) for (int soeji = start; soeji > n; soeji--)
int main(void)
{
    int N;
    cin >> N;
    int tmp;
    vector<int> a;
    for (int i = 0; i < N; i++)
    {
        cin >> tmp;
        a.push_back(tmp);
    }
    int ans = 0;
    for (int i = 0; i < N; i++)
    {
        if ((i + 1) % 2 == 1 && a[i] % 2 == 1)
        {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n,i,s,a[100],sum=0,m=100000;
	scanf("%d %d",&n,&s);
	for(i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
		s-=a[i];
		sum++;
		if(a[i]<m)
			m=a[i];
	}
	s/=m;
	sum+=s;
	printf("%d",sum);
	return 0;
}

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

struct Node {
    int key;
    Node *right, *left, *parent;
};

Node *root, *NIL;

void insert(int k){
    Node *y = NIL;
    Node *x = root;
    Node *z;

    z = (Node *)malloc(sizeof(Node));
    z->key = k;
    z->left = NIL;
    z->right = NIL;

    while (x != NIL){
        y = x;
        if (z->key < x->key){
            x = x->left;
        } else {
            x = x->right;
        }
    }    
    z->parent = y;
    if (y == NIL){
        root = z;
    } else {
        if (z->key < y->key){
            y->left = z;
        } else{
            y->right = z;
        }
    }
}

void inorder(Node *u){
    if (u==NIL) return;
    inorder(u->left);
    printf(" %d", u->key);
    inorder(u->right);
}

void preorder(Node *u){
    if (u == NIL) return;
    printf(" %d", u->key);
    preorder(u->left);
    preorder(u->right);
}

int main(){
    int n, i, x;
    string com;

    scanf("%d", &n);

    for (i = 0; i < n; i++){
        cin >> com;
        if (com == "insert"){
            scanf("%d", &x);
            insert(x);
        }else if (com == "print"){
            inorder(root);
            printf("\n");
            preorder(root);
            printf("\n");
        }
    }
    return 0;
}


Measured memory_bytes: 26648
#include <iostream>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;

int main() {
    int f[50];
    f[0]=f[1]=1;
    int n;
    cin>>n;
    rep(i,n+1) if(i>1) f[i]=f[i-1]+f[i-2];
    cout<<f[n]<<endl;
    return 0;
}

Measured memory_bytes: 1164
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,t=0,sum=0,p=0,q=0,e=0,d=0;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
    {
     cin>>a[i];
    }
    for(int i=0;i<n;i++)
    {
        t+=a[i];
    }

    sum=(t/n);
    e=sum;
    if(t%n!=0)
    {
        sum++;
    }

    for(int i=0;i<n;i++)
    {
        p=abs(a[i]-sum);
        q+=(p*p);

    }
    for(int i=0;i<n;i++)
    {
        p=abs(a[i]-e);
        d+=(p*p);
    }
cout<<min(q,d)<<endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <vector>
#include <unordered_map>
#include <numeric>
#include <algorithm>
#define rep(it, ifrom, ito) for (auto it = ifrom; it != ito; ++it)
#define all(a) a.begin(), a.end()

using namespace std;

int main(int argc, char* argv[]) {
    const char* debug_env = getenv("DEBUG");
    const bool debug = debug_env && atoi(debug_env) != 0;

    int N;
    cin >> N;
    if (N == 3 || N == 5 || N == 7) cout << "YES" << endl;
    else cout << "NO" << endl;

    return 0;
}



Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val d = sc.nextInt()
    var n = sc.nextInt()
    if (n == 100) {
        n++
    }
    println(n.toString() + (1..d).map { "00" }.joinToString(""))
}


Measured memory_bytes: 31260
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<cstdio>
#include<stdio.h>
#include<cmath>
#include<math.h>
#include<vector>
#include<set>
#include<queue>
#include<map>
#include<sstream>
#define forn(i,n) for(int (i)=0;i<(n);i++)
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int,int>pii;
typedef long long ll;
typedef pair<ll,ll> pll;
const int MAXN=100005;
const int INF=2147483647;
const ll LINF=9223372036854775807;
const int dx[]={1,-1,0,0},dy[]={0,0,1,-1};
ll a,b,c;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>a>>b>>c;
	if(c-a-b<0ll)cout<<"No";
	else if((c-a-b)*(c-a-b)>4*a*b)cout<<"Yes";
	else cout<<"No";
	return 0;
}


Measured memory_bytes: 256
import sys
n,m,v,p=map(int,sys.stdin.readline().split())
a=sorted(list(map(int, sys.stdin.readline().split())),reverse=True)[p-1:]
l,r=0,n-p

while l+1<r:
    k=(l+r)//2
    b=a[k]+m
    if b<a[0] or (v-(n-k))*m>(k*b-sum(a[:k])):
        r=k
    else:
        l=k

b=a[r]+m
if b<a[0] or (v-(n-r))*m>(r*b-sum(a[:r])):
    print(p+l)
else:
    print(p+r)


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

using namespace std;

int main()
{
    int n;
    cin >> n;
    string s;
    cin >> s;
    if (n % 2 == 1)
    {
        cout << "No" << endl;
        return 0;
    }

    bool flag = true;
    for (int i = 0; i < n / 2; i++)
    {
        flag &= s[i] == s[i + n / 2];
    }

    if (flag)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

    return 0;
}

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

inline void solve(){
    map <int,int> mp;
    int  n, k,ans=0; cin >> n >> k ; 
    while (n--){
        int a; cin>>a;
        mp[a]++;
    }
    if (sz(mp)>k){
        n = sz(mp);
        vi v(n);
        int i=0;
        for (auto &it: mp) v[i++]=it.ss;
        sort(v.begin(), v.end());
        int c=n-k;
        for (int i=0;i<n;i++){
            ans += v[i];
            c--;
            if (c==0) break;
        }
    }
    cout << ans << endl;
}

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


Measured memory_bytes: 17076
def main():
    import numpy as np
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    a += [a[-1]]*k
    a = np.array(a, dtype=np.int64)

    dp = np.full(n+k, 10**10, dtype=np.int64)
    dp[0] = 0
    for i in range(n-1):
        dp[i+1:i+k+1] = np.minimum(dp[i+1:i+k+1],
                                   dp[i]+np.abs(a[i+1:i+k+1]-a[i]))

    print(dp[n-1])


main()

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

int main() {
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n), d(n + 1);
    
    rep(i, n) cin >> a[i];
    rep(i, n) {
        d[i + 1] = d[i] + a[i];
        d[i + 1] %= k;
    }
    map<ll, ll> mp;
    ll ans = 0;
    queue<ll> que;
    rep(r, n + 1) {
        ll t = (d[r] - r) % k;
        if (t < 0) t += k;
        ans += mp[t];
        mp[t]++;
        que.push(t);
        if (que.size() >= k) {
            mp[que.front()]--;
            que.pop();
        }
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 20332