akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> Pii;
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define INF 1000000000
#define rep(i,a,b) for(int i =(a);i<(b);i++)
#define first fs
#define second ss
inline int Scan() {
    int x=0;int f=1; char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-') f=-1; ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}
    return x*f;
}

template<typename T, typename U>
static inline void amin(T &x, U y)
{
    if (y < x)
        x = y;
}

// call by reference is used in x
template<typename T, typename U>
static inline void amax(T &x, U y)
{
    if (x < y)
        x = y;
}
//////////////////////////////////////end of template//////////////////////////////////////


double dp[3010][3010];


int main(){
 
 int n;
 cin >> n;
 
 double p[n];
 rep(i,0,n) cin >> p[i];
  
  memset(dp,0.00,sizeof(dp));
 
 dp[0][0] = 1.00;
 
 double ans = 0.00;
 
 for(int i = 1;i<=n;i++){
   for(int j = 0;j<=i;j++){	 
	 if(j) dp[i][j] = dp[i-1][j-1]*p[i-1];
	 dp[i][j] += dp[i-1][j]*(1-p[i-1]);
	
  }
 }
 
  
 
 
 for(int i =0;i<=n;i++){
    if( i > n-i) ans+= dp[n][i];
 
 }
 cout << setprecision(20) << ans << endl; 
}




Measured memory_bytes: 71040
#include <stdio.h>

int main(void){
	int a,b,c;
	int i,count;
	count = 0;
	while(scanf("%d%d%d",&a,&b,&c)==3){
		//if(!x&&!y) return 0;
	for(i=a;i<=b;i++){
		if(c%i == 0) count++;
	}
	printf("%d\n",count);
	return 0;
	}
	return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
#define ll long long
#define EPS 1e-9
#define rank asadf
using namespace std;

const int MAXN = 3e5 + 111;
const int MOD = 1e9 + 7;



int main() {
#ifdef LOCAL
    freopen("xxx.in", "r", stdin);
    freopen("xxx.out", "w", stdout);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    int cnt = 0;
    bool ok = false;
    for (int i = 0; i < n; ++i) {
        int a, b;
        cin >> a >> b;
        if (a == b)
            ++cnt;
        else
            cnt = 0;
        if (cnt == 3)
            ok = true;
    }
    cout << (ok ? "Yes" : "No");
    return 0;
}


Measured memory_bytes: 3648
S = input()
T = input()
length = len(T)
results = []
for i in range(len(S)-length+1):
    flag = True
    for s, t in zip(S[i:i+length], T):
        if s == "?":
            continue
        if s != t:
            flag = False
            break
    if flag:
        results.append(S[:i] + T + S[i+length:])

if len(results) == 0:
    print("UNRESTORABLE")
else:
    results = [res.replace("?", "a") for res in results]
    results.sort()
    print(results[0])

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

long long kai(long long a){
  long long b=1;
  r(i,a){
    b*=i+1;
    b%=1000000007;
  }
  return b;
}

int main(){
  ll n,m;
  cin >> n >> m;
  if(n==m){
    cout << kai(n)*kai(m)*2%1000000007<<endl;
  }
  else if(n+1==m||n==m+1){
    cout << kai(n)*kai(m)%1000000007<<endl;
  }
  else cout << 0 << endl;
}


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


int main()
{
    lli q=1;
    //cin>>q;
    
    while(q--)
    {
        lli a,b,k;
        cin>>a>>b>>k;
        lli t=min(a,k);
        a-=t;
        k-=t;
        //cout<<k<<endl;
        b-=min(b,k);
        cout<<a<<' '<<b<<endl;
    }
    return 0;

}

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

Int N, K;
vector<Int> A(200010, 0), F(200010, 0);

bool possible(Int X){
  Int shugyo = 0;
  for(int i=0; i<N; i++){
    shugyo += max((Int)0, (A[i] - X/F[i]));
  }

  return (shugyo <= K);
}

int main(){
  cin >> N >> K;

  Int sum = 0;
  for(int i=0; i<N; i++){ cin >> A[i]; sum += A[i];}
  for(int i=0; i<N; i++) cin >> F[i];

  if(sum <= K){ cout << 0 << endl; return 0; }

  sort(A.begin(), A.begin()+N);
  sort(F.begin(), F.begin()+N, greater<Int>());

  Int ng = -1, ok = 1e13;
  while(ok-ng > 1){
    Int m = (ok+ng)/2;

    if(possible(m)) ok = m;
    else ng = m;
  }
  
  cout << ok << endl;
}

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

int main(){
  int d,g,ans=114514;
  bitset<10> sol;
  cin >> d >> g;
  vector<int> p(d),c(d);
  for(int i=0;i<d;i++) cin >> p.at(i) >> c.at(i);
  
  for(int i=0;i<(1<<d);i++){
    int score = 0,num = 0;
    sol = i;
    for(int j=0;j<d;j++){
      if(sol.test(j)){
        score += 100*(j+1)*p.at(j)+c.at(j);
        num += p.at(j);
      }
    }
//    cout << sol << endl;
//    cout << num << " " << score;
    if(score<g){
      bool flag=false;
      for(int j=d-1;j>=0;j--){
        if(!(sol.test(j))){
          int cnt=0;
          while(score<g && cnt<p.at(j)){
            score += 100*(j+1);
            num++; cnt++;
          }
          flag = true;
        }
        if(flag) break;
      }
    }
    if(score>=g) ans = min(ans,num);
  }
  cout << ans << endl;
}

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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a<=x&&x<b)
#define MP make_pair
#define PB push_back
#define MOD 1000000007
#define INF (1LL<<30)
#define LLINF (1LL<<60)
#define PI 3.14159265359
#define EPS 1e-12
//#define int ll

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

string s[100], t[100];
signed main(void)
{
	int n, m;
  string s[55], t[55];
  cin >> n >> m;
  REP(i, n) cin >> s[i];
  REP(i, m) cin >> t[i];

  REP(i, n-m+1) REP(j, n-m+1){
    bool flag = true;
    REP(k, m) REP(l, m){
      if(s[i+k][j+l] != t[k][l]) flag = false;
    }
    if(flag) {
      cout << "Yes" << endl;
      return 0;
    }
  }

  cout << "No" << endl;
  return 0;
}


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

