akhauriyash/Code-Regression huggingface dataset:
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aryssoncf
 */



// Taken from: https://github.com/bqi343/USACO/blob/master/Implementations/content/contest/templateShort.cpp

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<ull> vul;
typedef vector<ll> vl;
typedef vector<pi> vpi;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define F0R(i, a) FOR(i,0,a)
#define ROF(i, a, b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i, a) ROF(i,0,a)
#define trav(a, x) for (auto& a: x)

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rsz resize

#define mp make_pair
#define pb push_back
#define f first
#define s second

const int MOD = 1e9 + 7; // 998244353; // = (119<<23)+1
const int MX = 2e5 + 5;

template<class T>
bool ckmin(T &a, const T &b) {
    return a > b ? a = b, 1 : 0;
}

template<class T>
bool ckmax(T &a, const T &b) {
    return a < b ? a = b, 1 : 0;
}

mt19937 rng((uint32_t) chrono::steady_clock::now().time_since_epoch().count());


//
// Created by aryssoncf on 28/10/2019.
//

#include <type_traits>


#include <iterator>
#include <utility>

template<typename T>
constexpr auto hasBegin(int) -> decltype(std::begin(std::declval<T>()), true) {
    return true;
}

constexpr bool hasBegin(...) {
    return false;
}

template<typename T>
using IsContainer = std::integral_constant<bool, hasBegin<T>(0)>;


#ifndef JHELPER_EXAMPLE_PROJECT_IO_HPP
#define JHELPER_EXAMPLE_PROJECT_IO_HPP

#endif //JHELPER_EXAMPLE_PROJECT_IO_HPP

template<typename T>
std::istream &operator>>(std::istream &is, std::vector<T> &vec) {
    for (T &element: vec) {
        is >> element;
    }
    return is;
}

template<typename T, typename U>
std::istream &operator>>(std::istream &is, std::pair<T, U> &p) {
    is >> p.first;
    is >> p.second;
    return is;
}

template<class X, class Y>
std::ostream &operator<<(std::ostream &os, std::pair<X, Y> const &p) {
    return os << p.first << " " << p.second;
}

template<class Ch, class Tr, class Container>
std::basic_ostream<Ch, Tr> &operator<<(std::basic_ostream<Ch, Tr> &os, Container const &x) {
    bool first = true;
    for (auto &y : x) {
        if (first) {
            first = false;
        } else {
            os << " ";
        }
        os << y;
    }
    return os;
}

using namespace std;

/*
PROG:
LANG: C++
*/

class AACOrWA {
public:
    void solve(std::istream &in, std::ostream &out) {
        int n, m;
        in >> n >> m;
        bool res = n == m;
        out << (res ? "Yes" : "No") << "\n";
    }

    void setup() {}
};


int main() {
    std::ios_base::sync_with_stdio(false);
    AACOrWA solver;
    solver.setup();
    std::istream &in(std::cin);
    std::ostream &out(std::cout);
    in.tie(nullptr);
    out << std::fixed;
    out.precision(20);
    solver.solve(in, out);
    return 0;
}


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

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    sort(a.begin(),a.end());
    reverse(a.begin(),a.end());
    int alice = 0, bob = 0;
    for(int i = 0; i < n; i++){
        if(i%2==0){alice += a[i];}
        else{bob += a[i];}
    }
    cout << alice - bob << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int D = sc.nextInt();
        int G = sc.nextInt()/ 100;
        int[] P = new int[D];
        int[] C = new int[D];
        for (int i = 0; i < D;i++) {
            P[i] = sc.nextInt();
            C[i] = sc.nextInt() / 100;
        }
        int res = Integer.MAX_VALUE;
        int score;
        int num;
        for (int i = 0; i < (1<<D); i++) {
            score = 0;
            num = 0;
            int[] used = new int[D];
            for (int j = 0; j < D; j++) {
                if ((i & (1 << j)) != 0) {
                    score += P[j] * (j + 1) + C[j];
                    num += P[j];
                    used[j] = 1;
                }
            }
            for (int j = D - 1; j >= 0; j--) {
                if (score >= G) break;
                if (used[j] == 0) {
                    for (int k = 0; k < P[j] - 1; k++) {
                        score += j + 1;
                        num++;
                        if (score >= G) break;
                    }
                }
            }
            if (score >= G) res = Math.min(res, num);
        }
        System.out.println(res);
    }
}


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

int main() {
	int n;
	cin >> n;
	vector<pair<int, int>>red;
	vector<pair<int, int>>blue;
	for (int i = 0;i < n;i++) {
		int a, b;
		cin >> a >> b;
		pair<int, int>p = make_pair(a, b);
		red.push_back(p);
	}
	sort(red.begin(), red.end());
	for (int i = 0;i < n;i++) {
		int a, b;
		cin >> a >> b;
		pair<int, int>p = make_pair(a, b);
		blue.push_back(p);
	}
	sort(blue.begin(), blue.end());
	int ans = 0;
	for (int i = 0;i < n;i++) {
		int num = -1;
		for (int j = 0;red[j].first < blue[i].first&&j < red.size();++j) {
			if (num == -1 && red[j].second < blue[i].second)num = j;
			else if (i != -1 && red[num].second < red[j].second&&red[j].second < blue[i].second)num = j;
		}
		if (red[num].first < blue[i].first&&red[num].second < blue[i].second) {
			ans++;
			red.erase(red.begin() + num);
		}
	}
	cout << ans << endl;
}

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

using namespace std;

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define cd complex<double>

complex<double> ci = complex<double>(0.0,1.0);
complex<double> mci = complex<double>(0.0,-1.0);

