akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <stdio.h>
#include <bitset>
#include <limits.h>
#include <complex>
#include <deque>
#include <iomanip>
using namespace std;
#define MM 1000000000
#define MOD MM+7
#define pi pair<int32,int32>
#define pl pair<int64,int64>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
template<typename T>
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
template<typename T>
T lcm(T x,T y){
    return x*y/GCD(x,y);
}
long long Pow(long long base,long long x){
    if (x == 0) return 1;
    if (x%2 == 1) return (base*Pow(base,x-1))%MOD;
    long long y = Pow(base, x/2);
    return y*y%MOD;
}
long long fac[100010],finv[100010],inv[100010];

const int MAX = 1010;
void init(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAX; i++){
        fac[i] = fac[i-1]*i%MOD;
        inv[i] = MOD - inv[MOD%i]*(MOD/i)%MOD;
        finv[i] = finv[i-1]*inv[i]%MOD;
    }
}

long long COM(int n,int k){
    if(n < k || n < 0 || k < 0) return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}

long long Euler_phi(int n){
    long long ret = n; 
    for(long long i = 2; i*i <= n; i++){
        if (n%i == 0){
            ret -= ret/i;
            while(n % i == 0) n /= i;
        }
    }
    if (n != 1) ret -= ret/n;
    return ret;
}

int main(){
    long long n; cin >> n;
    cout << Euler_phi(n) << endl;
}
  




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

