akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args) {
        int n = int.Parse(Console.ReadLine());
        LinkedList<string> list = new LinkedList<string>();
        for (int i = 0; i < n; i ++) {
            string[] s = Console.ReadLine().Split();
            switch(s[0]) {
                case "insert":
                    list.AddFirst(s[1]);
                    break;
                case "delete":
                    list.Remove(s[1]);
                    break;
                case "deleteFirst":
                    list.RemoveFirst();
                    break;
                case "deleteLast":
                    list.RemoveLast();
                    break;
                default:
                    break;
            }
        }
        Console.WriteLine(string.Join(" ", list));
    }
}


Measured memory_bytes: 122852
Scanf.scanf "%d %d %d" (fun hh ww m ->
    let module S = Set.Make (struct type t = int let compare = compare end) in
    let module S2 = Set.Make (struct type t = int * int let compare = compare end) in
    let node_h  = Array.make hh S.empty in 
    let node_w  = Array.make ww S.empty in 
    let count_h = Array.make hh 0 in 
    let count_w = Array.make ww 0 in 
    let hw = Array.init m (fun _ -> Scanf.scanf " %d %d" (fun h w -> h - 1, w - 1)) in

    Array.iter (fun (h, w) ->
        node_h.(h)  <- S.add w node_h.(h);
        node_w.(w)  <- S.add h node_w.(w);
        count_h.(h) <- count_h.(h) + 1;
        count_w.(w) <- count_w.(w) + 1;
    ) hw;
    let rec loop_h i set_h =
        if i = hh then set_h else
            loop_h (i + 1) (S2.add (count_h.(i), i) set_h)
    in
    let rec loop_w i set_w =
        if i = ww then set_w else
            loop_w (i + 1) (S2.add (count_w.(i), i) set_w)
    in
    let set_h = loop_h 0 S2.empty in
    let set_w = loop_w 0 S2.empty in

    let ((mch, mih) as mxh) = S2.max_elt set_h in
    let ((mcw, miw) as mxw) = S2.max_elt set_w in

    let rec loop_w w acc =
        if w = ww then acc else
            let cur = if S.mem w node_h.(mih) then mch + count_w.(w) - 1 else mch + count_w.(w) in
            loop_w (w + 1) (max acc cur)
    in
    let acc = loop_w 0 0 in
    let rec loop_h h acc =
        if h = hh then acc else
            let cur = if S.mem h node_w.(miw) then mcw + count_h.(h) - 1 else mcw + count_h.(h) in
            loop_h (h + 1) (max acc cur)
    in
    let acc = loop_h 0 acc in
    Printf.printf "%d\n" acc
)

Measured memory_bytes: 86744
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
string s;
string a[5003];
int main(){
	cin >> s;
	int n = s.length(), k;
	cin >> k;
	for (int i = 0; i < n; ++ i)
		for (int j = i; j < n; ++ j)
			a[i] += s[j];
	sort(a, a + n);
	for (int i = 0; i < n; ++ i){
		int lcp = 0;
		for (int j = 0; j < (i == 0 ? 0 : min(a[i].length(), a[i - 1].length())); ++ j)
			if (a[i][j] == a[i - 1][j])
				++ lcp;
			else
				break;
		if (k > a[i].length() - lcp)
			k -= a[i].length() - lcp;
		else{
			for (int j = 0; j < lcp + k; ++ j)
				cout << a[i][j];
			return 0;
		}
	}
}


Measured memory_bytes: 24832
def main():
  n = int(input())
  cnt, flag = 0, True
  for _ in range(n):
      a, b = map(int, input().split())
      if a == b:
          if flag:
              cnt += 1
          else:
              cnt = 1
              flag = True
      else:
          flag = False
          cnt = 0
      if cnt >= 3:
          break
  print("Yes" if cnt >= 3 else "No")
    

if __name__ == "__main__":
    main()

Measured memory_bytes: 9188
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long k = sc.nextLong();

        if(k>a){
            b = Math.max(0,b - k + a);
            a = 0;
        } else if (k <= a){
            a = a - k;
        }
        System.out.println(a+" "+b);
    }
}


Measured memory_bytes: 21972
import sys
input = lambda: sys.stdin.readline().rstrip()

s = int(input())

a = [s, ]

set_a = set()
i = 1
while True:
    c = a.pop()

    if c in set_a:
        print(i)
        break
    
    set_a.add(c)

    if c % 2 == 0:
        n_c = c // 2
    else:
        n_c = 3 * c + 1

    a.append(n_c)

    i += 1

Measured memory_bytes: 38384
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
  		int A = sc.nextInt();
  		int B = sc.nextInt();
  		int H = sc.nextInt();
  		int M = sc.nextInt();
  
  		double kakudoTansin = 30 * H + 0.5 * M;
  		double kakudoTyousin = 6 * M;
  		double kakudo = Math.abs(kakudoTansin - kakudoTyousin);
  		if(kakudo > 180){
        		kakudo = 360-kakudo;
        }
  		double cnizyou = A * A + B * B - 2 * A * B * Math.cos(kakudo*(Math.PI/180));
        double c = Math.sqrt(cnizyou);
  		System.out.println(c);
	}
}

Measured memory_bytes: 27184
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pb push_back
#define f first
#define s second
#define MOD 1000000007
 #define PI 3.141592653
using namespace std;

int A[101];

void solve(){
	int n; cin>>n;
	for(int i=1; i<n; i++){
		cin>>A[i];
	}
	ll ans =0;
	ans += A[1];
	for(int i=1; i<n-1; i++){
		ans += min(A[i],A[i+1]);
	}
	ans += A[n-1];
	cout<<ans;

}


int main()
{ 
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout<<fixed<<setprecision(12);
	int t =1; //cin>>t;
	for(int i=1; i<=t; i++){
		solve();
		cout<<"\n";
	}
	return 0;

}


Measured memory_bytes: 256
import sys

input = sys.stdin.readline
N, M, L = list(map(int,input().split()))
P = [list(map(int,input().split())) for i in range(M)]
Q = int(input())
st = [list(map(int,input().split())) for i in range(Q)]

