akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1001001001001001001;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    ll n, k;
    cin >> n >> k;
    vector<vector<P>> td(n);
    for(ll i = 0; i < n; ++i){
        int t, d;
        cin >> t >> d;
        --t;
        td[t].push_back(P(d, 0));
    }
    for(int i = 0; i < n; ++i){
        sort(td[i].begin(), td[i].end(), greater<P>());
        if(td[i].size() > 0){
            td[i][0].second = 1;
        }
    }
    
    // (d, 初出かどうか)
    priority_queue<P> que1;
    for(int i = 0; i < n; ++i){
        for(int j = 0; j < td[i].size(); ++j){
            que1.push(td[i][j]);
        }
    }
    
    ll res = 0;
    ll cnt = 0;         // ネタの種類数
    // (初出のネタかどうか, d)
    priority_queue<P, vector<P>, greater<P>> que2;
    while(que2.size() < k){
        P p = que1.top();
        que1.pop();
        if(p.second == 1)   ++cnt;
        res += p.first;
        que2.push(P(p.second, p.first));
    }
    
    vector<ll> ans(n+2, -INF);
    ans[cnt] = res + cnt * cnt;
    
    for(ll i = cnt + 1; i <= n; ++i){
        if(que1.empty())    break;
        P p1 = que1.top();
        que1.pop();
        
        P p2 = que2.top();
        if(p2.first == 1)   break;
        que2.pop();
        res -= p2.second;
        
        while(!que1.empty() && p1.second == 0){
            p1 = que1.top();
            que1.pop();
        }
        
        if(p1.second == 0)  break;
        res += p1.first;
        que2.push(P(p1.second, p1.first));
        
        ans[i] = res + i * i;
    }
    
    cout << *max_element(ans.begin() + cnt, ans.end()) << "\n";
}

Measured memory_bytes: 9972
import sys

# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
import heapq
import decimal
# import statistics
import queue

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    def combinations_count(n, r):
        if n > 1:
            return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
        else:
            return 0

    n = ni()
    a = na()

    a.insert(0, 0)

    perm = [0 for _ in range(n + 1)]

    for i in range(1, n + 1):
        perm[i] = perm[i - 1] + a[i]

    c = collections.Counter(perm)

    ans = 0
    for v in c.values():
        ans += combinations_count(v, 2)

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 43296
# -*- coding: utf-8 -*-

from sys import stdin
    
def main():
    n,k = [int(x) for x in stdin.readline().rstrip().split()]
    s = stdin.readline().rstrip()

    ans = s[0:max(0,k-1)] + s[k-1].lower() + s[k:n]
    print(ans)
    
if __name__=='__main__':
    main()

Measured memory_bytes: 3060
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string>
#include<math.h>
#include<vector>
#include<iomanip>
using namespace std;

int main(void)
{
	int a, b;
	cin >> a >> b;
	if (a <= 5) { cout << 0 << endl; }
	else if (6 <= a && a <= 12) { cout << b / 2 << endl; }
	else { cout << b << endl; }
	return 0;
}

Measured memory_bytes: 256
from collections import Counter
n, k = map(int, input().split())
a = [x - 1 for x in map(int, input().split())]

sa = [0 for _ in range(n+1)]
for i in range(n):
    sa[i+1] = (sa[i] + a[i]) % k
#print(sa)

if n < k:
    cnt = Counter(sa)
    ans = 0
    for x in cnt.values():
        ans += x * (x - 1) // 2
    print(ans)

else:
    cnt = Counter(sa[:k-1])
    ans = 0
    for i in range(n):
        cnt[sa[i]] -= 1
        if i + k - 1 <= n:
            cnt[sa[i+k-1]] += 1
        ans += cnt[sa[i]]
    print(ans)

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

#define int long long
int a[51];
int sum;
int n;
signed main(){
	cin >> n;
	for(int i = 1 ; i <= n ; i ++){
		cin >> a[i];
		for(int j = 1 ; j < i ; j ++)
			sum += a[i]*a[j];
	}
	cout << sum;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long i64;
using std::cout;
using std::endl;
using std::cin;

int main() {
	int n, m; cin >> n >> m;
	std::vector<std::vector<std::pair<int, int>>> g(n);
	std::vector<int> h(n);
	for(int i = 0; i < m; i++) {
		int a, b, c; cin >> a >> b >> c;
		
		g[a - 1].push_back({b - 1, c});
		h[b - 1]++;
	}
	
	std::queue<int> qu;
	std::vector<int> vec;
	for(int i = 0; i < n; i++) if(!h[i]) qu.push(i);
	while(!qu.empty()) {
		auto p = qu.front(); qu.pop();
		vec.push_back(p);
		
		for(auto e : g[p]) {
			if(!--h[e.first]) qu.push(e.first);
		}
	}
	for(auto v : h) {
		if(v) {
			cout << "No" << endl;
			return 0;
		}
	}
	
	std::map<int, int> mp;
	mp[vec[0]] = 1;
	for(auto v : vec) {
		for(auto e : g[v]) {
			if(mp[e.first] and mp[v] + e.second != mp[e.first]) {
				cout << "No" << endl;
				return 0;
			}
			mp[e.first] = mp[v] + e.second;
		}
	}
	
	cout << "Yes" << endl;
	return 0;
}


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

int main() {
  int n;
  cin >> n;
  
  vector<int> R(n);
  for (int i = 0; i < n; i++) {
    cin >> R.at(i);
  }
  
  int maxv = -2000000000;
  int minv = R.at(0);
  
  for (int i = 1; i < n; i++) {
    maxv = max(maxv, R.at(i) - minv);
    minv = min(minv, R.at(i));
  }
  cout << maxv << endl;
}



Measured memory_bytes: 3624
from math import fabs

n = int(input())
T, A = map(int, input().split())
H = list(map(int, input().split()))
index, ave = 0, fabs(T - 0.006 * H[0] - A)
for i in range(1, n):
    tmp = fabs(T - 0.006 * H[i] - A)
    if tmp < ave:
        index, ave = i, tmp
print(index + 1)

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

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define rrep(i,n) RFOR(i,n,0)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

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

	ll n;
	cin >> n;

	if(n == 2){
		cout << "No" << endl;
		return 0;
	}

	ll a = 1;
	for(; a <= n; a++){
		if(a * (a-1) / 2 > n){
			cout << "No" << endl;
			return 0;
		}
		if(a * (a-1) / 2 == n) break;
	}

	ll g[a+1][a];
	rep(i, a+1) rep(j, a) g[i][j] = 0;

	ll ind[a+1];
	rep(i, a+1) ind[i] = 0;

	ll l = 1;
	for(ll i = 1; i < a; i++){
		for(ll j = i+1; j <= a; j++){
			g[i][ind[i]] = l;
			g[j][ind[j]] = l;
			ind[i]++;
			ind[j]++;
			l++;
		}
	}

	cout << "Yes" << endl;
	cout << a << endl;
	rep(i, a){
		cout << a-1;
		rep(j, a-1){
			cout << " " << g[i+1][j];
		}
		cout << endl;
	}
}


