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

using namespace std;

int N,W;

int dp[105][10005];

int ans=0;

int main(){
    scanf("%d%d",&N,&W);
    for(int i=1;i<=N;i++){
        int v,w;
        scanf("%d%d",&v,&w);

        for(int weight=0;weight<=W;weight++)
            for(int j=0;j<=1;j++){
                int neww=weight+j*w,newv=dp[i-1][weight]+j*v;
                if (neww>W) continue;
                dp[i][neww]=max(dp[i][neww],newv);
                ans=max(ans,dp[i][neww]);
            }
    }

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

    return 0;
}


Measured memory_bytes: 6528
N = int(input())
left = 0
right = 10000
while right - left > 1:
    mid = (left + right) // 2
    if mid * (mid + 1) // 2 < N:
        left = mid
    else:
        right = mid
ans = {i for i in range(1, right + 1)}
ans -= {right * (right - 1) // 2 - N + right}
print('\n'.join(map(str, ans)))


Measured memory_bytes: 3572
import java.util.Scanner;

/**
 * 
 * @author tmikami
 * 
 * solution:
 * 
 * prerequisite :
 *  if C=D -> "No" (impossible)
 *  if one of A-th, B-th, C-th, D-th place is "#" -> "No" (impossible)
 * 
 * case 1) C < D :
 *   if "##" block does not exist in the interval (A,C) and (B,D): -> "Yes"
 *   else: -> "No"
 *  
 * case 2) C > D :
 *   if "..." block does not exist in the interval [B-1,D+1] -> "No"
 *   else: -> same as case 1)
 *
 */
public class Main {

	/**
	 * problem solver
	 */
	public static class Problem {

		/**
		 * paramters
		 */
		private int N;
		private int A;
		private int B;
		private int C;
		private int D;
		private String S;

		/**
		 * constructor
		 */
		Problem() {
		}

		/**
		 * standard input
		 */
		void input() {
			Scanner sc = new Scanner(System.in);
			N = sc.nextInt();
			A = sc.nextInt();
			B = sc.nextInt();
			C = sc.nextInt();
			D = sc.nextInt();
			S = sc.next();
			sc.close();
			
			S = "_" + S;
		}


		/**
		 * solver
		 */
		void solve() {
			
			// prerequisite
			if ( C == D || S.charAt(A) == '#' || S.charAt(B) == '#' || S.charAt(C) == '#' || S.charAt(D) == '#') {
				System.out.println("No");
				return;
			}
			
			// case 2
			if ( C > D) {
				
				// check if "..." block exists in the interval [B-1,D+1] 
				boolean flag = false;
				for (int i=B-1; i<=D-1; i++) {
					// boost
					if ('#' == S.charAt(i+2)) {
						i+=2;
						continue;
					}

					if ("...".equals(S.substring(i,i+3))) {
						flag = true;
						break;
					}
				}
				if (!flag) {
					System.out.println("No");
					return;					
				}
			}
			
			// case 1
			// check if "##" block does not exist in the interval (A,C) and (B,D)
			boolean flag = true;
			for (int i=A+1;i<Math.max(C, D);i++) {
				if (i>=C && i<=B) continue;
				
				if ("##".equals(S.substring(i,i+2))) {
					flag = false;
					break;
				}				
				
			}
			
//			for (int i=A+1;i<C;i++) {
//				if ("##".equals(S.substring(i,i+2))) {
//					flag = false;
//					break;
//				}
//			}
//			for (int i=B+1;i<D;i++) {
//				if ("##".equals(S.substring(i,i+2))) {
//					flag = false;
//					break;
//				}
//			}
			
			if (flag) {
				System.out.println("Yes");
			} else {
				System.out.println("No");
			}
			
		}

	}

	public static void main(String args[]) {

		Problem p = new Problem();

		p.input();

		p.solve();
	}
}


Measured memory_bytes: 34980
#include <stdio.h>
int main(void){
    int n,a,b,c;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d%d",&a,&b);
        c=a%b;
        if(c==0)c+=b;
        printf("%d\n",c);
    }
    
}


Measured memory_bytes: 2768
#include <bits/stdc++.h>
//#pragma GCC optimize(2)

using namespace std;
#define LL long long
#define Rint register int
#define U unsigned
#define forn(i,a,b) for(int i = a;i <= b;++i)
#define nfor(i,a,b) for(int i = a;i >= b;--i)
#define pii pair<int ,int>
#define MS0(X) memset(X,0,sizeof(X))
#define MSf(X) memset(X,false,sizeof(X))
#define MS1(X) memset(X,-1,sizeof(X))
#define BR printf("--------------------\n")
#define pb push_back
#define rep(i,a,b) for(Rint i=a;i<=b;++i)
#define DEBUG(x) std::cerr << #x << '=' << x << std::endl
const double PI=atan(1.)*4.;
const int maxn=1e6+5;
const int inf = 0x3f3f3f3f;
const int mod=1e9+7;
const double e=2.71828182845904523536;
int dirx[8]={1,0,-1,0,1,-1,-1,1};
int diry[8]={0,1,0,-1,1,1,-1,-1};

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int a,b;
    cin>>a>>b;
    if(a>9||b>9||a<1||b<1)
    cout<<-1<<"\n";
    else 
    cout<<a*b<<"\n";
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
const int maxn=2e5+7;
ll gcd1(ll a,ll b)
{
	if(b==0) return a;
	else
	{
		return gcd1(b,a%b);
	}
}
int main()
{
	ll n,a,b,x;
	scanf("%lld",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&x);
		if(i==1)
		{
			a=x;
		}
		else
		{
			a=gcd1(a,x);
		}
	}
	printf("%lld\n",a);
	return 0;
}

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

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

int main() {
    int y, m, d;
    char c1, c2;
    cin >> y >> c1 >> m >> c2 >> d;
    if (m <= 4)
        cout << "Heisei" << endl;
    else
        cout << "TBD" << endl;
    return 0;
}

