akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T> >;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define repb(i, n) for(ll i = (n)-1; i >= 0; i--)
#define repr(i, a, b) for(ll i = (a); i < (b); i++)
#define reprb(i, a, b) for(ll i = (b)-1; i >= (a); i--)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
const ll MOD = 1000000007;
const ll INF = 100000000000000000LL;
const ld EPS = 1e-12L;
const ld PI = 3.1415926535897932385L;
inline ll GCD(ll a, ll b){ return b?GCD(b, a % b):a; }
inline ll LCM(ll a, ll b){ return a/GCD(a, b)*b; }
inline ll powint(ull x, ll y){ ll r=1; while(y){ if(y&1) r*=x; x*=x; y>>=1; } return r; }
inline ll powmod(ll x, ll y, ll m = MOD){ ll r=1; while(y){ if(y&1) r*=x; x*=x; r%=m; x%=m; y>>=1; } return r; }
template<class S, class T>inline bool chmax(S &a, const T &b){ if(a<b) { a=b; return 1; } return 0; }
template<class S, class T>inline bool chmin(S &a, const T &b){ if(b<a) { a=b; return 1; } return 0; }
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll n;
    cin >> n;
    vll p(n);
    rep(i, n){
        cin >> p[i];
        p[i]--;
    }
    vi cnt(n+1, 0), rgt(n+1, 0);
    rep(i, n){
        cnt[p[i]]++;
        rgt[p[i]] = 1-cnt[p[i]+1];
    }
    rgt[n-1] = 0;
    dump(rgt);
    ll cnt2 = 0;
    ll ans = 0;
    rep(i, n){
        if(rgt[i] == 1) cnt2++;
        else cnt2 = 0;
        chmax(ans, cnt2);
    }
    cout << n-1-ans << endl;
    return 0;
}

Measured memory_bytes: 3456
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
int main(){
	int N, Q; cin >> N >> Q; 
	pair<int, pair<int, int>> S[200010] = {}; 
	for(int i = 0; i < N; i++){
		cin >> S[i].second.first >> S[i].second.second >> S[i].first; 
	}
	sort(S, S+N); 
	int D[200010] = {}; 
	set<int> E; 
	for(int i = 0; i < Q; i++){
		cin >> D[i]; E.insert(D[i]);  
	}
	map<int, int> M; 
	for(int i = 0; i < N; i++){
		auto it1 = E.lower_bound(S[i].second.first - S[i].first); 
		auto it2 = E.lower_bound(S[i].second.second - S[i].first); 
		vector<int> used = {}; 
		for(auto it = it1; it != it2; it++){
			M[*it] = S[i].first; used.push_back(*it); 
		}
		for(int j = 0; j < used.size(); j++){
			E.erase(used[j]); 
		}
	}
	for(int i = 0; i < Q; i++){
		if(M[D[i]]) cout << M[D[i]] << endl; 
		else cout << -1 << endl; 
	}
}

Measured memory_bytes: 22656
#include<iostream>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cstdio>
#include<numeric>
using namespace std;
using ll = long long;
int main(){
  int n;
  cin >> n;
  if(n == 1){
    cout << "Hello World\n";
  }else{
    int a, b;
    cin >> a >> b;
    cout << a + b << endl;
  }
  return 0;
}

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


int main(){
    int a, b;
    cin >> a >> b;
    if(a+b==3){
        cout << 3 << "\n";
        return 0;
    }else if(a+b==4){
        cout << 2 << "\n";
        return 0;
    }else{
        cout << 1 << "\n";
        return 0;
    }
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main (String[] args) {
        Scanner s = new Scanner(System.in);
        int a = s.nextInt();
        int b = s.nextInt();
        if (a < b) {
            System.out.println("a < b");
        }
        else if (a > b) {
            System.out.println("a > b");
        }
        else if (a == b) {
            System.out.println("a == b");
        }
    }
}


Measured memory_bytes: 26284
def RoKuKer(s):
    n = len(s)

    if n%2 != 1:
        return "No"

    s_reverse = ''
    for i in range(n-1, -1, -1):
        s_reverse += s[i]
    if s != s_reverse:
        return "No"

    l = s[:(n-1)/2]; l_recerse = ''
    r = s[(n+1)/2:]; r_reverse = ''

    for i in range(len(l)-1, -1, -1):
        l_recerse += l[i]
    for i in range(len(r)-1, -1, -1):
        r_reverse += r[i]
    
    if l != l_recerse or r != r_reverse:
        return "No"
    
    return "Yes"




if __name__ == '__main__':
    S = str(raw_input())
    print RoKuKer(S)

Measured memory_bytes: 2692
import java.io.*;
import java.util.*;
import java.util.function.*;

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer in=new StringTokenizer("");
        int n=Integer.parseInt(br.readLine());
        Map<String,Long> mp=new HashMap<>();
        Consumer<String> fun=(s)->mp.put(s, mp.getOrDefault(s, 0L)+ 1L);
        for(int i=0;i<n;i++)fun.accept(Arrays.toString(br.readLine().chars().mapToObj(it -> (char) it).sorted().toArray()));
        System.out.println(mp.values().stream().mapToLong(it -> it * (it - 1) / 2).sum());
    }
}

Measured memory_bytes: 97956
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>

using namespace std;

int main(){
    int n;
    cin >> n;
  	vector<int> h(n), dp(n);
    
    for(int i = 0; i < n; i++){
        cin >> h[i];
    }
    dp[0] = 0;
    dp[1] = abs(h[0] - h[1]);
    
    for(int i = 2; i < n; i++){
        dp[i] = min(dp[i-1] + abs(h[i-1] - h[i]), dp[i-2] + abs(h[i-2] - h[i]));
    }
    
    cout << dp[n-1] << endl;
}


Measured memory_bytes: 1024
#include<iostream>
#include<set>

int main(){
    
    std::set<char> s;

    for(size_t i = 0; i < 4; i++){
        char tmp;
        std::cin >> tmp;
        s.insert(tmp);
    }

    if(s.size() == 2){
        std::cout << "Yes" << std::endl;
    }else{
        std::cout << "No" << std::endl;
    }
    
    return 0;
}


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

