akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef pair<int,int> pint;
typedef pair<long long, long long> pll;

#define MP make_pair
#define PB push_back
#define ALL(s) (s).begin(),(s).end()
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << 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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P) 
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P) 
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P) 
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s; }



const string paint[3][5] = 
{
    {
        "..#..",
        ".###.",
        "..#..",
        ".....",
        "....."
    },
    {
        "..###",
        "..###",
        "..###",
        ".....",
        "....."
    },
    {
        "..#..",
        ".###.",
        "#####",
        ".###.",
        "..#.."
    }
};

const int dy[3] = {1, 1, 2};
const int dx[3] = {0, 1, 0};

bool solve(vector<vint> &s, int n, int y, int x) {
    if (x == 15) {
        ++y;
        x = 5;
        if (y == 15) return n == 0;
    }
    
    if (s[y][x] == 0) return solve(s, n, y, x+1);
    if (n == 0) return false;
    
    for (int k = 0; k < 3; ++k) {
        bool ok = true;
        for (int i = 0; i < 5; ++i) {
            for (int j = 0; j < 5; ++j) {
                if (paint[k][i][j] == '#' && s[y+i][x+j-2] == 0)
                    ok = false;
            }
        }
        if (!ok) continue;
        
        for (int i = 0; i < 5; ++i) 
            for (int j = 0; j < 5; ++j) 
                if (paint[k][i][j] == '#')
                    --s[y+i][x+j-2];

        if (solve(s, n-1, y, x)) {
            cout << (x - 5 + dx[k]) << " " << (y - 5 + dy[k]) << " " << (k+1) << endl;
            return true;
        }
        
        for (int i = 0; i < 5; ++i) 
            for (int j = 0; j < 5; ++j)
                if (paint[k][i][j] == '#')
                    ++s[y+i][x+j-2];
    }
    
    return false;
}
        

int main() {
    int n;
    cin >> n;
    
    vector<vint> s(20, vint(20));
    for (int i = 5; i < 15; ++i)
        for (int j = 5; j < 15; ++j)
            cin >> s[i][j];
    
    solve(s, n, 5, 5);
    
    return 0;
}


Measured memory_bytes: 1224
#include <bits/stdc++.h>
using namespace std;
const int INF = 2100100100;
using ll = long long;

int main() {
    ll n,k;
    cin >> n >>k;
    vector<ll> h(n);
    for (int i=0;i<n;i++){
        cin >> h.at(i);
    }
    sort(h.begin(),h.end(),greater<int>());
    int cnt=0;
    ll sum =0;
    for (int i=0;i<n;i++){
        if (cnt < k){
            h.at(i) = 0;
        }
        sum+=h.at(i);
        cnt++;
    }
    cout << sum << endl;
    
    return 0;
}



Measured memory_bytes: 1792
let h, w, m, ans, a_ss = Scanf.(scanf "%d %d" @@ fun h w -> Array.(h, w, ref 0, make (h * w) (0, 0, 0, 0), init h @@ fun _ -> init w @@ fun _ -> scanf " %d" (+) 0))
let _ = Array.(iteri (fun i a_s -> iteri (fun j a -> let k, d = if i mod 2 = 1 then w - 1 - j, -1 else j, 1 in if a_s.(k) mod 2 = 1 && (j <> w - 1 || i <> h - 1) then let i1, j1 = if j = w - 1 then i + 1, k else i, k + d in ans.(!m) <- i + 1, k + 1, i1 + 1, j1 + 1; incr m; a_ss.(i1).(j1) <- a_ss.(i1).(j1) + 1) a_s) a_ss; Printf.(printf "%d\n" !m; iteri (fun i (a, b, c, d) -> if i < !m then printf "%d %d %d %d\n" a b c d) ans))

Measured memory_bytes: 14208
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1e9+7
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(x) (x).begin(),(x).end()
ll min(ll a,ll b){
  if(a>b){
    return b;
    }
      else{
        return a;
      }
  }
  
  ll max(ll a,ll b){
    if(a>b){
      return a;
    }
    else{
      return b;
    }
  }

ll power(ll a,ll b){
 ll ans=1;
 for(ll i=1;i<=b;i++){
ans*=a;
  }
  return ans;
}

 long long int gcd(long long int m,long long int n){
 	if(n==0){
       return m;
     }
   return gcd(n,m%n);
 }
long long int lcm(long long int number1,long long int number2){
	return number1 * number2 / gcd(number1,number2);	

}
int main(){
  
  ll N;
  cin>>N;
  
  vector<ll>a(N);
  bool flag=true;
  
  rep(i,N){
cin>>a[i];
  }

  sort(all(a));
  ll ans=0;
 ll sum=1;
  
  if(N==1){
    if(a[0]==1){
      cout<<0<<endl;
      flag=false;
    }
    else{
      cout<<1<<endl;
      flag=false;
    }
  }
else{
  
  for(ll i=1;i<N;i++){
    if(a[i]==a[i-1]){
      sum++;
    }
    else{
if(a[i-1]<=sum){
  
ans+=(sum-a[i-1]);
  sum=1;
}
      else{
        ans+=sum;
        sum=1;
      }
    }
    
 if(i==N-1){
   if(a[i]==a[i-1]){
     if(a[i]<=sum){
       ans+=sum-a[i];
     }
     else{
       ans+=sum;
   }
   }
   else{
     if(a[i]!=1){
       ans++;
     }
   } 
  }
  }
                      
                      cout<<ans<<endl;
}
                     }
    
    
    
    

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main () {
  int N;
  cin >> N;
  for(int i = 0; i <= N; i++){
    if((i * 108) / 100 == N){
      cout << i << endl;
      return 0;
    }
  }
  cout << ":(" << endl;
  return 0;
}

Measured memory_bytes: 256
from bisect import bisect_left, bisect_right
from collections import defaultdict

def find_gt(a, x):
    'Find leftmost value greater than x'
    i = bisect_right(a, x)
    if i != len(a):
        return a[i]
    return -1

s = list(input())
t = list(input())
if len(set(t)-set(s)) != 0:
    print(-1)
    exit(0)

