akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<tuple>
#include<map>
#include<queue>
#include<stack>
#include<deque>
#include<bitset>
#include<math.h>
using namespace std;
int main(){
    int x,n;
    cin >> x >> n;
    
    if(n==0){
        cout << x << endl;
        return 0;
    }
    
    map<int,int> p;
    int i;
    for(i=0;i<=101;i++) p[i]=i;
    int q;
    for(i=0;i<n;i++){
        cin >> q;
        p.erase(q);           
    }

    int a=0,u=x,o=101-x,b=101;
    for(i=0;i<=101;i++){
        if(p.count(i)){
            if(i<=x){
                if(u>x-p.at(i)){
                    u = x-p.at(i);
                    a = p.at(i);
                }
            }
            if(i>x){
                if(o>p.at(i)-x){
                    o = p.at(i)-x;
                    b = p.at(i);
                }
            }
        }else{
            continue;
        }
    }

    if(u<=o){
        cout << a << endl;
    }else{
        cout << b << endl;
    }

}


Measured memory_bytes: 3608
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define INF 1e16
typedef long long ll;
typedef pair<ll,ll> P;

bool dp[100010];

int main(void){
    int n,k;
    cin>>n>>k;
    vector<int>a(n);
    for(int i=0;i<n;i++)cin>>a[i];
    for(int i=0;i<100010;i++)dp[i]=false;
    dp[0]=false;
    for(int i=1;i<=k;i++){
        for(int j=0;j<n;j++){
            if(i>=a[j]){
                if(!dp[i-a[j]])dp[i]=true;
            }
        }
    }
    if(!dp[k])cout<<"Second"<<endl;
    else cout<<"First"<<endl;
    return 0;
}

Measured memory_bytes: 384
s=input()
c=0
count=0
hantei=0
d=["A","C","T","G"]
for i in s:
  if i=="A" or i=="C" or i=="T" or i=="G":
    count+=1
  else:
    if hantei<count:
      hantei=count
      count=0
if hantei<count:
  hantei=count
print(hantei)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
 
#define int         long long
#define ll          long long
#define uint        unsigned int
#define ld          long double
#define showoff     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb          push_back
#define pii         pair<int,int>
#define FOR(i,a,b)  for(int i=a;i<b;++i)
#define RFOR(i,a,b) for(int i=a;i>b;--i)
#define f           first
#define se          second
#define maxn        200005
#define all(v)      v.begin(),v.end()
#define sz(x)       (int)x.size()
#define mod         1000000007
#define pqueue      priority_queue<pii>
#define pdqueue     priority_queue< int,vector<int> ,greater< int >>
 
using namespace std;
 
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
int power(int a,int n)
{
    a %= mod;
    if(n == 1)return a;
    if(n == 0)return 1;
    if(n%2)return (a*(power((a*a)%mod,n/2)%mod))%mod;
    return power((a*a)%mod,n/2)%mod;
}
 
const int inf = (int) 1e18;
 
int inverse(int x){
    return power(x,mod-2)%mod;//little fermat....
} 

void solve(){
    int x;
    cin >> x;
    if(x >= 30)cout << "Yes\n";
    else cout << "No\n";
}
signed main()
{
    showoff;
    int T = 1;
    //cin >> T;
    FOR(t,1,T+1){
        solve();
        //cout << "\n";
    }
    return 0;
}
//*->for large size of matrix take int not long long if possible......
//*->always take maximum as inf for safer side ...

Measured memory_bytes: 3648
#include <stdio.h>

int n;
int adj[8][8];
int visited[8];

int dfs(int cur, int num) {
	if (num == n)
		return 1;

	visited[cur] = 1;

	int sum = 0;
	for (int i = 0; i < n; i++)
		if (adj[cur][i] && !visited[i])
			sum += dfs(i, num + 1);

	visited[cur] = 0;

	return sum;
}

int main(void) {
	int m;

	scanf("%d %d", &n, &m);
	for (int i = 0; i < m; i++) {
		int a, b;
		scanf("%d %d", &a, &b);
		a--; b--;
		adj[a][b] = adj[b][a] = 1;
	}

	printf("%d\n", dfs(0, 1));

	return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
#define N 100

int main(){
  int n, i, j, temp, count=0;
  int A[N+1];
  
  scanf("%d",&n);
  
  for(i=0;i<n;i++) {
    scanf("%d",&A[i]);
  }
  
  for(i = 0; i<n-1; i++) {
    for(j=n-1;j>0;j--) {
      if(A[j]< A[j -1]) {
        temp = A[j-1];
        A[j-1] = A[j];
        A[j] = temp;
        count++;
      }
    }
  }
  
  for(i=0;i<n;i++) {
    if(i < n-1) printf("%d ",A[i]);
    else if(i == n-1) printf("%d\n", A[n-1]);
  }
  printf("%d\n", count);
  return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#include<string>
using namespace std;
#define ll long long
#define ld long double
#define endl '\n'
#define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const int maxn=2*1e5+5;

int main()
{
    FAST

 ll x,y;
 cin>>x>>y;
 cout<<(ll)x*y/(ll)__gcd(x,y)<<endl;
    return 0;
}


Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LS()
    return l
sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    n = I()
    ans = float("inf")
    for i in range(n+1):
        m = 0
        k = i
        while k > 0:
            m += k%6
            k //= 6
        k = n-i
        while k > 0:
            m += k%9
            k //= 9
        if m < ans:
            ans = m
    print(ans)
    return

#B
def B():
    n = I()
    x = [None for i in range(n)]
    y = [None for i in range(n)]
    h = [None for i in range(n)]
    for i in range(n):
        x[i],y[i],h[i] = LI()
    if n == 1:
        print(x[0],y[0],h[0])
        quit()
    for cy in range(101):
        for cx in range(101):
            for i in range(n):
                if h[i] > 0:break
            ch = h[i]+abs(x[i]-cx)+abs(y[i]-cy)
            f = 1
            for i in range(n):
                if max(ch-abs(x[i]-cx)-abs(y[i]-cy),0) != h[i]:f = 0
            if f:
                print(cx,cy,ch)
                quit()
    return

#C
def C():
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#I
def I_():
    return

#J
def J():
    return

#Solve
if __name__ == "__main__":
    B()


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

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

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int cnt[200005];
int a[200005];
int main(){
  int n;
  cin >> n;
  
  int mx = 0, mx1 = 0;
  
  for(int i = 1;i<=n;i++){
   
    cin >> a[i];
    cnt[a[i]]++;
    mx1 = max(mx1, min(a[i], mx)); //cout << mx1 << endl; 
    mx = max(a[i],mx);
  }
  
  for(int i = 1;i<=n;i++){
    if(a[i]!=mx)cout << mx << endl;
    else{
      if(cnt[mx]>1)cout << mx << endl;
      else cout << mx1 << endl;
    }
  }
  return 0;
}
    
  


Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x.size())
#define PI 3.1415926535897932384626433832795
int MOD=1e9+7;
int powmod(int a,int l, int md){int res=1;while(l){if(l&1)res=res*a%md;l/=2;a=a*a%md;}return res;}
int binpow(int a,int l){int res=1;while(l){if(l&1)res=res*a;l/=2;a=a*a;}return res;}
typedef long long ll; typedef vector<ll> vi; typedef pair<ll, ll> ii; typedef vector<ii> vii;
#define pb push_back
int __set(int b, int i) {return b|(1<<i);} //set ith bit
int __unset(int b, int i) {return b&(~(1UL<<i));}
int __check(int b, int i) {return b&(1<<i);} //returns 0 if ith bit is 0
int mulmod(int a, int b, int md) {return ((a%md)*(b%md))%md;}
int addmod(int a, int b, int md) {return (a+b)%md;}
int submod(int a, int b, int md) {return (((a-b)%md)+md)%md;}
int divmod(int a, int b, int md) {return mulmod(a, powmod(b, md-2, md), md);} //if md is prime;
const ll inf = 0xFFFFFFFFFFFFFFFL; //very large number
priority_queue<int, vector<int>, greater<int> > pq; //for min priority_queue
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
clock_t time_p=clock();
void time()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}

