akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 60;
const long long MOD = 1000000007;

int main(){
  int n;
  cin >> n;
  if(n == 1){
    cout << 0 << endl;
    return 0;
  }
  unsigned long long ans = 1;
  for(int i = 0; i < n; i++){
    ans *= 10;
    ans %= MOD;
  }
  unsigned long long cnt = 1;
  for(int i = 0; i < n; i++){
    cnt *= 9;
    cnt %= MOD;
  }
  cnt *= 2;
  cnt %= MOD;
  unsigned long long cnt2 = 1;
  for(int i = 0; i < n; i++){
    cnt2 *= 8;
    cnt2 %= MOD;
  }
  unsigned long long re = ans - cnt + cnt2;
  cout << (re + MOD) % MOD << endl;
}


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

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MOD 1000000007

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


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a, p;
  cin >> a >> p;
  int num = a * 3 + p;
  cout << num/2 << endl;
}


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

#define MAXN 200007

int n ;
long long ans = 0 ;
int k[ MAXN ] ;
int l[ MAXN ] ;
int r[ MAXN ] ;

int cnt1 , cnt2 ;

vector < int > v[ MAXN ] ;
vector < int > w[ MAXN ] ;

priority_queue < int > q ;

void input ( ) {
    cin >> n ;
    ans = 0 ;
    cnt1 = cnt2 = 0 ;
    while ( q.empty ( ) == false ) { q.pop ( ) ; }
    for ( int i = 1 ; i <= n ; ++ i ) {
        v[ i ].clear ( ) ;
        w[ i ].clear ( ) ;
    }
    for ( int i = 1 ; i <= n ; ++ i ) {
        cin >> k[ i ] >> l[ i ] >> r[ i ] ;
        ans += min ( l[ i ] , r[ i ] ) ;
        if ( l[ i ] >= r[ i ] ) {
            ++ cnt1 ;
            v[ k[ i ] ].push_back ( l[ i ] - r[ i ] ) ;
        }
        else {
            ++ cnt2 ;
            w[ k[ i ] + 1 ].push_back ( r[ i ] - l[ i ] ) ;
        }
    }
}

void solve ( ) {
    for ( int i = n ; i >= 1 ; -- i ) {
        int sz = v[ i ].size ( ) ;
        for ( int j = 0 ; j < sz ; ++ j ) {
            q.push ( v[ i ][ j ] ) ;
        }
        if ( i <= cnt1 && q.empty ( ) == false ) {
            ans += q.top ( ) ;
            q.pop ( ) ;
        }
    }
    while ( q.empty ( ) == false ) { q.pop ( ) ; }
    for ( int i = 1 ; i <= n ; ++ i ) {
        int sz = w[ i ].size ( ) ;
        for ( int j = 0 ; j < sz ; ++ j ) {
            q.push ( w[ i ][ j ] ) ;
        }
        if ( i > cnt1 && q.empty ( ) == false ) {
            ans += q.top ( ) ;
            q.pop ( ) ;
        }
    }
    cout << ans << "\n" ;
}


int main ( ) {
    ios_base :: sync_with_stdio ( false ) ;
    cin.tie ( NULL ) ;
    int t ;
    cin >> t ;
    while ( t -- ) {
        input ( ) ;
        solve ( ) ;
    }
    return 0 ;
}


Measured memory_bytes: 20112
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

h,w,k=nii()
c=[list(input()) for i in range(h)]

black=0
for i in c:
  black+=i.count('#')

ans=0
for th in range(2**h):
  for tw in range(2**w):
    h_use=[]
    for i in range(h):
      if (th>>i)&1:
        h_use.append(i)
    w_use=[]
    for i in range(w):
      if (tw>>i)&1:
        w_use.append(i)

    t_cnt=0
    for i in h_use:
      t_cnt+=c[i].count('#')
    for i in w_use:
      for z in range(h):
        if c[z][i]=='#':
          t_cnt+=1
    for i in h_use:
      for j in w_use:
        if c[i][j]=='#':
          t_cnt-=1

    if black-t_cnt==k:
      ans+=1

print(ans)

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

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

int ball[10];

bool dfs(int n, int a, int b) {
    if (n == 10) return true;
    if (ball[n] > a && dfs(n+1, ball[n], b)) return true;
    if (ball[n] > b && dfs(n+1, a, ball[n])) return true;
    return false;
}

int main() {
    int n; cin >> n;
    while (n--) {
        rep(i, 10) cin >> ball[i];
        if (dfs(0, 0, 0)) puts("YES");
        else puts("NO");
    }
}

Measured memory_bytes: 3012
from collections import Counter
def D():
    N = int(input())
    A = list(map(int, input().split()))
    nums = Counter(A)
    if 1 in nums:
        if nums[1] > 1:
            print(0)
            return
        else:
            print(1)
            return
    n = max(A)
    dp = [True for i in range(n+1)]
    p = 2
    while (p <= n): 
        if (p in nums and dp[p] == True): 
            for i in range(p*2, n+1, p): 
                # print(i)
                dp[i] = False
        p += 1
    ans = 0
    for num in nums:
        if nums[num] == 1 and dp[num]:
            # print(num)
            ans += 1
    print(ans)

D()

Measured memory_bytes: 43032
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <utility>
#include <cmath>

#define INF_LL 9000000000000000000
#define INF 2000000000

#define REP(i, n) for(int i = 0;i < (n);i++)
#define FOR(i, a, b) for(int i = (a);i < (b);i++)

using namespace std;

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

class Union_find{
private:
	vector<int> par;
	vector<int> rank;
	int n;

public:
	Union_find(int a){
		n = a;
		for(int i = 0;i < n;i++){
			par.push_back(i);
			rank.push_back(0);
		}
	}

	int find(int x){
		if(par[x] == x){
			return x;
		}else{
			return par[x] = find(par[x]);
		}
	}

	void unite(int x, int y){
		x = find(x);
		y = find(y);
		if(x == y) return;

		if(rank[x] < rank[y]){
			par[x] = y;
		}else{
			par[y] = x;
			if(rank[x] == rank[y]) rank[x]++;
		}
	}

