akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>

#define repd(i,a,b) for (int i=(a);i<(b);++i)
#define rep(i,n) repd(i,0,n)
#define reprd(i,a,b) for (int i=(a);i>=(b);--i)
#define repr(i,n) reprd(i,n,0)
typedef long long ll;

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

using namespace std;

const ll BIG = 1000000007LL;

int inputValue(){
    int a;
    cin >> a;
    return a;
};

template<typename T>
void inputArray(T* p, int a){
    rep(i, a){
        cin >> p[i];
    }
};

template<typename T>
void inputVector(vector<T> * p, int a){
    rep(i, a){
        T input;
        cin >> input;
        p -> push_back(input);
    }
}

template <typename T>
void output(T a, int precision = 0) {
    if(precision > 0){
        cout << setprecision(precision)  << a << "\n";
    }
    else{
        cout << a << "\n";
    }
}

const int Max = 110000;
int N;
ll A[Max], Aabs[Max];

int main(int argc, const char * argv[]) {
    cin >> N;
    inputArray(A, N);

    int minusCount = 0;
    rep(i, N) {
        if (A[i] < 0) minusCount++;
    }

    rep(i, N) {
        Aabs[i] = abs(A[i]);
    }

    ll sumA = 0;
    rep(i, N) {
        sumA += Aabs[i];
    }

    if (minusCount %2 == 0) {
        output(sumA);
    } else {
        ll minA = Aabs[0];
        rep(i, N) {
            chmin(minA, Aabs[i]);
        }
        output(sumA - 2*minA);
    }

    return 0;
}

Measured memory_bytes: 1792
import java.util.Scanner;
 
public class Main{
  public static void main(String[] args){
	Scanner in=new Scanner(System.in);
  	int W=in.nextInt();
    int H=in.nextInt();
    int x=in.nextInt();
    int y=in.nextInt();
    int m;
    double mid_W=(double)W/2;
    double mid_H=(double)H/2;
    if(mid_W==x && mid_H==y)
      m=1;
    else
      m=0;
    double area=(double)W*H/2;
    System.out.println(area+" "+m);
    in.close();
  }
}

Measured memory_bytes: 21716
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
using namespace std;

const int N=370;
const int M=30;

struct node{
	int x,y;
	node(){}
	node(int x,int y):x(x),y(y){}
}p[N];
int D,ans;
int s[N][M],lst[M],c[M],t[N],cnt[N][M];

int calc(){
	int sum=0;
	for (int i=1;i<=26;i++) lst[i]=0;
	for (int i=1;i<=D;i++){
		sum+=s[i][t[i]];
		lst[t[i]]=i;
		for (int j=1;j<=26;j++) sum-=c[j]*(i-lst[j]);
	}
	return sum;
}

int argmx(int d){
	int id=1;
	for (int i=2;i<=26;i++)
		if (s[d][i]>s[d][id]) id=i;
	return id;
}

bool cmp(node a,node b){
	return a.y>b.y;
}

int main(){
	scanf("%d",&D);
	for (int i=1;i<=26;i++) scanf("%d",&c[i]);
	for (int i=1;i<=D;i++)
		for (int j=1;j<=26;j++) scanf("%d",&s[i][j]);
	for (int i=1;i<=D;i++) t[i]=argmx(i);
	ans=calc();
	int lim=100000/D/20;
	int sum,tmp,nxt;
	for (int T=1;T<=lim;T++){
		for (int d=1;d<=D;d++){
			for (int i=1;i<=26;i++) lst[i]=0;
			for (int i=1;i<d;i++) lst[t[i]]=i;
			for (int i=1;i<=26;i++){
				nxt=d;
				for (int j=d;j<=D;j++)
					if (t[j]==i){
						nxt=j;
						break;
					}
				p[i]=node(i,s[d][i]-c[i]*(d-lst[i])+(nxt-d)*(d-lst[i]));
			}
			sort(p+1,p+1+26,cmp);
			for (int i=1;i<=10;i++){
				int q=p[i].x;
				tmp=t[d];
				t[d]=q; sum=calc();
				if (sum>ans) ans=sum;
				else t[d]=tmp;
			}
		}
	}
	for (int i=1;i<=D;i++) printf("%d\n",t[i]);
	return 0;
}

Measured memory_bytes: 3844
#include <bits/stdc++.h>
    using namespace std;
     
    int main() {
      char S;
      char check[100] = {'a', 'i' ,'u', 'e', 'o'};
      bool flag = false;
      cin >> S;
     
      for (int i = 0; i < 5; i++){
        if (S == check[i]) flag = true;
      }
      
      if(flag) {
        cout << "vowel" << endl;
      } else {
        cout << "consonant" << endl;
      }

    }

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

