akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;

// modint: mod 計算を int を扱うように扱える構造体
template<int MOD> struct Fp {
long long val;
constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
if (val < 0) val += MOD;
}
constexpr int getmod() { return MOD; }
constexpr Fp operator - () const noexcept {
return val ? MOD - val : 0;
}
constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
constexpr Fp& operator += (const Fp& r) noexcept {
val += r.val;
if (val >= MOD) val -= MOD;
return *this;
}
constexpr Fp& operator -= (const Fp& r) noexcept {
val -= r.val;
if (val < 0) val += MOD;
return *this;
}
constexpr Fp& operator *= (const Fp& r) noexcept {
val = val * r.val % MOD;
return *this;
}
constexpr Fp& operator /= (const Fp& r) noexcept {
long long a = r.val, b = MOD, u = 1, v = 0;
while (b) {
long long t = a / b;
a -= t * b; swap(a, b);
u -= t * v; swap(u, v);
}
val = val * u % MOD;
if (val < 0) val += MOD;
return *this;
}
constexpr bool operator == (const Fp& r) const noexcept {
return this->val == r.val;
}
constexpr bool operator != (const Fp& r) const noexcept {
return this->val != r.val;
}
friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
return os << x.val;
}
friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
if (n == 0) return 1;
auto t = modpow(a, n / 2);
t = t * t;
if (n & 1) t = t * a;
return t;
}
};

const int MOD = 1000000007;
using mint = Fp<MOD>;

const int MAX_N = 100050;

vector<int> G[MAX_N];
mint white[MAX_N], black[MAX_N];

void dfs(int v, int p = -1) {
    white[v] = 1;
    black[v] = 1;
    for(int nv : G[v]) {
        if(nv == p) continue;
        dfs(nv,v);
        black[v] *= white[nv];
        white[v] *= white[nv] + black[nv];
    }
}

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

int N;
cin >> N;
rep(i,N-1) {
    int x,y;
    cin >> x >> y;
    x--; y--;
    G[x].push_back(y);
    G[y].push_back(x);
}
dfs(0);
cout << white[0] + black[0] << endl;
return 0;
}

Measured memory_bytes: 14208
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        
        if(a<b && b<c){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 26396
#include<stdio.h>

int main(){

int n[30]={};
int N;
int r=0;
while(1){
scanf("%d",&N);if(N==0)break;

for(int i=0;i<N;i++)
scanf("%d",&n[i]);

int P=32;
int j=0;
while(1){
if(P<=0)break;
P-=(P-1)%5;printf("%d\n",P);
if(P==1)break;
P-=n[j];printf("%d\n",P);
j++;j=j%N;
}
P=0;printf("%d\n",P);
}
return 0;
}

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

int main(){
  int N, k;
  string S;
  cin >> N >> S >> k;
  for(int i=0; i < N; ++i){
    if(S[i] != S[k-1]) S[i] = '*';
  }
  cout << S << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
int n,m,i,x,y,viz[100005],val[100005],nod,nod2,k;
vector <int> v[100005];
queue <int >q;
int main()
{
    cin>>n>>m;
    for(i=1;i<=m;i++)
    {
        cin>>x>>y;
        v[x].pb(y);
        v[y].pb(x);
    }
  q.push(1);
  viz[1]=1;
  while(!q.empty())
  {     nod=q.front();
        q.pop();
      for(i=0;i<v[nod].size();i++)
      {nod2=v[nod][i];
          if(!viz[nod2])
          {
              viz[nod2]=1;
              val[nod2]=nod;
              q.push(nod2);
              k++;
          }
      }
  }

  if(k==n-1)
  {
       cout<<"Yes \n";
       for(i=2;i<=n;i++)
        cout<<val[i]<<"\n";
  }
       else
        cout<<"No";
    return 0;
}


Measured memory_bytes: 10884
#include<bits/stdc++.h>
 #include <ext/pb_ds/tree_policy.hpp>
 #include <ext/pb_ds/assoc_container.hpp>
 #include<chrono>
 using namespace std;
 using namespace std::chrono;      
 using namespace __gnu_pbds; 
 #define fastio     ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
 #define fi         first
 #define se         second
 #define int         long long 
 #define pb         push_back
 #define emp        emplace_back
 #define vv(x)      vector<x>
 #define mp(x,y)    map<x,y>
 #define dq(x)      deque<x>
 #define pql(x)     priority_queue<x>
 #define pqs(x)     priority_queue<x,vv(x),greater<x> >
 #define M          1000000007
 #define forf(i,a,b) for(int i=a;i<b;i++)
 #define it(x)      x::iterator
 #define ll         long long 
 #define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
 #define time__(d)  for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false); debug("%s time : %.4fs", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
 #define vii        vector<int>
 #define big        3e18
 #define sm         -2e9
 #define mkr        make_pair
 #define vpi        vector<pair<int,int> >
 #define pii        pair<int,int>
 #define rng        500005
 #define sz(x)      (int)x.size()
 #define rv(x)      reverse(x.begin(),x.end())
 #define out(x)     cout<<x.fi<<" "<<x.se<<endl;

//#define ordered_set tree<pii, null_type,less<pii>, rb_tree_tag,tree_order_statistics_node_update> 
  
void pr_init()
{
   
    #ifndef ONLINE_JUDGE
    freopen("gin.txt", "r", stdin);
    freopen("gout.txt", "w", stdout);
   
    #endif
}
 

void solve()
{
 

 int an = big,n;
 cin >> n;

 for(int i=1;i*i<=n;i++)
 if(n%i==0)
 {
    an = min(an , i+n/i-2);
 }


 cout<<an ;
    
}


int32_t main()
{
  pr_init();
  fastio;
  
  auto start = high_resolution_clock::now(); 
 
  solve();
  auto stop = high_resolution_clock::now();
  auto duration = duration_cast<microseconds>(stop - start); 
   // cout << "Time taken by function: "
   //       << duration.count() << " microseconds" << endl; 

 }
      
      

Measured memory_bytes: 3636
#include<stdio.h>
#define N 20
#define Q 200
int solve(int,int);
int n,I[N],J[Q];
main(){
  int q,i;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&I[i]);
  }
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&J[i]);
  }
  for(i=0;i<q;i++){
    if(solve(J[i],0)>0) printf("yes\n");
    else printf("no\n");
  }
  return 0;
}

