akhauriyash/Code-Regression huggingface dataset:
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
# UnionFind
class UnionFind():
    def __init__(self, n):
        self.nodes=[-1] * n  # nodes[x]: 負なら、絶対値が木の要素数

    def get_root(self, x):
        # nodes[x]が負ならxが根
        if self.nodes[x] < 0:
            return x
        # 根に直接つなぎ直しつつ、親を再帰的に探す
        else:
            self.nodes[x]=self.get_root(self.nodes[x])
            return self.nodes[x]

    def unite(self, x, y):
        root_x=self.get_root(x)
        root_y=self.get_root(y)
        # 根が同じなら変わらない
        # if root_x == root_y:
        # pass
        if root_x != root_y:
            # 大きい木の方につないだほうが計算量が減る
            if self.nodes[root_x] < self.nodes[root_y]:
                big_root=root_x
                small_root=root_y
            else:
                small_root=root_x
                big_root=root_y
            self.nodes[big_root] += self.nodes[small_root]
            self.nodes[small_root]=big_root

def main():
    MAX_XY = 10**5
    N=I()
    XY=LLIN_(N)
    uf=UnionFind(2*MAX_XY)
    get_root, unite, nodes=uf.get_root, uf.unite, uf.nodes
    
    for x,y in XY:
        unite(x,y+MAX_XY)
    x_cnt = defaultdict(int)
    y_cnt = defaultdict(int)
    for x in range(MAX_XY):
        x_cnt[get_root(x)] += 1
    for y in range(MAX_XY,2*MAX_XY):
        y_cnt[get_root(y)] += 1
    
    ans = 0
    for x in range(MAX_XY):
        if(get_root(x)==x):
            ans += x_cnt[x]*y_cnt[x]
        y = x+MAX_XY
        if(get_root(y)==y):
            ans += x_cnt[y]*y_cnt[y]
    ans-=N
    print(ans)
if __name__ == '__main__':
    main()

Measured memory_bytes: 121688
#include<iostream>
#include<sstream>
#include<vector>
#include<iterator>
#include<map>
using namespace std;

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

	return gcd(b, a%b);
}

int main(void)
{
	int N, M;
	cin >> N >> M;

	string S, T;
	cin >> S >> T;

	long long n = gcd(max(N, M), min(N, M));
	long long size = n * N/n * M/n;
	map<long long, char> dic;
	long long index;
	for(int i=0; i<N; i++){
		index = i * size / N;
		if(dic[index] == 0)
			dic[index] = S[i];
		else if(dic[index] != S[i]){
			cout << -1 << endl;
			return 0;
		}
	}

	for(int i=0; i<M; i++){
		index = i * size / M;
		if(dic[index] == 0)
			dic[index] = T[i];
		else if(dic[index] != T[i]){
			cout << -1 << endl;
			return 0;
		}
	}

	cout << size << endl;

	return 0;
}


Measured memory_bytes: 10880
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;


