akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define int long long
#define F first
#define S second
using namespace std;
int mod=1e9+7;


int32_t main() {
    int T;
    T=1;
    //cin>>T;
    while(T--){
        int n,W;
        cin>>n>>W;
        int w[n], v[n];
        for(int i=0;i<n;i++){
            cin>>w[i]>>v[i];
        }
        int dp[n][W+1], ans=0;
        memset(dp,0,sizeof(dp));
        for(int i=0;i<n;i++){
            for(int j=1;j<=W;j++){
                if(j-w[i]>=0){
                    dp[i][j]=v[i]+((i>0)?dp[i-1][j-w[i]]:0);
                }
                if(i>0)
                    dp[i][j]=max(dp[i][j], dp[i-1][j]);
            }
            
        }
        // for(int i=0;i<n;i++){
        //     for(int j=0;j<=W;j++){
        //         cout<<dp[i][j]<<" ";
        //     }cout<<endl;
        // }
        cout<<dp[n-1][W];
        cout<<'\n';
    }
	return 0;
}

Measured memory_bytes: 78336
n=int(input())
h=list(map(int,input().split()))
h.append(99999999999999999999)
temp=[0]*(n+1)
temp[0]=0
for i in range(n):
  if h[i]>=h[i+1]:
    temp[i+1]=temp[i]+1
  else:
    temp[i+1]=0
del temp[n]
print(max(temp))


Measured memory_bytes: 14252
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
//#########################################
const int INF = 1e18;
signed main(){
	int n,m;cin >> n >> m;
	vector<P> students(n);
	rep(i,n){
		cin >> students[i].first >> students[i].second;
	}
	vector<P> p(m);
	rep(i,m){
		cin >> p[i].first >> p[i].second;
	}
	vector<int> ans(n);
	rep(i,n){
		int x = students[i].first,y = students[i].second;
		int tmp = INF;
		rep(j,m){
			int nx = p[j].first,ny = p[j].second;
			tmp = min(tmp,abs(nx - x) + abs(ny - y));
		}
		rep(j,m){
			int nx = p[j].first,ny = p[j].second;
			if(abs(nx - x) + abs(ny - y) == tmp){
				ans[i] = j+1;
				break;
			}
		}
	}
	rep(i,n)cout << ans[i] << " ";
	cout << endl;
	// trace(ans);

	return 0;
}

Measured memory_bytes: 3580
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>

#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,x,n) for(int i=x; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define all(X) (X).begin(),(X).end()
#define X first
#define Y second
#define pb push_back
#define eb emplace_back

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

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

template<class A, size_t N, class T> void Fill(A (&a)[N], const T &v){ fill( (T*)a, (T*)(a+N), v ); }

const ll INF = 0x3fffffff;


int main(){
	//ios_base::sync_with_stdio(0);
	int q, ans=0;
	string S, T;
	int sum[2][2][100005]; // SorT, AorB, i

	cin >> S >> T;
	rep(i,S.length()){
		sum[0][0][i+1] = sum[0][0][i] + (S[i] == 'A');
		sum[0][1][i+1] = sum[0][1][i] + (S[i] == 'B');
	}
	rep(i,T.length()){
		sum[1][0][i+1] = sum[1][0][i] + (T[i] == 'A');
		sum[1][1][i+1] = sum[1][1][i] + (T[i] == 'B');
	}

	cin >> q;
	rep(i,q){
		int a, b, c, d;
		cin >> a >> b >> c >> d;
		a--; b--; c--; d--;

		int num_SA = sum[0][0][b+1] - sum[0][0][a];
		int num_SB = sum[0][1][b+1] - sum[0][1][a];
		int num_TA = sum[1][0][d+1] - sum[1][0][c];
		int num_TB = sum[1][1][d+1] - sum[1][1][c];

		int h_s = (num_SA%3 - num_SB%3 + 3) % 3;
		int h_t = (num_TA%3 - num_TB%3 + 3) % 3;
		if( h_s == h_t ){
			cout << "YES" << endl;
		}else{
			cout << "NO" << endl;
		}
	}

	return 0;
}


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

#define Q int t; scanf("%d", &t); for(int q=1; q<=t; q++)
typedef long long int lli;
typedef pair<int, int> pi;
typedef pair<lli, int> pii;

vector<int> adj[100010];
int ans;
bool vis[100010];
int hight[100010];

void check(int x)
{
    vis[x] = true;
    for(auto y: adj[x]){
        if(hight[y] < hight[x]){
            vis[y] = true;
        }
        else return;
    }
    ans++;
    return;
}

