akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>
int comp(const void *b,const void * a){
  return *(int*)a - *(int*)b;
}
void cal(int sub,int data[1000],int count,int i,int sum,int rest,int* halt,int* max){//sum(i of data 1 or 0)
  //want to look at data[i]
  //if halt == 1 >>> return;
  //if sum == sub  >>>  halt=1; max; return;
  //if i == count  >>> return sum
  //
  //printf("calculating sub %d,i %d,sum %d,rest %d,max %d\n",sub,i,sum,rest,*max);
  if(*halt==1){//halt
    return;
  }
  if(sum==sub){//to halt
    *halt=1;
    *max=sub;
    return;
  }
  if(rest+sum < *max){
    return;
  }
  if(rest+sum < sub && rest + sum > *max){//or new max
    *max=rest+sum;
    if(*max==sub){
      *halt=1;
    }
    return;
  }
  if(*max<sum){//new max
    *max=sum;
  }
  if(i<count){
    if(data[i]+sum <= sub){
      cal(sub,data,count,i+1,sum+data[i],rest-data[i],halt,max);
    }
    if(*halt){
      return;
    }
    cal(sub,data,count,i+1,sum,rest-data[i],halt,max);
    if(*halt){
      return;
    }

  }
  
  return;
}
int calsub(int sub,int data[1000][2],int count,int maxi,int rest){
  
  int i,j;
  int data2[1000];
  for(i=0;i<count;i++){
    data2[i]=data[i][1];
  }
  data2[maxi]=0;
  qsort(data2,count,sizeof(int),comp);
  int halt=0,max=0;
  
  FILE *fp;
  fp = fopen("log","w");
  fprintf(fp,"count:%d\nsub:%d\nrest:%d\n",count,sub,rest);
  for(i=0;i<count;i++){
    fprintf(fp,"%d\n",data2[i]);
  }
  
  cal(sub,data2,count,0,0,rest,&halt,&max);
  return sub-max;
  
}


int main(void){
  FILE *fp;
  //fp = fopen("003","r");
  //fp = fopen("2510-in1.txt","r");
  fp = stdin;
  /*if(fp==NULL){
    printf("error opening file\n");
    return 1;
    }*/
  
  int count;
  int i,j;
  int data[1000][2];
  int max,maxi,rsum,wsum;
  int sub;
  int rest;
  int res;
  while(1){
    fscanf(fp,"%d",&count);
    if(count==0){
      return 0;
    }
    max=0;rsum=0;wsum=0;
    for(i=0;i<count;i++){
      fscanf(fp,"%d %d",&data[i][0],&data[i][1]);
      if(data[i][0]>max){
	max=data[i][0];
	maxi=i;
      }
      rsum+=data[i][0];
      wsum+=data[i][1];
    }
    
    if(2*max<=rsum){
      res=rsum+wsum;
    }else{
      rest=wsum-data[maxi][1];
      sub = 2 * max - rsum;
      if(rest<=sub){
	res=rsum+wsum+sub-rest;
      }else{
	//printf("sub%d rest%d rsum-max%d wsum%d rsum+wsum%d\n",sub,rest,rsum-max,wsum,rsum+wsum);
	sub = calsub(sub,data,count,maxi,rest);
	res = rsum+wsum+sub;
      }
    }

    printf("%d\n",res);
    
  }
  
}

Measured memory_bytes: 716
using System;

namespace B___0_or_1_Swap
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var pi = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            var count = 0;
            for (int i = 0; i < N; i++) if (pi[i] != i + 1) count++;
            Console.WriteLine(count <= 2 ? "YES" : "NO");
        }
    }
}


Measured memory_bytes: 11092
B,W=map(int,input().split())
N=B+W+2
mod=10**9+7
table=[1]*(N+3)
t=1
for i in range(1,N+3):
    t*=i
    t%=mod
    table[i]=t
rtable=[1]*(N+3)
t=1
for i in range(1,N+3):
    t*=pow(i,mod-2,mod)
    t%=mod
    rtable[i]=t
p=[0]*(B+W+1)
q=[0]*(B+W+1)
t=pow(2,mod-2,mod)
for i in range(W,B+W+1):
    if i==W:
        p[i]=pow(t,i,mod)
    else:
        p[i]=(p[i-1]+table[i-1]*rtable[W-1]*rtable[i-W]*pow(t,i,mod))%mod
            #(table[i]*rtable[W]*table[i-W]*pow(t,i,mod))%mod
for i in range(B,B+W+1):
    if i==B:
        q[i]=pow(t,i,mod)
    else:
        q[i]=(q[i-1]+table[i-1]*rtable[B-1]*rtable[i-B]*pow(t,i,mod))%mod
#print(p,q)
for i in range(B+W):
    ans=((1+p[i]-q[i])*pow(2,mod-2,mod))%mod
    print(ans)

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

#define LL long long
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(x) (x).begin(),(x).end()
const int IINF = 1e9;
const LL LINF = 1e18;
const LL mod = 1e9+7;

int main() {
    int r;
    cin >> r;
    cout << 3*r*r << endl;
    return 0;
}


Measured memory_bytes: 256
# AOJ 0272: The Lonely Girl's Lie
# Python3 2018.6.26 bal4u

def counting_sort(nmax, la):  # nmax:最大値, n:len(la), a:データリスト
	f = [0]*(nmax+1)
	nmax = 0
	for a in la:
		f[a] += 1
		if a > nmax: nmax = a
	k, i = len(la), nmax
	la = []
	while k:
		if f[i]:
			la += [i]*f[i]
			k -= f[i]
		i -= 1
	return la
	
while True:
	n = int(input())
	if n == 0: break
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	a = counting_sort(100000, a)
	b = counting_sort(100000, b)
	ans, i = n, -1
	for k in range(0, n, 2):
		i += 1
		if a[k] > b[i]:
			ans = k + 1
			break
	print("NA" if ans == n else ans)



Measured memory_bytes: 14260
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		long n = sc.nextLong();

		long minSteps = Long.MAX_VALUE;
		for(int i = 1; i <= Math.sqrt(n); i++){
			if(n%i != 0){
				continue;
			}

			long tmp = n/i + i - 2;

			if(minSteps > tmp){
				minSteps = tmp;
			}
		}

		System.out.println(minSteps);
	}

}


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

using namespace std;