int main() {
    int n = 0;
    int is = 0;
    int aVal;
    ll ans = 0;
    // 人数入力
    cin >> n;
    // フレンドリーさ入力
    vector<int> a(n);
    rep(i, n) {
        cin >> aVal;
        a.push_back(aVal);
    }
    // 降べきの順にそろえる
    sort(a.begin(), a.end(), greater<>());
    // 要素数が偶数か奇数か確認
    // 偶数
    ans = ans + a[0];
    if (n % 2 == 0) {
        for (is = 1;is < n / 2;is++) {
            ans = ans + a[is] * 2;
        }
    }
    // 奇数
    else{
        for(is = 1;is < n / 2;is++) {
            ans = ans + a[is] * 2;
        }
        ans = ans + a[n / 2];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4820
def lucas(_tmp1, _tmp2):
    _tmp3 = _tmp1 + _tmp2
    return _tmp2, _tmp3

lines = input()
_tmp1 = 2
_tmp2 = 1

for i in range(int(lines)-1):
  _tmp1, _tmp2 = lucas(_tmp1, _tmp2)

print(_tmp2)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n, k, a[100010];
  cin >> n >> k;
  for(int i = 0; i < n; i++) cin >> a[i];
  int dp[100010];
  dp[0] = dp[1] = 0; dp[2] = abs(a[0]-a[1]);
  for(int i = 3; i <= n; i++){
    int min = 2000000000;
    for(int j = 1; j <= k; j++){
      if(i-j < 1) break;
      else{
        if(min > dp[i-j]+abs(a[i-j-1]-a[i-1])) min = dp[i-j]+abs(a[i-j-1]-a[i-1]);
      }
    }
    dp[i] = min;
  }
  cout << dp[n] << endl;
}

Measured memory_bytes: 1024
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<cmath>
#include<string>
#include<algorithm>
using namespace std;
const int MaxN = 100;
char s[MaxN + 5];

int main()
{
	int n;
	int sum1 = 0, sum2 = 0, sum3 = 0, sum4 = 0;
	scanf("%d", &n);
	for(int i = 1; i <= n; i++) scanf(" %c", &s[i]);
	for(int i = 1; i <= n; i++)
	{
		if(s[i] == 'P') sum1++;
		if(s[i] == 'W') sum2++;
		if(s[i] == 'G') sum3++;
		if(s[i] == 'Y') sum4++;
	}
	if(sum1 == 0 || sum2 == 0 || sum3 == 0 || sum4 == 0) printf("Three\n");
	else printf("Four\n");
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

void swap(int *x, int *y)
{
        int tmp;

        tmp = *x;
        *x = *y;
        *y = tmp;
}
int main(void){
  int a,b,c;
  scanf("%d %d %d",&a,&b,&c);
  swap(&a,&b);
  swap(&a,&c);
  printf("%d %d %d\n",a,b,c);
  return 0;
}

Measured memory_bytes: 1716
//bismillahir rahmanir rahim            //Author:Fayed Anik
 
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
//using namespace __gnu_pbds;
 
//#define         ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define         ll                          long  long
#define         lf                          double
#define         pb(x)                       push_back(x)
#define         ull                         unsigned long long
#define         sfl(a)                      scanf("%lld",&a)
#define         sf(a)                       scanf("%d",&a)
#define         pf(a)                       printf("%d\n",a)
#define         pfl(a)                      printf("%lld\n",a)
#define         FOR(x,n)                    for(ll x=1;x<=n;++x)
#define         pii                         pair< ll , ll >
#define         mp(a,b)                     make_pair(a,b)
#define         mod                         1000000007
#define         INF                         2e18
#define         EPS                         1e-15
#define         f1                          first
#define         f2                          second
#define         all(v)                      v.begin(),v.end()
#define         PI                          acos(-1)
#define         printminusone               printf("-1\n")
#define         bug                         printf("bug")
#define         FILEIN                      freopen("in.txt","r",stdin)
#define         FILEOUT                     freopen("out.txt","w",stdout)
 
//ll SET(ll mask,ll pos){ return mask = (mask | (1ll<<pos)); }
//ll RESET(ll mask,ll pos){ return mask = mask & ~(1ll<<pos); }
//bool CHECK(ll mask,ll pos) { return (bool) (mask & (1ll<<pos)); }
//priority_queue <ll, vector<ll>, greater<ll> > pq;

ll MAP[2021];
int main(){
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    
    string s;
    cin>>s;
    ll n = s.size();
    s = "#"+s;
    ll ans=0,now=0,pw=1;
    MAP[0]=1;
    for(ll i=n;i>=1;i--){
        now += (s[i]-'0')*pw;
        now %= 2019;
        pw = pw*10;
        pw %= 2019;
        ans += MAP[now];
        MAP[now]++;
    }
    pfl(ans);
    return 0;
}

Measured memory_bytes: 3824
import java.io.*; 
class Main {
public static void main(String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int i=0;
int x;
while((x=Integer.parseInt(br.readLine())) != 0){
i++;
System.out.println("Case " +i+ ": " + x);
}
br.close();
}
}

Measured memory_bytes: 32088
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <random>

using namespace std;

const int N = 1e5 + 7;

int gr[N];
int used[N];
vector<int> g[N];

void dfs(int cur) {
    used[cur] = 1;
    vector<int> sons;
    for (auto t : g[cur]) {
        if (!used[t]) {
            dfs(t);
            sons.push_back(t);
        }
    }
    if (sons.empty()) {
        gr[cur] = 0;
    } else {
        for (auto t : sons) {
            gr[cur] ^= (gr[t] + 1);
        }
    }
}

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

    int n;
    cin >> n;
    for (int i = 0; i + 1 < n; i++) {
        int x, y;
        cin >> x >> y;
        x--;
        y--;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    dfs(0);
    if (!gr[0]) {
        cout << "Bob\n"; 
    } else {
        cout << "Alice\n";
    }
}       


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

ll gcd(ll x, ll y);
int fac(ll n, vector<int> num);

const int INF = 1001001001;

//mint�p�̒萔 (10��9��)
const int mod = 1000000007;

struct mint {
    ll x; // typedef long long ll;
    mint(ll x = 0) :x((x% mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }
    mint& operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream & is, const mint & a) { return is >> a.x; }
ostream& operator<<(ostream & os, const mint & a) { return os << a.x; }

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    vector<int> num(100002);

    rep(i, n) {
        if (a[i] - 1 >= 0)
            num[a[i] - 1]++;
        num[a[i]]++; 
        num[a[i] + 1]++;
    }

    int ans = 0;
    rep(i, 100002) {
        ans = max(ans, num[i]);
    }

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

/*���C�u�����ő����*/
//���[�O���b�h�̌ݏ��@
ll gcd(ll x, ll y) {
    ll num[3];
    num[0] = (x > y) ? x : y;
    num[1] = (x <= y) ? x : y;
    num[2] = num[0] % num[1];

    while (num[2]) {
        num[0] = num[1];
        num[1] = num[2];
        num[2] = num[0] % num[1];
    }

    return num[1];
}

/*�f��������*/
//���색�C�u����
int fac(ll n, vector<int> num) {
    ll kazu = n;
    for (int i = 2; i <= sqrt(n); i++) {
        while (1) {
            if (kazu % i != 0) break;

            kazu /= i;
            num[i]++;
        }
    }
    if (kazu == n && n != 1) return 1;
    int ans = 0;
    if (kazu != 1) ans++;
    for (int i = 2; i <= sqrt(n); i++) {
        for (int j = 1; j <= num[i]; j++) {
            num[i] -= j;
            ans++;
        }
    }
    return ans;
}

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

using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  string s, t;
  cin >> s >> t;
  bool can = true;
  long long L = 1LL * n / __gcd(n, m) * m;
  long long np = L / n, mp = L / m;
  for (int i = 0; i < n; i++) {
    if (np * i % mp == 0) {
      can &= s[i] == t[np * i / mp];
    }
  }
  cout << (can ? L : -1) << '\n';
  return 0;
}


Measured memory_bytes: 3760
#include <cstdio>

const int p=1000000007;

int fac[200000],inv[200000];
int d[200000];
int i,n,s1,s2,t,x,y;

inline int power(int x,int y)
{
	int s=1;
	for (int i=30;i>=0;i--)
	{
		s=1LL*s*s%p;
		if (y&(1<<i))
			s=1LL*s*x%p;
	}
	return s;
}

inline void pre_C()
{
	fac[0]=1;
	for (i=1;i<=n+1;i++)
		fac[i]=1LL*i*fac[i-1]%p;
	inv[n+1]=power(fac[n+1],p-2);
	for (i=n;i>=0;i--)
		inv[i]=1LL*(i+1)*inv[i+1]%p;
	return;
}

inline int C(int x,int y)
{
	return 1LL*inv[y]*inv[x-y]%p*fac[x]%p;
}

int main()
{
	scanf("%d",&n);
	for (i=1;i<=n+1;i++)
	{
		scanf("%d",&t);
		if (! d[t])
			d[t]=i;
		else
			x=d[t],y=i;
	}
	pre_C();
	for (i=1;i<=n+1;i++)
	{
		s1=C(n+1,i),s2=0;
		if (x+n-y+1>=i)
			s2=C(x+n-y,i-1);
		printf("%d\n",(s1-s2+p)%p);
	}
	return 0;
}

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

int main(void){
  int a,b,c,count=0;
  cin >> a >> b >> c;
  for(int i=1;i<=b-1;i++){
    if(a*i%b==c){
      count++;
      break;
    }
  }
  if(count){
    cout << "YES" << endl;
  }
  else{
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 256
# 二分探索　データの削除から　クラス定義を用いて
class Node:
    def __init__(self, key):
        self.key = key
        self.parent = None
        self.left = None
        self.right = None

class BinarySearchTree:
    def __init__(self):
        self.root = None

    def insert(self, key):
        root_node = self.root
        insert_node = Node(key)
        parent_node = None

        while root_node:
            parent_node = root_node
            if insert_node.key < root_node.key:
                root_node = root_node.left
            else:
                root_node = root_node.right
            
        insert_node.parent = parent_node

        if parent_node == None:
            self.root = insert_node
        elif insert_node.key < parent_node.key:
            parent_node.left = insert_node
        else:
            parent_node.right = insert_node
        
    def find(self, key):
        node = self.root

        while node:
            if node.key == key:
                return node
            elif node.key < key:
                node = node.right
            else:
                node = node.left 

        return None

    def delete(self, key):
        node = self.find(key)

        if node == None:
            return 
        
        if node.left and node.right:
            next_node = node.right

            while next_node.left:
                next_node = next_node.left

            node.key = next_node.key
            node = next_node

        if node.left:
            node.left.parent = node.parent
            if node.parent.left == node:
                node.parent.left = node.left
            else:
                node.parent.right = node.left
        elif node.right:
            node.right.parent = node.parent
            if node.parent.left == node:
                node.parent.left = node.right
            else:
                node.parent.right = node.right
        else:
            if node.parent.left == node:
                node.parent.left = None
            else:
                node.parent.right = None

    def show_inorder(self, node):
        if node == None:
            return 
        self.show_inorder(node.left)
        print(' ' + str(node.key), end = '')
        self.show_inorder(node.right)

    def show_preorder(self, node):
        if node == None:
            return 
        print(' ' + str(node.key), end = '')
        self.show_preorder(node.left)
        self.show_preorder(node.right)

tree = BinarySearchTree()
n = int(input())

for i in range(n):
    command = input().split()

    if command[0] == 'insert':
        tree.insert(int(command[1]))
    elif command[0] == 'find':
        a = tree.find(int(command[1]))
        if a != None:
            print('yes')
        else:
            print('no')        
    elif command[0] == 'delete':
        tree.delete(int(command[1]))
    elif command[0] == 'print':
        tree.show_inorder(tree.root)
        print()
        tree.show_preorder(tree.root)
        print()


Measured memory_bytes: 85280
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;

//typedef
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//conversion
inline LL toLong(string s) {LL v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) LL((a).size())
#define EACH(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define UNTIL(p) while(!(p))

//constant
const double EPS = 1e-5;
const double PI  = acos(-1.0);

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

#define PUTS(x) cout << (x) << endl;

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    LL n,m;
    cin>>n>>m;
    vector<PLL> ab;
    REP(i,n){
        LL a,b;
        cin>>a>>b;
        if(a <= m)ab.PB(MP(a,b));
    }

    sort(ALL(ab), [](auto x, auto y){
            if(x.second == y.second){
                return x.first > y.first;
            }else{
                return x.second > y.second;
            }
            });

    VVL day(m);
    //REP(i,m)day[i] = i - 1;

    LL ans = 0;
    REP(i, ab.size()){
        LL a = ab[i].first;
        LL b = ab[i].second;
        day[m-a].PB(b);
        //if(day[m - a] >= -1){
        //    LL index = day[m - a];
        //    day[m - a] = -100;
        //    day[index]
        //}
        //ans += b;
        //while(i < ab.size() && a == ab[i].first)i++;
        //i--;
    }
    priority_queue<LL> q;
    REP(i, m){
        LL index = m - i - 1;
        EACH(it, day[index])q.push(*it);
        if(!q.empty()){
            ans+=q.top();
            q.pop();
        }
    }

    PUTS(ans);
}

Measured memory_bytes: 7280
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        int ans = 0;
        for (int i = 0; i < S.length(); ++i) {
            if (S.charAt(i) == '1') {
                ++ans;
            }
        }
        System.out.println(ans);
    }
}

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

int main() {
	int W, H, x, y, r;

	cin >> W >> H >> x >> y >> r;

	if((x-r >= 0) && (x+r <= W)) {
		if((y-r >= 0) && (y+r <= H)) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout<<"No"<<endl;
	return 0;
}


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

const int MAX = 2000050;
const int mod = 1e9 + 7;

long long fac[MAX], finv[MAX], inv[MAX];

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

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

int main(){
    ll x, y; cin>>x>>y;
    if((x + y) % 3) cout<<0<<endl;
    else{
        ll z = (x + y) / 3;
        if(z > x || z > y) cout << 0 << endl;
        else{
            ll n = (x-z) + (y-z);
            ll r = (x-z);
            combInit();
            ll res = comb(n, r);
            cout << res << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 47104
import java.util.*;

public class Main {
	Scanner sc = new Scanner(System.in);
	void doIt() {
		char[] s = sc.next().toCharArray();
		char[] t = sc.next().toCharArray();
		int len = s.length;
		char[] cks = new char[26];
		char[] ckt = new char[26];
		Arrays.fill(cks, '.');
		Arrays.fill(ckt, '.');
		for(int i = 0; i < len; i++) {
			if(cks[(int)(s[i] - 'a')] == '.' && ckt[(int)(t[i] - 'a')] == '.') {
				cks[(int)(s[i] - 'a')] = t[i];
				ckt[(int)(t[i] - 'a')] = s[i];
			}
			else if(cks[(int)(s[i] - 'a')] != t[i] || ckt[(int)(t[i] - 'a')] != s[i]) {
				System.out.println("No");
				return;
			}
		}
		System.out.println("Yes");
	}
	Main(){doIt();}
	public static void main(String[] args) {
		new Main();
	}

}


Measured memory_bytes: 28784
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll=long long;
using vi = vector<int>;
using Graph = vector<vi>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;

int main(){
    int n;
    cin >> n;
    vector<P> in(n);
    rep(i,n)cin >> in[i].first >> in[i].second;
    vi o(n);
    iota(o.begin(),o.end(),0);
    double dis = 0;
    do{
        rep(i,n-1){
            int x1 = in[o[i+1]].first;
            int y1 = in[o[i+1]].second;
            int x2 = in[o[i]].first;
            int y2 = in[o[i]].second;
            double t = sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));
            dis += t;
        }
    }while(next_permutation(o.begin(),o.end()));
    rep(i,n){
        dis /= (double)(i+1);
    }
    cout << fixed << setprecision(12) << dis << endl;
}

Measured memory_bytes: 256
/*********************************************JMD**********************************************/
//                                  |\  |     | |   |   /\                                   //
    //                              | \ |     | |---|  /--\                              //
        //                          |  \| |___| |   | /    \1999                     //
/*******************************************************************************************/
#include <bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;

#define mp make_pair
#define pb push_back
#define pf push_front
#define ss second
#define ff first
#define mem(x,val) memset(x,val,sizeof(x))
#define forr(i,a,b) for(ll i=a;i<b;i++)
#define f(i,n) forr(i,0,n)
#define sz(x) ll((x).size())
#define all(x) ((x).begin(),(x).end())
#define asc(x) ((int)(x))
#define precision(x) cout<<fixed<<setprecision((x));

const ll mod=1e9 + 7;

/*******************************************************************************************/

void solve()
{
    ll n,q;
    cin>>n>>q;

    string s;
    cin>>s;

    ll dp[n];
    mem(dp,0);

    f(i,n-1)
    {
        dp[i+1]=dp[i];
        if(s[i]=='A' && s[i+1]=='C') dp[i+1]++;
    }

    while(q--)
    {
        ll x,y;
        cin>>x>>y;
        x--,y--;

        cout<<dp[y]-dp[x]<<"\n";
    }

    return;
}

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

    ll t=1;
    //cin>>t;
    clock_t launch=clock();

    while(t--)
    {
        solve();
    }

    clog<<((long double)(clock()-launch)/CLOCKS_PER_SEC)<<"\n";
}


Measured memory_bytes: 1872
#include "bits/stdc++.h"
#include "math.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef vector<pair<ll,ll> > vp;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
const int INF=1e9+7;

int main(){
  int r;cin>>r;
  cout<<fixed<<setprecision(20)<<2*r*M_PI<<endl;
}

Measured memory_bytes: 3748
//   _/                _/                 _/_/_/   _/
//_/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
// _/     _/    _/   _/     _/    _/  _/_/_/     _/
//_/     _/    _/   _/     _/    _/  _/    _/   _/
// _/_/   _/_/       _/_/   _/_/      _/_/     _/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
#include<string>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=2e9;
const ll INF=5e18;
typedef pair<int,int> P;
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  ll n,a[200005]={},cnt=0,ans=INF,x=0;
  cin >> n;
  for(int i=0; i<n; i++) {
    cin >> a[i];
    cnt+=a[i];
  }
  for(int i=0; i<n; i++) {
    x+=a[i];
    if(i<n-1) {
      ans=min(ans,abs((cnt-2*x)));
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 1792
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<bitset>
#include<vector>
#include<deque>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<iomanip>
#include <functional>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const int INF = 1 << 28;
//cout << fixed << std::setprecision(9)
//memset(a, 0, sizeof(a));
//--------------------------


int n;
int g[110][110];

int main()
{
	cin >> n;
	int v, k, u;
	for (int i = 0; i < n; i++) {
		cin >> v >> k;
		v--;
		for (int j = 0; j < k; j++) {
			cin >> u;
			u--;
			g[v][u] = 1;
		}
	}

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (j) {
				cout << " " << g[i][j];
			}
			else {
				cout << g[i][j];
			}
		}
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 1208
#include  <bits/stdc++.h>
using namespace  std;
int main()
{
	int n;
	cin>>n;
	vector<int>A(n), pre(n), suf(n);
	for(int i=0; i<n; i++)cin>>A[i];
	if(n==1){cout<<A[0];return 0;}
	int max1=0, max2=0;
	for(int i=0; i<n; i++)
	{
		max1=max(max1, A[i]);
		pre[i]=max1;
	}
	for(int i=n-1; i>=0; i--)
	{
		max2=max(max2, A[i]);
		suf[i]=max2;
	}
	for(int i=0; i<n; i++)
	{
		if(i!=0&&i!=n-1)
		cout<<max(pre[i-1], suf[i+1])<<endl;
		else if(i==0)cout<<suf[1]<<endl;
		else cout<<pre[n-2]<<endl;
	}
}


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

int main()
{
    int N,K;
    int H[200000];
    cin >> N >> K;
    for(int i=0; i<N; i++)
    {
        cin >> H[i];
    }

    sort(H,H+N,greater<>());
    
    for(int j=0; j<K; j++)
    {
        H[j] = 0;
    }

    unsigned long long int sum = 0;

    for(int k=0; k<N; k++)
    {
        sum += H[k];
    }

    cout << sum;


    return 0;
}

Measured memory_bytes: 1024
import math
def facts(n):
    ans = []
    for  i in range(1, int(math.sqrt(n)+1)):
        if(n%i==0):
            ans.append(i)
            ans.append(n//i)
    ans = sorted(ans)
    return ans


n,m = map(int, input().split())
hs = list(map(int, input().split()))
state = [1 for i in range(n)]
for i in range(m):
    a,b = map(int, input().split())
    if(hs[a-1]>=hs[b-1]):
        state[b-1] =0
    if(hs[a-1]<= hs[b-1]):
        state[a-1]= 0
ans = 0
for i in range(n):
    if(state[i]==1):
        ans+=1
print(ans)


Measured memory_bytes: 91676
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define PI 3.14159265359
using namespace std;

int main()
{
  int N;
  cin >> N;
  map<int,int> zyousi;
  for(int i = 2;i <= N;i++){
    int x;
    cin >> x;
    if(zyousi.count(x)){
      zyousi.at(x)++;
    }
    else{
      zyousi[x] = 1;
    }
  }
  for(int i = 1;i <= N;i++){
    if(zyousi.count(i)){
      cout << zyousi.at(i) << endl;
    }
    else{
      cout << 0 << endl;
    }
  }
}


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

using namespace std;
using ll = long long;
const int mod = 998244353;

struct mint {
    ll x; // typedef long long ll;
    mint(ll x = 0) : x((x % mod + mod) % mod) {}

    mint operator-() const { return mint(-x); }

    mint &operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }

    mint &operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }

    mint &operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }

    mint operator+(const mint a) const { return mint(*this) += a; }

    mint operator-(const mint a) const { return mint(*this) -= a; }

    mint operator*(const mint a) const { return mint(*this) *= a; }

    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }

    mint &operator/=(const mint a) { return *this *= a.inv(); }

    mint operator/(const mint a) const { return mint(*this) /= a; }
};

istream &operator>>(istream &is, const mint &a) { return is >> a.x; }

ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }

