akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;

//typedef
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//conversion
inline LL toLong(string s) {LL v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) LL((a).size())
#define EACH(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define UNTIL(p) while(!(p))

//constant
const double EPS = 1e-5;
const double PI  = acos(-1.0);

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

#define PUTS(x) cout << (x) << endl;

const LL MOD = 1e9 + 7;
const LL M = 50;
LL n;
vector<vector<LL>> link;

LL dp[50][50][M+1] = {0};
map<LL,LL> memo[50][50];

LL f(LL i, LL j, LL k) {
    if(k < M){
        return dp[i][j][k];
    }
    if(EXIST(memo[i][j], k)){
        return memo[i][j][k];
    }
    LL x = k/2;
    LL y = k - x;
    LL sum = 0;
    REP(t,n){
        sum += (f(i, t, x) * f(t, j, y)) % MOD;
        sum %= MOD;
    }
    memo[i][j].insert(MP(k, sum));
    return sum;
}

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

    LL k;
    cin>>n>>k;
    link.resize(n);
    REP(i,n){
        REP(j,n){
            LL a;
            cin>>a;
            if(a == 1)link[i].PB(j);
        }
    }

    REP(i,n)dp[i][i][0] = 1;
    REP(len,M){
        REP(i,n){
            for(LL to : link[i]){
                REP(st, n){
                    dp[st][to][len+1] += dp[st][i][len];
                    dp[st][to][len+1] %= MOD;
                }
            }
        }
    }

    LL ans = 0;
    REP(i,n)REP(j,n){
        ans += f(i, j, k);
        ans %= MOD;
    }
    PUTS(ans);
}

Measured memory_bytes: 18432
#include<bits/stdc++.h>
#define mod 1000000007
using namespace std;

int main()
{
    long long int n,i,j,len;
    cin>>n;

    long long int dp[n][n];

    for(i=0;i<n;i++)
        for(j=0;j<n;j++)
            dp[i][j]=1e14;

    vector<long long int> v(n+1,0);
    for(i=1;i<=n;i++)
        cin>>v[i],v[i]+=v[i-1],dp[i-1][i-1]=0;

    for(len=2;len<=n;len++)
    {
        for(i=0;i<=n-len;i++)
        {
            for(j=i;j<i+len-1;j++)
                dp[i][i+len-1]=min(dp[i][i+len-1],dp[i][j]+dp[j+1][i+len-1]+v[i+len]-v[i]);
        }
    }
    cout<<dp[0][n-1];
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
 
int st, x, l, r, d, sw, n, m, dd, tmp, res, rl, rr;
 
struct S{
	int d;
	int std;
}s[100010];

int root(int i){
	if(s[i].std == i) return i;
	return root(s[i].std);
}
 
int main(){
	scanf("%d %d", &n, &m);
	
	sw = 1;
	
	for(int i=1; i<=m; i++){
		scanf("%d %d %d", &l, &r, &d);
		
		if(s[l].std==0 && s[r].std==0){
			s[l].std = s[r].std = l;
			s[r].d = d;
		}
		else if(s[l].std == 0){
			s[l].std = s[r].std;
			s[l].d = s[r].d - d;
		}
		else if(s[r].std == 0){
			s[r].std = s[l].std;
			s[r].d = s[l].d + d;
		}
		else {
			// std 갱신  
			rl = root(l), rr = root(r);
			while(s[l].std != rl){
				s[l].d += s[s[l].std].d;
				s[l].std = s[s[l].std].std;
			}
			while(s[r].std != rr){
				s[r].d += s[s[r].std].d;
				s[r].std = s[s[r].std].std;
			}
			
			if(s[r].std != s[l].std){ // res를 구하고, d와 비교
				s[s[r].std].d = -s[r].d;
				s[s[r].std].std = r;
				s[r].std = r;
				s[r].d = 0;
				
				s[s[l].std].d = -s[l].d;
				s[s[l].std].std = l;
				s[l].std = l;
				s[l].d = 0;
				
				s[r].std = l;
				s[r].d = d;
			}
			else if(s[r].d != s[l].d + d) {
				sw = 0;
				break;
			}
		}
	}
	if(sw) printf("Yes");
	else printf("No");
	
	return 0;
}

Measured memory_bytes: 1024
n = int(input())
s = [input() for i in range(n)]
empl = [[],[],[],[]]
for i in s:
    if i == 'AC':
        empl[0].append(i)
    elif i == 'WA':
        empl[1].append(i)
    elif i == 'TLE':
        empl[2].append(i)
    else:
        empl[3].append(i)
print('AC x',len(empl[0]))
print('WA x',len(empl[1]))
print('TLE x',len(empl[2]))
print('RE x',len(empl[3]))

Measured memory_bytes: 87572
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;

const ll LINF = 1e18;
const int INF = 1e9;
const ll MOD = 1000000007;

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

int main(){

    ll n;
    cin >> n;
    char c[26] = {'z','a','b','c','d','e','f','g','h',
                    'i','j','k','l','m','n','o',
                    'p','q','r','s','t','u','v',
                    'w','x','y'};
    if(n <= 26){
        cout << c[n%26] << endl;
        return 0;
    }
    string ans = "";

    bool flg = true;
    while(n / 26 != 0){

        ans += c[n%26];
        if(n%26 == 0){
            n /= 26;
            n--;
            if(n == 0) flg = false;
        }
        else{
            n /= 26;
        }
    } 
    if(flg) ans += c[n%26];

    reverse(ans.begin(), ans.end());
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3580
#define __mode_debug__
/*   ξ
     ll
   ＿ll＿
 ／  ∞  ＼
│*  Ａ  *│
│*  Ｃ  *│
│*  祈  *│
│*  願  *│
│*      *│
 ￣￣￣￣￣    */
//C++14 (GCC 5.4.1)
#include <bits/stdc++.h>
using namespace std;
#ifdef __mode_debug__
    #define DBG
#else
    #define DBG if(false)
#endif

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

#define whole(a) (a).begin(),(a).end()
#define rwhole(a) (a).rbegin(),(a).rend()

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define rrepd(i,a,b) for(int i=(a);i>=(b);i--)
#define each(itr,ds) for(auto itr=(ds).begin();itr!=(ds).end();itr++)

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

template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); }

