akhauriyash/Code-Regression huggingface dataset:
/*
 * @Filename: 
 * @Author: shifaqiang
 * @Email: 14061115@buaa.edu.cn
 * @Github: https://github.com/luoboganer
 * @Date: 2020-07-12 00:38:24
 * @LastEditors: shifaqiang
 * @LastEditTime: 2020-07-12 22:23:03
 * @Software: Visual Studio Code
 * @Description: 
 */

#include <algorithm>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>

using namespace std;

int main(int argc, char *argv[])
{
    int n, w, weight, value;
    cin >> n >> w;
    vector<long long> dp(w + 1, 0);
    for (auto i = 0; i < n; i++)
    {
        cin >> weight >> value;
        for (auto j = w; j >= weight; j--)
        {
            dp[j] = max(dp[j], dp[j - weight] + value);
        }
    }
    cout << dp[w] << endl;
    return 0;
}

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

using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define FORR(i, a, b) for(int i = (a); i > (b); --i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define VECCIN(x)                                                              \
    for(auto &youso_ : (x)) cin >> youso_
#define mp make_pair
#define bitcnt __builtin_popcount
#define All(a) (a).begin(), (a).end()
template <typename T = long long> inline T IN() {
    T x;
    cin >> x;
    return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&... tail) {
    cin >> head;
    CIN(move(tail)...);
}
#define CINT(...)                                                              \
    int __VA_ARGS__;                                                           \
    CIN(__VA_ARGS__)
#define LCIN(...)                                                              \
    ll __VA_ARGS__;                                                            \
    CIN(__VA_ARGS__)
#define SCIN(...)                                                              \
    string __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define Yes(a) cout << (a ? "Yes" : "No") << "\n"
#define YES(a) cout << (a ? "YES" : "NO") << "\n"

typedef long long ll;
typedef vector<int> V;
typedef vector<ll> VL;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef priority_queue<int> PQ;
typedef priority_queue<int, V, greater<int>> PQG;

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

ll N, K;
vector<V> edge;

int main() {
    cin >> N;
    edge.resize(N + 1);
    if(N % 2) {
        FOR(i, 1, N + 1) FOR(j, 1, i) {
            if(i + j != N) {
                edge[i].push_back(j);
            }
        }
        cout << N * (N - 2) / 2 + 1 << "\n";
    } else {
        FOR(i, 1, N + 1) FOR(j, 1, i) {
            if(i + j != N + 1) {
                edge[i].push_back(j);
            }
        }
        cout << N * (N - 2) / 2 << "\n";
    }
    FOR(i, 1, N + 1) REP(j, edge[i].size()) {
        cout << i << " " << edge[i][j] << "\n";
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vout(x) rep(i,x.size()) cout << x[i] << " "
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll,ll>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 2*1e5;
const int mod = 1e9+7;

int main() {
    string s1, s2, s3; cin >> s1 >> s2 >> s3;
    char a = s1[0];
    char b = s2[0];
    char c = s3[0];
    a += 'A' - 'a';
    b += 'A' - 'a';
    c += 'A' - 'a';
    cout << a << b << c << endl;
}

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

#include <iostream>
//#include <algorithm>
// #include <iomanip>
#define ll long long
#define map unordered_map
#define set unordered_set

using namespace std;

const ll MOD = 1000000007;

const ll INF = (1LL << 62);

ll dp[105][100005];

int main() {
  ll N, W;
  scanf("%lld %lld", &N, &W);

  vector<pair<ll, ll>> list(N);
  for (ll i = 0; i < N; i++) {
    ll n, w;
    scanf("%lld %lld", &n, &w);
    list[i] = make_pair(n, w);
  }

  fill(dp[0], dp[104], INF);
  dp[0][0] = 0;

  for (ll i = 0; i < N; i++) {
    ll w = list[i].first;
    ll v = list[i].second;

    for (ll sum_v = 0; sum_v < 100005; sum_v++) {
      if (sum_v >= v) {
        dp[i + 1][sum_v] = min(dp[i + 1][sum_v], dp[i][sum_v - v] + w);
      }
      dp[i + 1][sum_v] = min(dp[i + 1][sum_v], dp[i][sum_v]);
    }
  }

  ll ans = 0;
  for (int sum_v = 0; sum_v < 100005; sum_v++) {
    if (dp[N][sum_v] <= W) {
      ans = sum_v;
    }
  }

  cout << ans << endl;

  // for (ll i = 0; i < 4; i++) {
  //   for (ll j = 0; j < 16; j++) {
  //     cout << dp[i][j] << " ";
  //   }
  //   cout << " " << endl;
  // }
}


Measured memory_bytes: 82176
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
typedef int64_t Int;

int main(){
    Int K, N; vector<Int> A(200010);

    cin >> K >> N;
    rep(i,N) cin >> A[i];

    Int max_dist = 0;
    rep1(i,N-1){
        max_dist = max(max_dist, A[i]-A[i-1]);
    }
    max_dist = max(max_dist, K-A[N-1]+A[0]);

    cout << K - max_dist << endl;
}

Measured memory_bytes: 1920
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int main(){
  string n;
  cin >> n;
  int ye,mo;
  ye=(n[0]-'0')*10+(n[1]-'0');
  mo=(n[2]-'0')*10+(n[3]-'0');
  if(ye>=1 && ye<=12 && mo>=1 && mo<=12){
    cout << "AMBIGUOUS" << endl;
  }
  else if(ye>=1 && ye<=12){
    cout << "MMYY" << endl;
  }
  else if(mo>=1 && mo<=12){
    cout << "YYMM" << endl;
  }
  else{
    cout << "NA" << endl;
  }
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
 
using namespace std;
inline void prep ()
{
  cin.tie (0);
  cin.sync_with_stdio (0);
};
const double pi = acos(-1.);
//printf(%.12lf\n,mid);
// __builtin_popcount(int) count 1's in binary
// get decimal part of number
/*
double intpart;
double thiss = modf((double)(n*m)/(double)k, &intpart);
*/
// round = (int)(num+.5)
long long mod = 1000000007;
 
long long mymod(long long num){
  if (num< 0 && !(num%mod == 0)){
    if (mod == 1){
      return 0;
    }
    return mod-abs(num)%mod;
  }else{
    return num%mod;
  }
}
 
/*string sentence = And I feel fine...;
    istringstream iss(sentence);
*/  
 
double eps = .000000001;
long long arr[200000];
int ternsearch(int l, int r){
    int origr = r;
    int origl = l;
    r--;
   int lastmid1 = -1;
   int lastmid2 = -1;
   int mid1 = 0;
   int mid2 = 0;
   while (true){
     mid1 = (r-l)/3+l;
     mid2 = r-(r-l)/3;
     if (mid1 == lastmid1 && mid2 == lastmid2){
       break;
     }
     long long sum1r = arr[origr]-arr[mid1];
     
     long long sum2r = arr[origr]-arr[mid2];
     long long sum1l, sum2l; 
     if (origl == 0){
         sum1l = arr[mid1];
         sum2l = arr[mid2];
     }else{
         sum1l = arr[mid1]-arr[origl-1];
         sum2l = arr[mid2]-arr[origl-1];
     }
     
     if (abs(sum1l-sum1r) > abs(sum2l-sum2r)){
       l = mid1+1;
     }else if (abs(sum1l-sum1r) < abs(sum2l-sum2r)){
       r = mid2-1;
     }else{
       l = mid1;
     }
     lastmid1 = mid1;
     lastmid2 = mid2;
   }
   return lastmid1;
}
int main(){
  prep();
  int n;
  cin >> n;
  
  for (int i=0; i<n; i++){
      cin >> arr[i];
  }
  for (int i=1; i<n; i++){
      arr[i] = arr[i]+arr[i-1];
  }
  long long minn = 1000000000000000000LL;
  for (int i=1; i<n-2; i++){
      // in the space after element i
      int lastgood1 = ternsearch(0, i);
      int lastgood2 = ternsearch(i+1, n-1);
      long long sum1 = arr[lastgood1];
      long long sum2 = arr[i]-arr[lastgood1];
      long long sum3 = arr[lastgood2]-arr[i];
      long long sum4 = arr[n-1]-arr[lastgood2];
      long long lst[4] = {sum1, sum2, sum3, sum4};
      sort(lst, lst+4);
      //cout << sum1 << " " << sum2 << " " << sum3 << " " << sum4 << endl;
      minn = min(minn, lst[3]-lst[0]);
  }
  cout << minn;
  return 0; 
}

Measured memory_bytes: 1792
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define MOD 1000000007
#define INF 1e9
#define PIE 3.14159265358979323

template <class T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
T GCD(T a, T b) {
    if (b == 0)
        return a;
    else
        return GCD(b, a % b);
}
template <class T>
inline T LCM(T a, T b) {
    return (a * b) / GCD(a, b);
}
#define int long long

signed main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    int sum = 0;
    int b = 1;
    for (int d = 0; d < 60; d++) {
        int odd = 0;
        int even = 0;
        for (int i = 0; i < n; i++) {
            if (a[i] & (1LL << d))
                odd++;
            else
                even++;
        }
        int add = (odd * even) % MOD;
        add = (add * b) % MOD;
        b = (b * 2) % MOD;
        sum = (sum+add) % MOD;
    }
    cout << sum << endl;
}

Measured memory_bytes: 2560
#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;
	cin >> N;
	ll H[N];
	rep(i,N) cin >> H[i];

	for (int i = N-2; i >=0; i--) {
		if (H[i]-H[i+1] == 1) H[i]--;	
		if (H[i]-H[i+1] > 1) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;

	return 0;
}


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

int main(){
  string a;
  cin>>a;
  for(int i=0;i<a.size();i++){
    if(a.at(i)=='9'){
      cout<<"Yes"<<endl;
      break;
    }
    if(i==a.size()-1)
      cout<<"No"<<endl;
  }
}

Measured memory_bytes: 256
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
''' 
------------------------
author : iiou16
------------------------
'''

def main():
    N = int(input())
    D = list(map(int, input().split()))

    out = []
    for i in range(N):
        for j in range(i, N):
            if i != j:
                out.append(D[i] * D[j])
    print(sum(out))


if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
const int inf = 1e17;
typedef pair<int, int> P;
typedef pair<int,P> PP;

struct BIT {
	int N; vector<int> bit;
	void init(int n) {
		N = n;
		bit.resize(n+1);
	}
	int sum(int i) {
		int s = 0;
		while (i > 0) {
			s += bit[i];
			i -= i&-i;
		}
		return s;
	}
	void add(int i, int x) {
		while (i <= N) {
			bit[i] += x; i += i&-i;
		}
	}
};
BIT B;
deque<int>Q[26];

signed main() {
	string s; cin >> s;
	int n = s.size();
	B.init(n);
	rep(i, n)B.add(i + 1, 1);
	rep(i, n) {
		Q[s[i] - 'a'].push_back(i+1);
	}
	int cnt = 0; rep(i, 26)cnt += 1 & (Q[i].size());
	if (cnt>1) {
		puts("-1"); return 0;
	}
	int ans = 0;
	rep(i, n / 2) {
		int cost = inf;
		int nl = 0;
		rep(j, 26) {
			if (Q[j].size() > 1) {
				int l = Q[j].front(), r = Q[j].back();
				int ncost =B.sum(l - 1) + B.sum(n) - B.sum(r);
				if (ncost < cost) {
					cost = ncost; nl = j;
				}
			}
		}
		B.add(Q[nl].front(), -1);
		B.add(Q[nl].back(), -1);
		Q[nl].pop_back();
		Q[nl].pop_front();
		ans += cost;
	}
	cout << ans << endl;
}

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

int main() {
	// your code goes here
	int n;
	cin>>n;
	string s;
	cin>>s;
	int j=0;
	int count=0;
	for(int i=1;i<s.size();i++)
	{
		if(s[i]==s[j])
		  continue;
		else if(s[i]!=s[j])
		 {
		 	count++;
		 	j=i;
		 }
	}
	cout<<count+1;
	return 0;
}

Measured memory_bytes: 512
n, m = map(int, input().split())
st = []
cp = []
for i in range(n):
    st.append(list(map(int, input().split())))
for i in range(m):
    cp.append(list(map(int, input().split())))

for i in range(n):
    distance = 0
    shortest_cp = 0
    for j in range(m):
        if j == 0:
            distance = 1
            shortest_cp = abs(st[i][0]-cp[j][0]) + abs(st[i][1]-cp[j][1])
        else:
            if (abs(st[i][0]-cp[j][0]) + abs(st[i][1]-cp[j][1])) < shortest_cp:
                distance = j + 1
                shortest_cp = abs(st[i][0]-cp[j][0]) + abs(st[i][1]-cp[j][1])
                
    print(distance)

Measured memory_bytes: 9236
#include <bits/stdc++.h>
#include <cmath>
#include <limits>

using namespace std;
typedef long long LL;
static long long INF = (1LL<<62);

using Graph = vector<vector<int>>;
using LLPair = pair<LL, LL>;
using WeightedGraph = vector<vector<LLPair>>;
using PriorityQ = priority_queue<LLPair, vector<LLPair>, greater<LLPair>>;

void dijkstra(WeightedGraph &WG, vector<LL> &D, LL s){
	for(int i=0; i<D.size(); i++){
		D[i] = INF;
	}
	D[s] = 0;

	PriorityQ pq;
	pq.push(make_pair(0, s));
	while(!pq.empty()){
		LL pos = pq.top().second; pq.pop();
		for(auto nv : WG[pos]){
			LL to = nv.first; 
			LL cost = nv.second;
			if(D[to] > D[pos] + cost){
				D[to] = D[pos] + cost; 
				pq.push(make_pair(D[to], to));
			}
		}
	}
	return;
}

int main(int argc, char* argv[]){
	cin.tie(0);
	ios::sync_with_stdio(false);

	int N; cin >> N;

	WeightedGraph WG(N);
	for(int i=0; i<N-1; i++){
		int a, b, c; cin >> a >> b >> c;
		a--; b--;
		WG[a].push_back(make_pair(b, c));
		WG[b].push_back(make_pair(a, c));
	}

	int Q, K; cin >> Q >> K; K--;
	vector<LL> dist(N);
	dijkstra(WG, dist, K);
	for(int i=0; i<Q; i++){
		int x, y; cin >> x >> y;
		x--; y--;
		LL d = dist[x] + dist[y];
		printf("%lld\n", d);
	}
	return 0;
}

Measured memory_bytes: 14036
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n, k; cin >> n >> k;
  vector<int> f(k + 1, 0);
  const int mod = 1000000007;
  f[0] = 1;
  for(int i = 0; i < n; i++){
    int x; cin >> x;
    vector<int> nf(k + 1, 0);
    int sum = 0;
    for(int j = 0; j <= k; j++){
      sum += f[j]; if(sum >= mod) sum -= mod;
      if(j > x) {
        sum += mod - f[j - x - 1];
        if(sum >= mod) sum -= mod;
      }
      nf[j] = sum;
    }
    f = nf;
  }
  cout << f[k] << endl;
  return 0;
}


Measured memory_bytes: 1024
using System;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            MainStream();
        }
        static void MainStream()
        {
            string[] N_K = Console.ReadLine().Split(' ');
            int n = int.Parse(N_K[0]);
            int k = int.Parse(N_K[1]);

            if(n%k == 0)
            {
                Console.WriteLine("0");
            }
            else
            {
                Console.WriteLine("1");
            }
        }
    }
}