int solve(int q,int o){ 
  if(q==0) return 1;
  if(q<0) return 0;
  if(o>=n) return 0;  
  return solve(q-I[o],o+1)+solve(q,o+1);
}

Measured memory_bytes: 580
#include "bits/stdc++.h"
#define rep(i,a,n) for(int i=a;i<n;i++)
using namespace std;
using ll=long long;
const int M=100010;

int nine_mul(int x){	//9^xを出力;
	int ans=1;
	while(x!=0)ans*=9,x--;
	return ans;
}
int six_mul(int x){
	int ans=1;
	while(x!=0)ans*=6,x--;
	return ans;
}

int main(){
	int dp[M]={},n;
	vector<int> v;

	cin>>n;
	rep(i,0,7)v.push_back(nine_mul(i));
	rep(i,0,8)v.push_back(six_mul(i));
	sort(v.begin(),v.end(),greater<int>());
	rep(i,1,n+1){
		rep(j,0,v.size()){
			if(i>=v[j]){
				if(dp[i]==0)dp[i]=dp[i-v[j]]+1;	
				if(dp[i]>dp[i-v[j]]+1)
					dp[i]=dp[i-v[j]]+1;				
			}
		}
	}
	cout<<dp[n]<<endl;	
}

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

typedef struct {double x;double y;} Point;

void kock(int n, Point a, Point b){
	if(n==0) return;
	
	//三等分
	 Point s,t,u;
	double th =M_PI*60.0/180.0;
	
	s.x=(2.0*a.x+1.0*b.x)/3.0;
	s.y=(2.0*a.y+1.0*b.y)/3.0;
	t.x=(1.0*a.x+2.0*b.x)/3.0;
	t.y=(1.0*a.y+2.0*b.y)/3.0;
	u.x=(t.x-s.x)*cos(th)-(t.y-s.y)*sin(th)+s.x;
	u.y=(t.x-s.x)*sin(th)+(t.y-s.y)*cos(th)+s.y;
	
	kock(n-1,a,s);
	printf("%.8f %.8f\n",s.x,s.y);
	
	kock(n-1,s,u);
	printf("%.8f %.8f\n",u.x,u.y);
	
	kock(n-1,u,t);
	printf("%.8f %.8f\n",t.x,t.y);
	
	kock(n-1,t,b);
}

int main(void){
	int n;
	Point a,b;
	
	scanf("%d",&n);
	
	a.x=0;
	a.y=0;
	b.x=100;
	b.y=0;
	
	printf("%.8f %.8f\n",a.x,a.y);
	kock(n,a,b);
	printf("%.8f %.8f\n",b.x,b.y);
	
	return 0;
}


Measured memory_bytes: 2108
#include<bits/stdc++.h>
using namespace std;
void findnumofdigit(long  n,long k)
{
    int digit = (int)(floor( log(n) /log(k)) + 1);
    cout<<digit;
}
int main()
{
    long long int n,k;
    cin>>n>>k;
    findnumofdigit(n,k);
    return 0;
}


Measured memory_bytes: 256
import collections
N = int(input())
A = list(map(int, input().split()))
c = collections.Counter(A)
values,counts = zip(*c.most_common())
A = sorted(c.most_common(), key=lambda x: x[0])
A.append([-1])
p = 0
for u in range(N):
    if A[p] != -1:
        if A[p][0] != u+1:
            print(0)
        else :
            print(A[p][1])
            p+=1
    else :
        print(0)

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

#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
#define rep2(i,s,n) for(long long i=(s); i<(long long)(n);i++)

typedef long long ll;

const ll inf = 1e18+7;
const ll mod = 1e9+7;


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

    bool jdg=true;

    rep(i,n){
        int a;
        cin>>a;

        if(a%2==0){
            if(a%3==0||a%5==0){
                continue;
            }
            else jdg=false;
        }
    }

    if(jdg){
        cout<<"APPROVED"<<endl;
        return 0;
    }
    cout<<"DENIED"<<endl;
}


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

vector<int> to[200005];
vector<int> ans;

void dfs(int v, int p =-1){
  for (int u : to[v]) {
    if (u == p) continue;
    ans[u] += ans[v];
    dfs(u, v);
  }
}

int main() {
  int n, q;
  cin >> n >> q;
  rep(i, n-1) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  ans.resize(n);
  rep(i, q) {
    int p, x;
    cin >> p >> x;
    --p;
    ans[p] += x;
  }
  dfs(0);
  rep(i, n) printf("%d ", ans[i]);
  return 0;
}

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

int main(){
    int n,t,a;
    cin >> n >> t >> a;
    int h[n];
    for(int i = 0; i < n; i++) cin >> h[i];
    float min = t - h[0]*0.006,minat = 1;
    for(int i = 1; i < n; i++){
        float ave = t - h[i]*0.006;
        if(abs(a - min) > abs(a - ave)){
            min = ave;
            minat = i+1;
        }
    }
    cout << minat << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);


    	while(true){
    	int	a=sc.nextInt();
        String op=sc.next();
        int b=sc.nextInt();
    	if(op.equals("+")){
    	System.out.println(a+b);
    	}else if(op.equals("-")){
    	System.out.println(a-b);
    	}else if(op.equals("*")){
        System.out.println(a*b);
    	}else if(op.equals("/")){
        System.out.println(a/b);
    	}else if(op.equals("?")){
        break;
    	}
    	}
    }
}



