akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math,inline")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,lzcnt,mmx,abm,avx,avx2")

#include <algorithm>
#include <array>
#include <cassert>
#include <iostream>
#include <vector>
using namespace std;

template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename T, size_t size> ostream& operator<<(ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }

void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }

#ifdef NEAL_DEBUG
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif


const int BITS = 18;

int N, K, S, T;
int64_t ALL;
vector<int> A;
array<array<int64_t, 2>, BITS> fail;
vector<vector<int64_t>> choose;
vector<int64_t> up_to_K;
int64_t answer;

void recurse(int index, int sign, int64_t mask) {
    if (mask == 0)
        return;

    if (index == BITS) {
        answer += sign * up_to_K[__builtin_popcountll(mask)];
        return;
    }

    recurse(index + 1, sign, mask);
    recurse(index + 1, -sign, mask & fail[index][0]);
    recurse(index + 1, -sign, mask & fail[index][1]);
}

int main() {
    cin >> N >> K >> S >> T;

    if ((S | T) != T) {
        cout << 0 << '\n';
        return 0;
    }

    for (int i = 0; i < N; i++) {
        int a;
        cin >> a;

        if ((a & S) != S || (a | T) != T)
            continue;

        A.push_back(a);
    }

    N = int(A.size());
    K = min(K, N);

    choose.assign(N + 1, vector<int64_t>(N + 1, 0));

    for (int i = 1; i <= N; i++) {
        choose[i][0] = choose[i][i] = 1;

        for (int j = 1; j < i; j++)
            choose[i][j] = choose[i - 1][j] + choose[i - 1][j - 1];
    }

    up_to_K.assign(N + 1, 0);

    for (int i = 1; i <= N; i++)
        for (int j = 1; j <= K; j++)
            up_to_K[i] += choose[i][j];

    ALL = (1LL << N) - 1;

    for (int bit = 0; bit < BITS; bit++) {
        if ((S >> bit & 1) == 0) {
            fail[bit][0] = 0;

            for (int i = 0; i < N; i++)
                if (A[i] >> bit & 1)
                    fail[bit][0] |= 1LL << i;
        } else {
            fail[bit][0] = 0;
        }

        if ((T >> bit & 1) == 1) {
            fail[bit][1] = 0;

            for (int i = 0; i < N; i++)
                if ((A[i] >> bit & 1) == 0)
                    fail[bit][1] |= 1LL << i;
        } else {
            fail[bit][1] = 0;
        }
    }

    dbg(fail);

    answer = 0;
    recurse(0, 1, ALL);
    cout << answer << '\n';
}


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

#define rep(n) for(int i=0;i<n;i++)
#define repp(j, n) for(int j=0;j<n;j++)
#define reppp(i, m, n) for(int i=m;i<n;i++)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define debug(x) cerr << #x << ": " << x << endl

using namespace std;

typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pii;
struct edge{int from, to; ll cost;};

const ll MOD = 1000000007;

int main(){
    int n;
    cin >> n;
    ll a[n], x[20][n+1], total[n+1];
    repp(j, 20) x[j][0] = 0LL;
    total[0] = 0LL;
    rep(n){
        cin >> a[i];
        repp(j, 20){
            x[j][i+1] = x[j][i] + ((a[i] >> j) & 1);
        }
        total[i+1] = total[i] + a[i];
    }

    ll ans = 0;
    reppp(i, 1, n+1){
        int ok = i, ng = n+1, mid;
        repp(k, 30){
            mid = (ok+ng) >> 1;
            bool is_ok = true;
            repp(j, 20){
                if( ( (x[j][mid]-x[j][i-1]) >> 1 ) != ( (x[j][i]-x[j][i-1]) >> 1 )){
                    is_ok = false;
                    break;
                }
            }
            if(is_ok){
                ok = mid;
            }else{
                ng = mid;
            }
        }
        ans += ll(ok - i + 1); 
    }
    cout << ans << endl;
}

Measured memory_bytes: 34560
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n;
int m[101],d[101],s[101],v[101];
int out[1000][101];

int main(void){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d%d%d%d",&m[i],&d[i],&v[i],&s[i]);
		int id=(m[i]-1)*30+d[i]-1;
		for(int j=id;j<id+v[i];j++){
			out[j][i]+=s[i];
		}
		if(id+v[i]>=360){
			for(int j=0;j<id+v[i]-360;j++){
				out[j][i]=max(s[i],out[j][i]);
			}
		}
		int now=(id-1+360)%360;
		int cnt=s[i]-1;
		while(cnt>0){
			out[now][i]=max(out[now][i],cnt);
			cnt--;
			now=(now-1+360)%360;
		}
		now=(id+v[i]+360)%360;
		cnt=s[i]-1;
		while(cnt>0){
			out[now][i]=max(out[now][i],cnt);
			cnt--;
			now=(now+1+360)%360;
		}
	}
	int res=11451419;
	for(int i=0;i<360;i++){
		int now=0;
		for(int j=0;j<n;j++){
			now=max(out[i][j],now);
		}
		res=min(now,res);
	}
	printf("%d\n",res);
	return 0;
}

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

using namespace std;

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

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

int main() {

	int a, b, k; cin >> a >> b >> k;

	vector<int> div;

	for (int i = 1; i < 101; i++) {
		if ((a%i == 0) && (b%i == 0)) {
			div.push_back(i);
		}
	}

	sort(div.rbegin(), div.rend());


	cout << div[k - 1] << endl;

	return 0;
}

Measured memory_bytes: 256
x,y,z,k=(int(i) for i in input().split())
#print(x,y,z,k)
a=list(int(i) for i in input().split())
a.sort(reverse=True)
b=list(int(i) for i in input().split())
b.sort(reverse=True)
c=list(int(i) for i in input().split())
c.sort(reverse=True)
#print(a,b,c)

