akhauriyash/Code-Regression huggingface dataset:
/**
 * File    : D.cpp
 * Author  : Kazune Takahashi
 * Created : 2018-3-4 21:11:47
 * Powered by Visual Studio Code
 */

#include <iostream>
#include <iomanip>   // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple>
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set>
#include <random> // random_device rd; mt19937 mt(rd());
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.

typedef long long ll;

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

// const int C = 1e6+10;
// const ll M = 1000000007;

vector<ll> V[100010];
vector<ll> sum[100010];
ll H, W, D;
int A[310][310];
int Q;
ll L[100010];
ll R[100010];

typedef tuple<ll, ll> point;
point P[100010];

ll dist(point p, point q)
{
  return abs(get<0>(p) - get<0>(q)) + abs(get<1>(p) - get<1>(q));
}

int main()
{
  cin >> H >> W >> D;
  for (auto i = 0; i < H; i++)
  {
    for (auto j = 0; j < W; j++)
    {
      cin >> A[i][j];
      A[i][j]--;
    }
  }
  cin >> Q;
  for (auto i = 0; i < Q; i++)
  {
    cin >> L[i] >> R[i];
    L[i]--;
    R[i]--;
  }
  for (auto i = 0; i < H; i++)
  {
    for (auto j = 0; j < W; j++)
    {
      P[A[i][j]] = point(i, j);
    }
  }
  for (auto k = 0; k < D; k++)
  {
    int now = k;
    while (now + D < H * W)
    {
      V[k].push_back(dist(P[now], P[now + D]));
      now += D;
    }
  }
  for (auto k = 0; k < D; k++)
  {
    sum[k] = vector<ll>(V[k].size() + 1, 0);
    for (auto i = 0; i < (int)V[k].size(); i++)
    {
      sum[k][i + 1] = sum[k][i] + V[k][i];
    }
  }
  for (auto i = 0; i < Q; i++)
  {
    int k = L[i] % D;
    int l = L[i] / D;
    int r = R[i] / D;
#if DEBUG == 1
    cerr << "k = " << k << ", l = " << l << ", r = " << r << endl;
#endif
    cout << sum[k][r] - sum[k][l] << endl;
  }
}

Measured memory_bytes: 11264
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include<bitset>

using namespace std;
#define loop(i,n) for(int i = 0; i < (n); ++i)
#define loops(i,f,n) for(int i = (f); i < (n); ++i)
#define INF 9999999
#define lint long long int
#define in(a) cin>>a
#define out(a) cout<<a<<endl


int main()
{
	lint n, k;
	cin >> n >> k;
	vector<pair<lint, lint>> nums;
	loop(i, n)
	{
		lint a, b;
		cin >> a >> b;
		nums.push_back(make_pair(a, b));
	}
	sort(nums.begin(), nums.end());
	lint ans = 0;
	loop(i, n)
	{
		if (nums[i].second >= k)
		{
			ans = nums[i].first;
			break;
		}
		else
		{
			k -= nums[i].second;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 2420
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ll long long
#define MOD 1000000007
#define MAX 1000010
#define test(a,n) REP(i,n) cout << a[i] << " ";
using namespace std;

int main(){
  int n,k;
  cin >> n >> k;
  int sum = 0;
  
  while(n >= k){
    sum++;
    n = n / k;
  }
  
  cout << sum+1;
  return 0;
}

Measured memory_bytes: 256
# ABC089C - March
import sys

input = sys.stdin.readline

from itertools import combinations


def main():
    n = int(input())
    lst = [input().rstrip()[0] for _ in range(n)]
    print(
        sum(x * y * z for x, y, z in combinations([lst.count(s) for s in "MARCH"], 3))
    )


if __name__ == "__main__":
    main()

Measured memory_bytes: 3884
#include <bits/stdc++.h>
#define LL long long
#define mp make_pair
#define pb push_back
#define VI vector<int>
#define pii pair<int,int>
#define INF 0x3f3f3f3f
using namespace std;
const int MAXN = 1e5;
char S[MAXN+10];
int n;
int main(){
	scanf("%s", S);
	n = strlen(S);
	if(S[0] == '0' || S[n-1] == '1'){
		printf("-1\n");
		return 0;
	}
	for(int i = 0; i < (n-1)/2; i++){
		if(S[i] != S[n-i-2]){
			printf("-1\n");
			return 0;
		}
	}
	int cur = 1, nxt = 2;
	for(int i = 0; i < n - 1; i++){
		printf("%d %d\n", cur, nxt);
		if(S[i] == '1') cur = nxt; 
		nxt++;
	}
	return 0;
}

Measured memory_bytes: 1536
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc  =new Scanner(System.in);
      	int a = sc.nextInt();
      	int b = sc.nextInt();
	    int c = sc.nextInt();
      	int d = sc.nextInt();
      
      	if(a+b == c+d){
        	System.out.println("Balanced");
        }else if (a+b > c+d){
        	System.out.println("Left");
        }else{
        	System.out.println("Right");
        }
    }
}

Measured memory_bytes: 35636
N,M = map(int,input().split()) #N:スイッチ　＃M：電球
light=[]
for i in range(M):
    light.append(list(map(int,input().split())))



p = list(map(int,input().split()))
ans = 0
for i in range(2**N):
    #print("num {}" .format(i), end="")
    sw = [0]*N
    for j in range(N):
        if ((i >>j) & True):
            sw[j]=1
    On_Light_nmb = 0
    for m in range(M): #電球ごとに判定
        sum = 0
        for k in range(light[m][0]):
            s_nmb = int(light[m][k+1])
            sum += sw[s_nmb-1]

        if sum%2 == p[m]: #電球mのOnスイッチの合計が
            #Ans.append(1)
            On_Light_nmb +=1


    #もしすべてのライトがついていたら
    if On_Light_nmb == m+1:
        ans +=1

print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using pii=pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
#define all(c) begin(c),end(c)
#define rall(c) rbegin(c),rend(c)
#define fore(x,c) for(auto &&x:c)
#define rep(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define rrep(i, a, n) for(int i=(int)(n-1);i>=a;--i)
#define sz(c) ((int)c.size())
#define contains(c,x) (c.find(x)!=end(c))
#define inseg(l,x,r) ((l)<=(x)&&(x)<(r))
#define dump(...)
#define pb push_back
#define _ 0
const signed INF_=1001001001; const long long INF=1001001001001001001LL;
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    for (auto i = begin(v); i != end(v); i++) os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    for (auto i = begin(v); i != end(v); i++) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T, class U> bool chmax(T &a,const U &b){return a<b?a=b,1:0;}
template<class T, class U> bool chmin(T &a,const U &b){return a>b?a=b,1:0;}
template <class T> void psum(T& c) {partial_sum(begin(c), end(c), begin(c));}
template<class T> using heap=priority_queue<T,vector<T>,greater<T>>;
struct before_main_function {
    before_main_function() {
        cin.tie(nullptr); ios::sync_with_stdio(0);
        cout << setprecision(15) << fixed;
        // #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    int N, A, B;
    cin >> N >>A >> B;
    int mn = 0;
    if (A + B > N) {
        mn = A + B - N;
    }
    cout << min(A, B) << " " << mn << endl;
    return (0^_^0);
}



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

int main() {
    ll x,k,d,ans;
    cin >> x >> k >> d;
    if(x < 0){
        x*=-1;
    }
    if(k < x/d){
        ans = x - k*d;
    }else{
        k -= x/d;
        ans = x%d;
        if(k%2 == 1){
            ans -= d;
            ans *= -1;
        }
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3604
//header{{{
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include<boost/multiprecision/cpp_int.hpp>
#include<boost/math/common_factor_rt.hpp>
  
using namespace std;
using namespace boost::multiprecision;  
using namespace boost::math;

#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define Fixed fixed << setprecision(12)
//#define int int64_t
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9+7; 
constexpr int mod2 = 998244353;

template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class T> using min_heap = priority_queue<T,vector<T>,greater<T> >;
template <class T> using max_heap = priority_queue<T>;
template <class A, class B> using umap = unordered_map<A,B>;
  
inline int square(int a){ return a * a;}
inline int updiv(int a,int b){ return (a + b - 1) / b; }

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

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

    int n;
    cin >> n;

    vector<string> s(n);

    int maxv = 0;
    umap<string,int> mp;
    rep(i,n){
        cin >> s[i];
        mp[s[i]]++;
        chmax(maxv,mp[s[i]]);
    }

    sort(all(s));
    umap<string,bool> flg;

    rep(i,n){
        if(mp[s[i]] == maxv && !flg[s[i]]){
            cout << s[i] << '\n';
            flg[s[i]] = true;
        }
    }


    return 0;
}


Measured memory_bytes: 35656
import java.util.*;
 
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());
    	int c = Integer.parseInt(sc.next());
    	int k = Integer.parseInt(sc.next());
    	int i = 0;
    while(a >= b){
       b*=2;
       i++;
     }
     while(b >= c){
       c*=2;
       i++;
     }
     
   
    if(i<=k){
		System.out.println("Yes");
      }else{
    System.out.println("No");
    }
 /*System.out.println(a);
     System.out.println(b);
     System.out.println(c);
    System.out.println(i);
     System.out.println(k); */
  }
}

