akhauriyash/Code-Regression huggingface dataset:
def rotate(id, l)->list:
    dir = ['S', '', 'WS', 'ES', 'SS', 'N']
    for o in dir[id]:
        l = [ l[int(k)] for k in list(s[o])]
    return l 

def search(j, i):
    lj = a[j]
    li = a[i]
    if len(set(lj) ^ set(li)) == 0: 
        at = 0
        for l in range(6): 
            if lj.count(lj[l]) == 1: 
                at = l
                break
        bt = li.index(lj[at]) 
        lj = rotate(at, lj)
        li = rotate(bt, li)
        for o in 'EEEE':
            lj = [ lj[int(k)] for k in list(s[o]) ]
            if li == lj: return True
    else: return False

s = {'E': '310542', 'W': '215043', 'S': '402351', 'N': '152304'}  # 東西南北
a = []
n = int(input())
i = 0
while i < n:
    a.append(list(map(int, input().split())))
    j = 0
    while j <= i-1: 
        if search(j, i): 
            print('No')
            i = n
            break 
        j+=1
    if i == n-1: print('Yes')
    i+=1


Measured memory_bytes: 5616
#include <iostream>
#include <vector>
#include <algorithm>
#define ll long long
using namespace std;

int main(){
    ll n, a;
    cin >> n >> a;
    string b;
    vector<string> d(n);
    for(auto &i: d) cin >> i;
    sort(d.begin(), d.end());
    string e;
    for(auto i:d) e += i;
    cout << e << endl;
    return 0;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
a=[0]*n
b=[0]*n
for i in range(m):
  p,s=input().split()
  p=int(p)-1
  if a[p]==0:
      if s=="AC":
        a[p]=1
      else:
        b[p]+=1
for i in range(n):
    if a[i]==0:
        b[i]=0
print(sum(a),sum(b))

Measured memory_bytes: 4596
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Runtime.InteropServices;
using System.Runtime.Remoting.Messaging;
using System.Security.Principal;
using System.Text;
class Simple
{
    int N;
    void Solve() {
        //input
        N = io.Int;
        //cal
        var x = 800 * N;
        var y = 200 * (N / 15);
        var ans = x - y;
        //ret
        Console.WriteLine(ans);
    }
    SimpleIO io = new SimpleIO();
    public static void Main(string[] args) => new Simple().Stream();
    void Stream() {
        //var exStdIn = new System.IO.StreamReader("stdin.txt");
        //System.Console.SetIn(exStdIn);
        Solve();
        io.writeFlush();
    }
}
class SimpleIO
{
    string[] nextBuffer;
    int BufferCnt;
    char[] cs = new char[] { ' ' };
    StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
    public SimpleIO() {
        nextBuffer = new string[0];
        BufferCnt = 0;
        Console.SetOut(sw);
    }
    public string Next() {
        if (BufferCnt < nextBuffer.Length) return nextBuffer[BufferCnt++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        BufferCnt = 0;
        return nextBuffer[BufferCnt++];
    }
    public string String => Next();
    public char Char => char.Parse(String);
    public int Int => int.Parse(String);
    public long Long => long.Parse(String);
    public double Double => double.Parse(String);
    public void writeFlush() { Console.Out.Flush(); }
}


Measured memory_bytes: 11092
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define INF 1<<30
#define LINF 1LL<<60
int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
	ll Q, H, S, D; cin >> Q >> H >> S >> D;
	ll N; cin >> N;
	ll min_two = INF, min_one = INF;
	min_two = min(8 * Q, min(4 * H, min(2 * S, D)));
	min_one = min(4 * Q, min(2 * H, S));
	if (N % 2 == 0) {
		cout << min_two * (N / 2) << endl;
	}
	else {
		cout << min_two *(N / 2) + min_one << endl;
	}
	
return		0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

	public static void main (String[] args)  {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int size = (int)Math.pow(2, n);
		int[] arr = new int[size];
		for (int i = 0; i < size; i++) {
			arr[i] = sc.nextInt();
		}
		Arrays.sort(arr);
		TreeMap<Integer, Integer> map = new TreeMap<>();
		int prev = arr[0];
		int count = 1;
		for (int i = 1; i < size; i++) {
			if (prev == arr[i]) {
				count++;
			} else {
				map.put(prev, count);
				count = 1;
			}
			prev = arr[i];
		}
		map.put(prev, count);
		PriorityQueue<Integer> queue = new PriorityQueue<Integer>(new Comparator<Integer>() {
		public int compare(Integer i1, Integer i2) {
			return i2.intValue() - i1.intValue();
		}
		});
		PriorityQueue<Integer> next = new PriorityQueue<Integer>(new Comparator<Integer>() {
		public int compare(Integer i1, Integer i2) {
			return i2.intValue() - i1.intValue();
		}
		});
		Map.Entry<Integer, Integer> en = map.lastEntry();
		if (en.getValue() != 1) {
			System.out.println("No");
			return;
		}
		queue.add(en.getKey());
		map.remove(en.getKey());
		for (int i = 0; i < n; i++) {
			while (queue.size() > 0) {
				int x = queue.poll();
				Map.Entry<Integer, Integer> entry = map.lowerEntry(x);
				if (entry == null) {
					System.out.println("No");
					return;
				}
				if (entry.getValue() == 1) {
					map.remove(entry.getKey());
				} else {
					map.put(entry.getKey(), entry.getValue() - 1);
				}
				next.add(x);
				next.add(entry.getKey());
			}
			PriorityQueue<Integer> tmp = queue;
			queue = next;
			next = tmp;
		}
		System.out.println("Yes");
	}
}


Measured memory_bytes: 93384
#include <iostream>
#include <vector>
#include <cmath>

int main()
{
	int n, m;
	std::cin >> n >> m;

	std::vector<std::pair< int, int > > s;
	for( int i = 0; i < n; i++ ) {
		int a, b;
		std::cin >> a >> b;
		s.push_back( std::make_pair( a, b ) );
	}

	std::vector<std::pair< int, int > > c;
	for( int i = 0; i < m; i++ ) {
		int a, b;
		std::cin >> a >> b;
		c.push_back( std::make_pair( a, b ) );
	}

	for( int i = 0; i < n; i++ ) {
		int t = 0, min = 0, minidx = 0;
		for( int j = 0; j < m; j++ ) {
			t = abs( s[ i ].first - c[ j ].first )
			+ abs( s[ i ].second - c[ j ].second );
			if( j == 0 ) {
				min = t;
				minidx = 0;
				continue;
			}

			if( t < min ) {
				min = t;
				minidx = j;
			}
		}
		std::cout << minidx + 1 << std::endl;
	}

	return 0;
}



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

void get_common_divisor(int vals[])
{
  int i, min, first;

  min = vals[0];
  if ( min > vals[1] ) min = vals[1];
  if ( min > vals[2] ) min = vals[2];

  for (i = 1; i <= min; i ++) {
    if ( vals[0] % i == 0 &&
	 vals[1] % i == 0 &&
	 vals[2] % i == 0 ) {
      printf("%d\n", i);
      first = 0;
    }
  }
}

int main()
{
  char line[256];
  int n, vals[3];

  fgets(line, 256, stdin);
  sscanf(line, "%d", &n);
  fgets(line, 256, stdin);
  if ( n == 2 ) {
    sscanf(line, "%d %d", vals+0, vals+1);
    vals[2] = vals[1];
  } else if ( n == 3 ) {
    sscanf(line, "%d %d %d", vals+0, vals+1, vals+2);
  }
  get_common_divisor(vals);

  return 0;
}



Measured memory_bytes: 2108
#include<bits/stdc++.h>
using namespace std;
int a[1010];string ans;
int main()
{
	long long n;
	cin>>n;
	while(n)
	{
		ans=(char)(97+(n-1)%26)+ans;
		n=(n-1)/26;
	} 
	cout<<ans;
	return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
using namespace std;

#define ll long long
#define pb push_back

int main(){

	int N,K;
	string D;
	cin>>N>>K;
	for(int i=0;i<K;i++){
		int d;
		cin>>d;
		D.pb('0'+d);
	}
	while(1){
		string num=to_string(N);
		bool flag=true;
		for(int i=0;i<num.size();i++){
			for(int j=0;j<K;j++){
				if(num[i]==D[j]){
					flag=false;
				}
			}
		}
		if(flag){
			cout<<N<<endl;
			break;
		}
		N++;
	}

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define rep(i, a, n) for(int i=a; i<n; i++)
#define ll long long
#define all(x) begin(x), end(x)
#define toInt(x) (x - '0')
#define pll pair<ll, ll>
#define pli pair<ll, int>
// #define int long long
const int inf = 1 << 30;
#define INF 1e+9
#define MAX_V 100008


int main(){
  int n; cin >> n;
  map<string, int> mp;
  rep(i, 0, n){
    string s; cin >> s;
    mp[s]++;
  }

  vector<string> cand = {"AC", "WA", "TLE", "RE"};
  for(int i=0; i<4; i++){
    cout << cand[i] << " x " << mp[cand[i]] << endl;
  }
}


Measured memory_bytes: 3636
import java.util.*;
import java.lang.*;

class Pair implements Comparable<Pair>{
  int a;
  int cnt;
  public Pair(int i, int j){
    this.a = i;
    this.cnt = j;
  }
  public int compareTo(Pair p){
    if(this.cnt == p.cnt) return 0;
    if(this.cnt<p.cnt) return -1;
    return 1;
  }
}

class Main{
  public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);
      int N = Integer.parseInt(sc.next());
      HashMap<Integer,Pair> map = new HashMap<>();
      ArrayList<Pair> l = new ArrayList<>();
      for(int i = 0; i<N; i++){
        int c = Integer.parseInt(sc.next());
        for(int j = 0; j<3; j++){
          if(j == 1) c--;
          else if(j == 2) c+=2;
          //System.out.println("i,c = "+i+" "+c);
          if(!map.containsKey(c)){
             Pair p = new Pair(c,1);
             map.put(c, p);
             l.add(p);
          }else{
            Pair p = map.get(c);
            p.cnt++;
          }
        }
      }
      Collections.sort(l);
      Pair res = l.get(l.size()-1);
      System.out.println(res.cnt);
  }
}

Measured memory_bytes: 56996
N, M = map(int, input().split())

if M >= 1:
    S = []
    C = []
    for _ in range(M):
        s, c = map(int, input().split())
        S.append(s)
        C.append(c)
else:
    if N == 3:
        print(100)
    elif N == 2:
        print(10)
    else:
        print(0)
    exit()

ans = [[] for _ in range(N)]

for i in range(M):
    ans[S[i]-1].append(C[i])

ans2 = []

for i in range(len(ans)):
    if len(set(ans[i])) > 1:
        print(-1)
        exit()
    if len(ans[i]) == 0:
        if i == 0:
            ans2.append(1)
        else:
            ans2.append(0)
        continue
    ans2.append(list(set(ans[i]))[0])

if ans2[0] == 0:
    if N == 1:
        print(0)
        exit()
    else:
        print(-1)
        exit()

print(''.join(map(str,ans2)))
    


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

using namespace std;
using ll = long long;
#define rep(i, n) for(ll i = 0; i < (ll)(n); ++i)
#define REP(i, n) for(ll i = n-1; i >= 0; i--)
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr << #x << " = " << x << endl
#define mp make_pair
#define pb push_back

const long long MOD = 1000000007;
const long long INF = 1LL<<60;


int main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    cout << fixed << setprecision(12);

    string s;
    cin >> s;

    ll sum_ = 0;
    for(int i = 0; i < (1<<(s.size()-1)); i++){
        ll tmp = s[0]-'0';
        for(int j = 0; j < s.size()-1; j++) {
            if(i & (1 << j)) {
                sum_ += tmp;
                tmp = s[j+1]-'0';
            } else {
                tmp = tmp * 10 + (s[j+1]-'0');
            }
        }
        sum_ += tmp;
    }

    cout << sum_ << endl;

    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <stack>
#include <functional>
#include <set>
#include <map>
#include <deque>
#include <cmath>
#define WMAX 10000
#define HMAX 10000

//コメントアウトするとdebug()を実行しない
#define DEBUG

using namespace std;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

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

struct edge{
  int to,cost;
};

int A,B,C,N,W,H,ans = 0,dp[HMAX][WMAX];
string S;
static const int dx[8] = {0,1,1,1,0,-1,-1,-1},
					dy[8] = {1,1,0,-1,-1,-1,0,1};

void solve(){
	if(C >= A && C <= B)ans = 1;
}

void debug(){

}

void answer(){
	if(ans){
		cout << "Yes\n";	
	}else{
		cout << "No\n";
	}
	
}

int main(){
	cin >> A >> B >> C;
	solve();
	#ifdef DEBUG
	debug();
	#endif
	answer();

	return 0;
}

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

int main(void){
  int n;
  cin >> n;
  if(n <= 111){
    cout << 111 << endl;
  } else if(112 <= n && n <= 222){
    cout << 222 << endl;
  } else if(223 <= n && n <= 333){
    cout << 333 << endl;
  } else if(334 <= n && n <= 444){
    cout << 444 << endl;
  } else if(445 <= n && n <= 555){
    cout << 555 << endl;
  } else if(556 <= n && n <= 666){
    cout << 666 << endl;
  } else if(667 <= n && n <= 777){
    cout << 777 << endl;
  } else if(778 <= n && n <= 888){
    cout << 888 << endl;
  } else if(889 <= n && n <= 999){
    cout << 999 << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
  char str[4];
  int ans=700;
  scanf("%s",str);
  if(str[0] == 'o')
    {
      ans+=100;
    }
  if(str[1] == 'o')
    {
      ans+=100;
    }
  if(str[2] == 'o')
    {
      ans+=100;
    }
  printf("%d\n",ans);
  return 0;
}


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

int main(void)
{
  int N;
  std::cin >> N;

  int cnt = 0;
  bool flag = false;
  for (int i = 0; i < N; i++) {
    int a, b;
    std::cin >> a >> b;

    if (a != b) {
      cnt = 0;
    }
    else {
      cnt++;

      if (cnt == 3) {
        flag = true;
        break;
      }
    }
  }

  if (flag) {
    std::cout << "Yes" << std::endl;
  }
  else {
    std::cout << "No" << std::endl;
  }

  return 0;
}

Measured memory_bytes: 3576
#include <iostream>
using namespace std;
#define MAX 100000
typedef long long llong;
 
int n, k;
llong T[MAX];
 
int check(llong P) {
int i = 0;
for (int j = 0; j < k; j++) {
llong s = 0;
while(s + T[i] <= P) {
s += T[i];
i++;
if (i == n) return n;
}
}
return i;
}
 
int solve() {
llong left = 0;
llong right = 100000* 10000;
llong mid;
while(right - left > 1){
mid = (left + right) / 2;
int v = check(mid);
if(v >= n) right = mid;
else left = mid;
}
return right;
}
 
main () {
    cin >> n >> k;
    for (int i = 0; i < n; i++) cin >> T[i];
llong ans = solve();
cout << ans << endl;
}

Measured memory_bytes: 3888
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }

int N;
vector<vector<int> > res;

void rec(int left, int right, int v) {
    if (right - left <= 1) return;

    // 再帰的に
    int mid = (left + right) / 2;
    rec(left, mid, v+1);
    rec(mid, right, v+1);

    // 二部グラフの中間部分を埋める
    for (int i = left; i < mid; ++i) {
        for (int j = mid; j < right; ++j) {
            res[i][j] = v;
        }
    }
}

int main() {
    cin >> N;
    res.assign(N, vector<int>(N, 1));
    rec(0, N, 1);

    for (int i = 0; i < N; ++i) {
        for (int j = i+1; j < N; ++j) {
            cout << res[i][j] << " ";
        }
        cout << endl;
    }
}


Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
 
 
// type definitions
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector< vi > vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef complex<int> ci;
typedef complex<double> cd;
typedef complex<long double> cld;
 
// macros
#define rep(i, a, b) for(int i=a; i<b; i++)
#define TIME clock() * 1.0 / CLOCKS_PER_SEC
#define all(c) c.begin(), c.end()
#define tr(c, it) for(auto it=(c).begin(); it!=c.end(); it++)
#define PB push_back
#define MP make_pair
#define bitcount __builtin_popcount
#define watch(x) cerr<< (#x) << " is " << (x) <<"\n";
#define sz(x) ((int)((x).size()))
#define UNIQUE(c) (c).resize(unique(all(c)) - (c).begin())
#define pii2ll(p) ((ll)(p).first<<32 | (p).second)
 
 
// template functions
template <typename T>
inline void printV(vector<T>& a) { rep(i, 0, sz(a)) { cout<<a[i]<<" "; } cout<<"\n"; }
template <typename T>
inline void printV(vector<T>& a, int n) { rep(i, 0, n) { cout<<a[i]<<" "; } cout<<"\n"; }
template <typename T>
inline void printVV(vector<vector<T>>& a)
{
    rep(i, 0, sz(a)) {
        printV(a[i]);
    }
    cout<<"\n";
}
 
template <typename T>
inline void clearVV(vector<vector<T>>& a)
{
    for(auto& x:a) {
        x.clear();
    }
    a.clear();
}
template <typename T>
inline void assignVV(vector<vector<T>> &a, T val)
{
    for(int i=0; i<sz(a); i++) {
        for(int j=0; j<sz(a[i]); j++) {
            a[i][j]=val;
        }
    }
}
 
// random number generation
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
// constants
const long double eps = LDBL_EPSILON;
const int inf = 5e8;
const int modn = 1e9+7;
const int MAX = 1e5;
 
inline int add(int a, int b)
{
    int ret=((ll)a+b)%modn;
    if(ret<0) {
        ret=(ret+modn)%modn;
    }
    return ret;
}
 
inline int mul(int a, int b)
{
    int ret=((ll)a*b)%modn;
    if(ret<0) {
        ret=(ret+modn)%modn;
    }
    return ret;
}
 
int n;
int dp[4][4][4][103];
int cnt=0;
 
bool checkagc(int i1, int i2, int i3)
{
    if(i1==0 and i2==2 and i3==1) return 1;
    return 0;
}
 
bool check(int i1, int i2, int i3)
{
    if(checkagc(i1, i2, i3) or checkagc(i1, i3, i2) or checkagc(i2, i1, i3)) return 1;
    return 0;
}
 
 
 
int solve(int prev1, int prev2, int prev3, int ind)
{
    if(ind==n) {
        if(check(prev1, prev2, prev3)) return 0;
        return 1;
    }
   
    int &memo=dp[prev1][prev2][prev3][ind];
    if(memo!=-1) return memo;
   
    if(check(prev1, prev2, prev3)) return 0;
   
    int ans=0;
   
    for(int i=0; i<4; i++) {
        if(checkagc(prev1, prev2, i) or checkagc(prev1, prev3, i)) continue;
        ans=add(ans, solve(prev2, prev3, i, ind+1));
    }
    return memo=ans;
}
 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // Your code here
    memset(dp, -1, sizeof(dp));
    cin>>n;
    int ans=0;
    for(int i=0; i<4; i++) {
        for(int j=0; j<4; j++) {
            for(int k=0; k<4; k++) {
                ans=add(ans, solve(i, j, k, 3));
            }
        }
    }
    cout<<ans<<"\n";
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

		int n = sc.nextInt();
		
		if ((n / 100) == (n % 10)) System.out.println("Yes");
		else System.out.println("No");
	}
}

