akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <ctime>
 
using namespace std;
 
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)
 
long gcd(long a, long b){
	if (a%b==0){
		return b;
	}
	else{
		return gcd(b,a%b);
	}
}
 
long lcm(long a, long b){
	return (a*b) / gcd(a,b);
}
 
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a < b) { a = b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a > b) { a = b; return 1; } return 0; }
 
typedef long long ll;
 
const ll INF = 1ll<<60;
const ll MOD = 1000000007;
const double EPS = 1e-10;

int x[200003];
int a[200003];

int main(){
	int n;
	
	cin >> n;
	
	REP(i,n){
		cin >> x[i];
		
		a[i] = x[i];
	}
	
	sort(a, a+n);
	
	REP(i,n){
		if (x[i] > a[(n-1)/2]) cout << a[(n-1)/2] << endl;
		else cout << a[n/2] << endl;
	}
	
	return 0;
}

Measured memory_bytes: 3712
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX_N = 100005;
int N, M,t;
ll ans;
priority_queue<double>pq;
int A[MAX_N];
int main(void)
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> N >> M;
	for (int i = 0; i < N; i++)
	{
		cin >> t;
		pq.push(t);
	}
	for (int i = 0; i < M; i++)
	{
		pq.push(pq.top() / 2);
		pq.pop();
	}
	for (int i = 0; i < N; i++)
	{
		ans += (int)pq.top();
		pq.pop();
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1400
#include <iostream>
#include <string>
using namespace std;
int main(){
    int A, B;
    cin >> A >> B;
    string S;
    cin >> S;

    bool ans = true;
    for(int i=0; i<=A+B; i++){
        if(A==i){
            if(S[i]!='-'){
                ans = false;
                break;
            }
        }else{
            if(S[i]<'0' || '9'<S[i]){
                ans = false;
                break;
            }
        }
    }

    if(ans) cout << "Yes\n";
    else cout << "No\n";
    return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include  <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include <stdlib.h>
#include<stdio.h>
#include <queue>
#include<map>
#include <sstream>
#include<set>
#include<stack>

//#include<bits/stdc++.h>


using namespace std;

int main() {
	int n;
	cin >> n;
	
	cout << pow(n, 3) << endl;

	return 0;


}

Measured memory_bytes: 512
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9 + 7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))


def main():
    n,m = LI()
    a = [[c=='#' for c in S()] for _ in range(n)]
    b = [[0] * m for _ in range(n)]
    c = [[0] * m for _ in range(n)]
    for i in range(n):
        j = 0
        ai = a[i]
        while j < m:
            if ai[j]:
                j += 1
                continue
            k = j+1
            while k < m and not ai[k]:
                k += 1
            s = k - j
            for l in range(j,k):
                b[i][l] = s
            j = k

    for i in range(m):
        j = 0
        while j < n:
            if a[j][i]:
                j += 1
                continue
            k = j+1
            while k < n and not a[k][i]:
                k += 1
            s = k - j
            for l in range(j,k):
                c[l][i] = s
            j = k

    r = 0
    for i in range(n):
        bi = b[i]
        ci = c[i]
        for j in range(m):
            t = bi[j] + ci[j] - 1
            if r < t:
                r = t

    return r


print(main())



Measured memory_bytes: 151768
#include<stdio.h>
int main(void){
	int w,n;
	int x;
	int i;
	int a,b;
	int c[31];
	scanf("%d",&w);
	for(i=0;i<w;i++){
		c[i]=i+1;
	}
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d,%d",&a,&b);
		x=c[a-1];
		c[a-1]=c[b-1];
		c[b-1]=x;
	}
	for(i=0;i<w;i++){
		printf("%d\n",c[i]);
	}
	return 0;
}

Measured memory_bytes: 592
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdint>
#include <unordered_map>
#include <cmath>
#include <cassert>
#include <cstring>

class SolutionAlign {
public:
    int64_t test(int n, std::vector<int> values, std::vector<int> order) {
        std::vector<int> result(n);

        for (int i = 0; i < n; i++)
            result[order[i]] = values[i];

        int64_t ans = 0;
        for (int i = 1; i < n; i++)
            ans += std::abs(result[i] - result[i - 1]);
        return ans;
    }

    void solve(std::istream& in, std::ostream& out) {
        int n;
        in >> n;
        std::vector<int> values(n);
        for (int& v : values)
            in >> v;
        std::sort(values.begin(), values.end());

        std::vector<int> order;
        for (int i = 1; i < n; i += 2) {
            order.push_back(i);
        }
        order.push_back(0);
        if (n % 2 != 0)
            order.push_back(n - 1);
        for (int i = 2; i < n - 1; i += 2) {
            order.push_back(i);
        }
        auto ans = test(n, values, order);
        std::reverse(values.begin(), values.end());
        ans = std::max(ans, test(n, values, order));

        out << ans << std::endl;
    }
};

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

    using Solution = SolutionAlign;

    int tests = 1;
//    std::cin >> tests;
    for (int test = 0; test < tests; ++test) {
        Solution solution;
        solution.solve(std::cin, std::cout);
    }

    return 0;
}

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

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forn1(i,n) for (int i = 1; i <= int(n); i++)
#define popcnt __builtin_popcount
#define ffs __builtin_ffs

using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pil = pair<int,ll>;
using pll = pair<ll,ll>;
template <typename T> using vec = vector<T>;
using vi = vec<int>;
using vl = vec<ll>;
template <typename T> using que = queue<T>;
template <typename T> using deq = deque<T>;

