akhauriyash/Code-Regression huggingface dataset:
// Author : Nachiket Kanore
// Institute : PICT, Pune

/* 
   If you know what you’re worth, 
   then go out and get what you’re worth
   But you gotta be willing to take the hits, 
   and not pointing fingers saying you ain’t 
   where you wanna be because of him, or her, or anybody. 
   Cowards do that and that ain’t you. You’re better than that! 
*/

#include <bits/stdc++.h>

using namespace std;
#define int long long
#define ld long double
#define endl '\n'
#define rep(x,s,e) for(int x=s;x<=(e);x++)
#define repn for(int x=0;x<n;x++)
#define rep1n for(int x=1;x<=n;x++)
#define rep1m for(int y=1;y<=m;y++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(), x.rend()
#define precise(x) cout << fixed << setprecision(x)
#define bits(x) __builtin_popcount(x)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define test int t; cin>>t; while(t--)
#define FAST                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL)

typedef vector<int> vi;
typedef vector<pair<int,int>> vii;
typedef pair<int,int> pii;


void __print(int x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}


template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define see(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define see(x...)
#endif

const int inf = 1e18;
const int N = 1e5+5;


int32_t main(){
    FAST;

    int h , n;  cin >> h >> n;
    int sum = 0;
    for(int i = 0; i < n; i++){
        int v;  cin >> v;
        sum += v;
    }   cout << (sum >= h? "Yes" : "No") << endl;
    
    return 0;
}




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

int main(){
    string s;
    int k;
    cin >> s >> k;

    for(int i=0;i<s.size();++i){
        if(s[i] != 'a' && k > 'z' - s[i]){
            k -= ('z' - s[i] + 1);
            s[i] = 'a';
        }
    }

    k %= 26;

    while(k > 0){
        s[s.size()-1]++;
        k--;
    }

    cout << s << endl;

    return 0;
}


Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

    public Main() {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();

        int AC=0;
        int WA=0;
        int TLE=0;
        int RE=0;
        for (int i = 0; i < N; i++) {
            String S = scanner.next();
            if(S.equals("AC")){
                AC++;
            } else if(S.equals("WA")){
                WA++;
            } else if(S.equals("TLE")){
                TLE++;
            } else if(S.equals("RE")){
                RE++;
            }
        }
        System.out.println("AC x " + AC);
        System.out.println("WA x " + WA);
        System.out.println("TLE x " + TLE);
        System.out.println("RE x " + RE);
    }

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


Measured memory_bytes: 58012
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef long long int lli;
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 (a>b) { a=b; return true; } return false; }

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

int main(){
    int n, m;
    cin >> n >> m;
    map<int, set<int>> mp;
    rep(i,m) {
        int a, b;
        cin >> a >> b;
        mp[a].insert(b);
    }
    for(int a: mp[1]){
        if (mp[a].find(n) != mp[a].end()){
            cout << "POSSIBLE" << endl; 
            return 0;
        }
    }
    cout << "IMPOSSIBLE" << endl;
}