Measured memory_bytes: 21716
<?php
//error_reporting(0);
$N = (int)trim(fgets(STDIN));
//$S = trim(fgets(STDIN));
//list($a,$b,$c) = array_map('intval',explode(" ",trim(fgets(STDIN))));
//$s = trim(fgets(STDIN));
//$a = array_map('intval',explode(" ",trim(fgets(STDIN))));

$sum=0;
for($i=1;$i<=$N;$i++) {
  if (($i % 3)==0 || ($i % 5)==0) {
    continue;
  }
  $sum += $i;
}
printf("%d\n",$sum);


Measured memory_bytes: 16000
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
 
using namespace std;
 
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define rep(i,n) REP(i, 0, n)
#define pb push_back
#define mp make_pair
#define all(r) (r).begin(),(r).end()
#define rall(r) (r).rbegin(),(r).rend()
#define fi first
#define se second
#define DBG(X) cout<<" "<<#X<<" : "<<X<<endl
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;

const int INF = 1e9;
const double EPS = 1e-8;
const int mod = 1e9 + 7;
const ll LINF = 1e18;
const double PI = acos(-1);

struct Input
{
	int n;char c;char str[1024];string s;ll l;
	int nextInt(){scanf("%d", &n);return n;}
	ll nextLong(){scanf("%lld", &l);return l;}
	char nextChar(){scanf("%c", &c);return c;}
	string next(){scanf("%s", str);return string(str);}
	string nextLine(){getline(cin, s);return s;}
};
Input in;