Measured memory_bytes: 26252
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define rrep(i, a, n) for (int i = (int)(a); i >= (int)(n); --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) \
  rep(f, 0, (x.size() - 1)) cerr << x[f] << (f == (x.size() - 1) ? "\n" : " ")
#define all(x) x.begin(), x.end()
#define int long long
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int MX = 1e5 + 5, INF = 5 << 28, MOD = 1e9 + 7;

int N, M, K;
vector<int> A, B;
string S, T;

void input() {
  int x, y, z;
  ;
  cin>>S;
}

void solve() {
  bool ans=true;
  if (S[1] != S[2]) ans=false;
  else if (S[0] != S[1]) {
    if (S[2] != S[3]) ans=false;
    else ans=true;
  }
  else {
    ans=true;
  }
  cout<<(ans ? "Yes" : "No")<<endl;

}
signed main() {
  input();
  solve();
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <cstring>

using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define FIND(x, target) find(x.begin(),x.end(),target)
#define pb(x) push_back(x)
#define output(x) cout<<x<<endl
#define ERASE(x, n) erase(x.begin(), x.begin+n)
// #define int long long
#define P pair<int, int>
typedef long long ll;

const long long int MOD = 1e9+7;
const int INF = -1;

signed main(void) {
  	int N;
  	cin >> N;
  	vector<int> A;
  	vector<int> B;
  	rep(i, N) {
  		int tmp;
  		cin >> tmp;
  		A.pb(tmp);
  		B.pb(tmp);
  	}
  	
  	SORT(A);
  	rep(i, N) {
  		if(B[i] == A[N-1]) {
  			cout << A[N-2] << endl;
  		} else {
  			cout << A[N-1] << endl;
  		}
  	}
 	
	return 0;
}


Measured memory_bytes: 3436
#include <queue>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <string>
#include <vector>
#include <map>
#include <functional>
#include <set>

#define rep(i, n) for(int i = 0; i < (n); i++)
#define MAX(a, b) (((a) < (b)) ? (b) : (a))
#define MIN(a, b) (((a) < (b)) ? (a) : (b))

using namespace std;
typedef long long int ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pint;
const ll inf = (1LL << 60);
const ll mod = 1000000007;
ll max(ll a, ll b) {
	if (a < b)
		return b;
	else
		return a;

}
ll min(ll a, ll b) {
	if (a < b)
		return a;
	else
		return b;

}



int main() {
	ll N;
	cin >> N;
	vector<ll> A(N);
	vector<ll> X(N);
	rep(i, N) {

		cin >> A[i];
	}

	X[0] = A[0];


	for (int i = 1; i < N; i++) {
		if (i % 2 == 1)
			X[0] -= A[i];
		else
			X[0] += A[i];
	}

	

	for (int i = 1; i < N; i++) {
		X[i] = 2*A[i-1] - X[i - 1];

	}

	rep(i, N) {
		cout << X[i] << " ";
	}

	return 0;
}

Measured memory_bytes: 2944
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 string S;
 cin >>S;
 vector<long long>aaa(S.size()+1,0);
 long long answer=0;
 for(long long i=0;i<S.size();i++){
     if(S.at(i)=='<'){
         aaa.at(i+1)=aaa.at(i)+1;
     }
 }
 for(long long i=S.size()-1;0<=i;i--){
     if(S.at(i)=='>'){
         if(aaa.at(i+1)>=aaa.at(i)){
             aaa.at(i)=aaa.at(i+1)+1;
         }
     }
 }
for(int i=0;i<=S.size();i++){
    answer+=aaa.at(i);
}
cout<<answer<<endl;
}

Measured memory_bytes: 7724
require 'tsort'

class Hash
  include TSort
  alias tsort_each_node each_key
  def tsort_each_child(node, &block)
    self[node].each(&block)
  end
end

idx = Hash[%w(
   Rock Fire Scissors Snake Human Tree Wolf Sponge Paper Air Water Dragon Devil Lightning Gun
).map.with_index {|g, i| [g, i] }]

loop do
  n = gets.to_i
  break if n == 0
  gestures = (1..n).map { gets.chomp }.uniq

  if gestures.size == 1
    puts 'Draw'
    next
  end

  graph = Hash[gestures.map {|g| [g, []] }]
  gestures.permutation(2) do |g1, g2|
    i, j = idx[g1], idx[g2]
    graph[g1] << g2 if (i - j) % 15 <= 7
  end

  begin
    sorted = graph.tsort
    puts sorted[0]
  rescue TSort::Cyclic
    puts 'Draw'
  end
end


Measured memory_bytes: 7024
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

