akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define mp make_pair
#define F first
#define S second
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define INF 0x3f3f3f3f
typedef long long ll;
/*while(l<=r)
{
    ll mid=(l+r)/2;
    if(check(mid)) r=mid-1;
    else l=mid+1;
}*/
ll n,k,q;
ll co[1000005];
int main()
{
    while(cin>>n>>k>>q)
    {
        rep1(i,n) co[i]=k-q;
        rep(i,q)
        {
            ll tmp;
            cin>>tmp;
            co[tmp]+=1;
        }
        rep1(i,n)
        {
            //cout<<co[i]<<"\n";
            if(co[i]>0) cout<<"Yes\n";
            else cout<<"No\n";
        }
    }

    return 0;
}


Measured memory_bytes: 1408
fun main(args: Array<String>) {
    val x = readIntList()
    println(x.indexOfFirst { it == 0 }+1)
}

// Tools
fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)

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


bool vis[1000010];

int main(){
    int s;cin>>s;
    int m = 1,x = s;
    while(true){
        assert(x < 1000010);
        vis[x] = true;
        if(x&1) x = 3*x + 1;
        else x >>= 1;
        m += 1;
        if(vis[x]) break;
    }
    cout<<m<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const ll MOD = 1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b, const ll mod=MOD) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b, const ll mod=MOD) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b, const ll mod=MOD) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b, const ll mod=MOD) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    string in; cin >> in;
    int n = in.size();

    bool ok = true;

    ok &= (in[0] == 'A');

    int cnt = 0;
    rep(i, 1, n){
        char c = in[i];
        if(isupper(c)){
            if(i == 1 or i == n-1 or c != 'C'){
                ok = false;
            }
            cnt++;
        }
    }
    ok &= (cnt == 1);

    cout << (ok ? "AC":"WA") << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<bits/stdc++.h>
#include<string>
using namespace std;
int main()
{
  vector<char> a(1100) ;
  
  for(int i=0;i<=100;i++){
   cin >> a.at(i) ;
  }
  
  bool cond2 = 1 ;
  for(int i=0;i<1100;i++){
   if(i%2==0){
   if(a.at(i)=='L'){
     cond2 = 0 ;
     break ;
   }
   }else if(i%2!=0){
     if(a.at(i)=='R'){
     cond2 = 0 ;
     break ;
   }
   }
  }//for(i)
  
  if(cond2)
    cout << "Yes" << endl ;
  else
    cout << "No" << endl ;
    
    return 0 ;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define mod 1000000007
#define f(i,a,b) for(ll i=a;i<b;i++)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ii pair<ll,ll>
#define vii vector<ii>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define MAX 1e9
 
ll modpow(ll base, ll exp, ll modulus) {base %= modulus;ll result = 1;while (exp > 0) {if (exp & 1) result = (result * base) % modulus;base = (base * base) % modulus;exp >>= 1;}return result;}
const ld pi=acos(-1);

int main(){
    IOS;
    ll a[3][3];
    f(i,0,3){
        f(j,0,3)cin>>a[i][j];
    }
    ll n;cin>>n;
    map<ll,ll>m;
    f(i,0,n){
        ll x;cin>>x;m[x]=1;
    }
    f(i,0,3){
        f(j,0,3)if(m[a[i][j]])a[i][j]=0;
    }
    bool ok=0;ll cnt=0;
    f(i,0,3)if(!a[i][0])cnt++;
    if(cnt==3)ok=1;cnt=0;
    f(i,0,3)if(!a[i][1])cnt++;
    if(cnt==3)ok=1;cnt=0;
    f(i,0,3)if(!a[i][2])cnt++;
    if(cnt==3)ok=1;cnt=0;
    
    f(j,0,3)if(!a[0][j])cnt++;
    if(cnt==3)ok=1;cnt=0;
    f(j,0,3)if(!a[1][j])cnt++;
    if(cnt==3)ok=1;cnt=0;
    f(j,0,3)if(!a[2][j])cnt++;
    if(cnt==3)ok=1;cnt=0;
    
    f(i,0,3)if(!a[i][i])cnt++;
    if(cnt==3)ok=1;cnt=0;
    
    if(!a[0][2] && !a[1][1] && !a[2][0])ok=1;
    if(ok)cout<<"Yes";
    else cout<<"No";
    return 0;  
} 





Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int X,a;
    cin>>X;
    a=X%7;
    if(a==0) cout<<"thu";
    if(a==1) cout<<"fri";
    if(a==2) cout<<"sat";
    if(a==3) cout<<"sun";
    if(a==4) cout<<"mon";
    if(a==5) cout<<"tue";
    if(a==6) cout<<"wed";
    cout<<endl;
}



Measured memory_bytes: 3116
#include <iostream>
#define INT_MAX 2147483647

int main(void){
  int n;
  std::cin >> n;
  int val[n];

  int min=INT_MAX;
  int max=0;
  int profit=-INT_MAX;

  for(int i=0; i<n; i++){
      std::cin >> val[i];
      if (val[i] < min){ //底値割
        if(i>0 && profit < val[i]-min){
          profit = val[i]-min;
        }
        min = val[i];
      }else if (profit < val[i]-min){
        profit = val[i]-min;
      }
  }
  std::cout << profit << '\n';
  return 0;
}



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

#define rep(i,N) for(int i=0;i<(int)(N);++i)
#define rrep(i,N) for(int i=(int)(N)-1;i>=0;--i)
#define debug(x) cout<<#x<<"="<<x<<endl;
constexpr ll MOD=1000000007;
constexpr ll INF=1LL<<60;
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<typename T> void fail(T v){cout << v << endl;exit(0);}
//template end