	bool same(int x, int y){
		return find(x) == find(y);
	}
};

struct edge{ int u, v, cost; };

edge es[100000];
int V, E;

bool comp(const edge& e1, const edge& e2){
	return e1.cost < e2.cost;
}

int main(void){
	cin >> V >> E;
	for(int i = 0;i < E;i++){
		int a, b, c;
		cin >> a >> b >> c;
		es[i].u = a;
		es[i].v = b;
		es[i].cost = c;
	}
	Union_find uf(V);
	sort(es, es+E, comp);
	int res = 0;
	for(int i = 0;i < E;i++){
		edge e = es[i];
		if(!uf.same(e.u, e.v)){
			uf.unite(e.u, e.v);
			res += e.cost;
		}
	}
	cout << res << endl;
}

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

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = "";
		while ((line = br.readLine()) != null) {
			int r, s;
			r = Integer.parseInt(line);
			s = 0;
			for (int i = 1; r * i < 600; i++) {
				s += r * r * r * i * i;
			}
			System.out.println(s);
		}
	}
}

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

signed main(){

    int n, k;
    cin >> n >> k;
    vector<int> a(n), dp(k+2);
    for(int i = 0; i< n; i++)
        cin >> a[i];

    for(int i = 1; i <= k; i++) {
        for (int j = 0; j < n; j++) {
            if (i - a[j] == 0) {
                dp[i] = 1;
            }
            if(i - a[j] >= 0 and dp[i-a[j]] == 0){
                dp[i] = 1;
            }
        }
    }

    cout << (dp[k] ? "First":"Second") << "\n";
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#include <cstdlib>
#include <deque>

using namespace std;
const long long P = 1000000007;

int main() {
  long long n;
  cin >> n;
  vector<long long> x(n,0),a(n);
  for(int i = 0; i < n; i++) {
    cin >> x[i];
  }
  a = x;
  sort(a.begin(),a.end());
  int mid = n/2;
  for(int i = 0; i < n; i++) {
    if(x[i] <= a[mid-1]) {
      cout << a[mid] << endl;
    }else {
      cout << a[mid-1] << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 5376
#include <iostream>
#include <ios> 
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

using namespace std;
typedef long long int lli;
//const int MAX=;

int main(){
	int N;
	cin>>N;
	stack<int> s;
	int t=N;
	while(t!=0){
		if(t%2==0){
			s.push(0);
			t=t/2;
			t=t*(-1);
		}
		else{
			s.push(1);
			t=t-1;
			t=t/2;
			t=t*(-1);
		}
	}
	while(!s.empty()){
      	int x=s.top();
		cout<<x;
		s.pop();
	}
  if(N==0)cout<<0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;
ll MOD=1000000007;
int main(){
  ll n;
  cin>>n;
  vector<ll> a(n);
  rep(i,n) cin>>a[i];
  rep(i,n){
    if(a[i]==0){
      cout<<0<<endl;
      return 0;
    }
  }
  ll ans=a[0];
  rep2(i,1,n){
    if(a[i]>1000000000000000000/ans){
      cout<<-1<<endl;
      return 0;
    }
    ans*=a[i];
  }
    cout<<ans<<endl; 
return 0;
}

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

int main()
{
    int D, T, S;
    cin >> D >> T >> S;

    cout << (T * S >= D ? "Yes" : "No")<< endl;

    return 0;
}

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

typedef vector<vector<int> > graph;

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


void visit(graph& g, vector<int>& PostOrder, vector<bool>& visited, int ps)
{
	visited[ps]=1;
	int S=g[ps].size();
	REP(i,S)
	{
		int next=g[ps][i];
		if(visited[next]) continue;
		visit(g, PostOrder, visited, next);
	}
	
	PostOrder.push_back(ps);
}

void walk(graph& g, vector<int>& in, int ps, int gcnt)
{
	in[ps]=gcnt;
	
	int S=g[ps].size();
	REP(i,S)
	{
		int next=g[ps][i];
		if(in[next]!=-1) continue;
		walk(g,in,next,gcnt);
	}
}

//StronglyConnectedComponent
int SCC(vector<int>& in, int V, graph& g, graph& rg)
{
	int gcnt=0;
	vector<int> PostOrder;
	vector<bool> visited(V,false);
	
	REP(i,V)
	{
		if(visited[i]) continue;
		visit(g,PostOrder,visited, i);
	}
		
	for(int i=PostOrder.size()-1; i>=0; --i)
	{
		if(in[PostOrder[i]]==-1) 
		{
			walk(rg,in,PostOrder[i],gcnt++);
		}
	}

	return gcnt;
}

int recipe[1050], self[1050],reduce[1050];

int dfs(int p, vector<bool>& use, graph& g, graph& c)
{
	use[p]=1;

	int ret=0;
	for(int i=0; i<g[p].size(); i++)
	{
		int next=g[p][i];
		if(use[next]) continue;
		ret+=dfs(next, use, g, c);
		ret+=c[p][i];
	}

	return ret;

}

int calc(vector<int>& v, vector<bool>& created, graph& g, graph& c)
{
	vector<bool> use(10000, 1);
	for(int i=0; i<v.size(); i++)
		use[v[i]]=0;

	int ret=0,mn=(1<<24),r;
	if(v.size()==1)
	{
		int p=v[0];
		if(created[recipe[p]]) ret=reduce[p];
		else ret=self[p];
	}
	else
	{
		for(int i=0; i<v.size(); i++)
		{
			int p=v[i];
			if(self[p]-reduce[p]<mn)
			{
				r=p;
				mn=self[p]-reduce[p];
			}
		}

		for(int i=0; i<v.size(); i++)
		{
			int p=v[i];
			if(p==r) ret+=self[p];
			else ret+=reduce[p];
		}
	}

	for(int i=0; i<v.size(); i++)
		created[v[i]]=1;

	return ret;
}

int main()
{
	int N;
	while(cin >> N, N)
	{
		graph g(N), rg(N), c(N), rc(N);

		int dcnt=0;
		map<string, int> dic;
		for(int i=0; i<N; i++)
		{
			string s,t;
			int a,b,u,v;
			cin >> s >> a >> t >> b;

			if(!dic.count(s)) dic[s]=dcnt++;
			if(!dic.count(t)) dic[t]=dcnt++;
			
			u=dic[s];
			v=dic[t];

			 g[u].push_back(v);
			rg[v].push_back(u);
			 c[u].push_back(b);
			rc[v].push_back(b);

			self[u]=a;
			recipe[u]=v;
			reduce[u]=b;
		}

		vector<int> in(N, -1);
		int gcnt=SCC(in,N,rg,g);

		vector<vector<int> > loop(gcnt);
		for(int i=0; i<N; i++)
			loop[in[i]].push_back(i);

		vector<bool> created(N, 0);

		int ans=0;
		for(int i=0; i<gcnt; i++)
		{
			ans+=calc(loop[i], created, rg, rc);
		}

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

Measured memory_bytes: 1188
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;

int main() {
	//freopen("in", "r", stdin);
	//freopen("out", "w", stdout);
	int n;
	scanf("%d", &n);
	int a = 0, b, c, d;
	for (int i = 1; i <= n; i++) {
		scanf("%d%d", &c, &d);
		if (a < c) {a = c; b = d;}
	}
	printf("%d", a + b);
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))


def dcg(a, b):
    while not (a == 0 or b == 0):
        if a > b:
            a %= b
        else:
            b %= a
    return a + b


for i in range(N-1):
    A[i+1] = dcg(A[i], A[i+1])
print(A[-1])


Measured memory_bytes: 14224
#include<bits/stdc++.h>
using namespace std;
typedef double db;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
#define dd(x) cout << #x << " = " << x << ", "
#define de(x) cout << #x << " = " << x << endl
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
//INF = 1 061 109 567 ; INF + INF = 2 122 219 134 ;
//LINF = 4 557 430 888 798 830 399 ; LINF + LINF = 9 114 861 777 597 660 798 ;
const int INF = 0x3f3f3f3f;     // -INF: 0xc0   abs(-INF) = INF + 1
const ll LINF = 0x3f3f3f3f3f3f3f3f;
/*}}}*/                         // zr, zm
const int MOD = (int)1e9+7;     // when MOD = 1e9+7, inv2 = 500000004
const int N = (int)1e6+7;
const int M = (int)-1;

int main()

{
	int n;scanf("%d",&n);
	double ans = 0;
	rep(i,0,n) {
		int t;;
		scanf("%d",&t);
		ans += 1.0/t;
	}
	printf("%.7f\n",1.0/ans);
	return 0;
}


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

#define ld long double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

//-------------------------------------------------

int main(void)
{
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    int n,m; cin>>n>>m;
    using P = tuple<ll,ll,ll>;
    vector<P> ps(m);
    vi cnt(n+1,0);
    vector<pi> ans(m);
    rep(i,m){
        ll p,y; cin>>p>>y;
        ps[i] = tie(y,p,i);
    }
    sort(all(ps));
    rep(i,m){
        ll y,p,idx;
        tie(y,p,idx) = ps[i];
        ans[idx] = mp(p, ++cnt[p]);
    }
    rep(i,m){
        printf("%06d%06d\n", ans[i].fi, ans[i].se);
    }
    return 0;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define FIN         ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ii          pair<int,int>
#define F           first
#define S           second
#define pb          push_back
#define all(x)      (x).begin(),(x).end()
#define rall(x)     (x).rbegin(),(x).rend()
#define fore(i,a,b) for(int i = a;i < b; i+= 1)
#define forr(i,a)   for(int i = a; i >= 0; i--)
#define fori(i,m)   for(auto i = m.begin(); i != m.end(); i++) 
#define w(t)        while(t--)
#define sz(s)       int(s.size())
#define cls(a,car)  memset(a,car,sizeof (a))
#define db(x)       cerr << #x << " is " << x << '\n'
#define FL          freopen("input.txt", "r", stdin),freopen("output.txt", "w", stdout);
#define EjecuteTime cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"
#define angle(x)    double(x * acos(-1) / 180.0)
using namespace std;
typedef long long   ll;
typedef vector<int> vi;
typedef vector<ii>  vii;
const int N = 1 * 1e5 + 5;
const ll mod = 1e9 + 7;
const double E = 1e-9;
int dx[] = {1, 0}, dy[] = {0, 1};
//int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
//int dx[] = {2, 1, -1, -2, -2, -1, 1, 2}, dy[] = {1, 2, 2, 1, -1, -2, -2, -1};
// fflush(stdout)
// cout << flush
// a + b = a ^ b + 2 * (a & b)
int add(int a, int b){return  a + b > mod ? a + b - mod : a + b;}
int mul(int a, int b){return a * b >=    mod ? a * b % mod : a * b;}  
int n, k;
int v[105];
int dp[105][N], prefixsum[N]; 
int f(int i, int w){
    if(w < 0)return 0;
    if(i == 0){
        return w == 0 ? 1 : 0;
    }
    int &ans = dp[i][w];
    if(ans == -1){
        ans = 0;
        for(int j = 0; j <= v[i]; j++)
            ans = add(ans, f(i - 1, w - j));
    }
    return ans;
} 
int main(){
    //FL;
    FIN;
    cin >> n >> k;
    for(int i = 1; i <= n; i++)
        cin >> v[i];
    for(int i = 0; i <= n; i++){
        if(i){
            prefixsum[0] = dp[i - 1][0];
            for(int j = 1; j <= k; j++)
                prefixsum[j] = add(prefixsum[j - 1], dp[i - 1][j]);
        }

        for(int w = 0; w <= k; w++){
            int &ans = dp[i][w];
            if(i == 0){
                ans = (!w ? 1 : 0);
                continue;
            }
            ans = 0;
            
            ans = prefixsum[w];
            if(w - v[i] - 1 >= 0)
                ans = ((ans - prefixsum[w - v[i] - 1] + mod) % mod) % mod;
        }
    }

    cout << dp[n][k] << '\n';

    EjecuteTime;
    return 0;
}       


Measured memory_bytes: 43572
#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>
#include <set>
#include <cmath>
#include <tuple>
#include <cstring>
#include <map>
#include <iomanip>
#include <ctime>
#include <complex>
#include <cassert>
#include <climits>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define _ << " " <<
#define all(X) (X).begin(), (X).end()
#define len(X) (X).size()
#define Pii pair<int, int>
#define Pll pair<ll, ll>
#define Tiii tuple<int, int, int>
#define Tlll tuple<ll, ll, ll>

int main() {
    int a, b, m;
    cin >> a >> b >> m;
    int x[a], y[b], xm = 1e9, ym = 1e9;
    for (int i = 0; i < a; i++) {
        cin >> x[i];
        if (xm > x[i]) xm = x[i];
    }
    for (int i = 0; i < b; i++) {
        cin >> y[i];
        if (ym > y[i]) ym = y[i];
    }
    int mn = xm + ym;
    for (int i = 0; i < m; i++) {
        int p, q, r;
        cin >> p >> q >> r;
        if (mn > x[p-1] + y[q-1] - r) {
            mn = x[p-1] + y[q-1] - r;
        }
    }
    cout << mn << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
    using namespace std;
     
    int main(){
      int n, k, d, a;
      cin >> n >> k;
      vector<int> arr(n + 1, 0);
      for(int i = 0; i < k; i++){
        cin >> d;
        for(int j = 0; j < d; j++){
          cin >> a;
          arr[a]++;
        }
      }
      int cnt = 0;
      for(int i = 1; i <= n; i++)
        if(!arr[i])
          cnt++;
      cout << cnt << endl;
      return 0;
    }

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

int main()
{
  // pre exec
  vector<bool> prime(300001, true); 
  prime[0] = prime[1] = false;
  // 月曜木曜素数の生成
  // エラトステネスの篩 + 月曜木曜数であることが月曜木曜素数の条件
  for (int i = 2; i <= 300000; i++) {
    if (prime[i]) {

      if (((i % 7) != 1) && ((i % 7) != 6)) {
        prime[i] = false;
        continue;
      }

      for (int k = 2; (i * k) <= 300000; k++) {
        prime[i * k] = false;
      }
    }
  }

  int N;

  while(cin >> N && (N > 1)) {
    cout << N << ":";
    for (int i = 2; i <= N; i++) {
      if (prime[i] && (N % i) == 0) {
        cout << " " << i;
      }
    }
    cout << endl;
  }
}

Measured memory_bytes: 944
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;

alias sread = () => readln.chomp();
alias Point2 = Tuple!(long, "y", long, "x");

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}

void minAssign(T, U = T)(ref T dst, U src)
{
    dst = cast(T) min(dst, src);
}

enum MOD = 10 ^^ 9 + 7;

void main()
{
    long N = lread();
    long[] inp;
    foreach (_; 0 .. 5)
        inp ~= lread();
    long tmp = inp.reduce!min();
    writeln(4 + ((N + tmp - 1) / tmp));
}


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

int main(void){
    int N;
    cin >> N;
    double x[N];
    string y[N];
    
    double total = 0;
    for(int i = 0 ; i < N ; i++){
        cin >> x[i] >> y[i];
        if(y[i] == "JPY"){
            total += x[i];
        }else{
            total += x[i] * 380000.0;
        }
    }
    cout << total << endl;
    return 0;
}

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

int main() {
    int N, M, Q;
    cin >> N >> M >> Q;
    vector<vector<int>> dp(N, vector<int>(N, 0));
    rep(i, M) {
        int L, R;
        cin >> L >> R;
        L--;
        R--;
        dp[L][R]++;
    }
    rep(L, N) rep(R, N - 1) dp[L][R + 1] += dp[L][R];

    rep(i,Q){
      int p,q;
      cin >> p >> q;
      p--;q--;
      ll ans =  0;
      for(int i=p;i<=q;i++) {
        ans += dp[i][q];
      }
      cout << ans << endl;
    }
}

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

int main(){
    int n, k;
    cin >> n >> k;
    vector<int> v(n);
    for(int i=0; i<n; i++) cin >> v[i];
    sort(v.begin(), v.end());
    int ans = 1e9;
    for(int i=0; i<=v.size()-k; i++){
        ans = min(ans, v[i+k-1] - v[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=3.14159265359;

int main() {
    ll N, Y;
    cin>>N>>Y;
    ll sen=-1, gosen=-1, man=-1;
    for(ll i=0;i<=N;++i){
        for(ll j=0;j<=N;++j){
            if(i+j>N) continue;
            if((Y-1000*i-5000*j)==10000*(N-i-j)){
                sen = i;
                gosen = j;
                man = N-i-j;
                break;
            }
        }
    }
    cout<<man<<" "<<gosen<<" "<<sen<<endl;
}



Measured memory_bytes: 256
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    from collections import Counter
    n = int(readline())
    a = list(map(int, readline().split()))
    q = int(readline())
    counter = Counter(a)
    res = sum(a)

    for i in range(q):
        b, c = map(int, readline().split())
        res -= counter[b] * b
        res += counter[b] * c
        counter[c] += counter[b]
        counter[b] = 0
        print(res)

if __name__ == '__main__':
    main()


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

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


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

#define Fast ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)
#define FO freopen("in.txt", "r", stdin)
#define FC freopen("out.txt", "w", stdout)
#define aise cout<<"aise"<<endl
#define pb push_back
#define mp make_pair
#define ll long long
#define mset(v, a) memset(v, a, sizeof(v))
#define pll pair< ll, ll >
#define pdd pair< double, double >
#define ff first
#define ss second
#define pi acos(-1.0)
#define mxN 2097162
#define inf 1e9
#define MOD 1000000007

int main()
{

    ll n;
    cin >> n;
    vector< ll > v(n+2, 0), v1(n+2, 0), v2(n+2, 0);
    for(ll i = 1; i <= n; i++) cin >> v[i];
    for(ll i = 1; i <= n; i++)
    {

        v1[i] = __gcd(v1[i-1], v[i]);
    }
    for(ll i = n; i >= 1; i--)
    {

        v2[i] = __gcd(v2[i+1], v[i]);
    }
    ll ans = 0;
    for(ll i = 1; i<= n; i++)
    {

        ll x = v1[i-1], y = v2[i+1];
        ll z = __gcd(x, y);
        ans = max(ans, z);
    }
    cout << ans;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
#include <string>
#include <cmath>
using namespace std;
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<ll> vll;
 
#define all(v) v.begin(),v.end()
#define test() int t;cin>>t;while(t--) 
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ff first
#define ss second
const ll mod = (ll)1e9 + 7;
const ll INF = -(ll)1e10;
ll power(ll x, ll a)
{
    if(a==0)return(1);
    ll z  = power(x, a/2);
    z = (z * z)%mod;
    if(a%2)z = (z * x)%mod;
    return(z);
}
int main()
{
    int n;
    cin>>n;
    vector<pair<ll, ll>> points(n);
    ll mx1 = INF, mx2 = INF, mn1 = -INF, mn2 = -INF;
    for(int i = 0; i<n; i++)
    {
        ll x, y;
        cin>>x>>y;
        mx1 = max(mx1, x+y);
        mn1 = min(mn1, x+y);
        mx2 = max(mx2, x-y);
        mn2 = min(mn2, x-y);
    }
    cout<<max(mx1-mn1, mx2 - mn2)<<endl;
}


Measured memory_bytes: 6428
import sys

N = int(input())
nums = list(map(int, input().strip().split()))
dp = [sys.maxsize]*N
dp[0] = 0

for i in range(N):
  for j in range(i + 1, min(N, i + 3)):
    dp[j] = min(dp[j], dp[i] + abs(nums[j] - nums[i]))
print(dp[-1])

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

public class Main {

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

        Scanner sc = new Scanner(System.in);
        ArrayList<Integer> dis = new ArrayList<Integer>();
        String judge;
        for(int i=0;i<5;i++) {
        	dis.add(Integer.parseInt(sc.next()));
        }
        int k = Integer.parseInt(sc.next());
        int max = Collections.max(dis);
        int min = Collections.min(dis);
        int flag = max - min;
        if(flag > k) {
        	System.out.println(":(");
        }else {
        	System.out.println("Yay!");
        }
	}
}


Measured memory_bytes: 21716
import collections
n=int(input())
a=list(map(int,input().split()))
a=collections.Counter(a)
b,c=[],[]
for t in a:
  if a[t]==1:
    b.append(t)
  else:
    c.append(t)
if len(b) == 0:
  print(0)
  exit()
b.sort()
bm = b[-1]
ok = [True]*(bm+1)

if len(c)>0:
  c.sort()
  for t in c:
    if t>=bm: continue
    if ok[t] == False: continue
    i = 1
    while i*t<=bm:
      ok[i*t]=False
      i+=1
for t in b:
  if ok[t] == False: continue
  i = 2
  while i*t<=bm:
    ok[i*t]=False
    i+=1
ans = 0
for t in b:
  if ok[t]:
    ans+=1
print(ans)  

Measured memory_bytes: 36792
def main():
    input = sys.stdin.readline
    try:
        a, b, x = map(int, input().split())
        def fn(n):
            if n == -1:
                return 0
            else:
                return n // x + 1
        print(fn(b) - fn(a-1))

    finally:
        input = None

import sys; sys.setrecursionlimit(50000)
if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,k,c,i,j,s,p,t;
  int arr[20],brr[20];
  cin>>n>>k;
  for(i=0;i<k;i++)
  {
    cin>>arr[i];
  }
  t=1000000;
  while(1)
  {
    p=n;
//    cout<<p<<endl;
    c=0;
    while(n>0)
    {
      brr[c++]=n%10;
      n=n/10;
    }
    n=p+1;
  //  cout<<n<<endl;
    for(i=c-1;i>=0;i--)
    {
      for(j=0;j<k;j++)
      {
        if(brr[i]==arr[j])
        {
        //  s=brr[i];
        // cout<<s<<endl;
        //  t=i;
        i=-2;
          break;
      //    break;
        }

      }
  //    cout<<i<<endl;
    }
    if(i==-1)
    {
          cout<<p<<endl;
          break;
    }
    else if(i==-2)
    {
  //  cout<<n<<endl;
    //  break;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#S = "RBRBGRBGGBBRRGBBRRRBGGBRBGBRBGBRBBBGBBB"# * 1000
#N = len(S)

N=int(input())
S=input()
r = len(S.replace("G", "").replace("B", ""))
g = len(S.replace("R", "").replace("B", ""))
b = N - r - g
 
ans = r * g * b
 
is_break = False
for i in range(N):
    for j in range(i, int((N+i)/2 + 1)):
        k = 2 * j - i
        if k < N:
            s = S[i] + S[j] + S[k]
            if ("R" in s) & ("G" in s) & ("B" in s):
                    ans -= 1

print(ans)


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

typedef long long ll;
#define all(x) (x).begin(), (x).end()  // sortなどの引数を省略
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define max3(x, y, z) max(x, max(y, z))
#define min3(x, y, z) min(x, min(y, z))

#ifdef _MSC_FULL_VER  //デバッグ出力
#define dout cout
#define debug() if (true)
#define check(x) std::cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) std::cout << "☆" << x << endl
#else
#define dout \
  if (false) cout
#define debug() if (false)
#define check(x) \
  if (false) cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) \
  if (false) cout << "☆" << x << endl
#endif

using namespace std;
int main(){ 
  vector<int> l(75000);
  for (int i = 1; i < 110; i++) {
    for (int j = 1; j < 110; j++) {
      for (int k = 1; k < 110; k++) {
        l[i*i+j*j+k*k+i*j+j*k+i*k]++;
      }
    }
  }
  int N;
  cin >> N;
  for ( int i = 1; i <=N; i++) {
    cout << l[i] << endl;
  }
}
/*
//よく使うやつ
int N;
cin >> N;
vector<int> list(N);
rep(i,N) {
  cin >> list[i];
}
//配列(スタックとしても使える)
vector<int> list;
list.at(i)
vector<vector<int>> list(10, vector<int>(10));
//ソート クイックだからO(NlogN)
sort(all(list));
sort(all(list), greater<int>());

//配列の内容表示
dout << "====listの内容====\n";
for (int edp = 0; edp < N; edp++) dout << list[edp] << endl;
dout << "====ここまで====\n";


//配列の最小最大(Nは要素数)
*min_element(all(c))
*max_element(all(c))

//a[0]からa[N]を逆順にする(計算量はO(N))
reverse(all(a));
//listの末尾に要素を追加
list.push_back(10);
//listの末尾から要素を削除
list.pop_back();
//空ですか？
list.empty()



//キュー(待ち行列)
//定義
queue<int> a;
//追加
a.push(x);
//取る
a.pop();
//チェック
a.front()
//サイズ
a.size()
//空ですか
a.empty()



//優先度付きキュー※全部計算量がO(NlogN)あるので注意
// int 型の要素を持ち、最も小さい値を取り出す形の priority_queue を定義
priority_queue<int, vector<int>, greater<int>> Q1;
// double 型の要素を持ち、最も大きい値を取り出す形の priority_queueを定義
priority_queue<double, vector<double>, less<double>> Q2;
//追加
a.push(x);
//取る
a.pop();
//一番小さいの教えて下さい
a.top()
//サイズ
a.size()
//空ですか
a.empty()



//部分文字列
//添字3から5文字
s.substr(3,5)
//添字3から全部
s.substr(3)

//入れ替え
swap(a,b);



// int 型の番地に string 型の変数を記録する場合（2^31 要素の
string型配列と同じような感じ） map<int, string> mp; for (auto itr =mp.begin();
itr != mp.end(); itr++) {
    //順番にマップを眺める。itr->firstでキー、itr->secondがバリュー
}

//ソート済みのaの中で初めてx以上になるインデックスを返す
lower_bound(all(a), x) - a

//next_permutation
do {
  //ここにパーテーションがくる
} while (next_permutation(s.begin(), s.end()));

//set
set<int> hoge;
hoge.insert(50);  //hogeに挿入。重複は無視される。
hoge.insert(20);  //内部は小さい順に並ぶ
hoge.erase(50);   //hogeから消し去る。
//40以上である最小の要素を指すイテレーターを返す。
//もちろんそんなものはないからEndが出力される
auto itr1 = Set.lower_bound(40);
if (itr1 == Set.end()) cout << "End" << endl;
else cout << (*itr1) << endl;

//pair
//たくさんつくる
vector<pair<int,string>> hoge(10);
//参照
hoge[0].first
sort(all(hoge), greater<pair<int, string>>());




*/


Measured memory_bytes: 3576
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x)(x).begin(), (x).end() // 昇順ソート
#define rall(v)(v).rbegin(), (v).rend() // 降順ソート
#define INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair < ll, ll >
#define F first
#define S second
const int MOD = 1000000007;
template < class T > bool chmax(T & a,const T & b) { if (a < b) { a = b; return true; } return false; }
template < class T > bool chmin(T & a,const T & b) { if (a > b) { a = b; return true; } return false; }
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main() {
    LL N;cin >> N;
    LL ans = 0;
    for(int i = 1;i <= N;i++){
        LL tmp = N/i;
        LL sum = tmp*(2*i+(tmp-1)*i)/2;
        ans += sum;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3512
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <set>
#include <map>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;

#define MAXN 3000
ll dp[MAXN][MAXN];

ll dfs(ll i, ll j){
  if(dp[i][j]!=-1) return dp[i][j];
  return dp[i][j] = max(dfs(i,i)-dfs(i+1,j),dfs(j,j)-dfs(i,j-1));
}

int main(){
  ll n;
  cin >> n;
  fill(dp[0],dp[n],-1);
  REP(i,n){
    cin >> dp[i][i];
  }
  cout << dfs(0,n-1) << endl;
  return 0;
}


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

int k,x,y,nowx,nowy,a=-1;
struct r2{int x,y;};
vector<r2> ans;
void move(int x,int y){
  nowx+=x;nowy+=y;
  ans.push_back({nowx,nowy});
}

int main(){
  cin>>k>>x>>y;
  int X=abs(x),Y=abs(y); if(X>Y)swap(X,Y);

  if( !(k&1) && ((X+Y)&1) ) {cout<<-1<<endl;return 0;}
  if(X+Y==k){cout<<1<<endl<<x<<" "<<y<<endl;return 0;}

  for(int i=k*2-(X+Y);a<0;i+=k) if(!(i&1)) a=i/2;

  while(a>=k)move(0,-k),a-=k;
  move(-a,k-a);
  while(nowx+k<=X)move(k,0);
  while(nowy+k<=Y)move(0,k);
  if(nowx!=X||nowy!=Y)ans.push_back({X,Y});

  cout<<ans.size()<<endl;
  for(r2 p:ans){
    int ansx=p.x,ansy=p.y;
    if(abs(x)>abs(y))swap(ansx,ansy);
    if(x<0)ansx*=-1; if(y<0)ansy*=-1;
    cout<<ansx<<" "<<ansy<<endl;
  }
}


Measured memory_bytes: 5244
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ii pair<int,int>
#define VI vector<int>
#define MAXN 100010
VI edge[MAXN], delta[MAXN];
int xv[MAXN];
bool visited[MAXN];
void dfs(int i, int x) {
	visited[i] = true;
	xv[i] = x;
	int k = edge[i].size();
	for (int j=0; j<k; j++) {
		int v = edge[i][j],d = delta[i][j];
		if (!visited[v]) {
			dfs(v, x+d);
		}
	}
}
int main() {
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	int n,m;cin >> n >> m;
	int l[m+1],r[m+1],d[m+1];
	for (int i=1; i<=n; i++) {
		visited[i] = false;
		xv[i] = 0;
	}
	for (int i=1; i<=m; i++) {
		cin >> l[i] >> r[i] >> d[i];
		edge[l[i]].push_back(r[i]);
		edge[r[i]].push_back(l[i]);
		delta[l[i]].push_back(d[i]);
		delta[r[i]].push_back(-d[i]);
	}
	for (int i=1; i<=n; i++) {
		if (!visited[i]) {
			dfs(i, 0);
		}
	}
	bool valid = true;
	for (int i=1; i<=m; i++) {
		if ((xv[r[i]]-xv[l[i]]) != d[i]) {
			valid = false;
		}
	}
	if (valid) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 18944
#include<iostream>
#include<cstdio>
#include <stdio.h>
#include<algorithm>
#include<cstring>
#include <string>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<map>
#include<vector>
#include<bits/stdc++.h>
#include <set>
#define ll   long long
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#define inf 0x3f3f3f3f
#define pi 3.1415926535898
#define mod 998244353
#define N 1000010
using namespace std;

int main()
{
    int n,m;
    cin>>n>>m;
    int l=1,r=m+1;
    while(l<r)
    {
        cout<<l++<<" "<<r--<<endl;
    }
    l=m+2,r=2*m+1;
    while(l<r)
    {
        cout<<l++<<" "<<r--<<endl;
    }
    return 0;
}


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

vector<ll>E[100000];
ll c[100000], cost[100000];
ll ans[100000];
bool flag[100000];

int main() {
	ll n, m, k, s, p, q; scanf("%lld%lld%lld%lld%lld%lld", &n, &m, &k, &s, &p, &q);
	fill(cost, cost + n, p);
	rep(i, k) {
		scanf("%lld", &c[i]); c[i]--;
		cost[c[i]] = -1;
	}
	rep(i, m) {
		ll a, b; scanf("%lld%lld", &a, &b);
		E[--a].push_back(--b);
		E[b].push_back(a);
	}
	queue<P>que;
	rep(i, k) {
		memset(flag, 0, sizeof(flag));
		que.push(P(c[i], 0));
		while (!que.empty()) {
			P p = que.front(); que.pop();
			ll f = p.first;
			rep(j, E[f].size()) {
				if (flag[E[f][j]] || cost[E[f][j]] == -1)continue;
				cost[E[f][j]] = q;
				flag[E[f][j]] = true;
				if (p.second + 1 < s)
					que.push(P(E[f][j], p.second + 1));
			}
		}
	}
	cost[n - 1] = 0;
	priority_queue<P, vector<P>, greater<P>>pque;
	memset(ans, 0x7f, sizeof(ans));
	ans[0] = 0;
	pque.push(P(0, 0));
	while (!pque.empty()) {
		P p = pque.top(); pque.pop();
		ll f = p.first; s = p.second;
		if (ans[f] < s)continue;
		rep(i, E[f].size()) {
			ll j = E[f][i];
			if (cost[j] == -1)continue;
			if (ans[j] > s + cost[j]) {
				ans[j] = s + cost[j];
				pque.push(P(j, s + cost[j]));
			}
		}
	}
	printf("%lld\n", ans[n - 1]);
}

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

int main() {
  int n, i;
  cin >> n;
  vector<int> v(n);
  for (i = 0; i < n; i++)
    cin >> v[i];
  sort(v.begin(), v.end());
  double sum = (v[0]+v[1])/2.0;
  for (i = 2; i < n; i++)
    sum = (v[i]+sum)/2;
  cout << sum << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define INF 1 << 30
#define N 101
int main(void){
	int n,m[N][N],tmp[N];
	cin >> n;
	for(int i = 1 ; i <= n ; i++){
		cin >> tmp[i-1] >> tmp[i];
	}
	for(int i = 1 ; i <= n ; i++){
		m[i][i] = 0;
	}
	for(int j = 2; j<= n ; j++){
		for(int i = 1; i <= n- j + 1; i++){
			int k = i + j -1;
			m[i][k] = INF;
			for(int l = i; l <= k - 1 ; l++){
				m[i][k] = min(m[i][k],m[i][l] + m[l+1][k]+tmp[i-1] * tmp[l] * tmp[k]);
			}
		}
	}

	cout << m[1][n] << endl;

}

Measured memory_bytes: 1200
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int h, w, k;
	cin >> h >> w >> k;
	vector<string> s(h);
	vector<int> ids(h);
	int id = 0;
	rep(i,h){
		cin >> s[i];
		bool flag = false;
		rep(j,w){
			if(s[i][j] == '#') flag = true;
		}
		if(flag) ids[i] = ++id;
		else if(id == 0) ids[i] = 1;
		else ids[i] = id;
	}
	int num = 1;
	vector<vector<int>> a(h, vector<int>(w));
	rep(i,h){
		int b = i;
		while(b+1 < h && ids[b+1] == ids[i]) ++b;
		bool first = true;
		rep(j,w){
			bool flag = false;
			for(int l = i; l <= b; ++l){
				if(s[l][j] == '#') flag = true;
			}
			if(flag){
				if(first) first = false;
				else ++num;
			}
			for(int l = i; l <= b; ++l){
				a[l][j] = num;
			}
		}
		i = b;
		++num;
	}
	rep(i,h){
		rep(j,w) cout << a[i][j] << " ";
		cout << endl;
	}
	return 0;
}


Measured memory_bytes: 3840
a=list(input())
b=list(input())
c=list(input())
cur='a'
ai=-1
bi=-1
ci=-1
while ai<len(a) and bi<len(b) and ci<len(c):
    if cur=='a':
        ai+=1
        if ai<len(a):
            cur=a[ai]
    elif cur=='b':
        bi+=1
        if bi<len(b):
            cur=b[bi]
    else:
        ci+=1
        if ci<len(c):
            cur=c[ci]
if ai==len(a):
    print('A')
elif bi==len(b):
    print('B')
else:
    print('C')

Measured memory_bytes: 3064
#include "bits/stdc++.h"
using namespace std;
int main(){
	int N;
	cin >> N;
	vector<int> V(N);
	vector<int> C(N);
	for(int x = 0;x<N;x++){
		cin >> V[x];
	}
	for(int x = 0;x<N;x++){
		cin >> C[x];
	}
	vector<int> diff(N);
	for(int x= 0;x<N;x++){
		diff[x] = V[x]-C[x];
	}
	sort(diff.begin(), diff.end());
	int sum = 0;
	for(auto x : diff){
		if(x>0)sum+=x;
	}
	cout << sum;
	

}

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

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

    vector<vector<bool>> t = {{0, 0}, {0, 1}, {1, 0}, {1, 1}};// 0 = S, 1 = W
    for(int i=0; i<4; i++){
        for(int j=1; j<=n-2; j++){
            if(s[j] == 'o' && t[i][j] == 0) t[i].push_back(t[i][j-1]);
            if(s[j] == 'o' && t[i][j] == 1) t[i].push_back(!t[i][j-1]);
            if(s[j] == 'x' && t[i][j] == 0) t[i].push_back(!t[i][j-1]);
            if(s[j] == 'x' && t[i][j] == 1) t[i].push_back(t[i][j-1]);
        }
        bool flag1 = false, flag2 = false;
        if(s[n-1] == 'o' && t[i][n-1] == 0 && t[i][n-2] == t[i][0]) flag1 = true;
        if(s[n-1] == 'o' && t[i][n-1] == 1 && t[i][n-2] != t[i][0]) flag1 = true;
        if(s[n-1] == 'x' && t[i][n-1] == 0 && t[i][n-2] != t[i][0]) flag1 = true;
        if(s[n-1] == 'x' && t[i][n-1] == 1 && t[i][n-2] == t[i][0]) flag1 = true;

        if(s[0] == 'o' && t[i][0] == 0 && t[i][n-1] == t[i][1]) flag2 = true;
        if(s[0] == 'o' && t[i][0] == 1 && t[i][n-1] != t[i][1]) flag2 = true;
        if(s[0] == 'x' && t[i][0] == 0 && t[i][n-1] != t[i][1]) flag2 = true;
        if(s[0] == 'x' && t[i][0] == 1 && t[i][n-1] == t[i][1]) flag2 = true;

        if(flag1 == true && flag2 == true){
            for(int j=0; j<n; j++){
                if(t[i][j] == 0) cout << "S";
                if(t[i][j] == 1) cout << "W";
            }cout << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　 |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/














int N; char P[101010];
//---------------------------------------------------------------------------------------------------
char M(char x, char y) {
    if (x == 'T' and y == 'F') return 'F';
    return 'T';
}
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N;
    rep(i, 0, N) cin >> P[i];

    char p = P[0];
    rep(i, 1, N) p = M(p, P[i]);
    cout << p << endl;
}


Measured memory_bytes: 3200
import java.util.*

fun main(args: Array<String>) {
    val argList = Scanner(System.`in`)

    val n = argList.nextLine().toInt()

    val music = mutableMapOf<String, Int>()
    val musicOrder = mutableListOf<String>()

    (1..n).forEach {
        val row = argList.nextLine().split(" ")
        music[row[0]] = row[1].toInt()
        musicOrder.add(row[0])
    }

    val x = argList.nextLine()

    val listenIndex = musicOrder.indexOf(x)
    val musicInSleeping = musicOrder.filterIndexed { index, s ->
        index > listenIndex
    }

    val seconds = musicInSleeping.mapNotNull {
        music[it]
    }

    println(seconds.sum())
}

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

int main() {

	int N;
	cin >> N;
	int aa = 0;
	vector<int> A(N, 0);
	for (int i = 0; i < N; i++) {
		int a;
		cin >> a;
		A[i] = a;
		aa ^= a;
	}
	cout << (aa ^ A[0]);
	for (int i = 1; i < N; i++) {
		cout << " " << (aa ^ A[i]);
	}
	cout << endl;

	return(0);
}


Measured memory_bytes: 3956
# frozen_string_literal: true

N = gets.to_i
graph = Array.new(N) { [] }
list = []

(N - 1).times do
  a, b = gets.split.map!(&:to_i).map!(&:pred)
  graph[a] << b
  graph[b] << a
  list << [a, b]
end

queue = [0]
prev = [0]
edge = {}
k = 1

while queue.any?
  v = queue.shift
  color = 1

  graph[v].each do |i|
    next if prev[i]

    color += 1 if color == prev[v]
    k = color if k < color
    queue << i
    edge[[v, i]] = edge[[i, v]] = prev[i] = color
    color += 1
  end
end

puts k
list.each { |i| puts edge[i] }

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

int f(int x){
  if(x == 0 || x == 1) return 0;
  
  return x * (x - 1)/2;
}

  
int main(){
  int n, m;
  cin >> n >> m;
  
  cout << f(n) + f(m) << endl;
  return 0;
}

Measured memory_bytes: 3552
#include <bits/stdc++.h>
#define INF 1e9
#define f first
#define s second
using namespace std;
typedef pair <int,int> P;
int dp[2][100010];

int main(){
  int n,m,hp[101];

  while(cin>>n,n){
  for(int i=0;i<n;i++) cin>>hp[i];

  vector <P> mg[2];  
  cin>>m;
  for(int i=0,cost,dam;i<m;i++){
    string name,type;
    cin>>name>>cost>>type>>dam;
    mg[type=="All"].push_back(P(dam,cost));
  }


  for(int i=0;i<2;i++)for(int j=1;j<100010;j++)dp[i][j]=INF;
 
  for(int k=0;k<2;k++)
    for(int i=0;i<mg[k].size();i++)
      for(int j=mg[k][i].f;j<100000+mg[k][i].f;j++)
	dp[k][min(100000,j)]=min(dp[k][min(100000,j)],dp[k][min(100000,j-mg[k][i].f)]+mg[k][i].s);
		
  
  for(int i=0;i<2;i++)
    for(int j=100000;j>=0;j--)
      dp[i][j]=min(dp[i][j],dp[i][j+1]);

long long ans=INF;
  for(int i=0;i<=100000;i++){
    long long cost=dp[1][i];
    for(int j=0;j<n;j++)cost+=dp[0][max(0,hp[j]-i)];
    ans=min(ans,cost);
 }
  cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 1996
while(True):
    a,op,b=input().split()
    a=int(a)
    b=int(b)
    if(op=="?"):
        break
    elif(op=="+"):
        print(a+b)
    elif(op=="-"):
        print(a-b)
    elif(op=="*"):
        print(a*b)
    elif(op=="/"):
        print(a//b)


Measured memory_bytes: 5592