int n;

void dfs(string s, int x, vector<string> &A) {
    if (s.size() == n) {
        A.emplace_back(s);
        return;
    }
    for (int i = 0; i <= x + 1; ++i) {
        char c = ('a' + i);
        dfs(s + c, max(x, i), A);
    }
}

int main() {
    cin >> n;
    vector<string> A;
    dfs("", -1, A);
    for (int i = 0; i < A.size(); ++i) {
        cout << A[i] << endl;
    }
    return 0;

}


Measured memory_bytes: 7796
#include<bits/stdc++.h>
using namespace std;
void f(int i,vector<vector<int>> &g,map<pair<int,int>,int> &m,vector<int> &c){
  int j,k;
  for(j=0;j<g.at(i).size();j++){
    k=g.at(i).at(j);
    if(c.at(k)==-1){
      if(m.at(make_pair(min(i,k),max(i,k)))%2==0) c.at(k)=c.at(i);
      else c.at(k)=c.at(i) xor 1;
      f(k,g,m,c);
    }
  }
}
int main(){
  int n,u,v,w,i;
  cin>>n;
  vector<int> c(n+1,-1);
  vector<vector<int>> g(n+1,vector<int>(0));
  map<pair<int,int>,int> m;
  for(i=0;i<n-1;i++){
    cin>>u>>v>>w;
    g.at(u).push_back(v);
    g.at(v).push_back(u);
    m[make_pair(u,v)]=w;
  }
  c.at(1)=0;
  f(1,g,m,c);
  for(i=1;i<=n;i++) cout<<c.at(i)<<endl;
}