constexpr ll infl = 10000000000000007LL;
constexpr int inf = 1000000007;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    int max_abs = 0;
    int idx = -1;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        if (abs(a[i]) >= abs(max_abs)) {
            max_abs = a[i];
            idx = i;
        }
    }
    cout << 2 * n - 1 << endl;
    for (int i = 0; i < n; ++i) {
        cout << idx + 1 << " " << i + 1 << endl;
    }

    if (max_abs >= 0) {
        for (int i = 0; i < n - 1; ++i) {
            cout << i + 1 << " " << i + 2 << endl;
        }
    } else {
        for (int i = n - 1; i >= 1; --i) {
            cout << i + 1 << " " << i << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
// 競技プログラミング.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
#include <iostream>
#include <string>


using namespace std;

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

	int lenge = a.size();

	int kausu = 0;
	for (int i = 0; i < lenge; i++) {
		if (a[i] == 'o')
			kausu++;
	}
	if ((15 - lenge) >= (8 - kausu))
		cout << "YES" << endl;
	else
		cout << "NO" << endl;

	return 0;
}




Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
maxi = max((abs(a), i) for i, a in enumerate(A))[1]
if A[maxi] == 0:
    print(0)
    exit()
print(2*(N-1))
for i in range(N):
    if i == maxi: continue
    print(maxi+1, i+1)
if A[maxi] > 0:
    for i in range(N-1):
        print(i+1, i+2)
else:
    for i in range(N-1)[::-1]:
        print(i+2, i+1)

Measured memory_bytes: 3064
#include <iostream>

using namespace std;

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

    int ans = 0;
    
    
    while(N > 0){
        ans += N % 10;
        N = N / 10;
    }

    if(ans == 1){
        ans = 10;
    }

    cout << ans << endl;
    

    return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {

    val n = readLine()!!.toInt()
    val b = readLine()!!.split(" ").map { it.toInt() }.toTypedArray()

    val c = Array(n) { 0 }

    // 先頭
    c[0] = b[0]

    for (i in 1 until n - 1) {
        c[i] = Math.min(b[i - 1], b[i])
    }
    // 最後
    c[n - 1] = b[n - 2]

    println(c.sum())
}

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

typedef long long ll;

int h, w, x, y, d;
ll n;
ll dp[102][102][4];
char t[102][102];

int dx[] = {0, 1, 0, -1};
int dy[] = {-1, 0, 1, 0};
char str[] = "NESW";

void walk(){
  for(int i = 0; i < 4; i++){
    int nd = (d + i) % 4;
    int nx = x + dx[nd];
    int ny = y + dy[nd];

    if(0 <= nx && nx < w && 0 <= ny && ny < h && t[ny][nx] == '.'){
      x = nx;
      y = ny;
      d = nd;
      return;
    }
  }
}

void solve(){
  ll cnt = 0;
  memset(dp, -1, sizeof(dp));

  while(dp[x][y][d] == -1 && cnt < n){
    dp[x][y][d] = cnt;
    walk();
    cnt++;
  }

  if(cnt == n) return;

  ll rem = (n - dp[x][y][d]) % (cnt - dp[x][y][d]);

  while(rem--){
    walk();
  }
}

int main(){
  while(cin >> h >> w >> n, h || w || n){
    for(int i = 0; i < h; i++){
      cin >> t[i];

      for(int j = 0; j < w; j++){
        if(t[i][j] != '.' && t[i][j] != '#'){
          if(t[i][j] == 'N') d = 0;
          else if(t[i][j] == 'E') d = 1;
          else if(t[i][j] == 'S') d = 2;
          else if(t[i][j] == 'W') d = 3;

          x = j;
          y = i;
          t[i][j] = '.';
        }
      }
    }

    solve();

    cout << y + 1 << " " << x + 1 << " " << str[d] << endl;
  }
}

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

int main(int argc, const char * argv[]) {
    uint32_t A, B, C, K;
    cin >> A >> B >> C >> K;
    int ans = 0;
    
    // A
    if (0 < K) {
        if (A < K) {
            ans += A;
            K -= A;
        }else {
            ans += K;
            K = 0;
        }
    }
    
    // B
    if (0 < K) {
        if (B < K) {
            K -= B;
        }else {
            K = 0;
        }
    }
    
    // C
    if (0 < K) {
        ans -= K;
        K = 0;
    }
    
    cout << ans;
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#ifdef PRAGMA
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#endif
#define fst first
#define snd second
#define fore(i,a,n) for(int i=a;i<n;i++)
#define pb push_back
#define mp make_pair
#define bs binary_search
#define ALL(s) s.begin(),s.end()
#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define SZ(n) ((int) (n).size())
#define MAXI ((ll)1e16)
#define MINI ((ll)-1e16)
using namespace std;
typedef long long ll;  
     
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b,a%b); } 
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }        
ll n;
ll k;
ll a,b,c;
long double dp[301][301][301];
long double solve(ll a, ll b, ll c){
	if(a==0&&b==0&&c==0)return (long double)1.0;
	if(dp[a][b][c]>=0.0)return dp[a][b][c];
	long double sum = a+b+c;
	dp[a][b][c] = (long double)n/sum;
	if(a>0)dp[a][b][c]+=(long double)((long double)(a/sum)*solve(a-1,b,c));
	if(b>0)dp[a][b][c]+=(long double)((long double)(b/sum)*solve(a+1,b-1,c));
	if(c>0)dp[a][b][c]+=(long double)((long double)(c/sum)*solve(a,b+1,c-1));
	return dp[a][b][c];
}
int main(){FIN;
	cin >> n;
	fore(i,0,n){
	 cin >> k;
		if(k==1)a++;
		if(k==2)b++;
		if(k==3)c++;
	}
	fore(i,0,301){
		fore(j,0,301){
			fore(k,0,301){
				dp[i][j][k]=(long double)-1.0;
			}
		}
	}
	cout << setprecision(15) << solve(a,b,c)-(long double)1.0;
}

Measured memory_bytes: 426496
#include<iostream>
#include<math.h>
#include<string>
#include<map>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<time.h>
#include<random>
#include<queue>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int main() {
	int a;
	cin >> a;
	int min;
	cin >> min;
	int cnt = 1;
	rep(i,  a-1) {
		int x;
		cin >> x;
		if (x <= min) {
			cnt++;
			min = x;
		}
	}
	cout << cnt << endl;;
	return 0;
}

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

