akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h> 
using namespace std;
typedef long long ll;
template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;}
template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;}



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

    ll n;
    cin>>n;
    string s;
    cin>>s;
    ll ans = 0;
    vector<int> r,g;
    map<int,int> mp;
    ll cnt = 0;
    for(int i=0;i<n;i++){
        if(s[i] == 'R')r.push_back(i);
        else if(s[i]=='G')g.push_back(i);
        else{
            cnt++;
            mp[i]=1;
        }
    }
    for(int i=0;i<r.size();i++){
        for(int j=0;j<g.size();j++){
            int t = abs(r[i] - g[j]);
            int ma = max(r[i],g[j]);
            int ret = cnt;
            if(mp[ma+t])ret--;
            int mi = min(r[i],g[j]);
            if(mp[mi-t])ret--;
            int sum = r[i]+g[j];
            if(sum%2==0 && mp[sum/2])ret--;
            ans += ret;
        }
    }
    cout << ans << endl;

}

Measured memory_bytes: 4052
#include<bits/stdc++.h>
#define ll long long int
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define inf 1e9

using namespace std;

ll find(vector<ll> &h, ll n) {
	vector<ll> dp(n + 1);
	dp[1] = 0;
	for (ll i = 2; i <= n; i++) {
		ll opt1 = abs( h[i] - h[i - 1] ) + dp[i - 1];
		ll opt2 = (i == 2) ? inf : abs(h[i] - h[i - 2]) + dp[i - 2];
		dp[i] = min(opt1, opt2);
	}
	return dp[n];
}

int main() {

	fio

	ll n;
	cin >> n;

	vector<ll> h(n + 1);

	for (ll i = 1; i <= n; i++)
		cin >> h[i];

	cout << find(h, n) << "\n";

}



Measured memory_bytes: 1792
//#pragma GCC target("avx2")
//#pragma GCC optimize("O3")
   
//#include <x86intrin.h>
#include <bits/stdc++.h>   
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace __gnu_pbds;
using namespace std;

template<typename T> using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
     
#define F first
#define S second           
#define lb lower_bound               
#define ub upper_bound
#define pb push_back
#define pf push_front    
#define ppb pop_back
#define mp make_pair                                     
#define bpp __builtin_popcountll                                                                                        
#define sqr(x) ((x) * (x)) 
#define al 0x3F3F3F3F
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define in insert
#define ppf pop_front
#define endl '\n'
//#define int long long
 
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
 
const int mod = (int)1e9 + 7;
const int N = (int)3e5 + 123;
const ll inf = (ll)1e18 + 1;

const double pi = acos (-1.0);
const double eps = 1e-7;                  
const int dx[] = {0, 0, 1, 0, -1};
const int dy[] = {0, 1, 0, -1, 0};

int n;
ll a[N], res, sum;
bool used[N];

inline void boost () {                    
   ios_base :: sync_with_stdio (NULL);
   cin.tie (NULL), cout.tie (NULL);          
}                                                     

inline void Solve () {
   cin >> n;
   for (int i = 1; i <= n; i ++) cin >> a[i], sum ^= a[i];   
   for (int bit = 60; bit >= 0; bit --) {
      if (!(sum & (1ll << bit))) continue;
      for (int i = 1; i <= n; i ++)
         if (a[i] & (1ll << bit))
            a[i] -= (1ll << bit);
   }                                               
   for (int bit = 60; bit >= 0; bit --) {
      int pos = -1;
      for (int i = 1; i <= n; i ++) {
         if (used[i]) continue;
         if (a[i] & (1ll << bit)) {
            pos = i;
         }
      }
      if (pos != -1) {
         used[pos] = 1;
         for (int i = 1; i <= n; i ++)
            if (i != pos && (a[i] & (1ll << bit)))
               a[i] ^= a[pos];
      }
   }
   for (int i = 1; i <= n; i ++) res ^= a[i];
   cout << res + (sum ^ res);
}

main () {                                       
// freopen (".in", "r", stdin);    
// freopen (".out", "w", stdout);              
   boost ();
   int tt = 1;
   //cin >> tt;   
   while (tt --) {
      Solve ();
   }                                               
   return 0;      
}
                          

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <map>
const int MOD = 1e9+7;
typedef long long ll;
using namespace std;

ll llmax(ll x, ll y){
	if (x > y) return x;
	return y;
}