Measured memory_bytes: 3624
#include <cstdio>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <cmath>
#include <iomanip>
#include <deque>
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;
ll intpow(ll N, ll P){
    if(P==0) return 1;
    if(P%2==0){
        ll t = intpow(N, P/2);
        return t*t;
    }
    return N * intpow(N, P-1);
}
ll gcd(ll n,ll m){
    n = max(n,m);
    m = min(n,m);
    if(n%m == 0)return m;
    return gcd(m,n%m);
}
ll lcm(ll n,ll m){
    return n*m/gcd(n,m);
}
deque<char> deq;
int main(){
    string s;cin>>s;
    for(auto tmp : s){
        deq.push_back(tmp);
    }
    int q;cin >> q;
    int sw=0;
    rep(i,q){
        int qu;cin>>qu;
        if(qu==1)sw++;
        else{
            int f;char c;cin>>f>>c;
            if(sw%2 == 0){
                if(f == 1)deq.push_front(c);
                if(f == 2)deq.push_back(c);
            }
            if(sw%2 == 1){
                if(f == 1)deq.push_back(c);
                if(f == 2)deq.push_front(c);
            }
        }
    }
    string ans;
    for(auto tmp : deq)ans.push_back(tmp);
    if(sw%2 == 0){
       cout <<ans<< endl;
    }
    else{
        reverse(ans.begin(),ans.end());
        cout << ans <<endl;
    }
}

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

int main()
{
    int n;
    cin >> n;
    vector<ll> A(n);
    rep(i, n) cin >> A[i];

    int ans = 0;
    int s = 0; //1は増加中,2は減少中
    rep(i, n - 1)
    {
        if (s == 1 && A[i + 1] < A[i])
        {
            s = 0;
            ans++;
        }
        else if (s == 2 && A[i + 1] > A[i])
        {
            s = 0;
            ans++;
        }
        else if (s == 0)
        {
            if (A[i] < A[i + 1])
                s = 1;
            if (A[i] > A[i + 1])
                s = 2;
        }
    }

    cout << ans + 1 << endl;
}

Measured memory_bytes: 4052
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define D()
#define INF 1000000000000
#define MOD 10000007
#define MAXR 100000
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define INITA(a,i,j,v) for(ll k=i;k<=j;k++){a[k]=v;}

int main() {
    ll n; cin >> n;
    ll a[100001]; INITA(a, 0, 100000, 0);
    ll b[100001]; INITA(b, 0, 100000, 0);

    ll a_tot = 0;
    ll b_tot = 0;
    REP(i, n) { cin >> a[i]; a_tot += a[i]; }
    REP(i, n) { cin >> b[i]; b_tot += b[i]; }

    if (a_tot < b_tot) {
        cout << -1 << endl;
    } else {
        // a - bの差分を取得する (plus, minusにわける)
        vector<ll> plus;
        ll minus_tot = 0;
        ll res = 0;
        REP(i, n) {
            ll diff = a[i] - b[i];
            if (diff < 0) {
                minus_tot -= diff;
                res++;
            } else if (diff > 0) {
                plus.push_back(diff);
            }
        }
        sort(ALL(plus));
        while (minus_tot > 0) {
            ll p = plus[plus.size()-1];
            plus.pop_back();
            res++;
            minus_tot -= p;
        }
        cout << res << endl;
    }

    return 0;
}

Measured memory_bytes: 5500
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int ans = 0;
		for (int i = 0; i < n; i++) {
			int a = sc.nextInt();
			while (a % 2 == 0) {
				ans++;
				a /= 2;
			}
		}
		sc.close();

		System.out.println(ans);
	}
}


Measured memory_bytes: 34368
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

ll MOD = 998244353LL;

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

    ll cnt[N];
    fill(cnt, cnt + N, 0);
    for(int i = 0; i < N; i++){
        cnt[d[i]]++;
    }

    //int mx_d = *max_element(d, d + N);

    bool exist = true;
    if(cnt[0] != 1) exist = false;
    if(d[0] != 0) exist = false;
    for(int i = 0; i < N - 1; i++){
        if(cnt[i + 1] > 0 && cnt[i] == 0) exist = false;
    }

    ll ans = 0;
    if(exist){
        ans = 1;
        for(int i = 1; i < N; i++){
            if(cnt[i] > 0){
                for(int j = 0; j < cnt[i]; j++){
                    ans *= cnt[i - 1];
                    ans %= MOD;
                }
            }
        }
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
	int a[10];
	for(int i=0;i<10;i++){
		cin>>a[i];
	}
	sort(a,a+10);
	cout<<a[9]<<endl;
	cout<<a[8]<<endl;
	cout<<a[7]<<endl;
	return 0;
	}


Measured memory_bytes: 3104
import numpy as np

def solve(a, b, h, m):
    theta_a = 2 * np.pi * (h + m / 60) / 12
    theta_b = 2 * np.pi * m / 60
    x_a, y_a = (a * np.cos(theta_a), a * np.sin(theta_a))
    x_b, y_b = (b * np.cos(theta_b), b * np.sin(theta_b))
    return np.sqrt((x_a-x_b)**2 + (y_a-y_b)**2)

a, b, h, m = map(int, input().split())
print(solve(a, b, h, m))

Measured memory_bytes: 27108
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int N,K;
	long long c1=0;
	long long c2=0;
	cin >> N >> K;
	
	for(int i=1; i <= N; i++){
		if(K % 2 == 0){
			if(i % K ==0)
              c1++;
			else if(i % (K/2) == 0)
              c2++;
		}
		else{
			if(i % K ==0)
				c1++;
		}
	}
	
	cout << c1 * c1 * c1 + c2 * c2 * c2 << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
 
        int a = sc.nextInt();
        int b = sc.nextInt();
 
        System.out.println(gcd(a, b));
 
    }
 
    public static int gcd(int x, int y){
        int r;
        if (x < y) {
            swap(x, y);
        }
        while (y > 0) {
            r = x % y;
            x = y;
            y = r;
        }
        return x;
    }
    public static void swap(int a,int b)
 
    {
 
        int temp=a;
 
        a=b;
 
        b=temp;
 
    }
}


Measured memory_bytes: 26248
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int X = sc.nextInt();
        int Y = sc.nextInt();
        int prize = 0;
        
        switch(X){
            case 1: prize += 100000;
            case 2: prize += 100000;
            case 3: prize += 100000;
        }
        switch(Y){
            case 1: prize += 100000;
            case 2: prize += 100000;
            case 3: prize += 100000;
        }
        if(prize == 600000){
            prize += 400000;
        }
        
        System.out.println(prize);
    }
}


Measured memory_bytes: 25172
#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>;

// Binary Indexed Tree (Fenwick Tree)
// https://youtu.be/lyHk98daDJo?t=7960
template<typename T>
struct BIT {
	int n;
	vector<T> d;
	BIT(int n = 0) :n(n), d(n + 1) {}
	void add(int i, T x = 1) {
		for (i++; i <= n; i += i & -i) {
			d[i] += x;
		}
	}
	T sum(int i) {
		T x = 0;
		for (i++; i; i -= i & -i) {
			x += d[i];
		}
		return x;
	}
	T sum(int l, int r) {
		return sum(r - 1) - sum(l - 1);
	}
};