signed main(void)
{
	IOS;
	int n;
	cin>>n;
	string s;
	string t;
	cin>>s>>t;
	string f="";
	for(int i = 0; i < n; i++) {
		f.pb(s[i]);
		f.pb(t[i]);
	}
	cout<<f<<endl;
	// time();
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
//#pragma comment(linker, "/STACK:102400000,102400000")
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <limits.h>
#include <math.h>
#include <algorithm>
#include <deque>
#include <queue>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <string>
#include <vector>
#include <bitset>
#include <functional>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef double db;
typedef long double ldb;
#define rep(i,a,b) for(i=a;i<b;i++)
#define repu(i,a,b) for(i=a;i<=b;i++)
#define repd(i,a,b) for(i=a;i>=b;i--)
#define repc(i,a,b,c) for(i=a;i<b;i+=c)
#define repcu(i,a,b,c) for(i=a;i<=b;i+=c)
#define repcd(i,a,b,c) for(i=a;i>=b;i-=c)
#define FIN freopen("test.in","r",stdin)
#define FOUT freopen("test.out","w",stdout)
#define CC(a) memset(a,0,sizeof(a))
#define MST(a,b) memset(a,b,sizeof(a))
#define PII pair<int,int>
#define PLL pair<long long,long long>
#define VI vector<int>
#define VL vector<long long>
#define VII vector<PII>
#define VLL vector<PLL>
#define all(x) x.begin(),x.end()
#define mp make_pair
#define pb push_back
#define pf push_front
 
template<typename T>inline void gn(T &x){
	x=0;T f=1;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
	while(isdigit(ch)){x=x*10+ch-'0';ch=getchar();}
	x*=f;
}
template<typename T>inline void gt(T x){
	if(!x)return;
	gt(x/10);putchar(x%10+'0');
}
 
const LL N=1e5+5;
struct NODE{
	LL i,r,c,num;
}tt,ss;
LL t,n,m,q,ans;
LL MOD=1e9+7,inf=0x1f1f1f1f;
db eps=1e-5;
LL f[N],dp[20][N];

int main()
{
//	FIN;FOUT;
	ios_base::sync_with_stdio(false);cin.tie(0);
	LL i,j,k,l,ca=0,u,v,tmp;
	cin>>n;
	repu(i,1,n)cin>>f[i];f[n+1]=1e18;
	cin>>m;
	
	for(tmp=i=1;i<n;i++){
		for(j=tmp+1;j<=n;j++)
			if(f[j]-f[i]>m)break; 
		tmp=dp[1][i]=j-1;
	}
	for(i=2;(1<<i)<=n;i++){
		for(j=1;j<=n;j++){
			dp[i][j]=dp[i-1][dp[i-1][j]];
		}
	}k=i;
	
	cin>>t;
	while(t--){
		cin>>u>>v;ans=0;
		if(u>v)swap(u,v);
		while(u<v)
		for(i=k;i>0;i--){
			if(dp[i][u]>v){
				if(i>1)continue;
				else {
					ans++;
					u=dp[i][u];
					break;
				}
			}
			if(dp[i][u])ans+=(1<<i>>1),u=dp[i][u];
			if(u==v)break;
		}
		cout<<ans<<endl;
	}
	return 0;
}

/*

10
1 2 3 5 6 7 9 10 11 13
2

*/

Measured memory_bytes: 14080
#include "bits/stdc++.h"
using namespace std;

#define int long long
#define MAX_N (300005)
#define INF (1LL<<60)
#define debug(x) cerr << #x <<":"<< x << endl;
#define debugVec(x) cerr << #x <<": "; for(auto p:(x)) cerr << p <<" "; cerr << endl;
#define debugVecPair(x) for(auto p:(x)) cerr << #x <<": "<< p.first <<", "<< p.second << endl;
#define debug2(x, y) cerr << #x <<" : "<< x <<", "<< #y <<" : "<< y << endl;
#define debug3(x, y, z) cerr << #x <<" : "<< x <<", "<< #y <<" : "<< y <<", "<< #z <<" : "<< z << endl;
const int MOD = (int)1e9+7;
typedef pair<int,int> P;

signed main() {
    int A, B, C;
    cin >> A >> B >> C;
    if(A<=C && C<=B || B<=C && C<=A) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**6)

H, W = map(int, input().split())
S = [input() for _ in range(H)]
check = [[0]*W for _ in range(H)]
di = [-1, 0, 1, 0]
dj = [ 0,-1, 0, 1]
black, white = 0, 0

def dfs(i, j):
    global check, black, white
    if check[i][j]:
        return
    else:
        check[i][j] = 1
    if S[i][j] == '#':
        black += 1
    else:
        white += 1
    for dir in range(4):
        ni = i + di[dir]
        nj = j + dj[dir]
        if ni < 0 or ni >= H or nj < 0 or nj >= W: continue
        if S[i][j] == S[ni][nj]: continue
        dfs(ni, nj)
    return

ans = 0
for i in range(H):
    for j in range(W):
        black, white = 0, 0
        dfs(i, j)
        ans += black * white

print(ans)


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

using namespace std;

typedef struct {
    int x, y;
} Point;

const int INF = 1e9;

int absP(Point A, Point B) {
    return abs(A.x - B.x) + abs(A.y - B.y);
}

int main() {
    int N, M;
    cin >> N >> M;
    
    vector<Point> A(N);
    vector<Point> B(M);

    for (int i = 0; i < N; i++)
        cin >> A[i].x >> A[i].y;

    for (int i = 0; i < M; i++)
        cin >> B[i].x >> B[i].y;

    vector<int> ans(N);

    for (int i = 0; i < N; i++) {
        int min = INF;
        for (int j = 0; j < M; j++) {
            if (absP(A[i], B[j]) < min) {
                min = absP(A[i], B[j]);
                ans[i] = j + 1;
            }
        }
    }

    for (int i = 0; i < N; i++)
        cout << ans[i] << endl;
}

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

int a[15], b[2], flag[2];

int main()
{
    int t;
    cin >> t;
    while(t--)
    {
        int is_yes = 1;
        b[0] = b[1] = 0;
        for(int i = 0; i < 10; i++)
            cin >> a[i];
        for(int i = 0; i < 10; i++)
        {
            flag[0] = flag[1] = 0;
            for(int j = 0; j < 2; j++)
            {
                //cout << "a[i]" << a[i] << endl;
                if(b[j] == 0)
                {
                    b[j] = a[i];
                    break;
                }
                else if(b[j] < a[i])
                {
                    b[j] = a[i];
                    break;
                }
                flag[j] = 1;
            }
            //for(int j = 0; j < 2; j++)
                //cout << "b[" << j <<"] = " << b[j] << endl;
            if(flag[1] && flag[0])
            {
                cout << "NO" << endl;
                is_yes = 0;
                break;
            }
        }
        if(is_yes)
            cout << "YES" << endl;
    }


    return 0;
}



Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define sayyes cout<<"Yes"<<endl;
#define sayno cout<<"No"<<endl;
#define vv(a,b) vector< vector<int> > v(a,vector<int>(b,0));
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const int mod =1e9+7;

int main()
{
    int a,b,k;
    cin>>k;
    cin>>a>>b;
    for(int i=a;i<=b;i++)
    {
        if(i%k==0)
        {
            cout<<"OK";
            return 0;
        }
    }
    cout<<"NG";
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
typedef long long int ll;
#define M 1000000007
#define all(a) a.begin(), a.end()
#define forr(i,a,b) for(ll i=a;i<b;i++)
#define stringupper(s) transform(s.begin(), s.end(), s.begin(), ::toupper)
#define stringlower(s) transform(s.begin(), s.end(), s.begin(), ::tolower)
#define nl cout<<endl
#define pb push_back
#define mp make_pair
#define vll vector<ll>
using namespace std;
int main()
{
	
	ll n;
	cin>>n;
	ll a=n%10;
	if(a==3)
		cout<<"bon";
	else if(a==0||a==1||a==6||a==8)
		cout<<"pon";
	else 
		cout<<"hon";
	return 0;
}


Measured memory_bytes: 3632
class LazySegmentTree
	def initialize(n, l = 0, r = n-1)
		@range_min = l
		@range_max = r
		@start = 0
		@between = 0
		@end = 0
		if l == r
		else
			c = (l + r) / 2
			@left_child = self.class.new(n, l, c)
			@right_child = self.class.new(n, c+1, r)
		end
	end

	attr_reader :range_min, :range_max

	def add_start(x, bits)
		if @range_min == @range_max
			@start |= bits
		else
			force
			if x <= @left_child.range_max
				@left_child.add_start(x, bits)
			else
				@right_child.add_start(x, bits)
			end
		end
	end

	def add_end(x, bits)
		if @range_min == @range_max
			@end |= bits
		else
			force
			if x <= @left_child.range_max
				@left_child.add_end(x, bits)
			else
				@right_child.add_end(x, bits)
			end
		end
	end

	def add_between(x, y, bits)
		return if x > y

		if x == @range_min && y == @range_max
			@between |= bits
		else
			force
			lr = @left_child.range_max
			@left_child.add_between(x, lr < y ? lr : y, bits)
			rl = @right_child.range_min
			@right_child.add_between(rl > x ? rl : x, y, bits)
		end
	end

	def force
		if @range_min != @range_max
			@left_child.take(@start, @between, @end)
			@right_child.take(@start, @between, @end)
		end
		@star = @between = @end = 0
	end

	def take(start, between, finish)
		@start |= start
		@between |= between
		@end |= finish
	end

	def net_start_count(x)
		if @range_min == @range_max
			bits = @start
			bits -= bits & @end
			bits -= bits & @between
			bits.to_s(2).count("1")
		else
			force
			if x <= @left_child.range_max
				@left_child.net_start_count(x)
			else
				@right_child.net_start_count(x)
			end
		end
	end

	def net_end_count(x)
		if @range_min == @range_max
			bits = @end
			bits -= bits & @start
			bits -= bits & @between
			bits.to_s(2).count("1")
		else force
			if x <= @left_child.range_max
				@left_child.net_end_count(x)
			else
				@right_child.net_end_count(x)
			end
		end
	end
end


ones = [0]
10000.times{
	ones << ((ones[-1] << 1) | 1)
}

t = Time.new

loop {
	n, r = gets.split.map(&:to_i)
	break if n == 0


	a = (1..n).map{ gets.split.map(&:to_i) }
	max_x = a.map{|_,_,x2,_| x2}.max
	max_y = a.map{|_,_,_,y2| y2}.max
	v_st = LazySegmentTree.new(max_x+1)
	h_st = LazySegmentTree.new(max_y+1)

	a.each {|x1, y1, x2, y2|
		bits = ones[y2-y1] << y1
		v_st.add_start(x1, bits)
		v_st.add_between(x1+1, x2-1, bits) if x1+1 < x2
		v_st.add_end(x2, bits)
		bits = ones[x2-x1] << x1
		h_st.add_start(y1, bits)
		h_st.add_between(y1+1, y2-1, bits) if y1+1 < y2
		h_st.add_end(y2, bits)
	}

	area = 0
	for x in 0..max_x
		area += v_st.net_start_count(x) * (10000-x)
		area -= v_st.net_end_count(x) * (10000-x)
	end
	p area

	if r == 2
		len = 0
		for x in 0..max_x
			len += v_st.net_start_count(x)
			len += v_st.net_end_count(x)
		end
		for y in 0..max_y
			len += h_st.net_start_count(y)
			len += h_st.net_end_count(y)
		end
		p len
	end
}

Measured memory_bytes: 89276
#include"bits/stdc++.h"
using namespace std;
using ll=long long;
template<typename T=ll>inline T in(istream&is=cin){T ret;is>>ret;return ret;}
template<typename T>inline auto vec2(typename vector<T>::size_type h,typename vector<T>::size_type w,T v=T()){return vector<vector<T>>(h,vector<T>(w,v));}

int main()
{
    ll n=in(),k=in();
    vector<ll>a(n);for(ll i=0;i<n;++i)a[i]=in()-1;

    vector<ll>first_time(n,-1);
    ll now=0;
    for(ll i=0;i<k;++i){
        if(first_time[now]!=-1){
            for(ll foo=(k-i)%(i-first_time[now]);foo;--foo)now=a[now];
            break;
        }
        first_time[now]=i;
        now=a[now];
    }
    cout<<now+1<<endl;
}


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

int main() {
  int n,k;
  cin>>n>>k;
  vector<int> moto(n);
  for(int i=0;i<n;i++){
    moto.at(i)=i+1;
  }
  for(int i=0;i<k;i++){
    int kazu;
    cin>>kazu;
    vector<int> data(kazu);
    for(int k=0;k<kazu;k++){
    cin>>data.at(k);
    }
        for(int k=0;k<kazu;k++){
    for(int j=0;j<n;j++){
      if(data.at(k)==moto.at(j)){
        moto.at(j)=0;
      }
    }
    }
  }
 int count=0;
  for(int i=0;i<n;i++){
    if(!(moto.at(i)==0)){
      count++;
    }
  }
  cout<<count<<endl;
}


Measured memory_bytes: 3652
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
#include<cstdio>
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> T;
int u[105];

int p(int x){
    if(u[x] == x)return x;
    return u[x] = p(u[x]);
}

void unin(int x, int y){
    x = p(x);
    y = p(y);
    u[x] = y;
}

int main(){
    int n, m, a, b, w;
    while(cin >> n, n){
	cin >> m;
	int res = 0;
	priority_queue<T, vector<T>, greater<T> > pq;
	for(int i = 0;i < m;i++){
	    scanf("%d,%d,%d", &a, &b, &w);
	    w/=100;w--;
	    pq.push(T(w, P(a, b)));
	}
	for(int i = 0;i <= n;i++)u[i] = i;
	while(!pq.empty()){
	    T tmp = pq.top();pq.pop();
	    int a = tmp.second.first, b = tmp.second.second;
	    if(p(a) == p(b))continue;
	    unin(a, b);
	    res += tmp.first;
	}
	cout << res << endl;
    }
    return 0;
}

Measured memory_bytes: 1372
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.reflect.Array;
import java.util.*;
import java.util.jar.JarOutputStream;

public class Main {

    public static int lower_bound(long[] arr,long target){
        int low = 0;
        int high = arr.length - 1;
        while(low < high){
            int mid = (low + high) / 2;
            if(arr[mid] < target){
                low = mid + 1;
            }
            else{
                high = mid;
            }
        }
        return low;
    }

    public static void main(String[] args) throws IOException {

        Reader.init(System.in);
        int n= Reader.nextInt();
        int[] cost=Reader.nextIntArray(n);
        int[] dp=new int[n];
        dp[0]=0;
        if(dp.length>1){
            dp[1]=Math.abs(cost[1]-cost[0]);
        }
        for(int i=2;i<dp.length;i++){
            dp[i] = Math.min(dp[i-1]+Math.abs(cost[i]-cost[i-1]),dp[i-2]+Math.abs(cost[i]-cost[i-2]));
        }
        System.out.println(dp[n-1]);

    }

}






class Reader {
    static BufferedReader reader;
    static StringTokenizer tokenizer;

    /** call this method to initialize reader for InputStream */
    static void init(InputStream input) {
        reader = new BufferedReader(
                new InputStreamReader(input) );
        tokenizer = new StringTokenizer("");
    }

    /** get next word */
    static String nextLine() throws IOException {
        while ( ! tokenizer.hasMoreTokens() ) {
            //TODO add check for eof if necessary
            tokenizer = new StringTokenizer(
                    reader.readLine() );
        }
        return tokenizer.nextToken();
    }

    static int nextInt() throws IOException {
        return Integer.parseInt( nextLine() );
    }
    static long nextLong() throws IOException {
        return Long.parseLong(nextLine());
    }

    static double nextDouble() throws IOException {
        return Double.parseDouble( nextLine() );
    }

    static float nextFloat() throws IOException {
        return Float.parseFloat( nextLine() );
    }
    static int[] nextIntArray(int length) throws IOException {
        int[] arr = new int[length];
        //System.out.println(length);
        for (int i=0; i<length; i++) {
            arr[i] = Integer.parseInt( nextLine() );
            //System.out.println(arr[i]);
        }
        //System.out.println(arr);
        return arr;
    }
    static long[] nextLongArray(int length) throws IOException {
        long[] arr = new long[length];
        for (int i=0; i<length; i++) {
            arr[i] = Long.parseLong( nextLine() );
        }
        return arr;
    }

}



Measured memory_bytes: 43040
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m,r;
  cin >> n >> m >> r;
  vector<int> t(r);
  for(int i=0;i<r;i++){
    cin >> t[i];
  }
  vector<vector<int>> d(n,vector<int>(n,1e9));
  for(int i=0;i<n;i++){
    d[i][i]=0;
  }
  for(int i=0;i<m;i++){
    int a,b,c;
    cin >> a >> b >> c;
    a--,b--;
    d[a][b]=c;
    d[b][a]=c;
  }
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      for(int k=0;k<n;k++){
        d[j][k]=min(d[j][k],d[j][i]+d[i][k]);
      }
    }
  }
  int ans=1e9;
  sort(t.begin(),t.end());
  do{
    int sum=0;
    for(int i=0;i<r-1;i++){
      sum+=d[t[i]-1][t[i+1]-1];
    }
    ans=min(ans,sum);
  }while(next_permutation(t.begin(),t.end()));
  cout << ans << endl;
}