int main()
{
	long long int n,m;
  cin>>n>>m;
  int arr[m];
  long long int sum=0;
  for(int i=0;i<m;i++)
  {
  	cin>>arr[i];
    sum+=arr[i];
  }
  if((n-sum)>=0)
  cout<< n-sum<<endl;
  else
    cout<<-1<<endl;
}

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

int main(){
    long long x, y;
    cin >> x >> y;

    bool flag = false;
    for(long long i = 0; i <= x; i++){
        long long j = x - i;
        if(2*i + 4*j == y){
            flag = true;
            break;
        }
    }

    if(flag == true){
        printf("Yes\n");
    }
    else{
        printf("No\n");
    }

    return 0;
}

Measured memory_bytes: 3632
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        string[] input = ReadLine().Split(' ');
        int A = int.Parse(input[0]);
        int B = int.Parse(input[1]);
        WriteLine(Lcm(A, B));
    }

    static long Lcm(long a, long b)
    {
        return a * b / Gcd(a, b);
    }

    static long Gcd(long a, long b)
    {
        if(a < b)
        {
            return Gcd(b, a);
        }
        while (b != 0)
        {
            var r = a % b;
            a = b;
            b = r;
        }
        return a;
    }
}

Measured memory_bytes: 13140
#include <iostream>
#include <cmath>
using namespace std;
 
#define MAXN 100020
 
#define INF 1000000010
 
int N,K;
long long dp[MAXN];
long long h[MAXN];
 
 
int main() {
	cin >> N >> K;
  	for (int i = 0; i < N; i++) cin >> h[i];
  
  	dp[0] = 0;
  	for (int i = 1; i < N; i++) {
		dp[i] = INF;
      	for (int j = max(0,i-K); j < i; j++) {
			dp[i] = min(dp[i],dp[j]+abs(h[i]-h[j]));
                        }
                        }
                        cout << dp[N-1] << endl;
                        }

Measured memory_bytes: 1792
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
 const ll INF = 1e18;
//const ll MOD = 1e9+7;
//const double pi = 3.14159265358979;
using vl = vector<ll>;
# define rep(i, n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(ll i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(ll i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(ll i=((int)(n)); i>0; --i)
# define all(x) (x).begin(), (x).end()

ll K;
string S;

int Main() {
    cin >> K >> S;
//    vl A(N);
    if(S.length() <= K) {
        cout << S << endl;
    } else {
        cout << S.substr(0, K) << "..." << endl;
    }
    return 0;
}

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


Measured memory_bytes: 3656
s = input()
t = input()
n = int(input())

a = [[0 for i in range(4)] for j in range(n)]
for i in range(n):
    a[i] = [int(j)-1 for j in input().split()]

def henkan(inp, n):
    o = [0] * n
    for i in range(n):
        if inp[i] == 'A':
            o[i] = 1
        else:
            o[i] = 2
    return o

def ruiseki(a, n):
    s = [0] * n
    s[0] = a[0]
    for i in range(1,n):
        s[i] =  s[i-1] + a[i]
    return s

def partSum(s, l, r):
    if l == 0:
        return s[r]
    return s[r] - s[l-1]

s_i = henkan(s,len(s))
t_i = henkan(t,len(t))

sum_s = ruiseki(s_i, len(s_i))
sum_t = ruiseki(t_i, len(t_i))

for i in range(n):
    x = partSum(sum_s, a[i][0], a[i][1])
    y = partSum(sum_t, a[i][2], a[i][3])
    if x%3 == y%3:
        print('YES')
    else:
        print('NO')


Measured memory_bytes: 39920
#include <cmath>
#include <queue>
#include <deque>
#include <string>
#include <vector>
#include <random>
#include <iostream>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
using namespace std;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    if (s == "abc") {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    
    return 0;
}

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

int main() {
  int k;
  int result = 0;
  cin >> k;
  if (k % 2 == 1) {
    result = (k+1)/2 * (k-1)/2;
  } else {
    result = (k/2) * (k/2);
  }
  
  cout << result << endl;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define SP << " " 
#define LLi long long int

using namespace std;

int imax=2147483647;
long long int llimax=9223372036854775807;
LLi mod=1000000007;

//int型vectorを出力
void PV(vector<int> pvv) {
	rep(i, pvv.size()) cout << pvv[i] SP;
	cout << endl;
}

//LLi型vectorを出力
void PVL(vector<LLi> pvv) {
	rep(i, pvv.size()) cout << pvv[i] SP;
	cout << endl;
}

int main(){

	string s;
	LLi e=1, a=0, b=0, c=0;

	cin>> s;

	rep(i, s.size()){
		if(s[i]=='?') c=(c*3)%mod;
		if(s[i]=='C' || s[i]=='?') c=(c+b)%mod;
		if(s[i]=='?') b=(b*3)%mod;
		if(s[i]=='B' || s[i]=='?') b=(b+a)%mod;
		if(s[i]=='?') a=(a*3)%mod;
		if(s[i]=='A' || s[i]=='?') a=(a+e)%mod;
		if(s[i]=='?') e=(e*3)%mod;
		//cout<< e SP << a SP << b SP << c <<endl;
	}
	
	cout<< c << endl;
 
	return 0;
}


Measured memory_bytes: 3712
#include<iostream>
#include <string> 
#include <vector>     

#define INF 1000000000
using namespace::std;




long Lmax(long x, long y) {
	if (x > y)return x;
	return y;
}

int max(int x, int y) {
	if (x > y)return x;
	return y;
}

long Lmin(long x, long y) {
	if (x < y)return x;
	return y;
}


int min(int x, int y) {
	if (x < y)return x;
	return y;
}

int abs(int x) {
	if (x < 0) {
		return -x;
	}
	return x;
}

bool c;
int N,C,H, M,K,W,al[50][26],ltl[26];
string S,s;
char a[50][50],b[26];
int main() {
	cin >> S;
	for (int i = 0; i < S.size(); i++) {
		if (S[i] == 'A') {
			if (S[i + 1] == 'C') {
				cout << "Yes" << endl;
				return 0;
			}
		}
	}

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




Measured memory_bytes: 256
#![allow(
  non_snake_case,
  unused_variables,
  unused_assignments,
  unused_mut,
  unused_imports,
  dead_code
)]
//use proconio::fastout;
use proconio::input;
use proconio::marker::*;
//use std::collections::HashSet;
use std::cmp::*;
//use std::collections::VecDeque;