int main() {
	int N, Q;
	scanf("%d %d", &N, &Q);
	BIT<long long> d(N);
	for (int i = 0; i < N; ++i) {
		long long num;
		scanf("%lld", &num);
		d.add(i, num);
	}
	for (int i = 0; i < Q; ++i) {
		long long x, y, z;
		scanf("%lld %lld %lld", &x, &y, &z);
		if (1 == x) {
			if (0 == y) {
				printf("%lld\n", d.sum(z - 1));
			}
			else {
				printf("%lld\n", d.sum(z - 1) - d.sum(y - 1));
			}
		}
		else {
			d.add(y, z);
		}
	}
	return 0;
}


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

int main(){
    int H,W;
   while(true){
       cin >>H >>W;
       if(H == 0&&W ==0) break;
       for(int i =0;i<H;i++){
           for(int j=0;j<W;j++){
               if(i%2==j%2){
                   cout << '#';
               }else{
                   cout <<'.';
               }
           }
           cout << "\n";
       }
       cout << endl;
       



   }
    
}


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

vector<vector<int>> edge;

void dfs(int now,int pre,int time,vector<int> &visitable){
  if(time<0) return;
  visitable.push_back(now);
  if(time==0) return;
  for(int i=0;i<edge[now].size();i++){
    int to=edge[now][i];
    if(to==pre) continue;
    dfs(to,now,time-1,visitable);
  }
  return;

}