Measured memory_bytes: 11092
//おまじない
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  
  cin>>n;
  vector<long int> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v.at(i);}
  
  sort(v.begin(),v.end());
  
  long int max=v.at(n/2);
  long int min=v.at(n/2-1);
  
  if(max>min){
    cout<<max-min<<endl;}
  else{cout<<0<<endl;}
}

Measured memory_bytes: 1024
//============================================================================
// Name        : test.cpp
// Author      : Qihan
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <bits/stdc++.h>
#define pi acos(-1.0)
using namespace std;
typedef long long int LLI;
typedef pair<LLI,LLI> PII;
#define Lowbit(x) (x & (-x))
const int inf = 0x3f3f3f;
const int maxn = (500000 + 10);

char str[maxn];

int main() {
//    freopen("/home/qihan/Documents/in","r",stdin);
//    freopen("/home/qihan/Documents/out","w",stdout);
	scanf("%s",str);
	for(int i = 0;str[i] != '\0';i ++){
        if(str[i] == ',')   printf(" ");
        else                printf("%c",str[i]);
	}
	printf("\n");
	return 0;
}


Measured memory_bytes: 256
#@k0gane_p 
a, b, c, d = [int(i) for i in input().split()]
def gcd(x,y):#最大公約数
    while y:
        x,y = y, x%y
    return x
