akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
using namespace std;
typedef pair<int, int> P;
int main(void){
    int k, x, y;
    int cx = 1, cy = 1;
    int s, z, v, h;
    vector<P> ans;
    cin >> k >> x >> y;
    if(x < 0){
        x = -x;
        cx = -1;
    }
    if(y < 0){
        y = -y;
        cy = -1;
    }
    z = x + y;
    v = k-z%k;
    if(k%2 == 0 && z%2 == 1){
        cout << -1 << endl;
        return 0;
    }

    if(z%k == 0){
        while(x >= k){
            ans.push_back(P(k, 0));
            x -= k;
        }
        if(x > 0){
            ans.push_back(P(x, k-x));
            y -= k-x;
        }
        while(y > 0){
            ans.push_back(P(0, k));
            y -= k;
        }
    }else{
        h = 0;
        if(v%2 == 1)v += k;
        v /= 2;
        //cout << x << " " << v << " " << k << endl;
        if(y+v < k){
            if((z+v*2)/k == 1){
                if(k%2 == 0){
                    v += k/2;
                    if(x > y){
                        h = v;
                        v = 0;
                    }
                }else{
                    h += k;
                }
            }else if((z+v*2)/k == 2){
                h = v;
                v = 0;
            }
        }
        while(h > 0){
            if(h >= k){
                ans.push_back(P(0, -k));
                y += k;
                h -= k;
            }else{
                ans.push_back(P(k-h, -h));
                x -= k-h;
                y += h;
                h -= h;
            }
        }
        while(x + v > 0){
            if(x + v >= k){
                ans.push_back(P(k, 0));
                x -= k;
            }else{
                ans.push_back(P(x + v, k-(x+v)));
                y -= k - (x+v);
                x -= x+v;
            }
        }
        while(y > 0){
            if(y >= k){
                ans.push_back(P(0, k));
                y -= k;
            }else{
                ans.push_back(P(-k+y, y));
                x += k-y;
                y -= y;
            }
        }
        while(x < 0){
            ans.push_back(P(-k, 0));
            x += k;
        }
    }

    s = ans.size();
    cout << s << endl;
    x = y = 0;
    for(int i=0;i<s;i++){
        x += cx * ans[i].first;
        y += cy * ans[i].second;
        cout << x << " " << y << endl;
    }
}


Measured memory_bytes: 3952
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;


int main() {
  string S, T;
  cin >> S >> T;
  S += T.back();
  if (S == T) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  
  return 0;
}

Measured memory_bytes: 3628
n=int(input())
h=list(map(int,input().split()))
INF=10**5
dp=[INF for i in range(n)]
dp[0]=0
dp[1]=abs(h[1]-h[0])
for i in range(n-2):
    dp[i+2]=min(dp[i+1]+abs(h[i+2]-h[i+1]),dp[i]+abs(h[i+2]-h[i]))
print(dp[n-1])

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


class Program
{
    static void Main(string[] args)
    {
        string s = Console.ReadLine();
        int N = int.Parse(s);
        int i = 2;
        while(N >= i)
        {
            i *= 2;
        }

        Console.WriteLine((i / 2).ToString());
    }
}

Measured memory_bytes: 11092
def merge_sort(left, right):
    if right-left > 1:
        mid = (left + right) // 2
        merge_sort(left, mid)
        merge_sort(mid, right)
        merge(left, mid, right)

def merge(left, mid, right):
    left_part = S[left:mid]
    right_part = S[mid:right]
    left_part.append(inf)
    right_part.append(inf)
    l, r = 0, 0
    for i in range(left, right):
        if left_part[l] < right_part[r]:
            S[i] = left_part[l]
            l += 1
        else:
            S[i] = right_part[r]
            r += 1
    num[0] += right-left

if __name__ == "__main__":
    num = [0]
    inf = float('inf')
    n = int(input())
    S = list(map(int, input().split()))
    merge_sort(0, n)
    print(' '.join(list(map(str, S))))
    print(num[0])


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