struct Data{
	vi x, y;
	int id;
	Data(){};
	Data(const vi& x_, const vi& y_, int id_) : x(x_), y(y_), id(id_){
		int sx = x[0], sy = y[0];
		rep(i, x.size()){
			x[i] -= sx;
			y[i] -= sy;
		}	
	};

	const bool operator ==(const Data& d)const{
		if(x.size() != d.x.size()) return false;
		rep(i, x.size()){
			if(x[i] != d.x[i] || y[i] != d.y[i]) return false;
		}
		return true;
	}
	// const bool operator <(const Data& d) const{
	// 	if(x.size() != d.x.size()) return x.size() < d.x.size();
	// 	rep(i, x.size()) if(x[i] != d.x[i]) return x[i] < d.x[i];
	// 	rep(i, y.size()) if(y[i] != d.y[i]) return y[i] < d.y[i];
	// 	if(id != d.id) return id < d.id;
	// 	return false;
	// }
};

int main(){
	while(1){
		int n = in.nextInt();
		//DBG(n);
		
		if(n == 0) break;
		Data d;
		vector<Data> v;
		rep(i, n + 1){
			int m = in.nextInt();
			//DBG(m);
			vi x(m), y(m), mx(m), my(m);
			rep(j, m) x[j] = in.nextInt(), y[j] = in.nextInt(), mx[j] = -x[j], my[j] = -y[j];
			if(i == 0){
				d = {x, y, 0};
			}
			else{
				v.pb({x, y, i});
				v.pb({my, x, i});
				v.pb({mx, my, i});
				v.pb({y, mx, i});

				reverse(all(x));
				reverse(all(mx));
				reverse(all(y));
				reverse(all(my));

				v.pb({x, y, i});
				v.pb({my, x, i});
				v.pb({mx, my, i});
				v.pb({y, mx, i});
			}
		}
		set<int> ans;
		rep(i, v.size()){
			if(d == v[i]) ans.insert(v[i].id);
		}
		for(auto a : ans){
			cout<<a<<endl;
		}
		cout<<"+++++"<<endl;
	}
}

