akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(void) {
    int n;
    cin >> n;
    vector<int> a;
    for (int i = 0; i < n; ++i) {
        int a_in;
        cin >> a_in;
        a.push_back(a_in);
    }

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

    int alicescore = 0, bobscore = 0;
    for (int i = 0; i < n; ++i) {
        if (i % 2 == 0) {
            alicescore += a[n - i - 1];
        } else {
            bobscore += a[n - i - 1];
        }
    }

    cout << alicescore - bobscore << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  
#include <chrono>
#include <random>
#include <time.h>
#include <fstream>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define endl "\n"
#define all(c) begin(c),end(c)
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}


#define LLINF 1e18+7
#define N 250000
ll MOD=1e9+7;
main(){
    int n=in();
    vector<int> v;
    rep(i,n)v.pb(in());
    int m=0;
    rep(i,n){
        int t=0;
        while(i<n-1&&v[i+1]<=v[i]){
            t++;i++;
        }
        m=max(m,t);
    }
    cout<<m<<endl;
}

Measured memory_bytes: 892
#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<vector>
#include<utility>
#include<stack>
#include<queue>
#include<list>
 
#define FOR(i, a, b) for(int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000001
 
using namespace std;
 
 
 
int main(void) {
   int n,x;
   int ma[100001];
   int mini=INF;
   long long int count=0;
   
   cin>>n;
   cin>>x;
   FOR(i,1,n){
     cin>>ma[i];
     x-=ma[i];
     if(ma[i]<mini)mini=ma[i];
   }
   count=n;
   count+=(x/mini);
   cout<<count<<endl;
   
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;
typedef long long ll;
const int MAX_N = 200010;

int a[MAX_N];

int main() {
    int n;
    cin >> n;
    for (int i=0;i<n;i++) {
        cin >> a[i];
    }
    int cur = 0;
    ll cnt = 0;
    int l = 0, r = 0;
    while(l < n) {
        while (r < n && (cur ^ a[r]) == cur + a[r]) {
            cur ^= a[r];
            cnt++;
            r++;
        }
        cur ^= a[l];
        l++;
        cnt += r-l;
    }
    cout << cnt << endl;
}


Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int main() {
	int x;
	cin >> x;
	int c = 0;
	for (int i = 0; i < x; i++) {
		for (int j = 0; j < x; j++) {
			for (int k = 0; k < x; k++) {
				c++;
			}
		}
	}
	cout << c << endl;
	return 0;
}

Measured memory_bytes: 256
s = input()
n = len(s)
ans = 0
for i in range(2**(n-1)):
  flag = [False] * (n-1)
  for j in range(n-1):
    if (i >> j) & 1:
      flag[j] = True
  tmp = int(s[0])
  for k in range(n-1):
    if flag[k]:
      ans += tmp
      tmp = int(s[k+1])
    else:
      tmp *= 10
      tmp += int(s[k+1])
  ans += tmp
print(ans)

Measured memory_bytes: 9208
//kruskal tree
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
using namespace std;
#define M 9999
int parent[M],a[M],b[M];
pair<double,int>node[M];
int root(int a){return parent[a]==a?a:parent[a]=root(parent[a]);}
int unite(int a,int b){
	int x=root(a),y=root(b);
	if(x==y)return 0;
	parent[x]=y;
	return 1;
}
int main(){
	int i,j,k,m,n,q;
	double x,y,z,r,t;
	for(;scanf("%d",&n),n;){
		vector<vector<double> >v;
		for(q=m=i=0;i<n;i++){
			scanf("%lf%lf%lf%lf",&x,&y,&z,&r),v.push_back({x,y,z,r}),parent[i]=i;
			for(j=0;j<i;j++){
				for(x=k=0;k<3;k++)x+=(t=v[i][k]-v[j][k])*t;
				x=sqrt(x)-v[i][3]-v[j][3];
				if(x<=0){if(unite(i,j))q++;}
				else a[m]=i,b[m]=j,node[m].first=x,node[m++].second=m;
			}
		}
		sort(node,node+m);
		for(x=i=0;i<m&&q<n-1;i++)if(unite(a[node[i].second],b[node[i].second]))x+=node[i].first,q++;
		printf("%.3f\n",x);
	}
}

Measured memory_bytes: 1296
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using static MyIO;


public class A
{
    public static void Main()
    {
        string a = GetString();
        string b = GetString();

        if ( a == "H" && b == "H" || a == "D" && b == "D")
        {
            Console.WriteLine("H");
        }
        else if ((a == "D" && b == "H") || (a == "H" && b == "D"))
        {
            Console.WriteLine("D");
        }
    }
}


public static class MyIO
{
    private static string[] args = null;
    private static int num = -1;
    private static int used = -1;

    private static string getArg()
    {
        if (used == num)
        {
            args = Console.ReadLine().Split(' ');
            num = args.Length;
            used = 0;
        }
        return args[used++];
    }

    public static int GetInt() { return int.Parse(getArg()); }
    public static long GetLong() { return long.Parse(getArg()); }
    public static double GetDouble() { return double.Parse(getArg()); }
    public static string GetString() { return getArg(); }
}


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

int main()
{
    int n;
    cin >> n;
    vector<int> e(100);
    vector<int> x(n);
    rep(i, n)
    {
        cin >> x[i];
    }

    rep(i, 100)
    {
        int sum = 0;
        rep(j, n)
        {
            sum += (i - x[j]) * (i - x[j]);
        }
        e[i] = sum;
    }
    sort(e.begin(), e.end());
    cout << e[0] << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#include<vector>
#include<iostream>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<iomanip>
#include<assert.h>
#include<unordered_map>
#include<unordered_set>
#include<string>
#include<stack>
#include<complex>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

#define WHATS(var)cout<<__LINE__<<' '<<#var<<"="<<var<<endl;

template<class S, class T> ostream& operator <<(ostream &os, const pair<S, T> v){
os << "( " << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator <<(ostream &os, const vector<T> &v){
for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator <<(ostream &os, const vector<vector<T>> &v){
for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}
template<class T> ostream& operator <<(ostream &os, const vector<set<T>> &v){
for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}
template<class T> ostream& operator <<(ostream &os, const set<T> &v){
int i=0;
for(auto it:v){
	if(i > 0){os << ' ';}
	os << it;
	i++;
} 
return os;
}
/*
1 2 3 4 5 6 7 8 9 10 11 12 13 14

12 1 11
13 3 10
14 5 9
15 7 8
16 2 14
17 4 13
18 6 12

1-12

11 1 10
12 3 9
13 5 8
13 6 7
14 2 12
15 4 11
*/

using ll=long long ;

int main() {
	ios::sync_with_stdio(false);
	int N;cin>>N;
	int K;cin>>K;
	vector<int>as(N),bs(N);
	if(N%2){
		for(int i=0;i<=N/2;++i){
			as[i]=2*i+1;
			bs[i]=(2*N+1)-(N/2-i)-as[i];
		}
		for(int i=N/2+1;i<N;++i){
			as[i]=2*(i-N/2);
			bs[i]=(2*N+1)+(i-N/2)-as[i];
		}
	}else{
		for(int i=0;i<N/2;++i){
			as[i]=2*i+1;
			bs[i]=(2*N+1)-(N/2-i)-as[i]+1;
		}
		as[N/2]=as[N/2-1]+1;
		bs[N/2]=bs[N/2-1]-1;
		for(int i=N/2+1;i<N;++i){
			as[i]=2*(i-N/2-1)+2;
			bs[i]=(2*N+1)+(i-N/2)-as[i];
		}
	}
	vector<int>cs(N);
	iota(cs.begin(),cs.end(),2*N+1);
	// WHATS(as)
	// WHATS(bs)
	// WHATS(cs)
	bool ok=true;
	for(int i=0;i<N;++i){
		as[i]+=K-1;
		bs[i]+=K-1;
		cs[i]+=K-1;
		if(as[i]+bs[i]>cs[i])ok=false;
	}
	if(ok){
		for(int i=0;i<N;++i){
			cout<<as[i]<<' '<<bs[i]<<' '<<cs[i]<<endl;
		}
	}else{
		cout<<-1<<endl;
	}
	return 0;
}

Measured memory_bytes: 3456
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

ans = B[A[0]-1]
tmp = A[0]
for i in range(1, N):
    ans+=B[A[i]-1]
    if A[i]==tmp+1:
        ans+=C[tmp-1]
    tmp = A[i]
    
print(ans)

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

#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define all(x) (x).begin(), (x).end()
#define uniq(x) (x).erase(unique(all(x)), end(x))
#define bit(n) (1LL << (n))
#define cdiv(a, b) (((a) - 1) / (b) + 1)
#define dump(x) cerr << #x " = " << (x) << endl
using vint = vector<int>;
using vvint = vector<vint>;
using pint = pair<int, int>;
using vpint = vector<pint>;
template<typename T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;
constexpr double PI = 3.1415926535897932384626433832795028;
constexpr int DY[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int DX[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<typename T> void fin(T mes) {
    cout << mes << endl;
    exit(0);
}
template<typename T, typename U> bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct setup {
    static constexpr int PREC = 20;
    setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

map<int, int> mp;
int A, B, C, D;
int f(int n) {
    if (n == 0) { return 0; }
    if (n == 1) { return D; }
    if (mp.count(n) != 0) { return mp[n]; }
    int ret = LLONG_MAX;
    chmin(ret, f(n / 2) + (n - n / 2 * 2) * D + A);
    chmin(ret, f(cdiv(n, 2)) + (cdiv(n, 2) * 2 - n) * D + A);
    chmin(ret, f(n / 3) + (n - n / 3 * 3) * D + B);
    chmin(ret, f(cdiv(n, 3)) + (cdiv(n, 3) * 3 - n) * D + B);
    chmin(ret, f(n / 5) + (n - n / 5 * 5) * D + C);
    chmin(ret, f(cdiv(n, 5)) + (cdiv(n, 5) * 5 - n) * D + C);
    if (n < INT_MAX) { chmin(ret, n * D); }
    return mp[n] = ret;
}

signed main() {
    int T;
    cin >> T;
    rep(i, T) {
        mp.clear();
        int N;
        cin >> N >> A >> B >> C >> D;
        cout << f(N) << endl;
        //for(auto p:mp)cerr<<p.first<<" "<<p.second<<endl;
    }
}


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

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define ll long long
const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1);

int main(void)
{
    string s,t; cin>>s>>t;
    ll ans=0;
    rep(i,s.size()){
        if(s[i]!=t[i]) ans++;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3916
#include <iostream>

using namespace std;

int main(){
  int n;
  string s;
  int res=0;
  cin >> n >> s;
  
  for (int i = 0; i < n; i++) {
    if (s.substr(i,3)=="ABC") {
	  res+=1;
	}
  }
 
  cout << res << endl;
  return 0;
} 

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
//using System.Linq;
//using System.Numerics;

class Program {
    static void Main (string[] args) {
        var input = INP();
        int N = TOI(input[0]);

        var input2 = INP();
        int[] a = new int[N];
        for(int i=0;i<N;i++) {
            a[i] = TOI(input2[i]);
        }

        int cnt = 0;
        for(int i=0;i<N;i++) {
            if((i+1)%2==1) {
                if(a[i]%2==1) {
                    cnt++;
                }
            }
        }

        CWL(cnt);
    }


    public static List<int> PrimeFactors (int n) {
        var tmpList = new List<int>();
        int i = 2;
        int tmp = n;

        while(i * i <= n) {
            if(tmp % i == 0) {
                tmp /= i;
                tmpList.Add(i);
            } else {
                i++;
            }
        }

        if(tmp != 1) tmpList.Add(tmp);

        return tmpList;
    }

    static string[] INP () {
        return Console.ReadLine().Split(' ');
    }

    static void CWL (string value) {
        Console.WriteLine(value);
    }

    static void CWL (int value) {
        Console.WriteLine(value);
    }

    static void CWL (long value) {
        Console.WriteLine(value);
    }

    static void CWL (float value) {
        Console.WriteLine(value);
    }

    static void CWL (double value) {
        Console.WriteLine(value);
    }

    static int TOI (string str) {
        return int.Parse(str);
    }

    static long TOL (string str) {
        return long.Parse(str);
    }

    static float TOF (string str) {
        return float.Parse(str);
    }

    static double TOD (string str) {
        return double.Parse(str);
    }

    /*static void Main (string[] args) {
        var input = INP();
        var input2 = INP();
        var input3 = INP();

        CWL("dummy");
    }*/
}


Measured memory_bytes: 27548
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        int[] h = new int[N];
        
        for(int i = 0; i < N; i++){
            h[i] = sc.nextInt();
        }
        
        Arrays.sort(h);
        
        int hmin = Integer.MAX_VALUE;
        for(int i = 0; i < N-K+1; i++){
            int min = h[i];
            int max = h[ i + (K-1) ];
            hmin = Math.min(hmin, max - min);
        }
        
        System.out.println( hmin );
    }
}


Measured memory_bytes: 50252
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;
//typedef tuple<ll, ll, ll> T;

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

void add(ll& a, ll b){a = (a+b) % MOD;}

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

int gcd(ll x, ll y){
  return y ? gcd(y, x%y) : x;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin>>N;
    vector<ll> A(N);
    REP(i,N) cin>>A[i];
    vector<int> right(N+1),left(N+1);
    for(int i=0;i<N;i++) left[i+1] = gcd(left[i],A[i]);
    for(int i=N-1;i>=0;--i) right[i] = gcd(right[i+1],A[i]);
    int res=0;
    for(int i=0;i<N;i++){
        int l = left[i];
        int r = right[i+1];

        chmax(res,gcd(l,r));
    }
    cout<<res<<endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
string s[60];
int cnt[60][150],n;
int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>s[i];
		for(int j=0;s[i][j];j++)
			cnt[i][s[i][j]]++;
	}
	for(int i=0;i<150;i++){
		int mn=10000000;
		for(int j=0;j<n;j++)
			mn=min(mn,cnt[j][i]);
		for(int j=0;j<mn;j++)
			cout<<char(i);
	}
	return 0;
}

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

const int MAXN = 100005;
const int MOD = 1000000007;

long long modpow(long long x, int p){
    if(p == 0)return 1;
    if(p % 2 == 1)return (x * modpow(x, p - 1)) % MOD;

    long long r = modpow(x, p / 2);
    return (r * r) % MOD;
}
long long modinv(long long x){
    return modpow(x, MOD - 2);
}

long long fact[2 * MAXN], invfact[2 * MAXN];
long long c(int n, int r){
    return (((fact[n] * invfact[r]) % MOD) * invfact[n - r]) % MOD;
}

int N;
long long A, B, C;
int main(){
    scanf("%d %lld %lld %lld", &N, &A, &B, &C);

    for(int i = 0; i <= 2 * N; i++){
        if(i == 0)fact[i] = 1;
        else fact[i] = (fact[i - 1] * i) % MOD;

        invfact[i] = modinv(fact[i]);
    }
    A = (A * modinv(100)) % MOD;
    B = (B * modinv(100)) % MOD;

    C = (100 * modinv(100 - C)) % MOD;
    A = (A * C) % MOD;
    B = (B * C) % MOD;

    long long p = 0;

    long long rp = 1;
    for(int i = 0; i < N; i++)
        rp = (rp * A) % MOD;

    for(int i = 0; i < N; i++){
        p = (p + ((c(N + i - 1, i) * rp) % MOD) * (N + i)) % MOD;
        rp = (rp * B) % MOD;
    }

    rp = 1;
    for(int i = 0; i < N; i++)
        rp = (rp * B) % MOD;

    for(int i = 0; i < N; i++){
        p = (p + ((c(N + i - 1, i) * rp) % MOD) * (N + i)) % MOD;
        rp = (rp * A) % MOD;
    }
    printf("%lld\n", (p * C) % MOD);

    return 0;
}


Measured memory_bytes: 3328
n = int(input())
a = list()
b = [int(i) for i in input().split()]
flag = True
find = False
while b != []:
    for i in reversed(range(0,len(b))):
        if b[i] == (i+1):
            del b[i]
            a.append(i+1)
            find = True
            break
    if find == True:
        find = False
        continue
    else:
        flag = False
        break
if flag == False:
    print(-1)
else:
    for i in reversed(range(0,n)):
        print(a[i])

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(ll i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll n;
  cin >> n;
  vector<P> a, b;
  rep(_, n) {
    string s;
    cin >> s;
    ll l = 0, r = 0, cnt = 0;
    rep(i, s.size()) {
      if(s[i] == ')')
        cnt++;
      else
        cnt--;
      l = max(l, cnt);
    }
    reverse(all(s));
    cnt = 0;
    rep(i, s.size()) {
      if(s[i] == '(')
        cnt++;
      else
        cnt--;
      r = max(r, cnt);
    }
    if(r - l >= 0)
      a.push_back({l, r});
    else
      b.push_back({r, l});
  }
  sort(all(a));
  sort(all(b), greater<P>());
  ll now = 0;
  bool ans = true;
  for(auto v : a) {
    ll l = v.first;
    ll r = v.second;
    if(now < l) ans = false;
    now += r - l;
  }
  for(auto v : b) {
    ll l = v.second;
    ll r = v.first;
    if(now < l) ans = false;
    now += r - l;
  }
  if(now != 0) ans = false;
  cout << (ans ? "Yes" : "No") << endl;
}

Measured memory_bytes: 19052
n = int(input())
a = list(map(int, input().split()))
ans = 1

for i in range(n):
    if a[i] == 0:
        print("0")
        exit()

for i in range(n):
    ans *= a[i]
    if ans > 10**18:
        print("-1")
        exit()

print(str(ans))


Measured memory_bytes: 21652
n=int(input())
a=[int(x) for x in input().split()]
m=10**9+7
s=0
for c in range(n):
    s=(s+a[c])%m
s=pow(s,2,m)
for c in range(n):
    s=(s-pow(a[c],2,m))%m
if s%2==0:
    print(s//2)
else:
    print((s+m)//2)

Measured memory_bytes: 31624
S = list(input())
N = len(S)
K = int(input())
T = S.copy()
S += T
ans = 0
cnt = 0

if N == 1:
    print(K//2)
    exit()

from collections import defaultdict

f = defaultdict(int)
for t in T:
    f[t]+=1
if len(f) == 1:
    print(N*K//2)
    exit()

for i in range(1, N):
    if S[i - 1] == S[i]:
        cnt += 1
        S[i] = "-1"
ans += cnt
if T[0] == T[-1] and S[N - 1] != "-1":
    cnt2 = 0
    for i in range(N):
        if T[i] == T[i - 1]:
            cnt2 += 1
            T[i] = "-1"
    ans += cnt2 * (K - 1)
else:
    ans += cnt * (K - 1)
print(ans)


Measured memory_bytes: 3316
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <iomanip>

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

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;

using namespace std;

#ifdef INPUT
#include <sstream>
stringstream input(R"(
2
)");
#define cin input
#endif

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

	cout << (n >= 1000 ? "ABD" : "ABC") << endl;

	return 0;
}


Measured memory_bytes: 764
#include <iostream>
using namespace std;
#define MAX 100000

int parent (int i) {
    return i/2;
}
int left (int i) {
    return 2*i;
}

int right (int i) {
    return 2 * i + 1;
}

int main (void) {
    int H,i,A[MAX+1];

    cin >> H;
    for (i = 1 ; i <=H ; i++) {
        cin >> A[i];
    }

    for (i = 1 ; i <=H ; i++) {
        cout << "node " << i << ": key = " << A[i] << ", ";
        if ( parent(i) >= 1) cout << "parent key = " << A[parent(i)] << ", ";
        if ( left(i) <= H ) cout << "left key = " << A[left(i)] << ", ";
        if ( right(i) <= H ) cout << "right key = " << A[right(i)] << ", ";
        cout << endl;
    }

    return 0;

}

Measured memory_bytes: 3128
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define INF INT_MAX
#define MOD 1000000007
#define fcout cout << fixed << setprecision(15)
typedef long long ll;
typedef pair<int, int> P;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a * b / gcd(a, b);};
int mod(int a,int b){return (a+b-1)/b;};
int month[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){std::fill( (T*)array, (T*)(array+N), val );};
template<class T>inline bool chmax(T& a,T b){if(a < b){a=b;return true;}return false;};
template<class T>inline bool chmin(T& a,T b){if(a > b){a=b;return true;}return false;};



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

  int n, k, q;
  cin >> n >> k >> q;
  int a[q];
  rep(i, q) {
    cin >> a[i];
    a[i]--;
  }
  int p[n] = {};
  rep(i, q) {
    p[a[i]]++;
  }
  //rep(i, n) cout << p[i] << " ";
  rep(i, n) {
    if(p[i] > q - k) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 1408
a = []
b = 0
c = 10
d = 0
e = []
for i in range(5):
    a.append(int(input()))
for i in range(5):
    d += a[i]
for i in range(5):
    b = 20
    c = 10
    while(b > 10 or b < 0):
        b = c - a[i]
        c += 10
    e.append(b)
e = sorted(e)
for i in range(4):
    d += e[i]
print(d)   



Measured memory_bytes: 3188
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<array>
#include<vector>
#include<functional>
#include<unordered_map>
#include<map>
#include<numeric>
#include<limits>
#include<utility>
#include<queue>
#include<random>
#include<math.h>
using namespace std;

int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	cout << max(a*b, c*d) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <ctype.h>
 
int main() {
 
  char ch[1200];
  int i,n;
  n=0;
  char a[1200];
 
  while(1) {
    scanf("%c",&a[n]);
    if(a[n] == '\n') {
      break;
    }
    ch[n] = a[n];
    if('A' <= a[n] && a[n] <= 'Z') {
      ch[n] = a[n] + 32;
    } else if(a[n] >= 'a' && a[n] <= 'z') {
      ch[n] = a[n] - 32;
 
    }
     
     
    n = n +1;
     
  }
   
  for(i=0; i<n ; i++) {
    printf("%c" ,ch[i]);
  }
  printf("\n"); 
  return 0;
}


Measured memory_bytes: 2104
/*
 * author: Tran Minh Khoa
 * Ho Chi Minh University of Science
 */

#include <bits/stdc++.h>

using namespace std;

const int inf = 1 << 31;
const long long INF = 1LL << 61;

const int MOD = 1000000007;
const int N = 123456;
const int M = 1010;

#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define sz(a) (int) a.size()
#define all(a) a.begin(), a.end()
#define sqr(x) (x) * (x)

#define REP(i, a, b) for (int i = (a); i < (b); i++)
#define REPN(i, a, b) for (int i = (a); i <= (b); i++)
#define DEBUG(x) cerr << #x << " = " << x << '\n';
#define PR(x, a, b) { cerr << #x << " = "; REP(i, a, b) cerr << x[i] << ' '; cerr << '\n'; }
                 
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr); cout.tie(nullptr);
  cout.precision(10); 
  cout << fixed;
#ifdef KM777
  freopen("in", "r", stdin);
#endif
  
  int n;
  cin >> n;
  vector<int> a(2 * n + 1);
  for (int i = 1; i <= 2 * n; i++) {
    cin >> a[i];
  }
  sort(a.begin() + 1, a.end());
  long long result = 0;
  for (int i = 1; i <= 2 * n; i += 2) {
    result += a[i];
  }
  cout << result << '\n';
  
#ifdef KM777
  cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,a,b) for(int i=(a),_end_=(b);i<=_end_;i++)
#define DREP(i,a,b) for(int i=(a),_end_=(b);i>=_end_;i--)
#define EREP(i,u) for(int i=start[u];i;i=e[i].next)
#define fi first
#define se second
#define mkr(a,b) make_pair(a,b)
#define SZ(A) ((int)A.size())
template<class T>inline void chkmax(T &a,T b){ if(a<b)a=b;}
template<class T>inline void chkmin(T &a,T b){ if(a>b)a=b;}
inline int read()
{
    int s=0,f=1; char ch=getchar();
    while(!isdigit(ch) && ch!='-')ch=getchar();
    if(ch=='-')ch=getchar(),f=-1;
    while(isdigit(ch))s=s*10+ch-'0',ch=getchar();
    return ~f?s:-s;
}

const int mod=1e9+7;

inline int power (int a,int b)
{
    int ans=1;
    while(b)
    {
	if(b&1)ans=(ll)ans*a%mod;
	b>>=1;
	a=(ll)a*a%mod;
    }
    return ans;
}

const int maxn=1<<20;

int n,p[maxn],L;
int f[maxn],g[maxn];

struct node {
    int s,ls,rs;
};
node c[maxn*40];
int ctot;

int rt[maxn];

void update(int x,int d,int &o,int l,int r)
{
    if(!o)o=++ctot;
    c[o].s=(c[o].s+d)%mod;
    if(l==r)return;
    int mid=l+r>>1;
    if(x<=mid)update(x,d,c[o].ls,l,mid);
    else update(x,d,c[o].rs,mid+1,r);
}

int Merge(int x,int y)
{
    if(!x || !y)return x|y;
    int tmp=++ctot;
    c[tmp].s=(c[x].s+c[y].s)%mod;
    c[tmp].ls=Merge(c[x].ls,c[y].ls);
    c[tmp].rs=Merge(c[x].rs,c[y].rs);
    return tmp;
}

int query(int ql,int qr,int o,int l,int r)
{
    if(!o)return 0;
    if(ql<=l && r<=qr)return c[o].s;
    int mid=l+r>>1,ans=0;
    if(ql<=mid)ans=(ans+query(ql,qr,c[o].ls,l,mid))%mod;
    if(qr>mid)ans=(ans+query(ql,qr,c[o].rs,mid+1,r))%mod;
    return ans;
}

inline void init()
{
    n=read(); L=1<<n-1;
    REP(i,1,L)p[i]=read();
    f[0]=1;f[1]=1; REP(i,2,(1<<n)-1)f[i]=(ll)f[i>>1]*i%mod;
    REP(i,1,(1<<n)-1)g[i]=power((ll)f[i]*f[i>>1]%mod,mod-2)%mod;
}

inline void doing()
{
    REP(i,L,2*L-1)update(p[i-L+1],(ll)f[i]*f[p[i-L+1]+L-1]%mod,rt[i],1,L);
    DREP(i,L-1,1)rt[i]=Merge(rt[2*i],rt[2*i+1]);
    int ans=0;
    REP(x,L,2*L-1)
    {
	int y=p[x-L+1]+L-1;
	REP(lca1,1,n-1)REP(lca2,1,n-1)
	{
	    int tx=x>>lca1-1,ty=y>>lca2-1;
	    tx^=1; ty^=1;
	    ans=(ans+(ll)query((ty<<lca2-1)-L+1,(ty+1<<lca2-1)-L,rt[tx],1,L)*f[x]%mod*f[y]%mod*g[x>>lca1]%mod*g[y>>lca2])%mod;
	}
    }
    ans=(ll)ans*(mod+1>>1)%mod;
    printf("%d\n",ans);
}

int main()
{
    init();
    doing();
    return 0;
}


Measured memory_bytes: 59512
#include<bits/stdc++.h>
using namespace std;
#define pi acos(-1)
#define ll long long int
#define sci(x) sca nf("%d",&x);
#define scd(x) scanf("%lf",&x);
#define pb(x) push_back(x)
#define FasterIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define mkp(x,y) make_pair(x,y)
#define pii pair<int , int>
#define SEIVE seive(){ prime[1]=1; for(ll i=2; i*i<=1000000; i++) { if(prime[i]) continue; for(ll j=i*i; j<=1000000; j+=i) prime[j]=1; } }
bool prime[1000006];
vector<int>vec[20000],root;
int vis[20002];


int main()
{
    int n;
    cin>>n;
    int a[n+3];
    int sum=0;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        sum^=a[i];
    }
    for(int i=1;i<=n;i++)
    {
        cout<<(sum^a[i])<<" ";
    }
    cout<<endl;

}

Measured memory_bytes: 4780
#include <algorithm>
#include <array>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define REP(X, Y, Z) for (ll(X) = (Y); (X) < (Z); (X)++)
#define REV(X, Y, Z) for (ll(X) = (Y); (X) > (Z); (X)--)

using namespace std;
using ll = long long;
using dll = deque<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using usll = unordered_set<ll>;
using umll = unordered_map<ll, ll>;
using sll = stack<int>;
using vll = vector<ll>;
using vvll = vector<vll>;

constexpr ll kMod = 1e9 + 7;

ll gcd(ll a, ll b) {
  if (a < b) {
    return gcd(b, a);
  }
  ll c = a % b;
  while (c != 0) {
    a = b;
    b = c;
    c = a % b;
  }
  return b;
}

ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

void init() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

int main() {
  init();

  ll N, L;
  cin >> N >> L;
  vector<string> S(N);
  REP(i, 0, N) {
    string s;
    cin >> s;
    S[i] = s;
  }
  sort(S.begin(), S.end());
  REP(i, 0, N) {
    cout << S[i];
  }
  cout << endl;

  return 0;
}


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

#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define rep2(i, m, n) for(int i = (int)m; i < (int)n; i++)
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii; //2次元配列
typedef vector<ll> vll;
typedef vector<string> vs;


/*FUNCs=================================================*/



/*MAIN==================================================*/
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化

    ll a,b,x; cin>>a>>b>>x;
    ll ans = (b / x) - (a / x);
    if(a%x == 0) ans++;
    cout << ans << endl;
}


Measured memory_bytes: 256
def min2(x,y):
    return x if x < y else y

from itertools import combinations
MOD = 2019
L, R = map(int, input().split())
data = [L%MOD]
for i in range(L+1, R+1):
    if data[0] ==i%MOD:
        break
    data.append(i%MOD)
res = float("inf")
for x, y in combinations(data, 2):
    res = min2((x*y)%MOD,res)
print(res)

Measured memory_bytes: 73660
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define ld long double
#define INF 1000000000000000000
typedef pair<ll, ll> pll;

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

    int N;
    cin >> N;
    string s;
    cin >> s;

    char dx[4] = {'S', 'W', 'S', 'W'};
    char dy[4] = {'S', 'W', 'W', 'S'};

    rep(i, 4) {
        vector<char> ans;
        ans.push_back(dx[i]);
        ans.push_back(dy[i]);

        for (int i = 1; i < N - 1; i++) {
            if ((s[i] == 'o' && ans[i] == 'S') ||
                (s[i] == 'x' && ans[i] == 'W')) {
                if (ans[i - 1] == 'S')
                    ans.push_back('S');
                else
                    ans.push_back('W');
            } else if ((s[i] == 'x' && ans[i] == 'S') ||
                       (s[i] == 'o' && ans[i] == 'W')) {
                if (ans[i - 1] == 'S')
                    ans.push_back('W');
                else
                    ans.push_back('S');
            }
        }

        bool judge = 1;

        int check[2] = {N - 1, 0};

        rep(j, 2) {
            int tar = check[j];
            int prev = (j == 1) ? N - 1 : tar - 1;
            int next = (j == 0) ? 0 : tar + 1;
            if ((s[tar] == 'o' && ans[tar] == 'S') ||
                (s[tar] == 'x' && ans[tar] == 'W')) {
                if (ans[prev] != ans[next])
                    judge = 0;

            } else if ((s[tar] == 'x' && ans[tar] == 'S') ||
                       (s[tar] == 'o' && ans[tar] == 'W')) {
                if (ans[prev] == ans[next])
                    judge = 0;
            }
        }

        if (judge) {
            rep(k, N) { cout << ans[k]; }
            cout << endl;
            return 0;
        }
    }

    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 3756
using System;

class Project
{
    static void Main(string[] args)
    {
        string[] input = Console.ReadLine().Split(' ');
        int X = int.Parse(input[0]); 
        int Y = int.Parse(input[1]);
        
        if(Y%2 == 0 && Y >= X * 2 && Y <= X * 4)
        {
            Console.WriteLine("Yes");
        }
        else
        {
            Console.WriteLine("No");
        }
    }
}

Measured memory_bytes: 27540
import Control.Applicative ((<$>), (<*>))
import Control.Monad
import Data.List
import Test.HUnit

main :: IO ()
-- main = runTestTT (TestList tests) >> return ()
main = do
  xs <- getl $ split toInt
  when (sum xs /= 0) $ do
    print $ solve xs
    main

solve :: [Int] -> Int
solve [a1,m1,a2,m2,a3,m3] = lcm (lcm c1 c2) c3
  where
    c1 = rtnCnt 0 1 1 (move a1 m1)
    c2 = rtnCnt 0 1 1 (move a2 m2)
    c3 = rtnCnt 0 1 1 (move a3 m3)
    
move a m p = a * p `mod` m

rtnCnt :: Int -> Int -> Int -> (Int -> Int) -> Int
rtnCnt cnt from to f
  | nxt == to = cnt + 1
  | otherwise = rtnCnt (cnt + 1) nxt to f
  where
    nxt = f from
    
toInt :: String -> Int
toInt s = read s

split :: (String -> a) -> String -> [a]
split f = map f . words

getl :: (String -> a) -> IO a
getl f = f <$> getLine

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

int main()
{
	long long A, B, K;	cin >> A >> B >> K;
	long long A_ans, B_ans;

	if (K <= A) {
		A_ans = A - K;
		B_ans = B;
	}
	else if (A < K && K < A + B) {
		A_ans = 0;
		B_ans = A + B - K;
	}
	else { // A+ B < K
		A_ans = 0;
		B_ans = 0;
	}

	cout << A_ans << " " << B_ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
 
#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define between(a,x,b) ((a)<=(x)&&(x)<=(b))
#define INF 1 << 30
 
using namespace std;
 
int main(){
  int e;
  while(scanf("%d", &e) && e){
    int res = INF;
    for(int i = 0; i * i * i <= e; i++){
      int z = i;
      int y = sqrt(e-z*z*z);
      int x = e-(y*y+z*z*z);
      res = min(res, z + y + x);
    }
 
    printf("%d\n", res);
  }
  return 0;
}


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

#include <math.h>
#define PI 3.14159265358979323846264338327950L

bool isPrime(long long x) {
    if (x == 1) return true;
    for (long long i = 2; i*i <= x; i++) {
        if (x % i == 0) return false;
    }
    return true;
}

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

vector<long long> common_divisors(long long a, long long b) {
    long long n = gcd(a, b);
    vector<long long> ans;
    for (long long i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            if (n / i == i) {
                ans.push_back(i);
            }
            else {
                ans.push_back(n / i);
                ans.push_back(i);
            }
        }
    }
    return ans;
}
vector<int> get_divisors(long long n) {
    vector<int> ans;
    for (long long i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            if (i == n / i) {
                ans.push_back(i);
            }
            else {
                ans.push_back(n / i);
                ans.push_back(i);
            }
        }
    }
    sort(ans.rbegin(), ans.rend());
    return ans;
}

bool is_sorted(vector<int> a) {
    int n = a.size();
    for (int i = 0; i < n - 1; i++) {
        if (a[i + 1] < a[i]) return false;
    }
    return true;
}

const int N = 2000, M = 2000;
int dp[N+1][M+1];

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    vector<int> b(m);
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < m; i++) cin >> b[i];

    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= m; j++) {
            if (i == 0 && j == 0) {
                dp[i][j] = 1;
            }
            else {
                long long x = 0;
                if (i > 0) {
                    x += dp[i - 1][j]; x %= MOD;
                }
                if (j > 0) {
                    x += dp[i][j - 1]; x %= MOD;
                }
                if (i > 0 && j > 0 && a[i-1] != b[j-1]) {
                    x = (x - dp[i - 1][j - 1]) % MOD;
                }
                dp[i][j] = x;
            }
        }
    }
    int ans = dp[n][m];
    if (ans < 0)
        ans += MOD;
    cout << ans << '\n';
    return 0;
}

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