INF = 100100100100100

dp = [[INF]*N for i in range(N)]
for s,e,d in P:
	if d<=L:
		dp[s-1][e-1] = d
		dp[e-1][s-1] = d
for i in range(N):
	dp[i][i] = 0

for k in range(N):
	for y in range(N):
		for x in range(N):
			dp[y][x] = min(dp[y][x], dp[y][k]+dp[k][x])

dp2 = [[INF]*N for i in range(N)]
for y in range(N):
	for x in range(N):
		if dp[y][x]<=L:
			dp2[y][x] = 1

for k in range(N):
	for y in range(N):
		for x in range(N):
			dp2[y][x] = min(dp2[y][x], dp2[y][k]+dp2[k][x])

for s, t in st:
	count = dp2[s-1][t-1]
	if count==INF:
		print(-1)
	else:
		print(count-1)

Measured memory_bytes: 72924
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		long x=sc.nextLong(),sum;
		sum=x/11*2;
		if(x%11!=0){
			if(x%11>6){
				sum+=2;
			}
			else {
				sum++;
			}
		}
		System.out.println(sum);
	}
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
const int MX = 200005;



int main() {
  int s;
  scanf("%d",&s);

  int n = (s+1)/2;
  vvi ans;

  if (s < 500) {
    n = s;
    ans = vvi(n,vi(n));
    rep(i,n)rep(j,n) ans[i][j] = i+1;
  } else {
    if (n&1) n++;
    vvi a(n,vi(2));
    int r = 1;
    rep(j,2)rep(i,n) {
      if (r <= s) a[i][j] = r;
      else a[i][j] = a[i][0];
      ++r;
    }

    ans = vvi(n,vi(n));
    rep(i,n)rep(j,n) {
      int x = (i+j)%n;
      int y = i%2;
      ans[i][j] = a[x][y];
    }
  }

  cout<<n<<endl;
  rep(i,n) cout<<ans[i]<<endl;

  return 0;
}






















Measured memory_bytes: 2176
// Ver19.02
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define INF 1 << 29
#define LLINF 4545454545454545454
#define MOD 1000000007
#define ll long long
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
int upll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? -1 : *(ll *)a > *(ll *)b ? 1 : 0; }
int downll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? 1 : *(ll *)a > *(ll *)b ? -1 : 0; }
void sortup(ll *a, int n) { qsort(a, n, sizeof(ll), upll); }
void sortdown(ll *a, int n) { qsort(a, n, sizeof(ll), downll); }

int main()
{
  int a, b;
  scanf("%d%d", &a, &b);
  if ((a + b) % 2 == 0)
    printf("%d\n", (a + b) / 2);
  else
    printf("%d\n", (a + b) / 2 + 1);
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define all(a) a.begin(), a.end()
#define forn(i,n) for(int i = 0; i < (int) n; i++)
#define ios ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)

#define MOD 1000000007
using namespace std;
typedef long long ll;

struct num {
  num(ll x = 0): x((x % MOD + MOD) % MOD) {}
  num& operator+=(const num& m) {
    x = (x + m.x) % MOD;
    return *this;
  }
  num& operator-=(const num& m) {
    x = (x - m.x + MOD) % MOD;
    return *this;
  }
  num& operator*=(const num& m) {
    x = (x * m.x) % MOD;
    return *this;
  }

  num exp(ll p) {
    p %= MOD - 1;
    if (p < 0) p += MOD - 1;
    num a = x, ans = 1;
    while(p) {
      if (p & 1) ans *= a;
      a *= a;
      p >>= 1;
    }
    return ans;
  }

  ll x;
};

num operator*(num a, num b) {
  num ret(a);
  ret *= b;
  return ret;
}
num operator+(num a, num b) {
  num ret(a);
  ret += b;
  return ret;
}
num operator-(num a, num b) {
  num ret(a);
  ret -= b;
  return ret;
}

int main() {
  ios;
  int k;
  string s;
  cin >> k >> s;
  int l = s.size();

  vector<num> fact(k + l + 3);
  fact[0] = 1;
  forn(i, fact.size() - 1) fact[i + 1] = fact[i] * (i + 1);

  num ans(0);
  forn(x, k + 1) {
    num tmp(0);
    tmp += num(25).exp(x);
    tmp *= num(26).exp(k - x);
    tmp *= fact[x + l - 1];
    tmp *= fact[x].exp(-1);
    tmp *= fact[l - 1].exp(-1);

    ans += tmp;
  }

  cout << ans.x << "\n";
}


Measured memory_bytes: 19840
#!/usr/bin/env python3
# coding: utf-8

def main():
    X = int(input())
    # a = math.ceil(math.log(X / 100, 1 + 0.01))
    m = 100
    c = 0
    while m < X:
        m = int(m * 1.01)
        c += 1
    print(c)

if __name__ == "__main__":
    main()


Measured memory_bytes: 9160
#include <bits/stdc++.h>
#define N 1000500
using namespace std;
int n,L,a[N];
inline int rd() {int r;scanf("%d",&r);return r;}
int main() {
	n = rd(), L = rd();
	for (int i=1;i<=n;i++) a[i] = rd();
	
	int d = 0;
	for (int i=1;i<n;i++) if (a[i]+a[i+1] >= L) d = i;
	if (!d) {
		puts("Impossible");
	} else {
		puts("Possible");
		for (int i=1;i<d;i++) printf("%d\n",i);
		for (int i=n-1;i>d;i--) printf("%d\n",i);
		printf("%d\n",d);
	}
	
	return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
#define M 200005
int n,A[M];
int dp[M],sum[M];
const int mod=1e9+7;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&A[i]);
	memset(sum,0,sizeof(sum));
	dp[0]=1;
	for(int i=1;i<=n;i++){
		dp[i]=dp[i-1];
		if(A[i]!=A[i-1]){
			dp[i]=(dp[i]+sum[A[i]])%mod;
			sum[A[i]]=dp[i]%mod;
		}
	}
	printf("%d\n",dp[n]);
	return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#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;
    cin >> n;
    vector<int> h(n);
    rep(i,n) cin >> h[i];
    for (int i = n-1; i >= 1; i--) {
        if (h[i] >= h[i-1]) continue;
        if (h[i-1] > h[i]+1) {
            cout << "No" << endl;
            return 0;
        }
        else h[i-1]--;
    }
    cout << "Yes" << endl;
    return 0;
}

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

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

    int N; cin >> N;
    ll s = 0;
    for(int i=1;i<=N;i++){
        if(i%3!=0 && i%5 != 0){
            s+= i;
        }
    }
    cout << s;

    return 0;
}