//DUMP
//  ostream vector<T> , vector<vector<T>> , set<T> ,queue<T> , priority_queue<T> , pair<T,U> , map<T,U>
template<class T> ostream& operator<<(ostream&os,vector<T>&vec){os<<"{ ";rep(i,vec.size()) os<<((i==0)?"":", ")<<i<<":"<<vec[i];os<<" }";return os;}
template<class T> ostream& operator<<(ostream&os,vector<vector<T>>&vec){os<<"{"<<endl;rep(i,vec.size())os<<"\t   "<<i<<":"<<vec[i]<<((i==vec.size()-1)? "":",")<<endl;os<<"\t }";return os;}
template<class T> ostream& operator<<(ostream&os,set<T>&p){os<<"{ ";each(itr,p)  os<<((itr==p.begin())?"":", ")<<*itr;os<<" }";return os;}
template<class T> ostream& operator<<(ostream&os,queue<T>&p){queue<T> q(p);os<<"[< "<<(q.empty()?" <]":"");while(!q.empty()){os<<q.front();q.pop();os<< (q.empty() ? " <]" : ", ");}return os;}
template<class T> ostream& operator<<(ostream&os,priority_queue<T>&p){priority_queue<T> q(p);os<<"[< "<<(q.empty()?" <]":"");while(!q.empty()){os<<q.top();q.pop();os<< (q.empty() ? " <]" : ", ");}return os;}
template<class T,class U> ostream& operator<<(ostream&os,pair<T,U>&p){os<<"("<<p.first<<","<<p.second<<")";return os;}
template<class T,class U> ostream& operator<<(ostream&os,map<T,U>&p){os<<"{ ";each(itr,p)os<<((itr==p.begin())?"":", ")<<itr->first<<":"<<itr->second;os<<" }";return os;}
void dump_f(string &nm,char t){cerr<<endl;}
template<class T,class... Ts> void dump_f(string &nm,char t,T &&x,Ts&&... ts){int l=nm.find_first_of(',');string name(nm,0,l),nx(nm,l+1,-1);if(t=='\n') cerr<<"  "<<name<<"\t: "<<x<<t;else cerr << name<<": "<<x<<","<<t;dump_f(nx,t,forward<Ts>(ts)...);}
template<class... Ts> void dump_m(int &&ln,string &&nm,char t,Ts&&... ts){cerr<<"[ln: "<<ln<<"]"<<t;dump_f(nm,t,forward<Ts>(ts)...);}
#define dump(...) DBG dump_m(__LINE__,#__VA_ARGS__,'\n',__VA_ARGS__)
#define dl(...) DBG dump_m(__LINE__,#__VA_ARGS__,'\t',__VA_ARGS__)

#define lower_bound_idx(V,c) distance(V.begin(),lower_bound(whole(V),c))

int main() {
    ios::sync_with_stdio(false);//stdout<=>cout
    cin.tie(nullptr);//cin<=>cout


    ll H,N,x;
    cin >>H>>N;
    rep(i,N){
        cin >> x;
        H-=x;
    }
    cout << ((H<=0) ? "Yes" : "No") <<endl;


    return (0);
}

Measured memory_bytes: 256
/*
 *  author : Atul Anand   
 *  created on : Wed Apr 01 2020
 */

import java.io.*;
import java.util.*;

public class Main{

    public static void main(String[] args) throws IOException {
        int N = in.nextInt();
        int d[] = new int[N];
        read(d, N);
        long sum = 0;
        for(int i = 0; i < N; i++){
            for(int j = i + 1; j < N; j++){
                sum += d[i] * d[j];
            }
        }
        println(sum);
        in.close();
        out.close();
    }

    static int MIN = Integer.MIN_VALUE;
    static int MAX = Integer.MAX_VALUE;
    static Reader in = new Reader();
    static PrintWriter out = new PrintWriter(System.out);

    static void read(int arr[], int N) throws IOException { 
    	for(int i = 0; i < N; i++){ 
    		arr[i] = in.nextInt(); 
    	} 
    }
    
    static void read(long arr[], int N) throws IOException { 
    	for(int i = 0; i < N; i++){ 
    		arr[i] = in.nextLong(); 
    	} 
    }
    
    static void read(String arr[], int N) throws IOException { 
    	for(int i = 0; i < N; i++){ 
    		arr[i] = in.next(); 
    	} 
    }
    
    static void print(Object O) {  
    	out.print(O); 
    }
    
    static void println(Object O) { 
    	out.println(O); 
    }
    
    static void println(int arr[]) { 
    	for(int i = 0; i < arr.length; i++){ 
    		print(arr[i]+" "); 
    	} 
    	println(""); 
    }

    static void println(int arr[][]) { 
    	for(int i = 0; i < arr.length; i++){ 
    		println(arr[i]); 
    	}
    }
    
    static void debug(Object O) { 
    	System.out.println(O); 
    }
}

class Reader {
    BufferedReader reader;
    StringTokenizer tokenizer;

    Reader() {
        reader = new BufferedReader(new InputStreamReader(System.in));
        tokenizer = new StringTokenizer("");
    }

    String next() throws IOException {
        while (!tokenizer.hasMoreTokens() ) { 
            tokenizer = new StringTokenizer(reader.readLine()); 
        }
        return tokenizer.nextToken();
    }

    int nextInt() throws IOException { 
        return Integer.parseInt(next()); 
    }
    
    double nextDouble() throws IOException { 
        return Double.parseDouble(next());
    }
    
    long nextLong() throws IOException { 
        return Long.parseLong(next()); 
    }
    
    String nextLine() throws IOException { 
        return reader.readLine(); 
    }
    
    void close() throws IOException { 
        reader.close(); 
    }
}

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