public class Main {
	private static void solve(){
	//Implement solution here.
		int n = ni();
		int k = ni();
		ptr = new long[n + 1][n + 1];
		
		for(int i = 1; i <= k; i++) {
			if (n - k + 1 < i) {
                System.out.println(0);
            } else {
            	System.out.println(ptrVal(n - k + 1, i) * ptrVal(k - 1, i - 1) % mod);
            }			
		}		
	}
	private static int mod = 1000000007;
	private static long[][] ptr;
	private static long ptrVal(int a, int b){
		if(ptr[a][b] > 0) {
			return ptr[a][b];
		} else {
			if(a == 0 && b == 0) {
				ptr[a][b] = 1;
			} else {
				if (a == b) {
					ptr[a][b] = ptrVal(a - 1, b - 1);				
				} else if(b == 0) {
					ptr[a][b] = ptrVal(a - 1, b);
				} else {
					ptr[a][b] = (ptrVal(a - 1, b - 1) + ptrVal(a - 1, b)) % mod;
				}
			}
//			System.out.println(a + "," + b);
//			for(int i = 0; i < 5; i++) {
//				for(int j = 0; j < 5; j++) {
//					System.out.print(ptr[i][j] + ",");
//				}
//				System.out.println();
//			}	
			return ptr[a][b];
		}
	}
	
    //Switch input source (stdin/file)
	private static BufferedReader br  = new BufferedReader(new InputStreamReader(System.in));
	public static void main(String[] args){
        String debugDataPath = System.getenv("DD_PATH");        
        if(debugDataPath != null){
            try{
            	br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(debugDataPath))));
            }catch(Exception e){
                throw new RuntimeException(e);
            }
        }
        solve();
	}

    //Input read utility
	private static StringTokenizer tokenizer = null;
	public static String next() {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}
    //Get next single int
	private static int ni() {
		return Integer.parseInt(next());
	}
    //Get next single long
	private static long nl() {
		return Long.parseLong(next());
	}
    //Get next single double
	private static double nd() {
		return Double.parseDouble(next());
	}
    //Get next int array from one line
	private static int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}
	//Get next char array from one line
	private static char[] ns() {
		return next().toCharArray();
	}
    //Get next long array from one line
	private static long[] nal(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nl();
		return a;
	}
}

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

int main() {
    int x;
    cin >> x;
    int ans = x == 1 ? 0 : 1;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3592
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vll vector<ll>
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(int argc, char const *argv[]) {
  ll n;std::cin >> n;
  string s;std::cin >> s;
  deque<vll> q;
  re(i, n){
    ll now = (s[i]=='('?1:-1);
    if(q.size()==0||!(q.back()[0]==1&&now==-1)) q.push_back(vll{now, i});
    else q.pop_back();
  }
  string t="";
  re(i, n){
    while(q.size()!=0&&q.front()[0]==-1&&q.front()[1]>=i){
      t+="(";
      q.pop_front();
    }
    t+=s[i];
  }
  while(q.size()!=0&&q.front()[0]==1){
    t+=')';
    q.pop_front();
  }
  std::cout << t << '\n';
  return 0;
}


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

int main(){
    int a,n,x;
    
    while(1){
        a=0;
        cin >>n >>x;
        if(n==0 && x==0){
            break;
        }
        else{
            for(int h=1; h<=n;h++){
                for(int i=h+1;i<=n;i++){
                    for(int j=i+1;j<=n;j++){
                        if(h+i+j==x){
                        a += 1;
                        }
                    }
                }
            }
            cout << a << endl;
        }
    }return 0;
}


Measured memory_bytes: 3084
use std::io::{Read, stdin};
use std::str::FromStr;

fn solve(s: String) {
    let str: String = "A".to_string() + s.chars().nth(0).unwrap().to_string().as_str() + "C";
    println!("{}", str);
}

fn main(){
    let _a :String = read();
    let s :String = read();
    let _c :String = read();
    solve(s);
}

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

Measured memory_bytes: 4352
#[allow(unused_imports)]
use std::cmp::{Ordering};

#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};

#[allow(unused_imports)]
use std::iter::FromIterator;

#[allow(unused_macros)]
macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::min($x, min!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::max($x, max!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! get { 
    ([$t: ty]) => { 
        { 
            let mut line = String::new(); 
            stdin().read_line(&mut line).unwrap(); 
            line.split_whitespace().map(|t|t.parse::<$t>().unwrap()).collect::<Vec<_>>()
        }
    };
    ([$t: ty];$n: expr) => {
        (0..$n).map(|_|get!([$t])).collect::<Vec<_>>()
    };
    ($t: ty) => {
        {
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t: ty),*) => {
        { 
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*)
        }
    };
    ($t: ty; $n: expr) => {
        (0..$n).map(|_|get!($t)).collect::<Vec<_>>()
    };
    ($($t: ty),*; $n: expr) => {
        (0..$n).map(|_|get!($($t),*)).collect::<Vec<_>>()
    };
}

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

const BIG_STACK_SIZE: bool = true;

#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}

fn solve() {
    let n = get!(usize);
    let a = get!([isize]);

    let mut vec = vec![0; n];
    for i in 0..n-1 {
        vec[i+1] = 2*a[i] - vec[i];
    }
    let plus = a[n-1]-vec[n-1]/2;
    let mut vec = vec![0;n];
    vec[0] = plus;
    for i in 0..n-1 {
        vec[i+1] = 2*a[i] - vec[i];
    }
    for i in 0..n {
        print!("{} ", vec[i]);
    }
}


Measured memory_bytes: 13564
import math
A, B, H, M = map(int, input().split())
l = (360/60)*M
s = (360/12)*H + (360/12/60)*M
theta = max(l, s) - min(l, s)
theta = min(theta, 360-theta)
print(math.sqrt(A**2 + B**2 - 2*A*B*math.cos(math.radians(theta))))


Measured memory_bytes: 9404
n = int(input())
A = list(map(int, input().split()))
c = []
other = 0
for a in A:
  if a < 400: c.append("gray")
  elif a < 800: c.append("brown")
  elif a < 1200: c.append("green")
  elif a < 1600: c.append("mblue")
  elif a < 2000: c.append("blue")
  elif a < 2400: c.append("yellow")
  elif a < 2800: c.append("orange")
  elif a < 3200: c.append("red")
  else: other += 1
c = set(c)
if c:
  print(len(c), len(c)+other)
else:
  print(1, other)

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

bool check_prime (int n)
{
    bool temp= true;
    for(int i=2;i*i<=n;i++)
    if(n%i==0)
 {   temp=false;
    break;
}
    return temp;
}

int main()
{
    long long int x;
    cin>>x;
    int i;
    for(i=x;;i++)
    {
       if( check_prime(i) )
        break;
    }
    
cout<<i;

return 0;
}


Measured memory_bytes: 256
a, b, c = map(int, input().split())
if a == 5 and b == 5 and c == 7:
    print('YES')
elif a == 5 and b == 7 and c == 5:
    print('YES')
elif a == 7 and b == 5 and c == 5:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 9092
// @skylag
//Practice -> Passion -> Patience -> 3 P's of my Life!
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define F first
#define S second
#define ALL(a) (a).begin(),(a).end()
#define SKY ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define int long long int
int power(int a,int n,int mod)
{
    a=a%mod;
    
    int res=1;
    while(n)
    {
        if(n&1)
        {
            res=((res%mod)*(a%mod))%mod;
            n--;
        }
        else
        {
            a=((a%mod*(a%mod)))%mod;
            n/=2;
        }
    }
    return res;
}
void solve()
{
    string s;
    map<string,int> mp;
    int n;
    cin>>n;
    while(n--)
    {
        cin>>s;
        mp[s]++;
    }
    cout<<"AC x "<<mp["AC"]<<"\n";
    cout<<"WA x "<<mp["WA"]<<"\n";
    cout<<"TLE x "<<mp["TLE"]<<"\n";
    cout<<"RE x "<<mp["RE"]<<"\n";
}
int32_t main()
{
    SKY;
    int t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
}




Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const lint mod = 1e9 + 7;
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl((lint)(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzl(x))
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; }
lint power(lint base, lint exponent, lint module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ lint root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position mv[4] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); } string to_string(string x){ return x; }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++) ans += to_string(*i) + " "; if(!ans.empty()) ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
template<class T> T gcd(T a, T b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }} template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct combination{ vector<lint> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } lint C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };
template<class itr> bool next_sequence(itr first, itr last, int max_bound){ itr now = last; while(now != first){ now--; (*now)++; if((*now) == max_bound){ (*now) = 0; }else{ return true; } } return false; }