fn main() {
  input! {
    N:usize,
    L:[u64;N]
  }
  let mut L = L;
  L.sort();
  let mut ans = 0;
  for i in 0..N {
    for j in i + 1..N {
      if L[i] == L[j] {
        continue;
      }
      for k in j + 1..N {
        if L[k] == L[j] {
          continue;
        }
        if L[i] + L[j] > L[k] {
          //println!("{},{},{}  ", L[i], L[j], L[k]);
          ans += 1;
        }
      }
    }
  }
  println!("{}", ans);
}


Measured memory_bytes: 2192
#include <bits/stdc++.h>
using namespace std;
const int M = 1e3 + 5;
const int N = (1 << 12) + 5;
int dp[M][N];
int n, m;
int cost[M];
vector<int> boxes[M];
int solve(int idx, int msk) {
    if ((1 << n) - 1 == msk) return 0;
    if (idx == m) return 1e9;
    int &ret = dp[idx][msk];
    if (ret != -1) return ret;
    ret = solve(idx + 1, msk);
    for (auto curr: boxes[idx]) {
        msk |= (1 << curr);
    }
    ret = min(ret, solve(idx + 1, msk) + cost[idx]);
    return ret;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        cost[i] = a;
        for (int j = 0; j < b; j++) {
            int x;
            cin >> x;
            boxes[i].push_back(x - 1);
        }
    }
    memset(dp, -1, sizeof dp);
    if (solve(0, 0) >= 1e9) cout << -1;
    else cout << solve(0, 0);
    return 0;
}

Measured memory_bytes: 19904
#include<stdio.h>
int main()
{
    int a, b, c, i;
    scanf("%d",&a);
    if (400 <= a && 599 >= a)
    {
        printf("8\n");
    }
    else if (600 <= a && 799 >= a)
    {
        printf("7\n");
    }
    else if (800 <= a && 999 >= a)
    {
        printf("6\n");
    }else if (1000 <= a && 1199 >= a)
    {
        printf("5\n");
    }
    else if (1200 <= a && 1399 >= a)
    {
        printf("4\n");
    }else if (1400 <= a && 1599 >= a)
    {
        printf("3\n");
    }
    else if (1600 <= a && 1799 >= a)
    {
        printf("2\n");
    }else if (1800 <= a && 1999 >= a)
    {
        printf("1\n");
    }
    return 0;
}

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

using namespace std;
typedef long long ll;

int main(){
    ll n;
    cin >> n;
    vector<ll> a(n);
    for(int i = 0; i < n; ++i){
        cin >> a.at(i);
    }

    ll s = 0;
    for(int i = 0; i < n; ++i){
        s += a.at(i);
    }

    ll snuke = a.at(0);
    ll ans = abs((s - snuke) - snuke);
    for(int i = 1; i < n - 1; ++i){
        snuke += a.at(i);
        ans = min(ans, abs((s - snuke) - snuke));
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

int maxVal = pow(2, 31) - 1;
class RMQ {
public:
    RMQ(int n, int v) {
        int i = 1;
        while(i < n){
            i *= 2;
        }
        tree = vector<int>(i*2-1, v);
        st_idx = i-1;
        s = i*2-1;
    };
    void update(int x, int v){
        int idx = x + st_idx;
        tree[idx] = v;
        while(idx){
            int p = (idx-1)/2;
            int sb = idx%2 ? idx+1 : idx-1;
            tree[p] = min(tree[idx], tree[sb]);
            idx = p;
        }
    }
    int findMin(int l, int r){
        return findMin(l+st_idx, r+st_idx, maxVal);
    }
    void print(){
        for(int x : tree){
            cout << x << ' ';
        }
        cout << endl;
    }
private:
    vector<int> tree;
    int s;
    int st_idx;
    int findMin(int l, int r, int v){
        //cout << l  << ' ' << r << endl;
        if(l > r){
            return  v;
        }
        if(l == r){
            return min(v, tree[l]);
        }
        int minVal = v;
        if(l%2 == 0){
            minVal = min(minVal, tree[l]);
            l /= 2;
        } else {
            l = (l-1)/2;
        }
        if(r%2 == 1){
            minVal = min(minVal, tree[r]);
            r = (r-2)/2;
        } else {
            r = (r-1)/2;
        }
        return findMin(l, r, minVal);
    }
};

int main(){
    int n, q;
    cin >> n >> q;
    RMQ rmq = RMQ(n, maxVal);
    int com, x, y;
    for(int i = 0; i < q; ++i){
        cin >> com >> x >> y;
        if(com){
            int v = rmq.findMin(x, y);
            cout << v << endl;
        } else {
            rmq.update(x, y);
            //rmq.print();
        }
    }
}

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

int main() {
    int n;
    cin >> n;
    double d = 0;
    for (int i = 0; i < n; i++) {
        double a;
        cin >> a;
        d += 1 / a;
    }
    
    cout << setprecision(10) << 1 / d << endl;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringJoiner;
import java.util.StringTokenizer;
import java.util.function.IntUnaryOperator;
import java.util.function.LongUnaryOperator;

class Main {
    static In in = new In();
    static Out out = new Out();
    static long mod = 1000000007;
    static long inf = 0xfffffffffffffffL;

    void solve() {
        int n = in.nextInt();
        int m = in.nextInt();
        if (n == m) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }

    public static void main(String[]$) {
        new Main().solve();
        out.flush();
    }
}

class In {
    private BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 0x10000);
    private StringTokenizer tokenizer;

    String next() {
        try {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                tokenizer = new StringTokenizer(reader.readLine());
            }
        } catch (IOException ignored) {
        }
        return tokenizer.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    char[][] nextCharArray(int n, int m) {
        char[][] a = new char[n][m];
        for (int i = 0; i < n; i++) {
            a[i] = next().toCharArray();
        }
        return a;
    }

    int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = nextInt();
        }
        return a;
    }

    int[] nextIntArray(int n, IntUnaryOperator op) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = op.applyAsInt(nextInt());
        }
        return a;
    }

    long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++) {
            a[i] = nextLong();
        }
        return a;
    }

    long[] nextLongArray(int n, LongUnaryOperator op) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++) {
            a[i] = op.applyAsLong(nextLong());
        }
        return a;
    }
}

class Out {
    private static PrintWriter out = new PrintWriter(System.out);

    void println(Object... a) {
        StringJoiner joiner = new StringJoiner(" ");
        for (Object obj : a) {
            joiner.add(String.valueOf(obj));
        }
        out.println(joiner);
    }

    void flush() {
        out.flush();
    }
}


Measured memory_bytes: 21588
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


