akhauriyash/Code-Regression huggingface dataset:
//
//  string_palindrome.cpp
//  learningCplusplus
//
//  Created by Tran Duc Chinh on 2020/04/04.
//  Copyright © 2020 Tran Duc Chinh. All rights reserved.
//

#include <iostream>
#include <string>
#include <vector>
#include <math.h>
using namespace std;

bool palindrome(const std::string s, int l, int r) {
  int numHalf = (l + r) / 2;
  bool is_palindrome = true;
  for (int i = 0; i <= numHalf; i++) {
    if (s[i] != s[r-i]) {
      is_palindrome = false;
    }
  }
  return is_palindrome;
}

int main(int argc, const char* argv[]) {
  std::string s;
  std::cin >> s;
  if (s.size() % 2 == 0) {
    exit(1);
  }
  // std::cout << palindrome(s, 0, s.size()-1) << std::endl;
  // std::cout << palindrome(s, 0, (s.size()-2)/2) << std::endl;
  // std::cout << palindrome(s, (s.size()+2)/2, s.size()-1) << std::endl;
  if (palindrome(s, 0, s.size()-1) && palindrome(s, 0, (s.size()-2)/2) && palindrome(s, (s.size()+2)/2, s.size()-1)) {
    std::cout << "Yes" << std::endl;
  }
  else {
    std::cout << "No" << std::endl;
  }

}

Measured memory_bytes: 256
n,m,q=map(int, input().split())
abcd=[]
for i in range(q):
  a,b,c,d=map(int, input().split())
  abcd.append([a,b,c,d])
def dfs(i,j):
  if i==0:
    alist=[]
    for k in range(j):
      alist.append([k+1])
    return alist
  elif i>0 and i<=n:
    blist=[]
    for k in dfs(i-1,j):
      last=k[-1]
      for l in range(last,j+1):
        clist=k.copy()
        clist.append(l)
        blist.append(clist)
    return blist
ans=0
for alist in dfs(n-1,m):
  cnt=0
  for i in range(q):
    if alist[abcd[i][1]-1]-alist[abcd[i][0]-1]==abcd[i][2]:
      cnt+=abcd[i][3]
  ans=max(ans,cnt)
print(ans)

Measured memory_bytes: 38668
package main

import (
	"fmt"
	"os"
)

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	var a, b, c int
	fmt.Fscan(fp, &a, &b, &c)
	if a == b && b == c {
		fmt.Println("Yes")
		return
	}
	fmt.Println("No")

}

Measured memory_bytes: 512
#include <iostream>
using namespace std;
#define ll long long int
int main(){
    ll a, b, ans=-1;
    cin>>a>>b;
    ll w[a], v[a], dp[a][b+1];
    for (ll i=0; i<a; i++){
        for (ll j=0; j<=b; j++){
            dp[i][j]=-1;
        }
    }
    for (ll i=0; i<a; i++){
        cin>>w[i]>>v[i];
        dp[i][w[i]]=v[i];
        dp[i][0]=0;
    }
    for (ll i=0; i<a-1; i++){
        for (ll j=0; j<=b; j++){
            if (dp[i][j]==-1) continue;
            dp[i+1][j]=max(dp[i+1][j], dp[i][j]);
            if (j+w[i+1]>b) continue;
            dp[i+1][j+w[i+1]]=max(dp[i+1][j+w[i+1]], dp[i][j]+v[i+1]);
        }
    }
    for (ll j=1; j<=b; j++) ans=max(ans, dp[a-1][j]);
    cout<<ans<<endl;
}

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

int main() {
    int n, m, c, cnt=0;
    cin >> n >> m >> c;
    int a[20], b[20];
    for(int i=0; i<m; i++) cin >> b[i];
    for(int i=0; i<n; i++) {
        int d=c;
        for(int j=0; j<m; j++) {
            cin >> a[j];
            d += a[j]*b[j];
        }
        if(d>0) cnt++;
    }
    cout << cnt << endl;
    return 0;
}


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

int main(void){
	char t[110],h[110];
	int n,T=0,H=0,i;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%s %s",t,h);
		if(strcmp(t,h)>0)T=T+3;
		if(strcmp(t,h)<0)H=H+3;
		if(strcmp(t,h)==0){
				T++;H++;
		}
	}
	printf("%d %d\n",T,H);
	return 0;
}

Measured memory_bytes: 604
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<unistd.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#define ST first
#define ND second
#define ll long long
#define ld long double
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
using namespace std;
using namespace __gnu_pbds;

// replace ll  with pair if multiset needed
typedef tree<pair<ll,ll>, null_type, greater<pair<ll,ll> >, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
ordered_set secik;

const ll  INF = 1e9 + 9;
const ll  MOD = 1e9 + 7;
const long long LINF = (ll)1e18 + 3;

// secik.insert({x, t++});
// secik.erase(secik.lower_bound({x,-1}));
// *secik.find_by_order(x)).first << "\n";
// secik.order_of_key(x)

//random_device device;
//mt19937 gener(device());
//uniform_int_distribution<ll > gen(0,n-1);
//gen(gener); // generate random number

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

	int n; cin >> n;
	vector<int> tab(n);
	for(int i = 0; i < n; i++) cin >> tab[i];
	sort(tab.begin(),tab.end());
	int res = 0;
	
	for(int i = 0; i < n; i++){
		for(int j = i + 1; j < n; j++){
			for(int k = j + 1; k < n; k++){
				if(tab[i] == tab[j] || tab[i] == tab[k] || tab[j] == tab[k]) continue;
				if(tab[i] + tab[j] > tab[k]) res++;
			}
		}
	}
	
	cout << res;
	
	return 0;
}

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

// @@ !! LIM()

int main(/* int argc, char *argv[] */) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  ll a, b, c; cin >> a >> b >> c;
  cout << ( ((a < c && c < b) || (a > c && c > b)) ? "Yes" : "No") << endl;

  return 0;
}



Measured memory_bytes: 3648
#include <stdio.h>
#include <iostream>