using namespace std;
typedef long long ll;

int main()
{
  ll N;
  cin>>N;
  ll L[N];
  ll T=0;
  ll Max=0;
  
  for(ll i=0;i<N;i++){
    cin>>L[i];
  }
  for(ll i=0;i<N;i++){
    T+=L[i];
    if(Max<=L[i]){
      Max=L[i];
    }
  }
  T-=Max;
  
  if(Max<T){
    cout<<"Yes"<<endl;
  }
  else{
  	cout<<"No"<<endl;
  }
  
  return 0;

}

Measured memory_bytes: 256
//hi
#include<bits/stdc++.h>
using namespace std;
#define PB push_back
#define MP make_pair
#define F first
#define S second
typedef long long int LL;
string s,t;
int main(void){
    int n;
    scanf("%d",&n);
    int i,j;
    cin>>s;
    cin>>t;
    int ans=2*n;
    for(i=0;i<n;i++){
		for(j=i;j<n;j++)
			if(s[j]!=t[j-i]) break;
		//printf("%d %d\n",i,j);
		if(j==n) ans=min(ans,n+i);
	}
	printf("%d\n",ans);
    return 0;
}


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

#define INF 1000010000
#define nl '\n'
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define fi first
#define se second
#define pii pair<int,int>
#define pdd pair<double,double>
#define all(c) (c).begin(), (c).end()
#define SORT(c) sort(all(c))
#define sz(c) (c).size()
#define rep(i,n) for( int i = 0; i < n; ++i )
#define repi(i,n) for( int i = 1 ; i <= n; ++i )
#define repn(i,n) for( int i = n - 1 ; i >= 0 ; --i )
#define repf(j,i,n) for( int j = i ; j < n ; ++j )
#define die(s) {std::cout << s << nl;}
#define dier(s) {std::cout << s; return 0;}
#define vi vector<int>
typedef long long ll;
#define MAXN 2020
using namespace std;