int N;
vector<int> A,B;
int which[10],value[10];


int main(){

	int num_0 = 0,num_1 = 0;

	scanf("%d",&N);

	for(int i = 0; i < N; i++){

		scanf("%d",&which[i]);

		if(which[i] == 0){

			num_0++;
		}else{

			num_1++;
		}
	}

	if(num_0 == 0 || num_1 == 0){

		printf("0\n");
		return 0;
	}

	for(int i = 0; i < N; i++){

		scanf("%d",&value[i]);

		if(which[i] == 0){

			A.push_back(value[i]);

		}else{

			B.push_back(value[i]);
		}
	}

	sort(A.begin(),A.end());
	sort(B.begin(),B.end());

	printf("%d\n",A[0]+B[0]);

	return 0;
}



Measured memory_bytes: 3264
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
const long long INFLL = 1LL << 60;
const int INFINT = 1 << 30;
const long long MOD = 1e9 + 7;

template <class T> void vecout(T V) {
    auto t = V.begin();
    while(t != V.end()) {
        cout << *t++;
        if(t != V.end()) cout << " ";
    }
    cout << endl;
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) a[i] = i + 1;
    do {
        vecout(a);
    } while(next_permutation(a.begin(), a.end()));
}


Measured memory_bytes: 3176
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn main(){
    let line: Vec<u32> = read_as_vec();
    let (a, b, k) = (line[0], line[1], line[2]);
    let mut ans = 0;
    for i in (1..cmp::min(a, b)+1).rev(){
        if a%i == 0 && b%i == 0 {
            ans += 1;
        }
        if ans == k{
            println!("{}", i);
            break;
        }
    }
    
}


Measured memory_bytes: 4352
using System;
using System.Linq;
using System.Collections.Generic;
public class Hello{
    public static void Main(){
        var city = new List<int>(){0,0,0,0};
        for(var i = 0;i < 3;i++){
            var input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var a = input[0] - 1;
            var b = input[1] - 1;
            city[a]++;
            city[b]++;
        }
        if(city.Count(x => x == 2) == 2 && city.Count(y => y == 2) == 2){
            Console.WriteLine("YES");
        }else{
            Console.WriteLine("NO");
        }
    }
}


Measured memory_bytes: 13396
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ui unsigned int
#define ull unsigned long long
#define db long double
#define pii pair<int,int>
#define pli pair<ll,int>
#define X first
#define Y second
#define mp make_pair
#define pb push_back
#define vi vector<int>
#define vii vector<vi>
#define lb lower_bound
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,b,a) for(int i=(b);i>=(a);--i)
#define rep0(i,a,b) for(int i=(a);i<(b);++i)
#define fore(i,a) for(int i=0;i<a.size();++i)
#define gc() getchar()
#define ls T[x].l,l,m
#define rs T[x].r,m+1,r
inline ll rd()
{
	ll x=0,w=1;char c=gc();while(!isdigit(c)&&c!='-')c=gc();
	if(c=='-')c=gc(),w=-1;while(isdigit(c))x=x*10+c-48,c=gc();return x*w;
}
const int N=3000010;
int n,m,K,W,tp,as[N],at[N],bs[N],bt[N];char S[N],T[N];
struct st{int i,o;}stk[N],q[N];
int main()
{
	n=rd();m=rd();K=rd();W=max(n,m);scanf("%s",S+1);scanf("%s",T+1);
	rep(i,1,n)as[i]=S[n+1-i]-'0';rep(i,1,m)at[i]=T[m+1-i]-'0';
	per(i,W,1)if(as[i]||at[i])
	{
		if(!as[i]||!at[i]){stk[++tp]=(st){i,as[i]<<1|at[i]};continue;}
		int k=K,p=i,x=3,cnt=0;
		while(tp)
		{
			if(x==3)
			{
				if(k<stk[tp].i-p)break;
				k-=stk[tp].i-p;p=stk[tp].i;
				q[++cnt]=(st){p,3^stk[tp].o};
				x=stk[tp].o;
			}
			else if(x)
			{
				if(stk[tp].i!=p+1)break;
				p=stk[tp].i;x=(x^stk[tp].o)?3:stk[tp].o;
			}
			else break;
			tp--;
		}
		if(x==3){p+=k;bs[p]=bt[p]=1;}
		else if(x){p++;q[++cnt]=(st){p,x};}
		per(j,cnt,1)stk[++tp]=q[j];
	}
	rep(i,1,tp){bs[stk[i].i]=stk[i].o>>1&1;bt[stk[i].i]=stk[i].o&1;}
	int c=W+K;while(bs[c]==0)c--;
	per(i,c,1)printf("%d",bs[i]);puts("");
	c=W+K;while(bt[c]==0)c--;
	per(i,c,1)printf("%d",bt[i]);puts("");
	return 0;
}


Measured memory_bytes: 47104
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using Edge = pair<int, ll>;
using Graph = vector<vector<int>>;
using WeightedGraph = vector<vector<Edge>>;
const ll INF = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 998244353;

int main() {
	ll n, m; cin >> n >> m;
	Graph G(n);
	for (int i = 0; i < m; ++i) {
		int a, b; cin >> a >> b; --a; --b;
		G[a].push_back(b);
		G[b].push_back(a);
	}

	// 適当なパスを構築
	deque<int> ans;
	ans.emplace_front(0);
	ans.emplace_back(G[0][0]);

	// 探索済み頂点を管理
	unordered_set<int> se;
	se.insert(0);
	se.insert(G[0][0]);

	// 始点を条件満たすまで更新
	while (true) {
		int now = ans.front();
		bool f = true;
		for (auto e : G[now]) {
			if (se.count(e)) continue;
			se.insert(e);
			ans.emplace_front(e);
			f = false;
			break;
		}
		if (f) break;
	}

	// 終点を条件満たすまで更新
	while (true) {
		int now = ans.back();
		bool f = true;
		for (auto e : G[now]) {
			if (se.count(e)) continue;
			se.insert(e);
			ans.emplace_back(e);
			f = false;
			break;
		}
		if (f) break;
	}

	int N = ans.size();
	cout << N << endl;
	for (int i = 0; i < N; ++i) {
		cout << ans[i]+1;
		if (i != N - 1) cout << " ";
		else cout << endl;
	}

	return 0;
}