#k=3000
#a=[int(i) for i in range(1000)]
#b=[int(i) for i in range(1000)]
#c=[int(i) for i in range(1000)]
x=[]
for h in range(len(a)):
    for i in range(len(b)):
        if (h+1)*(i+1) <=k:
            for j in range(len(c)):
                if (h+1)*(i+1)*(j+1) <=k:
                    x.append(a[h]+b[i]+c[j])

x.sort(reverse=True)
for i in range(k):
  print(x[i])
  


Measured memory_bytes: 51420
/*input
6
4 6 0 0 3 3
0 5 6 5 0 3

5
1 2 3 4 5
1 2 3 4 5
*/
#include <bits/stdc++.h>
using namespace std;

#define ll long long int

const ll N = 200005;
ll a[N], b[N], aa[N], bb[N];
ll n;

ll low_binary(ll pos, ll value){
	ll lo = 0, hi = n - 1, mid, res = -1;
	while(lo <= hi){
		mid = (lo + hi) >> 1;
		if(aa[pos] + bb[mid] >= value){
			res = mid;
			hi = mid - 1;
		}
		else{
			lo = mid + 1;
		
		}
	}
	return res;
}

ll high_binary(ll pos, ll value){
	ll lo = 0, hi = n - 1, mid, res = -1;
	while(lo <= hi){
		mid = (lo + hi) >> 1;
		if(aa[pos] + bb[mid] >= value){
			hi = mid - 1;
		}
		else{
			res = mid;
			lo = mid + 1;
		}
	}
	return res;
}