Measured memory_bytes: 2944
#include <iostream>

using namespace std;

#define Nfori(N) for(int i=0;i<(N);i++)
#define Nforj(N) for(int j=0;j<(N);j++)

int main(){
  	int N;
  	long long Y;
  	cin >> N >> Y;
  	Nfori(N+1){
      	Nforj(N+1-i){
          	if(i*10000+j*5000+(N-i-j)*1000 == Y){
              	cout << i << " " << j << " " << N-i-j << endl;
              	return 0;
            }
        }
    }
  	cout << "-1 -1 -1" << endl;
}

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

int main(){
    long long n;
    cin >> n;
    long long cnt = 0,count = 0;
    long long a;
    bool ans = false;
    long long i = 0;
    while (count < n){
        cin >> a;
        if (a == i + 1){
            i++;
            ans = true;
        }
        else {
            cnt++;
        }
        count++;
    }


    if (ans) cout << cnt << endl;
    else cout << -1 << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int mod=1e9+7;
const int N=200;
ll dp[N][10];
ll num[10][10];
int h,w,K;
void init(){
    scanf("%d%d%d",&h,&w,&K);dp[0][0]=1;
    for(int s=0;s<(1<<(w-1));s++){
        int flag=0;
        for(int i=0;i<w-1;i++){
            int t1=(s>>i)&1,t2=(s>>(i+1))&1;
            if(t1==t2&&t1)flag=1;
        }
        if(flag)continue;
        for(int i=0;i<=w-1;){
            if((s>>i)&1){
                num[i][i+1]++,num[i+1][i]++;i+=2;
            }
            else num[i][i]++,i++;
        }
    }
}
int main()
{
    init();
    for(int i=0;i<h;i++)
    for(int j=0;j<w;j++)
    for(int k=0;k<w;k++)dp[i+1][k]=(dp[i+1][k]+(dp[i][j]*num[j][k])%mod)%mod;
    printf("%lld\n",dp[h][K-1]);
}


Measured memory_bytes: 256
N = int(input())
blank = 2
h = list(map(int,input().split())) + [0] * blank

INF = 10 ** 9 + 1
dp = [INF] * (N + blank)
dp[0] = 0
for i in range(N):
  dp[i + 1] = min(dp[i] + abs(h[i + 1] - h[i]), dp[i + 1])
  dp[i + 2] = min(dp[i] + abs(h[i + 2] - h[i]), dp[i + 2])
  
print(dp[N - 1])


Measured memory_bytes: 20444
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 200005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;T f = 1;char c = getchar();
    while(c < '0' || c > '9') {
	if(c == '-') f = -1;
	c = getchar();
    }
    while(c >= '0' && c <= '9') {
	res = res * 10 +c - '0';
	c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
	out(x / 10);
    }
    putchar('0' + x % 10);
}
struct node {
    int to,next;
}E[MAXN * 2];
int N,head[MAXN],sumE,dep[MAXN],fr[MAXN],high[MAXN],low[MAXN];
char s[MAXN];
vector<int> rec[MAXN];
vector<pii > to[MAXN];
void add(int u,int v) {
    E[++sumE].to = v;
    E[sumE].next = head[u];
    head[u] = sumE;
}
void dfs1(int u,int fa) {
    for(int i = head[u] ; i ; i = E[i].next) {
	int v = E[i].to;
	if(v != fa) {
	    dfs1(v,u);
	    dep[u] = max(dep[u],dep[v] + 1);
	}
    }
}
void dfs2(int u,int fa) {
    vector<pii > vec;
    dep[u] = max(dep[u],fr[u] + 1);
    vec.pb(mp(1,u));
    if(fa) vec.pb(mp(fr[u] + 2,fa));
    pii p = mp(0,0);
    for(int i = head[u] ; i ; i = E[i].next) {
	int v = E[i].to;
	if(v != fa) {
	    vec.pb(mp(dep[v] + 2,v));
	    if(dep[v] > dep[p.se]) p.se = v;
	    if(dep[p.se] > dep[p.fi]) swap(p.fi,p.se);
	}
    }
    sort(vec.begin(),vec.end());
    high[u] = dep[u] - 1;
    int s = vec.size() - 1;
    high[u] = min(high[u],vec[s - 1].fi);
    if(high[u] < dep[u] - 1){
	to[u].pb(mp(vec[s].se,high[u]));
    }
    vec.clear();
    for(int i = head[u] ; i ; i = E[i].next) {
	int v = E[i].to;
	if(v != fa) {
	    fr[v] = max(fr[v],fr[u] + 1);
	    if(v != p.fi) fr[v] = max(fr[v],dep[p.fi] + 1);
	    if(v != p.se) fr[v] = max(fr[v],dep[p.se] + 1);
	}
    }
    for(int i = head[u] ; i ; i = E[i].next) {
	int v = E[i].to;
	if(v != fa) {
	    dfs2(v,u);
	}
    }
}
void Solve() {
    read(N);
    int a,b;
    for(int i = 1 ; i < N ; ++i) {
	read(a);read(b);add(a,b);add(b,a);
    }
    scanf("%s",s + 1);
    dep[0] = -1;fr[1] = -1;
    dfs1(1,0);dfs2(1,0);
    for(int i = 1 ; i <= N ; ++i) {
	rec[high[i]].pb(i);
	low[i] = high[i] + 1;
    }
    for(int i = 0 ; i <= N ; ++i) {
	for(auto v : rec[i]) {
	    if(s[v] == '1') {
		low[v] = 0;
	    }
	    if(low[v] <= high[v]){
		for(auto k : to[v]) {
		    low[k.fi] = min(low[k.fi],k.se);
		}
	    }
	}
    }
    int64 ans = 1;
    for(int i = 1 ; i <= N ; ++i) {
	ans += high[i] - low[i] + 1;
    }
    out(ans);enter;
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
    return 0;
}


Measured memory_bytes: 48768
//satyaki3794
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define MOD (998244353LL)
#define LEFT(n) (2*(n))
#define RIGHT(n) (2*(n)+1)
 
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<int, ii> iii;
 
ll pwr(ll base, ll p, ll mod=MOD){
ll ans = 1;while(p){if(p&1)ans=(ans*base)%mod;base=(base*base)%mod;p/=2;}return ans;
}


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