int main()
{
    int n, m;
    cin >> n >> m;
    for(int i=1; i<=n; i++) cin >> hight[i];

    while(m--){
        int u, v;
        cin >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    for(int i=1; i<=n; i++){
        if(vis[i] == false){
            check(i);
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 9128
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();

int main() {
    int n;
    double a, b;
    cin >> n;
    vector<vector<double>> pts;
    for(int i = 0; i < n; i++) {
        cin >> a >> b;
        pts.push_back({a, b});
    }
    vector<vector<double>> mat(n, vector<double>(n, 0.0));
    double acc = 0.0;
    for(int i = 0; i < n; i++) {
        for(int j = i+1; j < n; j++) {
            if (i == j) continue;
            double dis = (pts[i][0] - pts[j][0]) * (pts[i][0] - pts[j][0]);
            dis += (pts[i][1] - pts[j][1]) * (pts[i][1] - pts[j][1]);
            mat[i][j] = mat[j][i] = sqrt(dis);
            acc += mat[i][j] * 2.0;
        }
    }

    // (n! * (n-1)) / (n*n-n)
    // (n! * (n-1) / (n*(n-1)) => (n-1)!
    double fac = 1.0;
    for(int i = 1; i <= n-1; i++)
        fac *= i;
    // cout << acc << endl;
    // cout << fac << endl;
    cout << fixed << setprecision(12) << acc/n << endl;

    return 0;
}




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

using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for (ll i = (ll)(n) - 1; i >= 0; i--)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1LL << 62)

#define PI (acos(-1))
#define print(x) cout << x << endl
 
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll countDigit(ll n) { return floor(log10(n) + 1); } 
typedef pair <ll,ll> P;
static const ll dy[4] = {0,1,0,-1}, dx[4] = {1,0,-1,0};

template <typename T> 
ostream& operator<<(ostream& os, const vector<T>& v) 
{ 
    for (int i = 0; i < (int)v.size(); ++i) os << v[i] << " ";  
    return os; 
}

template <typename T1, typename T2> 
ostream& operator<<(ostream& os, const map<T1, T2>& m) 
{ 
    for (auto p : m) os << "<" << p.first << ", " << p.second << "> "; 
    return os; 
}

int main()
{
    vector<vector<ll>> mat(3, vector<ll>(3, 0));
    rep(i, 3) {
        rep(j, 3) {
            cin >> mat[i][j];
        }
    }
    ll N;
    cin >> N;
    vector<vector<ll>> check(3, vector<ll>(3, 0));
    rep(i, N) {
        ll b;
        cin >> b;
        rep(j, 3) {
            rep(k, 3) {
                if (mat[j][k] == b) mat[j][k] = 1;
            }
        }
    }
    rep(i, 3) {
        if (mat[i][0] * mat[i][1] * mat[i][2] == 1) {
            cout << "Yes" << endl;
            return 0;
        }
        if (mat[0][i] * mat[1][i] * mat[2][i] == 1) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    if (mat[0][0] * mat[1][1] * mat[2][2] == 1) {
        cout << "Yes" << endl;
        return 0;
    }
    if (mat[0][2] * mat[1][1] * mat[2][0] == 1) {
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;
    return 0;
} 

Measured memory_bytes: 256
h,w,k = map(int,input().split())
bl_check = []
num = 1
ls_a = [list(input()) for i in range(h)]
for i in ls_a:
    bl_check.append(1) if "#" in i else bl_check.append(0) 

for i in range(h):
    for j in range(w):
        if ls_a[i][j] == "#":
            ls_a[i][j] = num
            num += 1


for i in range(h):
    for j in range(w-1):
        if ls_a[i][j] != "." and ls_a[i][j+1] == ".":
            ls_a[i][j+1] = ls_a[i][j]
# 右に伸ばしていく

    for j in range(w-1,0,-1):
        if ls_a[i][j] != "." and ls_a[i][j-1] == ".":
            ls_a[i][j-1] = ls_a[i][j]
# 左に伸ばしていく

for i in range(h-1):
    if bl_check[i] == 1 and bl_check[i+1] == 0:
        for j in range(w):
            ls_a[i+1][j] = ls_a[i][j]
        bl_check[i+1] = 1
# 下に伸ばしていく

for i in range(h-1,0,-1):
    if bl_check[i] == 1 and bl_check[i-1] == 0:
        for j in range(w):
            ls_a[i-1][j] = ls_a[i][j]
        bl_check[i-1] = 1
# 上に伸ばしていく

# print(ls_a)
# print(bl_check)
print("\n".join([" ".join(map(str, l)) for l in ls_a]))

Measured memory_bytes: 8416
s=input()
n=len(s)
e=n
while e>8:
    if(s[e-5:e]=="dream" or s[e-5:e]=="erase"):
        e-=5
    elif(s[e-6:e]=="eraser"):
        e-=6
    elif(s[e-7:e]=="dreamer"):
        e-=7
    else:
        print("NO")
        break
else:
    if(s[:e]=="dream" or s[:e]=="erase" or s[:e]=="eraser" or s[:e]=="dreamer"):
        print("YES")
    else:
        print("NO")

Measured memory_bytes: 3188
N = int(input())
MOD = 10 ** 9 + 7
memo = {}
prev_num = 1
prev = None
for _ in range(N):
  c = int(input())
  if prev == c:
    continue
  tmp = prev_num
  if c in memo:
    tmp += memo[c]
  tmp %= MOD
  memo[c] = tmp
  prev_num = tmp
  prev = c
print(prev_num % MOD)

Measured memory_bytes: 27100
#include<bits/stdc++.h>
using namespace std;
const int N=1005;
int n,m,x[N],y[N],ans[N];
bool num[N];
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d%d",&x[i],&y[i]);
		num[(x[i]+y[i])&1]=1;
	}
	if(num[0]&&num[1]){
		puts("-1");
		return 0;
	}
	if(num[0])ans[++m]=1;
	for(int i=30;i>=0;i--)ans[++m]=(1<<i);
	printf("%d\n",m);
	for(int i=1;i<m;i++)
		printf("%d ",ans[i]);
	printf("%d\n",ans[m]);
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(abs(x[i])>abs(y[i])){
				if(x[i]>0)x[i]-=ans[j],putchar('R');
				else x[i]+=ans[j],putchar('L');
			}
			else{
				if(y[i]>0)y[i]-=ans[j],putchar('U');
				else y[i]+=ans[j],putchar('D');
			}
		}
		putchar('\n');
	}
	return 0;
}

Measured memory_bytes: 3808
/* ex3_2
    riverstone*/

#include<stdio.h>
 
int main(void){
    //Nをint型で定義して入力する。
    int N;
    scanf("%d", &N);
 
    // Nを10で割った値をswitchで場合分け
    switch (N % 10){
    case 2: case 4: case 5: case 7: case 9:
        printf("hon\n");
        break;
    
    case 0: case 1: case 6: case 8:
        printf("pon\n");
        break;
 
    case 3:
        printf("bon\n");
        break;
    }
    return 0;
}

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

using namespace std;

struct posi {
	int x;
	int y;
};

int main() {

	while (1) {
		int w, h;
		cin >> w >> h;

		if (w == 0 && h == 0) { return 0; }
		vector<vector<int>> mapp(h + 2, vector<int>(w + 2));
		for (int i = 1; i <= h; i++) {
			for (int j = 1; j <= w; j++) {
				cin >> mapp[i][j];
			}
		}


		vector<int> dx{ 1,1,0,-1,-1,-1,0,1 };
		vector<int> dy{ 0,1,1,1,0,-1,-1,-1 };

		vector<vector<bool>> seen(h + 2, vector<bool>(w + 2, false));
		deque<posi> todo; //考え方はスタックだけどdequeの方が使い勝手がいい


		posi s; //今いる場所
		int counter = 0;
		for (int i = 1; i <= h; i++) {
			for (int j = 1; j <= w; j++) {
				if (mapp[i][j] == 0) { continue; }
				//seen.resize(h + 2, vector<bool>(w + 2, false));

				if (seen[i][j] == false) {
					counter++;
					seen[i][j] = true;
					todo.push_back({ i,j });

					while (todo.empty() != true) {
						s = todo.back();
						bool tugiflg = false; //次があったらtrue
						for (int k = 0; k < 8; k++) {
							if (seen[s.x + dx[k]][s.y + dy[k]] != true) {
								seen[s.x + dx[k]][s.y + dy[k]] = true;
								if (mapp[s.x + dx[k]][s.y + dy[k]] == 1) {
									todo.push_back({ s.x + dx[k],s.y + dy[k] });;
									tugiflg = true;
									break;
								}
							}
						}
						if (tugiflg == false) {
							todo.pop_back();
						}
					}
				}
			}
		}

		cout << counter << endl;
	}
	return 0;

}


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

using namespace std;

int a[4100000];
int main(){
	int n;
	long long ans = 0;
	cin >> n;
	for(int i = 1;i <= n;i++)
	{   int x;
		scanf("%d",&x);
		if(i>=x)
		ans+=a[i-x];
		if(i+x<2*n)
		a[i+x]++;
	}
	cout<<ans<<endl;
	return 0; 
}

Measured memory_bytes: 5312
#include <stdio.h>

int main(void) {
  int i, j, k, l;
  int n;
  int count;

  while (scanf("%d", &n) != EOF) {
    count = 0;

    for (i = 0; i < 10; i++)
      for (j = 0; j < 10; j++)
        for (k = 0; k < 10; k++)
          for (l = 0; l < 10; l++)
            if (i + j + k + l == n)
              count++;
    
    printf("%d\n", count);
  }

  return 0;
}

Measured memory_bytes: 596
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 0
//#ifdef LOCAL
//#define DEBUG(s) cout << (s) << endl
//#define dump(x)  cerr << #x << " = " << (x) << endl
//#define BR cout << endl;
//#else
//#define DEBUG(s) do{}while(0)
//#define dump(x) do{}while(0)
//#define BR
//#endif


//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 20)
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね

//ここから編集する


int main() {
    int N;
    cin >> N;
    vector<vector<int> > v(N, vector<int>(10)), P(N, vector<int>(11));
    rep(i, 0, N) {
        rep(j, 0, 10) {
            cin >> v[i][j];
        }
    }

    rep(i, 0, N) {
        rep(j, 0, 11) {
            cin >> P[i][j];
        }
    }

    ll ans = -(ll)(1e9);
    for(int i = 1; i < (1 << 10); i++){
        //jの店と何個被ってるか
        vector<int> kabu(N);
        for(int j = 0; j < N; j++){
            int cnt = 0;
            for(int k = 0; k < 10; k++){
                if(v[j][k] == 1 && ((i >> k) & 1) == 1){
                    cnt++;
                }
            }
            kabu[j] = cnt;
        }

        ll ans_tmp = 0;
        for(int j = 0; j < N; j++){
            ans_tmp += 1LL *  P[j][kabu[j]];
        }
        ans = max(ans,ans_tmp);
        //        if(ans == 0){
        //            cout << "0" << endl;
        //        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
import sys
import math
from collections import defaultdict, deque
from copy import deepcopy
    
input = sys.stdin.readline
def RD(): return input().rstrip()
def F(): return float(input().rstrip())
def I(): return int(input().rstrip())
def MI(): return map(int, input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float,input().split()))
def Init(H, W, num): return [[num for i in range(W)] for j in range(H)]
    
    
def main():
    H, W, M = MI()
    Hlist = [[0, i] for i in range(H)]
    Wlist = [[0, i] for i in range(W)]
    Dlist = [set() for i in range(H)]
    H_max = -float('inf')
    W_max = -float('inf')
    
    for i in range(M):
        h, w = MI()
        Hlist[h-1][0]+=1
        Wlist[w-1][0]+=1
        Dlist[h-1] |= {w-1}
        H_max = max(H_max, Hlist[h-1][0])
        W_max = max(W_max, Wlist[w-1][0])
    Hlist = set([temp[1] for temp in Hlist if temp[0] == H_max])
    Wlist = set([temp[1] for temp in Wlist if temp[0] == W_max])
    ans = H_max+W_max-1

    for index1 in Hlist:
        for index2 in Wlist:
            if not index2 in Dlist[index1]:
                ans += 1
                break
        else:
            continue
        break
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 345668
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string s;
  cin>>s;
  set<char>st;
  for(int i=0;i<s.size();i++)
  {
    st.insert(s[i]);
  }
  bool f=true;
  for(char ch='a';ch<='z';ch++)
  {
    if(st.find(ch)==st.end())
    {
      cout<<ch<<endl;
      f=false;
      break;
    }
  }
  if(f)cout<<"None"<<endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int,int>;
#define rep(i,n) for(int i=0; i<n; i++)
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてから使う
#define INF 2147483647
#define LLINF 9223372036854775807LL

int main(){
  int n; cin >> n;
  vector<int>A_2(n);
  rep(i,n) cin >> A_2[i];
  vector<int>A_1(n);
  vector<int>A_3(n);
  rep(i,n){
    A_1[i] = A_2[i]-1;
    A_3[i] = A_2[i]+1;
  }
  map<int, int>mp;
  rep(i,n){
    mp[A_1[i]]++;
    mp[A_2[i]]++;
    mp[A_3[i]]++;
  }
  int mx = 0;
  int itr = -1;
  for (auto p:mp){
    if (mx < p.second){
      mx = p.second;
      itr = p.first;
    }
  }
  //cout << "かず：" << itr << endl;
  cout << mx << endl;
}

Measured memory_bytes: 8696
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<n;i++)
#define INF 10000000000000000
int main(void){
    int a,b;cin>>a>>b;
    if(a>=13)cout<<b;
    else if(6<=a&&a<=12)cout<<b/2;
    else cout<<0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
const int64_t MOD = 2019;

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

    int64_t l, r;
    cin >> l >> r;
    if (r-l >= 2019) cout << 0 << endl;
    else {
        int64_t res = 1e9+7;
        for (int64_t i = l; i < r; i++) {
            for (int64_t j = i+1; j < r+1; j++) {
                res = min(res, (int64_t)(i*j)%MOD);
            }
        }
        cout << res << endl;
    }
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;
 
import static java.lang.System.in;
 
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long P = sc.nextLong();
        if(n==1){
            System.out.println(P);
            System.exit(0);
        }
        long upper = (long) Math.sqrt(P)+1;
        long ans=1;
        for(long i=2;i<=upper&&i<=P;i++){
            if(P%i!=0) continue;
            long cnt=0;
            while(P%i==0){
                cnt++;
                P = P/i;
            }
            long now = cnt/n;
            ans*=(long) Math.pow(i,now);
        }
        PrintWriter out = new PrintWriter(System.out);
        out.println(ans);
        out.flush();
    }
}

