akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <complex>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
#include <assert.h>
#include <array>
#include <cstdio>
#include <cstring>
#include <random>
#include <functional>
#include <numeric>
#include <bitset>

using namespace std;

struct before_main{before_main(){cin.tie(0); ios::sync_with_stdio(false);}} before_main;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }

typedef long long ll;
int const inf = 1<<29;

int main() {

  int q; cin >> q;
  ll sum = 0;
  rep(i, q) {
    int p; char c; ll n; cin >> p >> c >> n;
    if(c == '(') {
      sum += n;
    } else {
      sum -= n;
    }
    cout << (sum == 0 ? "Yes" : "No") << endl;
  }  
  return 0;
}

Measured memory_bytes: 3208
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using ll = long long;
using P = pair<int, int>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr long long MOD = 1e9 + 7;

signed main() {
    int n;
    cin >> n;
    bool zero = false;
    ll a[n];
    rep(i, n) {
        cin >> a[i];
        if (a[i] == 0) zero = true;
    }
    if(zero){
        cout << 0 << endl;
        return 0;
    }
    __uint128_t ans = 1;
    for (int i = 0; i < n; i++) {
        ans *= (__uint128_t)a[i];
        if (ans > (__uint128_t)LINF) {
            cout << -1 << endl;
            return 0;
        }
    }
    cout << (ll)ans << endl;
    return 0;
}

Measured memory_bytes: 4376
N,M = map(int, input().split())
H = list(map(int, input().split()))
AB = [list(map(int, input().split())) for _ in range(M)]
ans = [1]*N
for A,B in AB:
    if H[A-1] > H[B-1]:
        ans[B-1] = 0
    elif H[A-1] < H[B-1]:
        ans[A-1] = 0
    else:
        ans[B-1] = 0
        ans[A-1] = 0
print(ans.count(1))

Measured memory_bytes: 32016
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
ll int b[200005];
ll int a[200005];
bool compare(const pair<ll int,int>p1,const pair<ll int,int>p2){
if(b[p1.second]==b[p2.second]){return p1.first<p2.first;}
return b[p1.second]<b[p2.second];}
int main()
{
    ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t=1;
//cin>>t;
while(t--){
int n;
cin>>n;

vector<pair<ll int,int> >v;
for(int i=0;i<n;i++){
    cin>>a[i]>>b[i];
    v.push_back({b[i]-a[i],i});
}
sort(v.begin(),v.end(),compare);
ll int time=0;
bool rt=true;

for(int i=0;i<n;i++){
    if(time<=v[i].first){}
    else{

        rt=false;
    break;}
    time+=a[v[i].second];

}
if(rt){
    cout<<"Yes"<<endl;
}
else{cout<<"No"<<endl;}
}}


Measured memory_bytes: 8176
#include <algorithm>
#include <iostream>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

