akhauriyash/Code-Regression huggingface dataset:
ary = Array.new(3, Array.new(3, nil) )

ary[0] = gets.split(' ').map(&:to_i).dup
ary[1] = gets.split(' ').map(&:to_i).dup
ary[2] = gets.split(' ').map(&:to_i).dup

#p ary                                                                                           

i=0
[*0..1].each{|j|
  a = ary[i][j] - ary[i][j+1]
  if (ary[i+1][j] - ary[i+1][j+1]) != a or (ary[i+2][j] - ary[i+2][j+1]) != a then
    puts 'No'
    exit
  end
  a = ary[j][i] - ary[j+1][i]
  if (ary[j][i+1] - ary[j+1][i+1]) != a or (ary[j][i+2] - ary[j+1][i+2]) != a then
    puts 'No'
    exit
  end
}

puts 'Yes'

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

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

const int INF = 1001001001;

int main(){
  int n; cin >> n;
  string s; cin >> s;
  s = 'L' + s;
  s = s + 'R';

  vector<int> ce(n+2), cw(n+2);
  ce[0] = 0;
  cw[0] = 0;
  REP(i, 1, n+1){
    if(s[i] == 'E') ce[i] = ce[i-1] + 1;
    else ce[i] = ce[i-1];
    if(s[i] == 'W') cw[i] = cw[i-1] + 1;
    else cw[i] = cw[i-1];
  }

  int res = INF;
  REP(i, 1, n){
    int cnt = cw[i-1] + (ce[n+1] - ce[i]);
    chmin(res, cnt);
  }

  cout << res << endl;

  return 0;
}


Measured memory_bytes: 2876
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define print(x)cout<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int main() {
  int n;
  cin >> n;
  vl a(n);
  rep(i,n)cin >> a[i];
  ll sum = 0;
  rep(i,n)sum^=a[i];
  rep(i,n){
    cout<<(sum^a[i])<<" ";
  }  
  cout<<endl;
  return 0;
}

Measured memory_bytes: 4792
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<P> vp;
typedef vector<PL> vpl;
typedef vector<vector<P>> vvp;
const int INF = 1001001001;
const ll LINF = 1e18;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define FORMAP(it, map) for(auto it = m.begin(); it != m.end(); it++)

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

bool p_comp_fs(const P p1, const P p2){ return p1.first < p2.first;};
bool p_comp_fg(const P p1, const P p2){ return p1.first > p2.first;};
bool p_comp_ss(const P p1, const P p2){ return p1.second < p2.second;};
bool p_comp_sg(const P p1, const P p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}


