akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

#ifdef RUBICK
#include "dbg.h"
#endif

using namespace std;
using namespace __gnu_pbds;

template<class T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef long long ll;

int main() {
    int n, k;
    scanf("%d %d", &n, &k);

    set<int> forbidden;
    while (k--) {
        int x;
        scanf("%d", &x);
        forbidden.insert(x);
    }

    const auto disliked = [&](int x) {
        while (x > 0) {
            int d = x % 10;
            x /= 10;

            if (forbidden.count(d) == 1)
                return true;
        }

        return false;
    };

    while (disliked(n))
        n ++;

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

    return 0;
}



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

using namespace std;

const int MOD=1e9+7;
const double PI=3.14159265359;


int main(){
    
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    int n,t;
    cin>>n>>t;
    
    int ans=MOD;
    for(int i=0; i<n; i++){
        int x,y;
        cin>>x>>y;
        if(y<=t){
            ans=min(ans,x);
        }
    }
    
    if(ans==MOD) cout<<"TLE";
    else cout<<ans;
    
    return 0;
    
}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.util.NoSuchElementException;

public class Main{

	static PrintWriter out;
	static InputReader ir;

	static void solve(){
		int cnt=0;
		int n=ir.nextInt();
		if(n%2==1)
			out.println("NO");
		else{
			for(int i=0;i<n;i++){
				if(ir.next().charAt(0)=='A')
					cnt++;
				else
					cnt--;
				if(cnt<0){
					out.println("NO");
					break;
				}
				if(i==n-1){
					if(cnt==0)
						out.println("YES");
					else
						out.println("NO");
				}
			}
		}
	}

	public static void main(String[] args) throws Exception{
		ir=new InputReader(System.in);
		out=new PrintWriter(System.out);
		solve();
		out.flush();
	}

	static class InputReader {

		private InputStream in;
		private byte[] buffer=new byte[1024];
		private int curbuf;
		private int lenbuf;

		public InputReader(InputStream in) {this.in=in; this.curbuf=this.lenbuf=0;}

		public boolean hasNextByte() {
			if(curbuf>=lenbuf){
				curbuf= 0;
				try{
					lenbuf=in.read(buffer);
				}catch(IOException e) {
					throw new InputMismatchException();
				}
				if(lenbuf<=0) return false;
			}
			return true;
		}

		private int readByte(){if(hasNextByte()) return buffer[curbuf++]; else return -1;}

		private boolean isSpaceChar(int c){return !(c>=33&&c<=126);}

		private void skip(){while(hasNextByte()&&isSpaceChar(buffer[curbuf])) curbuf++;}

		public boolean hasNext(){skip(); return hasNextByte();}

		public String next(){
			if(!hasNext()) throw new NoSuchElementException();
			StringBuilder sb=new StringBuilder();
			int b=readByte();
			while(!isSpaceChar(b)){
				sb.appendCodePoint(b);
				b=readByte();
			}
			return sb.toString();
		}

		public int nextInt() {
			if(!hasNext()) throw new NoSuchElementException();
			int c=readByte();
			while (isSpaceChar(c)) c=readByte();
			boolean minus=false;
			if (c=='-') {
				minus=true;
				c=readByte();
			}
			int res=0;
			do{
				if(c<'0'||c>'9') throw new InputMismatchException();
				res=res*10+c-'0';
				c=readByte();
			}while(!isSpaceChar(c));
			return (minus)?-res:res;
		}

		public long nextLong() {
			if(!hasNext()) throw new NoSuchElementException();
			int c=readByte();
			while (isSpaceChar(c)) c=readByte();
			boolean minus=false;
			if (c=='-') {
				minus=true;
				c=readByte();
			}
			long res = 0;
			do{
				if(c<'0'||c>'9') throw new InputMismatchException();
				res=res*10+c-'0';
				c=readByte();
			}while(!isSpaceChar(c));
			return (minus)?-res:res;
		}

		public double nextDouble(){return Double.parseDouble(next());}

		public int[] nextIntArray(int n){
			int[] a=new int[n];
			for(int i=0;i<n;i++) a[i]=nextInt();
			return a;
		}

		public long[] nextLongArray(int n){
			long[] a=new long[n];
			for(int i=0;i<n;i++) a[i]=nextLong();
			return a;
		}

		public char[][] nextCharMap(int n,int m){
			char[][] map=new char[n][m];
			for(int i=0;i<n;i++) map[i]=next().toCharArray();
			return map;
		}
	}
}

Measured memory_bytes: 24496
n = int(input())
a = []
b = []
for i in range(n):
    x,y = map(int, input().split())
    a.append(x)
    b.append(y)