Measured memory_bytes: 3616
#pragma GCC optimize "trapv"
#include<iostream>
#include <bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define vi vector<int>
#define vll vector<ll>
#define pb push_back
#define ld long double
#define mp make_pair
#define pii pair<int,int>
#define mod 1000000007
#define rep(i,n) for(int i=0;i<n;i++)
#define repp(i,a,n) for(int i=a;i<n;i++)
#define all(v) v.begin(),v.end()
#define input(arr,n) for(ll i1=0;i1<n;i1++ )cin>>arr[i1]
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>//s.order_of_key(val) *s.find_by_order(ind)
int main()
{
    fio;
    int t=1;
    //cin>>t;
    while(t--)
    {
        ll x;
        cin>>x;
        if(x==0)
        cout<<1<<endl;
        else
        cout<<0<<endl;
    }
}

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

ifstream in ("test.in" );
ofstream out("test.out");

const int DIM = 1e5 + 5;
const int INF = 0x3f3f3f3f;

int szt[DIM];
vector<pair<int, int>> edg[DIM];

void dfs(int x, int f, int n, int &spe, int &med, long long &ans)
{
    bool ok = true;
    
    szt[x] = 1;
    for (pair<int, int> y : edg[x]) {
        if (y.first == f)
            continue;
        
        dfs(y.first, x, n, spe, med, ans); szt[x] += szt[y.first];
        ans += 2LL * min(szt[y.first], n - szt[y.first]) * y.second;
        
        if (szt[y.first] == n - szt[y.first])
            med = y.second;
        if (szt[y.first] > (n >> 1))
            ok = false;
    }
    
    if (n - szt[x] > (n >> 1))
        ok = false;
    if (ok)
        spe = x;
    
    return;
}

int main(void)
{
    ios::sync_with_stdio(false);
    cin.tie(); cout.tie();
    
    int n;
    cin >> n;
    
    for (int i = 1; i < n; ++i) {
        int x, y, z;
        cin >> x >> y >> z;
        
        edg[x].push_back(make_pair(y, z));
        edg[y].push_back(make_pair(x, z));
    }
    
    long long ans = 0;
    int spe = -1, med = INF;
    
    dfs(1, 0, n, spe, med, ans);
    
    if (med == INF && spe != -1)
        for (pair<int, int> y : edg[spe])
            med = min(med, y.second);
    
    cout << ans - med << endl;
    return 0;
}


Measured memory_bytes: 15488
#include <stdio.h>
#include <string.h>
int main(void){
  char s[100];
  int a,b,c,d,board[9][9],i,j,x,y,cnt,n;
  while(1){
    scanf("%s",s);
    if(s[0]=='#')
      break;
    scanf("%d %d %d %d",&a,&b,&c,&d);
    memset(board,0,sizeof(board));
    cnt=0;
    x=y=0;
    for(i=0;i<strlen(s);i++){
      if(s[i]=='b')
	board[y][x++]=1;
      else if(s[i]=='/'){
	n=x;
	x=0;
	y++;
      }
      else{
	cnt=s[i]-'0';
	for(j=0;j<cnt;j++){
	  board[y][x++]=0;
	}
      }
    }
    y++;
    a--;
    b--;
    c--;
    d--;
    board[a][b]=0;
    board[c][d]=1;
    for(i=0;i<y;i++){
      if(i!=0)
	putchar('/');
      cnt=0;
      for(j=0;j<n;j++){
	if(board[i][j]==0){
	  while(j<n&&board[i][j]==0){
	    cnt++;
	    j++;
	  }
	  printf("%d",cnt);
	  cnt=0;
	}
	if(j<n&&board[i][j]==1)
	  putchar('b');
      }
    }
    puts("");
  }
  return 0;
}

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

int main() {
  int n,k;
  cin>> n>>k;
  vector<int> veca(n);
  for (int i = 0; i < n; i++) {veca.at(i)=0;}
  for (int j = 0; j < k; j++){
    int d;
  cin>>d;
   vector<int> vec(d);
  for (int i = 0; i < d; i++) { cin >> vec.at(i);}
    for (int i = 0; i < d; i++) {
      int vuu = vec.at(i)-1;
      veca.at(vuu)= 1;
    }
    
  
  }
  int sunuke =0;
   for (int i = 0; i < n; i++) { 
    if(veca.at(i)==1)sunuke++;}
  cout <<n-sunuke;
  
}  



Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n;
	scanf("%d", &n);

	int mn = 100999;
	int mx = -10999;
	int a[100100];
	for(int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
		mn = min(mn, a[i]);
		mx = max(mx, a[i]);
	}

	sort(a, a + n);
	set<int> s;
	for(int i = mn; i <= mx; i++) {
		int x = i - 1;
		int pos = upper_bound(a, a + n, x) - a;
		pos++;
		if(pos - 1 == n - pos + 1) s.insert(i);
	}

	printf("%d", int(s.size()));
	return 0;
}

Measured memory_bytes: 5376
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;

int main(){
	long long n;
	cin >> n;
	// cout << "n : " << n << endl;
	long long a = pow(n, 0.5);
	// cout << "a : " << a << endl;
	// cout << n << endl;
	// int ans = 0;
	for(int i = a; i >= 1; i--){
		if(n % i == 0){
			n /= i;
			// cout << "i : " << i << endl;
			// cout << "n : " << n << endl;
			cout << to_string(n).size() << endl;
			return 0;
		}
	}	
	return 0;
}



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

