akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cstring>
#include<algorithm>

#define INF 11451419
using namespace std;

int n,d;
struct weapon{
	int a,e,r;
};

bool comp(const weapon& g1,const weapon& g2){
	return g1.r<g2.r;
};

weapon b[101];
//武器の種類・EXP・HP
int dp[101][101][101];

int main(void){
	while(1){
		scanf("%d%d",&d,&n);
		if(n==0)break;
		for(int i=0;i<=100;i++){
			for(int j=0;j<=100;j++){
				for(int k=0;k<=100;k++)dp[i][j][k]=INF;
			}
		}
		for(int i=0;i<n;i++)scanf("%d%d%d",&b[i].a,&b[i].e,&b[i].r);
		sort(b,b+n,comp);
		dp[0][0][d]=0;
		int res=INF;
		for(int i=0;i<n;i++){
			for(int j=0;j<=100;j++){
				if(b[i].r>j)continue;
				for(int k=d;k>=0;k--){
					dp[i+1][j][k]=min(dp[i+1][j][k],dp[i][j][k]);
					dp[i][min(100,j+b[i].e)][max(0,k-b[i].a)]=min(dp[i][min(100,j+b[i].e)][max(0,k-b[i].a)],dp[i][j][k]+1);
					dp[i+1][min(100,j+b[i].e)][max(0,k-b[i].a)]=min(dp[i+1][min(100,j+b[i].e)][max(0,k-b[i].a)],dp[i][j][k]+1);
					if(k-b[i].a<=0)res=min(res,dp[i][j][k]+1);
				}
			}
		}
		if(res==INF)printf("NA\n");
		else printf("%d\n",res);
	}
	return 0;
}

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