int main(){
    int N,M;
    cin >> N >> M;
    vector<pair<long long, long long>> A(N);
    for (int i = 0; i < N; i++){
        cin >> A[i].first >> A[i].second;
    }
    sort(A.begin(), A.end());
    long long res = 0;
    for (int i = 0; i < N; i++){
        if (M > A[i].second){
            res += A[i].first * A[i].second;
            M -= A[i].second;
        }
        else{
            res += A[i].first * M;
            break;
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
#define rep(i,n) for (ll i = 0; i < (ll)(n); ++i)
#define rrep(i,j,n) for(ll i = (ll)(j); i < (ll)(n); i++)
#define mrep(i,n) for (ll i = (ll)(n); i > 0; i--)
#define be(v) (v).begin(), (v).end()
#define dcout cout << fixed << setprecision(20) 
ll INF = 1LL << 60;
ll mod = 1e9 + 7;

int main() {
	string n; cin >> n;
	string a = n.substr(0,3);
	cout << a << endl;
}

Measured memory_bytes: 3596
def divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n%i == 0:
            divisors.append(i)
            if i != n//i:
                divisors.append(n//i)
    return sorted(divisors) 
n = int(input())
ans = len(divisors(n-1))-1;
for k in divisors(n)[1:]:
    boz = n
    while (n % k == 0):
        n = n//k
    if (n % k == 1):
	    ans += 1
    n = boz
print(ans)


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

using namespace std;

#define int long long
#define ff first
#define ss second
#define pii pair<int, int>
#define pb emplace_back
#define pf emplace_front
#define mp make_pair
#define ld long double
#define all(x) (x).begin(), (x).end()

const int maxn = 309;
int a[maxn][maxn];
int b[maxn][maxn];
int n, m, k;

signed main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> m >> k;
    for (int i = 0; i < n; i++)
    {
        string s;
        cin >> s;
        for (int e = 0; e < m; e++)
            a[i][e] = (s[e] == '#');
    }
    int pr = 0;
    int cnt = 1;
    for (int i = 0; i < n; i++)
    {
        int k = 0;
        bool kek = 0;
        for (int e = 0; e < m; e++)
        {
            if (a[i][e])
            {
                for (int j = pr; j <= i; j++)
                {
                    for (int t = k; t <= e; t++)
                        b[j][t] = cnt;
                }
                cnt++;
                k = e + 1;
                kek = 1;
            }
        }
        if (kek)
        {
            for (int j = pr; j <= i; j++)
            {
                for (int t = k; t < m; t++)
                    b[j][t] = cnt - 1;
            }
            pr = i + 1;
        }
    }
    for (int i = 0; i < pr; i++)
    {
        for (int e = 0; e < m; e++)
            cout << b[i][e] << " ";
        cout << "\n";
    }
    for (int i = pr; i < n; i++)
    {
        for (int e = 0; e < m; e++)
            cout << b[pr - 1][e] << " ";
        cout << "\n";
    }
}


Measured memory_bytes: 2304
#include<iostream>
#include<vector>
typedef long long int ll;
using namespace std;
int main() {
    ll n, m, k, a, b, count = 0, sumA = 0, maxCount = 0, i = 0, j = 0;
    cin >> n >> m >> k;
    vector<ll> A(n);
    vector<ll> B(m);
    for(ll i = 0; i < n; i++) {
        cin >> A[i];
    }
    for(ll j = 0; j < m; j++) {
        cin >> B[j];
    }
    for(i = 0; i < n; i++) {
        if(sumA + A[i] <= k) {
            sumA += A[i];
            count++;
        }
        else
            break;
    }
    i--;
    //cout << i << endl;
    for(j = 0; j < m; j++) {
        if(sumA + B[j] <= k) {
            sumA += B[j];
            count++;
        }
        else
            break;
    }
    //cout << count << endl;
    maxCount = count;
    while(i >= 0 && j < m) {
        sumA -= A[i];
        i--;
        count--;
        while(j < m && sumA + B[j] <= k) {
            sumA += B[j];
            j++;
            count++;
            maxCount = max(count, maxCount);
        }
    }
    cout << maxCount;
    return 0;
}

Measured memory_bytes: 6348
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#ifdef TEST
#define getchar_unlocked _getchar_nolock
#define putchar_unlocked _putchar_nolock
#endif
#define int long long
#define ins insert
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front
#define pp pop
#define ppb pop_back
#define ppf pop_front
#define eb emplace_back
#define g0(a) get<0>(a)
#define g1(a) get<1>(a)
#define g2(a) get<2>(a)
#define g3(a) get<3>(a)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef double db;
typedef long long ll;
typedef pair<int, int> ii;
typedef tuple<int, int, int> iii;
typedef tree<pair<int, int>, null_type, less<pair<int, int> >, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef tree<pair<int, int>, null_type, less<pair<int, int> >, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

int H, W, K, ans;
char C[15][15], Y[15][15];

main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> H >> W >> K;
	for (int i = 0; i < H; i++)
		for (int j = 0; j < W; j++) cin >> C[i][j];
	for (int i = 0; i < (1 << (H + W)); i++) {
		int cnt = 0;
		for (int j = 0; j < H; j++)
			for (int k = 0; k < W; k++) Y[j][k] = C[j][k];
		for (int j = 0; j < (H + W); j++)
			if (i & (1 << j)) {
				if (j >= H) {
					for (int k = 0; k < H; k++)
						Y[k][j - H] = '.';
				} else {
					for (int k = 0; k < W; k++)
						Y[j][k] = '.';
				}
 			}
 		for (int j = 0; j < H; j++)
			for (int k = 0; k < W; k++) cnt += (Y[j][k] == '#');
		if (cnt == K) ans++;
	}
	cout << ans << '\n';
}


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

int main(void) {
  int N;
  cin >> N;
  vector<int> H(N);
  for (int i = 0; i < N; i++) {
    cin >> H[i];
  }
  string ans = "Yes";
  for (int i = N - 2; i >= 0; i--) {
    if (H[i] > H[i + 1]) H[i]--;
    if (H[i] > H[i + 1]) {
      ans = "No";
      break;
    }
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;

int test[100001];

int res = 0;

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

    int n;
    cin >> n;
    
    for (int i = 0; i < n; ++i)
    {
        int x; cin >> x;
        ++test[x];
    }
    
    for (int j = 0; j <= 99998; ++j)
        res = max(res, test[j] + test[j + 1] + test[j + 2]);
    
    cout << res;
}

Measured memory_bytes: 640
def cin():
    in_ = list(map(int,input().split()))
    if len(in_) == 1:  return in_[0]
    else:  return in_

N = cin()
A = []
for i in range(N):
    in1, in2 = cin()
    A.append([in2, in1])

A = sorted(A)
t = 0
flg = 1
for i in range(N):
    t += A[i][1]
    if t > A[i][0]:  flg = 0
if flg:  print("Yes")
else:  print("No")

Measured memory_bytes: 106692
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF =1e9;
const ll LINF=1e18;
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; 
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
//setprecision(15)有効数字15桁
//-std=c++14
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a / gcd(a, b)*b;}
int a, b;
string s,t,u;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> s>>t>>a>>b>>u;
    if(s==u)a--;
    if(t==u)b--;
    cout << a<<" "<<b << "\n";
}



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

using namespace std;

inline int64_t max(int64_t a, int64_t b) {
  return a >= b ? a : b;
}

inline int64_t min(int64_t a, int64_t b) {
  return a <= b ? a : b;
}

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

  int64_t r;
  int64_t r_min;
  int64_t d_max = -1000000000;
  cin >> r_min;
  for (int i = 1; i < n; ++i) {
    cin >> r;
    d_max = max(d_max, r - r_min);
    r_min = min(r_min, r);
  }
  cout << d_max << endl;

  return 0;
}

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

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