Measured memory_bytes: 384
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = ReadInt();
            var set = new HashSet<string>();
            for (int i = 0; i < n; i++)
            {
                var lines = ReadLines();
                if (lines[0] == "insert")
                {
                    set.Add(lines[1]);
                }
                else if (lines[0] == "find")
                {
                    if (set.Contains(lines[1]))
                    {
                        Console.WriteLine("yes");
                    }
                    else
                    {
                        Console.WriteLine("no");
                    }
                }
            }
        }

        static string ReadLine()
        {
            return Console.ReadLine();
        }

        static int ReadInt()
        {
            return int.Parse(ReadLine());
        }

        static string[] ReadLines()
        {
            return ReadLine().Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries);
        }

        static IEnumerable<int> ReadInts()
        {
            return ReadLines().Select(x => int.Parse(x));
        }
    }

    //static class Console
    //{
    //    static StreamReader reader = new StreamReader("input.txt");

    //    public static string ReadLine()
    //    {
    //        return reader.ReadLine();
    //    }
    //}
}

Measured memory_bytes: 38972
#include <iostream>
using namespace std;
int a[200006];
int main () {
    int N, K;
    cin >> N >> K;
    for (int i=0; i<N; i++) {
        cin >> a[i];
    }
    for (int i=0; i<N-K; i++) {
        if (a[i]<a[i+K]) {
            cout << "Yes" << endl;
        }
        else {
            cout << "No" << endl;
        }
    }
}