int main() {
  int N;
  cin>>N;
  vector<int>vec(N);
  for(int i=0;i<N;i++){
    cin>>vec.at(i);
  }
  sort(vec.begin(),vec.end());
  reverse(vec.begin(),vec.end());
  int A,B,ans;
  A=B=ans=0;
  for(int i=0;i<N;i++){
    if(i%2==0){
      A+=vec.at(i);
    }
    else{
      B+=vec.at(i);
    }
  }
    ans=A-B;
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define mod 1000000007
#define fi first
#define se second
#define pb push_back
#define IOS ios_base::sync_with_stdio(false);cout.tie(NULL);cin.tie(NULL);

using namespace std;

int main()
{
    IOS;
    int n,m;
    cin>>n>>m;
    int a[n+2]={0};
    int l,r;
    for(int i=0;i<m;i++)
    {
        cin>>l>>r;
        a[l]++;
        a[r+1]--;
    }
    int s=0,c=0;
    for(int i=1;i<=n;i++)
    {
        s+=a[i];
        if(s==m) c++;
    }
    cout<<c<<endl;
    return 0;
}

Measured memory_bytes: 640
n, m = map(int, input().split())
x = list(map(int, input().split()))

x.sort()
x_diff = []
for i in range(m-1):
    x_diff.append(x[i+1] - x[i])

x_diff.sort()

ans = 0
for i in range(len(x_diff) - (n-1)):
    ans += x_diff[i]
print(ans)

Measured memory_bytes: 20496
from collections import Counter,defaultdict,deque
import sys,bisect,math,itertools,string,queue,copy
from heapq import heappop, heappush
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7

def inp(): # n=1
    return int(input())
def inpm(): # x=1,y=2
    return map(int,input().split())
def inpl(): # a=[1,2,3,4,5,...,n]
    return list(map(int, input().split()))
def inpls(): # a=['1','2','3',...,'n']
    return list(input().split())
def inplm(n): # x=[] 複数行
    return list(int(input()) for _ in range(n))
def inpll(n): # [[1,1,1,1],[2,2,2,2],[3,3,3,3]]
    return sorted([list(map(int, input().split())) for _ in range(n)])
def sortx(x,n,k):
    if k == 0:x.sort(key=lambda y:y[1,n])
    else:x.sort(reversed=True, key=lambda y:y[1,n])
def graph():
    n,m=inpm()
    g=[[] for _ in range(n)]
    for _ in range(n-1):
        a,b=inpm()
        a-=1
        b-=1
        g[a].append(b)
        g[b].append(a)
    return n,m,g

def graphm():
    n=inp()
    g=[[] for _ in range(n)]
    for _ in range(n-1):
        a,b,w=inpm()
        a-=1
        b-=1
        g[a].append((b,w))
        g[b].append((a,w))
    return n,g

def main():
    n=inp()
    a=inplm(n)
    ans=0
    if a[0]!=0:
        print(-1)
        return
    for i in range(n-1):
        if a[i+1]>a[i]+1:
            print(-1)
            return
        if a[i+1]==a[i]:
            ans+=a[i]
        elif a[i+1]>a[i]:
            ans+=1
        elif a[i]>a[i+1]:
            ans+=a[i+1]
    print(ans)
if __name__ == "__main__":
    main()


Measured memory_bytes: 55768
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define F(i, s, n, k) for(int i=s;i<n;i+=k)
#define all_(a) a.begin(),a.end()
#define mp make_pair
#define INF INT_MAX
#define pb push_back
int n;
int a[101];
int dp[100005] = {0};


int solve(int k)
{
    if(dp[k])
    {
        return dp[k];
    }
    for(int i=0;i<n;++i)
    {
        if(k >= a[i])
        {
            if(solve(k-a[i]) == 2)
            {
                dp[k] = 1;
                return dp[k];
            }
        }
    }
    dp[k] = 2;
    return dp[k];
}


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);    
    int k;
    cin >> n >> k;
    for(int i=0;i<n;++i)
        cin >> a[i];
    
    //memset(dp, 0, sizeof(dp));
    dp[0] = 2;    
    if(solve(k) == 1)
    {
        cout << "First";
    }
    else cout << "Second";
    return 0;
}

Measured memory_bytes: 3712
#include<algorithm>
#include<array>
#include<cmath>
#include<iostream>
#include<iomanip>
#include<iso646.h>
#include<queue>
#include<stack>
#include<string>
#include<vector>

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

#define FOR(counter,initial_value,condition) for(int counter = initial_value; counter < condition;counter++)

int digitSum(int n,int digit=8) {
	// digit > 2
	int x = 1;
	FOR(i,0,digit){
		x *= 10;
	}
	int sum = 0;
	FOR(i, 0, digit) {
		sum += n / x;
		n %= x;
		x /= 10;
	}
	sum += n;
	return sum;
}