int main(){
	IOS;
	string str;
	cin >> str;
	vector<int> ch(26,0);
	int s=str.size();
	for(int i=0;i<s;i++) ch[str[i]-'a']++;
	for(int i=0;i<26;i++){
		if(!ch[i]){
			cout << (char)('a'+i) << '\n';
			return 0;
		}
	}
	cout << "None\n";
	return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (int)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
int main(){
  ll n,m;
  cin>>n>>m;
  ll ans=0;
  if(n==1&&m==1){
    COUT(1);
  }
  else if(n==1||m==1){
    COUT(max(n,m)-2);
  }
  else{
    COUT((n-2)*(m-2));
  }
}
  


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <fstream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <map>

using namespace std;
typedef long long ll;

int main()
{
    ios_base::sync_with_stdio(0);
    int x, y;
    cin >> x >> y;
    if (x % 2 == y % 2)
    {
        cout << (x + y) / 2;
    }
    else
        cout << "IMPOSSIBLE\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <sstream>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <numeric>
#include <cmath>
#include <climits>
#include <limits>
#include <cfloat>
#include <fstream>
using namespace std;

int main()
{
//	cut here before submit 
//	freopen ("testcase.LMSS", "r", stdin );
	string str = "";
	int i, n;
	vector <multimap <int, string > > res;

	while (getline (cin, str ) ){
		stringstream ssn(str);
		ssn >> n;
		
		if (n == 0 ){
			break;
		} // end if

		multimap <int, string> rank;

		for (i = 0; i < n; ++i){
			string team;
			int win, lose, draw;
			getline (cin, str );
			stringstream ss(str);
			ss >> team >> win >> lose >> draw;
			int point = 3*win + draw;
			rank.insert (make_pair (-point, team ) );
		} // end for
		res.push_back (rank );		
	} // end loop
	int size = res.size();
	
	for (i = 0; i < size; ++i){
		multimap <int, string>::iterator it = res[i].begin();
		for (; it != res[i].end(); ++it ){
			int point = -(*it).first;
			string team = (*it).second;
			cout << team << ',' << point << endl;
		} // end for
		if (i != size - 1){
			cout << endl;
		} // end if
	} // end for
		
	return 0;
}

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

int main(){
    
    int d;
    cin >> d;

    if(d == 25) cout << "Christmas" << endl;
    if(d == 24) cout << "Christmas Eve" << endl;
    if(d == 23) cout << "Christmas Eve Eve" << endl;
    if(d == 22) cout << "Christmas Eve Eve Eve" << endl;

}



Measured memory_bytes: 256
<?php
fscanf(STDIN, "%d", $n);
$a = explode(' ', trim(fgets(STDIN)));

for ($i=0; $i < $n ; $i++) {
    if ($a[$i] % 2 == 0) {
        if ($a[$i] % 3 == 0 || $a[$i] % 5 == 0) {
            $ans = 'APPROVED';
        } else {
            $ans = 'DENIED';
            break;
        }
    } else {
        $ans = 'APPROVED';
    }
}
echo $ans;


Measured memory_bytes: 4856
#include <bits/stdc++.h>
using namespace std;
using ll=unsigned long long;
/*
すごいでかい素数きた場合困る
  x
x
 x
4-1-(1/2)-1=3/2
超でかい長方形つくって、面積-1とか可能。
もし2で割り切れるなら、そのまま作るとか
ルートでとらな
9999とか
100^100

0,0, 0,100, 99,99で9999になる
10^18のルートは10^9かかるから無理
abs(x2*y3-x3*y2)=S
abs(
*/
int main(){
  ll S,z=1e9; cin>>S;
  if(S==1e18){
    cout<<"0 0 0 1000000000 1000000000 1000000000"<<endl;
    return 0;
  }
  ll y=S/z+1;
  ll x=z-S%z;
  cout<<"0 0 "<<z<<" "<<1<<" "<< x<<" "<<y<<endl;
}

Measured memory_bytes: 384
# https://atcoder.jp/contests/panasonic2020/tasks/panasonic2020_d

n = int(input())

def dfs(s, mx, path):
    if n == len(s):
        path.append(s)
        return
    for i in range(ord('a'), mx + 1):
        if i == mx:
            dfs(s + chr(i), mx + 1, path)
        else:
            dfs(s + chr(i), mx, path)

path = []
dfs('', ord('a'), path)
path.sort()
for ans in path:
    print(ans)

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

int main()
{
  
    int a,b,c,k;
    cin >> a >> b >> c >> k;

   int sum=0;
    if(a+b+c<k){
        return 0;

    }
   while(0<k){
       if(a >= k){
           sum += 1 * k;
           break;
        }else{
            sum += 1* a;
            k -= a;
            if(b >= k){
                 sum += 0 * k;
                break;
            }else{
                sum += 0 * b;
                k -= b;
                if(c >= k){
                    sum += -1 * k;
                    break;
              
                }
            }
        }
    }

    cout << sum  << endl;

    return 0;
}

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

int main()
{
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> c(n);
  int i, k;
  k = 1;
  int s = 0;
  for(i = 0; i < n; i++)
  {
    cin >> a.at(i);
  }
  for(i = 0; i < n; i++)
  {
    c.at(k-1)++;
    if(c.at(k-1) >= 2)
    {
      break;
    }
    k = a.at(k-1);
    if(k == 2)
    {
      s = 1;
      break;
    }
  }
  if(s == 1)
  {
    cout << i+1 << endl;
  }
  else
  {
    cout << -1 << endl;
  }
}

Measured memory_bytes: 1024
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#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__) << "] "
typedef long long ll;

int main(){
	int n ; 
	cin >> n ; 
	vector<int> v(n) ; 
	for(int &x : v){
		cin >> x ; 
	}
	int ans = 1e9 ; 
	for(int i=1;i<n;i++){
		int group1 = 0 ; 
		int group2 = 0 ; 
		for(int j=0;j<i;j++){
			group1 += v[j] ; 
		}
		for(int j=i;j<n;j++){
			group2 += v[j] ; 
		}
		ans = min(ans,abs(group1-group2)) ; 
	}
	cout << ans << endl;
    return 0 ;
}


Measured memory_bytes: 256
// #pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
#define String std::string
#define fir first
#define sec second
#define mp std::make_pair
#define Pair std::pair<int, int>
#define Map std::map< int, int >
#define Vector std::vector<int>

typedef long long ll;
typedef unsigned long long ull;

const int N = 100000 + 5;
const int M = 3000 + 5;
const int MOD = 1e9 + 7;
const int inv2 = 500000004;
const int dx[] = { 0, 1, -1, 0, 1, -1, 1, -1 };
const int dy[] = { 1, 0, 0, -1, 1, -1, -1, 1 };

inline ll read() {
    ll res = 0, f = 1;
    char ch = getchar();
    for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;
    for (; isdigit(ch); ch = getchar()) res = (res << 1) + (res << 3) + ch - '0';
    return res * f;
}

ll calc(ll x) {
    if (x <= 0) return 0;
    if (x % 2 == 0) return x ^ (((x - 1) / 2 + 1) & 1);
    else return ((x - 1) / 2 + 1) & 1;
}

int main() {
    ll a, b;
    std::cin >> a >> b;
    printf("%lld\n", calc(b) ^ calc(a - 1));
    return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)
MOD = 10 ** 9 + 7

N, M = map(int, input().split())

G = [[] for _ in range(N + 1)]
for _ in range(M):
    a, b = map(int, input().split())
    G[a].append(b)
    G[b].append(a)

for i in G[1]:
    for j in G[i]:
        if j == N:
            print ('POSSIBLE')
            exit()

print ('IMPOSSIBLE')

Measured memory_bytes: 38320
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const int MOD = 1000000007;
//const int MOD = 998244353;

// Lib
//

int main(){
#ifdef MYLOCAL
    ifstream in("input.txt");
    cin.rdbuf(in.rdbuf());
#endif
    int M, D; cin >> M >> D;
    if (D < 20){
        cout << 0 << endl;
        return 0;
    }
    ll ans = 0;
    for(int i = 0; i <= M; ++i){
        for(int j = 20; j <= D; ++j){
            if(j % 10 < 2){
                continue;
            }
            if(i == (j % 10) * (j / 10)){
                ++ans;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< pii >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; cin >> x;
#define int2(x, y) Int(x); Int(y);
#define int3(x, y, z) Int(x); int2(y, z);
#define in(x, a, b) ((a) <= (x) && (x) < (b))
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second
#define Decimal fixed << setprecision(10)

//int dxy[5] = {0, 1, 0, -1, 0};
// 01Trie BIT CHT DFT FFT avl cmd cusum dijkstra dinic geo2 gin graph kruskal lca lcm matrix ncm next_combination ppuf segtree st tmp topcoder uf vi 

int fact[1145140];
int pascal_table[100][100];

/*
 * tableをdoubleにしてncmの割合も求められる
 * 1/2して下ってゆくように書き換えてその場で作る.
 */
void make_pascal(int mod)
{
    rep(i, 100) {
        pascal_table[i][0] = 1;
        for (int j = 1; j < i; j++) {
            pascal_table[i][j] = (pascal_table[i-1][j-1] +
                    pascal_table[i-1][j]) % mod;
        }
        pascal_table[i][i] = 1;
    }
}

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

int extgcd(int a, int b, int &x, int &y)
{
    int d = a;
    if (b != 0) {
        d = extgcd(b, a % b, y, x);
        y -= (a / b) * x;
    } else { x = 1; y = 0; }
    return d;
}

int repow(int x, int n, int mod)
{
    if (n == 0) return 1;
    int res = repow(x * x % mod, n / 2, mod);
    if (n & 1) res = res * x % mod;
    return res;
}

int mod_inverse(int a, int m)
{
    int x, y;
    extgcd(a, m, x, y);
    return ( m + x % m ) % m;
}

int table(int n, int p)
{
    int sum = 1;
    fact[0] = 1;
    Rep(i, n+2) {
        sum *= i;
        sum %= p;
        fact[i] = sum;
    }
}

int mod_fact(int n, int p, int &e)
{
    e = 0;
    if (n == 0) return 1;
    int res = mod_fact(n / p, p, e);
    e += n / p;

    if (n / p % 2 != 0) return res * (p - fact[n % p]) % p;
    return res * fact[n % p] % p;
}

/*
 * nCr mod p
 * nHr = (n+r-1)Cr
 * 必ずtable()を呼んでから使う.
 * n = 1001000くらいで
 */
int mod_comb(int n, int k, int p) {
    if (n < 0 || k < 0 || n < k) return 0;
    int e1, e2, e3;
    int a1 = mod_fact(n, p, e1), a2 = mod_fact(k, p, e2), a3 = mod_fact(n-k, p, e3);
    if (e1 > e2 + e3) return 0;
    return a1 * mod_inverse(a2 * a3 % p, p) % p;
}

int ncm(int n, int r)
{
    if (r == 0) return 1;
    return (n-r+1) * ncm(n, r-1) / r;
}

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

    table(1001000, MOD);
    int2(n, k);
    int p = n-k;

    Rep(i, k+1) {
        cout << (mod_comb(p+1, i, MOD) * mod_comb(k-1, i-1, MOD)) % MOD << endl;
    }

    return 0;
}


Measured memory_bytes: 8320
n=int(input())
a=list(map(int,input().split()))
dp=[[float("inf")]*(n+1) for _ in range(n)]
z=0
for l in range(n):
    dp[l][l]=0
for k in range(1,n+1):
    for i in range(n):
        j=i+k
        if 0<=i<=n-2 and 1<=j<=n:
            if (n-(i+j))%2==0: #先手
                dp[i][j]=max(dp[i+1][j]+a[i],dp[i][j-1]+a[j-1])
            else:
                dp[i][j]=min(dp[i+1][j]-a[i],dp[i][j-1]-a[j-1])
        elif 0<=i<=n-2 and 0<=j<=n:
            dp[i][j]=dp[i+1][j]+a[i]
        elif 0<=i<=n-1 and 1<=j<=n:
            dp[i][j]=dp[i][j-1]+a[j-1]
        else:
            z=1

print(dp[0][n])

Measured memory_bytes: 308360
from collections import defaultdict

n = int(input())
a = list(map(int, input().split()))

if len(set(a)) == 1 and list(set(a))[0] == 0:
    print('Yes')
    exit()

if n % 3 == 0 and len(set(a)) == 3:
    x = list(set(a))
    e = x[0]
    b = x[1]
    c = x[2]
    if e ^ b != c:
        print('No')
        exit()
    if b ^ c != e:
        print('No')
        exit()
    if c ^ e != b:
        print('No')
        exit()
    d = defaultdict(int)
    for i in a:
        d[i] += 1
    if d[e] != d[b] or d[b] != d[c] or d[c] != d[e]:
        print('No')
        exit()
    print('Yes')
elif n % 3 == 0 and len(set(a)) == 2:
    x = list(set(a))
    x.sort()
    if x[0] == 0:
        t = 1
    else:
        print('No')
        exit()
    d = defaultdict(int)
    for i in a:
        d[i] += 1
    if d[x[0]]*2 == d[x[1]]:
        print('Yes')
        exit()
    print('No')
else:
    print('No')

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

using namespace std;

int n;
int a[51];

int main()
{
    int s = 0;
    scanf("%d",&n);
    for(int i =1;i <= n;i++)
    {
        scanf("%d",&a[i]);
        if(i != a[i])
            s++;
    }
    if(s < 3)
        printf("YES\n");
    else
        printf("NO\n");
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <vector>
#include <deque>
#include <math.h>
#include <map>
#include <bitset>
#include <queue>
#include <list>
#include <utility>

//#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ld = long double;
using p = pair<int, int>;
using Graph = vector<vector<char>>;
#define rep(i,n)  for(int i = 0; i < n ; i++)
int dx[4]{ -1,0,1,0 };
int dy[4]{ 0,1,0,-1 };

int main()
{
    int N, M;
    cin >> N >> M;
    // それぞれから2つ選ぶ
    int ans = 0;
    if (N <= 1 && M <= 1) { cout << 0 << endl;return 0; }
    ans = N * (N - 1) / 2;
    ans += M * (M - 1) / 2;
    cout << ans << endl;
}

Measured memory_bytes: 256
def main():
    X, Y, A, B, C = [int(i) for i in input().split()]
    red = [int(i) for i in input().split()]
    blue = [int(i) for i in input().split()]
    noc = [int(i) for i in input().split()]
    red = sorted(red)[-X:]
    blue = sorted(blue)[-Y:]
    rb = sorted(red + blue)
    score = sum(rb)
    noc = sorted(noc)[::-1]

    s_noc = 0
    s_rb = 0
    for i in range(min(len(rb), len(noc))):
        if rb[i] > noc[i]:
            break
        s_noc += noc[i]
        s_rb += rb[i]

    print(score + s_noc - s_rb)


if __name__ == '__main__':
    main()



Measured memory_bytes: 23340
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		if (s.charAt(2) == s.charAt(3) && s.charAt(4) == s.charAt(5)) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}

	}

}


Measured memory_bytes: 21844
#include <iostream>
#include <stdio.h>
#include <algorithm>
using namespace std;

int n, a[100005];

int BS_low(int x)
{
    int l = 1, r = n, mid, save = -1;
    while (l <= r)
    {
        mid = (l + r) / 2;
        if (a[mid] <= x)
        {
            l = mid + 1;
            save = mid;
        }
        else r = mid - 1;
    }
    return a[save];
}

int BS_high(int x)
{
    int l = 1, r = n, mid, save = -1;
    while (l <= r)
    {
        mid = (l + r) / 2;
        if (a[mid] >= x)
        {
            r = mid - 1;
            save = mid;
        }
        else l = mid + 1;
    }
    return a[save];
}

int main()
{
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    sort(a + 1, a + 1 + n);
    int low = 0, high = 0, mid = (a[n] + 1) / 2;
    low = BS_low(mid);
    high = BS_high(mid);
    if (mid - low <= high - mid) printf("%d %d", a[n], low); else printf("%d %d", a[n], high);
	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
  int a,b;
  cin >> a >> b;
  cout << max(0,a - b) << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		while(true){
			int a = sc.nextInt(), b = sc.nextInt();
			
			if(a == 0 && b == 0){
				break;
			}
			
			if(a < b){
				int tmp = a;
				a = b;
				b = tmp;
			}
			
			int count = 0;
			while(b != 0){
				a = a % b;
				
				int tmp = a;
				a = b;
				b = tmp;
				count++;
			}
			
			
			System.out.println(a + " " + count);
		}
	}
	
}



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

#define int long long 
#define ll long long 
#define pb push_back
#define mp make_pair
#define pii pair<ll,ll>
#define ff first
#define ss second
#define vi vector<ll>
#define mod 1000000007
#define full(a) a.begin(),a.end()
#define inf INT_MAX
#define minf INT_MIN

ll frog(ll i,ll n,ll a[],ll dp[]){
    if(i==n-1)return 0;
    if(dp[i]!=-1)return dp[i];

    ll q=INT_MAX,t=INT_MAX;
    if(i+1<n)q=abs(a[i+1]-a[i])+frog(i+1,n,a,dp);
    if(i+2<n)t=abs(a[i+2]-a[i])+frog(i+2,n,a,dp);

    return dp[i]=min(q,t);
}


int32_t main() 
{ 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif

    ll n;
    cin>>n;
    ll h[n];
    ll dp[n];
    memset(dp,-1,sizeof dp);
    for(int i=0;i<n;i++)cin>>h[i];

    cout<<frog(0,n,h,dp);
    
    

    return 0; 
 }
    

Measured memory_bytes: 11460
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <vector>
#include <math.h>
#include <map>
#include <queue>
#include <set>
using namespace std;
typedef long long ll;
const int maxn=3e5+50;
const int inf=0x3f3f3f3f;
const int mod=1e9+7;
const int phi=1e9+6;
int main()
{
    int x;
    cin>>x;
    if(x>=30)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 3632
#include <stdio.h>
#define N 100000
#define NIL -1
int Depth(int );
void display(int );
struct Node {
  int parent;
  int left;
  int right;
};

struct Node T[N];
int n,D[N];

int main()
{
  int a,b,i,j,l,m;
  scanf("%d",&n);
  for(i=0;i<n;i++)
    {
      T[i].parent=NIL;
      T[i].left=NIL;
      T[i].right=NIL;
    }

  for(i=0;i<n;i++)
    {
      scanf("%d%d",&l,&m);
      for(j=0;j<m;j++)
        {
          scanf("%d",&a);
          if(j==0) T[l].left=a;
          else T[b].right=a;
          b=a;
          T[a].parent=l;
        }
    }
  for(i=0;i<n;i++)
    {
      D[i]=Depth(i);
    }
  for(i=0;i<n;i++)
    {
      display(i);
    }
  return 0;
}

int Depth(int a)
{
  int d=0;
  while(T[a].parent!=-1)
    {
      a=T[a].parent;
      d++;
    }
  return d;
}
void display(int x)
{
  int i,j;
  printf("node %d: parent = %d, depth = %d, ",x,T[x].parent,D[x]);
  if(T[x].parent==-1) printf("root, ");
  else if(T[x].left==-1) printf("leaf, ");
  else printf("internal node, ");

  printf("[");
  for(i=0,j=T[x].left;j!=NIL;i++,j=T[j].right)
    {
      if(i) printf(", ");
      printf("%d",j);
    }
  printf("]\n");
}


Measured memory_bytes: 3408
#include<bits/stdc++.h>
using namespace std;
#define M 1000000007
#define int long long
#define max_n 21
#define mask (1<<max_n)
vector<vector<int>>dp(max_n+1,vector<int>(mask,0));

signed main(void){
    int n; cin >> n;
    vector<vector<int>> a(n,vector<int>(n,0));
    for(int i=0;i<n;i++)for(int j=0;j<n;j++)cin >> a[i][j];
    for(int i=0;i<n;i++){
        if(a[0][i]==1) dp[1][1<<i] = 1;
    }

    for(int i=2;i<=n;i++){
        for(int j=0;j<n;j++){
            if(a[i-1][j]==0) continue;
            for(int k=0;k<mask;k++){
                if((k&(1<<j))==0){
                    dp[i][(1<<j)+k] = (dp[i][(1<<j)+k] + dp[i-1][k])%M;
                }
            }
        }
    }

    // for(int i=0;i<=n;i++){
    //     for(int j=0;j<10;j++){
    //         cout << dp[i][j] << ' ';
    //     }cout << endl;
    // }cout << endl;
    
    cout << accumulate(dp[n].begin(),dp[n].end(),0) << endl;
    return 0;
}

// int main(void){
//     int n; cin >> n;
//     vector<vector<ll>>a(n,vector<ll>(n));
//     int mask = (1<<n);
//     vector<vector<ll>>dp(n,vector<ll>(mask,0));
//     for(int i=0;i<n;i++)for(int j=0;j<n;j++) cin >> a[i][j];
//     for(int i=0;i<n;i++){
//         if(a[n-1][i] == 0) continue;
//         dp[n-1][(1<<i)] = 1;　//１人めでの組み合わせ
//     }
//     ll ans = 0;
//     for(int i=n-2;0<=i;i--){
//         for(int j=n-1;0<=j;j--){
//             if(a[i][j] == 0) continue;
//             for(int k=0;k<mask;k++){
//                 if(((k)&(1<<j)) == 0){//既にペアになっている人とは組まない
//                     dp[i][(1<<j)+(k)] = (dp[i][(1<<j)+(k)]+dp[i+1][k])%M;
//                 }
//             }
//         }
//     }
//     for(int i=0;i<mask;i++)ans += dp[0][i];
//     cout << ans << endl;
//     return 0;
// }

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

void solve() {
    cin >> N;
    int A[N];
    int X[N][N];
    int Y[N][N];
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
        for (int j = 0; j < A[i]; ++j) {
            int x, y;
            cin >> x >> y;
            X[i][j] = x - 1;
            Y[i][j] = y;
        }
    }
    int m = 0;
    for (int bit = 1; bit < (1<<N); ++bit)
    {
        bool ok = true;
        int size = 0;
        for (int i = 0; i < N; ++i) {
            if ((bit >> i) & 1) {
                size++;
                for (int j = 0; j < A[i]; ++j) {
                    if ((bit >> X[i][j] & 1) ^ (Y[i][j])) {
                        ok = false;
                    }
                }
            }
        }
        if (ok) m = max(m, size);
    }
    cout << m << endl;
}

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


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        // 入力
        Scanner sc = new Scanner(System.in);

        int x = sc.nextInt();

        if( x == 7 || x == 5 || x == 3 ) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }
    }
}