int main(){
    lint A, B;
    cin >> A >> B;
    if(abs(A + B) % 2){
        cout << "IMPOSSIBLE" << endl;
    }else{
        cout << (A + B) / 2 << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i = (a);i <= (b);i++)
#define pii pair<int,int>
#define pll pair<long long, long long>
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const int maxn = 2e5 + 5;
const int maxm = 1e6 + 5;
const double eps = 1e-8;
const double pi = acos(-1.0);
ll gcd(ll a,ll b){return !b?a:gcd(b,a%b);}
ll lcm(ll a,ll b){return a * b / gcd(a,b);}
ll poww(ll x,ll y,ll p){ll ans = 1;while(y){if(y & 1) ans = ans * x % p;x = x * x % p;y >>= 1;}return ans % p;}
bool isp(ll x){if(x < 2) return 0; for(ll i = 2;i * i <= x;i++){if(x % i == 0) return 0;}return 1;}
char ch;
int main(){
// 	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> ch;
	cout << (char)(ch + 1) << endl;
	return 0;
}
//do smt instead of nothing! never give up!
//take care of long long!
//take care of upper or lower case e.g "yes" or "YES"?
//boundary condition! e.g. n = 0?
//brute force is always the first choice!
// print the ans to look for patterns in the data!

Measured memory_bytes: 256
require 'set'; require 'prime'; require 'pp'
INF=Float::INFINITY; MOD=10**9+7
n,k = gets.chomp.split.map(&:to_i)
a = gets.chomp.split.map(&:to_i)

k.upto(n-1) do |i|
  if a[i] > a[i - k]
    puts 'Yes'
  else
    puts 'No'
  end
end




Measured memory_bytes: 36112
n = int(input())
L = [1]
for i in range(1, 6):
    L.append(pow(9, i))
for i in range(1, 7):
    L.append(pow(6, i))
L = sorted(L)
dp = [float("inf") for _ in range(n + 1)]
dp[0] = 0
for i in range(1, n + 1):
    for l in L:
        if i - l >= 0:
            dp[i] = min(dp[i], dp[i - l] + 1)
print(dp[n])


Measured memory_bytes: 6296
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		int N = sc.nextInt();
		int[][] A = new int[N][N];
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < N; j++) {
				A[i][j] = sc.nextInt();
			}
		}
		long[] dp = new long[1 << N];
		for (int i = 0; i < (1 << N); i++) {
			for (int j = 0; j < N; j++) {
				if ((i & (1 << j)) == 0) continue;
				for (int k = j + 1; k < N; k++) {
					if ((i & (1 << k)) == 0) continue;
					dp[i] += A[j][k];
				}
			}
		}
		for (int i = 1; i < (1 << N); i++) {
			int mask = (1 << N) - 1 - i;
			for (int j = mask; j > 0; j = (j - 1) & mask) {
				dp[i | j] = Math.max(dp[i | j], dp[i] + dp[j]);
			}
		}
		System.out.println(dp[(1 << N) - 1]);
	}
}