int main(){
	ll a, b;
	cin >> a >> b;
	ll digit = (ll)log2(b)+1;
	vector<ll> bit1(50);
	vector<ll> bit2(50);
	for (int i = 0; i < digit; i++){
		bit1[i] = a/(1LL<<(i+1))*(1LL<<i) + llmax(0, a%(1LL<<(i+1))-(1LL<<i));
		bit2[i] = (b+1)/(1LL<<(i+1))*(1LL<<i) + llmax(0, (b+1)%(1LL<<(i+1))-(1LL<<i));
	}
	ll ans = 0;
	for (int i = 0; i < digit; i++){
		ans += (bit2[i]-bit1[i])%2*(1LL<<i);
	}
	cout << ans << endl;
	return 0;
 }



Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

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

	public static void main(String[] args) {
		char[] str = ("$" + sc.next() + "$").toCharArray();
		int ans = 0;
		int s = 0;
		for (int i = 1; i < str.length; ++i) {
			if (str[i] == 'O' && str[i - 1] != 'O') s = i;
			if (str[i] == 'O' && str[i + 1] != 'O') {
				int l = i - s + 1;
				if (s >= l && str.length - i - 1 >= l) {
					boolean ok = true;
					for (int j = 0; j < l; ++j) {
						if (str[s - 1 - j] != 'J' || str[i + 1 + j] != 'I') {
							ok = false;
							break;
						}
					}
					if (ok) ans = Math.max(ans, l);
				}
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 40428
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define me BOSS
#define bug() cout<<"AIkahne aise"<<endl
ll A[5000001],bin[5000001];
vector<ll>v;
map<int,int>myMap;
set<int>mySet;
vector<pair<ll,ll> >vp;
/* Precode Start Here *\



     Sieve
void sieve()
{
    for(ll i=3; i<=2000; i+=2)
    {
        for(ll j=i*i; j<=4000000; j+=i)
            A[j]=1;
    }
    v.push_back(2);
    for(ll i=3; i<=4000000; i+=2)
        if(A[i]==0)
            v.push_back(i);
}

     Power Function Modulo P

ll modPow(ll a, ll x, ll p) {
    //calculates a^x mod p in logarithmic time.
    long res = 1;
    while(x > 0) {
        if( x % 2 != 0) {
            res = (res * a) % p;
        }
        a = (a * a) % p;
        x /= 2;
    }
    return res;
}


   factorial

ll fact(ll n)
{
    ll ans=1;
    for(ll i=1;i<=n;i++)
    {
        ans=(ans*i)%mod;
    }
    return ans;
}
     Calculating nCr using Fermats law Theorem

ll modInverse(ll a, ll p) {
    //calculates the modular multiplicative of a mod m.
    //(assuming p is prime).
    return modPow(a, p-2, p);
}


ll modBinomial(ll n, ll k, ll p) {
// calculates C(n,k) mod p (assuming p is prime).

    ll numerator = 1; // n * (n-1) * ... * (n-k+1)
    for (ll i=0; i<k; i++) {
        numerator = (numerator * (n-i) ) % p;
    }

    ll denominator = 1; // k!
    for (ll i=1; i<=k; i++) {
        denominator = (denominator * i) % p;
    }

    // numerator / denominator mod p.
    return ( numerator* modInverse(denominator,p) ) % p;
}
     num of divisor and euler totient

ll phi[1000001],mark[1000001],divi[1000001];;
void divisorPhi(ll n)
{
    for(int i=1;i<=n;i++)
        phi[i]=i;
    for(int i=2;i<=n;i++)
    {
        if(!mark[i])
        {
            for(int j=i;j<=n;j+=i)
            {
                mark[j]=1;
                phi[j]*=(1-1/(double)i);
            }
        }
    }
    for(ll i=1;i<=n;i++)
    {
        for(ll j=i;j<=n;j+=i)
            divi[j]++;
    }
}




/* Precode Ends */
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
 ll a,b;
 cin>>a>>b;
 if(a<=9&&b<=9)
 {
     cout<<a*b<<endl;
 }
 else
    cout<<-1<<endl;
return 0;
}



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

using namespace std;

const int N = 1e5 + 5 , MOD = 1e9 + 7;
int p[N] , memo[N][14];
string s;

int mul(int a , int b , int m) {
    return a * 1ll * b % m;
}

int add(int a , int b , int m) {
    a += b;
    while (a >= m) a -= m;
    while (a < 0) a += m;
    return a;
}

int solve (int i , int m) {
    if (i == s.size())
        return m == 5;

    int &ret = memo[i][m];
    if (~ret)
        return ret;

    if (s[i] != '?')
        return ret = solve(i + 1 , add(m , mul(s[i] , p[s.size() - i - 1] , 13) , 13));

    ret = 0;

    for (int j = 0 ;j <= 9 ;j++)
        ret = add(ret , solve(i + 1 , add(m , mul(j , p[s.size() - i - 1] , 13) , 13)) , MOD);

    return ret;
}

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

    p[0] = 1;
    for (int i = 1 ;i < N ;i++)
        p[i] = p[i - 1] * 10 % 13;

    cin >> s;
    for (char &c : s) if (c != '?') c -= '0';
    memset(memo , -1 , sizeof memo);
    cout << solve(0 , 0);
}

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

vector<int> v(3);

int main() {
    for (int i = 0; i < 3; i++) {
        int x; cin >> x;
        v[i] = x;
    }
    sort(v.begin(), v.end());
    
    for (int i = 0; i < 2; i++) cout << v[i] << " ";
    cout << v[2] << endl;
    
    return 0;
}


Measured memory_bytes: 3152
import java.util.Scanner;
class Main {
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int k = sc.nextInt();
    int n = sc.nextInt();
    int[] a = new int[n + 1];
    int i;
    for(i = 0; i<n; i++){
      a[i] = sc.nextInt();
    }
    a[n] = k;
    int max = a[n] - a[n-1] + a[0];
    for(i = 0 ; i < n ; i++){
      max = Math.max(max , a[i + 1] - a[i]);
    }


    System.out.println(k - max);

  }
}


Measured memory_bytes: 67148
S = list(input())

S.pop(-1)
if (len(S)) % 2 == 1:
  S.pop(-1)
while True:
  count = 0
  for i in range(int(len(S)/2)):
    if S[i] == S[int(len(S)/2) + i]:
      count += 1
      continue
    else:
      break
  if count == len(S)/2:
    print(len(S))
    break
  S.pop(-1)
  S.pop(-1)

Measured memory_bytes: 8952
import math
n = int(input())

dig = float('inf')
for a in range(1, int(math.sqrt(n)) + 1):
    if n % a:
        continue
    b = n // a
    tmp = max(int(math.log10(a)), int(math.log10(b))) + 1
    if tmp < dig:
        dig = tmp

print(dig)

Measured memory_bytes: 3060
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int CM = 130000;
char cn[CM + 10], * ci = cn + 10, c, * owa = cn + CM;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	//swap(c, ci[8]);
	ll tmp = *(ll*)ci;
	int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0);
	tmp = tmp << dig & ma1;
	tmp = tmp * 10 + (tmp >> 8) & ma2;
	tmp = tmp * 100 + (tmp >> 16) & ma3;
	tmp = tmp * 10000 + (tmp >> 32) & ma4;
	//swap(c, ci[8]);
	ci += (64 - dig >> 3) + 1;

	if (ci - owa > 0) {
		memcpy(cn, owa, 10);
		ci -= CM;
		fread(cn + 10, 1, CM, stdin);
	}
	return tmp;
}