Measured memory_bytes: 16384
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <deque>
#include <queue>//for queue and priority_queue
#include <fstream>
#include <iomanip>
#include <stack>
#include <algorithm>
#define endl "\n"

using namespace std;
void Lancer() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); }

int  frq[100007];
int main(){
	Lancer();
	//cout << fixed << setprecision(12);
	
	int a, b, c;
	cin >> a >> b >> c;
	swap(a, b);
	swap(a, c);
	cout << a << " " << b << " " << c;
	cout << endl;
	return 0;
}


Measured memory_bytes: 384
n=int(input())
#a,b=map(int,input().split())
al=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]
q=int(input())
dic={}
for a in al:
    dic[a]=dic.get(a,0)+1

total=sum(al)
ansl=[]
for i in range(q):
    b,c=map(int,input().split())
    b_num=dic.get(b,0)
    total=total+b_num*(c-b)
    ansl.append(total)
    dic[b]=0
    dic[c]=dic.get(c,0)+b_num

for ans in ansl:
    print(ans)


Measured memory_bytes: 26712
import Text.Printf
main = do
  str<-getLine
  let [n,x]=map read $ words $ str::[Int]
  if(n==0 && x==0)
  then return ()
  else do
    putStrLn $ show $ length [1|a<-[1..n],b<-[1..a-1],c<-[1..b-1],a+b+c==x]
    main