sdict = defaultdict(list)
for i, ss in enumerate(s):
    sdict[ss].append(i)

index = -1
round = 0

for tt in t:
    index = find_gt(sdict[tt], index)
    if index == -1:
        index = sdict[tt][0]
        round += 1
ans = round * len(s) + index + 1
print(ans)


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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
using P = pair<int, int>;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}
struct edge {
  ll to, cost;
};

int main() {
  int N; cin >> N;
  vector<pair<int, pair<int, int>>> p;
  REP(i, N) {
    int a, b; cin >> a >> b;
    p.push_back(make_pair(i, make_pair(a, b)));
  }
  int tmp = 0;
  double res = 0;
  do {
    tmp++;
    for(int i = 0; i < N - 1; ++i) {
      res += sqrt(pow(p[i].second.first - p[i + 1].second.first, 2) + pow(p[i].second.second - p[i + 1].second.second, 2));
    }
  } while(next_permutation(p.begin(),p.end()));
  double ans = res / (double)tmp;
  cout << fixed << setprecision(15) << ans << endl;
}

Measured memory_bytes: 3760
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
struct div
{
	long long x,y;
	inline div operator+(const div& b)const
	{
		long long tmp=y*b.y/__gcd(y,b.y);
		return (div){x*tmp/y+b.x*tmp/b.y,tmp};
	}
	inline div operator-(const div& b)const
	{
		long long tmp=y*b.y/__gcd(y,b.y);
        return (div){x*tmp/y-b.x*tmp/b.y,tmp};
	}
}tmp,tmp1,tmp2,tmp3;
int main(void)
{
	long long i,j,n;
	scanf("%lld",&n);
	for(i=1;i<=3500;++i)
	{
		for(j=1;j<=3500;++j)
		{
			tmp1.x=4;tmp1.y=n;
			tmp2.x=1;tmp2.y=i;
			tmp3.x=1;tmp3.y=j;
			tmp=tmp1-tmp2-tmp3;
			if(tmp.x==1)
			{
				printf("%lld %lld %lld\n",i,j,tmp.y);
				return 0;
			}
		}
	}
	return 0;
}


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

int main(){
  
  int a,b;
  cin >> a >> b;
  
  if( a-b*2 > 0 ){
    
    cout << a-b*2 << endl;
    
  }
  
  else{
    
    cout << 0 << endl;
    
  }
  
}


Measured memory_bytes: 3608
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int k = Integer.parseInt(sc.next());
        int x = Integer.parseInt(sc.next());

        int maxPoint = x + k - 1;
        int minPoint = x - k + 1;

        for (int i = minPoint; i <= maxPoint; i++) {
            System.out.print(i + " ");
        }
    }
}

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

const ll MAX = 200000;
const ll INF = 1001001001;
const ll MOD = 1000000007;

ll N, ans=0, tmp=0;
string S;

signed main(){
    cin >> S;
    for(int i=0;i<S.size();i++) {
        if(S[i]=='p') tmp++;
    }
    ans = S.size()/2;
    ans -= tmp;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3768
#include <stdio.h>

int main(void){
    int a,b;
    scanf("%d %d",&a,&b);
    if(a<b){
        printf("a < b\n");
    }else if(a>b){
        printf("a > b\n");
    }else{
        printf("a == b\n");
    };
    return 0;
}


Measured memory_bytes: 2040
n = int(input())
a = list(map(int, input().split()))
A = []
f = 0
bf = 0
for i in range(n - 1):
    if a[i] < a[i + 1]:
        f = 1
    elif a[i] > a[i + 1]:
        f = -1

    if bf != f:
        A.append(a[i])

    bf = f
A.append(a[n-1])
m = 1000
c = 0
for i in range(len(A)-1):
    if A[i] < A[i + 1]:
        c = m // A[i]
        m %= A[i]
        if i == len(A) - 2:
            m += c * A[i+1]
            c = 0
    else:
        m += c * A[i]
        c = 0


print(m)


Measured memory_bytes: 9236
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1186
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>
using ll = long long;
using namespace std;

int const MOD = 1e9 + 7;

int main(void)
{
    int h, w;
    while (cin >> h >> w, h || w)
    {
        pair<int, int> ans(150, 150); //高さ 幅
        for (int i = 1; i < 150; ++i) // w
        {
            for (int j = 1; j < 150; ++j) // h
            {
                if (i <= j)
                    break;
                if (h * h + w * w < i * i + j * j)
                {
                    if ((i * i + j * j) < (ans.first * ans.first + ans.second * ans.second))
                    {
                        ans.first = j;
                        ans.second = i;
                    }
                    else if ((i * i + j * j) == (ans.first * ans.first + ans.second * ans.second))
                    {
                        if (j < ans.first)
                        {
                            ans.first = j;
                            ans.second = i;
                        }
                    }
                }
                if (h * h + w * w == i * i + j * j)
                {
                    if (i * i + j * j == (ans.first * ans.first + ans.second * ans.second))
                    {
                        if (h < j && ans.first > j)
                        {
                            ans.first = j;
                            ans.second = i;
                        }
                    }
                    else
                    {
                        if (h < j)
                        {
                            ans.first = j;
                            ans.second = i;
                        }
                    }
                }
            }
        }
        cout << ans.first << " " << ans.second << endl;
    }

    return 0;
}


Measured memory_bytes: 3008
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define E "\n"

using namespace std;
const long long MOD = (long long)1e9 + 7;

int r;

int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> r;
    cout << 3.1415926 * (r + r) << E;
    //system("pause");
    return 0;
}

Measured memory_bytes: 3804
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define popb  pop_back
#define mem(a,b) memset(a,b,sizeof(a))
#define i first
#define j second
#define inf 2e9
#define MOD 1000000007
#define M 100007
void FAST()
{
	std::ios_base::sync_with_stdio(false);
	cin.tie(NULL);
}