int main() {
    vector<int> s(3);
    for (int i = 0; i < 3;i++) {
        cin >> s.at(i);
    }
    int max = s.at(0);

    for (int i = 0; i < 3; i++) {
        if (max <= s.at(i)) {
            max = s.at(i);
        }
        }

  
    if (max == s.at(0)) {
        cout << s.at(1) + s.at(2) << endl;
    }
    else if (max == s.at(1)) {
        cout << s.at(0) + s.at(2) << endl;
    }
    else {
        cout << s.at(0) + s.at(1) << endl;
    }           
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
using ll = long long;

const ll none = 0;
const ll A = 1;
const ll G = 2;
const ll C = 3;
const ll T = 4;
const ll mod = (ll)(1e9) + 7;

ll n;
ll dp[5][5][5][5][105];

ll solve(ll c1, ll c2, ll c3, ll c4, ll pos);

int main() {
    for (int i = 0; i < 5; i++) {
        for (int ii = 0; ii < 5; ii++) {
            for (int iii = 0; iii < 5; iii++) {
                for (int iiii = 0; iiii < 5; iiii++) {
                    for (int j = 0; j < 105; j++) {
                        dp[i][ii][iii][iiii][j] = -1;
                    }
                }
            }
        }
    }
    
    cin >> n;

    cout << solve(0, 0, 0, 0, 0) << endl;

    return 0;
}

ll solve(ll c1, ll c2, ll c3, ll c4, ll pos) {
    if (dp[c1][c2][c3][c4][pos] != -1) return dp[c1][c2][c3][c4][pos];

    if (c2 == A && c3 == G && c4 == C) return 0;
    if (c1 == A && c2 == G && c4 == C) return 0;
    if (c1 == A && c3 == G && c4 == C) return 0;

    if (c2 == A && c3 == C && c4 == G) return 0;
    if (c2 == G && c3 == A && c4 == C) return 0;

    if (pos == n) return 1;

    ll ret = 0;
    for (int i = A; i <= T; i++) {
        ret += solve(c2, c3, c4, i, pos + 1);
        ret %= mod;
    }

    return dp[c1][c2][c3][c4][pos] = ret;
}


Measured memory_bytes: 768
#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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

int main(){
  int N;
  cin >> N;
  if(N<1000) {
    cout << "ABC" << endl;
  }
  else {
    cout << "ABD" << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <algorithm>
#include <functional>
#include <string>
#include <utility>
#include <cstdio>
#include <cmath>
#include <deque>

#define REP(i,n) for(int i = 0; i < (n); ++i)
#define REP1(i,n) for(int i = 1; i <= (n); ++i)
#define RREP(i, n) for(int i = (n) - 1; i >= 0; --i)
#define ALL(a) begin(a), end(a)
#define MP(a,b) make_pair((a), (b))
#define ROUNDUP(a,b) ((a) / (b) + ((a) % (b) == 0 ? 0 : 1))
#define X first
#define Y second
#define DEBUG(a) cout << #a << ": " << a << "\n"
// #define DEBUG(a) {}

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

constexpr int MOD = 1e9 + 7;
constexpr int INF = 1e9 + 1;
constexpr ll LLINF = 4 * 1e18 + 1;
// constexpr int INF = 2147483647; // 2 * 1e9
// constexpr ll LLINF = 9223372036854775807; // 9 * 1e18

template<typename T>
T debug(T x) {
	DEBUG(x);
	return x;
}

int a, b, c, d;

// 0->+ 1->-
int calc(int op1, int op2, int op3){
	int ans = a;
	if(op1 == 0) ans += b;
	else ans -= b;
	if(op2 == 0) ans += c;
	else ans -= c;
	if(op3 == 0) ans += d;
	else ans -= d;
	return ans;
}

char co(int n){
	return n == 0 ? '+' : '-';
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	string s;
	cin >> s;
	a = s[0] - '0';
	b = s[1] - '0';
	c = s[2] - '0';
	d = s[3] - '0';
	REP(i, 2){
		REP(j, 2){
			REP(k, 2){
				if(calc(i, j, k) == 7){
					cout << a << co(i) << b << co(j) << c << co(k) << d << "=7";
					return 0;
				}
			}
		}
	}
	return 0;
}


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

signed main() {
  int N, A, B;
  cin >> N >> A >> B;
  
  if( (B-A) % 2 == 1 ){
    cout << "Borys" << endl;
  }else{
    cout << "Alice" << endl;
  }
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

int main(){
    fastio;
    long long n,k;
    cin >> n >> k;
    if(n>=k){n%=k;}
    cout << min(n,k-n) << "\n";
    return 0;
}


Measured memory_bytes: 3644
n = int(input())
a = list(map(int, input().split()))

ans = 0
xor1 = a[0]
sum1 = a[0]
right = 1

for left in range(n):
    while right < n and (a[right] + sum1 == a[right] ^ xor1):
        sum1 += a[right]
        xor1 ^= a[right]
        right += 1
    ans += right - left
    if right == left: right += 1
    else:
        sum1 -= a[left]
        xor1 = xor1 ^ a[left]

print(ans)

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

public class Main {

	public static void main(String[] args) throws IOException {

		try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))){

			final String inputLine = br.readLine();
			final String[] inputNumbers = inputLine.split(" ");

			final Integer a = Integer.valueOf(inputNumbers[0]);
			final Integer b = Integer.valueOf(inputNumbers[1]);
			final Integer c = Integer.valueOf(inputNumbers[2]);

			if(a < b && b < c) {
				System.out.println("Yes");
			} else {
				System.out.println("No");
			}
		}

	}

}


Measured memory_bytes: 24400
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long int ll;
#define rep(i,n) for(int i=0;i<(int)n;i++)
int Min(int a, int b, int c) {
	if (a <= b) { return std::min(a, c); }
	else return std::min(b, c);
}
int main(void) {
	double a, b;
	cin >> a >> b;
	cout << a / b << endl;
	return 0;
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const ll INF = 1e9;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

int main() {
  int n;
  cin >> n;
  vector<ll> a(n), l(n + 1), r(n + 1);

  rep(i, n) cin >> a[i];

  for (int i = 0; i < n; ++i) l[i + 1] = gcd(l[i], a[i]);
  for (int i = n - 1; i >= 0; --i) r[i] = gcd(r[i + 1], a[i]);

  ll res = 0;
  for (int i = 0; i < n; ++i) {
    ll L = l[i];
    ll R = r[i + 1];
    res = max(res, gcd(L, R));
  }

  cout << res << endl;
  return 0;
}


Measured memory_bytes: 2560
# -*- coding: utf-8 -*-
 
import sys
 
debug = False
 
def log(text):
    if debug:
        print(text)
 
def parse_input(lines_as_string = None):
 
    global debug
    lines = []
    if lines_as_string is None:
        debug = False
        lines.append(input())
    else:
        debug = True
        lines = [e for e in lines_as_string.split("\n")][1:-1]
 
    token = lines[0].split()
    a = int(token[0])
    b = int(token[1])
 
    return (a, b)
 
 
def solve(a, b):
  
    if b == 1:
        return 0

    result = -1
    for n in range(1, 20):
        if a + (n-1)*(a-1) >= b:
            result = n
            break
        
 
    return result
 
 
def main():
    # 出力
 
    print("%s" % solve(*parse_input()))
 
if __name__ == '__main__':
 
    main()

Measured memory_bytes: 3064
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const int inf = 999999999;
const double pi = acos(-1);

#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}

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

int main(){
	int a[3];
	cin >> a[0] >> a[1] >> a[2];
	sort(a,a+3);
	if(a[0] + a[1]  == a[2] || a[0] == a[1]+ a[2])cout <<"Yes"<<endl;
	else cout << "No" << endl; 
	
	return 0;
}

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

#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int main() {
	cin.sync_with_stdio(false); cin.tie(0);
	cin.exceptions(cin.failbit);

	int n, m; cin >> n >> m;

	vector<int> v(m);
	rep(i, 0, m) cin >> v[i];
	sort(all(v));

	vector<int> diff(m - 1);
	rep(i, 0, m - 1) diff[i] = v[i + 1] - v[i];
	sort(all(diff));

	int ans = v.back() - v.front();
	rep(i, 1, n) if (diff.size()) { ans -= diff.back(); diff.pop_back(); }
	cout << ans << endl;
}


Measured memory_bytes: 1024
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author alireza_kaviani
 */

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;

#define all(x)                      (x).begin(),(x).end()
#define Sort(x)                     sort(all((x)))
#define X                           first
#define Y                           second
#define Mp                          make_pair
#define sep                         ' '
#define endl                        '\n'
#define debug(x)                    cerr << #x << " = " << x << endl
#define SZ(x)                       ll(x.size())
#define fast_io                     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define set_random                  mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

ll poww(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));
}