int main()
{
	int n;
	vector<int> a(100);
	cin >> n;
	a.resize(n);
	fill(a.begin(), a.end(), 0);
	FOR(i, 0, n) {
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	cout << a.back() - a.front() << endl;
}


Measured memory_bytes: 256
#pragma GCC optimize("O2,Ofast,inline,unroll-all-loops,-ffast-math")
#include <bits/stdc++.h>
#define pb(X) push_back(X)
#define INIT std::ios::sync_with_stdio(false);std::cin.tie(0);

using namespace std;

int n, a, b, c, d, q;

int main() {
	//INIT
	int k;
	cin >> n >> k;
	vector<int> a(n);
	vector<double> b(n + 1);
	double ans = 0.0;
	for (int i = 0; i < n; ++i) cin >> a[i];
	//b[0] = double(a[0] + 1) / 2.0;
	for (int i = 0; i < n; ++i) {
		b[i + 1] = b[i] + double(a[i] + 1) / 2.0;
	}
	for (int i = 0; i + k <= n; ++i) {
		ans = max(ans, b[i + k] - b[i]);
	}
	printf("%.7lf",ans);
	return 0;
}

Measured memory_bytes: 2560
// #include <boost/multiprecision/cpp_int.hpp> 
// using namespace boost::multiprecision; 
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define f first
#define s second
#define pb push_back
#define REP(i,a,b) for(long long int i=a ; i<b ; i++)
#define mp make_pair
#define INF 1000000000000000000
#define mod 1000000007
#define pi pair<ll,ll>
#define pd pair<ld,ld>
#define vi vector<ll>
#define vd vector<ld>
#define vvi vector<vi>
#define vvvi vector<vvi>
#define vvd vector<vd>
#define vpi vector<pi>
#define vpd vector<pd>
#define us unordered_set<ll>
#define um unordered_map<ll,ll>
#define sortA(a) sort(a.begin(),a.end())
#define sortD(a) sort(a.begin(),a.end(),greater<ll>())
#define all(a) a.begin(),a.end()
#define N 100005


#include <ext/pb_ds/assoc_container.hpp> 
using namespace __gnu_pbds; 
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> new_data_set; 
#define in insert
#define fbo find_by_order
#define ook order_of_key


void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

ll powmod(ll x,ll y)
{
	if(x==0)
		return 0;
	if(y==0 || x==1)
		return 1;
	if(y%2==0)
		return powmod((x*x)%mod,y/2)%mod;
	return (x*powmod(x,y-1)%mod)%mod;
}
void print1D(vi a)
{
	for(ll i=0;i<a.size();++i)
	{
		cout<<a[i]<<" ";
	}
	cout<<endl;
}
void print2D(vector<vi> a)
{
	for(ll i=0;i<a.size();++i)
	{
		for(ll j=0;j<a[i].size();++j)
		{
			cout<<a[i][j]<<" ";
		}
		cout<<endl;
	}
}
vvvi dp(10005,vvi(105,vi(2,-1)));
string k;
ll d;
ll count(ll pos,ll sum,ll tight)
{
	if(pos==k.size())
		return (sum==0);
	if(dp[pos][sum][tight]!=-1)
		return dp[pos][sum][tight];
	dp[pos][sum][tight]=0;
	ll mxd=9;
	if(tight)
		mxd=(k[pos]-'0');
	for(ll i=0;i<=mxd;++i)
	{
		dp[pos][sum][tight]=(dp[pos][sum][tight]+count(pos+1,(sum+i)%d,tight&(i==mxd)))%mod;
	}
	return dp[pos][sum][tight];
}
void solve()
{
	cin>>k>>d;
	dp[0][0][1]=count(0,0,1);
	cout<<(dp[0][0][1]-1+mod)%mod<<endl;
}
int main()
{
	ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
	ll t=1;
	// cin>>t;
	while(t--)
	{
		solve();
	}
}


Measured memory_bytes: 59136
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
int dp[55][55][4][1<<12];
char f[55][55];
int w,h,K;
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
bool out(int x,int y)
{
	if(x<0||x>=h||y<0||y>=w)return true;
	return false;
}
bool revisit(int bit)
{
	int tx=0,ty=0;
	for(int i=0;i<6;i++,bit>>=2)
	{
		int id=bit%4;
		tx+=dx[id];ty+=dy[id];
		if(tx==0&&ty==0)return true;
	}
	return false;
}
int rec(int x,int y,int k,int bit)
{
	if(x==0&&y==0)return 0;
	if(dp[x][y][k][bit]!=-INF)return dp[x][y][k][bit];
	int num=0;
	if(f[x][y]!='.'&&f[x][y]!='#'&&!revisit(bit))num=f[x][y]-'0';
	int res=-INF;
	for(int i=0;i<4;i++)
	{
		int nx=x+dx[i],ny=y+dy[i];
		if(!out(nx,ny)&&f[x][y]!='#'&&k-(i>=2)>=0)
		{
			res=max(res,rec(nx,ny,k-(i>=2),((1<<12)-1)&((bit<<2)+i))+num);
		}
	}
	return dp[x][y][k][bit]=res;
}
int main()
{
	cin >> h >> w >> K;
	for(int i=0;i<h;i++)
	{
		for(int j=0;j<w;j++)
		{
			cin >> f[i][j];
		}
	}
	for(int i=0;i<h;i++)
	{
		for(int j=0;j<w;j++)
		{
			for(int k=0;k<4;k++)
			{
				for(int l=0;l<(1<<12);l++)
				{
					dp[i][j][k][l]=-INF;
				}
			}
		}
	}
	cout << rec(h-1,w-1,K,0) << endl;
	return 0;
}

Measured memory_bytes: 177292
#include<bits/stdc++.h>//万能表头
using namespace std;
int a,b;
int main()
{
    cin>>a>>b;
    if(a%3==0||b%3==0||(a+b)%3==0)
    cout<<"Possible\n";
        else
        cout<<"Impossible\n";
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#pragma warning(disable:4996)
using namespace std;

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

vector<vector<int>>field(8, vector<int>(8));
bool ok(int y, int x) {
	return y >= 0 && y <= 7 && x >= 0 && x <= 7;
}

int turn(bool mami,vector<vector<int>>&field,const int y,const int x) {

	field[y][x] = mami ? 1 : 2;
	int changenum = 0;
	for (int i = 0; i < 8; ++i) {
		int nx = x + dx[i];
		int ny = y + dy[i];
		int num = 0;
		if (!ok(ny, nx))continue;
		if ((mami&&field[ny][nx] == 2) || (!mami&&field[ny][nx] == 1)) {
			while (1) {
				nx += dx[i];
				ny += dy[i];
				num++;
				if (!ok(ny, nx))break;
				if ((mami&&field[ny][nx] == 2) || (!mami&&field[ny][nx] == 1)) {

				}
				else if (!field[ny][nx]) {
					
					break;
				}
				else {
					for (int a = 1; a <= num; ++a) {
						field[y + dy[i] * a][x + dx[i] * a] = mami ? 1 : 2;
					}
					changenum += num;
					break;
				}

			}
		}
		
	}
	return changenum;
}
int main() {
	for (int i = 0; i < 8; ++i) {
		string st; cin >> st;
		for (int j = 0; j < 8; ++j) {
			if (st[j] == 'o') {

				field[i][j] = 1;
			}
			else if (st[j] == 'x') {
				field[i][j] = 2;
			}
			else {
				field[i][j] = 0;
			}
		}
	}
	bool mami = true;
	int flag = 2;
	while (flag) {
		flag--;


		vector<vector<int>>nums(8,vector<int>(8));

		for (int y = 0; y < 8; ++y) {
			for (int x = 0; x < 8; ++x) {
				if (!field[y][x]) {
					vector<vector<int>>cfield(field);
					nums[y][x] = turn(mami, cfield, y, x);
				}
			}
		}
		int amax = 0;
		int max_y;
		int max_x = 0;
		if (mami) {
			for (int y = 0; y < 8; ++y) {
				for (int x = 0; x < 8; ++x) {
					if (nums[y][x]>amax) {
						amax = nums[y][x];
						max_y = y;
						max_x = x;
					}
				}
			}
		}
		else {
			for (int y = 7; y >=0; --y) {
				for (int x = 7; x >=0; --x) {
					if (nums[y][x]>amax) {
						amax = nums[y][x];
						max_y = y;
						max_x = x;
					}
				}
			}
		}
		if (amax == 0) {}
		else {
			flag = 2;
			turn(mami, field, max_y, max_x);
			
		}
		mami = !mami;
	}
	for (int y = 0; y < 8; ++y) {
		for (int x = 0; x < 8; ++x) {
			if (field[y][x] == 2) {
				cout << 'x';
			}
			else if (field[y][x] == 1) {
				cout << 'o';
			}
			else {
				cout << '.';
			}
		}
		cout << endl;
	}
	return 0;
}

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

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define pb push_back
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define print(obj) cout << obj << endl
#define scan(obj) cin >> obj

typedef long long ll;

using namespace std;

int main(void){
    int n, ans = 0;
    map<int,int> a;
    cin >> n;
    rep(i, n){
        int temp;
        cin >> temp;
        if(a[temp] == 0) a[temp] = 1;
        else a[temp] = 0;
    }
    for(auto itr = a.begin(); itr != a.end(); itr++){
        ans += itr->second;
    }
    print(ans);
}

Measured memory_bytes: 4864
def solve(string):
    n, y = map(int, string.split())
    currents = [10000, 5000, 1000]
    for i in range(0, n + 1):
        _y = y - i * currents[0]
        for j in range(0, n + 1 - i):
            __y = _y - j * currents[1]
            if currents[2] * (n - i - j) == __y:
                return "{} {} {}".format(i, j, n - i - j)
    return "-1 -1 -1"


if __name__ == '__main__':
    print(solve(input()))


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using LL = long long int;
#define incID(i, l, r) for(int i = (l)    ; i <  (r); ++i)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); ++i)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); --i)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec(i, n)  decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
auto setmin   = [](auto & a, auto b) { return (b <  a ? a = b, true : false); };
auto setmax   = [](auto & a, auto b) { return (b >  a ? a = b, true : false); };
auto setmineq = [](auto & a, auto b) { return (b <= a ? a = b, true : false); };
auto setmaxeq = [](auto & a, auto b) { return (b >= a ? a = b, true : false); };
auto fl = [](auto a, auto b) { assert(b != 0); return a / b - (a % b != 0 && ((a >= 0) != (b >= 0)) ? 1 : 0); };
auto ce = [](auto a, auto b) { assert(b != 0); return a / b + (a % b != 0 && ((a >= 0) == (b >= 0)) ? 1 : 0); };
auto mo = [](auto a, auto b) { assert(b != 0); a %= b; if(a < 0) { a += abs(b); } return a; };
LL gcd(LL a, LL b) { return (b == 0 ? a : gcd(b, a % b)); }
LL lcm(LL a, LL b) { return a / gcd(a, b) * b; }
#define bit(b, i) (((b) >> (i)) & 1)
#define SI(v) static_cast<int>(v.size())
#define RF(e, v) for(auto & e: v)
#define until(e) while(! (e))
#define if_not(e) if(! (e))
#define ef else if
#define UR assert(false)

// ---- ----

int main() {
	int n;
	cin >> n;
	vector<int> a(n), b(n);
	inc(i, n) { cin >> a[i]; }
	inc(i, n) { cin >> b[i]; }
	
	int INF = n * n, ans = INF;
	inc(B, 1 << n) {
		vector<pair<int, int>> x, y;
		inc(i, n) { (bit(B, i) == i % 2 ? x : y).EB((bit(B, i) == 0 ? a : b)[i], i); }
		if(SI(x) != SI(y) + n % 2) { continue; }
		
		sort(ALL(x));
		sort(ALL(y));
		vector<int> v, w;
		inc(i, SI(x)) {
			v.PB(x[i].FI); w.PB(x[i].SE); if(i >= SI(y)) { break; }
			v.PB(y[i].FI); w.PB(y[i].SE);
		}
		if(! is_sorted(ALL(v))) { continue; }
		
		int t = 0;
		inc(i, n) {
		inc(j, n) {
			if(i < j && w[i] > w[j]) { t++; }
		}
		}
		setmin(ans, t);
	}
	
	if(ans == INF) { ans = -1; }
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
int n;
int a[105];
int myabs(int x) {
if(x>0) return x;
return -x;
}
int main() {
	int avg = 0;
	scanf("%d", &n);
	int i;
	for (i = 0; i < n; i++) {
		scanf("%d", &a[i]);
		avg += a[i];
		a[i] *= n;
	}
	int min = 2147483647,w=-1;
	for (i = 0; i < n; i++) {
		if (myabs(avg - a[i]) < min) {
			min = myabs(avg - a[i]);
			w = i;
		}
	}
	printf("%d", w);
	return 0;
}

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



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

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

using namespace std;

using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;

int main() {
    ll n, m, i, j, k;
    cin >> n >> m;
    cout << (n+m-1)/m << endl;
    return 0;
}

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

using namespace std;

#define int long long

const int mod = 998244353;

int n, s;
int a[3001], f[3001];

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

	cin >> n >> s;
	for (int i = 1; i <= n; i++)	
		cin >> a[i];
	f[0] = 1;
	for (int i = 1; i <= n; i++)
		for (int j = s; j >= 0; j--)
		{
			(f[j] *= 2) %= mod;
			if (j >= a[i])
				(f[j] += f[j - a[i]]) %= mod;	
		}
	cout << f[s];
}

Measured memory_bytes: 3700
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = list(input())
d = {'r':P, 's':R, 'p':S}

ans = 0

for i in range(N):
    if i < K:
        ans += d[T[i]]
    else:
        if T[i] != T[i - K]:
            ans += d[T[i]]
        else:
            T[i] = 'z'

print(ans)


Measured memory_bytes: 4084
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
typedef pair<ll, ll>P;
#define PI 3.14159265359
#define MOD 1000000007
const int MAX = 510000;

int main(){
  string S;
  cin>>S;
  int N=S.size();
  int cnt1=0,cnt0=0;
  rep(i,N){
    if(S[i]=='0'){cnt0++;}
    if(S[i]=='1'){cnt1++;}
  }
  int p=min(cnt0,cnt1);
  cout<<2*p;
}

Measured memory_bytes: 512
N=int(input())
M=[int(_) for _ in input().split()]
M.sort(reverse=True)
a=1
if M[-1]==0:
    print(0)
    exit()

else:
    for s in M:
        a=a*s
        if a>10**18:
            print(-1)
            exit()
print(a)

Measured memory_bytes: 84964
N = int(input())
S = input()

n = S[1:].count("E")
ans = n
for i, s in enumerate(S):
    if i == 0:
        continue
    if s == "E":
        n -= 1
    if S[i-1] == "W":
        n += 1
    ans = min(ans, n)

print(ans)


Measured memory_bytes: 3780
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <set>

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,j) FOR(i,0,j)
#define mp std::make_pair

typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int,int> P;
typedef std::pair<int,P> State;

const int INF = 1001001001;

// S N E W(南北東西)
const int dx[8] = {0, 0, 1, -1, 1, 1, -1, -1}, dy[8] = {1, -1, 0, 0, 1, -1, 1, -1};

int A[51];
std::string S[51];

int main(){
    A[0] = 1;
    S[0] = "kogakubu10gokan";

    int N, Q;
    std::cin >> N >> Q;

    FOR(i, 1, N+1){
        std::cin >> A[i];
        std::cin >> S[i];
    }

    int index = std::upper_bound(A, A+N+1, Q) - A - 1;
    std::cout << S[index] << std::endl;
}

Measured memory_bytes: 1204
#include<cstdio>
#include<vector>
using namespace std;
vector<int> x[100];
int n,m,boolx,ans;
bool vis[100];
void init(){
	scanf("%d%d",&n,&m);
	for(int a,b,i=1;i<=m;++i){
		scanf("%d%d",&a,&b);
		x[b].push_back(a);
		x[a].push_back(b);
	}
}
void dfs(int v){
	vis[v]=true; boolx++;
	if(boolx==n) {
		ans++;  return;
	}
	for(int i=x[v].size()-1;i>=0;--i){
		if(!vis[x[v][i]]){
			dfs(x[v][i]);
			vis[x[v][i]]=false;
			boolx--;
		}
	}
}
int main(){
	init();
	dfs(1);        
	printf("%d",ans);
	return 0;
}
/*
3 3
1 2
1 3
2 3
*/
/*
7 7
1 3
2 7
3 4
4 5
4 6
5 6
6 7
*/

Measured memory_bytes: 256
// in the name of GOD
#include <bits/stdc++.h>
#define  S second
#define  F first
#define pb push_back
#define sz(cp) 1LL*cp.size()
#define tm are_you_now_tm_is_define_?
#define ta(c) c-'a'+1 
#define int long long
using namespace std;
typedef long long ll ;
typedef long double ld ;
typedef pair < ll , ll > pii ;
const int maxn = 1e5 + 500 ;
int n , q , _n;
ll Ans[maxn] , path[maxn] ;
vector<pii>v[maxn] ;
vector<int>add[maxn] ;
vector<ll>mv ;

void get_yal(int i , ll w1){
	if(w1 <= n){
		add[w1].pb(i) ;
		return ;
	}
	int j = upper_bound(mv.begin(),mv.end(),w1)-mv.begin()-1 ;
	j = min(j,i-1) ;
	v[j].pb(pii(i,w1/mv[j])) ;
	get_yal(i,w1%mv[j]);
}
main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	cin >> n >> q ; _n = n ;
	for(int y = 0 ; y < q ; y++){
      ll i ;
      cin >> i ;
      mv.pb(i) ;
    }
  	if(q==0){
     for(int y = 1 ; y <= n ; y++)
       cout << 1 << '\n' ;
      return 0 ;
    }
	for(int y = q-2 ; y+1 ; y--)
	mv[y] = min(mv[y] , mv[y+1]) ;
	if(mv[0] <= n)
	n = mv[0] ;
	else
	reverse(mv.begin(),mv.end()),mv.pb(n),reverse(mv.begin(),mv.end()),q++;
	mv.pb(1LL*1e18+10) ; path[q-1] = 1;
	for(int y = 0 ; y < q ; y++)
	get_yal(y,mv[y]) ;
	for(int y = q-1 ; y+1 ; y--)
	for(auto A : v[y])
	path[y] += A.S*path[A.F] ;
	for(int y = n ; y ; y--){
		Ans[y] += Ans[y+1] ;
		for(auto A : add[y])
		Ans[y] += path[A] ;
	}
	for(int y = 1 ; y <= _n ; y++)
	cout << Ans[y] << endl ;
	return 0 ;
}