int main(void)
{
	using namespace std;

	int data[2];
	for(int i=0; i<2; i++){
		cin >> data[i];
	}

	int d =  data[0] / data[1];
	int r = data[0] % data[1];
	double f = static_cast<double>(data[0]) / static_cast<double>(data[1]);

	printf("%d %d %lf\n",d,r,f);
	//cout << d << " " << r << " " << f << endl;

	return 0;

}

Measured memory_bytes: 3212
import sys
sys.setrecursionlimit(1000000000)
import math
from math import gcd
def lcm(a, b): return a * b // gcd(a, b)
from itertools import count, permutations, chain
from functools import lru_cache
from collections import deque, defaultdict
from pprint import pprint
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
N1097 = 10**9 + 7

def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok

def get_inv(n, modp):
    return pow(n, modp-2, modp)

def factorials_list(n, modp):    # 10**6
    fs = [1]
    for i in range(1, n+1):
        fs.append(fs[-1] * i % modp)
    return fs

def invs_list(n, fs, modp):     # 10**6
    invs = [get_inv(fs[-1], modp)]
    for i in range(n, 1-1, -1):
        invs.append(invs[-1] * i % modp)
    invs.reverse()
    return invs

def comb(n, k, modp):
    num = 1
    for i in range(n, n-k, -1):
        num = num * i % modp
    den = 1
    for i in range(2, k+1):
        den = den * i % modp
    return num * get_inv(den, modp) % modp

def comb_from_list(n, k, modp, fs, invs):   
    return fs[n] * invs[n-k] * invs[k] % modp

#

class UnionFindEx:
    def __init__(self, size):
        #正なら根の番号、負ならグループサイズ
        self.roots = [-1] * size
    def getRootID(self, i):
        r = self.roots[i]
        if r < 0:   #負なら根
            return i
        else:
            r = self.getRootID(r)
            self.roots[i] = r
            return r
    def getGroupSize(self, i):
        return -self.roots[self.getRootID(i)]
    def connect(self, i, j):
        r1, r2 = self.getRootID(i), self.getRootID(j)
        if r1 == r2:
            return False
        if self.getGroupSize(r1) < self.getGroupSize(r2):
            r1, r2 = r2, r1
        self.roots[r1] += self.roots[r2]    #サイズ更新
        self.roots[r2] = r1
        return True

Yes = 'Yes'
No = 'No'


def main():
    from fractions import Fraction
    N=ii()
    zero = 0
    d = defaultdict(lambda : [0, 0])
    for _ in range(N):
        x, y = mis()
        if x == y == 0:
            zero += 1
            continue
        if y < 0 or (y==0 and x < 0):
            x, y = -x, -y
        g = gcd(x, y)
        x //= g
        y //= g
        if x<=0:
            rot = True
            c = (y, -x)
        else:
            rot = False
            c = (x, y)
        d[c][rot] += 1
    #
    N -= zero
    ans = 1
    for (q1, q2) in d.values():
        ans *= (pow(2, q1, N1097) - 1) + (pow(2, q2, N1097) - 1) + 1
        ans %= N1097
    ans -= 1
    ans %= N1097
    print(ans + zero)






main()



Measured memory_bytes: 61748
#include <stdio.h>
#include <string.h>
#include <queue>
#define MAXNUM 100000

using namespace std;

int main(void){
	int e[MAXNUM - 1], x[MAXNUM], t, n, k, i, j, l, max_i, sum;
	priority_queue<int> que;
	scanf("%d",&t);
	for(i = 0;i < t;i++){
		scanf("%d%d",&n,&k);
		k--;
		for(j = 0;j < n;j++)
			scanf("%d",&x[j]);
		memset(e,0,sizeof(e));
		if(n <= k + 1){
			printf("0\n");
			continue;
		}
		for(j = 0;j < n - 1;j++)
			que.push(x[j + 1] - x[j]);
		sum = 0;
		for(j = 0;j < k;j++){
			sum += que.top();
			que.pop();
		}
		while(que.size()) que.pop();
		printf("%d\n",x[n - 1] - x[0] - sum);
	}
	return 0;
}

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

int main(){
    int x, y, z;
    cin >> x >> y >> z;
    int sum = z;
    int people = 0;
    while(sum + y + z <= x){
        sum += y + z;
        people++;
    }
    cout << people << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define MAX 2000000
#define INFTY (1<<30)
int H,A[MAX+1];
void maxHeapify(int i){
  int l,r,largest;
  l=2*i;
  r=2*i+1;
  if(l<=H&&A[l]>A[i]) largest=l;
  else largest=i;
  if(r<=H&&A[r]>A[largest])largest=r;
  if(largest != i){
    swap(A[i],A[largest]);
    maxHeapify(largest);
  }
}
int extract(){
  int maxv;
  if(H<1) return -INFTY;
  maxv=A[1];
  A[1]=A[H--];
  maxHeapify(1);
  return maxv;
}
void increaseKey(int i,int key){
  if(key<A[i]) return;
  A[i]=key;
  while(i>1&&A[i/2]<A[i]){
    swap(A[i],A[i/2]);
    i=i/2;
  }
}
void insert(int key){
  H++;
  A[H]=-INFTY;
  increaseKey(H,key);
}
int main(){
  int key;
  char com[10];
  while(1){
    scanf("%s",com);
    if(com[0]=='e'&&com[1]=='n')break;
    if(com[0]=='i'){
    scanf("%d",&key);
    insert(key);
    }else{
      printf("%d\n",extract());
    }
  }
  return 0;
}



Measured memory_bytes: 6600
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string S;
    cin >> S;
    int o = 0;
    if (S[0] == 'o') o++;
    if (S[1] == 'o') o++;
    if (S[2] == 'o') o++;
    cout << 700 + 100 * o << endl;
}


Measured memory_bytes: 3604
#include<iostream>
#include<vector>
#include<string>
#include<math.h>
#include<algorithm>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
typedef long long ll;
int main() {
	string s, t;
	cin >> s >> t;
	rep(i, s.size()) {
		if (s[i] != t[i]){
			cout << "No" << endl;
			return 0;
			}
	}
	cout << "Yes" << endl;
	return 0;
}



Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define pi pair<int,int>
#define vp vector<pair<int,int> >
#define all(v) v.begin(),v.end()
using namespace std;

