akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vb = vector<bool>;
using vs = vector<string>;
using vvi = vector<vi>;
using vp = vector<pii>;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(a) (int)((a).size())
#define all(a) (a).begin(), (a).end()
#define each(x, a) for (auto&& x : (a))
#define _overload3(_1, _2, _3, name, ...) name
#define rep1(n) rep2(_, n)
#define rep2(i, n) rep3(i, 0, n)
#define rep3(i, a, n) for (int i = (a), i##_len = (n); i < i##_len; ++i)
#define rep(...) _overload3(__VA_ARGS__, rep3, rep2, rep1)(__VA_ARGS__)
constexpr int inf = (1LL<<31) - 1;
constexpr int mod = 1e9 + 7;
constexpr double eps = 1e-10;
const double pi = acos(-1.0);
constexpr int dx[] = {1, 0, -1, 0};
constexpr int dy[] = {0, 1, 0, -1};
template<class T> constexpr void print(const T& t) { cout << t << "\n"; }
template<class T, class U> constexpr bool chmax(T& a, const U& b) { if (a < b) a = b; return a < b; }
template<class T, class U> constexpr bool chmin(T& a, const U& b) { if (a > b) a = b; return a > b; }
template<class T, class U> istream& operator>>(istream& is, pair<T, U>& p) { is >> p.fi >> p.se; return is; }
template<class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p) { os << p.fi << " " << p.se; return os; }
template<class T> istream& operator>>(istream& is, vector<T>& v) { each(e, v) is >> e; return is; }
template<class T> ostream& operator<<(ostream& os, const vector<T>& v) { each(e, v) os << e << " "; return os; }
struct Init { Init() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); }} init;


int main() {
    int n, m;
    cin >> n >> m;
    dsu d(n);
    rep(m) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        d.merge(a, b);
    }
    set<int> s;
    rep(i, n) {
        s.insert(d.leader(i));
    }
    print(max(0,sz(s) - 1));
}


Measured memory_bytes: 7548
#include <stdio.h>

int main(void) {
	int A, B, C;
	
	scanf("%d %d %d", &A, &B, &C);
	
	for (int i = 1; i <= B; i++) {
		if (i * A % B == C) {
			printf("YES");
			return 0;
		}
	}
	printf("NO");
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define N 2005
#define INF 1000000005
#define INFLL (long long)1e18
#define PI 3.1415926535897
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define IN(a) cin>>(a)
#define OUT(a) cout<<(a)<<endl
typedef pair<int,int> P;
const int MAX = 1000005;
const int MOD = 1000000007;
int main(){
    int n;
    cin>>n;
    vector<int>a(n),b(n);
    REP(i,n){
        cin>>a[i];
        cin>>b[i];
    }
    sort(ALL(a));
    sort(ALL(b));
    int ans=0;
    if(n%2==0){
        ans=b[n/2]+b[n/2-1]-a[n/2]-a[n/2-1]+1;
    }else{
        ans=b[n/2]-a[n/2]+1;
    }
    OUT(ans);
    return 0;
}


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

using namespace std;
int n;
int a[22][22];
int d[23][1<<22];
const long long mod=1e9+7;
long long d__p(int i,int mask)
{
    if(i==n+1)
    {
        return d[i][mask]=1;
    }
    if(d[i][mask]!=-1)
        return d[i][mask];
    long long res=0;
    for(int j=1;j<=n;j++){
        if((!(mask &(1<<j)))&&a[i][j]==1)
        {
            res+=d__p(i+1, mask^(1<<j) );
            res%=mod;
        }
    }
    return d[i][mask]=res;
}
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
            cin>>a[i][j];
    }
    memset(d,-1,sizeof d);
    cout<<d__p(1,0);
    return 0;
}


Measured memory_bytes: 377088
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;


