akhauriyash/Code-Regression huggingface dataset:
import heapq

def main():

    INF = 1000000009
    n = int(input())
    e = [[] for _ in range(n)]
    for i in range(n):
        inf = list(map(int,input().split()))
        for j in range((inf[1])):
            e[inf[0]].append([inf[2+j*2],inf[2+j*2+1]])
    
    dp = [INF]*n
    dp[0] = 0
    pq = [[0,0]]
    heapq.heapify(pq)
    while pq:
        cost,v = heapq.heappop(pq)
        if dp[v]<cost:continue

        for i in range(len(e[v])):
            u = e[v][i][0]
            ncost = cost+e[v][i][1]
            if ncost < dp[u]:
                dp[u] = ncost
                heapq.heappush(pq,[ncost,u])
    for i in range(n):
        print(i,dp[i])


if __name__ == '__main__':
    main()




Measured memory_bytes: 76460
#include<iostream>
using namespace std;
#define int long long
int32_t main()
{
  int d,c;
  int M;
  cin>>M;
  int order=0,sum=0;
  for(int i=0;i<M;i++)
  {
    cin>>d>>c;
    order+=c;
    sum+=(d*c);
  }
  cout<<(order-1)+((sum-1)/9)<<endl;
  return 0;
}

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

int main(){
  char a,b;
  cin>>a>>b;
  if(b=='H'){
    if(a=='H'){
      cout<<"H";
    }else if(a=='D'){
      cout<<"D";
    }
  }else if(b=='D'){
    if(a=='H'){
      cout<<"D";
    }else if(a=='D'){
      cout<<"H";
    }
  }

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
	int l=0;
	int h=s.length()-1;
	int count=0;
	while(h>l)
	{
		if(s[h]!=s[l]){
			count++;
		}
		h--;
		l++;
	}
	cout<<count<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n, m;
char s[1111][1111];
int main(){
	cin >> n >> m;
	for(int i = 1; i <= n; i++)
	scanf("%s", s[i] + 1);
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= m; j++){
			if(i == 1) {printf("#"); continue;}
			if(i == n) {printf("."); continue;}
			if(j % 2 == 1){printf("#"); continue;}
			if(s[i][j] == '#'){printf("#"); continue;}
			printf(".");
		}
		puts("");
	}
	puts("");
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= m; j++){
			if(i == n) {printf("#"); continue;}
			if(i == 1) {printf("."); continue;}
			if(j % 2 == 0){printf("#"); continue;}
			if(s[i][j] == '#'){printf("#"); continue;}
			printf(".");
		}
		puts("");
	}
} 

Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
#define debug(x) cout<<"### "<<x<<endl;
#define For(a,b,c) for(int a=b;a<=c;++a)
#define Dor(a,b,c) for(int a=b;a>=c;--a)
inline int read(){
    int x=0;char c=getchar();
    while(c<'0'||c>'9')c=getchar();
    while(c>='0'&&c<='9')x=(x<<3)+(x<<1)+(c^48),c=getchar();
    return x;
}
int h[100009],n;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&h[i]);
	int ans=0,lst=0;
	for(int i=1;i<=n;i++){
		if(h[i]<=h[i-1])lst++;
		else lst=0;
		ans=max(ans,lst);
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 640
#include<iostream>
#include<string>

using namespace std;

int main(void)
{
  string s;
  cin >> s;
  
  int count = 0;
  
  if(s[0] == '1')
    count++;
  if(s[1] == '1')
    count++;
  if(s[2] == '1')
    count++;
  
  cout << count << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
int main(int argc, char const *argv[])
{
   int n;
   cin >> n;
   vector<int> p(n);
   for(int i = 0; i < n; i++)
   {
      cin >> p[i];
   }
   int cnt = 0;
   for(int i = 0; i < n; i++)
   {
      if(p[i] != i+1)
      {
         cnt++;
      }
   }
   if(cnt == 0 || cnt == 2)
   {
      cout << "YES" << endl;
   }
   else
   {
      cout << "NO" << endl;
   }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fastio                        \
    ios_base::sync_with_stdio(false); \
    cin.tie(0);                       \
    cout.tie(0)
#define scl(n) scanf("%lld", &n)
#define pcl(n) printf("%lld\n", n)
#define pcl1(n) printf("%lld ", n)
#define nln printf("\n")
#define dev(x) cout << #x << " " << x << " ";
#define PTT pair<ll, ll>

map<ll, ll> mp, mp1;
map<ll, ll>::iterator itr;

int main()
{
    ll t, n, x;
    scl(x);
    if (x >= 400 && x <= 599)
    {
        n = 8;
    }
    else if (x >= 600 && x <= 799)
    {
        n = 7;
    }
    else if (x >= 800 && x <= 999)
    {
        n = 6;
    }
    else if (x >= 1000 && x <= 1199)
    {
        n = 5;
    }
    else if (x >= 1200 && x <= 1399)
    {
        n = 4;
    }
    else if (x >= 1400 && x <= 1599)
    {
        n = 3;
    }
    else if (x >= 1600 && x <= 1799)
    {
        n = 2;
    }
    else
    {
        n = 1;
    }
    pcl(n);

    return 0;
}

Measured memory_bytes: 3824
n, x = map(int, input().split())

pate, slice = [1], [1]
for _ in range(n + 1):
    pate.append(2 * pate[-1] + 1)
    slice.append(2 * slice[-1] + 3)

ans = 0
while n > 0:
    if x >= slice[n - 1] + 2:
        ans += pate[n - 1] + 1
        x -= slice[n - 1] + 2
    elif x < slice[n - 1] + 2:
        x -= 1
    n -= 1
print(ans + (x > 0))


Measured memory_bytes: 9196
n = int(input())
a = [int(x) for x in input().split()]

I = a.count(3)
J = a.count(2)
K = a.count(1)

dp = [[[0 for _ in range(I+J+K+1)] for __ in range(I+J+1)]
      for ___ in range(I+1)]

for i in range(I+1):
    for j in range(I+J+1-i):
        for k in range(I+J+K+1-i-j):
            if i + j + k == 0:
                continue
            tmp = 0
            if k > 0:
                tmp += (k/n)*dp[i][j][k-1]
            if j > 0:
                tmp += (j/n)*dp[i][j-1][k+1]
            if i > 0:
                tmp += (i/n)*dp[i-1][j+1][k]
            dp[i][j][k] += (n/(i+j+k))*(1 + tmp)

print(dp[I][J][K])


Measured memory_bytes: 501640
#include <float.h>
#include <inttypes.h>
#include <limits.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <math.h>
#ifdef __cplusplus
#include <bits/stdc++.h>
#endif

#define getchar getchar
#define putchar putchar
int32_t nextint(void){ char c=getchar(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar(); bool s=false; if(c=='-'){s=true;c=getchar();} uint32_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar(); } return s?-x:x; }
int64_t nextlong(void){ char c=getchar(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar(); int s=0; if(c=='-'){s=1;c=getchar();} uint64_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar(); } return s?-x:x; }
uint32_t nextstr(char *s){ char c=getchar(); while(c==' '||c=='\n') c=getchar(); uint32_t len=0; while(c!=' '&&c!='\n'){ *s++=c; len++; c=getchar(); } *s='\0'; return len; }

#define P 1000000007

int k[2000001];
int rk[2000001];

int getk(int a, int x){
	if(x==1) return a;
	int b = getk(a, x/2);
	b = ((long)b)*b%P;
	if((x&1)==0){
		return b;
	}else{
		return ((long)b)*a%P;
	}
}
int comb(int a, int b){
	if(a<b) return 0;
	return ((long)k[a])*rk[b]%P*rk[a-b]%P;
}
void comb_init(int n){
	k[0]=1;
	for(int i=1; i<=n; i++){
		k[i]=k[i-1]*((long)i)%P;
	}	
	rk[n]=getk(k[n], P-2);
	for(int i=n-1; i>=0; i--){
		rk[i]=((long)rk[i+1])*(i+1)%P;
	}
}

char s[1000001];
int r25[1000001];
int r26[1000001];
int main(void){
	int m=nextint();
	int n=nextstr(s);
	r25[0]=1;
	r26[0]=1;
	for(int i=1; i<=m; i++){
		r25[i]=(long)r25[i-1]*25%P;
		r26[i]=(long)r26[i-1]*26%P;
	}
	long ans=0;
	comb_init(n+m);
	for(int i=m; i>=0; i--){
		long now=(long)comb(n+i-1,i)*r25[i]%P*r26[m-i]%P;
		ans=(ans+now)%P;
	}
	printf("%ld\n", ans);
	/*
	a[0][0]=1;
	for(int i=1; i<=n+m; i++){
		a[i][0]=(long)a[i-1][0]*26%P;
		for(int j=1; j<=n; j++){
			a[i][j]=((long)a[i-1][j]*25+a[i-1][j-1])%P;
		}
	}
	printf("%d\n", a[n+m][n]);
	*/
}


Measured memory_bytes: 25936
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N=I()
    TA=LLIN(N)
    C=1
    D=1
    for t,a in TA:
        n = max( -(-C//t), -(-D//a))
        C,D = n*t,n*a
    ans = C+D
    print(ans)
if __name__ == '__main__':
    main()

Measured memory_bytes: 40048
#include<iostream>
#include<string>
using namespace std;
int main()
{	string s;int n,i,flag,j;
	char c[26];
	for(i=0;i<26;i++)
		c[i]='a'+i;
	cin>>s;
	n=s.size();
	for(i=0;i<n;i++)
		for(j=0;j<26;j++)
		{	if(s[i]=='a'+j)
			{	c[j]='1';
				break;
			}
		}
	flag=1;
	for(i=0;i<26;i++)
		if(c[i]!='1')
		{	flag=0;cout<<c[i]<<endl;break;}
	if(flag==1)
		cout<<"None"<<endl;
	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    ll a,b;
    cin>>a>>b;
    if(a==1&&b!=1)
        cout<<"Alice"<<endl;
    else if(b==1&&a!=1)
        cout<<"Bob"<<endl;
    else if(a==b)
        cout<<"Draw"<<endl;
    else
    {
        if(a!=1&&b!=1&&a>b)
            cout<<"Alice"<<endl;
        if(a!=1&&b!=1&&a<b)
            cout<<"Bob"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  string s;
  cin >> s;
  int n = s.size();
  int cnt = 0;
  REP(i, n / 2) {
    if(s[i] != s[n - i - 1]) cnt++;
  }
  cout << cnt << '\n';
  return 0;
}


Measured memory_bytes: 256
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
#include<memory>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/
const llint mod=998244353;
const llint big=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
int main(void){
	int n,i,j,k,wa=0;cin>>n;
	vector<llint>zi(n+1);
	for(i=n;i>=0;i--){cin>>zi[i];}
	llint agc=abs(zi[n]);
	for(i=n-1;i>=0;i--){if(zi[i]!=0){agc=gcd(agc,abs(zi[i]));}}
	vector<int>ans(n);
	//cerr<<"agc="<<agc<<endl;
	for(i=2;i*i<=agc;i++){
		while(agc%i==0){agc/=i;ans.pub(i);}
	}
	if(agc!=1){ans.pub(agc);}
	vector<bool>sosu(n+1,1);
	sosu[0]=0;sosu[1]=0;
	for(i=2;i<=n;i++){
		if(!sosu[i]){continue;}
		for(j=i+i;j<=n;j+=i){sosu[j]=0;}
	}
	//cerr<<sosu[2]<<endl;
	for(i=2;i<=n;i++){
		if(!sosu[i]){continue;}
		int z=i-1;
		bool can=1;
		for(j=0;j<z;j++){
			llint gen=0;
			for(k=j;k<=n;k+=z){gen+=zi[k];}
			if(gen%i!=0){can=false;break;}
		}
		if(can&&zi[0]%i==0){ans.pub(i);}
	}
	SO(ans);ans.erase(unique(ans.begin(),ans.end()),ans.end());
	for(auto it:ans){
		if(n<it||sosu[it]){cout<<it<<endl;}
	}
	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))

using namespace std;
typedef pair<llint, string> P;


char enc(llint x)
{
	if(x < 26) return 'a'+x;
	if(x < 52) return 'A'+(x-26);
	return '0'+(x-52);
}

llint L = 128;
llint num[65];
priority_queue<P, vector<P>, greater<P> > Q;


int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	llint res, len = 0;
	for(int i = 0; i < 62; i++){
		string s;
		for(int j = 0; j < L; j++) s += enc(i);
		cout << "? " << s << endl;
		
		cin >> res;
		num[i] = L-res;
		if(num[i] > 0){
			s = "";
			for(int j = 0; j < num[i]; j++) s += enc(i);
			Q.push(P(num[i], s));
		}
		len += num[i];
	}
	
	while(Q.size() > 1){
		string s = Q.top().second; Q.pop();
		string t = Q.top().second; Q.pop();
		llint p = 0, q = 0; string str = t;
		while(p < s.size()){
			str.insert(str.begin()+p+q, s[p]);
			cout << "? " << str << endl;
			cin >> res;
			if(len-res == str.size()) p++;
			else{
				str.erase(str.begin()+p+q);
				q++;
			}
		}
		Q.push(P((llint)str.size(), str));
	}
	
	cout << "! "<< Q.top().second << endl;
	
	return 0;
}

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

int main(){
  int pay;
  int coin[4];  //c[0],c[1],c[2],c[3]は順に10,50,100,500円玉の枚数
  int cur;
  int used[4];
  const int number[4] = {10, 50, 100, 500};
  bool lf = false;
  while(cin >> pay && pay > 0){
    if(lf)
      cout << endl;
    cur = -pay;
    for(int i=0;i<4;i++){
      cin >> coin[i];
      used[i] = coin[i];
      cur += coin[i] * number[i];
    }

    int n;
    for(int i=3;i>=0;i--){
      n = cur/number[i];
      used[i] = (used[i] >= n) ? used[i] - n : 0;
      cur -= n * number[i];
    }
    for(int i=0;i<4;i++){
      if(used[i] > 0)
	cout << number[i] << ' ' << used[i] << endl;
    }
    lf = true;
  }
}



Measured memory_bytes: 3076
import math

class KochCurve:
    def koch(self, d, p1, p2): 
        if d == 0:
            return
        th = math.pi * 60.0 / 180.0
        sx = (2.0 * p1[0] + 1.0 * p2[0]) / 3
        sy = (2.0 * p1[1] + 1.0 * p2[1]) / 3
        s = (sx, sy)
        tx = (1.0 * p1[0] + 2.0 * p2[0]) / 3
        ty = (1.0 * p1[1] + 2.0 * p2[1]) / 3
        t = (tx, ty)
        ux = (tx - sx) * math.cos(th) - (ty - sy) * math.sin(th) + sx
        uy = (tx - sx) * math.sin(th) + (ty - sy) * math.cos(th) + sy
        u = (ux, uy)
        
        self.koch(d-1, p1, s)
        print("{} {}".format(sx, sy))
        
        self.koch(d-1, s, u)
        print("{} {}".format(ux, uy))

        self.koch(d-1, u, t)
        print("{} {}".format(tx, ty))
        
        self.koch(d-1, t, p2)

if __name__ == '__main__':
    n = int(input().rstrip())
    p1 = (0, 0)
    p2 = (100, 0)
    print("{} {}".format(p1[0], p1[1]))
    x = KochCurve()
    x.koch(n, p1, p2)
    print("{} {}".format(p2[0], p2[1]))

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

int main()
{
	int n;
	cin >> n;
	vector<int> N(n);
	
	int i = 0;
	while (i < n) {
		cin >> N.at(i);
		i++;
	}

	int ans = 0, k = 0 ,max=N.at(0);
	while (k < n - 1) {
		if (N.at(k + 1) > N.at(k)) max = N.at(k + 1);
		if (N.at(k + 1) < max - 1) {
			ans++;
			break;
		}
		k++;
	}

	if (ans == 0) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for (int (i) = 0; (i) < (n); i++)
#define ll long long
using namespace std;
int main() {
  ll N = 0, M = 0,x = 0;
  cin >> N >> M >> x;
  if(M*x >= N){
    cout << "Yes";
  }
  else{
    cout << "No";
  }
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1000000007;
const ld PI = acos(-1);  
const ld EPS = 0.0000000001;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define REP(i, n) for(ll i=0; i<(ll)(n); i++)
#define REPD(i, n) for(ll i=n-1; 0<=i; i--)
#define FOR(i, a, b) for(ll i=a; i<(ll)(b); i++)
#define FORD(i, a, b) for(ll i=a; (ll)(b)<=i; i--)
#define ALL(x) x.begin(), x.end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define SUM(x) accumulate(ALL(x), 0LL);
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main(){
    ld a, b;   cin >> a >> b;
    ll nb = b*100+0.5;
    ll res = (a*nb)/100;
    
    cout << res << endl;
    
}

Measured memory_bytes: 3720
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;

struct Edge {
  ll from, to;
  ll cost;
  Edge(ll from, ll to, ll cost):
  from(from),to(to),cost(cost){}
};

ll minv = -1ll * (1ll << 35ll);
ll n, m, p;
ll s, t, c;
ll dist[3000];
vector<Edge> G;

int bellman_ford(vector<Edge> &edges) {
  int state = 1;
  dist[1] = 0;
  for(int i = 0; i < n - 1; i++) {
    for(auto &e : edges) {
      if(dist[e.from] == minv) continue;
      dist[e.to] = max(dist[e.to], dist[e.from] + e.cost);
    }
  }
  
  ll d[3000];
  for (int i=0;i<3000;i++)d[i]=dist[i];
  for(int i = 0; i < n - 1; i++) {
    for(auto &e : edges) {
      if(d[e.from] == minv) continue;
      d[e.to] = max(d[e.to], d[e.from] + e.cost);
    }
  }
  
  return d[n]==dist[n];
}

int main() {
  for (int i=0;i<3000;i++) dist[i] = minv;
  cin >> n >> m >> p;
  
  for (int i=0;i<m;i++) {
    cin >> s >> t >> c;
    G.push_back(Edge(s,t,c-p));
  }
  
  if (bellman_ford(G)) cout << max(0ll,dist[n]) << endl;
  else cout << -1 << endl;
  
  return 0;
}


Measured memory_bytes: 576
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200010;
const int MOD = 1000000007;
int arr[MAXN];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n, k;
    cin >> n >> k;

    vector<int> pos, neg;
    for(int i = 1; i <= n; i++) {
        cin >> arr[i];
        if (arr[i] > 0) pos.push_back(arr[i]);
        else if (arr[i] <= 0) neg.push_back(-arr[i]);
    }
    if (k == n) {
        long long ans = 1;
        for (auto &pp : pos) ans = (ans * pp) % MOD;
        for (auto &nn : neg) ans = (ans * nn) % MOD;
        if (neg.size() % 2) cout << (ans == 0 ? ans : MOD - ans) << endl;
        else cout << ans << endl;
        return 0;
    }
    sort(pos.begin(), pos.end()); sort(neg.begin(), neg.end());
    reverse(pos.begin(), pos.end());  reverse(neg.begin(), neg.end());
    if (pos.empty() && k % 2 == 1) {
        // negative answer
        long long p = 1;
        for(int i = 0; i < k; i++) {
            p = (p * neg[neg.size() - i - 1]) % MOD;
        }
        cout << (p == 0 ? p : MOD - p) << endl;

    } else {
        //positive answer
        vector<pair<long long, int>> dbl;
        for(int i = 0; i + 1 < (int)neg.size(); i += 2) {
            dbl.push_back({1ll * neg[i] * neg[i + 1], -(i + 1)});
        }
        for(int i = 0; i + 1 < (int)pos.size(); i += 2) {
            dbl.push_back({1ll * pos[i] * pos[i + 1], i + 1});
        }
        sort(dbl.begin(), dbl.end());
        reverse(dbl.begin(), dbl.end());
        long long ans = 1;
        int mx_pos = -1, mx_neg = -1;
        for(int i = 0; i < k / 2; i++) {
            if (dbl[i].second > 0) mx_pos = max(mx_pos, dbl[i].second);
            else mx_neg = max(mx_neg, -dbl[i].second);
        }
        if (k % 2 == 1) {
            //cout << mx_pos << " " << mx_neg << endl;
            if (mx_pos + 1 >= (int)pos.size() && mx_neg + 2 < (int)neg.size()) {
                mx_neg += 2;
                mx_pos -= 2;
            }
            for(int i = 0; i < mx_neg; i += 2) {
                ans = (ans * neg[i]) % MOD;
                ans = (ans * neg[i + 1]) % MOD;
            }
            for(int i = 0; i < mx_pos; i += 2) {
                ans = (ans * pos[i]) % MOD;
                ans = (ans * pos[i + 1]) % MOD;
            }
            ans = (ans * pos[mx_pos + 1]) % MOD;
            cout << ans << endl;
        } else {
            for(int i = 0; i < mx_neg; i += 2) {
                ans = (ans * neg[i]) % MOD;
                ans = (ans * neg[i + 1]) % MOD;
            }
            for(int i = 0; i < mx_pos; i += 2) {
                ans = (ans * pos[i]) % MOD;
                ans = (ans * pos[i + 1]) % MOD;
            }
            cout << ans << endl;
        }
    }
    return 0;
}


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

int main() {
    int p;
    int q;
    int r;

    cin >> p >> q >> r;

    // p+q, q+r, r+pで一番小さいのはどれかってこと

    int min = p+q;
    if((q+r)<min){
        min = (q+r);
    }
    if((r+p)<min){
        min = (r+p);
    }

    cout << min << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
set<pair<char,int> >s;
string str="SHCD";
int main(){
	// S H C D
	int n;cin>>n;
	char c;int k;
	for(int i=0;i<n;i++){
		cin>>c>>k;
		s.insert({c,k});
	}
	for(int i=0;i<str.length();i++){
		c=str[i];
		for(int j=1;j<=13;j++)
			if(s.find({c,j})==s.end())
				cout<<c<<' '<<j<<endl;
	}
	return 0;
}


Measured memory_bytes: 3204
#include <vector>
#include <iostream>
#include <cmath>
#include <iomanip>
#include <string>
#include <utility>
#include <stack>
#include <numeric>
#include <random>
#include <algorithm>
#include <queue>
#include <functional>
#include <iterator>
#include <list>
#include <unordered_map>
#include <deque>
#include <math.h>
#include <tgmath.h>
using namespace std;

#define rep(i, b, e) for(i = b; i < e; ++i)
#define repr(i, b, e) for (i = b; i >= e; --i)
#define ull unsigned long long int
#define ll long long int
#define pint pair<int, int>

#define M_DEBUG 1
#define PI 3.141592653589793

#define E '\n'

#define print(x) cout << (x) << endl;
#define printa(x,n) for(int i = 0; i < n; i++){ cout << (x[i]) << "\n";}
#define INF (1e18)

const ll MAX = 1000000000;
const ll MOD = 1e9 + 7;

ull a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z;

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;
}

ll aabs(ll a) {
    if (a < 0) return -a;
    return a;
}

//fast power
ll calc(ll a, ll b) {
    if (b == 0) return 1;
    else if (b % 2 == 0) {
        ll d = calc(a, b / 2);
        return (d * d) % MOD;
    }
    else return (a * calc(a, b - 1)) % MOD;
}

//fast combination
ll comb(ll n, ll a) {
    ll b = 1, c = 1;
    for (ll i = 1; i <= a; ++i) {
        b = b * i % MOD;
        c = c * (n - i + 1) % MOD;
    }

    return c * calc(b, MOD - 2) % MOD;
}

int kyotsu(string ss, int st, int ed, string ss2) {
    int ans = 0;
    for ( int i = st; i < ed; ++i ) {
        if (i - st >= ss2.size()) return ans;
        if (ss[i] == ss2[i - st] || ss[i] == '?') {
            ans++;
        } else {
            return -1;
        }
    }
    return ans;
}

int main(void) {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string ss;
    cin >> ss;

    string tmpp = ss;
    reverse(tmpp.begin(), tmpp.end());
    if (ss != tmpp) {
        cout << "No" << endl;
        return 0;
    }

    string tmpr = ss.substr(0, (ss.size() - 1) / 2);
    string tmp = tmpr;
    reverse(tmpr.begin(), tmpr.end());
    if (tmp != tmpr) {
        cout << "No" << endl;
        return 0;
    }

    string tmpr2 = ss.substr((ss.size() + 2) / 2, (ss.size() - 1));
    string tmp2 = tmpr2;
    reverse(tmpr2.begin(), tmpr2.end());
    if (tmp2 != tmpr2) {
        cout << "No" << endl;
        return 0;
    }

    cout << "Yes" << endl;
 
    return 0;
}

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

#ifdef INPUT
#include <sstream>
stringstream input_(R"(
10
)");
#define cin input_
#endif

int main()
{
	int x;
	cin >> x;
	int max = 1;

	for (int i=2; i<x; i++)
	{
		int y = i*i;

		if (y > x)
			break;

		while (y <= x)
			y *= i;

		if (max < y/i)
			max = y/i;
	}

	cout << max << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
int32_t main()
{
  int a,v,b,w,t;
  cin>>a>>v>>b>>w>>t;
  int res=v*t;
  int res1=w*t;
  int d1=a+res;
  int d2=b+res1;
  int x=res-res1;
  int y=abs(a-b);
  if(x>=y)
  {
    cout<<"YES";
  }
  else
  {
    cout<<"NO";
  }
}

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

ll mod = 1000000007;

int main(){
	ll n, k;
	cin >> n >> k;
	ll ans = 1;
	vector<ll> a(n+1);
	ll l = 0;
	rep(i, n){
		l += i;
		if(l >= mod) l %= mod;
//		cout << l << endl;
		a.at(i) = l;
	}
	for(ll i=k; i<=n; i++){
		ans += i*n - a.at(i-1) - (a.at(i-1) - 1);
//		cout << i*n - a.at(i-1) << ' ' << a.at(i-1) - 1 << endl;
		if(ans >= mod) ans %= mod;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4728
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define ii pair<int, int>
#define vii vector<ii>
#define vvi vector<vi>
#define vvii vector<vii>
#define ld long double
#define iii tuple<int, int, int>
#define sc scanf
#define pb push_back
#define FOR for(int i=1; i<=n; ++i)

int a[200005];

int main() {

    int n;
    sc("%d", &n);

    FOR {
        sc("%d", &a[i]);
    }

    ll ans = 0LL;

    int mx = a[1];

    for(int i=2; i<=n; ++i) {

        if(a[i] < mx) {
            ans += (mx - a[i]);
        }
        mx = max(a[i], mx);
    }

    printf("%lld\n", ans);
}


Measured memory_bytes: 4536
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define TEST int t = 1; while(t--) solve()

void solve(){
    string s;
    cin>>s;
    int i=0;
    int j=s.size()-1;
    int ans=0;
    while(i<j)
      {
      	 if(s[i]!=s[j])
      	 	ans++;
      	 j--;
      	 i++;
      }
   cout<<ans<<" ";
}

signed main(){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL); TEST; return 0;
}

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

using namespace std;

int INF=1e9;

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

    int n;
    cin>>n;

    vector<int> a(n);
    for(int i=0;i<n;i++)cin>>a[i];

    sort(a.begin(),a.end());

    cout<<a[n-1]<<" ";

    int m=a[n-1]/2,r=abs((a[n-1]-a[0])-m),pos=0;

    for(int i=0;i<n;i++){
        if(abs((a[n-1]-a[i])-m)<r){
            r=abs((a[n-1]-a[i])-m);
            pos=i;
        }
    }
    cout<<a[pos]<<endl;
}

Measured memory_bytes: 768
#include <iostream>
#include <vector>
using namespace std;
 
int main() {
    int n,m;
    cin >> n >> m;
    vector<int> k(m),p(m);
    vector<int> s[m];
    for(int i=0; i<m; i++){
        cin >> k[i];
        for(int j=0; j<k[i]; j++){
            int x;
            cin >> x;
            s[i].push_back(x-1);
            }
        }
    for(int i=0; i<m; i++) cin >> p[i];
  
  int ans=0;
  for (int bits=0; bits < (1<<n); bits++) {
    bool flag = true;
    for(int i=0; i<m; i++){
      int sum=0;
      for(int j=0; j<k[i]; j++){
        sum += ((bits>>s[i][j]) & 1);
      }
      if(sum%2 != p[i]) flag = false;      
     }
    if (flag) ans++;
   } 
  cout << ans << endl;
}
 


Measured memory_bytes: 3616
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
Alice = list()
Bob = list()
for i in range(n):
    if i % 2 == 0:
        Alice.append(a[i])
    else:
        Bob.append(a[i])

print(sum(Alice) - sum(Bob))


Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include<vector>
#include<algorithm>
#include<utility>
#include<queue>
#include<math.h>
#include<stack>
#include<set>
#include<map>
#define INF 1000000007
#define rep(i,n,m) for(int i=n;i<m;i++)

using namespace std;

int main()
{
	int D, d = 26;
	cin >> D;
	vector<int>c(d);
	rep(i, 0, d)cin >> c[i];
	
	vector<int>ans;
	vector<int>done(26, 0);
	rep(j, 1, D+1) {
		vector<pair<long long int, int>>s(d);
		rep(i, 0, d) {
			cin >> s[i].first;
			s[i].second = i + 1;
			s[i].first += j*c[i] * (D-done[i]) * (D + 1-done[i]) / 2;
		}
		sort(s.begin(), s.end());
		ans.push_back(s[d - 1].second);
		done[s[d - 1].second - 1] = j;
	}
	for (auto a : ans)cout << a << endl;;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
#define rreps(i,n,s) for(int i=s;i>=n;i--)
#define MOD 1000000007
using ll = long long;
using namespace std;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int n,k;
cin>>n>>k;
vector<int>a(n);
rep(i,n)cin>>a[i];
if(n>k){
    int ans=1;
    int v=k;
    while(v+(k-1)<n){
        v+=(k-1);
        ans++;
    }
    ans++;
    cout<<ans<<endl;
}
else{
    cout<<1<<endl;
}
//system("pause");
return 0;
}

Measured memory_bytes: 640
#include <iostream>
using namespace std;
string a, b, c;
int main()
{
	cin >> a >> b >> c;
	if(a[a.size() - 1] == b[0] && b[b.size() - 1] == c[0]){
		cout << "YES";
	}else {
		cout << "NO";
	}
    return 0;
}


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

typedef long long int ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<ll, ll> Pair;
typedef vector<Pair> VP;

#define MOD 1000000007
#define times(n) rep(_idx, n)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, s, n) for(int i = (int)(s); i < (int)(n); i++)
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mk make_pair
#define out(x) cout << (x) << endl;
#define DU(x) cout << #x << " = " << (x) << endl;
#define VEC(n, x) VI n; n.resize(x); rep(i, x) cin >> n[i];
#define MAT(m, x, y) VVI m; m.resize(x); rep(i, x) m[i].resize(y); 

template <typename _Ty>ostream& operator << (ostream& ostr, const vector<_Ty>& v) {if (v.empty()) {ostr << "[]";return ostr;}ostr << "[" << v.front();for (auto itr = ++v.begin(); itr != v.end(); itr++) {ostr << ", " << *itr;}ostr << "]";return ostr;}

ll gcd(ll x, ll y) { return y == 0 ? x : gcd(y, x % y); }
ll lcm(ll x, ll y) { return x * (y / gcd(x, y)); }

int main() {
    int N, M; cin >> N >> M;
    VEC(a, N);
    rep(i, N) a[i] /= 2;
    ll t = a[0];
    rep(i, N) t = lcm(t, a[i]);
    rep(i, N) if ((t / a[i]) % 2 == 0) { out(0); return 0; }
    out((M / t + 1) / 2);
    return 0;
}

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

namespace AtCoder_solve
{
    class Program
    {
        public const ulong mod = 1000000007;

        static void Main(string[] args)

        {
            var nm = Input3();
            var a = Input3();
            var sum = 0L;
            var ans = "Yes";

            Array.Sort(a);

            foreach(var s in a)
            {
                sum += s;
            }

            if (a[nm[0] - nm[1]] < (double)sum/4/nm[1]) ans = "No";
            Console.WriteLine(ans);
                





        }

       
        static public long Input()
        {
            return long.Parse(Console.ReadLine());
        }

        static public string[] Input2()
        {
            return Console.ReadLine().Split();
        }

        static public long[] Input3()
        {
            string[] data = Console.ReadLine().Split();
            long[] res = new long[data.LongLength];
            for(long i = 0; i < data.LongLength; i++)
            {
                res[i] = long.Parse(data[i]);
            }
            return res;
        }
        public static long Choose(long n, long a)
        {
            long x = 1;
            long y = 1;
            for (long i = 0; i < a; i++)
            {
                x *= n - i;
                y *= i + 1;
            }
            return x / y;
        }
    }
}


Measured memory_bytes: 11348
#input of int(split by space)
def get_i()
  return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
  return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
  return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
  return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end
#create of array
def array(size1,init=nil,size2=-1)
  if size2==-1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

def max(a,b)
    return a>b ? a : b
end

def min(a,b)
    return a>b ? b : a
end

INF=Float::INFINITY

N,C,K=get_i
t=array(N)
N.times do|i|
    t[i]=gets.to_i
end
t.sort!
head=0
tail=0
ans=0
while head<N
    while tail<N and tail-head+1<=C and (t[tail]-t[head])<=K
      tail+=1   
    end
    if tail>=N
        ans+=1
        break
    end
    ans+=1
    head=tail
end
puts ans

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

	long long ans=0;
	for(int i=1; i<=n; ++i){
		long long y=n/i;
		ans += (y*(y+1)/2)*i;
	}

	cout << ans << endl;
}

Measured memory_bytes: 3616
{
  const main = (input: string) => {
    const r = reader(input)
    const n = r.n()

    const base = Math.floor(n / 1.08)
    const checks = [-2, -1, 0, 1, 2]
    const res = checks
      .map(v => v + base)
      .some(v => {
        if (Math.floor(v * 1.08) === n) {
          console.log(v)
          return true
        }
        return false
      })
    if (!res) {
      console.log(':(')
    }
  }

  // const values = obj => Object.keys(obj).map(e => obj[e]);

  const reader = (str: string) => {
    const lines = str.trim().split('\n')
    const s = () => lines.shift() || ''
    const n = () => Number(s())

    const ss = () => s().split(' ')
    const ns = () => ss().map(Number)
    return { lines, s, n, ss, ns }
  }

  const getInput = () => require('fs').readFileSync('/dev/stdin', 'utf8')
  main(getInput())
}


Measured memory_bytes: 7500
import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val n = sc.nextInt()
    val as = List.fill(n)(sc.nextInt())
    val ass = as.sorted.reverse
    var ans = 0
    for (i <- ass.indices) {
      if (i % 2 == 0) {
        ans += ass(i)
      } else {
        ans -= ass(i)
      }
    }

    println(ans)
  }
}


Measured memory_bytes: 25668
import java.util.Scanner;

public  class Main {

  public static void main(String[] args) {

    Scanner sin = new Scanner(System.in);

    int a = sin.nextInt();
    int b = sin.nextInt();

    sin.close();
    
    System.out.println(a*b + " " + (a+b)*2);
  }
}


Measured memory_bytes: 26132
from bisect import bisect_left, bisect_right
from math import ceil
x, y, z, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
a.sort()

bc = [x+y for x in b for y in c]
bc.sort()


def count_bigger_than(X):
    res = 0
    for v in a:
        res += len(bc)-bisect_right(bc,X-v-1)
    return res

  

right_bound = 3*10**10 + 1#以上の物の個数がK以下
left_bound = 0 #以上の物の個数がKより大きい

while right_bound - left_bound > 1:
    m = (right_bound + left_bound)//2
    if count_bigger_than(m)>k:
        left_bound = m
    else:
        right_bound = m


V = left_bound

ans_que = []

for v in a:
    for i in range(len(bc)-1,-1,-1):
        if v+bc[i]>=V:
            ans_que.append(v+bc[i])
        else:
            break

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







Measured memory_bytes: 243480
#include <stdio.h>
#include <iostream>
#include <vector>

int main(){
  int N;
  std::cin >> N;

  std::vector<int> vec(N);
  for (int i=0;i<N;i++){
    std::cin >> vec.at(i);
  }

  int count =0;
  bool flg = true;
  while (flg) {
    flg = false;
    for (int i=N-1 ; i > 0 ; i--  ) {
      if (vec.at(i)  < vec.at(i-1)) {
        int v1 = vec.at(i);
        vec.at(i) = vec.at(i-1);
        vec.at(i-1) = v1;
        flg =true;
        count++;
      }
    }
  }

  std::cout << vec.at(0);
  for (int i=1;i < N;i++){
    std::cout << " " << vec.at(i);
  }
  std::cout << std::endl << count << std::endl;

}


Measured memory_bytes: 3124
import java.util.*;
public class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
 
   int N = sc.nextInt();
   int K = sc.nextInt();
   int ans =1;
   for(int i=0;i<N;i++) 
   {
     if(ans<K) ans*=2;
     else ans+=K;
   } 
   System.out.println(ans);
 }
}

Measured memory_bytes: 19920
public class Main {


  private static void solve() {
    int a = ni();
    int b = ni();
    if (a <= 5) {
      System.out.println(0);
    } else if (a <= 12) {
      System.out.println(b / 2);
    } else {
      System.out.println(b);
    }
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}


Measured memory_bytes: 23252
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
int a[100005];
int main()
{
	int n,m,a,b;
	int x[200005]={0};
	scanf("%d%d",&n,&m);
	for(int i=0;i<m;i++)
	{
		scanf("%d%d",&a,&b);
		if(a==1)
		{
			x[b]++;
		}
		else if(b==1)
		{
			x[a]++;
		}
		if(a==n)
		{
			x[b]++;
		}
		else if(b==n)
		{
			x[a]++;
		}
	}
	for(int i=1;i<=m;i++)
	{
		if(x[i]>1)
		{
			printf("POSSIBLE\n");
			return 0;
		}
	}
	printf("IMPOSSIBLE\n");
	return 0;
 } 

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

public class Main {

	static Scanner scanner;
	public static void main(String[] args) {
	    scanner = new Scanner(System.in);

	    int n=gi();
	    long x=gl();
	    long[] a=new long[n];
	    long s=0;
	    for(int i=0; i<n;i++) {
	    	a[i]=gl();
	    	s+=a[i];
	    }
	    if (s<x) {
	    	System.out.println(n-1);
	    } else {
	    	Arrays.parallelSort(a);
	    	int c=0;
	    	for(int i=0; i<n;i++) {
		    	if(x>=a[i]) {
		    		x-=a[i];
		    		c++;
		    	}else {
		    		break;
		    	}
		    }
	    	System.out.println(c);
	    }
	    //System.out.println(d);
	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

Measured memory_bytes: 35560
#include<iostream>
#include<cstdio>
#include<functional>
#include<cstdlib>
#include<stdexcept>
#include<numeric>
#include<cmath>
#include<fstream>
#include<memory>
#include<algorithm>
#include<cstring>
#include<ctime>
#include<deque>
#include<sstream>
#include<iomanip>
#include<sstream>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<climits>
#include<map>
#include<set>
#include<list>
#include<cassert>
#include<deque>
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define INF 1<<27
#define all(n) n.begin(),n.end()
#define insert(a,b,c,d) PP(P(a,b),P(c,d))
#define F first
#define iter(c) __typeof__((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();++i)
#define S second
#define ppins(a,b,c,d) PP(P(a,b),P(c,d))
#define pb push_back
#define pf push_front
#define LIM 100000
using namespace std;
typedef pair<int,int> P;
typedef pair<P,P> PP;
typedef long long ll;
typedef unsigned long long ull;

int main(){
  int N;
  cin >> N;
  int C[N+1][N+1];

  rep(i,N)
      rep(j,N)
	cin >> C[i][j];

  ll cost = 0;
  rep(i,N)
    {
      for(int j=i+1;j<N;j++)
	{
	  cost += min(C[i][j],C[j][i]);
	}
    }    

  cout << cost << endl;

return 0;
}

Measured memory_bytes: 1196
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<math.h>
#include<queue>

using namespace std;


int main() {
	int E, Y;
	cin >> E >> Y;

	if (E == 0) {
		if (1868 <= Y && Y <= 1911) {
			cout << "M" << Y - 1867 << endl;
		}
		if (1912 <= Y && Y <= 1925) {
			cout << "T" << Y - 1911 << endl;
		}
		if (1926 <= Y && Y <= 1988) {
			cout << "S" << Y - 1925 << endl;
		}
		if (1989 <= Y && Y <= 2016) {
			cout << "H" << Y - 1988 << endl;
		}
	}
	if (E == 1) {
		cout << Y + 1867 << endl;
	}
	if (E == 2) {
		cout << Y + 1911 << endl;
	}
	if (E == 3) {
		cout << Y + 1925 << endl;
	}
	if (E == 4) {
		cout << Y + 1988 << endl;
	}


	return 0;
}



Measured memory_bytes: 3096
#include<bits/stdc++.h>
#define ll  long long
#define ull unsigned long long
using namespace std;
const int N=1e4+5,M=1e9+7;
const ull base=13331;
const double Pi=acos(-1.0);
const ll C=299792458;
int main(){
	ios::sync_with_stdio(false);
	int n;
	cin>>n;
	int pre=0;
	int ans=0;
	for(int i=1;i<=n;i++){
		int k;
		cin>>k;
		if(k>=pre){
			ans++;
			pre=k;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
from collections import deque

def make_wall(maze,h,w):
    maze=deque(maze)
    for i in range(h):
        maze[i]="#"+maze[i]+"#"
    maze.appendleft("#"*(w+2))
    maze.append("#"*(w+2))
    return list(maze)

def bfs(maze, visited, sy, sx, gy, gx):
    queue = deque([[sy, sx]])
    visited[sy][sx] = 0
    while queue:
        y, x = queue.popleft()
        if [y, x] == [gy, gx]:
            return visited[y][x]
        for j, k in ([1, 0], [-1, 0], [0, 1], [0, -1]):
            new_y, new_x = y+j, x+k
            if maze[new_y][new_x] == "." and visited[new_y][new_x]==-1:
                visited[new_y][new_x]=visited[y][x]+1
                queue.append([new_y,new_x])
    return -1

h,w=map(int,input().split())
maze=[input() for _ in range(h)]
kabe=0
for i in range(h):
    kabe+=maze[i].count("#")
maze=make_wall(maze,h,w)
visited=[[-1]*(w+2) for _ in range(h+2)]
sy,sx=1,1
gy,gx=h,w
d=1+bfs(maze, visited, sy, sx, gy, gx)
if d==0:
    print(-1)
else:
    print(h*w-kabe-d)

Measured memory_bytes: 3436
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
#define int long
#define ll long long
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define pb push_back
#define mk make_pair
#define all(x) x.begin(),x.end()
#define SZ(x) x.size()
#define fi first
#define se second
const int INF = 1e9;
using namespace std;

template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;

using pi=pair<int,int>;
using vi=vc<int>;

int N,A,B;
int H[100010];

bool isOK(int n) {
    int cnt=0;
    rep(i,N){
        int pos=H[i]-B*n;
        if(pos>0) cnt+=(pos+A-B-1)/(A-B);
    }
    if(cnt<=n) return true;
    else return false;
}

int binary_search() {
    int left = -1;
    int right = INF;

    while (right - left > 1) {
        int mid = left + (right - left) / 2;

        if (isOK(mid)) right = mid;
        else left = mid;
    }

    return right;
}

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

    cin >> N >> A >> B;
    rep(i,N) cin >> H[i];
    cout << binary_search() << endl;

}

Measured memory_bytes: 1024
import sys
input=sys.stdin.readline
from collections import deque
from heapq import heappush,heappop
import re

def int_raw():
    return int(input())
 
def ss_raw():
    return input().split()
 
def ints_raw():
    return tuple(map(int, ss_raw()))


def main():
    N ,Q = ints_raw()
    origST = []

    for _  in range(N):
        S,T,X = ints_raw()
        origST.append([S-X,T-X,X])
    Ds = [int(input()) for _ in range(Q)]

    origST.sort()
    stidx = 0
    cur_set = []
    for d in Ds:

        while stidx < len(origST):
            st = origST[stidx]
            if st[0] > d:
                break
            heappush(cur_set,(st[2],st[1]))
            stidx+=1
        while cur_set and cur_set[0][1] <=d:
            heappop(cur_set)
        if cur_set:
            print(cur_set[0][0])
        else:
            print(-1)
main()


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

int a[60], b[60], c[60], d[60];

int main() {
    int N, M;
    cin >> N >> M;
    for (int i = 0; i < N; i++) cin >> a[i] >> b[i];
    for (int i = 0; i < M; i++) cin >> c[i] >> d[i];

    for (int i = 0; i < N; i++) {
        int minDist = 1001001001, ans = 0;
        for (int j = 0; j < M; j++) {
            int dist = abs(a[i] - c[j]) + abs(b[i] - d[j]);
            if (minDist > dist) {
                minDist = dist;
                ans = j + 1;
            }
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 256