Measured memory_bytes: 31616
#include<iostream>
#include<vector>
#include<algorithm>
#include<stdio.h>
using namespace std;
int main() {
	char s[1000];
	string str;
	int n,kari,count=0,ans=0,a,b,c;
	vector<int> x, y;
	cin >> a>>b>>c;
	if (a + b >= c || a + b == c + 1)cout << b + c << endl;
	else cout << c + b - (c - (a + b + 1)) << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <math.h>
#include <queue>
#include <vector>

using namespace std;

const int SIZE = 3e2 + 10;
const int N = 1e4 + 10;
const int NN = 1e3 + 10;

struct AC {
    int ch[N][SIZE];
    int sz;
    int f[N];
    bool ed[N];
    int last[N];
    int vt[N][SIZE];
    int vn[N];
    int co[NN][NN];

    int newnode() {
        memset(ch[sz], 0, sizeof(ch[sz]));
        ed[sz] = false;
        f[sz] = 0;
        last[sz] = 0;
        vn[sz] = 0;
        return sz++;
    }

    void init() {
        memset(co, 0, sizeof(co));
        sz = 0;
        newnode();
    }

    void insert(int id, char *s) {
        int u = 0;
        int len = strlen(s);
        for (int i = 0; i < len; i++) {
            int idx = s[i];
            if (!ch[u][idx])
                ch[u][idx] = newnode();
            u = ch[u][idx];
        }
        ed[u] = true;
        vt[u][vn[u]++] = id;
    }

    void getfail() {
        queue<int> q;
        for (int i = 0; i < SIZE; i++)
            if (ch[0][i])
                q.push(ch[0][i]);

        while (!q.empty()) {
            int u = q.front();
            q.pop();
            for (int i = 0; i < SIZE; i++) {
                int v = ch[u][i];
                if (v) {
                    q.push(v);
                    int r = f[u];
                    while (r && !ch[r][i])
                        r = f[r];
                    f[v] = ch[r][i];
                    last[v] = (ed[f[v]] ? f[v] : last[f[v]]);
                }
                else {
                    ch[u][i] = ch[f[u]][i];
                }
            }
        }
    }

    void print(int r, int j, int c) {
        if (j) {
            for (int i = 0; i < vn[j]; i++)
                if (r >= vt[j][i])
                    co[r - vt[j][i]][c]++;
            print(r, last[j], c);
        }
    }

    void find(int r, char *s) {
        int u = 0;
        int len = strlen(s);
        for (int i = 0; i < len; i++) {
            int idx = s[i];
            u = ch[u][idx];
            if (ed[u]) print(r, u, i);
            else if (last[u]) print(r, last[u], i);
        }
    }

}ac;

char Mat[NN][NN];

int main() {

        int n, m, x, y;
        scanf("%d ", &n);scanf("%d ", &x);
        m=n;
        for (int i = 1; i <= n; i++)
            scanf("%s", Mat[i]);
        ac.init();

        y=x;
        for (int i = 1; i <= x; i++) {
            char str[SIZE];
            scanf("%s", str);
            if (x <= n && y <= m)
                ac.insert(i, str);
        }
        int ans = 0;
        if (x <= n && y <= m) {
            ac.getfail();
            for (int i = 1; i <= n; i++)
                ac.find(i, Mat[i]);

            for (int i = 0; i < n; i++)
                for (int j = 0; j < m; j++)
                    if (ac.co[i][j] == x)
                        ans++;
        }
        puts(ans?"Yes":"No");
    return 0;
}


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

int main(){
      int N;cin >> N;
      int X[N],L=0,M=0,ans1=0,ans2=0;
      for(int i = 0;i<N;i++){
            cin >> X[i];
            L+=X[i];
      }
      M = L/N;
      L = (double)L / (double)N + 0.999999;
      for(int i=0;i<N;i++){
            if(X[i] > L){
                  int P = X[i];
                  ans1 += (P - L) * (P - L);
            }else{
                  int P = X[i];
                  ans1 += (L - P) * (L - P);
            }
      }
      
      for(int i=0;i<N;i++){
            if(X[i] > M){
                  int P = X[i];
                  ans2 += (P - M) * (P - M);
            }else{
                  int P = X[i];
                  ans2 += (M - P) * (M - P);
            }
      }
      if(ans1 > ans2){
            cout << ans2 << endl;
      }else{
            cout << ans1 << endl;
      }
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;
int main (){

	int n;
	cin>>n;
	int a[100001];
	int p = 0;
	for(int i = 1;i < n+1;i++){
		cin>>a[i];
	}
	for(int i = 1;i < n+1;i++){
		if(a[a[i]]==i) {
			p++;
		}
	}
	

	cout<<p/2<<endl;
return 0;
}


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

ll merge_cnt(vector<ll> &a) {
    int n = a.size();
    if (n <= 1) { return 0; }

    ll cnt = 0;
    vector<ll> b(a.begin(), a.begin()+n/2);
    vector<ll> c(a.begin()+n/2, a.end());

    cnt += merge_cnt(b);
    cnt += merge_cnt(c);

    int ai = 0, bi = 0, ci = 0;
    // merge の処理
    while (ai < n) {
        if ( bi < b.size() && (ci == c.size() || b[bi] > c[ci]) ) {
            a[ai++] = b[bi++];
        } else {
            cnt += n / 2 - bi;
            a[ai++] = c[ci++];
        }
    }
    return cnt;
}

ll n,k;
vector<ll> a;
int main(){
    cin>>n>>k;
    a.resize(n+1);
    FOR(i,1,n+1){
        cin>>a[i];
        a[i]-=k;
        a[i]+=a[i-1];
    }
    cout<<merge_cnt(a)<<endl;
}

Measured memory_bytes: 4992
n = input()
A = map(int, raw_input().split())
count = 0
for i in xrange(n):
    for j in xrange(n-1,i,-1):
        if A[j] < A[j-1]:
            key = A[j]
            A[j] = A[j-1]
            A[j-1] = key
            count += 1
print ' '.join(map(str, A))
print count

Measured memory_bytes: 4224
#include <bits/stdc++.h>
#ifdef _DEBUG
#include "debug.hpp"
#else
#define debug(...)
#endif
#define REP(i, m, n) for(int (i) = (m); (i) < (n); ++i)
#define rep(i, n) REP(i, 0, n)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1e9 + 7;
const ll LINF = 1LL << 60;
template<class T, class U> inline bool chmax(T &a, const U &b) { if(a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if(a > b) { a = b; return true; } return false; }

ll dp[110][110];

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> rw(n), cl(n);
  rep(i,n) cin >> rw[i] >> cl[i];
  rep(i,110) rep(j,110) dp[i][j] = LINF;
  rep(i,110) dp[i][i] = 0;
  REP(i,1,n+1) rep(l,n) {
    int r = l+i;
    if(r >= n) continue;
    REP(j,l,r) {
      chmin(dp[l][r], dp[l][j]+dp[j+1][r]+rw[l]*cl[j]*cl[r]);
    }
  }
  cout << dp[0][n-1] << '\n';
  return 0;
}


Measured memory_bytes: 3276
a, b, c, x  = [int(input()) for _ in range(4)]
x //= 50
ans = 0
for i in range(a + 1):
    for j in range(b + 1):
        for k in range(c + 1):
            p = 10 * i + 2 * j + k
            if p == x:
                ans += 1
print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <functional>
#include <climits>
#include <cstring>

using namespace std;

#define int long long
#define rep(i, n) for (int i=0;i<(int)n;++i)
#define rep1(i, n) for (int i=1;i<=(int)n;++i)
#define unless(a) if(!(a))
#define all(a) begin(a),end(a)
#define fst first
#define scd second
#define PB emplace_back
#define PPB pop_back

using ll=long long;
using vi=vector<int>;
using pii=pair<int, int>;

constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }
bool chmin(int&a,int b){return a>b?(a=b,true):false;}
bool chmax(int&a,int b){return a<b?(a=b,true):false;}
ll read(){ll a;scanf("%lld",&a);return a;}

const int inf = 3 * TEN(18) + 10;
const int mod = 998244353;

struct SegTree { // 区間min,max
	int n;
	vector<int> Max;
	vector<int> Min;
	void init(int n_) {
		n = 1;
		while (n < n_) n *= 2;
		Max.resize(2 * n);
		Min.resize(2 * n);
		for (int i = 0; i < 2 * n - 1; ++i) {
			Max[i] = -inf;
			Min[i] = inf;
		}
	}
	void update(int idx, int val) {
		idx += n - 1;
		Min[idx] = val;
		Max[idx] = val;
		while (idx > 0) {
			idx = (idx - 1) / 2;
			Min[idx] = min(Min[idx * 2 + 1], Min[idx * 2 + 2]);
			Max[idx] = max(Max[idx * 2 + 1], Max[idx * 2 + 2]);
		}
	}
	int get_min(int a, int b, int k = 0, int l = 0, int r = -1) { // [a, b)のmin
		if (r == -1) r = n;
		if (r <= a || b <= l) return inf;
		if (a <= l && r <= b) return Min[k];
		int vl = get_min(a, b, k * 2 + 1, l, (l + r) / 2);
		int vr = get_min(a, b, k * 2 + 2, (l + r) / 2, r);
		return min(vl, vr);
	}
	int get_max(int a, int b, int k = 0, int l = 0, int r = -1) { // [a, b)のmax
		if (r == -1) r = n;
		if (r <= a || b <= l) return -inf;
		if (a <= l && r <= b) return Max[k];
		int vl = get_max(a, b, k * 2 + 1, l, (l + r) / 2);
		int vr = get_max(a, b, k * 2 + 2, (l + r) / 2, r);
		return max(vl, vr);
	}
};


int N;
vector<pii> robots;
int dp[200010];
SegTree st;

signed main()
{
	cin >> N;

	rep(i, N) {
		int x, d; scanf("%lld%lld", &x, &d);
		robots.PB(x, d);
	}

	robots.PB(inf, 0);
	sort(all(robots));

	st.init(N + 5);

	st.update(N - 1, N - 1);

	dp[N] = 1;
	for (int i = N - 1; i >= 0; --i) {
		dp[i] += dp[i + 1];
		dp[i] %= mod;

		pii r = robots[i];

		int distant_idx = lower_bound(all(robots), pii(r.fst + r.scd, 0)) - begin(robots) - 1;
		int nxt = max(st.get_max(i, distant_idx + 1), distant_idx) + 1;

		dp[i] += dp[nxt];
		dp[i] %= mod;

		st.update(i, max(distant_idx, st.get_max(i, distant_idx + 1)));
	}

	cout << dp[0] << endl;
}




Measured memory_bytes: 14188
#include <iostream>
#include <vector>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <stack>
#include <cctype>

using namespace std;

int main(){
	int a, b;
	stack<int> st;
	string op;
	while (cin >> op){
		//cout << op << endl;
		if (isdigit(op[0])) st.push(stoi(op));
		else {
			b = st.top();
			st.pop();
			a = st.top();
			st.pop();
			switch (op[0]){
			case '+':
				st.push(a + b);
				break;
			case '-':
				st.push(a - b);
				break;
			case '*':
				st.push(a * b);
				break;
			}
		}
	}
	cout << st.top() << endl;
}

Measured memory_bytes: 3176
#include <iostream>
#include <map>
#include <algorithm>
using namespace std;
int solve() {
    int n;
    cin >> n;
    map<int, int> odd, even;
    for (int i {}, t {}; i < n / 2; i++) {
        cin >> t;
        odd[t] = (odd.find(t) == odd.end() ? 1 : odd[t] + 1);
        cin >> t;
        even[t] = (even.find(t) == even.end() ? 1 : even[t] + 1);
    }
    auto findMax = [](const auto& m) {
        return *max_element(m.begin(), m.end(), [](const auto& p, const auto& q) {
            return p.second < q.second;
        });
    };
    const auto e1 = findMax(even), o1 = findMax(odd);
    even[e1.first] = 0;
    odd[o1.first] = 0;
    const auto e2 = findMax(even), o2 = findMax(odd);
    if (e1.first != o1.first) return n - e1.second - o1.second;
    return min(n - e1.second - o2.second, n - e2.second - o1.second);
}
int main() {
    cout << solve() << endl;
}


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

typedef long long lint;
typedef long double louble;

template<typename T1,typename T2> inline T1 max(T1 a,T2 b){return a<b?b:a;}
template<typename T1,typename T2> inline T1 min(T1 a,T2 b){return a<b?a:b;}

namespace ae86
{
	const int bufl = 1<<15;
	
	char buf[bufl],*s=buf,*t=buf;
	
	inline int fetch()
	{
		if(s==t){t=(s=buf)+fread(buf,1,bufl,stdin);if(s==t)return EOF;}
		return *s++;
	}
	
	inline int ty()
	{
		int a=0,b=1,c=fetch();
		while(!isdigit(c))b^=c=='-',c=fetch();
		while(isdigit(c))a=a*10+c-48,c=fetch();
		return b?a:-a;
	}
}
using ae86::ty;

const int _ = 103;

int n,ans[_]={0};
vector<int> val;

int main()
{
	n=ty();
	for(int i=1;i<=n;i++)val.emplace_back(ty());

	for(int i=1;i<=n;i++)
	{
		int loc=-1;
		for(int j=0;j<n-i+1;j++)if(val[j]==j+1)loc=j;
		if(loc<0){puts("-1");return 0;}
		ans[i]=loc+1,val.erase(val.begin()+loc);
	}

	for(int i=n;i>=1;i--)printf("%d\n",ans[i]);

	return 0;
}


Measured memory_bytes: 256
//BISMILLAH
#include <bits/stdc++.h>
using namespace std;
int main(){
    
    string s;
    cin >> s;
    if(s == "RRR") cout << 3 << endl;
    else if(s == "SSS") cout << 0 << endl;
    else if(s == "SRS" || s == "RSR" || s == "RSS" || s == "SSR") cout << 1 << endl;
    else cout << 2 << endl;
    return 0;
}

Measured memory_bytes: 3616
from fractions import gcd

def gcds(List):
    __ = 0
    for _ in List:
        __ = gcd(__, _)
    return __

n,x = map(int,input().split())
l = list(map(int,input().split()))

y = []
for i in range(n):
    y.append(abs(l[i]-x))

print(gcds(y))


Measured memory_bytes: 16284
package main

import "fmt"

func main() {
	var n int
	var a int
	fmt.Scanf("%d", &n)
	//list := make([]int, n)
	index := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &a)
		index[a-1] = i
	}
	for i := 0; i < n; i++ {
		fmt.Printf("%d ",index[i]+1)
	}
}