Measured memory_bytes: 4500
yobis = {"MON": 1, "TUE": 2, "WED": 3, "THU": 4, "FRI": 5, "SAT": 6, "SUN": 7}
S = input()
print(7 if yobis["SUN"] - yobis[S] == 0 else yobis["SUN"] - yobis[S])



Measured memory_bytes: 2940
import sys
from collections import Counter
from itertools import product
from random import randint

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def debug(n, a, b, V, ave):
    cnt = 0
    for pattern in product([0, 1], repeat=n):
        if a <= sum(pattern) <= b:
            tot = 0
            for idx, p in enumerate(pattern):
                if p == 1:
                    tot += V[idx]
            res = tot / sum(pattern)
            if abs(res - ave) <= 10 ** -6:
                cnt += 1
    return cnt


def resolve():
    n, a, b = map(int, input().split())
    V = list(map(int, input().split()))

    V.sort(reverse=True)
    ave = 0
    for i in range(a, b + 1):
        tot = sum(V[:i])
        if ave <= tot / i:
            ave = tot / i
            used = V[:i]

    if len(set(used)) == 1:
        cnt = V.count(used[0])
        ave = used[0]
        cmb = [0] * len(used)
        for i in range(a, len(used) + 1):
            x = y = 1
            for j in range(1, i + 1):
                x *= (cnt + 1 - j)
                y *= j
            cmb[i - 1] = x // y
        res = sum(cmb)
    else:
        use_cnt = Counter(used)
        used = set(used)
        D = Counter(V)
        res = 1
        for num in used:
            cnt = use_cnt[num]
            x = y = 1
            for j in range(1, cnt + 1):
                x *= (D[num] + 1 - j)
                y *= j
            res *= x // y
    print(ave)
    print(res)
    # print(debug(n, a, b, V, ave))


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 9672
#include <bits/stdc++.h>
using namespace std;
#define REP(i, t) for(int i = 0; i < t; i++)
#define INF (1 << 30)