Measured memory_bytes: 21844
#!/usr/bin/env ruby
X,N = gets.chomp.split.map(&:to_i)
P = gets.chomp.split.map(&:to_i)

a=[*-100..200]

P.each do |p|
  a[p+100] = -9999
end

idx = X
if a[idx+100] != -9999
  puts a[idx+100]
  return
end

(0...101).each do |i|
  if a[idx+100-i] != -9999
    puts a[idx+100-i]
    return
  end
  if a[idx+100+i] != -9999
    puts a[idx+100+i]
    return
  end
end

Measured memory_bytes: 14368
n = int(input())
s = {'M':0, 'A':0, 'R':0, 'C':0, 'H':0}
# M A R C H
for i in [0]*n:
  t = input()
  if t[0] in s:
    s[t[0]] += 1
print(s['M']*(s['A']*(s['R']+s['C']+s['H'])+s['R']*(s['C']+s['H'])+s['C']*s['H']) + s['A']*(s['R']*(s['C']+s['H'])+s['C']*s['H'])+s['R']*s['C']*s['H'])



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

using namespace std;

int main(){
	string s;
	bool rev = false;
	list<char> l;
	l.push_back('#');
	cin >> s;
	int q, t, f;
	char c;
	cin >> q;
	while(q--){
		cin >> t;
		if(t == 1)
			rev = rev ^ true;
		else if(t == 2){
			cin >> f >> c;
			if(((f == 1) && (!rev)) || ((f==2) && rev))
                l.push_front(c);
			else
				l.push_back(c);
		}
	}
	if(rev){
        while(!l.empty()){
            char ch = l.back();
            l.pop_back();
            if(ch == '#'){
                reverse(s.begin(), s.end());
                cout << s;
            }
            else
                cout << ch;
        }
	}
	else{
        while(!l.empty()){
            char ch = l.front();
            l.pop_front();
            if(ch == '#'){
                cout << s;
            }
            else
                cout << ch;
        }
	}
    return 0;
}