bool isLeapYear(int year) {
    return (year % 4 == 0 && year % 100 != 0) || year % 400 == 0;
}

int main() {
    const int daysPerMonth[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, };
    while (true) {
        int y[2], m[2], d[2];
        cin >> y[0] >> m[0] >> d[0] >> y[1] >> m[1] >> d[1];
        if (y[0] < 0 || m[0] < 0 || d[0] < 0 || y[1] < 0 || m[1] < 0 || d[1] < 0) {
            break;
        }
        int dayNumInYear[] = {d[0], d[1], };
        for (int i = 0; i < 2; i++) {
            for (int j = 0; j < m[i] - 1; j++) {
                dayNumInYear[i] += (j == 1 && isLeapYear(y[i])) ? 29 : daysPerMonth[j];
            }
        }
        int output = 0;
        output += dayNumInYear[1] - dayNumInYear[0];
        for (int i = y[0]; i < y[1]; i++) {
            output += (isLeapYear(i)) ? 366 : 365;
        }
        cout << output << endl;
    }
}

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

int main() {
  int N;
  cin >> N;
  vector <int> a(N);
  for(int i=0;i<N;i++){
    cin>>a.at(i);}
  int count,b = 0;
  while (1 > 0) {
    // 2で割り切れなけばループを抜ける
   if (b==N){
      break ;} 
   
    if (a.at(b) % 2 > 0) {
      b++;
      
    }
    else {
    a.at(b) = a.at(b) / 2;
    count++;}
   
  
    }
  
  cout << count << endl;
}