int main(){
	string s;
	char b[3][3];
	char ch, ans;
	bool v, h, s1, s2;
	while (cin >> s) {
		for (int y = 0; y < 3; y++) {
			for (int x = 0; x < 3; x++) {
				b[y][x] = s[x*3+y];
			}
		}

		ans = 'd';
		for (int i = 0; i < 2; i++) {
			ch = i == 0 ? 'o' : 'x';
			for (int j = 0; j < 3; j++) {
				v = h = s1 = s2 = true;
				for (int k = 0; k < 3; k++) {
					if (b[j][k] != ch) {
						h = false;
					}
					if (b[k][j] != ch) {
						v = false;
					}
					if(b[k][k] != ch){
						s1 = false;
					}
					if(b[k][2-k] != ch){
						s2 = false;
					}
				}
				if(v || h || s1 || s2){
					ans = ch;
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#define ll long long
#define gmax(x,y) x=max(x,y)
#define gmin(x,y) x=min(x,y)
#define F first
#define S second
#define P pair
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define V vector
#define RE return
#define ALL(a) a.begin(),a.end()
#define MP make_pair
#define PB emplace_back
#define PF emplace_front
#define FILL(a,b) memset(a,b,sizeof(a))
#define lwb lower_bound
#define upb upper_bound
using namespace std;
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	string a,b;
	cin>>a>>b;
	if(a.size()==b.size()-1){
		string t=b.substr(0,a.size());
		if(t==a){
			cout<<"Yes\n";RE 0;
		}
	} 
	cout<<"No\n";
	RE 0;
}




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

typedef long long LL;

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(x) (x).begin(),(x).end()
const int IINF = 1e9;
const LL LINF = 1e18;
const LL mod = 1e9+7;

int main() {
    int N;
    string S;
    cin >> N;
    cin >> S;
    vector<int> w(N, 0);
    vector<int> e(N, 0);
    FOR(i, 1, N) {
        w[i] = w[i - 1] + (S[i - 1] == 'W');
    }
    for(int i = N - 2;0 <= i;i--) {
        e[i] = e[i + 1] + (S[i + 1] == 'E');
    }
    int res = IINF;
    REP(i, N) {
        res = min(res, w[i] + e[i]);
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 3076
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        String s = sc.next();

        String text = "";
        int max = s.length();
        for (int i=0; i<max; i++) {
            int c = s.charAt(i) + n;
            if (c > 'Z') c = 'A' + c - 'Z' - 1;
            System.out.print((char)c);
        }
        System.out.println("");
    }
}

Measured memory_bytes: 25300
#include<bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 1000000000000000
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
void init(){
  cin.tie(0);
  ios::sync_with_stdio(false);
}


int main(){
  string s;

  cin>>s;

  rep(i,s.size()){
    FOR(j,i+1,i+3){
      if(j==s.size()) continue;
      if(s[i]==s[j]){
        cout<<i+1<<' '<<j+1<<endl;
        return 0;
      }
    }
  }

  cout<<-1<<' '<<-1<<endl;
}


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

namespace A
{
    class Program
    {
        static void Main(string[] args)
        {
            var K = int.Parse(Console.ReadLine());
            var input = Console.ReadLine().Split(' ');
            var A = int.Parse(input[0]);
            var B = int.Parse(input[1]);


            for (int i = A; i <= B; i++)
            {
                if (i % K == 0)
                {
                    Console.WriteLine("OK");
                    return;
                }
            }
            Console.WriteLine("NG");
        }
    }
}


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

int main(){
    ll n;
    cin >> n;
    vector <ll> a(n),b(n),c(n),d(n);
    ll aa;
    ll ans=0;
    rep(i,n){
        cin >> b[i];
        a[i]=b[i]-(-2000000+i-1);
        c[i]=b[i]-(-2000000+i-1);
        d[i]=-2000000+i-1;
        //ans+=a[i];
    }

    sort(a.begin(),a.end());
    rep(i,n){
        d[i]+=a[n/2];
        ans+=abs(d[i]-b[i]);
    }

    cout << ans << endl;
    

    return 0;
}

Measured memory_bytes: 9424
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <numeric>
#include <string>

using namespace std;

int main() {
    int n, k;
    cin >> n >> k;
    
    vector<int> x(n), y(n);
    vector<char> c(n);
    
    for (int i = 0; i < n; i++) {
        cin >> x[i] >> y[i] >> c[i];
    }
    
    vector<vector<int>> b(4 * k, vector<int>(4 * k));
    vector<vector<int>> w(4 * k, vector<int>(4 * k));
    
    for (int i = 0; i < n; i++) {
        int xi = x[i] % (2 * k);
        int yi = y[i] % (2 * k);
        
        if (c[i] == 'B') {
            b[yi][xi]++;
            b[yi + 2 * k][xi]++;
            b[yi][xi + 2 * k]++;
            b[yi + 2 * k][xi + 2 * k]++;
        } else {
            w[yi][xi]++;
            w[yi + 2 * k][xi]++;
            w[yi][xi + 2 * k]++;
            w[yi + 2 * k][xi + 2 * k]++;
        }
    }
    
    for (int i = 0; i < 4 * k; i++) {
        for (int j = 0; j < 4 * k; j++) {
            
            if (i > 0) {
                b[i][j] += b[i - 1][j];
                w[i][j] += w[i - 1][j];
            }
            
            if (j > 0) {
                b[i][j] += b[i][j - 1];
                w[i][j] += w[i][j - 1];
            }
            
            if (i > 0 && j > 0) {
                b[i][j] -= b[i - 1][j - 1];   
                w[i][j] -= w[i - 1][j - 1];
            }
        }
    }
    
    auto get = [](const vector<vector<int>>& x, int i, int j, int k, int l) {
        int ret = 0;
        
        if (k > 0 && l > 0) {
            ret += x[k - 1][l - 1];   
        
            if (i > 0 && j > 0) {
                ret += x[i - 1][j - 1];   
            }
        
            if (i > 0) {
                ret -= x[i - 1][l - 1];   
            }
            
            if (j > 0) {
                ret -= x[k - 1][j - 1];
            }
        }
        
        return ret;
    };
    
    int ans = 0;
    
    for (int i = 0; i < 2 * k; i++) {
        for (int j = 0; j < 2 * k; j++) {
            int cur = 0;
            
            cur += get(b, i, j, i + k, j + k);
            cur += get(b, i + k, j + k, i + 2 * k, j + 2 * k);
            cur += get(w, i, j + k, i + k, j + 2 * k);
            cur += get(w, i + k, j, i + 2 * k, j + k);
            
            ans = max(ans, cur);
        }
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 126464
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>

using namespace std;
typedef long long ll;

int main() {
    int N; cin >> N;
    map<int, int> M;
    for(int i=0; i<N; i++){
        int a; cin >> a;
        M[a]++;
    }
    
    int e1 = 0;
    int e2 = 0;
    for(auto m:M){
        if(m.second>=2) e1 = max(e1, m.first);
    }
    
    for(auto m:M){
        if((m.second>=2 && m.first!=e1) || (m.second>=4 && m.first==e1)) e2 = max(e2, m.first);
    }

    cout << (ll)e1*e2 << endl;
    return 0;
}


Measured memory_bytes: 4992
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std; typedef long long ll; int an=0; const ll INF = 1e18; const ll MOD = 1e9+7;
typedef pair<int,int> P; const int xx[4]={1,-1,0,0}, yy[4]={0,0,1,-1}; struct tp{int x,y; ll cs;};
struct unf {
  vector<int> v; unf(int n){v.resize(n); for(int i=0;i<n;i++) v[i]=i;}
  int root(int x) { if (v[x]==x) return x; return v[x]=root(v[x]);}
  void unite(int x,int y) {int p=root(x), q=root(y); if (p==q) return; v[p]=q;}
  bool same(int x, int y) {return root(x)==root(y);}
  void print() {for(int x:v) cout<<x<<" "; cout<<endl;}
};

int main(){
  int n,m; cin>>n>>m; //if (m==0) return puts("0")*0;
  tp t[m]; for(int i=0;i<m;i++) cin>>t[i].x>>t[i].y>>t[i].cs;
  sort(t,t+m,[](tp a, tp b){return a.cs<b.cs;});

  unf u(n); ll an=0;
  for(int i=0;i<m;i++) {
    //cout<<t[i].x<<" "<<t[i].y<<" "<<t[i].cs<<endl;
    if (!u.same(t[i].x, t[i].y)) {an+=t[i].cs; u.unite(t[i].x, t[i].y);}
  }
  cout<<an<<endl;
}


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

using namespace std;

string findtest;

int main(void){
  
  while( getline( cin , findtest ) ){
    while( findtest.find("the") == findtest.npos && findtest.find("that") == findtest.npos && findtest.find("this") == findtest.npos ) {
      // ここでthe.that.thisが見つかるまで文字を１つずつ動かす
      //１つでも見つかればwhileを抜け出して出力
      for( int i = 0 ; i < findtest.size() ; i++ ){
	//このforで全ての文字を１つずらす
	if( 'a' <= findtest[i] && findtest[i] <= 'y' )findtest[i]++;
	else if( findtest[i] == 'z' ) findtest[i] = 'a';
      }
    }
    cout << findtest << endl;
  }
  return 0;
}

Measured memory_bytes: 1176
N, M = map(int, input().split())
DP = [0]*(N+2)
DP[0] = 1
A = []
for i in range(M):
    a = int(input())
    DP[a] = -1

mod = 1000000007

# print(N, M, A)

for i in range(N):
    if DP[i] == -1:
        continue
    if DP[i + 1] != -1:
        DP[i + 1] = (DP[i] + DP[i + 1]) % mod
    if DP[i + 2] != -1:
        DP[i + 2] = (DP[i] + DP[i + 2]) % mod
print(DP[N])


Measured memory_bytes: 44760
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>
#include <stdexcept>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define FOR(i, a, done) for (int i = (a); i < (done); ++i)
#define all(a) (a).begin(), (a).end()
#define x first
#define y second
#define debug(a) cout << (a) << endl
namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;
template <class T>
bool chmax(T &a, const T &b)
{
	if (a < b)
	{
		a = b;
		return 1;
	}
	return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
	if (a > b)
	{
		a = b;
		return 1;
	}
	return 0;
}

ll M = 1000000007;

void solve()
{
	mp::cpp_dec_float_100 a;
	mp::cpp_dec_float_100 b;
	cin>>a>>b;
	a*=b;
	//a=(cpp_int)a;
	a=mp::floor(a);
	string ans=a.str();
	cout<<ans<<endl;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	solve();
	return 0;
}


Measured memory_bytes: 3704
#include<bits/stdc++.h>
#define cs const
#define pb push_back
using namespace std;
cs int Mod = 998244353;
int add(int a, int b){ return a + b >= Mod ? a + b - Mod : a + b; }
int dec(int a, int b){ return a - b < 0 ? a - b + Mod : a - b; }
int mul(int a, int b){ return 1ll * a * b % Mod; }
void Add(int &a, int b){ a = add(a,b); }
void Dec(int &a, int b){ a = dec(a,b); }
void Mul(int &a, int b){ a = mul(a,b); }
cs int N = 2e5 + 50;
int n, a[N], f[N]; char S[N];
void chk(int len){
    if(len & 1) return; 
    static int b[N]; int ans = 0;
    for(int i = 1; i <= len / 2; i++) 
    b[i] = a[i], ans = add(mul(ans, 2), a[i]);
    for(int i = len / 2 + 1; i <= n; i++)
    b[i] = b[i - len / 2] ^ 1; 
    bool ok = 1;
    for(int i = 1; i <= n && ok; i++)
        if(a[i] < b[i]) ok = 0;
        else if(a[i] > b[i]) break;
    f[len] = add(ans, ok);
}
int main(){
    #ifdef FSYolanda
    freopen("1.in","r",stdin);
    #endif
    scanf("%d%s", &n, S+1);
    for(int i = 1; i <= n; i++)
        a[i] = S[i] - '0';
    int t = n + n;
    for(int i = 1; i <= t; i++)
        if(t % i == 0 && n % i) chk(i); 
    for(int i = 1; i <= t; i++) if(f[i])
        for(int j = i + i; j <= t; j += i)
            Dec(f[j], f[i]);
    int ans = 0;
    for(int i = 1; i <= t; i++) 
    if(t % i == 0 && n % i)
    Add(ans, mul(f[i], i)); 
    cout << ans; return 0;
  
}

Measured memory_bytes: 6188
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String str = sc.next();
		String str2 = sc.next();
		
		Integer count = 0;
		
		for(int i = 0; i < str.length(); i++) {
			if(str.charAt(i) != str2.charAt(i)) {
				count ++ ;
			}
		}
		System.out.println(count);
	}
}


Measured memory_bytes: 44232
#!/usr/bin/env python

from sys import stdin, stderr

def is_palindrome(S):
   return S == S[::-1]

def main():
   S = stdin.readline().strip()

   N = len(S)
   if is_palindrome(S) and is_palindrome(S[:N/2]) and is_palindrome(S[(N+1)/2:]):
      print('Yes')
   else:
      print('No')
   
   return 0

if __name__ == '__main__': main()


Measured memory_bytes: 2568
#include<iostream>
#include<cstdio>
using namespace std;
int Tsukasa[1000];  //parent
int Hizikata[1000]; //left-child
int Yuuma[1000];    //right-child  May Be Yuma
bool used[1000];
int counter=0,n,Pos;
bool finfin=false;

void Init(int n){
  for(int i=0;i<n;i++){
    Tsukasa[i]=-1;
    Hizikata[i]=-1;
    Yuuma[i]=-1;
    used[i]=false;
  }
}

int SRoot(int n){ // root search
  for(int i=0;i<n;i++)if(Tsukasa[i] == -1)return i;
  return -2;
}

void Print(int s){ // print s and count number of used node
  printf("%d",s);
  counter++;
  if(counter != n)printf(" ");
  used[s]=true;
}
void BInit(int n){ // init of array
  for(int i=0;i<n;i++){
    used[i] = false;
  }
}

int Pre(int s){ // Preorder
  if(s!= -1){
    Print(s);
    Pre(Hizikata[s]);
    Pre(Yuuma[s]);
  }
}


int In(int s){ // Inorder
  if(s != -1){
    In(Hizikata[s]);
    Print(s);
    In(Yuuma[s]);
  }
}

int Po(int s){ //Postorder
  if(s != -1){
    Po(Hizikata[s]);
    Po(Yuuma[s]);
    Print(s);
  }
}

int main(){ // most important function. perhaps we cannot take "accepted" without this.
  int id,lef,rig,rn;
 
  scanf("%d\n",&n);
 
  Init(n); 
  rn = n;
  while(rn-- > 0){
    scanf("%d %d %d\n",&id,&lef,&rig);
    Tsukasa[lef] = Tsukasa[rig] = id;
    Hizikata[id] = lef;
    Yuuma[id] = rig;
  }
  // Tsukasa-array is used to store datas about parent
  // if node doesnt have parent, it is -1
 
  printf("Preorder\n");
  counter=0;
  printf(" ");
  Pre(SRoot(n));
  printf("\n");

  BInit(n);
  counter=0;
  printf("Inorder\n");
  printf(" ");
  In(SRoot(n));
  printf("\n");

  BInit(n);
  counter=0;
  printf("Postorder\n");
  finfin=false;
  BInit(n);
  printf(" ");
  Po(SRoot(n));
  printf("\n");
  return 0;
}



Measured memory_bytes: 3208
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val xs: List<Int> = readLine()!!.split(" ").map(String::toInt)
    println(xs.map { count(it) }.min())
}

fun count(x: Int): Int {
    return if (x % 2 != 0) 0 else 1 + count(x / 2)
}

Measured memory_bytes: 37612
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
int main() {
  ll n;
  cin >> n;
  if(n % 2 == 0 || n % 5 == 0) {
    cout << -1 << endl;
  } else {
    ll m = 7 % n;
    ll ten = 10;
    ll cnt = 1;
    while(m != 0) {
      cnt++;
      m += ten * 7 % n;
      m %= n;
      ten *= 10;
      ten %= n;
    }
    cout << cnt << endl;
  }
  return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
  
using namespace std;
  
#define MAX_H 60
#define MAX_W 60
#define INF 1e9
  
int H,W,N,ix,iy,ox,oy;
bool wall[MAX_H][MAX_W][4],a[MAX_H][MAX_W][4];
const int dx[4] = {-1,0,1,0};
const int dy[4] = {0,-1,0,1};
  
struct P{
    int x,y;
    P(int x,int y) : x(x),y(y) {}
};
  
inline bool inField(int x,int y){
    return (0 <= x && x < W && 0 <= y && y < H);
}
  
int bfs(){
    int d[MAX_H][MAX_W];
    for(int i = 0 ; i < H ; i++){
	for(int j = 0 ; j < W ; j++){
	    d[i][j] = INF;
	}
    }
    d[iy][ix] = 0;
    queue<P> Q;
    Q.push(P(ix,iy));
    queue<int> step;
    step.push(0);
  
    while(!Q.empty()){
	P p = Q.front(); Q.pop();
	int s = step.front(); step.pop();
	int x = p.x, y = p.y;
	if(x == ox && y == oy) return d[oy][ox];
	for(int i = 0 ; i < 4 ; i++){
	    int nx = x + dx[i], ny = y + dy[i];
	    if(wall[y][x][i]) continue;
	    if(!inField(nx,ny)) continue;
	    if(d[y][x]+1 < d[ny][nx]){
		d[ny][nx] = d[y][x]+1;
		Q.push(P(nx,ny));
		step.push(s+1);
	    }
	}
    }
    return -1;
}
  
int main(){
    cin >> W >> H >> N;
    for(int i = 0 ; i < N ; i++){
	int sx,sy,dx,dy;
	cin >> sx >> sy >> dx >> dy;
	if(sx > dx) swap(sx,dx);
	if(sy > dy) swap(sy,dy);
	bool t = false,y = false;
	if(sx != dx) y = true;
	if(sy != dy) t = true;
	if(y){
	    for(int j = sx ; j < dx ; j++){
		for(int k = sy ; k <= dy ; k++){
		    if(k-1 >= 0){
			wall[k-1][j][3] = true;
			a[k-1][j][3] = true;
		    }
		    wall[k][j][1] = true;
		    a[k][j][1] = true;
		}
	    }
	}
	if(t){
	    for(int j = sx ; j <= dx ; j++){
		for(int k = sy ; k < dy ; k++){
		    if(j-1 >= 0){
			wall[k][j-1][2] = true;
			a[k][j-1][2] = true;
		    }
		    wall[k][j][0] = true;
		    a[k][j][0] = true;
		}
	    }
	}
    }
    int res = 0;
    cin >> ix >> iy >> ox >> oy;
    int dist = bfs();
    for(int x = 0 ; x <= W+1 ; x++){
	for(int y = 0 ; y <= H+1 ; y++){
	    int xx = x-1,yy = y;
	    if(xx >= 0) wall[yy][xx][2] = wall[y][x][0] = true;
	    res = max(res,bfs()-dist);
	    if(xx >= 0){
		wall[yy][xx][2] = a[yy][xx][2];
		wall[y][x][0] = a[y][x][0];
	    }
	}
    }
    for(int x = 0 ; x <= W+1 ; x++){
	for(int y = 0 ; y <= H+1 ; y++){
	    int xx = x,yy = y-1;
	    if(yy >= 0) wall[yy][xx][3] = wall[y][x][1] = true;
	    res = max(res,bfs()-dist);
	    if(yy >= 0){
		wall[yy][xx][3] = a[yy][xx][3];
		wall[y][x][1] = a[y][x][1];
	    }
	}
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3172
#include <bits/stdc++.h>
#define INF 1000000000
using namespace std;

int main() {

  int mindif=INF;
  string n; cin>>n;
  for(int i=0; i<n.size()-2;i++){
    int tmp,dif;
    tmp = stoi(n.substr(i,3));
  //  cout<<tmp<<endl;
    dif=max(tmp,753)-min(tmp,753);
    if(mindif>dif)mindif=dif;
  }
  cout<<mindif<<endl;

}



    

Measured memory_bytes: 256
n = int(input())
numList  = [int(input()) for _ in range(n)]
maxVal = max(numList)
workList = numList[:]
workList.remove(maxVal)
secondVal = max(workList)
for num in numList:
  if num != maxVal:
    print(maxVal)
  else:
    print(secondVal)

Measured memory_bytes: 70104
#include<bits/stdc++.h>
#include<cmath>
#pragma GCC optimize("Ofast")
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
typedef long long ll;
const ll MOD = 1e9+7;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(ll i=num, i##_len=(n); i<i##_len; ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};
#define print(x) (cout << (x) << endl)
#define pb push_back
#define mp make_pair
#define sz(x) int(x.size())
#define fs first
#define sc second


const int INF = 1e9;
const ll LLINF = 1e16;

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}
 
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
 
template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}
 
template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}
 
template<typename T>
T gcd(T a,T b){return b?gcd(b,a%b):a;}

template<typename T>
T ngcd(vector<T> a){
    T res;
    res = a[0];
    for(int i = 1; i < a.size() && res != 1; i++) {
        res = gcd(a[i], res);
    }
    return res;
}
 
template<typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

template<typename T>
T nlcm(vector<T> numbers) {
    T res;
    res = numbers[0];
    for (int i = 1; i < numbers.size(); i++) {
        res = lcm(res, numbers[i]);
    }
    return res;
}

// 割り算の切り上げ処理
template<typename T>
T round_up(T a, T b) {
  return (a + b - 1) / b;
}

// 約数列挙
template<typename T>
vector<T> calc_divisor(T n) {
   vector<T> res;
   for (T i = 1LL; i*i <= n; ++i) {
       if (n % i == 0) {
           res.push_back(i);
           T j = n / i;
           if (j != i) res.push_back(j);
       }
   }
   sort(res.begin(), res.end());
   return res;
}

// 素数判定
template<typename T>
bool isPrime(T x){
    T i;
    if(x < 2)return 0;
    else if(x == 2) return 1;
    if(x%2 == 0) return 0;
    for(i = 3; i*i <= x; i += 2) if(x%i == 0) return 0;
    return 1;
}

// 桁和
template<typename T>
T digsum(T n) {
    T res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

// 指定した文字cが文字列に何文字入ってるか
ll stringcount(string s, char c) {
    return count(s.cbegin(), s.cend(), c);
}


using pint = pair<int, int>;
using pll = pair<ll, ll>;

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




int main(void)
{
    cout.tie(0);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    int r;
    cin >> r;
    print(r * r);
}


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

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

	int size = S.length();

	int ans = 0;
	int current = 0;
	for (int i = 0; i < size; i++) {
		if (S[i] == 'A' || S[i] == 'T' || S[i] == 'G' || S[i] == 'C') {
			current++;
			if (i == size - 1) {
				if (ans < current) ans = current;
			}
		}
		else {
			if (ans < current) ans = current;
			current = 0;
		}
	}

	cout << ans;

	return 0;
}

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 erep(i, n) for (ll i = 0; i <= (ll)(n); ++i)
#define FOR(i,a,b) for (ll i = (a); i < (ll)(b); ++i)
#define EFOR(i,a,b) for (ll i = (a); i <= (ll)(b); ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } }

typedef pair<int, int> P;
ll modnum = 1e9+7;

struct UnionFind {
    // parで親のnode値と、サイズを同時に管理する。
    // 根ではないnodeのparは親となるnodeの値が入ってる
    // 根にはサイズ数が入っている。区別できるようにサイズはマイナスの値で入っている
    // そのため、初期値はすべて-1になる(mergeの際にmergeされる側の根に、mergeする方の根が加算される
    vector<int> par;

    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }

    int root(int x) {
        // 上記の通り,負の値ということは、根である
        if (par[x] < 0) return x;
        return par[x] = root(par[x]);
    }

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        // サイズが大きいほうにマージする
        // 以下は必ずxが大きいほう(サイズはマイナスの値が入ってるので)にするように調整している
        if (par[x] > par[y]) swap(x, y);
        // xのサイズに、yのサイズを加算する
        par[x] += par[y];
        // yの根をxに更新する
        par[y] = x;
        return true;
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }

    int size(int x) {
        return -par[root(x)];
    }
};

int main() {
    int n,m; cin >> n >> m;
    UnionFind tree(n);
    vector<int> x(m);
    vector<int> y(m);
    vector<int> z(m);

    rep(i, m) {
        int x,y,z; cin >> x >> y >> z;
        x--;
        y--;
        z--;
        tree.merge(x,y);
    }

    set<int> ans;
    rep(i, n) {
        ans.insert(tree.root(i));
    }

    cout << ans.size() << endl;

    return 0;
}

Measured memory_bytes: 6400
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= (b); i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <class T>
inline bool chmin(T& a, T b) {
   if (a > b) {
      a = b;
      return true;
   }
   return false;
}
template <class T>
inline bool chmax(T& a, T b) {
   if (a < b) {
      a = b;
      return true;
   }
   return false;
}
void hr() {
   cerr << "--------------" << endl;
}
const int INF = 1001001001;
const int MOD = 1000000007;

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

   int k;
   cin >> k;
   int a, b;
   cin >> a >> b;
   bool ok = false;
   rep(i, a, b + 1) {
      if (i % k == 0) ok = true;
   }
   if (ok)
      cout << "OK" << endl;
   else
      cout << "NG" << endl;
   return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
 
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef unsigned long long ull;
typedef long double ld; 
typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> pbds;

ll dp[111111][3];
ll a[111111][3];

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n; cin>>n;
	for(int i=1;i<=n;i++)
	{
		for(int j=0;j<3;j++) cin>>a[i][j];
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=0;j<3;j++)
		{
			for(int k=0;k<3;k++)
			{
				if(j!=k)
				{
					dp[i][j]=max(dp[i][j],dp[i-1][k]+a[i][j]);
				}
			}
		}
	}
	cout<<max(dp[n][0],max(dp[n][1],dp[n][2]))<<'\n';
}