Measured memory_bytes: 23668
#include<bits/stdc++.h>
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
#define rep(i,n)for(ll i=0;i<n;i++)
using namespace std;
typedef long long ll;
typedef pair<int, int>P;

int t[10000];
vector<P>E[10000];
int d[10000][3][201];

struct st {
	int u, c, i, a;
};
bool operator<(st a, st b) {
	return a.c > b.c;
}
int main() {
	int n, m, x; scanf("%d%d%d", &n, &m, &x);
	rep(i, n)scanf("%d", &t[i]);
	rep(i, m) {
		int a, b, d; scanf("%d%d%d", &a, &b, &d); a--; b--;
		E[a].push_back(P(d, b)); E[b].push_back(P(d, a));
	}
	priority_queue<st>que;
	memset(d, 0x3f, sizeof(d));
	d[0][0][0] = 0; que.push({ 0,0,0,0 });
	while (!que.empty()) {
		st s = que.top(); que.pop();
		if (d[s.u][s.i][s.a] != s.c)continue;
		for (P v : E[s.u]) {
			int a = min(x, s.a + v.first), k = t[v.second];
			if (abs(s.i - t[v.second]) == 2) {
				if (a < x)continue;
			}
			if (k == 1)k = s.i;
			else a = 0;
			if (d[v.second][k][a] > s.c + v.first) {
				d[v.second][k][a] = s.c + v.first;
				que.push({ v.second, d[v.second][k][a],k,a });
			}
		}
	}
	int Min = INF;
	rep(i, 3)rep(j, x + 1) {
		Min = min(Min, d[n - 1][i][j]);
	}
	printf("%d\n", Min);
}

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

 const int H=1000+5, W=1000+5;