Measured memory_bytes: 6912
#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<vector>
#include<utility>
#include<stack>
#include<queue>
#include<list>
 
#define FOR(i, a, b) for(int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000001
 
using namespace std;
 
 
 
int main(void) {
  int n;
  int p;
  int sn=0;
  
  cin>>n;
  
  p=n;
  
  while(p!=0){
    sn+=p%10;
    p/=10;
    }
    
    if(n%sn==0){
      cout<<"Yes"<<endl;
      }else{
        cout<<"No"<<endl;
        }
   
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	int x, y, n, i;	

	for(i = 1; 1; i++){
		scanf("%d %d", &x, &y);
		if(x == 0 && y == 0){
			break;
		} else{
			if(x > y){
				n = x;
				x = y;
				y = n;
			}
			printf("%d %d\n", x, y);

		}
	}
	
	return 0;
}

Measured memory_bytes: 1768
import itertools,sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
N = I()
abc = [LI() for _ in range(N)]
dp = [[0,0,0] for _ in range(N)]
dp[0] = abc[0]
for i,j,k in itertools.product(range(N),[0,1,2],[0,1,2]):
    if j==k:
        continue
    if i-1>=0:
        dp[i][j] = max(dp[i][j],dp[i-1][k]+abc[i][j])
print(max(dp[-1]))