Measured memory_bytes: 5248
#include <bits/stdc++.h>
using namespace std;
#define int long long 
#define f(i,x,n) for(int i=x;i<n;i++) 
#define all(c) c.begin(),c.end()
const int MOD = 1e9 + 7, N = 3e3 + 10;
const int LINF = LLONG_MAX;
double dp[N][N];
double C[N];
int n;
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout << setprecision(10) << fixed ;
    memset(dp,0,sizeof(dp));
    cin >> n;
    f(i,0,n){
        cin >> C[i];
    }
    dp[0][0] = 1;
    for(int i = 0;i < n;i++){
        for(int j = 0;j <= i;j++){
            dp[i+1][j+1] += dp[i][j]*C[i];
            dp[i+1][j] += dp[i][j]*(1 - C[i]);
        }
    }
    double ans = 0;
    for(int j = (n+1)/2;j <= n;j++){
        ans += dp[n][j];
    }
    cout << ans;
    return 0;
}
 

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

int v[maxn];
int nx[30];

int main() {
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
        scanf("%d",v+i);
    ll ans = 0;
    for(int i=0;i<30;i++)
        nx[i] = n-1;
    int t = n-1;
    for(int i=n-1;i>=0;i--){
        for(int j=0;j<30;j++)
            if(v[i] & (1<<j)){
                t = min(t,nx[j]);
                nx[j] = i-1;
            }
        ans += t-i+1;
    }
    printf("%lld\n",ans);
    
}