Measured memory_bytes: 35700
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
int main(void)
{
  LL n;
  cin>>n;
  LL f[100];
  f[0] = 2;
  f[1] = 1;
  for(int i = 2;i <= n;i++)
  f[i] = f[i-1] + f[i-2];
  cout<<f[n]<<endl;
  return 0;
}

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

#define  fast         ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define  loop(i,m,n)  for(int i=m;i<n;i++)
#define  rloop(i,m,n) for(int i=m;i>=n;i--)
#define  mod          1000000007
#define  mp(x,y)      make_pair(x,y)
#define  pb(x)        push_back(x)
#define  Pop()        pop_back()
#define  F            first 
#define  S            second
#define  B()          begin()
#define  E()          end()

typedef  vector<int>            vi;
typedef  map<int,int>           mi;
typedef  vector<pair<int,int>>  vp;
typedef  pair<int,int>          pi;
typedef  long long              ll;

int main(){
    fast
    string s;
    cin>>s;
    ll res=0;
    loop(i,0,s.size()){
        int t=s[i];
        res+=t-48;
        if(res%9==0) res=0;
    }
    if(res%9==0)cout<<"Yes";
    else cout<<"No";
    return 0;
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007


int main() {
	vector<ll>a;
	ll n;
	cin>>n;
	for(int i=0;i<n;i++){
		ll x;
		cin>>x;
		a.push_back(x);
	}
	vector<ll>ans;
	for(int i=n;i>=1;i--){
		ll j=i;
		while(j!=a[j-1]){
			j--;
			if(j==0){
				cout << -1;
				return 0;
			}
		}
		ans.push_back(a[j-1]);
		a.erase(a.begin()+j-1);
	}
	reverse(ans.begin(),ans.end());
	for(int i=0;i<n;i++){
		cout << ans[i]<<endl;
	}
}

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

int main(){
  long n,a,b;
  cin>>n>>a>>b;
  long c,k,l,j;
  c = a+b;
  k = n/c;
  l = n%c;
  if(l<a){
    j = k*a + l;
  }
  else{
    j = (k+1)*a;
  }
  cout<<j<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _USE_MATH_DEFINES
#define ios std::ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define PI acos(-1.0) //3.14159265358
#define EPS 1e-9 //epsilon, 10^-9, checking for equality 
#define pb push_back
#define fi first
#define se second
#define sz(x) x.size()
#define rep(i,n) for(int i=0;i<n;i++)
#define isort(x) sort(x.begin(),x.end())
#define dsort(x) sort(x.rbegin(),x.rend())
const int inf=1e9+7; //10^9 +7
const int modc=998244353;
typedef long long int ll;typedef vector<int> vi;typedef vector<ll> vll;
typedef pair<int,int> ii;typedef map<int,int> mii;
inline void rvi(vi &v, int n){int temp; rep(i,n){cin>>temp;v.pb(temp);}}
inline void rvll(vll &v, int n){ll temp;rep(i,n){cin>>temp;v.pb(temp);}}
inline void prvi(vi &a){rep(i,sz(a)){cout<<a[i]<<" ";}cout<<endl;}
inline void prvll(vll &a){rep(i,sz(a)){cout<<a[i]<<" ";}cout<<endl;}
inline vll prefixsum(vi &a){vll b;b.pb(a[0]);for(int i=1;i<sz(a);i++){b.pb(a[i]+b[i-1]);}return b;}
inline vll suffixsum(vi &a){vll b(sz(a));b[sz(a)-1]=a[sz(a)-1];for(int i=sz(a)-2;i>=0;i--){b[i]=a[i]+b[i+1];}return b;}
inline vll prefixsum(vll &a){vll b;b.pb(a[0]);for(int i=1;i<sz(a);i++){b.pb(a[i]+b[i-1]);}return b;}
inline vll suffixsum(vll &a){vll b(sz(a));b[sz(a)-1]=a[sz(a)-1];for(int i=sz(a)-2;i>=0;i--){b[i]=a[i]+b[i+1];}return b;}
void solve();int main(){ios;solve();return 0;}
//--------SOLVE--------------------------------------------------------------------
int f(int n)
{
	if(n&1) return 3*n+1;
	else return n/2;
}
void solve()
{
	int s;cin>>s;
	map<int,bool> mp;
	mp[s]=true;
	int i=0;
	while(1)
	{
		s=f(s);
		// cout<<"s="<<s<<endl;
		i++;
		if(mp.count(s)) break;
		mp[s]=true;
	}
	cout<<i+1<<endl;

}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <iterator>
#define loop(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define debug(x)  cout << #x << " = " << (x) << endl;

using namespace std;
using LL = long long;
using ULL = unsigned long long;

const LL INF = (1LL << 60);

bool warshall_floyd(vector<vector<LL>> &dist) {
    int n = dist.size();
    rep(k, n) rep(i, n) if (dist[i][k] != INF) {
        rep(j, n) if (dist[k][j] != INF) {
            dist[i][j]= min(dist[i][j] , dist[i][k] + dist[k][j]);
            if (j == k and dist[j][k] < 0) return false;
        }
    }
    return true;
}
int main() {
    int h, w; cin >> h >> w;

    vector<vector<LL>> magic(10, vector<LL>(10, 0));
    rep(i, 10) rep(j, 10) {
        cin >> magic[i][j];
    }
    warshall_floyd(magic);

    map<int, int> m;
    rep(i, h) rep(j, w) {
        int a; cin >> a;
        if (a == -1) continue;
        ++m[a];
    }

    int ans = 0;
    for (auto e: m) {
        ans += magic[e.first][1] * e.second;
    }
    cout << ans << endl;
}


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

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int arr[] = new int[n + 1], srt[] = new int[n + 1];
		for (int i = 1; i <= n; i++) {
			arr[i] = sc.nextInt();
			srt[i] = arr[i];
		}
		Arrays.parallelSort(srt);
		for (int i = 1; i <= n; i++) {
			System.out.println(srt[n / 2 + (arr[i] >= srt[n / 2 + 1] ? 0 : 1)]);
		}
	}

}