int main(){
  int n,k; cin>>n>>k;
  edge.resize(n);
  for(int i=0;i<n-1;i++){
    int a,b; cin>>a>>b;
    a--,b--;
    edge[a].push_back(b);
    edge[b].push_back(a);
  }
  int sur_k=k/2;
  if(k%2==1){
    sur_k++;
  }
  int res=1e9;
  for(int g=0;g<n;g++){
    for(int j=0;j<edge[g].size();j++){
      vector<int> visitable;
      visitable.push_back(g);
      for(int i=0;i<edge[g].size();i++){
	if(i==j){
	  dfs(edge[g][i],g,sur_k-1,visitable);
	}
	else{
	  dfs(edge[g][i],g,k/2-1,visitable);
	}
      }

      int vc=visitable.size();
      res=min(res,n-vc);
    }
  }
  cout<<res<<endl;
  return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
//#define mt make_tuple
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
//typedef tuple<int,int,int> tp;
//typedef vector<tp> vt;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-7;
const int inf=1e9;
const ll INF=2e18;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(){
	int n,m;
	while(cin>>n>>m,n){
		vector<bool>in(8000000);
		for(int i=n;;i++)if(!in[i]){
			if(m==0){
				cout<<i<<endl;
				break;
			}
			m--;
			for(int j=i;j<8000000;j+=i)in[j]=true;
		}
	}
}

Measured memory_bytes: 4044
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7


def main():
    a = input().split()
    s = set(a)
    return len(s)


print(main())


Measured memory_bytes: 7840
N, M = map(int, input().split())
A = set(map(int, input().split()))

dp = [-1] * (N+1)
weights = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
# 0本のマッチで作れる最大の整数は０
dp[0] = 0

for i in range(N+1):
    for a in A:
        if i + weights[a] > N:
            continue
        dp[i + weights[a]] = max(dp[i + weights[a]], dp[i] * 10 + a)
print(dp[N])



Measured memory_bytes: 14692
#include <bits/stdc++.h>
 
#define ALL(l)  (l).begin(),(l).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
ll mod =  1000000007;
ll maxn = 1000000000;
 
//---------------------------------------------------------------------------------------------------
using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vll = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける
using vs = vector<string>; // stringの1次元の型に vs という別名をつける
using pll = pair<ll, ll>; // これ以降 pii という型名はpair<ll, ll> と同じ意味で使える
//---------------------------------------------------------------------------------------------------
 
int main(){
    ll x,y,a,b,c,ans=0;
    cin>>x>>y>>a>>b>>c;
    priority_queue<ll> bigq;
    
    vll p(a),q(b),r(c);
    rep(i,a)cin>>p.at(i);
    rep(i,b)cin>>q.at(i);
    rep(i,c)cin>>r.at(i);
    
    sort(ALL(p));
    reverse(ALL(p));
    sort(ALL(q));
    reverse(ALL(q));
    sort(ALL(r));
    reverse(ALL(r));

    rep(i,x) bigq.push(p.at(i));
    rep(i,y) bigq.push(q.at(i));
    if(x+y<c){
        rep(i,x+y) bigq.push(r.at(i));
    }else{
        rep(i,c) bigq.push(r.at(i));
    }
    
    rep(i,x+y){
        ll k=bigq.top();
        ans+=k;
        bigq.pop();
    }
    
    cout<<ans<<endl;
    
    
    
    
}
   



Measured memory_bytes: 8688
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int A, B, C, D, E, F;

int main() {
    cin >> A >> B >> C >> D >> E >> F;
    A *= 100; B *= 100;

    long long answater = 0; long long anssugar = 0;
    long double noudo = 0.0;
    for(int i = 0; i*A <= F; ++i) {
        for(int j = 0; j*B <= F-i*A; ++j) {
            long long water = i*A + j*B;
            long long sugarmax = (water/100) * E;
            // cout << "water " << water << " sugar " << sugarmax << endl;
            for(int k = 0; k*C <= sugarmax; ++k) {
                for(int l = 0; l*D <= sugarmax-k*C; ++l) {
                    long long sugar = k*C + l*D;
                    if(sugar <= sugarmax) {
                        if(water+sugar <= F) {
                            long double nownoudo = 100.0*sugar / (water+sugar);
                            if(nownoudo > noudo) {
                                answater = water;
                                anssugar = sugar;
                                noudo = nownoudo;
                            }
                        }
                    }
                }
            }
        }
    }

    if(anssugar == 0 && answater == 0) {
        cout << A << " " << anssugar << endl;
    }else {
        cout << answater+anssugar << " " << anssugar << endl;
    }
}

Measured memory_bytes: 256
// practice with Dukkha
#include <algorithm>
#include <iostream>

using namespace std;

const int N = 200000, MD = 1000000007;

int pp[N], qq[N];

int main() {
	int n, k; cin >> n >> k;
	if (n == k) {
		long long ans = 1;
		while (n--) {
			int a; cin >> a;
			ans = ans * a % MD;
		}
		if (ans < 0)
			ans += MD;
		cout << ans << '\n';
		return 0;
	}
	int np = 0, nq = 0;
	while (n--) {
		int a; cin >> a;
		if (a >= 0)
			pp[np++] = a;
		else
			qq[nq++] = -a;
	}
	sort(pp, pp + np);
	sort(qq, qq + nq);
	if (np == 0) {
		if (k % 2)
			reverse(qq, qq + nq);
		long long ans = 1;
		for (int j = nq - 1; j >= nq - k; j--)
			ans = ans * qq[j] % MD;
		if (k % 2)
			ans = MD - ans;
		cout << ans << '\n';
		return 0;
	}
	long long ans = 1;
	if (k % 2)
		ans = pp[--np];
	k /= 2;
	while (k--)
		if (np >= 2 && nq >= 2) {
			long long p = (long long) pp[np - 1] * pp[np - 2];
			long long q = (long long) qq[nq - 1] * qq[nq - 2];
			if (p > q) {
				ans = ans * (p % MD) % MD;
				np -= 2;
			} else {
				ans = ans * (q % MD) % MD;
				nq -= 2;
			}
		} else if (np >= 2) {
			long long p = (long long) pp[np - 1] * pp[np - 2];
			ans = ans * (p % MD) % MD;
			np -= 2;
		} else {
			long long q = (long long) qq[nq - 1] * qq[nq - 2];
			ans = ans * (q % MD) % MD;
			nq -= 2;
		}
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 4404
#include <cstdio>
#include <iostream>
#include <array>
#include <vector>
#include <deque>
#include <string>
#include <algorithm>
#include <functional>
#include <tuple>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <stack>
#include <utility>
#include <memory>
#include <valarray>
#include <climits>

using namespace std;

using ll = long long int;

#define REP(i, N) for (int i = 0; i < (N); ++i)
#define scanInt(x) int x; scanf("%d", &(x)); getchar();
#define scanLLInt(x) ll x; scanf("%lld", &(x)); getchar();
#define scanVecInt(A, N) vector<int> A(N); REP(i, N){scanf("%d", &(A[i])); getchar();}
#define scanVecLLInt(A, N) vector<ll> A(N); REP(i, N){scanf("%lld", &(A[i])); getchar();}

ll Dijkstra(vector<unordered_map<int, ll>>& edges, int start, int goal)
{
    if (start == goal) return 0;
    auto comp = [](pair<int, ll>& l, pair<int, ll>& r){return l.second > r.second;};
    priority_queue<pair<int, ll>, vector<pair<int, ll>>, decltype(comp)> pq(comp);
    vector<char> finished(edges.size(), false);
    pq.emplace(start, 0);
    finished[start] = true;

    while (!pq.empty()){
        const int next_node = get<0>(pq.top());
        const ll temp_cost = get<1>(pq.top());
        pq.pop();
        if (next_node == goal) return temp_cost;
        finished[next_node] = true;
        for (auto& node : edges[next_node]){
            if (finished[node.first]) continue;
            pq.emplace(node.first, temp_cost + node.second);
        }
    }
    return -1;
}

int main()
{
    scanInt(H);
    scanInt(W);
    vector<unordered_map<int, ll>> edges(10);
    REP(i, 10){
        REP(j, 10){
            scanInt(c);
            edges[i].emplace(j, c);
        }
    }
    vector<ll> min_cost;
    REP(i, 10) min_cost.emplace_back(Dijkstra(edges, i, 1));
    ll result = 0;
    REP(h, H){
        REP(w, W){
            scanInt(n);
            if (n != -1) result += min_cost[n];
        }
    }
    cout << result << endl;
}


Measured memory_bytes: 256
//計数ソート
//2018-12-21
//Ebitani Akira

#include <stdio.h>
#include <stdlib.h>
#define MAX 2000001
#define VMAX 10000

int main(){
  unsigned short *A, *B;
  int C[VMAX+1];
  int n, i, j;

  scanf("%d", &n);
  if( n < 1 || n > 2000000 ){
    printf( "要素数が適当ではありません。\n" );
  }

  A = malloc(sizeof(short)*n+1);
  B = malloc(sizeof(short)*n+1);

  /* your code */
  for( i= 0 ; i <= VMAX ; i++ ){
    C[i] = 0;
  }
  for( i = 0 ; i < n ; i++ ){
    scanf( "%hu", &A[i + 1] );
    C[A[i + 1]]++;

  }


  for( i = 0 ; i < VMAX ; i++ ){
    C[i + 1] = C[i + 1] + C[i];
  }


  for( j = 0 ; j < n ; j++ ){
    B[C[A[j+1]]] = A[j+1];
    C[A[j+1]]--;
  }


  for( i = 1 ; i <= n ; i++ ){
    printf( "%d", B[i] );
    if( i != n ){
      printf( " " );
    }
  }
  printf( "\n" );


  return 0;
}



Measured memory_bytes: 9652
using System;

public class First_problem{
  public static void Main(){
    int n;
    n = int.Parse(Console.ReadLine());
    
    int[] w = new int[n];
    int sum = 0;
    
    string[] str_weapon = Console.ReadLine().Split(' ');
    for(int i = 0 ; i < n ; i++){
      w[i] = int.Parse(str_weapon[i]);
      sum += w[i];
    }
    
	int t = 0;
    int count_t = 0;
    int first_t = 0;
    int last_t = 0;
    
    int cnt = 99999999;
    
    for( t = 1 ; t < n-1 ; t++){
      first_t = 0;
      last_t = 0;
      
      for( count_t = 0 ; count_t <= t ; count_t++ ){
        first_t += w[count_t];
      }
      
      last_t = sum - first_t;
      
      if( cnt > Math.Abs(first_t - last_t) ){
        cnt = Math.Abs(first_t - last_t);
      }
      
    }
    
    Console.WriteLine(cnt);
    
  }
}

Measured memory_bytes: 11092
import sys
input = sys.stdin.readline
sys.setrecursionlimit(100000)

def getN():
    return int(input())
def getList():
    return list(map(int, input().split()))
import math

n =getN()

nums = getList()
flag = 0
for i, x in enumerate(nums):
    if x != (i+1):
        flag += 1

if flag <= 2:
    print("YES")
else:
    print("NO")


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

//typedef long long ll;

int main(){
  int N,Y;
  cin>>N>>Y;
  int mmr=0;
  int maximum;
  maximum=Y/1000;
  int alpha=maximum-N;
  if(alpha<0){
    mmr=1;
  }
  int modf=alpha%4;
  int x=(alpha-9*modf)/4;
  if(x<0){
    mmr=1;
  }
  modf+=(x/9)*4;
  x=x%9;
  if(N<x+modf){
    mmr=1;
  }
  int sen=(Y-5000*x-10000*modf)/1000;
  if(mmr==1){
    cout<<-1<<" "<<-1<<" "<<-1<<endl;
  }
  else{
    cout<<modf<<" "<<x<<" "<<sen<<endl;
  }
}

Measured memory_bytes: 256
//Dragon_warrior7(IITK)
#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize ("-ffloat-store")
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;
#define ll long long
#define pb push_back
#define nl cout << '\n'
#define sor(x) sort(x.begin(), x.end())
#define rev(v) reverse(v.begin(), v.end())
#define lb(v, temp) lower_bound(v.begin(), v.end(), temp)
#define ub(v, temp) upper_bound(v.begin(), v.end(), temp)
#define fi first
#define se second
#define llmax 1000000000000000000
#define pll pair<ll, ll> 
#define ull unsigned ll
#define vll vector<ll> 
#define rub cout << "\n------------------------------------\n"
#define deb(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) 
{
	cout << *it << " = " << a;
	nl;
	err(++it, args...);
}
//typedef  tree < int ,  null_type ,  greater<int> ,  rb_tree_tag ,  tree_order_statistics_node_update > oset;
void read(vector<ll> &v)
{
	for (int i = 0; i < v.size(); i++)
		cin >> v[i];
}
// const int mod=1e9+7;
// ll power(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
// ll modInverse(ll a){return power(a,mod-2);}
ll n,m,a,b,c,k,temp,x,y;
void solveforthiscase(const int & test)
{//deb(test);
cin>>n>>k;
vll v(n);
read(v);
ll sum=0;
int pos=0;
int neg=0;
int z=0;
ll sumpos=0;
for(int i=0;i<n;i++)
{
   if(v[i]>0)
  { pos++;sumpos+=v[i];}
   else if(v[i]==0)
   z++;
   else
   neg++;
}
if(k>=n+neg)
{
   cout<<sumpos;
   return ;
}
ll mx=-llmax;
for(int i=0;i<=min(k,n);i++)
{
   for(int j=0;j<=min(k-i,n);j++)
   {
   ll oper=k;
      ll sum=0;
      priority_queue<ll,vll,greater<ll>> negs;
      for(int x=0;x<i;x++)
      {
         sum+=v[x];
         if(v[x]<0)
         negs.push(v[x]);
         oper--;
      }
      
      for(int x=n-1;x>n-1-j && x>=i;x--)
      {
         sum+=v[x];
         oper--;
         if(v[x]<0)
         negs.push(v[x]);
      }
      while(negs.size() && oper--)
      {
         sum-=negs.top();
         negs.pop();
      }
      mx=max(mx,sum);
   }
}
cout<<mx;






return ;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int test=1;
	//cin>>test;
    for(int i=1;i<=test;i++)
    {
        solveforthiscase(i);
    }
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
int main(){
  int c=0,i;
  char s[3],t[3];
    scanf("%s%s",&s,&t);
  
  for(i=0;i<3;i++){
    if(s[i]==t[i])
      c++;
  }
    printf("%d",c);
}

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

int main() {
	long long N;
	cin >> N;
	long long ans = 0;
	long long mx = sqrt(N);

	for (long long x = 1; x < mx+1; x++)
	{
		if (N % x == 0 && N / x - 1 > x) ans += N / x - 1;
	}

	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr long long MOD = 1000000000 + 7;
constexpr long long INF = 1e17 - 10;
const double PI = acos(-1);
typedef pair<LL, LL> Pll;
LL n, m, ans = 0, f[1000000] = {}, sum = 0;
int flag = 0;
string str;
int main(){
	cin >> f[0];
	f[3] = f[0] % 10;
	f[2] = (f[0] / 10) % 10;
	f[1] = (f[0] / 100) % 10;
	f[0] = (f[0] / 1000) % 10;
	for (int i = 0; i < (1 << 3); i++) {
		bool bb[3] = {};
		int sss = f[0];
		for (int j = 0; j < 3; j++) {
			bb[j] = (i % (1 << (j + 1))) / (1 << (j));
			if (bb[j] == 0)
				sss += f[j + 1];
			else
				sss -= f[j + 1];
		}
		if (sss == 7) {
			flag = i;
			break;
		}

	}
	for (int j = 0; j < 3; j++) {
		cout << f[j];
		int aaa = (flag % (1 << (j + 1))) / (1 << (j));
		if (aaa == 0)
			cout << "+";
		else
			cout << "-";
	}
	cout << f[3] << "=7" << endl;
	return 0;
}

Measured memory_bytes: 256
import queue
import math
import copy
"""
N = int(input())
#S = input()
# (N,M) = (int(i) for i in input().split(" "))
# A = [int(i) for i in input().split()]
A = []
for i in range(N):
	A.append(int(input()))

print(A)

"""

(N,M) = (int(i) for i in input().split(" "))
print("Yes" if N==M else "No")

Measured memory_bytes: 4336
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define pi 3.141592653589793238
#define int long long
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

// mt19937 gen_rand_int(chrono::steady_clock::now().time_since_epoch().count());
// mt19937_64 gen_rand_ll(chrono::steady_clock::now().time_since_epoch().count());
// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

long long power(long long a, long long b) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a ;
        a = a * a ;
        b >>= 1;
    }
    return res;
}

int pp[60];
int bit[60];
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);  
cout.tie(0);   

#ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
    freopen ("INPUT.txt" , "r" , stdin);
    freopen ("OUTPUT.txt" , "w" , stdout);
    }
