akhauriyash/Code-Regression huggingface dataset:
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    H,W,K = MI()
    grid = []
    for i in range(H):
        grid.append(ST())

    ans = [[0]*W for _ in range(H)]
    first = [[] for _ in range(H)]
    num = 0
    for i,row in enumerate(grid):
        for index,x in enumerate(row):
            if x=="#":
                first[i].append(index)
                num+=1
                ans[i][index] = num
    
    for h in range(H):
        # before = -1
        if first[h]:
            before = first[h][0]
        else:
            continue
        for w in range(W):
            # if before == -1:
                # pass ##後で考える()
            # else:
            if grid[h][w] == "#":
                before = w
            else:
                ans[h][w] = ans[h][before]
    
    for h in range(1,H):
        for w in range(W):
            if ans[h][w] == 0:
                ans[h][w] = ans[h-1][w]
    for h in range(H-1)[::-1]:
        for w in range(W):
            if ans[h][w] == 0:
                ans[h][w] = ans[h+1][w]
    for a in ans:
        print(*a)

    # print(["".join(a) for a in ans],sep="\n")      
if __name__ == '__main__':
    main()

Measured memory_bytes: 47964
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#pragma warning(disable : 4996)
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<time.h>
#include<random>
#include<array>
#include <regex>
using namespace std;
int main(void) {
	int n, x, y;
	cin >> n >> x >> y;
	vector<int> len_count(n);
	int temp_len_1 = -1;
	int temp_len_2 = -1;
	int max_len = n - 1 - (y - x - 1);
	for (int i = 1; i <= n - 1; i++) {//0 - n-2が1-(n-1)に対応
		for (int j = i+1; j <= n; j++) {//1-n-1が2―nに対応
			temp_len_1 = j - i;
			if (i <= x && y <= j) {//BPを含む
				temp_len_1 -= (y - x - 1);//これは必ず短い
			}
			
			temp_len_2 = abs(x - i) + 1 + abs(y - j);//ムリにでもBp使うルート
			temp_len_1 = min(temp_len_1, temp_len_2);

			len_count[temp_len_1]++;
		}		
	}
	for (int i = 1; i <= n - 1; i++) {
		cout << len_count[i] << endl;
	}
}

Measured memory_bytes: 256
using System;
using System.Linq;
class Program
{
  static void Main()
  {
    int n = int.Parse(Console.ReadLine());
    int[] p = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
    
    int count = 0;
    for (int i = 1; i <= n - 2; i++)
    {
      if ((p[i-1] - p[i]) * (p[i] - p[i+1]) > 0)
        count++;
    }
    
    Console.WriteLine(count);
  }
}

Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;

#define repr(i, n) for(int i = n; i >= 0; i--)
#define reprl(i, n) for(ll i = n; i >= 0; i--)
#define all(v) v.begin(), v.end()

const ll mod=1000000007;

int countBits(int in){
  int res=0;
  for(int i=0;i<10;i++){
    int msk=1<<i;
    if((in&msk)!=0){
      res++;
    }
  }
  return res;
}

template<typename T>
void show2dVector(vector<vector<T>>& v){
  for(int i=0;i<v.size();i++){
    int m=v[i].size();
    cout<<i<<" : ";
    for(int j=0;i<m;i++){
      cout<<v[i][j]<<" ";
    }
    cout<<endl;
  }
}

void bfs(const vector<vector<int>>&g, int v, vector<bool>& seen){
  seen[v]=true;
  cout<<v<<" ";
  for(auto next: g[v]){
    if(seen[next]){
      continue;
    }
    bfs(g,next,seen);
  }
}

bool dfs(vector<vector<int>> &g,int start,int goal,vector<bool>&seen){
  bool res=false;
  seen[start]=true;
  if(start==goal){
    return true;
  }
  for(auto next: g[start]){
    if(seen[next]){
      continue;
    }
    res=dfs(g,next,goal,seen);
    if(res){
      break;
    }
  }
  return res;
}

ll gcd(ll a,ll b) {
  return b? gcd(b,a%b): a;  
}
ll lcm(ll a,ll b) {
  return a*b/gcd(a,b);
}
bool isLowerCase(char c){
  return (c>='a'&&c<='z');
}
const string outputYesNo(bool ans){
  return (ans?"Yes":"No");
}
int main() {
  int n,m,x;cin>>n>>m>>x;
  vector<int> c(n);
  vector<vector<int>> a(n,vector<int>(m));
  for(int i=0;i<n;i++){
    cin>>c[i];
    for(int j=0;j<m;j++){
      cin>>a[i][j];
    }
  }
  ll ans=LLONG_MAX;
  int cnt=0;
  int mx=pow(2,n);
  for(int cnt=0;cnt<mx;cnt++){
    vector<int> sum(n,0);
    ll cost=0;
    for(int i=0;i<n;i++){
      if(((cnt>>i)&0x01)==0){
        continue;
      }
      cost+=c[i];
      for(int j=0;j<m;j++){
        sum[j]+=a[i][j];
      }
    }
    bool checker=true;
    for(int j=0;j<m;j++){
      if(sum[j]<x){
        checker=false;
        break;
      }
    }
    if(checker){
      ans=min(ans,cost);
    }
  }
  if(ans==LLONG_MAX){
    ans=-1;
  }
  cout<<ans<<endl;
  return 0;
}


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

int main()
{
  int n;
  cin >> n;
  vector<ll> a;
  ll cnt = 0;

  for (int i = 0; i < n; ++i)
  {
    ll tmp;
    cin >> tmp;
    a.push_back(tmp);
  }
  for (int i = 0; i < n - 1; ++i)
  {
    if (a[i] % 2 == 1 && a[i + 1])
    {
      cnt++;
      a[i]--;
      a[i + 1]--;
    }
  }
  for (int i = 0; i < n; ++i)
  {
    cnt += a[i] / 2;
  }
  cout << cnt << endl;

  return 0;
}


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

#define ll long long int
#define str string
#define sec .second