int main(){

  while(1){
    int n;
    cin >> n;
    if (n==0)break;
    vector<complex<double> > p(n);
    rep(i,n){
      double real,imag;
      cin >> real >> imag;
      p[i] = complex<double>(real,imag);
    }
    int summax = 1;
    rep(i,n){
      rep(j,n){
        if (i==j)continue;
        if (abs(p[i]-p[j])>2)continue;
        complex<double> mid = (p[i]+p[j])/2.0;
        double l = abs(p[i]-mid);
        double h = sqrt(1-l*l);
        complex<double> c1 = mid + (mid-p[i])*ci*h/l;
        complex<double> c2 = mid + (mid-p[i])*mci*h/l;

        int sum1 = 2,sum2 = 2;
        rep(k,n){
          if(k==i||k==j)continue;
          if(abs(p[k]-c1)<1.0)sum1++;
          if(abs(p[k]-c2)<1.0)sum2++;
        }
        if (max(sum1,sum2)>summax)summax=max(sum1,sum2);
      }
    }
    cout << summax << endl;
  }

  return 0;
}



Measured memory_bytes: 3176
#include<stdio.h>
#include<string.h>

int main(void){

	int n;
	long long int k;
	int a[200000];
	int b[200000] = {};
	int i;
	int f = 1;
	int num;
	int next;
	int count;
	int l;
	int now;

	scanf("%d %lld",&n,&k);
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
		a[i]--;
		b[i] = -1;
	}

	next = 0;
	b[next] = 0;
	count = 0;

	if(k<200000){
		for(i=0;i<k;i++){
			next = a[next];
		}

		printf("%d\n",next+1);

	}else{
		while(f==1){
			next = a[next];
			count++;
			if(b[next] == -1){
				b[next] = count;
			}else{
				l = count-b[next];
				f = 0;
			}
			k--;
		}


		for(i=0;i<k%l;i++){
			next = a[next];
		}

		printf("%d\n",next+1);
	}

	return 0;
}