void solve(){
    int N,P;
    while(1){
        cin>>N>>P;
        if(!(N|P))break;
        int idx=0,now=P;
        vector<int> A(N);
        while(1)
        {
            if(now){
                A[idx]++;now--;
            }else{
                now+=A[idx];
                A[idx]=0;
            }
            if(A[idx]==P)break;
            idx++;
            if(idx==N)idx=0;
        }
        cout<<idx<<endl;
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    solve();
    return 0;
}


Measured memory_bytes: 3188
import statistics


def solve():
    N = int(input())
    A = list(map(int, input().split()))
    A_i = [A[i] - i - 1 for i in range(N)]
    b = statistics.median_high(A_i)
    print(sum(abs(a - b) for a in A_i))



if __name__ == "__main__":
    solve()

Measured memory_bytes: 33816
N, W = gets.chomp.split.map(&:to_i)

dp = [0] * (W+1)

1.upto(N) do |i|
  w_i, v_i = gets.chomp.split.map(&:to_i)

  W.downto(1) do |w|
    next if w_i > w

    dp[w] = dp[w-w_i] + v_i if dp[w] < dp[w-w_i] + v_i
  end
end

puts dp[W]

Measured memory_bytes: 14988
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<n;++i)
#define rep2(i,a,b) for (ll i=a;i<b;++i)
const ll MOD=1000000007;

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

vector<ll> divisor(ll n){
    vector<ll> res;
    for (ll i=1;i*i<=n;i++){
        if (n%i==0){
            res.push_back(i);
            if (i!=n/i){
                res.push_back(n/i);
            }
        }
    }
    return res;
}

int main(){
    ll N,K;
    cin >> N >> K;
    vector<ll> A(N);
    ll sum=0;
    rep(i,N){
        cin >> A[i];
        sum+=A[i];
    }
    vector<ll> can=divisor(sum);
    ll ans=0;
    rep(i,can.size()){
        ll x=can[i];
        vector<ll> mod(N);
        rep(i,N){
            mod[i]=A[i]%x;
        }
        sort(mod.begin(),mod.end());
        vector<ll> left(N),right(N);
        left[0]=mod[0],right[N-1]=x-mod[N-1];
        rep(i,N-1){
            left[i+1]=left[i]+mod[i+1];
            right[N-2-i]=right[N-1-i]+x-mod[N-2-i];
        }
        rep(i,N-1){
            if (left[i]<=K&&right[i+1]<=K){
                chmax(ans,x);
            }
        }
    }
    cout << ans << endl;
}

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

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<unordered_set>
#include<bitset>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

int dp[1 << 13];
int A[1010];
vector<int> B[1010];

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

	int N, M;
	cin >> N >> M;
	int b,c;
	rep(i, 0, M)
	{
		cin >> A[i] >> b;
		rep(j, 0, b)
		{
			cin >> c;
			c--;
			B[i].push_back(c);
		}
	}

	rep(i, 0, 1 << N)dp[i] = INF;
	dp[0] = 0;

	rep(i, 0, 1 << N)
	{
		if (dp[i] == INF)continue;
		rep(j, 0, M)
		{
			int ni = i;
			for (auto e : B[j])
			{
				ni |= (1LL << e);
			}
			chmin(dp[ni], dp[i] + A[j]);
		}
	}

	int ans = dp[(1 << N) - 1];
	if (ans == INF)
	{
		cout << -1 << endl;
	}
	else
	{
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
using namespace std;

class osa_k{
private:
    vector<int> prime_sieve;
    vector<int> set_prime;
    int N;
    void eratosthenes(){
        for(int i=2;i*i<N;i++) {
            if(prime_sieve[i]<i) continue;
            for(int j=i*i;j<N;j+=i){
                if(prime_sieve[j]==j) prime_sieve[j] = i;
            }
        }                
    }

    void setPrimeSet(){
        for(int i=2;i<N;i++){
            if(prime_sieve[i]==i){
                set_prime.emplace_back(i);
            }
        }        
    }
public:    
    osa_k(const int n){
        N=n;
        prime_sieve.resize(n);
        iota(prime_sieve.begin(),prime_sieve.end(),0);
        eratosthenes();
        setPrimeSet();
    }

    vector<int> get_factor(int i) {
        vector<int> res;
        while(i>1){
            res.emplace_back(prime_sieve[i]);
            i/=prime_sieve[i];
        }
        //素因数の重複なしが欲しいなら、以下のコメントアウトを解除
        sort(res.begin(),res.end());
        decltype(res)::iterator result = unique(res.begin(), res.end());
        res.erase(result, res.end());
        return res;
    }

};



int main(){
    int n;cin>>n;
    osa_k o(1000005);
    vector<int> a(n);
    for(int i=0;i<n;i++) cin>>a[i];
    vector<int> s(1000005);
    int co=a[0];
    for(int i=0;i<n;i++){
        co=gcd(co,a[i]);
    }
    if(co!=1){
        cout<<"not coprime"<<endl;
        return 0;
    }
    for(int i=0;i<n;i++){
        vector<int> tmp=o.get_factor(a[i]);
        for(int j=0;j<tmp.size();j++){
            if(s[tmp[j]]>0){
                cout<<"setwise coprime"<<endl;
                return 0;
            }
            else{
                s[tmp[j]]+=1;
            }
        }
    }
    cout<<"pairwise coprime"<<endl;    

    return 0;
}

Measured memory_bytes: 15268
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
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; }
//(a+b-1)/b