ll MOD = 1000000007,INFL = 1ll << 60,INF = 1 << 30;
ll A[100][100] = {};
ll X[1000000] = {};
ll rui[100002] = {},ruin[100002] = {};
int dy[]={0, 0, 1, -1},dx[]={1, -1, 0, 0};
vector <ll> v;
ll a = 0,b = 0,c = 0,n = 0,sum = 0, ma = INF,mi=-1;
pair<str,ll> S[1000];
bool an = false,bn = false;

int findDigits(int n) {
        int i = 0;
        while (n > 0) {

                X[i] = n%10;
                n /= 10;
                i++;
        }
        return i;
}


int main(){
        cin.tie(0);
        ios::sync_with_stdio(false);
        //Code Line
cin >> a >> b;
if(b == 1)cout << 0 << endl;
else cout << a - b << endl;

  //Code Line
        return 0;
}


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

int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i, 0, n) cin >> a[i];
    map<int, int> mp;
    rep(i, 0, n) mp[a[i]]++;
    vector<int> b;
    int sum = 0;
    for(auto i : mp){
        sum++;
        b.push_back(i.second);
    }
    sort(b.begin(), b.end());
    if(sum <= k) cout << 0 << endl;
    else{
        int ans = 0;
        rep(i, 0, sum - k) ans += b[i];
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 14368
#include <algorithm>
#include <cassert>
// #include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
// #include <random>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

/*
unsigned seed1 = std::chrono::system_clock::now().time_since_epoch().count();
mt19937 g1.seed(seed1);
*/
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<pii, pii> ppiipii;
typedef pair<int, ppiipii> pippiipii;
typedef pair<int, pii> pipii;
typedef pair<pii, int> ppiii;
typedef pair<int, ppiii> pippiii;
typedef pair<int, ll> pill;
typedef pair<int, double> pid;
// note to self, the below two triggers someone
typedef pair<ll, ll> pll;
typedef pair<ll, int> plli;
typedef long double ld;

char buf[100];
char ret[100];

int main() {
  scanf("%s", buf);
  int len = 0;
  for(int i = 0; i < strlen(buf); i++) {
    if(buf[i] == 'B') {
      if(len > 0) len--;
    }
    else {
      ret[len++] = buf[i];
    }
  }
  for(int i = 0; i < len; i++) {
    printf("%c", ret[i]);
  }
  printf("\n");
}


Measured memory_bytes: 384
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long a = sc.nextLong();
		long b = sc.nextLong();
		long prev = 0;
		long total = 0;
		for (int i = 0; i < n; i++) {
			long x = sc.nextLong();
			if (i == 0) {
				prev = x;
				continue;
			}
			total += Math.min((x - prev) * a, b);
			prev = x;
		}
		System.out.println(total);
	}
}


Measured memory_bytes: 50276
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <unordered_map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e15;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
typedef pair<ll,ll> P;
typedef pair<double,double> point;
const ll MAX = 200005;
constexpr ll nx[8] = {1,0,-1,0,1,-1,1,-1};
constexpr ll ny[8] = {0,1,0,-1,1,1,-1,-1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll x,y;
    cin >> x >> y;
    ll s = y-2*x;
    bool ok = 1;
    if (s < 0) ok = 0;
    else if (s%2) ok = 0;
    else if (x-s/2 < 0) ok = 0;
    Yes(ok);
}


Measured memory_bytes: 3648
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>
#include <set>
#include <unordered_map>

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}

using int64 = long long;
using P = pair<int64, int64>;

struct Sieve {
    int n;
    vector<int> f, primes;
    Sieve(int n=1):n(n), f(n+1) {
        f[0] = f[1] = -1;
        for (int64 i = 2; i <= n; ++i) {
            if (f[i]) continue;
            primes.push_back(i);
            f[i] = i;
            for (int64 j = i*i; j <= n; j += i) {
                if (!f[j]) f[j] = i;
            }
        }
    }
    bool isPrime(int x) { return f[x] == x;}
    set<int> factorList(int x) {
        set<int> res;
        while (x != 1) {
            res.insert(f[x]);
            x /= f[x];
        }
        return res;
    }
//    vector<P> factor(int x) {
//        vector<int> fl = factorList(x);
//        if (fl.size() == 0) return {};
//        vector<P> res(1, P(fl[0], 0));
//        for (int p : fl) {
//            if (res.back().first == p) {
//                res.back().second++;
//            } else {
//                res.emplace_back(p, 1);
//            }
//        }
//        return res;
//    }
    vector<pair<int64,int>> factor(int64 x) {
        vector<pair<int64,int>> res;
        for (int p : primes) {
            int y = 0;
            while (x%p == 0) x /= p, ++y;
            if (y != 0) res.emplace_back(p,y);
        }
        if (x != 1) res.emplace_back(x,1);
        return res;
    }
};

int main() {
    int n;
    cin >> n;
    vector a(n,0);
    for (int i=0; i<n; i++) cin >> a[i];

    Sieve si(1000001);
    unordered_map<int, bool> um;
    bool f = true;
    for (int i=0; i<n; i++) {
        set<int> s = si.factorList(a[i]);
        for (auto ss : s) {
            if (um[ss]) {
                f = false;
                break;
            }
            um[ss] = true;
        }
        if (!f) break;
    }
    if (f) {
        cout << "pairwise coprime" << endl;
        return 0;
    }

    int GCD = a[0];
    for (int i=1; i<n; i++) GCD = gcd(GCD, a[i]);
    if (GCD == 1) {
        cout << "setwise coprime" << endl;
        return 0;
    }

    cout << "not coprime" << endl;
}

Measured memory_bytes: 11220
function Main(input) {
  var s = 0;
  var result = input.split('');

  for (var i = 0; i < 4; i++) {
    if(result[i] === '+') {
      s++;
    } else if(result[i] === '-') {
      s--;
    }
  }
  console.log(s);
}

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


Measured memory_bytes: 7372
N=int(input())
A=list(map(int,input().split()))