signed main(){
    int n;
    cin>>n;
    vp v(n);
    rep(i,n)cin>>v[i].first>>v[i].second;
    sort(all(v));
    rep(i,n)cout<<v[i].first<<" "<<v[i].second<<endl;
    return 0;
}


Measured memory_bytes: 4404
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
  }

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
  }

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };
    // 3
    // 1 2
    // 1 3
    // 1 4
    // のようなタイプ
    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    }};
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
  }

fn gcd(a: i64, b: i64) -> i64 {
    let mut aa: i64 = if a > b { a } else { b };
    let mut bb: i64 = if a > b { b } else { a };
    while bb != 0 {
        let tmp = bb;
        bb = aa % tmp;
        aa = tmp;
    }
    return aa;
}

fn lcm(a: i64, b: i64) -> i64 {
    a / gcd(a, b) * b
}

fn main() {
    input! {
        a:i64,
        b:i64
    }
    println!("{}", lcm(a, b));
}


Measured memory_bytes: 4352
#include<iostream>
#include<math.h>
using namespace std;

int isPrime(int x){
  if(x == 1)
    return 0; 
  if(x == 2)
    return 1;
  if(x == 3)
    return 1;
  if(x % 2 == 0)
    return 0;
  int i=3;

  while(i <= sqrt(x)){
    if( x % i == 0)
      return 0;
    i+=2;
  }
  return 1;
}

int main(){
  int x,n;
  int sum=0;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>x;
    sum += isPrime(x);
  }
  cout<<sum<<endl;

  return 0;
}

Measured memory_bytes: 3068
#include<stdio.h> 
#include<iostream> 
#include<string.h>
#include<cstring>
#include<string>
#include<math.h>
#include<algorithm>
#include<map>
#include<vector>
#include<cmath>
#include<queue>
#include<set>
#define cuttime ios::sync_with_stdio(false)
#define swap(x, y) x ^= y, y ^= x, x^= y
#define INF 0x3f3f3f3f
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define dep(i,a,b) for(int i=(a);i>=(b);--i)
#define scan1(x) scanf("%d",&x)
#define scan2(x,y) scanf("%d%d",&x,&y)
#define scan3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define scanll1(x) scanf("%lld",&x)
#define scanll2(x,y) scanf("%lld%lld",&x,&y)
#define scanll3(x,y,z) scanf("%lld%lld%lld",&x,&y,&z)
#define lowbit(x) (x&(-x))
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
const int N=2e5+20;
const int MAX=10000007;
inline int read() {
    char c=getchar();int x=0,f=1;
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0',c=getchar();}
    return x*f;
}