signed main(){
	ll a,b; cin>>a>>b;
	cout<<a*b/gcd(a,b)<<endl;
	
	return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
 
//LIFE IS NOT A PROBLEM TO BE SOLVED
 
#define rep(i,a,b) for( int i = (int) a; i < (int) b; i++ )
#define F first
#define S second
#define pb push_back
#define debug(a) cout << #a << " = " << a << endl;
#define debug2(a,b) cout << #a << " = " << a << " --- " << #b << " = " << b << endl;
#define debugP(a) cout << a.F << " " << a.S << endl;
#define debugV(v, n) { rep( i, 0, n ) { if(i) printf(" "); printf("%d", v[i]); } printf("\n"); }
#define debugM(mat,n,m) rep( i, 0, n ){ rep( j, 0, m ) { if(j) printf(" "); printf("%d", mat[i][j]); } printf("\n"); }
 
using namespace std;
 
typedef long long int ll;
typedef pair<int,int> ii;
 
 
int main(){
	
	int n; cin >> n;
	rep(i, 1, 10){
		rep(j, 1, 10){
			if(i*j==n){
				cout << "Yes\n" << '\n';
				return 0;
			}
		}
	}
	
	puts("No");
	
	
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <iterator>
#include <functional>
#include <vector>
#include <math.h>
using namespace std;

int main(void) {
	
	int N;
	cin >> N;
	vector<int> d(N);

	for (int i = 0; i < N; i++)
	{
		cin >> d[i];
	}

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

	int cnt = 1;
	int tmp = d[0];
	for (int i = 1; i < N; i++)
	{
		if (tmp != d[i])
		{
			cnt++;
		}
		tmp = d[i];
	}

	cout << cnt << endl;

	return 0;
}

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

int main(){
 int a,b,c;
  cin >> a >> b >> c;
  if(a+b+c <= 21) cout << "win" << endl;
  else cout << "bust" << endl;
}

Measured memory_bytes: 256
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby
    #from itertools import product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    n = int(input())
    a = list(map(int, input().split()))
    b = sorted(a)
    res = []
    if abs(b[0]) <= b[-1]:
        x = a.index(b[-1])
        for i in range(n):
            if a[i] < 0:
                res.append([x+1, i+1])
        print(n-1+len(res))
        for i in res:
            print(*i)
        for i in range(n-1):
            print(i+1, i+2)
    else:
        x = a.index(b[0])
        for i in range(n):
            if a[i] > 0:
                res.append([x+1, i+1])
        print(n-1+len(res))
        for i in res:
            print(*i)
        for i in range(n-1, 0, -1):
            print(i+1, i)
    

if __name__ == '__main__':
    main()

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

#define DEBUG(x) cerr << #x << "=" << x << endl
#define BINARY(x) static_cast<bitset<16> >(x)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)
#define if_range(x, y, w, h) if (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define is_in(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()

int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};
using namespace std;
typedef long long ll;
typedef vector<vector<int> > VVI;
const int INF = 1e9;
typedef pair<int, int> PII;

struct Edge {
    int to, cost;
    Edge(int _to, int _cost) : to(_to), cost(_cost) {}
};

struct State {
    int v, totalTime, remainTime;
    State(int _v, int _t, int _r) : v(_v), totalTime(_t), remainTime(_r) {}
    bool operator < (const State &b) const {return totalTime < b.totalTime;}
    bool operator > (const State &b) const {return totalTime > b.totalTime;}
};

const int MAX_V = 100;
vector<Edge> G[MAX_V];
bool canFreeze[MAX_V];

int main()
{
    int N, M, L, K, A, H;
    while (cin >> N >> M >> L >> K >> A >> H, N) {
        fill(canFreeze, canFreeze + MAX_V, false);
        rep(i, MAX_V) G[i].clear();

        rep(i, L) {
            int v; cin >> v;
            canFreeze[v] = true;
        }

        rep(i, K) {
            int X, Y, T;
            cin >> X >> Y >> T;
            G[X].emplace_back(Y, T);
            G[Y].emplace_back(X, T);
        }

        // map<PII, int> d;
        int d[110][110];
        fill(d[0], d[0]+110*110, INF);
        priority_queue<State, vector<State>, greater<State>> Q;

        // d[PII(A, M)] = 0;
        d[A][M] = 0;
        Q.emplace(A, 0, M);
        
        int ans = -1;
        while (Q.size()) {
            State s = Q.top(); Q.pop();
            // cerr << "(s.v, s.totalTime, s.remainTime) = (" << s.v << ", " << s.totalTime << ", " << s.remainTime << ")" << endl;

            if (s.v == H) {
                ans = s.totalTime;
                break;
            }

            // if (d.count(PII(s.v, s.remainTime)) && d[PII(s.v, s.remainTime)] < s.totalTime) continue;
            if (d[s.v][s.remainTime] < s.totalTime) continue;
            
            for (int j=0;j<G[s.v].size(); j++) {
                Edge e = G[s.v][j];
                int ncost = e.cost + s.totalTime;

                for (int i=0; i+s.remainTime <= M; i++) {
                    if (i>0 && !canFreeze[s.v]) break;


                    if (s.remainTime - e.cost + i < 0) continue;
                    // if (!d.count(PII(e.to, s.remainTime - e.cost + i)) || d[PII(e.to, s.remainTime - e.cost + i)] > ncost + i) {
                    if (d[e.to][s.remainTime - e.cost + i] > ncost + i) {
                        // d[PII(e.to, s.remainTime-e.cost + i)] = ncost + i;
                        d[e.to][s.remainTime-e.cost+i] = ncost + i;
                        Q.emplace(e.to, ncost + i, s.remainTime-e.cost + i);
                    }
                }
            }
        }

        if (ans == -1) cout << "Help!" << endl;
        else cout << ans << endl;
    }
}

Measured memory_bytes: 3380
#include <algorithm>
#include <climits>
#include <iostream>
#include <numeric>
#include <vector>

using namespace std;

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

    vector<long long> As(N);
    for (int i = 0; i < N; ++i)
    {
        cin >> As[i];
    }

    int negativeNum = 0;
    for (const long long A : As)
    {
        if (A < 0) ++negativeNum;
    }

    vector<long long> absAs;
    long long sum = 0;
    long long minAbs = LLONG_MAX;
    for (const long long A : As)
    {
        const long long absA = abs(A);
        absAs.push_back(absA);
        sum += absA;
        if (absA < minAbs)
        {
            minAbs = absA;
        }
    }

    if (negativeNum % 2 == 0)
    {
        cout << sum;
    }
    else
    {
        cout << sum - minAbs * 2;
    }

    return 0;
}