char* di = cn;
const int MAX = 200000;
class shuturyoku_unko {
public:
	char C[MAX * 6 - 100000];
	int K[MAX + 10];
	constexpr shuturyoku_unko() : C(), K() {
		auto di = C + 1;
		C[0] = '0';
		K[1] = 1;
		rep1(i, MAX) {
			int X = i;
			int keta = 0;
			char c[10] = {};
			while (X) {
				*(c + keta) = '0' + X % 10;
				X /= 10;
				keta++;
			}
			for (int j = keta - 1; j >= 0; j--)* di++ = (*(c + j));
			K[i + 1] = K[i] + keta;
		}
	}
} f;
inline void putint(ll X) {
	int ue = X / 100000;
	if (ue >= 10) {
		memcpy(di, f.C + f.K[ue], f.K[ue + 1] - f.K[ue]);
		di += f.K[ue + 1] - f.K[ue];
		int sita = X - ue * 100000ll;
		rep(i, 5 - f.K[sita + 1] + f.K[sita])* di++ = '0';
		for (int i = f.K[sita]; i < f.K[sita + 1]; i++)* di++ = f.C[i];
	}
	else if (ue) {
		*di++ = f.C[f.K[ue]];
		int sita = X - ue * 100000ll;
		rep(i, 5 - f.K[sita + 1] + f.K[sita])* di++ = '0';
		for (int i = f.K[sita]; i < f.K[sita + 1]; i++)* di++ = f.C[i];
	}
	else for (int i = f.K[X]; i < f.K[X + 1]; i++)* di++ = f.C[i];
	*di++ = '\n';
}

int B[200001];

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


	fread(ci, 1, CM, stdin);

	int N = getint();
	ll kotae = 1;
	int A[200000];
	rep(i, N) kotae += B[(A[i] = getint())]++;
	int *a = A;
	
	int amari = N % 10800;
	int shou = N / 10800;
	rep(j, shou) {
		rep(k, 10800) putint(kotae - B[*a++]);
		fwrite(cn, 1, di - cn, stdout);
		di = cn;
	}
	rep(k, amari) putint(kotae - B[*a++]);
	fwrite(cn, 1, di - cn, stdout);

	Would you please return 0;
}

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

int main() {
    ll n,k,c;
    cin>>n>>k>>c;
    string s;
    cin>>s;
    ll cnt=0;
    V r;
    rep(i,n){
        if(s[n-1-i]=='o'){
            cnt++;
            r.push_back(n-1-i);
            i+=c;
        }
    }
    if(cnt==k){
        V l(k,0);
        reverse(r.begin(), r.end());
        ll pos=0;
        rep(i,n){
            if(s[i]=='o'){
                l[pos]=i;
                pos++;
                i+=c;
            }
        }
        rep(i,k){
            if(l[i]==r[i]){
                cout<<l[i]+1<<endl;
            }
        }
    }
}


Measured memory_bytes: 4980
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

MX = 10**18
n=ni()
a = sorted(nl())



num = 1
for i in range(n):
  num*=a[i]
  if num > MX:
    print(-1)
    exit()
print(num)

Measured memory_bytes: 21656
n, x, y = gets.split.map(&:to_i)
d = Array.new(n).map{Array.new(n, 0)}
1.upto(n) do |p|
    (p + 1).upto(n) do |q|
        d[p - 1][q - 1] = [q - p, (x - p).abs + 1 + (y - q).abs].min
    end
end
count = Array.new(n, 0)
d.each do |r|
    r.each do |c|
        count[c] += 1
    end
end
puts count.slice(1..n)

Measured memory_bytes: 34592
h, w, a, b = map(int, input().split())