int main() {
  int N, N_, digitsum = 0;
  cin >> N;
  N_ = N;
  for (int i = 0; i < 10; i++) {
    digitsum += N_ % 10;
    N_ /= 10;
//    cout << "N_ =" << N_ <<", digitsum = " << digitsum << endl;
  }
  if (N % digitsum == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
ans_list = list()
while True:
    x,y = map(int,input().split())
    xy = [x,y]
    if [x,y] == [0,0]:
        break
    ans_list.append([x,y])

for pair in ans_list:
    pair =sorted(pair)
    pair = [str(n) for n in pair]
    print(' '.join(pair))



Measured memory_bytes: 6020
#幅優先探索（BFS）を利用
# 頂点と辺の数を入力する
N, M = map(int, input().split())
# 隣接リストを作成する
list_adjlist = [[] for _ in range(N + 1)]
# 辺のリストを作成する
list_edge = []
# 辺を入力し、隣接リストおよび辺のリストに格納する
for _ in range(M):
    a, b = map(int, input().split())
    list_edge.append((a, b))
    list_adjlist[a].append(b)
    list_adjlist[b].append(a)

def FIFO(list_FIFO, node):
    if node != None:
        list_FIFO.append(node)
        return None
    return list_FIFO.pop(0)

# 橋の総数（all_bridge）を初期化する
all_bridge = 0

# uv間の辺がなくても、uからvへたどり着けるか探索
for u, v in list_edge:
    # uv間の辺が橋かどうか（uv_bridge）を初期化する（初期状態：1＝橋である）
    uv_bridge = 1
    # FIFOキューを初期化する
    list_FIFO = []
    # FIFOキューに入れたことのある点かどうかをチェックするリスト（list_check）を初期化する
    list_check = [False] * (N + 1)
    # FIFOキューにuを追加する
    FIFO(list_FIFO, u)
    # uをFIFOキューに入れた点としてチェックする
    list_check[u] = True
    # FIFOキューが空でない、かつvにたどり着いていない限り、幅優先探索
    while list_FIFO != [] and list_FIFO[-1] != v:
        # FIFOキューから点（node）を取り出す
        node = FIFO(list_FIFO, None)
        # nodeの隣接点（adjnode）について繰り返す
        for adjnode in list_adjlist[node]:
            # adjnodeがFIFOキューに入れたことのある点だった場合
            if list_check[adjnode]:
                # 以降の処理は行わずに次の隣接点に移る
                continue
            # adjnodeがvだった場合
            if adjnode == v:
                # nodeがuでない場合
                if node != u:  
                    # uv_bridgeを更新する（0＝橋でない）
                    uv_bridge = 0
                    # FIFOキューにadjnodeを追加する
                    FIFO(list_FIFO, adjnode)
                    # 繰り返しを終了する
                    break
            # adjnodeがv出ない場合
            else:
                # FIFOキューにadjnodeを追加する
                FIFO(list_FIFO, adjnode)
                # adjnodeをFIFOキューに入れた点としてチェックする
                list_check[adjnode] = True
    # all_bridgeにuv_bridgeを加える
    all_bridge += uv_bridge
                
# all_bridgeを出力する
print(all_bridge)      


Measured memory_bytes: 3064
from itertools import product as p
N,A,B,C=map(int,input().split())
l=[int(input()) for _ in range(N)]

ans=10**12

for i in p(range(4),repeat=N):
  if not (i.count(1)>=1 and i.count(2)>=1 and i.count(3)>=1):continue
  a,b,c=0,0,0
  cost=0
  tt=N-i.count(0)

  for (k,j) in enumerate(i):
    if j==1:a+=l[k]
    elif j==2:b+=l[k]
    elif j==3:c+=l[k]
  
  cost=abs(a-A)+abs(b-B)+abs(c-C)
  cost+=10*(tt-3)

  ans=min(ans,cost)

print(ans)

Measured memory_bytes: 3064
program main
  implicit none
  integer i,N
  real(8) ans1,ans2
  real(8),allocatable :: v(:)
  read(*, *) N
  allocate(v(N))
  read(*, *) (v(i), i = 1,N)

  call qsort(v)

  do i = 1,N-1
    v(i+1) = (v(i+1)+v(i))/2
  end do

  write(*, *) v(N)

  contains

  recursive subroutine qsort(a)
  implicit none
  !integer(8),intent(in) :: n
  real(8),intent(inout) :: a(:)
  integer::i,j,n
  real(8)::toobig,toosmall,pv
  n = size(a)
  i = 1
  j = n
  pv = a((i+j)/2)
  do
     do
       if (a(i) < pv) then
         i = i+1
       else
         exit
       end if
     end do
     do
       if(a(j) > pv) then
         j = j-1
       else
         exit
       end if
     end do
     if (i>=j) then
       exit
     else
       toobig = a(j)
       toosmall = a(i)
       a(i) = toobig
       a(j) = toosmall
       i = i+1
       j = j-1
     end if
   end do
   if (i > 2) then
     call qsort(a(1:i-1))
   end if
   if (j < n-1) then
     call qsort(a(j+1:n))
   end if
  end subroutine qsort
end program main


Measured memory_bytes: 768
#include<complex>
#include<cstdio>
#include<iostream>
#include<vector>
using namespace std;

typedef complex<double> Point;

#define EPS (1e-10)
#define EQ(a,b) (abs((a)-(b)) < EPS)
typedef vector<Point> Polygon;

double cross(const Point &a, const Point &b) {
  return imag(conj(a)*b);
}

double area(const Polygon &p) {
  double A = 0;
  for(int i=0; i<p.size(); i++) {
    A += cross( p[i], p[(i+1)%p.size()] );
  }
  return A;
}

int main() {
  int n;
  int count=1;
  while(true) {
    cin>>n;
    if(!n) break;

    Polygon p;
    int x,y;
    for(int i=0; i<n; i++) {
      cin>>x>>y;
      Point k(x,y);
      p.push_back(k);
    }

    Polygon s(p.rbegin(),p.rend());
    printf("%d %.1lf\n", count, area(s)/2);
    count++;
  }

}

Measured memory_bytes: 0
/* Author - thiolhub */

#include <bits/stdc++.h>

using namespace std;

#define ll              long long int
#define ld              long double
#define db              double
#define pi              3.1415926535897932384626
#define PI              acos(-1.0)
#define endl            "\n"
#define mod             1000000007
#define mk              make_pair
#define pb              push_back
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define ps(x,y)         fixed<<setprecision(y)<<x
#define w(t)            ll t; cin>>t; while(t--)
#define sc(a)	        scanf("%lld",&a);
#define pr(a)	        printf("%lld\n",a)
#define f(i,a,n)		for(ll i=a;i<n;i++)
#define m(a)		    memset(a,0,sizeof(a))
#define FastIO          ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)




int main(){ FastIO;

int a,b;cin>>a>>b;
if(a>8 ||  b>8) cout<<":(";
else cout<<"Yay!";


return 0;
}


Measured memory_bytes: 256
from heapq import heappop, heappush

def getlist():
	return list(map(int, input().split()))

N, M = getlist()
task = []
for i in range(N):
	A, B = getlist()
	heappush(task, [A, B])

Q = []
ans = 0
for i in range(M):
	while True:
		if task != [] and task[0][0] ==1 + i:
			a, b = heappop(task)
			heappush(Q, [-b, a])
		else:
			break
	if Q != []:
		x, y = heappop(Q)
		ans += -x


print(ans)

Measured memory_bytes: 100696
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<utility>
#include<cmath>
#include<string>
#include<cstring>
#include<map>
#include<queue>
#include<set>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define prin(arg) std::cout<<arg<<"\n"
#define prin2(arg1,arg2) std::cout<<arg1<<" "<<arg2<<"\n"
#define fill(arg,n) std::memset(arg,n,sizeof(arg))
#define mp(a,b) std::make_pair(a,b)
#define pb push_back
using std::cin;
typedef long long ll;
typedef std::pair<int,int> pi;
typedef std::vector<int> vi;
typedef std::set<int> si;
typedef std::string str;
const int INF=1e+9;
const ll INFLL=1e+17;
const ll MOD=1e+9+7;
int N;
ll A[100010],B[100010];
int main(){
  cin>>N;
  rep(i,N) cin>>A[i]>>B[i];
  ll cnt=0;
  for(int i=N-1;i>=0;i--){
    ll y=(B[i]-(A[i]%B[i]))%B[i];
    if(cnt<=y) cnt=y;
    else cnt=((cnt-y-1)/B[i]+1)*B[i]+y;
    
  }
  prin(cnt);
  
  return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define L long long
using namespace std;
const int q=1000000007;
int n,m,a,b,c;
L p;
char s[1010][1010];
struct mat
{
	int a[2][2];
	inline mat operator*(mat x)
	{
		mat p={};
		int i,j,k;
		for(i=0;i<=1;i++)
		  for(j=0;j<=1;j++)
		    for(k=0;k<=1;k++)
		      p.a[i][j]=(p.a[i][j]+(L)a[i][k]*x.a[k][j])%q;
		return p;
	}
}u,v;
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	int i,j;
	L k;
	scanf("%d%d%lld",&n,&m,&p);
	for(i=1;i<=n;i++)
	  scanf("%s",&s[i]);
	for(i=1;i<=n;i++)
	  if(s[i][0]=='#' && s[i][m-1]=='#')
	    a++;
	for(i=0;i<m;i++)
	  if(s[1][i]=='#' && s[n][i]=='#')
	    b++;
	for(i=1;i<=n;i++)
	  for(j=0;j<m;j++)
	    if(s[i][j]=='#')
	      c++;
	if(a && b)
	  printf("1\n");
	else
	  {
	   v.a[0][0]=c;
	   if(a)
	     {
		  v.a[1][1]=a;
		  for(i=1;i<=n;i++)
		    for(j=0;j<m-1;j++)
		      if(s[i][j]=='#' && s[i][j+1]=='#')
		        v.a[0][1]--;
		 }
	   if(b)
	     {
		  v.a[1][1]=b;
		  for(i=1;i<n;i++)
		    for(j=0;j<m;j++)
		      if(s[i][j]=='#' && s[i+1][j]=='#')
		        v.a[0][1]--;
		 }
	   v.a[0][1]=(v.a[0][1]+q)%q;
	   u.a[0][0]=u.a[1][1]=1;
	   p--;
	   for(k=1;k<=p;k<<=1);
	   for(k>>=1;k;k>>=1)
	     {
		  u=u*u;
		  if(p&k)
		    u=u*v;
		 }
	   printf("%d\n",(u.a[0][0]+u.a[0][1])%q);
	  }
	return 0;
}


Measured memory_bytes: 1280
#include <stdio.h>

int main()
{
	int a,b,c;
	scanf("%d %d %d",&a,&b,&c);

	if (a < b && b < c)
	{
		printf("%s\n", "Yes");
	}
	else
	{
		printf("%s\n", "No");
	}
	return 0;
}


Measured memory_bytes: 2104
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int h, w;
    cin >> h >> w;
    vs grid(h);
    rep(i, h) cin >> grid[i];
    rep(i, h) rep(j, w) {
        if (grid[i][j] == '#') {
            bool flag = false;
            rep(k, 4) {
                int ni = i + dy[k];
                int nj = j + dx[k];
                if (ni < 0 || h <= ni || nj < 0 || w <= nj) continue;
                if (grid[ni][nj] == '#') flag = true;
            }
            if (!flag) {
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 256
n = int(input())
c = list(input())
sc = sorted(c)

if sc[0] == "W" or sc[-1] == "R":
    print(0)
    
else:
    for i in range(n):
        if sc[i] == "W":
            W_start = i
            break

    W_in_R = 0

    for i in c[:W_start]:
        if i == "W":
            W_in_R += 1

    R_in_W = 0

    for i in c[W_start:]:
        if i == "R":
            R_in_W += 1

    print(max(W_in_R , R_in_W))

Measured memory_bytes: 13656
#include <bits/stdc++.h>
 
using namespace std;
typedef long long int lli;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef pair <lli,lli> pii;
#define ff first
#define ss second
#define MOD 1000000007
#define pb push_back
#define EPS 1e-6
const lli MAX=1e9+7;
 
int main()
{
    fast;
    int n;
    cin>>n;
    if(n>=30) cout<<"Yes";
    else cout<<"No";
    return 0;
}

Measured memory_bytes: 3568
#include <bits/stdc++.h>
using namespace std;
long long MOD = 1000000007;
long long gcd(long long a, long long b){
	return (b > 0)? gcd(b, a % b) : a ;
}
long long power(long long a, long long n){
	long long ans = 1; long long mul = a;
	while(n){
		if(n & 1){
			ans *= mul; ans %= MOD;
		}
		n >>= 1;
		mul = mul * mul % MOD;
	}
	return ans;
}
int main(){
	long long H, W, T;
	cin >> H >> W >> T;
	long long GG = gcd(gcd(H, W), T);
	H /= GG; W /= GG; T /= GG; 
	long long G = gcd(H, W);
	long long G1 = gcd(H, T);
	long long G2 = gcd(W, T);
	long long t = (power(2, H / G1) + power(2, W / G2) + power(2, G) + MOD - 3) % MOD;
	long long ans = power(t, G1 * G2 * GG * GG);
	cout << ans << endl;
}

Measured memory_bytes: 256
n,m = gets.split.map(&:to_i)
arr = gets.split.map(&:to_i).sort
abs = []
arr.each_with_index do |x,i|
  break if arr[i+1] == nil
  a = x - arr[i+1]
  abs << a.abs
end

if n >= m
  puts 0
else
  p abs.sort.reverse[n-1..-1].inject(:+)
end

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

int ruisekiwa[100001][20];
int main() {
	memset(ruisekiwa, 0, sizeof(ruisekiwa));
	int a, b;
	cin >> a >> b;
	int c[20]{};
	for (int d = 0; d < a; d++) {
		int e;
		scanf("%d", &e);
		e--;
		c[e]++;
		for (int f = 0; f < b; f++) {
			ruisekiwa[d + 1][f] = c[f];
		}
	}
	unordered_map<int, int>MINCOST;//20 19.......2 1
	for (int i = 1; i <= b; i++) {
		for (int bit = 0; bit < (1 << b); bit++) {
			int sum = 0, r = 0;;
			for (int g = 0; g < 22; g++) {
				if (bit >> g & 1) {
					sum++;
					r += ruisekiwa[a][g];
				}
			}
			if (sum == i) {
				int MIN = 1 << 29;
				for (int g = 0; g < 22; g++) {
					if (bit >> g & 1) {
						int copy = 1 << g;
						bit -= copy;
						MIN = min(MIN, MINCOST[bit] + ruisekiwa[a][g] - (ruisekiwa[r][g] - ruisekiwa[r - ruisekiwa[a][g]][g]));
						bit += copy;
					}
					MINCOST[bit] = MIN;
				}
			}
		}
	}
	cout << MINCOST[(1 << b) - 1] << endl;
}

Measured memory_bytes: 51608
#include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rp(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
////////////////////////////////////////////////////////////////////////////////
const ll mod=998244353;

int main(){
    ll n;
    cin >> n;
    priority_queue<PLL> que;
    rp(i,n){
        ll x,d;
        cin >> x >> d;
        que.push(mp(x,d));
    }
    stack<PLL> scts;
    ll ans=1ll;
    scts.push(mp(INF,1ll));
    while(!que.empty()){
        PLL p=que.top(); que.pop();
        if(scts.top().first>=p.first+p.second){
            scts.push(mp(p.first,2ll));
            continue;
        }
        ll integrate=1ll;
        while(scts.top().first<p.first+p.second){
            PLL pp=scts.top(); scts.pop();
            integrate *= pp.second;
            integrate %= mod;
        }
        integrate += 1ll;
        scts.push(mp(p.first,integrate));
    }
    while(!scts.empty()){
        ans *= scts.top().second;
        ans %= mod;
        scts.pop();
    }
    print(ans);
    return 0;
}

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

using namespace std;

typedef long long ll;

const double pi = 3.14159265358979323846;

#define rep(i, n) for (ll i = 0; i < n; i++)
#define mod 1000000007LL
#define PS(p) cout << setprecision(15) << fixed << p << endl;
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
#define ALL(c) c.begin(), c.end()
#define CIN(v) cin >> v;
#define COUT(v) cout << v << endl;

int main() {
  int N, K;

  CIN(N >> K);

  int h[N];

  for (int i = 0; i < N; i++) {
    cin >> h[i];
  }

  sort(h, h + N);
  int result = INT_MAX;

  for (int i = 0; i < N; i++) {
    int maxV = 0;
    int minV = INT_MAX;

    if (N < i + K) {
      // COUT("break " << i << " " << K)
      break;
    }

    result = min(result, h[i + K - 1] - h[i]);
  }

  COUT(result);

  return 0;
}


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

int main() 
{
	int a,b,c;
	string str;
	
	cin>>a>>b>>c;
	
	if(a==b && b==c)
	{
		cout<<"Yes"<<endl;
	}
	else cout<<"No"<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
using namespace std;
const int maxn=1e5+5;
int main()
{
	int n;
	cin>>n;
	int ans=0;
	for(int i=1;i<=n;i++){
		string s=to_string(i);
		if(s.length()%2!=0) ans++;
	}
	cout<<ans;
}



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<unordered_map>
#include<iomanip>
#include<bitset>
#define mod 1000000007
using namespace std;
typedef long long ll;
#define chmax(a,b) a=max(a,b)
#define chmin(a,b) a=min(a,b)
#define mad(a,b) a=(a+b)%mod
#define mul(a,b) a=a*b%mod

vector<ll> solve(ll n,ll a,ll b){
    vector<ll> ans;
    if(n==1){
	ans.push_back(a);
	ans.push_back(b);
	return ans;
    }
    ll x=a&(1<<(n-1)); a%=(1<<(n-1));
    ll y=b&(1<<(n-1)); b%=(1<<(n-1));
    if(x!=y){
	ll mid=a^1;
	for(auto t:solve(n-1,a,mid)){
	    ans.push_back(t+x);
	}
	for(auto t:solve(n-1,mid,b)){
	    ans.push_back(t+y);
	}
	return ans;
    }
    y=(1<<(n-1))-x;
    bool p=0;
    for(auto t:solve(n-1,a,b)){
	if(p==0){
	    ans.push_back(t+x);
	    ans.push_back(t+y);
	}
	if(p==1){
	    ans.push_back(t+y);
	    ans.push_back(t+x);
	}
	p^=1;
    }
    return ans;
}

int main(){
    ll n,a,b;
    cin>>n>>a>>b;
    ll cnt=0;
    for(int i=0;i<n;i++){
	if((a&(1<<i))!=(b&(1<<i)))cnt++;
    }
    if(cnt%2==0)cout<<"NO"<<endl;
    else{
	cout<<"YES"<<endl;
	vector<ll> res=solve(n,a,b);
	for(auto t:res)cout<<t<<endl;
    }
}




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

ans = 0
memo = [0] * (N + 1)
for i in range(1,N+1):
    n = N // i
    if memo[n] == 0:
        tmp = n * (n + 1) // 2
        ans += tmp * i
        memo[n] = tmp
    else:
        ans += memo[n] * i
print(ans)

Measured memory_bytes: 87352
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-12;

//int N, M, K, T, H, W, L, R;
long long int N, M, K, T, H, W, L, R;

vector<int> Prime(int num) {
	vector<int>ret;
	ret.push_back(2);
	ret.push_back(3);
	for (int i = 5; i <= num; i += 6) {
		bool flag = true;
		for (int j = 2; j < ret.size(); j++) {
			if (ret[j] * ret[j] > i)break;
			if (i%ret[j] == 0) {
				flag = false;
				break;
			}
		}
		if (flag)ret.push_back(i);
		flag = true;
		for (int j = 2; j < ret.size(); j++) {
			if (ret[j] * ret[j] > i + 2)break;
			if ((i + 2) % ret[j] == 0) {
				flag = false;
				break;
			}
		}
		if (flag)ret.push_back(i + 2);
	}
	return ret;
}

int gcd(int a, int b) {
	while (b) {
		a %= b;
		swap(a, b);
	}
	return a;
}

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

	cin >> N;
	auto P = Prime(1000);
	vector<int>v(N);
	for (auto &i : v)cin >> i;
	int g = 0;
	for (auto i : v) {
		g = gcd(g, i);
	}
	if (g > 1) {
		cout << "not coprime" << endl;
		return 0;
	}
	vector<int>flag(1000001);
	for (auto &i : v) {
		for (auto j : P) {
			if (i%j)continue;
			if (flag[j]) {
				cout << "setwise coprime" << endl;
				return 0;
			}
			while (i%j == 0)i /= j;
			flag[j] = 1;
		}
	}
	for (auto i : v) {
		if (i > 1) {
			if (flag[i]) {
				cout << "setwise coprime" << endl;
				return 0;
			}
			else {
				flag[i] = 1;
			}
		}
	}
	cout << "pairwise coprime" << endl;
}

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

int main(){
    int hour;
    int minute;
    int second;

    int epoch;
    int remain;
    int remain3;

    while(cin >> hour >> minute >> second, hour != -1 && minute != -1 && second != -1){
        epoch = hour * 3600 + minute * 60 + second;
        remain = 120 * 60 - epoch;
        remain3 = remain * 3;

        hour = remain / 3600;
        remain = remain % 3600;
        minute = remain / 60;
        remain = remain % 60;
        second = remain;

        printf("%02d:%02d:%02d\n", hour, minute, second);

        hour = remain3 / 3600;
        remain3 = remain3 % 3600;
        minute = remain3 / 60;
        remain3 = remain3 % 60;
        second = remain3;

        printf("%02d:%02d:%02d\n", hour, minute, second);
    }

    return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<int> vec;
typedef vector<vec> mat;
int main(){
    int A[3];
    rep(i,3) cin>>A[i];
    sort(A,A+3);
    if(A[0]==A[1]&&A[1]!=A[2]) cout<<"Yes";
    else if(A[0]!=A[1]&&A[1]==A[2]) cout<<"Yes";
    else cout<<"No";
}

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

int main() {
    int64_t h, n;
    cin >> h >> n;

    int64_t damage = 0;
    for(int i = 0; i < n; i++) {
        int64_t a;
        cin >> a;
        damage += a;
    }

    if(damage >= h) cout << "Yes\n";
    else            cout << "No\n";

    return 0;
}

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, l;
  cin >> n >> l;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  int ls = -1;
  for (int i = 0; i + 1 < n; ++i) {
    if (a[i] + a[i + 1] >= l) {
      ls = i + 1;
      break;
    }
  }
  if (ls != -1) {
    cout << "Possible" << '\n';
    for (int i = 1; i < ls; ++i) {
      cout << i << " ";
    }
    for (int i = n - 1; i > ls; --i) {
      cout << i << " ";
    }
    cout << ls << '\n';
  }
  else {
    cout << "Impossible" << '\n';
  }
  return 0;
}

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

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

typedef pair<int, int> Pi;
typedef tuple<int, int, int> Ti;
typedef vector<int> vint;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int n;
  cin >> n;

  int al[55][26] = {{}};
  rep(i, n) {
    string s;
    cin >> s;
    rep(j, s.size()) al[i][s[j]-'a']++;
  }
  rep(i, 26) {
    int mn = inf;
    rep(j, n) chmin(mn, al[j][i]);
    rep(j, mn) cout << (char)(i+'a');
  }
  cout << endl;

  return 0;
}


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

#define pout(n)  printf ("%d\n", n)

#define rep(i,a,n) for (int i = a;i < n;i++)
#define per(i,n,a) for (int i = n-1;i >= a;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());

const int d4x[4] = {1, 0, -1, 0};
const int d4y[4] = {0, 1, 0, -1};
const int d8x[8] = { 1,1,0,-1,-1,-1,0,1 };
const int d8y[8] = { 0,1,1,1,0,-1,-1,-1 };

#define MAX_N (int)2e5+20
#define INF 1e12+20

typedef long long ll;
using namespace std;

string s;
int main() {
	cin >> s;
	bool ans = false;
	if(s[0] == 'Y'){
		if(s[1] == 'A'){
			if(s[2] == 'K'){
				if(s[3] == 'I'){
					ans = true;
				}
			}
		}
	}
	if(ans == true) printf("Yes\n");
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
    int N, T;
    int cost, t;
    int cost_min = 1001;    //入力範囲が1~1000のため
    int i;
    
    scanf("%d %d%*c", &N, &T);
    for(i = 0; i < N; i++){
        scanf("%d %d%*c", &cost, &t);
        if(t <= T && cost < cost_min) cost_min = cost;
    }
    if(cost_min > 1000){
        printf("TLE\n");
    }else{
        printf("%d\n", cost_min);
    }
    
    return 0;
}


Measured memory_bytes: 128
n, m = map(int, input().split())

a = list(map(int, input().split()))


nums = {}
for i in a:
    nums[i] = nums.get(i, 0) + 1

for i in range(m):
    b,c = map(int, input().split())

    nums[c] = nums.get(c, 0) + b


ans = 0
for k, v in sorted(nums.items(), key=lambda x: -x[0]):
    if n  >= v:
        ans += k*v
        n -= v
    else:
        ans += k*n
        n = 0
    if n == 0:
        break
print(ans)

Measured memory_bytes: 49440
<?php
fscanf(STDIN, "%d%d", $H, $N);
$dp = array_fill(0, $H + 1, 10**18);
$dp[0] = 0;
for($i = 1; $i <= $N; $i++){
  fscanf(STDIN, "%d%d", $a, $b);
  for($j = 1; $j <= $H; $j++){
    if($j - $a >= 0){
      if($dp[$j]>$dp[$j-$a]+$b)$dp[$j] = $dp[$j-$a]+$b;
    }else{
      if($dp[$j]>$b)$dp[$j] = $b;
    }
  }
}
echo $dp[$H];

Measured memory_bytes: 4728
using namespace std;
#include <bits/stdc++.h>
#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define debug(x) cout << #x <<" = " << x << endl
bool check(int a,int b,int c)
{
    if((a+b>c)&&(a+c>b)&&(b+c>a))
    return true;
    return false;
}
void solve()
{
int n;
cin>>n;
int cnt=0;
int arr[n];
for (int i = 0; i < n; i++)
{
    cin>>arr[i];
}
//sort(arr,arr+n);
for (int i = 0; i < n-2; i++)
{
    for (int j = i+1; j < n-1; j++)
    {
        for (int k = j+1; k < n; k++)
        {
            if(check(arr[i],arr[j],arr[k])&&(arr[i]!=arr[j])&&(arr[j]!=arr[k])&&(arr[i]!=arr[k]))
            {
                //cout<<i+1<<" "<<j+1<<" "<<k+1<<endl;
            cnt++;
            }
        }
        
    }
}
cout<<cnt<<endl;
}
int main()
{

FASTIO
 long long int t;
 t=1;
 while(t--)
  solve();
  return 0;
}


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

int main() {
    int ans = 0;
    string s, t;
    cin >> s >> t;
    for(int i = 0; i < s.size(); ++i) {
        if(s[i] != t[i]) ans++;
    }
    cout << ans << '\n';
}


Measured memory_bytes: 3916
#include <stdio.h>
 
int main(){
  int R,N;
  scanf("%d %d", &N, &R);
  
  if(N > 9){
    printf("%d\n",R);
  }else{
    int result;
    result = R + (100 *(10 - N));
    printf("%d\n", result);
  }
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main() {
    char c;
    int ans[26];
    for(int i=0;i<26;i++)
        ans[i]=0;
    while(cin >> c) {
        if(isalpha(c)){
            int i=tolower(c)-'a';
            ans[i]++;
        }
    }
    for(int i=0;i<26;i++) {
        printf("%c : %d\n",i+'a',ans[i]);
    }
}


Measured memory_bytes: 3200
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
    int N, A, B; cin >> N >> A >> B;
    vector<int> a(3, 0);
    for (int i = 0; i < N; ++i) {
        int x; cin >> x;
        if (x <= A) a[0]++;
        else if (A + 1 <= x && x <= B) a[1]++;
        else if (x >= B + 1) a[2]++;
    }
    sort(a.begin(), a.end());
    printf("%d\n", a[0]);
}


Measured memory_bytes: 3704
class Union():
    def __init__(self, N):
        self.Parent = []
        for i in range(N):
            self.Parent.append(-1)

    def root(self, A):
        if (self.Parent[A] < 0):
            return A
        else:
            self.Parent[A] = self.root(self.Parent[A])
            return self.Parent[A]

    def size(self, A):
        return int(-1 * self.Parent[self.root(A)])

    def connect(self, A, B):
        A = self.root(A)
        B = self.root(B)
        if (A == B):
            return False

        if (self.size(A) < self.size(B)):
            A, B = B, A
        self.Parent[A] += self.Parent[B]
        self.Parent[B] = A
        return True

N, M = map(int, input().split())
union = Union(N)
for i in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    union.connect(a, b)

ans = 0
for i in range(N):
    ans = max(ans, union.size(i))


print(ans)



Measured memory_bytes: 14880
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <functional>
using namespace std;

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define Repr(e, b, i) for(int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n-1, i)
#define repr(n, i) Repr(n-1, 0, i)
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define uniq(x) (x).erase(unique(all(x)),(x).end())

typedef pair<int, int> intP;

const int MAX_N = 128;
const int MAX_W = MAX_N*MAX_N;


//dp[i][j] := i番目までで重さj以下になるように品物を選んだ時の価値の最大値
int dp[MAX_N][MAX_W];

void solve(void){
    int N, W;
    cin >> N >> W;
    vector <intP> P(N);
    rep(N, i) cin >> P.at(i).first >> P.at(i).second;
    rep(N, i) rep(W+1, j) {
        if (P[i].second + j <= W) dp[i+1][P[i].second + j] = max(dp[i][P[i].second + j], dp[i][j] + P[i].first);
        dp[i+1][j] = max(dp[i][j], dp[i+1][j]) ;
    }
    cout << dp[N][W] << endl;
}

int main(void){
  solve();
  //cout << "yui(*-v・)yui" << endl;
  return 0;
}



Measured memory_bytes: 7048
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <iomanip>
#include <cmath>
#define REP(i,n) for (int i=0;i<(n);++i)
using namespace std;
using ll = long long;
constexpr ll MOD = 1e9 + 7;
constexpr int INF = 1 << 30;

ll h;

int main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> h;
  ll cnt = 1, ans = 0;
  while(h) {
    ans += cnt;
    h >>= 1;
    cnt <<= 1;
  }
  cout << ans;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
#define e_b emplace_back
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
using namespace std;
using ll = long long;
using ld = long double;
template<class T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<class T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}

int main(){
  ios_base::sync_with_stdio(false);cin.tie(0);
  string T;
  cin >> T;

  for(int i=0;i<sz(T);i++){
    if(T.at(i)=='?')  T.at(i)='D';
  }
  cout << T << endl;

  return 0;
}

Measured memory_bytes: 3772
// ITP1_7_C

import java.util.Scanner;

class Main{
  public static void main(String[] args){
    // Configuration
    Scanner sc = new Scanner(System.in);

    // Input
    String[] row = sc.nextLine().split(" ");
    int r = Integer.parseInt(row[0]);
    int c = Integer.parseInt(row[1]);
    int[][] board = new int[r+1][c+1];
    for(int i=0; i<r; i++){
      String[] tmp = sc.nextLine().split(" ");
      for(int j=0; j<c; j++){
          board[i][j] = Integer.parseInt(tmp[j]);
      }
    }

    // Row Calculation
    for(int i=0; i<r; i++){
      int answer = 0;
      for(int j=0; j<c+1; j++){
        if(j==c){
          board[i][j] = answer;
        }else{
          answer += board[i][j];
        }
      }
    }

    // Column Calculation
    for(int j=0; j<c; j++){
      int answer = 0;
      for(int i=0; i<r+1; i++){
        if(i==r){
          board[i][j] = answer;
        }else{
          answer += board[i][j];
        }
      }
    }

    // Sum Calculation
    int sum = 0;
    for(int i=0; i<r; i++){
      sum += board[i][c];
    }
    board[r][c] = sum;

    // Output
    for(int i=0; i<r+1; i++){
      for(int j=0; j<c+1; j++){
        if(j==c){
          System.out.print(board[i][j]);
        }else{
          System.out.print(board[i][j] + " ");
        }
      }
      System.out.println();
    }
  }
}



Measured memory_bytes: 32888
#!/usr/bin/env python3

# N:全日数 K:働く日数 C:働いた日からその後働かない日数
N, K, C = map(int, input().split())
S = input()

# num回目に働く日はl[num-1]日目以降
l = []
num = 0
i = 0
while num < K:
    if S[i] == "o":
        l.append(i)
        num += 1
        i += C + 1
    else:
        i += 1

# num回目に働く日はl[num-1]日目以前
r = []
num = 0
i = N - 1
while num < K:
    if S[i] == "o":
        r.append(i)
        num += 1
        i -= C + 1
    else:
        i -= 1
r.reverse()

for i in range(K):
    if l[i] == r[i]:
        print(l[i] + 1)

Measured memory_bytes: 20660
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;

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

       int t=1;
       //cin>>t;
       while(t--)
       {
               string s;
               cin>>s;
               string ans;
               for(int i=0;i<s.size();++i)
               {
                    if(s[i]=='0')
                         ans.pb('0');
                    else if(s[i]=='1')
                         ans.pb('1');
                    else if(ans.size()>0)
                         ans.pop_back();
               }
               cout<<ans;
       }
}


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

int main() {
    int A;
    int B;
    int C;
    int D;
    cin >> A >> B >> C >> D ;
    if(A+B > C+D){
        cout << "Left" << endl;
    }
    if(A+B == C+D){
        cout << "Balanced" << endl;
    }
    if(A+B < C+D){
        cout << "Right" << endl;
    }
}

Measured memory_bytes: 256
from functools import reduce

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

def solve(N, As):
    Lgcd = [0 for _ in range(len(As) + 1)]
    Rgcd = [0 for _ in range(len(As) + 1)]
    for i in range(len(As)):
        Lgcd[i + 1] = gcd(Lgcd[i], As[i])
    for i in reversed(range(len(As))):
        Rgcd[i] = gcd(Rgcd[i + 1], As[i])
    ans = 1
    for i in range(len(As)):
        ans = max(ans, gcd(Lgcd[i], Rgcd[i + 1]))
    print(ans)


if __name__ == '__main__':
    N = int(input()) # ignore
    As = list(map(int, input().split()))
    solve(N, As)

Measured memory_bytes: 14652
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  int n = s.size(), N=0, W=0, S=0, E=0;
  for (int  i = 0; i < n; i++) {
    if (s[i] == 'N') N = 1;
    if (s[i] == 'W') W = 1;
    if (s[i] == 'S') S = 1;
    if (s[i] == 'E') E = 1;
  }
  string ans = "No";
  if ((N + S) % 2 == 0 && (W + E) % 2 == 0) ans = "Yes";
  cout << ans << endl;
}

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

int main() {
	string S;
	cin >> S;
	int ans = 0;
	for (int i = 0, j = 0;i < S.size();++ i) {
		if (S[i] == 'A' || S[i] == 'T' || S[i] == 'G' || S[i] == 'C') ans = max(ans, ++j);
		else j = 0;
	}
	cout << ans;
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり
また、コンテスト後に https://31536000.hatenablog.com/ で解説していると思うので、良かったら読んでねー

やるだけー
*/

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <cstdio>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;

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

typedef long long ll;

const int Inf = 1e9;
const double EPS = 1e-9;

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

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

int bitCount(long bits) {
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, y;  cin >> n >> y;
    for (int i = n; i >= 0; --i) {
      for (int j = n - i; j >= 0; --j) {
        if (i * 10000 + 5000 * j + 1000 * (n - i - j) == y && n - i - j >= 0) {
          cout << i << " " << j << " " << n - i - j << '\n';
          return 0;
        }
      }
    }
    cout << "-1 -1 -1" << '\n';

    return 0;
}


Measured memory_bytes: 256
#include "iostream"
#include "algorithm"
#include "vector"
#include "string"
#include "cmath"
#include "utility"
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;

void print_mine(ll id){
  int keta=0;
  ll id_ori = id;
  while (id !=0) {
    id /= 10;
    keta++;
  }

  for (size_t i = 0; i < 12 - keta; i++) {
    std::cout << "0";
  }

  std::cout << id_ori << '\n';
}


int main(int argc, char const *argv[]) {
  ll NN, MM;

  std::cin >> NN>>MM;

  ll Y[MM];

  std::vector<std::pair<ll, ll>> P(MM);

  for (size_t i = 0; i < MM; i++) {
      std::cin >> P[i].first>>Y[i];
      P[i].second = i;
  }

  // for (size_t i = 0; i < MM; i++) {
  //   std::cout << "P.first::"<<P[i].first <<"   P.second::"<<P[i].second << '\n';
  // }
  //
  // std::cout << "after sort" << '\n';
  sort(P.begin(), P.end());

  // for (size_t i = 0; i < MM; i++) {
  //   std::cout << "P.first::"<<P[i].first <<"   P.second::"<<P[i].second << '\n';
  // }

  for (size_t i = 0; i < MM; i++) {
    ll get_id = P[i].first;
    ll nums = 0;
    while (P[i+nums].first == get_id) {
      nums++;
    }

    std::vector<std::pair<ll, ll>> pyy(nums);
    for (size_t j = 0; j < nums; j++) {
      pyy[j].first = Y[P[i+j].second];
      pyy[j].second = j;
    }
    sort(pyy.begin(), pyy.end());

    for (size_t t = 0; t < nums; t++) {
      P[i + pyy[t].second].first = get_id * 1000000 + t+1;
    }
    i += nums-1;

  }

  // std::cout << "after process" << '\n';
  //
  // for (size_t i = 0; i < MM; i++) {
  //   std::cout << "P.first::"<<P[i].first <<"   P.second::"<<P[i].second << '\n';
  // }

  // std::cout << "answer_test" << '\n';
  std::sort(P.begin(), P.end(), [](auto &left, auto &right) {
    return left.second < right.second;
  });

  for (size_t i = 0; i < MM; i++) {
    print_mine(P[i].first);
  }

  return 0;
}


Measured memory_bytes: 4424
#include<stdio.h>
int main()
{

    int w,a,b, sum;
    while(scanf("%d%d%d",&w,&a,&b) != EOF)
    {
        if(b>a)
        {
            sum = b - (w + a);
        }
        else if(b<a)
        {
            sum = a - (w + b);
        }
        else
            sum = 0;
        if(sum < 0)
            sum = 0;
        printf("%d\n",sum);
    }
    return 0;
}


Measured memory_bytes: 128
n, m = map(int, raw_input().split())
a = []
b = []
c = [0 for i in range(n)]
for i in range(n):
  a.append(map(int, raw_input().split()))
for i in range(m):
  b.append(input())
for i in range(n):
  for j in range(m):
    c[i] += a[i][j]*b[j]
for i in range(n):
  print c[i]

Measured memory_bytes: 6588
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let v = read_vec::<usize>();
    let (n, m) = (v[0], v[1]);
    let h = read_vec::<i64>();
    let mut graph = vec![vec![]; n];
    for _ in 0..m {
        let v = read_vec::<usize>();
        let (a, b) = (v[0] - 1, v[1] - 1);
        graph[a].push(b);
        graph[b].push(a);
    }
    let mut ans = 0;
    for i in 0..n {
        if graph[i].iter().all(|&x| h[x] < h[i]) {
            ans += 1;
        }
    }
    println!("{}", ans);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 8680
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define all(v) (v).begin(),(v).end()
template<class T>bool chmax(T &a,T b){if(a<b){a=b;return 1;} return 0;}
template<class T>bool chmin(T &a,T b){if(b<a){a=b;return 1;} return 0;}

int dx[4] = {0,0,-1,1};
int dy[4] = {1,-1,0,0};
string rlud = "RLUD";


const int MAX = 10000;
const int mod = 998244353;

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

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

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

ll dp[2][2001][2001];

// run : ctrl + c 
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    
    string s;
    cin>>s;
    int n = s.size();
    COMinit();
    int r=0,b=0;
    int x = 1;
    dp[0][0][0] = 1;
    for(int i=0;i<n;i++){
        int nb=b,nr=r;
        if(s[i]=='0')nr+=2;
        if(s[i]=='2')nb+=2;
        if(s[i]=='1')nr++,nb++;
        for(int j=0;j<=i;j++){
            dp[x][j][i-j]=0;
        }
        for(int j=0;j<=i;j++){
            if(r>=j && b>=i-j){
                if(nr-j>0){
                    dp[x][nr-j-1][nb-(i-j)] += dp[x^1][r-j][b-(i-j)];
                    dp[x][nr-j-1][nb-(i-j)] %= mod;
                }
                if(nb-(i-j)>0){
                    dp[x][nr-j][nb-(i-j)-1] += dp[x^1][r-j][b-(i-j)];
                    dp[x][nr-j][nb-(i-j)-1] %= mod;
                }
            }
        }
        r=nr, b=nb;
        x ^= 1;
    }
    ll ans = 0;
    x ^= 1;
    for(int i=0;i<=n;i++){
        ans += (dp[x][i][n-i] * COM(n,i))%mod;
        ans %= mod;
    }
    cout << ans << endl;

    
}

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

#define forn(i,n) for(int i=0;i<(int)(n);i++)
#define si(c) ((int)(c).size())
#define forsn(i,s,n) for(int i = (int)(s); i<((int)n); i++)
#define dforsn(i,s,n) for(int i = (int)(n)-1; i>=((int)s); i--)
#define all(c) (c).begin(), (c).end()
#define D(a) cerr << #a << "=" << a << endl;
#define pb push_back
#define eb emplace_back
#define mp make_pair

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

const int N = 2e5 + 10;

int n,m;
vi adj[N];

bool vis[N];
int pre[N], a = -1,b;
void dfs_cycle(int u, int p) {
    vis[u] = true;
    pre[u] = p;
    for (int v : adj[u]) if (v != p) {
        if (vis[v]) {
            if (a == -1) {
                a = v; 
                b = u;
            }
        }
        else dfs_cycle(v,u);
    }
}

vi cycle;
bool cyc[N];
void build_cycle() {
    for (int x = b; x != -1; x = pre[x]) {
        //cerr << x << ' ' << pre[x] << endl;
        cyc[x] = true;
        cycle.pb(x);
        if (x == a) break;
    }
}

ll res = 0;
int bal[N];
void dfs(int u, int p) {
    bal[u] = 1;
    for (int v : adj[u]) if (!cyc[v] && v != p) {
        dfs(v,u);
        bal[u] -= bal[v];
    }
    if (p != -1) res += abs(bal[u]);
}

void result(ll res) {
    printf("%lld\n", res);
    exit(0);
}

int main() {
    scanf("%d %d", &n, &m);
    forn(_,m) {
        int u,v;
        scanf("%d %d", &u, &v);
        u--; v--;
        adj[u].pb(v);
        adj[v].pb(u);
    }

    if (m == n) {
        dfs_cycle(0,-1); build_cycle();
        vi cbal;
        for (int r : cycle) {
            dfs(r,-1);
            cbal.pb(bal[r]);
        }

        if (si(cycle) % 2) {
            ll total = 0;
            forn(i,si(cbal)) {
                if (i%2 == 0) total -= cbal[i]; else total += cbal[i];
            }
            if (total%2) result(-1);
            total /= 2;
            for (auto b : cbal) {
                res += abs(total);
                total = -total-b;
            }
            result(res);
        }
        else {
            vector<ll> cum;
            cum.pb(0);
            forn(i,si(cbal)) {
                if (i%2 == 0) cum.pb(cum.back()-cbal[i]);
                else cum.pb(cum.back()+cbal[i]);
            }
            if (cum.back() != 0) result(-1);

            cum.pop_back(); sort(all(cum));
            ll med = cum[si(cum)/2];
            for (ll x : cum) res += abs(x-med);
            result(res);
        }
    }
    else {
        dfs(0,-1);
        if (bal[0] != 0) result(-1);
        result(res);
    }

    return 0;
}


Measured memory_bytes: 15608
# include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 10;
int s1[N] , s2[N] , a[N] , n , allsum;
int sum(int x){
	if(x % 2){
		// x is odd
		// allsum = from 1 to n;
		// s1[x - 1] = from 1 to x - 1;
		// s2[n] - s2[x] = from x + 1 to n;
		return allsum - s1[x - 1] - (s2[n] - s2[x]);
	}
	else{
		// x is even 
		// allsum = from 1 to n
		// s2[x - 1] + 2 * a[n] = from 1 to x - 1  and n
		// s1[n - 1] - s1[x] = from x + 1 to n - 1
		return allsum - s2[x - 1] - 2 * a[n] - (s1[n - 1] - s1[x]);
	}
}
int main(){
	cin >> n;
	for(int i = 1; i <= n; i ++) cin >> a[i] , allsum += a[i];
	for(int i = 2; i <= n; i += 2) s1[i] = (i > 1 ? s1[i - 2] : 0) + a[i - 1] * 2; /// from 1 to i
	for(int i = 3; i <= n; i += 2) s2[i] = (i > 2 ? s2[i - 2] : 0) + a[i - 1] * 2; /// from 2 to i 
	for(int i = 1; i <= n; i ++)
		cout << sum(i) << " ";
}

Measured memory_bytes: 2432
import sys

lines = [l for l in sys.stdin]
length = int(lines[0])
digits = lines[1].split(' ')
nums = [int(s) for s in digits]

flag = 'APPROVED'
for n in nums:
  if n % 2 != 0: continue
  if n % 3 != 0 and n % 5 != 0:
    flag = 'DENIED'
    
print(flag)

Measured memory_bytes: 3060