a.sort()
b.sort()
if n%2:
    mid_min = a[n//2]
    mid_max = b[n//2]
    print(mid_max-mid_min+1)
else:
    mid_min = (a[n//2-1]+a[n//2])/2
    mid_max = (b[n//2-1]+b[n//2])/2
    print(int((mid_max-mid_min)*2)+1)

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

int main() {
	int n, m;
	cin >> n >> m;
	int p[m], y[m];
	map<int, int>mp;
	map<int, int>mmp;
	vector<pair<int, int>>v;
	for (int i = 0; i < m; i++) {
		cin >> p[i] >> y[i];
		pair<int, int>q = make_pair(p[i], y[i]);
		v.push_back(q);
	}
	sort(v.begin(), v.end());
	for (int i = 0; i < m; i++) {
		int f = v[i].first, s = v[i].second;
		mp[f]++;
		mmp[s] = mp[f];
	}
	for (int i = 0; i < m; i++) {
		string s = to_string(p[i]), t = to_string(mmp[y[i]]);
		for (int j = 0; j + s.size() < 6; j++)cout << 0;
		cout << s;
		for (int j = 0; j + t.size() < 6; j++)cout << 0;
		cout << t << endl;
	}
}

Measured memory_bytes: 12404
#include <iostream>
#include <vector>
#include <string>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <climits>
#include <map>
#include <functional>
#include <cmath>
#include <cassert>

using namespace std;

int main()
{
    long n, m;
    cin >> n >> m;

    if (n == 1 && m == 1)
        cout << 1 << endl;
    else if (n == 1 || m == 1)
        cout << m * n - 2 << endl;
    else
        cout << (m-2)*(n-2) << endl;
    return 0;
}

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

int main(int argc, char **argv)
{
	int n = 0;
	unsigned long long total_push = 0;
	std::vector<unsigned long long> a;
	std::vector<unsigned long long> b;

	std::cin >> n;

	a.resize(n);
	b.resize(n);

	for (int i = 0; i < n; i++)
	{
		std::cin >> a[i] >> b[i];
	}

	for (int i = n - 1; i >= 0; i--)
	{
		unsigned long long push = 0;

		a[i] += total_push;
		if (a[i] % b[i] == 0)
		{
			push = 0;
		}
		else
		{
			push = b[i] - (a[i] % b[i]);
		}

		total_push += push;
	}

	std::cout << total_push;

	return 0;
}

Measured memory_bytes: 1792
import sys

def factorization(n):
    d = dict()
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            d[i] = cnt
    
    if temp != 1:
        d[temp] = 1
    
    if len(d) == 0:
        d[n] = 1
    
    return d

def main():
    input = sys.stdin.readline
    A, B = map(int, input().split())
    if A == B == 1:
        return 1

    Af = factorization(A,)
    Bf = factorization(B,)
    cnt = 1
    for a in Af.keys():
        if a in Bf.keys():
            cnt += 1

    return cnt

if __name__ == '__main__':
    print(main())

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

int main() {
  int N;
  cin >> N;
  string s;
  
  for (int i = 0; i < N; i++) {
    cin >> s;
    if (s == "Y") {
      cout << "Four" << endl;
      break;
    } else if (N - i > 1){
      continue;
    } else {
      cout << "Three" << endl;
    }
  }
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
  int weight;
  while (cin >> weight) {
    bool flag = false;
    for (int b = 1; b <= 512; b *= 2) {
      if (b & weight) {
        if (flag) cout << ' ';
        cout << b;
        flag = true;
      }
    }
    cout << endl;
  }

  return 0;
}

Measured memory_bytes: 0
package main

import "fmt"

var dp [3001][3001]int

func main() {
	var s, t []byte
	fmt.Scan(&s, &t)

	for i := 0; i < len(s); i++ {
		for j := 0; j < len(t); j++ {
			a, b := i+1, j+1
			if s[i] == t[j] {
				dp[a][b] = Max(dp[a][b], dp[i][j]+1)
			}
			dp[a][b] = Max(dp[a][b], dp[a][j])
			dp[a][b] = Max(dp[a][b], dp[i][b])
		}
	}

	i, j, idx := len(s), len(t), 0
	ans := make([]byte, dp[i][j])

	for i > 0 && j > 0 {
		if dp[i][j] == dp[i-1][j] {
			i--
			continue
		}

		if dp[i][j] == dp[i][j-1] {
			j--
			continue
		}

		i--
		j--
		ans[idx] = s[i]
		idx++
	}

	Reverse(ans)
	fmt.Println(string(ans))
}

// generated by https://github.com/murosan/gollect

func Max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func Reverse(s []byte) {
	for i, j := 0, len(s)-1; i < j; i, j = i+1, j-1 {
		s[i], s[j] = s[j], s[i]
	}
}


Measured memory_bytes: 70912
/* while(!cin.eof()) */

#include<bits/stdc++.h>
using namespace std; 
#define int long long 
#define mod (int)(1e9+7)
#define MAXI (int)(1e18+100)
#define N 1000001

int n;
int in_edges[N];
vector<int> gr[N];

int node(int x, int y)
{
    return min(x, y)*1000 + max(x, y);
}

// Driver code to test above functions
int32_t main()
{
     
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);

    cin >> n;
    for(int i=0;i<n;i++)
    {
        int las, cur;
        cin >> las;
        las--;
        for(int j=0;j<n-2;j++)
        {
            cin >> cur;
            cur--;
            int x = node(i, las);
            int y = node(i, cur);
            gr[x].push_back(y);
            in_edges[y]++;
            las = cur;
        }
    }   

    //cout << in_edges[1] << " " << in_edges[2] << " " << in_edges[1002] << endl;

    vector<int> no_edges;
    for(int i=0;i<N;i++)
        if(in_edges[i]==0)
            no_edges.push_back(i);


    int ans = 0, removed = 0; 

    while(no_edges.size()!=0)
    {
        ans++;  
        removed += no_edges.size();

        vector<int> next_no_edges;

        for(int i=0;i<no_edges.size();i++)
        {
            for(int j=0;j<gr[no_edges[i]].size();j++)
            {
                int x = gr[no_edges[i]][j];
                in_edges[x]--;
                if(in_edges[x]==0)
                    next_no_edges.push_back(x);
            }
        }

        no_edges = next_no_edges;
    }
    
    if(removed!=N)
        cout << -1 << endl;
    else
        cout << ans << endl;

    return 0;  
} 

Measured memory_bytes: 52468
using System;
using System.Collections.Generic;
using System.Linq;

namespace ProgramingStudying2
{
    class Program
    {

        static void Main(string[] args)
        {
            var hw = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var h = hw[0];
            var w = hw[1];

            var field = new string[h];
            for (int i = 0; i < h; i++) 
            {
                field[i] = Console.ReadLine();
            }

            var ans = new string[h];

            for (int x = 0; x < h; x++)
            {
                for (int y = 0; y < w; y++)
                {
                    var count = 0;

                    if(field[x][y] == '#')
                    {
                        ans[x] += '#';
                        continue;
                    }

                    for (int i = -1; i <= 1; i++)
                    {
                        for (int j = -1; j <= 1; j++)
                        {
                            if (x + i < 0 || x + i >= h)
                            {
                                continue;
                            }
                            if (y + j < 0 || y + j >= w)
                            {
                                continue;
                            }

                            if(field[x + i][y + j] == '#')
                            {
                                count++;
                            }
                        }
                    }
                    ans[x] += count.ToString();
                }
            }

            for(int i = 0; i < h; i++)
            {
                Console.WriteLine(ans[i]);
            }
        }
    }
}


Measured memory_bytes: 27972
import std.stdio;
import std.ascii;
import std.conv;
import std.string;
import std.algorithm;
import std.range;
import std.functional;
import std.math;
import core.bitop;

void main()
{
    auto n = readln.chomp.to!long;
    string result;
    while (n != 0)
    {
        long m = n % -2;
        // writeln([n,m]);
        n /= -2;
        result = ((m == 0) ? "0" : "1") ~ result;
        if (m == -1)
        {
            n++;
        }
    }
    if (result.length == 0)
    {
        writeln("0");
    }
    else
    {
        writeln(result);
    }
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		boolean[] f=new boolean[1000000];
		Arrays.fill(f, true);
		for(int i=2;i<1000000;i++){
			if(f[i]){
				for(int j=i+i;j<1000000;j+=i){
					f[j]=false;
				}
			}
		}
		while(sc.hasNextInt()){
			int n=sc.nextInt();
			int cnt=0;
			for(int i=2;i<=n;i++){
				if(f[i]==true)cnt++;
			}
			System.out.println(cnt);
		}
		sc.close();
	}
}

Measured memory_bytes: 27940
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
const ll mod=1e9+7;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

vector<ll>wt;
vector<ll>val;
ll kp(ll W,ll n){
    ll k[n+1][W+1];
    for(ll i=0;i<=n;i++){
        for(ll w=0;w<=W;w++){
            if((w==0)||(i==0)){
                k[i][w]=0;
            }
            else if(wt[i-1]>w){
                k[i][w]=k[i-1][w];
            }
            else if(wt[i-1]<=w){
                k[i][w]=max(k[i-1][w],val[i-1]+k[i-1][w-wt[i-1]]);
            }
        }
    }
    return k[n][W];
    }


int main(){
    ll n,w;
    cin>>n>>w;
    for(ll i=0;i<n;i++){
        ll a,b;
        cin>>a>>b;
        wt.push_back(a);
        val.push_back(b);
    }
    cout<<kp(w,n)<<endl;
    return 0;

    }


Measured memory_bytes: 79104
// Aizu Vol0 0031: Weight
// 2017.7.29

#include <stdio.h>
#include <stdlib.h>

char *gets(char *);

int w[10] = { 1, 2, 4, 8, 16, 32, 64, 128, 256, 512 };

int main()
{
	int i, x, f;
	char buf[100];

	while (gets(buf) != NULL) {
		x = atoi(buf);
		for (i = 0, f = 1; x > 0; i++, x >>= 1) {
			if (x & 1) {
				if (f) f = 0;
				else putchar(' ');
				printf("%d", w[i]);
			}
		}
		putchar('\n');
	}
	return 0;
}

Measured memory_bytes: 528
#include<stdio.h>
#include<string.h>
void f(int b[],int m[][331],int n,int s,int d){
  int i;
  int q[10];
  if(d==n){
    m[n][s]++;
  }else{
    for(i=0;i<10;i++){
      if(b[i]==0){
	memcpy(q,b,sizeof(q));
	q[i]=1;
	f(q,m,n,s+(d+1)*i,d+1);
      }
    }
  }
  return;
}
int main(){
  int i;
  int b[10],m[11][331],n,s;
  memset(m,0,sizeof(m));
  memset(b,0,sizeof(b));
  for(i=1;i<10+1;i++)
    f(b,m,i,0,0);
  while(scanf("%d%d",&n,&s)!=-1){
    if(n>10||s>330)
      puts("0");
    else
      printf("%d\n",m[n][s]);
  }
  return 0;
}

Measured memory_bytes: 300
#include <bits/stdc++.h>
#define PI 3.1415926535897
using namespace std;
typedef long long ll;
const int INF = 1000000000;
const ll LINF = 1000000000000000000; //1e18
const double EPS = 1e-10;

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

    int a;
    vector<int> ans(N);
    for (int i = 0; i < N; i++)
    {
        cin >> a;
        ans[a - 1] = i + 1;
    }
    for (int i = 0; i < N; i++)
    {
        printf("%d", ans[i]);
        if (i != N - 1)
        {
            printf(" ");
        }
    }
    printf("\n");
    return (0);
}


Measured memory_bytes: 1152
MOD = 1000000007
s = input()
q = 1
a = 0
ab = 0
ans = 0
for c in s:
    if c == 'A':
        a += q
        a %= MOD
    elif c == 'B':
        ab += a
        ab %= MOD
    elif c == 'C':
        ans += ab
        ans %= MOD
    else:
        ans *= 3
        ans += ab
        ans %= MOD
        ab *= 3
        ab += a
        ab %= MOD
        a *= 3
        a += q
        a %= MOD
        q *= 3
        q %= MOD
print(ans)


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

int main() {
  int output = 0;
  std::string ACGT = "ACGT";
  std::string S;
  std::cin >> S;
  int currentLength = 0;
  for (int i = 0; i < S.size(); ++i) {
    int found = ACGT.find(S[i]);
    if (found != std::string::npos) {
      ++currentLength;
    } else {
      currentLength = 0;
    }
    if (output < currentLength) {
      output = currentLength;
    }
  }
  std::cout << output << "\n";
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define ppll pair<ll,pll>
#define pdd pair<double,double>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define eb emplace_back
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (ll) (x).size()
#define pq priority_queue<ll>
#define pqg priority_queue<ll,vector<ll>,greater<ll>>
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end())
#define int ll
// #define ll int
using namespace std;
const ll INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
// const ll mod = 998244353;
const ll MAX = 2100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[8] ={1,0,-1,0,1,-1,1,-1};
ll dy[8] ={0,1,0,-1,1,-1,-1,1};
 
template<class T> 
inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> 
inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }



map<ll,ll> res;
void prime_factor(ll n){
    for(ll i=2;i*i<=n;i++){
        while(n%i==0){
            res[i]++;
            n/=i;
        }
    }
    if(n!=1) res[n]++;
    return;
}


void solve() {
    ll n,cnt=0;
    cin>>n;
    prime_factor(n-1);
    ll ans=1,a=1;
    for(auto i : res){
        a*=i.sc+1;
    }
    ans+=a-1;
    for(ll i=2;i*i<=n;i++){
        if(n%i!=0) continue;
        ll m=n;
        while(true){
            // cout<<i<<endl;
            if(m<i) break;
            if(m%i==0){
                ll next=m/i;
                if(next==m){
                    break;
                }
                m=next;
            }
            else{
                m-=m/i*i;
                if(m<i) break;
            }
        }
        if(m==1){
            ans++;
            // cout<<i<<endl;
        }

    }
    cout<<ans<<endl;




}





signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);


    solve(); 


    return 0;
}