Measured memory_bytes: 3296
#include<stdio.h>
int main(void){
	int n,y;
	scanf("%d %d",&n,&y);
	int i,j;
	for(i=0;i<=n;i++)
		for(j=0;j<=n-i;j++)
			if(10000*i+5000*j+1000*(n-i-j)==y){
			printf("%d %d %d\n",i,j,n-i-j);
			return 0;
		}
	printf("-1 -1 -1\n");
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=5e4+5,mod=1e9+7;
ll hs[N],f[N],invf[N];
int n;
char s[N];
int get_hs(int l,int r)
{
    return (hs[r]-hs[l-1]+mod)%mod*invf[l-1]%mod;
}
map<int,int>vis;
bool judge(int m)
{
    if(m==0) return true;
    vis.clear();
    for(int i=n-m+1;i>=1;i--)
        vis[get_hs(i,i+m-1)]++;
    int pos=1;
    for(int i=1;i<=n-m+1;i++)
    {
        while(pos<=i+m-1&&pos<=n-m+1)
            vis[get_hs(pos,pos+m-1)]--,pos++;
        if(pos>n-m+1) return false;
        if(vis[get_hs(i,i+m-1)]) return true;
    }
    return false;
}
ll qpow(ll a,ll n)
{
    ll ans=1;
    while(n)
    {
        if(n&1) ans=ans*a%mod;
        a=a*a%mod;
        n>>=1;
    }
    return ans;
}
int main()
{
    f[0]=invf[0]=1;
    for(int i=1;i<N;i++)
        f[i]=f[i-1]*13331%mod,invf[i]=qpow(f[i],mod-2);
    scanf("%d%s",&n,s+1);
    for(int i=1;i<=n;i++)
        hs[i]=(hs[i-1]+(s[i]-'a')*f[i])%mod;
    int l=0,r=n,ans;
    while(l<=r)
    {
        int m=l+r>>1;
        if(judge(m)) ans=m,l=m+1;
        else r=m-1;
    }
    printf("%d\n",ans);
}


Measured memory_bytes: 1280
a, b, k = gets.split.map(&:to_i)
ab = b - a
if k * 2 > ab
    ab.times do |i|
        puts a + i
    end
    puts b
else
    k.times do |i|
        puts a + i
    end
    k.times do |i|
        puts b - k + i + 1
    end
end

Measured memory_bytes: 1788
N,Y = list(map(int,input().split()))

ans = 0
for i in range(N+1):
    for j in range(N+1):
            if 10000*i + 5000*j + 1000*(N-(i+j)) == Y and ((N-(i + j)) >=0):
                print(i,j,N-(i+j))
                ans +=1
                break
    else:
        continue
    break

if ans == 0:
    print('-1','-1','-1')

Measured memory_bytes: 3064
# でつoO(YOU PLAY WITH THE CARDS YOU'RE DEALT..)
import sys
def main(D, C, S):
    def evaluate(i, t, satisfaction, last):
        satisfaction += S[i][t]
        last[t] = i
        for j, c in enumerate(C):
            satisfaction -= c * (i - last[j])
        return (satisfaction, last)

    ans = []
    satisfaction = 0
    last = [-1] * 26
    for i in range(D):
        tt = -1
        ts = -10**10
        tl = None
        ps = satisfaction
        pl = last[:]
        for t in range(26):
            s, l = evaluate(i, t, ps, pl[:])
            if ts < s:
                tt = t
                ts = s
                tl = l
        ans.append(tt + 1)
        satisfaction = ts
        last = tl
    return ans

if __name__ == '__main__':
    input = sys.stdin.readline
    D = int(input())
    *C, = map(int, input().split())
    S = [list(map(int, input().split())) for _ in range(D)]
    ans = main(D, C, S)
    for a in ans:
        print(a)


Measured memory_bytes: 9428
using System;
using System.Collections.Generic;
using System.Linq;
using static Input;
public class Hello
{
    public static void Main()
    {
        string S = NextString();
        int A = int.Parse(S.Substring(0, 2));
        int B = int.Parse(S.Substring(2));
        if (1 <= A && 1 <= B && A <= 12 && B <= 12) Console.WriteLine("AMBIGUOUS");
        else if (1 <= A && A <= 12) Console.WriteLine("MMYY");
        else if (1 <= B && B <= 12) Console.WriteLine("YYMM");
        else Console.WriteLine("NA");
        //Console.WriteLine(A + " " + B);
    }
}

public class Input
{
    private static Queue<string> queue = new Queue<string>();
    private static void Confirm() { if (queue.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) queue.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(queue.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(queue.Dequeue()); }
    public static string NextString() { Confirm(); return queue.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(queue.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
}


Measured memory_bytes: 11220
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
using namespace std;
int m, a, b;
int ans;
int main(){
	scanf("%d %d %d", &m, &a, &b);
	if(b > a + m) ans = b - (a + m);
	else if(a > b + m) ans = a - (b + m);
	else ans = 0;
	printf("%d\n", ans);
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ri register
#define int long long
#define E (n+1)
using namespace std; const int N=200010;
inline int read()
{
    int s=0, w=1; ri char ch=getchar();
    while(ch<'0'||ch>'9') { if(ch=='-') w=-1; ch=getchar(); }
    while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch^48), ch=getchar();
    return s*w;
}
int n,A;
signed main()
{
    n=read(), A=read();
    n%=500;
    if(A>=n) puts("Yes");
    else puts("No");
    return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define rep(i, m, n) for(int i = m; i < (n); i++)
#define print(x) cout << (x) << endl;
#define printa(x,n) for(int i = 0; i < n; i++){ cout << (x[i]) << " ";} cout << endl;
#define printa2(x,m,n) for(int i = 0; i < m; i++){ for(int j = 0; j < n; j++){ cout << x[i][j] << " ";} cout << endl;}
#define printp(x,n) for(int i = 0; i < n; i++){ cout << "(" << x[i].first << ", " << x[i].second << ") "; } cout << endl;
#define INF (1e18)
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
typedef struct{
    int x;
    int y;
} P;
typedef struct{
    ll to;
    ll cost;
} edge;
typedef pair<ll, ll> lpair;
ll val_a[200010] = {}, val_b[200010] = {}, val_c[200010] = {}, val_d[200010] = {};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    ll A[200010];
    cin >> N;
    rep(i,0,N){
        cin >> A[i];
    }
    ll ans = INF;
    ll sum[200010] = {};
    rep(i,0,N){
        sum[i+1] = sum[i] + A[i];
    }
    ll fi = 0;
    rep(i,1,N-2){
        while(fi+1 < i){
            ll lv = sum[fi+1];
            ll rv = sum[i+1] - sum[fi+1];
            ll lv_next = sum[fi+2];
            ll rv_next = sum[i+1] - sum[fi+2];
            if(abs(lv-rv) <= abs(lv_next - rv_next)) break;
            fi++;
        }
        val_a[i] = sum[fi+1];
        val_b[i] = sum[i+1] - sum[fi+1];
    }
    fi = N-2;
    for(int i = N-3; i >= 1; i--){
        while(fi - 1 > i){
            ll lv = sum[fi+1] - sum[i+1];
            ll rv = sum[N] - sum[fi+1];
            ll lv_next = sum[fi] - sum[i+1];
            ll rv_next = sum[N] - sum[fi];

            if(abs(lv -rv) <= abs(lv_next - rv_next)) break;
            fi--;
        }
        val_c[i] = sum[fi+1] - sum[i+1];
        val_d[i] = sum[N] - sum[fi+1];
    }
    rep(i,1,N-2){
        ll max_val = max(max(val_a[i],val_b[i]), max(val_c[i],val_d[i]));
        ll min_val = min(min(val_a[i],val_b[i]), min(val_c[i],val_d[i]));
        ans = min(ans, max_val-min_val);

    }
    print(ans);


}


Measured memory_bytes: 9600
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define FOR(i,l,r) for(i=l;i<r;i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define P pair<ll,ll>
#define F first
#define S second
#define VEC vector
#define V VEC<ll>
signed main(){
 int N,M,i,A;cin>>N>>M;
 REP(i,M){cin>>A;N-=A;}
 cout<<max(-1,N)<<endl;
 return 0;
}

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

int main() {
	int coin_500_total ,coin_100_total, coin_50_total, price, ans;

	cin >> coin_500_total >> coin_100_total >> coin_50_total >> price;
	ans = 0;

	for(int coin_500=0; coin_500 <= coin_500_total; coin_500++){
		for(int coin_100=0; coin_100 <= coin_100_total; coin_100++){
			for(int coin_50=0; coin_50 <= coin_50_total; coin_50++){
				if(coin_500 *500 + coin_100 *100 + coin_50 * 50 == price)
					ans+=1;
			}
		}
 	 }


 	 cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <algorithm>
#include <queue>
#include <iterator>
#include <functional>
#include <numeric>
#include <cmath>
#include <stack>
#include <limits>
#include <ctime>

using namespace std;

#define ll long long
#define sc(n) static_cast<ll>(n)
#define IO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

int main() {
	IO;
#ifdef _DEBUG
	ifstream cin("In.txt");
#endif	
	string st;
	cin >> st;
	cout << ((st[2]==st[3] && st[4]==st[5]) ? "Yes":"No") << endl;
	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/python3

from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def main():
    s = sorted(input())
    t = sorted(input(), reverse=True)
    if s < t:
        print(Yes)
    else:
        print(No)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3960
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#ifndef FAST_IO
 #define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);
#endif

#define int long long
#define FILE_IO freopen("input.txt","r",stdin)/#define int long long
#define f first
#define s second
#define endl '\n'
#define all(c) c.begin(),c.end()
#define bp __builtin_popcount
#define debug(x) cerr << #x << " = " << x << endl;

const int MOD = 1e9 + 7;
const int INF = 1e18;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename T>void print(T t){for (auto &it : t) cout << it << " ";}
inline int powerexp(int a, int b, int m = MOD){ int res = 1;while(b){if(b&1)res = res * a % m;a = a * a % m,b >>= 1;}return res % m;}
inline int modinv(int a){ return powerexp(a,MOD-2,MOD);}
inline int lcm(int a, int b){ int g = __gcd(a,b);return a/g*b;}
inline int add(int x, int y){ x += y; if (x >= MOD) x -=  MOD; return x;}
inline int mul(int x, int y){ return (x * 1ll * y) % MOD;}
inline int sub(int x, int y){ x -= y; if (x<0) x += MOD; return x ;}

//-------------------< start here >-------------------------// 

void solve(){
  int n;
  cin >> n;
  vector<int> v;
  
  for (int i = 0; i < n; i++){
	  int x;
	  cin >> x;
	  v.push_back(x);  
	}
   int lo = *min_element(all(v));
   int hi = *max_element(all(v));
   cout << hi - lo << endl;
}

//-----------------------------
//comment from here for TOPCODER 
int32_t main(){
   IOS;
   solve();
   //find();
   #ifdef LOCAL_DEFINE
   cerr << "time elapsed " << (double)clock()/CLOCKS_PER_SEC << endl;
   #endif
}


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

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

flist = factorization(N)

ans = 0
for f in flist:
    if f[0] == 1:
        continue
    num = f[1]
    for i in range(1, num+1):
        if i <= num:
            num -= i
            ans += 1
        else:
            break

print(ans)

Measured memory_bytes: 9452
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

int main() {

	string s;
	cin >> s;

	map<char, int>m;

	rep(i, s.size())
		m[s[i]]++;
	
	bool flag = true;
	for (auto i = m.begin(); i != m.end(); i++) {
		if (i->second % 2 == 1) {
			flag = false;
			break;
		}
	}

	flag ? cout << "Yes" : cout << "No";
	cout << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,bg,ed) for(ll i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007
#define int long long
using namespace std;
typedef long long ll;
const int INF = 1e9;



signed main()
{
    int A, B, C;
    cin >> A >> B >> C;

    if (A == B && B == C) {
        if (A % 2 == 1) {
            cout << 0 << endl;
        } else {
            cout << -1 << endl;
        }
        return 0;
    }

    int ans = 0;
    while (true) {
        if (A % 2 == 1 || B % 2 == 1 || C % 2 == 1) break;
        int nA = 0, nB = 0, nC = 0;
        nA = B / 2 + C / 2;
        nB = A / 2 + C / 2;
        nC = A / 2 + B / 2;
        A = nA; B = nB; C = nC;
        ans++;
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
while buf=gets
        c=0
        n=buf.to_i
        10.times{|i|
                break if i > n
                10.times{|j|
                        break if i+j > n
                        10.times{|k|
                                break if i+j+k > n
                                10.times{|l|
                                        if i+j+k+l == n
                                                c+=1
                                        end
                                        break if i+j+k+l > n
                                }
                        }
                }
        }
        puts c
end

Measured memory_bytes: 8760
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    int i=1;
    while(++i<=n){
        int x=i;
        if(x%3==0){
          cout << " " << i;
          continue;
        }
        while(x){
          if(x%10==3){
    	cout << " " << i;
    	break;
          }
          x/=10;
        }
    }
    cout << endl;
}


Measured memory_bytes: 3088
from operator import itemgetter
N = int(input())
A = []
B = []
for i in range(N):
    u, v = map(int, input().split())
    A.append((u, v))
for i in range(N):
    u, v = map(int, input().split())
    B.append((u, v))
A.sort()
B.sort()
num = 0
for i in range(N):
    K = [A[k] for k in range(len(A)) if (A[k][0] <B[i][0]) and (A[k][1] < B[i][1])]
    if K:
        num += 1
        t = sorted(K, key=itemgetter(1))[-1]
        A.remove(t)
print(num)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define go(i, a, n) for (ll i = a; i < n; i++)
#define gor(i, a, n) for (int i = n - 1; i >= a; i--)
#define show(x) cout << x << '\n'
#define ll long long
#define ull unsigned long long
#define ld long double
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define vpair vector<pair<ll, ll>>
#define vtuple vector<tuple<ll, ll, ll>>
#define ff first
#define ss second
#define mod 1000000007
#define memset(a, k) memset(a, k, sizeof(a))
#define answer(z, k) cout << "Case #" << z << ": " << k << endl;
auto t1 = chrono::high_resolution_clock::now();
bool prime[1000001];
ll expo(ll a, ll b)
{
	if (b == 0)
		return 1;
	if (b % 2)
		return ((a % mod) * (expo((a * a) % mod, b / 2) % mod)) % mod;
	return expo((a * a) % mod, b >> 1) % mod;
}
ll mul(ll a, ll b)
{
	a = a % mod;
	b = b % mod;
	if (b == 0)
		return 0;
	if (b % 2)
		return ((a % mod) + (mul((a + a) % mod, b >> 1) % mod)) % mod;
	return mul((a + a) % mod, b >> 1) % mod;
}

bool ispoweroftwo(ll x)
{
	return x && !(x & (x - 1));
}
ll xorcal(ll n)
{
	if (n % 4 == 0)
		return n;
	if (n % 4 == 1)
		return 1;
	if (n % 4 == 2)
		return n + 1;
	if (n % 4 == 3)
		return 0;
}
void sieve(ll n)
{
	memset(prime, true);
	prime[0] = false;
	prime[1] = false;
	for (ll i = 2; i * i <= n; i++)
	{
		if (prime[i] == true)
		{
			for (ll j = i * i; j <= n; j += i)
				prime[j] = false;
		}
	}
}
bool isprime(ll n)
{
	if (n <= 1)
		return false;
	if (n <= 3)
		return true;

	if (n % 2 == 0 or n % 3 == 0)
		return false;

	for (ll i = 5; i * i <= n; i += 6)
	{
		if (n % i == 0 or n % (i + 2) == 0)
			return false;
	}
	return true;
}

ll modinverse(ll a, ll m)
{
	ll m0 = m;
	ll y = 0, x = 1;

	if (m == 1)
		return 0;

	while (a > 1)
	{
		ll q = a / m;
		ll t = m;

		m = a % m;
		a = t;
		t = y;

		y = x - q * y;
		x = t;
	}

	if (x < 0)
		x += m0;

	return x;
}

ll gcd(ll a, ll b)
{
	if (a == 0)
		return b;
	return (b % a, a);
}
bool ispalindrome(string s)
{
	string t = s;
	reverse(t.begin(), t.end());
	if (t == s)
		return true;
	return false;
}
void binary(ll a[], ll n)
{
	gor(i, 0, 64)
	{
		ll k = n >> i;
		a[i] = k & (ll)1;
	}
}
ll countBits(ll n)
{
	if (n == 0)
		return 0;
	return 1 + countBits(n & (n - 1));
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll w, s;
	cin >> w >> s;
	if (w <= s)
		show("unsafe");
	else
		show("safe");
	auto t2 = chrono::high_resolution_clock::now();
	auto duration = chrono::duration_cast<chrono::milliseconds>(t2 - t1).count();
	clog << "Time taken = " << duration * 1.0 / 1000 << " seconds" << endl;
	return 0;
}


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ITR(x,c) for(__typeof(c.begin() x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin() x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

#define lf double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	string a, b;
	cin >> a;
	cin >> b;
	if (a[0]==b[2] && a[2]==b[0] && a[1]==b[1]){
		cout << "YES\n";
	}else{
		cout << "NO\n";
	}
	return 0;
}

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

const int MAX = 1000000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

template <class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
const long long INF = 1LL << 60;

int main() {
    ll H, W, N;
    cin >> H >> W >> N;
    vector<ll> a(N);
    rep(i, N) { cin >> a[i]; }
    ll num = 1;
    ll cnt = a[0];
    bool toRight = true;
    vector<vector<ll>> ans(H, vector<ll>(W));
    rep(i, H) {
        if (toRight) {
            for (ll j = 0; j < W; j++) {
                ans[i][j] = num;
                cnt--;
                if (cnt == 0) {
                    num++;
                    if (num <= N) {
                        cnt = a[num - 1];
                    }
                }
            }
            toRight = false;
        } else {
            for (ll j = W - 1; j >= 0; j--) {
                ans[i][j] = num;
                cnt--;
                if (cnt == 0) {
                    num++;
                    if (num <= N) {
                        cnt = a[num - 1];
                    }
                }
            }
            toRight = true;
        }
    }
    rep(i, H) {
        rep(j, W) { cout << ans[i][j] << " "; }
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 512
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
ll mod_pow(ll a, ll n) {
	if (n == 0) return 1;
	if (n % 2 == 0) {
		ll tmp = mod_pow(a, n / 2);
		return (tmp * tmp) % MOD;
	}
	return (a * mod_pow(a, n - 1)) % MOD;
}

vector<ll> fact;
vector<ll> inv_fact;

void comb_init(int n) {
	fact.resize(n + 1);
	inv_fact.resize(n + 1);
	fact[0] = inv_fact[0] = 1;
	for (int i = 1; i <= n; i++) {
		fact[i] = (fact[i - 1] * i) % MOD;
		inv_fact[i] = (inv_fact[i - 1] * mod_pow(i, MOD - 2)) % MOD;
	}
}
ll dp1[17][1 << 16];
ll dp3[17][1 << 16];
int A[17];
int main() {
	int N, M;
	cin >> N >> M;
	comb_init(1 << N);
	A[0] = 1;
	for (int i = 1; i <= M; i++) cin >> A[i];
	dp1[0][0] = 1;
	for (int i = 1; i <= M; i++) {
		for (int j = 0; j < N; j++) for (int b = 0; b < (1 << N); b++) if (b&(1 << j)) (dp1[i - 1][b] += dp1[i - 1][b ^ (1 << j)]) %= MOD;
		for (int U = 0; U < (1 << N); U++) {
			int t = U - (A[i - 1] - 1);
			int d = A[i] - 1 - A[i - 1];
			if (t >= d) {
				dp3[i][U] = (fact[t] * inv_fact[t - d]) % MOD;
				(dp3[i][U] *= dp1[i - 1][U]) %= MOD;
			}
		}
		for (int j = 0; j < N; j++) for (int b = 0; b < (1 << N); b++) if (b&(1 << j)) (dp3[i][b] += MOD - dp3[i][b ^ (1 << j)]) %= MOD;
		for (int U = 0; U < (1 << N); U++) if (U >= A[i] - 2) dp1[i][U] = dp3[i][U] * (U - (A[i] - 2)) % MOD;
	}
	ll ret = 0;
	for (int U = 0; U < (1 << N); U++) (ret += dp1[M][U]) %= MOD;
	(ret *= fact[(1 << N) - A[M]]) %= MOD;
	(ret *= 1 << N) %= MOD;
	cout << ret << endl;
}

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

namespace ConsoleApp2
{
    using static System.Console;
    using static System.Math;

    class Program
    {
        static void Main(string[] args)
        {
            var a = ReadLine().Split().Select(long.Parse).ToArray();
            R = a[0];
            D = a[1];
            X = a[2];
            Solve();
        }

        static long R, D, X;

        static void Solve()
        {
            var x = X;
            for (int i = 0; i < 10; i++)
            {
                x = R * x - D;
                WriteLine(x);
            }
        }
    }
}


Measured memory_bytes: 11348
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
  int64_t n;
  cin >> n;
  if(n==1){
    cout << 0;
    return 0;
  }
  vector<int> v(100000);
  ll p=0,q=0;
  ll i;
  bool is;
  ll cp=n;
  for(i=2;i*i<=n;i++){
    is=false;
    while(cp%i==0){
      v.at(p)++;
      cp/=i;
      is=true;
    }
    if(is){
      p++;
    }
  }
  ll ans=0;
  for(i=0;i<100000;i++){
    q=1;
    while(v.at(i)-q>=0){
      ans++;
      v.at(i)-=q;
      q++;
    }
  }
  if(ans==0){
    cout << 1;
    return 0;
  }
  if(cp!=1){
    ans++;
  }
  cout << ans;
}
   

Measured memory_bytes: 3764
/**
 *    author:  otera    
**/
#include<iostream>
#include<string> 
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm> 
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

//#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

void solve() {
	int n, a; cin >> n >> a;
    if(n % 500 <= a) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}

Measured memory_bytes: 3564
#include<stdio.h>
int main(void)
{
	int c1,c5,c10,c50,c100,c500,x,y;
	scanf("%d %d %d %d",&c1,&c5,&c10,&c50);
	scanf("%d %d",&c100,&c500);
	x=c1*1+c5*5+c10*10+c50*50+c100*100+c500*500;
	if(x>=1000){
		printf("1\n");
	}
	else{
		printf("0\n");
	}
	return 0;
}


Measured memory_bytes: 2100
// template version 1.15
using namespace std;
#include <bits/stdc++.h>

// varibable settings
#define int long long
const int INF=1e18;

// define basic macro {{{
#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__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)((b)-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(i,a) for (auto&& i : a)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define mt(a, b, c) make_tuple(a, b, c)
#define ub upper_bound
#define lb lower_bound
#define posl(A, x) (lower_bound(all(A), x)-A.begin())
#define posu(A, x) (upper_bound(all(A),x)-A.begin())
template<class T> inline void chmax(T &a, const T &b) { if((a) < (b)) (a) = (b); }
template<class T> inline void chmin(T &a, const T &b) { if((a) > (b)) (a) = (b); }

#define divceil(a,b) ((a)+(b)-1)/(b)
#define is_in(x, a, b) ((a)<=(x) && (x)<(b))
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define slice(l, r) substr(l, r-l)

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;

template<typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

#if defined(PCM) || defined(LOCAL)
  #include "lib/dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
  #define cerrendl 42
#endif
//}}}

signed main() {
  string s;cin>>s;
  reverse(all(s));
  int n = sz(s);

  vvi dp(2, vi(n+1,INF));
  dp[0][0] = 0;

  rep(i, 1, n+1){
    int v = s[i-1] - '0';
    rep(num, 0, 10){
      if (num>=v){
        chmin(dp[0][i], dp[0][i-1]+num+num-v);
      }
      else{
        chmin(dp[1][i], dp[0][i-1]+num+(10+num-v));
      }

      if ((num-1)>=v){
        chmin(dp[0][i], dp[1][i-1]+num+(num-1)-v);
      }
      else{
        chmin(dp[1][i], dp[1][i-1]+num+(10+(num-1)-v));
      }
    }
  }
  dump_2d(dp, 2, n+1);

  int ans = INF;
  ans = min(dp[0][n], dp[1][n]+1);
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 24860
import java.util.*;

class Main {
	Scanner sc;
	
	private void calc() {
		sc = new Scanner(System.in);
		String S = sc.next();
		String T = sc.next();
		System.out.println(T+S);
	}

	public static void main(String[] args) {
		new Main().calc();
	}
}

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

//solution:
#define int int64_t

struct line {
    int m, c; //slope-intercept form
    line() {};
    line(int m, int c): m(m), c(c) {}
    auto intersect(line l) { //returns the intersection point as a fraction
        array<int, 2> x = {l.c - c, m - l.m};
        return x;
    }
    auto f(int x) { //evaluates the line at a given point
        return m * x + c;
    }
};

struct cht { //semi-offline
    deque<line> hull;
    cht() {};
    cht(line l) { 
        hull.push_back(l);
    };
    void insert(line l) {
        while(hull.size() >= 2 and remove(end(hull)[-2], end(hull)[-1], l)) {
            hull.pop_back();
        }
        hull.push_back(l);
    }
    bool remove(line prev, line now, line next) {
        auto x = prev.intersect(next), y = prev.intersect(now);
        return (__int128)x[0] * y[1] <= (__int128)y[0] * x[1];
    }
    auto query(int x) { //ternary-search the required line
        line result(0, 0);
        int  lo = 0, hi = hull.size() - 1;
        while(lo <= hi) {
            int mid1 = lo + (hi - lo) / 3;
            int mid2 = hi - (hi - lo) / 3;
            int y1 = hull[mid1].f(x), y2 = hull[mid2].f(x);
            if(y1 <= y2) result = hull[mid1], hi = mid2 - 1;
            else result = hull[mid2], lo = mid1 + 1;
        }
        return result;
    }
};

void hike() {
    int n, c; cin >> n >> c;
    vector<int> h(n);
    for(int& i: h) cin >> i;
    int dp[n] = {};
    cht env(line(-2 * h[0], h[0] * h[0]));
    for(int i = 1; i < n; ++i) {
        line l = env.query(h[i]);
        dp[i] = l.f(h[i]) + h[i] * h[i] + c;
        env.insert(line(-2 * h[i], h[i] * h[i] + dp[i]));
    }
    cout << dp[n - 1] << "\n";
}

signed main() {
    int t = 1; //cin >> t;
    while(t--) hike();
    return 0;
} //farewell, until we meet again..

Measured memory_bytes: 9460
/*
 * src.cpp
 *
 *  Created on: 2016/08/25
 *      Author: joi
 */

#include <bits/stdc++.h>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)

typedef long long ll;

const int MAX_N=1e5,MAX_SQRTS=3e3;
const ll MAX_S=1e10;

int N;
ll S[MAX_N];

bool pflg[MAX_SQRTS+1];
vector<ll> prime;

void sieve(){
	memset(pflg,true,sizeof(pflg));
	pflg[0]=pflg[1]=false;
	for (int i=2;i<=MAX_SQRTS;i++){
		if (!pflg[i]) continue;
		prime.push_back(i);
		for (int j=i*2;j<=MAX_SQRTS;j+=i){
			pflg[j]=false;
		}
	}
}

map<ll,int> mp;

int main(){
	scanf("%d",&N);
	REP(i,N){
		scanf("%lld",&S[i]);
	}
	sieve();
	REP(i,N){
		for(int j=0;j<prime.size();j++){
			ll p=prime[j];
			while(S[i]%(p*p*p)==0){
				S[i]/=p*p*p;
			}
		}
		mp[S[i]]++;
	}
	int ans=0;
	for(map<ll,int>::iterator ite=mp.begin();ite!=mp.end();ite++){
		if (ite->first==1){
			continue;
		}
		ll pa=ite->first*ite->first;
		for(int i=0;i<prime.size();i++){
			ll p=prime[i];
			while (pa%(p*p*p)==0){
				pa/=p*p*p;
			}
		}
		ans+=max<ll>(ite->second,mp[pa]);
		ite->second=0;
		mp[pa]=0;
	}
	if (mp[1]>0){
		ans++;
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 19456
#include<bits/stdc++.h>
#define endl '\n'
#define int long long
#define eps 1e-9
#define oo 1e7+5

using namespace std;

typedef unsigned long long ull;
typedef vector<pair<int,pair<int,int>>> dirgraph;
typedef vector<vector<int>> graph;

int32_t main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	
	map<int,bool> mp;
	int x,n;
	cin>>x>>n;
	for(int i=0;i<n;i++){
		int aux;
		cin>>aux;
		mp[aux]=1;
	}

	int ans=0;
	for(int i=0;;i++){
		if(!mp[x-i])
		{
			ans=x-i;
			break;
		}
		else if(!mp[x+i])
		{
			ans=x+i;
			break;
		}
	}

	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 3660
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 5;
const long long mod = 1e9 + 7;

int n;
int H, W;
int arr[MAXN];
int mat[105][105];
void solve(){
    int i = 0, j = 0;
    int c = 1;
    int cnt = 0;
    for(i = 0; i < H; i++){
        if(i % 2 == 0){
            for(j = 0; j < W; j++){
                mat[i][j] = c;
                cnt++;
                if(arr[c - 1] == cnt){
                    cnt = 0;
                    c++;
                }
            }
        }
        else{
            for(j = W - 1; j >= 0; j--){
                mat[i][j] = c;
                cnt++;
                if(arr[c - 1] == cnt){
                    cnt = 0;
                    c++;
                }
            }
        }
    }
    for(i = 0; i < H; i++){
        for(j = 0; j < W; j++)
            cout << mat[i][j] << " ";
        cout << "\n";
    }
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> H >> W >> n;
    int i = 0;
    for(i = 0; i < n; i++)
        cin >> arr[i];
    solve();
    return 0;
}


Measured memory_bytes: 384
void main(){
	int a, b;
	readf("%d %d", &a, &b);
	if(a<=5){
		writeln(0);
	}else if(6<=a && a<=12){
		writeln(b/2);
	}else{
		writeln(b);
	}
}

import std.stdio, std.conv, std.algorithm, std.numeric, std.string, std.math;

// 1要素のみの入力
T _scan(T= int)(){
	return to!(T)( readln().chomp() );
}

// 1行に同一型の複数入力
T[] _scanln(T = int)(){
	T[] ln;
	foreach(string elm; readln().chomp().split()){
		ln ~= elm.to!T();
	}
	return ln;
}


Measured memory_bytes: 2796
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

#############
# Main Code #
#############

N, M = getNM()
query = [getList() for i in range(N)]

w = []
v = []
w_rev = []
v_rev = []
for i in range(N):
    w.append(query[i][0])
    v.append(query[i][1])
    w_rev.append(query[N - i - 1][0])
    v_rev.append(query[N - i - 1][1])

def knapsack_1(N, limit, weight, value):
    dp = [[0] * (limit + 1) for i in range(N + 1)]
    dp[0][0] = 0

    for i in range(N):
        for j in range(limit + 1):
            if weight[i] <= j:
                dp[i + 1][j] = max(dp[i][j], dp[i][j - weight[i]] + value[i])
            else:
                dp[i + 1][j] = dp[i][j]
    return dp

dp_1 = knapsack_1(N, M, w, v)
dp_2 = knapsack_1(N, M, w_rev, v_rev)

# 全ての料理について
ans = 0
for i in range(1, N + 1):
    opt = 0
    for j in range(M):
        if i == 1:
            o = query[i - 1][1] + dp_2[N - i][M - j - 1]
        elif i == N:
            o = dp_1[i - 1][j] + query[i - 1][1]
        else:
            # dp_1[i - 1][j] A[i]以前のものをj分以内に食べるナップサック
            # dp_2[N - i][M - j - 1] A[i]以降のものをM - j - 1分以内に食べるナップサック
            # dpにアクセスするだけなのでO(1)でいける
            o = dp_1[i - 1][j] + query[i - 1][1] + dp_2[N - i][M - j - 1]
        opt = max(opt, o)
    ans = max(ans, opt)
print(ans)

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

int main()
{
	int Q;
	string S;
	cin >> S >> Q;
	cin.ignore( numeric_limits<streamsize>::max(), '\n' );

	int rev = 0;
	string b;
	for( int i = 0; i < Q; i++ ) {
		string s;
		getline( cin, s );
		if( s[0] == '1' ) {
			rev  = 1 - rev;
		}
		else {
			int cmd;
			int f;
			char c;
			sscanf( s.c_str(), "%d %d %c", &cmd, &f, &c );
			if( f == 1 ) {
				if( rev == 0 ) b += c;
				else S += c;
			}
			else {
				if( rev ) b += c;
				else S += c;
			}
		}
	}

	if( rev ) {
		reverse( S.begin(), S.end() );
		cout << S << b << endl;
	}
	else {
		reverse( b.begin(), b.end() );
		cout << b << S << endl;
	}
}


Measured memory_bytes: 1216
function Main(input) {
	input = input.split("\n");
	input[0] = input[0].split(" ");
	input[1] = input[1].split(" ");
	var ans = input[1];
	if(input[2]==input[0][0]) ans[0]--;
	else ans[1]--;
	console.log(ans.join(" ")); 
}Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());

Measured memory_bytes: 21064
N=int(input())
A=[int(input()) for i in range(N)]
S=sorted(A)
from bisect import bisect_left
p=[0]*N
for i,a in enumerate(A):
    p[bisect_left(S,a)]=i
print(sum([(p[i]-i)%2 for i in range(N)])//2)

Measured memory_bytes: 12976
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <memory.h>
#include <cassert>

using namespace std;


#define all(c) ((c).begin()), ((c).end())
#define debug(c) cerr << "> " << #c << " = " << (c) << endl;
#define iter(c) __typeof((c).begin())
#define present(c, e) ((c).find((e)) != (c).end())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define tr(i, c) for (iter(c) i = (c).begin(); i != (c).end(); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, a, b) for (int i = (int)(a); i <= (int)(b); i++)

#define mp make_pair
#define fst first
#define snd second
#define pb push_back


const double EPS = 1e-10;


typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef complex<double> P;

ll dsum(ll a, ll d, ll n) {
	return n * (2 * a + (n - 1) * d) / 2;
}

ll gcd(ll a, ll b) {
	return b == 0 ? a : gcd(b, a % b);
}

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}

int main() {
	for(int n, m; cin >> n >> m, (n | m) != 0; ) {
		ll a = dsum(1, 1, n);
		ll b = n;
		int p[20];
		bool haveone = false;
		rep(i, m) {
			cin >> p[i];
			if (p[i] == 1) haveone = true;
//			a -= dsum(p[i], p[i], n / p[i]);
//			b -= n / p[i];
		}
		
		for(int mask = 1; mask < (1 << m); mask++) {
			int l = 1;
			int cnt = 0;
			rep(i, m) if (mask & (1 << i)) {
				l = lcm(l, p[i]);
				cnt++;
			}
			if (cnt % 2 == 0) {
				a += dsum(l, l, n / l);
				b += n / l;
			}
			else {
				a -= dsum(l, l, n / l);
				b -= n / l;
			}
		}
		
		if (haveone) printf("%.6f\n", 0);
		else printf("%.6f\n", (double)a / b);
	}
	
	return 0;
}

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

template<typename T_char>
T_char ToUpper(T_char cX){return toupper(cX);}

int main(){
  int n, m, X, Y;
  cin >> n >> m >> X >> Y;

  vector<int> x(n), y(m);
  for(int i=0; i<n; ++i) cin >> x[i];
  for(int i=0; i<m; ++i) cin >> y[i];

  sort(x.rbegin(), x.rend());
  sort(y.begin(), y.end());

  int diff = y[0] - x[0];
  int num = x[0];
  bool flag = false;
  for(int i=0; i<diff; ++i){
   num++;
   if(X < num && num < Y) flag = true;
   else{
     flag = false;
     break;
   }
  }
  if(flag) cout << "No War" << endl;
  else cout << "War" << endl;

}


Measured memory_bytes: 3580
def resolve():
    from collections import defaultdict
    N = int(input())
    A = [int(i) for i in input().split()]
    d = defaultdict(int)
    for a in A:
        d[a] += 1
    maxA = 0
    d = dict(d)
    for key in d.keys():
        sumA = d.get(key)
        if key - 1 in d:
            sumA += d.get(key - 1)
        if key + 1 in d:
            sumA += d.get(key + 1)
        maxA = max(maxA, sumA)
    print(maxA)

resolve()


Measured memory_bytes: 21020
#include <stdio.h>
#include <string.h>
#define BUF 200     // ??????????????????

int main(void) {
    char str[BUF], tmp[BUF];
    int h, i, j, m, len;

    while(1) {
        scanf("%s", str);
        if (str[0] == '-') break;
        len = strlen(str);
        scanf("%d", &m);
        for (i = 0; i < m; i++) {
            scanf("%d", &h);
            strncpy(tmp, str, h);
            tmp[h] = '\0';
            for (j = 0; j < len - h; j++) str[j] = str[h + j];
            str[len - h] = '\0';
            strcat(str, tmp);
        }
        printf("%s\n", str);
    }

    return 0;
}

Measured memory_bytes: 604