char a[H][W];
int h, w;

int mem[H][W];
int mod=1e9+7;
    int dp(int i, int j){
    if(i==h-1&&j==w-1)
        return 1;
        if(i==h||j==w)
            return 0;
        if(a[i][j]=='#')
            return 0;
    if(mem[i][j]!=-1)
        return mem[i][j];

   int  p1=dp(i+1,j)%mod;
   int p2=dp(i,j+1)%mod;
    return mem[i][j]=(p1+p2)%mod;
    }
int main(){

scanf("%d%d",&h,&w);
for(int i=0;i<h;i++)

    scanf("%s",&a[i]);
memset(mem,-1,sizeof mem);
    printf("%d\n",dp(0,0));
}


Measured memory_bytes: 5248
using System;
using System.Text;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		// 整数の入力
		int N = int.Parse(Console.ReadLine());
		// スペース区切りの整数の入力
		string[] Xs = Console.ReadLine().Split(' ');
      	List<int> array1 = new List<int>(Xs.Length);
      	List<int> array2 = new List<int>(Xs.Length);
      	
      	// parsing
      	for(int i = 0; i < Xs.Length; i++)
        {
        	array1.Add(Int32.Parse(Xs[i]));
          	array2.Add(array1[i]);
        }
      	array2.Sort();
      	// logic
      	int Left = array2[Xs.Length / 2 - 1];
      	int Right = array2[Xs.Length / 2];
		//出力
      	for(int i = 0; i < Xs.Length; i++)
        {
          ///*
          if(Left < array1[i])
          {
			Console.WriteLine(Left);
          }
          else
          {
          	Console.WriteLine(Right);
          }
          //*/
        }
	}
}


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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a*b/gcd(a, b);
}