Measured memory_bytes: 4388
#include<stdio.h>
int main(void){
  int n=0;
  scanf("%d", &n);
  int sum=0;
  for(int a=0; a<100; a++){
    for(int b=0; b<100; b++){
      sum=a*4+b*7;
      if(sum==n){
        printf("Yes\n");
        return 0;
      }
    }
  }
  printf("No\n");
  return 0;
}

Measured memory_bytes: 128
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
const int N=1e5+5,YL=1e9+7;
int n,mp[26];char s[N];
int main()
{
	cin>>n>>s+1;int ans=1;
	for(int i=1;i<=n;++i)mp[s[i]-'a']++;
	for(int i=0;i<26;++i)ans=1ll*ans*(mp[i]+1)%YL;
	printf("%d\n",ans-1);
	return 0;
}


Measured memory_bytes: 384
# -*- coding: utf-8 -*-
import sys
# ----------------------------------------------------------------
# Use Solve Function

def solve(lines):
    N,M = map(int, lines.pop(0).split(' '))
    res = set(range(1,M+1))
    for i in range(N):
        a = list(map(int, lines.pop(0).split(' ')))
        a.pop(0)
        res = res & set(a)
    print(len(res))


#
# main
#
lines = [x.strip() for x in sys.stdin.readlines()]

