akhauriyash/Code-Regression huggingface dataset:
import math
n,k=map(int, input().split())
a=list(map(int, input().split())) 
count=0
ans=0
x=0
y=0
y=(k+1)*k//2
y=y%(10**9+7)
b=sorted(a)
for i in range(n):
    for j in range(i,n):
        if a[i]>a[j]:
            count+=1
    for p in range(n):
        if b[p]==a[i]:
            x=p
            break
    
    ans+=count*k+x*(k-1)*k//2
    count=0
            

print(ans%(10**9+7))

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define idfc ios_base::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
#define ll long long
#define pb push_back
#define mp make_pair
#define nt _int128
#define ld long double
long double PI =3.14159265358979323846;


const ll modo=1e9+7;
const ll inf=2e14;
const ll ms=(1e5) +5;

ll ar[ms];
ll ans=0;
ll fac[ms];
void add(ll x)
{
    ans+=x;
    ans%=modo;
}

void sub(ll x)
{
    ans-=x;
    ans+=modo;
    ans%=modo;
}


ll pow(ll a, ll b)
{
    ll rr=1;
    a%=modo;
    while (b>0)
    {
        if(b&1)
        {
            rr*=a;
            rr%=modo;
        }
        a*=a;
        a%=modo;
        b>>=1;
    }
    return rr;
}


ll ncr(ll n, ll r)
{
    if(r>n)return 0;

    ll nn=fac[n];
    ll den=pow(fac[r]*fac[n-r],modo-2);
    return (nn*den)%modo;
}

int main()
{
    idfc;
    fac[0]=1;
    for(ll i=1;i<=1e5;i++)
    {
        fac[i]=(fac[i-1]*i)%modo;
    }
    ll n,k;
    cin>>n>>k;
    int i;
    for(i=1;i<=n;i++)cin>>ar[i];

    sort(ar+1,ar+(n+1));

    if(k==1)
    {
        cout<<0;
        return 0;
    }

    ar[0]=modo;
    ar[n+1]=modo;

    ll pr=0;
    ll tt,pp;
    for(i=n;i>=1;i--)
    {
        tt=ncr(i-1,k-1);
            pp=tt*ar[i];
            add(pp);
            pr=pp;
        //cout<<pr<<" ";
    }
   // cout<<endl;
    pr=0;
    for(i=1;i<=n;i++)
    {
            tt=ncr(n-i,k-1);
            pp=tt*ar[i];
            sub(pp);
            pr=pp;
        //else sub(pr);
        //cout<<pr<<" ";
    }
    //cout<<endl;
    cout<<ans;
    return 0;
}

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

int main() {
  vector<int> x(5);
  for(int i = 0; i < 5; i++){
    cin >> x.at(i);
  }
  for(int i = 0; i < 5; i++){
    
    if(x.at(i) == 0){
      cout << i + 1 << endl;
    }
  }
}