int main()
{
    cout << fixed << setprecision(15);
    ll A, B, C, D;
    cin >> A >> B >> C >> D;

    cout << max(0LL, min(B,D) - max(A,C)) << endl;
    return 0;
}

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

vector<ll> vec;
void brute(int d, ll num, int tam) {
    if(tam > 11) return;
    vec.pb(num);

    if(d - 1 >= 0) {
        brute(d-1, num * 10 + d-1, tam + 1);
    }
    brute(d, num * 10 + d, tam + 1);
    if(d + 1 <= 9) {
        brute(d+1, num * 10 + d+1, tam + 1);
    }
}

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

    for(int i = 1; i <= 9; ++i) brute(i, i, 1);

    ll k; cin >> k;
    k--;

    nth_element(vec.begin(), vec.begin() + k, vec.end());
    cout << vec[k] << endl;
}

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

using namespace std;
typedef long long ll;

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

  string s;
  cin >> s;

  cout << s.substr(0, 5) + " " + s.substr(6, 7) + " " + s.substr(14)<< "\n";
}


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

int main() {
  int N,K;
  cin >> N >> K;
  int ans = 10000000;
  for (int i = 0;i<=N;i++) {
    int temp = 1;
    temp *= pow(2,i);
    temp += K*(N-i);
    ans = min(ans,temp);
  }
  cout << ans << endl;
    
    
  
}


Measured memory_bytes: 512
#include<stdio.h>
int main(void)
{
	int a,n,m,cnt,i,j,box,sum,box2;
	scanf("%d %d %d",&a,&n,&m);
	cnt=0;
	for(i=1;i<=72;i++){
		box=i;
		sum=0;
		box=box+a;
		box2=box;
		for(j=2;j<=n;j++){
			box2=box2*box;
		}
		if(box2<=m){
		while(box2>0){
		    sum=sum+box2%10;
			box2=box2/10;
		}
		if(sum==i){
			cnt++;
		}
		}
	}
	printf("%d\n",cnt);
	return 0;
}


Measured memory_bytes: 2076
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>
#include <stdlib.h>
#include <stdio.h>
#include <functional>
#include <cfloat>
#include <math.h>
#include <numeric>
#include <string.h>
#include <sys/time.h>
#include <random>


#define fs first
#define sc second

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;


int main(){
    int h, w, n; cin >> h >> w >> n;
    if(h > w){
        swap(h, w);
    }

    cout << (n-1) / w + 1 << endl;



    return 0;
}


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

int main(void){
  int i=0,num;
  double a[N]={0},b[N]={0},c[N]={0},d[N]={0},e[N]={0},f[N]={0};
  double x,y,delta;

  while(scanf("%lf%lf%lf%lf%lf%lf",&a[i],&b[i],&c[i],&d[i],&e[i],&f[i])==6) i++;
  num=i;
  for(i=0;i<num;i++){
    delta=a[i]*e[i]-d[i]*b[i];
    x=(c[i]*e[i]-f[i]*b[i]);
    if(x!=0.0 && delta!=0.0)  x/=delta;
    y=(a[i]*f[i]-d[i]*c[i]);
    if(y!=0.0 && delta!=0.0)  y/=delta;
    printf("%0.3f %0.3f\n",x,y);
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
 
int main(){
    ll N;
    cin >> N;

    string ans = "";
    while(N > 0){
        N--;
        ans += 'a' + N % 26;
        N /= 26;
    }
    reverse(ans.begin(), ans.end());
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3612
ls = list(map(str, input().split()))

for i, moji in enumerate(ls):
    for txt in moji:
        if txt.isupper():
            print(txt.lower(),end='')
        else:
            print(txt.upper(),end='')
    if i != len(ls)-1:
        print('' ,end=' ')
    else:
        print()



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

using namespace std;

#define int long long

const int MAX_N = 1e5 + 5;
const int MAX_L = 20; // ~ Log N
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef unordered_map<int,int> mii;
typedef unordered_map<char,int> mci;
typedef unordered_map<string,int> msi;

#define pb push_back
#define f first
#define s second 
 
void solve() {
    string s,t,ans="";cin>>s>>t;
    int n=s.length(),m=t.length();
    vvi dp(n+1,vi(m+1));
    for(int i=1;i<=n;i++) {
        dp[i][0] = 0;
    }
    for(int i=1;i<=m;i++) {
        dp[0][i] = 0;
    }
    dp[0][0] = 1;

    for(int i=1;i<=n;i++) {
        for(int j=1;j<=m;j++) {
            if(s[i-1]==t[j-1]) {
                dp[i][j] = 1+ dp[i-1][j-1];
            }
            else {
                dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
            }
        }
    }
    int i=n,j=m;
    while(i>0 && j>0) {
        if(s[i-1]==t[j-1]) {
            ans+= s[i-1];
            i--,j--;
        }
        else {
            if(dp[i-1][j]>=dp[i][j-1]) {
                i--;
            }
            else {
                j--;
            }
        }
    }
    reverse(ans.begin(),ans.end());
    cout<<ans<<'\n';
}

int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    //#ifdef ONLINEJUDGE
 //       freopen("input.txt", "r", stdin);
    //     freopen("output.txt", "w", stdout);
    //#endif

    int tc; tc=1;
    for (int t = 1; t <= tc; t++) {
        //cout << "Case #" << t  << ": ";
        solve();
    }
}

Measured memory_bytes: 73680
#include<stdio.h>

int main()
{
    char ch;
    scanf("%c",&ch);
    switch(ch){
        case 'A':
        printf("T");
        break;
        case 'T':
        printf("A");
        break;
        case 'C':
        printf("G");
        break;
        case 'G':
        printf("C");

    }




return 0;
}


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

int main()
{
	string ans, str, S;
	str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

	int N,x;
	cin >> N >> S;
	ans = S;

	for (int i = 0; i < S.size(); i++) {
		for (int j = 0; j < 25+1; j++) {
			if (S.at(i) == str.at(j)) {
				 x = j + N;
				while (x > 25) x = x - 26;
				ans.at(i) = str.at(x);
				break;
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <math.h>
#include <string>

using namespace std;

int main(){

  long long h, n;
  cin >> h >> n;
  int A[n];
  for (int i=0; i<n; i++){ cin >> A[i];}

  for(int i=0; i<n; i++){
    h -= A[i];
    if (h < 1) break;
  }

  if (h<1) {
    cout << "Yes";
  } else {
    cout << "No";
  }
  //  cout << h;

}


Measured memory_bytes: 640
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

int main() {
#ifdef DEBUG
  ifstream ifs("in.txt");
  cin.rdbuf(ifs.rdbuf());
#endif
  int P, Q, R;
  while (cin >> P >> Q >> R) {
    int res = P + Q + R - max({P, Q, R});
    cout << res << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define N 1000003
#define MAX 1100000
using namespace std;

long long factorial[MAX] = {0}, finverse[MAX] = {0},
          inverse[MAX] = {0};

void smodfact() {
  factorial[0] = factorial[1] = 1;
  finverse[0] = finverse[1] = 1;
  inverse[1] = 1;
  for(int i = 2; i < MAX; ++i) {
    factorial[i] = factorial[i - 1] * i % N;
    inverse[i] = N - (inverse[N % i] * (N / i)) % N;
    finverse[i] = finverse[i - 1] * inverse[i] % N;
  }
}

long long calccomb(long long n, long long k) {
  if(n == k && n == 0) return 1;
  if(n < 0 || k < 0 || n < k) return 0;
  return factorial[n] * finverse[k] % N * finverse[n - k] %
         N;
}

long long n, d, q, x;
long long memo[64] = {0};

long long solve();
long long calc(long long now);

int main() {
  smodfact();
  cin >> q;
  for(int i = 0; i < q; ++i) {
    cin >> x >> d >> n;
    cout << solve() << endl;
  }
  return 0;
}

long long solve() {
  long long ans = 0;
  if(d == 0)
    ans = calc(x);
  else{
      x *= inverse[d];
      x %= N;
      if((x + n + N - 1) % N > (x + N - 1) % N && n < N) {
        ans = factorial[(x + n + N - 1) % N] *
        finverse[(x + N - 1) % N] % N * calc(d) % N;
    }
  }
  return ans;
}

long long calc(long long now) {
  long long ans = 1, nown = n;
  memo[0] = now;
  for(long long i = 1; i < 33; ++i)
    memo[i] = memo[i - 1] * memo[i - 1] % N;
  for(long long i = 32; i >= 0; --i)
    if((1LL << i) <= nown) {
      nown -= 1LL << i;
      ans *= memo[i];
      ans %= N;
    }
  return ans;
}


Measured memory_bytes: 26624
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;i<(n);i++)
#define REP(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define INF LLONG_MAX - 100
#define MOD 1000000007
#define fcout cout << fixed << setprecision(15)
#define int long long
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)?"YES":"NO")
#define lowb lower_bound
#define upb upper_bound
typedef long long ll;
typedef pair<int, int> P;
typedef priority_queue<int> pque;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a/gcd(a,b)*b;};
int mod(int a,int b){return (a+b-1)/b;};
int month[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
template<typename A, size_t N, typename T>
void Fill(A(&array)[N],const T &val){std::fill((T*)array,(T*)(array+N),val);}
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;};



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

	int a[5];
	rep(i, 5) cin >> a[i];
	sort(a, a + 5, greater<>());
	rep(i, 5) {
		if(i) cout << " ";
		cout << a[i];
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 3116
#include<iostream>
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 + j) % 2 == 0)cout << "#";
				else {
					cout << ".";
				}
			}
			cout << "\n";
		}
		cout << "\n";
	}
}