int main(){
    ll N, M; cin >> N >> M;
    vvb ok(N + 1, vb(N + 1, false));
    REP(i, M){
        ll a, b; cin >> a >> b; ok[a][b] = true; ok[b][a] = true;
    }
    
    vl v(N - 1); ll ret = 0;
    iota(v.begin(), v.end(), 2);
    do{
        bool flag = ok[1][v[0]];
        REP(i, N - 2){
            if(!ok[v[i]][v[i+1]]) flag = false;
        }
        if(flag) ret++;
    }while(next_permutation(v.begin(), v.end()));
    cout << ret << endstr;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <set>
#include <map>
#define SIZE 200005

using namespace std;

vector <int> vec[SIZE];
int dist[SIZE];
int n;

void dfs(int v,int p,int d)
{
	dist[v]=d;
	for(int i=0;i<vec[v].size();i++)
	{
		int to=vec[v][i];
		if(to!=p) dfs(to,v,d+1);
	}
}
int farthest(int v)
{
	dfs(v,-1,0);
	int mx=-1;
	for(int i=0;i<n;i++) mx=max(mx,dist[i]);
	for(int i=0;i<n;i++) if(dist[i]==mx) return i;
}
int main()
{
	scanf("%d",&n);
	for(int i=0;i<n-1;i++)
	{
		int a,b;
		scanf("%d %d",&a,&b);a--,b--;
		vec[a].push_back(b);
		vec[b].push_back(a);
	}
	int a=farthest(0);
	int b=farthest(a);
	puts(dist[b]%3==1?"Second":"First");
	return 0;
}


Measured memory_bytes: 24448
#include <bits/stdc++.h>
using namespace std;
int main(){
	int a,b;
	cin >> a >> b;
	int ans=1;
	ans*=b;
	for(int i=1;i<a;i++){
		ans*=b-1;
	}
	cout << ans << 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++)
using ll = long long;

int main(){
  int w, h, x, y;
  cin >> w >> h >> x >> y;
  double ans = (double)h*(double)w/2.0;
  int can = 0;
  if(2*x == w && 2*y == h) can = 1;
  printf("%.9f %d\n",ans,can);
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  set<char> t;
  for(int i=0; i<s.size(); i++){
    if(t.count(s[i])) {
      cout << "no" << endl;
      return 0;
    }
    t.insert(s[i]);
  }
  cout << "yes" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(void){
    int min, n, people = 0;
    string s;
    cin >> n;
    cin >> s;
    for (int i = 1; i < n; i++) {
        if (s[i] == 'E') people++;
    } // 一番左の人
    min = people;
    for (int i = 1; i < n; i++) {
        if (s[i - 1] == 'W') people++;
        if (s[i] == 'E') people--;
        if (people < min) min = people;
    }
    
    cout << min;
    return 0;
}


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

public class Main {
	public static void main(String[] args) throws IOException {
		
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str = br.readLine();
		//String str = "6 5";
		String[] num = str.split(" ", 0);
		int a = Integer.parseInt(num[0]);
		int b = Integer.parseInt(num[1]);

		if (a < b) {
			System.out.println("a < b");
		} else if (a > b) {
			System.out.println("a > b");
		} else {
			System.out.println("a == b");
		}
	}
}

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

using namespace std;

#define ll long long
#define f first
#define s second
#define vi vector<int>
#define vll vector<ll>
#define pii pair<int,int>
#define vpii vector<pair<int,int>> 
#define pb push_back

void solve() {
	int a,b,c;
	cin>>a>>b>>c;
	int k;
	cin>>k;
	int cnt=0;
	while(b<=a) {
		b*=2;
		cnt++;
	}
	while(c<=b) {
		c*=2;
		cnt++;
	}
	if(cnt>k) {
		cout<<"No\n";
	}
	else cout<<"Yes\n";
}

int main() {
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	//freopen("ou.txt","w",stdout);
	#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
    //cin>>t;
    while(t--) {
    	solve();
    }
    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
long n, p, b, w, all;
vector<long> xs;

int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    cin >> n >> p;
    for(int i = 0; i < n; ++i) {
      cin >> w >> b;
      // 平均値がpになるように定義。入ってる白と青の集合をw, bとすると
      // 平均値がpになる
      // => sum(w) / sum(w + b) * 100 >= p
      // => 100 * sum(w) >= p * sum(w + b)
      // => sum((100-p)*w - p*b) >= 0
      // まず平均値最低の状態から効率よく平均値を上げていくことを考える。
      all -= p * b; // 全員bを入れてしまった
      xs.push_back((100-p) * w + p * b);
    }
  
    sort(xs.rbegin(), xs.rend());
    for(int i = 0; i < n; ++i) {
      all += xs[i];
      if(all >= 0) {
        cout << i + 1;
        return 0;
      }
    }
    return 0;
}

Measured memory_bytes: 1528
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, n) for (int i = 0; i < n; i++)

using namespace std;
typedef long long ll;

int main() {
    int N;  cin >> N;
    ll W;   cin >> W;
    vector<ll> w(N), v(N);
    rep(i, N)
        cin >> w[i] >> v[i];
    ll w1 = w[0];

    vector<vector<ll> > c(4);
    rep(i, N) {
        c[w[i]-w1].push_back(v[i]);
    }
    rep(i, 4)
        sort(c[i].begin(), c[i].end(), greater<ll>());
    vector<vector<ll> > s(4);
    rep(i, 4) {
        int l = c[i].size();
        s[i].resize(l+1, 0);
        rep(j, l) {
            s[i][j+1] = s[i][j] + c[i][j];
        }
    }
    ll ans = 0;
    rep(i, c[0].size()+1) {
        rep(j, c[1].size()+1) {
            rep(k, c[2].size()+1) {
                rep(l, c[3].size()+1) {
                    if (w1*(i+j+k+l) + j+2*k+3*l > W)
                        continue;
                    ans = max(ans, s[0][i] + s[1][j] + s[2][k] + s[3][l]);
                }
            }
        }
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3548
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
from collections import deque
from fractions import gcd
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#############
# Main Code #
#############

N,M = inputIL()
l = inputIL()

s = sum(l)

count = 0
for i in l:
  if i >= s/4/M:
    count += 1

if count >= M:
  print('Yes')

else:
  print("No")


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

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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int K;
    cin >> K;
    int ans = 0;
    for (int i = 1; i <= K; ++i) {
        for (int j = 1; j <= K; ++j) {
            for (int k = 1; k <= K; ++k) {
                ans += gcd(gcd(i, j), k);
            }
        }
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
#define INF 999999999
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

using llong = long long;
using namespace std;

// long long gcd(long long a, long long b){
//     if (a < b){
//         a ^= b;
//         b ^= a;
//         a ^= b;
//     }
//     return b ? gcd(b, a % b) : a;
// }

// long long lcm(long long a, long long b){
//     return a * b / gcd(a, b);
// }

int main(){
    int n;
    cin >> n;
    vector<int> p(n),q(n);
    rep(i,n) cin >> p[i];
    rep(i,n) cin >> q[i];
    vector<int> a(n);
    rep(i,n) a[i] = i+1;
    
    map<vector<int>, int> mp;
    do{
        mp[a] = mp.size();
    }while(next_permutation(a.begin(),a.end()));
    cout << abs(mp[p]-mp[q]) << endl;
}


Measured memory_bytes: 5248
a1 = list(map(int,input().split()))
a2 = list(map(int,input().split()))
a3 = list(map(int,input().split()))

n = int(input())

a_1 = [a1[0], a2[0], a3[0]]
a_2 = [a1[1], a2[1], a3[1]]
a_3 = [a1[2], a2[2], a3[2]]

naname1 = [a1[0],a2[1],a3[2]]
naname2 = [a1[2],a2[1],a3[0]]

hit = []
for i in range(n):
    hit.append(int(input()))

yes = False

for bar in [a1, a2, a3, a_1, a_2, a_3, naname1, naname2]:
    if set(bar) <= set(hit):
        print('Yes')
        yes = True
        break

if not yes:
    print('No')

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

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

/* define const */
const long long INF = (1LL << 60);
/* end defineing */

int main()
{
    int h, w, hh, ww;

    cin >> h >> w >> hh >> ww;

    cout << (h - hh) * (w - ww) << endl;
}


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

int main(){
  int N;
  cin>>N;
  
  vector<int> A(N);
  
  for(int i=0;i<N;i++){
    cin>>A.at(i);
  }
   
    int sum=0;
    
    bool flag=false;
  
int max=0;
  
  for(int i=0;i<N;i++){
    if(max<A.at(i)){
      max=A.at(i);
    }
  }
  
      for(int j=0;j<max;j++){
    
    for(int i=0;i<N;i++){
      if(A.at(i)%2==0){
        A.at(i)=A.at(i)/2;
        
        if(i==N-1){
          sum++;
      }
      }
      else{
        flag=true;
        break;
      }
      }
      
      if(flag){
        break;
      }

      }
    
  
      cout<<sum<<endl;
    }
    

Measured memory_bytes: 256
import bisect
A, B, Q = map(int, input().split())
INF  = 10 ** 18
S = [-INF] + [int(input()) for _ in range(A)] + [INF]
T = [-INF] + [int(input()) for _ in range(B)] + [INF]

for _ in range(Q):
    x = int(input())
    s1 = bisect.bisect_left(S, x) -1 #自分の左側のindex
    s2 = s1 + 1 #自分の右側のindex
    t1 = bisect.bisect_left(T, x) -1 #自分の左側のindex
    t2 = t1 + 1 #自分の右側のindex
    res = 10 ** 18
    for s in [S[s1], S[s2]]:
        for t in [T[t1], T[t2]]:
            d1, d2 = abs(s-x) + abs(t-s), abs(t-x) + abs(s-t)
            res = min(res, d1, d2)
    print (res)

Measured memory_bytes: 14356
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cmath>
#include <list>
#include <bitset>
using namespace std;


#define MAX 500000
#define SENTINEL 2000000000
#define INFTY (1<<21)
#define NIL -1
#define WHITE 0
#define GRAY 1
#define BLACK 2

int main(){
  string S; cin >> S;
  int A[4];
  for (int i=0; i<4; i++){
    A[i] = S[i] - '0';
  }
  bool acc = false;
  char op1, op2, op3;
  for (int bit=0; bit<(1<<3); bit++){
    int ans = A[0];
    if (bit & 1){
      ans += A[1];
      op1 = '+';
    } else {
      ans -= A[1];
      op1 = '-';
    }
    if (bit & 2){
      ans += A[2];
      op2 = '+';
    } else {
      ans -= A[2];
      op2 = '-';
    }
    if (bit & 4){
      ans += A[3];
      op3 = '+';
    } else {
      ans -= A[3];
      op3 = '-';
    }
    if (ans == 7){
      cout << A[0] << op1 << A[1] << op2 << A[2] << op3 << A[3] << "=7" << endl;
      break;
    }
  }
  return 0;
}

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

#define FOR(i,a,n) for (int i = a; i < (int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define whole(f,x,...) ([&](decltype((x)) whole) { \
    return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
template<typename T> bool chmin(T &a, const T &b) {if (a > b) { a = b; return true; }return false;}
template<typename T> bool chmax(T &a, const T &b) {if (a < b) { a = b; return true; }return false;}

using ll = int_fast64_t;

constexpr ll INF = (1e9);
constexpr ll MOD = (1e9+7);

int main() {
  ll n; cin >> n;
  vector<vector<ll>> a(2, vector<ll>(n));
  REP(i,2) REP(j,n) cin >> a[i][j];
  ll ans = 0;
  FOR(i,1,n) {
    a[0][i] += a[0][i-1];
    a[1][n-i-1] += a[1][n-i];
  }
  REP(i,n) {
    chmax(ans, a[0][i] + a[1][i]);
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;

using ll = long long;

int main() {
	int N;
	cin>>N;
	vector<int> X(N);
	int min_v = INT_MAX;
	int max_v = INT_MIN;
	for (auto& x : X) {
		cin>>x;
		min_v = min(x, min_v);
		max_v = max(x, max_v);
	}

	int ans = INT_MAX;
	for (int i = min_v; i <= max_v;++i) {
		int t_ans = 0;
		for (int j = 0;j < N;++j) {
			t_ans += (X[j]-i) * (X[j]-i);
		}
		
		ans = min(ans, t_ans);
	}

	cout<<ans<<endl;
	return 0;
}


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

int main()
{
    ll h, n, sum = 0;

    cin >> h >> n;

    for(ll i = 0; i < n; i++){
        ll x;
        cin >> x;
        sum += x;
    }

    if(sum >= h) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
while True :
    a, op, b = map(str,input().split())
    if op  == "?" :
        break
    elif op == "+" :
        print(int(a) + int(b))
    elif op == "-" :
        print(int(a) - int(b))
    elif op == "*" :
        print(int(a) * int(b))
    elif op == "/" :
        print(int(a) // int(b))
    else :
        pass



Measured memory_bytes: 5592
N = input()
counter=0
counter += N.count('1')*1
counter += N.count('2')*2
counter += N.count('3')*3
counter += N.count('4')*4
counter += N.count('5')*5
counter += N.count('6')*6
counter += N.count('7')*7
counter += N.count('8')*8
counter += N.count('9')*9

if int(N) % counter == 0:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e6+5;
vector<ll> V;
int pre[maxn],a[maxn],b[maxn];
int main() {
    int n;cin>>n;
    n%=10;
    if(n==2||n==4||n==5||n==7||n==9) puts("hon");
    else if(n==3) puts("bon");
    else puts("pon");
    return 0;
}

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

int main(){

int A,B,C;
cin >> A >> B >> C;
if (min(min(A,B),C) == 5 &&  max(max(A,B),C) == 7){
  if( A+B+C == 17 ){
    cout << "YES" << endl;
    }
    else {
      cout << "NO" << endl;
      }
  }
  else {
    cout << "NO" << endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int Inf = 2100000010;
constexpr ll INF= 2000000000000000000;
constexpr ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<int,int> P;
typedef pair<int,P> PP;

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

ll mod(ll val, ll M) {
    val = val % M;
    if(val < 0) {
        val += M;
    }
    return val;
}

template<typename T>
T RS(T N, T P, T M){
    if(P == 0) {
        return 1;
    }
    if(P < 0) {
        return 0;
    }
    if(P % 2 == 0){
        ll t = RS(N, P/2, M);
        if(M == -1) return t * t;
        return t * t % M;
    }
    if(M == -1) {
        return N * RS(N,P - 1,M);
    }
    return N * RS(N, P-1, M) % M;
}

int main() {
    int N;
    cin >> N;
    vector<ll> vec(N);
    for(int i = 0;i < N;i++) {
        cin >> vec.at(i);
    }
    ll ret = 1000;
    for(int i = 0;i < N - 1;i++) {
        if(vec.at(i) < vec.at(i + 1)) {
            ret = ret % vec.at(i) + ret / vec.at(i) * vec.at(i + 1);
        }
    }
    cout << ret << endl;
}

Measured memory_bytes: 3528
#include<stdio.h>

int main(void)
{
        int r,g,b,sum;

        scanf("%d%d%d",&r,&g,&b);

        sum = r*100+g*10+b;

        if(sum%4)
                printf("NO\n");
        else
                printf("YES\n");

        return 0;
}


Measured memory_bytes: 128
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#include<limits.h>
#define SENTINEL INT_MAX

int A[500000],c=0;

void Merge(int left, int mid, int right){
	int i, j, k;
	int n1 = mid - left;
	int n2 = right - mid;
	int L[1000000], R[1000000];
	//L = (int *)malloc(sizeof(int)*n1);
	//R = (int *)malloc(sizeof(int)*n2);

	for (i = 0; i < n1;i++){
		L[i] = A[left + i];
	}
	for (i = 0; i < n2;i++){
		R[i] = A[mid + i];
	}
	L[n1] = SENTINEL;
	R[n2] = SENTINEL;
	i = 0;
	j = 0;
	for (k = left; k < right;k++){
		c++;
		if (L[i] <= R[j]){
			A[k] = L[i];
			i = i + 1;
		}else{
			A[k] = R[j];
			j = j + 1;
		}
	}
	//free(L);
	//free(R);
}

void Merge_Sort(int left, int right){
	int mid;
	if (left + 1 < right){
		mid = (left + right) / 2;
		Merge_Sort(left, mid);
		Merge_Sort(mid, right);
		Merge(left, mid, right);
	}
}

int main(){
	int i, j, k;
	scanf("%d",&i);
	for (j = 0; j < i;j++){
		scanf("%d",&A[j]);
	}

	Merge_Sort(0,j);

	
	for (i = 0; i < j; i++){
		printf("%d", A[i]);
		if (i < j - 1){
			printf(" ");
		}
	}
printf("\n%d\n",c);
return 0;
}

Measured memory_bytes: 5584
/**
 *    author:  FromDihPout
 *    created: 2020-09-01
**/

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


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    
    set<int> primes;
    bool pairwise = true;
    for (int i = 0; i < n; i++) {
        bool ok = true;
        int num = a[i];
        for (int x = 2; x * x <= a[i]; x++) {
            if (num % x == 0) {
                if (primes.count(x)) {
                    ok = false;
                    break;
                }
                primes.insert(x);
                while (num % x == 0) {
                    num /= x;
                }
            }
        }
        if (num > 1) {
            if (primes.count(num)) {
                ok = false;
            }
            else {
                primes.insert(num);
            }
        }
        
        if (!ok) {
            pairwise = false;
            break;
        }
    }
    if (pairwise) {
        cout << "pairwise coprime" << '\n';
        return 0;
    }
    
    int gcd = a[0];
    for (int i = 1; i < n; i++) {
        gcd = __gcd(gcd, a[i]);
    }
    if (gcd == 1) {
        cout << "setwise coprime" << '\n';
    }
    else {
        cout << "not coprime" << '\n';
    }
    return 0;
}

Measured memory_bytes: 7328
import copy
import sys
from bisect import bisect_left, bisect_right
from collections import ChainMap, Counter, deque, defaultdict, namedtuple
from fractions import gcd
from heapq import heappop, heappush
from itertools import accumulate
from math import ceil, floor, sqrt
from operator import itemgetter

# sys.setrecursionlimit(10**6)


M = 2019


def main():
    a, b = [int(x) for x in input().split(' ')]

    if 2019 <= (b - a):
        print(0)
        return

    a_q = a // M
    b_q = b // M

    if a_q != b_q:
        print(0)
        return

    a = a % M
    b = b % M

    m = M

    for i in range(a, b + 1):
        for j in range(i + 1, b + 1):
            m = min(m, (i * j) % M)

    print(m)


if __name__ == '__main__':
    main()


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

main(){
    int a,b,c,d;cin>>a>>b>>c>>d;a--;
    cout<<b-a+a/c-b/c+a/d-b/d+b/c*__gcd(c,d)/d-a/c*__gcd(c,d)/d;
}


Measured memory_bytes: 256
local mmi, mma = math.min, math.max
local n, t = io.read("*n", "*n")
local w, v = {}, {}
for i = 1, n do
  w[i], v[i] = io.read("*n", "*n")
end
local dp = {}
for i = 1, n - 1 do
  dp[i] = {}
  for j = 1, t do
    dp[i][j] = 0
  end
end
do
  for j = 1 + w[1], t do
    dp[1][j] = v[1]
  end
end
for i = 2, n - 1 do
  for j = 1, t do
    dp[i][j] = dp[i - 1][j]
  end
  local wi, vi = w[i], v[i]
  for j = 1, t - wi do
    dp[i][j + wi] = mma(dp[i][j + wi], dp[i - 1][j] + vi)
  end
end
local ret = dp[n - 1][t] + v[n]
local backtbl = {}
for i = 1, t do
  backtbl[i] = 0
end
for i = n, 2, -1 do
  local wi, vi = w[i], v[i]
  for j = t - wi, 1, -1 do
    backtbl[j + wi] = mma(backtbl[j + wi], backtbl[j] + vi)
  end
  if 2 < i then
    local cand = 0
    for j = 1, t do
      cand = mma(cand, dp[i - 2][j] + backtbl[t + 1 - j])
    end
    ret = mma(ret, cand + v[i - 1])
  else
    ret = mma(ret, v[1] + backtbl[t])
  end
end
print(ret)


Measured memory_bytes: 102700
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1000000007;
const ld PI = acos(-1);  
const ld EPS = 0.0000000001;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define REP(i, n) for(ll i=0; i<(ll)(n); i++)
#define REPD(i, n) for(ll i=n-1; 0<=i; i--)
#define FOR(i, a, b) for(ll i=a; i<(ll)(b); i++)
#define FORD(i, a, b) for(ll i=a; (ll)(b)<=i; i--)
#define ALL(x) x.begin(), x.end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define SUM(x) accumulate(ALL(x), 0LL);
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main(){
    int n;  cin >> n;
    
    vector<ll> a(n);
    REP(i, n){
        cin >> a[i];
    }
    sort(ALL(a));
    ll res=1;
    if(a[0]==0){
        res = 0;
    }else{
        REP(i, n){
            if(1000000000000000000/res<a[i]){
                cout << -1 << endl;
                return 0;
            }
            res *= a[i];
        }
    }
    cout << res << endl;
    
}

Measured memory_bytes: 4052
#include <algorithm>
#include <cmath>
#include <fstream>
#include <functional>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
#include <unordered_map>
 
 
using namespace std;
using ll = long long;
 
int main() {
	string s;
	int N;
	unordered_map<string, ll> hash;
	ll sum = 0;
 
	cin >> N;
 
	for (int i = 0; i < N; i++) {
		cin >> s;
		sort(s.begin(), s.end());
		hash[s]++;
	}
	
	for (auto itr = hash.begin(); itr != hash.end(); ++itr) {
		sum += itr->second * (itr->second - 1) / 2;
	}
 
	cout << sum;
 
	return 0;
}

Measured memory_bytes: 10660
n, m = map(int, input().split())
l = [list(map(int, input().split(' '))) for _ in range(m)]
#print(l)
for v in range(m):
    l[v].append(v)

l = sorted(l)
#print(n,m)
#print(l)

x = l[0][0]
y = 1

for i in range(m):
    if l[i][0] == x:
        l[i][1] = y
        y += 1
    else:
        y = 1
        l[i][1] = y
        y += 1
        x = l[i][0]
#print(l)
l = sorted(l, key=lambda x:(x[2]))
#print(l)
z = []
for j in range(m):
    z.append(str(l[j][0]).rjust(6,'0') + str(l[j][1]).rjust(6,'0'))
#z.sort()
for k in range(m):
    print(z[k])

Measured memory_bytes: 39212
#include "bits/stdc++.h"

using namespace std;

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

    bool ans = true;
    map<char, char> ma, ima;

    for (int i = 0; i < S.size(); ++i) {
        char s = S[i], t = T[i];
        if (ma.count(s)) if (ma[s] != t) ans = false;
        if (ima.count(t)) if (ima[t] != s) ans = false;
        ma[s] = t;
        ima[t] = s;
    }
    cout << (ans ? "Yes" : "No") << endl;
}

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

#define ll long long int
#define rep(i, a, n) for (ll i = a; i < n; i++)
#define repm(i, a, n) for (ll i = a; i >= n; i--)
#define INF 1e9
#define LINF 1e17
#define MOD (int)(1e9 + 7)
#define mod (int)(1e9 + 7)
#define pi 3.141592653589
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vll vector<ll>
#define vd vector<double>
#define vb vector<bool>
#define vs vector<string>
#define vii vector<vector<int>>
#define vllll vector<vector<ll>>
#define ALL(a) (a).begin(), (a).end()

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

void print(bool f)
{
    cout << (f ? "Yes" : "No") << endl;
}

void Print(bool f)
{
    cout << (f ? "YES" : "NO") << endl;
}

int main(void)
{
    ll h, w;
    cin >> h >> w;
    vs s(h);
    rep(i, 0, h) cin >> s[i];

    vllll down(h, vll(w)), left(h, vll(w)), up(h, vll(w)), right(h, vll(w));
    rep(i, 0, h)
    {
        rep(j, 0, w)
        {
            if (i != 0)
                down[i][j] = (s[i - 1][j] == '.') ? down[i - 1][j] + 1 : 0;
            if (j != 0)
                left[i][j] = (s[i][j - 1] == '.') ? left[i][j - 1] + 1 : 0;
        }
    }
    repm(i, h - 1, 0)
    {
        repm(j, w - 1, 0)
        {
            if (i != h - 1)
                up[i][j] = (s[i + 1][j] == '.') ? up[i + 1][j] + 1 : 0;
            if (j != w - 1)
                right[i][j] = (s[i][j + 1] == '.') ? right[i][j + 1] + 1 : 0;
        }
    }
    ll ans = 0;
    rep(i, 0, h)
    {
        rep(j, 0, w)
        {
            if (s[i][j] == '#')
                continue;
            ll sum = left[i][j] + right[i][j] + up[i][j] + down[i][j] + 1;
            ans = max(ans, sum);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 129664
n = int(input())
# マンハッタン距離
# 45度回転
z = []
w = []
for i in range(n):
    x, y = map(int, input().split())
    z.append(x + y)
    w.append(x - y)
z.sort()
w.sort()
print(max(z[-1]-z[0], w[-1]-w[0]))


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

struct UF{
 UL N;
 vector<pair<UL,LL>> V;
 void init(UL n){
  N=n; V.resize(N);
  rep(i,N) V[i]={i,0};
 }
 pair<UL,LL> root(UL a){
  if(V[a].first==a) return V[a];
  auto buf=root(V[a].first);
  buf.second+=V[a].second;
  return V[a]=buf;
 }
 void unite(UL r,UL s,LL h){
  auto R=root(r); r=R.first; h+=R.second;
  R=root(s); s=R.first; h-=R.second;
  if(r==s) return;
  V[s]={r,h};
 }
};

bool PtrCmp(int* l, int* r) {return *l<*r;}

int main() {
 UL N,Q; scanf("%u%u",&N,&Q);
 UF G; G.init(N);
 rep(q,Q){
  UL c; scanf("%u",&c);
  if(c==0){
   UL x,y,h; scanf("%u%u%u",&x,&y,&h);
   G.unite(x,y,h);
  }
  else if(c==1){
   UL x,y; scanf("%u%u",&x,&y);
   auto X=G.root(x);
   auto Y=G.root(y);
   if(X.first!=Y.first) printf("?\n");
   else printf("%lld\n",Y.second-X.second);
  }
 }
 return 0;
}



Measured memory_bytes: 4392
#include<bits/stdc++.h>
#define ll long long
#define mod  1000000007
using namespace std;
 
 
void testcase()
{
	ll n,c,i,x,y,f;
	c = 0;
	f = 0;
	cin>>n;
	for(i=0;i<n;i++)
	{
		cin>>x>>y;
		if(x==y)
			c++;
		else
			c = 0;
		if(c == 3)
		{
			f = 1;
			break;
		}
	}
	if(f==1)
		cout<<"Yes\n";
	else
		cout<<"No\n";
}
 
 
int main()
{
    ll t,test;
    //cin>>test;
    //for(t=0;t<test;t++)
        testcase();
}

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

#define trace(...) __f( #__VA_ARGS__ , __VA_ARGS__ )
template <typename Arg1>
void __f( const char* name , Arg1&& arg1 ) {
        cerr << name << " : " << arg1 << "\n";
}
template <typename Arg1, typename... Args>
void __f( const char* na , Arg1&& arg1 , Args&&... args ) {
        const char* c = strchr( na + 1 , ',' );
        cerr.write( na , c - na ) << " : " << arg1 << " , ";
        __f( c + 1 , args... );
}
#define endl "\n"
#define all(V) V.begin(),V.end()
#define Unique(V) sort(all(V)),V.erase(unique(all(V)),V.end())
#define IO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long long int LL;
typedef pair <int,int> pii;
const int MOD = 1e9 + 7;
const int inf = 1e9;
const double EPS = 1e-9;
const double PI = acos(-1.0);
const long long INF = 1e18;
const int N = 1e5 + 5;

int main( ) {
        IO;
        #ifdef LOCAL
            //freopen( "input.txt" , "r" , stdin );
        #endif // LOCAL
        int num;
        cin >> num;
        int x = num%100 , y = num/100;
        if( x >= 1 && x <= 12 && y >= 1 && y <= 12 ) {
                return cout << "AMBIGUOUS" << endl,0;
        }
        if( x >= 1 && x <= 12 ) return cout << "YYMM" << endl,0;
        if( y >= 1 && y <= 12 ) return cout << "MMYY" << endl,0;
        cout << "NA" << endl;
        return 0;
}










Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<cmath>
#define pb push_back
#define ld long double
#define mp make_pair
#define vl vector<ll> 
#define vd vector<double>
#define vld vector<long double>
#define ll long long int
#define pl pair<ll, ll>
#define all(a) a.begin(), a.end()
#define forr(i, n) for(ll i=0; i<n; i++) 
#define forr1(i, n) for(ll i=1; i<=n; i++)
using namespace std;
const ld PI =3.1415926535897923846;
const ll MOD = 1e9+7;
void solve()
{
   ll n;
   cin>>n;
   vl a(n);
   forr(i, n)
   {
       cin>>a[i];
   }
   sort(all(a));
   map<ll, ll> mp1;
   vector<bool> visited(n, false);
   for(ll i=0; i<n; i++)
   {
       if(i)
       {
           if(a[i]==a[i-1])
           {
               visited[i]=true;
               visited[i-1]=true;
           }
       }
       if(!i)
       {
           if(a[i]==a[i+1])
           {
               visited[i]=true;
               visited[i+1]=true;
           }
       }
       if(mp1.find(a[i])!=mp1.end())
       {
           visited[i]=true;
           continue;
       }
       ll num=a[i];
       mp1[num]++;
       for(ll x=num*2; x<=1000000; x+=num)
       {
           mp1[x]++;
       }
   }
   ll ans=0;
   forr(i, n)
   {
       if(!visited[i])
       ans++;
   }
   cout<<ans;
}
int main()
{
    ll test=1;
    //cin>>test;
    while(test--)
        solve();
}

Measured memory_bytes: 67316
require 'prime'
require 'set'
require 'tsort'
include Math
def max(a,b);              a > b ? a : b                              end
def min(a,b);              a < b ?  a : b                             end
def swap(a,b);             a, b = b, a                                end
def gif;                   gets.to_i                                  end
def gff;                   gets.to_f                                  end
def gsf;                   gets.chomp                                 end
def gi;                    gets.split.map(&:to_i)                     end
def gf;                    gets.split.map(&:to_f)                     end
def gs;                    gets.chomp.split.map(&:to_s)               end
def gc;                    gets.chomp.split('')                       end
def pr(num);               num.prime_division                         end
def digit(num);            num.to_s.length                            end
def array(s,ini=nil);      Array.new(s){ini}                          end
def darray(s1,s2,ini=nil); Array.new(s1){Array.new(s2){ini}}          end
def rep(num);              num.times{|i|yield(i)}                     end
def repl(st,en,n=1);       st.step(en,n){|i|yield(i)}                 end


ans = []
loop {
  n = gif
  break if n == 0
  st = []
  en = []
  rep n do
    s,e = gs
    stt = s.split(':').map(&:to_i)
    enn = e.split(':').map(&:to_i)
    st << stt[0]*60*60 + stt[1]*60 + stt[2]
    en << enn[0]*60*60 + enn[1]*60 + enn[2]
  end
  max = 0
  st.sort!
  en.sort!
  rep n do |i|
    tmp = 0
    repl i, n-1 do |j|
      if en[i] > st[j] && en[i] <= en[j]
        tmp += 1
        max = tmp if tmp > max
      end
    end
  end
  ans << max
}

puts ans

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

void print_vec(vector<int> vec)
{
  cout << "[";
  for (int i = 0; i < vec.size(); i++)
  {
    cout << vec.at(i);
    if (i < vec.size() - 1)
    {
      cout << ", ";
    }
  }
  cout << "]...size: " << vec.size() << endl;
}

int main()
{
  vector<pair<int, int>> vec;

  while (true)
  {
    int h, w;
    cin >> h >> w;
    if (h == 0 && w == 0)
    {
      break;
    }

    vec.push_back(make_pair(h, w));
  }

  for (auto &&v : vec)
  {
    int h = v.first;
    int w = v.second;

    rep(i, h)
    {
      rep(j, w)
      {
        if ((i % 2 == 0 && j % 2 == 0) || (i % 2 == 1 && j % 2 == 1))
        {
          printf("#");
        }
        else
        {
          printf(".");
        }
      }
      printf("\n");
    }
    printf("\n");
  }
}



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

int main() {
    int a, b;
    cin >> a >> b;
    if(a < b) {
        for(int i=0; i<b; ++i) cout << a;
        cout << '\n';
    } else {
        for(int i=0; i<a; ++i) cout << b;
        cout << '\n';
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main(void){
 
string s;
cin >> s;
if (s.size() == 2){
    cout << s << endl;
}
if (s.size() == 3){
    cout << s[2] << s[1] << s[0] << endl;
}
 
 
 return 0; 
}


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

struct Day{
    int a,b,c;
    void set(Day &d){
        this->a = d.a;
        this->b = d.b;
        this->c = d.c;
    }
} dp[2],a[2];

int main() {
    int n;
   	scanf("%d", &n);
	scanf("%d %d %d", &a[0].a , &a[0].b , &a[0].c);
    dp[0].set(a[0]);

    for (int i=1; i<n; i++){
		scanf("%d %d %d", &a[i%2].a , &a[i%2].b , &a[i%2].c);
        dp[i%2].a = max(dp[(i-1)%2].c + a[i%2].a , dp[(i-1)%2].b + a[i%2].a );
        dp[i%2].b = max(dp[(i-1)%2].c + a[i%2].b , dp[(i-1)%2].a + a[i%2].b );
        dp[i%2].c = max(dp[(i-1)%2].a + a[i%2].c , dp[(i-1)%2].b + a[i%2].c );
    }
    printf("%d", max(dp[(n-1)%2].a, max(dp[(n-1)%2].b, dp[(n-1)%2].c)));
}


Measured memory_bytes: 3800
import java.util.*;
 
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    String S = sc.next();
    char[] c = S.toCharArray();
    
    for(int i=0; i<S.length(); i++){
      c[i]= (char)((c[i]-'A'+N)%26+'A');
    }
    String str = "";
    System.out.println(str.valueOf(c));
  }
}

Measured memory_bytes: 35940
N=int(input())
import queue
que=queue.Queue()
que.put(3);que.put(5);que.put(7)
num=[3,5,7]
cnt=0
while not que.empty():
    v=que.get()
    for n in num:
        nv=v*10+n
        if nv<=N:
            que.put(nv)
            nv_str=str(nv)
            if "3" in nv_str and "5" in nv_str and "7" in nv_str and len(set(nv_str))==3:
                cnt+=1
print(cnt)


Measured memory_bytes: 4592
#include <iostream>

using namespace std;

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

    if (a <= b) 
    {
        for (int i = 0; i < b; i++) 
        {
            cout << a;
        }
    }
    else 
    {
        for (int i = 0; i < a; i++) 
        {
            cout << b;
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll N=pow(10,9)+7;

ll gcd(ll a, ll b){
    ll m,n;
    m=max(abs(a),abs(b));
    n=min(abs(a),abs(b));
    if(m%n==0) return n;
    else return gcd(m%n, n);
}

ll mod_pow2(ll n){
    if(n==0) return 1;
    else{
        ll k=(mod_pow2(n/2)*mod_pow2(n/2))%N;
        if(n%2==0) return k;
        else return(k*2)%N;
    }
}

int main(){
    ll n;
    cin >> n;
    ll bothzero=0;
    vector<ll> a(n),b(n);
    for(int i=0; i<n; i++){
        cin >> a.at(i) >> b.at(i);
        if(a.at(i)==0&&b.at(i)==0) bothzero++;
    }
    vector<pair<ll, ll>> I;
    for(int i=0; i<n; i++){
        pair<ll, ll> p;
        if(a.at(i)==0 && b.at(i)==0){
            continue;
        }
        else if (a.at(i)==0){
            p=make_pair(0,1);
        }
        else if(b.at(i)==0){
            p=make_pair(1,0);
        }
        else{
            ll g=gcd(a.at(i), b.at(i));
            p=make_pair(a.at(i)/g, b.at(i)/g);
            if(p.first<0){
                p.first *= -1;
                p.second *= -1;
            }
        }
        I.push_back(p);
    }
    map<pair<ll, ll>, pair<ll, ll>> m;
    for(int i=0; i<I.size(); i++){
        pair<ll, ll> p,p_inv;
        p=I.at(i);
        p_inv.first=p.second;
        p_inv.second=p.first;
        if(p_inv.first>0) p_inv.second*=-1;
        else if(p_inv.first<0) p_inv.first *=-1;
        if(m.count(p)){
            m.at(p).first++;
        }
        else if(m.count(p_inv)){
            m.at(p_inv).second++;
        }
        else{
            pair<ll, ll> q=make_pair(1,0);
            m[p]=q;
        }
    }
    ll ans=1;
    //cout << endl;
    for(pair<pair<ll, ll>, pair<ll, ll>> p:m){
        pair<ll, ll> q;
        q=p.second;
        //cout << p.first.first << " " << p.first.second << endl;
        //cout << q.first << " " << q.second << endl;
        ll k=(mod_pow2(q.first)+mod_pow2(q.second)-1)%N;
        ans= (ans*k)%N;
        //cout << ans << endl;
        //cout << endl;
        ans = ans%N;
    }
    ans = ans-1+bothzero;
    if(ans>=0) cout << ans%N << endl;
    else cout << ans+N << endl;
}

Measured memory_bytes: 24940
import java.util.Scanner;

public class Main {
	static int w;
	static int h;
	static int[][] map;
	static boolean[][] check;
	static int count;
	
	static void go(int i,int j) {
		if(!check[i][j]) {
			check[i][j] = true;
			if(i-1>=0 && map[i-1][j] == 1) go(i-1,j);
			if(i+1<h && map[i+1][j] == 1) go(i+1,j);
			if(j-1>=0 && map[i][j-1] == 1) go(i,j-1);
			if(j+1<w && map[i][j+1] == 1) go(i,j+1);
			if(i-1>=0 && j-1>=0 && map[i-1][j-1] == 1) go(i-1,j-1);
			if(i-1>=0 && j+1<w && map[i-1][j+1] == 1) go(i-1,j+1);
			if(i+1<h && j-1>=0 && map[i+1][j-1] == 1) go(i+1,j-1);
			if(i+1<h && j+1<w && map[i+1][j+1] == 1) go(i+1,j+1);
		}
	}

    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	while(true) {
    		w = Integer.parseInt(sc.next());
    		h = Integer.parseInt(sc.next());
    		if(w==0 && h==0) break;
    		map = new int[h][w];
    		check = new boolean[h][w];
    		for(int i=0;i<h;i++) {
    			for(int j=0;j<w;j++) {
    				map[i][j] = sc.nextInt();
    			}
    		}
    		count = 0;
    		for(int i=0;i<h;i++) {
    			for(int j=0;j<w;j++) {
    				if(map[i][j] == 1 && !check[i][j]) {
    					go(i,j);
    					count++;
    				}
    			}
    		}
    		System.out.println(count);
    	}
    }
}



Measured memory_bytes: 45484
#include<iostream>
#include<vector>

using namespace std;
int h, w, n;
char c[30][30];

bool hoge(int _i, int l, int r){
   char d[h][w];
   for(int i=0; i<h; i++){
      for(int j=0; j<w; j++){
         d[i][j]=c[i][j];
      }
   }
   swap(d[_i][l], d[_i][r]);
   while(1){
      //FallDown
      for(int j=0; j<w; j++){
         for(int i=0; i+1<h; i++){
            if(d[i+1][j]=='.')for(int k=i+1; k>0; k--){
               swap(d[k-1][j], d[k][j]);
            }
         }
      }
      //Finished?
      bool fin=true;
      for(int j=0; j<w; j++){
         fin&=(d[h-1][j]=='.');
      }
      if(fin) return true;
      //Find_Chain
      bool D[h][w];
      for(int i=0; i<h; i++){
         for(int j=0; j<w; j++){
            D[i][j]=0;
         }
      }
      for(int i=0; i<h; i++){
         for(int j=0; j+1<w; j++){
            int m=1;
            for(int k=j+1; k<w; k++){
               if(d[i][j]==d[i][k]&&d[i][j]!='.') m++;
               else break;
            }
            if(m>=n)for(int k=j; k<j+m; k++){
               D[i][k]=1;
            }
         }
      }
      for(int j=0; j<w; j++){
         for(int i=0; i+1<h; i++){
            int m=1;
            for(int k=i+1; k<h; k++){
               if(d[i][j]==d[k][j]&&d[i][j]!='.') m++;
               else break;
            }
            if(m>=n)for(int k=i; k<i+m; k++){
               D[k][j]=1;
            }
         }
      }
      //Found?
      bool f=false;
      for(int i=0; i<h; i++){
         for(int j=0; j<w; j++){
            f|=D[i][j];
         }
      }
      if(!f) return false;
      //Delete
      for(int i=0; i<h; i++){
         for(int j=0; j<w; j++){
            if(D[i][j]) d[i][j]='.';
         }
      }
   }
}

int main(){

   cin>> h>> w>> n;
   for(int i=0; i<h; i++){
      for(int j=0; j<w; j++){
         cin>> c[i][j];
      }
   }

   bool ok=false;
   for(int i=0; i<h; i++){
      for(int j=0; j+1<w; j++){
         ok|=hoge(i, j, j+1);
      }
   }

   cout<< (ok? "YES": "NO")<< endl;

   return 0;
}

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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP0(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REP1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)

typedef long long LL;
typedef pair<int, int> pii;

const int INTINF = 1e9;
const LL LLINF = 1e18;

void solve()
{
    int N;
    cin >> N;
    set<int> A;
    REP0(i, N)
    {
        int a;
        cin >> a;
        if (A.find(a) == A.end())
            A.insert(a);
        else
            A.erase(a);
    }
    cout << (int)A.size() << endl;
}

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(10);
    solve();
    return 0;
}

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

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

int main(){
	int n; scanf("%d",&n);
	vector<int> a(n);
	rep(i,n) scanf("%d",&a[i]);

	auto b=a;
	sort(b.begin(),b.end());

	int bad=0;
	rep(i,n){
		int idx=lower_bound(b.begin(),b.end(),a[i])-b.begin();
		if(i%2==0 && idx%2==1) bad++;
	}
	printf("%d\n",bad);

	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
using ll = long long;
const ll mod = 1000000007;
const ll INF = 100000000000000000LL;
signed main(){
    int a,b;
    cin>>a>>b;
    cout<<2*b-a<<endl;
}

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

int main(){
	int n;
	cin>>n;
	int op=0;
	for(int i=1;i<=n;i++){
		int x;
		cin>>x;
		if(i&1&&x&1){
			op++;
		}
	}
	cout<<op<<endl;
	return 0;
}

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


using namespace std;
const long long mod=1000000007;
#define max 10005
int main(){
    long n;
    cin >> n;
    long long f=1;
    for(int i=1; i<=n; i++){
      f = f*i;
      f = f%mod;
    }
    cout << f << endl;
    return 0;
}

Measured memory_bytes: 3544
def call(n):
    print "",
    i = 1
    while i <= n:
        x = i
        if x % 3 == 0:
            print str(i),
            i += 1
            continue

        while x:
            if x % 10 == 3:
                print str(i),
                break
            x /= 10
            
        i += 1
        
    print

n = int(raw_input())
call(n)


Measured memory_bytes: 4644