Measured memory_bytes: 2168
N,Q=map(int,input().split())
S=input()

cnt=[0 for i in range(N+1)]
s=0
f=False
for i in range(N):
    if f and S[i]=='C':
        s+=1
    if S[i]=='A':
        f=True
    else:
        f=False
    cnt[i]=s
for i in range(Q):
    l,r=map(int,input().split())
    print(cnt[r-1]-cnt[max(0,l-1)])



Measured memory_bytes: 6128
#include<bits/stdc++.h>
#define MAXN 3010010
#define Max 25
#define LL long long
using namespace std;

int main()
{
	LL a , b , c , d;
	cin >> a >> b >> c >> d;
	LL sum = a + b + c;
	LL mx = max(a , max(b , c));
	sum -= mx;
	mx <<= d;
	sum += mx;
	cout << sum << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <map>
#include <algorithm>
using namespace std;
const int N=200005;
struct coord
{
	int x,y;
	coord(int a,int b)
	{
		x=a;
		b=y;
	}
	coord(){}
};
coord c[N];
int h,w,n,r,o,d;
int ans;
bool cmp (coord a,coord b)
{
	return a.x<b.x;
}
int main()
{
	scanf("%d%d%d",&h,&w,&n);
	ans=h;
	for (int i=1;i<=n;i++)
		scanf("%d%d",&c[i].x,&c[i].y);
	sort(c+1,c+n+1,cmp);
	o=-1;
	for (int i=1;i<=n;i++)
	{
		o+=c[i].x-c[i-1].x+d;
		r=i;
		d=0;
		while (r<=n&&c[r].x==c[i].x)
		{
			if (c[r].x==1)
			{
				r++;
				continue;
			}
			if (c[r].y<=o)
				if (c[r].x-1<ans)
					ans=c[r].x-1;
			if (c[r].y==o+1)
				d=-1;
			r++;
		}
		i=r-1;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

using namespace std;

#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = a; i <= b; i++)
#define revrep(i, s) for (int i = s-1; i > 0; i--)
#define revrrep(i, s) for (int i = s-1; i >= 0; i--)
#define all(a)  begin((a)),end((a))
#define uniq(c) (c).erase(unique(all((c))), end((c)))

int main()
{
    int A, B, T; cin >> A >> B >> T;
    cout << (T/A) * B << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <limits.h>
#include <math.h>
int acs(const void *a, const void *b){return *(int*)a - *(int*)b;} /* 1,2,3,4.. */
int des(const void *a, const void *b){return *(int*)b - *(int*)a;} /* 8,7,6,5.. */
int cmp_char(const void *a, const void *b){return *(char*)a - *(char*)b;} /* a,b,c,d.. */
int cmp_str(const void *a, const void *b){return strcmp(*(const char **)a, *(const char **)b);} /* aaa,aab.. */
#define rep(i, n) for (int i = 0; i < n; i++)
#define min(a,b) (a < b ? a: b)
#define max(a,b) (a > b ? a: b)
#define MAX 1000000001
#define MOD 1000000007

typedef long long int lli;

int main(void) {
  int n, m;
  scanf("%d %d", &n, &m);

  int a, b, c, s;
  int mi, bi;
  int dp[5000], key[1001][2]; // key[集合(状態)][料金]
  rep (i, 1 << n) {
    dp[i] = MAX;
  }
  dp[0] = 0;
  for (mi = 0; mi < m; mi++) {
    scanf("%d %d", &a, &b);
    s = 0;
    for (bi = 0; bi < b; bi++) {
      scanf("%d", &c);
      s |= 1 << (c - 1);
    }
    key[mi][0] = s; key[mi][1] = a;
  }

  // ある状態から鍵を使って、遷移先状態の最小料金を更新
  rep(s, 1 << n) {
    rep(mi, m) {
      int uni = s | key[mi][0];
      int cost = dp[s] + key[mi][1];
      dp[uni] = min(dp[uni], cost);
    }
  }
  int last = (1 << n) - 1;
  int ans = dp[last] == MAX ? -1 : dp[last];
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mpr make_pair
#define mt make_tuple
 
using namespace std;
 
const ll N = 100010;
const ll mod = 1e9 + 7;
ll power(ll x, ll   y, ll p){ ll res = 1; x = x % p;while (y > 0){ if (y & 1) res = (res*x) % p; y = y>>1; x = (x*x) % p;} return res; }

ll dp[N];

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,w;
    ll arr[N][2];
    cin>>n>>w;
    memset(dp, mod, sizeof(dp));
    for(int i=1;i<=n;i++)    cin>>arr[i][0]>>arr[i][1];
    dp[0] = 0;
    for(int i=1;i<=n;i++){
        for(int j=N-1;j>=arr[i][1];j--)
            dp[j] = min(dp[j], dp[j-arr[i][1]] + arr[i][0]);
    }
    for(int i = N-1;i>=0;i--){
        if(dp[i] <= w){
            cout<<i<<endl;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<string>
#include<array>
#include<cmath>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<numeric>
#include<iomanip>
#include<utility>
using namespace std;
#define INF 1000000005
#define maxv 10

using namespace std;
struct edge{
    int to,cost;
};
typedef pair<int, int> P; //firstは最短距離,secondは頂点の番号

int V;
vector<edge> G[maxv];
int d[maxv];
int previ[maxv];

void dijkstra(int s){
    priority_queue<P, vector<P>, greater<P>> que;
    fill(d, d + V, INF);
    fill(previ, previ + V, -1);;
    d[s] = 0;
    que.push(P(0, s));


    while(!que.empty()) {
        P p = que.top();
        que.pop();
        int v = p.second;
        if(d[v] < p.first) continue;
        for(int i = 0; i < G[v].size(); i++){
            edge e = G[v][i];
            if(d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                previ[e.to] = v;
                que.push(P(d[e.to], e.to));
            }
        }
    }
}

vector<int> get_path(int t) {
    vector<int> path;
    for(; t != -1; t = previ[t]) path.push_back(t);
    reverse(path.begin(),path.end());
    return path;
}


int main()
{
V = 10;
int h,w;
std::cin >> h >> w;
for(int i = 0; i < 10; i++){
    for(int j = 0; j < 10; j++){
        int l;
        std::cin >> l;
        edge temp;
        temp.to = i;
        temp.cost = l;
        G[j].push_back(temp);
    }
}
dijkstra(1);
long long int sum = 0;
for(int i = 0; i < h * w;i++){
    int l;
    std::cin >> l;
    if(l == -1){
        continue;
    } else {
        sum += d[l];
    }
}
std::cout << sum << std::endl;
return 0;
}

Measured memory_bytes: 256
N, X = gets.split.map!(&:to_i)
L = gets.split.to_a.map!(&:to_i)
ans = [0]
cnt = 1
N.times do |i|
	tmp = ans.last + L[i]
	ans << tmp
	if tmp <= X
		cnt += 1
	else
		break
	end
end
puts cnt

Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define REP(i, n) for(int i=0;i<n;++i)

typedef long long ll;
using namespace std;
int main(){
    cin.tie(0);
   	ios::sync_with_stdio(false);
    int n, d;
    int x[11][11] = {};

    cin >> n >> d;
    REP(i, n){
        REP(j, d){
            cin >> x[i][j];
        }
    }

    int ans = 0;
    REP(i, n){ 
        for(int j=i+1;j<n;++j){
            double dist = 0.;
            REP(k, d){
                dist += (x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
            }
            dist = sqrt(dist);
            if(ceil(dist) == floor(dist))++ans;
        }
    }
    cout << ans << "\n";
    return 0;
}

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

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

  long long w[n+1];
  long long v[W+1];
  for(int i=0;i<n;i++){
    cin>>w[i]>>v[i];
  }

  long long dp[n+1][W+1];

  for(int i=0;i<n+1;i++){
    for(int j=0;j<W+1;j++){
      dp[i][j]=0;
    }
  }
  
  dp[0][0]=0;
  for(int i=0;i<n;i++){
    for(int j=0;j<W+1;j++){
      if(j>=w[i]){
        if(dp[i][j-w[i]]+v[i]>dp[i][j]){
          dp[i+1][j]=dp[i][j-w[i]]+v[i];
        }else{
          dp[i+1][j]=dp[i][j];
        }
      }else{
        dp[i+1][j]=dp[i][j];
      }
    }
  }
  cout<<dp[n][W]<<endl;
  return 0;
}

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

int main(){
  string str;
  cin >> str;
  if(str.back() == '2' || str.back() == '4' || str.back() == '5' || str.back() == '7' || str.back() == '9'){
    printf("hon");
    return 0;
  }
  else if(str.back() == '0' || str.back() == '1' || str.back() == '6' || str.back() == '8' ){
    printf("pon");
    return 0;
  }
  printf("bon");
}


Measured memory_bytes: 3720
import java.util.*;

public class Main{
	int w,h;
	int [] vx = {0,1,0,-1};
	int [] vy = {1,0,-1,0};
	
	class C{
		int x1,y1,x2,y2;

		public C(int x1, int y1, int x2, int y2) {
			this.x1 = x1;
			this.y1 = y1;
			this.x2 = x2;
			this.y2 = y2;
		}
		
	}

	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(true){
			w = sc.nextInt();
			h = sc.nextInt();
			if((w|h) == 0) break;
			char [][][]data = new char[2][h][w];
			for(int i = 0; i < h; i++){
				for(int j = 0; j < 2; j++){
					data[j][i] = sc.next().toCharArray();
				}
			}
			int x1 = 0,x2 = 0,y1 = 0,y2 = 0;
			for(int i = 0; i < h; i++){
				for(int j = 0; j < w; j++){
					if(data[0][i][j] == 'L'){
						data[0][i][j] = '.';
						x1 = j;
						y1 = i;
					}
				}
			}
			for(int i = 0; i < h; i++){
				for(int j = 0; j < w; j++){
					if(data[1][i][j] == 'R'){
						data[1][i][j] = '.';
						x2 = j;
						y2 = i;
					}
				}
			}
			LinkedList<C> open = new LinkedList<C>();
			open.add(new C(x1, y1, x2, y2));
			boolean [][][][] close = new boolean[h][w][h][w];
			close[y1][x1][y2][x2] = true;
			boolean ans = false;
			while(! open.isEmpty()){
				C now = open.poll();
				
				boolean flg = false;
				for(int i = 0; i < 4; i++){
					int xx = now.x1 + vx[i];
					int yy = now.y1 + vy[i];
					int xx2 = now.x2 + vx[i] *  -1;
					int yy2 = now.y2 + vy[i];
					if(! isOK(xx,yy) || data[0][yy][xx] == '#'){
						yy = now.y1;
						xx = now.x1;
					}
					if(! isOK(xx2, yy2) || data[1][yy2][xx2] == '#'){
						yy2 = now.y2;
						xx2 = now.x2;
					}
					if(data[0][yy][xx] == '%' && data[1][yy2][xx2] == '%'){
						flg = true;
						ans = true;
						break;
					}
					if(data[0][yy][xx] == '%' || data[1][yy2][xx2] == '%'){
						continue;
					}
					
					if(close[yy][xx][yy2][xx2]) continue;
					
					open.add(new C(xx, yy, xx2, yy2));
					close[yy][xx][yy2][xx2] = true;
				}
				if(flg){
					break;
				}
			}
			System.out.println(ans ? "Yes" : "No");
		}
	}

	private boolean isOK(int xx, int yy) {
		if(0 <= xx && xx < w && 0 <= yy && yy < h) return true;
		return false;
	}

	private void debug(Object... o) {
		System.out.println("debug = " + Arrays.deepToString(o));
	}

	public static void main(String[] args) {
		new Main().doit();
	}
}

Measured memory_bytes: 178464
using System;
using System.Collections.Generic;
using System.Text;
using System.Numerics;
using System.IO;

namespace SolutionCS
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            string[] s = Console.ReadLine().Split(' ');

            int ans = 0;
            for (int i = 0; i < s.Length; i++)
            {
                ans += int.Parse(s[i]) - 1;
            }

            Console.WriteLine(ans);
        }
    }
}


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

int abs(ll a, ll b) {
  return a > b? a-b : b-a;
}

int main() {
  int n, x, y;
  cin >> n >> x >> y;
  x--; y--;
  vector<int> cnt(n, 0);
  for (int i=0; i<n; i++) for (int j=i+1; j<n; j++) {
    int d = min(abs(j, i), abs(i, x)+1+abs(j, y));
    cnt[d]++;
  }
  rep(i, n-1) cout << cnt[i+1] << endl;
  return 0;
}


Measured memory_bytes: 256
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;

public class Main {

	private final static long MOD = 1000000007;

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		char[] A = sc.next().toCharArray();
		char[] B = sc.next().toCharArray();
		char[] C = sc.next().toCharArray();

		long count = 0;
		for (int i = 0; i < N; i++) {
			if (A[i] == B[i] && B[i] == C[i]) {
				count += 0;
				debug(A[i], B[i], C[i], 0);
			} else if ((A[i] == B[i] && B[i] != C[i])
					|| (B[i] == C[i] && A[i] != B[i])
					|| (C[i] == A[i] && C[i] != B[i])) {
				count += 1;
				debug(A[i], B[i], C[i], 1);
			} else {
				count += 2;
				debug(A[i], B[i], C[i], 2);
			}

		}

		System.out.println(count);
	}

	private static boolean isDebug = System.getProperty("sun.desktop") != null;

	private static void debug(Object... o) {
		if (isDebug) {
			System.err.println(Arrays.deepToString(o));
		}
	}

	public static class Scanner {
		private BufferedInputStream inputStream;
		private StringBuilder buffer = new StringBuilder();

		public Scanner(InputStream in) {
			inputStream = new BufferedInputStream(in);
		}

		public int nextInt() throws IOException {
			int num = 0;
			int sign = 1;

			int read = skip();
			if (read == '-') {
				sign = -1;
				read = inputStream.read();
			}

			do {
				num = num * 10 + sign * (read - 0x30);
			} while ((read = inputStream.read()) > 0x20);

			return num;
		}

		public void fill(int[] a) throws IOException {
			for (int i = 0; i < a.length; i++) {
				a[i] = nextInt();
			}
		}

		public void fill(int[] a, int[] b) throws IOException {
			if (a.length != b.length) {
				throw new IllegalArgumentException();
			}

			for (int i = 0; i < a.length; i++) {
				a[i] = nextInt();
				b[i] = nextInt();
			}
		}

		public long nextLong() throws IOException {
			long num = 0;
			int sign = 1;

			int read = skip();
			if (read == '-') {
				sign = -1;
				read = inputStream.read();
			}

			do {
				num = num * 10 + sign * (read - 0x30);
			} while ((read = inputStream.read()) > 0x20);

			return num;
		}

		public void fill(long[] a) throws IOException {
			for (int i = 0; i < a.length; i++) {
				a[i] = nextLong();
			}
		}

		public void fill(long[] a, long[] b) throws IOException {
			if (a.length != b.length) {
				throw new IllegalArgumentException();
			}

			for (int i = 0; i < a.length; i++) {
				a[i] = nextLong();
				b[i] = nextLong();
			}
		}

		public long[] nextLong(int n) throws IOException {
			long[] array = new long[n];
			for (int i = 0; i < n; i++) {
				array[i] = nextLong();
			}

			return array;
		}

		public String next() throws IOException {
			int read = skip();
			do {
				buffer.append((char) read);
			} while ((read = inputStream.read()) > 0x20);

			String text = buffer.toString();
			buffer.delete(0, buffer.length());

			return text;
		}

		private int skip() throws IOException {
			int read;
			while ((read = inputStream.read()) <= 0x20)
				;

			return read;
		}
	}
}


Measured memory_bytes: 21204
#include <bits/stdc++.h>
using namespace std;
int main(){
    int A,B,c;
    cin >> A >> B;
    
    if((B - 1) % (A - 1) == 0){
        c = (B - 1) / (A - 1);
        cout << c << endl;
    }

    
    else{
        c =  (B - 1) / (A - 1) + 1;
        cout << c << endl;
    }

}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<iostream>
#include <iomanip>
#include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include <queue>
#include <utility>
#include <map>
#include <set>
#include <deque>
#include <numeric>
using namespace std;

int main() {
    string S;
    cin >> S;
    int a, z;
    for (int i = 0; i < S.size(); i++) {
        if (S[i] == 'A') {
            a = i;
            break;
        }
    }
    for (int i = S.size() - 1; i >= 0; i--) {
        if (S[i] == 'Z') {
            z = i;
            break;
        }
    }

    cout << z - a + 1 << endl;
    

    return 0;
}

Measured memory_bytes: 640
using System;
using System.Linq;
using System.Collections.Generic;


namespace ConsoleApplication1 {

    class ClassMain {

       


        public static void Main(String[] args) {
            string line;
            while ((line = Console.ReadLine()) != null) {
                //int[] ints = line.Split(' ').Select(int.Parse).ToArray();
                //int n = ints[0];
                //int n = int.Parse(line);                
                //if (n == 0) { break; }
                if (line.Equals(".")) { break; }
                Stack<char> paren = new Stack<char>();
                for (int i = 0; i < line.Length; i++) {
                    char ch = line[i];
                    if (ch == '(') {
                        paren.Push('(');
                    }
                    else if (ch == '[') {
                        paren.Push('[');
                    }
                    else if (ch == ')') {
                        if (paren.Count == 0) { paren.Push('X'); break; }
                        if (paren.Peek() == '(') {
                            paren.Pop();
                        }
                        else { break; }
                    }
                    else if (ch == ']') {
                        if (paren.Count == 0) { paren.Push('X'); break; }
                        if (paren.Peek() == '[') {
                            paren.Pop();
                        }
                        else { break; }
                    }
                }
                if (paren.Count == 0) {
                    Console.WriteLine("yes");
                }
                else {
                    Console.WriteLine("no");
                }




            }
        }
    }
}

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

int main() {
  int N, K;
  cin >> N >> K;
  
  int R, S, P;
  cin >> R >> S >> P;
  
  map<char, int> Point;
  Point['s'] = R;
  Point['p'] = S;
  Point['r'] = P;
  bool flag[100010];
  
  
  string T;
  cin >> T;
  
  int ans = 0;
  for (int i = 0; i < K; i++) {
    ans += Point[T[i]];
    flag[i] = true;
  }
  
  for (int i = K; i < N; i++) {
    if (T[i] != T[i-K]) {
      ans += Point[T[i]];
      flag[i] = true;
    } else if (!flag[i-K]) {
      ans += Point[T[i]];
      flag[i] = true;
    } else {
      flag[i] = false;
    }
  }
  cout << ans << endl;
       
}

Measured memory_bytes: 512
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		Twin_string ts = new Twin_string(sc.next());
		int q = sc.nextInt(); int f;
		boolean rev = false;
		for (int i = 0; i < q; i++) {
			if(sc.nextInt()==1) rev = !rev;
			else {
				f = sc.nextInt();
				String c = sc.next();
				if((!rev&&f==1)||(rev&&f==2)) ts.addFirst(c);
				else ts.addLast(c);;
			}
		}
		System.out.println(ts.toString(rev));
	}
	public static class Twin_string{
		StringBuilder sb1, sb2;
		public Twin_string(String s) {
			sb1 = new StringBuilder();
			sb2 = new StringBuilder(s);
		}
		public void addFirst(String s) {
			sb1.append(s);
		}
		public void addLast(String s) {
			sb2.append(s);
		}
		public String toString(boolean rev) {
			if(rev) return new String(sb2.reverse()) + new String(sb1);
			else return new String(sb1.reverse()) + new String(sb2);
		}
	}
}

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    long long n_all = 1;
    long long n_odd = 1;
    while (N--){
        int a;
        cin >> a;
        n_all *= 3;
        if ((a % 2) == 0) n_odd *= 2;
    }
    cout << n_all - n_odd << endl;
    return 0;
}