Measured memory_bytes: 62440
#include <stdio.h>

int main()
{
    int H, W;
    while (1){
        scanf ("%d %d", &H, &W);
        if (W == 0 && W == 0) break;
        for (int i = 1; i <= H; i++){
            for (int j = 1; j <= W; j++){
                if (i % 2 == 0){
                    if (j % 2 == 0){
                        printf("#");
                    }
                    else {
                        printf(".");
                    }
                }
                else {
                    if (j % 2 == 0){
                        printf(".");
                    }
                    else {
                        printf("#");
                    }
                }
            }
            printf("\n");
        }
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 2104
#include<stdio.h>


int MAX(int a,int  b){


return (((a) > (b)) ? (a) : (b));
}
int MIN(int a,int  b){
      return  (((a) < (b)) ? (a) : (b));
     }
int main(){
  int n;
  int i;
  int R[200000];
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&R[i]);
  }
  int maxv = -2000000000;
  int minv = R[0];
  for(i=1;i<n;i++){
maxv=MAX(maxv,R[i]-minv);
minv=MIN(minv,R[i]);


  }
  printf("%d\n",maxv);
  return 0;
}

Measured memory_bytes: 1376
#!/usr/bin/env python3
import math
a, b, h, m = map(int, input().split())
y = 360 * m / 60
x = 360 * (h * 60 + m) / 720
if x == 0 and y >= 180:
    x = 360
if y == 0 and x >= 180:
    y = 360
ang = max(x, y) - min(x, y)
print(math.sqrt((a ** 2) + (b ** 2) - (2 * a * b * math.cos(math.radians(ang)))))

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