int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    int c[3][3];
    for(int i=0; i<3; i++)
        for(int j=0; j<3; j++)
            cin>>c[i][j];

    int a[3], b[3];
    a[0]=0; 

    b[0]=c[0][0]-a[0];
    b[1]=c[0][1]-a[0];
    b[2]=c[0][2]-a[0];

    a[1]=c[1][0]-b[0]; 
    a[2]=c[2][0]-b[0];

    for(int i=0; i<3; i++) {
        for(int j=0; j<3; j++) {
            if(a[i]+b[j]!=c[i][j]) {
                cout<<"No"<<endl;
                return 0;
            }
        }
    }
    cout<<"Yes"<<endl;

    return 0;
}

Measured memory_bytes: 256
package main

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

//Util
func nextStr() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func maxInt(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func minInt(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}

func absInt(a int) int {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func absFloat64(a float64) float64 {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func maxFloat64(a, b float64) float64 {
	if a > b {
		return a
	} else {
		return b
	}
}

func minFloat64(a, b float64) float64 {
	if a > b {
		return b
	} else {
		return a
	}
}

func str2Int(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}

func reverse(s string) string {
	runes := []rune(s)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return string(runes)
}

func powInt(p, q int) int {
	return int(math.Pow(float64(p), float64(q)))
}

func isPrime(x int) bool {
	if x == 1 {
		return false
	}
	if x == 2 {
		return true
	}
	if x%2 == 0 {
		return false
	}

	b := true
	rootx := int(math.Sqrt(float64(x)))
	i := 3
	for i <= rootx {
		if x%i == 0 {
			b = false
			break
		}
		i += 2
	}
	return b
}

func PrimeFactors(n int) (pfs []int) {
	// Get the number of 2s that divide n
	for n%2 == 0 {
		pfs = append(pfs, 2)
		n = n / 2
	}

	// n must be odd at this point. so we can skip one element
	// (note i = i + 2)
	for i := 3; i*i <= n; i = i + 2 {
		// while i divides n, append i and divide n
		for n%i == 0 {
			pfs = append(pfs, i)
			n = n / i
		}
	}

	// This condition is to handle the case when n is a prime number
	// greater than 2
	if n > 2 {
		pfs = append(pfs, n)
	}

	return
}

func sumInts(x []int) int {

	total := 0
	for _, v := range x {
		total += v
	}

	return total
}

//Main
const (
	initialBufSize = 10000
	maxBufSize     = 1000000
	mod            = 1e9 + 7
)

var (
	sc *bufio.Scanner = func() *bufio.Scanner {
		sc := bufio.NewScanner(os.Stdin)
		buf := make([]byte, initialBufSize)
		sc.Buffer(buf, maxBufSize)
		return sc
	}()
)

var S string

func main() {
	sc.Split(bufio.ScanWords)

	S = nextStr()
	cur := 0
	l := 1
	prev := ""
	ans := 0
	f := false
	for cur+l <= len(S) {
		if string(S[cur:cur+l]) == prev {
			l++
			continue
			f = true
		}
		//fmt.Println(S[cur:cur+l], prev)
		prev = S[cur : cur+l]
		cur += l
		l = 1
		ans++
		f = false
	}
	if f {
		ans++
	}

	fmt.Println(ans)
}


Measured memory_bytes: 2500
import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T
import Data.List (group)
import Data.Bits (shiftR)

main :: IO ()
main = do
  s <- getLine :: IO String
  let
    r :: Int
    r = sum . map h . g Nothing . map f . group $ s
      where
        f :: String -> (Bool, Int)
        f = (,) <$> (== '<') . head <*> length
        g :: Maybe Int -> [(Bool, Int)] -> [(Int, Int)]
        g Nothing ((True, l) : ps) = g (Just l) ps
        g (Just l) ((False, l') : ps) = (l, l') : g Nothing ps
        g _ ((_, l') : ps) = (0, l') : g Nothing ps
        g (Just l) _ = [(l, 0)]
        g _ _ = []
        h :: (Int, Int) -> Int
        h (l, l') = shiftR (l * pred l) 1 + shiftR (l' * pred l') 1 + max l l'
  print r

unsafeSignedDecimal :: T.Text -> Int
unsafeSignedDecimal s = case T.signed T.decimal s of
  Right (n, _) -> n


Measured memory_bytes: 32124
#include <iostream>
#include <cmath>
#include <numeric>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <algorithm>
using namespace std;

using ll = long long;

#define MOD 1000000007

#define FOR(i, m, n) for (ll i = m; i <= n; i++)
#define FORR(i, m, n) for (ll i = m; i >= n; i--)

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

int main() {
    string S;
    ll Q;
    cin >> S >> Q;

    deque<char> D;

    FOR(i, 0, S.size() - 1) {
        D.push_back(S[i]);
    }

    bool isAsc = true;

    FOR(i, 1, Q) {
        ll T;
        cin >> T;
        if (T == 1) {
            isAsc = !isAsc;
        }
        else {
            ll F;
            char C;
            cin >> F >> C;
            if (F == 1 && isAsc || F == 2 && !isAsc) {
                D.push_front(C);
            }
            else {
                D.push_back(C);
            }
        }
    }

    string ans;
    ll size = D.size();

    FOR(i, 1, size) {
        if (isAsc) {
            ans.push_back(D[0]);
            D.pop_front();
        }
        else {
            ans.push_back(D[D.size() - 1]);
            D.pop_back();
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1412
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repb(i, n) for (int i = (n-1); i >= 0; i--)
#define rea(i, a, b) for (int i = (a); i < (b); i++)
#define reab(i, a, b) for (int i = (a)-1; i >= (b); i--)
#define ALL(a) (a).begin(),(a).end()
#define SZ(x) ((int)(x).size())
#define PRINT(V) for (auto v:(V)) {cerr << v << " ";} cerr << endl
#define dump(x) cerr << #x << " : " << (x) << endl
#define dump2(x, y) cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")" << endl
inline ll GCD(ll a, ll b){return b ? GCD(b, a % b) : a;}
const int MOD = 1000000007;
/* END OF TEMPLATE */

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

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

using namespace std;

int main()
{
  int n, d;
  vector<vector<int>> vals;
  cin >> n >> d;
  vals.resize(n, vector<int>(d));
  for(int x = 0; x < n; x++)
  {
    for(int y = 0; y < d; y++)
    {
      cin >> vals[x][y];
    }
  }
  int r = 0;
  for(int x = 0; x < n; x++)
  {
    for(int y = x + 1; y < n; y++)
    {
      int temp = 0, tmp;
      for(int z = 0; z < d; z++)
      {
        temp += (vals[x][z] - vals[y][z]) * (vals[x][z] - vals[y][z]);
      }
      tmp = sqrt(temp);
      if(tmp == 0 || (!(temp%tmp) && temp/tmp == tmp))
      {
        r++;
      }
    }
  }
  cout << r;
}

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

int main() {
  int n,m;
  cin >> n >> m;
  int count[n];
  ll h[n];
  rep(i,n){
    cin >> h[i];
    count[i]=0;
  }
  
  rep(i,m){
    int a,b;
    cin >> a >> b;
    
    if(h[a-1]<=h[b-1]){
      count[a-1]=1;
    }
    
    if(h[b-1]<=h[a-1]){
      count[b-1]=1;
    }    
  }
  
  int ans=0;
  rep(i,n){
    if(count[i]==0){
      ans++;
    }
  }
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4732
#include <iostream>
using namespace std;
int main(){
    int N; cin >> N;
  	int param = 0;
	for(int i = 1; i <= 9; i++){
		for(int j = 1; j <= 9; j++){
			if(N == i * j) {cout << "Yes" <<endl; param = 1;break;}
        }
      if(param == 1)break;
    }
  	 if(param == 0)cout << "No" <<endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  char w[101] = { '\0' };
  scanf("%s", w);
  char temp;
  int i,j;
  int n = 1;
  int flag = 1;
  while(w[n] != '\0') n++;
  for(i = 0; i < n; i++){
    for(j = i + 1; j < n; j++){
      if(w[i] < w[j]){
	temp = w[i];
	w[i] = w[j];
	w[j] = temp;
      }
    }
  }
  i = 0;
  while(w[i] != '\0'){
    if(w[i] == w[i + 1]) i += 2;
    else{
      flag = 0;
      break;
    }
  }
  if(flag) printf("Yes\n");
  else printf("No\n");
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
using namespace std;
 
int mod = 1000000007;
int main() {
	// your code goes here
	int N;
	cin >> N;
	long long j = 1;
	for(long long i= 1;i <= N;i++){
		j *= i;
		j %= mod;
	}
	cout << j << endl;
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<set>
#include<algorithm>
#define maxn 100005
using namespace std;
typedef set<int>::iterator siter;
int n,fa[maxn];
bool a[maxn];
char s[maxn];
int main()
{
	scanf("%s",s+1);
	n=strlen(s+1);
	for(int i=1;i<=n;i++) a[i]=s[i]-'0';
	if(!a[1]||a[n]) { printf("-1\n"); return 0; }
	for(int i=1;i<=n;i++)
		if(a[i]!=a[n-i]) { printf("-1\n"); return 0; }
	int p=1;
	for(int i=2;i<=n/2+1;i++)
	{
		fa[i]=p;
		if(a[n/2-i+2]) p=i;
	}
	for(int i=n/2+2;i<=n;i++) fa[i]=1;
	for(int i=2;i<=n;i++) printf("%d %d\n",i,fa[i]);
}

Measured memory_bytes: 1664
#include <iostream>
#include <sstream>
#include <string>
using namespace std;

int main() {
	long long n;
	while (cin >> n, n) {
		int b=1;
		long long m=0;
		while (n) {
			m += b*(n%8);
			n /= 8;
			b *= 10;
		}
		stringstream ss;
		string s;
		ss << m;
		ss >> s;
		ss.str("");
		ss.clear(stringstream::goodbit);
		for (int i=0; i<s.size(); i++) {
			if (s[i]=='4') s[i]='5';
			else if (s[i]=='5') s[i]='7';
			else if (s[i]=='6') s[i]='8';
			else if (s[i]=='7') s[i]='9';
		}
		ss << s;
		ss >> m;
		cout << m << endl;
	}
	return 0;
}

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

int main(){
  int A,B;
  cin >> A >> B;
  if (A==B){
    cout << "Draw" << endl;
  }else{
    if((A==1||A>B)&& B!=1){
      cout << "Alice" << endl;
    }else{
      cout << "Bob"  << endl;
    }
  }
}

Measured memory_bytes: 256
import heapq as hq

N, M = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
que = []
for i, a in enumerate(A):
    hq.heappush(que, (-a, str(i))) 

for _ in range(M):    
    priority, a = hq.heappop(que)    
    if priority == 0:
        break
    priority = - priority
    priority //= 2
    hq.heappush(que, (-priority, a))

sum_ = 0
for q in que:
    sum_ += q[0]

print(-sum_)


Measured memory_bytes: 23664
# include <bits/stdc++.h>
# define ll int64_t
# define rep(i,n) for(ll i=0;i<n;i++)
# define rrep(i,n) for(ll i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define mod 1000000007
# define vec vector
#define dump(x) cerr<<#x<<"="<<x<<endl
#define Array vec<ll>
using namespace std;

bool compare_by_b(pair<string,ll> a,pair<string,ll> b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

bool my_compare(pair<string,ll> a,pair<string,ll> b){
    
    if(a.first != b.first) return a.first<b.first;
    if(a.second != b.second) return a.second>b.second;
    else return true;
}

ll factorial(ll n){
    ll x=1;
    rrep(i,n) (x*=i)%=mod;
    return x;
}

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

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

//累乗だってさ
ll modpow(ll a,ll n,ll mod1) {
    ll res=1;
    while(n>0){
        if(n&1) res=res*a%mod1;
        a = a*a%mod1;
        n >>= 1;
    }
    return res;
}

ll combination(ll n,ll r){
    ll sum=1;
    rrep(i,min(r,n-r)) (sum*=(n-i+1))%=mod;
    return sum;
}

//逆元だってさ
ll modinv(ll a,ll mod1) {
    return modpow(a, mod1 - 2, mod1);
}

ll n,m,ans=0;

void dfs(vec<vec<ll>>& g, ll v,Array order) {
    order.pb(v);
    if (order.size() == n) {
        ans++;
        return;
    }
    for (auto next : g[v]) {
        bool flag = false;
        for (auto i : order) if (i == next) flag = true;
        if (flag) continue;
        dfs(g, next, order);
    }
}

void solve(){
    cin>>n>>m;
    vec<vec<ll>> g(n);
    rep(i,m){
        ll a,b;
        cin>>a>>b;
        a--; b--;
        g[a].pb(b);
        g[b].pb(a);
    }
        Array order;
        dfs(g,0,order);
        cout<<ans<<endl;
    
}

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


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

int main() {
    int Q,i,j,m=0;
    cin >> Q;
    vector<int> l(Q),r(Q);

    for(i=0; i<Q; i++) {
        cin >> l.at(i) >> r.at(i);
        m = max(m, r.at(i));
    }
    
    vector<bool> sl(m+1,1);
    vector<int> c(m+1);

    for(i=2; i<=m; i++)
        if(sl.at(i))
            for(j=i*2; j<=m; j+=i)
                sl.at(j) = 0;
    
    for(i=3; i<=m; i++) {
        c.at(i) = c.at(i-1);
        if(sl.at(i) && sl.at((i+1)/2))
            c.at(i)++;
    }

    for(i=0; i<Q; i++)
        cout << c.at(r.at(i))-c.at(l.at(i)-1) << endl;
}

Measured memory_bytes: 1792
import java.util.*;

public class Main {
    public static long di(long a,long b){
        return(a+b-1)/b;
    }
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        long a=1,b=1;
        for(int i=0;i<n;i++){
            long x=Long.parseLong(sc.next());
            long y=Long.parseLong(sc.next());
            long m=Math.max(di(a,x),di(b,y));
            a=x*m;
            b=y*m;
        }
        System.out.println(a+b);
    }
}


Measured memory_bytes: 22996
#include <iostream>
#include <bits/stdc++.h>
#include <time.h>
#include <sys/timeb.h>
#include <cstdio>
#include <sys/time.h>

using namespace std;
#define ll long long
#define uint unsigned int
#define ulong unsigned long long int

template<typename T> bool InRange(T t, T l, T r){ return l <= t && t < r; }


class MaxFlow_Dinic{
	// arihon is god
	struct Edge {
		public:
			int To, Cap, Rev;
			Edge(int to = 0,int cap = 0,int rev = 0){
				To = to; Cap = cap; Rev = rev;
			}
	};
	
	vector<vector<Edge>> G;
	vector<int> Level;
	vector<int> Iter;
	
public :
	const int Inf = (int) 1e9;
	int N;
	void Init(int n){
		N = n;
		G.resize(N);
		Level.resize(N);
		Iter.resize(N);
	}
	
	
	void AddEdge(int from, int to, int cap){
		G[from].push_back((Edge){to, cap, (int) G[to].size()});
		G[to].push_back((Edge) {from, 0, (int) G[from].size() - 1});
	}

private:
	void bfs(int s){
		for(int j=0;j<G.size();j++)Level[j] = -1;
		queue<int> Q;
		Level[s] = 0;
		Q.push(s);
		
		while(Q.size()>0){
			auto v = Q.front(); Q.pop();
			for(auto& e : G[v]){
				if(e.Cap > 0 && Level[e.To] < 0){
					Level[e.To] = Level[v] + 1;
					Q.push(e.To);
				}
			}
		}
	}
	
	int dfs(int v, int t, int f){
		if(v == t) return f;
		for(;Iter[v] < G[v].size(); Iter[v]++){
			auto& e = G[v][Iter[v]];
			if(e.Cap > 0 && Level[v] < Level[e.To]){
				int d = dfs(e.To, t, min(f,e.Cap));
				if(d > 0){
					e.Cap -= d;
					G[e.To][e.Rev].Cap += d;
					return d;
				}
			}
		}
		return 0;
	}
	
public:
	int MaxFlow(int s,int t){
		int flow = 0;
		while(true){
			bfs(s);
			if(Level[t] < 0) return flow;
			for(int i=0;i<N;i++) Iter[i] = 0;
			
			int f;
			while( ( f = dfs(s,t,Inf)) > 0){
				flow += f;
			}
		}
	}
	
};


int main(){
	int N;
	cin >> N;
	vector<int> A(N),B(N),C(N),D(N);
	for(int i=0;i<N;i++) cin >> A[i] >> B[i];
	for(int i=0;i<N;i++) cin >> C[i] >> D[i];
	
	MaxFlow_Dinic mf;
	int NN = 2 * N + 2;
	int src = 2 * N;
	int sinc = src + 1;
	mf.Init(NN);
	for(int i=0;i<N;i++){
		mf.AddEdge(src, i, (int) 1);
	}
	for(int i=0;i<N;i++){
		mf.AddEdge(i + N, sinc, (int) 1);
	}
	for(int i=0;i<N;i++){
		for(int j=0;j<N;j++){
			if(A[i] < C[j] && B[i] < D[j]) mf.AddEdge(i, j + N, 1);
		}
	}
	
	cout << mf.MaxFlow(src, sinc) << endl;
	
	
	
	
	
	
    return 0;
}

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

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

using ll = long long int;
const ll MOD = 1e9 + 7;

template<long long int P>
struct _mint {
  long long int x;
  _mint(long long int x = 0): x((x % P + P) % P) {}

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

  _mint& operator+=(const _mint a) {
    if((x += a.x) >= P) {
      x -= P;
    }
    return *this;
  }
  _mint& operator-=(const _mint a) {
    if((x += P - a.x) >= P) {
      x -= P;
    }
    return *this;
  }
  _mint& operator*=(const _mint a) {
    (x *= a.x) %= P;
    return *this;
  }
  _mint& operator/=(const _mint a) {
    return (*this) *= a.inv();
  }

  _mint operator+(const _mint a) const {
    _mint res(*this);
    return res += a;
  }
  _mint operator-(const _mint a) const {
    _mint res(*this);
    return res -= a;
  }
  _mint operator*(const _mint a) const {
    _mint res(*this);
    return res *= a;
  }
  _mint operator/(const _mint a) {
    _mint res(*this);
    return res /= a;
  }

  _mint pow(long long int t) const {
    if(! t) return 1;
    _mint a = pow(t >> 1);
    a *= a;
    if(t & 1) a *= *this;
    return a;
  }

  // for prime P
  _mint inv() const {
    return pow(P - 2);
  }
};
using mint = _mint<2019>;

int main() {
  std::string s;
  std::cin >> s;

  int N = s.size();

  std::vector<int> S(N);
  rep(i, N) {
    S[i] = s[i] - '0';
  }

  std::vector<mint> T(N + 1);
  mint d = 1;
  std::map<ll, ll> cnt;
  T[N] = 0;
  ++cnt[0];
  for(int i = N - 1; i >= 0; --i) {
    T[i]  = T[i + 1] + d * S[i];
    d *= 10;
    ++cnt[T[i].x];
  }

  ll ans = 0;
  rep(i, 2019) {
    ans += cnt[i] * (cnt[i] - 1) / 2;
  }
  std::cout << ans << '\n';
}


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

using namespace std;

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

using ll = long long;

const char sp = ' ';
const char cmm = ',';
const int MOD = 1e9+7;
const int INF = 1e9;
const ll LINF = 1e18;

ll mod(ll a, ll b){return (a%b+b)%b;}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powMod(ll b, ll e, ll m){ll r=1;while(e>0){if(e&1)r=(r%m)*(b%m)%m;b=(b%m)*(b%m)%m;e>>=1;}return r;}
double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}

template<typename T>
void ppp(T n){cout << n << endl;}
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
	int len = v.size();
    cout << '[';
	for (int i = 0; i < len; ++i) {
		s << v[i]; if (i < len-1) s << ", ";
	}
    cout << ']';
	return s;
}

int main(){

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

    string s;
	cin >> s;

	int n = s.size();
	int cnt1 = 0, cnt2 = 0;
	rep(i, n){
	    if(i%2==0 and s[i] != '1' or i%2 and s[i] != '0') ++cnt1;
	}
	rep(i, n){
	    if(i%2 and s[i] != '1' or i%2==0 and s[i] !='0') ++cnt2;
	}

	ppp(min(cnt1, cnt2));

    return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<limits>
#include<iomanip>
#include<cmath>
#include<climits>

using namespace std;

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

const int mod=1e9+7;

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

int main(){
    int n;
    cin >> n;
    vector<int> a(n),lgcd(n),rgcd(n);
    for(int i=0;i<n;i++){
        cin >> a[i];
        lgcd[i]=(i==0?a[i]:gcd(lgcd[i-1],a[i]));
    }
    for(int i=n-1;i>=0;i--){
        rgcd[i]=(i==n-1?a[n-1]:gcd(rgcd[i+1],a[i]));
    } 
    int ans=0;
    for(int i=0;i<n;i++){
        if(i==0){
            ans=max(ans,rgcd[1]);
        }else if(i<n-1){
            ans=max(ans,gcd(lgcd[i-1],rgcd[i+1]));
        }else if(i==n-1){
            ans=max(ans,lgcd[n-2]);
        }    
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
  int n, ans;
  while (cin >> n) {
    ans = 0;
    for (int i=0;i<10000;i++) {
      int a = i%10, b = i%100/10, c = i%1000/100, d = i%10000/1000;
      if (a + b + c + d == n) {
        // cout << " " << a << ", " << b << ", " << c << ", " << d << endl;
        ans++;
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 3096
#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <algorithm>

using namespace std;

string A,B;
int lenA,lenB;

short dp[4096][4096];

int main(){
  while(cin >> A >> B){
    lenA = A.size(), lenB = B.size();
    memset(dp, 0, sizeof(dp));
    for(int i=0;i<lenA;i++){
      for(int j=0;j<lenB;j++){
	if(A[i]==B[j]) dp[i+1][j+1] = dp[i][j]+1;
      }
    }
    short res = 0;
    for(int i=0;i<=lenA;i++) for(int j=0;j<=lenB;j++) res = max(res, dp[i][j]);
    cout << res << endl;
  }
  return 0;
}

Measured memory_bytes: 33984
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;

/*
<url:https://agc014.contest.atcoder.jp/tasks/agc014_b>
問題文============================================================
 高橋君は木の問題が苦手です。そこで、青木君は高橋君の練習相手になってあげることにしました。
 
 まず、高橋君は N 頂点からなる木を用意し、頂点に 1 から N の番号を付けました。 そして、各辺に 0 と書きました。
 
 次に、青木君は高橋君に M 個のクエリを与えました。i 個目のクエリは以下のような内容です。
 
 頂点 ai と頂点 bi を結ぶパス上の辺すべてに対して、書かれている数を 1 増やす。
 全てのクエリを終えた後、高橋君は青木君にどの辺を見ても書かれている数が偶数になったと伝えました。
 しかし、青木君は最初に高橋君が用意していた木を確認していなかったので、
 高橋君が正しくクエリを処理できたか分かりませんでした。
 
 青木君を助けるために、高橋くんの言う性質を満たす木が存在するかどうかを判定してください。
=================================================================

解説=============================================================
適当に投げて見たら通った。
 全ての頂点の次数が偶数であればok
 一つでも奇数が存在すると　木が作れないことが証明できるらしい（根つき木やLCAで考える）
 詳細は解説を読む
 と思ったけど、考えて見たら確かにア
 
 辺(a,b)が存在し、木の根が r とすれば
 a-r-b への経路と a-b への経路　を同一視しても問題ない
 
 なぜなら問題は利用回数が偶数であればいいので, a-bが根を経由しなくても a-r と r-b をたどる際に
 必ず a or b から r への辺が偶数回使用されるためである
 
 よって、この考えから全ての辺が r を経由すると考えた時、全ての頂点の字数が偶数回存在しないと
 各辺の利用回数が偶数回にならないことは　実際に木を自分で書いて見たりすると明らか
================================================================
*/
string solve(){
    ll N,M; cin >> N >> M;
    vector<ll> a(M),b(M);
    for(int i = 0; i < M;i++){
        cin >> a[i] >> b[i];
    }
    vector<ll> cnt(N+1);
    for(int i = 0; i < M;i++){
        cnt[a[i]]++; cnt[b[i]]++;
    }
    for(auto v:cnt){
        if(v&1) return "NO";
    }
    return "YES";
}
int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
    cout << solve() << endl;
	return 0;
}


Measured memory_bytes: 2560
import Control.Arrow
import Data.List

main :: IO ()
main = print . solve =<< getLine

solve :: String -> Int
solve s = iter len $ reverse $ take len $ tail $ splits s
  where
    len = length s `div` 2 - 1
    iter _ []               = 0
    iter m ((xs, ys) : rs)  = if xs `isPrefixOf` ys then 2*m else iter (m - 1) rs

splits :: [a] -> [([a], [a])]
splits [] = [([], [])]
splits xxs@(x:xs) = ([], xxs) : map (first (x:)) (splits xs)


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

template<typename M>
struct segment_tree{
	typedef function<M(M, M)> F;
	int size;//2冪
	vector<M> val;//1-indexed
	F f;//結合関数
	M e;//単位元

	segment_tree(int N, vector<M> &data, F f, M e) : f(f), e(e){
		size = 1;
		while(size < N) size *= 2;
		val.assign(2 * size, e);
		for(int i = 0; i < N; i++) val[size + i] = data[i];
		for(int i = N; i < size; i++) val[size + i] = e;
		for(int i = size - 1; i > 0; i--) val[i] = f(val[2 * i], val[2 * i + 1]);
	}

	//k番目の要素をxに変更する
	void update(int k, M x){
		k += size;
		val[k] = x;
		while(k /= 2) val[k] = f(val[2 * k], val[2 * k + 1]);
	}

	//[a, b)の演算の結果を返す
	M query(int a, int b){
		M L = e, R = e;
		for(a += size, b += size; a < b; a /= 2, b /= 2){
			if(a & 1) L = f(L, val[a++]);
			if(b & 1) R = f(val[--b], R);
		}
		return f(L, R);
	}
};

//(int, min, inf)
#define inf (((int)1 << 31) - 1)

int mymin(int x, int y){
	return x < y ? x : y;
}

signed main(){
	int N, Q, i;
	scanf("%lld%lld", &N, &Q);
	vector<int> data(N, inf);
	segment_tree<int> t(N, data, mymin, inf);
	for(i = 0; i < Q; i++){
		int c, x, y;
		scanf("%lld%lld%lld", &c, &x, &y);
		if(c == 0){
			t.update(x, y);
		}
		else{
			printf("%lld\n", t.query(x, y + 1));
		}
	}
	return 0;
}


Measured memory_bytes: 5724
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using static MyIO;

namespace atcoder
{
    class Program
    {
        static void Main(string[] args)
        {

            int N = GetInt();
            long K = GetLong();
            int[] A = GetInts(N);

            int Start = 0;
            int Next = new int();

            bool[] Set = new bool[N];
            Set[0] = true;
            int count = 0;

            for (int i = 0; i < N; i++)
            {
                Next = A[Start];
                Start = Next - 1;
                if (Set[Start] == true)
                {
                    count++;
                    break;
                }
                Set[Start] = true;
                count++;
            }

            int pos = Start;
            int toPos = 0;

            Start = 0;

            for (int i = 0; i < N; i++)
            {
                if (Start == pos)
                {
                    toPos = i;
                    break;
                }
                Next = A[Start];
                Start = Next - 1;
            }

            long loop = count - toPos;

            if(K >= toPos)
            {
                K -= toPos;
                K %= loop;
                K += toPos;
            }
            Start = 0;
            for (int i = 0; i < K; i++)
            {
                Next = A[Start];
                Start = Next - 1;
            }

            Console.WriteLine(Next);

            return;
        }
    }
}


public static class MyIO
{
    private static string[] args = null;
    private static int num = -1;
    private static int used = -1;

    private static string getArg()
    {
        if (used == num)
        {
            args = Console.ReadLine().Split(' ');
            num = args.Length;
            used = 0;
        }
        return args[used++];
    }

    public static int GetInt() => int.Parse(getArg());
    public static long GetLong() => long.Parse(getArg());
    public static double GetDouble() => double.Parse(getArg());
    public static string GetString() => getArg();
    public static char GetChar() => getArg()[0];
    public static int[] GetInts(int N) => Enumerable.Range(0, N).Select(_ => GetInt()).ToArray();
    public static long[] GetLongs(int N) => Enumerable.Range(0, N).Select(_ => GetLong()).ToArray();
    public static double[] GetDoubles(int N) => Enumerable.Range(0, N).Select(_ => GetDouble()).ToArray();
    public static string[] GetStrings(int N) => Enumerable.Range(0, N).Select(_ => GetString()).ToArray();
}

Measured memory_bytes: 43292
object Main {

  def main(args: Array[String]): Unit = {
    val Array(n,k) = readLine().split(" ").map(_.toInt)
    val S = readLine().toArray

    val start = S.foldLeft( ('a',List[Int]()))( (t, n) => {
      val list = t._2
      if(n == t._1) (n, (list.head + 1) :: list.tail)
      else (n, 1 :: list)
    })._2.map(_ - 1).sum

    println( (start + 2 * k) min (n -1))



  }
}

Measured memory_bytes: 39924
//----AUTHOR:kkdrummer----/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef    long long   ll;
typedef    long double   ld;
//typedef    unordered_set<ll>   usll;
//typedef    unordered_multiset<ll>   umsll;
typedef    multiset<ll>   msll;
typedef    set<ll>   sll;
typedef    vector<ll>   vll;
typedef    pair<ll,ll>   pll;
typedef    vector<pll>   vpll;
typedef    priority_queue<ll>   pqll;
typedef    vector<int>   vi;
typedef    set<int>   si;
typedef    multiset<int>   msi;
//typedef    unordered_multiset<int>   umsi;
//typedef    unordered_set<int>   usi;
typedef     pair<int,int>   pi;
typedef    vector<pi>   vpi;
typedef    set<pi>   spi;
typedef    priority_queue<int>   pqi;
typedef    tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>   ind_set;
typedef    tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>   ind_setll;
#define    in   insert
#define    fi   first
#define    se   second
#define    pb   push_back
#define    mp   make_pair
#define    be   begin
#define    en   end
#define    itr   iterator
#define io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define    mo   1000000007
#define    inf  9223372036854775807
#define    ninf   -inf
#define    ima   2147483647
#define    imi   -ima
#define    oncnt    __builtin_popcount
#define    zerobegin   __builtin_clz
#define    zeroend   __builtin_ctz
#define    parity   __builtin_parity
#define all(x) x.be(),x.en()
#define    eps   1e-9
#define    coutd   cout<<setprecision(10)<<fixed
#define    debg(x)  cout<<"#x = "<<x<<"\n";
const    ld   PI=3.14159265359;
inline ll modpow(ll x,ll n){if(n==0)return 1;if(n==1)return(x%mo);ll u=(modpow(x,n/2));u=(u*u)%mo;if(n%2!=0)u=(u*x%mo)%mo;return u;}
inline ll modinv(ll x){return modpow(x,mo-2);}
inline ll mmul(ll a,ll b){    if(a>=mo)a=a%mo;if(b>=mo)b=b%mo;if(a*b>=mo)return(a*b)%mo;return(a*b);}
inline ll madd(ll a, ll b){if(a>=mo)a=a%mo;if(b>=mo)b=b%mo;if(a+b>=mo)return(a+b)%mo;return(a+b);}
inline ll msub(ll a, ll b){if(a>=mo)a=a%mo;if(b>=mo)b=b%mo;return(((a-b)%mo+mo)%mo);}
inline ll mdiv(ll a,ll bb){if(a>=mo)a=a%mo;ll b=modinv(bb);if(b>=mo)b=b%mo;if(a*b>=mo)return(a*b)%mo;return(a*b);}
inline ll gcd(ll a,ll b){return __gcd(a,b);}

ll dp[2001][2001];

int main()
{
io
int testcases=1;//cin>>testcases;
while(testcases--)
{


int n,m;
cin>>n>>m;
int s[n];
int t[m];
for(int i=0;i<n;i++)
cin>>s[i];

for(int i=0;i<m;i++)
cin>>t[i];


for(int i=0;i<=n;i++)
{
	for(int j=0;j<=m;j++)
	dp[i][j]=0;
}


for(int i=0;i<=n;i++)
{
	for(int j=0;j<=m;j++)
	{
		if(i==0||j==0)
		dp[i][j]=1;
		else
		{
			
			dp[i][j]=madd(dp[i][j],madd(dp[i-1][j],dp[i][j-1]));
			if(s[i-1]!=t[j-1])
			dp[i][j]=msub(dp[i][j],dp[i-1][j-1]);
		}
	}
}

cout<<dp[n][m];

}return 0;}


Measured memory_bytes: 31616
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pl = pair<ll,ll>;
using pi = pair<int,int>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//(a+b-1)/b
//priority_queue<ll, vector<ll>, greater<ll>> q;

signed main(){
	//cout << fixed << setprecision(10);
    ll n; cin >> n;
	//vl table(100100);
	ll ans = 0;
	rep(i,1,n){
		//if(n % i == 0)continue;
		ans += (n / i);
		ans -= (n % i == 0);
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3628
N=int(input())
A=list(map(int,input().split()))
l=[0]*(N+1)
t=0
for i in range(N):
    t+=A[i]
    l[i]=t
l.sort()
t=l[0]
c=1
a=0
for i in range(1,N+1):
    if l[i]==t:
        c+=1
    else:
        a+=c*(c-1)//2
        t=l[i]
        c=1
print(a+c*(c-1)//2)

Measured memory_bytes: 25720
#include<bits/stdc++.h>
#define ll               long long
#define mod              1000000007
#define endl              "\n"
#define fast               ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb                push_back
#define all(v)             v.begin(),v.end()
#define inp(V,n)      for(int i=0;i<n;i++){cin >> V[i];}
#define oup(V,n)     {for(int i=0;i<n;i++){cout <<  V[i] << " "  ;} cout << endl;}
using namespace std;
ll factorial(ll n)
{
    return (n == 1 || n == 0) ? 1 : n * factorial(n - 1);
}
ll gcd(ll a, ll b)
{
    if (a == 0)
      return b;
    return gcd(b % a, a);
}
ll lcm(ll a, ll b)
{
   return (a*b)/gcd(a, b);
}
bool sortByVal(const pair<ll,ll> &a,
               const pair<ll,ll> &b)
{
    return (a.second > b.second);
}
ll Powb(ll b,ll n)
{
    if(n==0) return 1LL;
    if(n==1) return b;
    ll temp = Powb(b,n/2);
    if(n%2==0){return (temp*temp)%mod;}
    else{return (b*((temp*temp)%mod))%mod;}
}
int main()
{
     fast;
     {
      ll i,j,c=0,d=0,e=0,f=0,g=0,h=0,n,sum=0,k;
      cin>>k;
      queue<ll> a;
      for(i=0;i<9;i++)
      {
      	a.push(i+1);
	  }
	  for(i=0;i<k;i++)
      {
	  	c=a.front();
	  	if(c%10!=0)
	  	{
	  	   e=c*10+(c%10)-1;
			 a.push(e);
		}
		e=c*10+(c%10);
		   a.push(e);
		   if(c%10!=9)
		   {
		   	e=c*10+(c%10)+1;
		   	a.push(e);
			 }	
		a.pop();
	  }
	  cout<<c;
     
     }



}


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

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(), (x).end()

using namespace std;

template <typename T> T &chmin(T &a, const T &b) {return a = min(a, b);}
template <typename T> T &chmax(T &a, const T &b) {return a = max(a, b);}

using ll = long long;
using ld = long double;

const int INF = 1e9;
const ld eps = 1e-9, pi = acos(-1.0);

bool row[100005];
bool col[100005];

int main(){
  int N, W, H;
  cin >> N >> W >> H;
  REP(i, N){
    int x, y, w;
    cin >> x >> y >> w;
    int fr, to;
    fr = max(0, x-w); to = min(x+w-1, W-1);
    memset(&col[fr], 1, (to-fr+1)*sizeof(col[0]));
    fr = max(0, y-w); to = min(y+w-1, H-1);
    memset(&row[fr], 1, (to-fr+1)*sizeof(row[0]));
  }
  bool res = true;
  REP(i, W){
    if(col[i]==0)
      res = false;
    if(!res)
      break;
  }
  if(res){
    cout << "Yes" << endl;
    return 0;
  }
  res = true;
  REP(i, H){
    if(row[i]==0)
      res = false;
    if(!res)
      break;
  }
  cout << (res ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 3304
use proconio::{fastout, input};

use std::collections::BTreeMap;

#[fastout]
fn main() {
    input! {
        n: usize,
        a: [u64; n],
    }
    let mut m = BTreeMap::new();
    for i in 0..n {
        *m.entry(i as i64 + a[i] as i64).or_insert(0) += 1;
    }
    let mut ans = 0 as i64;
    for i in 0..n {
        ans += *m.entry(i as i64 - a[i] as i64).or_insert(0);
    }
    println!("{}", ans);
}


Measured memory_bytes: 15596
n = int(input())
A = list(map(int, input().split()))

ans = 1
for a in A:
    # if a == 1:
    #     ans *= 2
    # else:
        ans *= 3
# 全体から全部奇数の場合を引く
odd = 1
for a in A:
    if a%2 == 0:
        odd *= 2

print(ans-odd)


Measured memory_bytes: 3064
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<string>
#include<algorithm>
using namespace std;
const int MaxN = 1e5;

char a[5][5],lj;

int main()
{
	int n,T;
		for(int i = 1;i <= 3;i++)
		{
			for(int j = 1;j <= 3;j++)
			{
				scanf("%c",&a[i][j]);
			}
			scanf("%c",&lj);
		}
		printf("%c%c%c\n",a[1][1],a[2][2],a[3][3]);
	return 0;
}

Measured memory_bytes: 128
#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 n;
void dfs(string s,char mx){
    //文字列を作るmxは使用可能な文字の種類
    //文字数nになったら終わり（終端条件）
    if(s.size()==n){
        cout << s << endl;
        return;
    }
    
    //分岐cは文字種類
    for(char c = 'a'; c <= mx+1 ;c++){
        string t = s;
        t += c;
        dfs(t,max(c,mx));
    }
   
    
}
 
int main() {
    cin >> n;
    dfs("",'a'-1);
    return 0;
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
#define REP(i, n) for (long long i = 0; i < (long long)n; i++)
//#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using Vl = vector<ll>;
using vi = vector<int>;
using Graph = vector<vi>;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  // std::cout << std::fixed << std::setprecision(15); //"for float-base
  // problem"
  int N;
  cin >> N;
  string S, T, U;
  cin >> S >> T;
  REP(i, N) {
    U.push_back(S[i]);
    U.push_back(T[i]);
  }
  cout << U << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {

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

	scanf("%d %d %d", &a, &b, &c);

	if (a < b) {
		d = a;
		e = b;
	}else {
		d = b;
		e = a;
	}

	if (c < d) {
		printf("%d %d %d\n", c, d, e);
	}else if (e < c) {
		printf("%d %d %d\n", d, e, c);
	}else {
		printf("%d %d %d\n", d, c, e);
	}

	return 0;
}


Measured memory_bytes: 2104
# -*- coding: utf-8 -*-
"""
AtCoder A
"""

import sys, math, random
import numpy as np

# N = int(input())
# A = list(map(int,input().split())) # N row 1 column
# A = [int(input()) for _ in range(N)] # 1 row N column
# S = str(input()) # str(input()) == input() -> 'abc'
# S = list(input()) # abc -> ['a','b','c']
# S.replace('ABC','X') # "testABCABC" -> "testXX"
 
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
 
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()


def main():
    N=LI()
    W = list(map(int,input().split()))
    S=sum(W)
    out=10e10
    p=0
    for w in W:
        p+=w
        S-=w
        out=min(out,abs(S-p))
    print(out)
    
if __name__ == "__main__":
    main()

Measured memory_bytes: 24768
#include<bits/stdc++.h>
using namespace std;
  
int main(){
  
  long long i, N, cnt = 0;
  string S;
  cin >> N;
  cin >> S;
  
  for(i = 0; i < N - 1; i++){
    
    if (S.at(i) == S.at(i + 1)) cnt++;
  }
  
  cout << N - cnt << endl;
  return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main(){
	string s;
    int n;
    cin>>n;
    cin>>s;
    int count=0;
    for(int i=0;i<n;i++){
        if(s[i]=='A'){
            if(s[i+1]=='B'){
                if(s[i+2]=='C')
                count++;
            }
        }
    }
    cout<<count<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  int num =0;
  for(int i = 0;i < 4;i++) {
      if(s[i] == '+') {
          num++;
      } else {
          num--;
      }
  }
  cout << num << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fastIO std::ios_base::sync_with_stdio(false); std::cin.tie(0); std::cout.tie(0)
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define trace(x) cout << '>' << #x << ':' << x << "\n" 
#define trace2(x,y) cout<< '>' << #x << ':' << x << " | " << #y << ':' << y << "\n" 
#define trace3(a,b,c) cout<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<"\n" 
#define trace4(a,b,c,d) cout<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<"\n" 
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define endl '\n' 
typedef vector<int> VI;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
const ll mod=1000000007;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1.0);
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

const int maxn = 1e5 + 10;

int main()
{
    fastIO;
    int x; 
    cin >> x;
    cout << (x ^ 1) << endl;
    return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long n,a,b;
    cin>>n>>a>>b;
     if(n>1&&b>=a||n==1&&a==b)
        cout<<(n-2)*(b-a)+1<<endl;
    else
        cout<<0<<endl; 
    return 0;
} 

Measured memory_bytes: 256
import numpy as np
import sys
x, y = map(int, input().split())

if (x + y) % 3 != 0 or x > 2 * y or y > 2 * x:
    print(0)
    sys.exit()

# 手数
n = (x + y) // 3
x -= n
y -= n


MOD = 10**9 + 7


def prepare(n, MOD):
    f = 1
    for m in range(1, n + 1):
        f *= m
        f %= MOD
    fn = f

    inv = pow(f, MOD - 2, MOD)
    invs = [1] * (n + 1)
    invs[n] = inv
    for m in range(n, 1, -1):
        inv *= m
        inv %= MOD
        invs[m - 1] = inv

    return fn, invs


fact, invs = prepare(n, MOD)

print(fact * invs[x] * invs[y] % MOD)

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

struct material
{
    int price;
    vector<string> need;
};

void solve(int);

int main()
{
    int n;

    while (cin >> n, n){
        solve(n);
    }

    return 0;
}

void solve(int n)
{
    int m;
    map<string, material> mmap;

    for (int i = 0; i < n; i++){
        string s;
        int p;

        cin >> s >> p;
        mmap[s] = { p, vector<string>() };
    }

    cin >> m;
    for (int i = 0; i < m; i++){
        string o;
        int k;
        int sum = 0;

        cin >> o >> k;
        while (k-- > 0){
            string q;

            cin >> q;
            mmap[o].need.push_back(q);
            sum += mmap[q].price;
        }
        mmap[o].price = min(mmap[o].price, sum);
    }

    string s;
    cin >> s;
    printf("%d\n", mmap[s].price);
}

Measured memory_bytes: 3108
import java.util.Scanner;


public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int hms = sc.nextInt();
        int h = hms / 3600;
        int m = hms % 3600 / 60;
        int s = hms % 60;
        System.out.println(h + ":" + m + ":" + s);
        sc.close();
    }
}


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

#define int long long
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

signed main(){
	int n;
	cin >> n;
	vector<string> s(n);
	for(int i = 0;i < n;i++) cin >> s[i];

	sort(s.begin(), s.end());
	s.erase(unique(s.begin(), s.end()), s.end());

	cout << s.size() << endl;

	return 0;
}


Measured memory_bytes: 9592