int main()
{
    int K, S;
    cin >> K >> S;

    int ans = 0;
    for (int X = 0; X <= K; X++)
    {
        for (int Y = 0; Y <= K; Y++)
        {
            if (0 <= S - X - Y && S - X - Y <= K) ans++;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#define int long long
#define INF 1e+18
using namespace std;

struct edge{ int to,cost1,cost2; };

signed main(){
	int n,p,dp[1000][1000],in[1000] = {},ord[1000];
	vector<int> tpo;
	vector<edge> G[1000];
	cin >> n >> p;
	for(int i = 0;i < p;i++){
		int s,e,a,b;
		cin >> s >> e >> a >> b; s--;e--;
		in[e]++;
		G[s].push_back({e,a,b});
	}
	queue<int> que;
	que.push(0);
	while(!que.empty()){
		int v = que.front();que.pop();
		tpo.push_back(v);
		ord[v] = tpo.size() - 1;
		for(int i = 0;i < G[v].size();i++){
			edge e = G[v][i];
			in[e.to]--;
			if(!in[e.to]) que.push(e.to);
		}
	}
	for(int i = 0;i < n;i++){
		for(int j = 0;j < n;j++) dp[i][j] = INF;
	}
	dp[0][0] = 0;
	for(int i = 0;i < n;i++){
		for(int j = 0;j < n;j++){
			if(dp[i][j] == INF) continue;
			if(i == j){
				for(int k = 0;k < G[tpo[i]].size();k++){
					for(int l = 0;l < G[tpo[i]].size();l++){
						edge e1 = G[tpo[i]][k],e2 = G[tpo[i]][l];
						if(k == l) dp[ord[e1.to]][ord[e2.to]] = min(dp[ord[e1.to]][ord[e2.to]],dp[i][j] + e1.cost1 + e2.cost2);
						else dp[ord[e1.to]][ord[e2.to]] = min(dp[ord[e1.to]][ord[e2.to]],dp[i][j] + e1.cost1 + e2.cost1);
					}
				}
			}else if(i < j){
				for(int k = 0;k < G[tpo[i]].size();k++){
					edge e = G[tpo[i]][k];
					dp[ord[e.to]][j] = min(dp[ord[e.to]][j],dp[i][j] + e.cost1);
				}
			}else{
				for(int k = 0;k < G[tpo[j]].size();k++){
					edge e = G[tpo[j]][k];
					dp[i][ord[e.to]] = min(dp[i][ord[e.to]],dp[i][j] + e.cost1);
				}
			}
		}
	}
	cout << dp[n - 1][n - 1] << endl;
	return 0;
}

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


def main():
    from math import gcd
    import sys
    input = sys.stdin.readline

    n = int(input())
    a = list(map(int, input().split()))
    max_a = 10 ** 6
    numbers = [0 for _ in range(max_a + 1)]

    for ai in a:
        numbers[ai] += 1

    is_pairwise = True

    for i in range(2, max_a + 1):
        count = 0

        for j in range(i, max_a + 1, i):
            count += numbers[j]

            if count > 1:
                is_pairwise = False

    if is_pairwise:
        print("pairwise coprime")
        exit()

    value_gcd = 0

    for i in range(n):
        value_gcd = gcd(value_gcd, a[i])

        if value_gcd == 1:
            print("setwise coprime")
            exit()

    print("not coprime")


if __name__ == '__main__':
    main()


Measured memory_bytes: 220588
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Created: Jul, 14, 2020 14:47:24 by Nobody
# $Author$
# $Date$
# $URL$
__giturl__ = "$URL$"


from collections import defaultdict
from collections import deque
from collections import OrderedDict
import itertools
from sys import stdin
input = stdin.readline


def main():
  N, K, Q = list(map(int, input().split()))
  A = [int(input())-1 for _ in range(Q)]

  num_ans = [0]*(N)
  for i in range(Q):
    num_ans[A[i]] += 1

  for i in range(N):
    score = max(0, K-Q+num_ans[i])
    if score:
      print('Yes')
    else:
      print('No')


if(__name__ == '__main__'):
  main()


Measured memory_bytes: 78144
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<math.h>
#include<stdlib.h>
#include<string>
#include<iostream>
#include<set>
#include<map>
#include<deque>
using namespace std;
typedef long long ll;
typedef pair<ll, ll>pii;
typedef pair<pii, ll>pi3;
ll mod = 1000000007;
int main()
{
	int a, b;
	cin >> a >> b;
	cout << a*a-b << endl;
	//printf((a>b) ? "Alice\n" :(a==b)?"Draw\n": "Bob\n");
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
const int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

int main() {
  int h, w, ch, cw, dh, dw; cin >> h >> w >> ch >> cw >> dh >> dw; --ch; --cw; --dh; --dw;
  vector<string> s(h); REP(i, h) cin >> s[i];
  vector dist(h, vector(w, INF));
  dist[ch][cw] = 0;
  using P = pair<int, pair<int, int>>;
  priority_queue<P, vector<P>, greater<P>> que;
  que.emplace(0, make_pair(ch, cw));
  while (!que.empty()) {
    auto [cost, pr] = que.top(); que.pop();
    auto [i, j] = pr;
    if (cost > dist[i][j]) continue;
    REP(k, 4) {
      int y = i + dy[k], x = j + dx[k];
      if (0 <= y && y < h && 0 <= x && x < w && s[y][x] == '.' && dist[y][x] > dist[i][j]) {
        dist[y][x] = dist[i][j];
        que.emplace(dist[y][x], make_pair(y, x));
      }
    }
    for (int r = -2; r <= 2; ++r) for (int c = -2; c <= 2; ++c) {
      int y = i + r, x = j + c;
      if (0 <= y && y < h && 0 <= x && x < w && s[y][x] == '.' && dist[y][x] > dist[i][j] + 1) {
        dist[y][x] = dist[i][j] + 1;
        que.emplace(dist[y][x], make_pair(y, x));
      }
    }
  }
  cout << (dist[dh][dw] == INF ? -1 : dist[dh][dw]) << '\n';
  return 0;
}


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

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

    int tsukaeru = 1;
    int count = 0;
    while(tsukaeru < B){
        tsukaeru --;
        count ++;
        tsukaeru += A;
    }

    cout << count << endl;
    return 0;
}

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

int main(){
  string S, T;
  cin >> S >> T;
  int ans = S.size();
  for(int i=0; i<=S.size()-T.size(); i++){
    int count = 0;
    for(int j=0; j<T.size(); j++){
      if(S.at(i+j)!=T.at(j)) count++;
    }
    ans = min(ans, count);
  }
  cout << ans;
  return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define REP(i, n) for(int i = 0; i < (n); ++i)

#define ABS(a) ((a < 0) ? ((-1)*(a)) : (a))

#define endl "\n"
#define pb push_back
#define rtn return
#define elif else if

#define MOD 1000000007
 
const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1};
const int dx_8[]={1,1,0,-1,-1,-1,0,1}, dy_8[]={0,-1,-1,-1,0,1,1,1};

typedef long long ll;
typedef unsigned long long ull;

template <typename T>
inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <typename T>
inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template <typename T>
inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template <typename T>
inline T nHr(T a,T b){return nCr(a+b-1,b);}
template <typename T>
inline T POW(T a,T b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}

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

	string n;
	cin >> n;

	REP(i, n.size()){
		if(n[i] == '1') cout << '9';
		else cout << '1';
	}
	cout << endl;
	rtn 0;
}

Measured memory_bytes: 764
require 'prime'
require 'set'
require 'tsort'
include Math
ALP = ('a'..'z').to_a
INF = 0xffffffffffffffff
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 pr?(num);              Prime.prime?(num)                          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
str = gc

size = str.size-2
puts str.first + size.to_s + str.last


Measured memory_bytes: 2428
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)

#define DEBUG

#ifdef DEBUG
#define var_dump(...) fprintf(stdout, __VA_ARGS__)
#define dump(a) cout << a << "\n";
#else
#define var_dump(...) 42
#define dump(a) 42
#endif

// https://beta.atcoder.jp/contests/abc059/tasks/abc059_b

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

    if (A.length() > B.length()) {
        cout << "GREATER" << "\n";
        return 0;
    }
    if (A.length() < B.length()) {
        cout << "LESS" << "\n";
        return 0;
    }

    REP(i, A.length()) {
        if (A[i] > B[i]) {
            cout << "GREATER" << "\n";
            return 0;
        }
        if (A[i] < B[i]) {
            cout << "LESS" << "\n";
            return 0;
        }
    }

    cout << "EQUAL" << "\n";

    return 0;
}


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

