akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define watch(x) cout << (#x) << " is " << (x) << '\n'
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef double db;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a; }
//head

void solve(){
    string s;
    cin >> s;
    int pa = 1e9, pz = -1;
    for (int i = 0; i < (int) s.size(); i++){
        if (s[i] == 'A') pa = min(pa, i);
        else if (s[i] == 'Z') pz = max(pz, i);
    }
    cout << pz - pa + 1 << '\n';
}

int main(void){ 
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    //int t; cin >> t; while (t--)
        solve();
}

Measured memory_bytes: 3740
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
typedef long long ll;
#define int long long
#define f(i,n) for(ll i=0;i<n;i++)
#define fo(i,a,b) for(ll i=a;i<=b;i++)
#define forr(i,a,b) for(ll i=a;i>=b;i--)
#define bp __builtin_popcount
#define all(x) (x).begin(),(x).end()
#define s(x) sort(all(x))
#define r(x) reverse(all(x))
#define vll vector<ll>
#define pll pair<ll,ll>
#define sz size()
#define ln length()
#define pi acos(-1)
#define U 1e9
#define MOD 1000000007
#define INF LONG_LONG_MAX
#define MINF LONG_LONG_MIN
#define pb push_back
#define pf push_front
#define mp make_pair
#define F first
#define S second 
#define vl vector<ll>
#define pll pair<ll,ll>
#define KHILADI ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL))
//cout << fixed << showpoint;
//cout << setprecision(7);

ll max(ll a , ll b){ if(a>b) return a; else return b;}
ll min(ll a , ll b){ if(a<b) return a; else return b;}

ll gcd(ll a,ll b){if(a==0)return b;return gcd(b%a,a);}          
ll lcm(ll a,ll b){return (max(a,b)/gcd(a,b))*min(a,b);}

signed main()
{
    KHILADI;
    string s;
    cin >> s;
    ll x=s.ln;
    f(i,x)
        cout << 'x';
    return 0;
}




Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
#define rep(i,l,r) for(int i=l;i<r;i++)
#define rep2(i,r,l) for(int i=r;i>=l;i--)
#define sz(a) (ll)a.size()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define nl "\n"
#define pii pair<ll,ll>
#define F first
#define S second
#define iterate(c,x) for(auto &x:c)
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
	template <typename Arg1>
	void __f(const char* name, Arg1&& arg1){
		cerr << name << " : " << arg1 << std::endl;
	}
	template <typename Arg1, typename... Args>
	void __f(const char* names, Arg1&& arg1, Args&&... args){
		const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
	}
#else
#define trace(...)
#endif
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
// less_equal
// ordered_set X;
//K-th smallest
//*X.find_by_order(k-1)
//NO OF ELEMENTS < A
//X.order_of_key(A)
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL),cout.tie(NULL);
	int n, k;
	cin>>n>>k;
	vector<int> h(n), dp(n,INT_MAX);
	for(int i = 0; i < n; i++)
		cin>>h[i];
	dp[n-1] = 0;
	for(int i = n-2; i >= 0; i--){
		for(int j = i+1; j <= min(n-1, i+k); j++){
			dp[i] = min(dp[i], abs(h[i]-h[j])+dp[j]);
		}
	}
	cout<<dp[0]<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
int main(){
  int n,m=100000,q[100010],r,t,d[100010];
  scanf("%d",&n);
  q[t=0]=1;
  for(r=0;r<n;r++)d[r]=1e9;
  for(r=d[1]=1;r-t;t++){//printf("%d %d\n",q[t],d[q[t]]);
    if(d[(q[t]+1)%n]>d[q[t]]+1){
      d[(q[t]+1)%n]=d[q[t]]+1;
      q[r++]=(q[t]+1)%n;
    }
    if(d[(q[t]*10%n)]>d[q[t]]){
      d[(q[t]*10)%n]=d[q[t]];
      q[t]=(q[t]*10)%n;
      t--;
    }
  }
  printf("%d\n",d[0]);
  return 0;
}


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