def cmb1(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 10**6
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

ans = 0
for i in range(b, w):
    ans += cmb1(i+h-1-a, i, mod)*cmb1(w-1-i+a-1, a-1, mod)
    ans %= mod
print(ans)

Measured memory_bytes: 127572
n = int(input())
x = []
for i in range(n):
    a = list(map(int,input().split()))
    x.append(a)
#print(x)
path_length = 0
cnt = 0
import itertools
for p in itertools.permutations(x):
    #print(p, p[1:])
    cnt += 1
    for (x1,y1), (x2,y2) in zip(p, p[1:]):
        path_length += ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** .5
#print(cnt)
print(path_length/(cnt))

Measured memory_bytes: 3064
N = int(input())
A = [0] * (N + 1)
A = list(map(int,input().split()))
# for i in range(N):
#     A[i] = int(i)
cMoney = 1000
stock = 0
A.append(0)
# for i in range(N):
#     if i == N - 1:
#         if stock > 0:
#             cMoney += A[i] * stock
#             stock = 0
#         continue

#     if A[i] >= A[i+1]:
#         if stock > 0:
#             cMoney += A[i] * stock
#             stock = 0
#     else:
#         stock = cMoney // A[i]
#         cMoney -= stock * A[i]

# print(cMoney)

for i in range(N):
    stock = 0
    if A[i] < A[i+1]:
        stock = cMoney // A[i]

    cMoney += (A[i+1] - A[i]) * stock
print(cMoney)

Measured memory_bytes: 9056
n = int(raw_input())
while n != 0:
    pass_flag = 0
    sales_dict = {}
    id_list = []
    for x in range(0, n):
        data = raw_input()
        data_list = map(int, data.split(' '))
        if not data_list[0] in sales_dict:
            sales_dict[data_list[0]] = data_list[1] * data_list[2]
            id_list.append(data_list[0])
        else:
            sales_dict[data_list[0]] += data_list[1] * data_list[2]
    for x in id_list:
        if  sales_dict[x] >= 1000000:
            print x
            pass_flag = 1
    if pass_flag == 0:
        print 'NA'
    n = int(raw_input())

Measured memory_bytes: 6364
n=int(input())
a=[0]+list(map(int,input().split()))
b=[0]*(n+1)
for i in range(n,0,-1):
  s=0
  t=i
  while t<=n:
    s+=b[t]
    t+=i
  if s%2==a[i]:
    pass
  else:
    b[i]=1
ans=0
c=[]
for i,bb in enumerate(b):
  if bb>0:
    ans+=bb
    c.append(i)
if ans>0:
  print(ans)
  print(*c)
else:
  print(0)

Measured memory_bytes: 17628
n=int(input())
l=[0,7,14,21]
count=0
for i in l:
    if n%7==0:
        count+=1
        break
    elif (n-i)>0 and (n-i)%4==0:
        count+=1
        break
    else:
        count=0
print('Yes' if count>0 else 'No')

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

int main(){
  ll n,k,a,b;
  cin >> n >> k;
  a=1;
  b=0;
  do{
    a=a*k;
    b+=1;
  }while(n>=a);
  cout << b;
}

Measured memory_bytes: 256
var
    s,t,r:ansistring;
    i:longint;
    f:array[0..31] of longint;
begin
    readln(s);readln(t);
    for i:=1 to length(s) do
        if f[ord(s[i])-97]=0 then f[ord(s[i])-97]:=ord(t[i])-97
        else if f[ord(s[i])-97]<>ord(t[i])-97 then 
            begin
                writeln('No');
                exit;
            end;
    r:=s;s:=t;t:=r;fillchar(f,sizeof(f),0);
    for i:=1 to length(s) do
        if f[ord(s[i])-97]=0 then f[ord(s[i])-97]:=ord(t[i])-97
        else if f[ord(s[i])-97]<>ord(t[i])-97 then 
            begin
                writeln('No');
                exit;
            end;
    writeln('Yes');
end.

Measured memory_bytes: 640
N, M = map(int, input().split())
A = sorted(list(map(int, input().split())))
bc = [0] * M
for i in range(M):
    bc[i] = list(map(int, input().split()))

bc = sorted(bc, key= lambda x: x[1], reverse=True)

n = 0
f = 0
for i in range(M):
    for j in range(bc[i][0]):
        if A[n] < bc[i][1]:
            A[n] = bc[i][1]
            n += 1
            if n == N:
                f = 1
                break
        else:
            f = 1
    if f == 1:
        break

print(sum(A))

Measured memory_bytes: 99144
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>

#include <cmath>
#include <iomanip>

using namespace std;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  int dp[n][3]; // dp[i][j] represents the maximum happiness at the end of day i+1 if Taro did activity number j that day.
  int cur;
  cin >> cur;
  dp[0][0] = cur;
  cin >> cur;
  dp[0][1] = cur;
  cin >> cur;
  dp[0][2] = cur;
  for (int i = 1; i < n; i++) {
    cin >> cur;
    dp[i][0] = cur+max(dp[i-1][1], dp[i-1][2]);
    cin >> cur;
    dp[i][1] = cur+max(dp[i-1][0], dp[i-1][2]);
    cin >> cur;
    dp[i][2] = cur+max(dp[i-1][0], dp[i-1][1]);
  }
  cout << *max_element(dp[n-1], dp[n-1]+3) << "\n";
  return 0;
}

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






int main(){

  

  int n,m;
  cin>>n>>m;
  
  vector<vector<pair<int,int>>> data(n+1,vector<pair<int,int>>(0));
  
  for (int i=1;i<=m;i++){
    int p,y;
    cin>>p>>y;
    
    pair<int,int> tmp=make_pair(y,i);
    
    data.at(p).push_back(tmp);
  }
  
  for (int i=1;i<=n;i++){
    sort(data.at(i).begin(),data.at(i).end());
  }


  
  
  vector<string> answer(m+1);
  
  for (int i=1;i<=n;i++){
    int provsize=int(data.at(i).size());
    
    for (int j=0;j<provsize;j++){
      
      string formerstring="";
      string latterstring="";
      
      string formernumber=to_string(i);
      string latternumber=to_string(j+1);
      
      
      for (int k=0;k<(6-int(formernumber.size()));k++){
        formerstring+="0";
      }
      formerstring+=formernumber;
      for (int k=0;k<(6-int(latternumber.size()));k++){
        latterstring+="0";
      }
      latterstring+=latternumber;
      

      
      answer.at(data.at(i).at(j).second)=(formerstring+latterstring);
      
    }
  }
  
  for (int i=1;i<=m;i++){
    cout<<answer.at(i)<<endl;
  }
  
  
           
    
      
           
      
      
      
    
  
  
  
    
    
    
    


  
}

Measured memory_bytes: 12416
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vll = vector<vl>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1e9+7;
const ll INF = 2e15;
template<class T> void print(const T& t){ cout << t << endl; }
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; }
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

int main(){
  ll n;
  cin>>n;
  vl a(n);
  ll count = 0;
  bool z = true;
  rep(i, n){
    cin >> a[i];
    if(a[i]==0){
      count++;
    }
  }
  if(count==n){
    print("Yes");
    return 0;
  }
  else if (n % 3 != 0){
    print("No");
    return 0;
  }
  sort(all(a));
  ll c = a[0] ^ a[n / 3] ^ a[n - 1];
  if (count == n / 3 && a[n / 3] == a[n - 1]){
    print("Yes");
  }
  else if(a[0]==a[n/3-1]&&a[n/3]==a[n/3*2-1]&&a[n/3*2]==a[n-1]&&a[0]!=a[n/3]&&a[n/3]!=a[n/3*2]&&c==0){
    print("Yes");
  }
  else{
    print("No");
  }
}


Measured memory_bytes: 4056
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0;i<ll(n);i++)
long long gcd(long long a, long long b) {
    if (b == 0) {
        return a;
    } else {
        return gcd(b, a % b);
    }
}
 