Measured memory_bytes: 256
def main():
    import sys
    input = sys.stdin.buffer.readline
    N = int(input())
    c = [[int(i) for i in input().split()] for j in range(N)]
    from collections import defaultdict
    edge = defaultdict(set)
    deg = defaultdict(int)
    for i, A in enumerate(c, start=1):
        for j in range(N-2):
            if i < A[j]:
                if i < A[j+1]:
                    edge[i*N+A[j]].add(i*N+A[j+1])
                    deg[i*N+A[j+1]] += 1
                else:
                    edge[i*N+A[j]].add(A[j+1]*N+i)
                    deg[A[j+1]*N+i] += 1
            else:
                if i < A[j+1]:
                    edge[A[j]*N+i].add(i*N+A[j+1])
                    deg[i*N+A[j+1]] += 1
                else:
                    edge[A[j]*N+i].add(A[j+1]*N+i)
                    deg[A[j+1]*N+i] += 1
    from collections import deque
    que = deque()
    dist = defaultdict(int)
    for i in range(1, N+1):
        for j in range(i+1, N+1):
            # print(i, j, i*N+j)
            if deg[i*N+j] == 0:
                que.append(i*N+j)  # root
                dist[i*N+j] = 1
    while que:
        u = que.popleft()
        for v in edge[u]:
            deg[v] -= 1
            dist[v] = max(dist[v], dist[u] + 1)
            if deg[v] == 0:
                que.append(v)

    if any(deg.values()):
        # 閉路検出
        print(-1)
    else:
        print(max(dist.values()))