Measured memory_bytes: 6016
package main

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

func main() {
    var fp *os.File
    fp = os.Stdin
    reader := bufio.NewReaderSize(fp, 1024)
    line := readLine(reader)
    arr := strings.Split(line, " ")
    N, _ := strconv.Atoi(arr[0])
    L, _ := strconv.Atoi(arr[1])
    var sum int = 0

    if L > 0 {
        j := L + 1
        cnt := N - 1

        for i := 0; i < cnt; i++ {
            sum += j + i
        }
    } else if L == 0 {
        cnt := N

        for i := L; i < cnt; i++ {
            sum += i
        }
    // minus
    } else {
        // 0またぎ
        if L + N - 1 >= 0 {
            for i := 1; i <= N; i++ {
                sum += L + i - 1
            }
        } else {
            for i := 1; i < N; i++ {
                sum += L + i - 1
            }
        }
    }

    fmt.Println(sum)
}

func readLine(reader *bufio.Reader) string {
    buf := make([]byte, 0, 1024)

    for {
        l, p, _ := reader.ReadLine()

        buf = append(buf, l...)

        if !p {
            break
        }
    }

    return string(buf)
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/



typedef long long ll;
#define INF 1LL<<60
#define rrep(i,a,b) for(int i=a;i>=b;i--)
int N;
ll A[301010];
ll B[301010], C[301010];
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N;
    rep(i, 0, N * 3) cin >> A[i];

    priority_queue<ll> pre; ll sm = 0;
    rep(i, 0, N * 3) {
        pre.push(-A[i]);
        sm += A[i];

        if (N < pre.size()) {
            ll p = pre.top(); pre.pop();
            sm += p;
        }

        B[i] = sm;
    }

    priority_queue<ll> post; sm = 0;
    rrep(i, N * 3 - 1, 0) {
        post.push(A[i]);
        sm += A[i];

        if (N < post.size()) {
            ll p = post.top(); post.pop();
            sm -= p;
        }

        C[i] = sm;
    }

    ll ans = -INF;
    rep(c, N, N * 2 + 1) ans = max(ans, B[c - 1] - C[c]);
    cout << ans << endl;
}