Measured memory_bytes: 3296
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}

int main(){
  long N, A, B, ans = 11;
  cin >> N;

  for(A = 1; (A * A) <= N; A++){
    if(N % A != 0) continue;
    else {
      B = N / A;
      if(ans > max((long)log10((double)A) + 1,(long)(log10((double)B)) + 1)){
        ans = max((long)log10((double)A) + 1,(long)(log10((double)B)) + 1);
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vector<ll>> vvi;
typedef pair<ll,ll> pii;
typedef vector<pii> vpii;
#define REP(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define PB push_back
#define LB lower_bound
#define UB upper_bound
#define PQ priority_queue
#define UM unordered_map
#define US unordered_set
#define ALL(a) (a).begin(),(a).end()
const ll INF = (1ll << 60);

int main() {
  string s; cin>>s;
  vi v(4);
  REP(i,4) v[i]=s[i]-'0';
  REP(i,8) {
    ll sum=v[0];
    REP(j,3) {
      if((1ll<<j)&i) sum+=v[j+1];
      else sum-=v[j+1];
    }
    if(sum==7) {
      REP(j,3) {
        cout<<v[j];
        if((1ll<<j)&i) cout<<'+';
        else cout<<'-';
      }
      cout<<v[3]<<"=7"<<endl;
      return 0;
    }
  }
}


Measured memory_bytes: 764
//#pragma GCC optimize ("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
#define pb push_back
#define F first
#define S second
#define ins insert
#define mp make_pair
#define fo(i, n1, n, x) for(int i = n1; i <= n; i += x)
#define foo(i, n, n1, x) for(int i = n; i >= n1; i -= x)
#define bit __builtin_popcount
#define md (l + ((r - l) / 2))
#define all(x) x.begin(),x.end()
#define eb emplace_back
#define ub upper_bound
#define lb lower_bound
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)

using namespace std;
//using namespace __gnu_pbds;
//using namespace __gnu_cxx;


using ll = long long;

#define int ll

using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;



const int N = 2e5 + 11, mod = 1e9 + 7, mod2 = 998244353;
const int MAX = 1e5 + 11;
const int INF1 = 2e9 + 11;
const ll INF2 = 6e18 + 11;
const double INF3 = 1e8 + 11;
const int base = 500;
const int P = 31;
const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
const int dy[] = {0, 0, 1, -1, 1, -1, 1, -1};
const double EPS = 1e-4;
const double PI = acos(-1.0);


//template<typename T> using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }


mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int n, a[N], ans, l[N], r[N], suff[N];
main() {
  file("threesum");
  ios;
  cin >> n;
  fo(i, 0, n, 1) cin >> a[i];
  if (n and a[0]) return !(cout << -1);
  if (!n) return !(cout << (a[0] != 1 ? -1 : 1));
  foo(i, n, 0, 1) suff[i] = suff[i + 1] + a[i];
  r[0] = 1;
  fo(i, 0, n, 1) {
    if (i) r[i] = (r[i - 1] - a[i - 1]) * 2;
    chmin(r[i], suff[i]);
    if (r[i] < a[i]) return !(cout << -1);
    ans += r[i];
  }
  cout << ans;
  return 0;
}
/**
we know:
cnt[n] = a[n],
cnt[0] = 1

cnt[i] = [ cnt[i - 1] - a[i - 1], (cnt[i - 1] - a[i - 1]) * 2 ]

cnt[i] = [ (cnt[i + 1] + 1) / 2, inf );

l[3] = 2;
l[2] = 1;

*/


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


int main() {
    ll a,b,c,k;
    cin >> a>>b>>c>>k;
    ll ans;
    if(k<=a) {cout << k <<endl;
             return 0;}
    else if(k<=a+b) {
        ans = a;
        cout << ans << endl;
        return 0;
    }
    else {
        cout <<a-(k-a-b) <<endl;
        return 0;
    }
  }

Measured memory_bytes: 3596
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int A = sc.nextInt();
		int B = sc.nextInt();

		int AA = A * N;
		int ans = 0;

		if ( AA < B ) {
			ans = AA ;
		} else if ( AA > B ) {
			ans = B ;
		} else {
			ans = AA ;
		}
		System.out.println( ans );
	}
}

Measured memory_bytes: 21972
n, a, b, c, d = map(int, input().split())
result = "NO"
for i in range(n-2):
    k = n-1-i
    mi = c*k-d*i
    ma = d*k-c*i
    if mi <= abs(b-a) and abs(b-a) <= ma:
        result = "YES"
        break
print(result)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using Graph=vector<vector<int>>;
#define MAX 1000000
#define MOD 1000000007
#define INF 100000000000000

int main(){
  int H,W,A,B;
  cin>>H>>W>>A>>B;

  for(int i=0;i<B;i++){
    for(int j=0;j<A;j++){
      cout<<1;
    }
    for(int j=A;j<W;j++){
      cout<<0;
    }
    cout<<endl;
  }
  for(int i=B;i<H;i++){
    for(int j=0;j<A;j++){
      cout<<0;
    }
    for(int j=A;j<W;j++){
      cout<<1;
    }
    cout<<endl;
  }

}


Measured memory_bytes: 1280
n = int(input())
B = list(map(int, input().split()))

A = [0]*n
A[n-1] = B[n-2]
A[0] = B[0]

for i in range(n-2,0,-1):
  A[i] = min(B[i],B[i-1])
  
print(sum(A))

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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
#define LINF 1e18
typedef long long ll;

vector<int> get_prime_numbers(int n){
    vector<int> table(n+1, 1);
    table[0] = 0;
    table[1] = 0;
    for (int i=0; i<=(int)sqrt(n); i++){
        if (table[i]){
            for (int j=2*i; j<=n; j+=i){
                table[j] = 0;
            }
        }
    }
    return table;
}

//素因数分解
vector<pair<int,int>> prime_fact(int n){
    vector<pair<int,int>> a;
    if (n <= 1) return a;
    int n_origin = n;
    for(int i=2; i<=(int)sqrt(n_origin); i++){
        if (n%i == 0){
            int count = 0;
            while(n%i == 0){
                n/=i;
                count ++;
            }
            a.push_back(make_pair(i, count));
        }
    }
    if (n!=1){
        a.push_back(make_pair(n,1));
    }
    return a;
}

int main() {
    int N; cin >> N;
    vector<int> A(N);
    REP(i,N) cin >> A[i];

    int g = A[0];
    REP(i,N){
        g = __gcd(g,A[i]);
    }
    
    if(g > 1){
        cout << "not coprime" << endl;
        return 0;
    }

    vector<int> table = get_prime_numbers(1e6+1);

    REP(i,N){
        vector<pair<int,int>> p = prime_fact(A[i]);
        for(auto a: p){
            if(table[a.first] == 0){
                cout << "setwise coprime" << endl;
                return 0;
            }else{
                table[a.first] = 0;
            }
        }
    }

    cout << "pairwise coprime" << endl;





    return 0;
}

Measured memory_bytes: 11008
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
using namespace std; 
#define pb push_back
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define rep2(i,a,b) for(int i=a;i>=b;i--)
#define ll long long
#define sc(x) scanf("%d",&x)
#define sl(x) scanf("%lld",&x)
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int n,m,s;
int c[55],d[55];
ll ans[55];
ll dp[55][2555];
vector< pair<int,pair<int,int > > >E[55];
int main(int argc, char** argv) {
	cin>>n>>m>>s;
	rep(i,1,m)
	{
		int l,r,a,b;
		scanf("%d%d%d%d",&l,&r,&a,&b);
		E[l].pb({r,{a,b}});
		E[r].pb({l,{a,b}});
	}
	rep(i,1,n)
	{
		sc(c[i]);
		sc(d[i]);
	}
	rep(i,1,n)
	{
		rep(t,0,2500)
		dp[i][t]=1e18;
	}
	dp[1][min(s,2500)]=0;
	rep(k,1,n*2)
	{	
		rep(i,1,n)
		{
			rep(t,0,2500)
			{
				dp[i][min(2500,t+c[i])]=min(dp[i][min(2500,t+c[i])],dp[i][t]+d[i]);
			}
			rep(j,0,E[i].size()-1)
			{	
				int v=E[i][j].first;
				int w=E[i][j].second.first;
				int c=E[i][j].second.second;
				rep2(t,2500,0)
				{
				
				dp[v][t]=min(dp[v][t],dp[i][min(t+w,2500)]+c);
				}
			}
		}
		
	}
	rep(i,2,n)
	{ans[i]=1e18;
	rep(t,0,2500)
	{
		ans[i]=min(ans[i],dp[i][t]);
	}
	cout<<ans[i]<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 4724
#include <stdio.h>

int main(void)
{
   int d,n,p,i;
   scanf("%d%d",&d,&n);

   p = n;
   if(n==100)
      p++;

   for(i=0;i<d;i++){
      p *= 100;
   }

   printf("%d",p);

   return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
    int n;
    int k;
    cin >> n >> k;
    vector<int> d(k);
    vector<int> a(d);
    vector<int> num(n);
    for(int i = 0; i < k; i++){
        cin >> d[i];
        for(int j = 0; j < d[i]; j++){
            cin >> a[i];
            num[a[i] - 1] = 1;
        }
    }
    int result = 0;
    for(int i = 0; i < n; i++){
        if(num[i] == 0){
            result++;
        }
    }
    cout << result << endl;
}

Measured memory_bytes: 3576
{-# LANGUAGE Strict #-}

main :: IO ()
main = do
  k <- readLn
  print $ solve k

solve :: Int -> Int
solve k = sum [gcd3 a b c | a <- [1 .. k], b <- [1 .. k], c <- [1 .. k]]

gcd3 :: Int -> Int -> Int -> Int
gcd3 a b c = gcd (gcd a b) c


Measured memory_bytes: 3940
N,M = map(int,input().split())
L = 0
R = N
for m in range(M):
    L_new,R_new = map(int,input().split())
    if L_new > L:
        L = L_new
    if R_new < R:
        R = R_new

if R - L < 0:
    print(0)
else:
    print(R-L+1)

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

// #define int long long // intで書いたけど心配なときにlong longに変換する
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

/* short */
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)
#define X real()
#define Y imag()

/* REPmacro */
#define REPS(i, a, n) for (ll i = (a); i < (ll)(n); ++i)
#define REP(i, n) REPS(i, 0, n)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (ll i = (a); i >= (ll)(n); --i)
#define DEP(i, n) DEPS(i, n, 0)
#define EACH(i, n) for (auto&& i : n)

/* debug */
#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';

/* alias */
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using plglg = pair<ll, ll>;
using tlglglg = tuple<ll, ll, ll>;
using D = double;
using P = complex<D>;
using vs = vector<string>;
template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;
const D EPS = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

/* func */
inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}
inline int in() {int x; cin >> x; return x;}
inline ll IN() {ll x; cin >> x; return x;}
inline vs split(const string& t, char c) {vs v; stringstream s(t); string b; while(getline(s, b, c)) v.eb(b); return v;}
template <typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;}
template <typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;}
template <typename T, typename S> inline void print(const pair<T, S>& p) {cout << p.first << " " << p.second << endl;}
template <typename T> inline void print(const T& x) {cout << x << endl;}
template <typename T, typename S> inline void print(const vector<pair<T, S>>& v) {for (auto&& p : v) print(p);}
template <typename T> inline void print(const vector<T>& v, string s = " ") {REP(i, v.size()) cout << v[i] << (i != (ll)v.size() - 1 ? s : "\n");}
inline void yesno(bool ok, string yes = "Yes", string no = "No") {cout << (ok?yes:no) << endl;}