l = r = 0
ans = 0
X = Y = A[0]
while 1:
    if X==Y:
        ans += r-l+1
        if r < N-1:
            r += 1
            X ^= A[r]
            Y += A[r]
        else:
            break
    else:
        X ^= A[l]
        Y -= A[l]
        l += 1
 
print(ans)

Measured memory_bytes: 24584
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int64_t A, B, C, K;
  cin >> A >> B >> C >> K;
  if(K % 2 == 1){
    cout << B-A << endl;
  }else{
    cout << A-B << endl;
  }
 
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long
using namespace std;
int main()
{
int n;
cin>>n;
int a[n];
for(int i=0;i<n;i++)
{
cin>>a[i];
}
int dp[n];
dp[0]=0;
dp[1]=abs(a[0]-a[1]);
for(int i=2;i<n;i++)
{
dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
}
cout<<dp[n-1]<<endl;
}


Measured memory_bytes: 1024
from collections import defaultdict
import sys
input = sys.stdin.buffer.readline
N = int(input())
ab = [list(map(int,input().split())) for i in range(N)]
cd = [list(map(int,input().split())) for i in range(N)]
ab.sort()
cd.sort()

g = defaultdict(list)

for c,d in cd:
    for a,b in ab:
        if a < c and b < d:
            g[c].append(a)
            g[a].append(c)

used = [False]*(2*N)
match = [-1]*(2*N)

def dfs(v):
    used[v] = True
    for nv in g[v]:
        nnv = match[nv]
        if nnv == -1:
            match[v] = nv
            match[nv] = v
            return True
        elif not used[nnv] and dfs(nnv):
            match[v] = nv
            match[nv] = v
            return True
    return False

ans = 0
for i in range(2*N):
    if match[i] == -1:
        used = [False]*(2*N)
        if dfs(i):
            ans += 1
    #print(match)

print(ans)








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

int n,m,p,a,b;

void dijkstra(int s,vector<vector<pair<double,int>>> &d,vector<double> &res){
        priority_queue<pair<double,int>,vector<pair<double,int>>,greater<pair<double,int>>> q;
        vector<int> used((1<<n)*m,0);
        res[s]=0;
        while(s!=-1){
            used[s]=true;
            for(int i=0;i<d[s].size();i++){
                if(!used[d[s][i].second]){
                    q.push(make_pair(d[s][i].first+res[s],d[s][i].second));
                }
            }
            s=-1;
            while(!q.empty()){
                auto p=q.top();
                q.pop();
                if(!used[p.second]){
                    s=p.second;
                    res[s]=p.first;
                    break;
                }
            }

        }

}

int main(){
    while(cin>>n>>m>>p>>a>>b,n){
        a--,b--;

        vector<int> t(n);
        vector<int> x(p),y(p);
        vector<double> z(p);
        for(int i=0;i<n;i++) cin>>t[i];
        for(int i=0;i<p;i++){
            cin>>x[i]>>y[i]>>z[i];
            x[i]--,y[i]--;
        }
        vector<vector<pair<double,int>>> d((1<<n)*m);
        for(int i=0;i<p;i++){
            for(int s=0;s<(1<<n);s++){
                for(int j=0;j<n;j++){
                    if(s & (1<<j)){
                        d[s*m+x[i]].push_back(make_pair(z[i]/t[j],(s-(1<<j))*m+y[i]));
                        d[s*m+y[i]].push_back(make_pair(z[i]/t[j],(s-(1<<j))*m+x[i]));
                    }
                }
            }
        }
        vector<double> res((1<<n)*m,1e18);
        dijkstra(((1<<n)-1)*m+a,d,res);
        double respo=1e18;
        for(int i=0;i<(1<<n);i++){
            respo=min(respo,res[i*m+b]);
        }
        cout<<fixed<<setprecision(10);
        if(respo>1e17) cout<<"Impossible"<<endl;
        else cout<<respo<<endl;

    }
}

Measured memory_bytes: 36736
using System;

namespace B
{
    class Program
    {
        static void Main(string[] args)
        {
            var nk = Console.ReadLine().Split(' ');
            var n = int.Parse(nk[0]);
            var k = int.Parse(nk[1]);
            var strs = new string[k][];
            for(int i = 0; i < k; i++)
            {
                Console.ReadLine();
                strs[i] = Console.ReadLine().Split(' ');
            }
            var sunukes = new int[n + 1];
            sunukes[0]++;
            foreach(string[] ss in strs)
            {
                foreach(string str in ss)
                {
                    sunukes[int.Parse(str)]++;
                }
            }
            var count = 0;
            foreach(int num in sunukes)
            {
                if(num == 0)
                {
                    count++;
                }
            }
            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 27712
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<bitset>
#include<queue>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
typedef long long ll;
int main(){
	int a,b;
	cin >> a>>b;
	int cnt = 0;
	FOR(i,a,b+1){
		string s = to_string(i);
		if (s[0]==s[4]&&s[1]==s[3]) cnt++;
	}
	cout << cnt << endl;
	return 0;
}


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

int main(void){
    int N;
    cin>>N;
    vector<ll> a(N);
    rep(i,N)cin>>a[i];
    sort(all(a));
    int cnt=0;
    ll area=1;
    for(int i=N-1;i>0;i--){
        if(a[i]==a[i-1]){
            area*=a[i];
            i--;
            cnt++;
        }
        if(cnt==2)break;
    }

    if(cnt<2)cout<<0<<endl;
    else cout<<area<<endl;

    return 0;
}


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

int main()
{
    int N;cin>> N;
    vector<int> num(N,0);
    int a;
    for (int i=0;i<N-1;i++)
    {
        cin >> a;
        num[a-1]++;
    }
    for (int i=0;i<N;i++) cout << num[i] << endl;
    return 0;
}

Measured memory_bytes: 4048
//繝・Φ繝励Ξ
#include <bits/stdc++.h>
#define int long long
#define REP(i,n) for(int i = 0; i < (n); ++i)
#define FOR(i,a,b)  for(int i = (a); i <= (b); ++i)
#define ALL(v) (v).begin(),(v).end()
#define PAIR pair<int,int>
using namespace std;
//constexpr int MOD = 10e9+7;
//constexpr int INF = 1LL << 60;
template <class T> inline bool chmin(T& a, T b){if(a > b){ a = b; return 1;} return 0;}  
template <class T> inline bool chmax(T& a, T b){if(a < b){ a = b; return 1;} return 0;}  
//UP = 0;RIGHT = 1; DOWN = 2; LEFT =3;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) {
  if(a < b) gcd(b, a);
  int r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
//


int N;
int A[100000];
signed main (){
   ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
   cin >> N;
   REP(i,N)
   {
      cin >> A[i];
   }
   int g = A[0];
   REP(i,N)
   {
     g = gcd(g,A[i]); 
   }
   cout << g<<endl;
   //a + 5*k+13*l+8*m 縺ｨ陦ｨ縺帙ｋ繧ゅ・縺ｧ豁｣縺ｮ繧ゅ・縺ｮ譛蟆丞､縺檎ｭ斐∴縺ｫ縺ｪ繧・
}



//驛ｨ蛻・・譛蟆丞､
//譖ｴ譁ｰ縺励↑縺・ｴ蜷遺・邏ｯ遨阪ｏ
//莠梧ｬ｡蜈・↓縺励◆縺・・縺・ｂ縺呎ｳ・
//荳邂・園繧剃ｽ募屓繧よ峩譁ｰ縺励◆縺・・Segment Tree(縺溘□縺怜叙蠕涌(logN))
//遽・峇繧剃ｽ募屓繧よ峩譁ｰ縺励◆縺・・Lazy Segment Tree


Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        // TODO 自動生成されたメソッド・スタブ
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        String t = sc.next();

        int rtn = 0;
        for (int i = 0; i < s.length(); i++) {
            if (String.valueOf(s.charAt(i)).equals(String.valueOf(t.charAt(i)))) {
                continue;
            }
            rtn++;
        }
        System.out.println(rtn);
    }

}


Measured memory_bytes: 55024
#include <bits/stdc++.h>
#define rep(i,N) for (int i = 0; i < (N); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main(void){
  char x, y;
  cin >> x >> y;