int main(){
    int n,m,q;
    cin>>n>>m>>q;
    int train[n][n];
    memset(train,0,sizeof(train));
    rep(i,m){
        int l,r;
        cin>>l>>r;
        train[--l][--r]++;
    }

    int sums[n+1][n+1];
    memset(sums,0,sizeof(sums));
    rep(i,1,n+1) rep(j,1,n+1){
        sums[i][j]=sums[i][j-1]+sums[i-1][j]-sums[i-1][j-1]+train[i-1][j-1];
    }
    rep(i,q){
        int t0,t1;
        cin>>t0>>t1;
        --t0;
        cout<<sums[t1][t1]-sums[t0][t1]-sums[t1][t0]+sums[t0][t0]<<endl;
    }
}

Measured memory_bytes: 2816
a,b,c,k = map(int,input().split())
 
ans = 0

if k>a:
    ans += a
    k = k -a
else:
    ans += k
    k = 0

if k>b:
    k = k-b
else:
    k=0

if k>c:
    ans = ans -c
elif 0<k:
    ans = ans -k

print(ans)

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

#define fore(i, n) for(int i = 0; i < n; ++i)
const int MAXN = 1e5 + 5;
int memo[MAXN];
bool vis[MAXN];
int h[MAXN];
int n, k;

int solve(int i) {
  if (i >= n - 1) return 0;
  if (vis[i]) return memo[i];
  
  int res = 2e9;

  for (int j = i + 1; j <= min(i + k, n - 1); ++j)
    res = min(res, solve(j) + abs(h[i] - h[j]));

  vis[i] = true;
  return memo[i] = res;
}

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

  fore(i, n) 
    cin >> h[i];

  cout << solve(0) << endl;
  return 0;
}


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

using namespace std;

#define  CLR(a)  memset(a,0,sizeof(a))
#define  SET(a)  memset(a,-1,sizeof(a))
#define  nl "\n";
#define FIO ios_base::sync_with_stdio(false);cout.setf(ios::fixed);cout.precision(10);cout.tie(nullptr);cin.tie(nullptr);

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

template < class T> inline T biton(T n, T pos) { return n | ((T)1 << pos); }
template < class T> inline T bitoff(T n, T pos) { return n & ~((T)1 << pos); }
template < class T> inline T ison(T n, T pos) { return (bool)(n & ((T)1 << pos)); }
template < class T> inline T gcd(T a, T b) { while (b) { a %= b; swap(a, b); }return a; }

template <class T> inline T bigmod(T p, T e, T m) {
	T ret = 1;
	for (; e > 0; e >>= 1) {
		if (e & 1) ret = (ret * p) % m; p = (p * p) % m;
	} return (T)ret;
}

#define DEBUG

#ifdef DEBUG
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template < typename Arg1 >
void __f(const char* name, Arg1&& arg1)
{
	cerr << name << " is " << arg1 << std::endl;
}
template < typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args)
{
	const char* comma = strchr(names + 1, ',');
	cerr.write(names, comma - names) << " is " << arg1 << " | ";
	__f(comma + 1, args...);
}
#else
#define debug(...)
#endif



void solve()
{
	long long a;
	cin>>a;

	cout<<(a)+(a*a)+(a*a*a)<<nl;
}

int main()
{
	FIO;

	int t = 1;

	while (t--)
	{
		solve();
	}

	return 0;
}

Measured memory_bytes: 3608
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner scan = new Scanner(System.in);
        String s = scan.next();
        
        for(int i = 0; i < s.length(); i++) {
            if(i % 2 == 0) {
                System.out.print(s.charAt(i));
            }
        }
        System.out.println();
    }
}


Measured memory_bytes: 29548
#include <bits/stdc++.h>
#define fastio ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define endl '\n'
#define display(v) for (auto x : v) cout << x << ", "
#define dbg(x) cout << (#x) << " = " << (x) << "\n"
#define dbgp(x) cout << (#x) << " = {" << (x.first) << ", " << (x.second) << "}\n";
#define print(x) cout << (#x) << " = [ ";display(x); cout << "]\n"
#define pb push_back
typedef long long int ll;
typedef unsigned long long int ull;
using namespace std;


int main()
{
	fastio;

	ll l, r;
	cin >> l >> r;
	int ans = 2019;
	bool check[2019];
	fill(check, check + 2019, 0);
	int rem = 2019;
	for (ll i = l; i <= r and rem; i++)
	{
		int temp = i % 2019;
		if (check[temp] == 0)
		{
			rem--;
			check[temp] = 1;
		}
	}
	for (int i = 0; i < 2019; i++)
	{
		for (int j = 0; j < 2019; j++)
		{
			if (check[i] and check[j] and i != j)
			{
				ans = min(ans, (i * j) % 2019);
			}
		}
	}
	cout << ans;
	return 0;
}


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

int main() {
  string S;
  cin >> S;
  long Wnum = 0;
  long cnt = 0;
  for (size_t i=0; i<S.size(); i++) {
    if (S[i] == 'W') {
      Wnum += i - cnt;
      cnt++;
    }
  }
  cout << Wnum << endl;
}




Measured memory_bytes: 3760
# coding: utf-8
# Your code here!
n,m=map(int,input().split())
s = [list(input()) for i in range(n)]
cnt=0
for i in range(n):
    for j in range(m):
        if s[i][j]=='#':
            cnt+=1