int main() {
	int a, b, c;
	scanf("%d", &a);
	scanf("%d", &b);
	scanf("%d", &c);
	int k=b/a;
 if(k > c){
        printf("%d",c);
    }else{
        printf("%d",k);
    }

	return 0;
}

Measured memory_bytes: 128
# coding: utf-8
import sys


def main(argv=sys.argv):
  
  n = int(input())
  
  candy_count = 0

  if n == 1:
    candy_count = 1
  else:
    candy_count = (1 + n) * n // 2
    
  print(candy_count)
  
  return 0


if __name__ == '__main__':
  sys.exit(main())
  

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

int main(){
	vector<string> divi = {"dream", "dreamer", "erase", "eraser"};
	string s;
	cin >> s;

	reverse(s.begin(), s.end());
	rep(i, 4) reverse(divi.at(i).begin(), divi.at(i).end());

	bool can = true;
	for(int i = 0; i < s.size();){
		bool can2 = false;
		for(int j = 0; j < 4; j++){
			if(divi.at(j) == s.substr(i, divi.at(j).size())){
				can2 = true;
				i += divi.at(j).size();
			}
		}

		if(!can2){
			can = false;
			break;
		}
	}
	if(can) cout << "YES" << endl;
	else cout << "NO" << endl;
}

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

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

    if (r < 1200) {
        cout << "ABC";
    } else if (r < 2800) {
        cout << "ARC";
    } else {
        cout << "AGC";
    }

    return 0;
}

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