Measured memory_bytes: 23124
N,M = map(int,input().split())
coins = list(map(int,input().split()))
coins.sort()
dp = [[0] * M for _ in range(N+1)]
for i in range(N+1):
    dp[i][0] = i
for j in range(M):
    dp[0][j] = 0
for j in range(1,M):
    for i in range(1,N+1):
        if coins[j] <= i:
            dp[i][j] = min(dp[i-coins[j]][j]+1,dp[i][j-1])     
        else:
            dp[i][j] = dp[i][j-1]
        
print(dp[N][M-1])


Measured memory_bytes: 47284
#include <iostream>
#include <unordered_map>
#include <iterator>
#include <algorithm>
#include <string>
using namespace std;
#define ALL(a) (a).begin(), (a).end()
const int64_t BIG_PRIME = 1000000007;

unsigned gcd(unsigned a, unsigned b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

int ntimes(int a, int b, int c){
    if(a==b && b==c){
        return 1;
    }
    if(a!=b && b!=c && c!=a){
        return 6;
    }
    return 3;
}


int main()
{
    int n;
    cin >> n;
    int64_t sum = 0;

    for(int i=1; i<=n; i++){
        for(int j=i; j<=n; j++){
            for(int k=j; k<=n; k++){
                int g = gcd(i, j);
                g = gcd(g, k);
                g *= ntimes(i,j,k);
                sum += g;
            }
        }
    }

    cout << sum << endl;
}

Measured memory_bytes: 3620
import java.io.*;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  
    String[] line1 = br.readLine().split(" ");
  
    int n = Integer.parseInt(line1[0]);
    int m = Integer.parseInt(line1[1]);
    int[][] data = new int[2][m];
    String[] dataStr;
  
    for (int i = 0; i < m; i++) {
      dataStr = br.readLine().split(" ");
      data[0][i] = n + 1 - Integer.parseInt(dataStr[0]);
      data[1][i] = Integer.parseInt(dataStr[1]);
    }
    if(m==0){
      if (n==1){
        System.out.println(0);
      } else {
        System.out.println((int)Math.pow(10, n-1));
      }
      return;
    }
    if (n == 1) {
      for (int i = 0; i < 10; i++) {
        for (int j = 0; j < m; j++) {
          if (i != data[1][j]) {
            break;
          }
          if (j == m - 1) {
            System.out.println(i);
            return;
          }
        }
      }
    } else {
      for (int i = (int) Math.pow(10, n - 1); i < Math.pow(10, n); i++) {
        for (int j = 0; j < m; j++) {
          if ((i % (int) (Math.pow(10, data[0][j]))) / (int) Math.pow(10, data[0][j] - 1) != data[1][j]) {
            break;
          }
          if (j == m - 1) {
            System.out.println(i);
            return;
          }
        }
      }
    }
    System.out.println(-1);
  }
}