def lcm(x,y):#最小公倍数
    return x*y // gcd (x,y)
def count(A,B,C):#A以下で、BでもCでも割り切れない個数
    D=A//B
    E=A//C
    F=A // lcm(B,C)#Fは両方で割り切れる、最小公倍数で割り切れる
    return A-D-E+F#包除原理
ans = count(b, c, d) - count(a-1, c, d)
#A以上B以下の整数のうち、CでもDでも割り切れないものの個数
#Aを引く１することで、A以上が分かる
#if(a % c != 0 and a % d != 0):
    #ans += 1#AがCでもDでも割り切れないなら、足す１
print(ans)

Measured memory_bytes: 3064
#include<stdio.h>
int main(void){
  int k,i,j=0,s[10000],f,b;
  scanf("%d",&k);
  for(i=1;i<=k;i++){
    scanf("%d%d",&f,&b);
    s[i]=((b-f)+1);
  }
  for(i=1;i<=k;i++){
    j+=s[i];
  }
  printf("%d",j);
  return(0);
}


Measured memory_bytes: 128
#include <stdio.h>
#include <math.h>
#define N 10000

int hantei(int);

int main()
{
  int n,i,a[N],x,result;
  int cnt=0;

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

  for(i=0 ; i<n ; i++)
    {
      x = a[i];
      result = hantei(x);

      if(result == 1)
      {
        cnt++;
      }
    }

  printf("%d\n",cnt);

  return 0;
}

int hantei(int x)
{
  int i;

  if(x == 2) return 1;

  else if(x<2 || x%2 == 0) return 0;
  else
  {
    i=3;
    while(i <= sqrt(x))
    {
      if(x % i == 0) return 0;
      i = i + 2;
    }
  }

  return 1;

}



Measured memory_bytes: 2032
#include <iostream>
using namespace std;
int main()
{
  int r , g , b ;
  
  cin >> r >> g >> b ;
	if ( (r * 100 +  g * 10 + b) % 4 == 0 ) {
     cout << "YES" << endl;
   }
  
  else {
  cout << "NO" << endl;
  }
}

Measured memory_bytes: 256
def calcs(x,y,ax,ay,bx,by) ((ax-x)*(by-y)-(bx-x)*(ay-y))/2.0 end
def inpf() a=gets.chomp.split(" ").map(&:to_f)end
def inps() a=gets.chomp.split(" ")end  
def copy(a) Marshal.load(Marshal.dump(a)) end
def factorial(n)(n < 2)? 1 : (2..n).inject(:*) end
def scount(a) b=na(a.max+1);a.each{|n|b[n]+=1};return b end
def na(n,d=0) Array.new(n,d)end
def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end
def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end
def bit(n) n.to_s(2).split("").map(&:to_i) end
def inp() a=gets.chomp.split(" ").map(&:to_i)end
l = inp[0]
n2 = l.to_s(2).size
n = n2 
ans = []
kk = 2**(n2-1)
k = 2**(n2-2)
(1..(n-1)).each do |i|
  ans.push([i,i+1,0])
  ans.push([i,i+1,k])
  k/=2