Measured memory_bytes: 51380
//Author - Sumit

#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define int ll
#define ps push
#define pb push_back
#define INF 10000000000LL
#define MOD 1000000007
#define mp make_pair
#define rep(i,a,b) for (int i = a; i < b; i++)
#define repd(i,a,b) for (int i = a; i >= b; i--)
#define all(v) v.begin(),v.end()
#define pii pair<int,int>
#define F first
#define S second
#define mii map<int,int>
#define vi vector<int>
#define vvi vector<vi>
#define vpii vector<pair<int,int>>
#define itr :: iterator it
#define WL(t) while(t --)
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define debug(x) cout << x << "\n";
#define debug2(x,y) cout << x << " " << y << "\n";
#define debug3(x,y,z) cout << x << " " << y << " " << z << endl;



void solve(){
    int n;
    cin>>n;
    int a[n];
    rep(i,0,n) cin>>a[i];
    int res=0;
    rep(i,0,n){
        rep(j,i+1,n){
            res+=(a[i]*a[j]);
        }
    }  
    debug(res);  
}

signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    
    int t=1;
    // cin>>t;
    WL(t){
        solve();
    } 
} 

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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)
#define PI 3.14159265358979323846

typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,P> PP;

//-----------------------------------------------------------------------------

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

	while(true) {
		int n;
		cin>>n;
		if(n==0) break;
		int a[n];
		REP(i,n) cin>>a[i];
		sort(a,a+n);
		int ans=INF;
		REP(i,n-1) ans=min(ans,a[i+1]-a[i]);
		cout<<ans<<endl;
	}

	return 0;
}



Measured memory_bytes: 3192
#include<stdio.h>

int main() {
  int n,i;
  scanf("%d", &n);
  int a[n],count[n];
  for(i = 0; i<n; i++){
    count[i] = 0;
  }
  
  for (i = 1; i < n; i++) {
    scanf("%d", &a[i]);
    count[a[i]-1]++;
  }
  
  for(i = 0;i<n;i++){ 
    printf("%d\n",count[i]);
  }
}