Measured memory_bytes: 23116
#include<stdio.h>

int main(void)
{
  int H,N,i,cnt=0;
  int A[100000] = {0};
  
  scanf("%d %d",&H,&N);
  
  for(i=0;i<N;i++)
  {
    scanf("%d",&A[i]);
  }
  
  while(H>0 && cnt<N)
  {
    H -= A[cnt++];
  }
  
  if(H<=0) printf("Yes\n");
  else printf("No\n");
  
  return 0;
}

Measured memory_bytes: 512
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<memory>
#include<functional>
#include<set>

using namespace std;

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define P(p) cout<<(p)<<endl;
#define PP(p) cout<<(p)<<" ";
#define pb push_back
#define mp make_pair
#define INF 1e18

typedef long long ll;
#define int ll
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<char> vc;
typedef pair<int, int> pi;
//int dy[8]={1,1,1,0,-1,-1,-1,0};
//int dx[8]={-1,0,1,1,1,0,-1,-1};
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};

int N,M;
vi a,b;

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin>>N;
    vector<pair<int,pair<int,int>>>IN;
    IN.pb(mp(0,mp(0,0)));
    rep(i,N){
        int t,x,y;
        cin>>t>>x>>y;
        IN.pb(mp(t,mp(x,y)));
    }
    sort(ALL(IN));
    REP(i,1,N+1){
        int nx = IN[i].second.first;
        int ny = IN[i].second.second;
        int bx = IN[i-1].second.first;
        int by = IN[i-1].second.second;
        int t = IN[i].first-IN[i-1].first;
        int dt = abs(nx-bx)+abs(ny-by) - t ;
        /*if(dt<0){
            P("No")
            return 0;
        }*/
        if(dt>0||dt%2){
            P("No")
            return 0;
        }
        /*if((abs(nx-bx)-t)%2||(abs(nx-bx)-t)%2){
            P("No")
            return 0;
        }*/
        /*if(bx<=nx){
            if(bx+t<nx){
                P("No1")
                return 0;
            }
            else{
                if(abs(t-(nx-bx))%2==1){
                    P(abs(t-(nx-bx)))
                    P("NO")
                    return 0;
                }
            }
        }
        else{
            if(bx-t>nx){
                P("No")
                return 0;
            }
            else{
                if(abs(t-(bx-nx))%2==1){
                    P("No")
                    return 0;
                }
            }
        }*/
    }
    P("Yes")
    return 0;
}

Measured memory_bytes: 4596
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = ReadInt();
            var ab = ReadInts();
            var p = ReadInts();
            Array.Sort(p);
            var list = new List<int>(p);

            int a = 0;
            int b = 0;
            int c = 0;

            for (int i = 0; i < n; i++)
            {
                if (list[i] <= ab[0])
                {
                    a++;
                }
                else if (ab[0] + 1 <= list[i] && list[i] <= ab[1]) 
                {
                    b++;
                }
                else if (ab[1] + 1 <= list[i])
                {
                    c++;
                }
            }
            var ans = new List<int>() { a, b, c };
            WriteLine(ans.Min());
            
        }
        

        private static string Read() { return ReadLine(); }
        private static string[] Reads() { return (Read().Split()); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        //最大公約数
        
        public static int Gcd(int a, int b)
        {
            if (a < b)
            {
                return Gcd(b, a);
            }
            while (b != 0)
            {
                var reminder = a % b;
                a = b;
                b = reminder;
            }
            return a;
        }

        //最小公倍数
        public static int Lcm(int a, int b)
        {
            return a * b / Gcd(a, b);
        }

        //文字数を数える
        public static int CountChar(string s, char c)
        {
            return s.Length - s.Replace(c.ToString(), "").Length;
        }
    }
}


Measured memory_bytes: 13524
#include <numeric>
#include <algorithm>
#include <queue>
#define REP(i,n) for(int i=0; i<(int)(n); i++)

#include <iostream>
#include <set>
#include <cstdio>
#include <sstream>
inline int getInt(){ int s; scanf("%d", &s); return s; }

using namespace std;

int main(){
  int n = getInt();
  while(n --> 0){
    string s; cin >> s;

    bool fst = true;
    while(true){
      if(s.find("][") == string::npos) break;
      while(s.find("][") != string::npos)
        s.replace(s.find("]["), 2, ",");
      while(s.find("],[") != string::npos)
        s.replace(s.find("],["), 3, "][");
      // cout << s << endl;

      stringstream ss;

      vector<int> v;
      int tmp = 0;
      REP(i,s.size()){
        if(isdigit(s[i])){
          tmp = (tmp * 10) + s[i] - '0';
        }else if(s[i] == ','){
          if(fst) v.push_back(tmp / 2 + 1);
          else v.push_back(tmp);
          tmp = 0;
        }else{
          if(tmp){
            if(fst) v.push_back(tmp / 2 + 1);
            else v.push_back(tmp);
            tmp = 0;
          }

          if(v.size()){
            const int cnt = v.size();
            sort(v.begin(), v.end());
            // REP(i,v.size()) printf("%d ", v[i]); puts("");
            ss << accumulate(v.begin(), v.begin() + cnt / 2 + 1, 0);
            v.clear();
            tmp = 0;
          }
          ss << s[i];
        }
      }

      s = ss.str();
      // cout << s << endl;
      fst = false;
    }

    while(s.find("]") != string::npos)
      s.replace(s.find("]"), 1, "");
    while(s.find("[") != string::npos)
      s.replace(s.find("["), 1, "");
    cout << s << endl;
  }
  return 0;
}