void solve(){

}
bool cmp(string s, string t)
{
  int x = s.compare(t);
  if(x<=0)return 1;
  return 0;
}
int main(){
  FAST();
  ll n; cin>>n;
  string arr[n+1];
  for(int i = 0; i<n; ++i)
  {
    cin>>arr[i];
    sort(arr[i].begin(),arr[i].end());
  }
  sort(arr,arr+n);
  ll ans = 0;
  int i = 0;
  while(i<n)
  {
    int j = i+1;
    while(j<n&&arr[i].compare(arr[j])==0)
    {
      ++j;
    }
  //  cout<<i<<" "<<j<<"\n";
   
    ans+=((j-i)*1LL*(j-i-1))/2;
    i=j;
  }
  cout<<ans<<"\n";

return 0;
}

Measured memory_bytes: 5760
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<vector>
#include<bitset>

using namespace std;

int n;
vector<int> g[110000];
int v[110000];
int du[110000],root;
int sz[110000],f[110000];
void dfs(int x,int fa)
{
	int tmp=0,maxx=0;
	for (int i=0;i<g[x].size();i++)
		if (g[x][i]!=fa) 
		{
			dfs(g[x][i],x),sz[x]+=sz[g[x][i]];
			tmp+=sz[g[x][i]]-f[g[x][i]];
			f[x]+=f[g[x][i]];
			maxx=max(maxx,sz[g[x][i]]-f[g[x][i]]);
		}
	if (sz[x]==0) {sz[x]=v[x];return;}
	if (tmp-v[x]<0) {printf("NO\n");exit(0);}
	int delta=tmp-v[x];
	if (delta+delta>tmp||delta>tmp-maxx) {printf("NO\n");exit(0);}
	f[x]+=delta*2;
}
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
		scanf("%d",&v[i]);
	for (int i=1;i<n;i++)
	{
		int x,y;
		scanf("%d %d",&x,&y);
		g[x].push_back(y);
		g[y].push_back(x);
		du[x]++,du[y]++;
	}
	if (n==2)
	{
		if (v[1]==v[2]) printf("YES\n");
		else printf("NO\n");
		return 0;
	}
	for (int i=1;i<=n;i++)
		if (du[i]!=1)
		{
			root=i;
			break;
		}
	int all=0;
	dfs(root,0);
	if (sz[root]!=f[root]) printf("NO\n");
	else printf("YES\n");
	return 0;
}

Measured memory_bytes: 14208
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  vector<vector<int>> data(3, vector<int>(3));

  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> data.at(i).at(j);
    }
  }
 
  int N,b;
  cin >> N;
  for (int i = 0; i < N; i++) {
	cin >> b;
    for (int i = 0; i < 3; i++) {
      for (int j = 0; j < 3; j++) {
        if (data.at(i).at(j) == b) {
          data.at(i).at(j) = 0;
        }
      }
    }
  }
  
  //横
  for (int i = 0; i < 3; i++) {  
  	int count = 0;
    for (int j = 0; j < 3; j++) {   
      if (data.at(i).at(j) == 0) {
        count++;
      }
 	  if (count == 3) {
       cout << "Yes" << endl;
       return 0;
      }     
    }
  }
  
  //縦
  for (int i = 0; i < 3; i++) {  
  	int count = 0;
    for (int j = 0; j < 3; j++) {   
      if (data.at(j).at(i) == 0) {
        count++;
      }
 	  if (count == 3) {
       cout << "Yes" << endl;
       return 0;
      }     
    }
  }
  
  //斜め  
  if ((data.at(0).at(0) == 0) && (data.at(1).at(1) == 0) && (data.at(2).at(2) == 0)){
   cout << "Yes" << endl;
   return 0;
  }
  if ((data.at(0).at(2) == 0) && (data.at(1).at(1) == 0) && (data.at(2).at(0) == 0)){
   cout << "Yes" << endl;
   return 0;
  }
  
  cout << "No" << endl;
  return 0;
 
}


Measured memory_bytes: 256
// tsukasa_diary's programing contest code template
#include <bits/stdc++.h>
using namespace std;
#define TSUKASA_DIARY_S_TEMPLATE
// define
#define for_(i,a,b) for(int i=(a);i<(b);++i)

typedef unsigned long long ull;
const ull BASE = 1e9 + 7;

class RollingHash {
private:	
	int N;
	const string& text;
	vector< ull > mul;
	vector< ull > hash;
	
	void makeHash() {
		for_(i,1,N+1) {
			mul[i] = mul[i - 1] * BASE;
			hash[i] = hash[i - 1] * BASE + text[i - 1];
		}
	}
	
public:
	RollingHash(string& _text_)
	: N(_text_.size()), text(_text_), mul(N + 1, 1), hash(N + 1, 0) {
		makeHash();
	}
	
	ull getHash(int l, int r) {
		return hash[r] - hash[l - 1] * mul[r - l + 1];
	}
};

int main() {
	int n, m;
	cin >> n >> m;
	
	string text;
	cin >> text;
	
	RollingHash hash(text);
	
	set< ull > strs;
	int l = 1, r = 1;
	
	for_(i,0,m) {
		string q;
		cin >> q;
		
		if (q == "L++") ++l;
		if (q == "L--") --l;
		if (q == "R++") ++r;
		if (q == "R--") --r;
		
		strs.insert(hash.getHash(l, r));
	}
	
	cout << strs.size() << endl;
}

Measured memory_bytes: 20024
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdlib>
using namespace std;

const int N=100005;

int n,sum,ans;
int a[N],cnt[N],vis[N];

int main(){
	int i;
	scanf("%d",&n);
	for (i=1;i<=n;i++) scanf("%d",&a[i]);
	for (i=1;i<=n;i++) cnt[a[i]]++;
	for (i=1;i<=n;i++) if (!vis[a[i]]){
		vis[a[i]]=1;
		if (cnt[a[i]]%2==0) sum++;
		ans++;
	}
	if (sum%2==0) printf("%d\n",ans);
	else printf("%d\n",ans-1);
	return 0;
}

Measured memory_bytes: 1408
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

class Main {

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