signed main() {
    //my-code
    ll n; cin >> n;
    string s; cin >> s;

    ll ans = 0;
    ll l = 0, r = n-1;
    while (l<r) {
        if (s[l] != 'W') {
            l++;
            continue;
        }
        if (s[r] != 'R') {
            r--;
            continue;
        }
        if (s[l] == 'W' && s[r] == 'R') {
            ans++;
            l++;
            r--;
        }
    }

    print(ans);
    return 0;
}

// https://github.com/kurokoji/.cpp-Template/wiki テンプレートについて
// http://www.creativ.xyz/dump-cpp-652 dump()について
// https://gist.github.com/rigibun/7905920 色々

Measured memory_bytes: 3768
A,B = map(int,input().split())
s = list(input())
ans = "Yes"
for i in range(A+B+1):
    if 0 <= i < A or A < i <= A+B:
        if s[i] == "-":
            ans = "No"
            break
    if i == A:
        if s[i] != "-":
            ans = "No"
            break
if len(s) != A+B+1:
    ans = "No"
print(ans)


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

typedef long long ll;

string S;

int main() {
    cin >> S;

    ll ans = 0;
    int cnt = 0;
    for(int i = 0; i < S.size(); i++) {
        if(S[i] == 'B') {
            ans += (int)S.size() - 1 - i;
            cnt++;
        }
    }
    ans -= 1LL * cnt * (cnt - 1) / 2;
    cout << ans;
}