Measured memory_bytes: 10788
N = int(input())
import numpy as np
li = np.array(list(map(int,input().split())))	#1 2 3 4 5 ... n  li=[1,2,3,4,5,...,n]
li_abs = abs(li)
M = np.argmin(li_abs)
if sum(li < 0)%2 == 0:
    print(sum(li_abs))
else:
    for i in range(N-1):
        tmp = N-1-i
        if tmp == M:
            if li[tmp] >= 0:
                li[tmp] = li[tmp] * (-1)
                li[tmp - 1] = li[tmp - 1] * (-1)
        else:
            if li[tmp] < 0:
                li[tmp] = li[tmp]*(-1)
                li[tmp-1] = li[tmp-1]*(-1)

    print(sum(li))

Measured memory_bytes: 23268
#include<iostream>
#include<queue>
#include<stack>
#include<cstdio>
using namespace std;

int main()
{
	int n = 0;
	stack<int>s;
	bool flag = false; 

	while (scanf("%d" , &n) != EOF){

		if (n == 0){
			
			cout << s.top() << endl;
			s.pop();
		}else{
			s.push(n);
		}
	}

	return 0;
}

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

using namespace std;

int gcd(int a, int b) {

    while(b > 0) {
        int temp = b;
        b = a % b;
        a = temp;
    }
    
    return a;
}

int main() {

    int n, x;
    cin >> n >> x;
    
    int sol;
    for(int i = 0; i < n; i++) {
        int a;
        cin >> a;
        
        if(i == 0) {
            sol = abs(a - x);
            continue;
        }
        
        sol = gcd(sol, abs(a - x));
    }
    
    cout << sol << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<fstream>
#include<sstream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<string>
#include<cmath>
#include<cstdio>
#include<cassert>

using namespace std;

#define REP(i,m,n) for(int i=(m); i<(int)(n); i++)
#define RREP(i,m,n) for(int i=(int)(n-1); i>=m; i--)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) RREP(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aut(r,v) __typeof(v) r = (v)
#define each(it,o) for(aut(it,(o).begin()); it!=(o).end(); ++it)
#define reach(it,o) for(aut(it,(o).rbegin()); it!=(o).rend(); ++it)
#define fi first
#define se second
#define debug(...) {cerr<<"[L"<<__LINE__<<"] "; _debug(__VA_ARGS__);}

template<typename T1, typename T2> ostream& operator<<(ostream& o, const pair<T1, T2>& p)
{return o<<"("<<p.first<<", "<<p.second<<")";}
template<typename T>string join(const vector<T>&v, string del=", ")
{stringstream s;rep(i,v.size())s<<del<<v[i];return s.str().substr(del.size());}
template<typename T>ostream& operator<<(ostream& o, const vector<T>&v)
{if(v.size())o<<"["<<join(v)<<"]";return o;}
template<typename T>ostream& operator<<(ostream& o, const vector<vector<T> >&vv)
{int l=vv.size();if(l){o<<endl;rep(i,l){o<<(i==0?"[ ":",\n  ")<<vv[i]<<(i==l-1?" ]":"");}}return o;}
template<typename T>ostream& operator<<(ostream& o, const set<T>& st)
{vector<T> v(st.begin(),st.end());o<<"{ "<<join(v)<<" }";return o;}
template<typename T1, typename T2>ostream& operator<<(ostream& o, const map<T1, T2>& m)
{each(p,m){o<<(p==m.begin()?"{ ":",\n  ")<<*p<<(p==--m.end()?" }":"");}return o;}
inline void _debug(){cerr<<endl;}
template<class First, class... Rest>
void _debug(const First& first, const Rest&... rest){cerr<<first<<" ";_debug(rest...);}

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

const double PI = (1*acos(0.0));
const double EPS = 1e-9;
const int INF = 0x3f3f3f3f;
const ll INFL = 0x3f3f3f3f3f3f3f3fLL;
const int mod = 1e9 + 7;

inline void finput(string filename) {
    freopen(filename.c_str(), "r", stdin);
}

int H, W;
char G[1010][1010];

int main(){
    ios_base::sync_with_stdio(0);
    // finput("./input");

    cin >> H >> W;
    rep(i,H) cin >> G[i];

    vvi dp(H, vi(W, 0));
    dp[0][0] = 1;
    rep(i,H){
        rep(j,W){
            if(G[i][j] == '#') continue;
            if(i-1 >= 0 && G[i-1][j] == '.') dp[i][j] = (dp[i][j] + dp[i-1][j]) % mod;
            if(j-1 >= 0 && G[i][j-1] == '.') dp[i][j] = (dp[i][j] + dp[i][j-1]) % mod;
        }
    }
    cout << dp[H-1][W-1] << endl;
    return 0;
}

Measured memory_bytes: 5248
# coding: utf-8
while True:
    H,W=(int(x) for x in input().split())
    if H==0 & W==0:
        break
    else :
        for i in range(H):
            for j in range(W):
                if i%2==0:
                    if j%2==0:
                        print("#",end="")
                    else :
                        print(".",end="")
                else :
                    if j%2==0:
                        print(".",end="")
                    else :
                        print("#",end="")
            print("")
    print("")


Measured memory_bytes: 7024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

int main() {
  ll n;
  cin >> n;
  vector<ll> cnt(n + 1, 0), a(n);
  REP(i, n) {
    cin >> a[i];
    cnt[a[i]]++;
  }
  ll s = 0;
  REP(i, n + 1) { s += cnt[i] * (cnt[i] - 1) / 2; }

  REP(i, n) {
    ll c = cnt[a[i]];
    ll bef = c * (c - 1) / 2, aft = (c - 1) * (c - 2) / 2;
    cout << s + (aft - bef) << endl;
  }
}

Measured memory_bytes: 5760
#include<iostream>
using namespace std;
int main()
{

    int n,k;
    cin>>n>>k;
    int a[n];
    int i,count=0;
    for(i=0;i<n;i++)
        cin>>a[i];
    for(i=0;i<n;i++)
    {

        if(a[i]>=k)
            count++;
    }
    cout<<count;
    return 0;
}


Measured memory_bytes: 640
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc=new Scanner(System.in);
        int x1=sc.nextInt();
        int y1=sc.nextInt();
        int x2=sc.nextInt();
        int y2=sc.nextInt();
        System.out.print((x2-y2+y1)+" "+(y2-x1+x2)+" "+(x1-y2+y1)+" "+(y1-x1+x2));
    }
}