set_random;

const ll MAXN = 1e6 + 10;
const ll INF = 8e18;
const ll MOD = 1e9 + 7; // 998244353; // 1e9 + 9;

ll n , l , diff = INF , ans;

int main() {
    fast_io;

    cin >> n >> l;
    for(ll i = 0 ; i < n ; i++){
        ll d = abs(l * (n - 1) + n * (n - 1) / 2 - i - l * n - (n) * (n - 1) / 2);
        if(d < diff){
            diff = d;
            ans = l * (n - 1) + n * (n - 1) / 2 - i;
        }
    }
    cout << ans << endl;

    return 0;
}
/*

*/


Measured memory_bytes: 256
n,m = map(int,input().split())
stu,kyo = [],[]
for i in range(n):
    stu.append(list(map(int,input().split())))
for i in range(m):
    kyo.append(list(map(int,input().split())))
for i in range(n):
    ans = []
    for j in range(m):
        ans.append(abs(stu[i][0]-kyo[j][0])+abs(stu[i][1]-kyo[j][1]))
    print(1+ans.index(min(ans)))

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

// GNU C Compiler
//template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

// type
using ll = int_fast64_t;
using ull = uint_fast64_t;
using LL = long long;
using ULL = unsigned long long;
using PII = pair<int, int>;
//using pair<T1, T2> = p12;

//container
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())
#define ALL(v) v.begin(),v.end()

//repetition
#define REP(n) for(int i=0; i<(n); i++)
#define REPj(n) for(int j=0; j<(n); j++)
#define REPinit(i,a,n) for(int i=(a); i<(n); i++)
#define REPinitj(j,a,n) for(int j=(a); j<(n); j++)

//algorithm
//#define SORT(c) sort((c).begin(),(c).end())

//constant

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//Optimizer
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

/*
    add utility Algorithm
*/


int main(int argc, char const* argv[])
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int N, M;
    cin >> N >> M;


    string ans(N, '0');
    vector<bool> editflg(N, false);

    int digit;
    char tmp;

    //cout << "DEBUG " << ans << endl;

    REPinit(i, 0, M) {
        cin >> digit;
        cin >> tmp;
        if (!editflg[digit - 1] || ans[digit - 1] == tmp) {
            ans[digit - 1] = tmp;
            editflg[digit - 1] = true;
        }
        else
        {
            cout << "-1" << endl;
            return 0;
        }
    }

    if (ans[0] == '0' && ans.size() > 1) {
        if (!editflg[0]) {
            ans[0] = '1';
            cout << ans << endl;
        }
        else {
            cout << "-1" << endl;
        }
    }
    else {
        cout << ans << endl;
    }


    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef pair<int,int> pint;
typedef pair<long long, long long> pll;

#define MP make_pair
#define PB push_back
#define ALL(s) (s).begin(),(s).end()
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P) 
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P) 
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P) 
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s; }




const int MOD = 100000;
void add(int &a, int b) { a += b; if (a >= MOD) a -= MOD; }

int dp[110][110][2][2];    // 0:from i, 1:from j



int main() {
    memset(dp, 0, sizeof(dp));
    dp[0][0][0][1] = dp[0][0][1][0] = 1;
    
    for (int i = 0; i <= 100; ++i) {
        for (int j = 0; j <= 100; ++j) {
            
            // from 0, 0
            add(dp[i+1][j][0][0], dp[i][j][0][0]);
            add(dp[i][j+1][1][0], dp[i][j][0][0]);
            
            // from 0, 1
            add(dp[i+1][j][0][0], dp[i][j][0][1]);
            
            // from 1, 0
            add(dp[i][j+1][1][1], dp[i][j][1][0]);
            
            // from 1, 1
            add(dp[i+1][j][0][1], dp[i][j][1][1]);
            add(dp[i][j+1][1][1], dp[i][j][1][1]);            
        }
    }
    
    int w, h;
    while (cin >> w >> h) {
        if (w == 0) break;
        
        --w; --h;
        int res = 0;
        for (int i = 0; i < 2; ++i) for (int j = 0; j < 2; ++j) add(res, dp[w][h][i][j]);
        cout << res << endl;
    }
        
    return 0;
}