Measured memory_bytes: 3652
H, N = map(int, input().split()) 
abl = []
for _ in range(N):
    ab = list(map(int, input().split()) )
    abl.append(ab)

dp = [10**8]*(2*10**4+1)
dp[0] = 0
for h in range(H+1):
    for ab in abl:
        a,b = ab
        dp[h+a] = min(dp[h+a], dp[h]+b)

print(min( dp[H:] ))

Measured memory_bytes: 41964
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int H, W;
  cin >> H >> W;
  vector<string> S(H+2);//上下空白行
  string S_0(W+2, '.');
  
 for(int i=0; i<H+2; i++){
   if(i== 0 || i== H+1) S.at(i) = S_0;
   else{
    cin >> S.at(i);
    S.at(i) = "." + S.at(i) + ".";}
    //cout << S.at(i) << endl;
     }
  
  vector<vector<int>> M(H, vector<int>(W));//カウント行列
  for(int i=1; i<=H; i++){
   for(int j=1; j<=W; j++){
     int count = 0;
     for(int k=-1; k<=1; k++)
     {
     if((S.at(i+k)).at(j-1) == '#') count++;
     if((S.at(i+k)).at(j) == '#') count++;//自分が#でも上書きされる
     if((S.at(i+k)).at(j+1) == '#') count++;
     }
      M.at(i-1).at(j-1) = count;
    }}

  vector<vector<string>> T(H, vector<string>(W));
  for(int i=0; i<H; i++){
   for(int j=0; j<W; j++){
		T.at(i).at(j) = to_string(M.at(i).at(j));
     if(S.at(i+1).at(j+1) == '#')
        T.at(i).at(j) = "#";
        cout << T.at(i).at(j);
     if(j==W-1) cout << "" << endl;
   }
  }
  return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>