ii arr[202];

ii get_slope(int i, int j){
	int a = arr[j].ff - arr[i].ff;
	int b = arr[j].ss - arr[i].ss;
	if(a == 0)	return ii(0, 1);
	if(b == 0)	return ii(1, 0);
	int g = gcd(a, b);
	a /= g;	b /= g;
	if(a < 0){
		a *= -1;	b *= -1;
	}
	return ii(a, b);
}


int main(){

    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    	cin>>arr[i].ff>>arr[i].ss;

    ll ans = pwr(2, n) - 1 - n - n*(n-1)/2;
    for(int i=1;i<=n;i++)
    	for(int j=i+1;j<=n;j++){
    		int cnt = 0;
    		for(int k=j+1;k<=n;k++)
    			cnt += get_slope(i, k) == get_slope(i, j);
    		ans -= pwr(2, cnt) - 1;
    		ans %= MOD;
// cout<<i<<" "<<j<<", cnt = "<<cnt<<endl;
    	}

    ans %= MOD;
    ans += MOD;
    ans %= MOD;
    cout<<ans;
    return 0;
}







 




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define debug(x) cerr << # x << "; "<< x << endl


int main() {
	long long H, N, A;
	cin >> H >> N;
	int total = 0;
	for (int i = 0; i < N; i++) {
		cin >> A;
		total += A;
	}
	if (H > total) {
		cout << "No" << endl;
	}
	else {
		cout << "Yes" << endl;
	}
}

Measured memory_bytes: 3640
#include <iostream>

using namespace std;

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

    if(a == 0 && b == 0){
        cout << a << " " << b << endl;
        return 0;
    }

    if(a <= k){
        k -= a;
        a = 0;
        if(b-k <= 0){
            b = 0;
        }else{
            b -= k;
        }
    }else{
        a -= k;
    }

    cout << a << " " << b << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1505,p=1000000007;
int read(){
	int f=1,g=0;char ch=getchar();
	for (;!isdigit(ch);ch=getchar()) if (ch=='-') f=-1;
	for (;isdigit(ch);ch=getchar()) g=g*10+ch-'0';
	return f*g;
}
int n;
typedef unsigned short us;
us a[N][N],s[N][N],l[N][N],r[N][N];
ll ans;
char ch[N];
void del(int x,int y){
	for (int i=y;i<=n;i++) s[x][i]-=a[x][y];
	a[x][y]=0;
	if ((a[x][y+1])&&(!a[x-1][y+1])) del(x,y+1);
	if ((a[x+1][y])&&(!a[x+1][y-1])) del(x+1,y);
}
inline void chkmin(us &x,us y){if (x>y) x=y;}
inline void chkmax(us &x,us y){if (x<y) x=y;}
int main(){
	n=read();
	for (int i=1;i<=n;i++){
		scanf(" %s",ch+1);
		for (int j=1;j<=n;j++)
		a[i][j]=(ch[j]=='#') ? 0 : (ch[j]-'0'),s[i][j]=s[i][j-1]+a[i][j];
	}
	memset(l,0x3f,sizeof(l));
	for (int i=n;i;i--)
	for (int j=n;j;j--)
	if (a[i][j]){
		int t=-a[i][j];
		l[j][i]=r[j][i]=j;
		if (a[i][j+1]) for (int x=i;x<=n;x++){
			chkmin(l[j][x],l[j+1][x]);chkmax(r[j][x],r[j+1][x]);
			if (l[j][x]<=r[j][x]) t+=s[x][r[j][x]]-s[x][l[j][x]-1];else break;
		}
		else for (int x=i;(x<=n)&&(l[j][x]<=r[j][x]);x++)
			t+=s[x][r[j][x]]-s[x][l[j][x]-1];
		ans+=a[i][j]*t;
		if (a[i-1][j]+a[i][j-1]==0) del(i,j);
	}
	else{memset(l[j]+i,0x3f,(n-i+1)*2);memset(r[j]+i,0,(n-i+1)*2);}
	printf("%lld\n",ans);
	return 0;
}

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

bool done[500];
bool graph[500][500];
set<int> ret;

void dfs(int a,int depth){
	if(depth >2)return;
	ret.insert(a);
	for(int i=0;i<500;i++){
		if(graph[a][i] && !done[i]){
			dfs(i,depth+1);
		}
	}
}
int main(){
	int n,m,a,b;
	while(cin >> n >> m && n || m){
		for(int i=0;i<500;i++){
			for(int j=0;j<500;j++)graph[i][j] = false;
			done[i] = false;
		}
		
		for(int i=0;i<m;i++){
			cin >> a >> b;
			a--;b--;
			graph[a][b] = graph[b][a] = true;
		}
		ret.clear();
		dfs(0,0);
		cout << ret.size()-1 << endl;
	}
}

Measured memory_bytes: 0
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] cards = new int[100];
        int alice = 0;
        int bob = 0;
        for (int i = 0; i < n; i++) {
            cards[i] = sc.nextInt();
        }
        Arrays.sort(cards);
        for (int i = 0; i < cards.length; i++) {
            if(i % 2 == 0) {
                bob += cards[i];
            } else {
                alice += cards[i];
            }
        }
        System.out.println(alice - bob);
    }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i) = 0; (i) < (n); ++(i))
#define rrep(i,n) for(int (i) = (n) - 1; (i) >= 0; --(i)) //Reversi rep
#define nfor(i,a,b) for(int (i) = (a); (i) < (b); ++(i)) //Natural for
#define rfor(i,a,b) for(int (i) = (b) - 1; (i) >= (a); --(i)) //Reversi for
#define ll long long
#define mod (1000000007)
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define yes cout << "yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;
#define no cout << "no" << endl;

int asc(const void *a, const void *b) {
    return *(int *)a - *(int *)b;
}

int desc(const void *a, const void *b) {
    return *(int *)b - *(int *)a;
}

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


Measured memory_bytes: 1024
#include <iostream>

using namespace std;

class MaximumProfit
{
 public:
  int solve( int n, int *r );
};

int MaximumProfit::solve( int n, int *r )
{
  int maxp = -2000000000;
  int minr = r[0];
  for(int i=1; i<n; i++)
    {
      if((r[i] - minr) > maxp)
        maxp = r[i] - minr;
      if(r[i] < minr)
        minr = r[i];
    }
  
  return maxp;
}

int main( void )
{

  MaximumProfit *mp = new MaximumProfit();

  
  int n;
  
  cin >> n;

  int *r = new int[n];
  
  for(int i=0; i<n; i++)
    cin >> r[i];

  cout << mp -> solve( n, r ) << endl;

  delete mp;
  delete[] r;

  return 0;
}