template <typename T> T id(T b) {return b;};
template <class It> bool all(It f,It l){return std::all_of(f,l,id<bool>);}
template <class It> bool any(It f,It l){return std::any_of(f,l,id<bool>);}
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }
constexpr ll TEN(int n) { if (n == 0) return 1LL; else return 10LL*TEN(n-1); }

int n;
string s;

int main()
{
  fastio();

  int ans = 0;
  cin >> n >> s;
  forn(i,n) {
    int j = 0, k = 0;
    while (i + k < n) {
      while (i + k < n && s[k] == s[i+k] && i+j > k) k++;
      chmax(ans,k-j);
      k++, j = k;
    }
  }

  cout << ans << endl;

  return 0;
}


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

#ifdef NON_SUBMIT
#define TEST(n) (n)
#define tout cerr
#else
#define TEST(n) ((void)0)
#define tout cin
#endif

using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	TEST(freopen("input.txt","r",stdin));
	TEST(freopen("output.txt","w",stdout));
	TEST(freopen("debug.txt","w",stderr));
	string S;
	cin>>S;
	cout<<string(&S[0],&S[3])<<'\n';
	return 0;
}

Measured memory_bytes: 3652
// Standard I/O
#include <iostream>
#include <sstream>
#include <cstdio>
// Standard Library
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
// Template Class
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
// Container Control
#include <algorithm>

using namespace std;

#define rep( i, n ) for( int i = 0; i < n; ++i )
#define irep( i, n ) for( int i = n-1; i >= 0; --i )
#define reep( i, s, n ) for ( int i = s; i < n; ++i )
#define ireep( i, n, s ) for ( int i = n-1; i >= s; --i )
#define foreach(itr, x) for( typeof(x.begin()) itr = x.begin(); itr != x.end(); ++itr)

#define mp make_pair
#define pb push_back
#define eb emplace_back
#define all( v ) v.begin(), v.end()
#define fs first
#define sc second
#define vc vector

// for visualizer.html
double SCALE = 1.0;
double OFFSET_X = 0.0;
double OFFSET_Y = 0.0;
#define LINE(x,y,a,b) cerr << "line(" << SCALE*(x) + OFFSET_X << ","	\
	<< SCALE*(y) + OFFSET_Y << ","										\
	<< SCALE*(a) + OFFSET_X << ","										\
	<< SCALE*(b) + OFFSET_Y << ")" << endl;
#define CIRCLE(x,y,r) cerr << "circle(" << SCALE*(x) + OFFSET_X << ","	\
	<< SCALE*(y) + OFFSET_Y << ","										\
	<< SCALE*(r) << ")" << endl;

typedef long long ll;
typedef complex<double> Point;

typedef pair<int, int> pii;
typedef pair<int, pii> ipii;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector< vector<int> > vii;
typedef vector< vector<double> > vdd;

typedef vector<int>::iterator vi_itr;

const int IINF = 1 << 28;
const double INF = 1e30;
const double EPS = 1e-10;
const double PI = acos(-1.0);

// Direction : L U R D
const int dx[] = { -1, 0, 1, 0};
const int dy[] = { 0, -1, 0, 1 };

int main()
{
	int N;
	ll A[100000];

	cin >> N;
	rep(i, N) cin >> A[i];
	
	ll min_val = 1, ans = 0;
	rep(i, N){
		ll c = (A[i]-1)/min_val;
		ans += c;
		if( c != 0 ){
			if( min_val == 1 ){
				A[i] -= c * min_val;
			}
			else{
				A[i] -= (c-1)*min_val;
				A[i] = min_val-1;
			}
		}
		min_val = max(A[i]+1, min_val);

		// rep(j, N){
		// 	cout << A[j] << " ";
		// }
		// cout << endl;
	}
	cout << ans << endl;
}


Measured memory_bytes: 1152
import sys
input = sys.stdin.readline

n, m, p = map(int,input().split())
b = list(map(int,input().split()))
cnt = 0
for i in range(n):
  sums = p
  a = list(map(int, input().split()))
  for j in range(m):
    sums += a[j]*b[j]
  if sums>0:
    cnt+=1
print(cnt)

Measured memory_bytes: 3064
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <iomanip>


using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define shandom_ruffle random_shuffle

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy


int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout << std::setprecision(9);
    cout << std::fixed;

    ll n;
    cin >> n;
    ll l[n];
    ll sum = 0;
    F0R(i,n) {cin >> l[i]; sum +=l[i];}
    F0R(i,n) {
      if(l[i] >= sum - l[i])
      {
        cout << "No"<<endl;
        return 0;
      }
    }
    cout << "Yes" << endl;
    return 0;
}

// read the question correctly (ll vs int)
// template by super1 derived from bqi343


Measured memory_bytes: 256
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		if (S.contains("A") && S.contains("B")) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 21716
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define mod 1000000007
using ll=long long;
const int INF=1000000000;
const ll LINF=1001002003004005006ll;
int dx[]={1,0,-1,0},dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
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;}
 
struct IOSetup{
    IOSetup(){
        cin.tie(0);
        ios::sync_with_stdio(0);
        cout<<fixed<<setprecision(12);
    }
} iosetup;
 
template<typename T1,typename T2>
ostream &operator<<(ostream &os,const pair<T1,T2>&p){
    os<<p.first<<" "<<p.second;
    return os;
}
 