if __name__ == '__main__':
    main()


Measured memory_bytes: 261104
#include<bits/stdc++.h>
#define int long long
//#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
const int inf=0x3f3f3f3f;
const double eps=1e-6;
const int mod=1000000007;
typedef long long ll;
int modpow(int x,int y,int md=mod){if(y==0)return 1;int ret=modpow(x,y>>1,md);ret=(ll)ret*ret%md;if(y&1)ret=(ll)ret*x%md;return ret;}
int n;
vector<pair<int,int> >p;
vector<int>v[50];
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	cin>>n;
	int t=n;
	for(int i=2;i*i<=n;i++){
		int cnt=0;
		if(t%i==0){
			while(t%i==0){
				cnt++;
				t/=i;
			}
			p.push_back(make_pair(i,cnt));
		}
	}
	if(t!=1)p.push_back(make_pair(t,1));
	p.insert(p.begin(),make_pair(0,0));
	v[0].push_back(1);
	for(int i=1;i<p.size();i++){
		int d=p[i].first,y=p[i].second;
		for(auto x:v[i-1]){
			int mul=1;
			for(int j=0;j<=y;j++){
				v[i].push_back(x*mul);
				mul*=d;
			}
		}
		v[i-1].clear();
	}
	ll ans=0;
	for(auto x:v[p.size()-1]){
		int m=x-1;if(m==0)continue;
		int _1=n/m,_2=n%m;
		if(_1==_2){
			ans+=m;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 384
# include <bits/stdc++.h>
 
using namespace std;
 
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
    ~debug() { cerr << endl; }
    eni(!=) cerr << boolalpha << i; ris; }
    eni(==) ris << range(begin(i), end(i)); }
    sim, class b dor(pair < b, c > d) {
    ris << "(" << d.first << ", " << d.second << ")";
    }
    sim dor(rge<c> d) {
    *this << "[";
    for (auto it = d.b; it != d.e; ++it)
        *this << ", " + 2 * (it == d.b) << *it;
    ris << "]";
    }
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
 