Measured memory_bytes: 21076
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<iomanip>
#include<string>
#include<cmath>
#include<vector>
#include<set>
#include<queue>
#include<stack>
#include<fstream>
#include<map>
#include<bitset>
#include<unordered_map>
#include<cstring>
#include<cctype>
using namespace std;
#define  ll long long
#define  ull unsigned long long
#define  ul unsigned long
#define all(v) v.begin(),v.end()
#define sz(n) (int)n.size()
#define pb(s) push_back(s);
#define format(n) fixed<<setprecision(n)
#define finl "\n"
#define Mohammed_Atef_Hassan fast();
#define mod 1000000007
#define INF LLONG_MAX
#define PI acos(-1)
#define clr(dp,n) memset(dp,n,sizeof dp)
#define ex(n) return cout<<n<<finl,0;
int dx[] = { 0, 1, 0, -1, 1, 1, -1, -1 };
int dy[] = { 1, 0, -1, 0, 1, -1, 1, -1 };
ll fix_mod(ll x, ll y)
{
	return (y + x % y) % y;
}
void fast() {
	std::ios_base::sync_with_stdio(false);
	cin.tie(nullptr); cout.tie(nullptr);


}
map<string, ll>cnt;
int main()
{
	Mohammed_Atef_Hassan
		int t; string s;
	cin >> t;
	while (t--)
	{
		cin >> s;
		sort(all(s));
		cnt[s]++;
	}
	ll res = 0;
	for (auto v : cnt)
	{
		res += v.second*(v.second - 1) / 2;
	}
	ex(res);
}