template<typename T>
ostream &operator<<(ostream &os,const vector<T>&v){
    for(int i=0;i<(int)v.size();i++) os<<v[i]<<(i+1==(int)v.size()?"":" ");
    return os;
}

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

template<typename T>
istream &operator>>(istream &is,vector<T>&v){
    for(T &x:v)is>>x;
    return is;
}

int n,m;

// p[i][j],人iがjを解ける
int p[10010][1010];
int s[10010],mx[10010],mi[10010];

// 
void solve(){
    rep(i,n)rep(j,m)p[i][j]=0;
    rep(j,m){
        cin>>s[j];
        int k;cin>>k;
        rep(_,k){
            int i;cin>>i;i--;
            p[i][j]=1;
        }
    }

    // iがめっちゃ解く
    rep(i,n){
        int res=0;
        rep(j,m){
            if(p[i][j]){
                res+=s[j];
            }
        }
        mx[i]=res;
    }

    // i解かなくていいなら解かない
    rep(i,n)mi[i]=0;
    rep(j,m){
        int cnt=0;
        rep(i,n){
            cnt+=p[i][j];
        }
        if(cnt==1){
            rep(i,n){
                if(p[i][j]){
                    mi[i]+=s[j];
                }
            }
        }
    }

    int ans=0;
    rep(x,n){
        rep(y,n)if(x!=y){
            chmax(ans,mx[x]-mi[y]);
        }
    }
    // cout<<"mx ";rep(i,n)cout<<mx[i]<<" ";
    // cout<<endl;
    // cout<<"mi ";rep(i,n)cout<<mi[i]<<" ";
    // cout<<endl;
    cout<<ans+1<<endl;
}

signed main(){
    while(cin>>n>>m,n) solve();
    return 0;
}



Measured memory_bytes: 42680
#include<bits/stdc++.h>
using namespace std;
typedef pair<int, int> PA;
typedef priority_queue<int> PQ;
typedef vector<int> VE;
#define int long long
#define INF 1000000009
#define INFL 1000000000000000018
#define mod 1000000007
#define pb push_back
#define MAXN 100005

int n, a[MAXN], b = INF, c, ma;

signed main()
{
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    sort(a, a + n);
    ma = a[n - 1];
    ma++;
    for(int i = 0; i < n - 1; i++){
        if(b > abs(ma / 2 - a[i])){
            b = abs(ma / 2 - a[i]);
            c = a[i];
        }
    }
    printf("%lld %lld\n", ma - 1, c);


    return 0;
}


Measured memory_bytes: 1024
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include <iostream>
#include "bits/stdc++.h"

using namespace std;
typedef unsigned long long ll;
typedef int                     integer;
#define int                     long long
#define ii                      pair<int,int>
#define vii                     vector<pair<int,int>>
#define vi                      vector<int>
#define vvi                     vector<vector<int>>
#define f(a,b,c)                for(int a=b;a<c;a++)
#define s(x)                    in>>x
#define s2(x,y)                 in>>x>>y
#define s3(x,y,z)               in>>x>>y>>z
#define s4(x,y,z,w)             in>>x>>y>>z>>w
#define p(x)                    out<<x<<endl
#define p2(x,y)                 out<<x<<' '<<y<<endl
#define p3(x,y,z)               out<<x<<' '<<y<<' '<<z<<endl
#define p4(x,y,z,w)             out<<x<<' '<<y<<' '<<z<<' '<<w<<endl
#define pl(x)                   out<<x
#define pll(x)                  out<<x<<' '
#define range(v)                v.begin(),v.end()
#define rst(x)                  memset(x, -1, sizeof(x))
#define UNVISITED               -1
#define VISITED                 0
#define EXPLORED                2

#define EACH(x, a) for (auto& x: a)
template<class T> void read_v(T& x, std::istream& in) {
    in >> (x);
}
template<class A> void read_vec(vector<A>& x, std::istream& in) {
    EACH(a, x)
        read_v(a, in);
}

bool sortpairbysec(const pair<int,int> &a,const pair<int,int> &b){return (a.second < b.second);}
template <typename T>
T factmod(T a, T modulus){ int res = 1, i; for (i = 2; i <= a; i++){ res *= i; res%=modulus;} return res; }
template <typename T>
int powmod(T a,T b,int m){ int ans=1; while(b>0){if(b&1){ans*=a;ans%=m;}a*=a;a%=m;b>>=1;} return ans; }
template <typename T>
int power(T a, T b){ int ans=1; while(b>0){if(b&1){ans*=a;}a*=a;b>>=1;}return ans;}

int dist(string st1, string st2, int si){
    int dist = 0;
    f(i, 0, si){
        if(st1[i]!=st2[i]){
            dist++;
        }
    }
    return dist;
}

void ssolve(std::istream& in, std::ostream& out){
    string st1, st2; s2(st1, st2);
    int size1 = (int)st1.size();
    int size2 = (int)st2.size();
    int diff = size1-size2;
    int ans = dist(st1, st2, size2);
    f(i, 1, diff + 1){
        ans = min(ans, dist(st1.substr(i, size2), st2, size2));
    }
    p(ans);
}

class BSubstring {
public:
void solve(std::istream& in, std::ostream& out) {
    ios_base::sync_with_stdio(false);
    in.tie(nullptr);out.tie(nullptr);
    int t;
    int READ = 0;
    if(READ) s(t);
    else t = 1;
    while(t--){
        ssolve(in, out);
    }
}
};