int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.precision(0); 

	int n;
	cin >> n;
	
	int sum = 0;
	bitset<MAXN * MAXN> dp(1);
	rep(i , n){
		int e;
		cin >> e;
		dp |= dp << e;
		sum += e;
	}
	
	repf(i , sum / 2 + sum % 2 , MAXN * MAXN){
		if(dp[i]){
			dier(i);
		}
	}

	return 0;
}

Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
#define N 150
#define K 100500
typedef long long ll;
int n,k,a[N];
const ll m = 1e9 + 7;
ll ps[N][K],dp[N][K];

ll add(ll a , ll b) {
    return ((a % m) + (b % m)) % m;
}

ll rsum(int curr , int l , int r) {
    if (l == 0) return ps[curr][r] % m;
    return (((ps[curr][r] % m) - (ps[curr][l - 1] % m)) + 2 * m) % m;
}

void precompute() {
    for (int curr = 0 ; curr <= n ; curr++) {
        for (int sum = 0 ; sum <= k ; sum++) {
            if (curr == 0) {
                dp[curr][sum] = sum == 0 ? 1 : 0;
                ps[curr][sum] = sum == 0 ? dp[curr][sum] : add(ps[curr][sum - 1] , dp[curr][sum]);
            } else {
                dp[curr][sum] = rsum(curr - 1 , max(0 , sum - a[curr]) , sum);
                ps[curr][sum] = sum == 0 ? dp[curr][sum] : add(ps[curr][sum - 1] , dp[curr][sum]);
            }
        }
    }
}