#endif  

    pp[0]=1;
    for(int i=1;i<=60;i++)
        pp[i]=pp[i-1]*2;
    int n;
    cin>>n;
    int a[n+1];
    int x=0;
    int sum=0;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        if(i>2)
            x^=a[i];
    }
    for(int j=50;j>=0;j--)
    {
        bit[j]=bit[j+1];
        bit[j]+=(pp[j]&a[1]);
        bit[j]+=(pp[j]&a[2]);
    }
    int ini1=a[1];
    int ini2=a[2];
    sum=a[2]+a[1];
    int lol=0;
    a[2]=0;    
    int temp=x;
    int tot=0;
    for(int i=50;i>=0;i--)
    {
        x=temp;
        if(x&pp[i])
        {
            tot+=pp[i];
            a[2]+=(pp[i]);
        }
    }

    for(int i=50;i>=0;i--)
    {
        if(tot+2*pp[i]<=bit[0])
        {
            tot+=2*pp[i];
            lol+=pp[i];
            a[2]+=pp[i];
        }        
    }


    x=temp;
    x^=lol;
    x^=a[2];
    
    if(x||tot!=bit[0])
    {
        cout<<-1;
    }
    else
    {
        for(int i=0;i<50;i++)
        {
            if((lol^a[2])&pp[i])
            {
                if(lol-ini1>0)
                {
                    if(lol&pp[i])
                    {
                        lol-=pp[i];
                        a[2]+=pp[i];
                    }
                }
            }            
        }

        for(int i=50;i>=0;i--)
        {
            if((lol^a[2])&pp[i])
            {
                if(a[2]&pp[i])
                {
                    if(lol+pp[i]<=ini1)
                    {
                        lol+=pp[i];
                        a[2]-=pp[i];
                    }
                }                
            }            
        }
        if(ini1-lol<0||lol==0)
        {
            cout<<-1;
            return 0;
        }
    cout<<ini1-lol;
    }

} 
    