Measured memory_bytes: 3292
//#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string.h>
int main()
{
	char s[100], ss[200],p[100],u[100];
	int i,j,m,n;
	int t = 0;
	gets(s);
	gets(p);
	n = strlen(s);
	m = strlen(p);
	sprintf(ss, "%s%s\n", s, s);
	for (i = 0; i < n; i++){
		for (j = i; j < n; j++){
			strncpy(u, ss + j, m);
			u[m] = '\0';
			if (strcmp(u, p) == 0) {
				t = 1;
			}
		}
	}
	if (t==1) {
		printf("Yes\n");
	}
	else {
		printf("No\n");
	}
	return 0;
}

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

int main()
{
    bool f = false;
    vector<vector<int>> A(3, vector<int>(3));
    rep(i, 3)
    {
        rep(j, 3)
        {
            cin >> A.at(i).at(j);
        }
    }
    int N;
    cin >> N;
    vector<int> b(N);
    rep(i, N)
    {
        cin >> b.at(i);
    }
    rep(i, 3)
    {
        rep(j, 3)
        {
            rep(k, N)
            {
                if (b.at(k) == A.at(i).at(j))
                {
                    A.at(i).at(j) = -1;
                }
            }
        }
    }
    if (A.at(0).at(0) == A.at(0).at(1) && A.at(0).at(1) == A.at(0).at(2))
    {
        f = true;
    }
    else if (A.at(1).at(0) == A.at(1).at(1) && A.at(1).at(1) == A.at(1).at(2))
    {
        f = true;
    }
    else if (A.at(2).at(0) == A.at(2).at(1) && A.at(2).at(1) == A.at(2).at(2))
    {
        f = true;
    }
    else if (A.at(0).at(0) == A.at(1).at(0) && A.at(1).at(0) == A.at(2).at(0))
    {
        f = true;
    }
    else if (A.at(0).at(1) == A.at(1).at(1) && A.at(1).at(1) == A.at(2).at(1))
    {
        f = true;
    }
    else if (A.at(0).at(2) == A.at(1).at(2) && A.at(1).at(2) == A.at(2).at(2))
    {
        f = true;
    }
    else if (A.at(0).at(0) == A.at(1).at(1) && A.at(1).at(1) == A.at(2).at(2))
    {
        f = true;
    }
    else if (A.at(0).at(2) == A.at(1).at(1) && A.at(1).at(1) == A.at(2).at(0))
    {
        f = true;
    }
    if (f)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, const char * argv[]) {
    int j, s_length = 0;
    char s[101], p[101];
    scanf("%s", s);
    scanf("%s", p);

    for(int i = 0; s[i] != '\0';i++) s_length++;

    for(int left = 0;s[left] != '\0';left++){
        for(j = 0;p[j] != '\0' && p[j] == s[(left+j)%s_length];j++);
        if(p[j] == '\0'){
            printf("Yes\n");
            return 0;
        }
    }
    printf("No\n");
    return 0;
}



Measured memory_bytes: 2664
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<cctype>
#include<complex>
#include<iostream>
#include<sstream>
#include<algorithm>
#include<functional>
#include<utility>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
#include<set>
 
using namespace std;
const int dx[] = {1,0,-1,0},dy[] = {0,1,0,-1};
#define INF 1e+9
#define EPS 1e-9
#define rep(i,j) for(int i = 0; i < (j); i++)
#define reps(i,j,k) for(int i = j; i < (k); i++)
typedef long long ll;
double fert[128][128];
double dp[128][128];
int main(){
    int n,m;
    while(scanf("%d%d",&n,&m),(n|m)){
        memset(dp,0,sizeof(dp));
        rep(i,n)rep(j,n)scanf("%lf",&fert[i][j]);
        rep(i,m){
            rep(j,n){
                bool flg = false;
                if(i == 0)dp[i][j] = 1.0;
                else{
                    rep(k,n){
                        dp[i][j] = (!flg) ? dp[i-1][k] * fert[k][j] : max(dp[i][j],dp[i-1][k] * fert[k][j]);
                        flg = true;                    
                    }
                }
            }
        }
        double res = -1.0;
        rep(i,n){
            res = max(res,dp[m-1][i]);
        }  
        printf("%.2lf\n",res);
    }
    return 0;
}

Measured memory_bytes: 1480
package main

import (
	"fmt"
)