Measured memory_bytes: 1356
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>

using namespace std;

const int MOD = int(1e9) + 7;

char S[100500];
int P[100500];

int nxt[100500][3];
int ways[100500];

int main()
{
	int Test=1; while (Test--){
    scanf("%s", S+1);
    int N = strlen(S+1);

    // 1. XYXYXY.. 또는 YXYXYX.. 꼴이면 답 무조건 1
    bool is_alternating = true;
    for(int i = 1; i <= N; i++) {
      if(S[i] == S[i-1]) {
        is_alternating = false;
      }
    }
    if(is_alternating) {
      puts("1");
      continue;
    }

    int prv[3] = {0, -1, -1};
    for(int i = 1; i <= N; i++) {
      P[i] = (P[i-1] + "12"[S[i] - 'a'] - '0') % 3;
      for(int j = prv[P[i]]+1; j <= i; j++) {
        nxt[j][P[i]] = i;
      }
      prv[P[i]] = i;
    }

    for(int p = 0; p < 3; p++) {
      for(int j = prv[p]+1; j <= N; j++) {
        nxt[j][p] = N+1;
      }
    }

    for(int i = 0; i <= N; i++) ways[i] = 0;
    ways[0] = 1;
    for(int i = 0; i <= N; i++) {
      for(int p = 0; p < 3; p++) {
        if(p != P[i]) (ways[nxt[i][p]] += ways[i]) %= MOD;
      }
    }

    int ans = 0;
    for(int i = 1; i <= N; i++) {
      if((P[N] - P[i] + 3) % 3 == 0) {
        (ans += ways[i]) %= MOD;
      }
    }

    printf("%d\n", ans);
	}

	return 0;
}

Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define ALL(x) (x).begin(), (x).end()
#define REP(i ,n) for(int i = 0; i < (int)(n); i++)
#define pb push_back
typedef vector<int>vint;
typedef vector<ll>vll;
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename A,typename B>inline bool chmin(A &a,const B &b){if(a>b){a=b;return true;}else{return false;}}
template<typename A,typename B>inline bool chmax(A &a,const B &b){if(a<b){a=b;return true;}else{return false;}}

int main()
{
    int N;
    cin >> N;
    vector<string> S(N);
    cin >> S;
    vector<map<char,int>> cnt(N);
    REP(i,N)REP(j,26)cnt[i][(char)('a'+j)] = 0;
    REP(i,N){
        for(auto s:S[i]){
            cnt[i][s]++;
        }
    }
    string ans = "";
    REP(i,26){
        int num = 100;
        REP(j,N){
            chmin(num,cnt[j][(char)('a'+i)]);
        }
        REP(j,num){
            ans = ans + (char)('a'+i);
        }
    }
    cout << ans << endl;
}

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

using namespace std;

#define sqr(x) ((x) * (x))
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()

typedef vector<int> vi;
typedef map<int, int> mi;
typedef pair<int, int> pi;
typedef long long ll;

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

void solve() {
  string s;
  int ans = 100;
  cin >> s;
  for (int i = 0; i < s.size(); i++) {
    string tmp = s;
    while (check(tmp)) {
      for (int j = 0; j < tmp.size() - 1; j++) {
        if (tmp[j + 1] == s[i]) {
          tmp[j] = s[i];
        }
      }
      tmp.pop_back();
    }
    ans = min(ans, (int)(s.size() - tmp.size()));
  }
  cout << ans << endl;
}

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

  solve();

  return 0;
}

Measured memory_bytes: 256
from itertools import accumulate


def resolve():
    N, K = map(int, input().split())
    S = input()

    # even:1
    # odd:0
    # 1-0-1-0-1 の配列にする. 両端は1にする
    L = []
    pre = "1"
    cnt = 0
    for i in range(N):
        if pre == S[i]:
            cnt += 1
        else:
            L.append(cnt)
            cnt = 1
        pre = S[i]
    L.append(cnt)
    # 最後が0で終わっていたら、仮の1を付け足す。(値が0なので影響ない)
    if pre == "0":
        L.append(0)

    # 1-0-1-0-1の配列を作成し、K＝2だとする。
    # 0を2個含めた個数は, 1＝3、0＝2の長さが作成できる
    length = 2 * K + 1

    # 0をすべて変換できる
    if len(L) <= length:
        return print(N)

    acc = [0] + list(accumulate(L))
    ans = 0
    # 1-0-1-0-1の配列なので間に0を含んだ数え上げ
    # なので偶数とびに1を起点に数え上げ 
    for i in range(0, len(L) - length + 1, 2):
        ans = max(ans, acc[i + length] - acc[i])

    print(ans)


if __name__ == "__main__":
    resolve()