// *テンプレート*
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define P pair<int, int>
#define sz(x) x.size()
// aよりbの方が小さかったら、aの値をbの値に置き換える。(swapではない！)
template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
// aよりbの方が大きかったら、aの値をbの値に置き換える。
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;
//最大公約数
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
//最小公倍数
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
// 素数かどうか判定
bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}


const long long MOD = 1000000007;
const long long INF = 1LL << 60;
// *テンプレートここまで*

// pair -> vector<pair<int,int>> 
//		   AandB.push_back(make_pair(a[i],b[i]))

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

int h, w;
string fi[110];
int dist[110][110];

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> h >> w;
	int wnum = 0;
	rep(i, h) {
		cin >> fi[i];
		rep(j, w) {
			if (fi[i][j] == '.')wnum++;
		}
	}
	memset(dist, -1, sizeof(dist));
	dist[0][0] = 1;
	queue<P>que;
	que.push(P(0, 0));
	while (!que.empty()) {
		P cur = que.front();
		que.pop();
		int x = cur.first;
		int y = cur.second;
		rep(dir, 4) {
			int nx = x + dx[dir];
			int ny = y + dy[dir];
			if (nx < 0 || nx >= h || ny < 0 || ny >= w) {
				continue;
			}
			if (fi[nx][ny] == '#')continue;
			if (dist[nx][ny] == -1) {
				dist[nx][ny] = dist[x][y] + 1;
				que.push(P(nx, ny));
			}
		}
	}
	if (dist[h - 1][w - 1] == -1)cout << -1 << endl;
	else cout << wnum - dist[h - 1][w - 1] << endl;
	return 0;
}

Measured memory_bytes: 384
#include <stdio.h>

int main (){
	int i,n,count=0;
	char str[50];
	scanf("%d",&n);
	scanf("%s",str);

	for(i=0;i<n-2;i++){
		if(str[i]=='A'&&str[i+1]=='B'&&str[i+2]=='C'){
			count++;
		}
	}
	printf("%d", count);

	return 0;
}

Measured memory_bytes: 2152
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int> p(n);
  for (int i = 0; i < n; i++)
  {
    cin >> p[i];
  }

  int ans = 0;
  for (int i = 1; i < n-1; i++)
  {
    if ((p[i-1]<p[i] && p[i]<p[i+1])||(p[i-1]>p[i] && p[i]>p[i+1])) ans++;
  }
  cout << ans << endl;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define data_type long long
#define endl "\n"
int  main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int arr[11]={0};
    int a,b,c;
    cin>>a>>b>>c;
    arr[a]++,arr[b]++,arr[c]++;
    cout<<((arr[5]==2 && arr[7]==1)?"YES":"NO")<<endl;

    return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    sort(a.begin(),a.end());

    int left = a[n-1];
    double c = (double)left/2.0;
    int right;
    double min_diff = 1000000002.0;
    for(int i = 0; i < n-1; i++){
        double diff = abs((double)a[i]-c);
        if(min_diff > diff){
            min_diff = diff;
            right = a[i];
        }
    }

    cout << left << " " << right << endl;
    return 0;

}


Measured memory_bytes: 640
// #pragma GCC optimize(2)
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <cmath>
#include <string>
#include <vector>
#include <stack>
#include <map>
#include <sstream>
#include <cstring>
#include <set>
#include <cctype>
#include <bitset>
#define IO                       \
    ios::sync_with_stdio(false); \
    // cin.tie(0);                  \
    // cout.tie(0);
using namespace std;
int dis[8][2] = {0, 1, 1, 0, 0, -1, -1, 0, 1, -1, 1, 1, -1, 1, -1, -1};
typedef unsigned long long ULL;
typedef long long LL;
const int maxn = 1e5 + 10;
const int maxm = 1e6 + 10;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const LL mod = 1e9 + 7;
const double pi = acos(-1);
LL a[maxn];
LL dp[maxn];
int main()
{
#ifdef ONLINE_JUDGE
#else
    freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
#endif
    IO;
    int n;
    cin >> n;
    dp[0] = 1;
    for (int i = 0; i <= n - 3; i++)
        a[i] = i + 3;
    for (int i = 0; i <= n; i++)
    {
        for (int j = 0; j <= n - 3; j++)
        {
            if (i - a[j] >= 0)
                dp[i] = (dp[i] % mod + dp[i - a[j]] % mod) % mod;
        }
    }
    cout << dp[n] % mod;
    return 0;
}

Measured memory_bytes: 3168
fn read_stdin() -> String {
    use std::io::Read;
    let mut input = String::new();
    std::io::stdin().read_to_string(&mut input).unwrap();
    input
}