        try {

            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

            List<String> input = Arrays.asList(br.readLine().split(" "));
            List<Integer> numbers = new ArrayList<>();

            for (String s : input) {
                numbers.add(Integer.parseInt(s));
            }

            Integer sumNumbers = numbers.stream().mapToInt(i -> i).sum();
            String result = "IMPOSSIBLE";
            if (sumNumbers % 2 == 0) {
                sumNumbers = sumNumbers / 2;
                result = sumNumbers.toString();
            }

            System.out.println(result);
        } catch (IOException | NumberFormatException e) {
            e.printStackTrace();
            System.exit(0);
        } catch (final Exception e) {
            e.printStackTrace();
            System.exit(0);
        }
    }
}

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

const int N = 100005;

int n, k;
struct perm {
	int p[N];
	int& operator [] (int index) { return p[index]; }
	int operator [] (int index) const { return p[index]; }
	perm inverse() const {
		static perm tmp;
		for (int i = 1; i <= n; ++i)
			tmp[p[i]] = i;
		return tmp;
	}
	friend perm operator * (const perm &a, const perm &b) {
		static perm tmp;
		for (int i = 1; i <= n; ++i)
			tmp[i] = a[b[i]];
		return tmp;
	}
	perm pow(int k) const {
		static bool vis[N];
		static int cycle[N], id[N], tot;
		static perm tmp;
		for (int i = 1; i <= n; ++i) if (!vis[i]) {
			int j = i;
			tot = 0;
			do {
				id[j] = tot, cycle[tot++] = j, vis[j] = 1, j = p[j];
			} while (j != i);
			j = i;
			do {
				tmp[j] = cycle[(id[j] + k) % tot], j = p[j];
			} while (j != i);
		}
		return tmp;
	}
} p, q, t, s;


int main() {
	std::ios::sync_with_stdio(0), std::cin.tie(0);
	std::cin >> n >> k;
	for (int i = 1; i <= n; ++i) std::cin >> p[i];
	for (int i = 1; i <= n; ++i) std::cin >> q[i];
	t = q * p.inverse() * q.inverse() * p;
	switch (k % 6) {
		case 0: 
			s = q.inverse() * p; break;
		case 1:
			s = p; break;
		case 2:
			s = q; break;
		case 3:
			s = q * p.inverse(); break;
		case 4:
			s = t * p.inverse(); break;
		case 5:
			s = t * q.inverse(); break;
	}
	t = t.pow(k / 6), s = t * s * t.inverse();
	for (int i = 1; i <= n; ++i) std::cout << s[i] << ' ';
	std::cout << '\n';
	return 0;
}

Measured memory_bytes: 7808
#include<bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main() {
  string S;
  string T;
  cin >> S>>T;
  string Z=T+S;
  cout << Z << endl;
}

  

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <string>
#include <functional>
#include <set>
#define DB cerr<<"D"<<endl
#define pb push_back
using namespace std; using ll=long long; using ld=long double; const int INF=1e9; const ll LINF=1e18; const double dINF = 1e18; const ld ldINF = 1e18; const double EPS = 1e-6;
template<typename T, typename U, typename O> void caut(T a, U b, O c){cout<<"("<<a<<","<<b<<","<<c<<") ";} template<typename T, typename U> void caut(T a, U b){cout<<"("<<a<<","<<b<<") ";} template<typename T> void caut(T a){cout<<"("<<a<<") ";}
using P=pair<double,int>;
const ll M = 998244353;
void add(ll& x, ll y) {x+=y; x%=M;}
void chmax(ll& x, ll y) {if (x<y) x=y;}

int main() {
  string s; cin>>s;
  int n=s.size();
  for(int i=0;i<n;i++) {
    for(int j=0;j<=n-i;j++) {
      if (s.substr(0,i) + s.substr(i+j,n-i-j) == "keyence") {
        cout<<"YES"<<endl;
        return 0;
      }
    }
  }
  cout<<"NO"<<endl;
}

Measured memory_bytes: 384
#include <stdio.h>
#include <stdlib.h>