integer main() {
    BSubstring solver;
    std::istream& in(std::cin);
     std::ostream& out(std::cout);
     solver.solve(in, out);
}

Measured memory_bytes: 3660
import std.algorithm;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void main() {
  int n;
  readf (" %d", &n);
  long res;
  foreach (i; 1 .. n + 1) {
    if ((i % 3) && (i % 5)) res += i;
  }
  writeln(res);
}



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

int main(){
    int n,m;
    cin >> n >> m;
    vector < int > s(m);
    int a=0;
    for(int i=0;i<m;i++){
        cin >> s[i];
        a+=s[i];
    }
    if(a<=n){
        cout << n-a << endl;
    }
    else{
        cout << -1 << endl;
    }
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
//useful library
int long long gcd(int long long a, int long long b){
    return b?gcd(b,a%b):a;
} //最大公約数
int long long lcm(int long long a, int long long b){
    return a/gcd(a,b)*b;
} //最小公倍数
int long long GetDigit(int long long num){
    int long long digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
} //桁数
int long long GetDigitN(int long long num, int long long N){
    int long long digit=0;
    while(num!=0){
        num /= N;
        digit++;
    }
    return digit;
} //十進数でnumの際のN進数における桁数

int main(){
    int long long N, ans = 0;
    cin >> N;
    for(int i = 1; i <= N; i++){
        if((i % 15 == 1) || (i % 15 == 2) || (i % 15 == 4) || (i % 15 == 7) || (i % 15 == 8) || (i % 15 == 11) || (i % 15 == 13) || (i % 15 == 14)){
            ans = ans + i;
        }
    }
    cout << ans << endl;
    return 0;
}

// 1 + 2 + 4 + 7 + 8 + 11 + 13 + 14 = 60

Measured memory_bytes: 3528
N=int(input())
P=[int(x) for x in input().split()]
 
N_J=list(range(1,N+1))
ans='NO'
for i in range(N):
    for j in range(N):
        P_temp=P.copy()
        p_i=P[i]
        p_j=P[j]
 
        P_temp[i]=p_j
        P_temp[j]=p_i
        
        if P_temp==N_J:
            ans='YES'
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define def(a, b) ((a) > (b)) ? ((a) - (b)) : ((b) - (a))

int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;

	if ((def(a, c)) <= d || ((def(a, b)) <= d && (def(b, c)) <= d))
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

	return 0;	
}

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

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;

int INF = 1000000;
map<pii, int> dist;
map<pii, vector<pii>> v;

bool operator>(ppii x, ppii y){
  return x.second > y.second;
}

void shortest_path(int start){
  priority_queue<ppii, vector<ppii>, greater<ppii>> que;

  dist[make_pair(start,0)] = 0;
  que.push(make_pair(make_pair(start,0),0));

  while(!que.empty()){
    ppii now = que.top();
    que.pop();
    pii now_v = now.first;
    ll now_dist = now.second;
    // cerr << now_v << " " << now_dist << endl;
    if(dist[now_v] < now_dist) continue;

    for(auto next_v: v[now_v]){
      // cerr << now_v <<  " " << next_v  << " " << now_dist << endl;
      if(dist[next_v] > now_dist + 1 ){
        dist[next_v] = now_dist + 1;
        que.push(make_pair(next_v, dist[next_v]));
      }
    }
  }
}

int main(){
  cout << setprecision(10);
  int N,M; cin >> N >> M;

  for(int i= 0; i < M; i++){
    int s,t; cin >> s >> t;
    s--; t--;
    v[make_pair(s,0)].push_back(make_pair(t,1));
    v[make_pair(s,1)].push_back(make_pair(t,2));
    v[make_pair(s,2)].push_back(make_pair(t,0));
  }
  for(int i = 0; i < N; i++){
    for(int j = 0; j < 3; j++){
      dist[make_pair(i,j)] = INF;
    }
  }

  int S,T; cin >> S >> T;
  S--; T--;
  shortest_path(S);
  auto d = dist[make_pair(T,0)];
  cout << (d == INF ? -1 : d/3) << endl;
  
}


Measured memory_bytes: 55156
#include <iostream>
#include <cstdio>
#include <vector>

using namespace std;

int N, K;
int P[5005];
long long C[5005];

int used[5005];

void solve() {
  vector<vector<int> > gs;
  vector<long long> ls;
  for (int i = 0; i < N; i++) {
    if (used[i]) continue;

    vector<int> g;
    long long s = 0;
    int c = i;
    do {
      g.push_back(c);
      used[c] = true;
      c = P[c];
      s += C[c];
    } while (c != i);
    gs.push_back(g);
    ls.push_back(s);
  }

  vector<long long> gscore;
  for (int i = 0; i < gs.size(); i++) {
    vector<int> g = gs[i];
    int k = K;

    long long loop_score = 0;
    long long loop_times = 0;
    if (ls[i] > 0) {
      if (K / g.size() > 0) {
        loop_times = K / g.size() - 1;
      }
      k -= loop_times * g.size();
      loop_score = ls[i] * loop_times;
    } else {
      if (k > g.size()) {
        k = g.size();
      }
    }
    long long max_score = -(1LL<<62);
    for (int j = 0; j < g.size(); j++) {
      long long ss = 0;
      int c = g[j];
      int count = 0;
      while (count < k) {
        count++;
        c = P[c];
        ss += C[c];
        if (ss > max_score) max_score = ss;
      }
    }

    gscore.push_back(max_score+loop_score);
  }

  long long m = -(1LL<<62);
  for (int i = 0; i < gscore.size(); i++) {
    if (m < gscore[i]) m = gscore[i];
  }
  printf("%lld\n", m);
}