inline void out(int x) {   
	if(x>9) out(x/10);   
	putchar(x%10+'0'); 
} 
char s[N];
ll sum1[N][4];
int main(){
	int n;
	n=read();
	cin>>s+1;
	ll sum=0;
	rep(i,1,n){
		if(s[i]=='R')sum1[i][1]=sum1[i-1][1]+1;//R
		else sum1[i][1]=sum1[i-1][1];
		if(s[i]=='G')sum1[i][2]=sum1[i-1][2]+1;//G
		else sum1[i][2]=sum1[i-1][2];
		if(s[i]=='B')sum1[i][3]=sum1[i-1][3]+1;//B
		else sum1[i][3]=sum1[i-1][3];
	}
	rep(i,1,n){
		
		ll cnt=0;
		dep(j,i-1,1){
			cnt++;
			if(s[i]=='G'){
				if(s[j]=='B'){
					sum+=(sum1[n][1]-sum1[i][1]);
					if(s[i+cnt]=='R'){
						sum-=1;
					}
				}
				if(s[j]=='R'){
					sum+=(sum1[n][3]-sum1[i][3]);
					if(s[i+cnt]=='B'){
						sum-=1;
					}
				}
			}	
			if(s[i]=='B'){
				if(s[j]=='R'){
					sum+=(sum1[n][2]-sum1[i][2]);
					if(s[i+cnt]=='G'){
						sum-=1;
					}
				}
				if(s[j]=='G'){
					sum+=(sum1[n][1]-sum1[i][1]);
					if(s[i+cnt]=='R'){
						sum-=1;
					}
				}
			}
			if(s[i]=='R'){
				if(s[j]=='B'){
					sum+=(sum1[n][2]-sum1[i][2]);
					if(s[i+cnt]=='G'){
						sum-=1;
					}
				}
				if(s[j]=='G'){
					sum+=(sum1[n][3]-sum1[i][3]);
					if(s[i+cnt]=='B'){
						sum-=1;
					}
				}
			}
		}
		
	}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 3704
#include<bits/stdc++.h>
using namespace std;
#define  m_k make_pair
#define   P  pair<int,int>
#define  V vector
typedef long long LL;
typedef unsigned long long ULL;
int main()
{
    //freopen("D:\\CODE\\code_contest\\in.txt","w",stdout);
    //freopen("D:\\CODE\\code_contest\\in.txt","r",stdin);  
   int a,b,c;
   while(cin>>a>>b>>c){
    swap(a,b);swap(a,c);
    cout<<a<<" "<<b<<" "<<c<<endl;
   }
   

    return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
typedef vector<ll> Vec;
typedef vector<Vec> DVec;
typedef priority_queue<P, vector<P>, greater<P>> PQ;

#define fi             first
#define se             second
#define pb             push_back
#define INF            LLONG_MAX/3
#define MOD            1000000007
#define bcnt           __builtin_popcount
#define all(x)         (x).begin(),(x).end()
#define uni(x)         x.erase(unique(all(x)),x.end())
#define ub(x,y)        (upper_bound(all(x),y)-x.begin())
#define lb(x,y)        (lower_bound(all(x),y)-x.begin())
#define ssort(x)       sort(all(x))
#define rep(i,n)       repl(i,0,n-1)
#define mkp(x,y)       make_pair(x,y)
#define mmax(x,y)      (x>y?x:y)
#define mmin(x,y)      (x<y?x:y)
#define maxch(x,y)     x=mmax(x,y)
#define minch(x,y)     x=mmin(x,y)
#define exist(x,y)     (find(all(x),y)!=x.end())
#define each(itr,v)    for(auto itr:v)
#define repl(i,a,b)    for(ll i=(ll)(a);i<=(ll)(b);i++)
#define dvec(n1,n2,i)  DVec(n1,Vec(n2,i))

int main(){
  cin.sync_with_stdio(false);
  ll Q;
  cin >> Q;
  rep(i,Q){
    ll a,b;
    ll A,B;
    cin >> a >> b;
    A = mmin(a,b);
    B = mmax(a,b);
    if(A == B || A+1 == B)cout << 2*(A-1) << endl;
    else {
      ll C = ceil(sqrt(A*B))-1;
      if(C*(C+1) >= A*B)cout << 2*C-2 << endl;
      else cout << 2*C-1 << endl;
    }
  }


  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<map>
#include<string>
#include<numeric>
#include<set>
using namespace std;

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

  if(a >= 3200) cout << s << endl;
  else cout << "red" << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>
#include<math.h>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<map>
#include<numeric>
#include<stack>
#include<queue>
#include<functional>
#include<cassert>
#include<set>
#include<numeric>
#define rep(a,b) for(ll a=0;a<b;++a)
#define REP(a,b,c,d) for(ll a=b;a<c;a+=d)
#define yes cout<<"Yes"<<endl
#define no cout<<"No"<<endl
#define mod 1000000007
using namespace std;
using ll = long long;
using p_i = pair<int, int>;
int main() {
	string S; cin >> S;
	int zero = 0, one = 0;
	rep(i, S.size())if (S[i] == '0')++zero;
	one = S.size() - zero;
	cout << min(zero, one) * 2 << endl;
	cin >> S;
}

Measured memory_bytes: 512
H,W,K=map(int,input().split())

s=[input() for i in range(H)]

a=[[""]*W for k in range(H)]

c=0
while s[c].count("#")==0:
    c+=1


idx=1

for i in range(c, H):
    if s[i].count("#") == 0:
        for j in range(W):
            a[i][j] = a[i - 1][j]
    elif s[i].count("#") == 1:
        for j in range(W):
            a[i][j] = str(idx)
        idx += 1
    elif s[i].count("#") > 1:
        id = 0
        cnt = 0
        for j in range(W):
            if cnt == s[i].count("#"):
                a[i][j] = str(idx - 1)
            elif s[i][j] == ".":
                a[i][j] = str(idx)
            elif s[i][j] == "#":
                a[i][j] = str(idx)
                idx += 1
                id = j + 1
                cnt += 1

for i in range(c):
    for j in range(W):
        a[i][j]=a[c][j]

for i in range(H):
    print(" ".join(a[i]))

Measured memory_bytes: 9332
#include<iostream>
#include<algorithm>
#include<cmath>
#define DN 100005
#define x first
#define y second
using namespace std;
int n,f,g,viz[DN],nr,poz,p,p1,p2;
pair<pair<int,int>,int>a[DN],b[DN];
long long rez,rez2;
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i].x.x>>a[i].x.y;
        a[i].y=i;
        b[i]=a[i];
        swap(b[i].x.x,b[i].x.y);
        a[i].x.x=-a[i].x.x;
    }
    sort(a+1,a+n+1);
    sort(b+1,b+n+1);
    for(int i=1;i<=n;i++)
    {
        a[i].x.x=-a[i].x.x;
        swap(b[i].x.x,b[i].x.y);
    }
    poz=0;
    nr=n;
    p=p1=p2=1;
    while(nr--)
    {
       p=1-p;
       if(p==0)
       {
           while(viz[b[p1].y])
                p1++;
           viz[b[p1].y]=1;
           if(poz>=b[p1].x.x&&poz<=b[p1].x.y)
                continue;
            rez+=abs(b[p1].x.y-poz);
            poz=b[p1].x.y;
            continue;
       }
       while(viz[a[p2].y])
            p2++;
        viz[a[p2].y]=1;
        if(poz>=a[p2].x.x&&poz<=a[p2].x.y)
            continue;
        rez+=abs(a[p2].x.x-poz);
        poz=a[p2].x.x;
    }
    rez+=abs(poz);
    poz=0;
    nr=n;
    p=p1=p2=1;
    for(int i=1;i<=n;i++)
        viz[i]=0;
    while(nr--)
    {
       p=1-p;
       if(p==1)
       {
           while(viz[b[p1].y])
                p1++;
           viz[b[p1].y]=1;
           if(poz>=b[p1].x.x&&poz<=b[p1].x.y)
                continue;
            rez2+=abs(b[p1].x.y-poz);
            poz=b[p1].x.y;
            continue;
       }
       while(viz[a[p2].y])
            p2++;
        viz[a[p2].y]=1;
        if(poz>=a[p2].x.x&&poz<=a[p2].x.y)
            continue;
        rez2+=abs(a[p2].x.x-poz);
        poz=a[p2].x.x;
    }
    rez2+=abs(poz);
    cout<<max(rez2,rez);
}


Measured memory_bytes: 2944
import itertools 

def wall(A,c,H,W):
    for k in range(10):
        for i,j in itertools.product(range(10), range(10)):
            c[i][j] = min(c[i][j], c[i][k]+c[k][j])

    cost = 0
    for i,j in itertools.product(range(H), range(W)):
        if A[i][j] != -1 and A[i][j] != 1:
            cost += c[A[i][j]][1]
    print(cost)


items = list(map(int, input().split()))
H = items[0]
W = items[1]
c = list()
A = list()
for i in range(10):
	c_i = list(map(int, input().split()))
	c.append(c_i)
for i in range(H):
	A_i = list(map(int, input().split()))
	A.append(A_i)
wall(A,c,H,W)