Measured memory_bytes: 3708
x,n = map(int,input().split())
p = list(map(int,input().split()))
ans = 1000
applied = 1000
for i in range(-100,102):
    if i in p:
        pass
    else:
        dif = abs(x-i)
        if dif < ans:
            ans = dif
            applied = i
        else:
            pass
print(applied)

Measured memory_bytes: 9184
#include <bits/stdc++.h>
//---------------------------
using namespace std;
//---------------------------
#define REP(i,n) for(int i = 0; i < (n); i++)
#define P(x) cout << (x) << "\n"

#define MOD 1e9+7
#define PI acos(-1.0)
#define ll long long
#define INF 1000000001

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

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

  // ifstream in("input.txt");
  // cin.rdbuf(in.rdbuf());

  int n;cin>>n;
  if(n==1){
    P(1);
    return 0;
  }else if(n==2){
    int x1,x2;cin>>x1>>x2;
    if(x2-x1<3 && x2-x1>-3){
      P(2);return 0;
    }
    P(1);return 0;
  }
  int a[100000];
  int b[100000];
  int mx=0;
  REP(i,n)cin>>a[i];
  sort(a,a+n);
  REP(i,100000){
    // iの個数を求める→b[i]に入れる
    int t1=lower_bound(a,a+n,i)-a;
    int t2=upper_bound(a,a+n,i)-a;
    int t=t2-t1;
    b[i]=t;
  }
  for(int i=0;i<n-2;i++){
    mx=max(mx, b[i]+b[i+1]+b[i+2]);
  }
  P(mx);
  return 0;
}


Measured memory_bytes: 1024
// Problem : C - 4-adjacent
// Contest : AtCoder Regular Contest 080
// URL : https://atcoder.jp/contests/arc080/tasks/arc080_a
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define size(x) (int)x.size()

const int N = 1e6 + 1, mod = 1e9 + 7, inf = 2e9;

int n, odd = 0, even = 0, four = 0, a[N];

int main() { cin.tie(0)->sync_with_stdio(0);
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		if (a[i] % 2 == 1) {
			odd++;
		} else if (a[i] % 4 == 0) {
			four++;
		} else {
			even++;
		}
	}
	if (even % 2 == 1) {
		odd++;
	}
	if (odd - four < 2) {
		cout << "Yes";
	} else {
		cout << "No";
	}
}


Measured memory_bytes: 640
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <cstdint>
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <bitset>

using namespace std;

using ll =  long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;

constexpr ll MOD = 1000000007;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

ll modpow(ll a, ll t) {
    ll ret = 1LL;
    while(t){
        if(t & 1LL){
            ret *= a;
            ret %= MOD;
        }
        a *= a;
        a %= MOD;
        t >>= 1;
    }
    return ret;
}

int main() {
    std::ios::sync_with_stdio(false); cin.tie(nullptr);
    ll modpow2 = modpow(2, MOD-2);
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    vector<ll> b(n);
    vector<Pll> p(n);
    for(int i=0;i<n;++i){
        cin >> a[i];
        p[i].first = a[i];
        p[i].second = i;
    }
    sort(p.begin(), p.end());
    {
        for(int i=0;i<n;++i) {
            if(i && p[i].first == p[i-1].first){
                b[p[i].second] = b[p[i-1].second];
            } else {
                b[p[i].second] = i;
            }
        }
    }

    ll counter = 0;
    for(int i=0;i<n;++i) {
        for(int j=i+1;j<n;++j) {
            if(a[i] > a[j]) ++counter;
        }
    }

    ll ans = (counter * k) % MOD;
    for(int i=0;i<n;++i) {
        ans += (((((b[i] * k) % MOD) * (k-1)) % MOD) * modpow2) % MOD;
        ans %= MOD;
    }

    cout << ans << endl;
    

}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define ll long long int

using namespace std;

const ll mod=1000000007;
const ll inf=1e18;

int main(){

  ll n,k;
  cin >> n >> k;
  ll a[n+1]={};
  for(ll i=0;i<n;i++)cin >> a[i+1];

  ll s[n+1]={};
  for(ll i=0;i<n;i++)s[i+1]=s[i]+a[i+1];

  vector<pair<ll,ll>> v;
  for(ll i=0;i<=n;i++)v.push_back(make_pair(((s[i]-i)%k+k)%k,i));

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

  ll c=0;

  for(ll i=0;i<=n;i++){
    ll p=lower_bound(v.begin(),v.end(),make_pair(v[i].first,v[i].second))-lower_bound(v.begin(),v.end(),make_pair(v[i].first,v[i].second-k+1));
    c+=p;
  }

  cout << c << endl;

  //for(ll i=0;i<n;i++)cout << v[i].first << " " << v[i].second << endl;


}

Measured memory_bytes: 10596
#include<stdio.h>

int main(void){
    int i,n;
    scanf("%d", &n);
    int a[n];
    for ( i = 0 ; i < n ; i++ ){
        scanf("%d", &a[i]);
    }
    for ( i = n - 1 ; i >= 0 ; i-- ){
        printf("%d", a[i]);
        if ( i != 0 ) {
            printf(" ");
        } else {
            printf("\n");
        }
    }
    return 0;
}


