akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include<ctype.h>
# define pb push_back
#define fst first
#define sec second
#define For(i,a,b) for(int i=a;i<b;i++)
#define ll long long int
#define ull unsigned long long int
#define mod 1000000007
#define fo(i,n) for(ll i=0;i<n;i++)
#define endl "\n"
#define rev(i,n) for(ll i=n-1;i>=0;i--)
#define fo1(i,n) for(ll i=1;i<=n;i++)
#define boolsize 1000001
#define pi pair<ll,ll>
#define vi vector<ll>
#define vii vector<pi>
using namespace std;
template<typename T>
void showvector(vector <T> v)
{
    for(T x:v)
        cout<<x<<" ";
    cout<<endl;

}
template<typename T>
void showvector1(vector <T> v)
{
    ll n=v.size();
    fo1(i,n-1)
        cout<<v[i]<<endl;

}
template<typename T>
void showset(set <T> s)
{
    for(T x: s)
        cout<<x<<" ";
    cout<<endl;
}
template<class T>
void showvectorpair(vector<T> v)
{
    for(auto it=v.begin();it!=v.end();it++)
        cout<<it->first<<" "<<it->second<<endl;
    cout<<endl;
}
template<typename T,typename P>
void showmap(map <T,P> m)
{
    for(auto it=m.begin();it!=m.end();it++)
        cout<<it->first<<" "<<it->second<<endl;
    cout<<endl;
}
template<typename T>
bool comp(T a,T b)
{
    return (a>b);
}
template<class T>
bool comppair(T a,T b)
{
    if(a.first==b.first)
        return(a.second>b.second);
    return (a.first>b.first);
}
bool sameparity(ll a,ll b)
{
    return (a%2==b%2);
}
bool difparity(ll a,ll b)
{
    return !(a%2==b%2);
}
bool isprime(ll x)
{   if(x<=1)
     return false;
    for(ll i=2;i<=sqrt(x);i++)
    {
        if(x%i==0)
            return false;
    }
    return true;
}
bool iseven(ll x)
{
    return !(x%2);
}
bool isodd(ll x)
{
    return (x%2);
}
/// check for test case before submitting
void vfun()
{
    ll n,k;
    cin>>n;
    vector <ll> v(n);
    fo(i,n)
    cin>>v[i];

}