Measured memory_bytes: 1024
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cstdlib>
#include <functional>
#include <iostream>
#include <map>
#include <set>
#include <vector>
using namespace std;

#define REP(i, a, b) for(int i = (a); i < (int)(b); ++i)
#define rep(i, n) REP(i, 0, n)
#define ALL(x) begin(x), end(x)

struct point {
	int x, y, z;
	explicit point(int x_ = 0, int y_ = 0, int z_ = 0):x(x_), y(y_), z(z_) {}

	point operator+(const point &p) const {
		return point(x + p.x, y + p.y, z + p.z);
	}

	point operator-(const point &p) const {
		return point(x - p.x, y - p.y, z - p.z);
	}

	point operator-() const {
		return point(-x, -y, -z);
	}

	bool operator<(const point &p) const {
		if(x != p.x) return x < p.x;
		if(y != p.y) return y < p.y;
		return z < p.z;
	}

	bool operator==(const point &p) const {
		return x == p.x && y == p.y && z == p.z;
	}
};

struct segment {
	point a, b;
	segment(const point &a_, const point &b_):a(a_), b(b_) {
		if(b < a) swap(a, b);
	}

	bool operator<(const segment &s) const {
		if(!(a == s.a)) return a < s.a;
		return b < s.b;
	}

	bool operator==(const segment&s) const {
		return a == s.a && b == s.b;
	}
};