/*  lcm (a, b) : 2整数版
    入力：整数 a, b
    出力：aとbの最小公倍数
*/
long long lcm(long long a, long long b) {
    long long d = gcd(a, b);
    return a / d * b;
}
int main() {
    ll a, b, c, d, ans;
    cin >> a >> b >> c >> d;
    ans = b - a + 1;
    //cout << ans << ',';
    if (c <= b && b - b%c >= a) ans -= (b - b%c - a)/c + 1;
    //cout << ans << ',';
    if (d <= b && b - b%d >= a) ans -= (b - b%d - a)/d + 1;
    //cout << ans << ',';
    if (lcm(c,d) <= b && b - b%(lcm(c,d)) >= a) ans += (b - b%(lcm(c,d)) - a )/(lcm(c,d)) + 1;
    cout << ans << endl;
    return 0;
}


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

int main(){
    int N;
    cin >> N;
    if(N<10)cout << N << endl;
    else if(N<100) cout << 9 << endl;
    else if(N<1000) cout << N-90 << endl;
    else if(N<10000) cout << 909 << endl;
    else if(N<100000) cout << N-9090 << endl;
    else cout << 90909 << endl;
}

Measured memory_bytes: 256
times = []

for i in range(5):
    times.append(int(input()))

min_over = 9
loss_index = 0

for index, time in enumerate(times):
    step, mod = divmod(time, 10)
    if mod != 0:
        if min_over > mod:
            loss_index = index
            min_over = mod

fin = 0
for i in range(5):
    if i == loss_index:
       fin += times[i]
    else:
        step, mod = divmod(times[i], 10)
        if mod == 0:
            fin += times[i]
        else:
            fin += (step + 1) * 10