Measured memory_bytes: 11264
from bisect import bisect_left

A, B, Q = map(int, input().split())
S = [int(input()) for _ in range(A)]
T = [int(input()) for _ in range(B)]
Q = [int(input()) for _ in range(Q)]


for q in Q:
    ps = bisect_left(S, q)
    if ps == len(S):
        s1, s2 = S[ps - 1], S[ps - 1]
    elif ps == 0:
        s1, s2 = S[ps], S[ps]
    else:
        s1, s2 = S[ps - 1], S[ps]

    pt = bisect_left(T, q)
    if pt == len(T):
        t1, t2 = T[pt - 1], T[pt - 1]
    elif pt == 0:
        t1, t2 = T[pt], T[pt]
    else:
        t1, t2 = T[pt - 1], T[pt]

    ans = 10 ** 11
    for s in (s1, s2):
        for t in (t1, t2):
            path1 = abs(q - s) + abs(s - t)
            path2 = abs(q - t) + abs(s - t)
            ans = min(ans, path1, path2)
    print(ans)


Measured memory_bytes: 87256
H, W, M = map(int, input().split())
bombs = {}
rows = []
cols = []
for i in range(H):
    rows.append([i, 0])
for i in range(W):
    cols.append([i, 0])
for i in range(M):
    y, x = map(lambda x: x - 1, map(int, input().split()))
    bombs[(y,x)] = True
    rows[y][1] += 1
    cols[x][1] += 1


rows = sorted(rows, key=lambda x: x[1], reverse=True)
cols = sorted(cols, key=lambda x: x[1], reverse=True)
answer = 0
for row in rows:
    a = cols[0][1] + row[1] - (1 if (row[0], cols[0][0]) in bombs else 0)
    if a > answer:
        answer = a
for col in cols:
    a = rows[0][1] + col[1] - (1 if (rows[0][0], col[0]) in bombs else 0)
    if a > answer:
        answer = a
print(answer)

Measured memory_bytes: 134756
#pragma target("avx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
constexpr ll INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
constexpr ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, ans, a, b, c, d, tmp, m, h, w, x, y, sum, k, q;

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

  cin >> n;
  rep(i, ohara) {
    ans = i;
    ans *= 108;
    ans /= 100;
    if (ans == n) {
      Cout(i);
      return 0;
    }
  }
  Cout(":(");
  return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
const int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

int main() {
  string s; cin >> s;
  int n = s.length(), lb = 0, ub = n;
  while (ub - lb > 1) {
    int mid = (lb + ub) >> 1;
    bool ok = false;
    for (int parity : {0, 1}) {
      int l = parity, r = mid - (mid % 2 != parity);
      for (char c : s) {
        if (l > r) break;
        if (c == '0') {
          --l; --r;
          if (l < 0) l += 2;
        } else if (c == '1') {
          ++l; ++r;
          if (r > mid) r -= 2;
        } else if (c == '?') {
          --l; ++r;
          if (l < 0) l += 2;
          if (r > mid) r -= 2;
        }
      }
      ok |= l <= r;
    }
    (ok ? ub : lb) = mid;
  }
  cout << ub << '\n';
  return 0;
}


Measured memory_bytes: 4208
#include <iostream>
#include <cmath>
#include <vector>

using namespace std;

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

    vector<int> c;
    int temp;
    int all = 0;
    for (int i = 0; i < b; i++) {
        cin >> temp;
        all += temp;
        c.push_back(temp);
    }

    if (a - all >= 0) {
        cout << a - all;
    } else {
        cout << -1;
    }



    return 0;
}

Measured memory_bytes: 3700
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<long long int> vl;
typedef vector<vector<int>> vvi;
typedef vector<vector<long long int>> vvl;
typedef pair<int, int> pii;
typedef pair<long long int, long long int> pll;
typedef vector<pair<int, int>> vii;
typedef vector<pair<long long int, long long int>> vll;
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define test() long long int t; cin >> t; cin.ignore(); while(t--) 
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define MOD 1000000007
#define SMOD 998244353
#define pq priority_queue
#define all(x) x.begin(),x.end()
#define SP(x) setprecision(x)
#define sp " "
#define inp(a) ll a;cin>>a;cin.ignore()
#define inps(a,b) ll a,b;cin>>a>>b;cin.ignore()
#define out(a) cout<<SP(20)<<a<<'\n'
#define outs(a,b) cout<<SP(20)<<a<<" "<<b<<'\n'
#define ins insert
#define er erase
#define lb lower_bound
#define ub upper_bound
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
#define inpa(a,n) ll a[n]; for(int i=0; i<n; i++){cin>>a[i];}
#define inpv(a,n) vl a; for(int i=0; i<n; i++){inp(x);a.pb(x);}
#define outa(a,n) for(int i=0;i<n;i++){cout<<a[i]<<" ";}cout<<'\n';
#define outv(v) for(auto i:v){cout<<i<<" ";}cout<<'\n';
set<char> vow = {'a','e','i','o','u','A','E','I','O','U'};
ll xpow(ll n, ll m){if(m==0){return 1;}else{ll x = xpow(n, m/2);if(m&1){return x*x*n;}else{return x*x;}}}
ll xmod(ll a, ll m){return (((a%m)+m)%m);}
ll xmodpow(ll n, ll m, ll y){if(m==0){return 1;}else{ll x = xmodpow(n, m/2, y);if(m&1){return xmod((xmod((xmod(x,y)*xmod(x,y)),y)*xmod(n,y)),y);}else{return xmod((xmod(x,y)*xmod(x,y)),y);}}}
 
int main(){
    fast();

/* you get what you work for not what you wish for */
    inp(n);
    inpv(a, n-1);
    ll ans = a[0]+a[n-2];
    for(int i=0; i<n-2; i++){
        ans += min(a[i], a[i+1]);
    }
    out(ans);
}

