akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define INF 1<<29
int V;
vector<vector<vector<int> > > G;
int d[101];
bool used[101];

void dijkstra(int s,int r){
  memset(used,false,sizeof(used));
  fill(d,d+101,INF);
  d[s]=0;
  while(1){
    int id=-1;
    for(int i=1;i<=V;++i)
      if(!used[i] && (id==-1||d[id]>d[i]))
        id=i;
    if(id==-1) break;
    used[id]=true;
    for(int i=1;i<=V;++i)
      if(r)
        d[i]=min(d[i],d[id]+G[id][i][1]);
      else
        d[i]=min(d[i],d[id]+G[id][i][0]);
  }
}
int main(){
  int n;
  while(cin>>n>>V,n){
    G=vector<vector<vector<int> > >(V+1,vector<vector<int> >(V+1,vector<int>(2,INF)));
    for(int i=0;i<n;++i){
      int a,b,c,t; cin>>a>>b>>c>>t;
      G[a][b][0]=G[b][a][0]=c;
      G[a][b][1]=G[b][a][1]=t;
    }
    int k; cin>>k;
    for(int i=0;i<k;++i){
      int p,q,r; cin>>p>>q>>r;
      dijkstra(p,r);
      cout<<d[q]<<endl;
    }
    
  }
  
  return 0;
}

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

int n, k;
map<int, int> mp;
vector<int> v;

//(現在の種類数)-Kが変更するべき種類数なので、その種類数だけ、個数が少ない数字からボールの個数をカウントしていけば、答えが求まる。
//mapでボールの種類と個数をリンクさせ、その後個数だけを抽出し、最後にその個数を昇順にソートして貪欲法を適用
int main() {
  int ans = 0;
  cin >> n >> k;
  for(int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    ++mp[a];
  }
  for(auto it = mp.begin(); it != mp.end(); ++it) {
    v.push_back(it->second);
  }
  sort(v.begin(), v.end());
  if(v.size() > k)
    for(int i = 0; i < v.size() - k; ++i) ans += v[i];
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 10748
#include "bits/stdc++.h"
using namespace std;
#define INF 1e9
#define rep(i, n) for(int i = 0; i < n; i++)
#define ALL(x) (x).begin(), (x).end()  //昇順
#define RALL(x) (x).rbegin(), (x).rend() // 降順
const long long mod = 1e9+7;
typedef priority_queue<int> PQ;
typedef vector<long long> VL;
typedef vector<int> VI;  // VI a(n);
typedef vector<string> VS;  
typedef vector<char> VC; 
typedef vector<VS> VSS;
typedef vector<VC> VCC;    
typedef vector<VI> VII;   // VII a(n,vector<int>(m)) n * m 
typedef vector<VL> VLL;
typedef pair<int, int> PII;
typedef map<int, int> MP;   //MP a;
typedef vector<pair<int, int> > PS;
typedef long long ll;  //ll とdoubleは違う
template <class T>  // chmax(max, a);
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> //chmin(min,a)
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
template<typename T>   // operator << (cout,a);
ostream& operator << (ostream& os, vector<T>& v) {
    os << "{";
    rep(i, (int)v.size()) { os << v[i] << (i < v.size() - 1 ? ", " : ""); }
    os << "}";
    return os;
}

// g++ -std=c++11 prac.cpp
ll Max=-1e9,Min=1e9+1;
 
int main(){
    ll x,c,y=0,n,m,l,w,sum=0,sum2=0,ans=1;
    string t;
    bool f=true;
    cin >> x;
    n = x/11;
    if(11*n<x && x<=11*n+6){
        cout << n*2+1 << endl;
    }
    else if(11*n==x){
        cout << n*2 << endl;
    }
    else
        cout << (n+1)*2 << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>

int main(){
  int x;
  std::cin >> x;
  
  bool prime;
  
  for(x;;x++){
    prime = true;
    for(int b=2;b<(x/2);b++){
      if(x%b == 0){
        prime = false;
        break;
      }
    }
    if(prime){
      break;
    }
  }
  
  std::cout << x << std::endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;
using ll = long long;

#define REP(i, a) for (int i = 0; i < (a); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (a)-1; i >= (b); --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define SIZE(obj) (int)(obj).sizeT()
#define YESNO(cond, yes, no) \
    { cout << ((cond) ? (yes) : (no)) << endl; }
#define SORT(list) sort(ALL((list)));
#define RSORT(list) sort((list).rbegin(), (list).rend())
#define ASSERT(cond, mes) assert(cond&& mes)

constexpr int MOD = 1'000'000'007;
constexpr int INF = 1'050'000'000;

template <typename T>
T round_up(const T& a, const T& b) {
    return (a + (b - 1)) / b;
}

template <typename T1, typename T2>
istream& operator>>(istream& is, pair<T1, T2>& p) {
    is >> p.first >> p.second;
    return is;
}

template <typename T1, typename T2>
ostream& operator<<(ostream& os, pair<T1, T2>& p) {
    os << p.first << p.second;
    return os;
}

template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
    REP(i, (int)v.size())
    is >> v[i];
    return is;
}

template <typename T>
T clamp(T& n, T a, T b) {
    if (n < a) n = a;
    if (n > b) n = b;
    return n;
}

template <typename T>
static T GCD(T u, T v) {
    T r;
    while (v != 0) {
        r = u % v;
        u = v;
        v = r;
    }
    return u;
}

template <typename T>
static T LCM(T u, T v) {
    return u / GCD(u, v) * v;
}

template <typename T>
std::vector<T> enum_div(T n) {
    std::vector<T> ret;
    for (T i = 1; i * i <= n; ++i) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) { ret.push_back(n / i); }
        }
    }
    return ret;
}

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

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

struct ToUpper {
    char operator()(char c) {
        return toupper(c);
    }
};

struct ToLower {
    char operator()(char c) {
        return tolower(c);
    }
};

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

    int N;
    cin >> N;
    vector<int> A(N);
    cin >> A;

    map<int, int> m;
    REP(i, N) {
        m[A[i]]++;
    }

    int ans = 0;
    for (auto&& a : m) { ans += a.second - 1; }

    if (ans % 2 == 1) ans++;
    ans = N - ans;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5376