Measured memory_bytes: 3100
#include<stdio.h>
int main(){
  int n,h,w,a[1000],b[1000],i,j=0;
  scanf("%d%d%d",&n,&h,&w);
  for(i=0;i<n;i++){
    scanf("%d%d",&a[i],&b[i]);
    if(a[i]>=h&&b[i]>=w) j++;
  }
  printf("%d",j);
}

Measured memory_bytes: 128
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))

count = 0
pre   = 0
for i in range(N):
	now = A[i] - 1
	count += B[now]
	if i != 0 and pre == now - 1:
		count += C[pre]
	pre = now
print(count)


Measured memory_bytes: 3064
#include <stdio.h>
 
int F_to_C(int F, int C)
{
	C = (F - 30) / 2;
	return C;
} 
 
int main()
{
    int Fahrenheit, Celsius;
	scanf("%d", &Fahrenheit);
	Celsius=F_to_C(Fahrenheit, Celsius);
	printf("%d\n", Celsius);
	return 0;
}



Measured memory_bytes: 2092
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define pll pair<ll,ll>
#define pb push_back
#define F first
#define S second
#define I insert
#define vll vector<ll>
#define vpll vector<pll>
#define all(x) (x).begin(), (x).end()
#define sz(x) (ll)(x).size()
#define endl '\n'

ll power(ll a, ll b, ll mod){ ll c = 1; while(b>0){ if(b%2) c*=a, c%=mod; b/=2; a*=a; a%=mod; } return c; }
 
const ll N = (1e5) + 10;
const ll M = 320;
const ll Mod = 1e9 + 7;
ll ar[N],br[N];
vll u;

ll go(ll a, ll b){
	if(a == b) return 0;
	ll mid = (a+b)/2;
	ll ans = go(a,mid)+go(mid+1,b);
	u.clear();
	ll i,j;
	i = a; j = mid+1;
	while(i <= mid && j <= b){
		while(i<=mid && br[i] <= br[j]) u.pb(br[i++]), ans += j-(mid+1);
		if(i > mid) break;
		while(j<=b && br[j] < br[i]) u.pb(br[j++]);
	}
	while(i<=mid) u.pb(br[i++]), ans += j-(mid+1);
	while(j<=b) u.pb(br[j++]);
	for(i=a;i<=b;i++)
		br[i] = u[i-a];
	return ans;
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout<<setprecision(25);
    ll n,hi,lo,mid,a,b,c,d,i,j,k;
    cin>>n; vll v;
    for(i=1;i<=n;i++) cin>>ar[i], v.pb(ar[i]);
    ll amt = (n*(n+1))/2;
	ll inv,ans;
	sort(all(v)); v.resize(unique(all(v))-v.begin());
	lo = 0;
	hi = sz(v)-1;
    while(hi >= lo){
    	mid = (hi+lo)/2; ll aha = 0;
    	for(i=1;i<=n;i++) {br[i] = ((ar[i] >= v[mid]) ? 1 : -1), br[i] += br[i-1]; if(br[i] < 0) aha++;}
		inv = amt - go(1,n) - aha;
    	if(2*inv >= amt){
    		ans = mid;
    		lo = mid+1;
    	}
    	else{
    		hi = mid-1;
    	}
    }
    cout<<v[ans]<<endl;
    return 0;
}