Measured memory_bytes: 256
//daddy's back in town, back to rolling the damn hash yoooo babeeeeees//
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define clock (clock() * 1000.0 / CLOCKS_PER_SEC)
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
#define x first
#define y second
#define pi pair <int, int>
#define vi vector <int>
#define L nod<<1
#define R ((nod<<1)|1)
#define int ll
const ll mod = 998244353;
int n, m, ans, a[100010], id[100010], cur;
bool viz[100010];
vi g[100010];
vi xd[100010];

void dfs(int nod){
	viz[nod]=1;
	xd[cur].pb(nod);
	for(int i : g[nod]) if(viz[i]==0) dfs(i);
}

int32_t main(){
	ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();
	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	cin>>n>>m;
	for(int i=1; i<=n; i++){
		cin>>a[i];
		id[a[i]]=i;
	}
	for(int i=1, u, v; i<=m; i++){
		cin>>u>>v;
		g[u].pb(v);
		g[v].pb(u);
	}
	for(int i=1; i<=n; i++){
		if(viz[i]==0) cur++, dfs(i);
	}
	for(int i=1; i<=cur; i++){
		map<int, int> mp;
		for(int j: xd[i]) mp[j]++, mp[id[j]]++;
		for(pi j: mp) if(j.y==2) ans++;
	}
	cout<<ans;
}

Measured memory_bytes: 19828
/***************************************************************
	File name: E.cpp
	Author: ljfcnyali
	Create time: 2019年08月04日 星期日 19时58分15秒
***************************************************************/
#include<bits/stdc++.h>

using namespace std;

#define REP(i, a, b) for ( int i = (a), _end_ = (b); i <= _end_; ++ i ) 
#define mem(a) memset ( (a), 0, sizeof ( a ) ) 
#define str(a) strlen ( a ) 
typedef long long LL;

const int maxn = 510;

int n, k, sum, a[maxn], ans, b[maxn], c[maxn];

inline bool pd(int x)
{
    if ( x < ans ) return false;
    REP(i, 1, n) b[i] = a[i] % x;
    sort(b + 1, b + n + 1);
    REP(i, 1, n) c[i] = x - b[i];
    // REP(i, 1, n) printf("%d ", b[i]); puts("");
    REP(i, 2, n) { b[i] += b[i - 1]; c[i] += c[i - 1]; }
    REP(i, 1, n) if ( b[i] == (c[n] - c[i]) && b[i] <= k ) return true; 
    return false;
}