int main() {
  scanf("%d %d", &N, &K);
  for (int i = 0; i < N; i++) {
    scanf("%d", P+i);
    P[i]--;
  }
  for (int i = 0; i < N; i++) {
    scanf("%lld", C+i);
  }

  solve();
}

Measured memory_bytes: 3904
N,M=map(int,input().split())
List = []
for i in range (M):
  List.append(list(map(int, input().split())))
List.sort()

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

uf = UnionFind(N)
for i in range(M):
  uf.union(List[i][0]-1, List[i][1]-1)
print(uf.group_count())

Measured memory_bytes: 32064
#include <iostream>
using namespace std;
int num;


int fib(int n, int array[]) {
    array[0] = 1;
    array[1] = 1;
    for (int i= 2; i <= n; i++) {
        array[i] = array[i - 1] + array[i - 2];
    }
    cout << array[n] << endl;
}
int main(void) {

    cin >> num;
    int array[num] = {};
    fib(num, array);


}


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

// def
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
#define repeat(i, a, b) for (int i = (a); i < (b); i++)
#define revrepeat(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define revrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> P;
typedef vector<vector<int>> Graph;
const int M = 1e9 + 7;
const ll INF = 1e9;
const int MAX_V = 100000 + 5;
const int MAX_N = 1e6 + 5;
const double PI = acos(-1);

// Combination

// save memory
int mod = 1e9 + 7;
int MOD = 1e9 + 7;
long modpow(long m, long p) {
    if (p == 0) return 1;
    if (p % 2)
        return m * modpow(m, p - 1) % mod;
    else {
        long res = modpow(m, p / 2);
        return res * res % mod;
    }
}
long calcComb(int a, int b) {
    if (b > a - b) return calcComb(a, a - b);
    long mul = 1;
    long div = 1;
    for (int i = 0; i < b; i++) {
        mul *= (a - i);
        div *= (i + 1);
        mul %= MOD;
        div %= MOD;
    }
    long res = mul * modpow(div, MOD - 2) % MOD;
    return res;
}

int main() {
    int x, y;
    cin >> x >> y;
    if ((2 * x - y) % 3 != 0 || (2 * y - x) % 3 != 0 || (x + y) % 3 != 0 || (2*x - y) < 0 || (2*y - x) < 0) {
        out(0);
    } else {
        int a = (2 * x - y) / 3;
        int b = (2 * y - x) / 3;
        long ans = calcComb(a + b, max(a, b));
        out(ans);
    }
}


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

#define int long long
//#define uint __int128_t

#define pb push_back
#define fi first
#define se second
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define low(a,b) lower_bound(all(a),(b))-(a).begin()
#define upp(a,b) upper_bound(all(a),(b))-(a).begin()
#define fill(i,n) memset(i,n,sizeof(i))
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<vint> vvint;
typedef vector<pint>vpint;
typedef pair<pint,int> P1;
typedef pair<int,pint> P2;
typedef pair<pint,pint> PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD=1000000007;
const ll INF=1e18;

string s;

signed main() {
    IOS();
    //(1ll<<N)シフト演算のオーバーフローに気をつける
    cin>>s;
    int ans=0,cnt=0;
    rrep(i,0,s.size()){
        if(s[i]=='W')cnt++;
        else ans+=cnt;
    }
    cout<<ans<<endl;
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    




















































    return 0;
}

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

int main() {
	int x, n;
	cin >> x >> n;
	vector <bool> v(100, false);
	for(int i=0; i<n; i++)
	{
		int a;
		cin >> a;
		v[a]=true;
	}
	int ans, anss;
	for(int i=x; i>-100; i--)
	{
		if(v[i]==false)
		{
			ans=i;
			break;
		}
	}
	for(int i=x+1; i<200; i++)
	{
		if(v[i]==false)
		{
			anss=i;
			break;
		}
	}
	if(-(x-anss)<x-ans) cout << anss;
	else cout << ans;
	return 0;
}


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

string s;

void solve() {
    if(s[2] == s[3] && s[4] == s[5]) {
        cout << "Yes";
    }else{
        cout << "No";
    }
}

int main() {
    cin >> s;
    solve();
    return 0;
}

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

inline void solve(){
    int n,s=0; cin>>n; 
    vi a(n);
    for (int &i: a){
        cin >> i;
        s += i;
    }
    sort(a.begin(), a.end());
    for (int i=0;i<n;i++){
        if (s%10){
            cout << s << endl;
            return;
        }
        if ((s-a[i])%10){
            cout << s-a[i] << endl;
            return;
        }
    }
    cout << 0 << endl;
}

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


Measured memory_bytes: 3604
#include <iostream>
#include <climits>
#include <set>
#include <string>
#include <algorithm>
#include <vector>
#define MAX 1000000007


using namespace std;
#define ll long long
#define dbg if(0)
#define ISRANGE(val,lo,hi) ((lo<=val)&&(val<hi))

