akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  int N;cin >> N;
  vector<PII> v(N);
  vector<int> w(N);
  vector<PII> p(N);
  rep(i,N)cin >> p[i].second;
  rep(i,N)cin >> p[i].first;
  sort(all(p));
  rep(i,N){
    w[i] = p[i].first;
    v[i] = PII(p[i].second,i);
  }
  sort(all(v));
  sort(all(w));
  bool sat1 = true;
  rep(i,N) if(v[i].first > w[i])  sat1=false;
  bool sat2 = false;
  int count = 0;
  int s = 0;
  vector<bool> used(N,false);
  while(true){
    if(used[s])break;
    used[s] = true;
    s = v[s].second;
    ++count;
  }
  if(count != N)sat2 = true;
  rep(i,N-1) if(v[i+1].first <= w[i]) sat2 = true;
  YesNo(sat1&&sat2);
  return 0;
}


Measured memory_bytes: 2176
a = [1, 3, 5, 7, 8, 10, 12]
b = [4, 6, 9, 11]
c = [2]
xy = input().split(' ')
if int(xy[0]) in a and int(xy[1]) in a:
    print("Yes")
elif int(xy[0]) in b and int(xy[1]) in b:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
input:
4
1 2 2 4
2 1 4
3 0
4 1 3

output:
1 0
2 1
3 2
4 1
"""

import sys
from collections import deque

UNVISITED, VISITED_IN_QUEUE, POPPED_OUT = 0, 1, 2


def graph_bfs(v_init):
    queue = deque()
    status[v_init] = VISITED_IN_QUEUE
    distance[v_init] = 0
    queue.appendleft(v_init)

    while queue:
        current = queue.popleft()
        for adj in adj_table[current]:
            if status[adj] is UNVISITED:
                status[adj] = VISITED_IN_QUEUE
                distance[adj] = distance[current] + 1
                queue.append(adj)
        status[current] = POPPED_OUT
    return None


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    v_num = int(_input[0])
    vertices = list(map(lambda x: x.split(), _input[1:]))
    # assert len(vertex_info) == vertex_num

    status = [UNVISITED] * (v_num + 1)
    distance = [-1] * (v_num + 1)

    adj_table = tuple([] for _ in range(v_num + 1))
    for v_info in vertices:
        v_index, adj_num, *adj_list = map(int, v_info)
        # assert len(adj_list) == adj_num
        adj_table[v_index].extend(adj_list)

    graph_bfs(v_init=1)
    for index, v in enumerate(distance[1:], 1):
        print(index, v)

Measured memory_bytes: 8048
def process(A, B):
    hit, blow = 0, 0
    for a, b in zip(A, B):
        if a == b:
            hit += 1
        elif a in B:
            blow += 1
    return (hit, blow)

while True:
    try:
        A = input().split()
        B = input().split()
    except: break
    hit, blow = process(A, B)
    print(hit, blow)


Measured memory_bytes: 5556
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <algorithm>
#include <vector>
#include <cassert>
#define rep(i, a, b) for (int i = (a), _ = (b); i <= _; ++ i)
#define per(i, a, b) for (int i = (a), _ = (b); i >= _; -- i)
#define For(i, a, b) for (int i = (a), _ = (b); i < _; ++ i)
#define ri rd<int>
#define rl rd<LL>
using namespace std;
typedef long long LL;
const int maxN = 2e5 + 7;
const int maxC = 26;
const int maxM = 127;
const LL INF = 1e18;

template<class T> inline T rd() {
	bool f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') f = 0;
	T x = 0; for (; isdigit(c); c = getchar()) x = x * 10 + c - 48; return f ? x : -x;
}

char s[maxN];
int n, len, t;
int nx[maxN];
LL occ[maxC];
LL L, R;

void kmp() {
	nx[1] = 0; int i, j;
	for (i = 2, j = 0; i <= n; ++ i) {
		while (j && s[j+1] != s[i]) j = nx[j];
		if (s[j+1] == s[i]) ++ j;
		nx[i] = j;
	}
}

void solve1(LL len, LL kd) {
	LL tms = len / t, res = len % t;
	rep (i, 1, t) occ[s[i] - 'a'] += kd * (tms + (i <= res));
}

namespace solve2 {
	LL f[maxM][maxC], len[maxM], Top;
	
	void init() {
		len[1] = t; rep (i, 1, t) ++ f[1][s[i] - 'a'];
		len[0] = n - t; rep (i, t+1, n) ++ f[0][s[i] - 'a'];
		For (i, 2, maxM) {
			len[i] = len[i-1] + len[i-2];
			Top = i;
			For (j, 0, maxC) f[i][j] = f[i-1][j] + f[i-2][j];
			if (len[i] > INF) break;
		}
	}

	void dfs(int p, LL l, LL kd) {
		if (l <= 0) return;
		assert(l <= len[p]);
		if (l == len[p]) {
			For (i, 0, 26) occ[i] += kd * f[p][i];
			return;
		}
		if (p == 0 || p == 1) {
			int bg = (p == 1) ? 0 : t;
			rep (i, 1, l) occ[s[bg+i] - 'a'] += kd;
			return;
		}
		dfs(p-1, min(l, len[p-1]), kd);
		dfs(p-2, l - len[p-1], kd);
	}

	void work(LL l, LL kd) {
		dfs(Top, l, kd);
	}
}

int main() {

	scanf("%s", s+1);
	L = rl(), R = rl();
	n = strlen(s+1) >> 1;
	len = (n + 1) >> 1;
	kmp();
	
	t = n - nx[n];
	if (n % t == 0) solve1(R, 1), solve1(L-1, -1);
	else solve2::init(), solve2::work(R, 1), solve2::work(L-1, -1);

	For (i, 0, 26) printf("%lld%c", occ[i], " \n"[i == 25]);

	return 0;
}

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

using namespace std;

int n;
int a[100000];
int dp[100000];

int solve(int i)
{
	if (i == n - 1)
		return dp[i] = 0;
	if (dp[i] != -1)
		return dp[i];
	int ans = INT_MAX;
	if (i < n - 1)
		ans = min(ans, abs(a[i] - a[i + 1]) + solve(i + 1));
	if (i < n - 2)
		ans = min(ans, abs(a[i] - a[i + 2]) + solve(i + 2));
	return dp[i] = ans;
}
int main()
{
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	memset(dp, -1, sizeof(dp));
	cout << solve(0) << endl;
	return 0;
}


Measured memory_bytes: 4096
a, b, k = gets.chomp.split(" ").map(&:to_i)
divisor_ary = []

1.upto(100) do |num|
  if a % num == 0 && b % num == 0
    divisor_ary.push(num)
  end
end

divisor_ary.reverse!
puts divisor_ary[k - 1]



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

typedef long long LL;

const int N=2000,mod=1000000007;

int n,m,a[N+9];

void into(){
  scanf("%d%d",&n,&m);
  for (int i=1;i<=n;++i)
	scanf("%d",&a[i]);
}

int c[N+9];

void Add(int p,int v){for (;p<=N;p+=p&-p) c[p]+=v;}
int Query(int p){int res=0;for (;p;p-=p&-p) res+=c[p];return res;}
int Query(int l,int r){return Query(r)-Query(l-1);}

int ans;

void Get_ans(){
  for (int i=1;i<=n;++i){
	ans+=Query(a[i]+1,N);
	Add(a[i],1);
  }
  ans=(LL)ans*m%mod;
  for (int i=1;i<=N;++i) c[i]=0;
  for (int i=1;i<=n;++i) ++c[a[i]];
  for (int i=N;i>=1;--i){
	ans=(((LL)m*(m-1)>>1)%mod*c[i]%mod*c[i+1]+ans)%mod;
	c[i]+=c[i+1];
  }
}

void work(){
  Get_ans();
}

void outo(){
  printf("%d\n",ans);
}

int main(){
  into();
  work();
  outo();
  return 0;
}

Measured memory_bytes: 3764
S=input()
N=len(S)

S1=S[0:int(((N-1)/2))]
S2=S[int(((N+3)/2)-1):N]

N1=len(S1)
N2=len(S2)

for i in range(int(N//2)):
    if S[i] != S[N-i-1]:
        break
else:
    S = 'Palindrome'
    

for i in range(int(N1/2)):
    if S1[i] != S1[N1-i-1]:
       # print('No')
        break
else:
    S1 = 'Palindrome'
   

for i in range(int(N2/2)):
    if S2[i] != S2[N2-i-1]:
        #print('No')
        break  
else:
    S2 = 'Palindrome'
   

if (S == 'Palindrome' and S1 == 'Palindrome' and S2 == 'Palindrome'):
    print('Yes')

else:
    print('No')



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

int main(){
    map<char, int> card;
    for(int i=2; i<=9; i++){
        card['0'+i] = i;
    }
    card['A'] = 1;
    card['T'] = card['J'] = card['Q'] = card['K'] = 10;
    int n;
    cin >> n;
    for(int i=1; i<=n; i++){
        char pile[8];
        int point = 0;
        bool isblackjack = false;
        bool isace = false;
        for(int j=1; j<=2; j++){
            char tmp;
            cin >> tmp;
            if(tmp == 'A' && point <= 10){
                isace = true;
                point += 11;
            }else{
                point += card[tmp];
            }
        }
        if(point == 21) isblackjack = true;
        for(int j=0; j<8; j++){
            cin >> pile[j];
        }
        for(int j=0; j<8; j++){
            if(point <= 16 || (isace && point == 17)){
                if(pile[j] == 'A'){
                    if(point <= 10){
                        point += 11;
                        isace = true;
                    }else{
                        point +=card[pile[j]];
                    }
                }else{
                    point += card[pile[j]];
                }
                if(point > 21 && isace){
                    point -= 10;
                    isace = false;
                }
            }else{
                break;
            }
        }
        if(isblackjack){
            cout << "blackjack" << endl;
        }else if(point > 21){
            cout << "bust" << endl;
        }else{
            cout << point << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000007;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	map<Int, Int> edge;
	Int N;
	cin >> N;

	Int temp;
	for (Int i = 0; i < N; i++) {
		cin >> temp;
		edge[temp]++;
	}
	Int edge1 = 0;
	Int edge2 = 0;
	Int edge4 = 0;

	for (auto itr = edge.begin(); itr != edge.end(); itr++) {
		if (itr->second >= 4) {
			if (itr->first >= edge4) {
				edge4 = itr->first;
				continue;
			}
		}
		if (itr->second >= 2 && itr->second <= 3) {
			if (itr->first >= edge1) {
				edge2 = edge1;
				edge1 = itr->first;
				continue;
			}
			if (itr->first >= edge2) {
				edge2 = itr->first;
				continue;
			}
		}
	}

	Int ans = max({ edge4 * edge4,edge4 * edge1,edge1 * edge2 });
	cout << ans << "\n";
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  int T[105];
  cin>>N;
  int count = 0;
  for(int i = 1; i<=N; i++){
      cin >> T[i];
      count = count + T[i];
  }
  int M;
  cin>>M;
  int P[M],X[M],sum[M];
  for(int j = 0; j<M; j++){
      cin >> P[j] >> X[j];
      sum[j] = count - T[P[j]] + X[j];
      cout<<sum[j]<<endl;
  }
  
  return 0;
}
  

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    string str;
     
    while(true){
        int sum = 0;
        cin >> str;
        if(str=="0") break;
        for(int i = 0 ; i < str.size() ; i++){
            sum += str[i]-'0';
        }
        cout << sum << endl;
    }
     
    return 0;
}


Measured memory_bytes: 3212
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}




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


  ll N ; cin >> N ;
  vector<ll> moti;
  rep(i,N){
    ll inp; cin >> inp;
    moti.pb(inp);
  }
  rmsame(moti);
  cout << moti.size() << endl;
   
  //cout << fixed << setprecision(16) << ans << endl;
  
  return 0;
}


Measured memory_bytes: 256
import sys
N,L=map(int,input().split())
A=[int(i) for i in input().split()]
s=10**23
for i in range(N-1):
    if A[i]+A[i+1]>=L:
        s=i
        break
if s==10**23:
    print('Impossible')
    sys.exit()
print('Possible')
L=[]
for i in range(s):
    L.append(i+1)
for i in range(N-2,s,-1):
    L.append(i+1)
L.append(s+1)
#print(L,s)
print('\n'.join(map(str,L)))

Measured memory_bytes: 73828
#include <stdio.h>

int main(void)
{
	int c;
	int i;
	int vx[26];

	for (i = 0; i < 26; i++)
		vx[i] = 0;
	
	while (1)
	{
		c = getchar();

		if (c == EOF)
			break;

		else
			for (i = 0; i < 26; i++)
				if (c == i + 'a' || c == i + 'A')
				{
					vx[i]++;
					break;
				}
	}

	for (i = 0; i < 26; i++)
	{
		putchar(i + 'a');
		printf(" : %d\n", vx[i]);
	}

	return 0;
}

		

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

int main() {

long long t;
t = 1;
while(t--){
	int n;
  string a,b;
  cin >> n;
  cin >> a >> b;
  for(int i = 0; i < n; ++i){
    cout << a[i] << b[i];
  }
}
return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func nextString() string {
	if !sc.Scan() {
		panic("failed scan string")
	}
	return sc.Text()
}

func nextInt() int {
	if !sc.Scan() {
		panic("failed scan int")
	}
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)

	n := nextInt()
	a := nextString()
	b := nextString()
	c := nextString()

	var count int
	for i := 0; i < n; i++ {
		if a[i] == b[i] && b[i] == c[i] {
			continue
		} else if a[i] == b[i] || b[i] == c[i] || a[i] == c[i] {
			count++
		} else {
			count += 2
		}
	}

	fmt.Println(count)
}


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


int main(){
    int n,k;
    cin >> n >> k;
    string s;
    cin >> s;
    vector<int> a;
    int cnt = 1;
    bool flag;
    if(s[0]=='1') flag = true;
    else flag = false;

    rep(i,s.size()-1){
        if(flag){
            if(s[i+1]=='0'){
                flag = false;
                a.push_back(cnt);
                cnt = 1;
            }else cnt++;
        }else{
            if(s[i+1]=='1'){
                flag = true;
                a.push_back(cnt);
                cnt = 1;
            }else cnt++;
        }
    }
    a.push_back(cnt);
    if(s[n-1]=='0')a.push_back(0);
    int cnt0 = 0;
    int cnt1 = 0;
    if(s[0]=='0'){
        cnt1 = a.size()/2;
        cnt0 = cnt1+a.size()%2;
    }else{
        cnt0 = a.size()/2;
        cnt1 = cnt0 + a.size()%2;
    }

    int sum = 0;
    int ans = 0;
    if(k>=cnt0) {
        cout << n << endl;
        return 0;
    };
    
    if(s[0] =='0'){
        int ind = 0;
        rep(i,2*k) sum += a[i];
        ans = max(ans,sum);
        if(a.size()>2*k+1) sum += (a[2*k]+a[2*k+1]);
        else sum += a[2*k];
        sum -= (a[ind]);
        ans = max(ans,sum);
        ind++;
        while(ind+2*k+2<=a.size()-1){
            sum += (a[ind+2*k+1]+a[ind+2*k+2]);
            sum -= (a[ind]+a[ind+1]);
            ans = max(ans,sum);
            ind += 2;
        }
    }else{
        int ind = 0;
        rep(i,2*k+1) sum += a[i];
        ans = max(ans,sum);
        while(ind+2*k+2<=a.size()-1){
            sum += a[ind+2*k+1] + a[ind+2*k+2];
            sum -= (a[ind]+a[ind+1]);
            ans = max(ans,sum);
            ind += 2;
        }
    }
    //rep(i,a.size()) cout << a[i] << endl;
    cout << ans  << endl;
}

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

const double pi  = 2 * acos(0.0);
const double eps = 1e-8;

#define REP(i,a,b) for(int i=(a); i<(b);++i)
#define rep(i,n) REP(i,0,n)
#define INF (1<<29)
#define INFLL (1LL<<62)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

int main(void) {
  ios_base::sync_with_stdio(false); cin.tie(0);
  int n, m;
  cin >> n >> m;

  vector<pll> st(n), cp(m);

  rep(i, n) {
    cin >> st[i].first >> st[i].second;
  }

  rep(i, m) {
    cin >> cp[i].first >> cp[i].second;
  }

  for (auto s : st) {
    ll id = 0, mind = INFLL;
    rep(i, m) {
      ll d = abs(cp[i].first - s.first) + abs(cp[i].second - s.second);
      if (d < mind) {
        mind = d;
        id = i;
      }
    }
    cout << id + 1 << endl;
  }
  return 0;
}


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

using namespace std;

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;

typedef pair<ll, ll> P;

#define bit(n) (1LL << (n))

//#define int long long

#define all(v) v.begin(), v.end()

#define rep(i, n) for (ll i = 0; i < n; i++)
#define REP(i, n) for (ll i = 1; i < n; i++)

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

template <class T>
inline void chmax(T& a, T b) {
  a = std::max(a, b);
}
template <class T>
inline void chmin(T& a, T b) {
  a = std::min(a, b);
}

#define mod (ll)(1e9 + 7)
const long long INF = 1LL << 60;

struct Edge {
  int to;
  ll cost;
};
using Graph = vector<vector<Edge>>;

vector<bool> can_reach(const Graph& G, int start) {
  ll n = G.size();
  vector<bool> ans(n);
  queue<int> que;

  que.push(start);
  ans[start] = true;

  while (!que.empty()) {
    int index = que.front();
    que.pop();
    for (const auto& it : G[index]) {
      if (ans[it.to] == false) {
        que.push(it.to);
        ans[it.to] = true;
      }
    }
  }

  return ans;
}

// Bellman Ford
// G: グラフ
// rev: 逆辺のグラフ(閉路検出用)
// start: 始点
// goal: 終点
// 戻り値: goalに行くまでの最小コスト。負の閉路が存在する場合は-INFとなる。
ll bellman_ford(const Graph& G, const Graph& rev, const int start, const int goal) {
  const int n = G.size();

  // 始点からそこまで行くのにかかるのコスト
  vector<ll> cost(n, INF);
  cost[start] = 0;

  for (int i = 0; i < n; i++) {
    // すべての辺を走査
    for (int from = 0; from < n; from++) {
      if (cost[from] == INF) {
        continue;
      }
      for (auto e : G[from]) {
        // 更新
        if (cost[e.to] > cost[from] + e.cost) {
          cost[e.to] = cost[from] + e.cost;
        }
      }
    }
  }

  vector<ll> cost_middle = cost;

  for (int i = 0; i < n; i++) {
    // すべての辺を走査
    for (int from = 0; from < n; from++) {
      if (cost[from] == INF) {
        continue;
      }
      for (auto e : G[from]) {
        // 更新
        if (cost[e.to] > cost[from] + e.cost) {
          cost[e.to] = cost[from] + e.cost;
        }
      }
    }
  }

  // 始点から到達できるか
  auto can_reach_from_start = can_reach(G, start);
  // 各点が終点へ到達できるか
  auto can_reach_from_goal = can_reach(rev, goal);

  for (int i = 0; i < n; i++) {
    if (can_reach_from_start[i] && can_reach_from_goal[i]) {
      // 始点から終点へ移動できるノードの内、値が更新されるものが存在したら負のループが存在する。
      if (cost_middle[i] != cost[i]) {
        return -INF;
      }
    }
  }

  return cost[goal];
}

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

  ll n, m, p;
  cin >> n >> m >> p;

  Graph G(n + 1), rev(n + 1);

  rep(i, m) {
    int a, b;
    ll c;
    cin >> a >> b >> c;
    G[a].push_back((Edge){b, -c + p});
    rev[b].push_back((Edge){a, -c + p});
  }

  ll ans = bellman_ford(G, rev, 1, n);
  ans *= -1;
  chmax(ans, 0ll);
  if (ans == INF) {
    ans = -1;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 768
def f(n, m):
    s = list(map(int,input().split()))
    t = list(map(int,input().split()))
    dpi = [1] * (m + 1)
    for i, sk in enumerate(s):
        dpi1 = dpi[:]
        cs = 0
        for j, tk in enumerate(t):
            if sk == tk:
                cs = (cs + dpi[j]) % md
            dpi1[j + 1] = (dpi1[j + 1] + cs) % md
        dpi=dpi1
#    for x in dp:
#        print(*x)
    print(dpi1[-1])

md = 10 ** 9 + 7
n, m = map(int, input().split())
f(n, m)


Measured memory_bytes: 3316
#include <stdio.h>

int main(){
  int n;

  while(1){
    int otsuri,count,temp;
    count = 0;
    temp = 0;
    scanf("%d",&n);
    if(n == 0) break;
    otsuri = 1000 - n;
    temp = otsuri / 500;
    otsuri = otsuri - 500 * temp;
    count += temp;
    temp = otsuri / 100;
    otsuri = otsuri - 100 * temp;
    count += temp;    
     temp = otsuri / 50;
    otsuri = otsuri - 50 * temp;
    count += temp;
    temp = otsuri / 10;
    otsuri = otsuri - 10 * temp;
    count += temp;
    temp = otsuri / 5;
    otsuri = otsuri - 5 * temp;
    count += temp;
    temp = otsuri / 1;
    count += temp;   

    printf("%d\n",count);
  }
    
  return 0;
}
  

Measured memory_bytes: 0
{-# LANGUAGE
    BangPatterns, MultiWayIf, TupleSections, TypeApplications #-}
{-# OPTIONS_GHC -O2 #-}


import Control.Arrow
import Control.Concurrent
import Control.Monad
import qualified Data.ByteString.Builder as B
import qualified Data.ByteString.Char8 as C
import Data.Complex
import Data.Char
import Data.Function
import Data.Function.HT
import qualified Data.IntMap.Strict as IM
import qualified Data.IntSet as IS
import Data.List
import Data.Monoid
import Data.Ord
import qualified Data.Sequence as Sq
import Data.Vector.Algorithms.Search
import qualified Data.Vector as V
import qualified Data.Vector.Mutable as VM
import qualified Data.Vector.Unboxed as U
import qualified Data.Vector.Unboxed.Mutable as UM
import Debug.Trace
import System.IO


------------------
-- #   Read   # --
------------------

r :: Int -> IO (U.Vector Int)
r n = U.unfoldrN n (C.readInt . C.dropWhile (==' ')) <$> C.getLine

r' :: IO [Int]
r'  =   unfoldr    (C.readInt . C.dropWhile (==' ')) <$> C.getLine


main :: IO ()
main = do
    n <- readLn :: IO Int
    as <- r'
    print $ length $ filter ((uncurry (&&)).(odd *** odd)) $ zip [1..] as


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

using namespace std;
#define int long long
#define double long double
#define rep(i, n) for(int i=0;i<(n);++i)
#define INF (1ll<<60)
#define FI first
#define SE second
typedef pair<int, int> pii;
#define l_b lower_bound
#define u_b upper_bound

int N, M;
int x[100100], y[100100];
const int mod = 1000000007;

signed main() {
    cin >> N >> M;
    int sx = 0, sy = 0;
    for (int k = 1; k <= N; ++k) {
        cin >> x[k];
        x[k] = x[k] * (k - 1) - x[k] * (N - k);
        x[k] %= mod;
        sx += x[k];
        sx %= mod;
    }
    for (int k = 1; k <= M; ++k) {
        cin >> y[k];
        y[k] = y[k] * (k - 1) - y[k] * (M - k);
        y[k] %= mod;
        sy += y[k];
        sy %= mod;
    }
    cout << sx * sy % mod << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h> 
#define ll long long
#define F first
#define S second
#define FF first.first
#define FS first.second
#define pb push_back
using namespace std;
const ll N=1000006, INF=1e16, MOD=998244353;
     
ll n, q=1, a[N], b[N], c[N], m, x, y, z, X, Y, Z, o, u, h, w, mx, mn, ans=INF, Ans, k;
string s, S;
vector <ll> v[N];
pair<ll, ll> p[N];

main(){ios_base::sync_with_stdio(false), cin.tie(0);
                    
//    cin>>q;
                        
    while(q--){ans=INF;
        
        cin>>n;n*=2;
		cout<<(double)n*3.1415;
	}
	
}

Measured memory_bytes: 27244
fun main(args: Array<String>) {
    val n = readLine()!!.split(" ").map { it.toInt() }[0]
    val sum = readLine()!!.split(" ").map { it.toInt() }.sum()
    if (n < sum) {
        println(-1)
    } else {
        println(n-sum)
    }
}

Measured memory_bytes: 39360
#coding:utf-8
import sys
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = lambda *something : print(*something) if DEBUG else 0
DEBUG = False
def main(input = sys.stdin.readline):
    LMIIS = lambda : list(map(int,input().split()))
    II = lambda : int(input())

    N,M = LMIIS()
    for i in range(M//N,0,-1):
        if M % i == 0:
            print(i)
            return



if __name__ == '__main__':
    main()

Measured memory_bytes: 38384
#define w 200001
i;x;y;p;main(n,m,j,u){
  long int k,a[w],A[w],b[w],B[w];
  scanf("%d%d%ld",&n,&m,&k);
  
  for(;x<n;x++)scanf("%ld",&a[x]),A[x+1]=A[x]+a[x];
    
  for(;y<m;y++){
    scanf("%ld",&b[y]);
    B[y+1]=B[y]+b[y];
  }
  u=m;
        
  for(;i<=n;i++){
    if(A[i]>k)break;
            
    for(j=u;j>=0;j--){
      if(A[i]+B[j]<=k){
        if(i+j>p)p=i+j;
        u=j;
        break;
      }
    }
  }
  printf("%d",p);
}

Measured memory_bytes: 7964
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define ll long long
#define vi vector<int>
#define vii vector<vi>
#define vs vector<string>
#define vss vector<vs>
#define pii pair<int, int>
#define all(x) x.begin(), x.end()
#define rep(i, a, n) for (ll i = (a); i < (n); ++i)
#define repr(i, a, n) for (ll i = (n); i >= (a); --i)
using namespace std;
const int INF(1 << 30);
const ll LLINF(1LL << 55LL);
const int pi = 3.1415926536;
const int MOD = 1000000007;
const int MAX = 510000;

void Main() {
  int N, M;
  map<string, int> card;
  cin >> N;
  rep(i, 0, N) {
    string s;
    cin >> s;
    card[s]++;
  }
  cin >> M;
  rep(i, 0, M) {
    string t;
    cin >> t;
    if (card[t] != 0) {
      card[t]--;
    }
  }
  int ans = -INF;
  for (auto &c : card) {
    if (c.second > ans) {
      ans = c.second;
    }
  }
  cout << ans << endl;
}

int main() {
  std::cin.tie(nullptr);                  // 標準入出力高速化
  std::ios_base::sync_with_stdio(false);  // CとC++の入出力出力を非同期
  std::cout << std::fixed << std::setprecision(15);  // 小数を10進数表示
  Main();
}

Measured memory_bytes: 256
#-------最強ライブラリSCC(Python) ver25252------
class scc_graph:
  # n 頂点数
  def __init__(s, n): 
    s._n = n
    s.edge = [s.component() for i in range(n)]
  def num_vertices(s): return s._n
  # 辺を追加 frm 矢元 to 矢先
  # O(1)
  def add_edge(s, frm, to): 
    s.edge[frm].add_go(to)
    s.edge[to].add_rgo(frm)

  # グループの個数と各頂点のグループidを返す
  def scc_ids(s):
    def dfs(v):
      stack = [v]
      while stack:
        t = stack.pop()
        vis[t] = True
        for i in s.edge[t].go:
          if not vis[i]:
            stack.append(t)
            stack.append(i)
            break
        else:
          vs.append(t)

    def rdfs(v, n):
      stack = [v]
      vis[v] = True
      ids[v] = n
      while stack:
        t = stack.pop()
        vis[t] = True
        for i in s.edge[t].rgo:
          if not vis[i]:
            ids[i] = n
            stack.append(i)

    vis = [False] * s._n 
    vs = []
    ids = [-1] * s._n
    for i in range(s._n):
      if not vis[i]:
        dfs(i)
    group_num = 0
    vis = [False] * s._n 
    for i in vs[::-1]:
      if not vis[i]:
        rdfs(i, group_num)
        group_num += 1
    return group_num, ids 

  # 強連結成分となっている頂点のリストのリスト トポロジカルソート済み
  # O(n + m)
  def scc(s):
    ids = s.scc_ids()
    group_num = ids[0]
    counts = [0] * group_num
    for x in ids[1]: counts[x] += 1
    groups = [[] for _ in range(group_num)]
    for i in range(s._n):
      groups[ids[1][i]].append(i)
    return groups

  class component:
    def __init__(s):
      s.go = []
      s.rgo = []
    def add_go(s, to):
      s.go.append(to)
    def add_rgo(s, frm):
      s.rgo.append(frm)

#-------最強ライブラリここまで------

import sys
def main():
  input = sys.stdin.readline

  n, m = list(map(int, input().split()))
  ab = [list(map(int, input().split())) for _ in range(m)]

  g = scc_graph(n)

  for i in range(m):
    u, v = ab[i]
    g.add_edge(u, v)

  scc = g.scc()

  print(len(scc))

  for v in scc:
    print(len(v), end = " ")
    for x in v:
      print(x, end = " ")
    print("")

main()


Measured memory_bytes: 323576
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
#define rep(i,m,n) for(int i=m;i<n;i++)
#define co(n) cout<<n<<endl
#define all(n) (n).begin(),(n).end()
#define pb(n,m) n.push_back(m)
#define pi(n,m) n.insert(n.begin(),m);
#define ee(n) n.erase(n.end()-1)
#define eb(n) n.erase(n.begin())
using namespace std;
//using bint=boost::multiprecision::cpp_int;
typedef long long ll;
typedef unsigned long long ull;

int main(){
  ll n,m,k; cin>>n>>m>>k;
  ll a=0,b=0,ans=0;
  vector<ll> x(n),y(m);
  rep(i,0,n){
    ll z; cin>>z;
    a+=z; x[i]=a;
  }
  rep(i,0,m){
    ll z; cin>>z;
    b+=z; y[i]=b;
  }
  ans=upper_bound(all(y),k)-y.begin();
  rep(i,0,n){
    if(x[i]>k) break;
    ll v=upper_bound(all(y),k-x[i])-y.begin();
    ans=max(ans,v+i+1);
  }
  co(ans);
  
  return 0;
}

Measured memory_bytes: 6440
#include <algorithm>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
#include <math.h>
#include <utility>
#include <map>
#include <queue>
#include <stack>
#include <deque>

using namespace std;

#define INF 210000000
#define int long long

int gcd(int a, int b) {
  int amari = a % b;
  int c = b;
  if (amari == 0) {
    return b;
  } else {
    return gcd(b, amari);
  }
}

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

signed main() {
    vector<char> a;
    vector<char> b;
    for(int i=0;i<3;i++){
        char tmp;
        cin >> tmp;
        a.push_back(tmp);
    }
    for(int i=0;i<3;i++){
        char tmp;
        cin >> tmp;
        b.push_back(tmp);
    }
    string ans = "YES";
    for(int i=0;i<3;i++){
        if(a[i] != b[2-i]) {
            ans = "NO";
            break;
        }
    }
    cout << ans << endl;
}



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

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

    int res = 0;
    char prev = '*';
    rep(i, 0, N)
    {
        char now;
        cin >> now;
        if (now == prev) continue;
        else 
        {
            prev = now;
            ++res;
        }
    }
    cout << res << endl;
    return 0;
}

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

int main() {
	int n, ans = 0,x,sum=0,a[10000];
	int  m, t;
	cin >> n >> m >> t;
	
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}

	a[n + 1] = t + m;
	a[0] = -1 * m;

	for (int i = 0; i <= n; i++) {
			x = a[i + 1] - a[i];
		
		if (x > m * 2)
			sum = sum + (x - 2 * m);
	}

	cout << sum << endl;

}

Measured memory_bytes: 3088
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {

		Scanner sc = new Scanner(System.in);

		String X = sc.next();
		String Y = sc.next();

		if (X.compareTo(Y) < 0){
			System.out.println("<");
		} else if (X.compareTo(Y) > 0){
			System.out.println(">");
		} else {
			System.out.println("=");
		}

	}
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
int main(){
    while(1){
        int h,w;
        cin >> h >> w;
        if(h==0&&w==0)return 0;
        for(int i=0;i<h;i++){
            if(i==0||i==h-1){
            for(int r=0;r<w;r++){
                cout << "#" << flush;  
                }
            }
            else{
                cout << "#" << flush;
                for(int r=0;r<w-2;r++){
                cout << "." << flush;  
                }
                cout << "#" << flush;

            }
            cout << endl;
        }
        cout << endl;
    }
}



Measured memory_bytes: 3092
#include <cstdio>
#include <string>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <cassert>
#include <stack>
#include <queue>
#include <cmath>
#include <map>
#include <set>

using namespace std;

char op[8120];

int ok(vector<int> v,int val)
{
  set<int> s;
  s.insert(0);
  for(int i=0;i<v.size();i++)
  {
    set<int> tp;
    for(int a:s)
    {
      tp.insert(a+v[i]);
      tp.insert(a-v[i]);
    }
    s=tp;
  }
  return s.find(val)!=s.end();
}

int main()
{
  scanf("%s",op);
  int x,y;
  string s=op;
  int i=0;
  scanf("%d%d",&x,&y);
  while (s[i]=='F'&&i<s.size())
    i++;
  x-=i;
  s=s.substr(i);
  vector<int> X,Y;
  int cnt=0;
  for(int i=0;i<s.size();)
  {
    if(s[i]=='T')
    {
      cnt++;
      i++;
    }
    else
    {
      int tp=0;
      while(s[i]=='F'&&i<s.size())
      {
        i++;
        tp++;
      }
      if(cnt&1)
        Y.push_back(tp);
      else
        X.push_back(tp);
    }
  }
  if(ok(X,x)&&ok(Y,y)) cout<<"Yes";
  else cout<<"No";
  return 0;
}


Measured memory_bytes: 640
#include <stdio.h>

int main(void){
        int a,b,c,sum;
        if(scanf("%d",&a)<1||scanf("%d",&b)<1||scanf("%d",&c)<1){
                printf("Error in scanf");
                exit(1);
        }

        if(a<b){
                if(b<c){
                        sum=a+b;
                }else{
                        sum=a+c;
                }
        }else{
                if(a<c){
                        sum=a+b;
                }else{
                        sum=b+c;
                }
        }
        printf("%d\n",sum);
        return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int i=2,j,m,n,a,b;
    cin>>n;
    a=1000;
    while(1)
    {
        if(a>=n)
        {
            b=a-n;
            cout<<b<<endl;
            break;
        }
        else a=1000*i;
        i++;
    }
}


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

int N;
int x;
int a[105];
long long sum=0;
int happy=0;

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

    for (int i=1; i<=N; i++)
    {
        cin>>a[i];
        sum=sum+a[i];
    }

    sort(a+1, a+N+1);

    if (x==sum)
    {
        cout<<N<<endl;
    }

    else if (x>sum)
    {
        cout<<N-1<<endl;
    }

    else if (x<sum)
    {
        for (int i=1; i<=N; i++)
        {
            x=x-a[i];
            
            if (x<0)
            {
                cout<<happy<<endl;
                break;
            }

            else if (x==0)
            {
                happy=happy+1;
                cout<<happy<<endl;
                return 0;
            }

            else
            {
                happy=happy+1;
            }
        }
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define reg register
using namespace std;
string ss;
int w, n, e, s;
inline bool check() {
    if(w && e  && n && s )return 1;
    if(w  && e && n == 0 && s == 0)return 1;
    if(w == 0 && e == 0 && n && s)return 1;
    if(w == 0 && e == 0 && n == 0 && s == 0)return 1;
    return 0;
}
int main() {
    getline(cin, ss);
    for(reg int i = 0; i < ss.length(); i++)
        if(ss[i] == 'W')w++;
        else if(ss[i] == 'N')n++;
        else if(ss[i] == 'E')e++;
        else if(ss[i] == 'S')s++;
    puts(check() ? "Yes" : "No");
    return 0;
}

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

int main() {
	string s;
	cin>>s;
	int n = s.size();
	if(s[n-1] == 's'){
	    cout<<s<<"es";
	}
	else{
	    cout<<s<<"s";
	}
	return 0;
}


Measured memory_bytes: 3628
n = int(input())
s = input()
arr = []
E = s.count('E')
w = 0
e = 0
for i in range(n):
  if s[i] == 'W':
    arr.append(w + E - e)
    w += 1
  else:
    arr.append(w + E - e - 1)
    e += 1
ans = min(arr)
print(ans)

Measured memory_bytes: 21392
#include <bits/stdc++.h>
#include<algorithm>
using namespace std;
#define ll long long 

int main() {
  int n;
  string c;
  cin >> n >> c;
  
  int x,y,z;
  x = 0;
  y = 0;
  z = 0;
  for(int i = 0;i<n;i++){
    if(c[i] == 'R'){
      y++;
    }else{
      x++;
    }
  }
  
  for(int i = 0;i<y;i++){
    if(c[i] == 'W'){
      z++;
    }
  }
  
  cout << z;
}


Measured memory_bytes: 3716
#include <iostream>
#include <vector>
#include <set>
using namespace std;

#define REP(i,n)    for(int i = 0; i < (int)n; i++)

void solve(){
    int n;
    cin >> n;
    vector<int> d(n);
    set<int> s;
    REP(i,n){
        cin >> d[i];
        s.insert(d[i]);
    }
    cout << s.size() << endl;
}

int main(){
    solve();
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef list<int> liint;
typedef pair<int, int> pint;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }



int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll N, K, S;
    cin >> N >> K >> S;
    vll ans(N);
    rep(i, K) ans[i] = S;
    if (S < 1000000000) {
        REP(i, K, N) ans[i] = S + 1;
    }
    else {
        REP(i, K, N) ans[i] = 1;
    }
    rep(i, N){
        cout << ans[i] << " ";
    }

    cout << endl;
    return 0;
}

Measured memory_bytes: 2176
#include <stdio.h>

int area(int d)
{
	int i, s=0;
	for(i=d; i<600; i+=d)
	{
		s+=d*i*i;
	}
	return s;
}

int main (void)
{
	int d;
	while(scanf("%d", &d)!=EOF)
	{
		printf("%d\n", area(d));
	}
	return 0;
}

Measured memory_bytes: 0
/*
!لَا أَبْرَحُ حَتَّىٰ أَبْلُغَ
فَصَبْرٌ جَمِيلٌ
*/
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define endl                         '\n'	
#define Ceil(x,y)             ((x+y-1)/y)
#define sz(s)               (int)s.size()
#define RT(x)           return cout<<x,0;
#define mem(x,y)    memset(x,y,sizeof(x))
#define all(v) ((v).begin()), ((v).end())
#define vi                    vector<int>
#define Rabe3_adel           file();
#define fr(x,y) for(int x=0; x<(y); ++x)
const double PI = acos(-1), EPS = 1e-7;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int dr[] { -1, -1, 0, 1, 1, 1, 0, -1 };
const int dc[] { 0, 1, 1, 1, 0, -1, -1, -1 };
ll gcd(ll x, ll y) { return (!y) ? x : gcd(y, x%y); }
ll lcm(ll x, ll y) { return ((x / gcd(x, y))*y); }
ll mod = 998244353;
ll power(ll x, ll y)
{
	if (y == 0)return 1;
	if (y == 1)return x;
	ll r = power(x, y / 2) % mod;
	return r%mod*r%mod*power(x, y % 2) % mod;
}
void file() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif  !ONLINEJUDGE
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

}

int main()
{
	
	Rabe3_adel
		ll x, z = 100, ans = 0;
	cin >> x;
	while (z<x)
	{
		ans++;
		z += (z*0.01);

	}
	cout << ans;

}

Measured memory_bytes: 3648
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
#include <cctype>
#include <queue>
#include <algorithm>
using namespace std;
typedef long long lint;
#define cout cerr
#define ni (next_num<int>())
template<class T>inline T next_num(){
	T i=0;char c;
	while(!isdigit(c=getchar())&&c!='-');
	bool flag=c=='-';
	flag?c=getchar():0;
	while(i=i*10-'0'+c,isdigit(c=getchar()));
	return flag?-i:i;
}
template<class T1,class T2>inline void apmax(T1 &a,const T2 &b){if(a<b)a=b;}
template<class T1,class T2>inline void apmin(T1 &a,const T2 &b){if(b<a)a=b;}
const int N=2010;
int gcd(int a,int b){
	return b?gcd(b,a%b):a;
}
bool con[N][N];
int n,a[N];
struct cmp2{
	inline bool operator () (int x,int y){
		return a[x]<a[y];
	}
};
int dfn[N],tim=0;
int lst[N];
void dfs(int x){
	dfn[x]=++tim;
	for(int i=1,v;i<=n;i++){
		if(dfn[v=lst[i]]==0&&con[x][v]){
			dfs(v);
		}
	}
}
int deg[N];
inline void topsort(){
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			if(con[i][j]&&dfn[i]<dfn[j]){
				deg[j]++;
			}
		}
	}
	priority_queue<int,vector<int>,cmp2>q;
	for(int i=1;i<=n;i++){
		if(deg[i]==0){
			q.push(i);
		}
	}
	while(!q.empty()){
		int x=q.top();
		q.pop();
		printf("%d ",a[x]);
		for(int v=1;v<=n;v++){
			if(con[x][v]&&dfn[x]<dfn[v]&&(--deg[v])==0){
				q.push(v);
			}
		}
	}
}
inline bool lcmp(int x,int y){
	return a[x]<a[y];
}
int main(){
	n=ni;
	for(int i=1;i<=n;i++){
		a[i]=ni;
		lst[i]=i;
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			con[i][j]=gcd(a[i],a[j])!=1;
		}
	}
	sort(lst+1,lst+n+1,lcmp);
	memset(dfn,0,sizeof(dfn));
	for(int i=1;i<=n;i++){
		if(dfn[lst[i]]==0){
			dfs(lst[i]);
		}
	}
	topsort();
	putchar('\n');
	return 0;
}

Measured memory_bytes: 4352
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <tuple>
#include <set>
#include <map>
#include <unordered_map>
#include <complex>
#include <iomanip>
#include <cmath>
using namespace std;
typedef long long ll;

int main()
{
  int n, m;
  string s, ans = "Yes";
  cin >> n >> m >> s;

  for (int i = 0; i < s.size(); i++) {
    if (i == n && s[i] != '-') {
      ans = "No";
      break;
    }
    if (i != n && s[i] == '-') {
      ans = "No";
      break;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(k,i,n) for(long long i=k;i<n;++i)
using namespace std;
typedef long long ll;
int main(void){
    // Your code here!
    string S;
    cin>>S;
    rep(0,i,S.length()){
        string A=S.substr(i,1);
        if((i%2==0&&A=="L")||(i%2==1 && A=="R")){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
}


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



int main() {
  int64_t X;
  cin>>X;
  int64_t E=0;
  for(int64_t i=1;i<10000000000;i++){
    if(i*(i+1)>=2*X){
      cout<<i<<endl;
      break;
    }
  }
}

Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod = 1e9+7;

int main() {
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    int k = 0;
    while (1) {
        if (c <= 0) {
            cout << "Yes" << endl;
            return 0;
        }
        if (a <= 0) {
            cout << "No" << endl;
            return 0;
        }
        if (k == 0) {
            c -= b;
            k = 1;
        } else {
            a -= d;
            k = 0;
        }
    }   
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int n, h, a, b, c, d, in[500], out[500], f[N], ok[N];
int find(int x) {
    if(x == f[x]) return x;
    return f[x] = find(f[x]);
}
int main() {
    scanf("%d %d", &n, &h);
    for(int i = 1; i <= n; ++i) f[i] = i;
    for(int i = 1; i <= n; ++i) {
        scanf("%d %d %d %d", &a, &b, &c, &d);
        int x = h, y = h;
        if(!d) x -= b; else x += d;
        if(!c) y += a; else y -= c;
        ++out[x]; ++in[y];
        int fx = find(x), fy = find(y);
        if(fx != fy) f[fx] = fy;
    }
    for(int i = 1; i <= h + h; ++i) 
        if(out[i] != in[i] || (!out[i] && !in[i])) ok[find(i)] = 1;
    int ans = 1;
    for(int i = 1; i <= h; ++i) if(in[i] > out[i]) ans = 0;
    for(int i = h + 1; i <= h + h; ++i) if(out[i] > in[i]) ans = 0;
    for(int i = 1; i <= h + h; ++i) if(f[i] == i && !ok[i]) ans = 0;
    printf(ans ? "YES\n" : "NO\n");
    return 0;
}


Measured memory_bytes: 4168
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip> // setprecision
#include <complex> // complex
#include <functional>
#include <math.h> 
#define enld '\n'
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const int dx[8] = {1, 0, -1, 0,1,1,-1,-1};
const int dy[8] = {0, 1, 0, -1,1,-1,1,-1};
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; }
// ---------------------------------------------------------------------------



int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  cin >> N;
  string S;
  cin >> S;
  int ans = 0;
  int r = N-1;
  for(int i=0; i<r; i++){
    if(S[i] == 'W'){
      while(i<r){
        if(S[r] == 'R'){
          ans++;
          r--;
          break;
        }
        r--;
      }
    }
  }
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 3728
from collections import defaultdict

N = int(input())
S = input()
left = S[:N]
right = S[:N-1:-1]

# leftの(blue, red)のパターンを全列挙
br_pattern = defaultdict(int)

for bit in range(1<<N):
    blue = ""
    red = ""
    for isb in range(N):
        if bit & (1<<isb):
            blue = blue + left[isb]
        else:
            red = red + left[isb]
            
    br_pattern[(blue, red)] += 1

# rightの(red, blue)のパターンをひとつずつ調べ、br_patternに一致する数だけansに足す
ans = 0
for bit in range(1<<N):
    red = ""
    blue = ""
    for isr in range(N):
        if bit & (1<<isr):
            red = red + right[isr]
        else:
            blue = blue + right[isr]
            
    ans += br_pattern[(red, blue)]
        
print(ans)

Measured memory_bytes: 166136
def calc(m)
  return @memo[m] if @memo.key?(m)
  return 1 if m < 2

  @memo[m] = calc(m-1) + calc(m-2)
  @memo[m]
end

MOD = 10**9 + 7
N, M = gets.chomp.split.map(&:to_i)
@memo = {}
x = []
start = 0
M.times do
  bs = gets.to_i
  finish = bs - 1
  if start == bs
    x << 0
    break
  else
    x << calc(finish - start)
  end
  start = bs + 1
end
x << calc(N - start)
ans = 1
x.each do |_x|
  ans = ans * _x % MOD
end
puts ans

Measured memory_bytes: 458728
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include <queue>
#include <utility>
#include <map>
using namespace std;

int main() {
    string O, E;
    cin >> O >> E;

    
    for (int i = 0; i<E.size(); i++) {
        cout << O[i] << E[i];
    }
    if (O.size() > E.size())cout << O[O.size() - 1];
    
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
  int n,d,x;
  int a[110];
  scanf("%d %d %d",&n,&d,&x);
  for(int i=0;i<n;i++){
    scanf("%d",&a[i]);
  }

  int sum=n;
  for(int i=0;i<n;i++){
    int start=1;
    while(start+a[i]<=d){
      sum++;
      start+=a[i];
    }
  }

  printf("%d\n",sum+x);
  return 0;
}


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

int point(vector<int> &a,int start){
	int v = 0;
	while(start < a.size()){
		v += a[start];
		start += 2;
	}
	return v;
}

bool func(int a,int b){
	return a > b;
}

int main(){
	int n;
	cin >> n;
	vector<int> a(n);
	for(int i=0;i<n;++i){
		cin >> a[i];
	}
	sort(a.begin(),a.end(),func);
	cout << (point(a,0) - point(a,1)) << endl;
}

Measured memory_bytes: 256