Measured memory_bytes: 1800
a,b,c,d = map(int, input().split())

turn_taka = True
while True:
    if turn_taka:
        c -= b
    else:
        a -= d

    if a <= 0:
        print('No')
        break
    if c <= 0:
        print('Yes')
        break

    turn_taka = not turn_taka


Measured memory_bytes: 9096
#include <vector> 
#include <list> 
#include <map> 
#include <set> 
#include <deque> 
#include <queue> 
#include <stack> 
#include <bitset> 
#include <algorithm> 
#include <functional> 
#include <numeric> 
#include <utility> 
#include <sstream> 
#include <iostream> 
#include <iomanip> 
#include <cstdio> 
#include <cmath> 
#include <cstdlib> 
#include <cctype> 
#include <string> 
#include <cstring> 
#include <ctime> 

using namespace std;

#define _int64 long long

char a[700][700];

set<pair<int,int> > st;

int main()
{
  int i,j,k,l,n,b1,ans;
  st.clear();
  scanf("%d",&n);
  for (i=0;i<n;i++)
  {
    scanf("%s",a[i]);
  }
  for (i=0;i<n;i++)
    for (j=0;j<n;j++)
    {
      a[i+n][j]=a[i][j];
      a[i][j+n]=a[i][j];
      a[i+n][j+n]=a[i][j];
    }
  ans=0;
  for (i=0;i<n;i++)
  {
    b1=1;
    for (j=0;j<n;j++)
    {
      for (k=0;k<n;k++)
      {
        //cout<<i<<" "<<j<<" "<<k<<" "<<a[j][k+i]<<" "<<a[k][j+i]<<endl;
        if (a[j][k+i]!=a[k][j+i])
        {
          b1=0;break;
        }
      }
      if (b1==0) break;
    }
    if (b1==1) ans+=n;
  }
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define F(i,s,e) for(int i=s;i<e;++i)

int main()
{
    long long int n,a,b;
    cin >> n >> a >> b;
    long long int ans = n/(a+b)*a;
    if(n%(a+b) >= a ) ans+=a;
    else ans+=n%(a+b);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define MAXN 200005
#define LL long long
#define P int(1e4+7)
using namespace std;
 
int N,N1;
vector<int> adj[MAXN];
int deg[MAXN], c[MAXN];
int dp[MAXN];
bool vis[MAXN];
int ans1, ans2;
 
void dfs(int u){
	//cout<<"dfs: "<<u<<endl;
	
	vis[u] = 1;
	dp[u] = (c[u]==1) - (c[u]==0);
	
	int v, m1 = -1e9;
	for(int k=0;k<adj[u].size();k++){
		v = adj[u][k];
		if(vis[v]) continue;
		
		
		dfs(v);
		ans2 = max(ans2, m1 + dp[u] + 1 + dp[v]);
		m1 = max(m1, 1 + dp[v]);
	}
	
	if(m1 != -1e9) dp[u] += m1;
	
	ans2 = max(ans2, dp[u]);//cout<<"dp[u]: "<<u<<" "<<dp[u]<<" "<<ans2<<endl;
	return;
}
 
string s;
 
void init(){
	cin>>N;
	for(int i=1;i<=N;i++) adj[i].clear();
	
	memset(deg,0,sizeof(deg));
	memset(c,0,sizeof(c));
	memset(vis,0,sizeof(vis));
	memset(dp,0,sizeof(dp));
	ans1 = ans2 = 0;
	
	int u,v;
	for(int i=1;i<N;i++){
		cin>>u>>v;
		
		adj[u].push_back(v);
		adj[v].push_back(u);
		++deg[u]; ++deg[v];
	}
	
	cin>>s;
	s = "$" + s;
	
	N1 = N;
	queue<int> q;
	for(int i=1;i<=N;i++){
		if(s[i]=='B' && deg[i]==1){
			q.push(i);
		}
	}
	
	//
	while(!q.empty()){
		u = q.front(); q.pop();
		--deg[u]; 
		vis[u] = 1; --N1;
		
		
		for(int k=0;k<adj[u].size();k++){
			v = adj[u][k];
			if(vis[v]) continue;
			--deg[v];
			if(deg[v]==1 && s[v]=='B'){
				q.push(v);
			}
		}
	}
}
 
void work(){
	ans1 = 2*(N1-1);
	for(int i=1;i<=N;i++){
		if(vis[i]) continue;
		
		c[i] = (deg[i] + (s[i]=='B') + 1) % 2;
		ans1 += c[i];
	}
	 
	if(N1==1){
		cout<<ans1<<endl;
		return;
	}
	
	//ans2
	for(int i=1;i<=N;i++){
		if(!vis[i]){
			dfs(i);
			break;
		}
	} 
	//cout<<"ans2: "<<ans2<<endl;
	if(ans2 > 0) ans2 = ans1 - ans2 - 1;
	else ans2 = ans1;
	
	cout<<max(0, min(ans1, ans2))<<endl;
}
 
int main(){
	ios::sync_with_stdio(0);
	//freopen("20.in","r",stdin);
	//freopen("20.out","w",stdout);
	
 
		init();
		work();
 
 
	return 0;
}

Measured memory_bytes: 16364
#include <assert.h>
#include <climits>
#include <iostream>
#include <string>

struct TNode
{
	int Value;
	TNode* Parent;
	TNode* Left;
	TNode* Right;
	
	TNode();
	TNode(int AValue, TNode* AParent);
};

TNode::TNode()
{
	Value  = INT_MAX;
	Parent = NULL;
	Left   = NULL;
	Right  = NULL;
}

TNode::TNode(int AValue, TNode* AParent)
{
	Value = AValue;
	Parent = AParent;
	Left   = NULL;
	Right  = NULL;
}
void Insert(int Key, TNode* Root);
void Delete(TNode* Root)
{
	if(Root == NULL) return;
	Delete(Root->Left);
	Delete(Root->Right);
	delete Root;
}

void AddLeft(int Key, TNode* Root)
{
	assert(Root != NULL);
	if(Root->Left == NULL){
		TNode* Left = new TNode(Key, Root);
		Root->Left = Left;
	}else{
		Insert(Key, Root->Left);
	}
}

void AddRight(int Key, TNode* Root)
{
	assert(Root != NULL);
	if(Root->Right == NULL){
		TNode* Right = new TNode(Key, Root);
		Root->Right = Right;
	}else{
		Insert(Key, Root->Right);
	}
}

void Insert(int Key, TNode* Root)
{
	assert(Root != NULL);
	if(Root->Value == Key) return;
	if(Root->Value == INT_MAX){
		Root->Value = Key;
		return;
	}
	if(Root->Value > Key){
		AddLeft(Key, Root);
	}else{
		AddRight(Key, Root);
	}
}

void OutputPreOrder(const TNode* Root)
{
	if(Root == NULL) return;
	std::cout << " " << Root->Value;
	OutputPreOrder(Root->Left);
	OutputPreOrder(Root->Right);
}

void OutputInorder(const TNode* Root)
{
	if(Root == NULL) return;
	OutputInorder(Root->Left);
	std::cout << " " << Root->Value;
	OutputInorder(Root->Right);
}

void Print(const TNode* Node)
{
	OutputInorder(Node);
	std::cout << std::endl;
	OutputPreOrder(Node);
	std::cout << std::endl;
}

void DoOrder(const std::string& Order, TNode* Root)
{
	if(Order == "insert"){
		int Key = 0;
		std::cin >> Key;
		Insert(Key, Root);
	}else if(Order == "print"){
		Print(Root);
	}
}

int main()
{
	int Count = 0;
	std::cin >> Count;
	TNode* Root = new TNode();
	for(int i = 0; i < Count; ++i){
		std::string Order;
		std::cin >> Order;
		DoOrder(Order, Root);
	}
	Delete(Root);
	return 0;
}

Measured memory_bytes: 26368
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<sstream>
#include<iomanip>
#include<limits>
#include<deque>
#include<map>
#include<list>
#include<set>
#include <unordered_set>
#include<vector>
#include<cmath>
#include<cstdio>
#include<memory>
#include<bitset>
#include<stack>
#include<functional>
#include<queue>
#include<regex>
#include<time.h>
#include<type_traits>

using namespace std;


#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl

#define Tof(x) (x) ? Yes : No
#define TOF(x) (x) ? YES : NO
#define tof(x) (x) ? yes : no

using ll = long long;

constexpr ll MOD = 1000000007;
constexpr ll INF = 1050000000;
constexpr long long LONGINF = 1005000000000000000;



/*for文でx,yを上下左右確認するやつだよ。正直使いづらいよ。

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


for (int i = 0; i < 4; i++) {
	int ny = y + dy[i];
	int nx = x + dx[i];
}

*/


/*繰り返し二乗法だよ。modもとってくれるよ。n^kをmodで割った余りでやってくれるよ。

ll POW_MOD(ll n, ll k, ll mod) {
	ll r = 1;

	for (; k > 0; k >>= 1) {
		if (k & 1) {
			r = (r * n) % mod;
		}
		n = (n * n) % mod;
	}
	return r;
}

*/



/*まだ使えないテクニックのメモだよ。

for (int bit = 0; bit < (1<<n); ++bit)//bit全探索用のfor文だよ

*/

class UnionFind {
private:
	std::vector<int> parent;
	std::vector<int> height;
	std::vector<int> m_size;

public:
	UnionFind(int size_) : parent(size_), height(size_, 0), m_size(size_, 1) {
		for (int i = 0; i < size_; ++i) parent[i] = i;
	}
	void init(int size_) {
		parent.resize(size_);
		height.resize(size_, 0);
		m_size.resize(size_, 1);
		for (int i = 0; i < size_; ++i) parent[i] = i;
	}
	int find(int x) {
		if (parent[x] == x) return x;
		return parent[x] = find(parent[x]);
	}
	void unite(int x, int y) {
		x = find(x);
		y = find(y);
		if (x == y) return;
		int t = size(x) + size(y);
		m_size[x] = m_size[y] = t;
		if (height[x] < height[y]) parent[x] = y;
		else parent[y] = x;
		if (height[x] == height[y]) ++height[x];
	}
	bool same(int x, int y) {
		return find(x) == find(y);
	}
	int size(int x) {
		if (parent[x] == x) return m_size[x];
		return size(parent[x] = find(parent[x]));
	}
};

int GCD(int a, int b) {
	while (b) {
		int tmp = a % b;
		a = b;
		b = tmp;
	}
	return a;
}

int main() {
	int n; cin >> n;
	int a[100005];
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}

	sort(a, a + n);

	double max = a[n - 1] / 2.0;
	int tmp = INF * 2;
	for (int i = 0; i < n - 1; i++) {
		if (abs(a[i] - max) < abs(tmp - max)) { tmp = a[i]; }
	}

	cout << a[n - 1] << " " << tmp << endl;

	return 0;
}


Measured memory_bytes: 640
n,m=map(int, input().split())
h=list(map(int, input().split()))
dic = {}
ng = set()
chk = set()

for i in range(m):
  a,b=map(int, input().split())
  chk.add(a)
  chk.add(b)
  if h[a-1] == h[b-1]:
    ng.add(a)
    ng.add(b)
    if str(b) in dic:
      dic.pop(str(b))
    if str(a) in dic:
      dic.pop(str(a))
  elif h[a-1] > h[b-1]:
    if not a in ng:
      dic[str(a)] = h[a-1]
    ng.add(b)
    if str(b) in dic:
      dic.pop(str(b))
  else:
    if not b in ng:
      dic[str(b)] = h[b-1]
    ng.add(a)
    if str(a) in dic:
      dic.pop(str(a))
    
print(len(dic) + (n-len(chk)))

Measured memory_bytes: 28800
#include "bits/stdc++.h"
using namespace std;
int main(void)
{
	int N, M, X, Y;
	cin >> N >> M >> X >> Y;
	int minn = 0, maxx = 0;
	for (int i = 0; i < N; i++)
	{
		int a; cin >> a;
		if (i ==0 )
		{
			maxx = a;
		}
		maxx = max(maxx, a);
	}
	for (int i = 0; i < M; i++)
	{
		int a; cin >> a;
		if (i == 0)
		{
			minn = a;
		}
		minn = min(minn, a);
	}
	for (int i = X+1; i <= Y; i++)
	{
		if (i > maxx && i <=minn)
		{
			cout << "No War" << "\n";
			return 0;
		}
	}
	cout << "War" << "\n";
	return 0;
}
	

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

#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define MOD 1000000007

typedef long long ll;

using namespace std;

bool checkConnection(int n, vector<int> *g)
{
    bool res = true;
    REP(i, n)
    {
        int st = i;
        bool visited[n] = {false};
        queue<int> bfsQ;

        visited[st] = true;
        bfsQ.push(st);
        while (!bfsQ.empty())
        {
            int now = bfsQ.front();
            bfsQ.pop();
            for (int j = 0; j < g[now].size(); ++j)
            {
                int next = g[now][j];
                if (!visited[next])
                {
                    visited[next] = true;
                    bfsQ.push(next);
                }
            }
        }

        REP(j, n)
        {
            if (!visited[j])
            {
                res = false;
                break;
            }
        }

        if (!res)
        {
            break;
        }
    }

    return res;
}

int main()
{
    int N, M;
    cin >> N >> M;
    int a[M], b[M];
    REP(i, M)
    {
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
    }

    int ans = 0;
    REP(i, M)
    {
        vector<int> G[N];
        REP(j, M)
        {
            if (i != j)
            {
                G[a[j]].push_back(b[j]);
                G[b[j]].push_back(a[j]);
            }
        }
        // Gが連結であるか調べる
        if (!checkConnection(N, G))
        {
            ans++;
        }
     }

    cout << ans << endl;
}


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




int main()
{
	int m = 1000000007;
	int n;
	cin >> n;
	vector<long long> v(n);
	vector<long long> pref(n);
	for (int i = 0; i < n; i++) {
		cin >> v[i];
		if (i == 0) pref[0] = v[0]%m;
		else {
			pref[i] = ((pref[i - 1] % m) + (v[i] % m)) % m;
			pref[i] % m;
		}
	}
	long long ans = 0;
	for (int i = 1; i < n; i++) {
		ans += ((v[i] % m) * (pref[i - 1] % m)) % m;
		ans %= m;
	}
	cout << ans;
	
	
	

}



Measured memory_bytes: 6368
# cook your dish here
import sys,math
try:sys.stdin,sys.stdout=open('input.txt','r'),open('out.txt','w')
except:pass
from sys import stdin,stdout;mod=int(1e9 + 7);from statistics import mode
from collections import *;from math import ceil,floor,inf,factorial,gcd,log2,sqrt,log
ii1=lambda:int(stdin.readline().strip())
is1=lambda:stdin.readline().strip()
iia=lambda:list(map(int,stdin.readline().strip().split()))
isa=lambda:stdin.readline().strip().split()
# print('{:.3f}'.format(1),round(1.123456789,4))
# sys.setrecursionlimit(500000)
def lcm(a,b): return (a*b)//gcd(a,b)
def setbits(n):return bin(n).count('1')
def resetbits(n):return bin(n).count('0')
def modinv(n,p):return pow(n,p-2,p)
def ncr(n,r):
    num,den=1,1;r=min(n,n-r)
    for i in range(r):num*=(n-i);den*=(i+1)
    return num//den
def ncr_p(n, r, p):
    num,den=1,1;r=min(r,n-r)
    for i in range(r):num = (num * (n - i)) % p ;den = (den * (i + 1)) % p
    return (num * modinv(den,p)) % p
def isPrime(num) :
    if num<=1:return False
    if num==2 or n==3:return True
    if (num % 2 == 0 or num % 3 == 0) :return False
    m = int(num**0.5)+1
    for i in range(5,m,6):
        if (num % i == 0 or num % (i + 2) == 0) :return False
    return True
def bin_search(s, low, high, val):
    while low <= high:
        mid = low + (high - low) // 2;
        if s[mid] == val:return mid
        elif s[mid] < val:low = mid + 1
        else:high = mid - 1
    return -1
def sumofdigit(num):
    count=0;
    while num : count+=num % 10;num //= 10;
    return count;
def inputmatrix():
    r,c=iia();mat=[0]*r;
    for i in range(r):mat[i]=iia();
    return r,c,mat;
def prefix_sum(n,s):
    for i in range(1,n):s[i]+=s[i-1]
    return s;
def binomial(n, k):
    if 0 <= k <= n:
        ntok = 1;ktok = 1
        for t in range(1, min(k, n - k) + 1):ntok *= n;ktok *= t;n -= 1
        return ntok // ktok
    else:return 0
def divisors(n):
    res = [];
    for i in range(1,ceil(sqrt(n))+1):
        if n%i == 0:
            if i==n//i:res.append(i)
            else:res.append(i);res.append(n//i)
    return res;

# coding start heres
n = ii1()
arr=[];flag=False
for i in range(n):
    a,b=iia()
    arr.append([a,b])
for i in range(n-2):
    if arr[i][0]==arr[i][1] and arr[i+1][0]==arr[i+1][1] and arr[i+2][0]==arr[i+2][1]:
        flag=True
if flag:print('Yes')
else:print('No')



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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;
const ll mod = 1e9+7;


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

    ll r,d,x;cin>>r>>d>>x;
    REP(i,10){
        x = r*x-d;
        cout<<x<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
use std::io::{self, Read};

fn main() {
    let mut buf = String::new();
    let stdin = io::stdin();
    let mut stdin = stdin.lock();
    stdin.read_to_string(&mut buf).unwrap();
    let count = buf
        .chars()
        .fold(0, |acc, x| if x == '1' { acc + 1 } else { acc });
    print!("{}", count);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for(int i=0; i<int(n); i++)
#define RNG(i, f, t) for(int i=int(f); i<=int(t); i++)
#define REV(i, f, t) for(int i=int(f); i>=int(t); --i)
#define ALL(v) (v).begin(), (v).end()
bool RELAXED = false;
template<int,typename T> struct MINMAX{ T val; MINMAX(T val) : val(val) {} };
template<typename T> MINMAX<1,T> MAX(T val) { return MINMAX<1,T>(val); };
template<typename T> MINMAX<2,T> MIN(T val) { return MINMAX<2,T>(val); };
template<typename T, typename U> inline T& operator|=(T &lhs, MINMAX<1,U> rhs) { return lhs = (rhs.val > lhs ? (RELAXED=true,rhs.val) : (RELAXED=false,lhs)); }
template<typename T, typename U> inline T& operator|=(T &lhs, MINMAX<2,U> rhs) { return lhs = (rhs.val < lhs ? (RELAXED=true,rhs.val) : (RELAXED=false,lhs)); }
template<typename T> inline vector<T> readVector(int n) { vector<T> vec(n); FOR(i,n) cin>>vec[i]; return vec; }
template<typename T> void EXIT(T answer) { cout<<answer<<endl; exit(0); }
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef signed long long int ll;

const int MOD = 1e9+7;

ll inverseModulo(ll a, ll b){
    return 1<a ? b - inverseModulo(b % a, a) * b / a : 1;
}

ll binomial(int n, int k) {
    ll x=1;
    RNG(i,1,k) {
        x = x * (n + 1 - i) % MOD;
        x = x * inverseModulo(i, MOD) % MOD;
    }
    return x;
}

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

    int x,y; cin>>x>>y;
    if(x>y) swap(x,y);
    ll ans=0;
    FOR(i,x+1) {
        int dx = i;
        int dy = 2*i;
        int ex = x-dx>>1;
        int ey = y-dy;
        if((x-dx)%2==0 && ex==ey) {
            int m = dx+ey;
            ans += binomial(m,dx);
        }
    }
    cout<<ans<<endl;


    return 0;
}



Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define MOD 1000000007
using namespace std;
typedef long long ll;
#include <cstring>

int main() {
  int n, ans = 0;
  double x, y, d;
  cin >> n >> d;
  for (int i = 0; i < n; i++) {
    cin >> x >> y;
    if (x * x + y * y <= d * d) {
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3776
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(V) V.begin(),V.end()

int A[200010], B[200010];

int main() {
	int N;
	cin >> N;
	string S;
	cin >> S;
	int c = 0;
	for (int i = 0;i < N;i++) {
		if (S[i] == 'W')c++;
		A[i] = c;
	}
	int ans = c;
	c = 0;
	for (int i = N - 1;i >= 0;i--) {
		if (S[i] == 'R')c++;
		B[i] = c;
	}
	ans = min(ans, c);
	for (int i = 1;i < N;i++) {
		ans = min(ans, max(A[i - 1], B[i]));
	}
	cout << ans << endl;
}

Measured memory_bytes: 5276
cnt = [0 for i in range(26)]
while True:
    try:
        s = input()
    except:
        break
    if s == '':
        break
    for cdfix in range(26):
        cnt[cdfix] += s.count(chr(ord('a') + cdfix))
        cnt[cdfix] += s.count(chr(ord('A') + cdfix))
for r in range(26):
    print('{} : {}'.format(chr(ord('a') + r), cnt[r]))



Measured memory_bytes: 5572
#include<iostream>
#include<math.h>
#include<string.h>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<deque>
using namespace std;

int main(){
	long long x;
	cin >> x;
	vector<long long> A5(200,0),B5(200,0);
	for(long long i=0;i<=199;i++){
		A5[i]=i*i*i*i*i;
		B5[i]=i*i*i*i*i;
	}
	
	for(long long i=0;i<=199;i++){
		for(long long j=0;j<=199;j++){
			if(A5[i]-B5[j]==x){
				cout << i << " " << j << endl;
				return 0;
			}
			if(A5[i]+B5[j]==x){
				cout << i << " " << -1*j << endl;
				return 0;
			}
			if(B5[j]-A5[i]==x){
				cout << -1*i << " " << -1*j << endl;
				return 0;
			}
			if(-B5[j]-A5[i]==x){
				cout << -1*i << " " << j << endl;
				return 0;
			}
		}
	}
}


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

int main() {
  long X,K,D;
  cin>>X>>K>>D;
  X=abs(X);
  long  c=X/D;
  if(K<c){
    X-=K*D;
  }
  else{
    K-=c;
    X-=c*D;
    if(K%2==0){
      X=X;
    }
    else{
      X-=D;
    }
  }

  cout<<abs(X)<<endl;
}


Measured memory_bytes: 3616
#include<stdio.h>
 
int main()
{
    int a,b,c,d,e,k;
    scanf("%d%d%d%d%d%d",&a,&b,&c,&d,&e,&k);
    int x[5]={a,b,c,d,e};
    int i,j;
    int flag=0;
    for(i=0;i<5;++i) 
      {
          for(j=i+1;j<5;++j)
            {
                if(x[j]-x[i]>k)
                  {
                      flag=1;
                      break;
                  }
            }
            
            if(flag==1)
               break;
      }
      
      if(flag==1)
         printf(":(");
         
     else
       printf("Yay!");
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    string t;
    int check;
    int pip = 0;
    
    cin >> s;
    cin >> t;
    
    int ss = (int)s.size();
    int st = (int)t.size();
    
    string ans;
    
    for (int i = 0;i < ss;i++){
        ans += 'z';
    }
    
    for (int i = 0;i <= ss-st;i++){
        string res = s;
        check = 1;
        for (int j = 0;j < i;j++){
            if (res[j] == '?'){
                res[j] = 'a';
            }
        }
        for (int j = 0;j < st;j++){
            if (res[i+j] == '?'){
                res[i+j] = t[j];
            }
            else if (res[i+j] != t[j]){
                check = 0;
            }
        }
        for (int j = st+i;j < ss;j++){
            if (res[j] == '?'){
                res[j] = 'a';
            }
        }
        if (check && res.compare(ans) <= 0){
            ans = res;
            pip = 1;
        }
     }
    if (pip)
	cout << ans << endl;
    else
    cout << "UNRESTORABLE" << endl;
    return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n, k;cin >> n >> k;
  vector<int> v(n);
  int ans=0;
  for(int i=0;i<n;i++) {
    cin >> v[i];
    if(v[i] >= k) ans++;
  }
  cout << ans << endl;
}
                                          

Measured memory_bytes: 640
/* 
 * Project: AtCoder Beginners Contest 133 A - T or T
 * Author: toms74209200 <https://github.com/toms74209200>
 *
 * Created on 2020/09/17
 * Copyright (c) 2020 toms74209200
 * 
 * This software is released under the MIT License.
 * http://opensource.org/licenses/mit-license.php
 */
#include <cstdio>
#include <cstdint>
#include <algorithm>
using namespace std;

int32_t n;
int32_t a, b;

void solve() {

    int32_t price_train = n*a;
    int32_t price_taxi = b;
    printf("%d\n", min(price_train, price_taxi));
    
}

int main() {

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

    solve();

}

Measured memory_bytes: 3212
n = int(input())
a = list()
for i in range(n):
    a.append(int(input()))
f = max(a)
fp = a.index(f)
b = list(a)
b.remove(f)
s = max(b)
for i in range (n):
    if i == fp:
        print(s)
    else :
        print(f)

Measured memory_bytes: 14080
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <climits>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    VI a1(n), a2(n);
    cin >> a1[0];
    FOR(i, 1, n - 1) {
        int a;
        cin >> a;
        a1[i] = a1[i - 1] + a;
    }
    cin >> a2[0];
    FOR(i, 1, n - 1) {
        int a;
        cin >> a;
        a2[i] = a2[i - 1] + a;
    }

    int ans = a1[0] + a2.back();
    FOR(i, 1, n - 1)
        ans = max(ans, a1[i] + a2.back() - a2[i - 1]);
    cout << ans << endl;
    return 0;
}


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

int main() {
  string s;
  cin >> s;
  
  int res = 0;
  if(s.at(0) == 'R' && s.at(1) == 'R' && s.at(2) == 'R'){
    res = 3;
  }
  else if((s.at(0) == 'R' && s.at(1) == 'R') || (s.at(1) == 'R' && s.at(2) == 'R')){
    res = 2;
  }
  else if(s.at(0) == 'R' || s.at(1) == 'R' || s.at(2) == 'R'){
    res = 1;
  }
  else
    res = 0;
  
  cout << res << endl;
}

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

void solve(long long N, std::vector<long long> A)
{
    bool approved = true;
    for (int i = 0; (unsigned)i < A.size(); i++)
    {
        auto a = A[i];
        if (a % 2 == 0)
        {
            if (a % 3 == 0 || a % 5 == 0)
            {
                // pass
            }
            else
            {
                approved = false;
            }
        }
    }
    cout << ((approved) ? "APPROVED" : "DENIED") << endl;
}

int main()
{
    long long N;
    scanf("%lld", &N);
    std::vector<long long> A(N);
    for (int i = 0; i < N; i++)
    {
        scanf("%lld", &A[i]);
    }
    solve(N, std::move(A));
    return 0;
}


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

const int INF = 0x3f3f3f3f;
const int MAXN = 21+5;
const int MAXK = 3123456;
const int mod = 1000000000+7;

int n;
int match_values[MAXN][MAXN];
int pd[MAXN][MAXK];

int rec(int cur, int bmask)
{
	if(cur==n)
		return 1;

	if(pd[cur][bmask]!=-1)
		return pd[cur][bmask];

	int sum = 0;
	for(int j=0; j<n; j++)
	{
		if(match_values[cur][j] && !(bmask & (1<<j))){
			sum += rec(cur+1, bmask | (1<<j));
			sum = sum%mod;
		}
	}

	return pd[cur][bmask] = sum;
}

int main()
{
	memset(pd, -1, sizeof(pd));
	cin >> n;
	for(int i=0; i<n; i++)
		for(int j=0; j<n; j++)
		{
			cin >> match_values[i][j];
		}

	cout << rec(0, 0) << endl;

	return 0;
}

Measured memory_bytes: 317440
import java.util.*;
public class Main{
	public static void main(String[] a)throws java.io.IOException{
	Scanner scan=new Scanner(System.in);
	while(true){
		int q=scan.nextInt();
		if(q==-1)break;
		double x =q/2;
		while(Math.abs(Math.pow(x,3)-q)>=q*0.00001){
			x =x-(Math.pow(x, 3)-q)/(3*Math.pow(x, 2));
		}
		System.out.printf("%1.6f\n",x);

	}
	}
}

Measured memory_bytes: 11000
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    int m;
    scanf("%d",&m);
    ll ans = 0;
    ll sum = 0;
    ll dsum = 0;
    for (int i = 0; i < m; i++){
        int d;
        ll c;
        scanf("%d%lld",&d,&c);
        sum += c;
        dsum += d*c;
    }
    ans = (dsum-1)/9 + sum - 1;
    printf("%lld",ans);
}


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

using namespace std;
using int64 = long long;
const int mod = 1e9 + 7;

const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;


template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 > &p) {
  os << p.first << " " << p.second;
  return os;
}

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
  is >> p.first >> p.second;
  return is;
}

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

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

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

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
  return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}

int main() {
  int H, W;
  cin >> H >> W;
  vector< string > S(H);
  cin >> S;
  int ret = 0;
  queue< pair< int, int > > que;
  auto d = make_v< int >(H, W);
  fill_v(d, -1);
  for(int i = 0; i < H; i++) {
    for(int j = 0; j < W; j++) {
      if(S[i][j] == '#') {
        que.emplace(i, j);
        d[i][j] = 0;
      }
    }
  }
  const int vy[] = {0, -1, 0, 1};
  const int vx[] = {1, 0, -1, 0};
  while(que.size()) {
    auto p = que.front();
    que.pop();
    for(int i = 0; i < 4; i++) {
      int ny = p.first + vy[i];
      int nx = p.second + vx[i];
      if(ny < 0 || nx < 0 || ny >= H || nx >= W) continue;
      if(d[ny][nx] == -1) {
        d[ny][nx] = d[p.first][p.second] + 1;
        chmax(ret, d[ny][nx]);
        que.emplace(ny, nx);
      }
    }
  }
  cout << ret << endl;
}



Measured memory_bytes: 13456
#include <algorithm>
#include <array>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <string>
#include <utility>
#include <vector>

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

using namespace std;

int main() {
  vector<int> ret(2);
  cin >> ret[0];
  cin >> ret[1];

  rep(i, 3) {
    bool ok = false;
    rep(j, 2) {
      if( ret[j] == i+1 ) {
        ok = true; 
      }
    }
    if (!ok) {
      cout << i+1 << endl;
    }
  }

  return 0;
}


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

using i64 = long long;
using P = pair<i64, i64>;

#define overload3(_1, _2, _3, name, ...) name
#define rep1(i, n) for(i64 i = 0LL; i < (n); ++i)
#define rep2(i, a, b) for(i64 i = (a); i < (b); ++i)
#define rep(...) overload3(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)
#define all(v) v.begin(), v.end()


void solve(long long N, long long K, std::vector<long long> H){
    sort(all(H), greater<i64>());
    i64 ans = 0;
    rep(i, N){
        if(i >= K) ans += H[i];
    }
    cout << ans << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long K;
    scanf("%lld",&K);
    std::vector<long long> H(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&H[i]);
    }
    solve(N, K, std::move(H));
    return 0;
}