Measured memory_bytes: 3616
#include <stdio.h>
#include <math.h>
int main(void){
  long long int a,b,i;
  scanf("%lld %lld",&a,&b);
  if(a>0&&a<=b) printf("Positive");
  else if(a<=0&&0<=b) printf("Zero");
  else if(a<=b&&b<0){
    if((b-a+1)%2==0) printf("Positive");
    else printf("Negative");
  }
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin>>N;
    
    vector<int> p(N),q(N);
    for(int i=0;i<N;i++)cin>>p.at(i);
    for(int i=0;i<N;i++)cin>>q.at(i);
    int cnt=0;
    int a,b;
    vector<int> sam;
    for(int i=1;i<=N;i++)sam.push_back(i);
    do{
        cnt++;
        if(sam==p)a=cnt;
        if(sam==q)b=cnt;
    }while(next_permutation(sam.begin(),sam.end()));
        
    cout<<fabs(b-a)<<endl;



}



Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main ( void )
{
	int n;

	while ( cin >> n, n )
	{
		int A, B;
		A = B = 0;

		for (int i = 0, a, b; i < n; ++i)
		{
			cin >> a >> b;

			if ( a > b )
				A += a + b;
			else if ( a < b )
				B += a + b;
			else
			{
				A += a;
				B += b;
			}
		}

		cout << A << ' ' << B << endl;
	}

	return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
#define mod 1000000007
using namespace std;
long long f(long long num){
   if(num==2) return 3;
   return 1+2*f(num/2);
}

int main(void){
   long long H;
   cin>>H;
   long long ans=(long long)(pow(2,(int)log2(H)+1))-1;
   cout<<ans<<endl;
   return 0;
}

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

#define rep(i,n) for(ll i = 0; i < (n); i++)
#define rrep(i,n) for(ll i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(ll i = 1; i <= (n); i++)
#define rrep1(i,n) for(ll i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

int main(){
  ll n,m,k;cin>>n>>m>>k;
  vector<ll>a(n), b(m);
  rep(i, n)cin>>a[i];
  rep(i, m)cin>>b[i];

  rep(i, n-1)a[i+1]+=a[i];
  rep(i, m-1)b[i+1]+=b[i];

//for(auto c:a)cout<<c<<' ';cout<<endl;for(auto c:b)cout<<c<<' ';cout<<endl;cout<<endl;

  ll result=0;

  rep(i, n){
    ll lim = k-a[i];
    if(lim<0)continue;

    ll t=i+1;
    result = max<ll>(result, t);

    auto it = lower_bound(b.begin(), b.end(), lim);
    if(it==b.end())continue;

    ll diff = (ll)(it-b.begin())+1;
    if(*it>lim)diff--;
    diff=max<ll>(diff, 0);

    result = max<ll>(result, t+diff);
//  cout<<t<<' '<<diff<<' '<<lim<<endl;
  }

//cout<<"---"<<endl;

  rep(i, m){
    ll lim = k-b[i];
    if(lim<0)continue;

    ll t=i+1;
    result = max<ll>(result, t);

    auto it = lower_bound(a.begin(), a.end(), lim);
    if(it==a.end())continue;

    ll diff = (ll)(it-a.begin())+1;
    if(*it>lim)diff--;
    diff=max<ll>(diff, 0);

    result = max<ll>(result, t+diff);
//  cout<<t<<' '<<diff<<' '<<lim<<endl;
  }

  cout<<result<<endl;

  return 0;
}

Measured memory_bytes: 6408
from collections import defaultdict
import heapq
n,m,s,t=map(int, input().split())
s-=1
t-=1
yen={}
snk={}
adj=defaultdict(list)
for _ in range(m):
    u,v,a,b=map(int, input().split())
    u-=1    
    v-=1    
    adj[u].append(v)
    adj[v].append(u)
    yen[(u,v)]=a
    yen[(v,u)]=a
    snk[(u,v)]=b
    snk[(v,u)]=b

def dijkstra(s, t, cost):
    q=[]
    d=[float('inf')]*n
    d[s]=0
    heapq.heappush(q, (d[s], s))
    prev={}
    while q!=[]:
        du, u=heapq.heappop(q)
        for v in adj[u]:
            if d[v]>du+cost[(u,v)]:
                d[v]=du+cost[(u,v)]
                prev[v]=u
                
                heapq.heappush(q, (d[v], v))
    return d

d1=dijkstra(s, t, yen)
d2=dijkstra(t, s, snk)
snuke=[]
for d1i, d2i in zip(d1,d2):
    snuke.append(d1i+d2i)
ans=[]
mins=float('inf')
for si in reversed(snuke):
    if si<mins:
        ans.append(si)
        mins=si
    else:
        ans.append(mins)
ans.reverse()
for ai in ans:
    print(10**15-ai)


Measured memory_bytes: 105528
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <climits>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define ALL(A)		(A).begin(),(A).end()
#define DUMP(A)    cout<<#A<<"="<<(A)<< endl
#define SIZE(A)    (int)((A).size())
using namespace std;
typedef long long ll;

char ma[500][500];
int hist[500][500];

int main(){
    int H,W;
    for(;;){
        scanf("%d %d\n",&H,&W);
        if(H==0&&W==0) break;
        for(int i=0;i<H;i++){
            for(int j=0;j<W;j++){
                scanf("%c",&ma[i][j]);
            }
            scanf("\n");
        }
        for(int j=0;j<W;j++){
            int bef=0;
            for(int i=0;i<H;i++){
                if(ma[i][j]=='.') bef++;
                else bef=0;
                hist[i][j]=bef;
            }
        }
        int ret=0;
        for(int i=0;i<H;i++){
            stack<pair<int,int> > st;
            for(int j=0;j<W;j++){
                if(st.empty() || st.top().first< hist[i][j]){
                    st.push(make_pair(hist[i][j],j));
                }else if(st.top().first > hist[i][j]){
                    int lastpos;
                    while(!st.empty() && st.top().first > hist[i][j]){
                        ret=max(ret,st.top().first*(j-st.top().second));
                        lastpos=st.top().second;
                        st.pop();
                    }
                    if(st.empty() || st.top().first < hist[i][j]){
                        st.push(make_pair(hist[i][j],lastpos));
                    }
                }
            }
            while(!st.empty()){
                ret=max(ret,st.top().first*(W-st.top().second));
                st.pop();
            }
        }
        printf("%d\n",ret);
    }
}

Measured memory_bytes: 0
#include<stdio.h>
int main()
{
	int n;
	scanf("%d", &n);
	char s[102];
	scanf("%s", s);
	if (n % 2 == 1)
	{
		printf("No\n");
		return 0;
	}
	int i;
	for (i = 0; i < n / 2; i++)
	{
		if (s[i] != s[i + n / 2])
		{
			printf("No\n");
			return 0;
		}
	}
	printf("Yes\n");
	return 0;
}

Measured memory_bytes: 128
#include<iostream>

using namespace std;

int main() {
	int i, j, l, num[31], w, n, a=0, b=0, c;
	char kanma;
	
	cin >> w;
	for (i = 1; i <= w; i++) {
		num[i] = i;
	}
	cin >> n;
	for (i = 0; i < n; i++) {
		cin >> a >> kanma >> b;
		c = num[a];
		num[a] = num[b];
		num[b] = c;
	}
	for (i = 1; i <= w; i++) {
		cout << num[i] << endl;
	}
	return 0;
}

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

const int N = 1000010;
bool dp[N];

int main() {
  for (int i = 0; i < N; ++i) {
    dp[i] = true;
  }

  int n;
  cin >> n;
  set<int> a;
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    if (a.find(x) != a.end()) {
      dp[x] = false;
      continue;
    }
    a.insert(x);
    int num = 2 * x;
    while (N > num) {
      dp[num] = false;
      num += x;
    }
  }

  int ans = 0;
  for (const auto& e : a) {
    if (dp[e]) {
      ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 13944
#include <stdio.h>

int main()
{
	int min, max, test, ctr = 0;
	scanf("%d %d %d", &min, &max, &test);
	for(int i = min; i <= max; i++)
	{
		if(i % test == 0)
		{
			ctr++;
		}
	}
	printf("%d", ctr);
	
	
	
	
	return 0;
}

Measured memory_bytes: 1704
from fractions import gcd
n,m = map(int,input().split())
lis = list(map(int,input().split()))
devide = set()
for num in lis:
    cnt = 0
    b = num
    while b % 2 == 0:
        b /= 2
        cnt += 1
    devide.add(cnt)
if len(devide) != 1:
    print(0)
    exit()
ansnum = lis[0]//2
for i in range(1,n):
    lis[i] = lis[i]//2
    ansnum = (ansnum * lis[i])//gcd(ansnum,lis[i])
print(m//(ansnum)-m//(ansnum*2))

Measured memory_bytes: 16296
def xor(a, b):
  return a^b
from functools import reduce
flag = False

a, b = map(int, input().split())
if b - a < 100:
  print(reduce(xor, [i for i in range(a, b+1)]))
else:
  l = []
  for i in range(a, b):
    if i % 4 != 0:
      l.append(i)
    else:
      break
  for i in range(b, a, -1):
    if i % 4 != 0:
      l.append(i)
    else:
      l.append(i)
      break
  print(reduce(xor, l))

Measured memory_bytes: 3572
#include <bits/stdc++.h>
#define FOR(I,X,Y) for(int (I)=(X);(I)<(Y);(I)++)
#define REP(I,X,Y) for(int (I)=(Y)-1;(I)>=(X);(I)--)
#define ALL(X) (X).begin(),(X).end()
#define INF 1000000007
#define LINF 1000000000000000007
typedef long long ll;
using namespace std;

int main(){
  int N,T,A,minA=INF,maxd=0;
  cin >> N >> T;
  vector<pair<int,int>> vq,v;//:= 町iで売るときの、買う金額、売る金額
  FOR(i,0,N){
    cin >> A;
    minA = min(minA,A);
    vq.push_back(make_pair(minA,A));
    maxd = max(maxd,A-minA);
  }
  for(auto x:vq)if(x.second - x.first == maxd)v.push_back(x);
  cout << v.size() << endl;
}


Measured memory_bytes: 1908
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,m,c,i,j,a,sum=0,ans=0;
  	cin>>n>>m>>c;
  	vector<int> b(m);
  	for(i=0;i<m;i++){
      cin>>b[i];
    }
	for(i=0;i<n;i++){
      sum=0;
      for(j=0;j<m;j++){
        cin>>a;
        sum+=a*b[j];
      }
      if(sum+c>0){
        ans++;
      }
    }
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                    \
  ifstream in("abc179/abc179_d.txt"); \
  cin.rdbuf(in.rdbuf());
#define print_vec(v)                        \
  rep(l, v.size()) { cout << v[l] << " "; } \
  cout << endl;
#else
#define INPUT_FILE
#define print_vec(v)
#endif
#define CIN_OPTIMIZE \
  cin.tie(0);        \
  ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
typedef pair<ll, ll> pl;
const int INF = 100100100;
const ll LINF = 1e18 + 100;
const int MOD = 1e9 + 7;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
// const int mod = 1000000007;
const int mod = 998244353;
struct mint {
  ll x;  // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const { return mint(*this) += a; }
  mint operator-(const mint a) const { return mint(*this) -= a; }
  mint operator*(const mint a) const { return mint(*this) *= a; }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod - 2); }
  mint& operator/=(const mint a) { return *this *= a.inv(); }
  mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream& is, mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }

int main() {
  INPUT_FILE CIN_OPTIMIZE;

  int N, K;
  cin >> N >> K;

  vector<P> c(K);
  rep(i, K) {
    int l, r;
    cin >> l >> r;
    c[i] = {l, r + 1};
  }

  mint ans = 0;
  vector<mint> dp(N + 1, 0);
  dp[0] = 1;
  dp[1] = -1;
  rep(i, N) {
    if (i > 0) dp[i] += dp[i - 1];
    rep(j, K) {
      auto [l, r] = c[j];
      if (i + l < N) dp[i + l] += dp[i];
      if (i + r < N) dp[i + r] -= dp[i];
    }
  }
  cout << dp[N - 1] << endl;
}

Measured memory_bytes: 4724
#include<bits/stdc++.h>
using namespace std;
typedef long long int LL;
typedef vector<int> VI;
typedef VI::iterator VII;

int h, w, n;
bool bfield[1010][1010];
int dp[1010][1010];

int main()
{
  while(true){
    scanf("%d%d%d", &h, &w, &n);
    if(!h && !w && !n)
      break;

    memset(dp, 0, sizeof dp);

    for(int i = 1; i <= h; i++)
      for(int j = 1; j <= w; j++)
	scanf("%d", &bfield[i][j]);
    
    dp[1][1] = n - 1;
    for(int i = 1; i <= h; i++)
      for(int j = 1; j <= w; j++){
	if(!(dp[i][j] & 1)){
	  dp[i][j + 1] += dp[i][j] / 2;
	  dp[i + 1][j] += dp[i][j] / 2;
	}
	else{
	  dp[i][j + 1] += dp[i][j] / 2 + bfield[i][j];
	  dp[i + 1][j] += dp[i][j] / 2 + !bfield[i][j];
	  bfield[i][j] = !bfield[i][j];
	}
      }
    
    int i = 1, j = 1;
    while(i <= h && j <= w){
      if(bfield[i][j])
	j++;
      else
	i++;
    }
    
    if(i > h)
      printf("%d %d\n", h + 1, j);
    else
      printf("%d %d\n", i, w + 1);
  }
  return 0;
}

Measured memory_bytes: 6172
N,M = [int(i) for i in input().split()]
student_location = []
for i in range(N) :
    student_location.append([int(i) for i in input().split()])

checkpoint_location = []
for i in range(M) :
    checkpoint_location.append([int(i) for i in input().split()])

for student_loc in student_location :
    min_distance = 9999999999
    min_distance_index = -1
    index = 0
    for checkpoint_loc in checkpoint_location :
        index += 1
        d = abs(student_loc[0] - checkpoint_loc[0]) + abs(student_loc[1] - checkpoint_loc[1])
        if (d < min_distance) :
            min_distance = d
            min_distance_index = index
    # print([d,index])
    print(min_distance_index)


Measured memory_bytes: 3064
n = gets.to_i
a = gets.split.map(&:to_i)
b = gets.split.map(&:to_i)
c = gets.split.map(&:to_i)
ans = 0
pre = 100000
a.each do |dish|
  ans += b[dish - 1]
  ans += c[dish - 2] if dish == pre + 1
  pre = dish
end
puts ans

Measured memory_bytes: 1788
#include <iostream>
using namespace std;
int main()
{
   int N;
   cin >> N;
   char A[N], B[N], C[N];
   cin >> A;
   cin >> B;
   cin >> C;
   int max_cnt_change = 0;
   for(int i=0; i<N; i++)
   {
      if(A[i] != B[i] and B[i] != C[i] and C[i] != A[i]){max_cnt_change +=2;}
      else if(((A[i] != B[i]) and (B[i] != C[i])) ||((B[i] != C[i]) and (C[i] != A[i]))||((C[i] != A[i]) and (A[i] != B[i])))
      {max_cnt_change+=1;}
      else if((A[i] != B[i])or(B[i] != C[i])or(C[i] != A[i])){max_cnt_change++;}
   }
   if(max_cnt_change < 0){max_cnt_change = 0;}
   cout << max_cnt_change << endl;
   return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <queue>
using namespace std;
struct side{
    int to;
    int cost;
};
struct walk{
    int now;
    int cost;
};
int main(){
    int n,l,m,d[10000];
    queue<walk> q;
    vector<side> map[10000];
    walk temp,t;
    side s;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d%d",&l,&m);
        d[i]=-1;
        for(int j=0;j<m;j++){
            scanf("%d%d",&s.to,&s.cost);
            map[l].push_back(s);
        }
    }
    temp.now=temp.cost=0;
    q.push(temp);
    while(!q.empty()){
        temp=q.front();
        q.pop();
        if(d[temp.now]!=-1&&d[temp.now]<=temp.cost)continue;
        d[temp.now]=temp.cost;
        for(int i=0;i<map[temp.now].size();i++){
            t.cost=temp.cost+map[temp.now][i].cost;
            t.now=map[temp.now][i].to;
            q.push(t);
        }
    }
    for(int i=0;i<n;i++){
        printf("%d %d\n",i,d[i]);
    }
}

Measured memory_bytes: 29252
S = list(input())
T = list(input())
NS = len(S)
NT = len(T)
cnt = NS
for i in range(0,NS-NT+1):
    tmp = 0
    for j in range(NT):
        if S[i+j]!=T[j]:
            tmp+=1
    cnt = min(tmp,cnt)
print(cnt)


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

#define _p(...) (void)printf(__VA_ARGS__)
#define forr(x,arr) for(auto&& x:arr)
#define _overload3(_1,_2,_3,name,...) name
#define _rep2(i,n) _rep3(i,0,n)
#define _rep3(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2,)(__VA_ARGS__)
#define _rrep2(i,n) _rrep3(i,0,n)
#define _rrep3(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define bit(n) (1LL<<(n))
#define sz(x) ((int)(x).size())
#define ten(n) ((int)1e##n)
#define fst first
#define snd second
using ll=long long;
using pii=pair<int,int>;using pll=pair<ll,ll>;using pil=pair<int,ll>;using pli=pair<ll,int>;
using vs=vector<string>;using vvs=vector<vs>;using vvvs=vector<vvs>;
using vb=vector<bool>;using vvb=vector<vb>;using vvvb=vector<vvb>;
using vi=vector<int>;using vvi=vector<vi>;using vvvi=vector<vvi>;
using vl=vector<ll>;using vvl=vector<vl>;using vvvl=vector<vvl>;
using vd=vector<double>;using vvd=vector<vd>;using vvvd=vector<vvd>;
using vpii=vector<pii>;using vvpii=vector<vpii>;using vvvpii=vector<vvpii>;
template<class T> bool amax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> bool amin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
ll ri(){ll l;cin>>l;return l;} string rs(){string s;cin>>s;return s;}
template<class T>T read(){T t;cin>>t;return t;}
template<class T,class U>ostream&operator<<(ostream&o,const pair<T,U>&p){return o<<'('<<p.fst<<", "<<p.snd<<')';}
ostream&operator<<(ostream&o,const vb&t){forr(e,t)o<<"#."[e];return o;}
template<class T>ostream&operator<<(ostream&o,const vector<T>&t){o<<"{";forr(e,t)o<<e<<",";o<<"}"<<endl;return o;}
#ifdef LOCAL
vs s_p_l_i_t(const string&s,char c){vs v;stringstream ss(s);string x;while(getline(ss,x,c))v.emplace_back(x);return move(v);}
void e_r_r(vs::iterator it){cerr<<endl;}
template<class T,class... Args>void e_r_r(vs::iterator it,T a,Args... args){cerr<<it->substr((*it)[0]==' ',it->length())<<" = "<<a<<", ";e_r_r(++it,args...);}
#define out(args...){vs a_r_g_s=s_p_l_i_t(#args,',');e_r_r(a_r_g_s.begin(),args);}
#else
#define out(args...)
#endif

void Main() {
  int a = ri();
  int b = ri();
  cout << (a + b ) % 24 << endl;
}
int main() { cin.tie(nullptr); ios::sync_with_stdio(false); Main(); return 0; }


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rep1(i, n) for(int i=1; i<=n; i++)
#define rrep(i, n) for(int i=n-1; i>=0; i--)
#define rrep1(i, n) for(int i=n; i>=1; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const int MAX = 200010;
ll fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}

ll comb(int n, int k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    ll n, m, k;
    cin >> n >> m >> k;

    COMinit();

    ll t = comb(n*m-2, k-2);

    ll tx = 0, ty = 0;
    for (int i = 1; i < m; i++) {
        tx += i * (m-i) * n * n;
        tx %= MOD;
    }
    tx *= t;
    tx %= MOD;

    for (int i = 1; i < n; i++) {
        ty += i * (n-i) * m * m;
        ty %= MOD;
    }
    ty *= t;
    ty %= MOD;

    ll ans = (tx + ty) % MOD;
    cout << ans << endl;
}


Measured memory_bytes: 4992
#include <stdio.h>
#include <string>
#include <iostream>
#include <iomanip>
#include <map>
#include <algorithm>
#include <vector>
#include <math.h>
#define MOD 1000000007
using namespace std;

int main(void){
    int a,b,k;
    cin >> a >> b >> k;
    int count=0;
    for(int i=max(a,b); i>=0; i--){
        if(a%i==0 && b%i==0)count++;
        if(count==k){
            cout << i << endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<queue>
#include<map>
#include<unordered_map>

using namespace std;

int main(){
    char a;
    cin >> a;
    if('A'<= a && a<='Z'){
        cout << "A" << endl;
     }else{
         cout << "a" << endl;
     }

    return 0;

}

Measured memory_bytes: 3064
#include <stdio.h>

using namespace std;

int main()
{
    int n;
    scanf("%d",&n);
    int a=n%100;
    int b=n/100;
    int k=0;
    if(1<=a&&a<=12)
    {
    k+=1;
    }
    if(1<=b&&b<=12)
     {
         k+=2;
     }
    if(k==3)
        printf("AMBIGUOUS");
    else if(k==1)
        printf("YYMM");
    else if(k==2)
        printf("MMYY");
    else if(k==0)
        printf("NA");
    return 0;
}

Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;

namespace ABC145A
{
    class Program
    {
        static void Main(string[] args)
        {
            var v = Cin.Long();
            var solver = new Solver(v);

            Console.WriteLine(solver.Solve());
        }
    }

    class Solver
    {
        private long R;
        public Solver(long r)
        {
            R = r;
        }

        public IConvertible Solve()
        {
            return R * R;
        }
    }

    internal static class Cin
    {
        public static string String()
        {
            return Console.ReadLine();
        }

        public static int Int()
        {
            return int.Parse(String());
        }

        public static int[] IArr()
        {
            return Split().Select(int.Parse).ToArray();
        }

        public static long Long()
        {
            return long.Parse(String());
        }

        public static long[] LArr()
        {
            return Split().Select(long.Parse).ToArray();
        }

        public static double Double()
        {
            return double.Parse(String());
        }

        public static double[] DArr()
        {
            return Split().Select(double.Parse).ToArray();
        }

        private static IEnumerable<String> Split()
        {
            return String().Split(' ');
        }
    }
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int x, y;
  cin >> x >> y;
  if(y > 4*x) {
    cout << "No" << endl;
  } else if(y < 2*x) {
    cout << "No" << endl;
  } else {
    if(y%2 == 0) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }
    
}

Measured memory_bytes: 3636
#include<iostream>
#include<algorithm>
#include<vector>
#include<stdio.h>
#include<cstring>
#include<math.h>
#include<map>
#include<bitset>
using namespace std;

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

int n, q;
long long S[100000], T[50000];

int binary_search(long long key) {
    int r = n;
    int l = -1;
    while(r - l > 1) {
      int half = (r + l) / 2;
      if(key <= S[half]) r = half;
      else l = half;
    }
    return r;
}

int main() {
  cin >> n;
  rep(i, n) {
    cin >> S[i];
  }
  cin >> q;
  rep(i, q) {
    cin >> T[i];
  }

  long long count = 0;

  for(int i = 0; i < q; i++) {
    int half = binary_search(T[i]);
    if(S[half] == T[i]) count++;
  }

  cout << count << endl;

  return 0;
}


Measured memory_bytes: 4232
import java.util.*;

public class Main{

	public static void main(String[] args){

		Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        char[][] nn = new char[n][n];
        char[][] mm = new char[m][m];
       
        for(int i = 0; i < n; i++){
          String next = sc.next();
          char[] Next = next.toCharArray();
          for(int j = 0; j < n; j++){
            nn[i][j] = Next[j];
          }
        }
      
        for(int i = 0; i < m; i++){
          String next = sc.next();
          char[] Next = next.toCharArray();
          for(int j = 0; j < m; j++){
            mm[i][j] = Next[j];
          }
        }

      
       boolean ex = false; 
       
       for(int i = 0; i < n-m+1; ++i){
         for(int j = 0; j < n-m+1; ++j){
             boolean match  = false;
             int tcount = 0;
             for(int l = 0; l < m; ++l){
               for(int k = 0; k < m; ++k){
                 if(nn[i+l][j+k] == mm[l][k]){
                   match = true;
                   tcount++;
                 }
               }
               if(match == true && tcount ==m*m){
                 ex = true;
              }
               
             
           }
           
         }
       }
      
       if(ex == true){
         System.out.println("Yes");
       }else{
          System.out.println("No");
       }

	}
}

Measured memory_bytes: 35932
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
#define pi pair<int,int>
#define pl pair<long long,long long>
#define rd(x) cin >> x;
#define rda(a,n) for(int i=1;i<=n;i++) cin >> a[i];
#define wr(x) cout << x << ' ';
#define wrl(x) cout << x << '\n';
#define wra(a,n) for(int i=1;i<=n;i++) cout << a[i] << ' '; cout << '\n';
#define lg length()
#define pb(x) push_back(x)
ifstream in("file.in");
ofstream out("file.out");
#define MAXN 100005
#define INF 1000000005
#define LINF 1000000000000000005
struct comp{
    bool operator()(long long a, long long b){
        return a>b;
    }
};

bool comp(pair<long long,long long> a, pair<long long,long long> b){
    if(a.first==b.first) return a.second<b.second;
    return a.first<b.first;
}

long long n,s,t,bit[200005],k;
pair<long long,long long> p[200005];

void Upd(int nod){
    while(nod<=n+1){
        bit[nod]+=1;
        nod+=(nod&-nod);
    }
}

int Qry(int nod){
    int ans=0;
    while(nod){
        ans+=bit[nod];
        nod-=(nod&-nod);
    }
    return ans;
}

int main(){
    ios_base :: sync_with_stdio(0);
    cin >> n >> k;
    for(int i=1;i<=n;i++){
        cin >> t;
        s+=t;
        p[i]={s-k*i,i+1};
    }
    p[0]={0,1};
    t=0;
    sort(p,p+n+1,comp);
    for(int i=0;i<=n;i++){
        //  cout << p[i].first << ' ' << p[i].second << '\n';
        t+=Qry(p[i].second);
        Upd(p[i].second);
    }
    cout << t;
}


Measured memory_bytes: 4992
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int N, M, l[200005], r[200005];
long long int a[200005];

long long int st[2000000], val[2000000];

int num=1<<18;

void UPDATE(int k, long long int b) {

	int pos = k + num-1;

	st[pos] = b;

	while (pos > 0) {
		pos =pos/ 2;
		st[pos] = max(st[pos * 2], st[pos * 2 + 1]);
	}
}

long long int INF = 9999999999999999;

void EVAL(int k, int l, int r) {

	st[k] += val[k];

	if (r > l) {
		val[k * 2] += val[k];
		val[k * 2 + 1] += val[k];
	}

	val[k] = 0;
}

long long int Q(int k, int l, int r, int a, int b) {

	EVAL(k, l, r);

	if (b < l || r < a) { return -INF; }

	if (a <= l && r <= b) { return st[k]; }
	
	
		long long int ret;
		ret = max( Q(2 * k , l, (l + r) / 2, a, b), Q(2 * k + 1, (l + r) / 2+1, r, a, b));
		st[k] = ret;
		return ret;

}

void ADD(int k, int l, int r, int a, int b, long long int W) {

	EVAL(k, l, r);

	if (b < l || r < a) { return; }

	if (a <= l && r <= b) { 
		val[k] += W;     EVAL(k, l, r); 
	}
	else {
		 ADD(k * 2 , l, (l + r) / 2, a, b, W); 
		 ADD(k * 2 + 1, (l + r) / 2 + 1, r, a, b, W); 
		 st[k] = max(st[k * 2], st[k * 2 + 1]);
		// cout << " add " << k <<" st= " <<st[k]<< endl;
	}

}

vector<pair<pair<int, int>, long long int> > V;


int main(void) {

	cin >> N >> M;

	/*num = 1;
	while (num <= N) { num *= 2; }
	*/

	for (int i = 1; i <= M; i++) {
		cin >> l[i] >> r[i] >> a[i];
		V.push_back(make_pair(make_pair(r[i], l[i]),a[i]));
	}
	V.push_back(make_pair(make_pair(2222222, 2222222), 999999999));

	//Q(1,1,num, l[i], r[i]) 
	//ADD(1,1,num,l[i],r[i],W);

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

	/*for (int i = 1; i <= N; i++) {
		UPDATE(i, 0);
	}*/

	int p = 0;
	for (int i = 1; i <= N; i++) {
		long long int tmp = Q(1, 1, num, 1, i - 1);
		tmp = max((long long int) 0, tmp);
		//UPDATE(i,max(Q(1,1,num,i,i),Q(1, 1, num, 1, i - 1)));
		ADD(1, 1, num, i, i, tmp);
		while (V[p].first.first == i) {
			ADD(1, 1, num, V[p].first.second, V[p].first.first, V[p].second);
			p++;
		}
	}

	/*for (int i = 1; i <= N; i++) {
		cout << "dp[" << i << "]= " << Q(1,1,num,i,i) << endl;
	}*/

	/*for (int i = 1; i <= num*2; i++) {
		
		cout <<"st["<<i<<"]= "<<st[i]<<"   val[" <<i<<"]= "<< val[i] << endl;
		
	}*/
	
	cout << max((long long int) 0,Q(1, 1, num, 1, N)) << endl;

	return 0;
}

Measured memory_bytes: 17772
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <complex>
#include <tuple>

#define FAST ios_base::sync_with_stdio(false); cin.tie(0)
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
// #define repr(i, a, b) for(int i=int(a); i>=int(b); i--)
#define reps(i,n) for(int i=1;i<=int(n);++i)
#define repr(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define reprs(i,x) for(int i=((int)(x));i>0;i--)
#define iceil(x,y) (x+y-1)/y
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define all(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define LF "\n"

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

using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef pair<int, PII> PP;


int main(){
	FAST;
	int n;
	cin >> n;
	reps(i,9) {
		reps(j,9) {
			if (i*j == n) {	
				cout << "Yes\n";
				return 0;
			}
		}
	}

	cout << "No\n";
 
	return 0;
}

Measured memory_bytes: 256
N,A,B=gets.split.map(&:to_i)
S=gets.chomp

a=0
b=0
S.each_char do |c|
    if a+b < A+B
        if c == 'a'
            a += 1
            puts 'Yes'
        elsif c == 'b' && b < B
            b += 1
            puts 'Yes'
        else
            puts 'No'
        end
    else
        puts 'No'
    end
end


Measured memory_bytes: 2300
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
using namespace std; //std::の省略のため
using ll = long long;

int main()
{
  int num[3];

  for (int i = 0; i < 3; i++)
    cin >> num[i];

  int cnt7 = 0, cnt5 = 0;

  for (int i = 0; i < 3; i++)
  {
    if (num[i] == 7)
      cnt7++;
    else if (num[i] == 5)
      cnt5++;
  }

  if (cnt7 == 1 && cnt5 == 2)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}


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

struct UnionFind {
  vector< int > data;
 
  UnionFind(int sz) {
    data.assign(sz, -1);
  }
 
  bool unite(int x, int y) {
    x = find(x), y = find(y);
    if(x == y) return (false);
    if(data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return (true);
  }
 
  int find(int k) {
    if(data[k] < 0) return (k);
    return (data[k] = find(data[k]));
  }
 
  int size(int k) {
    return (-data[find(k)]);
  }
};

int main()
{
	int N, M;
	cin >> N >> M;
	UnionFind uf( N );
	for( int i = 0; i < M; i++ ) {
		int A, B;
		cin >> A >> B;
		A--;
		B--;
		uf.unite( A, B);
	}

	set<int> st;
	for( int i = 0; i < N; i++ ) {
		int p = uf.find( i );
		st.insert( p );
	}
	int ans = st.size() - 1;

	cout << ans << endl;
}


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

int main(){
                                                                     

    long long d, n, x;

    
    cin >> d >> n;


    if( d == 0 ){

        if( n < 100 ) x = n;

        else if( n == 100 ) x = 101;

        }

    else if( d == 1 ){

             if( n < 100 ) x = 100 * n ;

             else if( n == 100 ) x = 100 * 101;

             }

    else if( d == 2 ){

             if( n < 100 ) x = 100 * 100 * n ;

             else if( n == 100 ) x = 100 * 100 * 101;

             }


    cout << x << endl;

    return 0;

    }

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

using namespace std;

int main()
{
    int n,m,i,j;
    long long int total=0,sum=1;
    cin>>n>>m;
    if(n>1)
    total+=n*(n-1)/2;
    if(m>1)
    total+=m*(m-1)/2;
    
    cout<<total;
}

Measured memory_bytes: 256
import numpy as np

a, b, h, m = map(int, input().split())
hour_deg = np.pi * ((h + m / 60) / 6)
min_deg = np.pi * (m / 30)
print(np.sqrt((a * np.cos(hour_deg) - b * np.cos(min_deg)) ** 2 + (a * np.sin(hour_deg) - b * np.sin(min_deg)) ** 2))


Measured memory_bytes: 27200
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
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 (b<a) { a=b; return 1; } return 0; }

int main(){
    ll n,k;
    cin>>n>>k;
    ll ans=k;
    for(int i=1;i<n;i++){
        ans*=k-1;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double lld;
ll MOD = (1e9)+7;
const int dr[] = {+1, -1, +0, +0, +1, -1, +1, -1};
const int dc[] = {+0, +0, +1, -1, +1, -1, -1, +1};
const int kx[] = {+1, +2, -1, -2, +1, +2, -1, -2};
const int ky[] = {+2, +1, +2, +1, -2, -1, -2, -1};
//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")
inline void fastIO(){
  ios_base::sync_with_stdio(0);cin.tie(0);
}
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename T, size_t size> ostream& operator<<(ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }

void debug_out() { cerr << endl; }
template<typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << ' ' << H; debug_out(T...); }

#ifdef LOCAL
#define debug(...) cerr << "(" << #__VA_ARGS__ << "):", debug_out(__VA_ARGS__)
#else
#define debug(...) 47
#endif

int main(){
  fastIO();
  int ans=0;
  string s,t;
  cin>>s>>t;
  for(int i=0;i<s.length();i++){
    if(s[i]!=t[i])ans++;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3696
#include <bits/stdc++.h>
using namespace std;
int read(){
	int sum=0,f=1;
	char s=getchar();
	while (s<'0' or s>'9'){
		if (s=='-')f=-1;
		s=getchar();
	}
	while (s>='0' and s<='9'){
		sum=sum*10+s-'0';
		s=getchar();
	}
	return sum*f;
}
int n;
int main(){
	n=read();
	if (n>=30)cout<<"Yes"<<endl;
	else cout<<"No\n";
	
	return 0;
}



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

using std::pair;
using std::vector;
using std::string;

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

#define fst first
#define snd second
#define pb(a) push_back(a)
#define mp(a, b) std::make_pair(a, b)
#define debug(...) fprintf(stderr, __VA_ARGS__)

template <typename T> bool chkmax(T& a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> bool chkmin(T& a, T b) { return a > b ? a = b, 1 : 0; }

const int oo = 0x3f3f3f3f;

string procStatus() {
    std::ifstream t("/proc/self/status");
    return string(std::istreambuf_iterator<char>(t), std::istreambuf_iterator<char>());
}

template <typename T> T read(T& x) {
    int f = 1; x = 0;
    char ch = getchar();
    for(;!isdigit(ch); ch = getchar()) if(ch == '-') f = -1;
    for(; isdigit(ch); ch = getchar()) x = x * 10 + ch - 48;
    return x *= f;
}

const int N = 300000;

int n;
int p[N + 5];
int pre[N + 5], suf[N + 5];

int main() {
#ifdef Wearry
    freopen("in", "r", stdin);
    freopen("out", "w", stdout);
#endif

    read(n);
    for(int i = 1; i <= n; ++i) read(p[i]);

    pre[0] = 0, suf[n+1] = oo;
    for(int i = 1; i <= n; ++i) pre[i] = std::max(pre[i-1], p[i]);
    for(int i = n; i >= 1; --i) suf[i] = std::min(suf[i+1], p[i]);

    for(int i = 1; i <= n; ++i) {
        if((p[i] ^ i) & 1) return puts("No"), 0; 
        if(i < n && (p[i] == i) == (p[i+1] == i+1) && pre[i] != i) return puts("No"), 0;
        if(i > 1 && i < n && p[i] != i && pre[i-1] > p[i] && suf[i+1] < p[i]) return puts("No"), 0;
    }
    puts("Yes");

    return 0;
}


Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n; cin >> n;
	map<int,int> p;
	for(int i = 2; i <= n; i++){
		int k = i;
		for(int j = 2; j*j <= k; j++){
			if(k % j == 0){
				int c = 0;
				while(k % j == 0) k /= j, c++;
				p[j] += c;
			}
		}
		if(k != 1) p[k] += 1;
	}
	int ans = 1;
	for(auto e : p) ans = 1ll * ans * (e.second + 1) % 1000000007;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
//By Don4ick 
//#define _GLIBCXX_DEBUG

#include <bits/stdc++.h>

typedef long long ll;
typedef long double ld;
typedef unsigned int ui;

#define forn(i, n) for (int i = 1; i <= n; i++)
#define pb push_back
#define all(x) x.begin(), x.end()
#define y1 qewr1234

const double PI = acos(-1.0);
const int DIR = 4;
const int X[] = {1, 0, -1, 0};
const int Y[] = {0, 1, 0, -1};

using namespace std;

int main()
{
	//ios_base::sync_with_stdio(false);
	//cin.tie();
	//cout.tie();		

	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);

	//~read
	int n, m;
	cin >> n >> m;
	vector < int > a(m);
	for (int i = 0; i < m; i++)
	{	
		cin >> a[i];
	}
	//~solve
	if (m == 1)
	{	
		for (int i = 0; i < m; i++)
			cout << a[i] << ' ';
		cout << endl;
		if (a[0] == 1)
			cout << 1 << endl << 1 << endl;
		else
			cout << 2 << endl << a[0] - 1 <<  ' ' << 1 << endl;
		return 0;
	}
	int cnt = 0;
	for (int i = 0; i < m; i++)
	{
		cnt += (a[i] & 1);
	}
	if (cnt > 2)
	{
		cout << "Impossible" << endl;
		return 0;
	}
	for (int i = 1; i < m - 1; i++)
	{
		if (a[i] & 1)
		{
			if (a[0] & 1)
				swap(a[m - 1], a[i]);
			else
				swap(a[0], a[i]);
		}
	}
	vector < int > b;
	b.pb(a[0] + 1);
	for (int i = 1; i < m - 1; i++)
		b.pb(a[i]);
	if (a[m - 1] != 1)
		b.pb(a[m - 1] - 1);
	//~result
	for (int i = 0; i < m; i++)
		cout << a[i] << ' ';
	cout << endl;
	cout << (int)b.size() << endl;
	for (int i = 0; i < (int)b.size(); i++)
		cout << b[i] << ' ';
	cout << endl;	

	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>

#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define all(v) (v).begin(), (v).end()
#define rev(s) (s).rbegin(), (s).rend()
#define MP make_pair
#define X first
#define Y second
#define debug(x) cout << #x << " = " << x << endl;

using namespace std;

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

const int FIELD_SIZE = 10000;

const int coin[] = {500, 100, 50, 10, 5, 1};

int retcnt(int val){
	int cnt = 0;
	rep(i, 6){
		cnt += val/coin[i];
		val %= coin[i];
	}
	return cnt;
}

int usecnt(int val, vi a){
	int cnt = 0;
	rep(i, 6){
		while(val >= coin[i] && a[i]){
			cnt++;
			val-=coin[i];
			a[i]--;
		}
	}
	if(val != 0) return 1<<20;

	return cnt;
}

int main(){
	int p;
	while(cin >> p, p){
		vi a(6);
		rep(i, 6) cin >> a[i];
		a = vi(rev(a));
		
		int ans = 1<<20;
		for(int i = p; i < p+500; i++){
			ans = min(ans, usecnt(i, a)+retcnt(i-p));
		}
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 1216
#include"bits/stdc++.h"
using namespace std;
using ll=long long;
template<typename T=ll>inline T in(istream&is=cin){T ret;is>>ret;return ret;}
template<typename T>inline auto vec2(typename vector<T>::size_type h,typename vector<T>::size_type w,T v=T()){return vector<vector<T>>(h,vector<T>(w,v));}

int main()
{
    struct apple{ll d,c;};
    ll x=in(),y=in(),a=in(),b=in(),c=in();
    vector<apple>v(a+b+c);
    for(ll i=0;i<a;++i)v[i]={in(),0ll};
    for(ll i=0;i<b;++i)v[i+a]={in(),1ll};
    for(ll i=0;i<c;++i)v[i+a+b]={in(),2ll};
    sort(v.begin(),v.end(),[](const apple&a1,const apple&a2){return a1.d>a2.d||a1.d==a2.d&&a1.c==2ll&&a2.c!=2ll;});
    ll r=0,g=0,n=0,ans=0;
    for(ll i=0;i<v.size();++i){
        if(v[i].c==0){
            if(r<x){
                ans+=v[i].d;
                ++r;
            }
        }else if(v[i].c==1){
            if(g<y){
                ans+=v[i].d;
                ++g;
            }
        }else{
            if(n<x-r+y-g){
                ans+=v[i].d;
                ++n;
            }
        }
        if(r+g+n==x+y)break;
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 4992
from collections import deque
h,w=map(int,input().split())
l=[list(input()) for i in range(h)]

ll=[[-1 for i in range(w)] for j in range(h)]
ld=deque()

ld.append([0,0])
ll[0][0]=0
while len(ld)!=0:
    k=ld.popleft()
    y=k[0]
    x=k[1]
    p=ll[y][x]
    if 0<=y+1<h and 0<=x<w and ll[y+1][x]==-1 and l[y+1][x]!="#":
        ld.append([y+1,x])
        ll[y+1][x]=p+1
    if 0<=y-1<h and 0<=x<w and ll[y-1][x]==-1 and l[y-1][x]!="#":
        ld.append([y-1,x])
        ll[y-1][x]=p+1
    if 0<=y<h and 0<=x+1<w and ll[y][x+1]==-1 and l[y][x+1]!="#":
        ld.append([y,x+1])
        ll[y][x+1]=p+1
    if 0<=y<h and 0<=x-1<w and ll[y][x-1]==-1 and l[y][x-1]!="#":
        ld.append([y,x-1])
        ll[y][x-1]=p+1
        
s=0
if ll[h-1][w-1]==-1:
    print(-1)
else:
    for i in range(h):
        s+=l[i].count("#")
    print(h*w-s-ll[h-1][w-1]-1)


Measured memory_bytes: 3316
#include <iostream>
#include <vector>
#include<list>
#include <algorithm>
#include <string>
#include <math.h>
#include<map>
#include <utility>

#include<queue>
using namespace std;
#define REP(i,k,n) for(int i=k;i<n;i++)
 
#define INF 1844674407370955161
typedef long long int ll;
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
#define MOD 1000000007

template<typename T>
std::vector<T> enum_div(T n)//nの約数を列挙
{
	std::vector<T> ret;
	for(T i=1 ; i*i<=n ; ++i)
	{
		if(n%i == 0)
		{
			ret.push_back(i);
			if(i!=1 && i*i!=n)
			{
				ret.push_back(n/i);
			}
		}
	}
	return ret;
}





int main()
{
	string s, t;
	cin >> s >> t;
	int Ns = s.size();
	int Nt = t.size();

	int dic[26];
	vector<int> di[26];
	if(Ns==1&&Nt==1){
		if(s==t){
			cout << 1 << endl;
			
		}else{
			cout << -1 << endl;
		}
		return 0;
	}

	REP(i,0,26){
		dic[i] = 0;
	}
	REP(i, 0, Ns)
	{
		dic[s[i] - 'a']++;
		di[s[i] - 'a'].push_back(i);
	}
	bool flag = true;
	ll ans = 0;
	ll c = 1;
	int prev = 0;
	REP(i, 0, Nt)
	{
		if(dic[t[i]-'a']==0){
			cout << -1 << endl;
			return 0;
		}
	}
	int il;
	REP(i, 0, Nt)
	{
		int search = t[i] - 'a';
		auto it = lower_bound(di[search].begin(), di[search].end(), prev);

		if(it!=di[search].end()){
			prev = (int)*it+1;
			il = *it;
		}
		else
		{
			c++;
			prev = di[search][0];
			il = prev;
			prev++;
		}

		//cout << c << endl;

	}
	//cout << c << endl;
	
	cout << (c - 1) * Ns + il+1 << endl;

	return 0;
}

Measured memory_bytes: 1216
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int,int>;

vector<int>bitSearch(int bit,int n){
    vector<int>S;
    rep(i,n)if(bit&(1<<i))S.push_back(i);
    return S;
}



int main(){
   int n, k;
   cin >> n >> k;

   ll res = 0;
   if(k == 0){
       cout << (ll) n * n << endl;
       return 0;
   }
   int cnt = 1;
   REP(i, k+1, n){
       res += n / i * cnt;
       res += max(0, n % i - k + 1);
       cnt++;
   }
   cout << res << endl;
}



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

using namespace std;

int gcd(int a, int b){
    if(a < b) swap(a, b);
    if(b == 0) return a;
    return gcd(b, a % b);
}
int main(){
  int n,ans;
  ans=0;
  cin>>n;
  vector<int> a(n);
  vector<int> l(n+1);
  vector<int> r(n+1);
  l[0]=0;
  r[0]=0;
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  for(int i=0;i<n;i++){
      l[i+1]=gcd(l[i],a[i]);
      r[i+1]=gcd(r[i],a[n-i-1]);
  }
  for(int i=0;i<n;i++){
      ans=max(gcd(l[i],r[n-i-1]),ans);
  }
  cout<<ans;
}


Measured memory_bytes: 1408
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
	int a, b, c, d;
	cin>>a>>b>>c>>d;
	while(1){
		c-=b;
		if(c<=0){
			cout<<"Yes"<<endl;
			return 0;
		}
		a-=d;
		if(a<=0){
			cout<<"No"<<endl;
			return 0;
		}
	}
	return 0;
}


Measured memory_bytes: 3624