Measured memory_bytes: 14592
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
typedef pair<ll,ll> ii;
typedef vector<ii> vii;
#define all(v) v.begin(), v.end()
#define rep(i, from, to) for (ll i = from; i < ll(to); ++i)

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

    ll n;
    cin>>n;
    vi a(n);
    vi b(n);
    ll sa = 0;
    ll sb=0;
    rep(i,0,n) {
        cin>>a[i];
        sa+=a[i];
    }
    rep(i,0,n){
        cin>>b[i];
        sb+=b[i];
    }
    ll x=sb-sa;
    if(x<0){
        cout<<"No"<<endl;
        return 0;
    }
    ll tws = 0;
    rep(i,0,n){
        if(a[i]<b[i]){
            if(a[i]%2!=b[i]%2){
                b[i]++;
            }
            tws+=(b[i]-a[i])/2;
        }
    }
    if(tws<=x){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
        




    return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include <numeric>
#include<queue>
#include<climits>


#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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
//#define INF LLONG_MAX / 2;
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
typedef long long int ll;
typedef pair<ll,int> LL_IP;

const ll INF = LLONG_MAX;

#define ARRAY_MAX 100005
#define INF 1e9+7


int main(){

    ll N,K;
    cin >> N >> K;
    vector<ll> x(N),y(N),xarr,yarr;
    REP(i,N){
        cin >> x[i] >> y[i];
        xarr.push_back(x[i]);
        yarr.push_back(y[i]);
    }
    VSORT(xarr);
    VSORT(yarr);

    ll ans = (xarr[N-1]-xarr[0]) * (yarr[N-1]-yarr[0]);

    for(int lx = 0; lx < N;lx++){

        for(int rx = lx+1;rx < N;rx++){

            for(int oy = 0;oy < N;oy++){

                for(int uy = oy+1;uy < N;uy++){

                    ll num = 0;
                    ll le_x = xarr[lx];
                    ll ri_x = xarr[rx];
                    ll ov_y = yarr[oy];
                    ll un_y = yarr[uy];

                    for (int i = 0; i < N; i++){
                        if(le_x <= x[i] && x[i] <= ri_x && ov_y <= y[i] && y[i] <= un_y){
                            num++;
                        }
                    }
                    if(num >= K){
                        ans = min(ans,(ri_x-le_x) * (un_y-ov_y));
                    }
                }
            }
        }
    }
    cout << ans << endl;


    return 0;
}

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

int main() {
    int W , a , b;
    cin >> W >> a >> b;
    int m = min(a , b) , t = max(a , b);
    if(W + m >= t){
        cout << 0 << endl;
    }
    else{
        cout << t - W - m << endl;
    }
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

int main(void)
{
	int n;
	static int sosuu[1000000];
	int i, j;
	int ans;
	
	//すべて素数と仮定する
	for (i = 1; i < 1000000; i++){
			sosuu[i] = 1;
	}
	
	//1 を例外して素数じゃないとする
	sosuu[1] = 0;
	
	//篩する
	for (i = 2; i * i < 1000000; i++){//消す倍数を選ぶ
		if (sosuu[i] == 1){
			for (j = 2 * i; j < 1000000; j += i){//その倍数を消す
				sosuu[j] = 0;
			}
		}
	}
	
	while (scanf("%d", &n) != EOF){
		ans = 0;
		for (i = 1; i <= n; i++){
			if (sosuu[i] == 1){
				ans++;
			}
		}
		printf("%d\n", ans);
	}
	
	return (0);
}

Measured memory_bytes: 4500
import sys

K = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))

if A[-1] != 2:
    print(-1)
    sys.exit()