Measured memory_bytes: 3828
#include<iostream>
#include<algorithm>
#include<functional>
#include<vector>
#include<string>
#include<tuple>
#include<queue>
#define LL long long
#define TT std::tuple<LL,LL,LL>
#define PP std::pair<LL,LL>
int N, X;
int m = 1 << 30;

int main() {
	std::cin >> N >> X;
	for (int i = 0; i < N; i++) {
		int tmp;
		std::cin >> tmp;
		m = std::min(m, tmp);
		X -= tmp;
	}
	N += X / m;
	std::cout << N << std::endl;
	return 0;
}

Measured memory_bytes: 256
N = int(input())
P = [int(input()) for _ in range(N)]
permu_index = {}
for i in range(N):
    permu_index[P[i]] = i
ans = []
for i in range(1, N+1):
    ans.append(permu_index[i])
max_len = 0
tmp = 1
now = ans[0]
for a in ans[1:]:
    if a > now:
        tmp += 1
        now = a
    else:
        max_len = max(max_len, tmp)
        now = a
        tmp = 1
max_len = max(max_len, tmp)
print(N-max_len)


Measured memory_bytes: 35012
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <set>
#include <functional>
#include <map>
#include <queue>
#include <cmath>
#include <string>
#include <stack>

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

vector <P> vec;
vector <P> at;
ll cnt[15];

bool ex(int x,int y)
{
	int pos=lower_bound(vec.begin(),vec.end(),P(x,y))-vec.begin();
	return pos<vec.size()&&vec[pos]==P(x,y);
}
int main()
{
	ll H,W;
	int n;
	scanf("%lld %lld %d",&H,&W,&n);
	for(int i=0;i<n;i++)
	{
		int a,b;
		scanf("%d %d",&a,&b);a--,b--;
		for(int j=a-2;j<=a;j++)
		{
			for(int k=b-2;k<=b;k++)
			{
				if(j>=0&&k>=0&&j+2<H&&k+2<W)
				{
					at.push_back(P(j,k));
				}
			}
		}
		vec.push_back(P(a,b));
	}
	sort(at.begin(),at.end());
	at.erase(unique(at.begin(),at.end()),at.end());
	sort(vec.begin(),vec.end());
	cnt[0]=(H-2)*(W-2)-at.size();
	for(int i=0;i<at.size();i++)
	{
		int x=at[i].first,y=at[i].second;
		int nm=0;
		for(int j=x;j<=x+2;j++)
		{
			for(int k=y;k<=y+2;k++)
			{
				nm+=ex(j,k);
			}
		}
		cnt[nm]++;
	}
	for(int i=0;i<10;i++) printf("%lld\n",cnt[i]);
	return 0;
}


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

int main(){
  int n,nc,sn=0,d;
  cin >> n;
  nc = n;
  
  for(int i=9;i>=0;i--){
    d = nc / pow(10,i);
    nc = nc - d*pow(10,i);
    sn += d;
  }
  
  if(n%sn==0) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;

}


Measured memory_bytes: 256
w,h,n = map(int,input().split())
x0,y0 = 0,0

for i in range(n):
    x,y,a = map(int,input().split())
    if a==1:
        x0=max(x0,x)
    elif a==2:
        w=min(w,x)
    elif a==3:
        y0=max(y0,y)
    else:
        h=min(h,y)
print(0 if w-x0<=0 or h-y0<=0 else (w-x0)*(h-y0))


Measured memory_bytes: 3060
#include "bits/stdc++.h"

using namespace std;