print(fin)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7/*998244353*/;
const ll INF = 1LL << 60;
ll mod_pow(ll, ll, ll); ll mod_fact(ll, ll); ll mod_inv(ll, ll); ll gcd(ll, ll); ll lcm(ll, ll);
//
int main(){
    ll a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;
    ll total = 0;
    total += min(a + b, 2 * c) * min(x, y);
    if(x == max(x, y)){
        x -= min(x,y);
        total += x * min(a, 2 * c);
    }
    else{
        y -= min(x,y);
        total += y * min(b, 2 * c);
    }
    cout << total;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b)  for(int i=(a),i##formax=(b);i< i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formin=(b);i>=i##formin;i--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max((x),(y))
#define mins(x,y) x=min((x),(y))
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define all(a) ((a).begin()),((a).end())
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define bit(n) (1LL<<(n))
typedef long long ll;
typedef __int128_t lll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>using P=pair<T,Y>;
template<class T,class Y>ostream& operator<<(ostream&o,P<T,Y>&p){return o<<"("<<p.fi<<","<<p.se<<")";}
template<class T>ostream& operator<<(ostream&o,V<T>&v){for(T&t:v)o<<t<<",";return o;}
template<class T>void uniq(V<T>&v){sort(all(v));v.erase(unique(all(v)), v.end());}
template<class A,size_t N,class T>void Fill(A(&a)[N],const T&v){fill((T*)a,(T*)(a+N),v);}

const int MOD = 1e9+7; //998244353;

lll gcd(lll a,lll b,lll&x,lll&y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll modInv(ll a,ll m=MOD){lll x,y;gcd(a,m,x,y);return(x%m+m)%m;}
ll modPow(lll a,lll n,ll m=MOD){lll p=1;for(;n;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return p;}
//V<ll>Fac,Rac;void setF(int n,int m=MOD){Fac=Rac=V<ll>(++n);Fac[0]=1;FOR(i,1,n)Fac[i]=Fac[i-1]*i%m;Rac[n-1]=modInv(Fac[n-1],m);FORR(i,n-1,1)Rac[i-1]=Rac[i]*i%m;}
//ll comb(int a,int b,int m=MOD){return a<b||b<0?0:Fac[a]*Rac[b]%m*Rac[a-b]%m;}

const int IINF = 1e9+6;
const ll LINF = 1e18;
const int N = 2e5;
int n, A[N], c[N];
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  ll ans = 0;
  FOR(i, 0, n){
    cin >> A[i];
    A[i]--;
    ans += c[A[i]]++;
  }
  ans++;
  FOR(i, 0, n) cout << ans-c[A[i]] << endl;
}

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

## Library

import sys
from fractions import gcd
import math
from math import ceil,floor
import collections

## input

# n=int(input())
# A,B,C,D=map(int, input().split())
# string = input()
# list = list(map(int, input().split()))

A = int(input())
B = int(input())
C = int(input())
X = int(input())

## Logic

ans = 0
for i in range(0,min(X//500,A)+1):
    for j in range(0,min((X-500*i)//100,B)+1):
        for k in range(0,min(X-500*i-100*j,C)+1):
            if X-500*i-100*j-50*k == 0:
                ans += 1
                break

print(ans)


Measured memory_bytes: 69228
#include <iostream>

using namespace std;
//#define long long ll

long long gcd(long long a, long long b){
    if (a == 0 || b == 0) return 0;
    
    // Make sure a has greater value
    if (a < b) {
        long long temp = a;
        a = b;
        b = temp;
    }
    
    // Calculate gcd which will be in b
    long long r = a % b;
    while(r != 0) {
        a = b;
        b = r;
        r = a % b;
    }
    
    return b;
}

// Returns least common multiple of two int a, b
long long lcm(long long a, long long b){
    return a * (b / gcd(a, b));
}
int N;
int main() {
  cin >> N;
  long long t, ans = 1LL;
  for(int i = 0; i < N; i++) {
    cin >> t;
    ans = lcm(ans, t);
  }
  cout << ans;
}

Measured memory_bytes: 256
function main(input) {
  const args = input.split('\n');
  const N = parseInt(args[0], 10);
  const VA = args[1].split(' ').map(n => parseInt(n, 10));
  const CA = args[2].split(' ').map(n => parseInt(n, 10));
  //VAからCAを引いたときの値を入れる配列
  let GA = [];
  let ans = 0;
  
  for (let i = 0; i < N; i++) {
    GA.push(VA[i] - CA[i]);
  }
  
  for (let i = 0; i < N; i++) {
    if (GA[i] > 0) { ans += GA[i]; }
  }
  
  console.log(ans);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 29528
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using Graph = vector<vector<pii>>;
const int INF = 1e9 + 1;
const ll LLINF = 1e18;
const int MOD = 1e9 + 7;

int main() {
    int N;
    cin >> N;
    int cnt = 0;
    bool ok = false;
    for (int i = 0; i < N; ++i) {
        int a;
        cin >> a;
        if (a == cnt + 1) {
            ok = true;
            cnt++;
        }
    }
    cout << (ok ? N - cnt : -1) << endl;
    return 0;
}


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

int main()
{
    long long q, h, s, d, n;
    cin >> q >> h >> s >> d >> n;

    long long oneL;
    oneL = q * 4 < 2 * h ? q * 4 : 2 * h;
    oneL = oneL < s ? oneL : s;

    if (n % 2 == 0 && oneL * 2 < d) {
        cout << oneL * n << endl;
    } else if (n % 2 == 0 && oneL * 2 > d) {
        cout << (n / 2) * d << endl;
    } else if (n % 2 != 0 && oneL * 2 < d) {
        cout << oneL * n << endl;
    } else if (n % 2 != 0 && oneL * 2 > d) {
        cout << ((n / 2) * d + (n % 2) * oneL) << endl;
    }
}


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

#define EPS (1e-10)
#define rep(i, a, b) for (int i = a; i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = b - 1; i >= (int)(a); --i)
#define all(a) a.begin(), a.end()

using namespace std;
using ll = long long;
using vi = vector<int>;
using vb = vector<bool>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;
using vvb = vector<vb>;

constexpr int MOD = 1000000007;

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

    int n, m;
    cin >> n >> m;

    // O(nlog(n))
    priority_queue<ll> q;
    rep(_, 0, n) {
        ll a;
        cin >> a;
        q.push(a);
    }

    // O(mlog(n))
    rep(_, 0, m) {
        ll a = q.top() / 2;
        q.pop();
        q.push(a);
    }

    ll ans = 0;
    rep(i, 0, n) {
        ll a = q.top();
        q.pop();
        ans += a;
    }

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

Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long int
#define rep(i, n) for(int i = 0; i < n; i++)
#define repp(i, n) for(int i = 1; i <= n; i++)
#define sort(v) sort((v).begin(), (v).end())
#define pb push_back
#define mp make_pair
#define riverse(v) reverse((v).begin(), (v).end())
using vi = vector<int>;
using vs = vector<string>;
using vvi = vector<vi>;
using vll = vector<ll>;
const int MOD = 1e9+7;


int main() {
    int N, M, X;
    cin >> N >> M >> X;
    vi C(N);
    vvi A(N, vi(M));
    rep(i, N) {
        cin >> C[i];
        rep(j, M) {
            cin >> A[i][j];
        }
    }
    vll kouho;
    for (int bit = 0; bit < (1 << N); ++bit) {
        vll v(M, 0);
        ll cost = 0;
        for (int i = 0; i < N; ++i) {
            if (bit & (1 << i)) {
                cost += C[i];
                rep(j, M) {
                    v[j] += A[i][j];
                }
            }
        }
        sort(v);
        if (v[0] >= X) kouho.push_back(cost);
    }
    if (!kouho.empty()) {
        sort(kouho);
        cout << kouho[0] << endl;
    }
    else cout << -1 << endl;
}

Measured memory_bytes: 3692
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include <string.h>
#include <math.h>

using namespace std;

vector<int> n;
string ans = "";

void df(int c, int sum, string s) {
	if (ans != "") return;
	if (c == n.size()) {
		if (sum == 7)ans = s;
		return;
	}
	df(c + 1, sum + n[c], s + "+" + std::to_string(n[c]));
	df(c + 1, sum - n[c], s + "-" + std::to_string(n[c]));
	return;
}

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

	for (int i = 0; i < s.size(); i++) n.push_back(s[i] - '0');
	df(1, n[0], std::to_string(n[0]));
	cout << ans << "=7" << endl;

	return 0;
}


Measured memory_bytes: 256
/*
 *  author : Atul Anand   
 *  created on : Thu Apr 02 2020
 */

import java.io.*;
import java.util.*;

public class Main{

    public static void main(String[] args) throws IOException {
        int r = in.nextInt();
        int D = in.nextInt();
        int x = in.nextInt();
        int ans = x;
        for(int i = 2001; i <= 2010; i++){
            ans = r*ans - D;
            println(ans);
        }
        
        in.close();
        out.close();
    }

    static int MIN = Integer.MIN_VALUE;
    static int MAX = Integer.MAX_VALUE;
    static Reader in = new Reader();
    static PrintWriter out = new PrintWriter(System.out);

    static void read(int arr[], int N) throws IOException { 
    	for(int i = 0; i < N; i++){ 
    		arr[i] = in.nextInt(); 
    	} 
    }
    
    static void read(long arr[], int N) throws IOException { 
    	for(int i = 0; i < N; i++){ 
    		arr[i] = in.nextLong(); 
    	} 
    }
    
    static void read(String arr[], int N) throws IOException { 
    	for(int i = 0; i < N; i++){ 
    		arr[i] = in.next(); 
    	} 
    }
    
    static void print(Object O) {  
    	out.print(O); 
    }
    
    static void println(Object O) { 
    	out.println(O); 
    }
    
    static void println(int arr[]) { 
    	for(int i = 0; i < arr.length; i++){ 
    		print(arr[i]+" "); 
    	} 
    	println(""); 
    }

    static void println(int arr[][]) { 
    	for(int i = 0; i < arr.length; i++){ 
    		println(arr[i]); 
    	}
    }
    
    static void debug(Object O) { 
    	System.out.println(O); 
    }
}

class Reader {
    BufferedReader reader;
    StringTokenizer tokenizer;

    Reader() {
        reader = new BufferedReader(new InputStreamReader(System.in));
        tokenizer = new StringTokenizer("");
    }

    String next() throws IOException {
        while (!tokenizer.hasMoreTokens() ) { 
            tokenizer = new StringTokenizer(reader.readLine()); 
        }
        return tokenizer.nextToken();
    }

    int nextInt() throws IOException { 
        return Integer.parseInt(next()); 
    }
    
    double nextDouble() throws IOException { 
        return Double.parseDouble(next());
    }
    
    long nextLong() throws IOException { 
        return Long.parseLong(next()); 
    }
    
    String nextLine() throws IOException { 
        return reader.readLine(); 
    }
    
    void close() throws IOException { 
        reader.close(); 
    }
}

Measured memory_bytes: 20944
A, B = map(int, input().split())
S = input()
for a in range(A):
    if S[a] not in ("0", "1", "2", "3", "4", "5", "6", "7", "8", "9"):
        print("No")
        exit()
if S[A] != "-":
    print("No")
    exit()
for b in range(B):
    if S[A + 1 + b] not in ("0", "1", "2", "3", "4", "5", "6", "7", "8", "9"):
        print("No")
        exit()
print("Yes")


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

int main(){
  ll N, K;
  cin >> N >> K;
  vl A(N);
  rep(i, N) cin >> A[i];

  ll ans = 1 + (N - K) / (K - 1) + ((N - K) % (K - 1) > 0 ? 1 : 0);

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


Measured memory_bytes: 1024
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <complex>

#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

#include <stdexcept>

using namespace std;

// type alias
using ll = long long;
using ull = unsigned long long;
using comp = complex<double>;

const ll MOD = 1000000007LL;
const double PI = 3.14159265358979323846;

//conversion
//------------------------------------------
inline int toint(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class t> inline string tostring(t x) { ostringstream sout; sout << x; return sout.str(); }

// for loop
#define REP(i, n) for ((i) = 0;(i) < (ll)(n);(i)++)

//debug
#define DUMP(x)  cerr << #x << " = " << (x) << endl
#define DEBUG(x) cerr << #x << " = " << (x) << " (l" << __line__ << ")" << " " << __file__ << endl

int solve() {
	ll n;
	cin >> n;

	//vector<pair<ll, ll>> abs;
	vector<ll> as;
	vector<ll> bs;
	ll a, b;
	for (ll i = 0; i < n; ++i) {
		cin >> a >> b;
		as.emplace_back(a);
		bs.emplace_back(b);
	}
	sort(as.begin(), as.end());
	sort(bs.begin(), bs.end());

	ll res = 0;
	if (n % 2 == 0) {
		res = bs[n / 2LL] + bs[n / 2LL - 1LL] - as[n / 2LL] - as[n / 2LL - 1LL] + 1LL;
	}
	else {
		res = bs[(n - 1LL) / 2LL] - as[(n - 1LL) / 2LL] + 1LL;
	}

	cout << res << endl;

	return 0;
}

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

	solve();

	return 0;
}


Measured memory_bytes: 6656
import java.util.*;
public class Main
  {
  public static void main(String args[])
    {
    Scanner sc=new Scanner(System.in);
    int N=sc.nextInt();
    int M=sc.nextInt();
    int A=sc.nextInt();
    int i=0;
    if(N>=M)
      {
      i=A/N;
      if((A%N)!=0)
        ++i;
      }
    else
      {
      i=A/M;
      if((A%M)!=0)
        ++i;
      }
    System.out.println(i);
    }
  }


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


# 入力を整数に変換して受け取る
def input_int():
    return int(input())


# マイナス1した値を返却
def int1(x):
    return int(x) - 1


# 半角スペース区切り入力をIntに変換してMapで受け取る
def input_to_int_map():
    return map(int, input().split())


# 半角スペース区切り入力をIntに変換して受け取る
def input_to_int_tuple():
    return tuple(map(int, input().split()))


# 半角スペース区切り入力をIntに変換してマイナス1した値を受け取る
def input_to_int_tuple_minus1():
    return tuple(map(int1, input().split()))


import collections
import math
def main():

    n = input_int()
    ans = collections.defaultdict(set)
    max_val = int(math.sqrt(n)) + 1
    for x in range(1, max_val):
        for y in range(1, max_val):
            for z in range(1, max_val):
                temp = (x ** 2) + (y ** 2) + (z ** 2) + (x * y) + (x * z) + (y * z)
                if temp <= n:
                    ans[temp].add((x, y, z))

    for i in range(1, n + 1):
        print(len(ans[i]))


if __name__ == "__main__":
    main()


Measured memory_bytes: 43564
import sys


def input():
    return sys.stdin.readline()[:-1]

# N = int(input())
# A = [int(x) for x in input().split()]
# a, b, c = map(int, input().split())
# name1 = str(input())
# alph = {"A": 1, "B": 2, "C": 3, "D": 4, "E": 5}


a,b=map(int,input().split())
if b%a==0:
    print(a+b)
else:
    print(b-a)

Measured memory_bytes: 2940
n = int(input())
a = list(map(int, input().split()))
c4 = 0
c2 = 0
for i in a:
    if i%4 == 0:
        c4 += 1
    elif i%2 == 0:
        c2 += 1
c0 = n - c4 - c2

ans = False
if c2 < 2:
    if c0 + c2 <= c4 + 1:
        ans = True
else:
    if c0 <= c4:
        ans = True
if ans:
    print("Yes")
else:
    print("No")

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

int main() {
	string s, t; cin >> s >> t;
	sort(s.begin(), s.end());
	sort(t.begin(), t.end());
	reverse(t.begin(), t.end());
	
	if( s < t )cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll INF = 1000000000;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int s,w;
    cin>>s>>w;
    if(w>=s){
    	cout<<"unsafe"<<'\n';
    }
    else{
    	cout<<"safe"<<'\n';
    }
    return 0;
}

Measured memory_bytes: 3648
//Volume1-0141
import java.util.Scanner;

public class Main {

	private static int x,y,dr,n;
	private static final int     X   = 0,
			                     Y   = 1;
	private static final int[][] dir = {{0,-1},{1,0},{0,1},{-1,0}};
	private static char[][] ptn;

	public static void main(String[] args){

		//declare
		int d;

		//input
        Scanner sc = new Scanner(System.in);
        d = sc.nextInt();
        while(d-- > 0){
        	n   = sc.nextInt();
        	ptn = new char[n][n];
        	init();
        	while(true){
        		if(search()){
        			Go();
        		} else {
        			break;
        		}
        	}
        	print();
        	if(d > 0){System.out.println();}
        }
	}

	private static void print(){
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				System.out.print(ptn[i][j]);
			}
			System.out.println();
		}
	}

	private static void Go(){
		x += dir[dr][X];
		y += dir[dr][Y];
		ptn[y][x] = '#';
	}

	private static void init(){
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				ptn[i][j] = ' ';
			}
		}
    	x   = 0;
    	y   = n;
    	dr  = 0;
	}

	private static boolean search(){
		boolean ret = false;
		for(int i=0;i<2;i++){
			if(chk(x,y,dr)){ret = true;break;}
			turn();
		}
		return ret;
	}

	private static boolean chk(int x,int y,int r){
		boolean ret = false;
		int r_x,r_y;
		int s_x = x+dir[r][X];
		int s_y = y+dir[r][Y];
		if(s_x < 0 || s_x >= n || s_y < 0 || s_y >= n || ptn[s_y][s_x] == '#'){
			return ret;
		}
		r=trn(r,-1);
		ret = true;
		for(int i=0;i<3;i++){
			r_x = s_x+dir[r][X];
			r_y = s_y+dir[r][Y];
			if(0 <= r_x && r_x < n && 0 <= r_y && r_y < n && ptn[r_y][r_x] == '#'){
				ret = false;
				break;
			}
			r = trn(r);
		}
		return ret;
	}

	private static int trn(int r){
		return ++r%4;
	}
	private static int trn(int r,int i){
		return (r+i+4)%4;
	}

	private static void turn(){
		dr = ++dr%4;
	}
}

Measured memory_bytes: 25016
#include<iostream>
 
using namespace std;
 
int main(){
	int N;
	char s[101], t[101];
	int ans;
	bool flag;
	cin >> N;
	cin >> s >> t;
	ans = N * 2;
	for(int i = 0; i < N; i++){
		flag = true;
		for(int j = 0; j < N - i; j++){
			if(s[i + j] != t[j]){
				flag = false;
				break;
			}
		}
		if(flag == true){
			ans -= N - i;
			break;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int a, b, d, r;
	double f;
	scanf("%d%d", &a, &b);
	d=a/b; r=a%b; f=(double)a/b;
	printf("%d %d %f\n", d, r, f);
	return 0;
}

Measured memory_bytes: 636
#include <bits/stdc++.h>
#ifdef __DEBUG__
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
#else
    #define DBG(X)
    #define SAY(X)
#endif

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int dx[]={1, 0, -1, 0, 1,-1, 1,-1};
int dy[]={0, 1, 0, -1, 1, 1,-1,-1};
const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);

inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const map<T, S> p) { for (auto el : p) cout << "[" << el.first << ";" << el.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const deque<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const set<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

int N,M;
vector<vector<int>> Lang;
map<int,int> mpL;
void input(){
    fast_io();
    cin >> N >> M;
    Lang.resize(N);
    for (int i = 0; i < N; i++)
    {
        int k; cin >> k;
        for (int j = 0; j < k; j++)
        {
            int l; cin >> l;
            // mpL[l] = 0;
            Lang[i].push_back(l);
        }
        
    }
    
}

struct UnionFind {
  vector< int > data;
 
  UnionFind(int sz) {
    data.assign(sz, -1);
  }
 
  bool unite(int x, int y) {
    x = find(x), y = find(y);
    if(x == y) return (false);
    if(data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return (true);
  }
 
  int find(int k) {
    if(data[k] < 0) return (k);
    return (data[k] = find(data[k]));
  }
 
  int size(int k) {
    return (-data[find(k)]);
  }
  bool same(int x,int y){
      return (find(x)==find(y));
  }
};

int solve(){
    UnionFind uf(N+M+1);
    for (int i = 0; i < N; i++)
    {
        for(int l:Lang[i]){
            uf.unite(i,l+N);
        }
    }
    bool flag = true;
    for (int i = 0; i < N; i++)
    {
        if(!uf.same(i,(i+1)%N)) {
            flag = false;
            break;
            }
    }

    if(flag) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}   

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

Measured memory_bytes: 6528
#include<iostream>
#include<string>
#include<vector>

using namespace std;

int main(void) {
	int m,n;
	vector<long int> a;
	int choice_Amount = 0;
	long long max = 0;
	cin >> n >> m;

	while (n--) 
	{
		int buf;
		cin >> buf;
		max+=buf;
		a.push_back(buf);
	}

	//選べる個数
	for (int i = 0; i < a.size();i++)
	{
		if (a[i] * 4 * m >= max)
		{
			choice_Amount++;
			if (choice_Amount >= m)
				break;
		}
	}
	if (choice_Amount >= m)
		cout << "Yes";
	else
		cout << "No";

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<queue>
#define int long long
using namespace std;
const int inf = 1000000000;

signed main() {
  int n, m;
  cin>>n>>m;
  vector<int>g[n];
  int a, b;
  for(int i = 0; i < m; i++) {
    cin>>a>>b;
    a--;
    b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  
  vector<int>dist(n, inf), pre(n, -1);
  queue<int>q;
  dist[0] = 0;
  q.push(0);
  while(!q.empty()){
    int v = q.front();
    q.pop();
    for(int u : g[v]){
      if(dist[u] != inf) continue;
      dist[u] = dist[v] + 1;
      pre[u] = v;
      q.push(u);
    }
  }
  
  cout<<"\nYes";
  for(int i=1; i<n; i++)
    cout<<"\n"<<pre[i]+1;
  return 0;
}

Measured memory_bytes: 13600