int main()
{
    scanf("%d%d", &n, &k);
    REP(i, 1, n) scanf("%d", &a[i]), sum += a[i];
    for ( int i = 1; i * i <= sum; ++ i ) 
    {
        if ( sum % i != 0 ) continue ;
        if ( pd(sum / i) ) ans = max(ans, sum / i);
        if ( pd(i) ) ans = max(ans, i);
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 256
import Data.Char as Char
import Control.Monad as Monad

solve :: [Int] -> [(Int, String)]
solve (n:ns) = map (foldl
                     (\ (acc,s) (op,digit) -> (toFunc op acc digit, s ++ op : show digit))
                      (n, show n)) $
                        map (`zip` ns) $ Monad.replicateM 3 ['+', '-']
               where toFunc c
                       | c == '+'     = (+)
                       | otherwise    = (-)

main :: IO ()
main = getLine >>=
  putStrLn .
  (\ ans -> (snd $ head ans) ++ "=7") .
  filter ((==7) . fst) .
  solve .
  map digitToInt

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

int main(){
  int A, B;
  cin >> A >> B;
  int mod1, mod2, mod3;
  mod1 = A % 3;
  mod2 = B % 3;
  mod3 = (A+B) % 3;
  string ans;
  if ((mod1==0) || (mod2==0) || (mod3==0)) ans = "Possible";
  else ans = "Impossible";
  cout << ans;
  return 0;
}

Measured memory_bytes: 256
import fractions

N = int(input())

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

L = [0] * N
R = [0] * N

now = A[0]
for i in range(N):

    if i >= 1:

        now = fractions.gcd(now,A[i-1])
        L[i] = now

A.reverse()

now = A[0]
for i in range(N):

    if i >= 1:

        now = fractions.gcd(now,A[i-1])
        R[i] = now

A.reverse()
R.reverse()

maxi = 0
for i in range(N):

    if L[i] == 0 or R[i] == 0:
        maxi = max(maxi,L[i],R[i])

    else:
        maxi = max(maxi, fractions.gcd(L[i],R[i]))

print (maxi)


Measured memory_bytes: 89580
#include <bits/stdc++.h>
using namespace std;
using  unll = unsigned long long;

int main() {
  string s;
  cin >> s;
  string ans;
  for(int i=0;i<s.size();i++){
    if( s.at(i) == 'B' ){
      ans = ans.substr(0,ans.size()-1);
    }else{
      ans.push_back(s.at(i));
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <algorithm> // sort
#include <string.h>
#include <bits/stdc++.h>
#include <math.h>

#define REP(i, n) for (long long i = 0; i < (n); i++) 
typedef long long ll;
static const ll MOD = 1000000007;
static const ll INF = 1000000000000000000LL;
using namespace std;


int main(){
    //std::ifstream in("resource/input.txt");
    //std::cin.rdbuf(in.rdbuf());

	int n;
	cin >> n;

	double x[n], y[n];
	
	REP(i,n)
	{
		cin >> x[i];
	}
	REP(i,n)
	{
		cin >> y[i];
	}

	//xiとyiの距離
	double diff[n];
	REP(i,n)
	{
		diff[i] = abs(x[i] - y[i]);
	}
	
	// p = 1;
	double d1 = 0;
	REP(i,n)
	{
		d1 += diff[i];
	}

	//p = 2;
	double d2 = 0;
	REP(i,n)
	{
		d2 += diff[i] * diff[i];
	}
	d2 = sqrt(d2);

	//p = 3
	//pow(x, 1.0 / 3.0); 3乗根
	double d3 = 0;
	REP(i,n)
	{
		d3 += diff[i] * diff[i] * diff[i];
	}

	d3 = pow(d3, 1.0 / 3.0);

	//p = 無限
	double dm = 0.0;
	REP(i,n)
	{
		dm = max(dm, diff[i]);
	}


    cout << fixed << setprecision(5) << d1 << endl;
    cout << fixed << setprecision(5) << d2 << endl;
    cout << fixed << setprecision(5) << d3 << endl;
    cout << fixed << setprecision(5) << dm << endl;


	//std::printf("%.5f¥n", res);
	
	return 0;
}




Measured memory_bytes: 3432
import java.util.*;

//update 2020/1/1 23:01

public class Main{

  static Scanner sc = new Scanner(System.in);
  static StringBuilder sb = new StringBuilder();

  public static void main(String[] args) {

    String s1 = next();
    String[] ss1 = splitString(s1);

    int n = s1.length();

    String s2 = "";
    String s3 = "";

    for(int i=0;i<(n-1)/2;i++){
      s2 += ss1[i];
    }

    for(int i=(n+3)/2-1;i<n;i++){
      s3 += ss1[i];
    }

    String[] ss2 = splitString(s2);
    String[] ss3 = splitString(s3);

    boolean ok = true;

    for(int i=0;i<s1.length();i++){
      if(!ss1[i].equals(ss1[s1.length()-1-i])){
        ok = false;
        break;
      }
    }

    for(int i=0;i<s2.length();i++){
      if(!ss2[i].equals(ss2[s2.length()-1-i])){
        ok = false;
        break;
      }
    }

    for(int i=0;i<s3.length();i++){
      if(!ss3[i].equals(ss3[s3.length()-1-i])){
        ok = false;
        break;
      }
    }

    if(ok){
      System.out.println("Yes");
    }
    else{
      System.out.println("No");
    }

  }

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

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

  /*
    static String toSmall(String s){
      char c = s.charAt(0);
      //if(Character.isUpperCase(c)){
      if(c<=90){
        c += 32;
      }
      return String.valueOf(c);
    }
    static String toBig(String s){
      char c = s.charAt(0);
      //if(Character.isLowerCase(c)){
      if(c>=97){
        c -= 32;
      }
      return String.valueOf(c);
    }
  */

  static String toSmall(String s){
    return s.toLowerCase();
  }

  static String toBig(String s){
    return s.toUpperCase();
  }

  static String next(){
    return sc.next();
  }

  static int nextInt(){
    return Integer.parseInt(sc.next());
  }

  static long nextLong(){
    return Long.parseLong(sc.next());
  }

  static double nextDouble(){
    return Double.parseDouble(sc.next());
  }

  static String[] splitString(String s){
    return s.split("");
  }

  static char[] splitChar(String s){
    return s.toCharArray();
  }

  static int charToInt(char a){
    return a - 48;
  }

////////////////////////////////////////////
  public static int max(int[] a){
    int lng = a.length;
    int max = a[0];
    for(int i=1;i<lng;i++){
      max = Math.max(max,a[i]);
    }
    return max;
  }
  public static long max(long[] a){
    int lng = a.length;
    long max = a[0];
    for(int i=1;i<lng;i++){
      max = Math.max(max,a[i]);
    }
    return max;
  }
////////////////////////////////////////////

////////////////////////////////////////////
  public static int min(int[] a){
    int lng = a.length;
    int min = a[0];
    for(int i=1;i<lng;i++){
      min = Math.min(min,a[i]);
    }
    return min;
  }
  public static long min(long[] a){
    int lng = a.length;
    long min = a[0];
    for(int i=1;i<lng;i++){
      min = Math.min(min,a[i]);
    }
    return min;
  }
////////////////////////////////////////////

}


Measured memory_bytes: 22996
import bisect

(a, b, q) = map(int, input().split())
s = [-10 ** 19]
for _ in range(a):
    s.append(int(input()))
s.append(10 ** 19)
t = [-10 ** 19]
for _ in range(b):
    t.append(int(input()))
t.append(10 ** 19)
x = [int(input()) for _ in range(q)]

for x_i in x:
    ss = bisect.bisect_left(s, x_i)
    tt = bisect.bisect_left(t, x_i)

    sc = [ss - 1, ss]
    tc = [tt - 1, tt]
    optimum = 10 ** 19
    for s_i in sc:
        for t_i in tc:
            dist = abs(s[s_i] - x_i) + abs(s[s_i] - t[t_i])
            if dist < optimum:
                optimum = dist
            dist = abs(t[t_i] - x_i) + abs(t[t_i] - s[s_i])
            if dist < optimum:
                optimum = dist
    print(optimum)

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

int main(){
    int n;
    cin>>n;
    int a[100];
    rep(i,n){
        cin>>a[i];
    }
    int count=0;
    rep(i,n){
        int minj=i;
        for(int j=i;j<n;j++){
            if(a[j]<a[minj]){
                minj=j;
            }
        }
        swap(a[i],a[minj]);
        if(a[i]!=a[minj])count++;
    }
    rep(i,n-1){
        cout<<a[i]<<" ";
    }
    cout<<a[n-1]<<endl;
    cout<<count<<endl;
    return 0;
}


Measured memory_bytes: 3084
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();
        if (a%3 == 0 || b%3 == 0 || (a+b) % 3 == 0) {
            System.out.println("Possible");
        } else {
            System.out.println("Impossible");
        }
    }
}


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

main()
{
  int n,h;
  int ans=0;
  int a_max=0;
  int a,b;

  priority_queue<int>que;
  que.push(0);

  cin >> n >> h;

  for(int i=0;i<n;i++){
    cin >> a >> b;
    a_max=max(a,a_max);
    que.push(b);
  }
  
  while(que.top()>a_max&&(!que.empty())&&h>0){
    ans++;
    h-= que.top();
    que.pop();
  }

  if(h>0){
    int d=h/a_max;
    if(d*a_max<h)
      ans++;
    ans+=d;
  }

  cout << ans << endl;

  return (0);
}


Measured memory_bytes: 892
#include <iostream>
#include <vector>
#define abs(x) (x>0?x:-(x))
#define MAX(x,y) (x>y?x:y)
#define D 200
#define N 200
#define INF 1000000
using namespace std;

typedef struct{
	int max_t,min_t,c;
} clothes;

int main(){
	clothes clt[210];
	int t[210];
	int d,n,old_c=0,sum=0;
	cin>>d>>n;

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

	for(int i=0;i<n;i++){
		cin>>clt[i].min_t>>clt[i].max_t>>clt[i].c;
	}

	int dp[D][N];
	
	for(int i=0;i<d;i++){
		for(int j=0;j<n;j++){
			if(i==0 && clt[j].min_t<=t[0] && clt[j].max_t>=t[0]) dp[i][j]=0;
			else dp[i][j]=-INF;
		}
	}

	for(int i=1;i<d;i++){
		for(int j=0;j<n;j++){
			if(clt[j].min_t<=t[i] && clt[j].max_t>=t[i]){
				for(int k=0;k<n;k++){
					dp[i][j]=MAX(dp[i][j],dp[i-1][k]+abs(clt[k].c-clt[j].c));
				}
			}
		}
	}
	
	int m=0;
	for(int i=0;i<n;i++){
		m=MAX(m,dp[d-1][i]);
	}

	cout<<m<<endl;
	return 0;
}

Measured memory_bytes: 1316
//Dragon_warrior7(IITK)
#include <bits/stdc++.h>
using namespace std;
#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 maxin(v) *max_element(v.begin(), v.end())
#define minin(v) *min_element(v.begin(), v.end())
#define sumall(vect) accumulate(vect.begin(), vect.end(), 0)
#define count(x, vect) count(vect.begin(), vect.end(), x)
#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 100000000000000000
#define deb(x) cout << #x << " " << x << "\n"
#define pll pair<ll, ll> 
#define vll vector<ll> 
#define rub cout << "------------------------------------\n"
//#define min(a, b, c) min(a, min(b, c))
//#define max(a, b, c) max(a, max(b, c))
void read(vector<ll> &v)
{
	for (int i = 0; i < v.size(); i++)
		cin >> v[i];
}

void print(vector<ll> v)
{
	for (int i = 0; i < v.size(); i++)
		cout << v[i] << " ";
}
ll n,m,a,b,temp;
string str;
set<ll> s;
vll v;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n>>m;
	ll c;
	cin>>c;
	vector<ll> b(m);
	read(b);
	while(n--)
	{
	    vll v(m);
	    read(v);
	    ll sum=0;
	    for(int i=0;i<m;i++)
	    sum+=v[i]*b[i];
	    if(sum+c>0)
	    a++;
	    
	}
	cout<<a;
	
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define N 1000000

typedef struct p{
	int task;
	char name[100];
}  P;

P newP(int task, char name[100]){
	P *pi;
	pi = (P *)malloc(sizeof(P));

	pi->task = task; 
	for(int i=0;i<100;i++) pi->name[i] = name[i];
	return *pi;
}

P *que;
int start, end;

void push(int task, char name[100]){
	que[end] = newP(task, name);
	end = (end+1)%N;
}

void ppush(P p){
	que[end] = p;
	end = (end+1)%N;
}

P pop(){
	P ans = que[start];
	start = (start+1)%N;
	return ans;
}

int main(){
	que = (P *) malloc(N*sizeof(P));
	start = end = 0;
	int n, q;
	scanf("%d %d", &n, &q);
	for(int i=0;i<n;i++){
		char *name;
		name = (char *) malloc(sizeof(char)* 100);
		int h;
		scanf(" %s %d", name, &h);
		push(h, name);
	}
	int now = 0;
	while(1){
		if(start == end) break;
		P nm = pop();
		if(nm.task <= q){
			now += nm.task;
			printf("%s %d\n", nm.name, now);
		} else {
			now += q;
			nm.task -= q;
			ppush(nm);
		}
	}
	return 0;
}

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

typedef long long ll;
typedef pair<ll, ll> P;
constexpr ll MOD = ll(1e9+7);

ll power(ll x, ll n){
    ll res = 1;
    x %= MOD;
    while(n > 0){
        if(n&1){
            res = res*x % MOD;
        }
        x = x*x % MOD;
        n >>= 1;
    }
    return res;
}

int main(){
    ll N, C;
    cin >> N >> C;
    vector<ll> A(N), B(N);
    for(int i=0;i<N;i++) cin >> A[i];
    for(int j=0;j<N;j++) cin >> B[j];

    vector<vector<ll> > sum(N+1, vector<ll>(C+1,0)), dp(N+1, vector<ll>(C+1));

    // sum[i][j] = A_i^j + (A_i+1)^j + ... + B_i^j
    for(int i=0;i<N;i++){
        for(int j=0;j<=C;j++){
            for(int k=A[i];k<=B[i];k++){
                sum[i][j] += power(k,j);
                sum[i][j] %= MOD;
            }
        }
    }
    dp[0][0] = 1;
    for(int i=0;i<N;i++){
        for(int j=0;j<=C;j++){
            for(int k=0;k<=C-j;k++){
                dp[i+1][j+k] += dp[i][j] * sum[i][k];
                dp[i+1][j+k] %= MOD;
            }
        }
    }
    cout << dp[N][C] << endl;
    return 0;
}

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

using namespace std;

int main()
{
	int n, k;
	cin >> n >> k;
	int h[n];
	for(int i=0;i<n;i++)
		cin >> h[i];
	int dp[n];
	dp[0] = 0;
	for(int i=1;i<n;i++)
	{
		int m = (int)1e9;
		for(int j=i-1;i - j <= k;j--)
		{
			if(j < 0) continue;
			m = min(m, dp[j] + abs(h[i] - h[j]));
		}
		dp[i] = m;
	}
	cout << dp[n-1] << "\n";
	return 0;
}


Measured memory_bytes: 1024