  if (x == y){
    cout << '=' << endl;
  }else if (x < y){
    cout << '<' << endl;
  }else{
    cout << '>' << endl;
  }
}


Measured memory_bytes: 3560
function main(input) {
    input = input.trim().split("\n");
    var a = parseInt(input[0], 10);
    var b = parseInt(input[1], 10);
    var num = [1, 2, 3];
    var ans = num.filter(x => x !== a && x != b);
    console.log(ans[0]);
  }
   
  main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

const double EPS = 1e-10;
const ll INF = 100000000;
const ll MOD = 1000000007;

string s;

int main() {
    cin >> s;
    if (s.size() != 26) {
        for (int i = 0; i < 26; i++) {
            char a = (char)('a'+i);
            bool ok = true;
            rep(j,s.size()) {
                if (s[j] == a) {
                    ok = false;
                    break;
                }
            }
            if (ok) {
                cout << s << a << endl;
                return 0;
            }
        }
    } else {
        for (int i = 24; i >= 0; i--) {
            if (s[i] < s[i+1]) {
                rep(j,i) {
                    cout << s[j];
                }
                char x = 'z';
                for (int j = i+1; j < 26; j++) {
                    if (s[j] < s[i]) continue;
                    x = min(x, s[j]);
                }
                cout << x << endl;
                return 0;
            }
        }
        cout << -1 << endl;
    }
}
































Measured memory_bytes: 256
#include<cstring>
#include<iostream>
#include<string>
#include<vector>
#include<fstream>
#include<cmath>
#include<algorithm>
#define ll long long
using namespace std;
int n;
struct node
{
	int v=0;
	int cnt=0;
}o[100006],e[100006];
bool cmp(node a,node b)
{
	return a.cnt>b.cnt;
}
int main()
{	
    scanf("%d",&n);
    int lo=0,le=0,x;
    for(int i=1;i<=n;i++)
    {
    	scanf("%d",&x);
    	if(i%2)
		{
			o[x].v=x;
			o[x].cnt++;
		}
		else
		{
			e[x].v=x;
			e[x].cnt++;
		}
	}
	sort(o+1,o+100005,cmp);
	sort(e+1,e+100005,cmp);
	int ans;
	if(o[1].v==e[1].v)
	{
	 ans=min(n-o[2].cnt-e[1].cnt,n-o[1].cnt-e[2].cnt);
	}
	else
	{
		ans=n-o[1].cnt-e[1].cnt;
	}
	cout<<ans<<endl;
}

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

bool passed[101][101];
vector<pair<int,int> > d;
int cnt=0;

// Eº©çÔÉèµÄ¢­
void dfs(int x,int y,int left){
  // cèª0ÉÈÁ½çJEg
  if(left==0)
    cnt++;
  else{
    // »ÝÌêðè
    // à¤ÊßÏÝÈçAÖ
    if(passed[y][x]){
      int ny=y;
      int nx=x-1;
      if(nx<0){
	ny--;nx=3;
	if(ny<0)
	  return;
      }
      dfs(nx,ny,left);
    }
    else{
      // ÊßÏÝÅÈ¢ÈçAÜ¾ÇÁÅ«éÆ±ëð
      // ÇÁµAÄA
      passed[y][x]=true;
      for(int i = 0; i < d.size(); i++){
	int ny=d[i].first+y;
	int nx=d[i].second+x;
	// ÍÍàÅ é
	if(ny>=0&&nx>=0&&ny<4&&nx<4&&!passed[ny][nx]){
	  // ÊßÏÝÉ·é
	  passed[ny][nx]=true;
	  // »ÝÊuÌÌêÉÚ®µAÄA
	  int nny=y;int nnx=x-1;
	  if(nnx<0){
	    nny--;nnx=3;
	  }
	  dfs(nnx,nny,left-2);
	  // ³Éß·
	  passed[ny][nx]=false;
	}
      }
      passed[y][x]=false;
    }
  }
}