void Main() {
    int N;
    cin >> N;
    set<int> A;
    for (int i = 0; i < N; ++i) {
        int a;
        cin >> a;
        A.insert(a);
    }

    cout << ((A.size() == N) ? "YES" : "NO") << endl;
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 9600
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
    int n;
    cin >> n;
    vector<pair<int, int>> a(n);
    for(int i = 0; i < n; i++){
        scanf("%d", &a[i].first);
        a[i].second = i+1;
    }
    sort(a.begin(), a.end());
    for(int i = 0; i < n; i++){
        printf("%d ", a[i].second);
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 1664
#include <stdio.h>
int main(void){
	long a, b, c, d;
	scanf("%ld", &a);
	scanf("%ld", &b);
	scanf("%ld", &c);
	scanf("%ld", &d);
	long x;
	x = a*c;
	if (a*d > x) {
		x = a*d;
	}
	if (b*c > x) {
		x = b*c;
	}
	if (b*d > x) {
		x = b*d;
	}
	printf("%ld\n", x);
	return 0;
}


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

using namespace std;
using ll = long long;
using v1 = vector<int>;
using v2 = vector<vector<int>>;
int N;

int main(){
	ll n;
	string s;
	cin >> n >> s;
	ll size = s.size();
	ll east = 0;
	ll west = 0;
	rep(i, size){
		if(s.at(i) == 'E') east++;
		if(s.at(i) == 'W') west++;
	}
	ll change_left = 0;
	ll change_right;
	if(s.at(0) == 'E') change_right = east-1;
	if(s.at(0) == 'W') change_right = east;
	ll sum = change_right+change_left;
	rep(i, size){
		if(i == 0) continue;
		if(s.at(i) == 'E') change_right--;
		if(s.at(i-1) == 'W') change_left++;
		if(change_right+change_left < sum) sum = change_right+change_left;
	}
	cout << sum << endl;
}


Measured memory_bytes: 900
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define mod 1000000007
#define fi first
#define se second
#define pii pair<int,int>
#define int long long
#define endl '\n'
#define pll pair<long long,long long>
//#define LONGLONG_MAX 10000000000000000
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
long long power(long long a,long long b){
    long long ans=1;
    while(b>0){
        if(b&1){ans=(ans*a)%mod;}
                a=(a*a)%mod;
                b>>=1;
        }
    return ans;
        
}
int fact[200005],fact_inv[200005];
void pre(){
    fact[0]=1;
    fact_inv[0]=1;
    for(int i=1;i<200005;i++){
        fact[i]=fact[i-1]*i;
        fact[i]%=mod;
        fact_inv[i]=power(fact[i],mod-2);
    }
}
long long ncr(long long n,long long r){
    if(n<r){return 0;}
    if(n==r||r==0){return 1;}
    return (((fact[n]*fact_inv[n-r])%mod)*fact_inv[r])%mod;
    //return x; 
}
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n,k;
    cin>>n>>k;
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    pre();
    sort(a,a+n);
    int ans=0;
    for(int i=0;i<n;i++){
        ans+=(a[i]*ncr(i,k-1))%mod;
        ans%=mod;
        ans-=(a[i]*ncr(n-i-1,k-1))%mod;
        ans+=mod;
        ans%=mod;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 4224
#!/usr/bin/env python3

import math

n,m = list(map(int,input().split(" ")))

s = 0
t = 10**5+1
for i in range(m):
    a,b = list(map(int,input().split(" ")))
    if s < a:
        s = a
    if b < t:
        t = b
if t < s:
    print(0)
else:
    print(t-s+1)

Measured memory_bytes: 3060
#include <stdio.h>

int main(){
    char mk[4]={'S','H','C','D'};
    int c[4][14];
    int n,i,j;
    int m,s;
    char g;
    
    for(i=0;i<4;i++)
        for(j=0;j<14;j++)
            c[i][j]=0;
    
    scanf("%d",&n);
    
    for(i=0;i<n;i++){
        scanf(" %c %d",&g,&s);
        if(g=='S')m=0;
        if(g=='H')m=1;
        if(g=='C')m=2;
        if(g=='D')m=3;
        c[m][s]=1;
    }
    for(i=0;i<4;i++){
        for(j=1;j<14;j++){
            if(c[i][j]==0)printf("%c %d\n",mk[i],j);
        }
    }
    
return 0;
}

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

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

    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: usize = read();

    let ans = (1..10).find(|i| n / i <= 9 && n % i == 0);
    println!("{}", if ans == None { "No" } else { "Yes" });
}


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

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

  int n;
  cin >> n;
  vector<bool> exist(101);
  for (int i = 0; i < n; i++) {
    int d;
    cin >> d;
    exist[d] = true;
  }

  int res = 0;
  for (int i = 0; i < 101; i++) {
    res += exist[i];
  }
  cout << res << '\n';
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <bitset>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <queue>

#define mp make_pair
#define pb push_back


typedef long long ll;
typedef long double ld;

using namespace std;
#define y0 y0_aklsdfj

int pr[120][120];
char s[120][120];
int dp[120][120][120];
int n, m;
int x0, y0;

int get(int i, int j, int l, int r) {
	if (i > j || l > r)
		return 0;
	return pr[j + 1][r + 1] - pr[j + 1][l] - pr[i][r + 1] + pr[i][l];
}

int main() {
	cin >> n >> m;
	for (int i = 0; i < n; ++i)
		cin >> s[i];
	for (int i = 0; i < n; ++i)
		for (int j = 0; j < m; ++j)
			if (s[i][j] == 'E')
				x0 = i, y0 = j;
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= m; ++j)
			pr[i][j] = pr[i - 1][j] + pr[i][j - 1] - pr[i - 1][j - 1] + (s[i - 1][j - 1] == 'o' ? 1 : 0);
	for (int i = 0; i < n; ++i) {
		for (int l = m - 1; l >= 0; --l)
			for (int r = l; r < m; ++r) {
				if (l == r) {
					if (s[i][l] == 'o')
						dp[l][r][i] = 1;
					for (int j = i - 1; j >= 0; --j) {
						dp[l][r][j] = max(dp[l][r][j] + get(max(i, i + x0 - n + 1), min(i, j + x0), max(l, r + y0 - m + 1), min(r, l + y0)),
								dp[l][r][j + 1] + get(max(j, i + x0 - n + 1), min(j, j + x0), max(l, r + y0 - m + 1), min(r, l + y0)));
					}
				}
				else {
					dp[l][r][i] = max(dp[l][r - 1][i] + get(max(i, i + x0 - n + 1), min(i, i + x0), max(r, r + y0 - m + 1), min(r, l + y0)),
							dp[l + 1][r][i] + get(max(i, i + x0 - n + 1), min(i, i + x0), max(l, r + y0 - m + 1), min(l, l + y0)));
					for (int j = i - 1; j >= 0; --j) {
						dp[l][r][j] = max(dp[l][r][j] + get(max(i, i + x0 - n + 1), min(i, j + x0), max(l, r + y0 - m + 1), min(r, l + y0)),
								max(dp[l][r][j + 1] + get(max(j, i + x0 - n + 1), min(j, j + x0), max(l, r + y0 - m + 1), min(r, l + y0)), 
									max(dp[l][r - 1][j] + get(max(j, i + x0 - n + 1), min(i, j + x0), max(r, r + y0 - m + 1), min(r, l + y0)), 
										dp[l + 1][r][j] + get(max(j, i + x0 - n + 1), min(i, j + x0), max(l, r + y0 - m + 1), min(l, l + y0)))));
					}
				}
			}
	}
	cout << dp[0][m - 1][0] << "\n";
	return 0;
}




Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    int N; cin >> N;
    set<int> S;
    rep(i,N) {
        int a; cin >> a;
        if (S.count(a) > 0) S.erase(a);
        else S.insert(a);
    }
    cout << S.size() << endl;
}


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

using namespace std;

#define M (151200)

vector<int> p, q;
void init() {
    p.push_back(0);
    for (int i = 1; i * i * i <= M; i++) {
        p.push_back(i * i * i);
    }
    q.push_back(0);
    for (int i = 1; i * (i + 1) * (i + 2) / 6 <= M; i++) {
        q.push_back(i * (i + 1) * (i + 2) / 6);
    }
}

int solve(int n) {
    int ret = 0;
    for (int i = 0; i < p.size(); i++) {
        for (int j = 0; j < q.size(); j++) {
            if (p[i] + q[j] > n) continue;
            ret = max(ret, p[i] + q[j]);
        }
    }
    return ret;
}