int main() {
    scanf("%d%d" , &n , &k);
    for (int i = 1 ; i <= n ; i++)
        scanf("%d" , &a[i]);
    precompute();
    printf("%lld\n" , dp[n][k]);
}


Measured memory_bytes: 162048
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
const ll MOD=1e9+7;
const long long INF = 1LL<<60;

int main() {
    int n,x,y;
    cin >> n >> x >> y;

    // 隣接関係を表すグラフ
    using Graph = vector<vector<int>>;
    Graph G(n);
    for(int i = 0;i<n-1;i++){
        G[i+1].push_back(i);
        G[i].push_back(i+1);
    }
    G[x-1].push_back(y-1);
    G[y-1].push_back(x-1);

    vector<vector<int>> distance_pair(n,vector<int>(n,-1));

    // 各点ごとにBFSをして各点から各点への距離を計算する
    for(int i = 0;i<n;i++){
        // BFSを行うために必要な道具
        vector<int> dist(n,-1);
        queue<int> que;

        // 初期状態(iから辿った距離を計算するので、iを初期点とする)
        dist[i]=0;
        que.push(i);

        // BFS
        while(!que.empty()){
            int v = que.front();
            que.pop();

            for(int nv:G[v]){
                if(dist[nv]!=-1) continue; // 発見済みの頂点は探索しない

                // 新規発見した頂点nvに関しては距離情報を更新後キューに追加する
                dist[nv] = dist[v]+1;
                que.push(nv);
            }
        }

        for(int v=0;v<n;++v){
            distance_pair.at(i).at(v)=dist[v];
        }
    }

    map<int,int> answers_double;
    for(int k = 1;k<n;k++){
        answers_double[k]=0;
    }
    for(int i = 0;i<n;i++){
        for(int j = 0;j<n;j++){
            answers_double[distance_pair.at(i).at(j)]++;
        }
    }

    for(int k = 1;k<=n-1;k++){
        cout << answers_double[k]/2 << endl;
    }
}