signed main()
{
    int x;

    for (int i = 0; i < 5; ++i)
    {
        cin >> x;

        if (x == 0)
        {
            std::cout << i + 1 << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 3672
#include<iostream>

using namespace std;

int main() {

	int a, b, c;

	cin >> a >> b >> c;

	if (a < b&&b < c) {

		cout << "Yes" << endl;

	}else if (a >= b||b>=c){

		cout << "No" << endl;

    }

return 0;

}


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

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vbb;
typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair

#define loop(i,a,b) for(int i=(a);i<ull(b);++i)
#define rep(i,n) loop(i,0,n)

const double eps = 1e-10;
const double pi  = acos(-1.0);
const double inf = (int)1e8;

bool check(string s){
    for(int i=0; i< s.size()-1; i++) if(s[i] != s[i+1]) return false;
    return true;
}

int main(){
    string s;
    while(cin >> s, s!= "0"){
        queue<pair<string, int> > que;
        que.push(make_pair(s, 0));
        int ret = 100;

        map<string, int> m;
        while(que.size()){
            s = que.front().first; int count = que.front().second; que.pop();

            if(ret < count) continue;
            if(check(s))ret = count;

            if(m[s] == 0 || count+1 < m[s]){
                string tmp = s;
                m[s] = count+1;
                string t = "rgb";
                vector<int> v(3); v[0] = 0; v[1] = 1; v[2] = 2;
                map<string, int> mp; mp["r"] = 0; mp["g"] = 1; mp["b"] = 2;
                do{
                    for(int i=0; i< s.size(); i++){
                        s[i] = t[v[mp[s.substr(i, 1)]]];
                    }
                    m[s] = count+1;
                }while(next_permutation(v.begin(), v.end()));
                s = tmp;
            }
            else continue;

            for(int i=0; i< s.size()-1; i++){
                if(s[i] != s[i+1]){
                    string t = s.substr(i, 2);
                    sort(t.begin(),t.end());
                    if(t == "br") t = "gg";
                    else if(t == "bg") t = "rr";
                    else if(t == "gr") t = "bb";
                    que.push(make_pair(s.substr(0, i)+t+s.substr(i+2), count+1));
                }
            }
        }
        if(ret == 100) cout << "NA" << endl;
        else cout << ret << endl;
    }
}

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

int main()
{
    int N, H;
    cin >> N >> H;
    vector<vector<int>> data(H, vector<int>(2));
    vector<int> toshi(N);
    for (int i = 0; i < H; i++)
    {
        for (int j = 0; j < 2; j++)
        {
            cin>>data.at(i).at(j);
        }
    }

    for (int i = 0; i < H; i++)
    {
        for (int j = 0; j < 2; j++)
        {
            toshi.at(data.at(i).at(j) - 1)++;
        }
    }
    for (int i = 0; i < N;i++){
        cout << toshi.at(i) << endl;
    }
}


Measured memory_bytes: 256
n, m, x = list(map(int, input().split()))

cas = []
for i in range(n):
    ca = list(map(int, input().split()))
    cas.append(ca)

kingakumin = 10000000000

for i in range(2 ** n):
    now = []
    inow = i
    for j in range(n):
        now.append(i % 2)
        i = i // 2

    syuutoku = []
    for j in range(m):
        syuutoku.append(0)

    kingaku = 0
    for j in range(n):
        if now[j] == 1:
            kingaku = kingaku + cas[j][0]
            for k in range(m):
                syuutoku[k] = syuutoku[k] + cas[j][k + 1]

    flag = True
    for j in range(m):
        if syuutoku[j] < x:
            flag = False

    if flag and kingakumin > kingaku:
        kingakumin = kingaku

if kingakumin == 10000000000:
    kingakumin = -1

print(kingakumin)

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


int main(){
  ll l, r;
  cin >> l >> r;
  ll ans = 2019;
  
  if(r-l+1 < 2019){
    for(ll i = l; i <= r-1; i++){
      for(ll j = i+1; j <= r; j++){
        ans = min(ans, ((i*j)%2019));
      }
    }
  }
  else ans = 0;  
  
  
  cout << ans << endl;
}

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

int main(int argc, char const *argv[])
{ 
    string s;
    int f,l;
    cin>>s;
    for(int i=0;i<s.length();i++){
        if(s[i]=='A'){
            f=i;
            break;
        }
    }
    for(int i=s.length()-1;i>=0;i--){
        if(s[i]=='Z'){
            l=i;
            break;
        }
    }
    cout<<l-f+1;
    return 0;
}


Measured memory_bytes: 644
#include<stdio.h>
int gcd(int a, int b)
{
    int r = a % b;
    while (r > 0)
    {
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}
int main()
{
    int n, k;
    scanf("%d %d", &n, &k);
    int i;
    int a[100005];
    for (i = 0; i < n; i++)
        scanf("%d", &a[i]);
    int max = 0;
    for (i = 0; i < n; i++)
        if (max < a[i])
            max = a[i];
    if (k > max)
    {
        printf("IMPOSSIBLE\n");
        return 0;
    }
    int g = a[0];
    for (i = 0; i < n; i++) {
        g = gcd(g, a[i]);
    }
    if (k%g == 0)
        printf("POSSIBLE\n");
    else
        printf("IMPOSSIBLE\n");
    return 0;
}


Measured memory_bytes: 512
import heapq

V,E = map(int,input().split())
C = [[] for _ in range(V)]
for _ in range(E):
    s,t,w = map(int,input().split())
    C[s].append([t,w])
    C[t].append([s,w])

visited = [False]*V
visited[0] = True
q = []
node = 0
node_cnt = 1
ans = 0

while node_cnt < V:
    for adj,w in C[node]:
        if not visited[adj]:
            heapq.heappush(q,(w,adj))
    while 1:
        weight,node = heapq.heappop(q)
        if not visited[node]:
            break
    visited[node] = True
    ans += weight
    node_cnt += 1
print(ans)


    





Measured memory_bytes: 40516
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <cctype>
#define len length()
#define sz size()
#define rng(i, a, b) for(int i = a; i < b; i++)
#define rep(i, n) rng(i, 0, n)
#define srt(v) sort(v.begin(), v.end())
#define rev(s) reverse(s.begin(), s.end())
#define vi(a, n) vector<int> a(n)
#define vs(a, n) vector<string> a(n)
#define vc(a, n) vector<char> a(n)
#define psb(a) push_back(a)
#define ppb pop_back()
#define erc(S, i) S.erase(S.begin() + i)
#define ers(S, i, j) S.erase(S.begin() + i, S.begin() + j)
#define sp(n) cout << setprecision(n) << fixed
#define fst(s) s.at(0)
#define lst(s) s.at(s.len - 1)
typedef long long ll;
using namespace std;
int mod = 1000000007;

int main(){
    int a,b;
    cin >> a >> b;
    if(a > 12) cout << b << endl;
    else if(a > 5) cout << b / 2 << endl;
    else cout << 0 << endl;
    return 0;   
}

Measured memory_bytes: 256
import itertools

times = [int(input()) for i in range(5)]
ans = 0

for i in itertools.permutations(times):
        order_times = [t+(10-t%10)%10 for t in i[:-1]] + [i[-1]]
        ans = sum(order_times) if ans==0 else min(ans, sum(order_times))

print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <cmath>
using namespace std;

int triple_max(int x, int y, int z);

int main(){
    int a, b;
    cin >> a >> b;
    cout << (a-1) * (b-1) << endl;


    return 0;
}

int triple_max(int x, int y, int z){
    int ans = x;
    if (y > x && y > z) ans = y;
    else if (z > x && z > y) ans = z;

    return ans;
}


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

int main()
{
  int n;cin>>n;
  string s,t;
  cin>>s>>t;
  int i;
  for(i=0;i<n;i++)
  {
    cout<<s.at(i)<<t.at(i);
  }
  cout<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
int main(void){
    int n,ans=0,sum=0;
    scanf("%d",&n);
    int a[n];
    for (int i=0; i<n; i++){
        scanf("%d",&a[i]);
        sum+=a[i];
    }
    for (int i=0; i<n; i++){
        if (abs(a[ans]*n-sum)>abs(a[i]*n-sum)){
            ans=i;
        }
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<algorithm>

typedef long long ll;
using namespace std;
int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	if ((a * 100 + b * 10 + c) % 4 == 0) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define ll long long int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
using namespace std;
ll mod = 1e9 + 7;
int main(void)
{
	ll h, w, i, j;
	cin>>h>>w;
	string s[h];
	for(i=0; i<h; i++)
		cin>>s[i];
	ll ans[h][w];
	ans[0][0] = 1;
	for(i=1; i<w; i++)
	{	
		if(s[0][i] == '.')
			ans[0][i] = ans[0][i-1];
		else
			ans[0][i] = 0;
	}
	for(i=1; i<h; i++)
	{
		if(s[i][0] == '.')
			ans[i][0] = ans[i-1][0];
		else
			ans[i][0] = 0;
	}
	for(i=1; i<h; i++)
	{
		for(j=1; j<w; j++)
		{
			if(s[i][j] == '#')
				ans[i][j] = 0;
			else
				ans[i][j] = (ans[i-1][j] + ans[i][j-1])%mod;
		}
	}
	cout<<ans[h-1][w-1]<<"\n";
}	

Measured memory_bytes: 9088
#include <iostream>
#include <vector>
#include <queue>
#include<map>
#include<algorithm>
#include<set>
#include<iomanip>
#define rep(i,n) for(int i = 0;i < n;i++)
#define req(i,n) for(int i = 1; i<=n;i++)
#define rrep(i,n) for(int i = n-1;i >=0;i--)
#define ALL(a) a.begin(),a.end()
#define PI  acos(-1)
using namespace std;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T & val) {
    std::fill((T*)array, (T*)(array + N), val);
}
typedef long long int ll;
typedef long double ld;
const int MOD = 1e9 + 7;
int dx[4] = { 0,0,1,-1 }, dy[4] = { 1,-1,0,0 }, sum = 0,h,w;
int main() {
    int n, c,sum=0,p; cin >> n >> c;
    n++;rep(i, c) cin >> p, sum += p;
    if (sum % n != 0) {
        sum += n;
    }cout << sum / n << endl;
}


Measured memory_bytes: 3092
import java.util.*;

public class Main {
    static long mod = 1000000007;
    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);
        int n=in.nextInt();
        if(n==1){
            System.out.println(0);
            return ;
        }
        long ans=pow(10,n)-pow(9,n)-pow(9,n)+pow(8,n);
        while(ans<0)
            ans+=mod;
        ans%=mod;
        System.out.println(ans);

    }
    public static long pow(int a,int b){
        long ans=1;
        for(int i=0;i<b;i++){
            ans*=a;
            ans%=mod;
        }
        return ans;
    }

}

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

using namespace std;

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

int main(){
  int n;
  cin >> n;
  vector<pair<double, pair<int64_t, int64_t> > > v;
  REP(i, n){
    int64_t a, b;
    cin >> a >> b;
    if(a == 0 && b == 0) continue;
    auto c = atan2(b, a);
    v.push_back({c, {a, b}});
  }
  n = v.size();
  sort(v.begin(), v.end());
  REP(i, n){
    v.push_back(v[i]);
  }
  int64_t m = 0;
  REP(i, n){
    int64_t x = 0, y = 0;
    REP(j, n){
      int64_t a, b;
      tie(a, b) = v[i + j].second;
      x += a, y += b;
      m = max(m, x * x + y * y);
    }
  }
  printf("%.20f\n", sqrt(m));
  return 0;
}

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

int main() {
	int n, m;
	while(cin >> n >> m, n || m) {
		vector<int> v;
		for(int i = 0; i < n; i++) {
			int tmp;
			cin >> tmp; v.push_back(tmp);
		}
		sort(v.rbegin(), v.rend());
		int res = 0;

		for(int i = 0; i < v.size(); i++) {
			if((i+1) % m)
				res += v[i];
		}
		cout << res << endl;
	}
}

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

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

    static class A {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int a = Integer.parseInt(in.next());
            int ans = a + a * a + a * a * a;

            // 出力
            out.println(ans);

        }

    }
}



Measured memory_bytes: 35660
#include <iostream>
#include <string>
#include <stdlib.h>

#define INC(i, a, b) for(int (i) = (a); (i) < (b); ++(i))
#define DEC(i, a, b) for(int (i) = (a); (i) > (b); --(i))
#define REP(i, n)    INC(i, 0, n)
#define comp(a, b) int comp(const void *(a), const void *(b))

typedef unsigned int uint;
typedef unsigned long ul;
typedef long long  ll;
typedef unsigned long long ull;

const int MOD = 1e9 + 7;

using namespace std;

void TFprint(bool b, std::string T, std::string F){
    if(b){
        cout << T << endl;
    }else{
        cout << F << endl;
    }
}

int abs(int x){
    return x > 0? x : -x;
}

int max(int a, int b){
    return a > b? a : b;
}

int min(int a, int b){
    return a < b? a : b;
}


int main(){
    int N, have;
    int m = 1001, sum = 0;
    cin >> N >> have;
    int need[N];
    REP(i, N){
        cin >> need[i];
        if(need[i] < m){
            m = need[i];
        }
        sum += need[i];
    }
    cout << N + (have - sum) / m << endl;
    return 0;
}

Measured memory_bytes: 256
package main

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

var reader = bufio.NewReaderSize(os.Stdin,1000000)
func NextLine() string {
  var line,buffer []byte
  var isPrefix bool = true
  var err error
  for isPrefix {
    line,isPrefix,err = reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer,line...)
  }
  return string(buffer)
}
func NextInt() int {
  var n int
  n,_ = strconv.Atoi(NextLine())
  return n
}

func main() {
  var N int
  N = NextInt()
  P := make([]int, N)
  Q := make([]int, N + 1)
  for i := range P {
    P[i] = NextInt()
    Q[i] = 1
  }
  cnt := 1
  for _, p := range P {
    if cnt < Q[p - 1] { cnt = Q[p - 1] }
    Q[p] = Q[p - 1] + 1
  }
  fmt.Println(N - cnt)
}

Measured memory_bytes: 8192
#include <iostream>
#include <cstdio>

using namespace std;
#define ll long long
const int MAX = 1e5 + 111;
const int mod = 1e9 + 7;
int n, k;

int main(){
    ll ans = 0;
    scanf("%d%d", &n, &k);
    for (int i = k; i <= n+1; i++){
        ans = (ans+1ll*i*(2*n-i+1)/2-1ll*i*(i-1)/2+1)%mod;
    }
    printf("%lld\n", ans);
}


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

using ll=long long;
const ll INF=1e9;
struct Edge{
    int to;
    ll w;
};
using Graph=vector<vector<Edge>>;

int main(){
    int n,m;
    cin>>n>>m;
    Graph g(n); 
    ll sumall=0;
    for(int i=0;i<m;i++){
        int a,b;
        ll c;
        cin>>a>>b>>c;
        sumall+=c;
        a--,b--;
        g[a].push_back(Edge{b,c});
        g[b].push_back(Edge{a,c});
    }

    vector<ll> sc(1<<n,0LL);
    for(int i=0;i<(1<<n);i++){
        ll sum=0;
        for(int j=0;j<n;j++){
            if((i>>j)&1){
                for(int k=0;k<g[j].size();k++){
                    if((i>>g[j][k].to)&1) sum+=g[j][k].w;
                }
            }
        }
        sc[i]=sum/2;
    }
    vector<vector<ll>> dp(1<<n,vector<ll>(n,-INF));
    dp[1][0]=0;
    for(int bit=1;bit<(1<<n);bit++){
        int sup=((1<<n)-1)&(~bit);
        for(int j=0;j<n;j++){
            if(!((bit>>j)&1)) continue;
            if(j==n-1){
                dp[(1<<n)-1][n-1]=max(dp[(1<<n)-1][n-1],dp[bit][n-1]+sc[sup+(1<<(n-1))]); 
            }
            else{
                int sub=sup;
                do{
                    dp[sub|bit][j]=max(dp[sub|bit][j],dp[bit][j]+sc[(1<<j)^sub]);
                    sub=(sub-1)&sup;
                }while(sub!=0);
            }
            for(int k=0;k<g[j].size();k++){
                if(!((bit>>g[j][k].to)&1)) dp[bit|(1<<g[j][k].to)][g[j][k].to]=max(dp[bit|(1<<g[j][k].to)][g[j][k].to],dp[bit][j]+g[j][k].w);
            }
        }
    }
    /*
    for(int i=0;i<(1<<n);i++){
        for(int j=0;j<n;j++){
            cerr<<"#"<<bitset<4>(i)<<" "<<j<<" "<<dp[i][j]<<endl;
        }
    }
    */
    cout<<sumall-dp[(1<<n)-1][n-1]<<endl;
    return 0;
}

Measured memory_bytes: 5376
#include <bits/stdc++.h>//solved by *ALIKHAN*
#define ll long long
#define ld long double
#define pb push_back
#define sz(x) (int)x.size()
#define F first
#define S second
#define ppb pop_back
#define mp make_pair
#define all(n) n.begin(), n.end()
#define timefaster ios_base::sync_with_stdio(0);cin.tie(0)

using namespace std;

const int N = (int)2e5 + 123;
const int mod = (int)1e9 + 7;
const ll INF = (ll)1e18;
int a[N] , b[N] , c[N] , sum;
int main(){
	timefaster;
	int n ;
	cin >> n;
	for(int i = 1;i < n;i ++){
	 	cin >> a[i];
	}
	sum += (a[1] + a[n - 1]);
	for(int i = 2;i < n;i ++){
	 	sum += min(a[i] , a[i - 1]);
	}
	cout << sum;
}// Aksay sila

Measured memory_bytes: 256
N = int(input())
A = str(input())
B = str(input())
C = str(input())

ans = 0
for i in range(N):
    if len(list(set([A[i], B[i], C[i]])))== 2:
        ans += 1
    elif len(list(set([A[i], B[i], C[i]]))) == 3:
        ans += 2


print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<cstdlib>

#define N 100000
using namespace std;


typedef struct{
  int num[N];
  int head;
  int tail;
}Queque;


//grobal
Queque que;

//add to head position
void Enqueue(int);
//delete head position
void Dequeue(void);
//return now of stck
int front(void);


int main(){
  //format
  que.head=0;
  que.tail=0;

  int pasttime=0;
  int i,n,q,tim=0;
  string name[N];
  int finishcount=0;
  int flag[N];
  int st;

  //load n and q
  cin >>n>>q;

  //load name and time
  for(i=0;i<n;i++){
    cin >>name[i]>>tim;
    Enqueue(tim);
  }

  //format flag
  for(i=0;i<n;i++){
    flag[i]=0;
  }
  
  i=0;

  while(1){
    if(finishcount==n) break;
    //i->n i=0 continue
    else if(i==n){
      i=0;
      continue;
      }
    //flag=1 go next
      else if(flag[i]==1){
      i++;
      continue;
    }
    //load
    st=front();

    if(st>q){
      Enqueue(st-q);
      Dequeue();
      pasttime+=q;
    }

    else{
      Dequeue();
      pasttime+=st;
      flag[i]=1;
      finishcount++;
      //print
      cout <<name[i]<<" "<<pasttime<<endl;
    } 
    
    i++;
  }
    
  
  return 0;
  
}

//add to head position
void Enqueue(int x){
  que.num[que.tail]=x;
  que.tail++; 
}
//delete head position
void Dequeue(void){
  que.head++;
}
//return now of stck
int front(void){
  return que.num[que.head];
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e7+10;
ll f[N];
int n;
int main()
{
	cin>>n;
	for(int i=1;i<N;i++)
		for(int j=i;j<N;j+=i) f[j]++;//逆向思维
	ll ans=0;
	for(ll i=1;i<=n;i++) ans=ans+f[i]*i;
	cout<<ans<<endl;
 } 

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

int main(void){
	int n;
	int a,b,c;
	while(cin>>n,n){
		std::map<int,int> m;
		for(int i=0;i<n;i++){
			cin>>a>>b>>c;
			m[a]=b+c;
		}
		__typeof(m.begin()) res=m.begin();
		for(__typeof(m.begin()) it=m.begin();it!=m.end();it++){
			if(res->second<it->second)res=it;
		}
		cout<<res->first<<" "<<res->second<<endl;
	}
	return 0;
}

Measured memory_bytes: 3484
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef pair<int,int>P;
int main(){
  vector<P>v;
  int n;
  cin>>n;
  while(n--){
    int x,y;
    cin>>x>>y;
    v.push_back(P(x,y));
  }
  sort(v.begin(),v.end());
  r(i,v.size()){
    cout<<v[i].first<<' '<<v[i].second<<endl;
  }
}


Measured memory_bytes: 3872
package main

import (
	"fmt"
	//"math"
)

func main() {
	var s1 string
	fmt.Scanf("%s", &s1)
	var s2 string
	fmt.Scanf("%s", &s2)
	c := 0 
	for i:=0;i<3;i++{
		if s1[i] == s2[i]{
			c++
		}
	}
	fmt.Print(c)
}

Measured memory_bytes: 512
package main

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

func main() {
	s := IOInitialize()
	N := Int(s)
	fmt.Println(N / 3)
}

func IOInitialize() *bufio.Scanner {
	s := bufio.NewScanner(os.Stdin)
	s.Split(bufio.ScanWords)
	return s
}

func Int(s *bufio.Scanner) int {
	if !s.Scan() {
		panic("scan error")
	}

	value, err := strconv.Atoi(s.Text())
	if err != nil {
		panic("text to int error")
	}
	return value
}


Measured memory_bytes: 640
fun main(args:Array<String>?): Unit {
    while(true) {
        val (n, m) = readLine()!!.trim().split(' ').map(String::toInt)
        if (n == 0 && m == 0) return
        val time = (listOf(0) + listOf(n, m).filter{it != 0}.flatMap{readLine()!!.trim().split(' ').map(String::toInt)}).sorted()
        println(
                time.indices.drop(1).map { i -> time[i] - time[i - 1] }.max()
        )
    }
}


Measured memory_bytes: 53788
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Main main = new Main();
		main.run();
	}

	public void run() {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int a[] = new int[n];
		for(int i=0; i<n; i++) {
			a[i]=sc.nextInt();
		}
		for(int i=0; i<n; i++) {
			a[i] -= i+1;
		}
		Arrays.sort(a);
		long b=-1;
		if(n%2==1) {
			b=a[n/2];
		}else {
			b=(a[n/2-1]+a[n/2])/2;
		}

		long ans = 0;
		for(int i=0; i<n; i++) {
			ans += Math.abs(a[i]-b);
		}
		System.out.println(ans);
		sc.close();
	}


}


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

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