point rotate_x(const point &p) {
	return point(p.x, p.z, -p.y);
}

point rotate_y(const point &p) {
	return point(p.z, p.y, -p.x);
}

point rotate_z(const point &p) {
	return point(p.y, -p.x, p.z);
}

bool input(set<segment> &segs) {
	int n;
	cin >> n;

	if(n == 0) return false;
	segs.clear();

	point move_d[128];
	move_d['x'] = point(1, 0, 0);
	move_d['y'] = point(0, 1, 0);
	move_d['z'] = point(0, 0, 1);

	point current(0, 0, 0);
	map<int, point> label;

	rep(i, n) {
		string s;
		cin >> s;

		if(isdigit(s[0])) { // label
			const int idx = stoi(s);
			if(!label.count(idx)) {
				label[idx] = current;
			}
			else {
				current = label[idx];
			}
		}
		else { // move
			point d = move_d[s[1]];
			if(s[0] == '-') d = -d;
			const point next = current + d;
			segs.insert(segment(current, next));
			current = move(next);
		}
	}

	return true;
}

bool match(const set<segment> &a, const set<segment> &b) {
	if(a.size() != b.size()) return false;
	auto it_a = a.cbegin();
	auto it_b = b.cbegin();

	const point offset = a.cbegin()->a - b.cbegin()->a;

	while(it_a != a.end()) {
		const segment &s_a = *it_a;
		const segment s_b(it_b->a + offset, it_b->b + offset);
		if(!(s_a == s_b)) return false;

		++it_a;
		++it_b;
	}

	return true;

}