Measured memory_bytes: 640
from math import factorial
from itertools import accumulate
from collections import Counter
N, a, b = [int(item) for item in input().split()]
v = sorted([int(item) for item in input().split()], reverse=True)

vsum = list(accumulate(v))
vcounts = []
for i in range(N):
    vcounts.append(Counter(v[:i+1]))

ans = 0
ans_count = 0
for i in range(a, b+1):
    val = vsum[i-1] / i
    if val > ans:
        n = vcounts[N-1][v[i-1]]
        r = vcounts[i-1][v[i-1]]
        ans_count = factorial(n) // factorial(r) // factorial(n-r)
        ans = val
    elif val == ans:
        n = vcounts[N-1][v[i-1]]
        r = vcounts[i-1][v[i-1]]
        ans_count += factorial(n) // factorial(r) // factorial(n-r)
print(ans)
print(ans_count)

Measured memory_bytes: 3444
use proconio::*;

fn run() {
    input! {
        n: usize,
        a: [usize; n],
    }
    let m = 1000000;
    let mut cnt = vec![0; m + 1];
    for a in a {
        cnt[a] += 1;
    }
    let mut ans = 0;
    for i in 1..=m {
        if cnt[i] == 0 {
            continue;
        }
        if cnt[i] == 1 {
            ans += 1;
        }
        let mut j = i;
        while let Some(c) = cnt.get_mut(j) {
            *c = 0;
            j += i;
        }
    }
    println!("{}", ans);
}