Measured memory_bytes: 21332
from types import GeneratorType
def bootstrap(f, stack=[]):
    def wrappedfunc(*args, **kwargs):
        if stack:
            return f(*args, **kwargs)
        else:
            to = f(*args, **kwargs)
            while True:
                if type(to) is GeneratorType:
                    stack.append(to)
                    to = next(to)
                else:
                    stack.pop()
                    if not stack:
                        break
                    to = stack[-1].send(to)
            return to
    return wrappedfunc
n = int(input())
lis = list(map(int, input().split()))
dp = {}
@bootstrap
def TD(i):
    if i == n - 1:
        yield 0

    if i in dp:
        yield dp[i]
    mi = float('inf')
    for j in range(1, 3):
        if i + j < n:
            tmp = yield TD(i+j)
            mi = min(mi, abs(lis[i] - lis[i+j])+ tmp)
    dp[i] = mi
    yield mi
print(TD(0))   

Measured memory_bytes: 137608
import itertools
N, M, R = map(int, input().split())
r = list(map(lambda x:int(x)-1, input().split()))
graph = [[] for _ in range(N)]
d = [[float('inf')]*N for _ in range(N)]
for _ in range(M):
  a, b, c = map(int, input().split())
  a -= 1
  b -= 1
  graph[a] += [[b, c]]
  graph[b] += [[c, a]]
  d[a][b] = c
  d[b][a] = c

for i in range(N):
  d[i][i] = 0

def warshall_floyd(d):
  #d[i][j]: iからjへの最短距離
  for k in range(N):
    for i in range(N):
      for j in range(N):
        d[i][j] = min(d[i][j],d[i][k] + d[k][j])
  return d

d = warshall_floyd(d)
ans = float('inf')
for v in itertools.permutations(r):
  tmp = 0
  for i in range(len(v)-1):
    tmp += d[v[i]][v[i+1]]
  ans = min(ans, tmp)
print(ans)

Measured memory_bytes: 78832
#include <stdio.h>
#include <stdlib.h>
#include "time.h"
#include "unistd.h"
#include "string.h"
#include <math.h>
int ans;
int i=0;
int main(int argc, char* argv[]){
  long int a=0,b=0,c=0;
  char s[7];
  scanf("%ld",&a);
  b=a/500;
  c=a%500;
  c=c/5;
  printf("%d",b*1000+c*5);
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
using namespace std;
using ll = long long;
#define pi 3.1415926

int a[(int)2e5][11];

int main(){
    int n,r;
    cin >> n >> r;
    if(n >= 10)
        cout << r;
    else 
        cout << r+(100*(10-n));    

}

    

		


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn=100+10;
int n,G[maxn][maxn],dis[maxn],vis[maxn];
void bfs(){
    memset(dis,0,sizeof dis);
    memset(vis,0,sizeof vis);
    queue<int>que;
    que.push(1);vis[1]=1;dis[1]=0;
    while(!que.empty()){
        int cur=que.front();que.pop();
        for(int i=1;i<=n;i++){
            if(G[cur][i]&&!vis[i]){
                que.push(i);
                dis[i]=dis[cur]+1;
                vis[i]=1;
            }
        }
    }
}
int main()
{
    cin>>n;
    for(int i=0;i<n;i++){
        int u,k;cin>>u>>k;
        for(int j=0;j<k;j++){
            int v;cin>>v;
            G[u][v]=1;
        }
    }
    bfs();
    for(int i=1;i<=n;i++) if(!vis[i]) dis[i]=-1;
    for(int i=1;i<=n;i++) cout<<i<<" "<<dis[i]<<"\n";
    /*
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            cout<<G[i][j]<<" ";
        }cout<<endl;
    }*/
}
/*
4
1 2 2 4
2 1 4
3 0
4 1 3
*/



Measured memory_bytes: 3116
#include <stdio.h>

int main(void)
{
    int n, x;
    int L[100];

    scanf("%d%d", &n, &x);

    for (int i=0; i<n; i++) {
        scanf("%d", &L[i]);
    }

    int d=0, c=0;

    int i=0;
    while (d<=x) {
        c++;
        d += L[i++];
    }

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

    return 0;
}

Measured memory_bytes: 128
package main

import (
	"fmt"
	"strconv"
	"strings"
)

func main() {
	var n string
	fmt.Scan(&n)

	data := strings.Split(n, "")
	var ans int
	for _, i := range data {
		s, _ := strconv.Atoi(i)
		ans = ans + s
	}
	if ans%9 == 0 {
		fmt.Println("Yes")
	}else{
		fmt.Println("No")
	}
}


Measured memory_bytes: 6548
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0; i<n; ++i)
#define rep1(i,n) for(ll i=1; i<=n; ++i)
#define revrep(i,n) for(ll i=n-1; n>=0; --i)
inline constexpr ll Inf = (1ULL << 62) -1;
#define fastio cin.tie(nullptr); ios_base::sync_with_stdio(false);
#define endl '\n'
template <class T> bool updmax(T& a, T b) { if (b > a) { a = b; return true;} return false;}
template <class T> bool updmin(T& a, T b) { if (b < a) { a = b; return true;} return false;}

int main() {
    fastio;
    ll ans=0;
    ll N,K;
    cin >> N >> K;
    string s;
    cin >> s;
    for (int i=1; i<(int)s.size(); ++i) {
        if (s[i] == s[i-1]) {
            ans++;
        }
    }
    for (int i=1; i<(int)s.size() && K > 0; ++i) {
        if (s[i] == s[i-1]) {
            continue;
        }
        int j=i+1;
        ++ans;
        for (; j<(int)s.size(); ++j) {
            if (s[j] != s[i]) {
                ++ans;
                break;
            }
        }
        i = j;
        --K;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3768
#include<bits/stdc++.h>
 
 
using namespace std;
int main()
{
 
int a,b,c;
 
cin>>a>>b>>c;
 
if(a>=b&&a>=c){
    a=a*10;
}
else if(b>=a&&b>=c){
    b=b*10;
}
else c=c*10;
 
cout<<a+b+c<<endl;
 
 
 
    return 0;
}

Measured memory_bytes: 256
import sys
from itertools import combinations
import math


def I(): return int(sys.stdin.readline().rstrip())


def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))


def S(): return sys.stdin.readline().rstrip()


def LS(): return list(sys.stdin.readline().rstrip().split())


n = I()
s = S()
# print(s.count('ABC'))
ans = 0
for i in range(len(s)-2):
    if s[i] == 'A' and s[i+1] == 'B' and s[i+2] == 'C':
        ans += 1