int main(){
  int N,k=10000;
  cin>>N;
  vector<int> W(N);
  for(int &i:W)
    cin>>i;
  for(int i=1;i<N;i++){
    int S1=0,S2=0;
    for(int j=0;j<N;j++){
      if(j<i)
        S1+=W[j];
      else
        S2+=W[j];
    }
    k=min(k,abs(S1-S2));
  }
  cout<<k<<endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iostream>
#include <sstream>
#include <climits>
#include <cfloat>
#include <complex>


typedef long long ll;
const double Eps = 1e-6;

using namespace std;

int main()
{
	int d[101][101];
	const int Inf = 100000000;
	for (int i = 1; i < 101; ++i)
		for (int j = 1; j < 101; ++j)
			d[i][j] = Inf;
	for (int i = 1; i < 101; ++i)
		d[i][i] = 0;

	int n;
	scanf("%d", &n);
	while (n--)
	{
		int no, m;
		scanf("%d %d", &no, &m);
		while (m--)
		{
			int t;
			scanf("%d", &t);
			d[no][t] = 1;
		}
	}
	for (int k = 1; k < 101; ++k)
		for (int i = 1; i < 101; ++i)
			for (int j = 1; j < 101; ++j)
				d[i][j] = min(d[i][j], d[i][k] + d[k][j]);

	int p;
	scanf("%d", &p);
	while (p--)
	{
		int src, dest, ttl;
		scanf("%d %d %d", &src, &dest, &ttl);
		int r = d[src][dest] + 1;
		if (ttl >= r)
			printf("%d\n", r);
		else
			puts("NA");
	}

	return 0;
}

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

int main() {
	char s[11];
	scanf("%s", s);
	sort(s, s+4);
	puts((s[0]==s[1]&&s[1]!=s[2]&&s[2]==s[3]) ? "Yes" : "No");
	
	return 0;
}

Measured memory_bytes: 256
from bisect import bisect


def search_alphabet_index(string):
    cs = [[] for i in range(26)]
    for i, s in enumerate(string):
        j = ord(s) - ord("a")
        cs[j].append(i)
    return cs


def main():
    S = input()
    T = input()
    N = len(S)

    cs = search_alphabet_index(S)

    for c in set(T):
        if not cs[ord(c) - ord("a")]:
            ans = -1
            print(ans)
            exit()

    rnd = 0
    k = -1
    for t in T:
        ti = ord(t) - ord("a")
        i = bisect(cs[ti], k)
        if i == len(cs[ti]):
            k = cs[ti][0]
            rnd += 1
        else:
            k = cs[ti][i]
    ans = rnd * N + k + 1
    print(ans)


if __name__ == "__main__":
    main()

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

int main() {
#define rrep(i, n) for(int i = 1; i <= (int)(n); i++)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
  int N;
  cin>>N;
  vector<int> a(N+1);
  int j=0;
  rep(i,N-1){
    cin>>j;
    a[j]++;
  }
  rrep(i,N)
    cout<<a[i]<<" ";
}

Measured memory_bytes: 4048
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

n = ri() % 500
print('Yes' if ri() >= n else 'No')
















Measured memory_bytes: 26980
#include<bits/stdc++.h>
using namespace std;
int main(){
  int w,a,b;
  cin >> w >> a >> b;
  if(a>b+w) cout << a-(b+w) << endl;
  else{
    if(b-(a+w)>=0)
    cout << b-(a+w) << endl;
    else cout << 0 << endl;
  }
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){

	int m,a,b,c,temp;

	while(1){
		scanf("%d %d",&c,&m);
		if(c==0&m==0){
			break;
		}
		temp=m-c;
		c=temp/1000;
		temp=temp-c*1000;
		b=temp/500;
		temp=temp-b*500;
		a=temp/100;
		printf("%d %d %d\n",a,b,c);
	}
}

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

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

typedef long long ll;
using namespace std;
int mod = 1000000007;

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string S; cin >> S;
    int cnt[26] = {};
    rep(i, S.length()){
        cnt[S[i]-'a']++;
    }
    if(S.length() == 26){
        int exc = 25;
        while(exc >= 1 && S[exc-1] > S[exc]){
            exc--;
        }
        if(exc == 0) cout << -1 << endl;
        else{
            string ans = "";
            rep(i, exc-1) ans += S[i];
            //S[exc-1]より大きいS[exc]以降の最小文字
            char sw = 'z';
            for(int i = exc; i < 26; i++){
                if(S[exc-1] < S[i]) sw = min(sw, S[i]);
            }
            ans += sw;
            cout << ans << endl;
        }
    }
    else{
        int add = -1;
        rep(i, 26){
            if(cnt[i] == 0){
                add = i;
                break;
            }
        }
        S += ('a'+add);
        cout << S << endl;
    }
    return 0;
}

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

const int MAX_V=200000;

vector<int> G[MAX_V+1];
vector<int> res;
int n,Q;

//v:=current vertex, p:=parent of v
void dfs(int v, int p) {
  for (auto e : G[v]) {
    if (e==p) continue;
    res[e]+=res[v];
    dfs(e, v);
  }
}

int main() {
  scanf("%d %d", &n, &Q);
  for (int i=0; i<n-1; i++) {
    int u,v;
    scanf("%d %d", &u,&v);
    u--; v--;
    G[u].push_back(v);
    G[v].push_back(u);
  }
  res.resize(n, 0);
  for (int q=0; q<Q; q++) {
    int v,cost; cin>>v>>cost;
    v--;
    res[v]+=cost;
  }
  dfs(0, -1);
  for (int i=0; i<n; i++) cout<<res[i]<<endl;
  return 0;
}


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

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

    int a, b, c, d;
    a = S / 1000;
    b = (S - a * 1000) / 100;
    c = (S - a * 1000 - b * 100) / 10;
    d = S % 10;

    if(a == b){
        cout << "Bad" << endl;
    }else if(b == c){
        cout << "Bad" << endl;
    }else if(c == d){
        cout << "Bad" << endl;
    }else{
        cout << "Good" << endl;
    }
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func configure(scanner *bufio.Scanner) {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
}
func getNextString(scanner *bufio.Scanner) string {
	scanned := scanner.Scan()
	if !scanned {
		panic("scan failed")
	}
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	extra := 0
	if os.Getenv("I") == "IronMan" {
		fp, _ = os.Open(os.Getenv("END_GAME"))
		extra = 100
	}
	scanner := bufio.NewScanner(fp)
	configure(scanner)
	writer := bufio.NewWriter(wfp)
	defer func() {
		r := recover()
		if r != nil {
			fmt.Fprintln(writer, r)
		}
		writer.Flush()
	}()
	solve(scanner, writer)
	for i := 0; i < extra; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	m := getNextInt(scanner)
	aa := make([]int, n+1)
	for i := 0; i < n; i++ {
		aa[i+1] = (aa[i] + getNextInt(scanner)) % m
	}
	var ans int64
	mp := map[int]int64{}
	mp[0]++
	for i := 0; i < n; i++ {
		ans += mp[aa[i+1]]
		mp[aa[i+1]]++
	}
	fmt.Fprintln(writer, ans)
}


Measured memory_bytes: 9280
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>
#include <fstream>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }

int main()
{
	int n;
	while(cin >> n && n)
	{
		int ans = 0;
		while(5 <= n)
		{
			ans += n / 5;
			n = (n - n % 5) / 5;
		}
		cout << ans << endl;
	}
}

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

using namespace std;

typedef long long ll;
const ll N = (ll) 5e5 + 7;
ll n, sol[N], top, dp[N];
bool u[N];
vector<ll> g[N];