fn main() {
    run();
}


Measured memory_bytes: 8708
N = int(input())
A = []
for i in range(2):
    A.append(list(map(int, input().split())))

if N < 2:
    print(A[0][0]+A[1][0])

else:
    A[1] = A[1][::-1]
    a = [0]*N
    b = [0]*N
    a[0] = A[0][0]
    b[0] = A[1][0]
    a[1] = a[0] + A[0][1]
    b[1] = b[0] + A[1][1]
    for i in range(2, N):
        a[i] = a[i-1] + A[0][i]
        b[i] = b[i-1] + A[1][i]
    b = b[::-1]
    ans = 0
    for i in range(N):
        ans = max(ans, a[i]+b[i])
    print(ans)

Measured memory_bytes: 3064
#include<stdio.h>
#include <math.h>
int main(void){
    double a,b;
    scanf("%lf %lf",&a,&b);
    int i=0;
    while(1){
        if(floor((double)i*0.1)==b && floor((double)i*0.08)==a){
            printf("%d\n",i);
            break;
        }
        if(i>10000){
            printf("-1");
            break;
        }
        i++;
    }
        return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
int main()
{
  int i,j,count=0;
  int n,s[10001],q,t[500];

  scanf("%d",&n);
  for(i=0; i<n; i++) scanf("%d",&s[i]);
  scanf("%d",&q);
  for(i=0; i<q; i++) scanf("%d",&t[i]);
  
  for(i=0; i<q; i++) {
    s[n] = t[i];
    j = 0;
    while(s[j]!=t[i])
      j++;
    if(j!=n) count++;
  }

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

  return 0;
}

Measured memory_bytes: 640
n = int(input())
x = list(map(int, input().split()))
ans = dict()
x_copy = sorted(x[:])
right = x_copy[(n//2)-1]
left = x_copy[-(n//2)]

for i in range(n):
    if i < n//2:
        ans[x_copy[i]] = left
    else:
        ans[x_copy[i]] = right

for i in x:
    print(ans[i])

Measured memory_bytes: 34828
/**
*    created: 28.06.2020 02:06:06
**/
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pcnt(bit) __builtin_popcountll(bit)
using namespace std;
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;}
const int mod = 1000000007;
const long double pi = acos(-1.0);
const int inf = 1LL << 60;

signed main() {

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

    string s;
    cin >> s;
    int pcnt = 0;
    int mcnt = 0;
    rep(i,4) {
        if (s[i] == '+') pcnt++;
        else mcnt++;
    }
    cout << pcnt - mcnt << endl;
    return 0;
}

Measured memory_bytes: 3620
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a = sc.nextInt();
		int count =0;
		for (int i=0;i<n;i++) {
			int temp =sc.nextInt();
			if (temp>=a) {
				count++;
			}
		}
		System.out.println(count);
	}
}


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

int fa[200010], siz[200010], n, q;
int ufs(const int &u);

int main() {
	scanf("%d%d", &n, &q);
	for (int i = 1; i <= n; ++i)
		fa[i] = i, siz[i] = 1;
	while (q--) {
		int t, u, v;
		scanf("%d%d%d", &t, &u, &v);
		if (t)
			printf("%d\n", ufs(u) == ufs(v));
		else {
			if (siz[ufs(u)] < siz[ufs(v)])
				swap(u, v);
			siz[ufs(u)] += siz[ufs(v)],
				fa[ufs(v)] = ufs(u);
		}
	}
	return 0;
}

int ufs(const int &u) {
	return fa[u] == fa[fa[u]] ? fa[u] : fa[u] = ufs(fa[u]);
}



Measured memory_bytes: 5132
import java.util.Scanner;
import java.lang.String;
 
public class Main {
  
  public static void main (String[] arg) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    long Takahashi = sc.nextLong();
    long Aoki = sc.nextLong();
    
    for (int i = 1; i < N; i++) {
    	long Ti = sc.nextLong();
    	long Ai = sc.nextLong();
    	long mulFactor = ((Takahashi - 1 + Ti)/Ti > (Aoki - 1 + Ai)/Ai) ? (Takahashi - 1 + Ti)/Ti : (Aoki - 1 + Ai)/Ai;
    	
    	Takahashi = Ti * mulFactor;
    	Aoki = Ai * mulFactor;
    }
    
    sc.close();
    System.out.println(Takahashi + Aoki);
  }
}

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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf=1e9;
const int64_t inf64=1e18;
const double eps=1e-9;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

using i64=int64_t;

void solve(){
    int N;
    cin >> N;
    vector<set<int>> graph(N);
    vector<int> deg(N);
    rep(i,0,N-1){
        int a,b;
        cin >> a >> b;
        --a;
        --b;
        graph[a].insert(b);
        graph[b].insert(a);
    }
    queue<int> que;
    rep(i,0,N) if(graph[i].size()==1) que.push(i);
    vector<bool> done(N);
    while(!que.empty()){
        int u=que.front();
        que.pop();
        if(done[u]) continue;
        done[u]=true;
        if(graph[u].empty()){
            cout << "First" << endl;
            return;
        }
        int v=*graph[u].begin();
        graph[v].erase(u);
        done[v]=true;
        for(int w:graph[v]){
            graph[w].erase(v);
            if(graph[w].size()==1) que.push(w);
        }
    }
    cout << "Second" << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(10);
    solve();
    return 0;
}


Measured memory_bytes: 14976
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <cstdlib>

using namespace std;
int main(int argc, char **argv){
    int N;
    cin>>N;
    int P[N];
    int Q[N];
    int a=0;
    int b=0;
for(int i=0; i<N;i++){
    cin>>P[i];
}
for(int i=0; i<N;i++){
    cin>>Q[i];
}
//std::sort (Q,Q+N);

  do {
a++;
  } while ( std::next_permutation(Q,Q+N) );
    do {
b++;
  } while ( std::next_permutation(P,P+N) );

  cout<<abs(a-b);

    return 0;
}

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

string s;
int ans = 0;
int main() {
    cin >> s;
    for(int i = 0; i < s.length() / 2; i++) {
        if(s[i] != s[s.length()-1-i]) ans++;
    }
    cout << ans;
}

Measured memory_bytes: 256
import numpy as np

H, W, N = map(int, input().split())
si, sj = map(int, input().split())
si, sj = si - 1, sj - 1

S = input()
T = input()


min_i = si
max_i = si
min_j = sj
max_j = sj

piece_remaining = True

for t in range(N):
	if S[t] == 'U':
		min_i -= 1
	elif S[t] == 'D':
		max_i += 1
	elif S[t] == 'L':
		min_j -= 1
	elif S[t] == 'R':
		max_j += 1

	if min_i < 0 or H <= max_i or min_j < 0 or W <= max_j:
		piece_remaining = False
		break

	if T[t] == 'U':
		max_i = max(0, max_i - 1)
	elif T[t] == 'D':
		min_i = min(H - 1, min_i + 1)
	elif T[t] == 'L':
		max_j = max(0, max_j - 1)
	elif T[t] == 'R':
		min_j = min(W - 1, min_j + 1)

print('YES' if piece_remaining else 'NO')


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

int main() {
  int N;
  cin >> N;
  
  if(N % 10 == 7) cout << "Yes" << endl;
  else if(N % 100 >= 70 && N % 100 < 80) cout << "Yes" << endl;
  else if(N >= 700 && N < 800) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 3592
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>

using namespace std;

int main(void){
    int a,b,c,d;

    cin >> a >> b >> c >> d;

    if(abs(b-a)<=d && abs(b-c)<=d){
        cout << "Yes" << endl;
    }
    else if(abs(a-c)<=d){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define erep(i, n) for (ll i = 0; i <= (ll)(n); ++i)
#define FOR(i,a,b) for (ll i = (a); i < (ll)(b); ++i)
#define EFOR(i,a,b) for (ll i = (a); i <= (ll)(b); ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } }

#include <iostream>
#include <vector>
#include <queue>
using namespace std;
using Graph = vector<vector<int>>;
using P = pair<int, int>;

int main() {
    ll a,b,c; cin >> a >> b >> c;
    if(c-a-b > 0 && 4*a*b < (c-a-b)*(c-a-b)) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

int main()
{
    int n, k;
    cin >> n >> k;

    int a[n];
    rep(i, n) cin >> a[i];
    int t = 0;

    rep(i, n)
    {
        t += 2 * min(a[i], abs(k - a[i]));
    }

    OP(t);
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main() {
  unsigned long int n, a, b, div, mod, plus;
  if(scanf("%ld %ld %ld", &n, &a, &b) <= 0) {
    printf("fail");
  }
  if (a == 0) {
    printf("%d", 0);
    return 0;
  }
  div = n / (a + b);
  mod = n % (a + b);
  plus = a > mod ? mod : a;
  printf("%lu", a * div + plus);
  return 0;
}

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

using ll = long long;
#define REP(i,n) for(int i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)

#define INF 1e9

int main(){
  int H, W;
  cin >> H >> W;
  vector<vector<int>> a(H, vector<int>(W));
  REP(i, H){
    REP(j, W){
      cin >> a[i][j];
    }
  }
  vector<vector<int>> ans;
  REP(i, H){
    REP(j, W-1){
      if(a[i][j] % 2 == 1){
        a[i][j+1]++;
        ans.push_back({i+1, j+1, i+1, j+2});
      }
    }
  }
  REP(i, H-1){
    if(a[i][W-1] % 2 == 1){
      a[i+1][W-1]++;
      ans.push_back({i+1, W, i+2, W});
    }
  }
  cout << ans.size() << endl;
  REP(i, ans.size()){
    REP(j, 4){
      cout << ans[i][j] << (j != 3 ? " ": "\n");
    }
  }
  return 0;
}


Measured memory_bytes: 9904
# Author: cr4zjh0bp
# Created: Thu Mar 12 20:21:32 UTC 2020
import sys
 
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni = lambda: int(ns())
nin = lambda y: [ni() for _ in range(y)]
na = lambda: list(map(int, stdin.readline().split()))
nan = lambda y: [na() for _ in range(y)]
nf = lambda: float(ns())
nfn = lambda y: [nf() for _ in range(y)]
nfa = lambda: list(map(float, stdin.readline().split()))
nfan = lambda y: [nfa() for _ in range(y)]
ns = lambda: stdin.readline().rstrip()
nsn = lambda y: [ns() for _ in range(y)]
ncl = lambda y: [list(ns()) for _ in range(y)]
nas = lambda: stdin.readline().split()

N = ni()

i = 1
ans = 0
while i * i <= N:
    ans = i * i
    i += 1

print(ans)

Measured memory_bytes: 3064
#include <iostream>

using namespace std;

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

  int add = A + B;
  int minus = A - B;
  int multiply = A * B;

  int max = add;
  if (minus > max) {
    max = minus;
  }

  if (multiply > max) {
    max = multiply;
  }

  cout << max;

  return 0;
}


Measured memory_bytes: 256