int main() {
    string s;
    cin >> s;
    int n = stoi(s);
    int tmp = 0;
    rep(i, s.size()) tmp += (s[i]-'0');
    cout << ((n%tmp==0) ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
n,a,b=[int(i) for i in input().split()]

def check(n):
    each=list(str(n))
    total=0
    for i in each:
        total+=int(i)
    if total>=a and total<=b:
        return True
    return False

ans=0
for i in range(1,n+1):
    if check(i):
        ans+=i
print(ans)

Measured memory_bytes: 3060
n, p = map(int, input().split())
a = list(map(int, input().split()))
a_even = 0
a_odd = 0
for i in a:
    if i % 2 == 0:
        a_even += 1
    else:
        a_odd += 1
        
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k]) 
    
    return result
        
if p == 0:
    odd = 0
    for i in range(a_odd//2 + 1):
        odd += cmb(a_odd, 2 * i)
    print((2 ** (a_even)) * odd)
else:
    odd = 0
    if a_odd % 2 == 0:
        for i in range(a_odd//2):
            odd += cmb(a_odd, 2 * i + 1)
    else:
        for i in range(a_odd//2 + 1):
            odd += cmb(a_odd, 2 * i + 1)
    print((2 ** (a_even)) * odd)

Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
const int64 mod = 1000000007;

struct Combination {
	vector<int64_t> fact, rfact;
	Combination(int sz) : fact(sz + 1), rfact(sz + 1) {
		fact[0] = 1;
		for(int i = 1; i < fact.size(); i++){
			fact[i] = fact[i - 1] * i % mod;
		}
		rfact[sz] = inv(fact[sz]);
		for(int i = sz - 1; i >= 0; i--){
			rfact[i] = rfact[i + 1] * (i + 1) % mod;
		}
	}
	int64_t inv(int x) const {
		return pow(x, mod - 2);
	}
	int64_t pow(int64_t x, int64_t n) const {
		int64_t ret = 1;
		while(n > 0){
			if(n & 1) (ret *= x) %= mod;
			(x *= x) %= mod;
			n >>= 1;
		}
		return (ret);
	}
	int64_t P(int n, int r) const {
		if(r < 0 || n < r) return (0);
		return (fact[n] * rfact[n - r] % mod);
	}

	int64_t C(int p, int q) const {
		if(q < 0 || p < q) return (0);
		return (fact[p] * rfact[q] % mod * rfact[p - q] % mod);
	}

	int64_t H(int n, int r) const {
		if(n < 0 || r < 0) return (0);
		return (r == 0 ? 1 : C(n + r - 1, r));
	}
};

int64 n;
vector<int> G[200010];
Combination c(200010);
int64 ans = 0;

int dfs(int v, int p){
	int64 sz = 0;
	int64 pr = 0;
	for(auto u : G[v]){
		if(u == p) continue;
		int tmp = dfs(u, v);
		sz += tmp;
		pr += (c.pow(2, tmp) - 1 + mod) % mod * c.inv(c.pow(2, n - 1)) % mod;
		// cout << " " << v << " " << tmp << endl;
		ans %= mod;
	}
	int op = n - sz - 1;
	// cout << " " << v << " " << op << endl;
	if(op) pr += (c.pow(2, op) - 1 + mod) % mod * c.inv(c.pow(2, n - 1)) % mod;
	pr += c.inv(c.pow(2, n - 1));
	pr %= mod;
	ans += (1 - pr + mod) % mod * c.inv(2) % mod;
	ans %= mod; 
	// cout << v << ' ' << sz + 1 << endl;
	return sz + 1;
}

int main(){
	cin >> n;
	for(int i = 0; i < n - 1; i++){
		int a, b;
		cin >> a >> b;
		a--; b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	dfs(0, -1);
	cout << ans << endl;
}

Measured memory_bytes: 25472
import sys
H, W = map(int, input().split())
if H == 1 or W == 1:
    print(1)
    sys.exit()
odd = int((H + 1) / 2) * int((W + 1) / 2)
even = int(H / 2) * int(W / 2)
print(odd + even)


Measured memory_bytes: 2940
// #includes {{{
#ifdef MY_DEBUG
#include "header/header.hpp"
#else
#include <bits/stdc++.h>
#endif

using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define RREP(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();++i)
#define LET(x,a) __typeof(a) x(a)
//#define IFOR(i,it,c) for(__typeof((c).begin())it=(c).begin();it!=(c).end();++it,++i)
#define ALL(c) (c).begin(), (c).end()
#define MP make_pair

#define EXIST(e,s) ((s).find(e)!=(s).end())

#define RESET(a) memset((a),0,sizeof(a))
#define SET(a) memset((a),-1,sizeof(a))
#define PB push_back
#define DEC(it,command) __typeof(command) it=command

//debug

#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)

typedef long long Int;
typedef unsigned long long uInt;
typedef long double rn;

template<class T>
constexpr T inf = numeric_limits<T>::has_infinity ? numeric_limits<T>::infinity():(numeric_limits<T>::max()/2);

int __inf_ignore(){
	int t = inf<int>;
	return t;
}

typedef pair<int,int> pii;

#ifdef MY_DEBUG
#include"print.hpp"
#include"debug.hpp"
#endif
// }}}

Int N;
Int K;

void solve(){
	Int D = (N-1)*(N-2)/2;
	if(K>D){
		cout<<-1<<endl;
	}else{
		assert(K<=D);
		vector<pii> vs;
		REP(u,N-1)for(int v = u + 1;v < N-1;v++){
			vs.push_back({u,v});
		}
		vector<pii> e;
		REP(u,N-1)e.push_back({u,N-1});
		REP(i,D - K)e.push_back(vs[i]);
		cout<<e.size()<<endl;
		for(auto &&p:e){
			cout<<p.first + 1<<" "<<p.second + 1<<endl;
		}
	}
}

//{{{ main fucnction
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin >> N;
    cin >> K;
	solve();
	return 0;
}

//}}}


Measured memory_bytes: 384
//              _      _                 
//             (_)    | |                
//    _ __ ___  _  ___| |__   __ _  ___  
//   | '_ ` _ \| |/ __| '_ \ / _` |/ _ \ 
//   | | | | | | | (__| | | | (_| | (_) |
//   |_| |_| |_|_|\___|_| |_|\__,_|\___/ 
//                                       
// 
#include <bits/stdc++.h>
#define int long long
#define mp make_pair
#define pb push_back
#define ld long double
#define pii pair<int,int>
#define sz(x) (int)x.size()
#define piii pair<pii,pii>
#define precise cout<<fixed<<setprecision(10)
#define st first
#define nd second
#define ins insert
#define vi vector<int>
#define BOOST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
const int MAX=2e5+5;
int tab[MAX];
int ans=0;
int32_t main()
{
  BOOST;
  int n;
  cin>>n;
  for (int i=1;i<=n;i++)cin>>tab[i];
  sort(tab+1,tab+n+1,greater<int>());
  ans+=tab[1];
  int wsk=2;
  int xd=0;
  for (int i=3;i<=n;i++)
  {
  	if (xd==2)xd=0,wsk++;
  	ans+=tab[wsk];
  	xd++;
  }
  cout<<ans;
  return 0;
}


Measured memory_bytes: 5212
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

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

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  s=S()
  s=s.replace('?','D')

  return s

# main()
print(main())


Measured memory_bytes: 10764
package main

import (
	"fmt"
)

func main() {
	a, b := SingleInt(), SingleInt()

	if a-b >= 1 {
		fmt.Printf("%#v\n", a+(a-1))
		return
	}

	if a == b {
		fmt.Printf("%#v\n", a+b)
		return
	}

	if b-a >= 1 {
		fmt.Printf("%#v\n", b+(b-1))
		return
	}
}

func SingleInt() int {
	var n int
	fmt.Scan(&n)
	return n
}


Measured memory_bytes: 512
n, k = map(int, input().split())
s = input()

see = s[0]
cnt = 0
cluster = 1
for i in range(1, n):
    if see == s[i]:
        cnt += 1
    else:
        see = s[i]
        cluster += 1

for i in range(k):
    if cluster > 2:
        cluster -= 1
        cnt += 2
    else:
        print(n - 1)
        exit()
print(min(cnt, n - 1))


Measured memory_bytes: 39536
N=int(input())
lst=[0]
mod=10**9+7
for i in range(N):
  a=int(input())
  if lst[-1]==a:
    continue
  else:
    lst.append(a)
length=len(lst)
L=[0]*(2*10**5+1);DP=[0]*(length-1)
DP.insert(0,1)
for i in range(1,length):
  if L[lst[i]]==0:
    DP[i]=DP[i-1]%mod
    L[lst[i]]=i
  else:
    j=L[lst[i]]
    DP[i]=(DP[i-1]+DP[j])%mod
    L[lst[i]]=i
print(DP[-1])


Measured memory_bytes: 20500
import os
import sys
from collections import defaultdict, Counter
from itertools import product, permutations,combinations, accumulate
from operator import itemgetter
from bisect import bisect_left,bisect
from heapq import heappop,heappush
from fractions import gcd
from math import ceil, floor, sqrt
from copy import deepcopy

def main():
    l,r = map(int, input().split())
    ans = 2019

    if r - l >= 2019:
        print(0)
        sys.exit()

    for i in range(l,r+1):
        for j in range(i+1,r+1):
            if i%2019 == 0 or j%2019 == 0:
                ans = 0
                break
            else:
                ans = min(ans, (i*j)%2019)
    print(ans)
   
if __name__ == "__main__":
    main()

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

int main()
{
    int N;
    cin >> N;
    vector<int> bar(N);
    rep(i, 0, N) cin >> bar[i];
    sort(bar.begin(), bar.end());

    ll res = 0;
    rep(i, 0, N-2)
        rep(j, i+1, N-1)
        {
            int a = bar[i];
            int b = bar[j];
            int max_c = a+b-1;
            int k = upper_bound(bar.begin()+j+1, bar.end(), max_c)  - bar.begin();
            // cout << i << ' ' << j << ' ' << k << ' ' << max_c << ' ' << res << endl;
            res += (ll) k-1-j;
            // if (k == N)
            //     res += (ll) k-1-j;
            // else 
            // {
            //     if (max_c < bar[k])
            //         --k;
            //     res += (ll) k-j;
            // }
        }
    cout << res << endl;
    return 0;
}

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

using namespace std;

int  main(){
  int r0,w0,C,R;
  int i;
  int ans;

  while(cin>>r0>>w0>>C>>R){
    if(r0==0&&w0==0&&C==0&&R==0){
      break;
    }
    ans=1;
    i=1;

    if(r0>=w0*C){
      cout << 0 << endl;
    }

 else if(r0<w0*C){
   while(1){
     if((r0+i*R) >= w0*C){
       cout << ans << endl;
       break;
     }
     ans+=1;
     i++;
   }
 }
  }
  return 0;
}

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

using namespace std;

int main()
{
	int n,i,j;
	string str;
	
	cin >> n;
	
	for(i=0;i<n;i++)
	{
		cin >> str;
		
		if(str[0]=='>')
		{
			if(str[1]=='\'')
			{
				int num=0;
				for(j=2;j<str.size();j++)
				{
					if(str[j]=='=')
						num++;
					else if(num>0 && str[j]=='#')
					{
						for(j+=1;j<str.size();j++)
						{
							if(j==str.size()-1 && str[j]=='~' && num==0)
								cout << "A" << endl;
							else if(j!=str.size()-1 && str[j]=='=')
								num--;
							else
							{
								cout << "NA" << endl;
								break;
							}
						}
						break;
					}
					else
					{
						cout << "NA" << endl;
						break;
					}
				}
			}
			else if(str[1]=='^')
			{
				if(str.size()<6)
					cout << "NA" << endl;
				else
				{
					for(j=2;j<str.size();j++)
					{
						if(j==str.size()-2 && str[j]=='~' && str[j+1]=='~')
						{
							cout << "B" << endl;
							break;
						}
						else if(j==str.size()-2 && (str[j]!='~' || str[j+1]!='~'))
						{
							cout << "NA" << endl;
							break;
						}
						else if((j%2==0 && str[j]!='Q') || (j%2==1 && str[j]!='='))
						{
							cout << "NA" << endl;
							break;
						}
					}
				}
			}
			else
				cout << "NA" << endl;
		}
		else
			cout << "NA" << endl;
	}
}

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

int main()
{
    string s;
    cin >> s;
    int n = s.size();
    int j = n - 1, c = 0;
    for (int i = 0; i < (n / 2); i++)
    {
        if(s[i] != s[j])
        {
            c++;
        }
        j--;
    }
    cout << c << endl; 
    return 0;
}

Measured memory_bytes: 256
a,b,c=map(int,input().split())
list=[a,b,c]
x=max(list)
y=min(list)
list.sort()
z=list[1]
if a==b==c:
    print("0")
elif a==b==x or b==c==x or c==a==x:
    if (x-y)%2==0:
        print(int((x-y)/2))
    else:
        print(int((x+1-y)/2)+1)
elif a==b==y or b==c==y or c==a==y:
    print(x-y)
else:
    if (z-y)%2==0:
        print(int((z-y)/2)+x-z)
    else:
        v=x+1
        w=z+1
        print(1+int((w-y)/2)+v-w)
    

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#include <set>
#include <cmath>
#include <string>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define FI first
#define SE second
#define VE vector<int>
#define PB push_back
#define LL long long
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
using namespace std;
//
const int INF=1e9+7;
const int MOD=1e9+7;
//
LL N;
LL M,A,R,C,H;
int main(){
  cin>>N;
  FOR(i,0,N){
    string S;
    cin>>S;
    if(S[0]=='M'){
      M++;
    }else if(S[0]=='A'){
      A++;
    }else if(S[0]=='R'){
      R++;
    }else if(S[0]=='C'){
      C++;
    }else if(S[0]=='H'){
      H++;
    }
  }
  LL ans=M*A*R+M*A*C+M*A*H+M*R*C+M*R*H+M*C*H+A*R*C+A*R*H+A*C*H+R*C*H;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;


// ?????????????????????????????????????????????????????????
public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = 2;
		boolean same = true; 
		Dice[] dice = new Dice[n];
		int[] temarray = new int[6 + 1];
		int[] tararray = new int[6 + 1];
		temarray[0] = 0;
		for (int i = 0; i < n; i++) {
			for (int j = 1; j < 7; j++) {
				temarray[j] = scan.nextInt();
			}
			dice[i] = new Dice(temarray);
		}
		
		temarray = dice[0].getNum();
		if (dice[1].check(temarray)) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}
	

class Dice {
	private int[] num = new int[6 + 1];
	Dice() {
	}

	Dice(int[] array) {
		for (int i = 0; i < array.length; i++) {
			this.num[i] = array[i];
		}
	}
	
	public int[] getNum() {
		return this.num;
	}
	
	public int getNumber(int i) {
		return this.num[i];
	}
	
	// ??????????????¢??????????????????
	public int[] roll(int[]ary, String order) {
		int now_1 = 1;	int now_2 = 2;	int now_3 = 3;	int tmp;
		int[] array = ary;
		char[] check = {'N', 'E', 'S', 'W'};
		for (int i = 0; i < order.length(); i++) {
			for (int j = 0; j < check.length; j++) {
				if (order.charAt(i) == check[j]) {
					switch (j + 1) {
						case 1:
							tmp = now_1;
							now_1 = now_2;
							now_2 = 7 - tmp;
							break;
						case 2:
							tmp = now_1;
							now_1 = 7 - now_3;
							now_3 = tmp;
							break;
						case 3:
							tmp = now_1;
							now_1 = 7 - now_2;
							now_2 = tmp;
							break;
						case 4:
							tmp = now_1;
							now_1 = now_3;
							now_3 = 7 - tmp;
							break;
					}
				}
			}
		}
		int[] cp_array = new int[array.length];
		cp_array[1] = array[now_1]; cp_array[2] = array[now_2];
		cp_array[3] = array[now_3]; cp_array[4] = array[7 - now_3];
		cp_array[5] = array[7 - now_2]; cp_array[6] = array[7 -now_1];
		return cp_array;
	}
	
	
	// ??????????????????????????????????????????
	public boolean check(int[] tarary) {
		int[] ary = tarary;
		String[] str = {"null", "N", "N", "N", "E", "WW"};
		int sum = 0;
		int[] array = new int[this.num.length];
		for (int i = 0; i < this.num.length; i++) {
			array[i] = this.num[i];
		}
		boolean decision = false;
		for (int i = 0; i < str.length; i++) {
			array = this.roll(array, str[i]);
			for (int j = 0; j < 4; j++) {
				if (array[1] == ary[1]) {
					if (array[2] == ary[2]) {
						for (int k = 3; k < ary.length; k++) {
							
							if (array[k] != ary[k]) {
								decision = false;
								break;
							}
							decision = true;
						}
					}
					if (decision) {
						break;
					} else {
						array = this.roll(array, "NWS");
					}
				} else {
					break;
				}
			}
			if (decision) break;
		}
		

		return decision;
	}
}

Measured memory_bytes: 26360
s=input()

for i in range(len(s)//2):
    l=len(s)-2*i-2
    #lなど変数で置き換えればわかりやすい
    #print(s[:l//2])
    #print(s[l//2:l])
    if s[:l//2]==s[l//2:l]:
        print(l)
        break

Measured memory_bytes: 2940
//{{{
#include <bits/stdc++.h>
using namespace std;
#define rep(...) repN((__VA_ARGS__,rep3,rep2,loop,~))(__VA_ARGS__)
#define loop(n) rep2(_loop_,n)
#define rep2(i,n) rep3(i,0,n)
#define rep3(i,begin,end) for(int i=(int)(begin),i##_end=(int)(end);i<i##_end;++i)
#define repN(a) repX a
#define repX(a0,a1,a2,x,...) x
#define foreach(x,a) for(auto &x:a)
typedef long long ll;
const ll MOD = 1e9+7;
//}}}

int a[200001];
int b[200001];
int c[200000];
int main(){
  int N, M;
  cin >> N >> M;
  rep(i, M){
    cin >> a[i];
    cin >> b[i];
  }
  bool ans = false;
  rep(i, M){
    if(a[i] == 1) c[b[i]]++;
  }
  rep(i, M){
    if(b[i] == N && c[a[i]]) ans = true;
  }

  puts(ans ? "POSSIBLE" : "IMPOSSIBLE");
  return 0;
}


Measured memory_bytes: 2560
input = gets.chomp.split(" ").map{|x|x.to_i}

x,y = input
b = (y - x * 2)/2.0
a = x - b
if a >= 0 && b >= 0 && a%1 == 0 && b%1 == 0
  puts "Yes"
else
  puts "No"
end


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

int main(void){
  string n;
  cin >> n;
  if((n[0] == n[1] && n[1] == n[2]) || (n[1] == n[2] && n[2] == n[3])) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
x,n = list(map(int, input().split())) 
l = list(map(int, input().split())) 

ret = 0
i = 0
if n==0:
    ret = x
else:
    ret=x
    if( ret in l):
        while True:
            i+=1
            ret = x-i
            if( not ret in l):
                break
            ret = x+i
            if( not ret in l):
                break
print(ret)


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

int main() {
  int N;
  cin >> N;
  vector<int> H(N);
  for (int i = 0; i < N; i++) cin >> H.at(i);

  int A = *max_element(H.begin(), H.end());

  H.push_back(0);

  int ans = 0;

  for (int i = 0; i < A; i++) {
    for (int j = 0; j < N; j++) {
      if (H.at(j) > 0) {
        H.at(j)--;
        if (H.at(j + 1) == 0) ans++;
      }
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i=0; i<ll(n); i++)
#define REPR(i, n) for(ll i=n-1; i>=0; i--)
#define FOR(i, m, n) for(ll i=m; i<ll(n); i++)
#define ALL(v) v.begin(), v.end()
#define SIZE(x) ll(x.size()) 
using P = pair<int, int>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 2e9;
const ll LINF = (1LL<<60);

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n; cin >> n;
  vector<ll> a(n);
  REP(i,n) cin >> a[i];

  ll par = a[0];
  ll ans = 0;
  FOR(i,1,n){ 
    if(par>a[i]){
      ans += par-a[i];
      a[i] = par;
    }
    par = a[i];
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 4772
open Printf open Scanf
open Array

let () =
  scanf " %d" @@ fun n ->
    let a = init n (fun _ -> scanf " %d" @@ fun v -> v) in
    let nn = map (fun v -> if v < 0 then 1 else 0) a
    |> fold_left (+) 0 in
    let aa =
      map abs a in
    let res = if nn mod 2 = 0 then (
      fold_left (+) 0 aa
    ) else (
      let mn = fold_left min max_int aa in
      fold_left (+) 0 aa - 2 * mn
    ) in
    print_int res




Measured memory_bytes: 6272
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
const int N = 5e5 + 10;
const int mod = 1e9 + 7;

ll fac[N];

ll binpow(ll a, ll b) {
    ll res = 1;
    while (b > 0) {
        if (b & 1) res = res * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return res;
}

void init() {
    fac[0] = 1;
    for (int i = 1; i < N; i++) 
        fac[i] = fac[i - 1] * i % mod;
}

ll inv(ll a) {
	return binpow(a, mod - 2);
}

ll A(ll n, ll m) {
	return fac[n] * inv(fac[n - m]) % mod;
}

ll C(ll n, ll m) {
    return fac[n] * inv(fac[m]) % mod * inv(fac[n - m]) % mod;
}

int main() {
	init();
	int n, m; cin >> n >> m;
	ll sum = 0;
	for (int i = 0; i <= n; i++) {
		sum += binpow(-1, i) * C(n, i) * A(m - i, n - i) % mod;
		sum = (sum + mod) % mod;
	}
	cout << A(m, n) * sum % mod << "\n";
}

Measured memory_bytes: 7548
#include <bits/stdc++.h>
#define FOR(i, a, n) for(int (i) = (int)(a); (i) < (int)(n); ++(i))
#define FORe(i, a, n) for(int (i) = (int)(a); (i) <= (int)(n); ++(i))
#define rFOR(i, a, n) for(int (i) = (int)(n)-1; (i) >= (int)(a); --(i))
#define REP(i, n) FOR((i), 0, (n))
#define REPe(i, n) FORe((i), 0, (n))
#define rREP(i, n) rFOR((i), 0, (n))
#define rep(i, n) FOR((i), 0, (n))
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define fi first
#define se second
#define dup(x, y) (((x)+(y)-1)/(y))
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using P = pair<int,int>;
using T = tuple<int,int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vs = vector<string>;
using vp = vector<P>;
using vt = vector<T>;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
  int n;
  string s;
  cin >> n >> s;
  rep(i,s.size()) {
    char c = s[i];
    c += n;
    if (c > 'Z') c -= 26;
    s[i] = c;
  }
  cout << s << endl;

  return 0;
}

Measured memory_bytes: 256
import bisect,collections,copy,itertools,math,string
def I(): return int(input())
def S(): return input()
def LI(): return list(map(int,input().split()))
def LS(): return list(input().split())
##################################################
H,W = LI()
C = [LS() for _ in range(H)]
for x in C:
    print(*x)
    print(*x)

Measured memory_bytes: 4020
N,M = map(int, input().split())
dp = [1] * (N + 1)

for _ in range(M):
  a = int(input())
  dp[a] = 0

for i in range(2,N+1):
  if (1 == dp[i]):
    dp[i] = (dp[i-1] + dp[i-2]) % 1000000007


print(dp[-1])


Measured memory_bytes: 6900
//
// Created by Hideaki Imamura on 2020-03-28.
//
# include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair <ll, ll> l_l;
typedef pair<int, int> i_i;

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

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

# define EPS (1e-7)
# define INF (1e9)
# define PI (acos(-1))
//const ll mod = 1000000007;

int N, X, Y;

int main() {
    cin >> N >> X >> Y;
    vector<int> d(N, 0);
    for (int i = 1; i <= N; ++i) {
        for (int j = i + 1; j <= N; ++j) {
            int distance = min(j - i, min((int)abs(X - i) + (int)abs(Y - j) + 1, (int)abs(Y - i) + (int)abs(X - j) + 1));
            d[distance]++;
        }
    }
    for (int k = 1; k <= N - 1; ++k) cout << d[k] << endl;
    return 0;
}

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

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int A, B;
    cin >> A >> B;
    if (B % A == 0) {
        cout << A + B << endl;
    } else {
        cout << B - A << endl;
    }
}

Measured memory_bytes: 256