l = 2
r = 2
for i in range(K-2, -1, -1):
    l = ((l - 1) // A[i] + 1) * A[i]
    r = ((r + A[i+1] - 1) // A[i]) * A[i] 

    if l > r:
        print(-1)
        sys.exit()

# print(l, r)
print(l, r + A[0] - 1)

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

int main(){
  int n;
  cin>> n;
  vector<int> a(n);
  for(int i=0; i<n; i++) cin>>a[i];
  
  int tollest=0;
  int64_t ans=0;
  for(int i=0; i<n; i++){
    if(tollest<a[i]) tollest=a[i];
    else ans+=tollest-a[i];
  }
  cout<< ans <<endl;
}

Measured memory_bytes: 3988
#include <stdio.h>

int main(int argc, const char * argv[]) {
    
    char text[4];
    int result = 0;
    
    scanf("%s",text);
    
    for (int i = 0; i < 4;  i++) {
        if (text[i] == '+') {
            result = result + 1;
        }else{
            result = result - 1;
        }
    }
    
    printf("%d",result);
    
    return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<string>
using namespace std;
string s;
long long ans=0;
int main()
{
	cin>>s;
	int len=s.size();
	for(int t=0;t<(1<<(len-1));t++)
	{	
		long long num=s[0]-'0';
		for(int i=0;i<len-1;i++)
		{			
			if(t&(1<<i))
			{
				ans+=num;
				num=0;
			}
			num=num*10+s[i+1]-'0';
		}
		ans+=num;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
#define forn(i,n) for(int i=0;i<(int) n;i++)
#define Forn(i,n) for(int i=1;i<=(int) n;i++)

int main()
{

  int n,i;
  cin>>n;
  map<string,int> mp;
  vector< pair<int,string> > v;
  for(i=0;i<n;i++)
  {
      string s;
      cin>>s;
      mp[s]++;

  }
  map<string,int>:: iterator it;
  for(it=mp.begin();it!=mp.end();it++)
  {
      string a;
      int b;
      a=it->first;
      b=it->second;
      v.push_back(make_pair(b,a));

  }
  int len=v.size();
  set<string> st;
  sort(v.begin(),v.end());
  int t=v[len-1].first;


  for(i=len-1;i>=0;i--)
  {
      //cout<<v[i].first<<' '<<v[i].second<<endl;
      if(v[i].first==t)
      {
          st.insert(v[i].second);
      }
  }

  set<string>:: iterator itt;
  for(itt=st.begin();itt!=st.end();itt++)
  {
      cout<<*itt<<endl;
  }

}






Measured memory_bytes: 42248
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int INF=1e9;

int main(){
    bool isPrime[100010];
    for(int i=2;i<=100000;i++)isPrime[i]=true;
    isPrime[0]=isPrime[1]=false;
    for(int i=2;i<=100000;i++){
        if(isPrime[i]){
            for(int j=i+i;j<=100000;j+=i){
                isPrime[j]=false;
            }
        }
    }
    int isOK[100010];
    isOK[0]=0;
    for(int i=1;i<=100000;i++){
        isOK[i]=isOK[i-1]+(i&1&&isPrime[i]&&isPrime[(i+1)/2]);
    }
    int q; cin>>q;
    for(int i=0;i<q;i++){
        int l,r;
        cin>>l>>r;
        cout<<isOK[r]-isOK[l-1]<<endl;
    }
}


Measured memory_bytes: 1152
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <fstream>
#include <math.h>
#include <map>
using namespace std;

int main()
{
	int N,ANS;
	cin >> N;

	for(int i=N;i<1000;i++)
	{
		if(i%111==0)
		{
			ANS=i;
			break;
		}
	}
	cout << ANS << endl;
}

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

Measured memory_bytes: 760
#include <bits/stdc++.h>
 using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
 int main(){
  int a,b;
   cin>>a>>b;
   if(a>=10||b>=10){
   cout<<"-1"<<endl;
   }
   else{
   cout<<a*b<<endl;
   }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <stack>
#include <unordered_set>
#include <algorithm>
#undef max
#undef min

int euclideanAlgorithm(int m, int n) {
	int a = std::max(m, n) % std::min(m, n);
	return a ? euclideanAlgorithm(std::min(m, n), a) : std::min(m, n);
}

int solve(int s, int t, std::vector<std::vector<int>> residualNet) {
	int sum = 0;
	while (1) {
		bool isOk = false;
		std::vector<int> route; // 辿ってきた道
		std::unordered_set<int> visited;
		route.push_back(s);

		// 経路探索
		while (!route.empty() && !isOk) {
			bool isMoved = false;
			auto pos = route.back();

			// 移動先を検索
			for (int next = 1; next < residualNet[pos].size(); next++) {
				if (!residualNet[pos][next]) continue;
				if (visited.count(next)) continue;
				if (next == t) {
					isOk = true;
					isMoved = true;
					route.push_back(next);
					break;
				}

				// 次のところへ移動
				isMoved = true;
				route.push_back(next);
				visited.insert(next);
				break;
			}
			if (!isMoved) route.pop_back();
		}

		// 増加路無し
		if (route.empty()) {
			break;
		}

		// 増加路あり
		int min = 999999;
		for (int i = 0; i < route.size() - 1; i++) {
			min = std::min(min, residualNet[route[i]][route[i + 1]]);
		}
		sum += min;
		// 残余ネットワーク更新
		for (int i = 0; i < route.size() - 1; i++) {
			residualNet[route[i]][route[i + 1]] -= min;
			residualNet[route[i + 1]][route[i]] += min;
		}
	}
	return sum;
}

int main() {
	int n, m;
	int sum = 0;
	while (std::cin >> m >> n && m && n) {
		std::vector<int> red, blue;
		std::vector<std::vector<int>> residualNet(n + m + 2, std::vector<int>(n + m + 2, 0)); // +2はスタートとゴール分
		for (int i = 0; i < m; i++) {
			int b; std::cin >> b;
			blue.push_back(b);
		}
		for (int i = 0; i < n; i++) {
			int b; std::cin >> b;
			red.push_back(b);
		}

		// ペア作成
		for (int i = 0; i < blue.size(); i++) {
			for (int j = 0; j < red.size(); j++) {
				int a = euclideanAlgorithm(blue[i], red[j]);
				if (a > 1) {
					residualNet[i + 1][m + j + 1] = 1;
				}
			}
		}

		// スタートと青を接続
		for (int i = 0; i < blue.size(); i++) {
			residualNet[0][i + 1] = 1;
		}
		// 赤とゴールを接続
		for (int i = 0; i < red.size(); i++) {
			residualNet[m + i + 1][m + n + 1] = 1;
		}

		std::cout << solve(0, m + n + 1, residualNet) << std::endl;
	}

}


Measured memory_bytes: 10948
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <numeric>
#include <map>
#include <queue>
#include <deque>
#include <set>
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define FOR(i,a,b) for (ll i = (a) ; i <= (b); ++i)
#define RFOR(i,a,b) for (ll i = (a) ; i >= (b); --i)
#define all(x) (x).begin(), (x).end()
//#define repitr(itr, st) for(auto itr = st.begin(); itr != st.end(); ++itr)
#define P_B push_back
#define PO_B pop_back
#define E_B emplace_back
#define M_P make_pair
#define fi first
#define se second
#define debug(x) cout << #x << ": " << x << endl
//#define print(x) printf("%d\n", x)

using namespace std;
using ll = long long;
using Pii = pair<int,int>;
using Pll = pair<ll,ll>;
using VI = vector<int>;
using VL = vector<ll>;
using VVI = vector<vector<int> >;
using VVL = vector<vector<ll> >;
//int dx[4] = {1, 0, -1, 0};
//int dy[4] = {0, 1, 0, -1};
//const ll LINF = (ll)1e18 - 1;
//const int INF = 1e9 - 1;
//int:±2*10^9くらい　ll:±9*10^18くらい



void Main(){
	ll ans, n;
	cin >> n;
	ans = (n-1) * n / 2;

	cout << ans << endl;

}

int main()
{
	cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();

  return 0;
}


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

int main() {
  int y, m, d;
  
  while( cin >> y >> m >> d ) {
    if( y < 1868
	|| y == 1868 && m < 9
	|| y == 1868 && m == 9 && d < 8
	) cout << "pre-meiji" << endl;
    else if( y < 1912
	|| y == 1912 && m < 7
	|| y == 1912 && m == 7 && d < 30
	     ) cout << "meiji " << y - 1868+1 << " " << m << " " << d << endl;
    else if( y < 1926
	|| y == 1926 && m < 12
	|| y == 1926 && m == 12 && d < 25
	) cout << "taisho " << y - 1912+1 << " " << m << " " << d << endl;
    else if( y < 1989
	|| y == 1989 && m == 1 && d < 8
	) cout << "showa " << y - 1926+1 << " " << m << " " << d << endl;
    else cout << "heisei " << y - 1989+1 << " " << m << " " << d << endl;
  }
  
  return 0;
}

Measured memory_bytes: 1168
#include<algorithm>
#include<iostream>
#include<vector>
#include<string>
#include<cstring>
using namespace std;
#define REP(i, a,b) for(i=a;i<b;i++) 
#define output(x) cout<<x<<endl;
int par[100001];

void init(int n) {
	for (int i = 0; i < n; i++) {
		par[i] = i;
	}
}
//木の根を求める
int root(int x) {
	if (par[x] == x)
		return x;
	else {
		return par[x] = root(par[x]);
	}
}
//find
bool same(int x, int y) {
	return root(x) == root(y);

}
//union
void unite(int x, int y) {
	x = root(x);
	y = root(y);
	if (x == y) return;
	par[x] = y;
}

int main()
{
	long long int N, i, j, k, l, m, ans, sum,flag;
	sum = 0;
	flag = 0;
	char s[100001];
	cin >> s;
	k = strlen(s);
	REP(i, 0, k-1) {
		if (s[i] == s[i + 1]) {
			flag = 1;
			break;
		}
	}
	REP(j, 0, k - 2) {
		if (s[j] == s[j + 2]) {
			flag = 2;
			break;
		}
	}
	if (flag==1) {
		cout << i + 1 << " " << i + 2 << endl;
	}
	else if (flag == 2) {
		cout << j + 1 << " " << j + 3 << endl;
	}
	else {
		output("-1 -1");
	}



	return 0;
}



Measured memory_bytes: 384
#include <stdio.h>

int main()
{
  int n;
  int count = 0;
  int res = 0;
  
  scanf("%d", &n);

  if (n % 3) res = 1;
  while (n / 3) {
    if (res == 0 && n % 3) res = 1;
    n /= 3;
    if (n == 2) res = 1;
    count++;
  } 

  printf("%d\n", count + res);

  return 0;
}



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

public class Main{
	public static void main(String[] args){
    	InputStream inputStream = System.in;
    	OutputStream outputStream = System.out;
    	Scanner sc = new Scanner(inputStream);
    	PrintWriter out = new PrintWriter(outputStream);
      	int H = Integer.parseInt(sc.next());
      	int W = Integer.parseInt(sc.next());
      	char table[][] = new char[50][50];
      	for(int i = 0; i < H; i++){
          	String line = sc.next();
 	 	    for(int j = 0; j < W; j++){
              	table[i][j] = line.charAt(j);
              	//out.print(table[i][j]);
            }
          	//out.println();
        }
      if(judge(W, H, table) == true){
      	out.println("Yes");
      }else{
      	out.println("No");
      }
    	out.close();
    }
  	private static boolean judge(int W, int H, char[][] table) {
    	int dx[] = {1, -1, 0, 0};
      	int dy[] = {0, 0, 1, -1};
      	boolean judge = true;
      	outside:for(int i = 0; i < H; i++){
        	for(int j = 0; j < W; j++){
				if(table[i][j] == '#'){
                  	boolean found = false;
                	for(int k = 0; k < 4; k++){
                    	int x = dx[k] + i;
                      	int y = dy[k] + j;
                      	if(0 <= x && x < H && 0 <= y && y < W && table[x][y] == '#'){
                        	found = true;
                        }
                     }
                  if(found == false){
                  	judge = false;
                    break outside;
                  }
                }            	
            }
        }
      return judge;
    }
}

Measured memory_bytes: 23252
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i];if(i<len-1) s<<" ";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i]<<endl;
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){
	s<<"{ ";
	for(auto itr=v.begin();itr!=v.end();++itr) {
		if (itr!=v.begin()) {s<< ", ";}
		s<<(*itr);
	}
	s<<" }";
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){
	s<<"{"<<endl;
	for(auto itr=m.begin();itr!=m.end();++itr){
		s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;
	}
	s<<"}"<<endl;
	return s;
}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s,t;
	cin>>s>>t;
	int a,b;
	cin>>a>>b;
	string u;
	cin>>u;
	if(s==u) a--;
	else b--;
	cout<<a<<' '<<b<<endl;
}

Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};
#[allow(unused_imports)]
use std::io::{stdout, stdin, BufWriter, Write};

fn main() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (writeln!(out,$($format)*).unwrap());
    }

    input!{
      l: usize,
      r: usize,
    }

    if r-l+1 >= 2019 {
        return puts!("{}", 0);
    }
    const MOD: usize = 2019;

    let mut ans = 2019;
    for i in l..r+1 {
        for j in i+1..r+1 {
            let temp = (i % MOD) * (j % MOD) % MOD;
            ans = min(ans, temp);
        }
    }
    puts!("{}", ans);
}