# define forn(i, n) for (ll i = 0; i < int(n); i++)
# define rfor(n, i) for (ll i = (n - 1); i >= 0; --i)
# define all(V) V.begin(), V.end()
# define rall(V) V.rbegin(), V.rend()
# define len(V) (int)V.size()
# define ll long long
# define ld long double
# define ff first
# define ss second
# define pb push_back
# define mp make_pair
# define endl '\n'
# define M_PI 3.14159265358979323846

const int MAX_N = 100;
vector<int> xy(MAX_N);
 
void solve()
{
        int n, k; cin >> n >> k;
        vector<int> a(n);
        forn(i, n)
        {
                cin >> a[i];
                //a[i] += i;
        }
        ll res = 0;
        forn(i, n)
        {
                res += min(a[i], k - a[i]);
        }
        cout << 2 * res;
}
 
int main()
{
        ios_base::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
        solve();
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define double long double
#define INF 1e18
using namespace std;
template<class T> inline bool chmax(T&a, T b){ if(a<b){ a=b; } return a<b; }
signed main() {
  int N; cin>>N; 
  int a[N][3];
  for(int i=0;i<N;i++) for(int j=0;j<3;j++) cin>>a[i][j];
  int dp[N+1][3];
  for(int i=0;i<N+1;i++) for(int j=0;j<3;j++) dp[i][j]=0;  
  
  for(int i=0;i<N;i++) {
    for(int j=0;j<3;j++) {
      for(int k=0;k<3;k++) {
        if(k!=j) {
          chmax(dp[i+1][j], dp[i][k]+a[i][j]);
        }
      }
    } 
  }

  int ans=0;
  for(int i=0;i<3;i++) chmax(ans,dp[N][i]);
  cout<<ans<<endl;
}


Measured memory_bytes: 4992
#include<stdio.h>
#include<algorithm>
using namespace std;
int w[101000], n, a1, b1, a2, b2;
int main(){
    int i;
    scanf("%d",&n);
    for(i=1;i<=n;i++){
        scanf("%d",&w[i]);
        w[i]=-w[i];
    }
    sort(w+1,w+n+1);
    for(i=1;i<=n;i++)w[i]=-w[i];
    for(i=1;i<=n;i++){
        if(w[i]!=w[i+1]){
            if(w[i] == i){
                printf("Second\n");
                return 0;
            }
            if(w[i]>i){
                a1 = i, b1 = w[i];
            }
            if(w[i]<i && !a2){
                a2 = i, b2 = w[i];
            }
        }
    }
    if( (a1 && (b1%2 != a1%2) && a1 >= b2) || (a2 && (b2%2 != a2%2) && b2 >= a1)) printf("First\n");
    else printf("Second\n");
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (int)n; i++)
#define all(x) x.begin(), x.end()
#define MOD 1000000007//1e9+7
typedef long long ll;
using namespace std;
int main()
{
  int a, b, c, x;
  cin >> a>> b >> c >> x;
  int ans = 0;
  int k = 0;
  REP(i,a + 1){
    if(500*i > x)continue;
    REP(j,b + 1){
      if(500*i + 100*j > x)continue;
      k = (x - 500*i - 100*j)/50;
      if(0 <= k&&k<= c){
	ans ++;
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#define re register
using namespace std;
long long l,r;

int main(){
	ios::sync_with_stdio(false);
	cin >> l >> r;
	if(r-l>=2019){
		cout << "0" <<endl;
		exit(0);
	}
	l = l % 2019;
	r = r % 2019;
	if(r<=l){
		r += 2019;
	}
	long long Min = 2018;
	for(re int i = l;i<r;i++){
		for(re int j = i+1;j<=r;j++){
			if(Min > ((i*j)%2019)){
				Min = (i*j)%2019;
			}
		}
	}
	cout << Min <<endl;
	return 0;
}


Measured memory_bytes: 256
a = int(input())
l = [int(x) for x in list(str(a))]
n = int(l[(len(l)-2)]*10 + l[(len(l)-1)])
m = int((a - n)/100)

if a < 100:
  print(0)
else:
  while n > 5 and m > 0:
    n = n - 5
    m = m - 1
  if m == 0:
    print(0)
  else:
    print(1)

Measured memory_bytes: 3064
from heapq import heappop, heappush
n, m, s = map(int, input().split())
edges = [[[] for _ in range(2501)] for _ in range(n)]

for _ in range(m):
    u, v, a, b = map(int, input().split())
    for x in range(2501):
        if x - a >= 0:
            edges[u-1][x].append((b, v-1, x-a))
            edges[v-1][x].append((b, u-1, x-a))

for i in range(n):
    c, d = map(int, input().split())
    for x in range(2500):
        edges[i][x].append((d, i, min(2500, x+c)))

inf = 1e15
d = [[inf for _ in range(2501)] for _ in range(n)]
s = min(s, 2500)
def dijkstra():
    que = []
    d[0][s] = 0
    heappush(que, (0, 0, s))

    while len(que):
        dist, city, coins = heappop(que)

        if d[city][coins] < dist:
            continue
        for cost, to_city, to_coins in edges[city][coins]:
            if d[to_city][to_coins] > dist + cost:
                d[to_city][to_coins] = dist + cost
                heappush(que, (d[to_city][to_coins], to_city, to_coins))


dijkstra()
for i in range(1, n):
    print(min(d[i]))

Measured memory_bytes: 171636