Measured memory_bytes: 256
from math import factorial
def com(n,r):
    if n<r:
        return 0
    return int(factorial(n) // factorial(r) // factorial(n-r))

N = int(input())
S = [[0 for j in range(10)] for i in range(N)]
for i in range(N):
    s = str(input())
    for j in range(10):
        S[i][j] = s[j]
    S[i].sort()
S.sort()
ans = 0
i = 0
j = 1
while i < N:
    tmp = 0
    while i + j < N and S[i] == S[i + j]:
        tmp += 1
        j += 1
    if tmp != 0:
        ans += com(tmp+1, 2)
    i += j
    j = 1
print(ans)

Measured memory_bytes: 26488
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>
#define ll long long

using namespace std;

long long MOD = 1000000007;

int main(){
    string S;
    cin >> S;
    int tmp=-1;
    for(int i=0; i<4; i++){
        int x=S[i]-'0';
        if(x==tmp){
            cout << "Bad" << endl;
            return 0;
        }
        tmp=x;
    }
    cout << "Good" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <iomanip>
#include <map>
#include <bitset>
#include <cstdio>
#include <set>
#include <stack>
#include <queue>
#include <cassert>
#include <numeric>
#define rep(i,n) Rep(i,0,n)
#define Rep(i,k,n) for(int i=k ; i<n ; i++)
#define rep1(i,n) for(int i=1 ; i<=n ; i++)
#define Rep1(i,k,n) for(int i=k ; i<=n ; i++)
#define vi vector<int>
#define vii vector<vector<int>>
#define mii map<int,int>
#define Sort(v) sort(v.begin(),v.end())
#define Reverse(v) reverse(v.begin(),v.end())
#define ALL(a)  (a).begin(),(a).end()
#define pb push_back
//#define int ll
typedef long long ll;

const int md = 1000000007;
const int INF = 1<<30;
using namespace std;

int main(){

    int n,k; cin >> n >> k;
    string s; cin >> s;
    s[k-1] = s[k-1] + 32;
    cout << s << endl;
    



}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
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 (a>b) { a=b; return 1; } return 0; }

const int mod=1e9+7;

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

    int N; cin>>N;
    vector<vector<int>> G(N);
    for(int i=0;i<N-1;i++){
        int a,b; cin>>a>>b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    vector<vector<int>> dp(N,vector<int>(2));
    function<int(int,int,int)> dfs=[&](int v,int c,int p)
    {   
        if(dp[v][c]!=0) return dp[v][c];
        int res=1;
        for(int u:G[v]) if(u!=p){
            if(c==0){
                res*=(dfs(u,0,v)+dfs(u,1,v));
                res%=mod;
            }else{
                res*=dfs(u,0,v);
                res%=mod;
            }
        }
        return dp[v][c]=res;
    };
    int ans=dfs(0,0,-1)+dfs(0,1,-1);
    ans%=mod;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 27904
using System;
// using System.Collections.Generic;

class Program
{
    static void Main()
    {
        String[] arr = Console.ReadLine().Split();
        int X, Y, Z;
        X = int.Parse(arr[0]);
        Y = int.Parse(arr[1]);
        Z = int.Parse(arr[2]);
        Console.WriteLine(
            Z.ToString() + " " + X.ToString() + " " + Y.ToString());
    }
}

Measured memory_bytes: 11092
n=int(input())
s=[]
for i in range(n):
  x,y,h=map(int,input().split())
  s.append([x,y,h])
s=sorted(s,key=lambda x:x[2],reverse=True)
x0,y0,h0=s[0] #少なくとも一つはhi>0だからhの最大のものを取る
for x in range(101):
  for y in range(101):
    H=h0+abs(x0-x)+abs(y0-y) #h0=H-abs(x0-x)+abs(y0-y)の式変形(hiが0以上の前提)
    for xi,yi,hi in s:
      if hi!=max(0,H-abs(xi-x)-abs(yi-y)):
        break
    else: #for文の下のelseは(breakすることなしに)for文を抜けることができたら反映
      print(x,y,H)
      exit()

Measured memory_bytes: 3064
#%%
import sys
def input():
    return sys.stdin.readline().rstrip()

def main():
    N=int(input())
    
    print(N//2 if N%2 else N//2 - 1)


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

# %%
# from atcoder_test import doTest
# doTest("nikkei2019-2-qual","a",main)

Measured memory_bytes: 2940
import java.util.*;
public class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int x = sc.nextInt();
    int a = sc.nextInt();
    int b = sc.nextInt();
    if(a>=b){
      System.out.println("delicious");
    }else if(b-a<=x){
      System.out.println("safe");
    }else{
      System.out.println("dangerous");
    }
  }
}


Measured memory_bytes: 23252
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;

class Program
{
    static void Main(string[] args)
    {
        var nums = Array.ConvertAll(ReadLine().Split(' '), int.Parse);
        var max = nums.Max();
        var submax = nums.Count(v=>v==max)>1?max:nums.Where(v=>v!=max).Max();
        var min = nums.Min();
        if ((max-(min + (max - submax))) % 2 == 0) WriteLine((max-(min + (max - submax))) / 2 + max - submax);
        else WriteLine((max-((min + (max - submax)))+1) / 2 + max - submax+1);
    }
}

Measured memory_bytes: 13396
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <stdio.h>
#include <cmath>
#include <math.h>
#include <sstream>
#include <iomanip>
#include <time.h>
#include <fstream>

using namespace std;

int main(){
	int n;
	cin>>n;
	vector<int> a(n);
	for(int i = 0; i < n; i++){
		cin>>a[i];
	}
	sort(a.begin(), a.end());
	int ans = 1;
	for(int i = 1; i < n; i++){
		if(a[i] != a[i - 1]) ans++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
#define pb push_back
#define ld long double
#define f first
#define s second
#define in insert
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e18 + 5;
const int mod = 1e9 + 7;
const int  N = 2e5 + 314;
const long double pi = 3.1415926535897932384626433832795;
void solve(){
	int n;
	cin>>n;
	vi v(n);
	map<int, int>cnt;
	for(int i = 0; i < n; i++){
		cin>>v[i];
		cnt[v[i]]++;
	}	
	sort(all(v));
	int i = n-1,a = -1, b = -1;
	while(i>=0)
	{
		if(cnt[v[i]]>1&&a==-1)a=v[i];
		if(v[i]!=a&&cnt[v[i]]>1&&b==-1)b=v[i];
		i--;
	}
	if(a==-1&&b==-1)cout<<"0\n";
	else if(a==-1||b==-1){
		if(a!=-1)cout<<a*a*(cnt[a]>3);
		else cout<<b*b*(cnt[b]>3);
	}
	else cout<<max({a*a*(cnt[a]>3), b*b*(cnt[b]>3), a*b});
}
signed main(){
	speed;
	int t=1;
	//cin>>t;
	while(t--)solve();
}

Measured memory_bytes: 10292
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn merge(a: &mut Vec<u64>, left: usize, mid: usize, right: usize) -> usize {
    let n1: usize = mid - left;
    let n2: usize = right - mid;
    let mut l: Vec<u64> = (0..n1)
        .map(|i| {
            let number: u64 = a[left + i];
            number
        })
        .collect();
    let mut r: Vec<u64> = (0..n2)
        .map(|i| {
            let number: u64 = a[mid + i];
            number
        })
        .collect();
    l.push(u64::max_value());
    r.push(u64::max_value());
    let mut i: usize = 0;
    let mut j: usize = 0;
    for k in left..right {
        if l[i] <= r[j] {
            a[k] = l[i];
            i += 1;
        } else {
            a[k] = r[j];
            j += 1;
        }
    }
    return i + j;
}

fn merge_sort(a: &mut Vec<u64>, left: usize, right: usize) -> usize {
    let mut count: usize = 0;

    if left + 1 < right {
        let mid: usize = (left + right) / 2;
        count += merge_sort(a, left, mid);
        count += merge_sort(a, mid, right);
        count += merge(a, left, mid, right);
    }
    return count;
}

fn main() {
    let n: usize = read();
    let mut a: Vec<u64> = (0..n)
        .map(|_| {
            let number: u64 = read();
            number
        })
        .collect();
    let count_number = merge_sort(&mut a, 0, n);
    for (index, number) in a.iter().enumerate() {
        if (index + 1) != a.len() {
            print!("{} ", number);
        } else {
            println!("{}", number);
        }
    }
    println!("{}", count_number);
}



Measured memory_bytes: 16608
#include <bits/stdc++.h>
#include <stdio.h>
 
using namespace std;
 
#define int long long
 
bool codejam = 0;
 
typedef long long li;
typedef long double ld;
 
void solve();
int32_t main () {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout << fixed << setprecision(20);
	#ifndef ONLINE_JUDGE
		//freopen("input.txt", "r", stdin);
	#endif
	int t = 1; 
	// cin >> t;
	int tt = t;
	while (t--) { 
		if (codejam) cout << "Case #" << tt - t << ": ";
		solve();
	}
	return 0;
}

string s;
void solve() {
	cin >> s;
	int l = (int) s.size();
	int cur = 0;
	for (int i = 0; i < (int) s.size(); ++i) {
		if (s[i] == 'S') cur += 1;
		else {
			if (cur) {
				--cur;
				l -= 2;
			}
		}
	}
	cout << l;
}		

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

using namespace std;

int main() {
	#ifdef HOME
	freopen("input.txt", "rt", stdin);
	#endif  //  HOME
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n, r;
 	cin >> n >> r;
	if (n >= 10) {
		cout << r;
		return 0;
	}
	cout << 100 * (10 - n) + r;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
map<ll,ll> mp;
set<ll> s;
const ll N = 10000000;
ll lp[N+1];
vector<ll> pr;
void init(){
for (ll i=2; i<=N; ++i) {
    if (lp[i] == 0) {
        lp[i] = i;
        pr.push_back (i);
    }
    for (ll j=0; j<(ll)pr.size() && pr[j]<=lp[i] && i*pr[j]<=N; ++j)
        lp[i * pr[j]] = pr[j];
}
}
int main()
{
    init();
    int n;
    cin>>n;
    ll arr[n];
    for(int i=0;i<n;i++)
        cin>>arr[i];
    ll g=arr[0];
    for(int i=0;i<n;i++)
        g=__gcd(g,arr[i]);
    if(g>1)
    {
        cout<<"not coprime";
        return 0;
    }
    for(int i=0;i<n;i++)
    {
        ll num=arr[i];
        while(num>1)
        {
            ll p=lp[num];
            mp[p]++;s.insert(p);
            while(num%p==0)
                num/=p;
        }
    }
    bool fg=true;
    auto it=s.begin();
    while(it!=s.end())
    {
        ll p=(*it);
        if(mp[p]>1)
            fg=false;
        it++;
    }
    if(fg)
        cout<<"pairwise coprime";
    else
        cout<<"setwise coprime";
}


Measured memory_bytes: 102868
#include <stdio.h>
 
int main() {
    int a[3]={1,0,0};
    char b[2][2], c[2];
    char str[3][2]={"A","B","C"};
    int i = 0;
     
    // Cup Change
    while( scanf("%s,%s", &b[0], &b[1])!=EOF) {
        c[0] = a[ b[0][0] - 'A' ];
        c[1] = a[ b[1][0] - 'A' ];
         
        // change
        a[ b[1][0] - 'A' ] = c[0];
        a[ b[0][0] - 'A' ] = c[1];
    }
     
    // print Alphabet of Cup with coin
    for(i=0; i<3; i++) {
        if (a[i]) printf("%s\n", str[i]);
    }
 
    return 0;
}


Measured memory_bytes: 2048
using System;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args)
    {
        var S = Console.ReadLine();

        var maxCount = 0;
        var count = 0;
        foreach(var str in S)
        {
            if (str == 'R')
            {
                count++;
            }
            else
            {
                maxCount = Math.Max(maxCount, count);
                count = 0;
            }
        }

        maxCount = Math.Max(maxCount, count);
        Console.WriteLine(maxCount);

    }
}


Measured memory_bytes: 25948
#include <bits/stdc++.h> 
#include <vector>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define size_of_array(array) (sizeof(array)/sizeof(array[0]))
using ll =long long;
using namespace std;
using Graph=vector<vector<int>>;
using Field=vector<vector<int>>;

int main(){
    ll a,b;
    cin>>a>>b;
    ll c=abs(a-b);
    ll d=a>b?b:a;
    if(c%2==0){
        cout<<(c/2)+d<<endl;
    }else{
        cout<<"IMPOSSIBLE"<<endl;
    }
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
#define maxn 200010
typedef long long ll;
ll a[maxn];
ll cnt[maxn];
ll nums[maxn];
int tot;
ll ans[maxn];
int main(void)
{
    int N;
    scanf("%d",&N);
    for(int i =0 ;i < N;i ++)
    {
        scanf("%lld",&a[i]);
        if(cnt[a[i]]==0)
            nums[tot ++] = a[i];
        cnt[a[i]] ++;
    }
    ll sum = 0;
    for(int i =0 ;i < tot;i ++)
    {
        ll k = nums[i];
        sum += cnt[k]*(cnt[k]-1)/2;
    }

    for(int i =0 ;i < N;i ++)
    {
        printf("%lld\n",sum - cnt[a[i]]+1);
    }
    return 0;
}


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

int main() {
	int S; cin >> S;
	int h, m;

	h= S/3600; S-= h*3600;
	m= S/60; S-= m*60;

	printf("%d:%d:%d\n", h, m, S);

	return 0;
}


Measured memory_bytes: 3208
import java.util.*;
class Main {
  public static void main (String[] args) throws Exception {
    
    Scanner sc = new Scanner(System.in);
    
    int n = sc.nextInt();
    int [] f = new int [n];
    
    int ans=0;
    
    for(int i=0; i<n; i++){
      f[i]=sc.nextInt();
     }
     
     boolean flag = false;
     int count =0;
     int d=0;
      
     while(count<n){
       if(d==n){
          d=0;
          if(flag==true)ans++;
          flag=false;
          }
       if(f[d]!=0){
         count=0;
         flag = true;
         f[d]--;
         }else{
           if(flag==true)ans++;
           flag=false;
           count++;
          }
        d++;
          
              //System.out.println(f[0]+" "+f[1]+" "+f[2]+" "+f[3]+" "+f[4]+" ans "+ans);
          
       }
       
      System.out.println(ans);

  }
  
}

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

int main() 
{
    lli a, b;
    cin >> a >> b;
    a = a +b;
    if(a == 3)
        cout << 3;
    else if(a == 4)
        cout << 2;
    else
        cout << 1;
    return 0;
}

Measured memory_bytes: 256
S = input()
N = len(S)

s1 = S[0:(N-1)//2]
s2 = S[(N+1)//2:]

s1_1 = list(s1)
s1_2 = list(reversed(s1_1))

if s1_1 == s1_2 and s1 == s2:
    print('Yes')
else:print('No')


Measured memory_bytes: 2940
#include<stdio.h>
#include<string.h>
int main(void)
{
	char s[100001];
	int n,i,j,cnt;
	scanf("%d",&n);
	scanf("%s",s);
	cnt=0;
	for(i=0;i<n-1;i++){
		if(s[i]!=s[i+1]){
			cnt++;
			i++;
		}
	}
	printf("%d\n",cnt);
	return 0;
}

		


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

int main(){
    string s;
    int K;
    cin >> s >> K;

    int N = s.length();
    for(int i=0; i<N; i++){
        if(s[i]=='a') continue;
        if('z'-s[i]+1 <= K){
            K -= 'z'-s[i]+1;
            s[i] = 'a';
        }
    }

    if(K>0){
        s[N-1] += K%26;
    }
    cout << s << endl;
}


Measured memory_bytes: 512
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		final int N = sc.nextInt();
		final int M = sc.nextInt();
		final int E = sc.nextInt();
		final int S = sc.nextInt();
		final int T = sc.nextInt();
		final int R = sc.nextInt();
		
		int[] as = new int[M];
		int[] bs = new int[M];
		boolean[][] adj = new boolean[N + 300][N + 300];
		for(int i = 0; i < M; i++){
			final int a = sc.nextInt();
			final int b = sc.nextInt();
			
			as[i] = a;
			bs[i] = b;
			adj[a][b] = adj[b][a] = true;
		}
		
		int[] cs = new int[E];
		int[] cas = new int[E];
		int[] cbs = new int[E];
		for(int i = 0; i < E; i++){
			final int a = sc.nextInt();
			final int b = sc.nextInt();
			final int c = sc.nextInt();
			
			cs[i] = c;
			cas[i] = a;
			cbs[i] = b;
		}
		
		boolean[][][] already = new boolean[N][R + 1][1 << E];
		LinkedList<Integer> time_queue = new LinkedList<Integer>();
		LinkedList<Integer> move_queue = new LinkedList<Integer>();
		LinkedList<Integer> bits_queue = new LinkedList<Integer>();
		LinkedList<Integer> city_queue= new LinkedList<Integer>();
		
		bits_queue.add(0);
		city_queue.add(S);
		time_queue.add(0);
		move_queue.add(0);
		already[S][0][0] = true;
		
		while(!city_queue.isEmpty()){
			final int city = city_queue.poll();
			final int time = time_queue.poll();
			int bits = bits_queue.poll();
			final int move = move_queue.poll();
			
			if(city == T){
				System.out.println(move);
				return;
			}
			
			// check event
			for(int i = 0; i < E; i++){
				if(city == cs[i]){
					bits |= (1 << i);
				}
			}
			//System.out.println(city + " " + time + " "  + Integer.toBinaryString(bits) + " " + move);
			
			if(!already[S][0][bits]){ // teleport
				already[S][0][bits] = true;
				city_queue.add(S);
				time_queue.add(0);
				bits_queue.add(bits);
				move_queue.add(move + 1);
			}
			
			if(time < R){
				for(int i = 0; i < E; i++){
					if((bits & (1 << i)) != 0){
						adj[cas[i]][cbs[i]] = adj[cbs[i]][cas[i]] = true;
					}
				}
				
				for(int next = 0; next < N; next++){
					if(!adj[city][next]){
						continue;
					}else if(already[next][time + 1][bits]){
						continue;
					}
					
					already[next][time + 1][bits] = true;
					city_queue.add(next);
					time_queue.add(time + 1);
					bits_queue.add(bits);
					move_queue.add(move + 1);
				}
				
				for(int i = 0; i < E; i++){
					if((bits & (1 << i)) != 0){
						adj[cas[i]][cbs[i]] = adj[cbs[i]][cas[i]] = false;
					}
				}
			}
		}
		
		System.out.println(-1);
	}
	
} 

Measured memory_bytes: 31080
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

int main() {
    int n, k;
    cin >> n >> k;
    vec d(k);
    vec a[110];
    vector<bool> has(n, true);
    rep(i, k) {
        cin >> d[i];
        a[i].resize(d[i]);
        rep(j, d[i]) {
            cin >> a[i][j];
            a[i][j]--;
            has[a[i][j]] = false;
        }
    }

    int res = 0;

    rep(i, n) if (has[i]) res++;

    cout << res << endl;
    return 0;
}

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

int comp1(const void *a,const void *b){
	return *(char *)a-*(char *)b;
}
int comp2(const void *a,const void *b){
	return *(char *)b-*(char *)a;
}

int ctoi(char *s){
	return ((s[0]-'0')*1000+(s[1]-'0')*100+(s[2]-'0')*10+(s[3]-'0')*1);
}
int func(char *s){
	int a,b;
	qsort(s,4,sizeof(char),comp2);
	a=ctoi(s);
	qsort(s,4,sizeof(char),comp1);
	b=ctoi(s);
	//printf("%d %d\n",a,b);
	
	return (a-b);
}

int main(){
	char n[9];
	int i,ans,a;
	
	while(1){
		scanf("%s",n);
		if(strcmp(n,"0000")==0)break;
		for(i=0;i<3;i++)if(n[i]!=n[i+1])break;
		if(i==3){
			printf("NA\n");
			continue;
		}
		ans=0;
		while(ctoi(n)!=6174){
			a=func(n);
			n[0]=(a/1000)%10+'0';
			n[1]=(a/100)%10+'0';
			n[2]=(a/10)%10+'0';
			n[3]=(a/1)%10+'0';
			ans++;
		}
		printf("%d\n",ans);
	}
	
	return 0;
}

Measured memory_bytes: 568
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
//#define at(x,i) get<i>(x);//
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
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;
}
int main(){
    ll n;cin >> n;
    ll a=1,b=1;
    rep(i,n){
        ll x,y;cin >> x >>y;
        ll c,d;
        c=(a+x-1)/x;
        d=(b+y-1)/y;
        ll k=max(c,d);
        a=k*x;b=k*y;
    }
    cout << a+b <<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main(void) {
  int n, m;
  cin >> n;
  vector<string> s(0);
  vector<int> cnt(0);
  for (int i = 0; i < n; i++) {
    bool exist = 0;
    string w;
    cin >> w;
    for (int j = 0; j < s.size(); j++) {
      if (w == s[j]) {
        exist = 1;
        cnt[j]++;
        break;
      }
    }
    if (!exist) {
      s.push_back(w);
      cnt.push_back(1);
    }
  }
  cin >> m;
  for (int i = 0; i < m; i++) {
    string w;
    cin >> w;
    for (int j = 0; j < s.size(); j++) {
      if (w == s[j]) {
        cnt[j]--;
        break;
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < cnt.size(); i++) {
    ans = max(ans, cnt[i]);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <math.h>
#include <map>
#include <vector>
#include <algorithm>
#define REP(i, n) for(int i = 0; i < (n); i++)

using namespace std;

int main() {
	long long a, b, n;
	cin >> a >> b >> n;
	long long x = n % b;
	if (x != n)x = b - 1;
	cout << (long long)(a * x / b) << endl;
}

Measured memory_bytes: 3624
#include<iostream> 
#include <algorithm>
#include <vector>
#include <cstdlib>
#include <sstream>
#include <vector>

using namespace std;
#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++)



int main() {
	int a, b,i=0;
	cin >> a >> b;
	while (1) {
		if (a * i - i + 1 >= b) {
			cout << i << endl;
			return 0;
		}
		i++;
	}

	return 0;
}




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

using namespace std;

#define FOR(i, m, n) for (int i = m; i < n; ++i)
#define FORD(i, m, n) for (int i = m; i >= n; --i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define REP1(i, n) for (int i = 0; i <= n; ++i)
#define REPR(i, n) for (int i = n; i >= 0; --i)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

using ll = long long;
using ull = unsigned long long;
using ld = long double;

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

	int k;
	cin>>k;
	REP(i,k){
		printf("ACL");
	}

	return 0;
}

Measured memory_bytes: 3684
#pragma GCC optimize("O3")

#define _GLIBCXX_DEBUG
#include <iostream>
#include <vector>
#include <string>
#include <string_view>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
using namespace std;

/*----------macros----------*/

//output================
#define endl '\n'
#define fcout(a) cout << fixed << setprecision((int)(a))

//typedef===============
typedef long long       ll;
typedef long double     ld;
typedef pair<int, int>  Pii;
typedef pair<ll, ll>    Pll;

//const number==========
constexpr ll INF9   = (ll)1e9 + 1;
constexpr ll INF18  = (ll)1e18 + 1;
constexpr ll MOD    = 1000000007;
constexpr ll MOD2   = 998244353;
constexpr ld PI     = 3.141592653589793L;

//member================
#define pb push_back
#define eb emplace_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second

//others================
#define all(x)          (x).begin(), (x).end()
#define rall(x)         (x).rbegin(), (x).rend()
#define rep(i, n)       for(int i = 0; (i) < (n); ++(i))
#define reps(i, n)      for(int i = 1; (i) <= (n); ++(i))
#define rrep(i, n)      for(int i = n - 1; (i) >= 0 ; --(i))
#define repbit(bit, n)  for(int bit = 0; (bit) < (1 << (n)); ++(bit))
#define ifbit(bit, i)   if((bit) & (1 << (i)))
#define CtoI(c)         int((c)) - int('0')
#define ItoC(c)         char((c) + '0')

//functions=============
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

//vector<int> dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
//vector<int> dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };

/*--------additional--------*/



/*----------main------------*/

int main() {
/*----------fastio----------*/
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    std::ios::sync_with_stdio(false);
/*----------solve-----------*/

    int n; cin >> n;
    vector<int> h(n);
    rep(i, n) cin >> h[i];

    for(int i = 0; i < n-1; ++i){
        if(h[i] > h[i+1]){
            ++h[i+1];
            if(h[i] > h[i+1]){
                cout << "No" << endl;
                return 0;
            }
        }
    }

    cout << "Yes" << endl;

return 0;
}

Measured memory_bytes: 3644
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
#define EPS (1e-10)
int K;
double R,L;
double P,E,T;
double Q;

double rec(int depth,double l,double r){
  double m=(l+r)/2.0;
  if(depth==K)return ((T-E<=m&&m<=T+E)?1:0);
  if(r<T-E || T+E<l)return 0;
  if(T-E-EPS<l && r<T+E+EPS)return 1;
  double A=rec(depth+1,l,m);
  double B=rec(depth+1,m,r);
  if(m>=T)return A*Q+B*P;
  else return A*P+B*Q;
}

int main(){
  while(cin>>K>>R>>L){
    cin>>P>>E>>T;
    Q=1.0-P;
    printf("%.10f\n",rec(0,R,L));
  }
  return 0;
}

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

#define int long long

int32_t main() {
	int n ;
	cin >> n ;
	int a[n+1] , b[n] ;
	for(int i = 0 ; i < n + 1 ; i++) cin >> a[i] ;
	for(int i = 0 ; i < n ; i++) cin >> b[i] ;
	int s = 0 ;
	for(int i = 0 ; i < n ; i++){
		if(a[i] > b[i])  s += b[i] , b[i] = 0;
		else b[i] -= a[i] , s += a[i] ;
		if(a[i+1] > b[i]) a[i+1] -= b[i] ,  s += b[i] , b[i] = 0;
		else b[i] -= a[i+1] , s += a[i+1] , a[i+1] = 0 ;
	}
	cout << s ;
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>

using namespace std;

int main() {
	int a, b, c, x; //aが500円、bが100円、cが50円
	int count = 0;
	cin >> a >> b >> c >> x;
	
	for (int i = 0; i <= a; i++) {
		for(int j = 0; j <= b; j++ ){
			for(int k = 0; k <= c; k++ ){
				if (x == 500 * i + 100 * j + 50 * k) count = count + 1;
			}
		}
	}

	cout << count;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(A) (A).begin(),(A).end()
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)

const ll mod = 1e9+7;
const ll INF = -1*((1LL<<63)+1);
const int inf = -1*((1<<31)+1);

using namespace std;

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

    int N; cin >> N;
    string S; cin >> S;
    int Q; cin >> Q;
    rep(q,Q){
        ll ret = 0;
        int k;
        cin >> k;
        ll a = 0 , b = 0 , c = 0;
        ll ab = 0;
        // a := 区間に含まれる D の個数
        // b := 区間に含まれる M の個数
        // C := 区間に含まれる C の個数

        // ここにk-DMC数を計算する処理を書く

        for(int i=0;i<k;i++){
            // 0 番目から k-1番目までは、そのまま集合に入れていく感じで
            if(S[i]=='D')a++;
            else if(S[i]=='M'){
                ab += a;
                b++;
            }
            else if(S[i]=='C')ret += ab;
        }
        for(int i=k;i<N;i++){
            // k番目からN番目は
            // まず、一番左の要素を出さないといけない
            if(S[i-k]=='D'){
                ab -= b;
                a--;
            }
            else if(S[i-k]=='M')b--;
            
            if(S[i]=='D'){
                a++;
            }else if(S[i]=='M'){
                ab += a;
                b++;
            }else if(S[i]=='C')ret += ab;
        }
        cout << ret << endl;
    }

}

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

int main() {

  string a,b,c,d,e,f;

  cin >> a ;
  for(int i=0;i<3;i++){
  if(a[i]=='1') {
    a[i]='9';
  }

          else{
            a[i]='1';
          }
  }
  cout<<a<<endl;
}


Measured memory_bytes: 256