void dfs(ll a)
{
    u[a] = 1;
    for (auto &b : g[a])
    {
        if (u[b] == 0)
        {
            dfs(b);
        }
    }
    sol[++top] = a;
}

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

    string s;
    cin >> s;
    n = (ll) s.size() + 1;

    for (ll i = 0; i < n - 1; i++)
    {
        if (s[i] == '<')
        {
            g[i + 1].push_back(i);
        }
        else
        {
            g[i].push_back(i + 1);
        }
    }

    for (ll i = 0; i < n; i++)
    {
        if (u[i] == 0)
        {
            dfs(i);
        }
    }


    ll ans = 0;
    for (ll j = 1; j <= n; j++)
    {
        ll i = sol[j];
        for (auto &k : g[i])
        {
            dp[i] = max(dp[i], 1 + dp[k]);
        }
        ans += dp[i];

     ///   cout << i << " " << dp[i] << "\n";
    }
    cout << ans << "\n";



    return 0;
}


Measured memory_bytes: 51996
#include <bits/stdc++.h>
#define ll long long int
#define pb(x) push_back(x)
#define TEST(t) int inox,t;cin>>t; for(inox=1;inox<=t;inox++)
#define rep(i,n) for(i=0;i<n;i++)
#define repr(i,n) for(i=n-1;i>=0;i--)
using namespace std;


int main(){
  ll n; cin>>n;
  ll i,sum=0,j,k;

  for(i=1;i<=n;i++){
    for(j=1;j<=n;j++){
        for(k=1;k<=n;k++){
            sum+=__gcd(i,__gcd(j,k));
        }
    }
  }
  cout<<sum;
}

Measured memory_bytes: 3636
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <cmath>
#include <cassert>
#include <string>
#define SIZE 1000005
#define MOD 1000000007

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

ll dp[SIZE];
ll rdp[SIZE];

int main()
{
	int N,H,D;
	scanf("%d %d %d",&N,&H,&D);
	ll fac=1,coef=0;
	for(ll i=1;i<=N;i++)
	{
		fac=fac*(ll) i%MOD;
		coef+=fac;
		if(coef>=MOD) coef-=MOD;
	}
	for(int i=1;i<=H;i++)
	{
		ll sum=rdp[i-1]-(i-D-1<0?0:rdp[i-D-1]);
		if(sum<0) sum+=MOD;
		sum=sum*coef%MOD;
		if(i<=D)
		{
			sum+=fac;
			if(sum>=MOD) sum-=MOD;
		}
		dp[i]=sum;
		rdp[i]=rdp[i-1]+sum;
		if(rdp[i]>=MOD) rdp[i]-=MOD;
	}
	printf("%lld\n",dp[H]);
	return 0;
}


Measured memory_bytes: 15744
import java.util.*;
import java.io.*;

class Main{
    public static void main(String[] args){
        FastScanner fs = new FastScanner();
        int n = fs.nextInt();
        int W = fs.nextInt();
        int[] w = new int[n];
        int[] v = new int[n];
        for(int i=0;i<n;i++){
            w[i] = fs.nextInt();
            v[i] = fs.nextInt();
        }
        long[][] dp = new long[n+1][W+1];
        for(int i=0;i<n;i++){
            for(int j=0;j<=W;j++){
                if(j-w[i]>=0){
                    dp[i+1][j] = Math.max(dp[i][j],dp[i][j-w[i]]+v[i]);
                }else{
                    dp[i+1][j] = dp[i][j];
                }
            }
        }
        System.out.println(dp[n][W]);
    }
    static class FastScanner{
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;

        private boolean hasNextByte(){
            if(ptr < buflen){
                return true;
            }else{
                ptr = 0;
                try{
                    buflen = in.read(buffer);
                }catch(IOException e){
                    e.printStackTrace();
                }
                if(buflen <= 0){
                    return false;
                }
            }
            return true;
        }

        private int readByte(){
            if(hasNextByte())return buffer[ptr++];
            else return -1;
        }

        private boolean isPrintableChar(int c){
            return 33<=c && c<=126;
        }

        public boolean hasNext(){
            while(hasNextByte() && !isPrintableChar(buffer[ptr]))ptr++;
            return hasNextByte();
        }

        public String next(){
            if(!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while(isPrintableChar(b)){
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }

        public long nextLong(){
            if(!hasNext()) throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if(b == '-'){
                minus = true;
                b = readByte();
            }
            if(b < '0' || '9' < b){
                throw new NumberFormatException();
            }
            while(true){
                if('0' <= b && b<='9'){
                    n*=10;
                    n+=b-'0';
                }else if(b==-1 || !isPrintableChar(b)){
                    return minus ? -n : n;
                }else{
                    throw new NumberFormatException();
                }
                b = readByte();
            }
        }
        public int nextInt(){
            long nl = nextLong();
            if(nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)throw new NumberFormatException();
            return (int)nl;
        }
        public double nextDouble(){return Double.parseDouble(next());}
    }
}

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

ll N;
using pint = pair<ll, ll>;
vector<pint> mem;
vector<ll> A;

int main() {
  cin >>N;
  mem.resize(N);
  A.resize(N - 1);
  for (int i = 0; i < N - 1; i++) cin >> A[i];
  for (int i = 0; i<N-1; i++){
    mem[A[i] - 1].second++;
  }
  for (int i = 0; i < N; i++) cout << mem[i].second << endl;
  return 0;
}

Measured memory_bytes: 12740
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,K;
  cin >> N;
  cin >> K;
  int min;
  
  for(int i=1;i<=N;i++){
    int x;
    x = 1*pow(2,i)+K*(N-i);
    if (i==1){
      min = x;
    }else{
	  if(x<min){
		min = x;
      }else{
        break;
      }
    }
  }
  cout << min <<endl;
}

Measured memory_bytes: 256
program exp
	implicit none
	integer :: y, c, i
	integer :: x

	read(*,*) x
	if ( x==1 ) then
    	write(*,*) 1
        stop
    end if
    
   	c = 1
	do i = 1, x
		do y = 2, x
			if (i**y <= x .and. i**y > c) then
				c = i ** y
			end if
		end do
	end do
	