Measured memory_bytes: 4352
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <sstream>
#include <stdio.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <iomanip>

//using namespace std;

#define Rep(i,a,b) for(int i = a; i < b; i++)
#define rep(i,b) Rep(i,0,b)
#define allof(a) (a).begin(), (a).end()

typedef long long ll;
const int inf = 1e9 + 7;
const ll infll = 1ll << 60ll;
const ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

template<typename T> void chmax(T& a, T b) { a = std::max(a, b); }
template<typename T> void chmin(T& a, T b) { a = std::min(a, b); }
template<typename T> void chadd(T& a, T b) { a = a + b; }

namespace {  // 名前なし名前空間
	// 最大公約数
	ll gcd(ll a, ll b) {
		if (b == 0) return a;
		return gcd(b, a % b);
	}

	// 最小公倍数
	ll lcm(ll a, ll b) {
		return a / gcd(a, b) * b;
	}
}

int main() {
	int h, w, a, b;
	std::cin >> h >> w >> b >> a;

	std::vector<std::vector<int>> ans(h, std::vector<int>(w));

	// 逆説的に解ける？
	// 一行目の少ないほうを 0 とし， ans[0][0~a] = 0 とする

	int overA = 0;
	rep(i, h) {
		if (i >= a) overA = 1;
		int overB = 0;
		rep(j, w) {
			if (j >= b) overB = 1;
			int cnt = overA + overB;
			ans[i][j] = cnt % 2;
		}
	}

	rep(i, h) {
		rep(j, w) {
			std::cout << ans[i][j];
		}
		std::cout << std::endl;
	}


	return 0;
}