Measured memory_bytes: 2068
#include<stdio.h>
int main(){
	int i,j,n,m,a[100][100],b[100],sum=0;
	scanf("%d %d",&n,&m);
	for(i=0;i<n;i++){
		for(j=0;j<m;j++){
			scanf("%d",&a[i][j]);
		}
	}
	for(i=0;i<m;i++){
		scanf("%d",&b[i]);
	}
	for(i=0;i<n;i++){
		for(j=0;j<m;j++){
			sum+=a[i][j]*b[j];
		}
		printf("%d\n",sum);
		sum=0;
	}
}


Measured memory_bytes: 2140
N=int(input())
A=list(map(int,input().split()))

abs_sum=0
nega=0
mini=10**9+7

for i in range(N):
    a=abs(A[i])
    abs_sum+=a
    mini=min(mini,a)
    if A[i]<0:
        nega+=1

if nega%2==1:
    abs_sum-=2*mini
print(abs_sum)

Measured memory_bytes: 64752
#include<bits/stdc++.h>
using namespace std;
int calc(int x){
	int c=0;
	for(int i=2;i<=x;++i)if(x%i==0)for(++c;x%i==0;x/=i);
	return c;
}
const int N=505;
typedef long long ll;
int a[N*2],aa[N*2],xb,i,j,n;ll b[N][N];
inline ll lcm(ll a,ll b){
	return a/std::__gcd(a,b)*b;
}
inline void spj(){
	unordered_set<ll>s;
	for(i=1;i<=n;++i)for(j=1;j<=n;++j)s.insert(b[i][j]),
		assert(b[i][j]<=1e15);
	assert(s.size()==n*n);
	for(i=1;i<=n;++i)for(j=1;j<n;++j)assert(max(b[i][j],b[i][j+1])%min(b[i][j],b[i][j+1])==1); 
	for(i=1;i<n;++i)for(j=1;j<=n;++j)assert(max(b[i+1][j],b[i][j])%min(b[i+1][j],b[i][j])==1); 
}
int main(){
	scanf("%d",&n);
	if(n==2){
		puts("4 7\n23 10");
		return 0;
	}
	int l=0,r=n*2+1;
	for(i=2;xb<n*2;++i)if(calc(i)<2)a[++xb]=i;
	
	for(i=1;i<=n;++i)for(j=1;j<=n;++j){
		int x=i+j,y=i-j+n;
		if(x&1)b[i][j]=a[x/2]*a[n+(y+1)/2];
		if(x%2==1 && abs(i-2)+abs(j-222)==1){
			++i,--i;
		}
	}
	for(i=1;i<=n;++i)for(j=1;j<=n;++j)if((i+j)%2==0){
		ll ans=1;
		if(i>1)ans=lcm(ans,b[i-1][j]);
		if(i<n)ans=lcm(ans,b[i+1][j]);
		if(j>1)ans=lcm(ans,b[i][j-1]);
		if(j<n)ans=lcm(ans,b[i][j+1]);
		if(ans>1ll*a[n*2]*a[n*2-1]*a[n]*a[n-1]) {
			++i,--i;
		}
		b[i][j]=ans+1;
	}
	spj();
	for(i=1;i<=n;++i,puts(""))for(j=1;j<=n;++j)printf("%lld ",b[i][j]);
	return 0;
}