	write(*,'(i0)') c
stop
end program exp

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

struct Rectangle{
    int height;
    int pos;
};

int getLargestRectangle(int size, int Hist[]){
    stack<Rectangle> S;
    int maxv=0;
    Hist[size]=0;

    for(int i=0; i<=size; i++){
        Rectangle rect;
        rect.height=Hist[i];
        rect.pos=i;

        if(S.empty()){
            S.push(rect);
        }
        else if(rect.height>S.top().height){
            S.push(rect);
        }
        else if(rect.height<S.top().height){
            int target=0; //changed later
            while(!S.empty() && rect.height<=S.top().height){
                Rectangle topRect=S.top(); S.pop();
                int area=topRect.height*(i-topRect.pos);
                maxv=max(maxv, area);
                target=topRect.pos;
            }
            rect.pos=target;
            S.push(rect);
        }
    }

    return maxv;
}

int H,W;
int Hist[1401][1401];

int solve(){
    int maxv=0;
    for(int i=0; i<H; i++){
        maxv=max(maxv, getLargestRectangle(W, Hist[i]));
    }

    return maxv;
}

int main(void){
    cin >> H >> W;
    int G[H][W];
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            cin >> G[i][j];
        }
    }

    //ヒストグラムを作る
    for(int j=0; j<W; j++){
        for(int i=0; i<H; i++){
            if(G[i][j]==1) Hist[i][j]=0;
            else Hist[i][j]= (i>0)? Hist[i-1][j]+1 : 1;
        }
    }

    cout << solve() << endl;
}


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

#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, b) FOR(, 0, b)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(), x.end()

using pi = pair<int, int>;
using vi = vector<int>;
using ld = long double;

int main() {
    int a, b, c;
    cin >> a >> b >> c;

    int cnt = a;
    while (cnt <= 10000) {
        if (cnt % b == c) {
            cout << "YES";
            return 0;
        }
        cnt += a;
    }

    cout << "NO";
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
  	int A, B, N, sum;
  	scanf("%d %d %d", &N, &A, &B);
    sum = A * N;
    if(sum >= B) {
        printf("%d", B);
    } else {
        printf("%d", sum);
    }
    return 0;
}

Measured memory_bytes: 128
N=int(input())
*A,=map(int,input().split())
M=1000*1000*1000+7
S=[0]*N

SS=0
for i in range(N-1,0,-1):
  S[i-1]=A[i]+S[i]
  SS+=A[i-1]*S[i-1]

print("{}".format(SS%M))

Measured memory_bytes: 31620
#include <bits/stdc++.h>
using namespace std;
 
int main(){

    int N , A ;

    cin >> N >> A ;

    if(N < 500){

        if(A < N){

            cout << "No" << endl;

        }

        if(A >= N){

            cout << "Yes" << endl;
            
        }
    
    } 

    if(N >= 500){

        if((N % 500) <= A){

            cout << "Yes" << endl;

        }

        if((N % 500) > A){

            cout << "No" << endl;
       
        }
    
    
    }





}




Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<stack>
#include<math.h>
#include<map>
#include<unordered_map> 
#include<vector>
#include<queue>
#include<set>
#include<deque> 
#include<bitset>
#include<string>
#define N 40
#define K 300005
#define MOD 1e9+7
#define int long long 
#define fastio  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;

int mod = 1e9 + 7;
int lim = 1e4 +1;

//denotes the number of numbers for pos i...end with rem of digit sum = j
//3rd index is for 0 if on border and 1 if not on border
int dp[10005][105][2];

string no;
int d;

int max(int a, int b){
	if(a > b)
		return a;
	return b;
}

int solve(int pos, int rem, int bor){
    //cout<<pos<<" "<<rem<<" "<<bor<<" "<<no[pos]<<endl;
    if(pos == lim){
        if(rem == 0)
            return 1;
        else
            return 0;
    }
    if(dp[pos][rem][bor] != -1)
        return dp[pos][rem][bor];
	int ans = 0;
	if(bor == 1){
		int last = no[pos] - '0';
		for(int i=0;i<=last;i++){
            int j = i %d;
			int rem_req = (rem + d - j)%d;
			if(i == last)
				ans += solve(pos + 1, rem_req, 1);
			else
				ans += solve(pos + 1, rem_req, 0);
			if(ans >= mod)
				ans %= mod;
		}
	}
	else{
		for(int i=0;i<10;i++){
            int j = i%d;
			int rem_req = (rem + d - j)%d;
			ans += solve(pos + 1, rem_req, 0);
			if(ans >= mod)
				ans %= mod;
		}
	}
    //cout<<pos<<" "<<rem<<" "<<ans<<endl;
	dp[pos][rem][bor] = ans;
	return dp[pos][rem][bor];
}

int32_t main(){
	cin>>no;
	cin>>d;
	
	int pad = lim - no.length();
	for(int i=0;i<pad;i++)
		no = '0' + no;
    //cout<<no<<endl;
	for(int i=0;i<lim;i++){
		for(int j=0;j<=100;j++){
			dp[i][j][0] = -1;
            dp[i][j][1] = -1;
		}
	}
    //cout<<"DDD"<<endl;
    //exit(0);
	int a1 = solve(0,0,1);
    //int a2 = solve(1,0, 1);
    //cout<<a1 -1<<endl;
	cout<<(a1 + mod - 1)%mod<<endl;
    
    

	
	
	
}



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

using namespace std;