using namespace std;

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

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

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

map<ll, ll> prime_factor(ll n) {
  map<ll, ll> res;
  for (ll i = 2; i * i <= n; ++i) {
    while (n % i == 0) {
      res[i]++;
      n /= i;
    }
  }
  if (n != 1) res[n] = 1;
  return res;
}

int main() {
  ll a, b;
  cin >> a >> b;
  ll g = gcd(a, b);
  map<ll, ll> p = prime_factor(g);
  cout << p.size() + 1 << endl;
  return 0;
}

Measured memory_bytes: 256
A,B,M=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
xyc=[]
for i in range(M):
    tmp=list(map(int,input().split()))
    xyc.append(tmp)
ans=min(a)+min(b)
judge=[a[v[0]-1]+b[v[1]-1]-v[2] for v in xyc]
print(min(ans,min(judge)))

Measured memory_bytes: 42516
#include <iostream>
using namespace std;
int main(void){
    int X;
    cin >> X;
    int ans = X-1;
    bool is_prime = false;
    while(!is_prime){
        ans++;
        is_prime = true;
        for(int i=2;i*i <= ans;i+=2){
            if(ans % i == 0){
                is_prime = false;
                break;
            }
            if(i == 2)i--;
        }
    }
    cout << ans << endl;
}


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

using namespace std;

using P = pair<int, int>;
using LL = long long;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define IN(v) int v;cin>>v;
#define OUT(v) cout<<v<<endl

int main() {
  IN(H); IN(W); IN(D);
  vector<P> m(H*W+1);
  vector<int> cost(H*W+1, 0);

  REP(i, H) {
    REP(j, W) {
      IN(a);
      m[a] = make_pair(i, j);
    }
  }
  FOR(a, 1, H*W+1) {
    if (a-D >= 1)
      cost[a] = abs(m[a].first - m[a-D].first) + abs(m[a].second - m[a-D].second) + cost[a-D];
  }
  IN(Q);
  REP(i, Q) {
    IN(L); IN(R);
    OUT(cost[R] - cost[L]);
  }

  return 0;
}


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

int main() {
  int N, marker;
  marker = 0;
  cin >> N;
  vector<int> b(N);
  for (int i = 0; i < N; i++){
    cin >> b.at(i);
  }

  for (int i = 0; i < N; i++){
    if (b.at(marker) == 2){
      cout << i+1 << endl;
      break;
    }
    else if (i == N-1){
      cout << -1 << endl;
    }
    else {
      marker = b.at(marker)-1;
    }
  }
}


Measured memory_bytes: 640