func main() {
	var a, b int
	fmt.Scanf("%d %d", &a, &b)

	if a == 1 {
		a = 14
	}
	if b == 1 {
		b = 14
	}

	ans := "Draw"
	if a > b {
		ans = "Alice"
	} else if a < b {
		ans = "Bob"
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 100000000;
#define rep1(i, n) for (ll i=0; i<(n); i++) 
#define rep2(i, k, n) for (ll i=k; i<(n); i++)
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; }

vector<ll> IntegerToVector(ll bit, ll N) {
    vector<ll> S;
    for (ll i = 0; i < N; ++i) {
        if (bit & (1 << i)) S.push_back(1);
        else S.push_back(0);
    }
    return S;
}

int main() {
    ll s;
    cin >> s;
    vector<ll> num;
    while (s>0){
        num.push_back(s%10);
        s /= 10;
    }
    reverse(num.begin(), num.end());
    ll ans = 0;
    ll N = num.size() - 1;
    for (ll bit = 0; bit < (1 << N); ++bit) {
        // どれを選ぶか
        vector<ll> S = IntegerToVector(bit, N);
        S.push_back(1);
        // 部分集合に対応する総和
        ll add = 0;
        for (ll i=0; i<(N+1); i++){
            add = add*10 + num[i];
            if (S[i]==1){
                ans += add;
                add = 0;
            }
        }
    }
    cout << ans << endl;
    //printf("%.12f", ans);
}

Measured memory_bytes: 3620
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>
#include <cmath>

auto & in = std::cin;
auto& out = std::cout;
#define all_range(C) std::begin(C), std::end(C)
const double PI = 3.141592653589793238462643383279502884197169399375105820974944;



template<typename T, typename U>
std::enable_if_t<std::rank<T>::value == 0> fill_all(T & arr, const U & v) {
	arr = v;
}
template<typename ARR, typename U>
std::enable_if_t<std::rank<ARR>::value != 0> fill_all(ARR & arr, const U & v) {
	for (auto& i : arr) {
		fill_all(i, v);
	}
}

int32_t N;

constexpr int64_t INF = 2500100000;

#include <queue>
#include <vector>
#include <functional>
#include <utility>
#include <algorithm>
#include <iterator>

struct edge {
	uint32_t to;
	int64_t cost;
	edge() {}
	edge(uint32_t to_, int64_t cost_)
		:to(to_), cost(cost_) {}
};


std::vector<edge> graph[2500];
std::vector<edge> graph2[2500];
int64_t dist[2500];
int64_t dist2[2500];


int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);
	in.tie(nullptr);
	out.tie(nullptr);

	int32_t M, P;
	in >> N >> M >> P;
	for (int32_t i = 0; i < M; i++)
	{
		int a, b, c;
		in >> a >> b >> c;
		--a;
		--b;
		c = P - c;
		graph[a].emplace_back(b, c);
		graph2[b].emplace_back(a, c);
	}

	fill_all(dist2, INF);
	dist2[N-1] = 0;
	for (int i = 0; i < 3 * N; i++)
	{
		for (int32_t from = 0; from < N; from++)
		{
			if (dist2[from] == INF) { continue; }
			for (auto& e : graph2[from]) {
				auto newdiff = dist2[from] + e.cost;
				if (dist2[e.to] > newdiff) {
					dist2[e.to] = newdiff;
				}
			}
		}
	}

	fill_all(dist, INF);
	dist[0] = 0;
	for (int i = 0; i < 3 * N; i++)
	{
		for (int32_t from = 0; from < N; from++)
		{
			if (dist[from] == INF) { continue; }
			for (auto& e : graph[from]) {
				auto newdiff = dist[from] + e.cost;
				if (dist[e.to] > newdiff) {
					dist[e.to] = newdiff;
					if (i > 2* N && dist2[e.to] != INF) {
						out << "-1\n"; return 0;
					}
				}
			}
		}
	}

	if (dist[N - 1] == INF) {
		out << "-1\n"; return 0;
	}
	out << std::max<int64_t>(0, -dist[N - 1])<<"\n";

	return 0;
}
#endif


Measured memory_bytes: 768
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;
using System.Numerics;

class Myon
{
    //chokudaiさんのコードをコピペ
    static Scanner cin;
    public Myon() { }
    public static int Main()
    {
        //Console.SetOut(new Printer(Console.OpenStandardOutput()));
        cin = new Scanner();
        new Myon().calc();
        Console.Read();

        return 0;
    }


    public void calc()
    {
        int n = cin.nextInt();
        string s = cin.next();
        int brktfall = 0;
        for (int i = 0; i < s.Length; i++) if (s[i] == '(') brktfall++;
            label:

        int tempF = 0;
        int tempB = 0;
        for (int i = 0; i < s.Length; i++)
        {
            if (s[i] == '(') tempF++;
            else tempB++;
            if (tempB > tempF)
            {
                s = "(" + s; goto label;
            }
        }
        while(tempF != tempB)
        {
            s += ")"; tempB++;
        }

        showL(s);

    }

    

    public void backetSort(ref int[] a)
    {
        //max a << a.len に対して有効なソート
        //よってa = int[] とする
        long n = a.Length;
        var count = new int[n];
        var loc = new long[n];//loc[i] は i が終わる 位置 max index where c[index] = loc[i]
        for (long i = 0; i < n; i++) count[a[i]]++;
        loc[0] = count[0] - 1;
        for (long i = 0; i < n-1; i++) loc[i+1] = loc[i] + count[i+1]; 
        long index = 0;

        for(int i = 0; i < n; i++)
        {
            while (index <= loc[i]) a[index++] = i; //incex <= loc[i] == index < loc[i] + 1
        }
    }

    public static void showL(long n) { Console.WriteLine(n); }
    public static void showL(string s) { Console.WriteLine(s); }
}

class Printer : StreamWriter
{
    public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } }
    public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) { }
    public Printer(Stream stream, Encoding encoding) : base(stream, encoding) { }
}

class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        while (i >= s.Length)
        {
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
        }
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }

}

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

int main(){
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  cout << max(a*b,c*d) << endl;
  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long 
int F[2100010];

int Mul(int a, int b) {
	return ((a % mod) * (b % mod)) % mod;
}

void fact(void) {
	F[0] = 1;
	F[1] = 1;
	for (int i = 2; i <= 2100000; i++) {
		F[i] = Mul(i, F[i - 1]);
	}
}
int square(int x) {
	return (x * x) % mod;
}

int power(int x, int y) {
	if (y == 0) return 1;
	else if (y == 1) return x % mod;
	else if (y % 2 == 0) return square(power(x, y / 2)) % mod;
	else return square(power(x, y / 2)) * x % mod;
}

int Div(int a, int b) {
	return Mul(a, power(b, mod - 2));
}
int P(int n, int r) {
	if (n < r || n < 0 || r < 0) return 0;
	return Div(F[n], F[n - r]);
}

int C(int n, int r) {
	if (n < r || n < 0 || r < 0) return 0;
	int ret;
	ret = Div(F[n], Mul(F[n - r], F[r]));
	return ret;
}
int H(int n, int r) {
	if (n == 0 && r == 0) return 1;
	return C(n + r - 1, r);
}
int sum[100010];
signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    int x[100100];
    fact();
    rep(i, N) cin >> x[i];
    sum[0] = 1;
    rep(i, N - 1) sum[i + 1] = (sum[i] + Div(1, i + 2));

    int ans = 0;
    rep(i, N - 1) {
        ans = (ans + Mul(sum[i], x[i + 1] - x[i])) % mod;
    }
    cout << Mul(ans, F[N - 1]) << endl;

    return 0;
}