int main()
{
	int N;
	char S[300001];
	scanf("%d", &N);
	scanf("%s", S);
	
	int i, count = 0, max = 0;
	for (i = 0; S[i] != 0; i++) if (S[i] == 'W') count++;
	for (i = 0, count; S[i] != 0; i++) {
		if (S[i] == 'W') count--;
		if (count > max) max = count;
		if (S[i] == 'E') count++;
	}
	
	printf("%d\n", N - max - 1);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 2012
import java.util.Scanner;

public class Main {
	public static void main(String[]args) {
		try(Scanner scan = new Scanner(System.in)){
			
			int sx = scan.nextInt();
			int sy = scan.nextInt();
			int tx = scan.nextInt();
			int ty = scan.nextInt();
			
			int Y = ty-sy;
			int X = tx-sx;
			
			StringBuffer sb = new StringBuffer();
			
			char u = 'U';
			char d = 'D';
			char r = 'R';
			char l = 'L';
			
			for(int i = 0;i<Y;i++)sb.append(u);
			for(int i = 0;i<X;i++)sb.append(r);
			for(int i = 0;i<Y;i++)sb.append(d);
			for(int i = 0;i<X;i++)sb.append(l);
			sb.append(l);
			for(int i = 0;i<Y+1;i++)sb.append(u);
			for(int i = 0;i<X+1;i++)sb.append(r);
			sb.append(d);
			sb.append(r);
			for(int i = 0;i<Y+1;i++)sb.append(d);
			for(int i = 0;i<X+1;i++)sb.append(l);
			sb.append(u);
			
			
			System.out.println(sb.toString());
			
			
			
		}
		
		
	}
		

}


Measured memory_bytes: 21844
#include <bits/stdc++.h> 
using namespace std;
map<int,vector<int> > m;
int arr[100005];

int dfs(int root,int depth)
{
	if(arr[root]!=-1)
		return arr[root];
	vector<int> v=m[root];
	//if(v.size()==0)return 1;
	int ans=1;
	for(int i=0;i<v.size();i++)
	{
		int d=dfs(v[i],1);
		ans=max(d+depth,ans);
	}
	arr[root]=ans;
	return ans;
}

int main()
{
	int n,M;
	cin>>n>>M;
	
	
	for(int i=0;i<M;i++)
	{
		int u,v;
		cin>>u>>v;
		m[u].push_back(v);
	}
	
	
	memset(arr,-1,sizeof(arr));
	
	for(int i=1;i<=n;i++)
	{
		if(arr[i]==-1)
			dfs(i,1);
	}
	int ans=0;
	for(int i=1;i<=n;i++)
		ans=max(ans,arr[i]);
	cout<<max(0,ans-1)<<endl;
	
}
               

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

ll x[55], y[55], xa[55], ya[55];

int main()
{
	ll n, k;
	cin >> n >> k;

	for (int i = 0; i < n; i++)
	{
		cin >> x[i] >> y[i];
		xa[i] = x[i]; ya[i] = y[i];
	}

	sort(x, x + n);
	sort(y, y + n);

	ll ans = (x[n - 1] - x[0]) * (y[n - 1] - y[0]);

	for (int xi = 0; xi < n; ++xi)
	{
		for (int xj = xi + 1; xj < n; ++xj)
		{
			for (int yi = 0; yi < n; ++yi)
			{
				for (int yj = yi + 1; yj < n; ++yj)
				{
					ll xleft = x[xi], xright = x[xj];
					ll yleft = y[yi], yright = y[yj];
					int num = 0;
					for (int count = 0; count < n; count++)
					{
						if(xa[count] >= xleft && xa[count] <= xright && ya[count] >= yleft && ya[count] <= yright)
							num++;
					}
					if (num >= k){
						ans = min(ans, (xright - xleft) * (yright - yleft));
					}
				}
			}
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
#include <fstream>
#define debug(x) cout << #x << " = " << x << endl
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define repr(i,n) for(int i = (n); i > -1; i--)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const double EPS = 1e-9;


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

  int sx,sy,tx,ty;
  cin>>sx>>sy>>tx>>ty;
  int a = ty - sy;
  int b = tx - sx;
  rep(i,a) cout << 'U';
  rep(i,b) cout << 'R';
  rep(i,a) cout << 'D';
  rep(i,b + 1) cout << 'L';
  rep(i,a + 1) cout << 'U';
  rep(i,b + 1) cout << 'R';
  rep(i,1) cout << 'D';
  rep(i,1) cout << 'R';
  rep(i,a + 1) cout << 'D';
  rep(i,b + 1) cout << 'L';
  rep(i,1) cout << 'U';
  cout << endl;


  return 0;
}


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

using namespace std;

template <long long Mod> struct ModInt { /* {{{ */
  long long v;
  constexpr ModInt(const long long x = 0) {
    v = x % Mod;
    if (v < 0) {
      v += Mod;
    }
  }
  constexpr ModInt operator+(const ModInt rhs) const {
    return ModInt(*this) += rhs;
  }
  constexpr ModInt operator-(const ModInt rhs) const {
    return ModInt(*this) -= rhs;
  }
  constexpr ModInt operator*(const ModInt rhs) const {
    return ModInt(*this) *= rhs;
  }
  constexpr ModInt operator/(const ModInt rhs) const {
    return ModInt(*this) /= rhs;
  }
  const ModInt &operator+=(const ModInt rhs) {
    v += rhs.v;
    if (v >= Mod) {
      v -= Mod;
    }
    return *this;
  }
  constexpr ModInt &operator-=(const ModInt rhs) {
    if (v < rhs.v) {
      v += Mod;
    }
    v -= rhs.v;
    return *this;
  }
  constexpr ModInt &operator*=(const ModInt rhs) {
    v = v * rhs.v % Mod;
    return *this;
  }
  constexpr ModInt &operator/=(ModInt rhs) {
    long long exp = Mod - 2;
    while (exp) {
      if (exp % 2) {
        *this *= rhs;
      }
      rhs *= rhs;
      exp /= 2;
    }
    return *this;
  }
  friend ostream &operator<<(ostream &s, ModInt<Mod> m) {
    s << m.v;
    return s;
  }
  friend istream &operator>>(istream &s, ModInt<Mod> m) {
    s >> m.v;
    return s;
  }
}; /* }}} */

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

const int mod = 1e9 + 7;
using modint = ModInt<mod>;

int main() {
  int N;
  cin >> N;
  vector<long long> A(N);
  for (auto &a : A) {
    cin >> a;
  }

  map<int, int> pf;
  for (int a = 0; a < N; a++) {
    int n = A[a];
    for (int i = 2; i * i <= A[a]; i++) {
      int count = 0;
      while (n % i == 0) {
        n /= i;
        count++;
      }
      chmax(pf[i], count);
    }
    if (n > 1) {
      chmax(pf[n], 1);
    }
  }
  modint ans = 0;
  for (auto a : A) {
    ans += modint(1) / a;
  }
  for (auto e : pf) {
    for (int i = 0; i < e.second; i++) {
      ans *= e.first;
    }
  }
  cout << ans << endl;

  return 0;
}
/* vim:set foldmethod=marker: */


Measured memory_bytes: 896
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;

//vector string deque break continue
#define forn(i, s, f) for (int i = (int)s; i < (int)f; i++)
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair <int, int>
#define fs first
#define sc second
#define pf push_front
#define pb push_back
#define pop_f pop_front
#define pop_b pop_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()

template <typename T> istream& operator>>(istream& in, vector <T>& a) {for (auto& i : a) in >> i; return in;}
template <typename T> ostream& operator<<(ostream& out, vector <T>& a)  {for (auto& i : a) out << i << " "; return out;}
template <typename T, typename U> void chkmin(T& a, U b) {if (a > b) a = b;}
template <typename T, typename U> void chkmax(T& a, U b) {if (a < b) a = b;}

vector <string> moves;

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    int n;
    cin >> n;
    vector <int> bal(3);
    cin >> bal;
    moves.resize(n);
    cin >> moves;
    auto get = [](string& s) -> int {
        if (s == "AB")
            return 2;
        if (s == "AC")
            return 1;
        if (s == "BC")
            return 0; 
    };
    vector <int> ans;
    forn (i, 0, n) {
        vector <int> busy;
        forn (j, 0, 3)
            if (j != get(moves[i]))
                busy.pb(j);
        if (bal[busy[0]] == 0 && bal[busy[1]] == 0)
            return cout << "No", 0;
        if (bal[busy[0]] == 1 && bal[busy[1]] == 1 && bal[get(moves[i])] == 0 && i + 1 < n) {
            if (get(moves[i + 1]) == busy[0]) {
                bal[busy[1]]++, bal[busy[0]]--;
                ans.pb(busy[1]);
            } else {
                bal[busy[0]]++, bal[busy[1]]--;
                ans.pb(busy[0]);
            }
        } else {
            if (bal[busy[0]] < bal[busy[1]]) {
                bal[busy[0]]++, bal[busy[1]]--;
                ans.pb(busy[0]);
            } else {
                bal[busy[1]]++, bal[busy[0]]--;
                ans.pb(busy[1]);
            }
        }
        //cout << bal << "\n";
    }
    cout << "Yes\n";
    for (auto i : ans)
        cout << (char)(i + 'A') << "\n";
    return 0;
}

Measured memory_bytes: 7012
# from sys import exit
while(True):
    N = int(input())
    if N == 0:
        break
    for _ in range(N):

        a, b, c, d, A, B, C, D = [int(n) for n in input().split()]
        z = a*A - b*B - c*C - d*D
        i = a*B + b*A + c*D - d*C
        j = a*C - b*D + c*A + d*B
        k = a*D + b*C - c*B + d*A
        print(z, i, j, k)
# a = [int(input()) for _ in range(N)]
# S = str(input())
# L = len(S)
# T = str(input())



Measured memory_bytes: 5604
def resolve():
    n = int(input())
    s = input()
    t = input()
    overwrap = 0
    if s == t:
        print(n)
        return 0
    for i in range(1, n):
        if s[i:] == t[:-i]:
            overwrap = n - i
            break
    print(2 * n - overwrap)


if __name__ == "__main__":
    resolve()


Measured memory_bytes: 38384
#![allow(unused_imports)]
use std::io::{ self, Write };
use std::str::FromStr;
use std::cmp::{ min, max };
use std::collections::{ BinaryHeap, VecDeque };

#[allow(unused_macros)]
macro_rules! trace {
    ($var:expr) => {
        let _ = writeln!(&mut std::io::stderr(), ">>> {} = {:?}", stringify!($var), $var);
    };
    ($($args:expr),*) => { trace!(($($args),*)) }
}

#[allow(unused_macros)]
macro_rules! put {
    ($var:expr) => {
        let _ = writeln!(&mut std::io::stdout(), "{}", $var);
    };
    ($var:expr, $($args:expr),*) => {
        let _ = write!(&mut std::io::stdout(), "{} ", $var);
        put!($($args),*);
    };
}

fn main() {
    let mut sc = Scanner::new();
    let n: usize = sc.cin();
    let ps = (0..n).map(|_| sc.cin::<f64>()).collect::<Vec<_>>();

    let mut p = vec![vec![0.0f64; 3000]; 3000];  // p[i][j] = Pr(j coins at i coins)
    p[0][0] = 1.0;

    for m in 1..n+1 {
        for k in 0..m+1 {
            p[m][k] = if k == 0 { 0.0 } else { p[m-1][k-1] * ps[m-1] } + p[m-1][k] * (1.0 - ps[m-1]);
            // trace!(m, k, p[m][k]);
        }
    }

    let ans: f64 = (n/2+1..n+1).map(|i| p[n][i]).sum();
    put!(ans);
}

#[allow(dead_code)]
struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
#[allow(dead_code)]
impl Scanner {
    fn new() -> Scanner { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn reserve(&mut self) {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
    }
    fn cin<T: FromStr>(&mut self) -> T {
        self.reserve();
        match self.buffer.pop_front().unwrap().parse::<T>() {
            Ok(a) => a,
            Err(_) => panic!("parse err")
        }
    }
}


Measured memory_bytes: 90492
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
e=Counter(a[::2]);e[0]=0
o=Counter(a[1::2]);o[0]=0
e1,e2=e.most_common(2)
o1,o2=o.most_common(2)
if e1[0]!=o1[0]:
    print(n-(e1[1]+o1[1]))
else:
    print(n-max(e1[1]+o2[1],e2[1]+o1[1]))

Measured memory_bytes: 18656
/* ****TCIITB**** */

#include<bits/stdc++.h>
#define io          ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); 
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
using namespace std;

#define N  100005

int main()
{
	
	io
	ll n;
	cin>>n;
	std::vector<ll> ord(n);
	rep(i,0,n)
	{
		cin>>ord[i];
	}
	std::map<ll,ll> val;
	rep(i,0,n)
	{

		ll x;
		cin>>x;
		val[i+1]=x;
	}
	std::vector<ll> ex(n-1);
	rep(i,0,n-1)
	{
		cin>>ex[i];
	}
	ll res=0;
	rep(i,0,n)
	{
		res+=val[ord[i]];
		if(i!=n-1 && ((ord[i+1]-ord[i])==1))
			res+=ex[ord[i]-1];
	}
	cout<<res;
	
}

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

int main()
{
    string s;
    cin>>s;
    int ans=0;
    int cnt=0;
    for(int i=0;i<s.length();i++)
    {
        if(s[i]=='R') cnt++;
        else cnt=0;
        ans=max(ans,cnt);
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
const int maxn=3e3+10;
const int mod=1e9+7,inv2=(mod+1)/2;
int a[maxn],dp[maxn][maxn];
int n,m,all=1;
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	for(int i=1;i<=n;i++)
	for(int j=1;j<=n;j++)dp[i][j]=a[i]<a[j];
	while(m--)
	{
		int x,y;
		all=all*1LL*2%mod;
		scanf("%d%d",&x,&y);
		dp[x][y]=dp[y][x]=inv2*1LL*(dp[x][y]+dp[y][x])%mod;
		for(int i=1;i<=n;i++)
		{
			if(i==x||i==y)continue;
			dp[i][x]=dp[i][y]=inv2*1LL*(dp[i][x]+dp[i][y])%mod;
			dp[x][i]=dp[y][i]=inv2*1LL*(dp[x][i]+dp[y][i])%mod;
		}
	}
	int ans=0;
	for(int i=1;i<=n;i++)
	for(int j=1;j<i;j++)ans+=dp[i][j]*1LL*all%mod,ans%=mod;
	printf("%d\n",ans);
}

Measured memory_bytes: 35584
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iomanip>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007; // 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};

struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    cerr << fixed << setprecision(10);
  }
} iosetup;
/*-------------------------------------------------*/
int main() {
  int x, t; cin >> x >> t;
  cout << max(x - t, 0) << '\n';
  return 0;
}


Measured memory_bytes: 256
//problem-C
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstdio>
#include <iostream>
#include <vector>
#include<string>
#include<queue>
#include<map>

using namespace std;

int main() {
	int N;
	cin >> N;
	vector<int> a(N);
	for (int i = 0; i < N; i++)
	{
		cin >> a[i];
	}
	int C_MAX = 8;
	int over3200 = 0;
	vector<int> colorNum(C_MAX, 0);
	for (int i = 0; i < N; i++)
	{
		if (a[i] >= 400 * C_MAX) {
			over3200++;
		}
		else colorNum[a[i] / 400]++;
	}
	int C = 0;
	for (int i = 0; i < C_MAX; i++)
	{
		if (colorNum[i] >= 1) C++;
	}
	int ans_min = max(1, C);
	int ans_max = C + over3200;

	cout << ans_min << " " << ans_max << endl;

	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <time.h>
#include <stdlib.h>
using namespace std;

int main(){
	int i,n,x,sum=0,l[100],ans=0;
	bool t=true;
	scanf("%d %d",&n,&x);
	for(i=0;i<n;i++) scanf("%d",&l[i]);
	for(i=1;i<=n;i++){
		sum += l[i-1];
		if(sum > x) break;
	}
	if(x<l[0]) i=0;
	printf("%d\n",i);
		
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
//const int INF = 1e8;
using namespace std;

#define int long long

const int gmax_n = 100005;

int par[gmax_n]; //親
int depth[gmax_n];//木の深さ

void init(int n){
	rep(i,n){
		par[i] = i;
		depth[i] = 0;
	}
}

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

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

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

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

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

	vector<pair<int, int>> p;

	init(n);
	rep(i,m){
		int a, b;
		cin >> a >> b;
		a--; b--;
		unite(a,b);
		p.emplace_back(a,b);
	}

	int a = 0, b = 0;
	vector<int> alone;
	rep(i,n){
		if(same(0,i)){
			a++;
		}else if(same(1,i)){
			b++;
		}else{
			alone.emplace_back(i);
		}
	}

	if(a >= b){
		a += alone.size();
		for(auto i : alone){
			unite(0,i);
		}
	}else{
		b += alone.size();
		for(auto i : alone){
			unite(1,i);
		}
	}

	cout << a * (a - 1) / 2 + b * (b - 1) / 2 - m << endl;
}


Measured memory_bytes: 5232
/**
 *      purpose : ABC 113 A
 *      author  : kyomukyomupurin
 *      created : 2018-11-04 21:01:30
**/

#include <bits/stdc++.h>
using namespace std;
#define int64 long long
#define print(x) cout << (x) << '\n'

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int X, Y; cin >> X >> Y;
    print(X + Y / 2);
    
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bits/stdc++.h>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define rep(X, S, E) for(int(X) = (S); (X) < (E); ++(X))
#define rrep(X, S, E) for(int(X) = (E)-1; (X) >= (S); --(X))
#define itrep(X, Y) for(auto(X) = (Y).begin(); (X) != (Y).end(); (X)++)
#define all(X) (X).begin(), (X).end()
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
#define print(x) cout << x << endl

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef priority_queue<ll, vl> decendingQueue;              //降順
typedef priority_queue<ll, vl, greater<ll>> ascendingQueue; //昇順
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll INF = 9 * 1e18;
const ll MOD = 1e9 + 7;

void solve(long long N, long long Q, std::vector<long long> S,
           std::vector<long long> T, std::vector<long long> X,
           std::vector<long long> D) {
    vector<pll> construction;
    rep(i, 0, N) { construction.push_back(mp(X[i], i)); }
    sort(all(construction));

    map<ll, ll> ansMap;
    rep(i, 0, N) {
        ll x = construction[i].fi;
        ll index = construction[i].sc;

        ll from = lower_bound(all(D), S[index] - x) - D.begin();
        ll to = lower_bound(all(D), T[index] - x) - D.begin();
        rep(j, from, to) { ansMap[D[j]] = x; }
        D.erase(D.begin() + from, D.begin() + to);
    }

    itrep(it, D) { ansMap[*it] = -1; }
    itrep(it, ansMap) { print(it->second); }
}

int main() {
    long long N;
    scanf("%lld", &N);
    long long Q;
    scanf("%lld", &Q);
    std::vector<long long> S(N);
    std::vector<long long> T(N);
    std::vector<long long> X(N);
    for(int i = 0; i < N; i++) {
        scanf("%lld", &S[i]);
        scanf("%lld", &T[i]);
        scanf("%lld", &X[i]);
    }
    std::vector<long long> D(Q);
    for(int i = 0; i < Q; i++) {
        scanf("%lld", &D[i]);
    }
    solve(N, Q, std::move(S), std::move(T), std::move(X), std::move(D));
    return 0;
}


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

int main() {
  string S;
  cin >> S;
  
  if (S == "RRR") cout << 3;
  if (S == "SRR") cout << 2;
  if (S == "RSR") cout << 1;
  if (S == "RRS") cout << 2;
  if (S == "SSR") cout << 1;
  if (S == "RSS") cout << 1;
  if (S == "SRS") cout << 1;
  if (S == "SSS") cout << 0;
}


Measured memory_bytes: 3588
H,W  = [int(x) for x in input().split()]
meiro= [list(input()) for _ in range(H)]
ans = [["0"]*W for _ in range(H)]
for i in range(H):
  for j in range(W):
    s = meiro[i][j]
    if s=="#":
      for a in range(3):
        for b in range(3):
          if 0<=i-1+a<H and 0<=j-1+b<W and ans[i-1+a][j-1+b]!="#":
            ans[i-1+a][j-1+b]= str(int(ans[i-1+a][j-1+b])+1)
      ans[i][j] ="#"
for i in range(H):
  print("".join(ans[i]))

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

using namespace std;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL 9223372036854775
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define MOD 1000000007
#define MOD9 998244353
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

#define int long long

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(a)  begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())

const int MAX_N = 100005;
const int MAX_M = 100005;
int N, M;

int X[MAX_M], Y[MAX_M], Z[MAX_M];

class UnionFind{
public:
  UnionFind(int aN)
  {
    init(aN);
  }

  void init(int aN)
  {
    par.clear(); cnt.clear();
    par.resize(aN); cnt.resize(aN);
    for (size_t i = 0; i < aN; i++) {
      par[i] = i;
      cnt[i] = 1;
    }
  }

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

  bool same(int aX, int aY)
  {
    return find(aX) == find(aY);
  }

  int size(int aX)
  {
    return cnt[find(aX)];
  }

  void unite(int aX, int aY)
  {
    aX = find(aX);
    aY = find(aY);
    if(aX == aY) return;

    par[aX] = aY;
    cnt[aY] += cnt[aX];
  }
private:
  vector<int> par;
  vector<int> cnt;
};

UnionFind uf(0);

bool used[MAX_N];

signed main()
{
  cin >> N >> M;
  uf.init(N);
  REP(m,M) {
    cin >> X[m] >> Y[m] >> Z[m];
    X[m]--; Y[m]--;
    uf.unite(X[m], Y[m]);
  }

  int ans = 0;
  REP(n,N) {
    if(!used[uf.find(n)]) {
      used[uf.find(n)] = true;
      ans++;
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 4480
STDOUT.sync = true
def isLeapYear?(y)
  if y%4==0&&y%100!=0
    true
  elsif y%400==0
    true
  else
    false
  end
end
c=0
while line = gets do
  a,b = line.split.map(&:to_i)
  if (a|b)==0
    break
  end
  if c!=0 then puts end 
  flag = true
  a.upto(b){|y|
    if isLeapYear?(y)
      puts y
      flag = false
    end
  }
  if flag
    puts "NA"
  end
  c+=1
end

Measured memory_bytes: 2380
n = int(input())
l=list(map(int ,input().split()))
ans=[]
for i in range(min(l)+1,max(l)):
    w=0
    for j in range(n):
        w+=(l[j]-i)**2
    ans.append(w)

if len(ans)==0:
    print(0)
else:
    print(min(ans))

Measured memory_bytes: 3060
N, M = map(int, input().split())
if N==1:
    if M==0:
        print(0)
    elif M==1:
        print(list(map(int,input().split()))[1])
    else:
        c = list(map(int, input().split()))[1]
        check=True
        for i in range(M):
            if list(map(int, input().split()))[1]!=c:
                check=False
                break
        if check:
            print(c)
        else:
            print(-1)
else:
    if M==0:
        keta = [0]*N
        keta[0] = 1
        ans = ""
        for i in range(N):
            ans = ans + str(keta[i])
        print(ans)
    elif M>=1:
        keta_list = [[-1]*(N) for i in range(M)]
        b_ans = True

        #initialization
        s, c = map(int, input().split())
        keta_list[0][s-1] = c

        for i in range(M-1):
            s_t, c_t = map(int, input().split())
            s_t = s_t - 1
            if keta_list[i][s_t] == -1:
                keta_list[i][s_t] = c_t
                for j in range(i,M-1):
                    for k in range(N):
                        keta_list[j+1][k] = keta_list[j][k]
            elif keta_list[i][s_t]!=c_t:
                b_ans = False
                break
            else: # same num
                for j in range(i,M-1):
                    for k in range(N):
                        keta_list[j+1][k] = keta_list[j][k]

        if b_ans:
            # list search
            ans_list = keta_list[M-1]
            for i in range(len(ans_list)):
                if ans_list[i]==-1 and i==0:
                    ans_list[i] = 1
                elif ans_list[i]==-1:
                    ans_list[i] = 0
            # sentou shori
            if ans_list[0]==0:
                print(-1)
            else:
                ans = ""
                for a in ans_list:
                    ans = ans + str(a)
                ans = int(ans)
                print(ans)
        else:
            print(-1)


Measured memory_bytes: 38384
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

typedef long long LL;

int main() {
  LL X, Y;
  scanf("%lld%lld", &X, &Y);
  int ans = 1;
  while (X * 2 <= Y) {
    ++ans;
    X <<= 1;
  }
  printf("%d\n", ans);
  return 0;
}


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

int main(){
    while(1){
        int h,w,cnum,sp;
        cin >> h;
        if(h == 0) break;
        cin >> cnum >> w >> sp;
        vector<string> str;
        string s;
        getline(cin, s);
        while(getline(cin, s), s!="?"){
            str.push_back(s);
        }
        
        vector<string> fstr;
        for(auto s: str){
            int len = s.length();
            if(len == 0) len++;
            s += string(w, '.');
            for(int i=0; i<len; i+=w){
                fstr.push_back(s.substr(i, w));
            }
        }

        int page = (fstr.size() +h*cnum -1) /(h*cnum);
        for(int i=0; i<h*cnum; i++){
            fstr.emplace_back(w, '.');
        }

        for(int i=0; i<page; i++){
            for(int j=0; j<h; j++){
                string s = "";
                for(int k=0; k<cnum; k++){
                    if(k != 0){
                        s += string(sp, '.');
                    }
                    s += fstr[i*h*cnum +k*h +j];
                }
                cout << s << endl;
            }
            cout << "#" << endl;
        }
        cout << "?" << endl;
    }
    return 0;
}


Measured memory_bytes: 3040