int main() {
    int n;
    cin>>n;
    int i,a[n],b[n],c[n];
    for(i=1;i<=n;i++)
    cin>>a[i];
    for(i=1;i<=n;i++)
    cin>>b[i];
    for(i=1;i<=n;i++)
    c[i]=a[i]-b[i];
    int s=0;
    for(i=1;i<=n;i++)
    {
        if(c[i]>0)
        s=s+c[i];
        
    }
    cout<<s;
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
//--<for debugging>
#define whatis(x) cout << #x << " is " << x<<" ";
#define whatisl(x) cout << #x << " is " << x<<"\n";
#define parr(array,end)for(ll loop=0;loop<end;loop++)cout<<array[loop]<<" ";cout<<"\n";
#define lline cout<<"\n";
#define errorl(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args);cout<<"\n";}
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args);cout<<"___";}
    
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << *it << " = " << a <<" , ";
    err(++it, args...);
}
//--</for debugging> 
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define testcase ll tt; cin >> tt; while(tt--)
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back 
#define vars ll h,i,j,k,d,l,p,q,r,x,y,a,b,c,v,var,n,m,z,s,ans,ind1,ind2,flag,limit1,limit2,limit3,mod;
#define vll vector<ll>
#define pll pair<ll,ll>
#define sll set<ll>
#define pint pair<int,int>
const ll INF=1e9+7;
const ll MOD=1e9+7;
int main()
{
    boost vars
    s=0;
    testcase
    {
        cin>>a>>b;
        if(s==0){x=a;y=b;}
        p=x/a+(x%a>0);
        q=y/b+(y%b>0);
        x=a*max(p,q);y=b*max(p,q);
        s=1;
    }
    cout<<x+y;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iomanip>      // std::setprecision
using namespace std;
#define what_is(x) cerr << #x << " is " << x << endl;
#define bit(x,i) (x&(1<<i))  //select the bit of position i of x
#define lowbit(x) ((x)&((x)^((x)-1))) //get the lowest bit of x
#define hBit(msb,n) asm("bsrl %1,%0" : "=r"(msb) : "r"(n)) //get the highest bit of x, maybe the fastest
#define max(a,b) (a<b?b:a)
#define IN(i,l,r) (l<i&&i<r) //the next for are for checking bound
#define LINR(i,l,r) (l<=i&&i<=r)
#define LIN(i,l,r) (l<=i&&i<r)
#define INR(i,l,r) (l<i&&i<=r)
#define F(i,L,R) for (int i = L; i < R; i++) //next four are for "for loops"
#define FE(i,L,R) for (int i = L; i <= R; i++)
#define FF(i,L,R) for (int i = L; i > R; i--)
#define FFE(i,L,R) for (int i = L; i >= R; i--)
#define char2Int(c) (c-'0')
#define lastEle(vec) vec[vec.size()-1] 
#define SZ(x) ((int)((x).size()))
#define REMAX(a,b) (a)=max((a),(b)) // set a to the maximum of a and b
#define REMIN(a,b) (a)=min((a),(b));
#define FENWICK(k) (k&-k)
#define FOREACH(i,t) for (auto i=t.begin(); i!=t.end(); i++) // traverse an STL data structure
#define ALL(c) (c).begin(),(c).end() //handy for function like "sort()"
#define PRESENT(c,x) ((c).find(x) != (c).end()) 
#define CPRESENT(c,x) (find(ALL(c),x) != (c).end()) 
#define LL long long //data types used often, but you don't want to type them time by time
#define ull unsigned long long
#define ui unsigned int
#define us unsigned short
#define IOS ios_base::sync_with_stdio(0); //to synchronize the input of cin and scanf
#define INF 1001001001
#define PI 3.1415926535897932384626
//for map, pair
#define mp make_pair
#define fi first
#define se second
//for vectors
#define pb push_back
typedef int elem_t;
typedef vector<int> vi; 
typedef vector<vi> vvi; 
typedef pair<int,int> ii; 
// directions
const int fx[4][2] = {{0,1}, {0,-1}, {1,0}, {-1,0}};
const int fxx[8][2] = {{0,1}, {0,-1}, {1,0}, {-1,0}, {1,1}, {1,-1}, {-1,1}, {-1,-1}};
const int rogi[4][2] = { {1,1}, {1,-1}, {-1,1}, {-1,-1} };

struct val {
	string s;
	int val,idx;
};

bool comp_vals(val a, val b) {
	if(a.s == b.s) {
		return a.val > b.val;
	} 
	return a.s<b.s;
}

vector<val >vals; 
int n;

void dane() {
	cin>>n;
	F(i,0,n){
		val v;
		cin>>v.s>>v.val;
		v.idx = i+1;
		vals.push_back(v);
	}

	sort(ALL(vals), comp_vals);
	F(i,0,n) cout<<vals[i].idx<<endl;
}    


int main() {
	IOS
	// int t;
	// cin>>t;
	// F(i,0,t)
	    dane();
    return 0;
}

Measured memory_bytes: 256
N,Y=map(int, input().split())
for x in range(N+1):
    for y in range(N-x+1):
        z=N-x-y
        if x>=0 and 10000*x+5000*y+1000*z==Y:
            break
    else:
        continue
    break
else:
    x,y,z=[-1]*3

print(x,y,z)


Measured memory_bytes: 2940
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_6_C
// Sort II - Quick Sort

#define SUBMIT

#include <utility>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <vector>
#include <limits>
#include <numeric>
#include <set>
#include <cmath>
#include <cstring>
#include <climits>

using namespace std;
using i64 = long long;

struct card {
    char suit;
    int value;
};

void merge(vector<card>& A, int left, int mid, int right) {
    auto n1 = mid - left;
    auto n2 = right - mid;
    card L[n1 + 1], R[n2 + 1];
    for (int i = 0; i < n1; ++i) L[i] = A[left + i];
    for (int i = 0; i < n2; ++i) R[i] = A[mid + i];
    L[n1].value = R[n2].value = INT_MAX;

    auto i = 0, j = 0;
    for (int k = left; k < right; ++k) {
        if (L[i].value <= R[j].value) {
            A[k] = L[i];
            i++;
        } else {
            A[k] = R[j];
            j++;
        }
    }
}

void merge_sort(vector<card>& A, int left, int right) {
    if (left + 1 < right) {
        auto mid = (left + right) / 2;
        merge_sort(A, left, mid);
        merge_sort(A, mid, right);
        merge(A, left, mid, right);
    }
}

int partition(vector<card>& A, int p, int r) {
    auto x = A[r];
    auto i = p - 1;
    for (int j = p; j < r; ++j) {
        if (A[j].value <= x.value) {
            i++;
            swap(A[i], A[j]);
        }
    }
    swap(A[i + 1], A[r]);
    return i + 1;
}

void quick_sort(vector<card>& A, int p, int r) {
    if (p < r) {
        auto q = partition(A, p, r);
        quick_sort(A, p, q - 1);
        quick_sort(A, q + 1, r);
    }
}

int main() {
    int n;
    cin >> n;
    vector<card> c_quick(n);
    vector<card> c_merge(n);
    for (int i = 0; i < n; ++i) {
        char suit;
        int value;

        cin >> suit >> value;

        c_quick[i].suit = suit;
        c_quick[i].value = value;

        c_merge[i].suit = suit;
        c_merge[i].value = value;
    }

    merge_sort(c_merge, 0, n);
    quick_sort(c_quick, 0, n - 1);

    auto quick_stable = true;
    for (int i = 0; i < n; ++i) {
        if (c_merge[i].suit != c_quick[i].suit) quick_stable = false;
    }

    if (quick_stable) cout << "Stable" << endl;
    else cout << "Not stable" << endl;

    for (int i = 0; i < n; ++i) cout << c_quick[i].suit << " " << c_quick[i].value << endl;
    return 0;
}


Measured memory_bytes: 5148
N,M=map(int,input().split())
A=[int(x) for x in input().split()]
num=[2,5,5,4,5,6,3,7,6]

#最小本数で作成可能な数字をリスト化
creat_A=[]
for n in A:
  creat_A.append(num[n-1])

#dp[N]:N本のマッチ棒を使って作ることのできる最大桁数
dp=[-1 for _ in range(N+1)]
for i in range(M):
  if creat_A[i] <= N:
    dp[creat_A[i]]=1

for i in range(N):
  if dp[i]>0:
    for j in range(M):
      if i+creat_A[j] <= N:
        dp[i+creat_A[j]]=max(dp[i+creat_A[j]],dp[i]+1)

#dp[N]から使用した数字の数を算出。
ans=[0 for _ in range(10)]

now=N
while dp[now] > 0:
  res=-1
  temp_i=-1
  for i in range(M):
    if now-creat_A[i] >0 and dp[now-creat_A[i]]==dp[now]-1:
      if res < A[i]:
        res=A[i]
        temp_i=i
  if res==-1:
    break
  else:
    ans[res]+=1
    now-=creat_A[temp_i]
    
temp2=0
for i in range(M):
  if creat_A[i]==now:
    temp2=max(temp2,A[i])
ans[temp2]+=1

#答えの出力。最小から加えて逆向きに読めばOK
ansans=""
for i in range(10):
  if ans[i]>0:
    ansans+=(str(i)*ans[i])
ansans=ansans[::-1]
print(ansans)

Measured memory_bytes: 3428
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
	"strings"
)