fn scan<'a, I: Iterator<Item = &'a str>, T: std::str::FromStr>(tokens: &mut I) -> T {
    tokens.next().unwrap().parse().ok().unwrap()
}

fn main() {
    let input = read_stdin();
    let tokens = &mut input.split_whitespace();
    let s: String = scan(tokens);
    let t: String = scan(tokens);
    let s = s.into_bytes();
    let t = t.into_bytes();
    let z: Vec<usize> = {
        let mut z = vec![0; t.len() + 1];
        let mut i = 0;
        let mut j = 1;
        while j < t.len() {
            if t[i] == t[j] {
                i += 1;
                j += 1;
                z[j] = i;
            } else if i == 0 {
                j += 1;
            } else {
                i = z[i];
            }
        }
        z
    };
    let f: Vec<bool> = {
        let mut f = vec![false; s.len()];
        let mut i = 0;
        let mut j = 0;
        while i < s.len() {
            if s[(i + j) % s.len()] == t[j] {
                j += 1;
                if j == t.len() {
                    f[i] = true;
                    i += j - z[j];
                    j = z[j];
                }
            } else if j == 0 {
                i += 1;
            } else {
                i += j - z[j];
                j = z[j];
            }
        }
        f
    };
    let mut dp = vec![State::Unvisited; s.len()];
    fn dfs(i: usize, ls: usize, lt: usize, f: &[bool], dp: &mut [State]) -> bool {
        match dp[i] {
            State::Unvisited => {
                if f[i] {
                    dp[i] = State::Visiting;
                    if dfs((i + lt) % ls, ls, lt, f, dp) {
                        return true;
                    }
                    dp[i] = State::Visited(dp[(i + lt) % ls].unwrap() + 1);
                } else {
                    dp[i] = State::Visited(0);
                }
                false
            }
            State::Visiting => true,
            State::Visited(_) => false,
        }
    }
    let mut ans = 0;
    for i in 0..s.len() {
        if dfs(i, s.len(), t.len(), &f, &mut dp) {
            println!("-1");
            return;
        }
        ans = std::cmp::max(ans, dp[i].unwrap());
    }
    println!("{}", ans);
}

#[derive(Clone, Copy)]
enum State {
    Unvisited,
    Visiting,
    Visited(usize),
}

impl State {
    fn unwrap(self) -> usize {
        match self {
            State::Visited(n) => n,
            _ => unreachable!(),
        }
    }
}


Measured memory_bytes: 49916
/*
    AUTHOR:hruday pabbisetty
    NIT ROURKElA
*/
#include <bits/stdc++.h>
#include <tr1/unordered_map>
using namespace std;
using namespace std::tr1;
#define opt ios_base::sync_with_stdio(0)
#define lli long long int
#define ulli unsigned long long int
#define I int
#define S string
#define D double
#define rep(i,a,b) for(i=a;i<b;i++)
#define repr(i,a,b) for(i=a;i>b;i--)
#define in(n) scanf("%lld",&n)
#define in2(a,b) scanf("%lld %lld",&a,&b)
#define in3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define out(n) printf("%lld\n",n)
#define inu(a) scanf("%lld",&a)
#define outu(a) printf("%llu",a)
#define ins(s) scanf("%s",&s)
#define outs(s) printf("%s",s)
#define mod 1000000007
#define inf 100000000000000
typedef long long       ll;
typedef pair<lli,lli>  plli;
typedef vector<lli>     vlli;
typedef vector<ulli>    vulli;
typedef vector<ll>      vll;
typedef vector<string>  vs;
typedef vector<plli>     vplli;
#define MM(a,x)  memset(a,x,sizeof(a));
#define ALL(x)   (x).begin(), (x).end()
#define P(x)       cerr<<"{"#x<<" = "<<(x)<<"}"<<endl;
#define P2(x,y)       cerr<<"{"#x" = "<<(x)<<", "#y" = "<<(y)<<"}"<<endl;
#define P3(x,y,z)  cerr<<"{"#x" = "<<(x)<<", "#y" = "<<(y)<<", "#z" = "<<(z)<<"}"<<endl;
#define P4(x,y,z,w)cerr<<"{"#x" = "<<(x)<<", "#y" = "<<(y)<<", "#z" = "<<(z)<<", "#w" = "<<(w)<<"}"<<endl;
#define PP(x,i)     cerr<<"{"#x"["<<i<<"] = "<<x[i]<<"}"<<endl;
#define TM(a,b)     cerr<<"{"#a" -> "#b": "<<1000*(b-a)/CLOCKS_PER_SEC<<"ms}\n";
#define UN(v)    sort(ALL(v)), v.resize(unique(ALL(v))-v.begin())
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define sz() size()
#define nl cout<<"\n"
#define MX1 100005
#define MX2 1000005
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
lli dx[]={0,0,-1,1,-1,-1,1,1};
lli dy[]={1,-1,0,0,1,-1,-1,1};
lli power(lli a,lli b)
    {
    lli value;
    if(b==0)
        {
        return 1;
    }
    else if(b%2==0)
        {
        value=power(a,b/2)%mod;
        return(value*value)%mod;
    }
    else
        {
        value=power(a,b/2)%mod;
        return ((a*value)%mod*(value))%mod;
    }
}
lli b[MX1],w[MX1],tb;
int main()
{
      /*  #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
        #endif*/
    opt;
    lli n,i,p;
    cin>>n>>p;
    vplli v;
    rep(i,0,n)
    {
        cin>>w[i]>>b[i];
        tb+=b[i];
        v.pb(mp(p*b[i]+(100-p)*w[i],i));
    }
    sort(ALL(v));
    reverse(ALL(v));
    lli num=0,den=tb;
    rep(i,0,v.sz())
    {
        num+=w[v[i].s];
        den+=w[v[i].s];
        den-=b[v[i].s];
        double per=(num*1.0/(den));
        //cout<<num<<" "<<den<<" "<<v[i].s<<" "<<per*100<<endl;
        if(num*100>=p*den)
        {
            cout<<i+1;
            exit(0);
        }
    }
}


Measured memory_bytes: 3572
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <climits>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef pair<int,int> pii;
const int INF = 1<<29;
const double PI = acos(-1);
const double EPS = 1e-8;