//ABCDEFGHIJKLMNOPQRSTUVWXYZ
string decode(string s){
    string ans="";
    ll diff=0;
    for(int i=0;i<s.size();i++){
        if (s[i]-'A'<26 && s[i]-'A'>=0){//文字確定
            ans+=(char)(((int)((s[i]-65)+diff)+26*8)%26+65);
            diff=0;
        }
        if (s[i]-'?'==0){//文字確定
            ans+=(char)(65);
            diff=0;
        }
        if (s[i]-'+'==0){//+
            diff++;
        }
        if (s[i]-'-'==0){//+
            diff--;
        }
        if(s[i]-'['==0){//[
            ll count=1;
            ll pos=i;
            while(count>0){
                pos++;
                if(s[pos]-'['==0)count++;
                if(s[pos]-']'==0)count--;
            }
            string rev=decode(s.substr(i+1,(pos-i-1)));
            reverse(rev.begin(),rev.end());
            ans+=rev;
            i=pos;
        }

    }
    return ans;
}


int main(){
    ll ans;
    string s;

    while(true){
        cin >>s;
        if(s==".")break;
        for(int i=0;i<s.size();i++){
        }
        cout << decode(s)<<endl;

    }

    return 0;

}


Measured memory_bytes: 3164
"""
Nは10**5以下。O(N)なら通る
"""

N = int(input())
A = []
B = []
for i in range(N):
    s = list(map(int, input().split()))
    A.append(s[0])
    B.append(s[1])

count = 0
for i in reversed(range(N)):
    if (count + A[i]) % B[i] == 0:
        continue
    else:
        s = B[i] - (count + A[i]) % B[i]
        count += s

print(count)

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

int main() {
  vector<int> A(3);
  for (int i = 0 ; i < 3 ; i++ ){
    cin >> A.at(i);
  }
  
  int number_5 = 0;
  int number_7 = 0;
  
  for (int i = 0 ; i < 3 ; i++ ){
    if (A.at(i) == 5 ){
      number_5 ++;
    }
    if (A.at(i) == 7 ){
      number_7 ++;
    }
  }
  
  if ( number_5 == 2 && number_7 == 1){
    cout << "YES";
  }
  else{
    cout << "NO";
  }
}

  

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

void dfs(int x, int y, string s) {
  if (x == y) {
    cout << s << endl;
    return;
  }
  char c = 'a';
  string st = "a";
  for (int i = 0; i < s.size(); i++) {
    c = max(c, s[i]);
  }
  for (int i = 0; i + 'a' <= c + 1; i++) {
    st[0] = 'a' + i;
    dfs(x + 1, y, s + st);
  }
}

int main() {
  int n;
  cin >> n;
  dfs(1, n, "a");
}

Measured memory_bytes: 1536
using System;
using System.Text;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Threading.Tasks;

class Solve
{
	const int mod = 1000000007;
	static void Main(string[] args)
	{
		var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
		int A = input[0];
		int B = input[1];
		Console.WriteLine(A + B >= 10 ? "error" : $"{A + B}");
	}
}

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

#define int long long
#define endl "\n"
#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPR(i,a,n) for(int i=a;i>n;--i)
#define RUP(a,b) ((a+b-1)/(b))
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define INF LLONG_MAX

typedef long long ll;
typedef pair<int,int> Pii;
typedef tuple<int,int,int> Tiii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<string> Vs;

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;}
template<class T> void YesNo(T a) {cout<<(a?"Yes":"No")<<endl;}
template<class T> void YESNO(T a) {cout<<(a?"YES":"NO")<<endl;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
void uniq(vector<int> &vec){sort(vec.begin(), vec.end());vec.erase(unique(vec.begin(), vec.end()), vec.end());}
void start(){cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);}


signed main(){start();
    string s;
    cin>>s;
    if(s[0]==s[1]){
        cout<<"Bad"<<endl;
        return 0;
    }
    if(s[1]==s[2]){
        cout<<"Bad"<<endl;
        return 0;
    }
    if(s[2]==s[3]){
        cout<<"Bad"<<endl;
        return 0;
    }
    cout<<"Good"<<endl;
    return 0;
}


Measured memory_bytes: 256
def rpn(p)
  st = []
  while p.size > 0
    x = p.shift
    case x
    when "+" then st.push(st.pop+st.pop)
    when "-" then st.push(-st.pop+st.pop)
    when "*" then st.push(st.pop*st.pop)
    when "/" then st.push(1.0/st.pop*st.pop)
    else st << x.to_f end
  end
  return st
end

while gets
  ln = $_.split.map(&:to_s)
  puts rpn(ln)
end

Measured memory_bytes: 8636
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#include<cmath>

#define REP(i,n) for (int i = 0; (i) < (n); ++ (i))
#define FOR(i,n) for (int i = 1; (i) <= (n); ++ (i))
#define dump(x)  cout << #x << " = " << (x) << endl;
#define pb push_back
#define int long long

const int INF = 1e18;
const int MOD = 1e9+7;
//const lint LINF = 1e18;
const double eps = 0.000000001;//もとの値の10^(-16)まで

using namespace std;

//typedef pair<int, int> P;
//priority_queue< P, vector<P>, greater<P> > q;//ダイクストラの時、greaterで小さい順
//cout << fixed << setprecision(10) << ans << endl;
//int gcd(int a,int b){return b?gcd(b,a%b):a;}