Measured memory_bytes: 5120
import java.util.Map.Entry;
import java.util.*;

import org.w3c.dom.css.Counter;

public class Main {
//public class App {

    public static void main(String[] args){
     //スキャン
     Scanner s = new Scanner(System.in);
     // 入力
        long n = s.nextInt();
        long an = 0;
    for(long i = 1 ;i<=n;i++){
        for(long i2 =1; i2 <= i;i2++){
            for(long i3 =1; i3 <= i2;i3++){
                long huge = hogehoge(i,i2);
                huge = hogehoge(huge,i3);
                if(i == i2 && i2==i3){
                    an += huge;
                }else if(i ==i2 || i2 ==i3){
                    an += huge*3;
                }else{
                    an += huge *6;
                }

            }
        }
    }
    System.out.println(an);
}
    public static long  hogehoge(long a , long b){
        long tmp;
        long x =a;
        long y=b;
        while((tmp = x % y) != 0){
            x = y;
            y = tmp;
        }
        return y;
    }
}




Measured memory_bytes: 35736
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

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

	private void solve() {
		// 入力
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		sc.close();

		// 計算
		List<String> list = new ArrayList<String>(Arrays.asList("abcdefghijklmnopqrstuvwxyz".split("")));
		for (String string : S.split("")) {
			list.remove(string);
		}
		String output = "None";
		if (!list.isEmpty()) {
			output = list.get(0);
		}

		// 出力
		System.out.println(output);

		return;
	}
}


Measured memory_bytes: 30924
#ABC 53, B - A to Z string
S = list(input())

for i in range(len(S)):
    if S[i] == 'A':
        start = i
        break
for j in range(len(S)-1, -1, -1):
    if S[j] == 'Z':
        end = j
        break
print(end - start+1)



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

int main(){
  double A, B, H, M;
  cin >> A >> B >> H >> M;
  double si=abs(30*H+M/2-6*M);
  si=min(si, 360-si);
  double P=3.14159265358979;
  double c=A*A+B*B-2*A*B*cos(si*2*P/360);
  cout << setprecision(15) << pow(c, 0.5) << endl;
}

Measured memory_bytes: 4340
def solve(p, s, list)
  result = Array.new
  while r=fill!(p, s, list) do
    result += r
  end
  list.each do |l|
    l.each do |v|
      return ["NO"] unless v
    end
  end
  result.sort{|a, b| a[0]!=b[0] ? a[0]<=>b[0] : (a[1]!=b[1] ? a[1]<=>b[1] : a[2]<=>b[2])}.collect{|v| v.last}
end

def fill!(p, s, list)
  result = Array.new
  p.times do |i|
    question = Array.new
    sum = 0
    s.times do |j|
      sum += list[i][j] if list[i][j]
      question.push(j) unless list[i][j]
    end
    next if question.size != 1
    list[i][question.first] = list[i].last - sum
    result.push([i, question.first, list[i][question.first]])
  end
  s.times do |j|
    question = Array.new
    sum = 0
    p.times do |i|
      sum += list[i][j] if list[i][j]
      question.push(i) unless list[i][j]
    end
    next if question.size != 1
    list [question.first][j] = list.last[j] - sum
    result.push([question.first, j, list [question.first][j]])
  end
  result.size.zero? ? nil : result
end

first = true
until (p,s=gets.split.map(&:to_i)).all?(&:zero?) do
  puts "" if !first
  first = false
  list = Array.new
  (p+1).times{list.push(gets.split.map{|v| v=="?" ? nil : v.to_i})}
  gets
  solve(p,s,list).each{|v| puts v}
end

Measured memory_bytes: 6132
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <stack>
using namespace std;

const int Maxn = 300000 + 10;
int pre[Maxn], last[Maxn], other[Maxn], vis[Maxn];
int all = -1, flag,n;

void build(int u, int v){
	pre[++all] = last[u];
	last[u] = all;
	other[all] = v;
}

void dfs(int x, int cnt){
	if(x == n && cnt <= 2){
		flag = 1;
		return ;
	}
	int dr, ed = last[x];
	while(ed != -1){
		dr = other[ed];
		if(!vis[dr]){
			vis[dr] = 1;
			dfs(dr, cnt + 1);
			if(flag) return;
		}
		ed = pre[ed];
	}
}

int main(){ 
	int  m;
	while(~scanf("%d %d",&n, &m)){
		flag = 0;
		memset(last, -1, sizeof(last));
		memset(vis, 0, sizeof(vis));
		for(int i = 1; i <= m; i++){
			int u, v;
			scanf("%d %d",&u, &v);
			build(u, v);
		}
		dfs(1, 0);
		if(flag) printf("POSSIBLE\n");
		else printf("IMPOSSIBLE\n");
	}
	return 0;
}

Measured memory_bytes: 4352