#
# solve !!
#
solve(lines)

Measured memory_bytes: 3060
import java.util.*

fun main(args:Array<String>){
    val (n,k,s) = readLine()!!.split(" ").map{it.toInt()}
    val st = StringBuilder()
    for(i in 0 until n){
        if(i < k){
            st.append(s)
            st.append(' ')
        }
        else{
            st.append(if(s == 1000000000) s - 1 else s + 1)
            st.append(' ')
        }
    }
    println(st.toString())
}


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

using S = pair<int64_t, int64_t>;
using F = pair<int64_t, int64_t>;

constexpr int64_t mod = 998244353;

S op(S a, S b) {
    return {(a.first + b.first) % mod, a.second + b.second};
}

S e() {
    return {0, 0};
}

S f(F p, S x) {
    return {(p.first * x.first + p.second * x.second) % mod, x.second};
}

F comp(F g, F h) {
    return {g.first * h.first % mod, (g.first * h.second + g.second) % mod};
}

F id() {
    return {1, 0};
}

int main() {
    int n, q;
    cin >> n >> q;
    vector<int64_t> a(n);
    vector<S> x(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        x[i] = {a[i], 1};
    }

    lazy_segtree<S, op, e, F, f, comp, id> seg(x);
    for (int i = 0; i < q; i++) {
        int t;
        cin >> t;
        if (t == 0) {
            int l, r, b, c;
            cin >> l >> r >> b >> c;
            seg.apply(l, r, {b, c});
        } else {
            int l, r;
            cin >> l >> r;
            cout << seg.prod(l, r).first << endl;
        }
    }
}


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

int main() {
  int h,w;
  cin >> h>> w;
  string a;
  for (int i = 0; i < w+2; i++) { cout << '#';}
  cout<< endl;
  
  for (int i = 0; i < h; i++) {
    cin>>a;
    cout << '#'<<a<<'#' << endl;
  }
  
  for (int i = 0; i < w+2; i++) { cout << '#';}
  cout<< endl;
}

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

using namespace std;

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

	int n, m;
	cin >> n >> m;

	vector<int> d(n);
	vector<vector<int> > G(n);
	for(int i = 0; i < m; ++i) {
		int x, y;
		cin >> x >> y;
		--x; --y;
		G[x].emplace_back(y);
		G[y].emplace_back(x);
		d[x] += 1;
		d[y] += 1;
	}

	int big = 0;
	int four = 0;
	int two = 0;
	bool odd = false;
	for(int i = 0; i < n; ++i) {
		if(d[i] == 2) {
			two += 1;
		}
		if(d[i] == 4) {
			four += 1;
		}
		if(d[i] % 2 == 1) {
			odd = true;
		}
		if(d[i] > 4) {
			big += 1;
		}
	}

	if(odd) {
		cout << "No" << '\n';
		exit(0);
	}

	vector<bool> vis(n);
	function<void(int)> dfs = [&] (int u) {
		vis[u] = true;
		for(int v : G[u]) {
			if(!vis[v]) {
				dfs(v);
			}
		}
	}; 

	if(big == 0) {
		if(four > 2) {
			cout << "Yes" << '\n';
		} else if(four < 2) {
			cout << "No" << '\n';
		} else {
			vector<int> node;
			for(int i = 0; i < n; ++i) {
				if(d[i] == 4) {
					node.emplace_back(i);
				}
			}
			vis[node[0]] = true;
			dfs(node[1]);
			int cnt = 0;
			for(int i = 0; i < n; ++i) {
				if(vis[i]) {
					cnt += 1;
				}
			}
			if(cnt == n) {
				cout << "No" << '\n';
			} else {
				cout << "Yes" << '\n';
			}
		}
	} else {
		cout << "Yes" << '\n';
	}

	return 0;
}

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

S = int(input())

if S == 1 or S == 2 or S == 4:
    print(4)
    exit()

e = S
cnt = 0
while True:
    if e % 2 == 0:
        v = e//2
    else:
        v = 3*e+1
    e = v
    cnt += 1
    if v == 4:
        print(cnt+4)
        exit()



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