Measured memory_bytes: 17536
#include<iostream>
using namespace std;
int main () {
  int mi[5];
  for (int i = 0; i < 5; i ++) cin >> mi[i];
  int ans = 700;
  for (int i = 0; i < 5; i ++) {
    int k = 0;
    for (int j = 0; j < 5; j ++) {
      if (j == i) k += mi[j];
      else {
        int a = 0;
        while(a < mi[j]) a += 10;
        k += a;
      }
    }
    if (ans > k) ans = k;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import sys

read = sys.stdin.buffer.read


N, *A = map(int, read().split())

ans = 0
right = 0
s = 0

for left in range(N):
    while right < N and s & A[right] == 0:
        s ^= A[right]
        right += 1

    ans += right - left

    if left == right:
        right += 1
    else:
        s ^= A[left]

print(ans)



Measured memory_bytes: 27808
program sample
    implicit none
    character(100000)::s,t
    integer(8) :: i,j,k,m,n
    integer(8)::a,b,c,d
    integer(8),allocatable::x(:),y(:)
  
   
    read(*,*)s
    n=len_trim(s)
   
    a=0
    b=0
    do i=1,n
        if(s(i:i).eq.'0')then
            a=a+1
        else
            b=b+1
        end if
    end do
    c=min(a,b)
    write(*,*)2*c
    stop
end program sample
  



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

using namespace std;


int main() {
    string w;
    cin >> w;
    vector<int> v(26,0);
    for(int i = 0; i < w.size(); i++) {
        v[w[i] - 'a']++;
    }
    bool ok = true;
    for(int i = 0; i < 26; i++) {
        if(v[i] % 2 != 0) {
            ok = false;
        }
    }
    if(ok) {
        puts("Yes");
    } else {
        puts("No");
    }
    return 0;
}

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

int main() {
    string S;
    cin >> S;
    int N = S.size();

    bool ok1, ok2, ok3;
    string T = S;
    reverse(T.begin(), T.end());
    ok1 = S == T;
    string U = S.substr(0, N / 2);
    string V = U;
    reverse(V.begin(), V.end());
    ok2 = U == V;
    /* string W = S.substr((N + 1) / 2, U.size());
    string X = W;
    reverse(X.begin(), X.end());
    if (W == X) {
        ok3 = true;
    } */

    if (ok1 && ok2) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
def input(): return sys.stdin.readline().rstrip()

def main():
    S=list(map(int,list(input())))
    K=int(input())
    for n in S:
        if n==1:
            K-=1
            if K==0:
                print(1)
                exit()
        else:
            print(n)
            exit()

if __name__ == '__main__':
    main()


Measured memory_bytes: 38512
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
using ll=long long;
static const ll mod = 1e9 + 7;
static const ll INF = 1LL << 50;
using namespace std;

template<typename T>
vector<T>divisor(T n){//約数列挙
    vector<T>v;
    for(T i=1;i*i<=n;++i){
        if(n%i==0){
            v.push_back(i);
        if(i*i!=n)v.push_back(n/i);
        }
    }
    sort(v.begin(),v.end());
    return v;
}
int main(){
    ll n,m;
    cin>>n>>m;
    auto ans=divisor<ll>(m);
    ll maxv=1;
    for(auto x:ans){
        ll cmp=m;
        cmp/=x;
        if(cmp<=1e9*n&&cmp>=n)maxv=max(x,maxv);
    }
    cout<<maxv<<endl;
    return 0;
    }


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

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define chmax(a,b) (a<(b)?(a=b,1):0)
#define chmin(a,b) (a>(b)?(a=b,1):0)
#define valid(y,x,h,w) (0<=y&&y<h&&0<=x&&x<w)
typedef long long ll;
typedef pair<int,int> pii;
const int INF = 1<<29;
const double PI = acos(-1);
const double EPS = 1e-8;

// appeal[i][j] = i回アピールしたとき，特定の要素をj回アピールする確率
// appeal[i+1][j+1] = appeal[i][j]*(1/3) + appeal[i][j+1]*(2/3)
// appeal2[j] = m回アピールしたとき，特定の要素をj回以上アピールする確率
// win[i][j][k] = アイドル1が要素iをj回アピールしたときアイドルkが勝利する確率
// dp[i][j][k][l] = k人のアイドルのうち，アイドル1が要素iをj回アピールしたとき勝利するアイドルがl人いる確率
// dp[i][j][k][l] = dp[i][j][k-1][l-1] * win[i][j][k] + dp[i][j][k-1][l] * (1-win[i][j][k])
// dp2[i][j][k] = k人のアイドルのうち，アイドル1が要素iをj回アピールしたとき全員勝利する確率
double appeal[2][2002];
double appeal2[2002];
double win[3][2002][2002];
double dp[3][2002][2][4];
double dp2[3][2002][2];

int idol1[3];
int value[2000][3];

int main() {
  int n,m;
  while(cin >> n >> m) {
    REP(i,3) cin >> idol1[i];
    n--;
    REP(i,n) {
      REP(j,3) cin >> value[i][j];
    }
    memset(appeal,0,sizeof(appeal));
    appeal[0][0] = 1;
    REP(i,m) {
      appeal[i+1&1][0] = appeal[i&1][0]*2/3;
      REP(j,i+1) {
        appeal[i+1&1][j+1] = appeal[i&1][j]/3 + appeal[i&1][j+1]*2/3;
      }
    }
    appeal2[m+1] = 0;
    for (int i=m; i>=0; --i) {
      appeal2[i] = appeal2[i+1] + appeal[m&1][i];
    }
    assert(abs(appeal2[0]-1)<EPS);
    REP(i,3) {
      REP(j,m+1) {
        int val = idol1[i] * j;
        REP(k,n) {
          int lower = (val+value[k][i]-1)/value[k][i];
          win[i][j][k] = lower<=m ? appeal2[lower] : 0.0;
        }
      }
    }
    memset(dp,0,sizeof(dp));
    REP(i,3) {
      REP(j,m+1) {
        dp2[i][j][0] = 1;
        dp[i][j][0][0] = 1;
        REP(k,n) {
          dp[i][j][k+1&1][0] = dp[i][j][k&1][0] * (1 - win[i][j][k]);
          REP(l,3) {
            dp[i][j][k+1&1][l+1] = dp[i][j][k&1][l] * win[i][j][k] + dp[i][j][k&1][l+1] * (1 - win[i][j][k]);
          }
          dp[i][j][k+1&1][3] += dp[i][j][k&1][3] * win[i][j][k];
          dp2[i][j][k+1&1] = dp2[i][j][k&1] * win[i][j][k];
        }
      }
    }
    double ans = -INF;
    REP(i,m+1) {
      REP(j,m-i+1) {
        int k = m-i-j;
        double p = 0;
        p += (1-dp[0][i][n&1][3]) * 5;
        p += (1-dp[1][j][n&1][3]) * 3;
        p += (1-dp[2][k][n&1][3]) * 2;
        // printf("%d %d %d %.10f  : %.5f, %.5f\n", i,j,k,p, dp[1][j][n&1][3], dp[2][k][n&1][3]);
        p -= dp2[0][i][n&1];
        p -= dp2[1][j][n&1];
        p -= dp2[2][k][n&1];
        // printf("%d %d %d %.10f\n", i,j,k,p);
        chmax(ans, p);
      }
    }
    printf("%.12f\n", ans);
  }
}

Measured memory_bytes: 95640