#pragma GCC optimize(3)
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/priority_queue.hpp>
#define MAXN 2005
#define INF 1000000000
#define MOD 1000000007
#define F first
#define S second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int,int> P;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef __gnu_pbds::priority_queue<int,greater<int>,pairing_heap_tag> pq;
typedef bitset<2000> bs;
int n;
bs win[MAXN],twin[MAXN];
int a[MAXN][MAXN];
bs dpl[MAXN],dpr[MAXN],tdpl[MAXN],tdpr[MAXN];
string str;
int main()
{
    scanf("%d",&n);
    for(int i=1;i<n;i++)
    {
        cin>>str;
        for(int j=0;j<i;j++)
        {
            int x=str[j]-'0';
            if(x) 
            {
                win[i].set(j);
                twin[j].set(i);
            }
            else 
            {
                win[j].set(i);
                twin[i].set(j);
            }
        }
    }
    for(int i=0;i<n;i++)
    {
        dpl[i].set(i); dpr[i].set(i);
        tdpl[i].set(i); tdpr[i].set(i);
    }
    for(int len=2;len<=n;len++)
    {
        for(int i=0;i+len-1<n;i++)
        {
            int j=i+len-1;
            if((dpr[i+1]&tdpl[j]&win[i]).count())
            {
                dpl[i].set(j);
                tdpl[j].set(i);
            }
            if((dpr[i]&tdpl[j-1]&win[j]).count())
            {
                dpr[i].set(j);
                tdpr[j].set(i);
            }
        }
    }
    int ans=0;
    for(int i=0;i<n;i++) if(dpl[i].test(n-1)&&dpr[0].test(i)) ans++;
    printf("%d\n",ans);
    return 0;
}



Measured memory_bytes: 4608
#include <stdio.h>

int main(void)
{
	int data[11][11];
	int kazu,i,j;
	
	while(scanf("%d",&kazu),kazu)
	{
		//初期化
		for(i=0;i<11;i++)
		{
			for(j=0;j<11;j++)
			{
				data[i][j]=0;
			}
		}
		//入力・計算
		for(i=0;i<kazu;i++)
		{
			for(j=0;j<kazu;j++)
			{
				scanf("%d",&data[i][j]);
				data[i][kazu]+=data[i][j];
				data[kazu][j]+=data[i][j];
				data[kazu][kazu]+=data[i][j];
			}
		}
		//出力
		for(i=0;i<=kazu;i++)
		{
			for(j=0;j<=kazu;j++)
			{
				printf("%5d",data[i][j]);
			}
			printf("\n");
		}
	}
	return 0;
}

Measured memory_bytes: 612
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        
        double A=sc.nextDouble();
        double B=sc.nextDouble();
        
        if(A>B){
            System.out.println("GREATER");
        }else if(A<B){
            System.out.println("LESS");
        }else{
            System.out.println("EQUAL");
        }
        
        
        
        
        
        
    }
}


Measured memory_bytes: 37060
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(){
	string s;
	int a,b,c;
	cin>>s;
	a=s[0]-'0';
	b=s[1]-'0';
	c=s[2]-'0';
	cout<<a+b+c<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <math.h>
#include <stack>
#include <climits>
#include <bitset>
#include <utility>


using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// const ll INF = 1LL <<60;
const int INF = 10000;

//最小公倍数
ll gcd(ll x, ll y) {
  ll tmp = 0;
  if (x < y){
    tmp=x;
    x=y;
    y=tmp;
  }
  while (y > 0) {
    ll r = x % y;
    x = y;
    y = r;
  }
  return x;
}

//最大公倍数
ll lcm(ll x,ll y){
  return x/gcd(x,y)*y;
}

//階乗
ll kaijo(ll k){
    ll sum = 1;
    for (ll i = 1; i <= k; ++i)
    {
        sum *= i;
        sum%=1000000000+7;
    }
    return sum;
}

//for(int i = ; i < ; i++){}

ll lmax(ll s,ll t){
  if(s>t){
    return s;
  }
  else{
    return t;
  }
}

ll lmin(ll s,ll t){
  if(s<t){
    return s;
  }
  else{
    return t;
  }
}
// ここから開始


int main(){
  string s;
  cin>>s;
  int cen = 0;
  vector<char> t;
  for(int i = 0; i < s.length(); i++){
    if(s[i]!='B'){
      t.push_back(s[i]);
      cen++;
    }
    else{
      if(t.size()>0) {
        t.pop_back();
      }
      cen--;
    }
  }
  for(int i = 0; i < t.size(); i++)cout<<t[i];
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#define ALL(x) (x).begin(), (x).end()
#define rt return
#define dll(x) scanf("%I64d",&x)
#define xll(x) printf("%I64d\n",x)
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define gg(x) getInt(&x)
#define db(x) cout<<"== [ "<<x<<" ] =="<<endl;
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll powmod(ll a,ll b,ll MOD){ll ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;}
inline void getInt(int* p);
const int maxn=1000010;
const int inf=0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/

int main()
{
    //freopen("D:\\common_text\\code_stream\\in.txt","r",stdin);
	//freopen("D:\\common_text\\code_stream\\out.txt","w",stdout);

	ll a,b,c,x,y;
	cin>>a>>b>>c>>x>>y;
	ll ans=1e18;
	c*=2;
	for(ll i=0;i<=max(x,y);i++)
	{
	    ans=min(ans,i*c+max(x-i,0ll)*a+max(y-i,0ll)*b);
	}
	cout<<ans<<endl;

    return 0;
}

inline void getInt(int* p) {
    char ch;
    do {
        ch = getchar();
    } while (ch == ' ' || ch == '\n');
    if (ch == '-') {
        *p = -(getchar() - '0');
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 - ch + '0';
        }
    }
    else {
        *p = ch - '0';
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 + ch - '0';
        }
    }
}