Measured memory_bytes: 9076
#include<iostream>
#include<vector>
using namespace std;
int main(){
    vector<int> a(5) ;
  cin >> a.at(0) >> a.at(1) >> a.at(2) >> a.at(3) >> a.at(4);
  for(int i = 0; i < 5; i++){
    if(a.at(i) == 0){
      cout <<  i + 1 << endl;
      break;}} 
    return 0;}



Measured memory_bytes: 3600
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define _USE_MATH_DEFINES
#include <math.h>
#define rep(i,n) for(int i = 0;i < n;i++)
#define NIL = -1;
#define all(x) x.begin(),x.end()
const ll INF = 1e9;
const ll mod = 1e9 + 7;

int digit(ll x) {
    if (x / 10 == 0) return 1;
    return digit(x / 10) + 1;
}

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

ll lcm(ll a,ll b){
    return ((a * b == 0)) ? 0 : (a / gcd(a,b) * b);
}

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


/////////////////////////////////////////////////////////////////////////////////////////


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

    int n;
    cin >> n;
    double N = n;
    double z = N - (N / 3);
    double x = z - (z / 2);
        
    cout << setprecision(12) << x * (z / 2.0) * (N / 3.0) << endl;
    
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>
#include <bitset>

#define repeat(i,n) for (long long i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i] << '\n'
#define debugArrayP(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i].first<< " " << x[i].second << '\n'

using namespace std;

typedef long long ll;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const ll INF = LLONG_MAX/10;
const ll MOD = 1e9+7;

int main(){
  ll H,W,d;cin >> H >> W >> d;
  vector<string> c(H,string(W,'?'));
  for(int i=0;i<=1200;i++){
    for(int j=0;j<=1200;j++){
      if((i+j)%2==1)continue;
      int y = i-600,x = j;
      int nx = (x+y)/2,ny = (x-y)/2;
      if(nx<0||W<=nx||ny<0||H<=ny) continue;
      char color='?';
      if(i/d%2==0&&j/d%2==0){
        color = 'R';
      }else if(i/d%2==0&&j/d%2==1){
        color = 'Y';
      }else if(i/d%2==1&&j/d%2==0){
        color = 'G';
      }else if(i/d%2==1&&j/d%2==1){
        color = 'B';
      }
      c[ny][nx] = color;
    }
  }
  repeat(i,H){
    cout << c[i] << endl;
  }
  return 0;
}


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

int main() {
	
	int A, B, C;
	cin >>A >>B >>C;
	
	if(B/A>=C){
		
		cout <<C <<endl;

	}
	else{
		
		cout <<B/A <<endl;
		
	}
	
}

Measured memory_bytes: 764
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <iomanip>
#include <map>
#include <set>
#include <ctype.h>
#include <numeric>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
const ll MOD = 1e9 + 7;
const int INF = 1e9;

int dx4[4] = { 0, -1, 1, 0 };
int dy4[4] = { -1, 0, 0, 1 };
int dx8[8] = { 0, -1, 1, 0, -1, 1, -1, 1 };
int dy8[8] = { -1, 0, 0, 1, -1, -1, 1, 1 };

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


Measured memory_bytes: 256
//Dream your Code, Code your Dream [Siriuslight -Subham Pal]
#include<bits/stdc++.h>
#define FIO ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
using namespace std;    typedef long long ll;    typedef long double ld;
const int inf = 1e9, N = 1e5+5;
const ll INF = 1e18, MOD = 1e9+7;;
ll power(ll a,ll b,ll m=MOD){ll r=1;while(b>0){if(b&1)r=r*a%m;a=a*a%m;b>>=1;}return r;}
ll gcd(ll a,ll b){if(b>a)swap(a,b);if(!b)return a;return gcd(b,a%b);}

int p[N], n, m, ans;
vector <int> g[N], cp;
bool vis[N], h[N];