int main() {
  int n;
  while(cin>>n,n) {
    REP(i,n) {
      int x1,y1,z1,w1;
      cin>>x1>>y1>>z1>>w1;
      int x2,y2,z2,w2;
      cin>>x2>>y2>>z2>>w2;
      int x = x1*x2-y1*y2-z1*z2-w1*w2;
      int y = x1*y2+y1*x2+z1*w2-w1*z2;
      int z = x1*z2-y1*w2+z1*x2+w1*y2;
      int w = x1*w2+y1*z2-z1*y2+w1*x2;
      cout << x << " " << y << " " << z << " " << w << endl;
    }
  }
}

Measured memory_bytes: 0
n = int(input())
l = []
t = 0
c = 0
ans = -1
for i in range(n):
    l.append(int(input())-1)
for i in range(n):
  if l[t]==1:
    ans = c+1
    break
  else:
    c +=1
    t = l[t]
print(ans)

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

// macro
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
using ll = long long;
using P = pair<int,int>;

// code starts
#define MOD 1000000007

ll mod_inv(ll a)
{
	ll left = MOD-2;
	ll ans = 1;
	ll ks = a;
	while(left > 0)
	{
		if(left %2 == 1)
		{
			ans = ans*ks%MOD;
		}
		ks = ks*ks%MOD;
		left /= 2;
	}
	return ans;
}

int main()
{
	int n;
	cin >> n;
	vector<ll> a(n);
	int i;
	rep(i,n) cin >> a[i];
	ll sums = 0;
	rep(i,n)
	{
		sums += a[i];
		sums %= MOD;
	}
	sums = sums*sums%MOD;
	rep(i,n)
	{
		ll dec = a[i]*a[i];
		dec %= MOD;
		sums = (sums-dec+MOD)%MOD;
	}
	//cout << sums << endl;
	cout << sums*mod_inv(2)%MOD << endl;
}


Measured memory_bytes: 4844
#include <bits/stdc++.h>
using namespace std;
const int INF = 1001001001;


int main() {
int N;
cin >> N;
vector<int64_t> vec(N);
for (int i = 0;i < N;i++) cin >> vec.at(i);

int cnt = 0;
for (int i = 0;i < N;i++) {
    while (vec.at(i) % 2 == 0) {
        vec.at(i) /= 2;
        cnt++;
    }
}


cout << cnt << endl;

return 0;
}


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

int main() {
  int l, r, d, cnt = 0;
  cin >> l >> r >> d;
  for (int i = l; i <= r; i++)
    if (i % d == 0) cnt++;
  cout << cnt << endl;
}

Measured memory_bytes: 3620
//templates
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <unordered_map>
#include <map>
#include <cmath>

#define rep(i,n) for(int i = 0; i < (n); i++)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back
#define SZ(x) ((int)(x).size())
typedef long long ll;

using namespace std;

int main(){
  int N,K;
  string S;
  cin >> N >> K;
  cin >> S;
  S[K-1] = tolower(S[K-1]);
  cout << S << endl;
}


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

string s;
int dp[10010][110],f[10010][110],d,sm[10010];

signed main()
{
	ios::sync_with_stdio(false);
	cin>>s;
	cin>>d;
	dp[0][0]=1;
	for(int i=1;i<=s.size();i++){
		for(int j=0;j<d;j++){
			int w=0;
			if(i==1) w=1;
			for(int k=w;k<=9;k++){
				int val=j+k;
				val%=d;
				dp[i][val]+=dp[i-1][j];
				if(dp[i][val]>=MOD) dp[i][val]-=MOD;
			}
		}
	}
	f[0][0]=1;
	for(int i=1;i<=s.size();i++){
		for(int j=0;j<d;j++){
			for(int k=0;k<=9;k++){
				int val=j+k;
				val%=d;
				f[i][val]+=f[i-1][j];
				if(f[i][val]>=MOD) f[i][val]-=MOD;
			}
		}
	}
	for(int i=1;i<=s.size();i++) sm[i]=sm[i-1]+(s[i-1]-'0');
	int ans=0;
	for(int i=1;i<=s.size();i++){
		int val=sm[i];
		val%=d;
		for(int j=s[i-1]-'0'+1;j<=9;j++){
			val++;
			val%=d;
			ans+=f[s.size()-i][(d-val)%d];
			if(ans>=MOD) ans-=MOD;
		}
	}
	int sum=0;
	for(int i=1;i<=s.size();i++){
		sum+=dp[i][0];
		if(sum>=MOD) sum-=MOD;
	}
	cout<<(sum-ans+MOD)%MOD<<endl;
	return 0;
}

Measured memory_bytes: 8960
#include <bits/stdc++.h>
#define nl ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long
#define all(v) (v).begin(), (v).end()
#define allr(v) (v).rbegin(), (v).rend()

using namespace std;

int main() {
    nl // 163 braces

    int t, x;
    cin >> t >> x;
    cout << fixed << setprecision(10) << double(t)/x;

    return 0;
}

Measured memory_bytes: 3756
import sys
input = sys.stdin.readline
N, K = map(int, input().split())
t = [0] * K
for i in range(1, N + 1): t[i % K] += 1
#print(t)
res = 0
for a in range(K):
  b = (K - a) % K
  c = (K - b) % K
  if (c + a) % K == 0:
    res += t[a] * t[b] * t[c]
print(res)

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

#define rep2(x,fr,to) for(int x=(fr);x<(to);x++)
#define rep(x,to) for(int x=0;x<(to);x++)
#define repr(x,fr,to) for(int x=(fr);x>=(to);x--)
#define all(c) c.begin(),c.end()
#define sz(v) (int)v.size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
typedef vector<ll> VL; const int MD = (int)1e9 + 7;
void dbg(){ cerr << "\n"; } template <typename T,typename ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T, class T2> void amax(T& a,T2 b){ if(a < b) a = b;}


int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n, m;
	cin >>n >>m;
	VI s(n), t(m);
	rep(i, n) cin >>s[i];
	rep(i, m) cin >>t[i];