Measured memory_bytes: 1324
def gcd(a,b):
	return a if b==0 else gcd(b,a%b)

while 1:
	n=input()
	if n==0:break
	s=[map(int,raw_input().split()) for i in range(n)]
	t=c=1
	for i in s:t=t*i[1]/gcd(t,i[1])
	for i in range(n):
		s[i]=t*s[i][0]/s[i][1]
		c=c*s[i]/gcd(c,s[i])
	for i in s:print c/i

Measured memory_bytes: 4252
#include<bits/stdc++.h>
using namespace std;
int v[1001];
int w[1001];
int dp[101][10001];
int N,W;
int solve(int a,int b);
int main(){
  cin >> N >> W;
  for(int i=0;i<N;i++){
    cin >> v[i] >> w[i];
  }
  cout << solve(0,W) << endl;
  
}
int solve(int a,int b){
  if(dp[a][b] != 0)return dp[a][b];
  if(a == N){
    return dp[a][b] = 0;
  }else if(b - w[a] < 0){
    return dp[a][b] = solve(a+1,b);
  }
  else{
    return dp[a][b] = max(solve(a+1,b),solve(a+1,b-w[a])+v[a]) ;
  }
}

Measured memory_bytes: 4900
N=int(input())

#1*a+(6^b1)*b+(9^c1)*c
list=[99999]*(N+1)
list[0]=0
list[1]=1
#1回でいけるところをあらかじめ記入
max6end =True
i=0
while max6end:
    if N <= 6**i :
        max6=i
        max6end=False
    i+=1
max9end =True
i=0
while max9end:
    if N <= 9**i :
        max9=i
        max9end=False
    i+=1
    
#print ("max6=%d max9=%d" % (max6,max9))
for n in range(1,N+1):
    list[n]=list[n-1]+1
    for i in range(1,max6+1):
        if n < 6**i:
            break
        else:
            if list[n] >= list[n-6**i]+1:
                list[n]=list[n-6**i]+1
    for i in range(1,max9+1):
        if n < 9**i:
            break
        else:
            if list[n] >= list[n-9**i]+1:
                list[n]=list[n-9**i]+1
print(list[N])

Measured memory_bytes: 3828
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;

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

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

int main() {
  ll N;
  cin >> N;
  vector<string> S(N);
  rep(i, N) cin >> S[i];

  vector<ll> cnt(5, 0);
  string march = "MARCH";
  rep(i, N) {
    rep(j, 5) {
      if (S[i][0] == march[j]) cnt[j]++;
    }
  }

  ll ans = 0;
  rep(i, 1 << 5) {
    int cn = 0;
    ll temp = 1;
    rep(j, 5) {
      if (i >> j & 1) {
        cn++;
        temp *= cnt[j];
      }
    }
    if (cn == 3) {
      ans += temp;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 6144
#!/usr/bin/env python3
import sys
INF = float("inf")


def solve(S: int):
    if S[0] == S[1] or S[1] == S[2] or S[2] == S[3]:
        print("Bad")
    else:
        print("Good")

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = str(next(tokens))  # type: int
    solve(S)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
from collections import Counter
N = int(input())
V = list(map(int, input().split()))
evens = Counter(V[0::2]).most_common()
odds = Counter(V[1::2]).most_common()
evens.append((0, 0))
odds.append((0, 0))

if evens[0][0] == odds[0][0]:
    print(min(N - evens[1][1] - odds[0][1], N - evens[0][1] - odds[1][1]))
else:
    print(N - evens[0][1] - odds[0][1])

Measured memory_bytes: 25176
#!/usr/bin/env python3
import sys

MAX = 10**2

def solve(N: int):
    ans = [0]*N
    for xi in range(1, MAX):
        x2 = xi**2
        for yi in range(1, MAX):
            y2 = yi**2
            for zi in range(1, MAX):
                k = x2 + y2 + zi**2 + xi*yi + xi * zi + yi*zi
                if k > N: break
                else: ans[k-1] +=1

    for ai in ans:
        print(ai) 
                

    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)

if __name__ == '__main__':
    main()


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

const int N = 1300;

int main()
{
    char str[N];
    int a[N];

    while (fgets(str, N, stdin))
    {
        for (int i = 0; i < strlen(str) - 1; i++)
        {
            if (str[i] >= 'A' && str[i] <= 'Z')
            {
                str[i] += 32;
            }
            a[str[i]]++;
        }
    }
    for (char i = 'a'; i <= 'z'; i++)
    {
        printf("%c : %d\n", i, a[i]);
    }
}


Measured memory_bytes: 2700
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int W = sc.nextInt();
		String[] a = new String[H];
		for(int i = 0 ; i < H ; i++) {
			a[i] = sc.next();
		}
		for(int i = 0 ; i < W + 2 ; i++) {
			System.out.print("#");
		}
		System.out.println();
		for(int i = 0 ; i < H ; i++) {
			System.out.print("#");
			System.out.print(a[i]);
			System.out.println("#");
		}
		for(int i = 0 ; i < W + 2 ; i++) {
			System.out.print("#");
		}
		System.out.println();
	}
}


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

int main(){
  	int N;
  	string S;
  	cin >> N >> S;
  	if(N==1 || N%2!=0){
    	cout << "No" << endl;
      	return 0;
    }
  	int mid = N/2;
  	for(int i=0; i<mid; i++){
    	if(S[i]!=S[i+mid]){
        	cout << "No" << endl;
          	return 0;
        }
    }
  	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256