int main(){
	ll i, bit;
	ll ans = 0;
	cin >> n;
	for(i = 0; i < n; ++i)cin >> a[i];
	for(i = 0; i < n; ++i)cin >> b[i];
	for(bit = 0; bit < 40; ++bit){
		ll T = (1LL << bit);
		for(i = 0; i < n; ++i){
			aa[i] = a[i] % (2*T);
			bb[i] = b[i] % (2*T);
		}

		sort(bb, bb + n);

		// for(i = 0; i < n; ++i)cout << aa[i] << " ";
		// cout << endl;
		// for(i = 0; i < n; ++i)cout << bb[i] << " ";
		// cout << endl;

		ll ct = 0, lower_bound, upper_bound;

		for(i = 0; i < n; ++i){
			lower_bound = low_binary(i, T);
			upper_bound = high_binary(i, 2*T);
			if(lower_bound != -1)
				ct = ct + (upper_bound - lower_bound + 1);
			lower_bound = low_binary(i, 3*T);
			upper_bound = high_binary(i, 4*T);
			if(lower_bound != -1)
				ct = ct + (upper_bound - lower_bound + 1);	
		}


		if(ct & 1)
			ans = ans + T;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 6528
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            int count = 0;
            var S = Console.ReadLine();
            var T = Console.ReadLine();
            //Console.WriteLine(S.Length);

            int len = S.Length;

            for (var i = 0; i < len; i++ )
            {
                //Console.WriteLine(i);
                if (S.Substring(i, 1) == T.Substring(i, 1))
                {
                }
                else
                {
                    count++;
                }
            }

            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 36960
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) x.begin(),x.end()
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
typedef long long ll;

using namespace std;

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

int main() {
  int h,w;
  cin >> h >> w;
  
  rep(i,h)
  cin >> bord[i];

  rep(i,h){
     rep(j,w){
        if(bord[i][j]=='#'){
           int a=1;
           rep(k,4){
           int x = i+dx[k];
           int y = j+dy[k];
           if(x>=0 && x<h && y>=0 && y<w && bord[x][y]=='#')
           a=0;
           }
           if(a){
           cout << "No" << endl; return 0;
           }
        }
     }
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int ll
//{ PXH612
using namespace std;
#define ll long long
#define pp pair<int,int>
#define x first
#define y second

#define in ({ll x=0;int o=0,c=char();for(;!isdigit(c);c=getchar()) o=c=='-';for(;isdigit(c);c=getchar()) x=x*10+c-'0';o?-x:x;})
#define inchar ({char c=getchar();while(c==' '||c=='\n') c=getchar();c;})

auto min(auto a,auto b){return a<b?a:b;}
auto max(auto a,auto b){return a>b?a:b;}
bool Min(auto &a,auto b) {if(a>b) {a=b;return true;}return false;}
bool Max(auto &a,auto b) {if(a<b) {a=b;return true;}return false;}

#define FOR(i,a,b) for(int i=a,_=b;i<=_;i++)
#define ROF(i,a,b) for(int i=b,_=a;_<=i;i--)
#define RR(x,a,b) {cout<<#x<<": ";FOR(__,a,b) cout<<x[__]<<" ";cout<<"\n";}
#define rr(x) " "<<#x<<'='<<x<<" "

#define bit(x,i) ((x>>(i-1))&1ll)
#define on(x,i) (x|(1ll<<(i-1)))
#define off(x,i) (x&~(1ll<<(i-1)))
#define bitnum(x) __builtin_popcountll(x)
#define mu(x) (1ll<<x)

#define VEC(i,a) for(auto&i:a)
#define pb push_back
#define vn(a) (int)a.size()-1

#define false(x) if(!(x))
#define midd(a,b) (a+(b-(a))/2)
#define open(x) freopen(x,"r",stdin)
#define shut(x) freopen(x,"w",stdout)
//}//////////////////////////////////////////

const int N=1e5+5;
int n;
int a[N],cnt[N];
int d[N],ans[N];

priority_queue<int,vector<int>,greater<int>> h;
priority_queue<pp> hc;

void CHOOSE(int i,int x)
{
    ans[i]=x;
    cnt[a[x]]--;
    d[x]=1;
}
main()
{
   // open("arrange.inp");
    n=in;int TK=min(n,10);
    FOR(i,1,n) a[i]=in;
    FOR(i,1,n) cnt[a[i]]++;

    FOR(i,1,n) h.push(i);
    FOR(i,1,n) hc.push({cnt[i],i});
    FOR(id,1,n-TK)
    {
        while(hc.size())
        {
            int x=hc.top().y;
            if(hc.top().x != cnt[x])
            {
                hc.pop();
                hc.push({cnt[x],x});
            }
            else if(d[x]==1) hc.pop();
            else break;

        }
        while(h.size()&&d[h.top()]==1) h.pop();

        if(hc.size()&&hc.top().x==n-id) CHOOSE(id,hc.top().y);
        else
        {
            int x=h.top();h.pop();
            int y=h.top();h.pop();
            if(a[ans[id-1]]==x) CHOOSE(id,y),h.push(x);
            else CHOOSE(id,x),h.push(y);
        }
    }
    vector<int> v;
    FOR(i,1,n) if(d[i]==0) v.pb(i);
    sort(v.begin(),v.end());

    FOR(i,1,n-TK) cout<<ans[i]<<" ";
    do
    {
        int ok=1;
        if(a[ans[n-TK]]==v.front()) ok=0;
        FOR(i,1,vn(v)) if(a[v[i-1]]==v[i]) ok=0;
        if(ok==0) continue;
        //FOR(i,1,vn(v)) cout<<rr(v[i-1]) rr(a[v[i-1]]) rr(v[i]) "\n";

        VEC(i,v) cout<<i<<" ";exit(0);
    }
    while(next_permutation(v.begin(),v.end()));
    cout<<-1;
}


Measured memory_bytes: 6384
#include<cstdio>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;

int n,m;
int t[110];
int sum;

int main()
{
	scanf("%d",&n);
	for(int i=0; i<n; i++)
	{
		scanf("%d",&t[i]);
		sum+=t[i];
	}
	scanf("%d",&m);
	for(int i=0; i<m; i++)
	{
		int p,x;
		scanf("%d%d",&p,&x);
		printf("%d\n",sum-(t[p-1]-x));
	}
	return 0;
}

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

typedef long long int ll;
ll mod = 1000000000 + 7;

const int nmax = 1000;
const int mmax = 10;

// All possible arrays where
// 1. Length = i
// 2. last element is j
ll arr[mmax][nmax] = {0};

int main(){
    int n; cin >> n;
    while(n > 0){
        if(n%10 == 7){
            cout << "Yes" << endl;
            return 0;
        }
        n /= 10;
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3596
#include <iostream>
#include <stdio.h>
#include <math.h>
using namespace std;

int main(void){
    int X;
    cin >> X;

    double A,B;

    int A_i,B_i,count;
    A_i=121;
    count=0;
    for (A_i = -118; A_i < 120; A_i++)
    {
        for (B_i = -119; B_i < 119; B_i++){
            if(X==pow(A_i,5)-pow(B_i,5)){
                cout << A_i <<" " << B_i << endl;
                count++;
                break;
            }
            if(count) break;
        }
    }

    return 0;
}

Measured memory_bytes: 4064
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.Collectors;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = Integer.parseInt(scanner.nextLine());

        int[] a = scanIntArray(scanner);

        int length = a.length;
        int swapCount = 0;
        for (int i = 0; i < length ; i++) {
            int minIndex = i;
            for (int j = i; j < length ; j++) {
                if (a[j] < a[minIndex]) {
                    minIndex = j;
                }
            }

            if (a[i] > a[minIndex]) {
                swap(a, i, minIndex);
                swapCount++;
            }
        }

        printIntArray(a, " ");
        System.out.println(swapCount);
    }

    private static void printIntArray(int[] array, String delimeter) {
        System.out.println(Arrays.stream(array)
                .mapToObj(String::valueOf)
                .collect(Collectors.joining(delimeter)));
    }

    private static int[] scanIntArray(Scanner scanner) {
        return Arrays.stream(scanner.nextLine().split(" ", 0))
                .mapToInt(Integer::parseInt)
                .toArray();
    }

    private static void swap(int[] array, int index1, int index2) {
        int tmp = array[index1];
        array[index1] = array[index2];
        array[index2] = tmp;
    }
}



Measured memory_bytes: 32684
# -*- coding: utf-8 -*-
#ABC109C
import sys

def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

tmp = input().split()
hoge = list(map(lambda a: int(a), tmp))
n=hoge[0]
x=hoge[1]

tmp = input().split()
hoge = list(map(lambda a: int(a), tmp))

res = abs(x-hoge[0])
for i in range(1,n):
	res=gcd(res, abs(hoge[i]-hoge[i-1]))
print(res)

Measured memory_bytes: 14480
#include <stdio.h>

int
main(void)
{
  int count, i, input, max = -1000000, min = 1000000;
  long sum = 0;
  scanf("%d", &count);
  for (i = 0; i < count; i++) {
    scanf("%d", &input);
    sum += input;
    if (max < input) {
      max = input;
    }
    if (min > input) {
      min = input;
    }
  }
  printf("%d %d %ld\n", min, max, sum);
  return 0;
}

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

 using namespace std;

 int main() {
   int A, B, C, i;
   string ans;

   cin >> A >> B >> C;

   ans = "NO";
   for (i = 1; i < B; i ++) {
     if (i * A % B == C) {
       ans = "YES";
       break;
     }
   }
   cout << ans << endl;

 }


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

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

    int cnt[1010] = {};

    for (int i=1; i<=n; i++) {
        int t = i;
        for (int j=2; j<=n; j++) {
            while (t%j == 0) {
                cnt[j]++;
                t /= j;
            }
        }
    }

    long long ans = 1;
    for (int i=0; i<1010; i++) {
        if (cnt[i]) {
            ans *= cnt[i] + 1;
            ans %= 1000000007LL;
        }
    }

    cout << ans << endl;

    return 0;
}


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

int p[300001];

void init(int n){
	for(int i = 0 ; i <= 300000 ; i++)
		p[i] = 1;
	p[0] = p[1] = 0;
	
	for(int i = 2 ; i*i <= n ; i++)
		if(p[i] == 1)
			for(int j = i*i ; j <= n ; j += i)
				p[j] = 0;
}
int main(){
	init(300000);
	for(int i = 1 ; i <= 300000 ; i++)
		p[i] += p[i-1];
	int n;
	while(cin >> n , n){
		int ans = 0;
		cout << p[2*n] - p[n] << endl;
	}
}

Measured memory_bytes: 0
#include<iostream>
#include<string>
#include <vector>
#include <algorithm>
#include<cstdlib>
#include <queue>
#include <cmath>
#include <iomanip>
#include<list>
#include <utility>
#define T long long


int main(){
	T x;
	std::cin >> x;
	T m=100;
	for(int i=1;1;i++){
		m += m/100;
		if(m>=x){
			std::cout << i <<std::endl;
			return 0;
		}
	}
}


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

int main(){
    int N,cnt = 0,ans = 0;
    cin >> N;
    for (int i = 1; i <= N; i++){
        for (int j = 1; j <= N; j++){
            if (i %j == 0 && (i/j) %2 ==1){
                cnt++;//iの約数の数
                if (cnt >= 8)ans++;
           }
        }
        cnt = 0;
    }    
    cout << ans << endl;

return 0;
}

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

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

int main(){
  int N,M;
  cin>>N>>M;
  int k[M],p[M],ans=0;;
  vector<vector<int>> S(M);
  rep(i,M){
    cin>>k[i];
    rep(j,k[i]){
      int a;
      cin>>a;
      S[i].push_back(a);
	}}
  rep(i,M)
    cin>>p[i];
  for(int bit =0;bit<(1<<N);bit++){
    vector<bool> A;
    bool Q=true;
    for(int i=0;i<N;i++){
      if(bit&(1<<i)){
	A.push_back(true);
      }else
	A.push_back(false);
    }
    // rep(f,A.size())
    //	cout<<A[f];
    // cout<<endl;
    for(int j=0;j<M;j++){
      int count=0;
     
      for(int o=0;o<k[j];o++){
	if(A[S[j][o]-1])
	  count++;
      }
      if(count%2!=p[j])
	Q=false;
    }
    if(Q)
      ans++;
  }
  
  cout<<ans<<endl;
  
  return 0;
}
  


Measured memory_bytes: 256
n,m,c=map(int,input().split())
b=list(map(int,input().split()))
ans=0
for i in range(n):
    a=list(map(int,input().split()))
    sum=0
    for i in range(m):
        sum+=b[i]*a[i]
    sum+=c
    if sum>0:
        ans+=1
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define int long long
using namespace std;
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; }

class ConvexFullTrick
{
 private:
    vector<pair<int,int>> lines;
 public:
    ConvexFullTrick(){}
    void add(int a,int b){
        // 傾きは単調減少
        pair<int,int> line(a,b);
        while(lines.size()>=2){
            pair<int,int> l1=lines[lines.size()-2];
            pair<int,int> l2=lines[lines.size()-1];
            if(check(l1,l2,line)) break;
            lines.pop_back();
        }
        lines.push_back(line);
    }
    int get(int x){
        int ng=-1,ok=lines.size()-1;
        while(ok-ng>1){
            int mid=(ng+ok)/2;
            if(f(mid,x)<f(mid+1,x)) ok=mid;
            else ng=mid;
        }
        return f(ok,x);
    }
    bool check(pair<int,int> l1,pair<int,int> l2,pair<int,int> l3){
        // (l1とl2の交点)<(l2とl3の交点)=>true
        int x=(l2.first-l3.first)*(l2.second-l1.second);
        int y=(l1.first-l2.first)*(l3.second-l2.second);
        return x<y;
    }
    int f(int i,int x){
        return lines[i].first*x+lines[i].second;
    }
};

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

    int N,C; cin>>N>>C;
    vector<int> h(N);
    for(int i=0;i<N;i++) cin>>h[i];

    vector<int> dp(N);
    dp[0]=0;
    ConvexFullTrick cht;
    cht.add(-2*h[0],dp[0]+h[0]*h[0]);
    for(int i=1;i<N;i++){
        dp[i]=cht.get(h[i])+h[i]*h[i]+C;
        cht.add(-2*h[i],dp[i]+h[i]*h[i]);
    }
    cout<<dp[N-1]<<endl;
    return 0;
}