/*	
	vector<VL> dp(n+2, VL(m+2)), sm(n+2, VL(m+2));
	dp[0][0] = sm[1][1] = 1;
	rep(i, n+1) rep(j, m+1) if(i+j !=0){
		if(i && j && s[i-1] == t[j-1]) dp[i][j] = sm[i][j] % MD;
		sm[i+1][j+1] = (sm[i+1][j] + sm[i][j+1] - sm[i][j] + dp[i][j]+MD)%MD;
	}
	cout << sm[n+1][m+1] <<"\n";
*/
	vector<VL> dp(n+2, VL(m+2)); dp[0][0] =1;
	rep(i, n+1) rep(j, m+1){
		if(i>0 && j>0 && s[i-1]==t[j-1]) dp[i][j] += dp[i-1][j-1];
		if(i>0) dp[i][j] += dp[i-1][j];
		if(j>0) dp[i][j] += dp[i][j-1];
		if(i>0 && j>0) dp[i][j] += MD - dp[i-1][j-1];
		dp[i][j] %=MD;
	}
	cout << dp[n][m] %MD <<"\n";
	//for(auto xl: dp){for(auto x :xl) cerr<<x<<" ";dbg("lcs");}

	return 0;
}


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

int exp();
int term();
int factor();
string str;
int p;

int factor(){
  int val=0;
  while(str[p]>='0' && str[p]<='9'){ 
    val*=10;
    val+=str[p]-'0';
    p++;
  }
  if(val!=0) return val;
  else  if(str[p]=='('){
    p++;
    val=exp();
  }
  if(str[p]==')'){
    p++;
  return val;
  }

if(val==0) return 0;
}

int term(){
  int val=factor();
  while(str[p]=='*' || str[p]=='/'){
  if(str[p]=='*'){
      p++;
      val*=factor();
    }else if(str[p]=='/'){
      p++;
      val/=factor();
    }
 }
 return val;
}

int exp(){
  int val=term();
  while(str[p]=='+' || str[p]=='-'){
    if(str[p]=='+'){
      p++;
      val+=term();
    }else if(str[p]=='-'){
      p++;
      val-=term();
    }
  }
  return val;
}


int main(){
  int n;
  
  cin>>n;
  for(int i=0;i<n;i++){
    p=0;
    cin>>str;
    cout<<exp()<<endl;
  }
  return 0;
}

Measured memory_bytes: 1200
if __name__ == "__main__":
    N = int(input())
    mydict = {}
    ans = 0
    for i in range(N):
        s = list(input())
        S = [str(c) for c in s]
        S.sort()
#        print(S)
        if str(S) in mydict.keys():
            mydict[str(S)] += 1 
        else:
            mydict[str(S)] = 1
#    print(mydict)

    for i in mydict.keys():
        tmp = mydict[i]
        if tmp >= 2:
            ans += tmp*(tmp-1)//2
    print(ans)