Measured memory_bytes: 1792
import java.util.*;

public class Main{
    void solve(){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        Map<Integer, Integer> s = new HashMap<>();
        int max = -1;
        for(int i = 0; i < n; i++){
            int a = scan.nextInt();
            int b = scan.nextInt();
            max = Math.max(max, a);
            s.put(a, b);
        }
        System.out.println(s.get(max) + max);
    }

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


Measured memory_bytes: 66496
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <algorithm>
#include <cctype>
using namespace std;

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    int d = (b + c - a > 0) ? b + c - a : 0;
    cout << d << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int M = 1e9 + 7;
int main() {
    int N;
    string S;
    cin >> N >> S;

    vector<int> v(26, 0);
    for (int i = 0; i < N; i++) {
        v[S[i] - 'a']++;
    }

    long long sum = 1;
    for (int i = 0; i < 26; i++) {
        if (v[i]) {
            sum = (sum * (v[i] + 1)) % M;
        }
    }
    
    cout << sum - 1 << endl;
}

Measured memory_bytes: 512
#include<stdio.h>
int main(void){
    int A,B,K,x;
    scanf("%d%d%d",&K,&A,&B);
        for(int i=A;i<=B;i++){
            if(i%K == 0){
                printf("OK\n");
                break;
            }else if(i==B) printf("NG\n");
        }
    return 0;
}

Measured memory_bytes: 1656