#[fastout]
fn main() {
    input! {n: usize, b: [u64; n]};
    let mut b: Vec<u64> = b;

    if init_b_len(&b) == uniqe_b_len(&mut b) {
        println!("YES")
    } else {
        println!("NO")
    }
}

fn init_b_len(b: &Vec<u64>) -> usize {
    b.len()
}

fn uniqe_b_len(b: &mut Vec<u64>) -> usize {
    b.sort();
    b.dedup();
    b.len()
}


Measured memory_bytes: 6272
#include <iostream>
#include <algorithm>

using namespace std;

int main() {
    int a, b, c, k;
    cin >> a >> b >> c >> k;

    int aa, bb, cc;
    aa = min(a, k);
    bb = min(b, k-a);
    if (k-a < 0) bb = 0;
    cc = min(c, k - a - b);
    if (k - a - b < 0) cc = 0;
    cout << aa - cc << endl;
    return 0;
}

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

typedef vector<vector<ll>> graph;

ll dfs(graph &G, vector<ll>&d, vector<ll>&f, ll node, ll count){

    if(d[node] != -1) return count;

    d[node] = count;
    count ++;

    for(ll tar : G[node]){
        if( d[tar] == -1 ){
            count = dfs(G, d, f, tar, count);
        }
    }

    f[node] = count;
    count ++;

    return count;

}


int main(){

    ll N;
    cin >> N;

    graph G(N);
    for (int i = 0; i < N; i++)
    {
        ll u,k;
        cin >> u >> k;
        for (int j = 0; j < k; j++)
        {
            ll v;
            cin >> v;
            G[u-1].push_back(v-1);
        }
    }

    vector<ll> d(N,-1),f(N,-1);

    ll count = 1;
    for (ll i = 0; i < N; i++)
    {
       count = dfs(G,d,f,i,count);
    }

    for (int i = 0; i < N; i++)
    {
        cout << i+1 << " " << d[i] << " " << f[i] <<endl;
    }
    
}


Measured memory_bytes: 3144
#include "bits/stdc++.h"
#include "math.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef vector<pair<ll,ll> > vp;
typedef vector<vp> vvp;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define drep(i,a,b) for(ll i=(a);i>(b);--i)
const int MOD = 1000000007;
const int MAX = 510000;


int main(){
  string s,ans;ll tmp=0;
  cin>>s;
  rep(i,0,s.size()){
    if(s[i]=='0'){ans[tmp]='0';tmp++;}
    if(s[i]=='1'){ans[tmp]='1';tmp++;}
    if(s[i]=='B'){if(tmp>0)tmp--;}
  }
  rep(i,0,tmp){
    cout<<ans[i];
  }
  cout<<endl;
}




Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

using P = tuple<int, int>;
template <typename F>
void forPerm(vector<P>& p, int offset, F f)
{
    if (offset == p.size()) {
        f();
    } else {
        for (int i = offset; i < p.size(); i++) {
            swap(p[offset], p[i]);
            forPerm(p, offset + 1, f);
            swap(p[offset], p[i]);
        }
    }
}

int main()
{
    int n;
    cin >> n;
    vector<P> p;
    rep(i, n)
    {
        int x, y;
        cin >> x >> y;
        p.push_back(P(x, y));
    }

    double result = 0;
    forPerm(p, 0, [&]() {
        rep(i, p.size() - 1)
        {
            int x0, y0, x1, y1;
            tie(x0, y0) = p[i];
            tie(x1, y1) = p[i + 1];

            result += sqrt((x0 - x1) * (x0 - x1) + (y0 - y1) * (y0 - y1));
        }
    });

    rep(i, n)
    {
        result /= (i + 1);
    }
    cout << fixed << setprecision(7) << result << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
#define FOR(n) for(i=0;i<n;++i)
#define inf 0x3f3f3f3f
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n;
string s;
signed main() {
	cin >> n;
	cin >> s;
	ll w = 0, r = 0, cnt = 0;
	int i, j;
	--n;
	for (i = 0; i <= n; ++i) {
		if (s[i] == 'R')continue;
		for (j = n; j > i; --j) {
			if (s[j] == 'R') {
				break;
			}
		}
		n = j-1;
		if (i <= n)++cnt;
	}
	cout << cnt << endl;
}

Measured memory_bytes: 3752
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>

#define nn 10010
using namespace std;

const int bs[2]={271,233};
const int mod[2]={998244353,1000000007};

char a[nn];
int n,pw[nn][2],N,as,h[nn][2];
struct Node{int h0,h1,p;}q[nn];

bool Cmp(Node a,Node b) {return(a.h0<b.h0||a.h0==b.h0&&a.h1<b.h1||a.h0==b.h0&&a.h1==b.h1&&a.p<b.p);}
inline bool Check(int md){
    N=0;
    for (int i=1;i+md-1<=n;i++){
        int nm[2];
        for (int j=0;j<2;j++) nm[j]=(h[i+md-1][j]-h[i-1][j]+mod[j])%mod[j];
        for (int j=0;j<2;j++) nm[j]=nm[j]*1ll*pw[n-(i+md-1)][j]%mod[j];
        q[++N]=(Node){nm[0],nm[1],i};
    }
    sort(q+1,q+1+N,Cmp);
    for (int j=1,i=1;i<=N;i=j){
        for (j=i;q[i].h0==q[j].h0&&q[i].h1==q[j].h1&&j<=N;j++);
        if (q[i].p+md<=q[j-1].p) return(1);
    }
    return(0);
}

int main()
{
    scanf("%d%s",&n,a+1);
    pw[0][0]=pw[0][1]=1;
    for (int i=1;i<=n;i++)
    for (int j=0;j<2;j++) pw[i][j]=pw[i-1][j]*1ll*bs[j]%mod[j];
    for (int i=1;i<=n;i++)
    for (int j=0;j<2;j++) h[i][j]=(h[i-1][j]+a[i]*1ll*pw[i][j]%mod[j])%mod[j];

    int l=1,r=n;
    while (l<=r){
        int md=(l+r)/2;
        if (Check(md)) as=md,l=md+1;
        else r=md-1;
    }
    printf("%d\n",as);
}

Measured memory_bytes: 384
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

int main(){
    int H;
    int W;

    while(true){
cin>>H;
cin>>W;
if(H==0 && W==0) break;
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            cout<<"#";
        }
        cout<<"\n";
    }
    cout<<"\n";
    }
}


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