Measured memory_bytes: 18176
n=int(input())
a=[[list(map(int,input().split()))for _ in'_'*int(input())]for _ in'_'*n]
m=0
for i in range(2**n):
  *s,=map(int,bin(i)[2:].zfill(n))
  f=1
  for j,t in enumerate(a):
    if s[~j]:
      for x,y in t:f&=s[-x]==y
  m=max(m,sum(s)*f)
print(m)

Measured memory_bytes: 44760
/**
 *    author:  gzhffIThh
 *    created: 19.08.2020
**/
#include <bits/stdc++.h>

using namespace std;

const int N=300010;

int n,m,k,ll[N],hh[N];
int xx[N],yy[N];
bool vish[N],visl[N];

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  
  scanf("%d%d%d",&n,&m,&k);
  int mxh=0,mxl=0;
 	for(int i=1;i<=k;i++){
 		int x,y;scanf("%d%d",&x,&y);
 		xx[i]=x;yy[i]=y;
 		hh[x]++;mxh=max(mxh,hh[x]);
 		ll[y]++;mxl=max(mxl,ll[y]);
 	}
 	long long tmp=0,hx=0,lx=0;
 	for(int i=1;i<=n;i++){
 		if(hh[i]==mxh)vish[i]=1,hx++;
 	}
 	for(int i=1;i<=m;i++){
 		if(ll[i]==mxl)visl[i]=1,lx++;
 	}
 	for(int i=1;i<=k;i++){
 		if(vish[xx[i]]&&visl[yy[i]])tmp++;
 	}
 	printf("%d\n",mxh+mxl-(tmp==(lx*hx)));

  return 0;
}


Measured memory_bytes: 9028
import java.util.*;

public class Main {
public static void main(String[] args) {
		
		Scanner keyboard = new Scanner(System.in); 
		
		int N= keyboard.nextInt();
		int[] a = new int[N+1];
		
		for(int i = 1; i<N+1; i++) {
			a[i]= keyboard.nextInt();
		}
		
		int ans = 0;
		
		for(int j = 1; j<N+1; j++) {
			if(j%2 != 0 && a[j]%2 != 0) {
				ans++;
			}
		}
		
		System.out.print(ans);
		keyboard.close();	
		
	}
}


Measured memory_bytes: 35652
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    N = int(readline())

    if N == 3:
        print(2, 5, 63)
    elif N == 4:
        print(2, 5, 20, 63)
    else:
        res = []
        p = N // 8
        q = N % 8
        b = [2, 3, 4, 6, 8, 9, 10, 12]

        for i in range(p):
            res.extend(map(lambda x: x + 12 * i, b))

        d = {0: [], 1: [6], 2: [3, 9], 3: [3, 9, 6], 4: [3, 9, 2, 4], 5: [3, 9, 6, 2, 4],
             6: [3, 9, 6, 2, 4, 12], 7: [3, 9, 6, 2, 4, 8, 10]}
        res.extend(map(lambda x: x + 12 * p, d[q]))
        res.sort()

        print(*res)


if __name__ == '__main__':
    main()


Measured memory_bytes: 75380
import java.util.*;

class Main{
    public static void main(String[] args){
	Scanner s = new Scanner(System.in);
	int a,b;
	double log;

	while(s.hasNextInt()){

	    a=s.nextInt();
	    b=s.nextInt();

	    log=Math.log10(a+b+1);

	    System.out.printf("%.0f\n",Math.ceil(log));

	}

    }

}

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

int main(int argc, const char * argv[]) {



    cin.tie(0);
    ios::sync_with_stdio(false);

    /////////////////////
    // Write code below /
    /////////////////////
    char b;

    cin>>b;

    if(b=='A')cout<<"T"<<endl;
    if(b=='T')cout<<"A"<<endl;
    if(b=='G')cout<<"C"<<endl;
    if(b=='C')cout<<"G"<<endl;

    return 0;
}


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

int main() {
	int i,n,b;
	int ans=0;
	int a[n];
	cin>>n;
	
	for(i=0;i<n;i++){
		cin>>b;
		a[i]=b-1;
	}
	
	for(i=0;i<n;i++){
		if(a[a[i]]==i){
			ans++;
		}
	}
	
	cout<<ans/2<<endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

int main(){
    int N; cin >> N;
    vector<vector<int>> F(N, vector<int>(10)), P(N, vector<int>(11));

    for(int i=0; i<N; ++i) for(int j=0; j<10; ++j) cin >> F[i][j];
    for(int i=0; i<N; ++i) for(int j=0; j<11; ++j) cin >> P[i][j];

    ll ans = -(1LL<<59);

    for(int bit=1; bit<(1<<10); ++bit){
        ll tmp = 0;
        for(int shop=0; shop<N; ++shop){
            int cnt = 0;
            for(int i=0; i<10; ++i) if(bit&1<<i && F[shop][i]) ++cnt;
            tmp += P[shop][cnt];
        }
        chmax(ans, tmp);
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
const ll INF = 1e+14;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
 
void Yes(){
	cout<<"Yes"<<endl;
	exit(0);
}
 
void No(){
	cout<<"No"<<endl;
	exit(0);
}

int main(){
  ll N,M;
  cin>>N>>M;
  vector<ll> L;
  vector<ll> R;
  rep(i,M){
    ll a,b;
    cin>>a>>b;
    L.push_back(a);
    R.push_back(b);
  }
  
  sort(L.begin(),L.end());
  sort(R.begin(),R.end());
  ll ans;
  ans=R[0]-L[M-1]+1;
  if(ans<=0) ans=0;
  cout<<ans<<endl;
}
    
    

Measured memory_bytes: 2036