int main(){
  while(1){
    memset(passed,0,sizeof(passed));
    d.clear();cnt=0;
    for(int i = 0; i < 4; i++){
      int x,y;
      cin>>x;
      if(x>4)
	return 0;
      cin>>y;
      d.push_back(make_pair(-y,-x));
    }
    dfs(3,3,16);
    cout<<cnt<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
import           Control.Monad.State
import qualified Data.ByteString.Char8        as B
import qualified Data.Vector.Unboxed          as U
import qualified Data.Hashable                as H
import qualified Data.IntSet                  as S

type Parser a = StateT B.ByteString Maybe a

parseInt :: Parser Int
parseInt = StateT $ B.readInt . B.dropWhile ((==) ' ')

readParser :: Parser a -> IO a
readParser p = maybe (error "parser error") fst . runStateT p <$> B.getLine

main :: IO ()
main = do
  n  <- readParser parseInt
  ss <- U.replicateM n $ H.hash <$> B.getLine
  print $ solve ss

solve :: U.Vector Int -> Int
solve = S.size . U.foldr S.insert S.empty


Measured memory_bytes: 35384
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define mod 1000000007
ll ffact[222222];
ll fact(ll n){
  if(n <= 1) return 1;
  if(ffact[n]) return ffact[n];
  return ffact[n] = n*fact(n-1)%mod;
}
ll inv(ll x,ll m){
  ll ret = 1;
  ll k = x;
  for(ll i = m-2; i > 0; i>>=1){
    if(i&1){
      ret *= k;
      ret %= m;
    }
    k *= k;
    k %= m;
  }
  return ret;
}

ll h,w;
ll a,b;
int main(void){
  for(ll i = 0; i < 222222; i++) fact(i);

  cin >> h >> w >> a >> b;
  h--;w--;
  ll ans = fact(h+w)*inv(fact(h)*fact(w)%mod,mod)%mod;
  for(int i = 0; i < b; i++){
    ans = (ans - (fact(h-a+i)*inv(fact(h-a)*fact(i)%mod,mod)%mod) * (fact(a-1+w-i)*inv(fact(a-1)*fact(w-i)%mod,mod)%mod)%mod + mod)%mod;
  }
  cout << ans << endl;
}


Measured memory_bytes: 1920
#!/usr/bin/env python3
import sys

YES = "Yes"
NO = "No"

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

least = sum(A) / (4 * M)

B = sorted(A,reverse=True)

cnt = 0
for i in range(N):
    if B[i] >= least:
        cnt += 1
    else:
        break

if cnt >= M:
    print(YES)
else:
    print(NO)

Measured memory_bytes: 38384
import sys
import bisect

inf = 10**15
mod = 10**9+7

def getH(Cx, Cy, x, y, h):
    return h + abs(x-Cx) + abs(y-Cy)

inf = 10**15
mod = 10**9+7
n = int(input())
Hinfo = [list(map(int, input().split())) for i in range(n)]
H = -1
Hmax = inf
for Cx in range(101):
    for Cy in range(101):
        H = -1
        flag = True
        for tmp in Hinfo:
            x,y,h = tmp
            if h == 0:
                Hmax = getH(Cx, Cy, x, y, h)
            else:
                canH = getH(Cx, Cy, x, y, h)
                if H > 0:
                    if H != canH:
                        flag = False
                        break
                else:
                    H = canH
            if Hmax < H:
                flag = False
                break
        if Hmax >= H and flag:
            print('{} {} {}'.format(Cx, Cy, H))
            sys.exit()

Measured memory_bytes: 43244
n = int(input())
t = [int(m) for m in input().split()]
T = sum(t)
v = [int(m) for m in input().split()]
v.append(0)
#maxv[i]
maxv=[0]
#maxv = []
i = 0
cnt = 0
#for i in range(2*T):
while i < n:
    cnt += 0.5
    if t[i] == cnt:
        maxv.append(min(v[i],v[i+1]))
        i += 1
        cnt = 0
    else:
        maxv.append(v[i])
maxv[0] = 0
#maxv.append(0)
maxv[2*T] = 0

for i in range(1, 2*T+1):
    maxv[i] = min(maxv[i], maxv[i - 1] + 0.5)

for i in range(2*T-1, -1, -1):
    maxv[i] = min(maxv[i], maxv[i + 1] + 0.5)

ans = 0
for i in range(1, 2*T+1):
    ans += (maxv[i - 1] + maxv[i]) * 0.5 * 0.5

print(ans)

Measured memory_bytes: 3500
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;

int main()
{
    int n;
    vector<int> v;
    double ans;
    cin>>n;
    for (int i = 0; i < n; i++)
    {
        int v_tmp;
        cin>>v_tmp;
        v.push_back(v_tmp);
    }
    sort(v.begin(),v.end());
    ans=v[0];
    for (int i = 0; i < n-1; i++)
    {
        ans=(ans+v[i+1])/2;
    }
    
    printf("%lf\n",ans);
    return 0;
}

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

using i64 = int64_t;

std::vector<i64> g_ACC;

i64 range_sum(size_t begin, size_t end)
{
    return g_ACC[end] - g_ACC[begin];
}

i64 sumdiff(size_t begin, size_t div, size_t end)
{
    return std::abs(range_sum(begin, div) - range_sum(div, end));
}

size_t eqcut(size_t begin, size_t end, size_t hint, bool inc)
{
    size_t best_ix = hint;
    size_t best_diff = sumdiff(begin, hint, end);
    for (size_t ix = hint; inc ? ix < end : ix > begin; inc ? ix++ : ix--) {
        size_t diff = sumdiff(begin, ix, end);
        if (diff > best_diff) {
            break;
        } else {
            best_ix = ix;
            best_diff = diff;
        }
    }
    return best_ix;

}

int main()
{
    size_t n;
    std::cin >> n;
    g_ACC.push_back(0);
    for (size_t i = 0; i < n; i++) {
        i64 a;
        std::cin >> a;
        auto sum = g_ACC.back() + a;
        g_ACC.push_back(sum);
    }

    std::vector<size_t> left(n);
    std::vector<size_t> right(n);

    left[2] = 1;
    right[n - 2] = n - 1;

    for (size_t div = 3; div <= n - 2; div++) {
        left[div] = eqcut(0, div, left[div - 1], true);
    }

    /*
    for (size_t div = 2; div <= n -2; div++) {
        std::cout << div << ' ' << left[div] << ' ' << range_sum(0, left[div]) << ' ' <<  range_sum(left[div], div) <<  std::endl;
    }
    std::cout << "----------" << std::endl;
    */
    for (size_t rdiv = 3; rdiv <= n - 2; rdiv++) {
        size_t div = n - rdiv;
        right[div] = eqcut(div, n, right[div + 1], false);
    }
    /*
    for (size_t div = 2; div <= n -2; div++) {
        std::cout << div << ' ' << right[div] << ' ' << range_sum(div, right[div]) << ' ' <<  range_sum(right[div], n) << std::endl;
    }
    */

    i64 best = g_ACC.back();
    for (size_t div = 2; div <= n - 2; div++) {
        i64 p[4];
        p[0] = range_sum(0, left[div]);
        p[1] = range_sum(left[div], div);
        p[2] = range_sum(div, right[div]);
        p[3] = range_sum(right[div], n);

        i64 max = 0, min = g_ACC.back();
        for (size_t i = 0; i < 4; i++) {
            min = std::min(min, p[i]);
            max = std::max(max, p[i]);
        }

        best = std::min(best, max - min);
    }
    std::cout << best << std::endl;





    return 0;
}


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

#define debug(x) cerr << #x << ": " << x << endl
#define debugArray(x, n)                                                       \
    for(long long hoge = 0; (hoge) < (n); ++(hoge))                            \
    cerr << #x << "[" << hoge << "]: " << x[hoge] << endl
using namespace std;

using ll = long long;
using ull = unsigned long long;
const ll INF = LLONG_MAX / 2;
const ll MOD = 1e9 + 7;

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    string S;
    cin >> S;
    int cnt[2] = {};
    for(int i = 0; i < S.length(); i++) {
        cnt[S[i] - '0']++;
    }
    cout << min(cnt[0], cnt[1]) * 2 << endl;
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define VI vector<int>
#define VVI vector<vector<int>>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define MOD 1000000007
#define INF 1e9
#define All(x) (x).begin(), (x).end()
typedef long long ll;
using namespace std;

int to_i(string s) {
  int sum = 0, c = 1;
  for (int i = s.size() - 1; i >= 0; i--) {
    sum += (s[i] - '0') * c;
    c *= 10;
  }
  return sum;
}

int main() {
  int a, b;
  cin >> a >> b;
  string s = to_string(a) + to_string(b);
  int sum = to_i(s);
  double c = sqrt(sum);
  if (c == (int)c)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}

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

using namespace std;

int main(){

  long N,A,B,t,s,ans;
  bool can;
  can=false;
  //  string S,A;
  
  cin>>N>>A>>B;
  
  t=N/(A+B);
  s=N-(A+B)*t;
  ans=t*A;
  if(s>A)ans+=A;
  else ans+=s;
  cout<<ans<<endl;
   return 0;
}


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

using ll = long long;
using pii = pair<ll, ll>;
using vi = vector<ll>;
using vvi = vector<vi>;

template <class T>
using max_heap = priority_queue<T>;
template <class T>
using min_heap = priority_queue<T, vector<T>, greater<T>>;

template <class T, class U>
void chmax(T &a, U b) {
    if (a < b) a = b;
}
template <class T, class U>
void chmin(T &a, U b) {
    if (b < a) a = b;
}

#define rep(i, j) for (int i = 0; i < j; i++)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
#define debug(x) cerr << #x << ": " << x << endl;
#define int ll

const ll mod = 1e9 + 7;
const ll inf = (1LL << 50);

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;

    string S;
    int Q;
    cin >> S >> Q;

    deque<char> deq;
    for (auto c : S) deq.push_back(c);
    vector<char> pre, suf;
    int flag = 1;
    while (Q--) {
        int t;
        cin >> t;
        if (t == 1)
            flag *= -1;
        else {
            int f;
            char c;
            cin >> f >> c;
            int flag2 = f == 1 ? 1 : -1;
            if (flag * flag2 > 0)
                deq.push_front(c);
            else
                deq.push_back(c);
        }
    }

    string ans = "";
    for (auto c : deq) ans += c;
    if (flag < 0) {
        reverse(all(ans));
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1368
package main

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

// main is...
func main() {
	var n int
	fmt.Scanln(&n)

	var sc = bufio.NewScanner(os.Stdin)
	// var list = make([]string, n)
	// var listInt = make([]int64, n)
	var list = make([]int, n)

	sc.Split(bufio.ScanWords)
	// if sc.Scan() {
	// 	list = strings.Fields(sc.Text())
	// }

	// for idx, value := range list {
	// 	valueInt, _ := strconv.Atoi(value)
	// 	// valueInt, _ := strconv.ParseInt(value, 10, 64)
	// 	listInt[idx] = valueInt
	// }

	for idx := range list {
		if sc.Scan() {
			valueInt, _ := strconv.Atoi(sc.Text())
			// valueInt, _ := strconv.ParseInt(value, 10, 64)
			list[idx] = valueInt
		}
	}

	max, tmp := 0, 0
	for i := n - 1; i > 0; i-- {
		if list[i-1] >= list[i] {
			tmp++
		} else {
			tmp = 0
		}

		if tmp > max {
			max = tmp
		}
	}
	// for i := 1; i < n; i++ {
	// 	if list[i-1] >= list[i] {
	// 		tmp++
	// 	} else {
	// 		tmp = 0
	// 	}

	// 	if tmp > max {
	// 		max = tmp
	// 	}
	// }
	fmt.Println(max)

}



Measured memory_bytes: 3072
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

/**
 * Created by zzt on 17-1-16.
 */
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int K = scanner.nextInt();
        int L = scanner.nextInt();

        UnionFind road = new UnionFind(N);
        UnionFind railway = new UnionFind(N);

        for (int i = 0; i < K; i++) {
            road.union(scanner.nextInt() - 1, scanner.nextInt() - 1);
        }
        for (int i = 0; i < L; i++) {
            railway.union(scanner.nextInt() - 1, scanner.nextInt() - 1);
        }
        Map<Long, Integer> count = new HashMap<>();
        for (int i = 0; i < N; i++) {
            long key = (long) road.find(i) * N +railway.find(i);
            if (count.containsKey(key))
                count.put(key, count.get(key) + 1);
            else
                count.put(key, 1);
        }
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < N; i++) {
            long key = (long) road.find(i) * N +railway.find(i);
            sb.append(count.get(key)).append(" ");
        }
        System.out.println(sb);
    }

    static class UnionFind {
        private int[] id;
        private int count;
        private int[] sz;

        public UnionFind(int n) {
            count = n;
            id = new int[n];
            sz = new int[n];
            for (int i = 0; i < n; i++) {
                id[i] = i;
                sz[i] = 1;
            }
        }

        public int count() {
            return count;
        }

        public boolean connected(int p, int q) {
            return find(p) == find(q);
        }

        public int find(int p) {
            while (p != id[p]) {
                id[p] = id[id[p]];
                p = id[p];
            }
            return p;
        }

        public void union(int p, int q) {
            int i = find(p);
            int j = find(q);

            if (i == j)
                return;
            if (sz[i] < sz[j]) {
                id[i] = j;
                sz[j] += sz[i];
            } else {
                id[j] = id[i];
                sz[i] += sz[j];
            }
            count--;
        }
    }
}