set<segment> rotate_points(const set<segment> &segs, const function<point(const point&)> &convert) {
	set<segment> res;
	for(const auto &seg : segs) {
		res.insert(segment(convert(seg.a), convert(seg.b)));
	}
	return res;
}

bool valid(const set<segment> &a, set<segment> b) {
	rep(loop_x, 4) {
		b = rotate_points(b, rotate_x);
		rep(loop_y, 4) {
			b = rotate_points(b, rotate_y);
			rep(loop_z, 4) {
				b = rotate_points(b, rotate_z);
				if(match(a, b)) return true;
			}
		}
	}

	return false;
}

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

	set<segment> a, b;
	while(input(a)) {
		assert(input(b));
		cout << (valid(a, b) ? "SAME" : "DIFFERENT") << endl;
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1264
n,x,d=gets.split.map(&:to_i)

if d == 0
  p (x == 0)? 1 : (n+1)
  exit
end

x,d = -x,-d if d < 0

list = Hash.new{|h,k|h[k]=[]}

(0..n).each{|nn|
  div,mod = (x*nn).divmod(d)
  top = nn*(nn-1)/2 + div
  bottom = nn*(n-1+n-nn)/2 + div
  list[mod].push([top,:start],[bottom+1,:end])
}

cnt = 0
list.each{|m,l|
  nest = 0
  start = 0
  l.sort.each{|i,type|
    case type
    when :start
      start = i if nest == 0
      nest += 1
    when :end
      nest -= 1
      cnt += i - start if nest == 0
    end
  }
}
p cnt


Measured memory_bytes: 58364
#include <bits/stdc++.h>
#define REP(i, N) for (int i = 0; i < (N); ++i)
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007
#define PB push_back
#define MP make_pair
using namespace std;
typedef long long ll;
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

//++時計回り --反時計回り
// int dx[4] = {1, 0, -1, 0};
// int dy[4] = {0, 1, 0, -1};

int main() {
  ll N;
  cin >> N;
  ll A[N];
  REP(i, N) cin >> A[i];
  ll x[N];
  x[0] = 0;
  REP(i, N) {
    if (i % 2 == 0)
      x[0] += A[i];
    else
      x[0] -= A[i];
  }
  for (int i = 1; i < N; i++) {
    x[i] = 2 * A[i - 1] - x[i - 1];
  }
  REP(i, N) {
    cout << x[i];
    if (i < N - 1)
      cout << ' ';
  }
  cout << '\n';
}


Measured memory_bytes: 2816
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def lcm(a,b):
    return a*b//gcd(a,b)
def main():
    A,B,C,D=MI()
    A-=1
    B_cnt = B-(B//C+B//D-B//lcm(C,D))
    A_cnt = A-(A//C+A//D-A//lcm(C,D))
    print(B_cnt-A_cnt)
if __name__ == '__main__':
    main()

Measured memory_bytes: 64748
#include<bits/stdc++.h>
using namespace std;
#define r(i,n) for(int i=1;i<=n;i++)
int main(){
  int z[9],sum=0;
  for(int i=0;i<9;i++)cin>>z[i];
  r(a,9)if(z[0]==-1||z[0]==a)
    r(b,9)if((z[1]==-1||z[1]==b)&&a!=b)
      r(c,9)if((z[2]==-1||z[2]==c)&&c!=b&&c!=a)
	r(d,9)if((z[3]==-1||z[3]==d)&&d!=a&&d!=b&&d!=c)
	  r(e,9)if((z[4]==-1||z[4]==e)&&e!=a&&e!=b&&e!=c&&e!=d)
	    r(f,9)if((z[5]==-1||z[5]==f)&&f!=a&&f!=b&&f!=c&&f!=d&&f!=e)
	      r(g,9)if((z[6]==-1||z[6]==g)&&g!=a&&g!=b&&g!=c&&g!=d&&g!=e&&g!=f)
		r(h,9)if((z[7]==-1||z[7]==h)&&h!=a&&h!=b&&h!=c&&h!=d&&h!=e&&h!=f&&h!=g)
			 r(i,9)if(z[8]==-1||z[8]==i){
			   int p[9];
			   p[0]=a;p[1]=b;p[2]=c;
			   p[3]=d;p[4]=e;p[5]=f;
			   p[6]=g;p[7]=h;p[8]=i;
			   sort(p,p+9);
			   if(p[0]!=p[1]&&p[1]!=p[2]&&p[2]!=p[3]&&p[3]!=p[4]&&p[4]!=p[5]&&p[5]!=p[6]&&p[6]!=p[7]&&p[7]!=p[8]){
			     if((a+c+f+b*10+e*10+d*100)==(g*100+h*10+i))sum++;
			   }
			 }
  cout<<sum<<endl;
}

Measured memory_bytes: 3160
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 100010;
ll a[N],b[N];
int n;
ll gcd(ll a,ll b){
	if(b==0) return a;
	return gcd(b,a%b);
}
int main(){
	ll ans = 0;
	scanf("%d",&n);
	for(int i=0;i<n;i++)  scanf("%d%d",&a[i],&b[i]);
	for(int i=n-1;i>=0;i--){
		a[i] += ans;
		if(a[i]%b[i]>0) ans  += b[i]-a[i]%b[i];
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <string>
#include <map>
using namespace std;


int main (int argc, char const *argv[])
{
    int A,B;
    string S,T,U;
    cin>>S>>T>>A>>B>>U;

    if(U==S){
        A--;
    }
    else{
        B--;
    }
    cout<<A<<" "<<B<<endl;
    return 0;
}

Measured memory_bytes: 256
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <queue>
# define MOD 1000000000+7
# define INF 1000000000
#define rep(i,rept)	for(ll i = 0; i<rept;i++)
typedef long long ll;
using namespace std;
vector<string>al;
int main()
{
	unsigned long long int a = 0, b = 0, c = 0,counter=0;
	char mo[10002][11];
	char mm;
	string str[10003];
	string mot,chars;
	cin >> a;
	mot = "          ";
	rep(i, a) {
		rep(j, 10) {
			cin >> mm;
			chars.push_back(mm);
		}
		sort(chars.begin(), chars.end());
		rep(k, 10) {
				mot[k] = chars[k];
		}
		al.push_back(mot);
		mot = "          ";
		chars.clear();
	}
	sort(al.begin(),al.end());
	rep(i, a) {
		vector<string>::iterator lit = lower_bound(al.begin(), al.end(), al[i]);
		vector<string>::iterator uit = upper_bound(al.begin(), al.end(), al[i]);
		counter+=uit - lit-1;
	}
	/*rep(i, al.size()) {
		cout << al[i] << endl;
	}*/
	cout << counter/2 << endl;
}


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

int main() {
  int N, K;
  scanf("%d%d", &N, &K);
  vector<int> a(N), dp(N);
  for (int &x : a) {
    scanf("%d", &x);
  }

  dp[0] = 0;
  fill(dp.begin() + 1, dp.end(), 2e9);
  for (int i = 0; i < N; ++i) {
    for (int j = 1; j <= K; ++j) {
      if (i + j < N) {
        dp[i + j] = min(dp[i + j], dp[i] + abs(a[i] - a[i + j]));
      }
    }
  }

  printf("%d\n", dp[N - 1]);
}

Measured memory_bytes: 1024