print(ans)


Measured memory_bytes: 38384
#include <stdio.h>
#define MOD         1000000007  /* 10^9 + 7 */
typedef long long ll;
ll POW(ll a, ll n){ ll ans=1; while(n){if(n&1){ans=ans*a%MOD;} a=a*a%MOD; n>>=1; } return ans; }

int main(){
   ll n,ans=0;
   scanf("%lld",&n);
   ans = POW(10,n) - POW(9,n) - POW(9,n) + POW(8,n);
   ans%=MOD;
   ans=(ans+MOD)%MOD;
   printf("%lld\n",ans);
   return 0;
}

Measured memory_bytes: 1696
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
t = [list(map(int, input().split())) for i in range(M)]


min_price = min(a) + min(b)

#チケット処理
for i in range(M):
    low = a[t[i][0]-1] + b[t[i][1]-1] - t[i][2]
    if low < min_price:
        min_price = low
print(min_price)


Measured memory_bytes: 38444
import java.util.*;

class Main {

    static public double solve(int L) {
        return Math.pow(L/3.0, 3);
    }

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

        int L = sc.nextInt();

        sc.close();

        System.out.println(String.format("%.7f", solve(L)));
    }
}

Measured memory_bytes: 23764
#!/usr/bin/env python3
def main():
    N, K = map(int, input().split())
    H = [int(x) for x in input().split()] + [0] * 200

    INF = 10 ** 10
    dp = [INF] * 10 ** 6
    dp[0] = 0
    for i in range(N):
        for k in range(1, K + 1):
            dp[i + k] = min(dp[i + k], dp[i] + abs(H[i] - H[i + k]))
    print(dp[N - 1])


if __name__ == '__main__':
    main()


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

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

  int i=0;
  for(;;){
    if(S[i] == 'd' && S.substr(i,7) == "dreamer" && (i+7 == S.length() || S[i+7] == 'd' || S[i+7] == 'e')){
      i += 7;
    if(i == S.length()){
      printf("YES\n");
      break;
    }
      continue;
    }
    if(S[i] == 'd' && S.substr(i,5) == "dream"){
      i += 5;
    if(i == S.length()){
      printf("YES\n");
      break;
    }
      continue;
    }
    if(S[i] == 'e' && S.substr(i,5) == "erase" && S.substr(i,6) != "eraser"){
      i += 5;
    if(i == S.length()){
      printf("YES\n");
      break;
    }
      continue;
    }
    if(S[i] == 'e' && S.substr(i,6) == "eraser"){
      i += 6;
    if(i == S.length()){
      printf("YES\n");
      break;
    }
      continue;
    }
    if(i != S.length()){
      printf("NO\n");
      break;
    }
    if(i == S.length()){
      printf("YES\n");
      break;
    }
  }
  return 0;
}


Measured memory_bytes: 512
n = int(input())
x, y = 0, 0
for _ in range(n):
    info = input().split()
    if info[0] > info[1]:
        x += 3
    elif info[0] < info[1]:
        y += 3
    else:
        x += 1
        y += 1
print(x, y)


Measured memory_bytes: 5600
#include<iostream>
#include<math.h>
#include<vector>
#include<set>
#include<algorithm>
#include<ctype.h>
#include<unordered_set>
#include<string>
#include<iomanip>
#include<queue>
#include<limits>
#include<map>
#include<stack>
using namespace std;
int gcd(int a, int b) {
	if (b == 0)
		return a;
	return gcd(b, a % b);
}
#define MOD 1000000007
#define INF 99999999999 
#define pb push_back
#define mt make_tuple
#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int power(ll x, ll y, ll p)
{
	int res = 1;
	x = x % p;

	while (y > 0)
	{

		if (y & 1)
			res = (res * x) % p;


		y = y >> 1;
		x = (x * x) % p;
	}
	return res;
}
ll modi(ll a, ll m)
{
	return power(a, m - 2, m);

}
ll ncr(ll n, ll r,ll m)
{
	ll i, ans = 1, k = 0;
	if (r == 0)
		return 1;
	else if (n < r)
		return 0;
	for (i = n; i >= n - r + 1; i--)
	{
		ans *= i;
		ans *= modi(n - i + 1, m);
		ans %= m;
	}


	return ans;

}
bool visited[6] = { false };
int n = 6;
vector<int> adj[6];


void max_heapify(int a[100], int i)
{
	int l, r, largest = i;
	l = 2 * i + 1;
	r = 2 * i + 2;
	if (l<n && a[l]>a[i])
		largest = l;
	if (r<n && a[r]>a[l])
		largest = r;
	if (largest != i)
	{
		int k;
		k = a[i];
		a[i] = a[largest];
		a[largest] = k;
		max_heapify(a, largest);
	}

}


bool square(ll n)
{
	double x;
	x = sqrt(n);
	if (x == floor(x))
		return true;
	else return false;
}


bool prime(ll n)
{
	ll i;
	for (i = 2; i * i <= n; i++)
	{
		if (n % i == 0)
			return false;
	}
	return true;
}

void dfs(ll a, vector<ll>adj[100099], bool visited[100001], ll dp[])
{
	visited[a] = true;
	if (adj[a].size() == 0) {
		dp[a] = 0;
	}
	
	for (auto u : adj[a])
	{
		if (!visited[u])
		{
			visited[u] = true;
			dfs(u, adj, visited, dp);
			dp[a] =max(dp[a], dp[u] + 1);
		}
		else {
			dp[a] = max(dp[a], dp[u] + 1);
		}
	}
	
}

ll calhash(string& s) {
	ll i, hash = 0, p = 1, pow = 3;
	for (i = 0; s[i] != '\0'; i++) {
		hash = (hash + p * (s[i] - 'a' + 1)) % MOD;
		p *= pow;
	}
	return hash;
}
ll digit(ll n)
{
	ll count = 0;
	while (n != 0) {
		n = n / 10;
		++count;
	}
	return count;
}
ll* kmp(string& s) {
	ll j, i, prefix[1000];
	prefix[0] = 0;
	for (i = 1; s[i] != '\0'; i++) {

			j = prefix[i - 1];
			while (j > 0 && s[j] != s[i]) {
				j = prefix[j - 1];
			}
			if (s[i] == s[j]) {
				prefix[i] = j + 1;
			}
	}
	return prefix;
}