Measured memory_bytes: 106128
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <utility>
#include <iomanip>  // std::setprecision()
using namespace std;
using ll = long long;
#define rep(i,a,b) for(int i=(a); i<(b); i++)
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define yes cout << "Yes" << endl;
#define no cout << "No" << endl;
ll gcd(ll a, ll b){if (a%b == 0)  return(b);else  return(gcd(b, a%b));}
ll lcm(ll a, ll b){return a * b / gcd(a, b);}
/* map<string,int> */
/* 大文字を小文字に変換 tolower*/
/* 小文字を大文字に変換 toupper*/
/* 辞書順 next_permutation(a.begin(),a.end()) */
 
int main() {
    int n,m;
    cin >> n >> m;
    vector <int> l(m+1);
    vector <int> r(m+1);
    int mi = 1000000 ,ma=0;
    rep(i,1,m+1) {
        cin >> l[i] >> r[i];
        ma = max(ma,l[i]);
        mi = min(mi,r[i]);
    }
    int ans =0;
    rep(i,1,n+1) {
        if (i >= ma && i <= mi) {
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
n,m=map(int,input().split())
s=eval('list(map(int,input().split()[1:])),'*m)
*p,=map(int,input().split())
a=0
r=range
for i in r(1<<n):
 c=[0]*m
 for j in r(n):
  for k in r(m):c[k]+=i>>j&1and j+1in s[k]
 a+=all(j==i%2for i,j in zip(c,p))
print(a)

Measured memory_bytes: 3064
import math

a,b,c=map(int,input().split())
s=a*b*math.sin(math.radians(c))/2
l=(a**2+b**2-2*a*b*math.cos(math.radians(c)))**(1/2)+a+b
h=2*s/a
print(s)
print(l)
print(h)


Measured memory_bytes: 5720
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<string, ll> Q;

void solve(long long N, vector<string> S, vector<long long> P){
	int res[N];
	for (int i=0; i<N; i++) {
		res[i] = i+1;
	}
	for (int i=0; i<N; i++) {
		for (int j=1; j<N-i; j++) {
			if (S[res[j-1]-1] > S[res[j]-1]) {
				// cout << "a: "<< res[j-1] << " " << res[j] << endl;
				swap(res[j-1], res[j]);
			} else {
				if (S[res[j-1]-1] == S[res[j]-1] && P[res[j-1]-1] < P[res[j]-1]) {
					// cout << "b: "<< res[j-1] << " " << res[j] << endl;
					swap(res[j-1], res[j]);
				}
			}
		}
	}
	for (int i=0; i<N; i++) {
		cout << res[i] << endl;
	}
}

int main(){	
	long long N;
	scanf("%lld",&N);
	vector<long long> P(N-1+1);
	vector<string> S(N-1+1);
	for(int i = 0 ; i <= N-1 ; i++){
		cin >> S[i];
		scanf("%lld",&P[i]);
	}
	solve(N, S, P);
	return 0;
}



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

pair<int,int> D[220];

int N, M, h, r;

int main() {

	while ( cin >> N && N ) {

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

			cin >> h >> r;
			D[i] = make_pair(h, r);

		}

		cin >> M;

		for ( int i = 0; i < M; i++) {

			cin >> h >> r;
			D[N+i] = make_pair(h, r);

		}

		sort(D,D+N+M);

		int A[200];
		
		A[0] = 0;

		for ( int i = 0; i < N + M; i++) {

			int maxaj = 0;
			
			for ( int j = 0; D[j].first < D[i].first; j++ ) {
			
				if ( D[j].second < D[i].second ) {
				
					maxaj = max( maxaj, A[j] );
				
				}
			
			}
			
			A[i] = 1 + maxaj;

		}
		
		int maxai = 0;

		for ( int i = 0; i < N + M; i++) {
			
			maxai = max( maxai, A[i] );
				
		}
		
		cout << maxai << endl;

	}

}

Measured memory_bytes: 1164
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<sstream>
#include<string>
#include<numeric>
using namespace std;
typedef long long ll;
//ll mod = 1e9+7;
ll mod = 998244353;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main(){
    int h, w, a, b;
    cin >> h >> w >> a >> b;
    rep(i, h) {
        rep(j, w) {
            if ( i < b && j < a ) {
                cout << 0;
            }
            else if ( i < b && j >= a ) {
                cout << 1;
            }
            else if ( i >= b && j < a ) {
                cout << 1;
            }
            else {
                cout << 0;
            }
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 1280
N = gets.to_i
arr = gets.split.map(&:to_i).sort
brr = gets.split.map(&:to_i).sort

AB = N % 2 == 0 ? 0 : arr.reduce(0){ |a,b| a ^= b } ^ brr.reduce(0){ |a,b| a ^= b }
rmask = ""
(0..28).to_a.reverse.each{ |i|
  mask = (1 << (i+1)) - 1
  arr.map!{ |a| a & mask }.sort!
  brr.map!{ |a| a & mask }.sort!
  #p mask, sarr, sbrr
  j = N-1
  carry = 0
  (0...N).each{ |i|
    while 0 <= j && arr[i] + brr[j] > mask
      j -= 1
    end
    #p [i,j]
    carry += N - j - 1
  }
  #p carry
  rmask += (carry % 2).to_s
}
rmask += "0"

puts AB ^ rmask.to_i(2)


Measured memory_bytes: 35432
#include<bits/stdc++.h>
using namespace std;
typedef double db;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pw(x) (1ll << (x))
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define rep(i,l,r) for(int i=(l);i<(r);++i)
#define per(i,l,r) for(int i=(r)-1;i>=(l);--i)
#define dd(x) cout << #x << " = " << x << ", "
#define de(x) cout << #x << " = " << x << endl
#define endl "\n"
//-----
const int N = 2e5 + 7;
int n, ans[N];
pii a[N];
int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	cin >> n; 
	rep(i, 0, n) cin >> a[i].fi, a[i].se = i;
	sort(a, a + n);
	int ans1 = a[n / 2 - 1].fi;
	int ans2 = a[n / 2].fi;
	rep(i, 0, n >> 1) ans[a[i].se] = ans2;
	rep(i, n >> 1, n) ans[a[i].se] = ans1;
	rep(i, 0, n) cout << ans[i] << endl;
	return 0;
}

Measured memory_bytes: 4608
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(int argc, char const *argv[]) {
    int n;
    cin >> n;
    vector<int> c(n-1);
    vector<int> s(n-1);
    vector<int> f(n-1);
    for (int i = 0; i < n-1; i++) cin >> c[i] >> s[i] >> f[i];
    for (int i = 0; i < n-1; i++) {
        int nowT;
        nowT = s[i]+c[i];
        for (int j = i+1; j < n-1; ++j) {
            if(nowT <= s[j]) nowT = s[j];
            else {
                int y = nowT/f[j];
                if (nowT%f[j] == 0) nowT = (f[j]*y);
                else nowT = f[j]*(y+1);
            }
            nowT+=c[j];
        }
        cout << nowT << std::endl;
    }
    cout << 0 << std::endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <ccomplex>
#include <vector>
#include <cassert>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <numeric>
#include <list>
#include <assert.h>
#include <math.h>
#include <valarray>
#include <stdio.h>
#include <algorithm>
#include <set>
#include <complex>
#include <list>
#include <time.h>
#include <stack>
#include <locale>
#include <clocale>
#include <ctype.h>
#include <wchar.h>
#include <random>
#include <vector>
#include <unordered_map>
#include <bitset>

using namespace std;
typedef long long int LL;
typedef long long int ll;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;

#define SORT(c) sort((c).begin(),(c).end())
#define BACKSORT(c) sort((c).begin(),(c).end(),std::greater<LL>())
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

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

  LL N;
  cin >> N;
  bool flag = false;
  REP(i,N){
    LL a;
    cin>>a;
    if(a%2!=0){
      flag=true;
    }
  }

  if(flag){
    cout << "first" << endl;
  }else{
    cout << "second" << endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define PI acos(-1)
typedef  long long ll;
ll gcd(ll x,ll y){
   if(y==0) return x;
   else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
   return x/gcd(x,y)*y;
}
using namespace std;

int main(){
   int n;
   cin>>n;
   vector<int> a(1000000,0);
   rep(i,n){
      int x;
      cin>>x;
      a[x]++;
   }
   
   ll ans=0;
   for(int i=0;i<100000;i++){
      ll kari=a[i]+a[i+1]+a[i+2];
      ans=max(ans,kari);
   }
   cout<<ans;


   
return 0;
}



Measured memory_bytes: 7164
($H,$W,$h,$w)=glob<>;
if($H%$h|$W%$w){
	print"Yes\n";
	for$y(0..$H-1){
		for$x(0..$W-1){
			print$x>0&&$",$x%$w|$y%$h?($x+1)%$w|($y+1)%$h?0:-1e9:9x9
		}
		print$/
	}
}else{
	print"No\n"
}


Measured memory_bytes: 3456
/*   _/                _/                 _/_/_/   _/
  _/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
   _/     _/    _/   _/     _/    _/  _/_/_/     _/
  _/     _/    _/   _/     _/    _/  _/    _/   _/
   _/_/   _/_/       _/_/   _/_/      _/_/     _/ */
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
using ll=long long;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=2e9;
const ll INF=1e18;
using P=pair<int,int>;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  int n,d[55]={},ans=0;
  cin >> n;
  for(int i=0; i<n; i++) {
    cin >> d[i];
  }
  for(int i=0; i<n; i++) {
    for(int j=i+1; j<n; j++) {
      ans+=d[i]*d[j];
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
a,b,c,d=[],[],[],[]
for _ in range(n):
    a_,b_=map(int,input().split())
    a.append(a_)
    b.append(b_)
for _ in range(m):
    c_,d_=map(int,input().split())
    c.append(c_)
    d.append(d_)

def mh(x,y,w,z):
    return abs(x-w)+abs(y-z)

for i in range(n):
    min_mh=mh(a[i],b[i],c[0],d[0])
    ansi=1
    for j in range(1,m):
        if min_mh > mh(a[i],b[i],c[j],d[j]):
            min_mh=mh(a[i],b[i],c[j],d[j])
            ansi=j+1
    print(ansi)


Measured memory_bytes: 3064