int main() {
	int x[4];
	int y[4];
	for (int i = 0; i < 2; i++) {
		cin >> x[i] >> y[i];
	}


	int xa = x[1] - x[0];
	int ya = y[1] - y[0];

	x[2] = x[1] - ya;
	y[2] = y[1] + xa;

	x[3] = x[2] - xa;
	y[3] = y[2] - ya;

	cout << x[2]  << " " << y[2] << " "  << x[3] << " " << y[3] <<"\n";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
vector<long long>v;
vector<long long>vv;
int main()
{
    long long n,m,i,j,k,x,y;
    cin>>n>>m;
    if(n==1 || m==1)
    {
        cout<<1;
        return 0;
    }
    for(long long i=2; i*i<=n; i++)
    {
        if(n%i==0)
        {
            long long temp=n/i;
            v.push_back(i);
            v.push_back(temp);
        }
    }
    for(long long i=2; i*i<=m; i++)
    {
        if(m%i==0)
        {
            long long temp=m/i;
            vv.push_back(i);
            vv.push_back(temp);
        }
    }
    v.push_back(n);
    vv.push_back(m);
    int len=unique(v.begin(),v.end())-v.begin();
    int len2=unique(vv.begin(),vv.end())-vv.begin();
    vector<long long>v1;

    for(i=0; i<len; i++)
    {
        //cout<<v[i]<<endl;
        for(j=0; j<len2; j++)
        {
            if(v[i]==vv[j])
            {
                v1.push_back(v[i]);
                break;
            }
        }
    }
    for(i=0; i<v1.size(); i++)
    {
        //cout<<v1[i]<<endl;
        if(v1[i]!=0)
        {
            for(j=0; j<v1.size(); j++)
            {
                if(v1[j]%v1[i]==0 && i!=j && v1[j]!=0)
                {
                    v1[j]=0;
                }
            }
        }
    }
    x=0;
    for(i=0; i<v1.size(); i++)
    {
        if(v1[i]!=0)
        {
            x++;
        }
    }
    cout<<x+1<<endl;
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stdio.h>
#include <cmath>
#include <cctype>

using namespace std;

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

    vector<int> a(n), dist(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }

    int max_dist = 0;
    int max_dist_i;
    int sum = 0;

    for(int i = 0; i < n; i++){
        if(i != 0){
            dist[i] = a[i] - a[i-1]; 
            sum += dist[i];
        }

        if(max_dist < dist[i]){
            max_dist = dist[i];
            max_dist_i = i;
        }
    }

    dist[0] = k-a[n-1] + a[0];
    sum += dist[0];
    if(max_dist < dist[0]){
            max_dist = dist[0];
            max_dist_i = 0;
    }

    int ans = sum - max_dist;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
typedef unsigned long ulong;

bool pairComp(const std::pair<ulong, ulong>& firstElof, const std::pair<ulong, ulong>& secondElof)
{
    return firstElof.second < secondElof.second;
}

int main()
{
    ulong n,m;
	std::pair<ulong, ulong> p;
    std::vector<std::pair<ulong, ulong>> v;
    std::cin >> n >> m;
    ulong a, b;
    for (int i = 0; i < m; i++) {
        std::cin >> a >> b;
        p.first = a;
        p.second = b;
        v.push_back(p);
    }

	ulong ct = 0;
    std::vector<std::vector<std::pair<ulong, ulong>>> t;
    t.resize(n);
    for (int j = 0; j < v.size(); j++) {
		p.first = j;
		p.second = v[j].second;
		t[v[j].first-1].push_back(p);
	}

    for (auto a : t) {
	    sort(a.begin(), a.end(), pairComp);
	    for (int j = 0; j < a.size(); j++) {
	    	v[a[j].first].second = j+1;
	    }
    }
    for (auto j : v) {
    	printf("%06d%06d\n", j.first, j.second);
    }
}


Measured memory_bytes: 8688
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {
    public static void main(String[] args) throws IOException {
    	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      	int y = Integer.parseInt(br.readLine());
      	int x1[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  		System.out.println(x1[y - 1]);
      
    }
}


Measured memory_bytes: 21204
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)


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


  int n;
  cin >> n;  
  int a[n], b[n];
  ll c=0;
  rep(i,n) cin >> a[i];
  rep(i,n) cin >> b[i];
  rep(i,n){    
    if(a[i]>b[i]){
      c-=a[i]-b[i];
    }
    else if(a[i]<b[i]){
      c+=(b[i]-a[i])/2;
    }
  }
  if(c>=0) cout << "Yes" << endl;
  else cout <<  "No" << endl;


  
  return 0;
    

}


Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <vector>
#include <complex>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <stack>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <cassert>

using namespace std;

typedef long long ll;
typedef ll li;
typedef pair<int,int> PI;
#define EPS (1e-10L)
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define F first
#define S second
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define SZ(a) (int)((a).size())
#define ALL(a) a.begin(),a.end()
#define FOR(it,a) for(__typeof(a.begin())it=a.begin();it!=a.end();++it)
void pkuassert(bool t){t=1/t;};
int dx[]={0,1,0,-1,1,1,-1,-1};
int dy[]={1,0,-1,0,-1,1,1,-1};

char tr;

string in[4][13];

int c2i(char c){
  if(c=='A') return 14;
  if(c=='T') return 10;
  if(c=='J') return 11;
  if(c=='Q') return 12;
  if(c=='K') return 13;
  return c-'0';
}

void solve(){
  rep(i,4)rep(j,13) cin >> in[i][j];

  int te=0;
  int ns=0;
  rep(i,13){
    PI num1(0,0),num2(0,0);
    rep(j,4){
      if(in[j][i][1]==tr){
        int co=c2i(in[j][i][0]);
        num1=max(num1,mp(co,j));
      }
      if(in[j][i][1]==in[te][i][1]){
        int co=c2i(in[j][i][0]);
        num2=max(num2,mp(co,j));
      }
    }
    if(num1.F){
      ns += num1.S&1;
      te=num1.S;
    }else{
      ns += num2.S&1;
      te=num2.S;      
    }
    //cout << "nesw"[te] << endl;
  }

  if(ns>6) cout << "EW " << ns-6 << endl;
  else cout << "NS " << 7-ns << endl;
}

int main(int argc, char *argv[])
{
  while(cin >> tr && tr!='#') solve();
  return 0;
}

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

int main(){
  int n,k;
  cin >> n >> k;
  int ans = 0;
  while(n > 0){
    n /= k;
    ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
// AOJ Volume 0 Problem 0088

#include <stdio.h>
#include <string.h>

#define MAX_STR (500)

typedef struct {
	char c;
	char *code;
} TABLE1;

TABLE1 table1[] = {
{' ', "101"},
{'\'', "000000"},
{',', "000011"},
{'-', "10010001"},
{'.', "010001"},
{'?', "000001"},
{'A', "100101"},
{'B', "10011010"},
{'C', "0101"},
{'D', "0001"},
{'E', "110"},
{'F', "01001"},
{'G', "10011011"},
{'H', "010000"},
{'I', "0111"},
{'J', "10011000"},
{'K', "0110"},
{'L', "00100"},
{'M', "10011001"},
{'N', "10011110"},
{'O', "00101"},
{'P', "111"},
{'Q', "10011111"},
{'R', "1000"},
{'S', "00110"},
{'T', "00111"},
{'U', "10011100"},
{'V', "10011101"},
{'W', "000010"},
{'X', "10010010"},
{'Y', "10010011"},
{'Z', "10010000"},
};

char *table2 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ .,-'?";

int main(void)
{
	char input[MAX_STR];
	char code[MAX_STR * 8];
	TABLE1 *p;
	int len;
	int i, j;
	int n;

	while (fgets(input, MAX_STR, stdin) != NULL){
		code[0] = '\0';
		for (i = 0; input[i] != '\n'; i++){
			p = table1;
			while (p->c != input[i]){
				p++;
			}
			strcat(code, p->code);
//			printf("<%s>", p->code);
		}
//		printf("(%s)", code);
		
		len = strlen(code);
		strcat(code, "0000");

		len = ((len + 4) / 5) * 5;

//		printf("[%d]", len);
		
		i = 0;
		while (i < len){
			n = 0;
			for (j = 0; j < 5; j++){
				n = n * 2 + code[i] - '0';
				i++;
			}
			printf("%c", table2[n]);
		}
		printf("\n");
	}
	
	return (0);
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
    
using namespace std;
    
typedef long long ll;
    
int main(){

    ll a, b;
    cin >> a >> b;

    ll n = b - a;
    cout << n*(n+1)/2 - b << endl;
    
}

Measured memory_bytes: 256
#include <inttypes.h>
#include <math.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void)
{
    char S[11], T[12];

    gets(S);
    gets(T);

    if (strncmp(S, T, strlen(S)) == 0) {
        puts("Yes");
    } else {
        puts("No");
    }

    return 0;
}


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

const int c[9] = {2, 5, 5, 4, 5, 6, 3, 7, 6};

int n, m;
int a[9];

int memo[10001] {0};

int dfs(int n){
    if(n < 0){
        return -100000000;
    }
    if(n == 0){
        return 0;
    }
    if(memo[n] != 0){
        return memo[n];
    }
    else{
        int r = -100000000;
        for(int i = 0; i < m; i++){
            r = max(r, dfs(n - c[a[i]]) + 1);
        }
        return memo[n] = r;
    }
}

int main()
{
    cin >> n >> m;
    for(int i = 0; i < m; i++){
        cin >> a[i];
        a[i]--;
    }
    sort(a, a + m, greater<int>());
    while(n > 0){
        for(int i = 0; i < m; i++){
            if(dfs(n) == dfs(n - c[a[i]]) + 1){
                cout << a[i] + 1;
                n -= c[a[i]];
                break;
            }
        }
    }
}

Measured memory_bytes: 384
H,N=map(int,input().split())

#dp配列
# dp=[[float('inf')]*(H+1) for _ in range(N+1)]
# for j in range(H+1):
#     dp[0][j] =0

# for i in range(N):
#     A_i,B_i = map(int,input().split())
#     for a in range(H+1):
#         if A_i<=a:
#             dp[i+1][a] = min(dp[i][a-A_i] + B_i , dp[i][a])
#         else:
#             dp[i+1][a] = dp[i][a]

# print(*dp,sep="\n")

# print(dp[N][H])
dp = [float('inf')]*(H+1)
dp[0] = 0

for i in range(N):
    A_i,B_i = map(int,input().split())
    for j in range(H+1):
        nj = min(j+A_i,H)
        dp[nj] = min(dp[nj],dp[j] + B_i)
# print(*dp,sep="\n")
print(dp[H])

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

using namespace std;

typedef long long ll;

int main(){
    int a, b;
    cin >> a >> b;
    
    if(a == 0 || b == 0){
        cout << "Zero\n";
        return 0;
    }
    if(a < 0 && b > 0){
        cout << "Zero\n";
        return 0;
    }
    if(a > 0){
        cout << "Positive\n";
        return 0;
    }
    
    int cnt = b - a + 1;
    if(cnt % 2 == 0){
        cout << "Positive\n";
        return 0;
    }
    else{
        cout << "Negative\n";
        return 0;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  //入力
  int N,M;
  cin>>N>>M;
  vector<vector<int>> G(N,vector<int>());//グラフ
  for(int i=0;i<M;i++){
    int a,b;
    cin>>a>>b;
    a--;
    b--;
    G.at(a).push_back(b);
    G.at(b).push_back(a);
  }
  
  queue<int> seen;
  int dist[N];//距離
  bool judge[N];//通ったか否か
  for(int i=0;i<N;i++){
    dist[i]=0;
    judge[i]=false;
  }
  
  judge[0]=true;
  seen.push(0);
  //dfs
  while(!(seen.empty())){
    int S=seen.front();
    //目印確認
    for(int i=0;i<G.at(S).size();i++){
      int nv=G.at(S).at(i);
      if(judge[nv]){
        continue;
      }
      dist[nv]=S;
      seen.push(nv);
      judge[nv]=true;
    }
    seen.pop();
  }
  cout<<"Yes"<<endl;
  for(int i=1;i<N;i++){
    cout<<dist[i]+1<<endl;
  }
}


Measured memory_bytes: 10396
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <map>
const int MOD = 1e9+7;
typedef long long ll;
using namespace std;


int main(){
	int n, x;
	cin >> n >> x;
	vector<int> l(n+1);
	l[0] = 0;
	for (int i = 1; i <= n; i++){
		cin >> l[i];
	}
	int bound = 0, ans = 0;
	for (int i = 0; i <= n; i++){
		bound += l[i];
		if (bound <= x) ans++;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <numeric>
#include <iomanip>
#include <tuple>

using namespace std;
const long long mod=1e9+7;
const long long INF=1LL<<60;

struct UnionFind {
    vector<int> par; // 親ノード
    vector<int> rank; // ランク
    vector<int> diff_weight;

    UnionFind(int n = 1) {
        init(n);
    }

    void init(int n = 1) {
        par.resize(n); rank.resize(n);diff_weight.resize(n);
        for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0;
    }

    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            diff_weight[x] += diff_weight[par[x]]; // 累積和をとる
            return par[x] = r;
        }
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    // weight(y) - weight(x) = w となるように merge する
    bool merge(int x, int y, int w) {
        // x と y それぞれについて、 root との重み差分を補正
        w += weight(x); w -= weight(y);
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y), w = -w;
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        diff_weight[y] = w;
        return true;
    }

    int weight(int x) {
        root(x); // 経路圧縮
        return diff_weight[x];
    }

    int diff(int x, int y) {
        return weight(y) - weight(x);
    }
};

int main(){
    int n,m;
    cin>>n>>m;
    UnionFind uf(n);
    vector<int> l(m),r(m),d(m);
    for(int i=0;i<m;i++)cin>>l[i]>>r[i]>>d[i];

    string ans="Yes";
    for(int i=0;i<m;i++){
        l[i]--;r[i]--;
        if(!uf.issame(l[i],r[i]))uf.merge(l[i],r[i],d[i]);
        else {
            if(uf.diff(l[i],r[i])!=d[i])ans="No";
        }
    }
    cout<<ans<<endl;

}




Measured memory_bytes: 3840
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <map>
#include <algorithm>  // std::unique
#include <cmath>
#include <limits.h>
#include <unordered_map>

#define _USE_MATH_DEFINES
#include <math.h>
using namespace std;

using ll = long long;
constexpr auto PrimeBigNum10_9_7 = 1000000007;


// 素数判定
template <typename T>
bool IsPrimeNumber(T value) {

	for (int i = 2; i * i <= value; ++i) {
		if ((value % i) == 0) {
			return true;
		}
	}
	return false;
}

// 桁数判定
template <typename T>
T GetFigureLength(T value) {
	T figure = 1;
	while (value >= 10) {
		value /= 10;
		++figure;
	}
	return figure;
}

// 素因数分解結果
template <typename T>
map<T, T> GetPrimeFactorize(T value) {

	map<T, T> res;

	for (T i = 2; i * i <= value; ++i) {
		if ((value%i) != 0)	continue;

		T count = 0;
		while ((value % i) == 0) {
			value /= i;
			++count;
		}

		res[i] = count;
	}

	if (value != 1) {
		res[value] = 1;
	}
	return res;
}

void DebugPrint(const vector<ll>& vec) {
	cout << "{";
	for (auto itr = vec.begin(); itr != vec.end(); ++itr) {
		cout << *itr << ",";
	}
	cout << "}" << endl;
}

// valueが2のx乗以下である計算
ll calc2x(ll value) {
	ll n = 0;
	while (value > 0) {
		value /= 2;
		++n;
	}
	return n;
}

struct Vec2 {
	double x;
	double y;

	void rotate(double rad) {
		double s = sin(rad);
		double c = cos(rad);
		double tmpX = this->x*c - this->y*s;
		double tmpY = this->x*s + this->y*c;
		this->x = tmpX;
		this->y = tmpY;
	}
};


std::map<ll, pair<ll, ll>> ans;

unordered_map<ll, std::vector<ll>> routes;

void func(const unordered_map<ll, std::vector<ll>> routeList, ll routePoint) {

	unordered_map<ll, std::vector<ll>> nextRouteList;
	ll nextRoute = 0;
	for ( auto itr=routeList.begin(); itr != routeList.end(); ++ itr ){
		for (ll i = 0; i < itr->second.size(); ++i) {
			auto rindex = itr->second[i];
			if (rindex == 1)	continue;
			if (ans[rindex].second > routePoint) {
				ans[rindex] = { itr->first, routePoint };

				nextRoute = rindex;
				nextRouteList[rindex] = routes[rindex];
			}
		}
	}

	if (nextRoute != 0 ) {

		func(nextRouteList, routePoint+1);
	}
}

int main(void) {

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

	for (ll i = 0; i < m; ++i) {
		ll a, b;
		cin >> a >> b;
		routes[a].push_back(b);
		routes[b].push_back(a);
	}

	for (ll i = 1; i < n; ++i) {
		ans[i + 1] = {0, n+1};
	}

	unordered_map<ll, std::vector<ll>> routeList;
	routeList[1] = routes[1];
	func(routeList, 1);

	bool isOK = true;
	for (auto itr = ans.begin(); itr != ans.end(); ++itr) {
		isOK &= itr->second.first != 0;
	}

	if (isOK) {
		cout << "Yes" << endl;
		for (auto itr = ans.begin(); itr != ans.end(); ++itr) {
			cout  << itr->second.first << endl;
		}
	}
	else {
		cout << "No";
	}
	


	/*auto output = "";
	cout << output;*/

	return 0;
}


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

#define rep(i,n) for(int i=0 ; i<(n) ; i++)
#define repr(i,n) for(int i=(n) ; i>=0 ; i--)
#define ALL(x) (x).begin(),(x).end()

typedef long long ll;
typedef unsigned long long ull;
 
const ll INF = 1LL<<60;
const int MINF = 1e9;
const int MOD = 1e9+7;

using vi = vector<int>;
using vii = vector<vi>;

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

template<typename T>
T GCD(T a,T b){ return b ? GCD(b,a%b) : a ;}
template<typename T>
T LCM(T a,T b){ return a*b / GCD(a,b) ;}

int main(){
    ll h,w;cin >> h >> w;
    if(h == 1 || w == 1){
        cout << 1 << endl;
        return 0;
    }
    if(h % 2 != 0 && w %2 != 0){
        cout << (h*w+1) / 2 << endl;
    }else{
        cout << (h*w)/2 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, start, n) for (int i = (int)(start); i < (int)(n); ++i)
int N, M;
void func()
{
    cin >> N;
    string S;
    cin >> S;
    int ans(0), tmp(0);
    rep(i, 1, N)
    {
        tmp = 0;
        rep(t, 0, 26)
        {
            bool check = false;
            rep(j, 0, i)
            {
                if (S[j] == t + 'a')
                {
                    rep(k, i, N)
                    {
                        if (S[k] == t + 'a')
                        {
                            ++tmp;
                            check = true;
                            break;
                        }
                    }
                    if (check)
                        break;
                }
            }
        }
        if (tmp > ans)
            ans = tmp;
    }
    cout << ans << endl;
}
int main()
{
    func();
}

Measured memory_bytes: 256
x1, y1, x2, y2 = map(int, input().split())
x = x2 - x1
y = y2 - y1
x3 = x2 - y
y3 = y2 + x
x4 = x1 - y
y4 = y1 + x
print(x3, y3, x4, y4)

Measured memory_bytes: 3060
def combination(n,r,mod=10**9+7):
    n1 = n+1
    r = min(r,n-r)
    numer = denom = 1
    for i in range(1,r+1):
        numer = numer * (n1-i) % mod
        denom = denom * i % mod
    return numer * pow(denom,mod-2,mod) % mod

N,M = map(int,input().split())
a = 0
b = 0
if N <= 1:
    a = 0
else:
    a = combination(N,2)
if M <= 1:
    b = 0
else:
    b =  combination(M,2)
print(a+b)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll MOD = 998244353;
ll n;
int main () {
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cin >> n;
    ll x = 1;
    long double lsum = 0;
    for (int i = 1; i <= n; ++i) {
        ll a; cin >> a;
        lsum += log10(1.0*a);
        x *= a;
    }
    if (lsum - 18 > 1e-16) return cout << -1 << endl, 0;
    if (x > 1000000000000000000) cout << -1 << endl; else
    cout << x << endl;
}

Measured memory_bytes: 3948
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string.h>
#include <vector>
#include <cmath>
#include <iostream>
#include <unordered_map>
#include <queue>
using namespace std;
typedef unsigned long long ui64;
typedef long long i64;
void AtCoderBeginnerContest111() {
	int N;
	cin >> N;
	for (size_t i = 0; i <= 999; i++)
	{

		if (i >= N && (i % 111) == 0 ) {
			cout << i << "\n";
			return;
		}
	}

}

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


Measured memory_bytes: 256
#include<stdio.h>
int f(int n){
  int i,j=0;
  for(i=n;i;i/=2)j+=i%2;
  return n%j;
}
int main(){
  int n,i,j,s=0,a,b,c,d[200010],e[200010][2];
  e[0][0]=e[0][1]=1;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%1d",&d[i]);
    s+=d[i];
  }
  e[0][0]=1%(s+1);
  if(s>1)e[0][1]=1%(s-1);//////////s−１が０のときやばい
  //printf("%d\n",s);
  for(i=a=b=0;i<n;i++){
    e[i+1][0]=(e[i][0]*2)%(s+1);
    if(s>1)e[i+1][1]=(e[i][1]*2)%(s-1);
    a=(a*2+d[i])%(s+1);
    if(s>1)b=(b*2+d[i])%(s-1);
  }
  //printf("%d %d\n",a,b);
  for(i=0;i<n;i++){
    if(d[i]==0)c=(a+e[n-i-1][0])%(s+1);
    else{
      if(s==1)c=-1;
      else c=(b-e[n-i-1][1]+s-1)%(s-1);
    }
    if(c<0)printf("0\n");
    //printf("!!!%d\n",c);
    else{
      for(j=1;c;j++)c=f(c);
      printf("%d\n",j);
    }
  }
  return 0;
}


Measured memory_bytes: 4080
package main

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

type node struct {
	v          byte
	prev, next *node
}

type deque struct {
	head, tail node
}

func newDeq() *deque {
	dq := new(deque)
	dq.head.prev = nil
	dq.head.next = &dq.tail
	dq.tail.prev = &dq.head
	dq.tail.next = nil
	return dq
}
func (dq *deque) isEmpty() bool {
	if dq.head.next == &dq.tail {
		return true
	}
	return false
}

func (dq *deque) pushBack(v byte) {
	nn := new(node)
	nn.v = v
	dq.tail.prev.next = nn
	nn.prev = dq.tail.prev
	nn.next = &dq.tail
	dq.tail.prev = nn
}
func (dq *deque) popBack(v *byte) bool {
	if dq.tail.prev == &dq.head {
		return false
	}
	*v = dq.tail.prev.v
	dq.tail.prev.prev.next = &dq.tail
	dq.tail.prev = dq.tail.prev.prev
	return true
}
func (dq *deque) pushFront(v byte) {
	nn := new(node)
	nn.v = v
	dq.head.next.prev = nn
	nn.next = dq.head.next
	nn.prev = &dq.head
	dq.head.next = nn
}
func (dq *deque) popFront(v *byte) bool {
	if dq.head.next == &dq.tail {
		return false
	}
	*v = dq.head.next.v
	dq.head.next.next.prev = &dq.head
	dq.head.next = dq.head.next.next
	return true
}

func rev(s string) string {
	r := make([]byte, len(s))
	i, j := len(s)-1, 0
	for i >= 0 {
		r[j] = s[i]
		j++
		i--
	}
	return string(r)
}

func main() {
	fq, bq := newDeq(), newDeq()
	var S string
	fmt.Scan(&S)
	var Q, rcnt int
	fmt.Scan(&Q)
	for i := 0; i < Q; i++ {
		var t int
		fmt.Scan(&t)
		if t == 1 {
			fq, bq = bq, fq
			rcnt++
		} else {
			var f int
			var c byte
			fmt.Scanf("%d %c", &f, &c)
			if f == 1 {
				fq.pushBack(c)
			} else {
				bq.pushBack(c)
			}
		}
	}
	if rcnt%2 == 1 {
		S = rev(S)
	}
	var c byte
	wtr := bufio.NewWriter(os.Stdout)
	for fq.popBack(&c) {
		fmt.Fprintf(wtr, "%c", c)
	}
	fmt.Fprintf(wtr, "%s", S)
	for bq.popFront(&c) {
		fmt.Fprintf(wtr, "%c", c)
	}
	fmt.Fprintln(wtr)
	wtr.Flush()
}


Measured memory_bytes: 11520
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    string s;
    string t;
    cin>>s>>t;
    
    int sl = s.size();
    int tl = t.size();
    int ct;
    int ans=1e8;
    for(int i=0;i<=(sl-tl);i++){
        ct=0;
        for(int j=0;j<tl;j++){
            if(s[i+j]==t[j]) ct++;
        }
        //cout<<tl-ct<<endl;
        if(ans> tl-ct ) ans=tl-ct;
    }
    
    cout<<ans<<endl;
    
}


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

using namespace std;

#define debug(x) cerr << "  - " << #x << ": " << x << endl;
#define debugs(x, y) cerr << "  - " << #x << ": " << x << "         " << #y << ": " << y << endl;
#define sep() cerr << "--------------------" << endl;
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)x.size()
#define pb push_back
#define fi first
#define se second
#define mp make_pair

typedef long long ll;
const ll mod = 1e9 + 7;

ll abso(ll x) {
	if(x < 0) return -x;
	return x;
}

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

	if(k & 1) {
		cout << b - a << endl;
	}
	else cout << a - b << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename X> ostream& operator << (ostream& x,const vector<X>& v){for(ll i=0;i<v.size();++i) x<<v[i]<<" ";return x;}
template <typename X> ostream& operator << (ostream& x,const set<X>& v){for(auto it:v) x<<it<<" ";return x;}
template <typename X, typename Y> ostream& operator << (ostream& x, const pair<X,Y>& v) {x<<v.ff<<" "<<v.ss;return x;}
template <typename T, typename S> ostream& operator << (ostream& os, const map<T, S>& v) { for (auto it : v) os << it.first << "=>" << it.second << endl; return os; }
struct pair_hash {inline std::size_t operator()(const std::pair<ll, ll> & v) const {return v.first*31+v.second;}};
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL)
#define pb push_back
#define fr first
#define sc second
#define prnt(m) for(auto it = m.begin() ; it != m.end() ; ++it){cout<<*it<<endl;}
#define tra(it,m) for(auto it=m.begin();it!=m.end();++it)
#define DBG(x) cout<<"# # #     "<<x<<'\n';
#define fri(i,s,n) for(ll i=s;i<n;i++)
#define mod 1000000007LL
#define mod2 998244353
#define vct2 vector<vector<ll>>
#define vct vector<ll>
#define pll pair<ll,ll>
#define rz(n) resize(n)
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define arrin(a,n) for(ll i = 0; i < n ; i++){cin>>a[i];}
#define arrout(a,n) for(ll i = 0;i < n; i++){cout<<a[i]<<" ";}
#define ex(s) cout<<s<<endl,exit(0);
#define inf 1e18
#define five 100005;
#define six 1000005;
#define prllclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
//___________________________________________________________________________________________________________________________________________________________
int main()
{
       int x = 0;
       string s1,s2;
       cin>>s1>>s2;
       fri(i,0,3){
              x += s1[i] == s2[i];
       }
       cout<<x<<endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
#define sz(a) ((int) (a).size())

int main() {
	int n, ans = 0;
	scanf("%d", &n);
	vector<int> v(n);
	map<int, int> cnt;
	for (int i = 0; i < n; ++i) {
		scanf("%d", &v[i]);
		cnt[v[i]]++;
	}
	sort(v.rbegin(), v.rend());
	for (int i = 0; i < sz(v); ++i) {
		if (cnt[v[i]] == 0) {
			continue;
		}
		cnt[v[i]]--;
		int nxt = 1;
		while (nxt <= v[i]) {
			nxt *= 2;
		}
		int who = nxt - v[i];
		if (cnt[who] > 0) {
			ans++;
			cnt[who]--;
		}
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 19840
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(c) c.begin(),c.end()
#define PB push_back

using namespace std;
typedef long long ll;

int main()
{
  ll A, B, C;
  cin >> A >> B >> C;
  ll X, Y;
  cin >> X >> Y;
  if (A + B <= 2*C) cout << (A*X + B*Y) << endl;
  else {
    ll ans = 0;
    ll m = min(X, Y);
    ans += 2*C*m;
    X -= m, Y -= m;
    if (X > 0 && A <= 2*C) ans += A*X;
    else if (Y > 0 && B <= 2*C) ans += B*Y;
    else ans += 2*C*(X + Y);
    cout << ans << endl;
  }

  return 0;
}

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

using namespace std;

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

    int len = 0;
    for (int i = 1; i < s.size()/2; i++) {
        if (s.substr(0, i) == s.substr(i, i)) len = 2 * i;
    }

    cout << len << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<ll,ll> P;
#define M 1000000007
int main(){
  int n,k;cin>>n>>k;
  vector<vector<double>> a(n,vector<double>(k));
  for(int i=0;i<n;i++){
    for(int j=0;j<k;j++){
      cin>>a[i][j];
    }
  }
  int c=0;
  map<double,bool> m;
  for(double i=0.0;i<1000.0;i++){
    m[i*i]=true;
  }
  for(int i=0;i<n-1;i++){
    for(int j=i+1;j<n;j++){
      double d=0;
      for(int g=0;g<k;g++){
        d+=pow(a[i][g]-a[j][g],2.0);
      }
      if(m[d])c++;
    }
  }
  cout<<c;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()

int main() {
  int n, l;
  cin >> n >> l;
  vector<string> vec(n);
  rep(i, n) cin >> vec[i];
  sort(all(vec));
  rep(i, n) cout << vec[i];
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL MOD = 1000000007;
#define lcm(x, y) ((x) * (y) / __gcd((x), (y)))
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define debug(x) cout << #x << " : " << x << endl
#define part cout << "----------------------------------\n";
#include <iostream>
#define fastinput                     \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);

LL POW(LL x, LL y)
{
    LL ans = 1;
    LL base = x;
    while (y)
    {
        if (y & 1)
        {
            ans *= base;
        }
        base = base * base;
        y = y >> 1;
    }
    return ans;
}

int main()
{
    fastinput;
    LL n,i,j,k,t,temp,tc,a,b;
    cin>>a;
    LL ans=a+a*a+a*a*a;
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S;
  long long K;
  char Y;
  bool M=false;
  cin>>S>>K;
  for(long long X=0;X<K;X++){
    if(S.at(X)!='1'){
      Y=S.at(X);
      M=true;
      break;
    }
  }
  if(M==false){
    cout<<1<<endl;
  }
  else{
    cout<<Y<<endl;
  }
}


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

using namespace std;
#define all(a)a.begin(),a.end()
#define rep(i,n) for (int i = 0; i < (n); ++i)
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod = int(1e9)+7;
using V = vector<ll>;
using P = pair<ll,ll>;
int main()
{
    int n;cin>>n;
    map<ll,ll> l;
    map<ll,ll> r;
    rep(i,n){
        ll a;cin >>a;
        l[i+a]++;
        r[i-a]++;
    }
    ll ans=0;
    for(auto v:l){
        //cout <<v.fi<< endl;
        ll s=l[v.first]*r[v.first];
        ans+=s;
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

int main(){
  int n;bool flag = true;
  int64_t time = 0;
  cin >> n;
  priority_queue<pair<int64_t,int64_t>,vector<pair<int64_t,int64_t>>,greater<pair<int64_t,int64_t>>> que;
  for(int i = 0;i < n;i++){
    int64_t a,b;cin >> a >> b;
    que.push({b,a});
  }
  for(int i = 0;i < n && flag;i++){
    pair<int64_t,int64_t> cost = que.top();que.pop();
    time += cost.second;
    if(time > cost.first)flag = false;
  }
  if(flag)cout << "Yes";
  else cout << "No";
  return 0;
}

Measured memory_bytes: 6128
N, M, C = list(map(int, input().split()))
B = list(map(int, input().split()))
ss = [list(map(int, input().split())) for _ in range(N)]
cnt = 0
for s in ss:
  t = 0
  for i, b in zip(s, B):
    t += i * b
  if (t+C) > 0:
    cnt += 1
print(cnt)
  

Measured memory_bytes: 3060
#include <iostream>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);++i)

int main() {
    string S;cin>>S;
    int sum = 0;
    REP(i,S.size()) sum += S[i]-'0';
    if(sum==1) cout << 10 << endl;
    else cout << sum << endl;
    return 0;
}

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

const int nmax = 100100;
int N;
int a[nmax];
int cnt(int x)
{
    
    int ans = 0;
    for(int i=2; i*i <= x; ++i)
    {
        if (i*i == x)
            ans +=1;
        else if(x%i==0)
            ans +=2;
    }
    return ans + 2;
}
void read(){
    cin >> N;
    int ans = 0;
    for(int i=1;i <= N; i+=2){
        ans += cnt(i) == 8;
    }
    cout << ans << endl;
}

void solve(){

}

int main(){
    read();
    solve();
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

ll N,M,Q;
int A[101010];
int col[1500000];

template<int um> class UF {
	public:
	vector<int> par,rank,cnt;
	UF() {par=rank=vector<int>(um,0); cnt=vector<int>(um,1); for(int i=0;i<um;i++) par[i]=i;}
	void reinit() {int i; FOR(i,um) rank[i]=0,cnt[i]=1,par[i]=i;}
	int operator[](int x) {return (par[x]==x)?(x):(par[x] = operator[](par[x]));}
	int count(int x) { return cnt[operator[](x)];}
	int operator()(int x,int y) {
		if((x=operator[](x))==(y=operator[](y))) return x;
		cnt[y]=cnt[x]=cnt[x]+cnt[y];
		if(rank[x]>rank[y]) return par[x]=y;
		rank[x]+=rank[x]==rank[y]; return par[y]=x;
	}
};

UF<1407070> uf1,uf2,uftail;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>M>>Q;
	FOR(i,Q) {
		cin>>A[i];
		for(j=A[i];j<14*M;j+=M) col[j]=1;
	}
	
	ll pat;
	int num[3]={};
	if(M%7==0) M/=7;
	/*
		FOR(i,M) {
			if(col[i]==0 && (i%7<6) && col[i+1]==0) uf1(i,i+1);
			if(col[i]==0 && (i+7<M) && col[i+7]==0) uf1(i,i+7);
		}
		FOR(i,2*M) {
			if(col[i]==0 && (i%7<6) && col[i+1]==0) uf2(i,i+1);
			if(col[i]==0 && (i+7<2*M) && col[i+7]==0) uf2(i,i+7);
		}
		FOR(i,M) if(col[i]==0 && uf1[i]==i) num[0]++;
		FOR(i,2*M) if(col[i]==0 && uf2[i]==i) num[1]++;
		pat=7*N/M;
	}
	else {
	*/
		FOR(i,7*M) {
			if(col[i]==0 && (i%7<6) && col[i+1]==0) uf1(i,i+1);
			if(col[i]==0 && (i+7<7*M) && col[i+7]==0) uf1(i,i+7);
		}
		FOR(i,14*M) {
			if(col[i]==0 && (i%7<6) && col[i+1]==0) uf2(i,i+1);
			if(col[i]==0 && (i+7<14*M) && col[i+7]==0) uf2(i,i+7);
		}
		FOR(i,7*M) if(col[i]==0 && uf1[i]==i) num[0]++;
		FOR(i,14*M) if(col[i]==0 && uf2[i]==i) num[1]++;
		pat=N/M;
	//}
	cout<<num[0]+(pat-1)*(num[1]-num[0])<<endl;
	
}



int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


Measured memory_bytes: 56576
/* 
 * Project: AtCoder Beginners Contest 167 B - Easy Linear Programming
 * Author: toms74209200 <https://github.com/toms74209200>
 *
 * Created on 2020/05/10
 * Copyright (c) 2020 toms74209200
 * 
 * This software is released under the MIT License.
 * http://opensource.org/licenses/mit-license.php
 */
#include <cstdio>
#include <cmath>
using namespace std;

int a, b, c, k;

void solve() {
    int sum = 0;
    int num = 0;
    if (k>=a) {
        sum += a;
        num += a;
    } else {
        sum += k;
        printf("%d\n", sum);
        return;
    }
    for (int i=0;i<b;i++) {
        num++;
        if (num >= k) {
            printf("%d\n", sum);
            return;
        }
    }
    for (int i=0;i<c;i++) {
        sum--;
        num++;
        if (num >= k) {
            printf("%d\n", sum);
            return;
        }
    }
    printf("%d\n", sum);
}

int main() {

    scanf("%d", &a);
    scanf("%d", &b);
    scanf("%d", &c);
    scanf("%d", &k);

    solve();

}

Measured memory_bytes: 3228
import os
import sys
import math
if os.environ.get("DEBUG") is not None:
    sys.stdin = open("in.txt", "r")
rl = sys.stdin.readline
rls = sys.stdin.readline().rstrip("\n")

x1, y1, x2, y2 = map(int, rls.split())
dx, dy = x2 - x1, y2 - y1
x3, y3 = x2 - dy, y2 + dx
x4, y4 = x1 - dy, y1 + dx
print(x3, y3, x4, y4)

Measured memory_bytes: 9128
#include <iostream>
#include <string>
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <algorithm>
#include <ctime>
using namespace std;

#define PI 3.14159265358979323846264338327950L

int INF = INT32_MAX;
//std::numeric_limits<int>::infinity();
int res;

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

    int N, M, X;
    cin >> N >> M >> X;
    int *algo = new int[M];
    int **array = new int *[N];
    int payment = INF;

    for (int i = 0; i < M; i++)
    {
        algo[i] = 0;
    }

    for (int i = 0; i < N; i++)
    {
        int *tmp = new int[M + 1];
        for (int j = 0; j < M + 1; j++)
        {
            cin >> tmp[j];
            //cout << "```" << tmp[j]<<endl;
            //cout << "**"<<tmp[0] << tmp[1] << tmp[2] << tmp[3] <<endl;
        }
        array[i] = tmp;
        //cout << "@"<<array[i][0] << array[i][1] << array[i][2] << array[i][3] << endl;
    }
    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j < M + 1; j++)
        {
            //cout << array[i][j] << endl;
        }
    }

    int *level = new int[M];
    for (int i = 0; i < M; i++)
    {
        level[i] = 0;
    }

    for (int i = 1; i < (1 << N); i++)
    {
        int paymenttmp = 0;
        for (int j = 0; j < N; j++)
        {
            if (i & (1 << j))
            {
                paymenttmp += array[j][0];
                for (int k = 0; k < M; k++)
                {
                    level[k] += array[j][k + 1];
                }
            }
        }

        for (int j = 0; j < M; j++)
        {
            if (level[j] < X)
            {
                for (int i = 0; i < M; i++)
                {
                    level[i] = 0;
                }
                break;
            }
            if (j == M - 1)
            {
                if (paymenttmp < payment)
                {
                    payment = paymenttmp;
                    for (int i = 0; i < M; i++)
                    {
                        level[i] = 0;
                    }
                }
                else
                {
                    for (int i = 0; i < M; i++)
                    {
                        level[i] = 0;
                    }
                }
            }
        }
    }
    if (payment != INF)
    {
        cout << payment << endl;
    }
    else
    {
        cout << -1 << endl;
    }
    return 0;
}

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

using namespace std;

#define int long long
#define ll long long
typedef pair<int, int> P;
#define mod 1000000007
#define INF (1LL<<60)

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define YES puts("YES\n")
#define Yes puts("Yes\n")
#define NO  puts("NO\n")
#define No  puts("No\n")
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }



signed main() {

	int L, R;
	cin >> L >> R;
	if (R - L >= 2018) {
		cout << 0 << endl; return 0;
	}
	L %= 2019;
	R %= 2019;
	if (R <= L) R += 2019;

	int ans = INF;
	for (int i = L; i <= R; i++)
		for (int j = i + 1; j <= R; j++) {
			ans = min(ans, i * j % 2019);
		}
	cout << ans << endl;

	return 0;
}


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

#define ll long long
int main() {
    ll t=1;
    //cin>>t;
    while(t--)
    {
      ll n;
      cin>>n;
      ll i;
      string s;
      cin>>s;
      priority_queue<int>p;
      priority_queue<int,vector<int>,greater<int>>q;
      for(i=0;i<n;i++)
      {
          if(s[i]=='W')
             q.push(i);
          else
            p.push(i);

      }
      ll ans=0;
      while(!q.empty()&&!p.empty()&&q.top()<p.top())
      {
          ll a=q.top();
          ll b=p.top();
          q.pop();
          p.pop();
          ans++;
      }
      cout<<ans<<endl;
    }
}


Measured memory_bytes: 4680
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>
#include <iomanip>

using namespace std;

#define FOR(i, a, b) for(int (i)=(a);(i)<(b);(i)++)
#define IFOR(i, a, b) for(int (i)=(a);(i)<=(b);(i)++)
#define RFOR(i, a, b) for(int (i)=(a);(i)>=(b);(i)--)
#define REP(i, n) FOR((i), 0, (n))

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template<class T>
void print_container(T &container, string delim=" ") {
    bool first = true;
    for(auto &t: container){
        if(!first){
            cout << delim;
        }
        first = false;
        cout << t;
    }
    cout << endl;
}

int main() {
    int n, k, c;
    cin >> n >> k >> c;
    string s;
    cin >> s;
    vector<int> greed_front;
    vector<int> greed_back;
    int cnt = 0;
    REP(i, n){
        if(s[i] == 'o'){
            greed_front.push_back(i);
            cnt++;
            if(cnt == k)
                break;
            i += c;
        }
    }
    cnt = 0;
    RFOR(i, n-1, 0){
        if(s[i] == 'o'){
            greed_back.push_back(i);
            cnt++;
            if(cnt == k)
                break;
            i -= c;
        }
    }
    reverse(greed_back.begin(), greed_back.end());

    vector<int> ans;
    REP(i, k){
        if(greed_front[i] == greed_back[i])
            ans.push_back(greed_front[i]+1);
    }


    for(auto t: ans)
        cout << t << endl;

    return 0;
}

Measured memory_bytes: 6088
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


using i64 = ::std::int_fast64_t;
using u64 = ::std::uint_fast64_t;
using i32 = ::std::int_fast32_t;
using u32 = ::std::uint_fast32_t;

namespace tools {
  template <typename T>
  void read(::std::istream& is, ::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    vector.reserve(size);
    ::std::copy_n(::std::istream_iterator<T>(is), size, ::std::back_inserter(vector));
  }
  template <typename T>
  void read(::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    ::tools::read(::std::cin, vector, size);
  }

  template <typename T, ::std::size_t N>
  void read(::std::istream& is, ::std::array<T, N>& array) {
    ::std::copy_n(std::istream_iterator<T>(is), N, array.begin());
  }
  template <typename T, ::std::size_t N>
  void read(::std::array<T, N>& array) {
    ::tools::read(::std::cin, array);
  }
}

#endif

// main.cpp

int main() {
  std::string S, T;
  std::cin >> S >> T;
  const i64 NS = S.size();
  const i64 NT = T.size();

  i64 answer = std::numeric_limits<i64>::max();
  for (i64 i = 0; i + NT <= NS; ++i) {
    i64 possible_answer = 0;
    for (i64 j = 0; j < NT; ++j) {
      if (S[i + j] != T[j]) ++possible_answer;
    }
    answer = std::min(answer, possible_answer);
  }

  std::cout << answer << std::endl;
  return 0;
}

Measured memory_bytes: 3628
from fractions import gcd
from functools import reduce


def lcm(a, b):
    return a * b // gcd(a, b)


def solve(string):
    n, m, *a = map(int, string.split())
    l = reduce(lcm, a)
    c = 2**len(bin(a[0]).split("1")[-1])
    for _a in a:
        if _a % c or not _a // c % 2:
            return "0"
    return str(max((m - l // 2) // l + 1, 0))


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))


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

#define pb push_back
#define mp make_pair

#define sz(c) (int)(c).size()
#define all(c) (c).begin(), (c).end()

using namespace std;

typedef long long ll;
typedef long double ld;

const int N = (int)(3e5 + 5);
const int MOD = (int)(1e9 + 7);
const int INF = (int)(1e9 + 11);

int main() {
    ios_base :: sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    string s;
    cin >> s;
    int n;
    cin >> n;
    for (int i = 0; i < (int)s.size(); i += n)
        cout << s[i];
    return 0;
}


Measured memory_bytes: 384