int main() {
  int a;
  cin >> a;
  if (a==1){
    cout << "Hello World" << endl;
  }
  else {
    int f,g;
    cin >> f >> g;
    cout << f+g << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;

int main(){
    int N;
    cin >> N;
    vector<double> fl;
    double a;
    double av=0;
    for(int i=0;i<N;i++){
        cin >> a;
        fl.push_back(a);
        av+=a;
    }
    av/=N;
    for(int i=0;i<N;i++){
        fl[i]=fabs(av-fl[i]);
    }
    double mi=1000,num=0;
    for(int i=0;i<N;i++){
        if(mi>fl[i]){
            mi=fl[i];
            num=i;
        }
    }
    cout << num << endl;

}

Measured memory_bytes: 256
import java.util.Scanner;

class Main{

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        final int N = sc.nextInt();
        final int Y = sc.nextInt();
        int x = 0;
        int y = 0;
        int z = 0;
      
            for ( int i = 0; i <= N; i++ ){
                for ( int j = 0; j <= N - i; j++ ){
                    int k = N - i - j;
                        int sum = (10000*i) + (5000*j) + (1000*k);
                        if( sum == Y ){
                            if( i + j + k == N ){
                                x = i;
                                y = j;
                                z = k;
                                System.out.println(x + " " + y + " " + z);
                                System.exit(0);
                            }
                        }else{
                            x = -1;
                            y = -1;
                            z = -1;
                        }       
                }    
            }
            System.out.println(x + " " + y + " " + z);
    }
}


Measured memory_bytes: 21972
#include <iostream>

using namespace std;

bool solve(int N, int A) {
    int Num = N % 500;
    if (Num == 0) return true;
    if (Num > A) {
        return false;
    } else {
        return true;
    }
}

int main() {
    int N, A;

    cin >> N >> A;

    if (solve(N, A)) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
import math


def diff(xi, xj, yi, yj):
    x = (abs(xi - xj)) ** 2
    y = (abs(yi - yj)) ** 2
    return (x + y) ** 0.5


a, b, h, m = map(int, input().split())

# a=hours, b=minutes, h時ｍ分
a_theta = 30 * h + 0.5 * m
b_theta = 6 * m
ax = math.cos(math.radians(a_theta)) * a
ay = math.sin(math.radians(a_theta)) * a
bx = math.cos(math.radians(b_theta)) * b
by = math.sin(math.radians(b_theta)) * b

ans = diff(ax, bx, ay, by)
print(ans)

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

int main() {
	int N;
	int t[110000],x[110000],y[110000];
	cin >> N;
	t[0]=x[0]=y[0]=0;
	for (int i =0;i<N;i++) cin>>t[i+1]>>x[i+1]>>y[i+1];
	
	bool can = true;
	for(int i=0;i<N;i++) {
	    int dt=t[i+1]-t[i];
	    int dist=abs(x[i+1]-x[i])+abs(y[i+1]-y[i]);
	    if(dist>dt) can = false;
	    if(dist%2!=dt%2) can=false;
	}
	
	if(can) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define PRINT(x) cout<<(x)<<endl
#define INF 1000000000000 // 10^12
#define MOD 1000000007 // 10^9+7
#define PB push_back
#define MP make_pair

const int MAX_N = 100, MAX_W = 10000;

int N, W, v[MAX_N], w[MAX_N], dp[MAX_N+1][MAX_W+1];

int main() {
    cin >> N >> W;
    REP(i, N) cin >> v[i] >> w[i];
    REP(i, N+1) {
        REP(j, W+1) dp[i][j] = 0;
    }
    REP(i, N) {
        REP(j, W+1) {
            dp[i+1][j] = max(dp[i+1][j], dp[i][j]);
            if (j - w[i] >= 0) dp[i+1][j] = max(dp[i+1][j], dp[i][j - w[i]] + v[i]);
        }
    }
    PRINT(dp[N][W]);
    return 0;
}


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

using namespace std;

int solve(int iL, int iR, int nL, int nR, int t)
{
    if (iL >= 5 && iR >= 5) return 2;
    if (nL >= 5 && nR >= 5) return 1;
    
    int res = (t == 0 ? 2 : 1);
    if (t == 0) {
        if (iL < 5) {
            if (nL < 5) res = min(res, solve(iL, iR, iL + nL, nR, 1));
            if (nR < 5) res = min(res, solve(iL, iR, nL, iL + nR, 1));
        }
        if (iR < 5) {
            if (nL < 5) res = min(res, solve(iL, iR, iR + nL, nR, 1));
            if (nR < 5) res = min(res, solve(iL, iR, nL, iR + nR, 1));
        }
    } else {
        if (nL < 5) {
            if (iL < 5) res = max(res, solve(iL + nL, iR, nL, nR, 0));
            if (iR < 5) res = max(res, solve(iL, iR + nL, nL, nR, 0));
        }
        if (nR < 5) {
            if (iL < 5) res = max(res, solve(iL + nR, iR, nL, nR, 0));
            if (iR < 5) res = max(res, solve(iL, iR + nR, nL, nR, 0));
        }
    }
    return res;
}

int main()
{
    int iL, iR, nL, nR;
    cin >> iL >> iR >> nL >> nR;
    cout << (solve(iL, iR, nL, nR, 0) == 1 ? "ISONO" : "NAKAJIMA") << endl;
    return 0;
}

Measured memory_bytes: 3104
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
 
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    ll ans1 = a * c;
    ll ans2 = b * d;
    ll ans3 = b * c;
    ll ans4 = a * d;
 
    ll largest= (ans1>ans2)?(ans1>ans3)?(ans1>ans4)?ans1:ans4:(ans3>ans4)?ans3:ans4:(ans2>ans3)?
            (ans2>ans4)?ans2:ans4:(ans3>ans4)?ans3:ans4;
    cout << largest << "\n";
}
 
 
 
 
 
 

Measured memory_bytes: 3664
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int x, y; cin >> x >> y;
  V<> a(13);
  a[4] = a[6] = a[9] = a[11] = 1;
  a[2] = 2;
  if (a[x] == a[y]) {
    cout << "Yes" << '\n';
  } else {
    cout << "No" << '\n';
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>

using namespace std;

#define int long long

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);

 	int n;
 	cin >> n;
 	vector<int> a(n);
 	int ans = 0;
 	for (auto &t : a) {
 		cin >> t;
 	}
 	for (int i = 0; i < n; i++) {
 		ans += a[i] / 2;
 		a[i] %= 2;
 		if (i + 1 < n) {
 			int cnt = min(a[i], a[i + 1]);
 			ans += cnt;
 			a[i] -= cnt;
 			a[i + 1] -= cnt;
 		}
 	}
 	cout << ans << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

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

using ipair = pair<ll,ll>;

ll INF = 1e16+7;

bool operator>(const ipair a,const ipair b){return a.first > b.first;}

int mod = 1e9+7;

int main(){

  int K;
  cin >> K;
  int A, B;
  cin >> A >> B;
  for(int i=A; i<=B; i++){
    if(i%K==0){
      cout << "OK" << endl;
      return 0;
    }
  }
  cout << "NG" << endl;

  return 0;
}


Measured memory_bytes: 3564
A = [list(map(int, input().split())) for _ in range(3) ]
X = [[0]*3 for _ in range(3)]
N = int(input())
for _ in range(N):
    b = int(input())
    for i in range(3):
        for j in range(3):
            if A[i][j]==b: X[i][j]=1

def bingo():
    print('Yes')
    exit()

for i in range(3):
    s = 0
    for j in range(3): s += X[i][j]
    if s==3:
        bingo()
        
for j in range(3):
    s = 0
    for i in range(3): s += X[i][j]
    if s==3:
        bingo()

if X[0][0]+X[1][1]+X[2][2]==3: bingo()
if X[0][2]+X[1][1]+X[2][0]==3: bingo()

print('No')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    int n;
    cin >> n;
    ll ans = 0;
    for (int i = 1; i <= n; i++)
    {
        if (i % 3 != 0 && i % 5 != 0)  ans += i; 
    }
    cout << ans;
    return 0;
    
}

Measured memory_bytes: 3592
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
//#pragma GCC target("avx,tune=native")
#include<bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
const int inf=0x3f3f3f3f;
const double eps=1e-6;
const int mod=1000000007;
typedef long long ll;
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
int modpow(int x,int y,int md=mod){if(y==0)return 1;int ret=modpow(x,y>>1,md);ret=(ll)ret*ret%md;if(y&1)ret=(ll)ret*x%md;return ret;}
bitset<1000005>state,segtree[66];
bitset<10005>dp[2020];
int pos[2020];
string s[2020];
int n,k;
char get(){
	int now=1;
	while(now<32){
		if((state&segtree[now<<1]).none())now=now*2+1;
		else now*=2;
	}
	return 'a'+now-32;
}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	cin>>n>>k;
	for(int i=0;i<n;i++)cin>>s[i];
	dp[n].set(0);
	for(int i=n-1;i>=0;i--){
		dp[i]=dp[i+1]|(dp[i+1]<<((int)s[i].size()));
	}
	string tmp="";
	for(int i=0;i<n;i++){
		pos[i]=tmp.size();
		tmp+=s[i];
	}
	pos[n]=tmp.size();
	for(int i=0;i<64;i++)segtree[i].reset();
	for(int i=0;i<tmp.size();i++){
		segtree[tmp[i]-'a'+32].set(i);
	}
	for(int i=31;i>=1;i--)segtree[i]=segtree[i<<1]|segtree[i<<1|1];
	state.reset();
	state[0]=1;
	string ans="";
	for(int i=0;i<k;i++){
		for(int j=0;j<n;j++)if(state[pos[j]])state.set(pos[j+1]);
		for(int j=0;j<n;j++)if(k-i-(int)s[j].size()<0||!dp[j+1][k-i-(int)s[j].size()])state.reset(pos[j]);
		char c=get();
		ans.push_back(c);
		state&=segtree[32+c-'a'];
		state<<=1;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 13196
from sys import *
from collections import deque
H, W = map(int, stdin.readline().split())
personY, personX = map(int, stdin.readline().split())
gH, gW = map(int, stdin.readline().split())

grid = [input() for x in range(H)]
visited = [[10**10] * W for i in range(H)]
options = deque([[personY-1, personX-1]])

visited[personY-1][personX-1] = 0
while(options):
    y,x = options.popleft()
    if y+1 < H and  grid[y+1][x] == ".":
        if visited[y+1][x] > visited[y][x]:
            options.appendleft((y+1, x))
            visited[y+1][x] = visited[y][x]

    if  y-1 >= 0 and grid[y-1][x] == ".":
        if visited[y-1][x] > visited[y][x]:
            options.appendleft((y-1, x))
            visited[y-1][x] = visited[y][x]

    if x+1 < W and grid[y][x+1] == ".":
        if visited[y][x+1] > visited[y][x]:
            options.appendleft((y, x+1))
            visited[y][x+1] = visited[y][x]

    if x-1 >= 0 and grid[y][x-1] == ".":
        if visited[y][x-1] > visited[y][x]:
            options.appendleft((y, x-1))
            visited[y][x-1] = visited[y][x]
   #-------------------------------------------
    for Y,X in [(2,-2),(2,-1),(2,0),(2,1),(2,2), (1,-2),(1,-1),(1,1),(1,2), (0,-2),(0,2), (-1,-2),(-1,-1),(-1,1),(-1,2), (-2,-2),(-2,-1),(-2,0),(-2,1),(-2,2)]:
       if x+X >= 0 and x+X < W and y+Y >= 0 and y+Y < H and grid[y+Y][x+X] == ".":
           if visited[y+Y][x+X] > visited[y][x] +1:
               options.append((y+Y, x+X))
               visited[y+Y][x+X] = visited[y][x]+1

print(-1 if visited[gH-1][gW-1] == 10**10 else visited[gH-1][gW-1] )


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

int main() {
  long long sum=0;
  string S;
  cin >> S;
  for(int i=0; i<S.size(); i++){
    sum +=  S[i]-'0';
    sum = sum%9;
  }
  if(sum%9 == 0){
    cout << "Yes" << endl;
    return 0;
  }
  cout << "No" << endl;
}


Measured memory_bytes: 3752
mohu=input().split()
mohu1=list(map(int,mohu))
donatsu=[]
for i in range(mohu1[0]):
    donatsu.append(int(input()))
donatsu.sort()
ichijyun=0
for k in range(mohu1[0]):
    ichijyun+=donatsu[k]
tsuikakosu=(mohu1[1]-ichijyun)/donatsu[0]
print(int(tsuikakosu)+mohu1[0])

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

using namespace std;

int main(){

	int L,M,N;
	while(cin>>L&&L!=0){
		int ac=-1;
		int sum=0;
		bool f=false;
		for(int i = 0; i < 12; i++){
			int a,b;
			cin>>a>>b;
			sum+=a-b;
			if(sum>=L&&!f){
				ac=i;
				f=true;
			}
		}
		if(ac!=-1)
			cout<<ac+1<<endl;
		else
			cout<<"NA"<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <cmath>
#include <algorithm>
#include <bitset>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <cstdlib>
#include <stack>
#include <random>

using namespace std;

typedef long long ll;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
        cin >> a[i];
    sort(a.begin(), a.end());
    int k = 0;
    for (int x : a)
        if (x <= m)
        {
            m -= x;
            k += 1;
        }
    if (m != 0)
    {
        if (k == n)
        {
            k--;
        }
    }
    cout << k;
    return 0;
}


Measured memory_bytes: 888
#include <iostream>
#include<math.h>
#include <vector>
#include <numeric>

using namespace std;


int main() {

    int N;
    cin >> N;

    vector<int> a(N);
    for (int i = 0; i < N; ++i) {
        cin >> a[i];
    }

    vector<int> counter(N);
    for (int i = 0; i < N; ++i) {
        int num = a[i];
        int count = 0;
        do {
            if (num % 2 != 0) {
                break;
            }

            num = num / 2;
            ++count;
        } while (true);
        counter[i] = count;
    }
    
    cout << accumulate(counter.begin(), counter.end(), 0) << endl;
    return 0;
}


Measured memory_bytes: 384
using System;
using System.Linq;

public class Program
{
    static void Main()
    {
        var str = Console.ReadLine().ToCharArray();
        var zero = str.Where(x => x == '0').Count();
        var one = str.Where(x => x == '1').Count();
        Console.WriteLine(Math.Min(zero, one) * 2);
    }
}


Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cout.tie(0);
cin.tie(NULL);
int n,m; cin>>n>>m;
int a[n];
for(int i=0;i<n;i++)
a[i]=10;
if(n==1&&m==0)
{
	cout<<0; return 0;
}
while(m--)
{
	int s,c;
	cin>>s>>c;
	if(a[s-1]!=10&&a[s-1]!=c)
	{
		cout<<-1; return 0;
	}
	a[s-1]=c;
}
if(a[0]==10)
cout<<1;
else if(a[0]==0&&n>=2)
{
		cout<<-1; return 0;
}
else
cout<<a[0];
for(int i=1;i<n;i++)
{
	if(a[i]==10)
	{
		a[i]=0;
	}
	cout<<a[i];
}
}


Measured memory_bytes: 256
#include <iostream>
#include<string>

using namespace std;

string S;

int main(void) {
	cin >> S;

	bool ans = true;

	if (S[0] != 'A') { ans = false; }

	int count = 0;

	for (int i = 2; i <(int) S.size()-1; i++) {
		if (S[i] == 'C') { count++; }
	}

	if (count != 1) { ans = false; }

	for (int i = 1; i < (int)S.size(); i++) {
		if (S[i] == 'C') { continue; }
		if (islower(S[i])) {}
		else { ans = false; }
	}

	if (ans == true) { cout << "AC" << endl; }
	else { cout << "WA" << endl; }


	//system("pause");
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>

using namespace std;

int main()
{
	int n, m;
	int a, b;
	scanf("%d %d", &n, &m);
	vector<int> v[100000];
	for(int i=0; i<m; i++){
		scanf("%d %d", &a, &b);
		a--;
		b--;
		v[a].push_back(b);
		v[b].push_back(a);
	}
	deque<int> path;
	set<int> st;
	path.push_back(0);
	st.insert(0);
	while(1){
		int x=path.back();
		int e=0;
		for(int i=0; i<v[x].size(); i++){
			if(st.find(v[x][i])==st.end()){
				path.push_back(v[x][i]);
				st.insert(v[x][i]);
				e=1;
				break;
			}
		}
		if(e==0) break;
	}
	while(1){
		int x=path.front();
		int e=0;
		for(int i=0; i<v[x].size(); i++){
			if(st.find(v[x][i])==st.end()){
				path.push_front(v[x][i]);
				st.insert(v[x][i]);
				e=1;
				break;
			}
		}
		if(e==0) break;
	}
   printf("%d\n", path.size());
	for(auto itr=path.begin(); itr!=path.end(); itr++){
		int x=*itr;
		x++;
		printf("%d ", x);
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 11392
#include <iostream>
#include <vector>
#include <functional>
#include <algorithm>
#include <numeric>
#include <string>
#include <map>
#include <queue>
#include <bitset>
#include <sstream>
#include <iomanip>

using namespace std;
typedef long long ll;


int main(){
        ll n, m;
        cin >> n >> m;
        cout << (n-1)*(m-1);
}


Measured memory_bytes: 256
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;
 
signed main() {
    int N; cin >> N;
    string s; cin >> s;

    vector<int> cntW(N+1);
    for(int i=0; i<N; i++) {
        cntW[i+1] = cntW[i] + (s[i] == '.');
    }

    int ans = INF;
    for(int i=0; i<=N; i++) {
        int A = i - cntW[i];
        int B = cntW[N] - cntW[i];
        chmin(ans, A+B);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 2180
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<iomanip>
#include<bitset>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

const int MAX = 1000005;
const int MOD = 1000000007;

ll dp[2][MAX];
// dp[i][j] は i番目までで jを作れる時の必要最小個数
ll odp[2][MAX];

int main(){
  vector<ll> a;
  while(1){
    ll c; cin >> c;
    if(c == 0) break;
    else a.pb(c);
  }
  // dp table初期化
  rep(i,2) rep(j,MAX) dp[i][j] = INF;
  dp[0][0] = 0;
  rep(i,2) rep(j,MAX) odp[i][j] = INF;
  odp[0][0] = 0;
  // dp 作成
  repn(i,200){
    ll num = i * (i + 1) * (i + 2) / 6;
    if(num > MAX) break;
    rep(j,MAX){
      if(j < num) dp[1][j] = dp[0][j];
      else dp[1][j] = min(dp[0][j] ,dp[1][j - num] + 1);
    }
    rep(j,MAX) dp[0][j] = dp[1][j];
    if(num % 2 == 1){
      rep(j,MAX){
        if(j < num) odp[1][j] = odp[0][j];
        else odp[1][j] = min(odp[0][j] ,odp[1][j - num] + 1);
      }
      rep(j,MAX) odp[0][j] = odp[1][j];
    }
  }

  rep(i,a.size()){
    cout << dp[0][a[i]] << " " << odp[0][a[i]] << endl;
  }
}



Measured memory_bytes: 34400
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <ctype.h>
#include <map>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <cctype>
#include <queue>
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define REP1(j,n) for(int j=0;j<(int)n;++j)
#define REPD(i,n) for(int i=n;i>=0;--i)
#define REPD1(j,n) for(int j=n;j=>0;--j)
#define REPS(i,n) for(int i=1;i<=(int)n;++i)
#define REPS1(j,n) for(int j=1;j<=(int)n;++j)
#define rep(i,a,n) for(int i=a;i<=(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define DescSort(a) sort(a.begin(),a.end(),std::greater<int>())

using namespace std;
typedef long long ll;
const ll INF=1e9+7;

int main(void) {
	vector<int> a(3);
	cin >> a[0] >> a[1] >> a[2];
	sort(a.begin(), a.end());
	cout << a[0] + a[1] << endl;
	return 0;
}

Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let v = read_vec::<usize>();
    let (a, b) = (v[0], v[1]);
    if a <= 5 {
        println!("0");
    } else if a <= 12 {
        println!("{:?}", b / 2);
    } else {
        println!("{:?}", b);
    }
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 4352
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
        int n; int num[5000]; int max1=-100000;
        while(cin >> n ,n){
                for(int i=0; i<n; i++)
                        cin >> num[i];
		max1=num[0];
                for(int i=0; i<n; i++){
                        int sum=0;
                        for(int j=i;j<n;j++){
                                sum+=num[j];
                                max1=max(max1,sum);
                        }
                }
                cout << max1 << endl;
        }
 
 
}

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

#ifdef LOCAL
#define debug(var) cerr << #var << " = " << var << endl;
#else
#define debug(var)
#endif

void init() {
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
}

void solve() {
	int n; scanf("%d", &n);
	if (n%10 == 9 || n/10%10 == 9 || n/100 == 9) puts("Yes");
	else puts("No");
}

int main() {
	init();
	int t = 1; //scanf("%d", &t);
	while (t--) {
		solve();
	}
	return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;

class Test
{
    static void Main()
    {
        double[] dd = Console.ReadLine().Split().Select(double.Parse).ToArray();
        double a = dd[0];
        double b = dd[1];
        double C = dd[2];

        double c = Math.Sqrt(a * a + b * b - 2 * a * b * Math.Cos(2 * Math.PI * C / 360));
        double h = b * Math.Sin(2 * Math.PI * C / 360);
        double S = a * h / 2;
        double L = a + b + c;

        Console.WriteLine(S);
        Console.WriteLine(L);
        Console.WriteLine(h);
    }
}


Measured memory_bytes: 18388
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define REPR(i, n) for(int i = (n); i >= 0; i--)
#define FOR(i, m, n) for(int i = (m); i < (n); i++)
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << ": " << x << endl;

using namespace std;
typedef long long ll;

vector<pair<long long, long long> > prime_factorize(long long n) {
  vector<pair<long long, long long> > res;
  for(long long p = 2; p * p <= n; ++p) {
    if(n % p != 0) continue;
    int num = 0;
    while(n % p == 0) {
      ++num;
      n /= p;
    }
    res.push_back(make_pair(p, num));
  }
  if(n != 1) res.push_back(make_pair(n, 1));
  return res;
}

signed main() {
  ll n;
  cin >> n;
  if(n == 1) {
    cout << 0 << endl;
    return 0;
  }
  auto vec = prime_factorize(n);
  ll cnt = 0;
  for(auto v : vec) {
    // cout << v.first << "^" << v.second << endl;
    int m = v.second;
    if(m == 1 || m == 2) {
      cnt++;
    } else {
      for(int j = 1; m > 1; j++) {
        m -= j;
        if(m < 0) break;
        cnt++;
      }
    }
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 3628
parseInt(x) = parse(Int,x)
parseMap(x::Array{SubString{String}, 1}) = map(parseInt, x)
function main()
  N = map(parseInt, split(readline()))[1]
  ans = 0;
  for i = 1:N
  	a,b = map(x -> x, split(readline()))
    a = parse(Float64, a)
    if b == "BTC"
      ans += 380000a
    else
      ans += a
    end
  end
  println(ans)
end
main()

Measured memory_bytes: 114412
#include <stdio.h>
#include <math.h>

long int min(long long int a, long long int b) {
  if(a > b) return b;
  return a;
}

int main(void) {
  long int n, m, ans = 1e12;
  scanf("%ld", &n);
  m = (long int)sqrt((double)n);
  for (long int i = 1; i <= m; i++) {
    long int tmp = 0;
    if (n%i == 0) {
      tmp = n/i;
      ans = min(ans, tmp+i-2);
    }
  }
  printf("%ld\n", ans);
  
  return 0;
}

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

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

int main() {
  int h,w;
  cin>>h>>w;
  vector<string> S;
  rep(i,h){
    string s;
    cin>>s;
    S.push_back(s);
  }
  
  rep(i,h){
    rep(j,w){
      if(S[i][j]=='#')
        cout<<"#";
      else{
        int ans=0;
        rep(k,8){
          int x=i+dx[k];
          int y=j+dy[k];
          if(x>=0 && x<h && y>=0 && y<w)
            if(S[x][y]=='#') ans++;
        }
        cout<<ans;
      }
    }
    cout<<endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

//Nは桁数が大きい場合があるので文字列として受け取る
string N;
vector<int> n;  //Nの各桁の数字を格納するベクター
ll dp[101][2][5];

int main(){
	cin>>N;
	int k;cin>>k;

  	//ベクターnを構成
  	for(auto a : N){
    	n.push_back(a-'0');
  	}
  	int l = N.size();  //nの長さ

  	dp[0][0][0] = 1LL;  //初期条件。他は0で初期化されている
	for(int i = 0; i < l; i++){
		for(int smaller = 0; smaller < 2; smaller++){
			for(int j = 0; j < k + 1; j++){
				for(int x = 0; x <= (smaller ? 9 : n[i]); x++){
					if (x != 0){
						dp[i + 1][smaller || x < n[i]][j + 1] += dp[i][smaller][j];          
					}
					else{
						dp[i + 1][smaller || x < n[i]][j] += dp[i][smaller][j];          
					}
				}
			}
		}
	}

  	cout << dp[l][0][k] + dp[l][1][k] << endl;
  	return 0;
}

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

int main(){
    int h,w;
    cin >> h >> w;
    char field[55][55];
    rep(i,h){
        string s;
        cin >> s;
        rep(j,w){
            field[i+1][j+1]=s[j];
        }
    }
    int ans[55][55]={0};
    rep(i,h){
        rep(j,w){
            for(int k=-1;k<=1;k++){
                for(int l=-1;l<=1;l++){
                    if(field[i+1+k][j+1+l]=='#'){
                        ans[i][j]++;
                    }
                }
            }
        }
    }
    rep(i,h){
        rep(j,w){
            if(field[i+1][j+1]=='.'){
                cout << ans[i][j];
            }
            else cout << '#' ;
        }
        cout << endl;
    }
    cout << endl;

    
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n,M[N][N];
int color[N],d[N],f[N],tt;

void dfs_visit(int u){
  int v;
  color[u] = GRAY;
  d[u] = ++tt;
  for(v=0;v<n;v++){
    if(M[u][v] == 0)continue;
    if(color[v] == WHITE){
      dfs_visit(v);
    }
  }
  color[u] = BLACK;
  f[u] = ++tt;
}

void dfs(){
  int u;
  for(u=0;u<n;u++)color[u] = WHITE;
  tt = 0;

  for(u=0;u<n;u++){
    if(color[u] == WHITE) dfs_visit(u);
  }
  for(u=0;u<n;u++){
    printf("%d %d %d\n",u+1,d[u],f[u]);
  }
}

int main(){
  int u,v,k,i,j;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++)M[i][j] = 0;
  }
  for(i=0;i<n;i++){
  scanf("%d %d",&u,&k);
  u--;
  for(j=0;j<k;j++){
    scanf("%d",&v);
    v--;
    M[u][v] = 1;
  }
  }
  
dfs();

return 0;
}



Measured memory_bytes: 2108
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
vector<int> adj[50];
int t = 1, cnt = 0;
vector<int> disc(50,-1),low(50,-1);
bool visited[50];

void dfs(int i,int p){
    disc[i] = low[i] = t++;
    for(auto j : adj[i]){
        if(disc[j] == -1){
            dfs(j,i);
            low[i] = min(low[i],low[j]);
            if(low[j] > disc[i]){
                ++cnt;
            }
        }else if(j != p){
            low[i] = min(low[i],disc[j]);
        }
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,m;
    cin>>n>>m;
    for(int i=0;i<m;i++){
        int a,b;
        cin>>a>>b;
        a--;b--;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    memset(visited,false,sizeof(visited));
    dfs(0,-1);
    cout<<cnt<<"\n";
    return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto& (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define sar(a,n) {cout<<#a<<":";rep(pachico,n)cout<<" "<<a[pachico];cout<<endl;}

using namespace std;

template<typename S,typename T>auto&operator<<(ostream&o,pair<S,T>p){return o<<"{"<<p.fi<<","<<p.se<<"}";}
template<typename T>auto&operator<<(ostream&o,set<T>s){for(auto&e:s)o<<e<<" ";return o;}
template<typename S,typename T,typename U>
auto&operator<<(ostream&o,priority_queue<S,T,U>q){while(!q.empty())o<<q.top()<<" ",q.pop();return o;}
template<typename K,typename T>auto&operator<<(ostream&o,map<K,T>&m){for(auto&e:m)o<<e<<" ";return o;}
template<typename T>auto&operator<<(ostream&o,vector<T>v){for(auto&e:v)o<<e<<" ";return o;}
void ashow(){cout<<endl;}template<typename T,typename...A>void ashow(T t,A...a){cout<<t<<" ";ashow(a...);}
template<typename S,typename T,typename U>
struct TRI{S fi;T se;U th;TRI(){}TRI(S f,T s,U t):fi(f),se(s),th(t){}
bool operator<(const TRI&_)const{return(fi==_.fi)?((se==_.se)?(th<_.th):(se<_.se)):(fi<_.fi);}};
template<typename S,typename T,typename U>
auto&operator<<(ostream&o,TRI<S,T,U>&t){return o<<"{"<<t.fi<<","<<t.se<<","<<t.th<<"}";}

typedef pair<int, int> P;
typedef pair<ll, ll> pll;
typedef TRI<int, int, int> tri;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<P> vp;
typedef vector<double> vd;
typedef vector<string> vs;

const int MAX_N = 100005;

int n, K;
vector<int> G[MAX_N];
int dp[MAX_N], sub[MAX_N], ans;

void dfs(int u, int p)
{
    int cnt = 0;
    sub[u] = 1;
    vector<pair<int, int> > vec;
    for(int v : G[u]){
        if(v != p){
            dfs(v, u);
            sub[u] += sub[v];
            vec.emplace_back(dp[v] - (sub[v] >= K), v);
            if(sub[v] >= K) ++cnt;
        }
    }
    sort(all(vec), greater<pair<int, int> >());
    dp[u] = cnt;
    // show(dp[u]);
    for(int v : G[u]){
        if(v != p){
            cmx(dp[u], dp[v] + cnt - (sub[v] >= K));
            cmx(ans, dp[v] + cnt - (sub[v] >= K) + (n - sub[u] >= K));
            if((int)vec.size() >= 2){
                int res = vec[0].fi;
                if(vec[0].se == v) res = vec[1].fi;
                cmx(ans, dp[v] + cnt + res - (sub[v] >= K) + (n - sub[u] >= K));
            }
        }
    }
    // ashow(u, dp[u], sub[u]);
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> K;
    rep(i,n-1){
        int a, b;
        cin >> a >> b;
        G[a-1].pb(b-1), G[b-1].pb(a-1);
    }
    dfs(0, -1);
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 17560
#include <bits/stdc++.h>
using namespace std;
#define int long long

signed main(){
    // cout << fixed << setprecision(10) << flush;

    int a, b, c, k;
    cin >> a >> b >> c >> k;

    if(a >= k){
        cout << k << endl;
    }
    else if(k <= a+b){
        cout << a << endl;
    }
    else{
        cout << a - (k-a-b) << endl;
    }

    return 0;
}

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

int main() {
  string s;

  cin >> s;

  int red = 0, blue = 0;

  for (int i = 0; i < (int)s.size(); i++) {
    if (s.at(i) == '0')
      red++;
    else
      blue++;
  }

  cout << min(red, blue) * 2;

  return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef pair<long long, long long> P;
#define int long long
#define override_rep(i, l, r, mes, ...) mes
#define rep1(i, n) for (int i = 0; i < n; i++)
#define rep2(i, l, r) for (int i = l; i < r; i++)
#define rep(...) override_rep(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)
template<typename T, typename U>
istream& operator>>(istream& in, pair<T, U>& p) {
    in >> p.first >> p.second;
    return in;
}
signed main(signed argc, char* argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    const int MOD = 1000000007;
    int a,b,c,d,in;
    cin>>in;
    a=(in-in%1000)/1000;
    b=(in-in%100)/100-a*10;
    c=(in-in%10)/10-b*10-a*100;
    d=in-c*10-b*100-a*1000;
    if(a+b+c+d==7)cout<<a<<"+"<<b<<"+"<<c<<"+"<<d<<"="<<7<<endl;
    else if(a+b+c-d==7)cout<<a<<"+"<<b<<"+"<<c<<"-"<<d<<"="<<7<<endl;
    else if(a+b-c+d==7)cout<<a<<"+"<<b<<"-"<<c<<"+"<<d<<"="<<7<<endl;
    else if(a-b+c+d==7)cout<<a<<"-"<<b<<"+"<<c<<"+"<<d<<"="<<7<<endl;
    else if(a+b-c-d==7)cout<<a<<"+"<<b<<"-"<<c<<"-"<<d<<"="<<7<<endl;
    else if(a-b+c-d==7)cout<<a<<"-"<<b<<"+"<<c<<"-"<<d<<"="<<7<<endl;
    else if(a-b-c+d==7)cout<<a<<"-"<<b<<"-"<<c<<"+"<<d<<"="<<7<<endl;
    else if(a-b-c-d==7)cout<<a<<"-"<<b<<"-"<<c<<"-"<<d<<"="<<7<<endl;
}


Measured memory_bytes: 256
//Created by Kira

#include<bits/stdc++.h>
using namespace std;

#define IOS cin.sync_with_stdio(0);cin.tie(0); cout.tie(0);
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define pii pair<int,int> 
#define pb push_back
#define vi vector<int> 
using ll = long long;

const int mod = 1e9 + 7;

ll pwr(ll a, ll b);
    

const double PI = 3.14159265358979;

int main(){
   IOS

   int a, b, h, m; cin>>a>>b>>h>>m;

   double dm = h * 60 + m;

   

   double theta = (dm/60.0 - dm/720.0) * 2 * PI;

   
   double val = sqrt(a*a + b*b - 2 * a * b * cos(theta));

   cout<<fixed<<setprecision(10)<<val<<"\n";

   

}

ll pwr(ll a, ll b){
   a %= mod;	//Remove mod if not required
   ll res = 1;
   while(b > 0){
    if(b&1)
        res = res * a % mod;
        a = a * a % mod;
    b >>= 1;
    }

    return res;
}



Measured memory_bytes: 4244
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <string>
#include <vector>
#include <array>
#include <algorithm>
#include <map>
#include <list>
#include <queue>
#include <set>
#include <iostream>
#include <fstream>
#include <chrono>

using namespace std;

const int DIV = 1000000007;

void solve(int test, istream &in) {
    int n;
    in >> n;
    string s;
    in >> s;
    int w = 0, r = n - 1;
    int cnt = 0;
    while (w < r) {
        while (w < n && s[w] != 'W')
            w++;
        while (r >= 0 && s[r] != 'R')
            r--;
        if (w < r) {
            std::swap(s[w], s[r]);
            cnt++;
        }
    }
    printf("%d\n", cnt);
}

int main(int argc, char* argv[])
{
#ifdef VLAD_LOCAL
    ifstream f("in.txt");
    auto start = std::chrono::steady_clock::now();
#else
    istream &f = cin;
#endif
    int tests = 1;
    //f >> tests;
    for (int test = 0; test < tests; test++) {
        solve(test, f);
    }
#ifdef VLAD_LOCAL
    auto end = std::chrono::steady_clock::now();
    double seconds = (double)std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count() / 1000;
    printf("%.3lf\n", seconds);
#endif
    return 0;
}


Measured memory_bytes: 3816
n = int(input())
a = [0] + [int(_) for _ in input().split()]

dp = [1000] * (n+1)
for i in range(1, n+1):

    stock = dp[i] // a[i]
    amari = dp[i] % a[i]
    max_price = 0
    for j in range(min(n+1, i+1), n+1):
        price = stock * a[j] + amari
        if price > max_price:
            max_price = price
        dp[j] = max(max_price, dp[j])

print(dp[n])

Measured memory_bytes: 65960
#include <iostream>

using namespace std;

int main() {
	int a; cin >> a;
	int b[a];
	for (int i = 0; i < a; i++) {
	    cin >> b[i];
	}
	int c, d = 0;
	do {
	    c = 0;
	    for (int o = 1; o < a; o++) {
	        int u = o - 1;
	        if (b[u] > b[o]) {
	            int x = b[u];
	            b[u] = b[o];
	            b[o] = x;
	            c++;
	        }
	    }
        d += c;
    } while (c > 0);
    for (int i = 0; i < a - 1; i++) cout << b[i] << " ";
    cout << b[a - 1] << endl << d << endl;
}



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

typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)
#define ALL(a) begin(a),end(a)
template<class T> inline void sort_uniq(T& c) { sort(ALL(c)); c.erase(unique(ALL(c)), c.end()); }
#define COUNTOF(a) (sizeof(a)/sizeof(a[0]))
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
template<class T> void cout_v(const vector<T>& c)
{ for (int i = 0; i < c.size(); i++) cout << c[i] << endl; }
template<class K, class V> void cout_v(map<K, V>& m)
{ for(auto it=m.begin();it!=m.end();it++)cout<<it->first<<":"<<it->second<<endl;}
template<class T> void cout_h(const vector<T>& c)
{ for (int i = 0; i < c.size(); i++) cout << c[i] << (i==c.size()-1?"\n":" "); }
template<class T> inline bool chmin(T& a, T b) {return a>b?a=b,true:false;}
template<class T> inline bool chmax(T& a, T b) {return a<b?a=b,true:false;}
inline int powi(int x,int y) {int p=1; while(y--) p*=x; return p;}
template<class T> inline bool is_overlap(const T& a, const T& b, const T& p, const T& q)
{ return p <=b && a <= q; }

#define SP << " " <<
#define FMT(a) #a<<":"<<a 
#define FMT2(a,b) #a<<":"<<a<<", "<<#b<<":"<<b 
#define FMT3(a,b,c) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c 
#define FMT4(a,b,c,d) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c<<", "<<#d<<":"<<d 
#define ANS(a) cout<<a<<endl
void YES(bool f){cout<<(f?"YES":"NO")<<endl;}


template<class T> void sort3a(T& a,T& b,T& c) {if (a>b) swap(a,b); if (b>c) swap(b,c); if (a>b) swap(a,b);}

int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    //cout<<std::fixed<<std::setprecision(10);

    int N; cin >> N;
    map<int,int> counter;
    rep(i, N) {
        int A; cin >> A;
        counter[A]++;
    }
    int ans = accumulate(ALL(counter), 0,
        [](int acc, pair<const int, int>& p) {
            return acc + (p.second % 2 ? 1 : 0);
        }
    );
    cout << ans << endl;
}


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

using namespace std;

int main() {
    string S;
    cin >> S;
    char C;
    C = S[0];

    if (C == 'S') {
        cout << "Cloudy" << endl;
        return 0;
    } else if (C == 'C') {
        cout << "Rainy" << endl;
        return 0;
    } else {
        cout << "Sunny" << endl;
        return 0;
    }

}

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

int main() {
  llong n;
  cin >> n;
  llong ans = n * (n - 1) / 2;
  cout << ans << endl;
  return 0;
}

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

int main () { 
  int h, w;
  cin >> h >> w;
  vector<string> squ(h);
  for (int i = 0; i < h; i++)
    cin >> squ.at(i);
  
  vector<bool> row(h, false);
  vector<bool> col(w, false);
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (squ.at(i).at(j) == '#') {
        row.at(i) = true;
        col.at(j) = true;
      }
    }
  }
  
  for (int i = 0; i < h; i++) {
    if (row.at(i)) {
      for (int j = 0; j < w; j++) {
        if (col.at(j))
          cout << squ.at(i).at(j);
      }
      cout << endl;
    }
  }
}

Measured memory_bytes: 256
s = input()
rl = []
start = 0
for i in range(len(s)):
    if i == len(s) - 1 or s[i] == "L" and s[i + 1] == "R":
        rl.append(s[start: i + 1])
        start = i + 1

ans = [0] * len(s)
start = 0
for i in range(len(rl)):
    x = rl[i].index("L")
    ans[start + x] = x // 2 + (len(rl[i]) - x - 1) // 2 + 1
    ans[start + x - 1] = (x - 1) // 2 + (len(rl[i]) - x) // 2 + 1
    start += len(rl[i])
print(*ans)

Measured memory_bytes: 14336
#include <bits/stdc++.h>
/**  I'm Klaus, NicKlaus :v **/
using namespace std;
#define ms(a,v) memset(a,v,sizeof a)
#define ll long long
#define LOG2(X) ((unsigned) (8*sizeof(int) - __builtin_clz((X)) - 1))
ll gcd(ll x, ll y){return (y ? gcd(y, x%y) : x); }
ll lcm(ll x, ll y){return x*(y/gcd(x,y));}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

int main(){
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	#ifdef LOCAL_JUDGE
		//freopen("in_out/in.txt", "rt", stdin);
		//freopen("int_out/out.txt", "wt", stdout);
	#endif
	int n, m;
	cin>>n>>m;
	priority_queue<int> q;
	while(n--){
		int x; cin>>x;
		q.push(x);
	}
	while(m--){
		int aux = q.top();
		q.pop();
		q.push(aux/2);
	}
	ll ans = 0 ;
	while ( !q.empty() ){
		ans += q.top();
		q.pop();
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 892
#include "bits/stdc++.h"
using namespace std;
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define put(a) cout<<a<<"\n"
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
typedef long long ll;
typedef pair<int, int> P;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){if(a>b){a=b;return 1;}return 0;}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){if(a<b){a=b;return 1;}return 0;}

ll pow(ll x,ll y){
    if(y<=0){return 1;}
    if(y%2==0){ll d = pow(x,y/2);return d*d;}
    else{return (x*pow(x,y-1));}
}

vector<int> demical(ll n,int k,int l){
    vector<int> rtn(l);
    REP(i,l){
        rtn[i]=n%k;
        n/=k;
    }
    //while(n>0){
    //rtn.push_back(n%k);
    //n/=k;
    //}
    return rtn;
}


ll strToll(string& s,int t,int g){
    ll res = 0;
    FOR(i,t,g){
        res *= 10;
        res += s[i]-'0';
    }
    return res;
}

int main(){
    string s;
    cin >> s;
    int n = s.size();
    ll m = pow(2ll,n-1);
    ll res = 0;
    REP(i,m){
        vector<int> t=demical(i,2,n-1);
        vector<int> k(1,0);
        REP(i,n-1){
            if(t[i]==1){
                k.push_back(i+1);
            }
        }
        REP(i,k.size()-1){
            res += strToll(s, k[i], k[i+1]);
        }
        res += strToll(s, oor(k.at((ll)k.size()-1)), n);
    }
    /*for(int bit=0;bit<(1<<(n-1));bit++){
        vector<int> t;
        for(int i=0;i<n-1;++i){
            if(bit&&(1<<i)){
                t.push_back(i);
            }
        }
        t.push_back(n-1);
        REP(i,t.size()-1){
            res += strToll(s, t[i], t[i+1]);
        }
    }*/
    put(res);
    return 0;
}


Measured memory_bytes: 256