end
ll = l.to_s(2)
ll = ll[1...(ll.size)]
l = ll.to_i(2)
while(l != 0)
  ll = l.to_s(2)
  ans.push([1,(n-ll.size+1),kk])
  kk += 2**(ll.size-1)
  ll = l.to_s(2)
  ll = ll[1...(ll.size)]
  l = ll.to_i(2)
end
puts "#{n} #{ans.size}"
ans.each do |a|
  puts "#{a[0]} #{a[1]} #{a[2]}"
end

Measured memory_bytes: 3836
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
int mod= pow(10,9) +7;
int main() {
  
int n,m;
cin>>n>>m;

char grid[n][m];

for(int i=0;i<n;i++){
    for(int j=0;j<m;j++){
        cin>>grid[i][j];

    }
}

ll dp[n][m];

for(int i=0;i<n;i++){
    for(int j=0;j<m;j++){
        dp[i][j]=0;

    }
}
dp[0][0]=1;

for(int i=0;i<n;i++){
    for(int j=0;j<m;j++){
        
        
        if(grid[i][j]=='#'){
            continue;
        }
        
        if(i-1>=0){
            dp[i][j]+=dp[i-1][j];
            dp[i][j]%=mod;
        }

        
        if(j-1>=0){
            dp[i][j]+=dp[i][j-1];
            dp[i][j]%=mod;
        }
        
    }
}

cout<<dp[n-1][m-1]%mod;







return 0;

}


Measured memory_bytes: 9088
#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--)

using namespace std;
using ll = long long;

int MOD;

class mint {
  int n;
public:
  mint(int n_ = 0) : n(n_) {}
  explicit operator int() { return n; }
  friend mint operator-(mint a) { return -a.n + MOD * (a.n != 0); }
  friend mint operator+(mint a, mint b) { int x = a.n + b.n; return x - (x >= MOD) * MOD; }
  friend mint operator-(mint a, mint b) { int x = a.n - b.n; return x + (x < 0) * MOD; }
  friend mint operator*(mint a, mint b) { return (long long)a.n * b.n % MOD; }
  friend mint &operator+=(mint &a, mint b) { return a = a + b; }
  friend mint &operator-=(mint &a, mint b) { return a = a - b; }
  friend mint &operator*=(mint &a, mint b) { return a = a * b; }
  friend bool operator==(mint a, mint b) { return a.n == b.n; }
  friend bool operator!=(mint a, mint b) { return a.n != b.n; }
  friend istream &operator>>(istream &i, mint &a) { return i >> a.n; }
  friend ostream &operator<<(ostream &o, mint a) { return o << a.n; }
};

mint modinv(mint n) {
  int a = (int)n;
  int b = MOD;
  int s = 1;
  int t = 0;
  while (b != 0) {
    int q = a / b;
    a -= q * b;
    s -= q * t;
    swap(a, b);
    swap(s, t);
  }
  if (s < 0) s += MOD;
  return s;
}

vector<mint> prod(vector<mint> a, vector<mint> b) {
  const int n = a.size();
  const int m = b.size();
  vector<mint> ans(n + m - 1);
  rep(i, n) {
    rep(j, m) {
      ans[i + j] += a[i] * b[j];
    }
  }
  return ans;
}