Measured memory_bytes: 4084
#include <bits/stdc++.h>
#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define RREP(i,a,b) for(int i=(a);i>=(b);i--)
typedef long long ll; typedef long double ld;
using namespace std;
const int INF=1e9, MOD=1e9+7, around[]={0,1,1,-1,-1,0,-1,1,0,0};
const ld PI=abs(acos(-1));
string s,w;

int main(){
	cin >> s >> w;
	
	bool f=true;
	REP(i,0,s.size()) if(s[i]=='?'){f=false; break;}
	if(f){cout << s << endl; return 0;}
	
	string t;
	REP(i,0,w.size()-1) t+='?';
	
	set<string> st;
	REP(i,0,s.size()){
		bool f=true;
		REP(j,0,w.size()) if(s[i+j]!='?' and s[i+j]!=w[j]) f=false;
		
		if(f){
			string a;
			a+=s.substr(0,i);
			a+=w;
			a+=s.substr(i+w.size(),s.size());
			
			REP(i,0,a.size()) if(a[i]=='?') a[i]='a';
			st.insert(a);
		}
	}
	
	if(st.size()){
		for(auto s:st){cout << s << endl; break;}
	}else{
		cout << "UNRESTORABLE" << endl;
	}
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pair<int, int>> vpii;
typedef pair<int, int> pii;
#define PB push_back
#define EB emplace_back
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

#define MOD 1'000'000'007LL
ll pw(ll a, ll b){
	ll c=1, d=a;
	while(b){
		if(b&1) c=c*d%MOD;
		d=d*d%MOD;
		b/=2;
	}
	return c;
}
ll inv(ll a){
	return pw(a, MOD-2);
}

#define N 112345
ll fct[N]={1}, fctinv[N]={1};
ll npr(ll a, ll b){
	// DEBUG("%lld %lld %lld\n", a, b, a-b);
	if(a<b) return 0;
	else return fct[a] * fctinv[a-b] % MOD;
}
ll n, k;
vi g[N];
ll dfs(int a, int p=-1){
	ll x = p==-1 ? k-1 : k-2;
	ll c = g[a].size();
	if(p==-1) c = c;
	else c = c-1;
	ll ret = npr(x, c);
	DEBUG("%d: %lld\n", a+1, ret);
	for(int &i: g[a]) if(i!=p) {
		ret = ret * dfs(i, a) % MOD;
	}
	return ret;
}

int main(){
	FOR(i, 1, N) fct[i]=fct[i-1]*i%MOD, fctinv[i]=inv(fct[i]);
	scanf("%lld%lld", &n, &k);
	REP(i, n-1){
		int a, b; scanf("%d%d", &a, &b); a--; b--;
		g[a].EB(b);
		g[b].EB(a);
	}
	printf("%lld\n", k * dfs(0) % MOD);
}


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

int main() {
  int n;
  while(cin >> n, n) {
    int target;
    vector<int> v(n);
    for(int i = 0; i < n; i++) cin >> v[i];
    cin >> target;

    int cnt = 1;
    bool b = false;
    int left = 0, right = n-1;
    while(left <= right) {
      int t = (right+left)/2;
      if(v[t] == target) {
        b = true;
        break;
      } else if(v[t] < target) {
        left = t+1;
      } else {
        right = t-1;
      }
      cnt++;
    }
    if(!b) cnt--;
    cout << cnt << endl;
  }
}

Measured memory_bytes: 1192
/*
If you want to aim high, aim high
Don't let that studying and grades consume you
Just live life young
******************************
If I'm the sun, you're the moon
Because when I go up, you go down
*******************************
I'm working for the day I will surpass you
https://www.a2oj.com/Ladder16.html
*/
import java.util.*;
import java.io.*;
import java.math.*;

   public class Main
   {
      public static void main(String omkar[]) throws Exception
      {
         BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));  
         StringTokenizer st = new StringTokenizer(infile.readLine());
         int N = Integer.parseInt(st.nextToken());
         int X = Integer.parseInt(st.nextToken());
         int Y = Integer.parseInt(st.nextToken());
         int[] res = new int[N];
         for(int a=1; a <= N; a++)
            for(int b=a+1; b <= N; b++)
            {
               int dist = b-a;
               dist = Math.min(dist, Math.abs(a-X)+Math.abs(b-Y)+1);
               res[dist]++;
            }
         StringBuilder sb = new StringBuilder();
         for(int k=1; k < N; k++)
            sb.append(res[k]+"\n");
         System.out.println(sb);
      }
   }

Measured memory_bytes: 22228
import math
import itertools
n = int(input())
city = [[int(i) for i in input().split()] for j in range(n)]


allnum = math.factorial(n)

city_num = [int(i) for i in range(n)]

ans = 0

for v in itertools.permutations(city_num):
    # print(v)
    pre = -1
    for i in v:
        if pre == -1:
            pre = i
            continue
        ans += math.sqrt((city[i][0] - city[pre][0]) **
                         2 + (city[i][1] - city[pre][1]) ** 2)
        pre = i

print(ans/allnum)


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

int main(void)
{
  int num1,num2;
  
  cin >> num1;
  cin >> num2;
  
  int max;
  max = num1;
  if( max < num2 ) {
    max = num2;
  }
  int n;
  cin >> n;
 if (n%max == 0) {
      cout <<n/max<<endl;
  }else{
      cout <<n/max + 1<<endl;
      }
  return 0;
}


Measured memory_bytes: 256
import sys, re
from math import ceil, floor, sqrt, pi, factorial, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left, bisect_right
from functools import reduce
from decimal import Decimal, getcontext
# input = sys.stdin.readline 
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7
num_list = []
str_list = []

def main():
    n = i_input()
    d, x = i_map()
    num_list = i_row(n)

    count = x

    for i in range(n):
        day = 1
        while day <= d:
            count += 1
            day += num_list[i]

    print(count)

if __name__ == '__main__':
    main()


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

int main() {
	int W, H, x, y, r;
	cin >> W >> H >> x >> y >> r;
	if (x >= r && x <= (W - r) && y >= r&&y <= H - r)
		cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 1160