void bfs(ll start, ll arr[], vector<ll> adj[], ll c) {
	queue<pair<ll,ll>> q;
	pair<ll, ll> temp;
	temp = { start, c };
	q.push(temp);
	while (!q.empty()) {
		temp = q.front();
		q.pop();
		for (auto u : adj[temp.first]) {
			    arr[u] = arr[u] - temp.second;
				q.push({ u , -temp.second});
			}
			
		
	}
}
int main() {
	fast;
	ll n, m, i, j, a, b, dp[1001][1010] = { 0 };
	char arr[1001][1001];
	cin >> n >> m;
	for (j = 1; j <= n; j++) {
		cin >> arr[j];

	}
	
	dp[1][1] = 1;
	for (i = 1; i <= n; i++) {
		for (j = 1; j <= m; j++) {
			if (arr[i][j-1] == '#') {
				dp[i][j] = 0;
			}
			else if (i * j != 1) {
				dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % MOD;
			}
			
		}
	}
	cout << dp[n][m];
	return 0;
}

Measured memory_bytes: 9088
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}


signed main() {
    int x;
    cin >> x;
    
    cout << (x/11)*2 + min(x%11, (x%11>6 ? 2 : 1));
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<n;++i)
#define REP(i,a,b) for(int i=int(a);i<(int)b;++i)


using namespace std;
using ll = long long;

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 n;
int cost[500][500];
bool exist[500][500];
int dir_x[4] = {1,0,-1,0};
int dir_y[4] = {0,1,0,-1};

void check(int x, int y){
    rep(i,4){
        if(x+dir_x[i] >= n || x+dir_x[i] < 0 || y+dir_y[i] >= n || y+dir_y[i] < 0) continue;
        if(exist[x][y]){
            if(cost[x][y]+1 < cost[x+dir_x[i]][y+dir_y[i]]){
            cost[x+dir_x[i]][y+dir_y[i]] = cost[x][y]+1;
            check(x+dir_x[i],y+dir_y[i]);
        }
        }else{
            if(cost[x][y] < cost[x+dir_x[i]][y+dir_y[i]]){
            cost[x+dir_x[i]][y+dir_y[i]] = cost[x][y];
            check(x+dir_x[i],y+dir_y[i]);
            }
        }
        
    }
}





int main(void)
{
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    cin >> n;
    queue<pair<int,int>> p;
    rep(i,n){
        rep(j,n){
            int k;
            cin>> k;
            k--;
            p.push(make_pair(k%n,k/n));
            exist[i][j] = true;
            int dist = min(min(n-1-j,j),min(n-1-i,i));
            cost[i][j] = dist;
        }
    }
    
    
    ll ans = 0;

    rep(i,n*n){
        ans += cost[p.front().first][p.front().second];
        
        //cout << "<" << p.front().first << " " << p.front().second << ">" << " " << cost[p.front().first][p.front().second] << endl;
        exist[p.front().first][p.front().second] = false;
        check(p.front().first,p.front().second);
        p.pop();
        


    }
    cout << ans << endl;

   
    return 0;
    
}


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

def resolve():
    A, B = map(int, input().split())
    aa_min = A / 0.08
    aa_max = (A+1) / 0.08
    bb_min = B / 0.1
    bb_max = (B+1) / 0.1
    if aa_min < bb_max and bb_min < aa_max:
        print(math.ceil(max(aa_min, bb_min)))
    else:
        print('-1')

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define ll long long
string s,ss,str;
map<string,ll>mp;
vector<string>v;
int main()
{
    ll n,i,f=0,r=0,j,c=0,res=0;
    cin>>n;
    ss="";
    r=n;
    while(n--){
        cin>>s;
        sort(s.begin(),s.end());
        mp[s]++;
        if(mp[s]>1)continue;
        v.push_back(s);
       // cout<<v[0]<<endl;
    }
    //cout<<v.size();
    for(i=0;i<v.size();i++){
      if(mp[v[i]]==1)continue;
       f=f+mp[v[i]];
       f--;
       res=res+(f*(f+1))/2;
       f=0;
    }
    f--;
    cout<<res<<endl;
}

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

int main(){
  int k, s; cin >> k >> s;
  long long ans = 0;
  for (int i = 0; i <= k; ++i){
    for (int j = 0; j <= k; ++j){
      if(s-(i+j)>=0 and s-(i+j)<=k) ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

H, W = mapint()
from collections import deque
query = [list(input()) for _ in range(H)]
dirc = [(0, 1), (1, 0), (0, -1), (-1, 0)]

def bfs(start):
    Q = deque([start])
    checked = [[0]*W for _ in range(H)]
    checked[start[0]][start[1]] = 1
    dist = [[0]*W for _ in range(H)]
    ret = 0
    while Q:
        y, x = Q.popleft()
        ret = max(ret, dist[y][x])
        for dy, dx in dirc:
            ny, nx = y+dy, x+dx
            if ny>=H or ny<0 or nx>=W or nx<0: continue
            if query[ny][nx]=='#': continue
            if checked[ny][nx]: continue
            checked[ny][nx] = 1
            dist[ny][nx] = dist[y][x]+1
            Q.append((ny, nx))
    return ret

ans = 0
for h in range(H):
    for w in range(W):
        if query[h][w]=='#': continue
        ans = max(ans, bfs((h, w)))

print(ans)
        

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

using namespace std;

vector<int> G[10010];
vector<int> L;
int visited[10010];

void dfs(int v)
{
    if (visited[v]) return;
    visited[v]=true;
    for(auto& u: G[v]) dfs(u);
    L.push_back(v);
}

int main()
{
    int V, E; cin>>V>>E;
    for(int i=0; i<E; ++i) {
        int s, t; cin>>s>>t;
        G[s].push_back(t);
    }

    for(int i=0; i<V; ++i) {
        if (visited[i]) continue;
        dfs(i);
    }

    for(int i=V-1; i>=0; --i) cout<<L[i]<<endl;
}



Measured memory_bytes: 3916
//D - Road to Millionaire /
//Hiia
#include <stdio.h>
typedef long long ll;
int main(){
  ll n;
  scanf("%lld", &n);

  ll a[200010]={};
  for(ll i = 1; i <= n; i++){
    scanf("%lld", &a[i]);
  }

  ll money=1000,tmp;
  for(ll i = 1; i <= n-1; i++){
    if(a[i]<a[i+1]){
      tmp=money/a[i];
      money=money%a[i] + tmp*a[i+1];
    }
  }

  printf("%lld\n", money);

  return 0;
}


Measured memory_bytes: 3288