int main() {
    init();
    int n;
    while (cin >> n, n) {
        cout << solve(n) << endl;
    }
    return 0;
}

Measured memory_bytes: 1216
#include <iostream>

using namespace std;

int n, k, q, x, a[100005];

int main()
{
    cin >> n >> k >> q;
    for(int i = 1; i <= q; i++){
        cin >> x;
        a[x]++;
    }
    for(int i = 1; i <= n; i++){
        if(k-(q-a[i])>0){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<queue>
#include<numeric>
#define all(x) (x).begin(),(x).end()
typedef long long ll;

using namespace std;

int main()
{
    int N;  cin >> N;
    vector<ll> v(N);
    ll s = 0;
    for(int i=0; i<N; i++){
        cin >> v[i];
        s += v[i];
    }
    ll t, tmp, ans;
    t = 0;
    ans = 1000000000000000;
    for(int i=0; i<N-1; i++){
        t += v[i];
        tmp = abs(s- 2*t);
        ans = min(ans, tmp);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4760
package main

import (
	"fmt"
)

func main() {
	var x int
	fmt.Scan(&x)

	for xx := x;; xx++ {
		a := true
		for b := 2; b <= xx/2; b++ {
			if xx%b == 0 {
				a = false
				break
			}
		}
		if a {
			fmt.Println(xx)
			return
		}
	}
}

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

//C++14 (GCC 5.4.1)

#define LLINF (1LL<<60)
typedef long long ll;
#define mod 1000000007

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define rrepd(i,a,b) for(int i=(a);i>=(b);i--)

template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

template<typename T> inline T divrup(T a, T b) { if (a % b) return a/b+1; else return a/b;}

#define dbg_v1(i,V) do{cout<<"-v1----\n";rep(i,V.size())cout<<" "<<i<<"\t:"<<V[i]<<endl;cout<<endl;}while(0)
#define dbg_v2(i,k,V) do{cout<<"-v2----\n";rep(i,V.size()){rep(k,V[0].size())cout<<" "<<V[i][k];cout<<endl;}}while(0)

int main() {
    ios::sync_with_stdio(false);//stdoutとcoutの同期解除
    cin.tie(nullptr);//cinとcoutの同期解除
    
    int N,X;
    cin >>N>>X;

    vector<int> L(N);
    rep(i,N) cin >> L[i];
    int D=0,ans=1;
    
    //-----------------------------------
    rep(i,N){
        D+=L[i];
        if(D<=X)ans++;
        else break;
    }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007
typedef long long int ll;
using namespace std;

int main()
{
    ll a, b, k; cin >> a >> b >> k;
    ll subk = max(k-a,ll(0));
    a = max(a-k,ll(0));
    b = max(ll(0),b-subk);
    cout << a << " " << b << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
int main(){
    fast
    string cad; cin >> cad;
    cad == "ABC"? cout << "ARC\n" : cout << "ABC\n";
    return 0;
}


Measured memory_bytes: 3656
n = gets.chomp.to_i
a1 = gets.chomp.split(" ").map(&:to_i)
a2 = gets.chomp.split(" ").map(&:to_i)

ans = []

n.times do |i|
  s = 0
  a1[0..i].each{|x| s += x}
  a2[i..n].each{|x| s += x}
  ans << s
end

puts ans.max

Measured memory_bytes: 3836
#![allow(unused)]

//input
use std::io::Read;

//collections
//use std::collections::BTreeMap;
//use std::collections::BTreeSet;
//use std::collections::HashMap;
//use std::collections::HashSet;

//入力マクロここから
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
//入力マクロここまで

fn main() {
    input! {
        n: usize,
        k: usize,
        h: [u64;n],
    }
    let mut h = h;

    h.sort_by_key(|x| !x);

    let mut ans = 0;
    for i in k..n {
        ans += h[i];
    }

    println!("{:?}", ans);
}

Measured memory_bytes: 6396
/*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
*$* WRITER:kakitamasziru/OxOmisosiru *$*
~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=*/
#ifdef LOCAL_JUDGE
#define _GLIBCXX_DEBUG //FOR THE DEBUG! COMMENT OUT THIS WHEN SUBMITTING!
#endif
/* I REALLY HOPE MY WISH REACH YOU , ATCODER'S ONLINE JUDGE */
#define WOULD
#define YOU
#define PLEASE
#define ACCEPT
#define MY
#define SUBMISSION
/* I REALLY HOPE MY WISH REACH YOU , ATCODER'S ONLINE JUDGE */
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <iomanip>
#include <limits>//setprecision
//#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <unordered_set> //unordered_set
#include <stack> // stack
#include <deque> // deque
#include <math.h>//pow,,,
#include <cmath>//abs,,,
#include <bitset> // bitset
//It is so troublesome that I include bits/stdc++.h !
using namespace std;

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const long long INF = 100100100100;
const long long MOD = 1000000007;
typedef pair<int,int> P;

//Solve N^M. This, mod_pow use Iterative Square Method.
long long mod_pow(long long N, long long M) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % MOD, M / 2);
    //最下位ビット(*N)が1の時は単独でNをかける
    if (M & 1) res = (res * N) % MOD;

    return res %= MOD;
}

long long gcd(long long a, long long b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
    return a * b / gcd(a, b);
}

vector<vector<int>> Edge(200005);
vector<int> dist(200005,0);
vector<bool> seen(200005,false);

int main() {
    int N,M;cin >> N >> M;
    for(int i = 0;i<M;i++){
        int a,b;cin >> a >> b;
        a--;b--;
        Edge.at(a).push_back(b);
        Edge.at(b).push_back(a);
    }
    //頂点,距離
    queue<P> Q;
    Q.push(make_pair(0,0));
    seen.at(0) = true;
    while(!Q.empty()){
        P p = Q.front();Q.pop();
        int from = p.first;
        int dis = p.second;
        dis++;
        for(int to : Edge.at(from)){
            if(seen.at(to)) continue;
            dist.at(to) = dis;
            seen.at(to) = true;
            Q.push(make_pair(to,dis));
        }
    }
    if(dist.at(N-1) != 2){
        cout << "IMPOSSIBLE" << endl;
    }
    else{
        cout << "POSSIBLE" << endl;
    }

}

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

int main()
{
	int x,y;
	while(1)
	{
		cin >> x >> y;
		if(x > y)
		{
			int tmp = x;
			x = y;
			y = tmp;
		}
		else if(x == 0 && y == 0)
		{
			break;
		}

		cout << x << " " << y << endl;
	}

	return 0;
}

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

using namespace std;
typedef long long ll;

#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mp make_pair
#define pb push_back
#define lp(i,s,f) for(ll i = s; i < ll(f); i++)
#define inF freopen("input.in", "r", stdin);
#define outF freopen("output.in", "w", stdout);
#define endl '\n'
#define MOD 1000000007
#define mm(arr) memset(arr, 0, sizeof(arr))
#define int ll

int32_t main(){
    FAST
    int n; cin >> n;
    int ans = 0;
    for(int i = 2; i * i <= n; i++){
        int cnt = 0;
        while(n%i == 0){n /= i; cnt++;}
        int a = 1;
        while(cnt){
            cnt -= a;
            if(cnt < 0)break;
            a++;
        }
        a--;
        ans += a;
    }
    if(n != 1){
        ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3580
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

namespace atcoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var buffer = Console.ReadLine().Split();
            var N = int.Parse(buffer[0]);
            var X = int.Parse(buffer[1]);
            var T = int.Parse(buffer[2]);

            if (N < X)
                Console.WriteLine(T);
            else if (N % X == 0)
                Console.WriteLine(N / X * T);
            else
                Console.WriteLine(N / X * T + T);
        }
    }
}


Measured memory_bytes: 27260
// ref. https://img.atcoder.jp/arc079/editorial.pdf

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> void printvec(const vector<T>& v) {
  for (auto x : v) { cout << x << " "; }
  cout << endl;
}
template<class T> void printtree(const vector< vector<T> >& tree) {
  for (long long i = 0; i < tree.size(); ++i) {
    cout << i + 1 << ": "; printvec(tree[i]);
  }
}
template<class T, class U> void printmap(const map<T, U>& mp) {
  for (auto x : mp) { cout << x.first << "=>" << x.second << endl; }
}

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

#define rep(i, n) for(ll i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()
#define fr first
#define sc second
#define mp make_pair
#define pb push_back

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;

const ll INF = 1e9;
const ll MOD = 1000000007;  // 1e9 + 7

int main(int argc, char** argv) {
  cin.tie(NULL);
  cout.tie(NULL);
  ios_base::sync_with_stdio(false);
  //cout << setprecision(10) << fixed;

  ll n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) {
    cin >> a[i];
  }
  ll ans = 0;
  while (true) {
    ll s = 0;

    // Check the validness of a
    bool ok = true;
    rep(i, n) {
      if (a[i] >= n) { ok = false; }
      s += a[i]/n;
    }
    if (ok) { break; }

    // Here, s is sum of a[i]/n. We do operations s times.
    ans += s;
    rep(i, n) {
      ll now = a[i]/n;
      a[i] -= now*n;
      a[i] += s-now;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include "iostream"
using namespace std;
int main(){
  int a;int b;int c;
  cin>>a>>b>>c;
  if(b>a){
    int d=0;
    while((b>=a)&&(c!=0)){
      c-=1;
      b-=a;
      d+=1;
    }
    cout<<d<<endl;
  }
  else if(a>b){
    cout<<0<<endl;
  }
  else{
    cout<<1<<endl;
  }

}


Measured memory_bytes: 3596
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    int n = Integer.parseInt(in.readLine());
    int[] a = new int[n];
    for(int i=0; i<n; i++) {
      a[i] = Integer.parseInt(in.readLine());
    }
    
    int count = 0;
    int currentButton = a[0];
    int[] ary = new int[n];
    boolean hantei = false;
    for(int i=0; i<n;) {
      if(currentButton==2) {
        count++;
        System.out.println(count);
        return;
      } else if(ary[currentButton-1]==2){
        System.out.println(-1);
        return;
      } else {
        count++;
        currentButton=a[currentButton-1];
        ary[currentButton-1]++;
      }
    }
  }
}

Measured memory_bytes: 41968
n = int(input())
line = input()
lista = [int(n) for n in line.split()]
pos = 1
can = 0
for l in lista:
    semi_lista = lista.copy()
    semi_lista = semi_lista[0:pos]
    semi_lista.sort()
    step_max = semi_lista[len(semi_lista)-1]
    if l >= step_max:
        can+=1
    pos+=1
print(can)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
#define PI acos(-1.0)
#define MOD 1000000007
#define R READ();
using namespace std;
typedef long long LL;
void READ()
{
    std::ios::sync_with_stdio(false);
//#ifdef ONLINE_JUDGE
//#else
 //   freopen("555input.txt","r",stdin);
//    //freopen("555output.txt","w",stdout);
//#endif
}
#define N 205
int ans,n,m,t,i,j,k,e[N],num,a,b,c,d[N][N],pl[N];
int mi=INF;
void floyd()
{
    for(int k=1; k<=n; k++)
        for(int i=1; i<=n; i++)
            for(int j=1; j<=n; j++)
                d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
}
int main()
{
    R
    cin>>n>>m>>num;
    for(i=0;i<num;i++)cin>>e[i];
    memset(d,0x3f,sizeof(d));
    for(int i=0; i<=n; i++)
        d[i][i]=0;
    for(i=0;i<m;i++)
    {
        cin>>a>>b>>c;
        d[a][b]=d[b][a]=c;
    }
    floyd();
    for(i=0;i<num;i++)
    {
        pl[i]=i;
    }
    do
    {
        ans=0;
        for(i=1;i<num;i++)
        {
            ans+=d[e[pl[i-1]]][e[pl[i]]];
        }
        mi=min(mi,ans);

    }while(next_permutation(pl,pl+num));
    cout<<mi;
    return 0;
}


Measured memory_bytes: 384