Measured memory_bytes: 9584
#include<iostream>

int main()
{
	int N, x = 0, y = 0,t;
	int xCurrent = 0, yCurrent = 0;
 
	std::cin >> N;
	int movements;
	bool pass = true,ultimatum = false;
	int lastTime = 0, preLastTime = 0; 
 
	for( int i = 0; i < N; i ++ )
	{
		std::cin >> t >> x >> y;
		
		preLastTime = t;

		if( x + y > xCurrent + yCurrent)
			movements = x + y - (xCurrent + yCurrent);
		else
			movements = xCurrent + yCurrent - (x + y); 
 		
		t = t - lastTime;

		lastTime = preLastTime;
 		

		pass = false;
 
		xCurrent = x;yCurrent = y;
 
		if( movements <= t )
		{
			if( t % 2 == 0 && movements % 2 == 0 )
			{
				pass = true;
			}
			
 
 
			if( t % 2 == 1 && movements % 2 == 1 )
			{
				pass = true;
			}
 
		
		}
		if( pass )
		{
			
		}
		else
		{
			ultimatum = true;
		
		}
 
 
	}
	if( ultimatum )
	{
		std::cout << "No";
	}
	else
	{
		std::cout << "Yes";
	} 
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#define N 20000
using namespace std;

int n, p, a[N + 5];
int main()
{
	int i;
	cin >> n;
	for (i = 1; i <= n; i++) {
		scanf("%d", &p);
		a[p] = i - n;
	}
	for (i = 1; i <= n; i++) printf("%d ", a[i] + i * N);
	puts("");
	for (i = 0; i < n; i++) printf("%d ", (n - i) * N);
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto& (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define sar(a,n) cout<<#a<<":";rep(pachico,n)cout<<" "<<a[pachico];cout<<endl
#define svec(v) cout<<#v<<":";rep(pachico,v.size())cout<<" "<<v[pachico];cout<<endl
#define svecp(v) cout<<#v<<":";each(pachico,v)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl
#define sset(s) cout<<#s<<":";each(pachico,s)cout<<" "<<pachico;cout<<endl
#define smap(m) cout<<#m<<":";each(pachico,m)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 100005;

class BinaryTrie {
public:
	struct Node {
		Node *next[2];
		bool ed;
		Node() : ed(false) { next[0] = next[1] = nullptr; }
	};
	Node* root;
	BinaryTrie(){
		root = new Node();
	}
	//Trie木にxを加える
	void add(string& s) {
		Node *curr = root;
        for(int i = 0; i < len(s); i++){
			int y = (s[i] - '0');
			if (!curr->next[y]) {
				curr->next[y] = new Node();
			}
			curr = curr->next[y];
        }
		curr->ed = true;
	}
    //何らかのクエリ
	ll query(Node *curr, const ll L){
		if(curr->ed){
			return 0;
		}else{
			ll res = 0;
			if(curr->next[0]){
				res ^= query(curr->next[0], L-1);
			}else{
				res ^= (L & (-L));
			}
			if(curr->next[1]){
				res ^= query(curr->next[1], L-1);
			}else{
				res ^= (L & (-L));
			}
			return res;
		}
	}
    ll query(const ll L){
        return query(root,L);
    }
};

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
	ll L;
    cin >> n >> L;
	BinaryTrie bt;
	rep(i,n){
		string s;
		cin >> s;
		bt.add(s);
	}
	if(bt.query(L)){
		cout << "Alice\n";
	}else{
		cout << "Bob\n";
	}
    return 0;
}


Measured memory_bytes: 5996
/* -- Basic Headers -- */
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cctype>
#include <algorithm>

/* -- STL Iterators -- */
#include <vector>
#include <string>
#include <stack>
#include <queue>

/* -- External Headers -- */

/* -- Defined Functions -- */
#define For(a,x,y) for (int a = x; a <= y; ++a)
#define Forw(a,x,y) for (int a = x; a < y; ++a)
#define Bak(a,y,x) for (int a = y; a >= x; --a)

/* -- Defined Words -- */

using namespace std;

namespace FastIO {
    void DEBUG(char comment[], int x) {
        cerr << comment << x << endl;
    }

    inline int getint() {
        int s = 0, x = 1;
        char ch = getchar();
        while (!isdigit(ch)) {
            if (ch == '-') x = -1;
            ch = getchar();
        }
        while (isdigit(ch)) {
            s = s * 10 + ch - '0';
            ch = getchar();
        }
        return s * x;
    }
    inline void __basic_putint(int x) {
        if (x < 0) {
            x = -x;
            putchar('-');
        }
        if (x >= 10) __basic_putint(x / 10);
        putchar(x % 10 + '0');
    }

    inline void putint(int x, char external) {
        __basic_putint(x);
        putchar(external);
    }
}

namespace Solution {

}

int main() {
    #define HANDWER_FILE
    #ifndef HANDWER_FILE
    freopen("testdata.in", "r", stdin);
    freopen("testdata.out", "w", stdout);
    #endif
    using namespace Solution;
    using namespace FastIO;
    int n = getint();
    int m = getint();
    for (int i = m / n; i >= 1; --i) {
        if (m % i == 0) {
            putint(i, '\n');
            return 0;
        }
    }
    return 0;
}




Measured memory_bytes: 256
#!python3

iim = lambda: map(int, input().rstrip().split())

def resolve():
    X = int(input())

    a, b = divmod(X, 500)
    ans = a * 1000
    a, b = divmod(b, 5)
    ans += a * 5
    print(ans)

if __name__ == "__main__":
    resolve()


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
#define For(i,a,b) for(i=a;i<b;i++)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define vsort(v) sort(v.begin(),v.end())
long labs(long a){return (a>0)?a:(0-a);}

int main(){
  long i,j,x,N,H,W,D,p,q;
  cin>>H>>W>>D;
  vector<long> dist(H*W+10,0),ox(H*W+10,0),oy(H*W+10,0);
  rep(i,H){
    rep(j,W){
      cin>>x;
      ox[x]=i;oy[x]=j;
    }
  }
  For(i,D+1,H*W+1){
    dist[i]=dist[i-D]+labs(ox[i]-ox[i-D])+labs(oy[i]-oy[i-D]);
  }
  cin>>N;
  while(N--){
    cin>>p>>q;
    cout<<dist[q]-dist[p]<<endl;
  }
  return 0;
}


Measured memory_bytes: 3200
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;
using namespace std;
 
int main(){
    int n,m;cin>>n>>m;
    vector<vector<int>> jobs(m);
    rep(i,n){
        int a,b;cin>>a>>b;
        if(a>m) continue;
        jobs[m-a].push_back(b);
    }
    priority_queue<int> q;
    ll ans=0;
    for(int i=m-1;i>=0;i--){
        for(auto x : jobs[i]){
            q.push(x);
        }
        if(!q.empty()){
            ans+=q.top();
            q.pop();
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 8364
#include<iostream>

using namespace std;

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

int main() {
	int h, w;
	cin >> h >> w;
	int a = h / gcd(h, w), b = w / gcd(h, w);
	cout << (a + b - 1) * gcd(h, w) + 1 << endl;
	return 0;
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
#define rep(i, l, r) for (register int i = l; i <= r; i++)
#define per(i, r, l) for (register int i = r; i >= l; i--)
#define srep(i, l, r) for (register int i = l; i < r; i++)
#define sper(i, r, l) for (register int i = r; i > l; i--)
#define maxn 
using namespace std;;

int main(){
	int a, b, c, d, e;
	scanf("%d%d%d%d%d", &a, &b, &c, &d, &e);
	printf("%d\n", (c * 60 + d) - (a * 60 + b) - e);
	return 0;
}

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

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

  if(R < 1200){
    cout << "ABC" << endl;
  } else if(R < 2800){
    cout << "ARC" << endl;
  } else {
    cout << "AGC" << endl;
  }
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(N: int):
    sN = str(N)
    print(YES if min(len(set(sN[:3])), len(set(sN[-3:]))) == 1 else NO)


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#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 D, T, S;
  cin >> D >> T >> S;

  if(D <= T * S) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define reps(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; --i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define reps2(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define inf 2e9
#define linf 9000000000000000000ll
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int m, k, n;
bool solve(vector<int> &ans) {
    if (m == 0) {
        if (k == 0) {
            ans = vector<int>({0, 0});
            return true;
        }
        return false;
    } else if (m == 1) {
        if (k == 0) {
            ans = vector<int>({0, 0, 1, 1});
            return true;
        }
        return false;
    }
    if (k >= pow(2, m)) {
        return false;
    }
    rep(i, n) {
        if (i != k) {
            ans.push_back(i);
        }
    }
    ans.push_back(k);
    rrep(i, n) {
        if (i != k) {
            ans.push_back(i);
        }
    }
    ans.push_back(k);
    return true;
}

int main() {
    cin >> m >> k;
    n = pow(2, m);
    vector<int> ans;
    if (!solve(ans)) {
        cout << -1 << endl;
    } else {
        rep(i, ans.size()) {
            if (i) {
                cout << " ";
            }
            cout << ans[i];
        }
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 2932
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();

		int[] a = new int[N];
		long lcm_a = 1;
		for(int i=0;i<N;i++) {
			a[i] = sc.nextInt();
			lcm_a = lcm(lcm_a,a[i]);
		}

		long m = lcm_a - 1;

		long ans=0;
		long ans2=0;
		for(int i=0;i<N;i++) {
			ans += a[i];
		}

		System.out.println(ans - N);
	}

	//最小公倍数
	public static long lcm (long lcm_a, long b) {
			long temp;
			long c = lcm_a;
			c *= b;
			while((temp = lcm_a%b)!=0) {
				lcm_a = b;
				b = temp;
			}
			return c/b;
	}

}

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

int N,total=0;
int arr[100005][3];
int dp[100005][3];

int maximum( int a, int b, int c )
{
   int max = ( a < b ) ? b : a;
   return ( ( max < c ) ? c : max );
}

int calc_happ(int day,int last_played){

	if(maximum(dp[day][0], dp[day][1], dp[day][2]) == 0){
		dp[day][0] = arr[day][0] + max(calc_happ(day-1,0), calc_happ(day-1,0));
		dp[day][1] = arr[day][1] + max(calc_happ(day-1,1), calc_happ(day-1,1));
		dp[day][2] = arr[day][2] + max(calc_happ(day-1,2), calc_happ(day-1,2));
		
		// printf("day:%d\n",day );
		// printf("%d %d %d\n",dp[day][0],dp[day][1],dp[day][2] );
	}

	if(last_played==-1)
		return maximum(dp[day][0], dp[day][1], dp[day][2]);
	else if(last_played==0)
		return max(dp[day][1], dp[day][2]);
	else if(last_played==1)
		return max(dp[day][0], dp[day][2]);
	else if(last_played==2)
		return max(dp[day][0], dp[day][1]);
	else{
		// printf("Error\n");
		return 0;
	}

}


int main(){

	scanf("%d",&N);
	for (int i = 0; i < N; ++i){
		scanf("%d %d %d",&arr[i][0],&arr[i][1],&arr[i][2]);
	}
	dp[0][0] = arr[0][0];	
	dp[0][1] = arr[0][1];	
	dp[0][2] = arr[0][2];	

	printf("%d\n",calc_happ(N-1,-1));	

}

Measured memory_bytes: 10368
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <vector>
#include <cstdio>
#include <cstdlib>

typedef long long int lld;
typedef unsigned long long int ulld;
const int mod = 1000000007;

using namespace std;

int main (void) {
	ios::sync_with_stdio (false);
	int i, j;
	cin >> i >> j;
	if (i * 500 >= j) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <deque>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>
#include <string>
#include <iostream>
using namespace std;
using Graph = vector<vector<int>>;
using ll = long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(), v.end()

int main() {
    char c;
    cin >> c;
    c++;
    cout << c << endl;
}

  

Measured memory_bytes: 256
#pragma GCC optimze("Ofast")
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace __gnu_pbds;
using namespace __gnu_cxx;
#ifndef rd
#define trace(...)
#define endl '\n'
#endif
#define pb push_back
#define fi first
#define se second
#define int long long
typedef long long ll;
typedef long double f80;
#define double long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define sz(x) ((long long)x.size())
#define fr(a,b,c) for(int a=b; a<=c; a++)
#define rep(a,b,c) for(int a=b; a<c; a++)
#define trav(a,x) for(auto &a:x)
#define all(con) con.begin(),con.end()
const ll infl=0x3f3f3f3f3f3f3f3fLL;
const int infi=0x3f3f3f3f;
//const int mod=998244353;
const int mod=1000000007;
typedef vector<int> vi;
typedef vector<ll> vl;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> oset;
auto clk=clock();
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim) {
	uniform_int_distribution<int> uid(0,lim-1);
	return uid(rang);
}
int powm(int a, int b) {
	int res=1;
	while(b) {
		if(b&1)
			res=(res*a)%mod;
		a=(a*a)%mod;
		b>>=1;
	}
	return res;
}


void solve() {
	string s;
	cin>>s;
	for(char &i:s)
		if(i=='?')
			i='D';
	cout<<s<<endl;
}

signed main() {
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	srand(chrono::high_resolution_clock::now().time_since_epoch().count());
	cout<<fixed<<setprecision(8);
	int t=1;
//	cin>>t;
	fr(i,1,t)
		solve();
#ifdef rd
	cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
#endif
	return 0;
}


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

using namespace std;



int main(){
 long long int n, a[200010] ,b[200010] = {0},ans=0;
  
  cin >> n;
  
  for(int i=0;i<n;i++)
    cin >> a[i];
  
  for(int i=0;i<n;i++){
    b[a[i]]++;
  }
  
  for(int i=1;i<=n;i++){
   ans += b[i]*(b[i]-1)/2;
  }
  
  for(int i=0;i<n;i++){
    
    cout << ans - b[a[i]]+1 << endl;
  }
  
}
  

Measured memory_bytes: 5760
/*
--------------              |   /
      |                     |  /
      |                     | /
      |             *       |/          |    |         ------            *
      |                     |           |    |        /      \
      |             |       |\          |    |       |       |\          |
   \  |             |       | \         |    |       |       | \         |
    \ |             |       |  \        |    |        \     /   \        |
     V              |       |   \        \__/|         -----     \       |
*/
#include <bits/stdc++.h>
using namespace std;

#define EmiliaMyWife ios::sync_with_stdio(0); cin.tie(NULL);
#define mem(i,j) memset(i,j,sizeof (i));
#define F first
#define S second
#define lowbit(x) ((x)&(-(x)))
#define siz(v) (long long)(v).size()
typedef int64_t ll;
typedef uint64_t ull;
const double EPS  = 1e-8;
const int INF     = 0x3F3F3F3F;
const ll LINF     = 4611686018427387903;
const int MOD     = 1e9+7;
/*-----------------------------------------------------------------------------------------------------*/

signed main() {
	EmiliaMyWife

    int n;
    cin >> n;
    vector<pair<int,int>> arr(n);
    vector<int> ans(n);
    for(int i = 0; i < n; i++) {
        cin >> arr[i].first;
        arr[i].second = i;
    }
    sort(arr.begin(), arr.end());
    int x = n/2;
    for(int i = 0; i < n; i++) {
        if(i < x)
            ans[arr[i].second] = arr[x].first;
        else
            ans[arr[i].second] = arr[x-1].first;
    }
    for(int i = 0; i < n; i++)
        cout <<ans[i] << '\n';

	return 0;
}


Measured memory_bytes: 4608
#include <iostream>
#include <vector>
#include <map>
#include <math.h>
#define rep(i, n) for(int i=0; i<n; i++)

using namespace std;

// n^r
long long power_(long long n, long long r){
  long long ret = 1;
  rep(i, r)
    ret = ret*n;
  return ret;
}

int main(){
  long long N, P;
  cin >> N >> P;
  // 入力終了

  // 素因数分解を格納
  map<long long, long long> fac; 

  // 素因数分解
  for(long long i=2; i*i<=P; i++){
    while(P%i == 0){
      fac[i]++;
      P /= i;
    }
  }
  // 最後に残ったやつ
  if(P != 1)
    fac[P]++;
  

  long long ans = 1;

  // 指数部分がN以上なら，Nで割ることで(指数)/N個に因数を分配できる
  for(auto x : fac){
    if(N <= x.second){
      long long num = x.second/N;
      // num個に因数を分配できるので，
      // 最大公約数は(因数)*numだけ増やせる
      ans = ans * power_(x.first, num);
    }
  }

  // 解答
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 3624
$N=<>;
($x[$_],$y[$_],$h[$_])=glob<>for@N=0..$N-1;
for$cx(0..100){for$cy(0..100){
	$i++while$h[$i]==0;
	$H=abs($cx-$x[$i])+abs($cy-$y[$i])+$h[$i];
	print"$cx $cy $H\n"if!grep{$h[$_]!=($-=$H-abs($cx-$x[$_])-abs($cy-$y[$_]))}@N
}}

Measured memory_bytes: 768
#include <stdio.h>
#define M 1000000007
#define N 200016

unsigned long ulget();
inline unsigned long ulget()
{
    register unsigned long t = 0;
    register char c;
    while((c = getchar() - '0') >= 0)
    {
        t = t * 10 + c;
    }
    return t;
}

unsigned int colorlastdp[N];
int main()
{
    unsigned int dp[N];
    unsigned int n = ulget();
    dp[0] = 0; dp[1] = 1;
    unsigned int color, lastcolor = 0;
    for (unsigned int i = 1; i <= n;)
    {
        color = ulget();
        if (color != lastcolor)
            dp[i] = (dp[i] + colorlastdp[color]) % M;
        dp[++i] = colorlastdp[color] = dp[i];
        lastcolor = color;
        //printf("%d %d %d\n", i, color, dp[i]);
    }
    printf("%u", dp[n]);
}


Measured memory_bytes: 3116
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Comparator;
import java.util.SortedSet;
import java.util.StringTokenizer;
import java.util.TreeSet;

import static java.lang.Integer.parseInt;

/**
 * Best Matched Pair
 */
public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		String[] words;

		int N = parseInt(br.readLine());
		int[] a = new int[N];

		StringTokenizer st = new StringTokenizer(br.readLine());

		for (int i = 0; i < N; i++) {
			a[i] = parseInt(st.nextToken());
		}

		SortedSet<Integer> pairs = new TreeSet<>(Comparator.reverseOrder());

		for (int i = 0; i < N; i++) {
			for (int j = 0; j < N; j++) {
				if (i != j) pairs.add(a[i] * a[j]);
			}
		}

		int ans = -1;
		for (int p : pairs) {
			if (check(p)) {
				ans = p;
				break;
			}
		}

		System.out.println(ans);

	} //end main

	static boolean check(int p) {

		String s = String.valueOf(p);
		boolean ret = true;

		char t = s.charAt(0);
		for (int i = 1; i < s.length(); i++) {
			if (t + 1 != s.charAt(i)) {
				ret = false;
				break;
			}
			t = s.charAt(i);
		}

		return ret;
	}
}

Measured memory_bytes: 87532
#include <stdio.h>

int main(void) {
	int A, B, a = 0, b = 0;
	double T, X;

	scanf("%d %d %lf", &A, &B, &T);
	X = T + 0.5;
	
	while (a <= T) {
		a += A;
		if (a <= T) b += B;
	}
	
	printf("%d\n", b);

	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<math.h>
#include<stdlib.h>
#include<string>
#include<limits.h>
#include<utility>
#include<queue>
#include<vector>
#include<tuple>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define ALL(A) A.begin(),A.end()
bool comparator(P a, P b) {
	return a.first / a.second < b.first / b.second;
}


int main() {
	int x;
	cin >> x;
	if (x <= 599) {
		cout << 8;
	}
	else if (x <= 799) {
		cout << 7;
	}
	else if (x <= 999) {
		cout << 6;
	}
	else if (x <= 1199) {
		cout << 5;
	}
	else if (x <= 1399) {
		cout << 4;
	}
	else if (x <= 1599) {
		cout << 3;
	}
	else if (x <= 1799) {
		cout << 2;
	}
	else {
		cout << 1;
	}
	cout << endl;
}


Measured memory_bytes: 3192
import scala.io.StdIn.{readInt, readLine};

object Main {
    def main(args: Array[String]): Unit = {
        val Array(n, k) = readLine.split(" ").map(_.toInt);
        val baggage = (0 until n).map(a => readInt).toList;
        println(allocation(baggage, k));
    }
    
    def allocation(baggage: List[Int], k: Int): Int = {
        def binSearch(first: Int, last: Int, min: Int): Int = {
            val pivot = (last + first) / 2;
            if (first >= last) {
                if (check(pivot, k, baggage)) pivot else min;
            } else {
                if (check(pivot, k, baggage)) {
                    binSearch(first, pivot - 1, pivot);
                } else {
                    binSearch(pivot + 1, last, min);
                }
            }
        }
        binSearch(1, baggage.sum, Int.MaxValue);
    }
    
    def check(maxCapa: Int, trucks: Int, baggage: List[Int]): Boolean = {
        def go(restCapa: Int, restTrucks: Int, b: List[Int]): Boolean = {
            b match {
                case Nil => true;
                case weight :: restBaggage => {
                    if (weight > maxCapa) {
                        false;
                    } else {
                        if (weight <= restCapa) {
                            go(restCapa - weight, restTrucks, restBaggage);
                        } else {
                            if (restTrucks == 0) {
                                false;
                            } else {
                                go(maxCapa - weight, restTrucks - 1, restBaggage);
                            }
                        }
                    }
                }
            }
        }
        go(0, trucks, baggage);
    }
}


Measured memory_bytes: 63928
import collections


def solve(n, m, hist):
    cor = 0
    pen = 0
    for p, tries in hist.items():
        for i, t in enumerate(tries):
            if t == 'AC':
                cor += 1
                pen += i
                break
    return '{0} {1}'.format(cor, pen)


def input_to_int():
    return [int(r) for r in input().split(' ')]


if __name__ == "__main__":
    n, m = input_to_int()
    hist = collections.defaultdict(list)
    for _ in range(m):
        p, s = input().split(' ')
        hist[p].append(s)
    print(solve(n, m, hist))


Measured memory_bytes: 31888
import java.util.Arrays;
import java.util.Scanner;

class Main{
	static int mod = 1000000007;
	public static void main(String args[]){
		Scanner sc=new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int[] a = new int[M];
		for(int i = 0; i < M; i++) a[i] = sc.nextInt();
		int[] dp = new int[N + 3];
		Arrays.fill(dp, 0);
		dp[0] = 1;
		for(int i = 0; i < M; i++) dp[a[i]] = -1;
		for(int i = 0; i < N; i++) {
			if(dp[i] == -1) continue;
			if(dp[i + 1] != -1) {
				dp[i + 1] += dp[i];
				dp[i + 1] %= mod;
			}
			if(dp[i + 2] != -1) {
				dp[i + 2] += dp[i];
				dp[i + 2] %= mod;
			}
		}
		System.out.println(dp[N]);
	}
}

Measured memory_bytes: 46496
n = int(input())

r = []

for i in range(n):
    city, score = input().split()
    score = int (score)
    r.append((i+1, city, score))

r.sort(key=lambda x:x[2], reverse=True)
r.sort(key=lambda x:x[1])

for i in range(n):
    print(r[i][0])

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

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


Measured memory_bytes: 256
/*  ***  In The Name of God ... ***  */ 
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;


#define int long long
#define all(v) v.begin() , v.end()
#define pb push_back
#define endl '\n' 
template<typename T> inline bool smin(T &a, const T &b){ return b < a ? a = b,1:0;}
template<typename T> inline bool smax(T &a, const T &b){ return a < b ? a = b,1:0;}

const int N = 1e5 + 10 , lg = 20 ;

int n , x [ N ] , L , q , nxt [ N ] [ lg ] ;

int32_t main()
{
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n ;
	for ( int i = 1 ; i <= n ; i++ )
		cin >> x [ i ] ;
	cin >> L ;
	int reach = 1 ; 
	for ( int i = 1 ; i <= n ; i++ ) {
		while ( reach + 1 <= n && x [ reach + 1 ] - x [ i ] <= L )
			reach++ ; 
		nxt [ i ] [ 0 ] = reach ;
		//cout << i << ' ' << reach << '\n' ; 
	}
	for ( int j = 1 ; j < lg ; j++ ) {
		for ( int i = 1 ; i <= n ; i++ ) {
			nxt [ i ] [ j ] = nxt [ nxt [ i ] [ j - 1 ] ] [ j - 1 ] ; 
		}
	}
	cin >> q ;
	while ( q-- ) {
		int a , b ;
		cin >> a >> b ;
		if ( a > b )
			swap ( a , b ) ;
		int res = 0 ;
		for ( int i = lg - 1 ; ~i ; i-- ) {
			if ( nxt [ a ] [ i ] < b ) {
				res += ( 1LL << i ) ;
				a = nxt [ a ] [ i ] ; 
			}
		}
		cout << ++res << '\n' ; 
	}
}


Measured memory_bytes: 17280