int main()
{
    #ifndef ONLINE_JUDGE
    freopen("inputh.txt", "r", stdin);
    freopen("outputh.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(0); ///cant use scanf, printf
    cin.tie(0);cout.tie(0); /// no longer auto flush cout before each cin, remove for interactive
    //cout << fixed << setprecision(11); /// no scientific output
    ll test=1;
//    cin>>test;
    while(test--)
    {

            ll n;
            cin>>n;

            vi v(n);
            ll w=0;
            fo(i,n)
                {cin>>v[i];w+=v[i];}
            ll sub=0;
            for(ll i=1;i<n;i+=2)
            {
                sub+=2*(v[i]);

            }
            ll x=w-sub;
            cout<<x<<" ";
            fo(i,n-1)
            {
                x=(2*v[i])-x;
                cout<<x<<" ";
            }

//         if(vfun())
//            cout<<"YES\n";
//         else
//            cout<<"NO\n";
    }
}
///before sub
/// check for value of zero and single input in array
///loop vars,1LL in mult, equal, one, bounds, int v ll, endl, finish taking inputs
/// check whether test cases are given or not





Measured memory_bytes: 3896
import java.io.*;

class Main {
	public static void main (String args[]) {
		InputStreamReader isr = new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader(isr);
		String buf;
 
		try {
			if ((buf = br.readLine())!=null) {
				double max,min;
				max = min = Double.parseDouble(buf);
				while ((buf = br.readLine())!=null) {
					double d = Double.parseDouble(buf);
					if (max<d) max = d;
					if (min>d) min = d; 
				}
				System.out.println(max-min);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}

Measured memory_bytes: 16916
import java.util.Scanner;

//Train
public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		while(N--!=0){
			char[] a = new char[3000];
			int p = 1500;
			int s = 1500;
			int t = 1500;
			char[] m = sc.next().toCharArray();
			a[p] = m[0];
			for(int i=1;i<m.length;i++){
				if(m[i]=='-')p++;
				else p--;
				i += 2;
				s = Math.min(s, p);
				t = Math.max(t, p);
				a[p] = m[i];
			}
			for(int i=s;i<=t;i++)System.out.print(a[i]);
			System.out.println();
		}
	}
}

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

#define REP(i,n) for(int i=0;i<n;i++)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define EPS (1e-7)
#define INF 1e9

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
int vx[]={0,1,0,-1};
int vy[]={1,0,-1,0};

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

const ll mod=1000000000+7;
const int MAX_N=1000;

int main(){
	int r,g;
	cin>>r>>g;
	cout<<g+(g-r)<<endl;
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

void solveA(){
    ll N,K; cin >> N >> K;
    if(N%K == 0) cout << 0 << endl;
    else cout << 1 << endl;
}
void solveB(){
    
}
void solveC(){
    
}
void solveD(){
    
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    solveA();
//    solveB();
//    solveC();
//    solveD();
    return 0;
}


Measured memory_bytes: 764
K,=list(map(int, input().split()))
se = 7
fiv = 1
for i in range(1,1000000):
  if K <= se:
    st = i
    break
  fiv *= 10 
  se = se + 7 * fiv
q1 = 7 * fiv % K
q2 = se % K
if q2 == 0:
  print(st)
  exit()
for i in range(st,1000000):
  if q2!=0:
    q1 = (10*q1) % K 
    q2 = (q1+q2)%K
    continue
  print(i)
  exit()  
print("-1")    

Measured memory_bytes: 9100
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
#define era(t) t.erase(unique(be(t)),t.end())
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;
typedef long long ll;
using namespace std;
const ll mod=1000000007,mod9=1000000009;
template <class T>inline T lcm(T a,T b){return (a*b/__gcd(a,b));}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b,c;
    cin>>a>>b>>c;
    if(a==b && b==c)cout << "Yes"<<endl;
    else cout <<"No"<<endl;
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<string.h>
#include<queue>
#include<map>
using namespace std;
typedef long long ll;
const int maxn = 50005;
const int maxm = 10005;
const int mod = 1000000009;
int n, m,k;
int tot;
int a[maxn];
int main(){
	scanf("%d", &n);
	for (int i = 0; i < n; i++){
		scanf("%d", &a[i]);
		tot += a[i];
	}
	if (tot % 10 == 0){
		sort(a, a + n);
		for (int i = 0; i < n; i++){
			if (a[i] % 10){ tot -= a[i]; break; }
		}
		if (tot % 10 == 0)printf("0");
		else printf("%d", tot);
	}
	else{
		printf("%d", tot);
	}
	return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

int cost(vector<int> a, int x){
	int ret = 0;
	for(auto y : a){
		ret += (x - y)*(x - y);
	}
	return ret;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout<<setprecision(32);

	int n;
	cin>>n;
	vector<int> a(n);
	int sum = 0;
	for(auto &x : a){
		cin>>x;
		sum += x;
	}
	int ans = min(cost(a, sum/n), cost(a, sum/n + 1));
	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <string>
#include <vector> 
#include <algorithm>
#include <numeric>
#include <map>   
#include <stdio.h>

#define FOR(i,a,b) for(i=(a);i<(b);++i) 
#define FORR(i,a,b) for(i=(a);i>(b);--i)
#define REP(i,n) for(i=0;i<(n);++i)
#define REPR(i,n) for(i=(n);i>0;--i)
#define PB push_back
#define ull unsigned long long
#define ll long long
#define INT_MAX 2147483647
#define LL_MAX 9223372036854775807
#define sortR(a,b) sort(a, b, greater<int>())

using namespace std;

int main() {
	int i, MAX = 9, j = 5, ans = 0;
	vector<int> A(5);
	cin >> A[0] >> A[1] >> A[2] >> A[3] >> A[4];
	REP(i, 5) {
		if ((A[i] % 10) != 0)
			if ((A[i] % 10) <= MAX) {
				MAX = A[i] % 10;
				j = i;
			}
	}
	REP(i, 5) {

		if (i == j)
			ans += A[i];
		else if ((A[i] % 10) == 0)
			ans += A[i];
		else
			ans += A[i] - (A[i] % 10) + 10;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long int li;
#define pb push_back
#define SZ(x) ((int)(x).size())

int N, Q, x, y;
vector<vector<int>> tree(200010, vector<int>());  //頂点関係
vector<int> par(200010, 0);  //頂点の親
vector<li> counter(200010, 0);  //カウンター


void add_counter(int v, int p, li cn_p){
  counter[v] += cn_p;  //vにcn_p分を伝搬
  for(int i = 0; i < SZ(tree[v]); i++){
    int chi_v = tree[v][i];
    if(chi_v == p) continue;
    par[chi_v] = v;
    add_counter(chi_v, v, counter[v]);
  }
  return;
}


int main(){
  cin >> N >> Q;
  
  /*以下、辺を取得*/
  for(int i = 0; i < N-1; i++){ 
    cin >> x >> y;
    tree[x].pb(y); tree[y].pb(x);
  }
  
  /*以下、カウンタを取得*/
  for(int i = 0; i < Q; i++){
    cin >> x >> y;
    counter[x] += y;  //xに加えるカウンタ数
  }
  
  add_counter(1, 0, 0);
  
  for(int i = 1; i <= N; i++) cout << counter[i] << endl;
  return 0;
}


Measured memory_bytes: 25088
#include <bits/stdc++.h>
using namespace std;
 
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);
#define left  (2*idx)+1
#define right (2*idx)+2
#define pb push_back
#define ll long long
#define all(x) x.begin(),x.end()
 

const ll MOD = (ll)(1e9 + 7); 
const ll N = 0;

int p[21][21];
int main()
{
	FIO;
	int h, w;
	int a, b;
	cin >> h >> w;
	cin >> a >> b;
	for(int i=1; i<=a; i++) {
		for(int j=1; j<=w; j++) {
			p[i][j] = 1;
		}
	}
	for(int i=1; i<=h; i++) {
		for(int j=1; j<=b; j++) {
			p[i][j] = 1;
		}
	}

	int ans = 0;
	for(int i=1; i<=h; i++) {
		for(int j=1; j<=w; j++) {
			ans = ans + (p[i][j]^1);
		}
	}
	cout << ans << "\n";
	return 0;	
}	

Measured memory_bytes: 256
#!/usr/bin/env python
# coding: utf-8

def ri():
    return int(input())

def rl():
    return list(input().split())

def rli():
    return list(map(int, input().split()))

def main():
    n, k = rli()
    lh = rli()
    lh.sort(reverse=True)
    ans = sum(lh[k:])
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 26024
#include "bits/stdc++.h"

using namespace std;

bool tab[107][107];
int N, K;

int ile() {
  int cnt = 0;
  for(int i=0; i<N; i++) {
    for(int j=i+1; j<N; j++) {
      if(!tab[i][j]) cnt++;
    }
  }
  return cnt;
}

void wypisz() {
  int edges = 0;
  for(int i=0; i<N; i++) for(int j=i+1; j<N; j++) if(tab[i][j]) edges++;
  cout << edges << "\n";
  for(int i=0; i<N; i++) for(int j=i+1; j<N; j++) if(tab[i][j]) cout << i+1 << " " << j+1 << "\n";
  exit(0);
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
  cin >> N >> K;
  for(int i=1; i<N; i++) tab[0][i] = tab[i][0] = true;
  for(int i=1; i<N; i++) for(int j=i+1; j<N; j++) {
    if(ile() == K) wypisz();
    tab[i][j] = tab[j][i] = true;
  }
  if(ile() == K) wypisz();
  cout << -1 << "\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, s, n) for(int i = s; i < (int)n; i++)
#define per(i, n) for(int i = n; i >= 0; i--)
#define ROF(i, s, n) for(int i = s; i >= (int)n; i--)
#define FORIT(i, A) for (auto i : A)
#define PRINT(x) cout << (x) << "\n"
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define MP make_pair
#define EACH(i, n) for (__typeof((n).begin()) i = (n).begin(); i != (n).end(); ++i)
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define CLR(a) memset((a), 0 ,sizeof(a))
#define dump(x) cout << #x << " = " << (x) << "\n";
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << "\n";
#define sq(n) (n) * (n)
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef priority_queue<int> maxpq;
typedef priority_queue< int, vector<int>, greater<int> > minpq;
static const double EPS = 1e-10;
static const double PI = acos( -1.0 );
static const int mod = 10007;
static const int INF = 1 << 25;
static const LL LL_INF = 1152921504606846976;
static const int dx[] = { -1, 0, 1, 0,  1, -1,  1, -1 };
static const int dy[] = { 0, -1, 0, 1 , 1,  1, -1, -1 };


int a, b, n;
VI pm;

int main() {
	pm.push_back( 2 );
	for ( int i = 3; i < 9000000; i += 2 ) {
		bool can_add = true;
		for ( int j = 0; j < pm.size() && pm[ j ] * pm[ j ] <= i; j++ ) {
			if ( !( i % pm[ j ] ) ) {
				can_add = false;
				break;
			}
		}
		if ( can_add ) {
			pm.push_back( i );
		}
	}
	while ( ~scanf( "%d %d %d", &a, &b, &n ) && a && b && n ) {
		while ( n ) {
			n -= binary_search( pm.begin(), pm.end(), a );
			if ( !n ) {
				printf( "%d\n", a );
				break;
			}
			a += b;
		}
	}
	return 0;
}

Measured memory_bytes: 5320
#include <cstdio>
#include <algorithm>

using namespace std;

const int N = 1e5 + 500;
const int INF = 0x3f3f3f3f;

int a, b, m, mi_a = INF, mi_b = INF;
int A[N], B[N], sol = INF;

int main(){
	scanf("%d%d%d", &a, &b, &m);
	for(int i = 0;i < a;i++)
		scanf("%d", A + i), mi_a = min(mi_a, A[i]);
	for(int i = 0;i < b;i++)
		scanf("%d", B + i), mi_b = min(mi_b, B[i]);
	for(int i = 0;i < m;i++){
		int x, y, z; scanf("%d%d%d", &x, &y, &z);
		sol = min(A[x - 1] + B[y - 1] - z, sol);
	}
	printf("%d\n", min(sol, mi_a + mi_b));
	return 0;
	
}

Measured memory_bytes: 896
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<string>
#include<queue>
#include<utility>
#include<cmath>
#include<sstream>
#include<istream>

using namespace std;


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

  vector<char> ss;

  for(int i=0; i<S.length(); i++){
    if(S[i] == '0') ss.push_back('0');
    else if(S[i] == '1') ss.push_back('1');
    else if(S[i] == 'B'){
      if(ss.empty() != true){
        ss.pop_back();
      }
    }
  }

  for(int i=0; i<ss.size(); i++){
    cout << ss[i];
  }

  cout << endl;

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
    int a, b, c, l, m, s;
    scanf("%d%d%d", &a, &b, &c);
    if(a<b){
        if(b>c){
            l = b;
            if(a<c){
                m = c;
                s = a;
            }else{
                m = a;
                s = c;
            }
        }else{
            l = c;
            m = b;
            s = a;
        }
    }else{
        if(a<c){
            l = c;
            m = a;
            s = b;
        }else{
            l = a;
            if(b<c){
                m = c;
                s = b;
            }else{
                m = b;
                s = c;
            }
        }
    }
    printf("%d %d %d\n", s, m, l);
    return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
int main () {
  int Q;
  string S;
  list<char> SS;
  cin >> S >> Q;
  for(int i = 0; i < S.size(); i++){
    SS.push_back(S.at(i));
  }
  int r = 0, T, F;
  char a;
  for(int i = 0; i < Q; i++){
    cin >> T;
    if(T == 1){
      if(r == 0)r = 1;
      else r = 0;
    } else {
      cin >> F >> a;
      if(F == 1){
        if(r == 0){
          SS.push_front(a);
        } else {
          SS.push_back(a);
        }
      } else {
        if(r == 0){
          SS.push_back(a);
        } else {
          SS.push_front(a);
        }
      }
    }
  }
  if(r == 1)SS.reverse();
  for(auto i = SS.begin(); i != SS.end(); i++){
    cout << *i;
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 9984
#include <iostream>

#include <vector>
#include <map>
#include <algorithm>
#include <fstream>
#include<cstdio>
#include<iomanip>
#include<stack>
#include<queue>
#include<string>
#include <cstdlib>
#include <typeinfo>

#define REP(i, n) for(int i=0;i<n;i++)
#define REP2(i, s, n) for(int i=s;i<n;i++)
#define REP_1(i, n) for(int i=1;i<n+1;i++)
#define bitSearch(bit, n) for(int bit = 0; bit < (1 << N); bit++)
using namespace std;

template<class T>
void print(const T &value) {
    std::cout << value << std::endl;
}

void yesno(bool a) { if (a)cout << "Yes" << endl; else cout << "No" << endl; }

void YESNO(bool a) { if (a)cout << "YES" << endl; else cout << "NO" << endl; }

typedef long long ll;
typedef unsigned long ul;
typedef long double ld;

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;
}

//ll INF = 10000000;
//ll mod = 1000000007;//10^9+7
int dx[8] = {-1, 0, 0, 1, -1, -1, 1, 1};
int dy[8] = {0, -1, 1, 0, -1, 1, -1, 1};
//using Graph = vector<vector<int>>;


//番号ズレ注意！！
int main() {
    int H, W;
    cin >> H >> W;
    string field[H];
    REP(i, H) {
        cin >> field[i];
    }


    int dist[H][W];
    REP(i, H) {
        REP(j, W) {
            dist[i][j] = -1;
        }
    }
    queue<pair<int, int>> que;
    que.push(make_pair(0, 0));
    dist[0][0] = 0;
    while (!que.empty()) {
        pair<int, int> v = que.front();
        que.pop();
        int x = v.first, y = v.second;
        REP(i, 4) {
            int nx = x + dx[i];
            int ny = y + dy[i];
            if (nx < 0 || nx >= H || ny < 0 || ny >= W) { continue; }
            if (field[nx][ny] == '#') { continue; }
            if (dist[nx][ny] != -1) { continue; }
            dist[nx][ny] = dist[x][y] + 1;
            que.push(make_pair(nx, ny));
        }
    }

    int black = 0;
    REP(i, H) {
        REP(j, W) {
            if (field[i][j] == '#') {
                black += 1;
            }
        }
    }
    int d = dist[H - 1][W - 1];
    int ans = H * W - black - d - 1;
    if (d == -1) { cout << "-1" << endl; }
    else {
        print(ans);
    }
}


Measured memory_bytes: 256
def lcs(x, y):
    ans = [[0]*(len(y)+1) for _ in range(len(x)+1)]
    for i, cx in enumerate(x, 1):
        ao = ans[i-1]
        old = ans[i][0]
        for j, cy in enumerate(y, 1):
            if cx == cy:
                old = ao[j-1] + 1
            else:
                a1, a2 = old, ao[j]
                old = a1 if a1 > a2 else a2
            ans[i][j] = old
    return ans[-1][-1]

def main():
    n = int(input())
    a = []
    for _ in range(n):
        X = input()
        Y = input()
        a.append(lcs(X, Y))
    print('\n'.join(list(map(str, a))))

if __name__ == "__main__":
    main()


Measured memory_bytes: 30868
class Dice():
    def __init__(self):
        self.nums = list(range(6))
        self.work = list(range(6))

    def set_nums(self, n0, n1, n2, n3, n4, n5):
        self.nums[0] = n0
        self.nums[1] = n1
        self.nums[2] = n2
        self.nums[3] = n3
        self.nums[4] = n4
        self.nums[5] = n5

    def rotate(self, cmd):
        for i in range(6):
            # deepcopy
            self.work[i] = self.nums[i]

        if cmd == 'N':
            self.set_nums(self.work[1], self.work[5], self.work[2], self.work[3], self.work[0], self.work[4])
        elif cmd == 'S':
            self.set_nums(self.work[4], self.work[0], self.work[2], self.work[3], self.work[5], self.work[1]),
        elif cmd == 'E':
            self.set_nums(self.work[3], self.work[1], self.work[0], self.work[5], self.work[4], self.work[2])
        else:
            self.set_nums(self.work[2], self.work[1], self.work[5], self.work[0], self.work[4], self.work[3])

    def top(self):
        return self.nums[0]

    def right(self, top, front):
        # サイコロの面IDを返す
        if top == 1:
            return [3,5,2,4][front-2]
        elif top == 6:
            return [4,2,5,3][front-2]
        elif top == 2:
            # 0が返る場合は不正なサイコロ
            return [4,0,1,6,0,3][front-1]
        elif top == 5:
            # 0が返る場合は不正なサイコロ
            return [3,0,6,1,0,4][front-1]
        elif top == 3:
            # 0が返る場合は不正なサイコロ
            return [2,6,0,0,1,5][front-1]
        elif top == 4:
            # 0が返る場合は不正なサイコロ
            return [5,1,0,0,6,2][front-1]
        else:
            pass

    def rolls(self):
        # 上面、前面、右面、左面、奥面、下面の値を返す
        return [self.nums[i] for i in range(6)]


import random

# init
n = int(input())
nums = [[int(arg) for arg in input().split()] for _ in range(n)]
dices = [Dice() for _ in range(n)]
for i in range(n):
    dices[i].set_nums(*nums[i])

master_roll = dices.pop(0).rolls()
results = []
for dice in dices:
    for i in range(1000):
        cmd = ['N', 'S', 'E', 'W'][random.randint(0,3)]
        dice.rotate(cmd)
        dice_roll = dice.rolls()
        if all([master_roll[i] == dice_roll[i] for i in range(6)]):
            results.append(0)
            break
print('Yes' if len(results) == 0 else 'No')



Measured memory_bytes: 8252
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

A,B,K = map(int, read().decode("utf-8").split())

if K > A:
  K = K - A
  A = 0
else:
  A = A - K 
  print(A, B)
  quit()

if K > B:
  K = K - B
  B = 0
else:
  B = B - K
  print(A, B)
  quit()

print(0, 0)


Measured memory_bytes: 3064
import java.util.*;
import java.math.*;

public class Main {
  public static void main(String[] args) {
    int[] arr = new int[]{1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    Scanner sc = new Scanner(System.in);
    int idx = sc.nextInt();
    System.out.println(arr[idx-1]);
  }
}


Measured memory_bytes: 21716
# AtCoder Beginner Contest 132
# D - Blue and Red Balls
# https://atcoder.jp/contests/abc132/tasks/abc132_d
N, K = map(int, input().split())
MAX = 510000
MOD = 10**9 + 7

fac = [0]*MAX
facinv = [0]*MAX
inv = [0]*MAX


def modinv(a, mod):
    b = mod
    x, u = 1, 0
    while b:
        q = a//b
        a, b = b, a-q*b
        x, u = u, x-q*u
    x %= mod
    return x


def mod_nCr_init(n, mod):
    fac[0] = fac[1] = 1
    facinv[0] = facinv[1] = 1
    inv[1] = 1
    for i in range(2, n):
        fac[i] = fac[i-1] * i % mod
        inv[i] = -inv[mod % i] * (mod // i) % mod
        facinv[i] = facinv[i-1] * inv[i] % mod


def mod_nCr(n, r, mod):
    if n < r or n < 0 or r < 0:
        return 0
    return fac[n] * (facinv[r] * facinv[n-r] % mod) % mod


mod_nCr_init(MAX, MOD)

for i in range(1, K+1):
    ans = mod_nCr(N-K+1, i, MOD)*mod_nCr(K-1, i-1, MOD) % MOD
    print(ans)


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

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef pair<int, int> pi;

int n;
const int maxn = 1e5 + 5;
int a[maxn];
int cnt[2];

bool check(int v){
    memset(cnt, 0, sizeof(cnt));
    for(int i = 1;i <= n;i++){
        if(a[i] < v - 1){
            return false;
        }
        cnt[v - a[i]]++;
    }
    if(cnt[1] > v)
        return false;
    else if(cnt[1] == v){
        if(cnt[0] == 0)
            return true;
        else
            return false;
    }else{
        if(cnt[0] / (v - cnt[1]) < 2){
            return false;
        }else
            return true;
    }
}

int main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> n;
    for(int i = 1;i <= n;i++){
        cin >> a[i];
    } 
    int mx = *max_element(a + 1, a + 1 + n);
    if(check(mx) or check(mx + 1)){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 640
import sys

output = []

def main():
    lines = sys.stdin.readlines()

    for line in lines:
        # print(line)
        line = line.strip('\n')
        elems = line.split(" ")
        output_num = 0
        if elems[1] == '+':
            output_num = int(elems[0]) + int(elems[2])
        elif elems[1] == '-':
            output_num = int(elems[0]) - int(elems[2])
        elif elems[1] == '*':
            output_num = int(elems[0]) * int(elems[2])
        elif elems[1] == '/':
            output_num = int(elems[0]) / int(elems[2])
        elif elems[1] == '?':
            sys.exit()
        print(output_num)

if __name__ == "__main__":
    main()

Measured memory_bytes: 6476
#include <iostream>
using namespace std;
int main() {
	string S, u;
	int K;
	cin >> S >> K;
	long long int d[3] = {};
	for (int j = 0; j < 3; j++) {
		auto t = u += S;
		for (int i = 1; i < t.length(); i++)
			if (t[i - 1] == t[i]) {
				t[i] = '!';
				d[j]++;
			}
	}
	if (K < 2) {
		cout << d[0] << endl;
	} else {
		cout << (K % 2 ? d[2] : d[1]) + (d[2] - d[0])*(K / 2 - 1) << endl;
	}
	return 0;
}


Measured memory_bytes: 256
import java.lang.NumberFormatException
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val h = sc.nextInt()
    val w = sc.nextInt()
    val s = (0 until h).map { sc.next().toCharArray() }
    println(problem075b(h, w, s))
}

fun problem075b(h: Int, w: Int, s: List<CharArray>): String {
    val ans = Array(h) { Array(w) { "0" } }
    for (i in 0 until h) {
        for (j in 0 until w) {
            if (s[i][j] != '#') {
                continue
            }
            ans[i][j] = "#"
            try {
                if (i != 0) ans[i - 1][j] = (ans[i - 1][j].toInt() + 1).toString()
            } catch (e: NumberFormatException) {
            }
            try {
                if (j != 0) ans[i][j - 1] = (ans[i][j - 1].toInt() + 1).toString()
            } catch (e: NumberFormatException) {
            }
            try {
                if (i != 0 && j != 0) ans[i - 1][j - 1] = (ans[i - 1][j - 1].toInt() + 1).toString()
            } catch (e: NumberFormatException) {
            }
            try {
                if (i != h - 1) ans[i + 1][j] = (ans[i + 1][j].toInt() + 1).toString()
            } catch (e: NumberFormatException) {
            }
            try {
                if (j != w - 1) ans[i][j + 1] = (ans[i][j + 1].toInt() + 1).toString()
            } catch (e: NumberFormatException) {
            }
            try {
                if (i != h - 1 && j != w - 1) ans[i + 1][j + 1] = (ans[i + 1][j + 1].toInt() + 1).toString()
            } catch (e: NumberFormatException) {
            }
            try {
                if (i != 0 && j != w - 1) ans[i - 1][j + 1] = (ans[i - 1][j + 1].toInt() + 1).toString()
            } catch (e: NumberFormatException) {
            }
            try {
                if (i != h - 1 && j != 0) ans[i + 1][j - 1] = (ans[i + 1][j - 1].toInt() + 1).toString()
            } catch (e: NumberFormatException) {
            }
        }
    }
    return ans.map { it.joinToString("") }.joinToString("\n")
}

Measured memory_bytes: 38728
# include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)

LL l, r;

int main(){
	cin >> l >> r;
	LL ans = 2020;
	for(LL i = l;i <= min({r, l + 2020});i++){
		for(LL j = i + 1LL;j <= min({r, l + 2020});j++){
			ans = min(ans, i * j % 2019);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
template<class T,class U> inline bool chmin(T&x,U y){if(x>y){x=y;return true;}return false;}
template<class T,class U> inline bool chmax(T&x,U y){if(x<y){x=y;return true;}return false;}

vector<int> e[100000],vis;
int sz;
int rec(int i,bool f=false){
    if(vis[i]>=0) return 0;
    ++sz;
    vis[i]=f;
    int a{1};
    for(auto&j:e[i]){
        if(vis[j]>=0 and vis[j]==f) a=2;
        if(vis[j]<0) chmax(a,rec(j,!f));
    }
    return a;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,m;
    cin>>n>>m;
    for(int i{},u,v;i<m;++i){
        cin>>u>>v;
        --u;--v;
        e[u].push_back(v);
        e[v].push_back(u);
    }
    vis.assign(n,-1);
    ll c0{},c1{},c2{};
    for(int i{};i<n;++i){
        sz=0;
        int a=rec(i);
        if(a==1) ++c1;
        if(a==2) ++c2;
        if(sz==1) --c1,++c0;
    }
    cout<<2*c1*c1+2*c1*c2+c2*c2+c0*n*2-c0*c0<<endl;
}

Measured memory_bytes: 9984
// 29/07/19 // 5:46 PM //

#include <iostream>

using namespace std;

#define MAXN 3010

string a, b;
int memo[MAXN][MAXN];

void bottom_lcs(){
    a = " " + a;
    b = " " + b;

    for(int i=1; i<a.size(); i++){
        for(int j=1; j<b.size(); j++){
            if(a[i]==b[j])
                memo[i][j] = 1 + memo[i-1][j-1];
            else
                memo[i][j] = max(memo[i-1][j], memo[i][j-1]);
        }
    }

    int i = a.size()-1, j = b.size()-1;
    string resp = "";
    while(i!=0 && j!=0){
        if(memo[i-1][j-1]==memo[i-1][j] && memo[i-1][j-1]==memo[i][j-1] && memo[i-1][j-1]+1==memo[i][j]){
            resp += a[i];
            i--;
            j--;
        }
        else if(memo[i][j]==memo[i-1][j])
            i--;
        else if(memo[i][j]==memo[i][j-1])
            j--;
    }

    for(i=resp.size()-1; i>=0; i--)
        cout << resp[i];
  	cout << "\n";
}

int main(){

    cin >> a >> b;

    bottom_lcs();

    return 0;
}


Measured memory_bytes: 35584
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
signed main(){
  string s;
  cin>>s;
  {
    string t=s;
    t.erase(unique(t.begin(),t.end()),t.end());
    if(t.size()==1u){
      cout<<s.size()<<endl;
      return 0;
    }
  }
  Int n=s.size();
  Int ans=1;
  for(Int k=0;k<2;k++){
    vector<Int> dp(n,1);
    for(Int i=n-2;i>=0;i--)
      if(s[i]==s[i+1]) dp[i]=dp[i+1]+1;
    
    for(Int i=1;i<n;i++)
      if(i+dp[i]>=n-i) 
	ans=max(ans,n-i);
    
    reverse(s.begin(),s.end());
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 1280
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <climits>
#include<unordered_set>
#include<string>
#include<cmath>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

#define INF INT_MAX/3
#define REP(i,n) for(int i=0;i<n;i++)
#define show(x) cout<< #x << " = " << (x) << endl
#define show_array(arr) REP(i,int((arr).size()))cout<< #arr << "["<<i<<"]"<<"="<<arr[i]<<endl


inline string invert_str(string str,int i,int j ){
	while(i < j){
		char tmp;
		tmp = str[i];
		str[i] = str[j];
		str[j] = tmp;
		i++;
		j--;
	}

	return str;
}


int main(){

	ios::sync_with_stdio(false);
	
	string str;

	cin>>str;
	
	ll answer = str.size() * (str.size()-1) / 2 + 1;
	// unordered_set<string> table;
    //
    //
	// table.insert(str);

	const int N = str.size();
	//ll wcount = 0;

		for(char c = 'a' ; c <= 'z'; c++){
			ll c_count = 0;
			for(int i = 0; i < N; i++ ){
				if(str[i] == c){
					c_count++;
				}
			}
			if(c_count != 0)answer -= c_count * (c_count - 1) / 2;
		}

	cout<<answer<<endl;
//	cout<<table.size()<<endl;	
	return 0;
}


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

int main(){

ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int a,p;
    cin>>a>>p;
    p+=a*3;
    cout<<p/2;

}

Measured memory_bytes: 256
N,K = list(map(int, input().split()))
A = list(map(int, input().split()))
now = 1
path = [1]
flag = []
for i in range(N):
  if(i==0):
    flag.append(1)
  else:
    flag.append(0)
for i in range(N):
  now = A[now - 1]
  if(flag[now - 1] == 0):
    path.append(now)
    flag[now - 1] += 1
  else:
    break
roop = [path[len(path) - 1]]
for i in range(N):
  now = A[roop[i] - 1]
  if(flag[now - 1] == 1):
    roop.append(now)
    flag[now - 1] += 1
  else:
    break
roop.pop(0)
if(K <= len(path) - 1):
  print(path[K])
elif(K == len(path)):
  print(roop[0])
else:
  print(roop[(K - len(path))%len(roop)])

Measured memory_bytes: 32312
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define repR(i, n) for(ll i = n; i >= 0; i--)
#define For(i, m, n) for(ll i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
ll gcd(ll a, ll b){
    ll r = a % b;
    while(r!=0){
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}

ll lcm(ll x, ll y)
{
    if(x == 0 || y == 0) {
        return -1;
    }
    
    return (x * y / gcd(x, y));
}

using namespace std;

int main(int argc, char *argv[]) {
    ll result = 0;
    ll P, Q, R;
    cin >> P >> Q >> R;
    result += P + Q + R;
    result -= max({P, Q, R});
    
    cout << result << endl;
    return 0;
}



Measured memory_bytes: 256
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

s = input()[::-1]
n = len(s)
now = [0] * 13
now[0] = 1
for i,x in enumerate(s):
    new = [0] * 13
    c = pow(10,i,13)
    if x == '?':
        for k in range(10):
            for j in range(13):
                new[(j+c*k)%13] += now[j]
                new[(j+c*k)%13] %= mod
    else:
        for j in range(13):
            new[(j+c*int(x))%13] += now[j]
            new[(j+c*int(x))%13] %= mod
    now = new[::]
print(now[5])

Measured memory_bytes: 68968
#include <algorithm>
#include <vector>
#include <cfloat>
#include <string>
#include <cmath>
#include <set>
#include <cstdlib>
#include <map>
#include <ctime>
#include <iomanip>
#include <functional>
#include <deque>
#include <iostream>
#include <cstring>
#include <queue>
#include <cstdio>
#include <stack>
#include <climits>
#include <sys/time.h>
#include <cctype>
#include <bitset>

using namespace std;

typedef long long ll;

#define EPS 1e-9

class circle {
public:
  int c;
  double x, y, r;
  circle(double tx, double ty, double tr, int tc) {
    x = tx;
    y = ty;
    r = tr;
    c = tc;
  }
};

vector <circle> tempCirc;

bool collision(circle c1, circle c2) {
  return c1.r+c2.r-hypot(c1.x-c2.x, c1.y-c2.y) >= EPS;
}

char memo[(2<<24)+1];
int rec(int x) {
  int n = tempCirc.size();
  vector <int> field[n];

  if (memo[x] != -1) return memo[x];
  int ret = 0;
  for (int i = n-1; i >= 0; i--) {
    if (! ((x>>i)&1) ) continue;
    for (int j = i-1; j >= 0; j--) {
      if (! ((x>>j)&1) ) continue;
      if (collision(tempCirc[i], tempCirc[j])) {
	field[i].push_back(j);
      }
    }
  }

  vector <int> list;
  for (int i = 0; i < n; i++) {
    if (field[i].size() == 0) list.push_back(i);
  }

  for (int i = 0; i < list.size(); i++) {
    for (int j = i+1; j < list.size(); j++) {
      if (! (x&(1<<list[i])) ) continue;
      if (! (x&(1<<list[j])) ) continue;
      if (tempCirc[list[i]].c != tempCirc[list[j]].c) continue;
      ret = max(ret, rec(x^(1<<list[i])^(1<<list[j]))+2 );
    }
  }


  return memo[x] = ret;
}

int main() {
  int n;
  while(true) {
    cin >> n;
    if (n == 0) break;
    vector <circle> circ;
    for (int i = 0; i < n; i++) {
      int c;
      double x, y, r;
      cin >> x >> y >> r >> c;
      circ.push_back(circle(x, y, r, c));
    }
    tempCirc = circ;

    memset(memo, -1, sizeof(memo));
    std::cout << rec((1<<n)-1) << std::endl;
  }
}

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

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


    vector<string> S(N+1, "TLE");
    int ac_cnt = 0;
    int wa_cnt = 0;
    vector<int> WA(N+1, 0);
    for(int i=0; i<M; i++){
        int p;
        string s;
        cin>>p;
        cin>>s;
        
        if(S[p] == "AC"){continue;}
            if(s == "AC"){
                S[p] = "AC";
                ac_cnt++;
                wa_cnt += WA[p];
            }else if(s == "WA"){ 
                S[p] = "WA";
                WA[p]++;
            }
        
    }

    cout<<ac_cnt<<" "<<wa_cnt<<endl;
    return 0;
}

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

int main() {
    int N;
    cin >> N;
    long C, K;
    cin >> C >> K;

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

    int c = 0;
    // int capa = 1;
    int t;
    // string state = "DEP";
    for (int i = 0; i < N;) {
        c++;
        t = i;
        while (i < N && A[i] - A[t] <=K && i - t < C)
            i++;
    }
    cout << c << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin>>s;
 int l=s.length();
  if(s[l-1]=='s')
    cout<<s<<"es"<<"\n";
  else
    cout<<s<<"s"<<"\n";
}

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


def dfs(s):
    if int(s) > N:
        return 0
    ct = 1 if all(s.count(a) for a in '357') else 0
    ct += dfs(s+'3')
    ct += dfs(s+'5')
    ct += dfs(s+'7')
    return ct


print(dfs('0'))


Measured memory_bytes: 3060
#include <algorithm>
#include <cstdio>

using namespace std;

int main() {
  int a, b, c;
  while (scanf("%d%d%d", &a, &b, &c) == 3) {
    bool cs[11];
    fill(cs+1, cs+11, true);
    cs[a] = cs[b] = cs[c] = false;
    int p = 0;
    for (int i = 1; i <= 10; i++)
      if (cs[i] && a + b + i <= 20)
        p++;
    puts(p >= 4 ? "YES" : "NO");
  }
  return 0;
}

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

int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++)
		cin >> a[i];
	vector<int> b(100000, 0);
	for (int i = 0; i < n; i++)
		b[a[i]]++;
	int max = 0;
	for (int i = 0; i < 99998; i++)
		if (max < b[i] + b[i + 1] + b[i + 2])
			max = b[i] + b[i + 1] + b[i + 2];
	cout << max << endl;
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
    int flag=0,i;
    string s,t;
    cin>>s>>t;
    if(t.size()==s.size()+1)
    {
        for(i=0;i<t.size()-1;i++)
        {
            if(s[i]!=t[i])
            flag++;
        }
    }
    else
    {
        flag++;
    }
    if(flag==0)
    cout<<"Yes"<<endl;
    else
    {
        cout<<"No"<<endl;
    }
    

}

Measured memory_bytes: 3596
from collections import deque
d = deque()

S = input()
Q = int(input())
d.extend(S)




front = True

for i in range(Q):
    inp = input().split()
    if inp[0] == '1':
        front = not front
    else:
        F = int(inp[1])
        C = inp[2]
        if F == 1:
            if front:
                d.appendleft(C)
            else:
                d.append(C)
        elif F == 2:
            if front:
                d.append(C)
            else:
                d.appendleft(C)

if not front:
    d.reverse()

d_list = list(d)
str = "".join(d_list)

print(str)


Measured memory_bytes: 9204
import heapq
# sys.stdin.readline()
import sys
input = sys.stdin.readline

N,Q = list(map(int, input().split()))

S,T,X = [],[],[]

Ev = []
for _ in range(N):
  s,t,x = list(map(int, input().split())) 
  Ev.append((s-x,True,x))
  Ev.append((t-x,False,x))
"""
2 5 6
5 -1
4 2
3 3
2 4
1 5
0 -1
"""
Ev.sort()
#print(Ev)
# C++のSetはminもO(logN)で取れるが、Pythonは無理。
# setとheapqを併用すると計算量が実現できる。
h = []
closed = set()
eidx = 0
D = []

# 受け取った方が早い・・・？
for i in range(Q):
  D.append(int(input()))

for d in D:
  # dはsortedでinputされる。
  #d = int(input())
  #Query.append(d)
  while eidx < 2*N and Ev[eidx][0] <= d:
    #pop
    t,e,x = Ev[eidx]
    eidx += 1
    if e:
      heapq.heappush(h, x)
      closed.add(x)
    else:
      closed.remove(x)
      
  # heqpqの最小値がsetに含まれている間、捨て続ければ、setの要素とheapqの要素が一致する
  while h and h[0] not in closed:
    heapq.heappop(h)
    
  # assert( len(h) == len(set) )
  if h:
    print(h[0])
  else:
    print(-1)


Measured memory_bytes: 162112
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;
 
//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();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
 
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
 

LL gcd(LL a, LL b){
    if(b == 0) return a;
    return gcd(b,a%b);
}

LL lcm(LL a, LL b){
    LL g = gcd(a,b);
    return a/g *b;
}

int main(){
   LL N;
   cin >> N;
   LL A[N];
   REP(i,N){
       cin >> A[i];
   }
   sort(A,A+N);
   LL count=1;
   LL num=0;
   LL res=0;
   LL yoko=0;
   LL tate=0;
    LL tmp=0;
    while(res<N){
        tmp=A[res];
        count=0;
        while(tmp==A[res]){
            ++count;
            if(count==2){
                if(yoko*A[res]<tate*A[res]){
                    yoko=A[res];
                    count=0;
                }
                else{
                    tate=A[res];
                    count=0;
                }
            }
            ++res;
        }
        
    }
    
   num=yoko*tate;
   cout << num ;
    }

Measured memory_bytes: 1024
sx,sy,tx,ty=map(int,input().split())
a=tx-sx
b=ty-sy
L="R"*a+"U"*b +"L"*a+"D"*b+"D"+"R"*(a+1)+"U"*(b+1)+"LU"+"L"*(a+1)+"D"*(b+1)+"R"
print(L)

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

int main() {
    int N;
    cin >> N;
    vector<ll> L;
    rep(i,N) {
        ll l;
        cin >> l;
        L.push_back(l);
    }
    sort(L.begin(),L.end(),greater<ll>());
    int cnt = 0;
    if(L.size() >= 3) {
        for(int i = 0; i < L.size()-2; i++) {
            for(int j = i+1; j < L.size()-1; j++) {
                if(L.at(j) == L.at(i)) continue;
                for(int k = j+1; k < L.size(); k++) {
                    if(L.at(k) == L.at(j)) continue;
                    if(L.at(i) < L.at(j) + L.at(k)) {
                        cnt++;;
                    }
                }
            }
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include <map>
#include <string>

using namespace std;

void solve()
{
	string str;
	cin >> str;
	map<char, int> Map;
	int n = str.size();
	for(int i = 0; i < n; ++i)
	{
		Map[str[i]]++;
	}
	int min = 100000000;
	if(Map['K'] < min)
	{
		min = Map['K'];
	}
	if(Map['U'] < min)
	{
		min = Map['U'];
	}
	if(Map['P'] < min)
	{
		min = Map['P'];
	}
	if(Map['C'] < min)
	{
		min = Map['C'];
	}
	cout << min << endl;
}

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

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

public class Main {
	
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		
		String s = sc.next();
		
		if (s.charAt(0) == s.charAt(1)) {
			out.println(1 + " " + 2);
		} else {
			boolean flag = true;
			for (int i = 2; i < s.length(); i++) {
				if (s.charAt(i - 2) == s.charAt(i)) {
					out.println(i - 1 + " " + (i + 1));
					flag = false;
					break;
				} else if (s.charAt(i - 1) == s.charAt(i)) {
					out.println(i + " " + (i + 1));
					flag = false;
					break;
				}
			}
			if (flag) out.println(-1 + " " + -1);
		}
		out.flush();
	}
	
}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;
	
	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}
	
	private byte readByte() {
		if (hasNextByte()) {
			return buffer[ptr++];
		} else {
			return -1;
		}
	}
	
	private boolean isPrintableChar(int c) {
		return '!' <= c && c <= '~';
	}
	
	private void skipUnprintable() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
			ptr++;
		}
	}
	
	public boolean hasNext() {
		skipUnprintable();
		return hasNextByte();
	}
	
	public String next() {
		if (!hasNext()) {
			throw new NoSuchElementException();
		}
		StringBuilder sb = new StringBuilder();
		byte b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}
	
}

Measured memory_bytes: 9680
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define all(obj) (obj).begin(),(obj).end() 
#define dump(x)  cout << #x << " = " << (x) << endl;
typedef long long lint;
using namespace std;
int main(){
	lint n,ans=0;
	cin>>n;
	vector<lint>a(n+1),b(n);
	rep(i,n+1)cin>>a.at(i);
	rep(i,n)cin>>b.at(i);
	rep(i,n){
		if(b.at(i)<a.at(i)){
			ans+=b.at(i);
			continue;
		}else{
			ans+=a.at(i);
			b.at(i)-=a.at(i);
			ans+=min(a.at(i+1),b.at(i));
			a.at(i+1)-=b.at(i);
			if(a.at(i+1)<0)a.at(i+1)=0;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 1792