Measured memory_bytes: 26340
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random,resource

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    n = I()
    a = sorted(LI(), reverse=True)

    if n % 2 == 0:
        return sum(a[:n//2]) * 2 - a[0]

    return sum(a[:n//2+1]) * 2 - a[0] - a[n//2]


print(main())




Measured memory_bytes: 33552
#define _CRT_SECURE_NO_WARNINGS

#include<iostream>
#include<functional>
#include<algorithm>
#include<stack>
#include<queue>
#include<iomanip>
#include<set>
#include<map>
#include<utility>
#include<string>
#include<vector>

using namespace std;

#define LL long long
const int dx[4] = { 1,-1,0,0 };
const int dy[4] = { 0,0,1,-1 };
bool OOA(int x, int y, int H, int W) { return (0 <= x && x<H) && (0 <= y && y<W); }

int main(){
	string f="";
	for(int i=0;i<9;i++){
		char c;
		cin>>c;
		f+=c;
	}

	map<string,int>d;
	string g="123456780";

	queue<string>q;
	q.push(f);
	d[f]=0;
	
	while(!q.empty()){
		string n=q.front();
		q.pop();
		if(n==g){
			cout<<d[n]<<endl;
			return 0;
		}
		int nd=d[n];
		for(int i=0;i<9;i++){
			if((i/3)&&(n[i]=='0'||n[i-3]=='0')){
				swap(n[i],n[i-3]);
				if(!d.count(n)){
					d[n]=nd+1;
					q.push(n);
				}
				swap(n[i],n[i-3]);
			}
			if((i%3)&&(n[i]=='0'||n[i-1]=='0')){
				swap(n[i],n[i-1]);
				if(!d.count(n)){
					d[n]=nd+1;
					q.push(n);
				}
				swap(n[i],n[i-1]);
			}
		}
	}
}



Measured memory_bytes: 23332
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int L = sc.nextInt();
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int D = sc.nextInt();
		int Japa , Math;
		
		if(A % C == 0){
			Japa = A / C;
		}else{
			Japa = A / C + 1;
		}
		
		if(B % D == 0){
			Math = B / D;
		}else{
			Math = B / D + 1;
		}
		
		int Bigone = Japa;
		
		if(Japa < Math){
			Bigone = Math;
		}
		
		System.out.println(L - Bigone);
		
	}
	
}

Measured memory_bytes: 26008
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i< (n); i++)
using namespace std;
 
int main() {
  int N, M;
  cin >> N >>M;
  
  //vector<int> p(N); 
  vector<vector<char>> p(N, vector<char>(M));
  for(int i = 0; i<N; i++){
  	for(int j = 0; j<M; j++){
    	cin>>p[i][j];
    }
  }

  vector<vector<char>> frame(N + 2, vector<char>(M + 2, '#'));
  for(int i = 0; i<N; i++){
    for(int j = 0; j<M; j++){
    	frame[i + 1][j + 1] = p[i][j];
    }
  }
  
  for(int i = 0; i<N + 2; i++){
    for(int j = 0; j<M + 2; j++){
    	cout<<frame[i][j];
    }
    cout<<endl;
  }
}

Measured memory_bytes: 256
#include <stdio.h>
#include <vector>
#include <iostream>
#include <queue>
#include <bits/stdc++.h>
 
#define rep(i,n) for (int i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef pair<int, int> pi;

const double PI=3.14159265358979323846;
int main() {
  double r;
  cin >> r;
  printf("%.6lf\n", 2 * r * PI);
  return 0;
}

Measured memory_bytes: 3768
using System;
using System.Collections.Generic;
using System.Text;

class TEST{
	static void Main(){
		while(true){
		String s="";
		if((s=Console.ReadLine())==null)break;
		String[] ss=s.Split(' ');
		long N=long.Parse(ss[0]);
		long K=long.Parse(ss[1]);
		if(N==0 && K==0)break;
		Sol mySol=new Sol(N,K);
		Console.WriteLine(mySol.Ans);
		}
	}
}

class Sol{
	String ans;
	public String Ans{
		get{return ans;}
	}
	public Sol(long N,long K){
		String[] ss=Console.ReadLine().Split(' ');
		long[] Stock=new long[K];
		for(int i=0;i<K;i++)Stock[i]=long.Parse(ss[i]);
		bool chk=true;
		for(int i=0;i<N;i++){
			var S=Console.ReadLine().Split(' ');
			for(int j=0;j<K;j++){
				Stock[j]-=long.Parse(S[j]);
				if(Stock[j]<0)chk=false;
			}
		}
		if(chk)ans="Yes";
		if(!chk)ans="No";
	}
}

Measured memory_bytes: 6028
n, m = map(int, input().split())
a = list(map(int, input().split()))

dp = dict.fromkeys(range(n + 1))  # dp[n]: n本使うときの桁数
dp[0] = 0

num = {1: 2, 2: 5, 3: 5, 4: 4, 5: 5, 6: 6, 7: 3, 8: 7, 9: 6}
anum = sorted(
    dict(filter(lambda e: e[0] in a, num.items())).items(), reverse=True
)  # 後の計算用にsortしておく

for i in range(n):
    dp[i + 1] = -float("inf")
    for e in anum:
        if i + 1 - e[1] >= 0:
            dp[i + 1] = max(dp[i + 1], dp[i + 1 - e[1]] + 1)

ans = ""
while dp[n] > 1:
    for e in anum:  # anum は降順sortされているので, 大きい順に確認
        if n - e[1] >= 0:
            if dp[n - e[1]] == dp[n] - 1:
                ans += str(e[0])
                n -= e[1]
                break

# 末尾桁は n =0(ちょうど使い切るように決定)
ans += str(list(filter(lambda e: e[1] == n, anum))[0][0])

print(ans)


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

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

    long long rs = 0, gs = 0, bs = 0;
    for(int i = 0; i < n; i++){
        if(s[i] == 'R'){
            rs++;
        }
        else if(s[i] == 'G'){
            gs++;
        }
        else{
            bs++;
        }
    }
    long long ans = rs * gs * bs;
    for(int i = 0; i < n - 2; i++){
        int tmp= 1;
        while(1){
            if(i + tmp * 2 >= n){
                break;
            }
            if(s[i] != s[i + tmp] and s[i + tmp] != s[i + tmp * 2] and s[i + tmp * 2] != s[i]){
                ans--;
            }
            tmp++;
        }
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
#define INF 1001001001

int cnt;

void merge(std::vector<int>&A, int left, int mid, int right){
    int n1 = mid - left;
    int n2 = right - mid;
    std::vector<int> L(n1+1);
    std::vector<int> R(n2+1);
    for(int i = 0; i < n1; i++){
        L[i] = A[left + i];
    }
    for(int i = 0; i < n2; i++){
        R[i] = A[mid + i];
    }
    L[n1] = INF;
    R[n2] = INF;
    int i = 0;
    int j = 0;

    for(int k = left; k < right; k++){
        if(L[i] <= R[j]){
            A[k] = L[i];
            i++;
        }else{
            A[k] = R[j];
            j++;
        }
        cnt++;
    }
    
}

void mergeSort(std::vector<int>&A, int left, int right){
    if(left + 1 < right){
        int mid = (left + right) / 2;
        mergeSort(A, left, mid);
        mergeSort(A, mid, right);
        merge(A, left, mid, right);
    }
}

int main(void){
    int n;
    cnt = 0;
    std::cin >> n;
    std::vector<int> A(n);

    for(int i = 0; i < n; i++){
        std::cin >> A[i];
    }
    

    mergeSort(A, 0, n);

    for(int i = 0; i < n; i++){
        if(i == 0){
            std::cout << A[i];
        }else{
            std::cout << " " << A[i];
        }
        
    }
    std::cout << std::endl;
    std::cout << cnt << std::endl;
    
    return 0;
}


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

//macro-----------------------------------------------------------------------------------------
#define rep(i,a,b) for(int i=a;i<b;i++)
#define int long long

const int inf = 100100100100100;
const int mod = 1000000007;
const string alphabet = "abcdefghijklmnopqrstuvwxyz";
int dx[8]={1,0,-1,0,-1,1,-1,1};
int dy[8]={0,1,0,-1,-1,-1,1,1};


//io_method
int input(){int tmp;cin >> tmp;return tmp;}
string raw_input(){string tmp;cin >> tmp;return tmp;}
string readline(){string s;getline(cin, s);return s;}
template<class T> void print(const T& n){cout << n << endl;}
void print(vector<int> arr){cout << arr[0];rep(i,1,arr.size()) cout << " " << arr[i];cout << endl;}
void print(pair<int, int> p){cout << p.first << " " << p.second;}
void print(vector<vector<int>> arr){rep(i,0,arr.size()){print(arr[i]);}}
void print(set<int> s){for(auto e = s.begin(); e != s.end(); e++){cout << *e << " ";}cout << endl;}
void print(map<int, int> mp){cout << "{";for(auto e = mp.begin(); e != mp.end(); e++){cout << "(" << e -> first << " " << e -> second << ")";}cout << "}" << endl;}

//main------------------------------------------------------------------------------------------

signed main(){


    int n = input();

    if(n == 1){
        print("Hello World");
    }else{
        int a,b;
        cin >> a >> b;
        print(a + b);
    }









}   

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <iomanip> // cout<<setprecision(n)
#include <functional> // std::function<void(long long)>
using namespace std;
#define All(v) (v).begin(),(v).end()
const long long mod = 1000000007;
const long long inf = mod*mod;
const int AMAX = 100000;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);
using ll = long long;
ll cnt[AMAX+1];
int main(void) {
    int N;
    ll K;
    cin >> N >> K;
    for (int i = 0; i < N; ++i) {
        int A, B;
        cin >> A >> B;
        cnt[A] += B;
    }
    for (int ans = 1; ans <= AMAX; ++ans){
        if (K <= cnt[ans]) {
            cout << ans << endl;
            break;  
        }
        K -= cnt[ans];
    }
    return 0;
}

Measured memory_bytes: 1152