if cnt>n+m-1:
    print('Impossible')
else:
    print('Possible')

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

int main(){
  int N,M;
  cin >> N >> M;
  int a[N],b[N],c[M],d[M];
  for(int i=0;i<N;i++){
    cin >> a[i] >> b[i];
  }
  for(int i=0;i<M;i++){
    cin >> c[i] >> d[i];
  }
  for(int i=0;i<N;i++){
    int min=1000000000;
    int minp=0;
    for(int j=0;j<M;j++){
      int dis=abs(a[i]-c[j])+abs(b[i]-d[j]);
      if(dis<min){
        min=dis;
        minp=j+1;
      }
    }
    cout << minp << endl;
  }
}



Measured memory_bytes: 256
import java.util.Scanner;

class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int h = sc.nextInt();
        int w = sc.nextInt();

        while (!(h == 0 && w == 0)) {

            for (int i = 0; i < h; i++) {
                for (int j = 0; j < w; j++) {
                    System.out.print("#");
                }
                System.out.println();
            }
            System.out.println();

            h = sc.nextInt();
            w = sc.nextInt();
        }
    }
}


Measured memory_bytes: 34648
// Crt. 2019-12-24  14:27:43
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <vector>
#define N 400
#define rint register int
using namespace std;
const int Mod = 1e9 + 7;

inline void inc(int &x, int y) {
    x += y, x -= x >= Mod ? Mod : 0;
}

int n, m, f[N][N][N];
vector<pair<int, int> > b[N];

bool check(int r, int j, int k) {
    for (int i = b[r].size() - 1; ~i; --i) {
        int l = b[r][i].first, x = b[r][i].second;
        if (l <= k && x != 3) return false;
        if (k < l && l <= j && x != 2) return false;
        if (j < l && x != 1) return false;
    } return true;
}

int main() {
#ifdef LOCAL_JUDGE
    freopen("work.in", "r", stdin);
    freopen("work.out", "w", stdout);
#endif

    cin >> n >> m;
    for (int i = 1, l, r, x; i <= m; ++i) {
        scanf("%d%d%d", &l, &r, &x);
        if (r - l + 1 < x) return puts("0"), 0;
        b[r].push_back(make_pair(l, x));
    }

    f[1][0][0] = 1;

    for (rint i = 1; i <= n; ++i)
        for (rint j = 0; j < i; ++j)
            for (rint k = 0; k <= j; ++k) {
                if (j && k == j) continue;
                if (!check(i, j, k)) { f[i][j][k] = 0; continue;}
                inc(f[i + 1][j][k], f[i][j][k]);
                inc(f[i + 1][i][j], f[i][j][k]);
                inc(f[i + 1][i][k], f[i][j][k]);
            }

    int ans = 0;
    for (int i = 0; i < n; ++i)
        for (int j = 0; j <= i; ++j) {
            if (j && i == j) continue;
            inc(ans, f[n][i][j]);
        }

    cout << 3ll * ans % Mod << endl;

    return 0;
}