int m(int b,int c,int B,int C){
  if(b>=B)
    B=b-B;
  if(b<B)
    B=B-b;
  if(c>=C)
    C=c-C;
  if(c<C)
    C=C-c;
  return B+C;
}

bool che(int min,int after){
  if(min>after)
    return false;
  if((after-min)%2==1)
    return false;
  return true;
}

int main(){
  int N;
  cin>>N;
  int a=-1,b,c,A=0,B=0,C=0;
  bool result=true;
  for(int i=0;i<N;i++){
    cin>>a>>b>>c;
    if(a==A)
      break;
    int min=m(b,c,B,C);
    int after=a-A;
    bool check=che(min,after);
    if(check==false){
      result=false;
      break;
    }
    A=a;
    B=b;
    C=c;
    N+=a;
  }
  if(result==true)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long a[200005],b[200005],c[200005],d[200005];
int main()
{
	long long t=0,i,k=0,j=0,h,n,m;
	cin>>n>>m;
	while(m--)
	{	
		cin>>a[t]>>b[t];
		if(a[t]==1&&b[t]!=1)
		c[b[t]]=1;
		if(b[t]==1&&a[t]!=1)
		c[a[t]]=1;
		if(a[t]==n&&b[t]!=n)
		d[b[t]]=1;
		if(b[t]==n&&a[t]!=n)
		d[a[t]]=1;
		t++;
	}
	bool x=true;
	for(i=0;i<n;i++)
	{
		if(c[i]==1&&d[i]==1)
		{
			printf("POSSIBLE\n");
			x=false;
			break;
		}
	}
	if(x)		
	printf("IMPOSSIBLE\n");
}

Measured memory_bytes: 6528
import java.util.*;
public class Main {
	
	public static void main(String[] args) {
		int INF = 1000000000;
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int[][] dp = new int[1 << N][M+1];
		for(int j = 1; j < 1 << N; j++)
			Arrays.fill(dp[j], INF);
		for(int i = 1; i <= M; i++) {
			int a = sc.nextInt();
			int b = sc.nextInt();
			int x = 0;
			for(int j = 0; j < b; j++)
				x |= 1<<(sc.nextInt()-1);
			for(int j = 0; j < 1 << N; j++) {
				dp[j][i] = Math.min(dp[j][i-1], dp[j][i]);
				dp[j|x][i] = Math.min(dp[j][i-1]+a, dp[j|x][i]);
			}
		}
		System.out.println(dp[(1 << N) - 1][M] == INF ? -1 : dp[(1 << N) - 1][M]);

	}

}

Measured memory_bytes: 54992
#include<bits/stdc++.h>
#define REP(i,u) for(int i=hd[u],v;v=to[i],i;i=nxt[i])
using namespace std;
typedef long long ll;
const int N=int(1e5)+10;

int n,m,len,px,py,tot; int dep[N],sm[N],K[N],q[N]; ll res;
int hd[N],to[N*2],nxt[N*2],ct;
void addE(int u,int v){ to[++ct]=v,nxt[ct]=hd[u],hd[u]=ct; }
void dae(int u,int v){ addE(u,v),addE(v,u); }

void dfs1(int p,int fa=0,int c=1,int d=1){
	dep[p]=d,sm[p]=c;
	REP(i,p) if(v!=fa){
		if(!dep[v]) dfs1(v,p,-c,d+1);
		else px=p,py=v,len=dep[p]-dep[v]+1;
	}
}

bool prework(){
	for(int i=1;i<=n;i++) tot+=sm[i];
	if(!(len&1) && tot) return 0;
	if(len&1 && abs(tot)&1) return 0;
	return 1;
}

void dfs2(int p,int fa=0){
	if(!fa) memset(dep,0,sizeof(dep));
    dep[p]=1;
    REP(i,p) if(!dep[v])
		dfs2(v,p),sm[p]+=sm[v],K[p]+=K[v];
}

int main(){
//	freopen("father.in","r",stdin);
//	freopen("father.out","w",stdout);
	
	scanf("%d%d",&n,&m);
	for(int i=1,u,v;i<=m;i++)
		scanf("%d%d",&u,&v),dae(u,v);
	dfs1(1);
	
	if(!prework()) return cout<<-1,0;
	if(len&1) sm[px]-=(tot/=2),sm[py]-=tot,res+=abs(tot);
	else K[px]++,K[py]--;
	
	dfs2(1); int len=1;
	for(int i=1;i<=n;i++)
		if(!K[i]) res+=abs(sm[i]);
		else q[++len]=K[i]*sm[i];
	
	sort(q+1,q+len+1);
	int mid=q[(len+1)/2];
	for(int i=1;i<=len;i++)
		res+=abs(q[i]-mid);
	
	return cout<<res,0;
} 

Measured memory_bytes: 14984
export class Main {
  static main(input: string): string {
    const tmp: string[] = input.split("\n");
    const [n]: number[] = tmp.shift().split(" ").map(int => parseInt(int));
    for (let i = 1; i <= 9; i++) {
      if (n % i == 0) {
        let t = n / i;
        if (1 <= t && t <= 9) {
          return "Yes";
        }
      }
    }
    return `No`;
  }
}
console.log(Main.main(require("fs").readFileSync("/dev/stdin", "utf8")));


Measured memory_bytes: 7372
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<string>
#include<stdio.h>
#include<stdlib.h>
#include<float.h>
#include<tuple>
#include<string.h>
#include<iomanip>
#include<stack>
#include<queue>
#include<map>

using namespace std;
#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define ALLOF(c) (c).begin(), (c).end()
#define Pa pair<ll,ll>
const ll mod=1000000007;
const ll INF=10e12;
const ll inf=-1;
ll ABS(ll a){return max(a,-a);}


int main(void){
    ll a,b,c;
    cin>>a>>b>>c;
    if(c<=a+b) cout<<"No"<<endl;
    else if(4*a*b<(c-a-b)*(c-a-b)) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
h,w=map(int,input().split())
a=[list(input()) for i in range(h)]
a2=[k for k in a if k!=["." for j in range(w)]]
h=len(a2)
count=[True for j in range(w)]
for j in range(w):
    res=True
    for i in range(h):
        if a2[i][j]=="#":
            res=False
            break
    if res:
        count[j]=False
a3=[[a2[i][j] for j in range(w) if count[j]] for i in range(h)]
for i in range(h):
    print("".join(a3[i]))


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

const int MAX_N = 200000;

int main() {
	int N;
	std::string S;

	std::cin >> N >> S;

	static int black[MAX_N] = {};
	if(S[0] == '#') black[0] = 1;
	for(int i = 1; i < N; ++i) {
		black[i] = black[i - 1];
		if(S[i] == '#') ++black[i];
	}

	int ans = std::min(black[N - 1], N - black[N - 1]);
	for(int i = 1; i < N; ++i) {
		ans = std::min(ans, black[i - 1] + (N - i) - (black[N - 1] - black[i - 1]));
	}

	std::cout << ans << std::endl;
}


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

typedef long long ll;
#define MOD1 1000000007
#define MOD2 1000000009
#define FOR(a,b) for(ll i=a;i<b;i++)
#define endl "\n"

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

  ll n, m, o;
  cin >> n >> m >> o;
  ll ans = (ceil((float)n / m)) * o;
  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 3628
import java.io.*;
import java.util.*;

public class Main {
    static BufferedReader in;

    public static void solve() throws IOException {
        Integer[] nw = nextArray(2);
        int n = nw[0];
        int w = nw[1];

        Integer[] weights = new Integer[n];
        Integer[] values = new Integer[n];

        Long[][] dp = new Long[n][w+1];

        for(int index = 0;index<n;index++){
            nw = nextArray(2);
            weights[index] = nw[0];
            values[index] = nw[1];
        }

        for (int i = 0;i<=w;i++){
            dp[0][i] = i >= weights[0]?values[0]:0L;
        }

//        System.out.println(Arrays.toString(dp[0]));

        for(int i = 1;i<n;i++){
            for(int j = 0;j<=w;j++){
                dp[i][j] = dp[i-1][j];
                if( j >= weights[i]){
                    dp[i][j] = Math.max(dp[i][j], values[i] + dp[i-1][j - weights[i]]);
                }
            }
        }

//        for(Long[] arr : dp){
//            System.out.println(Arrays.toString(arr));
//        }

        System.out.println(dp[n-1][w]);




    }




    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        solve();
    }

    static int nextInt() throws IOException {
        return Integer.parseInt(in.readLine().trim());
    }

    static long nextLong() throws IOException {
        return Long.parseLong(in.readLine().trim());
    }

    static Integer[] nextArray(int n) throws IOException {
        StringTokenizer st = new StringTokenizer(in.readLine());
        Integer[] tmp = new Integer[n];
        for (int i = 0; i < tmp.length; i++) {
            tmp[i] = Integer.parseInt(st.nextToken());
        }

        return tmp;
    }

}



Measured memory_bytes: 384596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const int inf = 1e9;
const ll INF = 1e18;
const double pi = 3.14159265358979323846;
#define rep(i,n) for(int i=0;i<n;i++)

int main(){
	int a,b,c;cin>>a>>b>>c;
	ll ans=0;
	int chk=1;
	while(chk){
		//cout<<a<<" "<<b<<" "<<c<<"\n";
		if(a%2==0&&b%2==0&&c%2==0) {
			chk=1;
			if(a==b&&b==c){
				chk=2;
				break;
			}
		}
		else{
			chk=0;
			break;
		}
		int x=a/2,y=b/2,z=c/2;
		a=y+z;
		b=z+x;
		c=x+y;
		ans++;
	}
	if(!chk) cout<<ans<<endl;
	else cout<<-1<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n;
int a[200];
int main()
{
	//freopen("H:\\c++1\\in.txt","r",stdin);
	//freopen("H:\\c++1\\out.txt","w",stdout);
	scanf("%d",&n);
	int ans1=0,ans2=0,sum=0;
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		sum+=a[i];
	}
	int t1=sum/n,t2=(sum+n-1)/n;
	for(int i=1;i<=n;i++){
		ans1+=(t1-a[i])*(t1-a[i]);
		ans2+=(t2-a[i])*(t2-a[i]);
	}
	printf("%d\n",min(ans1,ans2));
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
	int N,K;
	cin>>N>>K;
	int x=0;
	int y=0;
	for (int i=1;i<=N;i++){
		if (i%2==1){
			x++;
		}else{
			y++;
		}
	}
	if (x>=K || y>=K){
		cout<<"YES"<<endl;
		return 0;
	}

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

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

int main(){

  int m,f,r;

  while(1){
    cin >> m >>f >> r;

    if(m==-1 && f==-1 && r== -1)break;

    if(m==-1 || f ==-1){
      cout << "F" << endl;
	}
    else if (m+f>=80){
      cout << "A" << endl;
    }else if (m+f>=65){
      cout << "B" << endl;
    }else if (m+f >=50){
      cout << "C" << endl;
    }else if(r >= 50 && m+f>=30){
      cout << "C" << endl;
    }else if (m + f >= 30){
      cout << "D" << endl;

    }else{
      cout << "F" << endl;
    }
  }
}


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

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

void solve() {
  if (e - a > k) {
    cout << ":(\n";
    return;
  } else {
    cout << "Yay!\n";
    return;
  }
}

int main() {
  cin >> a >> b >> c >> d >> e >> k;
  solve();
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                                     \
  ifstream in("atcoder-problems/ddcc2020_qual_b.txt"); \
  cin.rdbuf(in.rdbuf());
#define print_vec(v)                        \
  rep(l, v.size()) { cout << v[l] << " "; } \
  cout << endl;
#else
#define INPUT_FILE
#define print_vec(v)
#endif
#define CIN_OPTIMIZE \
  cin.tie(0);        \
  ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
typedef pair<ll, ll> pl;
const int INF = 100100100;
const ll LINF = 1e18 + 100;
const int MOD = 1e9 + 7;

int main() {
  INPUT_FILE CIN_OPTIMIZE;

  int N;
  cin >> N;

  vector<ll> c(N);
  ll total = 0;
  rep(i, N) {
    cin >> c[i];
    total += c[i];
  }

  ll left = 0;
  ll right = total;
  ll ans = right - left;
  rep(i, N) {
    left += c[i];
    right -= c[i];
    ans = min(ans, abs(left - right));
  }
  cout << ans << endl;
}

Measured memory_bytes: 4752
def main():
    N = int(input())
    A = [int(a) for a in input().split()]
    mon1 = [a for a in A]
    mon2 = [a for a in A]

    for i in range(10**9):
        mon1 = sorted(mon2)
        mon2 = list()

        for j in range(1, len(mon1)):
            m_ = mon1[j] % mon1[0]
            if m_ != 0:
                mon2.append(m_)

        mon2.append(mon1[0])

        if len(mon2) == 1:
            break

    print(mon2[0])
    
if __name__ == "__main__":
    main()

Measured memory_bytes: 20136