// a / (x - b)
vector<mint> quot(vector<mint> a, mint b) {
  const int n = a.size();
  vector<mint> ans(n - 1);
  for (int i = n - 1; i >= 1; i--) {
    ans[i - 1] = a[i];
    a[i - 1] += a[i] * b;
  }
  return ans;
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cin >> MOD;
  int N = MOD;
  vector<mint> a(N); rep(i, N) cin >> a[i];
  vector<mint> b(N);
  vector<mint> f(1);
  f[0] = 1;
  rep(i, N) {
    f = prod(f, vector<mint>{-mint(i), 1});
  }
  rep(i, N) {
    mint p = 1;
    rep(j, N) if (i != j) {
      p *= mint(i) - mint(j);
    }
    p = a[i] * modinv(p);
    // (x-0) ... (x-N+1)
    auto g = quot(f, i);
    rep(j, N) {
      b[j] += p * g[j];
    }
  }
  rep(i, N) cout << b[i] << ' ';
  cout << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define mod 1000000007
#define ll long long 
#define f(j) for(ll i=0;i<j;i++)
#define pb(i) push_back(i)
#define faster ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;    
typedef vector<vector<long long> > matrix; 
int main(){
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
	// faster
	string s;
	cin>>s;
	ll ans=0;
	f(s.size())	ans+=s[i]-'0';
	if(ans%9)
		cout<<"No\n";
	else
		cout<<"Yes\n";	
return 0;	
}

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

#define int long long
typedef pair<int, int> P;
#define mod 1000000007
#define INF (1LL<<60)
 
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
#define YES puts("YES")
#define Yes puts("Yes")
#define NO  puts("NO")
#define No  puts("No")
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
 
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
 
 
#if 1
//-------------
// DUMPマクロ
// https://www.creativ.xyz/dump-cpp-652/
 
// vector
template <typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    for (T& x : vec) is >> x;
    return is;
}
// pair
template <typename T, typename U>
ostream& operator<<(ostream& os, pair<T, U>& pair_var) {
    os << "(" << pair_var.first << ", " << pair_var.second << ")";
    return os;
}
// vector
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
// map
template <typename T, typename U>
ostream& operator<<(ostream& os, map<T, U>& map_var) {
    os << "{";
    repi(itr, map_var) {
        os << *itr;
        itr++;
        if (itr != map_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
// set
template <typename T>
ostream& operator<<(ostream& os, set<T>& set_var) {
    os << "{";
    repi(itr, set_var) {
        os << *itr;
        itr++;
        if (itr != set_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
 
#define DUMPOUT cerr
 
void dump_func() {
    DUMPOUT << endl;
}
template <class Head, class... Tail>
void dump_func(Head&& head, Tail&& ... tail) {
    DUMPOUT << head;
    if (sizeof...(Tail) > 0) {
        DUMPOUT << ", ";
    }
    dump_func(std::move(tail)...);
}
#ifdef DEBUG
#define DEB
#define dump(...)                                                              \
    DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                            \
            << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]"        \
            << endl                                                            \
            << "    ",                                                         \
        dump_func(__VA_ARGS__)
#else
#define DEB if (false)
#define dump(...)
#endif
#endif


signed main() {

    string A,B,C;
    cin >> A >> B >> C;

    char t='a';
    while(true){
        if(t=='a'){
            if(A.size()==0){ cout << "A" << endl; return 0;}
            t=A[0];
            A = A.substr(1,A.size()-1);
        }
        else if(t=='b'){
            if(B.size()==0){ cout << "B" << endl; return 0;}
            t=B[0];
            B = B.substr(1,B.size()-1);
        }
        else if(t=='c'){
            if(C.size()==0){ cout << "C" << endl; return 0;}
            t=C[0];
            C = C.substr(1,C.size()-1);
        }
    }
    
    
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string str1,str2;
    cin>>str1;
    cin>>str2;
    int cnt=0;
    for(int i=0;i<3;i++)
    {
        if(str1[i]==str2[i])
            cnt++;
    }
    cout<<cnt<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>
#include <deque>
#include <iomanip>
#include <cstdio>
#include <stack>
#include <numeric>

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf 1000000007
#define mod 1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)

template<typename T> class BIT {
private:
	int n;
	vector<T> bit;
public:
	// 0_indexed で i 番目の要素に x を加える
	void add(int i, T x){
		i++;
		while(i < n){
			bit[i] += x, i += i & -i;
		}
	}
	// 0_indexed で [0,i] の要素の和(両閉区間！！)
	T sum(int i){
		i++;
		T s = 0;
		while(i > 0){
			s += bit[i], i -= i & -i;
		}
		return s;
	}
	BIT(){}
	//初期値がすべて0の場合
	BIT(int sz) : n(sz+1), bit(n, 0){}
	BIT(vector<T>& v) : n((int)v.size()+1), bit(n, 0){
		for(int i = 0; i < n-1; i++){
			add(i,v[i]);
		}
	}
	void print(){
		for(int i = 0; i < n-1; i++){
			cout << sum(i) - sum(i-1) << " ";
		}
		cout << "\n";
	}
	//-1スタート
	void print_sum(){
		for(int i = 0; i < n; i++){
			cout << sum(i-1) << " ";
		}
		cout << "\n";
	}
};

//u を昇順にソートするのに必要な交換回数(転倒数) (u は (0~n-1の並び替え))
long long inv_count(vector<ll>& u)
{
	int n = (int)(u.size());
	BIT<ll> bt(n);
	long long ans = 0;
	for(int i = 0; i < n; i++){
		ans += i-bt.sum(u[i]);
		bt.add(u[i],1);
	}
	return ans;
}
map<ll,ll> zip;
ll unzip[400000];

int compress(vector<ll> &x) {
    sort(x.begin(), x.end());
    x.erase(unique(x.begin(),x.end()),x.end());
    for(int i = 0; i < x.size(); i++){
        zip[x[i]] = i;
        unzip[i] = x[i];
    }
    return x.size();
}
int main(){
    ll n,k;
    cin >> n >> k;
    vector<int>a(n);
    rep(i,n)cin >> a[i];
    ll p[2010]={};
    ll q[2010]={};
    rep(i,n){
        p[a[i]]++;
    }

    rep(i,2010){
        if(i==0)q[i] = p[i];
        else q[i] = p[i]+q[i-1];
    }
    ll res = 0;
    ll s = (k*(k-1))/2;
    s %= mod;
    rep(i,2010){
        if(i==0)continue;
        res += s*p[i]*q[i-1]%mod; 
        res %= mod;
    }
    //cerr << res << endl;
    vector<ll> v,u;
    ll pp = 10000;
    map<int,int>mp;
    rep(i,n){
        v.push_back(pp*a[i]+mp[a[i]]);
        mp[a[i]]++;
    }
	u = v;
	compress(u);
    for(int i=0;i<n;i++){
		v[i] = zip[v[i]];
	}
	ll sm = inv_count(v);
    //cerr << sm << endl;
	cout << (res+(sm*k%mod))%mod << endl;;
    return 0;
}

Measured memory_bytes: 888
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <numeric>
typedef long long Int;
#define rep(i,a,b) for(Int i=a;i<b;++i)
#define rrep(i,a,b) for(Int i=a;i>=b;--i)
using namespace std;

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

    int W, a, b; cin >> W >> a >> b;
    if (a > b) swap(a, b);
    cout << max(0, b-a-W) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define lln long long int
#define llu unsigned lln
#define sc(n) scanf("%d",&n);
#define scl(n) scanf("%lld",&n);
#define scd(n) scanf("%lf",&n);
#define pf(res) printf("%d\n",res);
#define pfl(res) printf("%lld\n",res);
#define pfd(res) printf("%lf\n",res);
#define pb(n) push_back(n);
#define maxii 200005
using namespace std;
typedef pair<int,int> pii;
typedef pair<lln,lln> pll;
vector<int> vi;
vector<lln> vl;
vector<pii> vii;
vector<pll> vll;


char arr[maxii];
llu arr2[maxii];
//bool check[maxii];
bool check2[1000][1000];
//lln n,m;
llu gcd(llu a,llu b)
{
    if(b==0){
      return a;
     }
    return gcd(b,a%b);
}


int main()
{
    string a;
    cin>>a;
    int len=a.size();
    int c=0;
    int ans=0;
    int r=1;
    for(int i=len-1;i>=0;i-=2)
    {
        int p=i/2;
        c=0;
        for(int j=0,k=p;j<p;j++,k++)
        {
            if(a[j]!=a[k])
            {
                c=1;
                break;
            }
        }
        if(c==0)
        {
            ans=r*2;
            break;
        }
        r++;
    }
    cout<<len-ans;

}






Measured memory_bytes: 3576
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int top, S[1000];


void push(int x){
    top++;
    S[top] = x;
}

int pop(){
    top--;
    return S[top+1];
}


int main(void) {
    int a,b;
    top=0;
    char s[100];
    while( scanf("%s",s) != EOF){
        if( s[0]=='+'){
            a = pop();
            b = pop();
            push(a+b);
        } else if( s[0] == '-'){
            b=pop();
            a=pop();
            push(a-b);
        } else if( s[0] == '*'){
            a = pop();
            b= pop();
            push(a *b);
        } else{
            push(atoi(s));
        }
    }
    
    printf("%d\n",pop());
    
    return 0;
}

Measured memory_bytes: 548
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
 


public class Main {
	private static Scanner sc = new Scanner(System.in);
	//result = Math.pow(num1, num3)
	//StringBuffer str = new StringBuffer(hoge1);
	//String hoge2 = str.reverse().toString();
	//map.containsKey(A)

	//Map<String, Integer> map = new HashMap<String, Integer>(n);
	/*for ( キーのデータ型 key : マップの名前.keySet() ) {
		データのデータ型 data = マップの名前.get( key );
		
		// keyやdataを使った処理;
	}*/
	//int i = Integer.parseInt(s);
	//Queue<String> qq=new ArrayDeque<>(); //add,poll,peek
	//Deque<String> qq=new ArrayDeque<>();//push,pop,peek
	//ArrayList<String> cc = new ArrayList<>(n);
	//Collections.sort(list);
	//Array.sort(list);   cc.contains(tmp)
	//Arrays.asList(c).contains("a")
	//list.set(1,"walk");//1 1 2 3 5
	//static long mod =1000000007;
	//static 	ArrayList<Integer> cc = new ArrayList<>(100);
	static int N;
	public static void main(String[] args) {
		
		N=sc.nextInt();
		long Y=sc.nextLong();
		int g=-1,f=-1,d=-1;
		boolean x=true;;
		for(int a=0;x&&a*10000<=Y;a++) {
			
			for(int b=0;x&&a*10000+b*5000<=Y;b++) {
				int c=(int) ((Y-a*10000-b*5000)/1000);
				if(a+b+c==N) {
					x=false;
					g=a;
					f=b;
					d=c;
					break;
				}
			}
			
		}
		p(g+" "+f+" "+d);
		
		
		
	}
	static int a,b,c;
	
	
	
	
	/*static boolean v(int i,long sum1,long sum2) {
		if(i==N) {
			long b=Math.abs(sum1-sum2);
			if(b==0) {
				if(sum1<=K) {
					return true;
				}else return false;
			}else if(b%D==0) {
				if(Math.max(sum1, sum2)<=K)return true;
				else return false;
			}
			else return false;
		}
		
		if(v(i+1,sum1,sum2+v[i]%D))return true;
		
		if(v(i+1,sum1+D-v[i]%D,sum2))return true;
		return false;
		
	}*/
	
	
	
	
	

	


	
	static void p(String ans) {System.out.println(ans);};
	static void p(int ans) {System.out.println(ans);};
	static void p() {System.out.println();};
	static void p(long ans) {System.out.println(ans);};
	static void p(double ans) {System.out.println(ans);};
	public static int gcd(int a, int b) {
        return b == 0 ? a: gcd(b, a % b);
	}
	static String nextPermutation(String s) {
		ArrayList<Character> list=new ArrayList<>();
		for(int i=0;i<s.length();i++) {
			list.add(s.charAt(i));
		}
		int pivotPos=-1;
		char pivot=0;
		for(int i=list.size()-2;i>=0;i--) {
			if(list.get(i)<list.get(i+1)) {
				pivotPos=i;
				pivot=list.get(i);
				break;
			}
		}
		if(pivotPos==-1&&pivot==0) {
			return "Final";
		}
		int L=pivotPos+1,R=list.size()-1;
		
		
		
		int minPos=-1;
		char min =Character.MAX_VALUE;
		
		for(int i=R;i>=L;i--) {
			if(pivot<list.get(i)) {
				if(list.get(i)<min) {
					min=list.get(i);
					minPos=i;
				}
			}
		}
		
		Collections.swap(list, pivotPos, minPos);
		Collections.sort(list.subList(L, R+1));
		
		
		StringBuilder sb=new StringBuilder();
		for(int i=0;i<list.size();i++) {
			sb.append(list.get(i));
		}
		return sb.toString();
	}
}
	


Measured memory_bytes: 22996
#include<iostream>
using namespace std;
#define rep() for(int i = 1;i <= 3;i++)
char map[10][10];
void sim(int x,int y) {
	map[x][y] = '0';
	rep(){
		if (x - i <= 0)break;
		else if (map[x - i][y] == '1')sim(x - i, y);
	}
	rep(){
		if (x + i >= 9)break;
		else if (map[x + i][y] == '1')sim(x + i, y);
	}
	rep() {
		if (y - i <= 0)break;
		else if (map[x][y - i] == '1')sim(x, y - i);
	}
	rep() {
		if (y + i >= 9)break;
		else if (map[x][y + i] == '1')sim(x, y + i);
	}
	return;
}
void input() {
	for (int i = 1; i <= 8; i++) { for (int j = 1; j <= 8; j++)cin >> map[i][j]; }
	return;
}
void output() {
	for (int i = 1; i <= 8; i++) { 
		for (int j = 1; j <= 8; j++) cout << map[i][j]; 
		cout << endl;
	}
	return;
}
int main() {
	int n; cin >> n;
	for (int i = 0; i < n; i++){
		input();
		int x, y;
		cin >> x >> y;
		sim(y,x);
		cout << "Data " << i + 1 << ":\n";
		output();
	}
}

Measured memory_bytes: 3068
a,b,c,d = map(int, input().split())

for i in range(100): # 繰り返し処理したい、とりあえず100回以上の繰り返しはないから100回繰り返す
    c -= b # 青木くんの体力cから高橋くんの攻撃力bぶん引く
#    print('青木体力', c) # 残り体力を確認する時は先頭の#を外す
    if c <= 0: # 青木くん体力が0以下になったら
        print('Yes') # 高橋くんの勝ちなのでYes
        break # 体力が0になったら繰り返しも終了

    a -= d # 次に高橋くんの体力aから青木くんの攻撃力dを引く
 #   print('高橋体力',a) # 残り体力を確認する時は先頭の#を外す
    if a <= 0: # 高橋くん体力が0以下になったら
        print('No') # 青木くん勝利でNo
        break # 体力が0になったら繰り返しも終了
# どちらの体力も残ってたら次の繰り返し

Measured memory_bytes: 9160
from itertools import combinations
import numpy as np

N, M, X = map(int, input().split())

c = []
a = []

for _ in range(N):
    k = list(map(int, input().split()))
    c.append(k[0])
    a.append(k[1:])
    
cost = []

for i in range(1, N+1):
    l = list(combinations(range(N),i))
    for ls in l:
        cs = 0
        x = np.full(M,0)
        for n in ls:
            cs += c[n]
            x += np.array(a[n])
        if all(x >= X):
            cost.append(cs)

print(min(cost) if len(cost) != 0 else -1)

  

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

using namespace std;

#define all(v)				((v).begin()), ((v).end())
#define allr(v)				((v).rbegin()), ((v).rend())
#define sz(v)				((int)((v).size()))
#define rep(i, v)		for(int i=0;i<sz(v);++i)
#define lp(i, n)		for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n)	for(int i=(j);i<(int)(n);++i)
#define lpd(i, j, n)	for(int i=(j);i>=(int)(n);--i)
#define ll long long
#define pb					push_back
#define fIO ios_base::sync_with_stdio(0);cin.tie(0);

const ll inf = 1e8;
const double pi = 3.1415926535897;


const double EPS = (1e-7);
int dcmp(double x, double y) {	return fabs(x-y) <= EPS ? 0 : x < y ? -1 : 1;	}


typedef vector<int>                vi;
typedef vector<pair<int,int>>      vii;
typedef vector<ll>                 vll;
typedef vector<double>             vd;
typedef vector< vi >               vvi;
typedef vector< vd >               vvd;
typedef vector<string>             vs;
typedef pair<int, int>             pii;

/**
    * PLEASEEE READDD PROBLEEEM CARFULLY ****
    * Always check for OVERFLOW ll vs int
    * Always check for array bounds
    * Check for function return
    * READ OUTPUT SECTION AGAIN!!!
**/


int main(){
    fIO

    int n;
    cin >> n;

    vector<pii> points;
    vi indic;
    int x, y;

    for(int i = 0; i < n; i++) {
        cin >> x >> y;
        points.emplace_back(x,y);
    }

    for(int i = 0; i < n; i++) {
        indic.pb(i);
    }

    double ans = 0;
    double cnt = 0;
    do{
        double prevX = 0, prevY = 0;
        double dis = 0;
        cnt++;
        //cout << prevX << " " << prevY << endl;
        for(int i = 0; i < n; i++) {
            double currX = points[indic[i]].first, currY = points[indic[i]].second;
            double currDis = (currX - prevX) * (currX - prevX) + (currY - prevY) * (currY - prevY);
            if(i) dis += sqrt(currDis);
            prevX = currX;
            prevY = currY;
        }
        //cout << dis << "\n";
        ans += dis;
    }while(next_permutation(all(indic)));

    cout << fixed << setprecision(9) << ans / cnt;

}










Measured memory_bytes: 256
/*
	Created by Faisal Ahmed
*/

#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long int ll;
typedef long double ld;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(NULL);
	
	int n, arr[200010];
	
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> arr[i];
	}
	
	int ans = 1, mn = arr[0];
	for(int i = 1; i < n; i++){
		if(mn >= arr[i]){
			ans++;
		}
		mn = min(mn, arr[i]);
	}
	
	cout << ans << endl;
	
	return 0;
} 

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

using namespace std;
#define inputInt(a) int a; cin >> a; 
#define inputInt2(a,b) int a; int b; cin >> a >> b; 
#define inputInt3(a,b,c) int a; int b; int c; cin >> a >> b >> c;
#define inputLong(a) long a;cin >> a; 
#define inputIntArray(a,N) int a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputLongArray(a,N) long a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputIntArray2(a,b,N) int a[N]; int b[N]; for(int i=0;i<N;i++){cin >> a[i] >> b[i];}
#define output(answer) cout << answer << endl;
#define fN(i,N)    for(int i=0; i<N; i++)
#define fSE(i,s,e) for(int i=s; i<=e; i++)
#define ll long long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define FOR(i,N) for(int i=0; i<N; i++)
#define cinv(v,N) vector<int> v(N); for(int i=0; i<N; i++){ cin >> v[i]; }
const ll MOD2 = 998244353;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

bool comp(const tuple<int,string,int>& a, const tuple<int,string,int>& b){
  if(get<1>(a) != get<1>(b)){
    return get<1>(a) < get<1>(b);
  }else{
    return get<2>(a) > get<2>(b);
  }
}

int main()
{
  //input
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int N; cin >> N;
  vector<tuple<int,string,int>> v(N);
  for(int i=0; i<N; i++){
    string s; int p; cin >> s >> p;
    v[i] = mt(i,s,p);
  }
  
  //main
  sort(v.begin(), v.end(), comp);
  
  // output
  for(int i=0; i<N; i++){
    cout << get<0>(v[i])+1 << endl; 
  }

  return 0;
}

Measured memory_bytes: 256
nu = gets.to_i
nu2 = nu.to_s
le = nu2.length
inst1 = Array.new(le, 0)
ans = []
for i in 0..(4**le) - 1
  inst1[0] += 1
  for j in 0..le - 2
    if inst1[j] == 4
      inst1[j + 1] += 1
      inst1[j] = 1
    else
      break
    end
  end
  if inst1[-1] == 4
    break
  end
  count3 = 0
  count5 = 0
  count7 = 0
  for j in 0..le - 1
    if inst1[j] == 1
      count3 += 1
    elsif inst1[j] == 2
      count5 += 1
    elsif inst1[j] == 3
      count7 += 1
    end
  end
  count = 0
  if count3 >= 1 && count5 >= 1 && count7 >= 1
    for j in 0..le - 1
      if inst1[j] == 1
        count += 3*(10**j)
      elsif inst1[j] == 2
        count += 5*(10**j)
      elsif inst1[j] == 3
        count += 7*(10**j)
      end
    end
    ans.push(count)
  end

end

leng = ans.length
for i in 0..leng - 1
  if ans[i] > nu
    puts i
    exit
  end
end
puts leng


Measured memory_bytes: 2044
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
using static System.Math;
class Z { static void Main() => new K(); }
class K
{
	int F => int.Parse(Str);
	long FL => long.Parse(Str);
	int[] G => Strs.Select(int.Parse).ToArray();
	long[] GL => Strs.Select(long.Parse).ToArray();
	string Str => ReadLine();
	string[] Strs => Str.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
	const int MOD = 1000000007;
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	int hoge(string s) => s?.Length ?? 0;
	void Solve()
	{
    	var I = G;
		WriteLine(I[0]*I[1]*I[2]/2/I.Max());
	}
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
#define re return
#define pb push_back
#define po pop_back
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define ss second.second
#define sf second.first
#define ff first.first
#define fs first.second
#define si size
#define sqrt(x) sqrt(abs(x))
#define mp make_pair
#define pi 3.14159265359
#define er erase
#define in insert
#define em empty
#define ft front
#define fo(i,n) for(i = 0; i < n; i++)
#define ro(i,n) for(i = n - 1; i >= 0; i--)
#define fr(i,j,n) for(i = j; i < n; i++)
#define rf(i,j,n) for(i=n-1;i>=j;i--)
typedef std::vector<int> vi;
typedef std::vector<vi> vvi;
typedef std::pair<int,int> ii;
typedef std::vector<ii> vii;
typedef std::vector<std::string> vs;
typedef double dl;
typedef long double ld;
typedef long long ll;
typedef std::pair<ll, ll> pll;
typedef std::vector<ll> vll;
#define filename ""
using namespace std;
const int N=(int)1e5;
    vector<int> v[N];
    int was[N];
    int a[N];
    vector<int> d[N];
    int co[N];
    int gwas=0;
bool sss(int x,int y)
{
    if (a[x]!=a[y]) re a[x]<a[y];
    re x<y;
}
bool so(vector<int> &x,vector<int> &y)
{
    if (x.size()!=y.size()) re x.size()>y.size();
    re x[0]<y[0];
}
set<int,bool (*)(int,int)> s1(sss);
set<int,bool (*)(int,int)> s2(sss);
int f(int x)
{
    int i;
    was[x]=1;
    d[gwas].pb(x);
    fo(i,v[x].size())
    {
        if (!was[v[x][i]])
        {
            f(v[x][i]);
        }
    }
}
int main()
{
    /*
	freopen(filename".in","r",stdin);
	freopen(filename".out","w",stdout);
	*/
	/*
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
    */
    int n,m,c,t;
    cin>>n>>m;
    int i;
    fo(i,n)
    {
        scanf("%d",&a[i]);
    }
    fo(i,m)
    {
        scanf("%d%d",&c,&t);
        v[t].pb(c);
        v[c].pb(t);
    }
    int b;
    fo(i,n)
    {
        if (!was[i])
        {
            f(i);
            gwas++;
        }
    }
    sort(d,d+gwas,so);
    fo(i,d[0].size())
    {
        s1.in(d[0][i]);
        co[d[0][i]]=0;
    }
    int j;
    fr(i,1,gwas)
    {
        fo(j,d[i].size())
        {
            s2.in(d[i][j]);
            co[d[i][j]]=i;
        }
    }
    ll o=0;
    int r;
    fo(i,gwas-1)
    {
        if (s2.empty()||s1.empty())
        {
            cout<<"Impossible\n";
            re 0;
        }
        r=*s2.begin();
        o+=a[*s1.begin()];
        s1.er(s1.begin());
        o+=a[*s2.begin()];
s2.er(*s2.begin());
        fo(j,d[co[r]].size())
        {
if (s2.find(d[co[r]][j])!=s2.end())
            s1.in(d[co[r]][j]);
            s2.er(d[co[r]][j]);
        }
    }
    cout<<o<<endl;
    re 0;
}

Measured memory_bytes: 14464
open Scanf
open Printf

let flip f x y = f y x

let rec range a b = if a >= b then [] else a :: range (a+1) b

let read_int () = scanf " %d" (fun x -> x)
let rec read_ints n = if n = 0 then [] else let i = read_int () in i :: read_ints (n-1)

let rec for_iter a b f = if a >= b then [] else let x = f a in x :: for_iter (a+1) b f

let rec drop n xs =
  match xs with
  | [] -> []
  | (_::xs') -> if n = 0 then xs else drop (n-1) xs'

let solve scheds =
  let rec g t xs = match xs with
  | [] -> t
  | ((c, s, f)::xs') ->
    let dept = max s @@ ((t - s) + f - 1) / f * f + s in
    g (dept + c) xs' in
  g 0 scheds

let () =
  let n = read_int () in
  let scheds = for_iter 0 (n-1) (fun _ ->
    let c = read_int () in let s = read_int () in let f = read_int() in
    (c, s, f)) in
  for_iter 0 n (fun i -> solve @@ drop i scheds)
  |> List.iter @@ printf "%d\n"


Measured memory_bytes: 896
//Jai Bhole Ki
#include <bits/stdc++.h>
using namespace std;
#define fast static int fastline = []() { std::ios::sync_with_stdio(false); cin.tie(NULL); return 0; }();
#define ll long long
#define LL unsigned ll
#define pb push_back
#define pi pair<ll,ll>
#define debug(x) cout<<x<<"\n";
#define debugg cout<<"debugged\n";
#define minval -2e9
#define maxval 2e9
long double PI =3.14159265358979323846;
 
const ll M=1e9+7;
const ll inf=1e18;
const ll ms=2e5+5;
fast;
ll n,m,x,y,ans;
void solve()
{
    cin>>n;
    map<string,bool>mp;
    vector<string> s(n);
    for(int i=0;i<n;i++)
        cin>>s[i];
    mp[s[0]]=1;
    for(int i=1;i<n;i++)
    {
        if((s[i][0]!=s[i-1][s[i-1].size()-1])||mp[s[i]])
            {cout<<"No"<<endl;return;}
        mp[s[i]]=1;
    }
    
    cout<<"Yes";
}
int main()
{
 // freopen("input.txt","r",stdin);
//  freopen("output.txt","w",stdout);
    //int t;cin>>t;while(t--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

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

typedef int long long ll;
using namespace std;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;
static const int MAX = 100;
static const int INF = (1 << 23);

int main() {
    ll n,m;
    cin>>n>>m;
    vector<ll> a;
    rep(i,n){
        ll a1;
        cin>>a1;
        a.push_back(a1);
    }

    vector<pair<ll,ll>> v;
    rep(i,m){
        ll b1,c1;
        cin>>b1>>c1;
        v.push_back({c1,b1});
    }
    sort(v.rbegin(),v.rend());
    sort(a.begin(),a.end());
    ll vk=0;
    ll ans=0;
    ll ai=0;

    while(ai<n){
        if(a[ai]>=v[vk].first||vk>=v.size()){
            ans+=a[ai];
            ai++;
        }else{
           ll vkse=v[vk].second;
           
           while(vkse>0){
               if(a[ai]>v[vk].first||ai>=n)break;
               else{
                   ans+=v[vk].first;
                   vkse--;
                   ai++;
               }
           }

           vk++;
        }

    }
    cout<<ans<<endl;



    return 0;
}


Measured memory_bytes: 3188
#include<bits/stdc++.h>
/************************************************/
#define rep(i,n) for(int i=0;i<n;i++)
#define mp make_pair
#define pb push_back
#define fr first
#define se second
#define forn(i,a,n) for(int i=a;i<n;i++)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define sz(s) s.size()
#define all(s) s.begin(),s.end()
#define zero(x) memset(x,0,sizeof(x))
#define vii vector<pair<int,int> >
#define mpis map<int,string>
#define mpii map<int,int>
#define mpsi map<string,int>
#define re return
/************************************************/
using namespace std;

long long get(){
	char c=getchar();
	long long x=0LL;
	while(c<'0'||c>'9')
	c=getchar();
	while(c>='0'&&c<='9'){
		x*=10LL;
		x+=(c-'0');
		c=getchar();
	}
	return x;
}
ll a,b;
int main(){
	cin>>a>>b;
	ll ans=a/(__gcd(a,b));
	ans*=b;
	cout<<ans;
	re 0;
}


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

using namespace std;

#define pb emplace_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define ll long long
#define pii pair<int, int>

int main(){
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(0);
    int n;
    cin >> n;
    ll ans = 0;
    for (int i = 1; i <= n; i++) {
        ll now = n / i;
        ans += ((i + now * i) * now) / 2;
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 3496