func main() {
	io, flush := NewIO()
	defer flush()
	x, y, a, b, c := io.ScanInt(), io.ScanInt(), io.ScanInt(), io.ScanInt(), io.ScanInt()
	redApples := io.ScanInts(a)
	greenApples := io.ScanInts(b)
	colorlessApples := io.ScanInts(c)
	sort.Sort(sort.Reverse(sort.IntSlice(redApples)))
	sort.Sort(sort.Reverse(sort.IntSlice(greenApples)))
	sort.Sort(sort.Reverse(sort.IntSlice(colorlessApples)))

	apples := append(redApples[:x], greenApples[:y]...)
	apples = append(apples, colorlessApples...)
	sort.Sort(sort.Reverse(sort.IntSlice(apples)))
	io.Println(Sum(x+y, apples...))
}

func Sum(n int, nums ...int) (sum int) {
	for i := 0; i < n; i++ {
		sum += nums[i]
	}
	return sum
}

func Min(a, b int) int {
	if a > b {
		return a
	}
	return b
}

type IO struct {
	scanner *bufio.Scanner
	writer  *bufio.Writer
}

func NewIO() (*IO, func()) {
	io := &IO{
		scanner: newScanner(),
		writer:  newWriter(),
	}
	return io, func() { io.writer.Flush() }
}

func newScanner() *bufio.Scanner {
	s := bufio.NewScanner(os.Stdin)
	s.Buffer(make([]byte, 10000000), 10000000)
	s.Split(bufio.ScanWords)
	return s
}

func newWriter() *bufio.Writer {
	return bufio.NewWriter(os.Stdout)
}

func (io *IO) ScanBytes() []byte {
	if !io.scanner.Scan() {
		panic("scan string failed")
	}
	return io.scanner.Bytes()
}

func (io *IO) ScanString() string {
	if !io.scanner.Scan() {
		panic("scan string failed")
	}
	return io.scanner.Text()
}

func (io *IO) ScanStrings(n int) []string {
	strs := make([]string, n)
	for i := 0; i < n; i++ {
		strs[i] = io.ScanString()
	}
	return strs
}

func (io *IO) Scan2DStrings(y, x int) [][]string {
	strings := make([][]string, y)
	for i := 0; i < y; i++ {
		strings[i] = io.ScanStrings(x)
	}
	return strings
}

func (io *IO) Scan2DGraph(y int) [][]string {
	strs := make([][]string, y)
	for i := 0; i < y; i++ {
		strs[i] = strings.Split(io.ScanString(), "")
	}
	return strs
}

func (io *IO) ScanInt() int {
	return int(io.ScanInt64())
}

func (io *IO) ScanInts(n int) []int {
	ints := make([]int, n)
	for i := 0; i < n; i++ {
		ints[i] = io.ScanInt()
	}
	return ints
}

func (io *IO) Scan2DInts(y, x int) [][]int {
	ints := make([][]int, y)
	for i := 0; i < y; i++ {
		ints[i] = io.ScanInts(x)
	}
	return ints
}

func (io *IO) ScanInt64() int64 {
	i, err := strconv.ParseInt(io.ScanString(), 10, 64)
	if err != nil {
		panic(err)
	}
	return i
}

func (io *IO) ScanFloat64() float64 {
	i, _ := strconv.ParseFloat(io.ScanString(), 64)
	return i
}

func (io *IO) ScanFloat64s(n int) []float64 {
	floats := make([]float64, n)
	for i := 0; i < n; i++ {
		floats[i] = io.ScanFloat64()
	}
	return floats
}

func (io *IO) Println(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}


Measured memory_bytes: 16384