Measured memory_bytes: 12916
#include<iostream>
#include<cstdio>
#include<map>
#include<sstream>
#include<cstring>
#include<algorithm>
#include<string>
using namespace std;
const int maxn = 2e5+7;
int a[maxn];
char s[1000][1000];
int main()
{
    int n,m;
    int c,b;
    long long ans=0;
    cin >> n;
    for(int i = 0; i < n; i ++)
    {
        cin >> a[i];
        ans += a[i];
    }
    cin >> m;
    for(int i = 0; i < m; i ++)
    {
        cin >> c >> b;
        cout << ans - a[c-1] + b <<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
typedef long long ll;
typedef long double ld;
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF (1LL<<60)
#define MOD1 1000000007

void swap(ll *a, ll *b){ll c;c=*b;*b=*a;*a=c;}/*swap 交換*/
ll max2(ll a,ll b){return a>=b?a:b;}/*2つのうち大きい数を返す*/ 
ll min2(ll a,ll b){return a>=b?b:a;}/*2つのうち小さい数を返す*/ 
ll ABS(ll a){return a>=0?a:(-a);}/*絶対値*/ 
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}

typedef struct{
    ll aa;
    ll bb;
}frequent;

int main(void){
    ll a,b,ans=0;
    scanf("%lld%lld",&a,&b);
    // rep(i,0,n){
    //     scanf("%lld",&[i]);
    // }
    ans=12*a;
    while(1){
        if(ans*8/100==a && ans/10==b) break;
        if(ans/100>b){
            printf("-1\n");
            return 0;
        }
        ans++;
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=22e5+10;
int N,M;
int dist[maxn],vis[maxn];
struct Rail{int y,val;};
struct node
{
    int y,c;
    friend bool operator<(node A,node B){return (A.y==B.y)?(A.c<B.c):(A.y<B.y);}
};
struct Node{int y,Next,c;};
vector<node> real_emp;
vector<Node> emp_emp;
vector<Rail> v[maxn];
inline long long read()
{
    long long s=0,f=1; char ch; for(;ch<'0'||ch>'9';ch=getchar()) if(ch=='-') f=-1;
    for(;ch>='0'&&ch<='9';ch=getchar()) s=(s<<3)+(s<<1)+ch-'0'; return s*f;
}
void Dj(int st)
{
    priority_queue< pair<int,int> > q;
    memset(dist,0x3f,sizeof(dist));
    memset(vis,0,sizeof(vis));
    dist[st]=0; q.push(make_pair(0,st));
    while(!q.empty())
    {
        int x=q.top().second; q.pop();
        if(vis[x]) continue; vis[x]=1;
        for(register int i=0;i<v[x].size();++i)
        {
            int y=v[x][i].y,val=v[x][i].val;
            if(dist[y]>dist[x]+val)
            {
                dist[y]=dist[x]+val;
                q.push(make_pair(-dist[y],y));
            }
        }
    }
}
void Input()
{
    N=read(),M=read();
    int xx,yy,zz;
    for(register int i=1;i<=M;++i)
    {
        xx=read()-1,yy=read()-1,zz=read()-1;
        real_emp.push_back((node){xx,zz});
        real_emp.push_back((node){yy,zz});
        emp_emp.push_back((Node){xx,yy,zz});
        emp_emp.push_back((Node){yy,xx,zz});
    }
}
void Solution()
{
    Input();
    sort(real_emp.begin(),real_emp.end());
    for(register int i=0;i<real_emp.size();++i)
    {
        v[N+i].push_back((Rail){real_emp[i].y,1});
        v[real_emp[i].y].push_back((Rail){N+i,1});
    }
    for(register int i=0;i<emp_emp.size();++i)
    {
        int pos1=lower_bound(real_emp.begin(),real_emp.end(),(node){emp_emp[i].y,emp_emp[i].c})-real_emp.begin();
        int pos2=lower_bound(real_emp.begin(),real_emp.end(),(node){emp_emp[i].Next,emp_emp[i].c})-real_emp.begin();
        v[N+pos1].push_back((Rail){N+pos2,0});
    }
    Dj(0);
    printf("%d\n",(dist[N-1]==1061109567)?-1:(dist[N-1]>>1)); exit(0);
}
int main()
{
    Solution();
}


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

int main()
{
    int A, B, C, D;
    cin >> A >> B >> C >> D;

    while (true) {
        C -= B;
        if (C <= 0) {
            cout << "Yes" << endl;
            break;
        }
        A -= D;
        if (A <= 0) {
            cout << "No" << endl;
            break;
        }
    }
    return 0;
}

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

int main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    vector<vector<vector<int>>> data(4, vector<vector<int>>(3, vector<int>(10)));

    int n;
    cin >> n;
    rep(i, n){
        int b, f, r, v;
        cin >> b >> f >> r >> v;

        data[b-1][f-1][r-1] += v;
    }

    for(int bi = 0; bi < data.size(); bi++){
        for(int fi = 0; fi < data[bi].size(); fi++){
            for(int ri = 0; ri < data[bi][fi].size(); ri++){
                cout << " " << data[bi][fi][ri];
            }
            cout << endl;
        }
        if(bi != data.size()-1){
            cout << "####################" << endl;
        }
    }
}



Measured memory_bytes: 3176
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7;
struct aa{
	int first,second;
}P; 
aa arr[N];//记录区间 
int minnore[N]; 
aa S[N];

bool cmp1(aa a, aa b){
	return a.first > b.first;
}

int main(){
	int q, L, R, mxL = 0, mnR = 1e9 + 7, RR, LL;
	int flag1 = 0, flag2 = 0, maxlen = 0;
	scanf("%d", &q);
	for(int i = 0; i < q; i ++ ){
		scanf("%d%d", &L, &R);
		arr[i].first = L;
		arr[i].second = R;
		if(L > mxL){
			mxL = L;
			RR = R;
			flag1 = i;
		}
		if(R < mnR){
			mnR = R;
			LL = L;
			flag2 = i;
		} 
		maxlen = max(maxlen, R - L + 1);
	}
	int ans1 = maxlen;
	if(mnR >= mxL)	ans1 += mnR - mxL + 1;
	if(flag1 == flag2){
		cout << ans1 << endl;
		return 0;
	}
	for(int i = 0; i < q; i ++ ){
		S[i].first = max(arr[i].second - mxL + 1, 0);
		S[i].second = max(mnR - arr[i].first + 1, 0);
	}
	sort(S, S + q, cmp1);
	minnore[q-1] = S[q - 1].second;
	for(int i = q - 2; i >= 0; i --){
		minnore[i] = min(minnore[i + 1], S[i].second);
	}
	int ans2 = 0;
	for(int i = 0; i < q; i ++ ){
		ans2 = max(ans2, S[i].first + minnore[i+1]);
	}
	cout << max(ans2,ans1) <<endl;
	
	
	
	return 0;
} 

Measured memory_bytes: 2176
#include <bits/stdc++.h>//Carefully Crafted by hetp111
using namespace std;
#define int long long
#define double long double
#define all(v) (v).begin(),(v).end()
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vii vector<pii>
#define MOD 1000000007
#define MOD2 998244353
#define MOD3 1000000009
#define PI acos(-1)
#define eps (1e-8)
#define INF (1e18)
#define FASTER ios_base::sync_with_stdio(0);cin.tie(0)
template<class A,class B>ostream&operator<<(ostream&out,const pair<A,B>&a){return out<<"("<<a.first<<","<<a.second<<")";}
template<class A>ostream&operator<<(ostream&out,const vector<A>&a){for(const A &it:a)out<<it<<" ";return out;}
template<class A,class B>istream&operator>>(istream&in,pair<A,B>&a){return in>>a.first>>a.second;}
template<class A>istream&operator>>(istream&in,vector<A>&a){for(A &i:a)in>>i;return in;}
//ifstream cinn("in.in");ofstream coutt("out.out");
int poww(const int &a,int b,const int &m=MOD){if(b==0)return 1;int x=poww(a,b/2,m);x=x*x%m;if(b&1)x=x*a%m;return x;}
int ceil(const int &a,const int &b){return (a+b-1)/b;}
////Read:
//Check corner cases, n==1;
//
////Some function:
//__builtin_popcountll(), 

struct matrix{
    vvi cell;
    int n;
    
    matrix(int n){
        this->n=n;
        cell.resize(n,vi(n));
    }
    
    matrix operator*(const matrix &b){
        matrix c(n);
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                for(int k=0;k<n;k++){
                    c.cell[i][k]+=cell[i][j]*b.cell[j][k]%MOD;
                    c.cell[i][k]%=MOD;
                }
            }
        }
        return c;
    }
    
    matrix I(int n){
        matrix I(n);
        for(int i=0;i<n;i++)I.cell[i][i]=1;
        return I;
    }
    
    matrix pow(int k){
        if(k==0)return this->I(n);
        matrix ans=this->pow(k/2);
        ans=ans*ans;
        if(k&1)ans=ans*(*this);
        return ans;
    }
};

signed main(){
    FASTER;
    int n,k;cin>>n>>k;
    matrix adj(n);
    for(int i=0;i<n;i++)for(int j=0;j<n;j++)cin>>adj.cell[i][j];
    
    adj=adj.pow(k);
    
    int ans=0;
    for(int i=0;i<n;i++)for(int j=0;j<n;j++)ans=(ans+adj.cell[i][j])%MOD;
    cout<<ans;
}


Measured memory_bytes: 3712