void dfs(int x){
    cp.push_back(x);
    vis[x] = 1;
    for(auto ch : g[x]){
        if(!vis[ch]){
            dfs(ch);
        }
    }
}
int main(){
    FIO;
    cout << setprecision(10) << fixed;
    cin >> n >> m;
    for(int i = 1; i <= n; ++i){
        cin >> p[i];
    }
    for(int i = 0; i < m; ++i){
        int x, y;
        cin >> x >> y;
        g[x].push_back(y);
        g[y].push_back(x);
    }

    for(int i = 1; i <= n; ++i){
        if(!vis[i]){
            cp.clear();
            dfs(i);
            for(auto x : cp){
                h[x] = 1;
            }
            for(auto x : cp){
                if(h[p[x]]){
                    ans++;
                }
            }
            for(auto x : cp){
                h[x] = 0;
            }
        }
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 9852
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define all(v) (v).begin(),(v).end()
typedef long long int ll;
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int,int>

int main(){
  string s; cin >> s;
  int retval = 1000;
  for (int i=0;i<s.size()-2;i++){
    int d = stoi(s.substr(i,3));
    if (abs(d-753)<retval) retval = abs(d-753);
  }

  cout << retval << endl;
  
  // cout << fixed << setprecision(6);
  return 0;
}


Measured memory_bytes: 256
import java.io.PrintWriter

fun main(args: Array<String>) {
    PrintWriter(System.out).use { out ->
        solve(out)
        out.flush()
    }
}


fun solve(out: PrintWriter) {
    val (n, k) = readLongList().map { ModInt(it) }
    var ans = ModInt(0)
    for (i in k.x..(n.x + 1)) {
        val x = ModInt(i)
        ans += x * (n + n - x + ModInt(1)) / ModInt(2) - x * (x - ModInt(1)) / ModInt(2) + ModInt(1)
    }
    println(ans)
}

/** always positive number (Use for minus) */
class ModInt(x: Long, val MOD: Long = 1000000007L) {
    val x = ((x % MOD) + MOD) % MOD

    operator fun unaryMinus() = ModInt(-x, MOD)

    operator fun plus(other: ModInt): ModInt {
        var value = x + other.x
        if (value >= MOD) { value -= MOD }
        return ModInt(value, MOD)
    }

    operator fun minus(other: ModInt): ModInt {
        var value = x + MOD - other.x
        if (value >= MOD) { value -= MOD }
        return ModInt(value, MOD)
    }

    operator fun times(other: ModInt): ModInt {
        val value = (x * other.x) % MOD
        return ModInt(value, MOD)
    }

    operator fun div(other: ModInt) = this * other.inverse()

    override fun toString() = x.toString()


    /** O(log(n)) */
    private fun pow(n: Long): ModInt {
        var ret = ModInt(1L, MOD)
        var x = this
        var k = n
        while (k > 0) {
            if ((k and 1L) == 1L) { ret *= x }
            x *= x
            k = k shr 1
        }
        return ret
    }

    /**  O(log(MOD)) */
    private fun inverse() = pow(MOD - 2)
}

fun readInteger() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntegerList() = readStringList().map(String::toInt)
fun readLongList() = readStringList().map(String::toLong)
fun readDoubleList() = readStringList().map(String::toDouble)


Measured memory_bytes: 55544
{-# LANGUAGE BangPatterns #-}
import qualified Data.ByteString.Lazy.Char8 as B
import Data.Maybe
import qualified Data.IntMap as M
import Data.Bits

solve :: Int -> [Int] -> Int
solve n as = step 0 0 0 as as

step !acc !n _ _ [] = acc + sum [1..n]
step !acc !n !a (l:ls) (r:rs)
  | a + r == xor a r = step acc     (n+1) (a+r) (l:ls) rs
  | otherwise        = step (acc+n) (n-1) (a-l) ls     (r:rs)

bsReadInts :: B.ByteString -> [Int]
bsReadInts = map (fst . fromJust . B.readInt) . B.words

main :: IO ()
main = do
  conts <- B.getContents
  let (n:as) = bsReadInts conts
      answer = solve n as
  putStrLn (show answer)


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

typedef vector<int> vi;
typedef long long ll;

int N;
vector<vi> A, B;

int main(void) {
	cin >> N;

	A.resize(N, vi(N));
	B.resize(N, vi(N));
	for (int j = 0; j < N; ++j) {
		for (int i = 0; i < N; ++i) {
			int a;
			cin >> a;
			A[j][i] = B[j][i] = a;
		}
	}

	ll ans = 0LL;
	for (int k = 0; k < N; ++k) {
		for (int i = 0; i < N; ++i) {
			for (int j = 0; j < N; ++j) {
				if (A[i][j] > A[i][k] + A[k][j]) {
					i = k = N;
					ans = -1LL;
					break;
				}
				if (A[i][j] == A[i][k] + A[k][j]) {
					if(B[i][k] != 0 && B[k][j] != 0)
						B[i][j] = 0;
				}
			}
		}
	}

	if (ans != -1LL) {
		ans = 0;
		for (int i = 0; i < N - 1; ++i) {
			for (int j = i + 1; j < N; ++j)
				ans += B[i][j];
		}
	}

	cout << ans << '\n';
	return 0;
}


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


public class MyProgram
{	

    public static void Main()
	{
	    long[] n = Console.ReadLine().Split(' ').Select(s => long.Parse(s)).ToArray();
        long X = n[0];
        long Y = n[1];
        
        int cnt = 0;
        while(X <= Y)
        {
            X *= 2;
            cnt++;
        }
        
        Console.WriteLine(cnt);

	}
}

Measured memory_bytes: 13268
x, y = map(int, input().split())
ans = 0
if x == 1:
    ans += 300000
elif x == 2:
    ans += 200000
elif x == 3:
    ans += 100000

if y == 1:
    ans += 300000
elif y == 2:
    ans += 200000
elif y == 3:
    ans += 100000

if x == 1 and y == 1:
    ans += 400000

print(ans)


Measured memory_bytes: 9108
N = int(input())
X = list(map(int, input().split()))

L = min(X)
R = max(X)

def ene(p):
  cost = 0
  for x in X:
    cost += (x - p) * (x - p)
  return cost

energy = float('inf')
while (L <= R):
  energy = min([energy, ene(L)])
  L += 1
  
print(energy)

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

int main(){
  int a;
  int b;
  cin >> a >> b;
  vector <int> vec = {a+b, a-b, a*b};
  sort (vec.begin(), vec.end());
  
  
    cout << vec.at(2) << endl;
  
}

  

Measured memory_bytes: 256
while True:
    N = int(raw_input())
    if N == 0:
        break
    L = map(int, [raw_input() for _ in range(N)])
    
    maxi = max(L)

    for i in range(N):
        if L[i] <= 0:
            continue

        tot = L[i]
        for j in range(1, N - i):
            tot += L[i + j]

            if tot > maxi:
                maxi = tot

    print maxi

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


int main(){
    int n,m; cin >> n >> m;
    vector<string> a(n); rep(i,n) cin >> a[i];
    vector<string> b(m); rep(i,m) cin >> b[i];
    for(int i = 0; i + m - 1 < n; ++i){
        for(int j = 0; j + m - 1 < n; ++j){
            bool flag = false;
            rep(k,m){
                rep(l,m){
                    if(a[i+k][j+l] != b[k][l]){
                        flag = true;
                        break;
                    }
                }
                if(flag) break;
            }
            if(!flag){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }

    cout << "No" << endl;
}

Measured memory_bytes: 256
from collections import deque

dq = deque()
input_str = list(map(str, input().split()))

for i in range(len(input_str)):
  ch = input_str[i]
  if ch in ['+', '-', '*']:
    num1 = dq.pop()
    num2 = dq.pop()
    num = 0
    if ch == '+':
      num = num2 + num1
    if ch == '-':
      num = num2 - num1
    if ch == '*':
      num = num2 * num1
    dq.append(num)
  else:
    dq.append(int(ch))

print(dq[0])


Measured memory_bytes: 6004
#include<bits/stdc++.h>
#define rep(i,a,...) for(int i = (a)*(strlen(#__VA_ARGS__)!=0);i<(int)(strlen(#__VA_ARGS__)?__VA_ARGS__:(a));++i)
#define per(i,a,...) for(int i = (strlen(#__VA_ARGS__)?__VA_ARGS__:(a))-1;i>=(int)(strlen(#__VA_ARGS__)?(a):0);--i)
#define foreach(i, n) for(auto &i:(n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define all(x) (x).begin(), (x).end()
#define bit(x) (1ll << (x))
using ll = long long;
//const ll MOD = (ll)1e9+7;
const ll MOD = 998244353;
const int INF = (ll)1e9+7;
const ll INFLL = (ll)1e18;
using namespace std;
template<class t>
using vvector = vector<vector<t>>;
template<class t>
using vvvector = vector<vector<vector<t>>>;
template<class t>
using priority_queuer = priority_queue<t, vector<t>, greater<t>>;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}
#ifdef DEBUG
#define debug(x) cout<<"LINE "<<__LINE__<<": "<<#x<<" = "<<x<<endl;
#else
#define debug(x) (void)0
#endif

ll modpow(ll x, ll b){
  ll res = 1;
  while(b){
    if(b&1)res = res * x % MOD;
    x = x * x % MOD;
    b>>=1;
  }
  return res;
}

ll modinv(ll x){
  return modpow(x, MOD-2);
}

bool was_output = false;
template<class t>
void output(t a){
  if(was_output)cout << " ";
  cout << a;
  was_output = true;
}
void outendl(){
  was_output = false;
  cout << endl;
}
ll in(){
  ll res;
  scanf("%lld", &res);
  return res;
}

template<class t>
istream& operator>>(istream&is, vector<t>&x){
  for(auto &i:x)is >> i;
  return is;
}

template<class t, class u>
istream& operator>>(istream&is, pair<t, u>&x){
  is >> x.first >> x.second;
  return is;
}

template<class t>
void in(t&x){
  cin >> x;
}

template<class t>
void out(t x){
  cout << x;
}

ll x;
ll y;
ll a;
ll b;
ll c;
vector<ll> A;
vector<ll> B;
vector<ll> C;

void setup(){
  x = in();
  y = in();
  a = in();
  b = in();
  c = in();
  A.resize(a);
  B.resize(b);
  C.resize(c);
  foreach(i,A)i=in();
  foreach(i,B)i=in();
  foreach(i,C)i=in();
}

ll func(){
  ll res = 0;
  priority_queuer<ll> pqa;
  priority_queuer<ll> pqb;
  foreach(i,A){
    res += i;
    pqa.push(i);
    while(pqa.size()>(signed int)x){
      res -= pqa.top();
      pqa.pop();
    }
  }
  foreach(i,B){
    res += i;
    pqb.push(i);
    while(pqb.size()>(signed int)y){
      res -= pqb.top();
      pqb.pop();
    }
  }
  sort(all(C),greater<ll>());
  foreach(i,C){
    if(min(pqa.top(),pqb.top())>=i)break;
    if(pqa.top()<pqb.top()){
      res -= pqa.top();
      pqa.pop();
      res += i;
      pqa.push(i);
    }else{
      res -= pqb.top();
      pqb.pop();
      res += i;
      pqb.push(i);
    }
  }
  return res;
}

int main(){
  setup();
  cout << func() << endl;
  return 0;
}


Measured memory_bytes: 4852
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
using namespace std;

typedef long long ll;

#define INF 10e10
#define rep(i,n) for(int i=0; i<n; i++)
#define rep_r(i,n,m) for(int i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
// 昇順sort
#define sorti(x) sort(x.begin(), x.end())
// 降順sort
#define sortd(x) sort(x.begin(), x.end(), std::greater<int>())

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

  vector<int> num(4);
  for (int i = 0; i < 4; ++i) {
    num[i] = n % 10;
    n /= 10;
  }
  reverse(num.begin(), num.end());
  for (int i = 0; i < (1 << 3); ++i) {
    char op[3];
    int total = num[0];
    for (int j = 0; j < 3; ++j) {
      int bit = (i >> j) & 1;
      if (bit) {
        op[j] = '+';
        total += num[j + 1];
      } else {
        op[j] = '-';
        total -= num[j + 1];
      }
    }
    // cout << total << endl;
    if (total == 7) {
      cout << num[0] << op[0] << num[1] << op[1] << num[2] << op[2] << num[3] << "=7" << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 256
a,b,c,k=map(int,input().split())
ans=0
if a<=k:
    ans+=a
    k-=a
else:
    print(k)
    exit()
if b<=k:
    k-=b
else:
    print(ans)
    exit()
if c<=k:
    ans-=c
    print(ans)
else:
    print(ans-k) 

Measured memory_bytes: 9192
#include <bits/stdc++.h>
using namespace std;
 
#define P(s) cout<<s<<endl
#define All(c) c.begin(),c.end()
template<typename T>
inline T In() {
    T v;
    cin >> v;
    return v;
}
 
int main() {
    auto str = In<string>();
    
    auto pos = 0;
    auto cnt = 0;
    auto stc = 0;
    while (pos < str.size()) {
        auto prev = pos;
        pos = str.find_first_of('T', pos);
        if (pos == string::npos) {
            pos = str.size();
        }        stc += pos - prev;
        
        prev = pos;
        pos = str.find_first_of('S', pos);
        if (pos == string::npos) {
            pos = str.size();
        }
        stc -= pos - prev;

        if (stc < 0) {
            cnt += -stc;
            stc = 0;
        }
    }
    
    P(cnt + stc);
}

Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<stdio.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#include<algorithm>
#include<vector>
using namespace std;

int main() {
	int a, b, c, d, e;
	cin >> a >> b >> c >> d >> e;
	vector<int> dish(5);
	dish = { a,b,c,d,e };
	vector<int> time(5);
	rep(i, 5) {
		if (dish[i] % 10 != 0) time[i] = dish[i] + 10 - dish[i] % 10;
		else time[i] = dish[i];
	}

	int sumtime = 0;
	rep(i, 5) sumtime += time[i];
	int mintime = 114514;
	rep(i, 5) {
		int a;
		a = sumtime - time[i] + dish[i];
		mintime = min(a, mintime);
	}
	cout << mintime << endl;
	return 0;
}

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

int main(){
    int num[3];

    cin >> num[0] >> num[1] >> num[2];

    sort(num,num + 3);
    
    if(num[0] + num[1] == num[2]){
        cout << "Yes\n";
    }
    else{
        cout << "No\n";
    }

    return 0;
}

Measured memory_bytes: 256
ac,tle,wa,re=0,0,0,0
for _ in range(int(input())):
    st = input()
    if st == "AC":
        ac+=1
    elif st == "TLE":
        tle+=1
    elif st == "WA":
        wa+=1
    elif st == "RE":
        re+=1

print("AC x",ac)
print("WA x",wa)
print("TLE x",tle)
print("RE x",re)

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

int main(){
	int N; cin >> N;
	vector<pair<int, int>> a;
	for(int i=0; i<N; i++){
		int b; cin >> b;
		a.push_back({b, -i-1});
	}
	sort(a.begin(), a.end(), greater<pair<int, int>>() );
	long long ans[N+1];
	fill(ans, ans+N+1, 0);
	long long sum = a[0].first, prev = 0;
	int now = -a[0].second;
	for(int i=1; i<N; i++){
		if(-a[i].second < now){
			ans[now] = sum - (long long)a[i].first * i - prev;
			prev += ans[now];
			now = (-a[i].second);
		}
		sum += a[i].first;
	}
	ans[now] = sum - prev;
	for(int i=0; i<N; i++){
		cout << ans[i+1] << endl;
	}
	return 0;
}

Measured memory_bytes: 2804
//package ABC170;

import java.util.*;
import java.io.*;
class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc =new Scanner(System.in);
		int a=sc.nextInt();
		int l=sc.nextInt();
		
		int x=(4*a-l)/2;
		int y=(l-2*a)/2;
		
		if(x>=0 && y>=0 && x+y==a)
		{
			System.out.println("Yes");
		}
		else
		{
			System.out.println("No");
		}
			
		

	}

}


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

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define erep(i, n) for (ll i = 0; i <= (ll)(n); ++i)
#define FOR(i,a,b) for (ll i = (a); i < (ll)(b); ++i)
#define EFOR(i,a,b) for (ll i = (a); i <= (ll)(b); ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } }

typedef pair<int,int> P;



int main() {
    int n; cin >> n;
    vector<int> a(n);
    vector<int> b(n);
    vector<int> c(n);

    rep(i, n) cin >> a[i];
    rep(i, n) cin >> b[i];
    rep(i, n-1) cin >> c[i];

    int ans = 0;
    rep(i, n) {
        ans += b[a[i]-1];
        if(i > 0 && a[i-1]+1 == a[i]) {
            ans += c[a[i-1]-1];
        }
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main() {
	int n, k, count = 0;
	cin >> n >>k;
	for (int i = 0; i < n; i++) {
		int h;
		cin >> h;
		if (h >= k) count++;
	}
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define repone(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define Rep(j,n) for(int j=0;j<(int)(n);++j)
#define Repo(j,o,n) for(int j=o;j<(int)(n);++j)
#define Repone(j,n) for(int j=1;j<(int)(n);++j)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define int long long
#define pb(a) push_back(a)
#define eraser(v,i) (v).erase(v.begin()+(i))
#define pbpair(a,b) push_back(make_pair(a,b))
#define MOD 1000000007
#define INF 9223372036854775807
#define pairint pair<int,int>

signed main()
{
int x=0,y=0,z=0,w=0,n=0,m=0,a=0,b=0;
std::cin >> x;
std::vector<int> v(x);
rep(i,x){
  std::cin >> v[i];
}
rep(i,x){
  repo(j,i+1,x){
    y+=v[i]*v[j];
  }
}
std::cout << y << '\n';
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;
int main() {
	int k;
	string s,cha;
	cin >> k >> s;
	if (k >= s.size())cout << s << endl;
	else {
		s.erase(k);
		s=s + "...";
		cout << s<<endl;
		}
	return 0;
}

Measured memory_bytes: 3596
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1

def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, M, P, S):
    ac = set()
    wa = Counter()
    for i in range(M):
        if S[i] == 'AC':
            ac.add(P[i])
        elif P[i] not in ac:
            wa[P[i]] += 1
    return '%d %d' % (len(ac), sum([wa[i] for i in range(1, N+1) if i in ac]))


def main():
    N, M = read_int_n()
    P, S = [], []
    for _ in range(M):
        p, s = read_str_n()
        p = int(p)
        P.append(p)
        S.append(s)
    print(slv(N, M, P, S))


if __name__ == '__main__':
    main()


Measured memory_bytes: 84436
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        for (;;) {
            char[] l=sc.next().toCharArray(),a=new char[4];
            if(d(l)==0) {
                break;
            }
            if(d(l)%1111==0) {
                System.out.println("NA");
                continue;
            }
            int c=0;
            while (d(l)!=6174) {
                Arrays.sort(l);
                for(int i=0;i<4;i++) {
                    a[i]=l[3-i];
                }
                char[] r=String.valueOf(d(a)-d(l)).toCharArray();
                for(int i=0,j=0;i<4;i++) {
                    l[i]=i<4-r.length?'0':r[j++];
                }
                c++;
            }
            System.out.println(c);
        }
    }
    static int d(char[] c) {
        return Integer.parseInt(new String(c));
    }
}



Measured memory_bytes: 54808
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <cstdlib>
#include <utility>
#include <cstdio>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <map>
using ll = long long;
using itn = int;
using namespace std;
int GCD(int a, int b){
    return b ? GCD(b, a%b) : a;
}
int main() {
 int n, y;
 cin >> n >> y;
 bool x = true;
 for (int i = 0; i <= n;i++) {
  for (int j = 0; j <= n-i; j++) {
   int a = n - i - j;
   int b = y - 10000 * i - 5000 * j - 1000 * a;
   if (b==0) {
    cout << i << " " << j << " " <<a;
    x = false;
    break;
   }
  }
  if(!x) break;
 }
 if (x) cout << -1 << " " << -1 << " " << -1;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <string>
#include <stack>
#include <bitset>
#define INF 0x3f3f3f3f
#define eps 1e-8
#define FI first
#define SE second
using namespace std;
typedef long long LL;
char str[20][25];
bool bad[20];

inline bool Find(int a,int b)
{
    return strstr(str[a],str[b])!=NULL;
}

int nid[20],w[20][20],n;
inline int get_val(char *s1,char *s2)
{
    int len=strlen(s1);
    int l2=strlen(s2);
    for(int i=0;s1[i];++i)
    {
        if(len-i>l2) continue;
        bool ok=1;
        for(int k=0,j=i;s1[j]&&s2[k];++j,++k)
        {
            if(s1[j]!=s2[k]) {ok=0;break;}
        }
        if(ok) return len-i;
    }
    return 0;
}

inline void pre_process()
{
    for(int i=0;i<n;++i) for(int j=0;j<n;++j)
    {
        if(i==j) continue;
        int a=nid[i],b=nid[j];
        w[i][j]=strlen(str[b])-get_val(str[a],str[b]);
    }
}

inline void up(int &x,int v)
{
    if(x>v) x=v;
}

int dp[1<<14][14];
int main()
{
    while(scanf("%d",&n)&&n)
    {
        for(int i=0;i<n;++i) scanf("%s",str[i]);
        memset(bad,0,sizeof(bad));
        for(int i=0;i<n;++i)
        {
            for(int j=0;j<n;++j) if(i!=j)
            {
                if(Find(j,i))
                {
                    bad[i]=1;
                    break;
                }
            }
        }
        int nn=0;
        for(int i=0;i<n;++i) if(!bad[i]) nid[nn++]=i;
        n=nn;
        pre_process();
        memset(dp,0x3f,sizeof(dp));
        for(int i=0;i<n;++i) dp[1<<i][i]=strlen(str[nid[i]]);
        int U=(1<<n)-1;
        for(int i=0;i<=U;++i) for(int j=0;j<n;++j)
        {
            if(dp[i][j]==INF) continue;
            for(int k=0;k<n;++k)
            {
                if(i&(1<<k)) continue;
                up(dp[i|(1<<k)][k],dp[i][j]+w[j][k]);
            }
        }
        int ans=INF;
        for(int i=0;i<n;++i) ans=min(ans,dp[U][i]);
        printf("%d\n",ans);
    }
    return 0;
}

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

using namespace std;
typedef long long ll;

#define rep(i, N) for (int i = 0; i < (int)N; i++)
#define p_ll pair<ll, ll>
const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

struct edge { ll to; ll cost; };
struct mid { ll pos; ll cost; };
vector<vector<edge>> adj, adj1, adj2;
vector<ll> d, d1, d2;
ll n, m, s, t;

void dijkstra(ll s) {
  priority_queue<p_ll, vector<p_ll>, greater<p_ll>> q;
  fill(d.begin(), d.end(), LLINF); d[s] = 0; q.push(p_ll(0, s));
  while (!q.empty()) {
    p_ll p = q.top(); q.pop();
    ll v = p.second;
    for (auto e: adj[v]) {
      if (d[e.to] > d[v]+e.cost) {
        d[e.to] = d[v]+e.cost;
        q.push(p_ll(d[e.to], e.to));
      }
    }
  }
}


int main() {
  cin >> n >> m >> s >> t; s--; t--;
  adj.resize(n); adj1.resize(n); adj2.resize(n);
  d.resize(n); d1.resize(n); d2.resize(n);
  rep(i,m) {
    int u, v; cin >> u >> v; u--; v--;
    ll a, b; cin >> a >> b;
    adj1[u].push_back({v,a}); adj1[v].push_back({u,a});
    adj2[u].push_back({v,b}); adj2[v].push_back({u,b});
  }

  adj.swap(adj1); d.swap(d1);
  dijkstra(s); 
  adj.swap(adj1); d.swap(d1);
  adj.swap(adj2); d.swap(d2);
  dijkstra(t); 
  adj.swap(adj2); d.swap(d2);
  // rep(i,n) cout << d1[i] << " "; cout << endl;
  // rep(i,n) cout << d2[i] << " "; cout << endl;

  auto sh = [](const mid &x, const mid &y){return x.cost>y.cost;};
  priority_queue<mid, vector<mid>, decltype(sh)> path(sh);
  rep(i,n) path.push({i,d1[i]+d2[i]});
  rep(i,n) {
    mid now = path.top();
    while(now.pos<i) { path.pop(); now = path.top(); }
    ll result = pow(10,15) - now.cost;
    cout << result << endl;
  }
  // rep(i,n) { cout << path.top().pos << "->" << path.top().cost << endl; path.pop(); }

  return 0;
}

Measured memory_bytes: 22908