signed main(){
    int x;
    cin >> x;

    for(int i = -500;i <= 500 ; i++){
        int a1 = i * i * i * i * i;
        for(int j = -500; j <= 500 ; j++){
            int a2 = j * j * j * j * j;
            if(a1 - a2 == x){
                 cout << i << " " << j << endl;
                 return 0;
            }

        }
    }

    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<iomanip>
using namespace std;
#define ALL(v) (v).begin(),(v).end()
#define e << endl;
#define fix(q) cout << fixed << setprecision(10) << q e
#define rep(i,n) for(int i = 0; i < n; i++)
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 int INF = 1e9;  vector<long long int> t; vector<long long int>w;
long long int dp[1000010][100];  long long int ans = -1;
long long int a[10010][10010];;long long int f = 0;long long int g = INF;
bool diff(int a, int b, int c, int d) {
	if (a == b)return false;
	else if (c == b) return false;
	else if (c == d) return false;
	else if (d == a) return false;
	else if (a == c) return false;
	else if (d == b) return false;
	else return true;
}
int main() {
	string s;
	cin >> s;
	if (s == "SUN") cout << 7 e
	if(s == "SAT") cout << 1 e
	if(s == "MON") cout << 6 e
	if(s == "TUE")cout << 5 e
	if(s == "WED")cout << 4 e
	if(s == "THU") cout << 3 e
	if(s == "FRI")cout << 2 e
}

Measured memory_bytes: 256
#include <iostream>
#define US unsigned short
#define UI unsigned int
using namespace std;

int main(int argc, char const *argv[])
{
    UI N, out = 0;
    cin >> N;
    char S[N], now = '0';
    cin >> S;

    for (size_t i = 0; i < N; i++)
        if (S[i] != now)
        {
            now = S[i];
            out++;
        }
    cout << out << endl;
}


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
int main()
{
  int n;
  cin >> n;
  vector<int> p(n);
  rep(i,n){
    cin >> p[i];
  }

  int pv = 1e+9;
  int cnt = 0;
  rep(i,n){
    if(pv>=p[i]){
      cnt++;
      pv = p[i];
    }
  }

  cout << cnt << "\n";
  return 0;
}


Measured memory_bytes: 1024
//
//  main.cpp
//  contest
//
//  Created by TmpGuest on 2020/4/18.
//  Copyright © 2020 TmpGuest. All rights reserved.
//

#include <bits/stdc++.h>
#define endl '\n'

using namespace std;
int main() {
ios_base::sync_with_stdio(false);
    cin.tie(0);
    double pi=3.14159265358979323846;
    int i;
    cin>>i;
    cout<<2*i*pi<<endl;
    
    return 0;
}


Measured memory_bytes: 3804
#include <iostream>
#include <string>
#include<algorithm>
#include <cstdlib>

using namespace std;

int main()
{
	int a, b,c;
	cin >> a >> b>>c;
	if (c - b <= 0) cout << "delicious" << endl;
	else if (c - b <= a) cout << "safe" << endl;
	else cout << "dangerous" << endl;
    return 0;
}



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

int main() {
  int r;
  cin >> r;
  if (r < 1200) {
    cout << "ABC" << endl;
  }
  else if (r < 2800) {
    cout << "ARC" << endl;
  }
  else {
    cout << "AGC" << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <limits>
#include <list>
#include <string>
#include <queue>
#include <deque>
#include <tuple>
#include <map>
#include <sstream>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort(ALL(x))
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const long double PI  = acos(-1.0L);
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
#define chmax(a,b) a = (((a)<(b))?(b):(a))
#define chmin(a,b) a = (((a)>(b))?(b):(a))

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

// aのp乗を求める関数
ll mpow(ll a, ll b){
	if(b==0){
		return 1;
	}else if(b%2==0){
		ll memo = mpow(a,b/2);
		return memo*memo%MOD;
	}else{
		return mpow(a,b-1)*a%MOD;
	}
}


signed main(){
	string s; cin>>s;
	if(s.size()%2==1) return cout<<"No"<<endl,0;
	rep(i,s.size()){
		if(i%2){
			if(s[i]!='i') return cout<<"No"<<endl,0;
		}else{
			if(s[i]!='h') return cout<<"No"<<endl,0;
		}
	}
	cout << "Yes" <<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << endl
#define COUTF(x) cout << setprecision(15) << (x) << endl
#define ENDL cout << endl
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#ifdef _DEBUG
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
#else
#define debug(x)
#endif
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using P = pair<ll, ll>;
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr double PI = 3.141592653589793238462643383279;
ll getDigit(ll x) {
  return x == 0 ? 1 : log10(x) + 1;
}

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

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

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

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 debugV(const vector<T> v) {
#ifdef _DEBUG
  rep(i, v.size()) {
    cout << i << ":" << v[i] << " ";
  }
  cout << endl;
#else
  (void)v;
#endif
}

bool is_ACGT(char s) {
  return s == 'A' || s == 'C' || s == 'G' || s == 'T';
}

signed main() {
  string S;
  cin >> S;
  ll ans = 0;
  rep(i, S.size()) {
    ll count = 1;
    if (is_ACGT(S[i])) {
      rep2(j, i + 1, S.size()) {
        if (is_ACGT(S[j])) {
          count++;
        } else {
          break;
        }
      }
      ans = max(ans, count);
    }
  }
  COUT(ans);
  return 0;
}

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

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define repp(i,k,n) for(int i=k;i<(int)n;i++)
#define rei(n) for(int i=0;i<(int)n;i++)
#define rel(n) for(int l=0;l<(int)n;l++)
#define all(s) s.begin(),s.end()
#define INT_MAX 2147483647
#define debug(x) cout<<#x<<": "<<x<<endl;
#define PI 2*acos(0,0)
#define pb push_back
#define inin(x) int x; cin>>x;
#define ll long long
#define pb push_back

typedef pair<int, int> pii;
typedef pair<int, pii> pipii;

int main()
{
	int a = 0, b = 0;
	rep(i, 4)
	{
		inin(x); a += x;
	}
	rep(i, 4)
	{
		inin(x); b += x;
	}
	cout << max(a, b) << endl;

}

Measured memory_bytes: 1164
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <map>
#include <limits>
using namespace std;
typedef long long ll;

float inf = std::numeric_limits<float>::infinity();

/* 二次元配列の宣言
  vector<vector<int>> tb;
  tb.resize(H);
  for (size_t i = 0; i < H; i++) {
    tb[i].resize(W);
  }
*/
/*
  A.resize(N);
  for (int i = 0; i < N; i++) {scanf("%d",&A[i]);}
*/

int main(void) {
  ll N,x,ans=0;
  cin >> N >> x;

  ll ba=0,na,suma = 0;
  for (size_t i = 0; i < N; i++) {
    cin >> na;
    suma = ba + na;
    if (suma > x){
      ans += suma-x;
      na -= suma-x;
    }
    ba = na;
  }

  cout << ans << '\n';

}


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

int main()
{
    std::string s;
    std::cin >> s;
    int sizeS = s.length();
    int counter = 0;
    for(int i = 0; i < sizeS; i++){
        if(s[i] == s[i+1]){
            counter++;
            if(s[i] == '0'){
                s[i+1] = '1';
            }
            else if(s[i] == '1'){
                s[i+1] = '0';
            }
        } 
    }
    std::cout << counter;
    return 0;
}


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

int main() {
    // H < 11, M < 59 
    int A, B;
    double H, M;
    cin >> A >> B >> H >> M;

    //cout << setprecision(11) << sqrtl(184423) << endl;
    
    double pi = 2.0 * asin(1.0); 
    double h_a = 360*(H + M/60)/12;
    double m_a = 360*(M/60);
    double angle = max(h_a, m_a) - min(h_a, m_a); 
    
    if(angle > 180) h_a = 360 - h_a;
    double unit = pi / 180.0;

    //a2=b2+c2−2bccosA 
    double len = A*A + B*B - 2*A*B*cosl(angle*unit);
    
    //cout << setprecision(11) << angle*unit << endl;

    //cout << setprecision(11) << angle << endl;
    //cout << angle*unit << endl;
    //cout << cosl(angle*unit) << endl;
    //cout << setprecision(11) << cosl(angle*unit) << endl;
    len = sqrtl(len);
    cout << setprecision(11) << len << endl;
    
}

Measured memory_bytes: 4108
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, a, b) for (int i = (a); i < (b); i++)
//#include "library/debug.cpp"

ll modpow(ll x, ll n, ll mod) {
    ll r = 1;
    while (n > 0) {
        if (n & 1) r = r * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return r;
}

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

    ll n, mod = 1e9 + 7;
    cin >> n;
    vector<ll> c(n);
    rep(i, 0, n) cin >> c[i];
    sort(c.begin(), c.end());

    ll ans = 0;
    rep(i, 0, n) {
        ll sum = (n - i + 1) * c[i];
        sum %= mod;
        ans = (ans + sum) % mod;
    }
    ans = ans * modpow(4LL, n - 1, mod) % mod;
    cout << ans << endl;
    return 0;
}


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

#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
#define rep2(i,s,n) for(long long i=(s); i<(long long)(n);i++)
#define mod 1000000007
typedef long long ll;

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

    if(n%k==0){
        cout<<0<<endl;
    }
    else {
        cout<<1<<endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 5;
const long long mod = 1e9 + 7;

int n, k;
int arr[MAXN];
void solve(){
    sort(arr, arr + n);
    int sum = 0, i = 0;
    for(i = 0; i < k; i++)
        sum += arr[i];
    cout << sum;

}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int i = 0;
    cin >> n >> k;
    for(i = 0; i < n; i++)
        cin >> arr[i];
    solve();
    return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x)      begin(x),end(x)

using namespace std;
using vecint = vector<int>;
using ll = int64_t;
constexpr ll MOD = 1000000007;

int main()
{
  ll n;
  cin>>n;
  vector<ll> c;
  REP(i,n) {
    ll v;
    cin>>v;
    if (c.empty() || c.back() != v) {
      c.push_back(v);
    }
  }
  n = c.size();
  vector<ll> old(200001, -1);
  vector<ll> dp(n+1);
  dp[0] = 1;
  REP(i,n) {
    if (old[c[i]] != -1) {
      dp[i+1] = dp[i] + dp[old[c[i]]+1];
      dp[i+1] %= MOD;
    } else {
      dp[i+1] = dp[i];
    }
    old[c[i]] = i;
  }
  cout << dp[n] << endl;
  return 0;
}


Measured memory_bytes: 5104
s = str(raw_input())
no_flag = False
for i in range(len(s)):
  if i%2 == 0:
    if s[i] == 'L':
      print('No')
      no_flag = True
      break
  else:
    if s[i] == 'R':
      print('No')
      no_flag = True
      break
if no_flag == False:
  print('Yes')

Measured memory_bytes: 2568