Measured memory_bytes: 384
import sys
from collections import deque, defaultdict
import copy
import bisect
input=sys.stdin.readline
#sys.setrecursionlimit(10 ** 9)
import math

D, G = list(map(int, input().split()))
pc = []
for i in range(D):
	pc.append(list(map(int, input().split())))

total = []
for i in range(D):
	total.append((i+1)*pc[i][0]*100 + pc[i][1])

minn = 100000000
for i in range(2**D):
	sum = 0
	n = 0
	max0 = -1
	for j in range(D):
		x = (i & (2 ** j)) // (2 ** j)
		sum += total[j]*x
		n += pc[j][0]*x
		if x == 0:
			max0 = j

	if sum >= G:
		minn = min(minn, n)
	elif sum < G:
		rest = math.ceil((G - sum) / (100*(max0 + 1)))
		if rest < pc[max0][0]:
			minn = min(minn, n + rest)
print(minn)

Measured memory_bytes: 40944
def is_prime_five(num):
    if num % 5 == 1:
        for i in range(2, int(num**0.5)+1):
            if num % i == 0:
                return False

        return True

    else:
        return False


n = int(input())

PRIME, idx = [0 for i in range(55)], 0
for i in range(2, 55556):
    if idx == 55:
        break

    if is_prime_five(i):
        PRIME[idx] = i
        idx += 1

ans_lst = PRIME[:n]
print(" ".join([str(i) for i in ans_lst]))


Measured memory_bytes: 3060
S = input()
length = len(S)


def dfs(summary, array, i):
    if i == length:
        return 0
    elif i == length -  1:
        return sum([int(x) for x in array.split("+")])
    array_plus = array[:-(length-i-1)] + "+" + array[-(length-i-1):]
    summary = 0
    summary += dfs(summary, array ,i+1)
    summary += dfs(summary, array_plus ,i+1)
    return summary



if length == 1:
    print(S)
else:
    print(dfs(0, S, 0))


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

using namespace std;
     
