akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

int main( void ) {
	int n, a, v, win_a = 21, win_v = -1;

	scanf( "%d", &n );

	while ( n-- ) {
		scanf( "%d %d", &a, &v );

		if ( win_v < v ) {
			win_a = a;
			win_v = v;
		} else if ( win_v == v && a < win_a )
			win_a = a;
	}

	printf( "%d %d\n", win_a, win_v );

	return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
const ll MOD=10000000007;

int main() {
  string S;
  cin >> S;
  int s=S.size();
  bool ans=true;
  for (int i=0;i<s;i+=2){
    if (S[i]=='L'){
      ans=false;
    }
  }
  for (int i=1;i<s;i+=2){
    if (S[i]=='R'){
      ans=false;
    }
  }
  if (ans){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
H, W = map(int,input().split())

def side(h, W):
    Sa = W * h
    Sb = W * ((H-h)//2)
    Sc = W * ((H-h+1)//2)
    # print (Sa, Sb, Sc)
    return max(Sa, Sb, Sc) - min(Sa, Sb, Sc)

def vertical(h, W):
    Sa = W * h
    Sb = W//2 * (H-h)
    Sc = ((W+1)//2) * (H-h)
    # print (Sa, Sb, Sc)
    return max(Sa, Sb, Sc) - min(Sa, Sb, Sc)


def judge(H, W):
    ans = H * W
    for h in range(0, H):
        # print (side(h, W), vertical(h, W))
        ans = min(ans, side(h, W), vertical(h, W))
        # print (h, W, ans)
    return ans

tmp = judge(H, W)
H, W = W, H
tmp = min(tmp, judge(H, W))
print (tmp)


# print (judge(3, 5))

Measured memory_bytes: 3064
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int ans = 0;
        if(s.equals("SUN")) ans = 7;
        if(s.equals("MON")) ans = 6;
        if(s.equals("TUE")) ans = 5;
        if(s.equals("WED")) ans = 4;
        if(s.equals("THU")) ans = 3;
        if(s.equals("FRI")) ans = 2;
        if(s.equals("SAT")) ans = 1;

        System.out.println(ans);
        sc.close();

    }

}


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

#define ALL(a) (a).begin(),(a).end()
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define rrep(i,n) RFOR(i,n,0)
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define vint vector<int>
#define vdbl vector<double>
#define vstr vector<string>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

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

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

	if(a == b) {
		cout << 1 << endl;
		return 0;
	}

	ll t = 1LL << 60;
	while((a&t) == (b&t)) t >>= 1;

	ll m = t;
	a &= (t << 1) -1;
	b &= (t << 1) -1;

	while(m > 1 && (b & (m >> 1)) == 0) m >>= 1;
	
	ll ans = 0;
	if(m <= a){
		ans = t - a + t + m - a; 
	}else{
		ans = 2*t - a;
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
pow = [0 for _ in range(n)]
l, r = n-1, 0
while l >= 0:
    while (l+1) * 2**r < k:
        r += 1
    pow[l] = r
    l -= 1
ans = 0
for i in range(n):
    ans += 1/n * 0.5**pow[i]
print(ans)

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

int main(){
  int a,b,x,y,z;
  cin>>a>>b>>x>>y>>z;
  string c;
  cin>>c;
  for(int i=0;i<a-b;i++){
  if(c.at(i)==c.at(i+b)){
  c.at(i+b)='f';
  }
  }
  int sum=0;
  for(int j=0;j<a;j++){
  if(c.at(j)=='r'){
  sum+=z;
  }
  if(c.at(j)=='s'){
  sum+=x;
  }
  if(c.at(j)=='p'){
  sum+=y;
  }
  }
  cout<<sum<<endl;
}

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

#define NDEBUG
#include <cassert>


typedef long long ll;
typedef long double Double;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<long double> vD;

#define sz(a)  int((a).size())
#define pb  push_back
#define eb  emplace_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))
#define cons make_pair

#define PQ(T) priority_queue<T>
#define RPQ(T) priority_queue<T,vector<T>,greater<T>>

template<class T> inline void amin(T & a, T const & b) { a = min(a, b); }
template<class T> inline void amax(T & a, T const & b) { a = max(a, b); }

inline ll square(ll x) { return x * x; }
inline ll gcd(ll a, ll b) { while(a) swap(a, b%=a); return b; }
template <typename T>
inline T mod(T a, T b) { return ((a % b) + b) % b; }


const ll MOD=1000000007LL;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }

ll sub(ll N, int ga,int sa,int ba, int gb,int sb,int bb){
    if (gb < ga) gb = ga;
    if (sb < sa) sb = sa;
    if (bb < ba) bb = ba;

    vll dp(N+1, -1);
    dp[0] = 0;
    for (int i=0; i<=N; ++i) {
        if (dp[i] < 0) continue;
        if (i+ga <= N) amax(dp[i+ga], dp[i] + gb);
        if (i+sa <= N) amax(dp[i+sa], dp[i] + sb);
        if (i+ba <= N) amax(dp[i+ba], dp[i] + bb);
    }
    ll best = 0;
    for (int i=0; i<=N; ++i) {
        amax(best, dp[i] + (N-i));
    }
    return best;
}

ll solve(int N, int ga,int sa,int ba, int gb,int sb,int bb){
    ll m = sub(N, ga,sa,ba, gb,sb,bb);
    ll o = sub(m, gb,sb,bb, ga,sa,ba);
    return o;
}

int main() {
    int N; cin >> N;
    int ga,sa,ba; cin >> ga >> sa >> ba;
    int gb,sb,bb; cin >> gb >> sb >> bb;
    cout << solve(N, ga,sa,ba, gb,sb,bb) << endl;
    return 0;
}


Measured memory_bytes: 195584
#include "bits/stdc++.h"
using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define LL long long
int n;
int col[100000];

void dfs(int v,int c,vector<vector<int>> &g,vector<vector<int>> &w){
  if(col[v] >= 0)return;
  col[v]=c;
  REP(i,g[v].size()){
    dfs(g[v][i],(c+w[v][i])%2,g,w);
  }
}

int main(){
  cin>>n;
  vector<vector<int>> g(n),w(n);
  REP(i,n-1){
    int u,v;
    LL win;
    cin>>u>>v>>win;
    u--;v--;
    g[u].push_back(v);
    g[v].push_back(u);
    w[u].push_back((int)(win%2));
    w[v].push_back((int)(win%2));
  }
  REP(i,n)col[i]=-1;

  dfs(0,0,g,w);
  
  REP(i,n){
    cout<<col[i]<<endl;
  }
  return 0;
}


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



int main() {
    int N;
    cin>>N;
    string S;
    cin>>S;
    int ans=0;
    for(int i=1;i<N;i++){
        int count=0,now=0;
        rep(j,N-i){
            if(S.at(j)==S.at(j+i)){count++;}
            else{now=max(now,count);count=0;}
        }
        now=max(now,count);
        if(now>i){now=i;}
        ans=max(ans,now);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define all(in) in.begin(), in.end()
#define INF (sizeof(int) == 4 ? (int)1e9:(int)1e18)
#define EPS 0.0000000001
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
signed main(){
    int N; cin >> N;
    vector<string>grid(N);
    for(auto& s : grid) cin >> s;
    int ans = 0;
    for(int k = 0; k < grid.size(); ++k){
        bool res = true;
        auto cp = grid;
        rep(i,N)rep(j,N)cp[i][j] = grid[(i + k) % N][j];
        rep(i,N)rep(j,N)res = (res and cp[i][j] == cp[j][i]);
        ans += (res ? N : 0);
    }
    cout << ans << endl;
}


Measured memory_bytes: 512
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

struct UnionFind {
	vector<int> v;
	UnionFind(int n) : v(n)  { for (int i = 0; i < n; i++) v[i] = i; }
	int  find(int x)         { return v[x] == x ? x : v[x] = find(v[x]); }
	void unite(int x, int y) { v[find(x)] = find(y); }
};

int main() {
	int n, m;
	while (cin>>n>>m,n) {
		vi cb(m);
		REP(i, m)
			cin >> cb[i];
		vi os(n);
		REP(i, n)
			cin >> os[i];
		vi memo(256,1000000000);
		memo[128] = 0;
		REP(i, n) {
			vi copy(256, 1000000000);
			REP(j, 256) {
				if (memo[j] != 1000000000) {
					REP(k, m) {
						copy[min(255, max(0, j + cb[k]))] =min(copy[min(255, max(0, j + cb[k]))], memo[j] + (os[i] - min(255, max(0, j + cb[k])))*(os[i] - min(255, max(0, j + cb[k]))));
					}
				}
			}
			memo = copy;
		}
		int ans = 1e9;
		REP(i, 256)
			ans = min(ans, memo[i]);
		cout << ans << endl;
	}
}

Measured memory_bytes: 3240
function Main(arg)
{
  var N = arg.split("\n")[0] - 0;
  var A = arg.split("\n").slice(1, N+1);

  var ans = {};
  for (var i = 0; i < N; i++){
    ans[A[i]] = 0;
  }

  for (var i = 0; i < N; i++){
    ans[A[i]]++;
  }

  var max = 0;

  for(var key in ans) {
    if (max < ans[key]) {
      max = ans[key];
    }
  }

  var tmp = [];
  for(var key in ans) {
    if (max == ans[key]) {
      tmp.push(key);
    }
  }

  tmp.sort();

  console.log(tmp.join("\n"));

  return;
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 133420
#include "bits/stdc++.h"
#include<unordered_map>
#pragma warning(disable:4996)
using namespace std;

const int My_Inf=2147483647;
const long long int My_LInf=9223372036854775807;

int main() {
	while (1) {
		int T; cin >> T; if (!T)break;
		vector<int>sleeps;
		for (int i = 0; i < T; ++i) {
			int t; cin >> t;
			sleeps.push_back(t);
		}
		int N; cin >> N;
		vector<int>needtimes(100, 25);
		for (int i = 0; i < N; ++i) {
			int d, m; cin >> d >> m;
			d--;
			needtimes[d] = min(needtimes[d], m);
		}

		vector<vector<int>>dp(100 + 1, vector<int>(T, 999));
		dp[0][0] = 0;
		for (int i = 0; i < 100; ++i) {
			for (int j = 0; j < T; ++j) {
				if (needtimes[i] >= sleeps[j]) {
					dp[i + 1][(j + 1) % T] = min(dp[i][j], dp[i + 1][(j + 1) % T]);

				}
				dp[i + 1][1 % T] = min(dp[i + 1][1 % T], dp[i][j] + 1);
			}
		}
		int ans = 99999999;
		for (int i = 0; i < T; ++i) {
			ans = min(dp[100][i], ans);
		}
		cout << ans << endl;

	}
	
	return 0;
}

Measured memory_bytes: 3176
#include <stdio.h>

char P[10005][15];
int C[26], D[26];

int main() {
	int N, K; scanf("%d%d",&N,&K);
	for (int i = 1; i <= N; i++) {
		scanf("%s", P[i]);
		C[P[i][0]-'A']++;
	}
	int ans = 0;
	while (true) {
		for (int i = 0; i < 26; i++) {
			for (int j = i+1; j < 26; j++) {
				if (C[i] < C[j]) {
					int t = C[i];
					C[i] = C[j];
					C[j] = t;
				}
			}
		}
		bool fin = false;
		for (int i = 0; i < K; i++) {
			if (C[i] == 0) fin = true;
			else C[i]--;
		}
		if (fin) break;
		ans++;
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 256
#include<cstdio>
#include<vector>
#include<algorithm>
#define MN 2100001
using namespace std;

int n,m,a[MN],x,y; 
vector<int> v[MN];
long long g=0;
bool bo=1;
char s[100]="999999999999",c[10];
int main(){
	for (int i=0;i<=10;i++){
		int l=i==0,r=9,mid;
		while (l<r){
			mid=l+r>>1;
			s[i]=mid+'0';
			printf("? %s\n",s);
			fflush(stdout);
			scanf("%s",c);
			if (c[0]=='Y') r=mid;else l=mid+1;
		}
		if (l!=9) bo=0;
		g=g*10+l;
		printf("? %d\n",g+1);
		fflush(stdout);
		scanf("%s",c);
		if (bo){
			if (c[0]=='N') return printf("! %d\n",g),fflush(stdout),0;
		}else{
			if (c[0]=='Y') return printf("! %d\n",g),fflush(stdout),0;
		}
		s[i]=l+'0';
	}
}

Measured memory_bytes: 51796
from heapq import heappush, heappushpop
import sys
input = sys.stdin.readline

N = int(input())
a = list(map(int, input().split()))
first = [a[0]]
first_sum = [a[0]] + [0] * (3*N-1)
for i in range(1, 3*N):
    if i < N:
        first_sum[i] = first_sum[i-1] + a[i]
        heappush(first, a[i])
    else:
        first_sum[i] = first_sum[i-1] + a[i] - heappushpop(first, a[i])

second = [-a[-1]]
second_sum = [0] * (3*N-1) + [a[-1]]
for i in range(3*N-1)[::-1]:
    if i >= 2*N:
        second_sum[i] = second_sum[i+1] + a[i]
        heappush(second, -a[i])
    else:
        second_sum[i] = second_sum[i+1] + a[i] - (-heappushpop(second, -a[i]))
ans = max(first_sum[i] - second_sum[i+1] for i in range(N-1, 2*N))
print(ans)


Measured memory_bytes: 115232
#include <iostream>
#include<math.h>
#include<list>
#include <algorithm>
#include<set>
#include<vector>
#include<math.h>
#include<map>
#include<string>
using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;

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

#define in(x) cin >> x
#define out(x) cout << x
#define outn(x) cout << x << '\n'
#define outs(x) cout << x << ' '
#define rep(i,s,e) for(long i=s;i<e;i++)
#define repeq(i,s,e) for(long i=s;i<=e;i++)


int main() {
	string ans = "Yes";
	ll n;
	in(n);
	vll h(n);
	rep(i, 0, n) {
		in(h[i]);
	}

	reverse(h.begin(), h.end());

	rep(i, 0, n-1) {
		if (h[i] < h[i + 1]) {
			if (h[i + 1] - h[i] == 1) {
				h[i + 1]--;
			}
			else {
				ans = "No";
				break;
			}
		}
	}

	outn(ans);

	return 0;

}


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

int main(){
    int n;
    cin >> n;
    vector<int> array(n);
    for(int i=0;i<n;i++) cin >> array.at(i);
    int left = n+1,c=0;
    for(int i=0;i<n;i++){
        if(left > array.at(i)) {
            left = array.at(i);
            c++;
        }
    }
    cout << c << endl;
}

Measured memory_bytes: 4056
// inputに入力データ全体が入る
function Main(input) {
	var input = input.split(" ");
  	var num = parseInt(input[0],10);
  	var money = parseInt(input[1],10);
  	var result = "-1 -1 -1";

  	// 1000円札
  	loop:
  	for(var i=0; i<=num; i++){
      // 5000円札
      for(var j=0; j<=num; j++){
        if(i+j>num){
           continue;
        }
        // 10000円札
        sum = (10000*(num-j-i)) + (5000*j) + (1000*i);
        if(sum == money){
           result = `${num-i-j} ${j} ${i}`;
           //result = (num-j-i)+" "+j+" "+i;
           break loop;
        }
      }
    }
	//出力
	console.log(result);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

int main() {
  int n;
  cin >> n;
  if(n%1000%111 == 0){
    cout << "Yes" << endl;
  }
  else if(n/10%111 == 0){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }

}

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

int main(){
  
  while(1){
    stack<char>op;
    string str;
    bool ff=true;
    
    getline(cin,str);
    if(str == ".") break;

    for(int i=0;str[i]!='.';i++){
      if(str[i] == '(')
	{
	  op.push('(');
	}
      else if(str[i] == ')')
	{
	  if( op.empty() || op.top() != '(' ){
	    ff = false;
	    break;
	  }
	  op.pop();
	}
      else if(str[i] == '[')
	{
	  op.push('[');
	}
      else if(str[i] == ']')
	{
	  if( op.empty() || op.top() != '['){
	    ff = false;
	    break;
	  }
	  op.pop();
	}
    }

    if( op.empty() && ff ){
      cout << "yes" << endl;
    }
    else{
      cout << "no" << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 3160
N = int(input())
S = input()

cnt = 0
while cnt < 4:
    L = [0]*N
    if cnt == 0:
        L[-1] = "S"
        L[-2] = "S"
    elif cnt == 1:
        L[-1] = "S"
        L[-2] = "W"
    elif cnt == 2:
        L[-1] = "W"
        L[-2] = "S"
    else:
        L[-1] = "W"
        L[-2] = "W"

    for j in range(N-2, -1, -1):
        if L[j] == "S" and S[j] == "o":
            L[j-1] = L[j+1]
        elif L[j] == "S":
            if L[j+1] == "S":
                L[j-1] = "W"
            else:
                L[j-1] = "S"
        elif L[j] == "W" and S[j] == "o":
            if L[j+1] == "S":
                L[j-1] = "W"
            else:
                L[j-1] = "S"
        else:
            L[j-1] = L[j+1]
    if cnt <= 1 and L[-1] == "S" and S[-1] == "o":
        if L[-2] == L[0]:
            break
    elif cnt <= 1 and L[-1] == "S" and S[-1] == "x":
        if L[-2] != L[0]:
            break
    elif cnt >= 2 and L[-1] == "W" and S[-1] == "o":
        if L[-2] != L[0]:
            break
    elif cnt >= 2 and L[-1] == "W" and S[-1] == "x":
        if L[-2] == L[0]:
            break
    cnt += 1

if cnt == 4:
    print(-1)
else:
    print("".join(L))

Measured memory_bytes: 4852
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <string>
#include <cstdio>
#include <cmath>

using namespace std;

long long MOD = 1000000007;

int N;
long long Tmax[100005], Tmin[100005], Amax[100005], Amin[100005], tm = 0, am = 0;

int main() {

	cin >> N;

	for (int i = 0; i < N; i++) {
		cin >> Tmax[i];
		if (Tmax[i] > tm) {
			Tmin[i] = Tmax[i];
		}else{
			Tmin[i] = 0;
		}
		tm = max(tm, Tmax[i]);
	}

	for (int i = 0; i < N; i++) {
		cin >> Amax[i];
	}
	for (int i = N - 1; i >= 0; i--) {
		if (Amax[i] > am) {
			Amin[i] = Amax[i];
		}
		else {
			Amin[i] = 0;
		}
		am = max(am, Amax[i]);

	}


	long long ans = 1;
	for (int i = 1; i < N-1; i++) {

		if (min(Tmax[i], Amax[i]) - max(Tmin[i], Amin[i]) < 0) {
			ans = 0;
			break;
		}

		long long tmp = max((long long)1, min(Tmax[i], Amax[i]) - max(Tmin[i], Amin[i]));
		ans = ans * tmp % MOD;
	}

	sort(Amax, Amax + N);
	sort(Tmax, Tmax + N);
	if (Tmax[N-1] != Amax[N-1]) {
		ans = 0;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3456
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
typedef long long lng;
#define FOR(i,a,b) for(int i=(a); i<=(b); ++i)
#define FORD(i,b,a) for(int i=(b); i>=(a); --i)
#define REP(i,n) FOR(i,0,n-1)
#define ALL(a) (a).begin(), (a).end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end()) //ATTENTION: <a> must be sorted in advance

lng power(lng b, lng n) {lng sol=1; while(n>0) {if(n&1) {sol=sol*b;} n>>=1; b*= b;} return sol;} //calculate b^n

const int MOD = 1000000007; //10^9+7


/*********** variables ************/
int A,B,C,D;
/**********************************/

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> A >> B >> C >> D;

    cout << max(0, min(min(B-C, D-A), min(B-A, D-C))) << endl;
}


Measured memory_bytes: 256
#include<iostream>

class completeBinaryTree{
public:
  int node;
  int key;
  int parent;
  int left;
  int right;
  //check if there are
  //0=false; 1=true
  int checkP;
  int checkL;
  int checkR;
};

int main(){
  int H;
  std::cin>>H;
  int A[H];
  completeBinaryTree C[H];
  for(int i=0;i<H;i++){
    std::cin>>A[i];
    C[i].node=i+1;
    C[i].key=A[i];
  }
  for(int i=0;i<H;i++){
    if(i==0){
      C[i].checkP=0;
    }else{
      C[i].checkP=1;
      C[i].parent=C[(i+1)/2-1].key;
    }
    if((i+1)*2+1<=H){
      C[i].checkL=1;
      C[i].checkR=1;
      C[i].left=C[(i+1)*2-1].key;
      C[i].right=C[(i+1)*2].key;

    }else if((i+1)*2<=H){
      C[i].checkL=1;
      C[i].checkR=0;
      C[i].left=C[(i+1)*2-1].key;
    }else{
      C[i].checkL=0;
      C[i].checkR=0;
    }
  }
  for(int i=0;i<H;i++){
    std::cout<<"node "<<C[i].node<<": ";
    std::cout<<"key = "<<C[i].key<<", ";
    if(C[i].checkP)std::cout<<"parent key = "<<C[i].parent<<", ";
    if(C[i].checkL)std::cout<<"left key = "<<C[i].left<<", ";
    if(C[i].checkR)std::cout<<"right key = "<<C[i].right<<", ";
    std::cout<<std::endl;
  }
}



Measured memory_bytes: 3088
#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i=a; i<n; i++)
#define RREP(i, a, n) for(ll i=n-1; i>=a; i--)
typedef long long ll;
const ll mod =1e9+7;
const ll inf =1e18;
using namespace std;

ll n, m, l, q;
ll d[303][303]; // 2点間の最短距離
void warshall_floyd(){
    // l以下の2点間の最短距離
    REP(k, 0, n){
        REP(i, 0, n){
            if(d[i][k] > l) continue;

            REP(j, 0, n){
                if(d[k][j] > l) continue;

                d[i][j]=min(d[i][j], d[i][k]+d[k][j]);
            }
        }
    }

    // 距離1の辺を張る
    REP(i, 0, n){
        REP(j, 0, n){
            if(d[i][j] <= l) d[i][j]=1;
            else d[i][j]=inf;
        }
    }

    // 燃料補給回数の最小値
    REP(k, 0, n){
        REP(i, 0, n){
            if(d[i][k] == inf) continue;

            REP(j, 0, n){
                if(d[k][j] == inf) continue;

                d[i][j]=min(d[i][j], d[i][k]+d[k][j]);
            }
        }
    }
}
int main() {
    cin>>n>>m>>l;
    REP(i, 0, n){
        REP(j, 0, n){
            if(i!=j) d[i][j]=inf;
        }
    }
    REP(i, 0, m){
        ll a, b, c;
        cin>>a>>b>>c;

        if(c>l) continue;

        a--;
        b--;
        d[a][b]=c;
        d[b][a]=c;
    }

    warshall_floyd();

    cin>>q;
    REP(i, 0, q){
        ll s, t;
        cin>>s>>t;

        s--;
        t--;
        if(d[s][t] == inf) cout<<-1<<endl;
        else cout<<d[s][t]-1<<endl;
    }
    return 0;
}

Measured memory_bytes: 1280
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <cstring>
#include <vector>
using namespace std;

#define REP(i,a,n) for(int i=(a); i<(int)(n); ++i)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define DEB 0

map<string, int> ms;

int parse(string in){
#if DEB
  cout << "parse: " << in << endl;
#endif
  
  int ret = 0;
  for(int i=in.size()-1; i>=0;){
    if( '0'<=in[i] && in[i]<='9' ){
      int d = 0;
      int k = 1;
      for(;'0'<=in[i] && in[i]<='9';i--){
        d += (in[i]-'0')*k;
        k *= 10;
      }
      // a(cde)11
      // 01i34p
      if( in[i]==')' ){
        int p = i;
        int x = 0;
        for(;;i--){
          if( in[i]==')' )x++;
          if( in[i]=='(' )x--;
          if( x==0 ) break;
        }
        int t = parse(in.substr(i+1,p-(i+1)));
        if( t==-1 ) return -1;
        ret += t*d;
        i--;
#if DEB
        printf("num: ret: %d\n",ret);
#endif
      }else{ // 1 atomic
        string tmp;
        if( 'a'<=in[i] && in[i]<='z' ){
          tmp = in.substr(i-1,2);
          i-=2;
        }else{
          tmp = string(1,in[i]);
          i--;
        }
        if( ms.count(tmp)==0 ) return -1;
        ret += ms[tmp] * d;
#if DEB
        printf("num: ret: %d\n",ret);
#endif        
      }
      
    }else{
      string s;
      if( 'a'<=in[i] && in[i]<='z' ){
        s = in.substr(i-1,2);
        i-=2;
      }else{
        s = string(1,in[i]);
        i--;
      }
      if( ms.count(s)==0 ) return -1;
      ret += ms[s];
#if DEB
      printf("char: ret: %d\n",ret);
#endif      
    }
  }
#if DEB
  printf("  ret:%d\n",ret);
#endif
  return ret;
}

int main(){
  string in;
  // atomic table
  while(cin>>in,in!="END_OF_FIRST_PART"){
    int d; cin>>d;
    ms[in]=d;
  }
  // input seq
  while(cin>>in,in!="0"){
    int d = parse(in);
    if( d==-1 ){
      puts("UNKNOWN");
    }else{
      printf("%d\n",d);
    }
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
  int n,d;
  cin >> n >> d;
  int ans=0;
  vector<vector<int>> x(n,vector<int>(d));
  for(int i=0;i<n;i++){
    for(int j=0;j<d;j++){
      cin >> x.at(i).at(j);
    }
  }
  
  for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++){
      int sum=0;
      for(int k=0;k<d;k++){
        sum += (x.at(i).at(k)-x.at(j).at(k))*(x.at(i).at(k)-x.at(j).at(k));
      }
      double s;
      s=sqrt(sum);
      if(s==(int)s) ans++;
    }
  }
  
  cout << ans << endl;
  return 0;
      
}


Measured memory_bytes: 256
N = int(input())
S = str(input())
 
alpha = lambda c:ord(c) - ord('A') + 1
num2alpha = lambda c: chr(c+64)

answer = ''
for i in S:
  num = alpha(i) + N
  if num >= 27:
    num -= 26
  answer += num2alpha(num)

print(answer)

Measured memory_bytes: 3060
import java.util.*;
 
public class Main {
	public static void main (String[] args) {
		Scanner in = new Scanner(System.in);
		
		 int nam = in.nextInt();
		 
		String s = in.next();
		char[] s_chars = s.toCharArray();
		
		String t = in.next();
		char[] t_chars = t.toCharArray();
		
		for(int i = 0;i < nam; i++){
		    System.out.print(s_chars[i]);
		    System.out.print(t_chars[i]);
		}


      
	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define D(x) cout << #x << "=" << x << endl
#define De(...)
using namespace std; 

int _; 

int n,ans[10050];
 
int main()
{
	//for(scanf("%d",&_);_;_--)
	scanf("%d",&n);
	for(int i=0;i<n;i++)
		ans[i]=0;
	for(int x=1;x*x <= n;x++)
		for(int y=1;y*x <= n;y++)
			for(int z=1;z*x+y*x <= n;z++)
				if(x*x+y*y+z*z+x*y+x*z+y*z <= n) 
					ans[x*x+y*y+z*z+x*y+x*z+y*z]++;
	for(int i=0;i<n;i++)
		printf("%d\n",ans[i+1]);
	return 0;
}


Measured memory_bytes: 3788
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int inputValue(){
    int a;
    cin >> a;
    return a;
};

void inputArray(int * p, int a){
    REP(i, a){
        cin >> p[i];
    }
};

void inputVector(vector<int> * p, int a){
    REP(i, a){
        int input;
        cin >> input;
        p -> push_back(input);
    }
}

int main()
{
    int N = inputValue();
    int K = inputValue();
    int p[200000];
    double ans = 0;
    double E = 0;
    REP(i, N){
        p[i] = inputValue();
        E += 0.5 + p[i] * 0.5;
        if(i >= K){
            E -= 0.5 + p[i-K] * 0.5;
        }
        ans = max(ans, E);
    }
    cout << std::setprecision(8) << ans << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = int64_t;
using P = pair<ll, ll>;
template <class T>
using V = vector<T>;

int main() {
  int n;
  cin >> n;
  V<ll> a(n);
  rep(i, n) cin >> a[i];
  map<ll, int> m;
  rep(i, n) m[a[i]]++;

  if (m.size() == 1 && m[0] == n) {
    cout << "Yes" << endl;
    return 0;
  }

  if (n % 3 != 0) {
    cout << "No" << endl;
    return 0;
  }

  V<P> p;
  for (auto e : m) p.push_back({e.first, e.second});
  sort(p.begin(), p.end());

  bool ans = true;
  if (p.size() == 1) {
    ans = p[0].first == 0;
  } else if (p.size() == 2) {
    if (p[0].first == 0 || p[1].first == 0) {
      ans = p[0].second == n / 3 || p[1].second == n / 3;
    } else {
      ans = false;
    }
  } else if (m.size() == 3) {
    for (auto e : m) {
      if (e.second != n / 3) ans = false;
    }
    ll sum = p[0].first ^ p[1].first;
    sum ^= p[2].first;
    if (sum != 0) ans = false;
  } else {
    ans = false;
  }

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


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

#define rep(i, n) REP(i, 0, n)
#define REP(i,k,n) for(int i = k; i < n; i++)
#define mmax(start, end) *max_element(start, end)
#define mmin(start, end) *min_element(start, end)
#define argmax max_element
#define argmin min_element
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
typedef pair<int, int> prii;

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

template<class T = ll> T in() {
    T _in;
    cin >> _in;
    return _in;
}

const int n9[6] = {1, 9, 81, 729, 6561, 59049};
const int n6[7] = {1, 6, 36, 216, 1296, 7776, 46656};
const int n69[13] = {0, 1, 6, 9, 36, 81, 216, 729, 1296, 6561, 7776, 46656, 59049};

int dp[100002][13];

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

    int N;
    cin >> N;
    int ans = 0;

    REP(i, 1, N+1) {
        dp[i][1] = i; // 1円 x N回
        REP(j, 2, 13) {
            dp[i][j] = dp[i][j-1];
            if (i >= n69[j]) {
                dp[i][j] = min(dp[i][j-1], dp[i-n69[j]][j]+1);
            }
        }
    }

    // for(int i=11; i>-1; i--) {
    //     if(N >= n69[i]) {
    //         ans += N / n69[i];
    //         N = N % n69[i];
    //     }
    // }

    // rep(i, N+1) {
    //     rep(j, 13) {
    //         cout << dp[i][j] << " ";
    //     } cout << endl;
    // }

    cout << dp[N][12] << endl;

    return 0;
}


Measured memory_bytes: 5376
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 5LL << 60;
const ll mod = 1e9 + 7;

int main() {
	int N, Q;
	cin >> N >> Q;
	string S;
	cin >> S;

	int AC[N];
	AC[0] = 0;
	for(int i = 1; i < N; i++) {
		AC[i] = AC[i - 1];
		if(S[i - 1] == 'A' && S[i] == 'C') AC[i]++;
	}

	for(int i = 0; i < Q; i++) {
		int l, r;
		cin >> l >> r;
		l--;
		r--;
		cout << AC[r] - AC[l] << "\n";
	}
	return 0;
}


Measured memory_bytes: 4160
# encoding: "utf-8"

class Unreachable(Exception):
    pass


class SetManager:
    def __init__(self, n):
        self.data = list()
        for i in range(n):
            self.data.append((i, {i}))

    def ref(self, i):
        return self.data[i][1]

    def set(self, i, value):
        self.data[i] = (i, value)

    def find_set(self, i):
        value = self.ref(i)
        if isinstance(value, set):
            return self.data[i]
        elif isinstance(value, int):
            result = self.find_set(value)
            self.set(i, result[0])
            return result
        else:
            raise Unreachable

    def run(self, command):
        com, x, y = command
        if com == 0:
            # unite
            i, setx = self.find_set(x)
            j, sety = self.find_set(y)
            if i != j:
                new_set = setx | sety
                self.set(i, new_set)
                self.set(j, i)

        elif com == 1:
            # same
            if y in self.find_set(x)[1]:
                print(1)
            else:
                print(0)
        else:
            raise Unreachable

def main():
    n, q = [int(x) for x in input().split()]
    manager = SetManager(n)

    commands = list()
    for _ in range(q):
        com, x, y = [int(x) for x in input().split()]
        commands.append((com, x, y))
    
    for command in commands:
        manager.run(command)


if __name__ == "__main__":
    main()

Measured memory_bytes: 26800
#include <stdio.h>
#include <iostream>
#include <sstream>
#include <vector>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <set>
#include <algorithm>
#include <math.h>
using namespace std;
using i64 = int64_t;
#define rep(i, n) for(int i=0;i<n;++i)
#define rep2(i, x, n) for(int i=x;i<n;++i)

int main()
{   
    int m;
    cin >> m;
    cout << 48-m << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

void insertSort(int* a, int n) {
    // ソートする前
    for (int i = 0; i < n - 1; i++)
        cout << a[i] << " ";
    cout << a[n - 1] << "\n";

    for (int i = 1; i < n; i++) {
        int v = a[i];
        int j = i - 1;

        while ( (j >= 0) && (a[j] > v) ) {
            a[j + 1] = a[j];
            j--;
        }
        a[j + 1] = v;

        for (int i = 0; i < n - 1; i++)
            cout << a[i] << " ";
        cout << a[n - 1] << "\n";
    }
}

int main() {
    int N;

    cin >> N;
    int* a = new int[N];

    for (int i = 0; i < N; i++)
        cin >> a[i];

    insertSort(a, N);

    return (0);
}


Measured memory_bytes: 3092
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<map>
#include<algorithm>
#include<set>
#include <stdexcept>
#include<queue>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
typedef long long ll;
typedef pair<ll,int> P;
int ceil(int a,int b){// a以上bの倍数の最小値//
     return (a+b-1)/b*b;
 }
int stoii(string s){//stoi関数の代用 文字列⇒int型//
    return atoi(s.c_str());
}

char maze[51][51];
int n,m;
int sx,sy,gx,gy;
int dx[]={1,0,-1,0},dy[]={0,1,0,-1};
int d[51][51];
int bfs(){
	queue<P> que;
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			d[i][j]=inf;
		}
	}
	que.push(P(sx,sy));
	d[sx][sy]=0;

	while(que.size()){
		P p=que.front();
		que.pop();
		if(p.first==gx && p.second==gy) break;
		for(int i=0;i<4;i++){
			int nx=p.first+dx[i],ny=p.second+dy[i];

			if(0<=nx && nx<n && 0<=ny && ny<m && maze[nx][ny]!='#'&&d[nx][ny]==inf){
				que.push(P(nx,ny));
				d[nx][ny]=d[p.first][p.second]+1;
			}
		}
	}
	return d[gx][gy];
}
int main(){	
	string s,t;
	cin>>s>>t;
	string c;
	for(int i=s.size()-1;i>=0;i--){
		int start=i;
		int start2=0;
		rep(j,s.size()){
			if(start2+start>=s.size()) start2=-start;
			if(t[j]!=s[start2+start]) break;
			if(j==s.size()-1) {
				cout<<"Yes"<<endl;
				return 0;
			}
			start2++;
		}
	}
	cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  
  int n;
  while(1){
    cin >>n;
    if(n == -1)break;
    int ans=0;
    if(n <= 10){
      ans = 1150;
    }
    else if(n/10 == 1 || n==20 ){
      ans = 1150 + (n-10)*125;
    }
    else if(n/10 == 2 || n==30){
      ans = 1150 + 10*125 + (n-20)*140;
    }
    else{
      ans = 1150 + 10*125 + 10 *140 + (n-30)*160;
    }
    cout << 4280-ans << endl;
    
  }
    return 0;
}

Measured memory_bytes: 1160
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>


using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;

#define REP(i,n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i,a,b) for(int i = (a); i < (int)(b); ++i)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(v) ((int)v.size())

#define pb push_back
#define mp make_pair
#define mt make_tuple


map<ll, int> getFactorsMap(ll N){
    map<ll, int> ret;
    while(!(N % 2)){
        N /= 2;
        ++ret[2];
    }
    for (ll p = 3; p*p <= N; p += 2) {
        while (N % p == 0) {
            N /= p;
            ++ret[p];
        }
    }
    if (N > 1) ++ret[N];
    return ret;
}

ll solve(ll A, ll B) {
    auto m1 = getFactorsMap(A);
    auto m2 = getFactorsMap(B);

    set<ll> s1;
    set<ll> s2;
    for(auto kv: m1) s1.insert(kv.first);
    for(auto kv: m2) s2.insert(kv.first);

    // cout << "factor1:";
    // for(auto e: s1) cout << e << " ";
    // cout << endl;
    // cout << "factor2:";
    // for(auto e: s2) cout << e << " ";
    // cout << endl;

    set<int> intersect;
    set_intersection(s1.begin(),s1.end(),s2.begin(),s2.end(),
                     std::inserter(intersect,intersect.begin()));
    return SIZE(intersect) + 1;
}



int main(void)
{
    cin.sync_with_stdio(false);
    ll A, B;
    cin >> A >> B;

    auto ans = solve(A, B);
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SZ(x) ((int)(x).size())
typedef long long ll;
using namespace std;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cout.setf(ios::fixed); cout.precision(20);
    int a, b; cin >> a >> b;
    cout << max({2 * a - 1, 2 * b - 1, a + b}) << "\n";
}


Measured memory_bytes: 256
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
typedef long long LL;

LL f(LL n) {
  switch (n%4) {
    case 0:
      return n;  // 0 ^ 1 ^ .. n-1 ^ n -> (1^1)^(1^1)^...^(1^1)^n = n
    case 1:
      return 1;  // 0 ^ 1 ^ .. n-1 ^ n -> (1^1)^(1^1)^...^(1^1)^((n-1)^n} = 1
    case 2:
      return n^1;  // 0 ^ 1 ^ .. n-1 ^ n -> (1^1)^(1^1)^...^1^n} = 1^n
    case 3:
      return 0;  // 0 ^ 1 ^ .. n-1 ^ n -> (1^1)^(1^1)^...^(1^1) = 0
  }
}

int main() {
  LL A, B; std::cin >> A >> B;
  std::cout << (f(A-1)^f(B)) << std::endl;
}


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

#define rep(i, N) for (int i = 0; i < N; i++)
#define pb push_back
typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<ll, ll> ll_ll;
const int MOD = 998244353;
const int INF = INT_MAX / 2;
struct edge { int i, v, w; };

vector<int> gcd(vector<int> s, vector<int> t) {
	int N = s.size(), M = t.size();
	if (N < M) return gcd(t, s);
	if (!M) return s;
	rep(j, M) s[j] ^= t[j];
	int l = N;
	rep(i, N) if (s[i]) {
		l = min(l, i);
		break;
	}
	vector<int> a(N - l);
	rep(i, N - l) a[i] = s[l + i];
	return gcd(t, a);
}

int pow_mod(ll x, ll n, int M) {
	ll ans = 1;
	for (; n; n >>= 1) {
		if (n & 1) ans = ans * x % M;
		x = x * x % M;
	}
	return ans;
}

int main() {
	int N; cin >> N;
	string s; cin >> s;
	vector<string> a(N);
	rep(i, N) cin >> a[i];
	vector<int> d;
	rep(i, N) {
		int M = a[i].length();
		vector<int> b(M);
		rep(j, M) b[j] = a[i][j] - '0';
		d = gcd(d, b);
	}
	int n = s.length();
	vector<int> c(n), _c(n);
	rep(i, n) c[i] = s[i] - '0';
	int m = d.size();
	int ans = 0;
	for (int i = 0; i + m <= n; i++) {
		if (c[i]) ans = (ans + pow_mod(2, n - m - i, MOD)) % MOD;
		if (c[i] == _c[i]) continue;
		rep(j, m) _c[i + j] ^= d[j];
	}
	bool ok = true;
	if (_c > c) ok = false;
	if (ok) ans = (ans + 1) % MOD;
	cout << ans << endl;
}


Measured memory_bytes: 113024
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
long long gcd(int a,int b){
	return b == 0 ? a : gcd(b,a % b);
}
int main(){
	int a,b;
	scanf("%d%d",&a,&b);
	long long x = gcd(a,b);
	long long ans = a/x*b;
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ll long long int
const int INF = 2147483647;

using namespace std;

int main()
{
  int h, w;
  int row[100][100] = {};
  int col[100][100] = {};
  cin >> h >> w;
  vector<string> m(h);
  REP(i, h)
  {
    cin >> m[i];
  }

  REP(i, h)
  {
    REP(j, w)
    {
      if (m[i][j] == '#')
      {
        REP(r, w)
        {
          row[i][r] = 1;
        }
        REP(c, h)
        {
          col[c][j] = 1;
        }
      }
    }
  }

  REP(i, h)
  {
    bool update = false;
    REP(j, w)
    {

      if (row[i][j] == 1 && col[i][j] == 1)
      {
        update = true;
        cout << m[i][j];
      }
    }
    if (update)
    {
      cout << endl;
    }
  }
}


Measured memory_bytes: 384
/* Aditya0412 */
#include <bits/stdc++.h>
using namespace std; 
typedef long long int ll;
#define pb push_back 
#define ve vector
#define vii vector < int >
#define vll vector < ll > 
#define pii pair < int , int >
#define pll pair < ll , ll >
#define vpl vector < pll >
#define fi first
#define all(a)      (a).begin(),(a).end()
#define si(x)       (int)((x).size())
#define debug(x)    cout<<#x<<" is "<<(x)<<endl;cout.flush();  
#define se second 
#define endl        '\n'
#define f(i,a,b)    for(int i=a;i<b;i++)
#define mem(a,x)          memset(a,x,sizeof(a))

// === Debug macro starts here ===

int recur_depth = 0;
#ifdef DEBUG
#define dbg(x) {++recur_depth; auto x_=x; --recur_depth; cerr<<string(recur_depth, '\t')<<"\e[91m"<<__func__<<":"<<__LINE__<<"\t"<<#x<<" = "<<x_<<"\e[39m"<<endl;}
#else
#define dbg(x)
#endif
template<typename Ostream, typename Cont>
typename enable_if<is_same<Ostream,ostream>::value, Ostream&>::type operator<<(Ostream& os,  const Cont& v){
    os<<"[";
    for(auto& x:v){os<<x<<", ";}
    return os<<"]";
}
template<typename Ostream, typename ...Ts>
Ostream& operator<<(Ostream& os,  const pair<Ts...>& p){
    return os<<"{"<<p.first<<", "<<p.second<<"}";
}

// === Debug macro ends here ===


// const ll mod=998244353;
const ll mod = 1000000000+7;
const ll N=1000000+6;
#define M_PI           3.14159265358979323846
void inp(ll *arr,ll n)
{
  for(int i=0;i<n;i++)
    cin>>arr[i];
}
void inp_mat(ll *arr,ll n,ll m)
{
    for(int i=0;i<n;i++)
      for(int j=0;j<m;j++)
        {
          ll x;cin>>x;
          *((arr+i*m) + j)=x;
        }
}
// syntax for inp_mat inp_mat((ll *)arr,n,m);
// int x2[]={+1,-1,+0,+0};
// int y2[]={+0,+0,+1,-1};
int main() 
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //  #ifndef ONLINE_JUDGEc
    //   freopen ("INPUT.txt" , "r" , stdin);
    //   freopen ("OUTPUT.txt", "w" , stdout);
    // #endif 
    int t=1;
    // cin>>t;
    while(t--)
    {
         ll n;cin>>n;ll arr[n];inp(arr,n);
      ll x=0;
      f(i,2,n)
      x^=arr[i];
      if((arr[0]+arr[1]-x)%2!=0)
      cout<<"-1";
      else{
        ll y=(arr[0]+arr[1]-x)/2;
        dbg(y);
        if(y>arr[0] or y<0)
        cout<<"-1";
        else{
          ll ind=60;
          
          while(ind>=0)
          {
            dbg((ll)1<<ind);
            if((x&((ll)1<<ind))!=0)
            {
              if((y& ((ll)1 <<ind))!=0)
              {
                cout<<"-1";
                return 0;
              }
              if(((ll)1<<ind)+y<=arr[0])
              {
                y+=((ll)1<<ind);
              }
              
              
              
            }
            
            
            ind--;

          }
          dbg(y);
          if(y==0)
          cout<<"-1";
          else
          cout<<arr[0]-y;
        }
      }

    }    
} 

Measured memory_bytes: 3672
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
	int n,a[10000],i;
	long long max=-1000000,min=1000000,sum=0;
	cin>>n;
	for(i=0;i<n;i++){
	cin>>a[i];
	sum+=a[i];
	if(max<a[i]){
	max=a[i];
	}if(min>a[i]){
	min=a[i];
	}
	}
	cout<<min<<" "<<max<<" "<<sum<<endl;
	return 0;

}

Measured memory_bytes: 3112
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/* 
 * File:   main.cpp
 * Author: baisganon
 *
 * Created on 2017/06/04, 19:09
 */

#include<iostream>
using namespace std;

int count = 0;

void bubbleSort(int A[],int n){
	bool flag = true;
	while(flag){
		flag = 0;
		for(int j=n-1;j>0;j--){
			if(A[j]<A[j-1]){
				int tmp = A[j];
				A[j] = A[j-1];
				A[j-1] = tmp;
				flag = 1;
				count++;
			}
		}
	}
	return;
}

int main(){
	int size;
	cin >> size;
	int S[size];
	for(int i=0;i<size;i++){
		cin >> S[i];
	}

	bubbleSort(S,size);

	for(int i=0;i<size;i++){
		cout<<S[i]<<((i==size-1)?"":" ");
	}
	cout << endl << count << endl;
        int xxx;
        cin >> xxx;
	return 0; 
}

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

#define rep(i, n) for(int i=0; i < n; i++)
#define reps(i, n) for(int i=1; i <= n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()

using namespace std;
using ll=long long;

int main(){
	int N;
	cin >> N;
	vector<tuple<string,int,int>> list;
	rep(i,N){
		string s;
		int x;
		cin >> s >> x;
		list.push_back(make_tuple(s,-x,i+1));
	}

	sort(ALL(list));

	for(auto t : list)cout << get<2>(t)<<'\n';
}

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

int main(){

   string S;
   int K;
    cin >> K >> S;

    int num = S.size() - K;

    if(num <= 0){
        cout << S << endl;
    }else{
        cout <<  S.substr(0,K) <<  "..." << endl;
    }

}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  string t,p;
  cin>>t>>p;
  for(int i=0;i<((int)t.size())-((int)p.size())+1;i++){
    if(t.substr(i,p.size())==p) cout<<i<<endl;
  }
  return 0;
}

Measured memory_bytes: 3184
import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner cin = new Scanner(System.in);
        PrintWriter cout = new PrintWriter(System.out);

        int a = cin.nextInt();
        int b = cin.nextInt();

        cout.println(a < b * 2 ? 0 : a - (b * 2));

        cout.close();
    }
}

Measured memory_bytes: 23124
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

using ll = long long;



int main() {
    int n;
    scanf("%d", &n);
    // dp[heads]
    // if we had i tosses, then tails=i-heads
    vector<double> dp(n + 1);
    // dp[i] - p-bility that there are i heads so far
    dp[0] = 1;
    for(int coin = 0; coin < n; ++coin) {
        double p_heads;
        scanf("%lf", &p_heads);
        for(int i = coin + 1; i >= 0; --i) {
            dp[i] = (i == 0 ? 0 : dp[i-1] * p_heads) + dp[i] * (1 - p_heads);
        }
    }
    double answer = 0;
    for(int heads = 0; heads <= n; ++heads) {
        int tails = n - heads;
        if(heads > tails) {
            answer += dp[heads];
        }
    }
    printf("%.10lf\n", answer);
}


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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

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

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; }

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

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

  string S;
  cin >> S;
  vector<int> a(26);
  for(int i = 0; i < 26; i++){
    a[i] = 0;
  }
  for(int i = 0; i < S.length(); i++){
    a[S[i]-'a'] = 1;
  }

  int cnt = 0;
  for(int i = 0; i < 26; i++){
    cnt += a[i];
  }

  if(cnt == S.length()){
    cout << "yes" << endl;
  }else{
    cout << "no" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#define rep(i, a, n) for(int i = a;i < n;++i)
#define repe(i, a, n) for(int i = a;i <= n;++i)
#define repr(i, a, n) for(int i = a;i > n;--i)
#define reper(i, a, n) for(int i = a;i >= n;--i)
using namespace std;


int main(){
	int A, B, C, D;
	cin >> A >> B >> C >> D;

	int ans = min(A+C, A+D);
	ans = min(ans, B+C);
	ans = min(ans, B+D);

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256