Measured memory_bytes: 188672
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define mod 1000000007 //10^9+7
#define INF 1000000000000 //10^12
#define P pair<int,int>
#define rep(i,n) for(int i=0;i<n;i++)
string s;
set<char>st;
int ans=INF;
signed main(){
    cin>>s;
    int l=s.size();
    rep(i,l){
        st.insert(s[i]);
    }
    char c;
    rep(i,26){
        c='a'+i;
        if(st.find(c)==st.end())continue;
        int maxv=0,cnt=0;
        rep(j,l){
            if(s[j]!=c)cnt++;
            else{
                maxv=max(maxv,cnt);
                cnt=0;
            }
        }
        maxv=max(maxv,cnt);
        ans=min(ans,maxv);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
N = gets.to_i
list = []
N.times do |i|
  a,b = gets.split
  b = b.to_i
  list << [i+1,a,b]
end
list.sort_by!{|t| [t[1],-t[2]]}
list.each do |t|
  p t[0]
end


Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define is(a, b) a == b
#define len(v) ll(v.size())

const ll mod=1e9+7;

//vector書き出し
template <class T>
void cout_vec(const vector<T> &vec1){
  rep(i,len(vec1)){
    cout<<vec1[i]<<' ';
  }
  cout<<'\n';
}

typedef pair<ll,ll> P;

ll dp[101][4][4][4];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    dp[0][3][3][3]=1;
    rep(i,n){
      rep(j,4){
        rep(k,4){
          rep(l,4){
            if(dp[i][j][k][l]==0) continue;
            rep(a,4){
              if(a==2 && l==1 && k==0) continue;
              if(a==1 && l==2 && k==0) continue;
              if(a==2 && l==0 && k==1) continue;
              if(a==2 && l==1 && j==0) continue;
              if(a==2 && k==1 && j==0) continue;
              dp[i+1][k][l][a]+=dp[i][j][k][l];
              dp[i+1][k][l][a]%=mod;
            }
          }
        }
      }
    }
    ll ans=0;
    rep(j,4){
      rep(k,4){
        rep(l,4){
          ans+=dp[n][j][k][l];
          ans%=mod;
        }
      }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
def MRX():
    N,T = input().split()
    N,T= int(N),int(T)
    travel = {}
    for i in range(N):
        c , t = input().split()
        travel[int(c)] = int(t)
    for j in sorted(travel):
        if travel[j] <= T:
            return j
    return "TLE"



print(MRX())

Measured memory_bytes: 3064
#pragma comment(linker,"/stack:16777216")
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<list>
#include<stack>
#include<queue>
#include<deque>
#include<functional>
#include<utility>
#include<algorithm>
#include<sstream>
#include<cstring>
#include<cmath>
#include<cctype>
#include<exception>
#include<climits>
#include<cfloat>
#include<iomanip>
#include<bitset>
#include<streambuf>
#include<cstdlib>
#include<ctime>
//#include"functions.h"
//#include"highprecision.h"
#define pb push_back
#define pf push_front
#define ppb pop_back
#define mp make_pair
#define np next_permutation
#define fi first
#define sc second
#define vi vector<int>
#define vll vector<long long>
#define vvi vector<vector<int> >
#define vpi vector<pair<int,int> >
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pff pair<float,float>
#define pdd pair<double,double>
#define psi pair<string,int>
#define pis pair<int,string>
#define ppi pair<pii,int>
#define pdi pair<pii,pii>
#define LN 84757
#define INF 1e9
#define LLINF 1e18
#define MAXINT 0x7fffffff
#define MAXLL 0x7fffffffffffffff
#define EPS 1e-5
#define DEPS 1e-9
#define LDEPS 1e-13
#define MOD 1000000007
#define E 2.7182818284
#define PI 3.1415926535
#define rep(a,b) for(int a=0;a<b;a++)
#define rep(a,b) for(int a=0;a<b;a++)
#define forn(a,n) for(int a=1;a<=n;a++)
#define forr(a,n) for(int a=n;a>=1;a--)
#define repn(a,n,p) for(int a=0;a<n;a+=p)
#define repr(a,n) for(int a=n-1;a>=0;a--)
#define foreach(a,b) for(__typeof(b.begin())a=b.begin();a!=b.end();a++)
#define fillemp(a) memset(a,0,sizeof(a))
#define fillinf(a) memset(a,0x3f,sizeof(a))
#define frestream freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define stdf(a,b) freopen(a,"r",stdin);freopen(b,"w",stdout);
#define inputf(a) freopen(a,"r",stdin);
#define outputf(a) freopen(a,"w",stdout);
#define sz(a) a.size()
#define all(a) a.begin(),a.end()
#define mod 1000000007
typedef long long ll;
typedef long double ld;
using namespace std;

int d;
string s;
ll a[10010];
ll dp[10010][110][2];
int main(int argc,char** argv){
	cin>>s>>d;
	rep(i,sz(s)){
		a[i]=(s[i]-'0');
	}
	dp[0][0][1]=1;
	rep(i,sz(s))rep(can,2){
		int to=can?a[i]:9;
		rep(j,d)rep(k,to+1){
			dp[i+1][(j+k)%d][(can&&(k==to))?1:0]+=dp[i][j][can];
			dp[i+1][(j+k)%d][(can&&(k==to))?1:0]%=mod;
		}
	}
	cout<<(dp[sz(s)][0][0]+dp[sz(s)][0][1]-1+mod)%mod<<endl;
	return 0;
}

Measured memory_bytes: 20864
#include <bits/stdc++.h>
using namespace std;
int N, X, Y, Z, ans;
int a[101], b[101], c[101], p[101][3];
int main()
{
	cin >> N >> X;
	for(int i = 0; i < X; i++)
	{
		cin >> a[i];
		p[a[i]][0] = 1;
	}
	cin >> Y;
	for(int i = 0; i < Y; i++)
	{
		cin >> b[i];
		p[b[i]][1] = 1;
	}
	cin >> Z;
	for(int i = 0; i < Z; i++)
	{
		cin >> c[i];
		p[c[i]][2] = 1;
	}
	for(int i = 0; i <= N; i++)
		if(p[i][2] && (!p[i][0] || p[i][1]))
			ans++;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3084
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mk make_pair
#define ft first
#define sc second
#define ppb pop_back
#define sz size
#define forn(i,a,n) for(i=a;i<n;i++)
#define M 1000000007
#define inf 2e18

int main() {


ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
    
      
 ll a,b;
 cin>>a>>b;
 map<ll,ll> m;
 m[a]=1;
 m[b]=1;
 for(ll i=1;i<=3;i++)
    if(m[i]==0){
        cout<<i<<"\n";
        break;
    }
 
return 0;
}

Measured memory_bytes: 256
import sys
from collections import defaultdict
from math import gcd

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

MOD = 10**9 + 7

N = int(readline())
m = map(int, read().split())
A, B = zip(*zip(m, m))

pow2 = [1] * (N + 10)
for n in range(1, N + 10):
    pow2[n] = pow2[n - 1] * 2 % MOD

def to_standard_form(a, b):
    if a == 0:
        return (0, 1)
    g = gcd(a, b)
    a //= g
    b //= g
    if a < 0:
        return (-a, -b)
    return (a, b)

counter0 = defaultdict(int)
counter1 = defaultdict(int)
origin = 0
for a, b in zip(A, B):
    if a == b == 0:
        origin += 1
        continue
    a, b = to_standard_form(a, b)
    if b <= 0:
        counter0[(a, b)] += 1
    else:
        counter1[(b, -a)] += 1
        counter0[(b, -a)] += 0

answer = origin
k = 1
for key, cnt0 in counter0.items():
    cnt1 = counter1[key]
    x = pow2[cnt0] + pow2[cnt1]
    k = k * (x - 1) % MOD

answer += k - 1
answer %= MOD
print(answer)

Measured memory_bytes: 96064
#include<bits/stdc++.h>
#define N 100005
#define M 65540
using namespace std;
int n,s[N],S,ans,f[M],inf,sum[20];

int dfs(int S)
{
  if(!S)return 0; 
  if(f[S]<inf)return f[S];
  for(int i=0;i<16;i++)if((S>>i)&1)
    for(int j=0;j<16;j++)if(i!=j&&(S>>j)&1)
    {
      int p=i^j,x=S^(1<<i)^(1<<j)^(1<<p);
      if(S>>p&1)f[S]=min(f[S],dfs(x)+2);
      else f[S]=min(f[S],dfs(x)+1);
      //枚举每次异或的两个节点i,j,i异或掉j,j异或掉j,还剩下p=i^j
      //如果p本身存在那两个p直接消掉 
    }
  return f[S];
}

int main()
{
  int a,b,c;
  scanf("%d",&n);
  for(int i=1;i<n;i++)
    scanf("%d%d%d",&a,&b,&c),s[a]^=c,s[b]^=c;
  for(int i=0;i<n;i++)sum[s[i]]++;
  for(int i=1;i<16;i++)
    ans+=(sum[i]>>1),S+=(1<<i)*(sum[i]&1);
  memset(f,127,sizeof(f));inf=f[0];
  printf("%d\n",ans+dfs(S));
  return 0;
} 

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

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

using namespace std;
double const PI = acos(-1);

int main(){
    //freopen("i.txt", "s", stdin);
    int a,b,h,m;
    cin >> a >> b >> h >> m;
    int x = h*60+m;
    double mang = (m * 360.0) / 60.0;
    double hang = (x  * 360.0) / (12 * 60.0);
    //cout << PI << endl;
    double ans = a*a + b*b - 2*a*b*cos((mang - hang) * PI / 180.0);
    printf("%.12f", sqrt(ans) );

	return 0;
}


Measured memory_bytes: 4064
import sys

INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())

sys.setrecursionlimit(10 ** 9)


def main():
    N = INT()

    ans = 0
    high = INT()
    for i in range(N-1):
        P = INT()
        if P < high:
            ans += P
        else:
            ans += high
            high = P

    print(ans + high//2)


if __name__ == '__main__':
    main()

Measured memory_bytes: 38384
H, W = map(int, input().split())
S = []
for i in range(H):
    S.append(input())
dx = [-1, 0, 0, 1]
dy = [0, 1, -1, 0]
isOK = True
for i in range(H):
    for j in range(W):
        if(S[i][j] == '#'):
            isOK2 = False
            for k in range(4):
                if(0 <= i + dy[k] < H and 0 <= j + dx[k] < W):
                    if(S[i + dy[k]][j + dx[k]] == '#'):
                        isOK2 = True
            if(isOK2 == False):
                isOK = False
if(isOK):
    print('Yes')
else:
    print('No')

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

int fac(int k);

int main() {
	int N;
	cin >> N;
	if(N==N/2*2){
		cout << N/2 << endl;
	}
	else{
		cout << N/2+1 << endl;
	}
}


int fac(int k){
    int sum=1;
    for (int i = 1; i <= k; i++)
    {
        sum = sum*i;
    }
    return sum;
}

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

int main() {
  int N; cin >> N;
  vector<int> A(N), p, m;
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
    if (A.at(i) >= 0) p.push_back(A.at(i));
    else m.push_back(A.at(i));
  }
  sort(p.begin(), p.end(), greater<int>());
  sort(m.begin(), m.end());
  if (m.empty()) {
    m.push_back(p.back());
    p.pop_back();
  }
  if (p.empty()) {
    p.push_back(m.back());
    m.pop_back();
  }
  vector<pair<int, int>> ope;
  int M = m.at(0);
  for (int i = 0; i+1 < p.size(); i++) {
    ope.push_back(make_pair(M, p.at(i)));
    M -= p.at(i);
  }
  ope.push_back(make_pair(p.back(), M));
  M = p.back() - M;
  for (int i = 1; i < m.size(); i++) {
    ope.push_back(make_pair(M, m.at(i)));
    M -= m.at(i);
  }
  cout << M << endl;
  for (auto p : ope) cout << p.first << " " << p.second << endl;
}

Measured memory_bytes: 3828
#include <iostream>
using namespace std;
int main(void){
    int num;
    cin >> num;
    for (int i = 9; i > 0; i--) {
        if(num % i == 0 && num / i <= 9){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
//### In The Name Of GOD ###

#include <bits/stdc++.h>

using namespace std;

typedef long long ll ;

const int MOD = 1000000007;
const int INF = 30 * 1000 + 20;
const int MAXN = 100 * 1000 + 20;
const int MLOG = 18;
const int NMAX = 60;

#define int ll
#define pb push_back
#define pp pop_back
#define X first
#define Y second
#define IO ios_base::sync_with_stdio(false);
#define sz(a) (int)(a.size())
#define ct(x) const_cast<const int&>(x)


int all[2];
int prf[2][MAXN];
int ap[2][MAXN];

signed main(){
	int n, ans = 0, C;
	cin >> n >> C;
	vector< pair<int,int> > vec[2];	
	vec[0].pb({0, 0});
	vec[1].pb({0, 0});
	for (int i = 0;i < n; i++){
		int x , v;
		cin >> x >> v;
		vec[0].pb({x, v});
		vec[1].pb({C-x,v});
	}
	sort(vec[0].begin(),vec[0].end());
	sort(vec[1].begin(),vec[1].end());
	for(int i = 1; i <= n; i++){
		prf[0][i] = prf[0][i-1] - vec[0][i].X + vec[0][i-1].X + vec[0][i].Y;
		ap[0][i] = max(ap[0][i-1], prf[0][i] - vec[0][i].X);
//		cout << ap[0][i]  << " 1 " << prf[0][i]  - vec[0][i].X << ' '  << endl;
	}
	for(int i = 1; i <= n; i++){
		prf[1][i] = prf[1][i-1] - vec[1][i].X + vec[1][i-1].X + vec[1][i].Y;
		ap[1][i] = max(ap[1][i-1], prf[1][i] - vec[1][i].X);
//	cout << ap[1][i]  << " 2 " << prf[1][i] << ' ' << endl;
}
	for(int i = 1; i <= n; i++){
		all[0] += -vec[0][i].X + vec[0][i-1].X + vec[0][i].Y;
		ans = max(ans, all[0] + ap[1][n-i]);
//		cout << all[0]  << " 3 " << vec[0][i].Y << ' ' << endl;
	}
//	cout << endl;
	for(int i = 1; i <= n; i++){
		all[1] += -vec[1][i].X + vec[1][i-1].X + vec[1][i].Y;
		ans = max(ans, all[1] + ap[0][n-i]);
//		cout << all[1]  << " 4 "  << vec[1][i].Y << ' ' << endl;
	}
	cout << ans;
}

Measured memory_bytes: 6756
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;cin >> N;
  vector<int> A(N);int total = 0;
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
    total += A.at(i);
  }
  double average = (double)total / N;
  double min_diff = 100;
  int answer;
  for (int i = 0; i < N; i++) {
    int x = A.at(i);
    double d = abs(x - average);
    if (d < min_diff) {
      min_diff = d;
      answer = i;
    }
  }
  cout << answer << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <algorithm>

using namespace std;

int main(void)
{

    int N;
    scanf("%d", &N);
    vector<int> A(N);

    for (auto &e : A)
    {
        scanf("%d", &e);
    }

    bool res = all_of(A.begin(), A.end(), [](int x) {
        return x % 2 != 0 || (x % 3 == 0 || x % 5 == 0);
    });

    res ? printf("APPROVED") : printf("DENIED");

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<vector>
#include<cmath>
using namespace std;
struct Point{
	double x,y;
};
int n;
Point a[11111];
Point b[11111];
void conv(double theta)
{
	double C=cos(-theta);
	double S=sin(-theta);
	for(int i=0;i<n;i++)
	{
		b[i].x=a[i].x*C-a[i].y*S;
		b[i].y=a[i].x*S+a[i].y*C;
	}
}
main()
{
	cin>>n;
	for(int i=0;i<n;i++)cin>>a[i].x>>a[i].y;
	double ans=1e150;
	for(int i=0;i<n;i++)
	{
		int I=(i+1)%n;
		double now=hypot(a[I].x-a[i].x,a[I].y-a[i].y);
		double theta=atan2(a[I].y-a[i].y,a[I].x-a[i].x);
		//cout<<theta<<endl;
		conv(theta+5*M_PI/6);
		if(0&&i==0)
		{
			cout<<endl<<"debug"<<endl;
			for(int j=0;j<n;j++)cout<<b[j].x<<" "<<b[j].y<<endl;
			cout<<"debug"<<endl;
		}
		//double mx=1e150;
		//for(int j=0;j<n;j++)mx=min(mx,i==j?1e150:b[j].x-b[i].x);
		double mx=0;
		for(int j=0;j<n;j++)mx=max(mx,b[j].x-b[i].x);
		//cout<<mx<<" ";
		now+=mx/cos(M_PI/6);
		conv(theta+M_PI/6);
		if(0&&i==0)
		{
			cout<<endl<<"debug"<<endl;
			for(int j=0;j<n;j++)cout<<b[j].x<<" "<<b[j].y<<endl;
			cout<<"debug"<<endl;
		}
		mx=0;
		for(int j=0;j<n;j++)mx=max(mx,I==j?0:b[j].x-b[I].x);
		//cout<<mx<<endl;
		now+=mx/cos(M_PI/6);
		ans=min(ans,now);
	}
	cout<<fixed<<setprecision(9)<<ans<<endl;
}



Measured memory_bytes: 4028
#include<iostream>
using namespace std;
int main(){
  int n;
  cin >> n;
  char tc[n];
  int tn[n];
  for(int i=0;i<n;i++) cin >> tc[i] >> tn[i];
  int s[13];
  int h[13];
  int c[13];
  int d[13];  
for(int i=0;i<13;i++){
    s[i] = i+1;
    h[i] = i+1;
    c[i] = i+1;
    d[i] = i+1;
  }
 for(int i=0;i<4;i++){
for(int j=0;j<13;j++){ 
  if(i==0) cin >> s[j];
  if(i==1) cin >> h[j];
  if(i==2) cin >> c[j];
  if(i==3) cin >> d[j];
 }
  }
 for(int i=0;i<n;i++){
   if(tc[i]=='S'){
     for(int j=0;j<13;j++){
       if(tn[i]==s[j]) s[j] = 0;
     }
   }
   else if(tc[i]=='H'){
     for(int j=0;j<13;j++){
       if(tn[i]==h[j]) h[j] = 0;
     }
   }
   else if(tc[i]=='C'){
     for(int j=0;j<13;j++){
       if(tn[i]==c[j]) c[j] = 0;
     }
   }
   else if(tc[i]=='D'){
     for(int j=0;j<13;j++){
       if(tn[i]==d[j]) d[j] = 0;
     }
   }
 }
   for(int i=0;i<13;i++){
     if(s[i]>0) cout << 'S' << ' ' << s[i] << endl;
   }
 for(int i=0;i<13;i++){
   if(h[i]>0) cout << 'H' << ' ' << h[i] << endl;
 }
 for(int i=0;i<13;i++){
   if(c[i]>0) cout << 'C' << ' ' << c[i] << endl;
 }
 for(int i=0;i<13;i++){
   if(d[i]>0) cout << 'D' << ' ' << d[i] << endl;
   }
 return 0;
 }

Measured memory_bytes: 1168
{-# LANGUAGE BangPatterns #-}

import Control.Monad
import Data.List
import Data.Bits
import Debug.Trace
import Data.Maybe
import qualified Data.ByteString.Char8 as C

main :: IO ()
main = do
  [n, m] <- readIntegers
  inputs <- readNIntegers (fromIntegral n)
  print $ solve n m inputs

solve n m inputs = solveSub 0 m sorted
  where
    solveSub money _ [] = money
    solveSub money remain (x:xs) =
      if b > remain
        then money + a * remain
        else solveSub (money + a * b) (remain - b) xs
      where
        a = x !! 0
        b = x !! 1
    sorted = sortOn (!! 0) inputs

-- 以下ライブラリ

readInts :: IO [Int]
readInts = map (fst . fromJust . C.readInt) . C.words <$> C.getLine

readNInts :: Int -> IO [[Int]]
readNInts = flip replicateM readInts

readIntegers :: IO [Integer]
readIntegers = map (fst . fromJust . C.readInteger) . C.words <$> C.getLine

readNIntegers :: Int -> IO [[Integer]]
readNIntegers = flip replicateM readIntegers

getNLns :: Int -> IO [String]
getNLns = flip replicateM getLine

Measured memory_bytes: 75132
#ifdef __LOCAL
  #define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
using namespace std;
template<typename T> bool chmax(T &a,T b) {if(a<b) {a=b; return true;} return false;}
template<typename T> bool chmin(T &a,T b) {if(a>b) {a=b; return true;} return false;}
#define itn int
#define fi first
#define se second
#define intmax numeric_limits<int>::max()
#define llmax numeric_limits<ll>::max()
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(int)(n);i>=1;i--)
#define all(vec) vec.begin(),vec.end()
#define sortt(vec) sort((vec).begin(),(vec).end())
#define rsort(vec) sort((vec).rbegin(), (vec).rend())
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef tuple<ll,ll,ll> tlll;
typedef tuple<int,int,int> tiii;
const ll mod=1e9+7;
const int inf=1<<30;
const ll lnf=1ll<<60;

int main(){
  string s; cin >> s;
  itn n=s.size();
  if(s[n-1]=='s'){
    s.push_back('e');
    s.push_back('s');
  }
  else{
    s.push_back('s');
  }
  cout << s << endl;
}

Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <cmath>
#include <climits>
#include <cstdio>
#include <iomanip>
#include <utility>

using namespace std;
typedef long long int ll;

#define SP(x) setprecision((int)x)
#define ALL(v) v.begin(),v.end()

ll gcd(ll x, ll y)
{
    while (y > 0)
    {
        ll tmp = y;
        y = x % y;
        x = tmp;
    }
    return x;
}

ll lcm(ll x, ll y)
{
    return x / gcd(x, y) * y;
}

vector<ll> c; // 各頂点のカウンタ
vector<vector<ll> > v; // 連結リスト
vector<bool> check;

void dfs(ll num, vector<ll> t)
{
    for (auto e : t)
    {
        if (check[e])
        {
            continue;
        }
        check[e] = true;
        c[e] += num;
        dfs(c[e], v[e]);
    }
}

int main(int argc, char const *argv[])
{
    ll n, q;
    cin >> n >> q;
    c.resize(n, 0);
    v.resize(n);
    check.resize(n, false);
    for (ll i = 0; i < n - 1; i++)
    {
        ll a, b;
        cin >> a >> b;
        a--;
        b--;
        v[a].push_back(b);
        v[b].push_back(a);
    }

    for (ll i = 0; i < q; i++)
    {
        ll p, x;
        cin >> p >> x;
        p--;
        c[p] += x;
    }

    check[0] = true;
    dfs(c[0], v[0]);

    for (ll i = 0; i < n; i++)
    {
        cout << c[i];
        if (i != n - 1)
        {
            cout << " ";
        }
    }
    cout << endl;
}


Measured memory_bytes: 43008
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fill fill_n
#define pf push_front
#define pb push_back
#define FOR(i,l,r) for(int i=l;i<r;i++)
#define ROF(i,r,l) for(int i=r;i>=l;i--)
#define comp(v) (v).begin(),(v).end()
#define ff first
#define ss second
#define infile freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
typedef vector<int> vi;
typedef vector<ll> vli;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvli;
const int M = 1e9+7;
const int N = 2e5;
ll po(int,int);


void solve(){
    int x,n;
    cin>>x>>n;
    int p;
    set<int> s;
    FOR(i,0,n){
        cin>>p;
        s.insert(p);
    }
    int m = 1000000;
    int y;
    ll i=0;
    while(i<200){
        if(s.find(i)==s.end() &&  abs(i-x) < m){
            m = abs(i-x);
            y = i;
        }
        i++;
    }
    cout<<y;
  
    
} 





int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    int t=1;
    //cin>>t;
    while(t--){
        solve();
    }
    
	return 0;
	
	
}


ll po(int a,int b){
    if(b==0) return 1;
    ll ans=1;
    if(b%2==0){
        ans = po(a,b/2)%M;
        ans=(ans%M * ans%M)%M;
    }
    else{
        ans = po(a,(b-1)/2)%M;
        ans = (ans%M * ans%M * a)%M;
    }
    return ans%M;
}


Measured memory_bytes: 3600
nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()

N, M = nl()

like = set([i for i in range(1, M+1)])
for i in range(N):
    As = nl()
    K = As[0]
    As = As[1:]
    like = like & set(As)
print(len(like))


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

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<vpll> vvpll;
typedef vector<double> vd;
typedef vector<vd> vdd;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)
#define RFOR(i,x,y) for(ll i=(ll)x; i>=(ll)y; --i)
#define RREP(i,x) RFOR(i, x, 0)
#define ALL(a) a.begin(), a.end()
#define pb push_back
#define debug_print(x...) cerr << "line " << __LINE__ << " : "; debug_print_in(x);

template <typename First>
void debug_print_in(First first){
  cerr << first << endl;
  return;
}

template <typename First, typename... Rest>
void debug_print_in(First first, Rest... rest){
  cerr << first << " ";
  debug_print_in(rest...);
  return;
}

void IN(void){
  return;
}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
  cin >> first;
  IN(rest...);
  return;
}

template <typename First>
void OUT(First first){
  cout << first << endl;
  return;
}

template <typename First, typename... Rest>
void OUT(First first, Rest... rest){
  cout << first << " ";
  OUT(rest...);
  return;
}

template<class t, class u> t chmax(t&a,u b){if(a<b)a=b; return a;};
template<class t, class u> t chmin(t&a,u b){if(a>b)a=b; return a;};
int popcount(int t){return __builtin_popcount(t);} //GCC
int popcount(ll t){return __builtin_popcountll(t);} //GCC

template <typename T>
void vec_print(vector<T> VEC){
  REP(i, VEC.size()){
    cerr << VEC[i] << " ";
  }
  cerr << endl;
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  REP(i,MAT.size()){
    REP(j,MAT[i].size()){
      cerr << MAT[i][j] << " ";
    }
    cerr << endl;
  }
};

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;
constexpr ll MOD = (ll)((1E+9)+7);

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  ll N;
  IN(N);
  vvll A(3, vll(N));
  REP(j,N) REP(i,3) IN(A[i][j]);

  vec_print(A[0]);
  vec_print(A[1]);
  vec_print(A[2]);

  vvll dp(3, vll(N, INFLL));
  REP(i,3) dp[i][0] = A[i][0];

  REP(j,N-1){
    REP(i,3){
      dp[i][j+1] = max(dp[(i+1)%3][j], dp[(i+2)%3][j])+A[i][j+1];
    }
  }

  OUT(chmax(dp[0][N-1], chmax(dp[1][N-1], dp[2][N-1])));

  return 0;
}


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

using namespace std;

#define SZ(x) (int)(x.size())

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

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

  int a, b, c; cin >> a >> b >> c;
  cout << min(b/a, c) << endl;
}


Measured memory_bytes: 256
import Control.Monad
import qualified Data.ByteString.Char8 as BS
import Data.Maybe

main = do
    k <- readLn :: IO Int
    print $ answer k

answer k
    | even k = -1
    | mod k 5 == 0 = -1
    | mod k 7 == 0 = fst.head $ filter (judge k') $ nines k'
    | otherwise = fst.head $ filter (judge k'') $ nines k''
    where
        k' = 9*div k 7
        k'' = 9*k

judge k (_,nine) = mod nine k == 0

nines k = zip [1..] . scanl1 (\a b -> mod (a*10+b) k) $ repeat 9

Measured memory_bytes: 5136
#include<iostream>
using namespace std;
long long n,a,b,ans;
char c[100100];
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>c[i];
	ans=1;		
	for(int i=1;i<n;i++)
		if(c[i]!=c[i-1])
			ans++;
	cout<<ans<<endl;		
} 

Measured memory_bytes: 384
import java.util.*

fun insertionSort(A: Array<Int>, N: Int) {
    println(A.joinToString(" "))
    for (i in 1 until N) {
        val v = A[i]
        var j = i - 1
        while (j >= 0 && A[j] > v) {
            A[j + 1] = A[j]
            j--
        }
        A[j + 1] = v
        println(A.joinToString(" "))
    }
}

fun main(args: Array<String>) {
    val scanner = Scanner(System.`in`)
    val N = scanner.nextInt()
    val list = mutableListOf<Int>()
    (1..N).forEach {
        list.add(scanner.nextInt())
    }
    insertionSort(list.toTypedArray(), N)
}


Measured memory_bytes: 33520