int main(){
    int A,B,C,K,ans;
    cin >> A >> B >> C >> K;

    int D = max((A,B),C);
    if(A==D){
        ans = A*pow(2,K) + B + C;
    }
    else if(B==D){
        ans = B*pow(2,K) + A + C;
    }
    else{
        ans = C*pow(2,K) + A + B;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<string>
#include <set>
#include <cassert>
#include<cmath>
using namespace std;
#define MOD 1000000007
class UnionFind {
	vector<int> data;
public:
	UnionFind(int size) : data(size, -1) { }
	bool unionSet(int x, int y) {
		x = root(x); y = root(y);
		if (x != y) {
			if (data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
		return x != y;
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

int find(vector<long long> &arr, long long obj) {
	if (arr[arr.size() - 1] < obj)return arr.size()-1;
	if (arr[0] > obj)return -1;

	int min = 0; int max = arr.size() - 1;
	for (int i = 0; i < arr.size(); i++) {
		if (arr[min+(max-min) / 2] > obj) {
			max = min + (max - min) / 2;
		}
		else {
			min = min + (max - min) / 2;
		}
		if (max - min == 1) {
			return min;
		}
	}


}

int arr[200020];
int main() {
	int n;
	cin >> n;
	int *p = new int[n];
	int max = 0;
	for (int i = 0; i < n; i++) {
		cin >> p[i];
		p[i];
		arr[p[i] + 1] = arr[p[i]] + 1;
		if (max < arr[p[i]] + 1)max = arr[p[i]] + 1;
	}
	cout << n - max;

	return 0;
}


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

#if MYDEBUG
#include "lib/cp_debug.hpp"
#else
#define DBG(...) ;
#endif

using LL = long long;
constexpr LL LINF = 334ll << 53;
constexpr int INF = 15 << 26;
constexpr LL MOD = 1E9 + 7;

namespace Problem {
using namespace std;

class Solver {
 public:
  int n;
  vector<LL> a;
  Solver(LL n) : n(n), a(n){};

  void solve() {
    for (int i = 0; i < n; ++i) {
      cin >> a[i];
    }
    for (int i = 1; i < n; ++i) {
      a[i] += a[i - 1];
    }
    LL ans = LINF;
    for (int i = 2; i < n - 1; ++i) {
      //[0,i),[i,n)
      LL lsum = a[i - 1];
      LL rsum = a[n - 1] - a[i - 1];
      vector<LL> tmp;
      auto l = lower_bound(a.begin(), a.end(), (lsum + 1) / 2) - a.begin();
      DBG(l)
      if (l > 0 and (abs(lsum - a[l - 1] * 2) < abs(lsum - a[l] * 2))) {
        --l;
      }
      tmp.push_back(a[l]);
      tmp.push_back(lsum - a[l]);
      auto r =
          lower_bound(a.begin(), a.end(), lsum + (rsum + 1) / 2) - a.begin();
      if (r > i and (abs(a[n - 1] - a[r - 1] * 2 + lsum) <
                     abs(a[n - 1] - a[r] * 2 + lsum))) {
        --r;
      }
      DBG(r)
      tmp.push_back(a[r] - lsum);
      tmp.push_back(a[n - 1] - a[r]);
      DBG(tmp)
      sort(tmp.begin(), tmp.end());
      ans = min(ans, tmp[3] - tmp[0]);
    }
    cout << ans << "\n";
  }
};
}  // namespace Problem

int main() {
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(false);
  long long n = 0;
  std::cin >> n;

  Problem::Solver sol(n);
  sol.solve();
  return 0;
}


Measured memory_bytes: 1792
N, M = map(int, input().split())
A = list(map(int, input().split()))

T = 0
for i in range(N):
    T = T + A[i]

ok = 0
for i in range(N):
    if A[i] >=  T / 4 / M:
        ok = ok + 1

if ok >= M:
    print("Yes")
else:
    print("No")

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

using namespace std;

#define ll long long

int n, m;
vector < pair<ll,ll> > v;

int main () {

	ios_base::sync_with_stdio(false); cin.tie(NULL);

	cin >> n >> m;

	for (int i = 0; i < n; ++i) {
		ll a, b;
		cin >> a >> b;
		v.push_back({a, b});
	}

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

	ll value = 0;

	for (int i = 0; i < n; ++i) {
		if (m <= 0) break;

		ll val = v[i].first;
		ll qtd = v[i].second;

		value += val * (ll)min((ll)m, (ll)qtd);
		m -= qtd;

	}	

	cout << value << '\n';


	return 0;
}


Measured memory_bytes: 2420
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
    int T;
    cin>>T;
    ll N, A, B, C, D;
    ll ans[T];
    for(int i=0;i<T;++i){
        cin>>N>>A>>B>>C>>D;
        priority_queue<pair<ll, ll>, vector<pair<ll, ll> >, greater<pair<ll, ll> > > que;
        map<ll, int> amap;
        que.push(mp(0, N));
        pair<ll, ll> state;
        ll coin, n;
        while(!que.empty()){
            state = que.top();que.pop();
            coin = state.fi;
            n = state.se;
            if(n==0) {
                ans[i] = coin;
                break;
            }
            if(amap[n]>0) continue;
            amap[n]++;
            if(n%2==0){
                if(A%D==0){
                    if(A/D>n/2){
                        que.push(mp(coin+n/2*D, n/2));
                    }
                    else{
                        que.push(mp(coin+A, n/2));
                    }
                }
                else{
                    if(A/D>=n/2){
                        que.push(mp(coin+n/2*D, n/2));
                    }
                    else{
                        que.push(mp(coin+A, n/2));
                    }
                }
            }
            else{
                que.push(mp(coin+D, n+1));
                que.push(mp(coin+D, n-1));
            }
            if(n%3==0){
                if(B%D==0){
                    if(B/D>n/3*2){
                        que.push(mp(coin+n/3*2*D, n/3));
                    }
                    else{
                        que.push(mp(coin+B, n/3));
                    }
                }
                else{
                    if(B/D>=n/3*2){
                        que.push(mp(coin+n/3*2*D, n/3));
                    }
                    else{
                        que.push(mp(coin+B, n/3));
                    }
                }
            }
            else {
                que.push(mp(coin+n%3*D, n-n%3));
                que.push(mp(coin+(3-n%3)*D, n+(3-n%3)));
            }
            if(n%5==0){
                if(C%D==0){
                    if(C/D>n/5*4){
                        que.push(mp(coin+n/5*4*D, n/5));
                    }
                    else{
                        que.push(mp(coin+C, n/5));
                    }
                }
                else{
                    if(C/D>=n/5*4){
                        que.push(mp(coin+n/5*4*D, n/5));
                    }
                    else{
                        que.push(mp(coin+C, n/5));
                    }
                }
            }
            else {
                que.push(mp(coin+n%5*D, n-n%5));
                que.push(mp(coin+(5-n%5)*D, n+(5-n%5)));
            }
        }
    }
    for(int i=0;i<T;++i){
        cout<<ans[i]<<endl;
    }
}


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

int main(){
  int n,deli;
  cin >> n;
  vector<int> a(n-1,0),b(n,0),c(n-1,0);
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  deli=a[0]+a[n-2];
  for(int i=i;i<n-1;i++){
    deli+=min(a[i],a[i-1]);
  }
  cout << deli << endl;
  

}
             
            
          
      
    


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n)     for (int i = 0; i < (int)(n); ++i)
#define rep1(i, n)    for (int i = 1; i <= (int)(n); ++i)
#define irep(i, a, n) for (int i = a; i < (int)(n); ++i)
#define rrep(i, n)    for (int i = (int)(n) - 1; i >= 0; --i)
#define rrep1(i, n)   for (int i = (int)(n); i >= 1; --i)
#define allrep(V, v)  for (auto &&V : v)
#define all(x)        (x).begin(), (x).end()
using lint = long long;
constexpr int    INF  = 1 << 30;
constexpr lint   INFL = 1LL << 62;
constexpr int    MOD  = 1e9 + 7;
constexpr double EPS  = 1e-9;
using namespace std;

using Weight = int;
struct Edge {
  int src, dst;
  Weight weight;
  Edge(void) {}
  Edge(int src_val, int dst_val, Weight weight_val) : src(src_val), dst(dst_val), weight(weight_val) {}
};
using Edges = std::vector<Edge>;
using Graph = std::vector<Edges>;

Graph edges_to_graph(const Edges &edges, const int vertices_num, const bool directed = true) {
  Graph ret(vertices_num);
  for (const auto &e : edges) {
    ret[e.src].push_back(e);
    if (!directed) ret[e.src].push_back(Edge(e.dst, e.src, e.weight));
  }
  return ret;
}

void dfs(Graph &g, vector<lint> &check, int v, lint cnt) {
  if (check[v] <= cnt) return;
  check[v] = cnt;
  for (const auto es : g[v]) {
    dfs(g, check, es.dst, cnt + 1);
  }
}

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

  int n, m;
  cin >> n >> m;
  Edges edges(3 * m);
  rep (i, m) {
    int s, d;
    cin >> s >> d;
    edges[i].src = s;
    edges[i].dst = d + n;
    edges[i + m].src = s + n;
    edges[i + m].dst = d + 2 * n;
    edges[i + 2 * m].src = s + 2 * n;
    edges[i + 2 * m].dst = d;
  }
  int s, t;
  cin >> s >> t;
  Graph graph = edges_to_graph(edges, 3 * n + 1);
  vector<lint> check(3 * n + 1, INFL);
  queue<pair<int, int>> que;
  que.push({s, 0});
  while (!que.empty()) {
    int v = que.front().first, cnt = que.front().second;
    que.pop();
    if (check[v] <= cnt) continue;
    check[v] = cnt;
    for (const auto es : graph[v]) {
      que.push({es.dst, cnt + 1});
    }
  }
  cout << (check[t] != INFL ? check[t] / 3 : -1) << endl;
  return 0;
}

Measured memory_bytes: 22528
N,K = list(map(int,input().split()))

poss = 0
posssum = []
for i in range(1,N+1):
	point = i
	cou = 0
	while point <= K-1:
		point = 2*point
		cou=cou+1
#	print('cou=',cou)
	poss = 1.0/float(N) * 0.5 **(cou)
	posssum.append(poss)
#	print(poss)
print(sum(posssum))


Measured memory_bytes: 6296
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define all(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;

ll N;
vll A,B;

int solve(int i,int prevkill)
{
    int kill = min(A[i],B[i]) - prevkill;
    int nextkill = min(B[i]-kill,A[i+1]);
    if(i >= N-1)
    {
        return kill + nextkill;
    }
   
    return (solve(i+1,nextkill) + kill + nextkill);
}

int main()
{
    cin>>N;
    vll kill(N),overkill(N);
    ll ans = 0;
    A.resize(N+1);
    B.resize(N);
    rep(i,N+1)
    {
        cin>>A[i];
    }
    rep(i,N)
    {
        cin>>B[i];
    }
  //  cout<<solve(0,0);
  kill[0] = min(A[0],B[0]);
  overkill[0] =  min(B[0]-kill[0],A[1]);
  ans += kill[0] + overkill[0];
    for(int i = 1;i<N;i++)
    {
        ll res1 = A[i]-(overkill[i-1]);
        kill[i] = min(B[i],res1);
        overkill[i] = min(B[i]-kill[i],A[i+1]);
        ans += kill[i] + overkill[i];
    }
    cout<<ans;
}

Measured memory_bytes: 3456
#include "bits/stdc++.h"
using namespace std;
#define PB push_back
#define MP make_pair
#define REP(i,n) for(int i=0;i<(n);i++)

int to_i(string s){
    bool f=false;
    int res=0;
    REP(i,s.size()){
        if(s[i]=='-'){
            f=true;
        }else{
            res*=10;
            res+=(s[i]-'0');
        }
    }
    if(f)return res*(-1);
    return res;
}

int N;
int A[1000];
bool f[1000];
int main(){
    while(1){
        cin>>N;
        if(N==0)break;
        REP(i,N){
            string s;
            cin>>s;
            if(s=="x")f[i]=true;
            else{
                f[i]=false;
                A[i]=to_i(s);
            }
        }
        bool ok=true;
        int vmin=-2e9,vmax=2e9;
        REP(i,N-1){
            if(f[i]&&f[i+1]){
                ok=false;
            }
        }
        if(!ok){
            cout<<"none"<<endl;
            continue;
        }
        REP(i,N){
            if(f[i]){
                if(i%2){
                    if(i!=0)vmin=max(vmin,A[i-1]+1);
                    if(i!=N-1)vmin=max(vmin,A[i+1]+1);
                }else{
                    if(i!=0)vmax=min(vmax,A[i-1]-1);
                    if(i!=N-1)vmax=min(vmax,A[i+1]-1);
                }
            }else{
                if(i%2){//even
                    if(i!=0)if(!f[i-1])if(A[i-1]>=A[i])ok=false;
                    if(i!=N-1)if(!f[i+1])if(A[i+1]>=A[i])ok=false;
                }else{
                    if(i!=0)if(!f[i-1])if(A[i-1]<=A[i])ok=false;
                    if(i!=N-1)if(!f[i+1])if(A[i+1]<=A[i])ok=false;
                }
            }
        }
        if(!ok||vmax<vmin){
            cout<<"none"<<endl;
        }else if(vmax==vmin){
            cout<<vmax<<endl;
        }else{
            cout<<"ambiguous"<<endl;
        }
    }
}

Measured memory_bytes: 3160
#include <bits/stdc++.h>
#include <chrono>
#include <regex>
using namespace std;
#define len(_x) (sizeof((_x)) / sizeof(_x)[0])
#define ll long long
#define fastIO  ios_base::sync_with_stdio(false); cin.tie(0); 
#define Ichar(_x) char _x;scanf("%c",&_x);
#define Iint(_x) int _x;scanf("%d",&_x); 
#define Ill(_x)  ll _x;scanf("%lld",&_x);
#define inc(a,b,x)(x)>a && (x)<b	
#define incE(a,b,x)(x)>=a && (x)<=b	
#define fileIO 	freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);


ll modo(ll a)
{
	return a % (int)(1e9+7);
}



int arr[100000];
int main()
{
	Iint(a);
	Iint(a1);
	Iint(a2);
	std::cout << ((a1 - a2) % 2 == 0 ? "Alice" : "Borys");



}





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


int main(){
    int n;
    cin>>n;
    string s;
    map<string,int> poll;
    for(int i=0;i<n;i++){
        cin>>s;
        poll[s]+=1;
    }
    int maxi=0;
    for(auto j: poll)
    maxi=max(maxi,j.second);
    for(auto k: poll){
        if(maxi==k.second)
        cout<<k.first<<endl;
    }
    
  
    return 0;
}


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

int64_t calcGCD(int64_t a,int64_t b){
    int64_t p = a;
    int64_t q = b;
    int64_t c = a%b;
    while(c != 0){
        p = q;
        q = c;
        c = p%q;
    }
    return q;
}

int main(){
  int64_t n;
  string s;
  cin >> n >> s;
  int64_t count = 0; 
  rep(i,n){
    if(i <= n-3 && s.at(i) == 'A' && s.at(i+1) == 'B' && s.at(i+2) == 'C'){
      count++;
    }
  }
  cout << count << endl;
      
}

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

int main() {
  int A, B; cin >> A >> B;
  
  int ans = 0;
  
  if (A + B > A - B) ans = A + B;
  else ans = A -B;
  
  if (ans < A * B) ans = A * B;
  
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <numeric>
#include <map>
#include <vector>
#include <cmath>
#include <iostream>
#include <cassert>

using namespace std;
#define REP(i,n) for(int i=0;i<(int)n;i++)
#define ALL(s) s.begin(),s.end()
int main() {
	while(true){
		int n,l;cin >> n >> l;if(n==0)break;
		vector<int> dirL(n),pos(n);
		vector<int> map(n);iota(ALL(map),1);
		REP(i,n){
			char d;int p;cin >> d >> p;
			if(d=='L')dirL[i]=true;
			pos[i]=p;
		}

		vector<int> ndirL,npos;
		vector<int> nmap;
		int t=0;int last=-1;
		while(n>0){
			t++;
			// move
			REP(i,n){
				if(dirL[i])pos[i]--;
				else pos[i]++;
			}
			REP(i,n-1)if(pos[i]>pos[i+1]){
				swap(dirL[i],dirL[i+1]);
				swap(pos[i],pos[i+1]);
				swap(map[i],map[i+1]);
			}
			// rot
			REP(i,n-1)if(pos[i]==pos[i+1]){
				dirL[i]=!dirL[i];
				dirL[i+1]=!dirL[i+1];
			}
			//remove
			REP(i,n)if(1<=pos[i] && pos[i]<l){
				ndirL.push_back(dirL[i]);npos.push_back(pos[i]);nmap.push_back(map[i]);
			}
			//end
			if(npos.size()==0){
				REP(i,n)if(pos[i]==0)last=map[i];
				if(last==-1)REP(i,n)if(pos[i]==l)last=map[i];
				break;
			}
			//next
			dirL=ndirL;pos=npos;map=nmap;
			ndirL.clear();npos.clear();nmap.clear();
			n=pos.size();
		}
		assert(last!=-1);
		cout << t <<" "<< last <<endl;
	}
}

Measured memory_bytes: 1216
#include <stdio.h>
int main() {
  int n,a,b,c,d,e;
  scanf("%d",&n);
  a=n/1000;
  b=n/100-a*10;
  c=n/10-a*100-b*10;
  d=n-a*1000-b*100-c*10;
  e=b+c+d;
  if (a+e==7) {
    printf("%d+%d+%d+%d=7\n",a,b,c,d);
  } else if (a-e==7) {
    printf("%d-%d-%d-%d=7\n",a,b,c,d);
  } else if (a+e-2*d==7) {
    printf("%d+%d+%d-%d=7\n",a,b,c,d);
  } else if (a+e-2*c==7) {
    printf("%d+%d-%d+%d=7\n",a,b,c,d);
  } else if (a+e-2*b==7) {
    printf("%d-%d+%d+%d=7\n",a,b,c,d);
  } else if (a-e+2*d==7) {
    printf("%d-%d-%d+%d=7\n",a,b,c,d);
  } else if (a-e+2*c==7) {
    printf("%d-%d+%d-%d=7\n",a,b,c,d);
  } else {
    printf("%d+%d-%d-%d=7\n",a,b,c,d);
  }
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <map>
#include <utility>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>

#define REP(i,a,n) for(int i=a;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define REV(i,a,n) for(int i=n;i>=a;--i)
#define all(e) e.begin(),e.end()
#define rall(e) e.rbegin(),e.rend()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define show(n) cerr<<#n<<" = "<<n<<endl
#define shows(n) for(auto z:n){cerr<<z<<", ";}cerr<<endl

//ここからAtCoder向けdefine
#define yes cout << "Yes" << endl
#define no cout << "No" << endl

using namespace std;

using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using pint = pair<int,int>;

const int INF = ~(1 << 31);

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b, c;
    cin >> a >> b >> c;

    if(a + b >= c){
        yes;
    }else{
        no;
    }

    return 0;
}

Measured memory_bytes: 888
#include<stdio.h>
int main(void){
	int n,i,sum=0,t;
    scanf("%d",&n);
    t=n;
    while(t){
        sum+=t%10;
        t/=10; 
    }
    if(n%sum)
        printf("No\n");
    else
        printf("Yes\n");
	return 0;
}

Measured memory_bytes: 128
local _i={}
for i=1,2 do
    local a=io.read()
    _i[i]={}
    for s in string.gmatch(a,"%S+")do
        _i[i][#_i[i]+1]=tonumber(s)
    end
end

local n=_i[1][1]
local h=_i[2]
local rs=h[1]

for i=2,n do
  if(h[i-1]<h[i])then
    rs=rs+(h[i]-h[i-1])
  end
end
print(rs)

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>
#include <bitset>
#include <cstdint>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

const i64 mod = 1e9 + 7;
i64 n, m, dp[2001][2001];
vector<i64> s, t;
int main() {
  cin >> n >> m;
  read_n(s, n, 1);
  read_n(t, m, 1);

  dp[0][0] = 1;
  for (i64 i = 0; i <= n; ++i) {
    for (i64 j = 0; j <= m; ++j) {
      if (i == 0 || j == 0) dp[i][j] = 1;
      else {
        dp[i][j] = mod + dp[i - 1][j] + dp[i][j - 1];
        if (s[i] != t[j]) dp[i][j] -= dp[i - 1][j - 1];
        dp[i][j] %= mod;
      }
    }
  }
  cout << dp[n][m] << '\n';
  return 0;
}



Measured memory_bytes: 31616
#include <algorithm>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
/* clang-format on */

int main() {
  int N, M, Q;
  while (cin >> N >> M >> Q) {
    vec<int, 2> sum = make_v(N, N, 0);
    for (int i = 0; i < M; i++) {
      int L, R;
      cin >> L >> R;
      --L;
      --R;
      ++sum[L][R];
    }
    for (int i = 0; i < N; i++) {
      for (int j = 1; j < N; j++) {
        sum[i][j] += sum[i][j - 1];
      }
    }
    for (int t = 0; t < Q; t++) {
      int p, q;
      cin >> p >> q;
      --p;
      --q;
      int res = 0;
      for (int i = p; i <= q; i++) {
        res += sum[i][q];
      }
      cout << res << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 1920
def main():
    x = int(input())
    sosuu = [2]
    A = 200000
    if x == 2:
        print(2)
    else:
        for L in range(3, A, 2):
            for L2 in sosuu:
                if L % L2 == 0:
                    break
            else:
                sosuu.append(L)
                if L >= x:
                    print(L)
                    break
        
if __name__ == '__main__':
    main()

Measured memory_bytes: 39792
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<iomanip>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1e9+7
#define LINF (long long)4e18



int main(){
    int N; cin >> N;
    vector<long long> A(N);
    rep(i,N){
        cin >> A[i];
        A[i] -= i;
    }
    sort(A.begin(),A.end());
    long long b = 0;
    if(N % 2 == 0)b = (A[N/2] + A[N/2-1])/2;
    else b = A[(N-1)/2];
    long long ans = 0;
  	rep(i,N){
      ans += abs(A[i]-b);
    }
  	cout << ans << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " is " << x << endl
#define int ll

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;

const int INF = 1e9 + 7, N = 1e5 + 7;

int dp[N], up[N], m;
vi G[N], pre[N], suf[N];

void dfs(int u, int p = -1) {
	dp[u] = 1;
	for(int v:G[u]) if(v != p) {
		dfs(v, u);
		dp[u] = dp[u] * (dp[v] + 1) % m;
	}
	pre[u].resize(G[u].size());
	suf[u].resize(G[u].size());
	for(int i=0;i<(int)G[u].size();i++)
		pre[u][i] = (i ? pre[u][i-1] : 1) * (G[u][i] == p ? 1 : dp[G[u][i]] + 1) % m;
	for(int i=(int)G[u].size()-1;i>=0;i--)
		suf[u][i] = (i < (int)G[u].size()-1 ? suf[u][i+1] : 1) * (G[u][i] == p ? 1 : dp[G[u][i]] + 1) % m;

}

void dfs1(int u, int p = -1) {
	if(p == -1) up[u] = 1;
	for(int i=0;i<(int)G[u].size();i++) if(G[u][i] != p) {
		int v = G[u][i];
		up[v] = (1 + up[u] * (i ? pre[u][i-1] : 1) % m * (i == (int)G[u].size()-1 ? 1 : suf[u][i+1]) % m) % m;
		dfs1(v, u);
	}
}

signed main()
{
	IO_OP;
	
	int n;
	cin >> n >> m;
	for(int i=0;i<n-1;i++) {
		int u, v;
		cin >> u >> v;
		G[u].PB(v);
		G[v].PB(u);
	}	
	dfs(1);
	dfs1(1);
	for(int i=1;i<=n;i++)
		cout << dp[i] * up[i] % m << endl;
	
}





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

int sum[5005][5005];
int main() {
	int n, m; scanf("%d%d", &n, &m);
	rep(i, m) {
		int a, b, x; scanf("%d%d%d", &a, &b, &x);
		sum[a][b]++; sum[a][b + 1]--;
		sum[a + x + 1][b]--; sum[a + x + 2][b + 1]++;
		sum[a + x + 1][b + x + 2]++; sum[a + x + 2][b + x + 2]--;
	}
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= i + 1; j++)sum[i][j] += sum[i][j - 1];
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= i + 1; j++)sum[i][j] += sum[i - 1][j];
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= i + 1; j++)sum[i][j] += sum[i - 1][j - 1];
	int cnt = 0;
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= i + 1; j++)cnt += (sum[i][j] > 0);
	printf("%d\n", cnt);
}

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

int main() {
  int n, m, x, y;
  cin >> n >> m >> x >> y;
  vector<int> xv(n);
  vector<int> yv(m);
  rep(i, n) cin >> xv[i];
  rep(i, m) cin >> yv[i];
  xv.push_back(x);
  yv.push_back(y);
  int xmax = *max_element(xv.begin(), xv.end());
  int ymin = *min_element(yv.begin(), yv.end());
  if(xmax < ymin) cout << "No War" << endl;
  else cout << "War" << endl;
  return 0;
}
    

Measured memory_bytes: 3600
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <string.h>
#include <cmath>
using namespace std;

struct edge{int to, cap, rev;};

vector< vector<edge> > G(300);
int level[300];
int iter[300];
int INF = 100000000;

void bfs(int s){
  memset(level, -1, sizeof(level));
  queue<int> que;
  level[s] = 0;
  que.push(s);
  while(!que.empty()){
    int v = que.front();
    que.pop();
    for(int i = 0; i < G[v].size(); ++i){
      edge &e = G[v][i];
      if(e.cap > 0 && level[e.to] < 0){
        level[e.to] = level[v] + 1;
        que.push(e.to);
      }
    }
  }
}

int dfs(int v, int t, int f){
  if(v == t) return f;
  for(int &i = iter[v]; i < G[v].size(); ++i){
    edge &e = G[v][i];
    if(e.cap > 0 && level[v] < level[e.to]){
      int d = dfs(e.to,t,min(f,e.cap));
      if(d > 0){
        e.cap -= d;
        G[e.to][e.rev].cap += d;
        return d;
      }
    }
  }
  return 0;
}

int max_flow(int s, int t){
  int flow = 0;
  for(;;){
    bfs(s);
    if(level[t] < 0) return flow;
    memset(iter,0,sizeof(iter));
    int f;
    while((f = dfs(s,t,INF)) > 0){
      flow += f;
    }
  }
}

int main(){
  int N, M;
  cin >> N >> M;
  int a, b;
  map<pair<int,int>,int> mp;
  for(int i = 0; i < M; ++i){
    cin >> a >> b;
    --a;--b;
    mp[make_pair(a,b)] = i+1;
    mp[make_pair(b,a)] = -i-1;
    G[a].push_back((edge){b,1,G[b].size()});
    G[b].push_back((edge){a,0,G[a].size()-1});
    G[b].push_back((edge){a,1,G[a].size()});
    G[a].push_back((edge){b,0,G[b].size()-1});
  }
  int s, t;
  cin >> s >> t;
  --s;--t;
  cout <<  max_flow(s,t) << endl;
  set<int> V;
  for(int i = 0; i < N; ++i){
    for(int j = 0; j < G[i].size(); ++j){
      edge e = G[i][j];
      if(e.cap == 0 && mp[make_pair(i,e.to)] < 0){
        V.insert(abs(mp[make_pair(i,e.to)]));
      }
    }
  }
  cout << V.size() << endl;
  for(set<int>::iterator itr = V.begin(); itr != V.end(); ++itr) cout << *itr << endl;
  return 0;
}



Measured memory_bytes: 3396
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#pragma warning(disable:4996)
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;

using namespace std;

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

int main(int argc, char* argv[])
{
    long n;
    scanf("%ld", &n);
    vector<long> a(n);
    long i;
    for(i=0; i<n; i++) {
        scanf("%ld", &a[i]);
    }
    sort(a.begin(), a.end());

    for(i=0; i<n; i++) {
        if(a[i]>=0) break;
    }
    long k = i/2*2;

    ll sum0=0;
    for(i=0; i<n; i++) {
        sum0 += (i<k? (-a[i]): a[i]);
    }

    ll sum1=0;
    if(k+2<=n) {
        for(i=0; i<n; i++) {
            sum1 += (i<(k+2)? (-a[i]): a[i]);
        }
    }
    printf("%lld\n", MAX(sum0,sum1));

    return 0;
}


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

using namespace std;

int main() {
  string s;
  cin >> s;
  bool good = true;
  for (int i = 0; i < (int) s.size() - 1; i++) {
    if (s[i] == s[i + 1]) {
      good = false;
    }
  }
  cout << (good ? "Good\n" : "Bad\n");
  return 0;
}

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

#define ll long long

int main() {

#ifndef ONLINE_JUDGE 
	freopen("input.text", "r", stdin); 
	freopen("output.text", "w", stdout); 
#endif
	ios_base::sync_with_stdio();
    cin.tie(0);
    cout.precision(10);
    
    string s;
    cin>>s;

    for(int i = 0; i < 3; i++)
    {
    	cout<<s[i];
    }

    


}

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

int Total(int D,int A_i){
    
    int i= 0,c =0;
    while(1){
        if(A_i*i + 1 > D) break;
         i++; c++;
    }
    return c;
}

int main() {
    
    int N,D,X;
    cin >> N >> D >> X;
    
    for(int i=0;i<N;i++){
        int A_i;
        cin >> A_i;
        X += Total(D,A_i);
    }
    
    cout << X << endl;
}

Measured memory_bytes: 3540
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define pi 3.141592653589793238
#define int long long
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

// mt19937 gen_rand_int(chrono::steady_clock::now().time_since_epoch().count());
// mt19937_64 gen_rand_ll(chrono::steady_clock::now().time_since_epoch().count());
// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

long long power(long long a, long long b,long long m) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a %m;
        a = a * a %m;
        b >>= 1;
    }
    return res;
}

int fac[500005];
const int mod=1e9+7;
int dp[500005];
int ncr(int n,int r)
{
    if(n<r)
        return 0;
    int z=fac[n];
    z=(z*power(fac[n-r],mod-2,mod))%mod;
    z=(z*power(fac[r],mod-2,mod))%mod;
    return z;
}

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

#ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
    freopen ("INPUT.txt" , "r" , stdin);
    freopen ("OUTPUT.txt" , "w" , stdout);
    }
#endif  

    fac[0]=1;
    for(int i=1;i<=500000;i++)
        fac[i]=(fac[i-1]*i)%mod;
    int n,m;
    cin>>n>>m;

    int tot=0;
    for(int i=n;i>=0;i--)
    {
        int z=(ncr(m,i)*ncr(n,i))%mod*fac[i]%mod*ncr(m-i,n-i)%mod*ncr(m-i,n-i)%mod*fac[n-i]%mod*fac[n-i]%mod;
        dp[i]=z;
    }
    tot=0;
    for(int i=0;i<=n;i++)
    {
        if(i&1)
            tot+=mod-dp[i];
        else
            tot+=dp[i];
        tot%=mod;
    }
    cout<<tot<<'\n';

} 
    


Measured memory_bytes: 11480
#-*-coding:utf-8-*-

def main():
    a = input()
    b = input()
    c = input()

    position = a[0]
    a = a[1:]
    while True:
        if position == 'a':
            if len(a) == 0:
                print('A')
                break
            else:
                position = a[0]
                a = a[1:]
        elif position == 'b':
            if len(b) == 0:
                print('B')
                break
            else:
                position = b[0]
                b = b[1:]
        elif position == 'c':
            if len(c) == 0:
                print('C')
                break
            else:
                position = c[0]
                c = c[1:]
        
if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b!=0?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}

int main(){
    ll x;
    cin>>x;
    while(1){
        bool flag=1;
        for(ll i=2;i*i<x;i++){
            if(x%i==0){
                flag=0;
                break;
            }
        }
        if(flag==1){
            cout<<x<<endl;
            return 0;
        }
        x++;
    }
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author hakamada
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ABC105_1 solver = new ABC105_1();
        solver.solve(1, in, out);
        out.close();
    }

    static class ABC105_1 {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int NN = in.nextInt();
            int KK = in.nextInt();

            if ((NN % KK) > 0) {
                out.println(1);
            } else out.println(0);

        }

    }
}



Measured memory_bytes: 21076
#include<bits/stdc++.h>
using namespace std ;
const int maxn = 100 + 10 ;
int a[maxn] , sum ;
int main()
{
	int n ;
	cin >> n ;
	for ( int i = 0 ; i< 2*n ; i++) cin >> a[i] ;
	sort ( a , a+2*n ) ;
	for ( int i = 0; i< 2*n ; i+=2 )
		sum += a[i] ;
	cout << sum << endl;

}

Measured memory_bytes: 256
from sys import stdin
from sys import setrecursionlimit
from collections import Counter, deque, defaultdict
from math import floor, ceil
from bisect import bisect_left
from itertools import combinations
setrecursionlimit(100000)

INF = int(1e10)
MOD = int(1e9 + 7)

def main():
    from builtins import int, map
    D = int(input())
    C = list(map(int, input().split()))
    S = [list(map(int, input().split())) for _ in range(D)]
    V = [int(input()) for _ in range(D)]
    last = [0] * 26
    score = 0
    for i in range(D):
        j = V[i] - 1
        last[j] = i + 1
        for k in range(26):
            score -= C[k] * (i + 1 - last[k])
        score += S[i][j]
        print(score)

if __name__ == '__main__':
    main()

Measured memory_bytes: 69012