akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define MOD 1000000007
#define pb push_back
#define mp make_pair

template<typename T>
void print(vector<T> &v)
{
    for_each(v.begin(), v.end(), [](auto i){cout << i << ' ';});
    cout << '\n';
}

void f(int testCase)
{
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    for(int i = 0; i<n; i++)
        cin >> a[i];
    for(int i = 0; i<n; i++)
        cin >> b[i];
    map<int, int> cntA, cntB;
    for(auto x: a)
        cntA[x]++;
    for(auto x: b)
        cntB[x]++;
    set<vector<int>, greater<vector<int> >>  s;
    for(auto x: b) {
        if(cntA.find(x) == cntA.end())
            s.insert({0, cntB[x], x});
        else s.insert({cntA[x], cntB[x], x});
    }
    vector<int> ans(n);
    for(int i = 0; i<n; i++) {
        // cout << "---------- i = " << i << endl;
        // for(auto p: s)
        //     cout << p.first << ' ' << p.second << endl;
        // cout << "map:" << endl;
        // for(auto p: cntA)
        //     cout << p.first << ' ' << p.second << endl;
        auto it = s.begin();
        auto v = *it;
        if(v[2] == a[i]) {
            it++;
            if(it == s.end())
            {
                cout << "No\n";
                // print(ans);
                return;
            }
            v = *it;
        }
        int c = v[0];
        int x = v[2];
        int cb = v[1];
        ans[i] = x;
        int cnt = cntA[a[i]];
        cntA[a[i]]--;
        if(cntA[a[i]] == 0)
            cntA.erase(a[i]);
        if(s.find({cnt, cntB[a[i]], a[i]}) != s.end())
        {
            s.erase({cnt, cntB[a[i]], a[i]});
            // if(cnt >= 1)
            s.insert({max(0, cnt-1), cntB[a[i]], a[i]});
        }
        s.erase({c, cb, x});
        cntB[x]--;
        if(cntB[x] != 0)
            s.insert({c, cb-1, x});


    }
    cout << "Yes\n";
    print(ans);
    
}

int main()
{
    std::ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t = 1;
    //cin >> t;

    for(int i = 1; i<=t; i++)
        f(i);
    return 0;
}

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

using namespace std;

const int MAXN=2e5+5;
int n;
int a[MAXN],f[MAXN];

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i)
		scanf("%d",&a[i]);
	int len=0;
	for(int i=1;i<=n;++i)
		f[a[i]]=f[a[i]-1]+1,len=max(len,f[a[i]]);
	printf("%d\n",n-len);
	return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>

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

Measured memory_bytes: 3712
x,y=map(int,input().split())
if (2*y-x)%3==0 and(2*x-y)%3==0 and (2*y-x)>=0 and (2*x-y)>=0:
  
      a=(2*y-x)//3
      b=(2*x-y)//3
      numerator=1
      denominator=1
      for i in range(a):
          numerator=(numerator*(a+b-i))%(10**9+7)
          denominator=(denominator*(a-i))%(10**9+7)
      print((numerator*pow(denominator,10**9+5,10**9+7))%(10**9+7))

else:
    print(0)

Measured memory_bytes: 9128
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
using namespace std;
int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	if ((b - a <= d && b - a >= -d) && (c - b <= d && c - b >= -d))
		cout << "Yes" << "\n";
	else if (a - c <= d && a - c >= -d)
		cout << "Yes" << "\n";
	else
		cout << "No" << "\n";
}

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

for i in range(N - 1):
    if A[i] + 1 == A[i+1]:
        ans += C[A[i]-1]

print(ans)

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

int main(){
  int N, M, C;
  cin >> N >> M >> C;
  vector<int>B(M);
  vector<int>vec1(N);
  vector<int>vec2(M);
  int count = 0;
  
  for (int i = 0; i < M; i++)
  {
    cin >> B.at(i);
  }
  
  for (int i = 0; i < N; i++)
  {
    for (int j = 0; j < M; j++)
    {
      cin >> vec2.at(j);
    }
    for (int j = 0; j < M; j++)
    {
      vec1.at(i) += B.at(j) * vec2.at(j);
    }
  }
  
  for (int i = 0; i < N; i++)
  {
    if ((vec1.at(i) + C) > 0)
    {
      count++;
    }
  }
  cout << count << endl;
}

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

#define ll long long
#define endl "\n"
#define vi vector<int>
#define pb push_back
#define F first
#define S second
int N;
ll mat[100009][3];
void solve() {
	cin >> N;

	for (int i = 0; i < N; i++) {
		for (int j = 0; j < 3; j++) {
			cin >> mat[i][j];
		}
	}

	ll dp[N][3];
	int index[N][3];
	memset(dp, 0, sizeof(dp));
	for (int i = 0; i < 3; i++) {
		dp[0][i] = mat[0][i];
		index[0][i] = i;
	}

	for (int i = 1; i < N; i++) {
		for (int j = 0; j < 3; j++) {

			if (j == 0) {
				dp[i][j] = mat[i][j] + max(dp[i - 1][1], dp[i - 1][2]);
			}
			else if (j == 1) {
				dp[i][j] = mat[i][j] + max(dp[i - 1][0], dp[i - 1][2]);
			}
			else {
				dp[i][j] = mat[i][j] + max(dp[i - 1][0], dp[i - 1][1]);
			}
		}
	}

	cout << max(dp[N - 1][0], max(dp[N - 1][1], dp[N - 1][2])) << endl;
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("manish.txt", "r", stdin);
	//freopen("ps.txt", "w", stdout);
#endif
	int t; //cin >> t;
	t = 1;
	while (t--) {
		solve();
	}
	return 0;
}

Measured memory_bytes: 8268
import java.util.Scanner;
class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		
		//1000
		int x1 = 0;
		//100
		int x2 = 0;
		//10
		int x3 = 0;
		while(x>=1000){
			x-=1000;
			x1++;
		}
		while(x>=100){
			x-=100;
			x2++;
		}
		while(x>=10){
			x-=10;
			x3++;
		}
		if(x1==x2 && x2==x3){
			System.out.println("Yes");
		}else if (x2==x3 && x2 == x){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 23764
#include <bits/stdc++.h>
#define REP(i, n) for (long long i = 0; i < (long long)n; i++)
//#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using Vl = vector<ll>;
using vi = vector<int>;
using Graph = vector<vi>;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  // std::cout << std::fixed << std::setprecision(15); //"for float-base
  // problem"
  string S;
  cin >> S;
  for (int i = 0; i < 3; i++) {
    cout << S.at(i);
  }
  cout << "\n";
}

Measured memory_bytes: 3656
fun main(args: Array<String>){
    val (N, A, B) = readLine()!!.split(" ").map { it.toLong() }
    val X = readLine()!!.split(" ").map { it.toLong() }

    var ans = 0L
    for(i in 1 until N.toInt()){
        ans += Math.min(B, (X[i] - X[i - 1]) * A)
    }
    println(ans)
}

Measured memory_bytes: 51760
#include <iostream>
int main() {int n, x;while(std::cin>>n,n){int dat[7]={};for(int i=0;i<n;i++){std::cin>>x;if(x/10>6)x=60;dat[x/10]++;}for(int i=0;i<7;i++)std::cout<<dat[i]<<'\n';}}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;

#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
#define e_b emplace_back
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())

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

#ifdef LOCAL//compile with -DLOCAL
#define debug(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = "<<(x)<<endl
#define debug_vec(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = ";\
  rep(i,sz(x)){cerr<<x[i]<<" ";}cerr<<endl
#define debug_mat(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = "<<endl;\
  rep(i,sz(x)){rep(j,sz(x[i])){cerr<<x[i][j]<<" ";}cerr<<endl;}cerr<<endl
#else
#define debug(x) void(0)
#define debug_vec(x) void(0)
#define debug_mat(x) void(0)
#endif

template<class T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<class T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}

int N;
bool solve(vector<int> &taka,vector<int> &aoki,int W,int s){
  int l=1;
  int r=W;
  rep(i,N){
    int x=aoki.at(i);
    if(x==1)  r=min(W,r+1);
    if(x==-1) l=max(1,l-1);

    x=taka.at(i);
    if(x==1)  l++;
    if(x==-1) r--;

    if(l>W || r<=0) return false;
    if(r<l) return false;
  }
  if(l<=s && s<=r)  return true;
  else  return false;
}

int main(){
  ios_base::sync_with_stdio(false);cin.tie(0);
  int H,W;
  cin >> H >> W >> N;
  int sy,sx;
  cin >> sy >> sx;
  string S,T;
  cin >> S >> T;

  vector<int> taka1(N,0);
  vector<int> taka2(N,0);
  vector<int> aoki1(N,0);
  vector<int> aoki2(N,0);
  for(int i=N-1;i>=0;i--){
    if(S.at(i)=='L')  taka1.at(N-1-i)=1;
    if(S.at(i)=='R')  taka1.at(N-1-i)=-1;
    if(S.at(i)=='U')  taka2.at(N-1-i)=1;
    if(S.at(i)=='D')  taka2.at(N-1-i)=-1;
    if(T.at(i)=='L')  aoki1.at(N-1-i)=1;
    if(T.at(i)=='R')  aoki1.at(N-1-i)=-1;
    if(T.at(i)=='U')  aoki2.at(N-1-i)=1;
    if(T.at(i)=='D')  aoki2.at(N-1-i)=-1;
  }
  if(solve(taka1,aoki1,W,sx) && solve(taka2,aoki2,H,sy))  cout << "YES" << endl;
  else  cout << "NO" << endl;

  return 0;
}

Measured memory_bytes: 6912
import sys
from io import StringIO
import unittest

def yn(b):
    print("Yes" if b==1 else "No")
    return

def resolve():
    readline=sys.stdin.readline

    #n,m,k=list(map(int, readline().strip().split()))
    #arr=list(map(int, readline().strip().split()))
    n=int(readline().strip())

    a="1 1 1 2 1 2 1 5 2 2 1 5 1 2 1 14 1 5 1 5 2 2 1 15 2 2 5 4 1 4 1 51".split()
    print(a[n-1])

    return

if 'doTest' not in globals():
    resolve()
    sys.exit()

Measured memory_bytes: 6384
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <numeric>
#include <set>
#include <list>
#include <bitset>
#include <cstdlib>
#include <map>
using ll = long long int;
using namespace std;

int main()
{
    string S;
    cin >> S;
    if (S == "keyence")
    {
        cout << "YES" << endl;
        return 0;
    }
    else
    {
        for (unsigned int i = 0; i < S.size(); i++)
        {
            for (unsigned int j = i; j < S.size(); j++)
            {
                string str = "";
                for (unsigned int k = 0; k < S.size(); k++)
                {
                    if (i <= k && k <= j)
                    {
                        continue;
                    }
                    else
                    {
                        str.push_back(S[k]);
                    }
                }
                if (str == "keyence")
                {
                    cout << "YES" << endl;
                    return 0;
                }
            }
        }
    }
    cout << "NO" << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
ll N,P,ans=1;
cin>>N>>P;
if(N==1){
printf("%lld\n",P);
return 0;
}
for(ll i=2;pow(i,N)<=P;i++){
ll tmp=pow(i,N);
if(P%tmp==0)
ans = i;
}
printf("%lld\n",ans);
}


Measured memory_bytes: 256
#include<cstdio>
#include<vector>
#include<algorithm>

using namespace std;

using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
using vll=vector<ll>;
using vvll=vector<vll>;


int main(void)
{
	int n, d;

	while(scanf("%d%d", &n, &d)==2)
	{
		int ans=(n+2*d)/(2*d+1);

		printf("%d\n", ans);
	}
	return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		String[] date = sc.nextLine().split("/");
		if(Integer.parseInt(date[1])<=4) {
			System.out.println("Heisei");
		}else {
			System.out.println("TBD");
		}
	}
}



Measured memory_bytes: 21844
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll MOD = 1e9+7;

#define vec vector<int>
#define vecll vector<ll>
#define vpair vector<pair<int, int>>
#define vpairll vector<pair<ll, ll>>

#define rep(i,n)         for(int i=(int)0; i<(int)n; i++)
#define REP(i,m,n)       for(int i=(int)m; i<(int)n; i++)
#define arr(var, n)      vec var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n)    vecll var(n); rep(i,n){cin >> var[i];}
#define all(var)         (var).begin(), (var).end()
#define sortall(var)     sort(all(var))
#define prt(var)         cout << var << endl
#define prtd(n, var)     cout << fixed << setprecision(n) << var << endl
#define prt2(var1, var2) cout << var1 << " " << var2 << endl
#define prtseq(var, n)   rep(i,n){cout << var[i] << " ";} cout << endl
#define prtseql(var, n)  rep(i,n){cout << var[i] << " " << endl;}

//----------------------------------------------------------------

int main(void) {
  int n, m;
  cin >> n >> m;

  priority_queue<ll> a;
  rep(i,n){
    ll tmp;
    cin >> tmp;
    a.push(tmp);
  }

  rep(i,m){
    ll tmp = a.top();
    a.pop();
    a.push(tmp/2);
  }

  ll ans=0;
  rep(i,n){
    ans+=a.top();
    a.pop();
  }

  prt(ans);
}


Measured memory_bytes: 1400
#include<stdio.h>
#include<math.h>

int main(void)
{
int n=0,sum = 0,ans=0;
double heikin = 0;
int a[110];

scanf("%d",&n);
for(int i = 0;i < n;i++){scanf("%d",&a[i]); sum += a[i];}
heikin = (double)sum / (double)n;

ans = n-1;

for(int i = n-2;0 <= i;i--)
{
if(fabs(a[ans]-heikin) >= fabs(a[i]-heikin)){ans = i;}
}

printf("%d",ans);

return 0;
}


Measured memory_bytes: 128
from fractions import gcd

a,b,c,d = map(int,input().split())
a -= 1
def div(m,n):
	return m // n

ans_a = a - div(a,c) - div(a,d) + div(a,c*d//gcd(c,d))
ans_b = b - div(b,c) - div(b,d) + div(b,c*d//gcd(c,d))

print(ans_b - ans_a)


Measured memory_bytes: 5600
#include<stdio.h>
#include<algorithm>
#include<iostream>
using namespace std;

int main(){ 

  int i,j;
  int b,r,g,c,s,t;

  while(1){

    int bonus;      //ボーナスタイムの数
    int use_coin;   //回すために使ったコインの枚数
    int lost_turn;  //獲得コインが0だった回数
    int profits;    //利益

    scanf("%d %d %d %d %d %d",&b,&r,&g,&c,&s,&t);

    if(t==0)break;

    /*損したコインの枚数を計算する*/
    
    /*総プレイ回数の内ボーナスタイムの数を調べる*/
    bonus=b*5+r*3;

    /*総プレイ回数の内獲得が0だった回数を調べる*/
    lost_turn=t-(bonus+b+r+g+c+s);

    /*回すのに使ったコインの枚数を計算*/
    use_coin=lost_turn*3;

    /*利益を計算*/
    profits=100+b*12+r*12+bonus*13+g*4-c;

    /*差し引いた額を出力*/
    printf("%d\n",profits-use_coin);

  }

  return 0;
}

Measured memory_bytes: 1188
n,k=map(int,input().split())
x=list(map(int,input().split()))


res=3*10**8+1

for i in range(n-k+1):
	l=x[i]
	r=x[i+k-1]
	if l*r>=0:
		res=min(res,max(abs(l),abs(r)))
	else:
		res=min(res,abs(l)+abs(r)+min(abs(l),abs(r)))
	
print(res)

Measured memory_bytes: 14532
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<endl;}
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; }

vector<int> G[100010];

int main(int argc, char const *argv[]) {
  int n,m;
  cin >> n >> m;
  rep(i, m) { int a, b;
  cin >> a >> b;
  a--, b--;
  G[b].pb(a), G[a].pb(b);
  }
  vector<int> dist(n, -1);
  queue<int> q;
  q.push(0);
  dist[0] = 0;

  while(!q.empty()){
    int now = q.front();
    q.pop();
    for(auto p: G[now]){
      if (dist[p] != -1) continue;
      dist[p] = dist[now] + 1;
      q.push(p);
    }
  }
  puts("Yes");
  for(int i=1; i<n; i++){
    int rec = dist[i];
    for(auto p: G[i]){
      if(rec==dist[p]+1) {
        cout << p+1 << endl;
        break;
      }
    }
  }
  
  //show(dist);
  return 0;
}

Measured memory_bytes: 10092
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
  private static class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
      reader = new BufferedReader(new InputStreamReader(in));
      tokenizer = null;
    }

    public String next() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          tokenizer = new StringTokenizer(reader.readLine());
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
      return tokenizer.nextToken();
    }

    public String nextLine() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          return reader.readLine();
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }

      return tokenizer.nextToken("\n");
    }

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

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

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

    public int[] nextIntArray(int n) {
      int[] a = new int[n];
      for (int i = 0; i < n; i++)
        a[i] = nextInt();
      return a;
    }

    public long[] nextLongArray(int n) {
      long[] a = new long[n];
      for (int i = 0; i < n; i++)
        a[i] = nextLong();
      return a;
    }
  }

  public static void main(String[] args) {
    FastScanner sc = new FastScanner(System.in);
    String s = sc.next();
    int longest = 0;
    int last = 0;
    for (char c : s.toCharArray()) {
      if (c == 'A' || c == 'C' || c == 'G' || c == 'T') last++;
      else last = 0;
      if (last > longest) longest = last;
    }
    System.out.println(longest);
  }
}

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


int main() {
  int h,w,d;
  cin>>h>>w>>d;
  vector<P> a(1000000);
  rep(i,h)rep(j,w){
    ll a1;
    cin>>a1;
    a[a1]=make_pair(i,j);
  }
  int q;

  vector<ll> v[d+5];//あまりごとに

  for(int i=0;i<d;i++){
    ll now=i;
    if (i==0)now=d;
    P pos=a[now];
    v[i].push_back(0);
    ll cnt=0;
    while (now<=h*w){
      now+=d;
      P posnew=a[now];
      ll ad=abs(posnew.first-pos.first)+abs(posnew.second-pos.second);
    //  cout<<pos.first<<'f'<<pos.second<<"s"<<endl;
    //  cout<<posnew.first<<'f'<<posnew.second<<"s"<<endl;

    //  cout<<ad<<'i'<<i<<"now"<<now<<endl;
      cnt+=ad;
      v[i].push_back(cnt);
      pos=a[now];
    }
  }

  cin>>q;
  rep(i,q){
    int l1,r1;
    cin>>l1>>r1;

    ll D=l1%d;
    ll s1=(l1-D)/d;
    ll f1=(r1-D)/d;
    if (D==0){
      s1--;f1--;
    }
    //cout<<s1<<"s1"<<f1<<"f1"<<endl;
    ll cnt=v[D][f1]-v[D][s1];
    cout<<cnt<<endl;


  }
return 0;

}


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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]A - Sharing Cookies
            var line = ReadLine();

            if (CanSharing(line[0], line[1]))
            {
                Console.WriteLine("Possible");
            }
            else
            {
                Console.WriteLine("Impossible");
            }
        }

        static bool CanSharing(int a, int b)
        {
            if (a % 3 == 0)
            {
                return true;
            }
            else if (b % 3 == 0)
            {
                return true;
            }
            else if ((a + b) % 3 == 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        static List<int> ReadLine()
        {
            var line = Console.ReadLine();
            var array = line.Split(' ');

            return array.Select(x => int.Parse(x)).ToList();
        }
    }
}


Measured memory_bytes: 13268
//https://onlinejudge.u-aizu.ac.jp/challenges/sources/ICPC/Prelim/1192?year=2014

#include <bits/stdc++.h>

using namespace std;

int main() {
    int x, y, s;

    while (cin >> x >> y >> s, x | y | s) {
        int ans = 0;
        for (int p1 = 1; p1 < s; ++p1) {
            for (int p2 = 1; p1 + p2 <= s; ++p2) {

                int sx = p1 * (100 + x) / 100 + p2 * (100 + x) / 100;
                if (sx == s) {
                    int sy = p1 * (100 + y) / 100 + p2 * (100 + y) / 100;
                    ans = max(ans, sy);
                }
            }
        }
        cout << ans << endl;
    }
    
    return 0;
}

/*
 * 2商品の原価をp,q(p<q)とする。
 * 税率x%のときの値段は
 * [p (100+x) / 100]+[q (100+x) / 100]=s
 *
 */


Measured memory_bytes: 3076
# coding: utf-8
import bisect


def solve(*args: str) -> str:
    n = int(args[0])
    ln = sorted(list(map(int, args[1].split())))
    s = 0
    for i in range(n-1, 1, -1):
        for j in range(i-1, 0, -1):
            small = bisect.bisect_right(ln, ln[i] - ln[j])
            big = bisect.bisect_left(ln, ln[i] + ln[j], small, j)
            s += big - small

    return str(s)


if __name__ == "__main__":
    print(solve(*[input() for _ in range(2)]))


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

#define ll long long

using namespace std;
int main() {
  int N,b=1,cnt=0;
  cin>>N;
  int a[N];
  for(int i=0;i<N;i++) cin>>a[i];
  for(int i=0;i<N;i++){
    if(a[i]==b) b++;
    else if(a[i]!=b){
      cnt++;
    }
  }
  if(cnt==N) cout<<"-1"<<endl;
  else cout<<cnt<<endl;
}	


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

#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define mem(x,val) memset((x),(val),sizeof(x))
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define PI acos(-1.0) 

const int INF = 1 << 29 ;
typedef long long ll ;

int a[100] ;

int main() {
	int n , k , sum = 0;
	scanf("%d %d" , &n ,&k) ;
	for(int i = 0 ;i<n ; i++)scanf("%d" ,a+i) ;
	sort(a , a+n , greater<int>()) ;
	for(int i = 0 ; i<k ;i++)sum+=a[i] ;
	printf("%d\n" , sum) ;
     
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include <cmath>
#include <ctype.h>
#include<vector>
using namespace std;
int a, b, c;
int main() {
    cin >> a >> b >> c;
    bool flag=false;
    for(int i=1; i<b; ++i){
        if(a*i%b==c) flag=true;
        
    }
    if(flag) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
import math
N = int(input())
A = list(map(int, input().split()))


def union_gcd(lists):
    if len(lists) == 1:
        return lists[0]
    elif len(lists) > 1:
        num = lists[0]
        for i in range(1, len(lists)):
            num = math.gcd(num, lists[i])
        return num


def prime_to(n):
    prime = {i for i in range(2, n)}
    for i in range(2, n):
        if i in prime:
            for j in range(i*2, n, i):
                if j in prime:
                    prime.remove(j)
    return prime


is_pair_wise = True
is_all_gcd_1 = False

if union_gcd(A) == 1:
    is_all_gcd_1 = True

Num = [0 for i in range(10**6+1)]
for x in A:
    Num[x] += 1

seen = [False for i in range(10**6+1)]
A.sort()
primes = prime_to(10**6)
for num in primes:
    if seen[num] == False:
        seen[num] = True
        cnt = 0
        for i in range(1, 10**6+1):
            if num*i > 10**6:
                break
            else:
                cnt += Num[num*i]
        if cnt > 1:
            is_pair_wise = False
            break
if is_pair_wise:
    print("pairwise coprime")
else:
    if is_all_gcd_1:
        print("setwise coprime")
    else:
        print("not coprime")

Measured memory_bytes: 257848
#include<stdio.h>
int main()
{
  int n,m,i,j,sum;
  scanf("%d%d",&n,&m);
  int A[n][m],B[m],C[n][1];
  for(i=0;i<n;i++){
    for(j=0;j<m;j++){
      scanf("%d",&A[i][j]);
    }

  }
  for(i=0;i<m;i++){

      scanf("%d",&B[i]);

  }

  for(i=0;i<n;i++){sum=0;
    for(j=0;j<m;j++){
      sum=sum+A[i][j] * B[j];
       }
        printf("%d\n",sum);


  }


  return 0;
}



Measured memory_bytes: 2112
import java.io.*;

class Main{
	public static void main (String[ ] args) throws Exception{
		BufferedReader br = new BufferedReader (new InputStreamReader (System.in));

		for(int i = 1;; i++)
		{
			int n = Integer.parseInt(br.readLine());
			if(0 == n)
			{
				break;
			}
			System.out.println("Case " + i + ": " + n);
		}
	}
}

Measured memory_bytes: 31408
import math
from functools import reduce
N = int(input())
total = 0
def gcd(*numbers):
    return reduce(math.gcd, numbers)
def gcd_list(numbers):
    return reduce(math.gcd, numbers)
for i in range(1, N+1):
    for j in range(1, N+1):
        for k in range(1, N+1):
            total += gcd(i, j, k)
print(total)

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

using namespace std;

bool cmp(char a,char b)
{
    return a>b;
}

int main()
{
    char s1[105],s2[105];
    scanf("%s %s",s1,s2);
    int len1=strlen(s1),mn1='z'+1,mx2='a'-1;
    int len2=strlen(s2);
    sort(s1,s1+len1);
    sort(s2,s2+len2,cmp);
    for(int i=0;i<=min(len1,len2);i++)
    {
        if(s1[i]<s2[i])
        {
            printf("Yes\n");
            return 0;
        }
        else if(s1[i]>s2[i])
        {
            printf("No\n");
            return 0;
        }
    }
    printf("No\n");
}

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

namespace atcoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var buffer = Console.ReadLine().Split(' ');
            int X = int.Parse(buffer[0]);
            int N = int.Parse(buffer[1]);

            if (N == 0)
            {
                Console.WriteLine(X);
                return;
            }

            buffer = Console.ReadLine().Split(' ');
            int num = 0;
            while (true)
            {
                if (!buffer.Contains((X - num).ToString()))
                {
                    Console.WriteLine(X - num);
                    break;
                }
                if (!buffer.Contains((X + num).ToString()))
                {
                    Console.WriteLine(X + num);
                    break;
                }
                num++;
            }
        }
    }
}


Measured memory_bytes: 27872
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define SUM(a)  accumulate((a).begin(),(a).end(),0)
#define SORT(a) sort(ALL(a))
#define REV(a) reverse(ALL(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
typedef long long ll;
const int INF = 999999999;
const int MOD = (int)1e9 + 7;
const int EPS = 1e-9;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, y;
  cin >> n >> y;
  REP(i,n+1){
      REP(j,n+1-i){
            int k = n-i-j;
            //cout << i << " " << j << " " << k << endl;
            if (10000*i+5000*j+1000*k==y){
                cout << i << " " << j << " " << k << endl;
                return 0;
            }
      }
      
  }
  cout << -1 << " " << -1 << " " << -1 << endl;
}

Measured memory_bytes: 256
# import numpy as np
# import queue
# import heapq
from itertools import combinations_with_replacement


def main():
    N, M, Q = map(int, input().split())

    queries = [list(map(int, input().split())) for _ in range(Q)]

    As = combinations_with_replacement(range(1, M+1), N)

    max_total = 0
    for A in As:
        total = 0

        for i, q in enumerate(queries):
            if A[q[1]-1] - A[q[0]-1] == q[2]:
                total += q[3]

        max_total = max(max_total, total)

    print(max_total)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9204
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main() {
  string s; cin >> s;
  int ans = 1000;
  for(int i = 0; i < int(s.size()) - 2; i++) {
    int cur = 0;
    for(int j = 0; j < 3; j++) cur = cur * 10 + s[i+j] - '0';
    if(ans > abs(cur - 753)) ans = abs(cur - 753);
  }
  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
// #include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
// #include <random>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

/*
unsigned seed1 = std::chrono::system_clock::now().time_since_epoch().count();
mt19937 g1.seed(seed1);
*/
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<pii, pii> ppiipii;
typedef pair<int, ppiipii> pippiipii;
typedef pair<int, pii> pipii;
typedef pair<pii, int> ppiii;
typedef pair<int, ppiii> pippiii;
typedef pair<int, ll> pill;
typedef pair<int, double> pid;
typedef pair<string, string> pss;
// note to self, the below two triggers someone
typedef pair<ll, ll> pll;
typedef pair<ll, int> plli;
typedef long double ld;

char buf[10000];
vector<int> poss[2];
int goal[2];

bool dp[10000];

bool can(int idx) {
  memset(dp, 0, sizeof(dp));
  dp[0] = true;
  int totalSum = 0;
  for(int out: poss[idx]) {
    totalSum += out;
    for(int a = 8000; a >= out; a--) {
      dp[a] |= dp[a-out];
    }
  }
  goal[idx] = abs(goal[idx]);
  if(goal[idx] > totalSum) return false;
  if(totalSum%2 != goal[idx]%2) return false;
  return dp[(totalSum - goal[idx]) / 2];
}

bool can() {
  return can(0) && can(1);
}

int main() {
  scanf("%s", buf);
  int len = strlen(buf);
  scanf("%d%d", &goal[0], &goal[1]);
  int idx = 0;
  int i = 0;
  while(i < len && buf[i] == 'F') {
    goal[0]--;
    i++;
  }
  i++;
  idx++;
  while(i < len) {
    if(buf[i] == 'T') {
      idx++;
      idx%=2;
      i++;
      continue;
    }
    int j = i+1;
    while(j < len && buf[j] == 'F') j++;
    poss[idx++].push_back(j-i);
    idx%=2;
    i=j+1;
  }
  printf(can() ? "Yes\n" : "No\n");
}


Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)

	if n%2 == 1 {
		fmt.Println(0)
	} else {
		ans := 0
		m := n / 2

		for i := 5; i <= m; i *= 5 {
			ans += m / i
		}
		fmt.Println(ans)
	}
}


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

int main(){
	int n;
	string s;
	cin >> n >> s;
	int ans = 0;
	int count = 0;
	rep(i,n){
		if(s[i] == 'I') count++;
		if(s[i] == 'D') count--;
		ans = max(ans, count);
	}
	cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3584
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        m: i32,
    }
    let ans = 24 + 24 - m;
    println!("{}", ans);
}


Measured memory_bytes: 4352
import sys
import math
import heapq
from collections import defaultdict, deque
sys.setrecursionlimit(10**6)
input = sys.stdin.readline
def r():
    return int(input())
def rm():
    return map(int,input().split())
def rl():
    return list(map(int,input().split()))

'''C Tsundoku'''
n,m,k=rm()
a=rl()
b=rl()
c=[0]*(n+1)
d=[0]*(m+1)
for i in range(n):
    c[i+1]=c[i]+a[i]
for i in range(m):
    d[i+1]=d[i]+b[i]
ans=0;j=m
for i in range(n+1):
    if c[i]>k:
        break
    while c[i]+d[j]>k:
        j-=1
    ans=max(ans,i+j)
print(ans)

Measured memory_bytes: 122328
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define _GLIBCXX_DEBUG
#define rep(i, a, b) for(int i = a; i < b; i++)
#define ALL(v) v.begin(), v.end()

int main(){
    int n; cin>>n;
    cout<<n*n*n<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>

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

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

int main()
{
  string N;
  cin >> N;

  long long sum = 0;
  rep(i, N.size())
  {
    sum += N[i] - '0';
    sum %= 9;
  }

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

  return 0;
}


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

int main() {
  string S;
  cin >> S;
  
  if (S[0] == S[1] && S[2] == S[3] && S[0] != S[2] || S[0] == S[2] && S[1] == S[3] && S[0] != S[1] || S[0] == S[3] && S[1] ==S[2] && S[0] != S[1]) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
} 

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

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << setprecision(20);

  int n;
  cin >> n;
  vector<string> words(n);
  rep(i, n) { cin >> words[i]; } 
  
  bool ok = true;
  string prev;
  set<string> used;
  rep(i, n) {
    if (i != 0 && 
        words[i-1].back() != words[i].front()) {
        ok = false;
    }
    if (used.find(words[i]) != used.end()) { ok = false; }
    used.insert(words[i]);
  }
  if (ok) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#define SIZE 100

/* prototype declaration */
void counter();
int findMax();
void printMode();

int data[SIZE];

int main(int argc, const char *argv[])
{
	counter();
	findMax();
	printMode();	
	return 0;
}

void counter()
{
	int d;
	while(scanf("%d", &d) != EOF) data[d-1]++;
}

int findMax()
{
	int i, max = data[0];
	for(i=1; i<SIZE; i++)
		if(max < data[i]) max = data[i];
	
	return max;
}

void printMode()
{
	int i, max = findMax();
	for(i=0; i<SIZE; i++)
		if(data[i] == max) printf("%d\n", i+1);
}

Measured memory_bytes: 0
#include <iostream>

using namespace std;

int f(int a, int b) {
    int result = 0;
    for (int i = 0; i < 2; i++) {
        if (a > b) {
            result += a;
            a--;
        } else {
            result += b;
            b--;
        }
    }

    return result;
}

int main() {

    int a, b;
    cin >> a >> b;

    int result = f(a, b);
    cout << result << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
  vector<int> v(3);
  for(int i=0;i<3;i++){
    int num; cin >> num; v[i] = num;
  }
  sort(v.begin(), v.end());
  int k; cin >> k;
  for(int i=0;i<k;i++) v[2] = v[2]*2;
  cout << v[0]+v[1]+v[2] << endl;
  return 0;
}

Measured memory_bytes: 256
n, m, q = map(int, input().split())

a = [0] * 55; b = [0] * 55; c = [0] * 55; d = [0] * 55

for i in range(q):
    a[i], b[i], c[i], d[i] = map(int, input().split())

def socer(A):
    now = 0
    for i in range(q):
        if A[b[i]-1] - A[a[i]-1] == c[i]: now += d[i]
    return now

def dfs(A):
    # print(A)
    if len(A) == n: return socer(A)
    res = 0
    last = A[-1] if A else 0
    for i in range(last, m):
        A.append(i)
        res = max(res, dfs(A))
        A.pop()
    return res
      
print(dfs([]))

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

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

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n ;
		int countOfExc = 0;
		n = in.nextInt();
		int[] a = new int[n];
		for(int i = 0;i<n;i++){
			a[i] = in.nextInt();
		}
		for(int i = 0;i<n-1;i++){
			int min = i;
			for(int j = i+1;j<n;j++){
				if(a[min]>a[j]){
					min = j;
				}
			}
			int temp = a[i];
			a[i] = a[min];
			a[min] = temp;
			if(min > i) countOfExc++;
		}

		for(int i = 0;i<n;i++){
			if(i>0)System.out.print(" ");
			System.out.print(a[i]);
		}
		System.out.println("");
		System.out.println(countOfExc);
	}
}

Measured memory_bytes: 26264
#include<iostream>
#include<sstream>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<complex>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cassert>

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf = (int)1e9;
const double INF = 1e12, EPS = 1e-9;

int main(){
	int n;
	while(scanf("%d", &n), n){
		map<int, vector<pi> > v;
		map<int, int> sum;
		rep(i, n){
			int mo, d, h, m, id;
			char c;
			scanf("%d/%d %d:%d %c %d", &mo, &d, &h, &m, &c, &id);
			int t = mo * 31 * 24 * 60 + d * 24 * 60 + h * 60 + m;
			v[id].pb(mp(t, c == 'I' ? -1 : 1));
		}
		int mx = 0;
		each(i, v){
			if(i->first == 0) continue;
			
			vector<pi> vv = i->second;
			each(j, v[0]) vv.pb(mp(j->first, j->second));
			
			sort(all(vv));
			int sum = 0, s = 0, prev = -1;
			each(j, vv){
				if(s < -1) sum += j->first - prev;
				prev = j->first;
				s += j->second;
			}
			mx = max(mx, sum);
		}
		cout << mx << endl;
	}
	return 0;
}

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

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

    string s;
    cin >> s;
    if(s[2] == s[3] && s[4] == s[5]) {
        cout << "Yes" << "\n";
    } else {
        cout << "No" << "\n";
    }
    return 0;
}


Measured memory_bytes: 3636
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<string>
#include<utility>
#include<numeric>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;

using ll = long long;

class Stream{
public:
    Stream(){

    }
    //配列以外の入力を受け取る
    void read(){

    }
    template<typename First, typename... Rest>
    void read(First& first, Rest&... rest){
        cin >> first;
        read(rest...);
    }
    template<typename T>
    vector<T> read_vec(size_t n){
        vector<T> tmp(n);
        for(size_t i = 0; i < n; i++){
            cin >> tmp[i];
        }
        return tmp;
    }
    //配列を区切って出力する
    template<typename T>
    void write_vec(vector<T>& v, char divider){
        for(size_t i = 0; i < v.size(); i++){
            cout << v[i] << divider;
        }
    }
};

int main(){
    Stream io;
    
    string s;
    io.read(s);
    string ans;
    for(int i = 0; i < s.size(); i += 2){
        ans.push_back(s[i]);
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 512
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.io.PrintWriter
import java.lang.IllegalArgumentException
import java.lang.StringBuilder
import java.util.*

fun PrintWriter.solve(sc: FastScanner) {
    var n = sc.nextLong()
    var ans = ""
    while (n > 0) {
        val r = (n % 26).toInt()
        val m = (if (r == 0) 26 else r) - 1
        ans = ('a' + m) + ans
        n = (n - 1) / 26
    }
    println(ans)
}

fun main(args: Array<String>) {
    val writer = PrintWriter(System.out, false)
    writer.solve(FastScanner(System.`in`))
    writer.flush()
}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}

Measured memory_bytes: 34396
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
// 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;
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() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  vector<int> s, t;
  rep(i,n) {
    cin >> a[i];
    if (a[i] < 0) t.push_back(a[i]);
    else s.push_back(a[i]);
  }
 
  int S = s.size();
  int T = t.size();
  bool ok = false;
  if (S > 0) {
    if (n == k) ok = (T%2==0);
    else ok = true;
  } else {
    ok = (k%2==0);
  }
 
  mint ans = 1;
  if (!ok) {
    sort(a.begin(), a.end(), [](int x, int y) {
      return abs(x) < abs(y);
    });
    rep(i,k) ans *= a[i];
  } else {
    sort(s.begin(), s.end());
    sort(t.rbegin(), t.rend());
    if (k%2 == 1) {
      ans *= s.back();
      s.pop_back();
    }
    vector<ll> p;
    while (s.size() >= 2) {
      ll x = s.back(); s.pop_back();
      x *= s.back(); s.pop_back();
      p.push_back(x);
    }
    while (t.size() >= 2) {
      ll x = t.back(); t.pop_back();
      x *= t.back(); t.pop_back();
      p.push_back(x);
    }
    sort(p.rbegin(), p.rend());
    rep(i,k/2) ans *= p[i];
  }
 
  cout << ans << endl;
  return 0;
}

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

long long fact( int n ){
	if( n == 0 ) return 1;
	return (long long)n * fact(n - 1);
}

int main()
{
	string s;
	int cnt[26] = {0};
	int i;
	
	cin >> s;
	for( i = 0; i < s.length(); i++ ){ cnt[s[i] - 'a']++; }
	
	int oddcnt = 0;
	long long div = 1;
	for( i = 0; i < 26; i++ ){
		if( cnt[i] % 2 ){
			oddcnt++;
		}
		div *= fact(cnt[i] / 2);
	}
	
	if( oddcnt >= 2 ){
		cout << 0 << endl;
	}
	else if( oddcnt == 1 ){
		int l = (s.length() - 1) / 2;
		cout << fact(l) / div << endl;
	}
	else{
		cout << fact(s.length() / 2) / div << endl;
	}
	return 0;
}

Measured memory_bytes: 1184
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
#include<cstdio>
#include<cstdlib>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

const double EPS = 1e-10;

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;


int main(){
    int N,K,S; cin >> N >> K >> S;
    vector<int> ans(N);
    rep(i,K){
        ans[i] = S;
    }
    if(S == 1000000000){
        repr(i,K,N) ans[i] = 1;
    }
    else{
        repr(i,K,N) ans[i] = 1000000000;
    }
    rep(i,N) cout << ans[i] << " ";
    cout << endl;
}


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

using namespace std;

struct Point
{
    int nx,ny,dis;
    Point(int _nx,int _ny,int _dis)
    {
        nx=_nx;
        ny=_ny;
        dis=_dis;
    }
};

bool operator < (const Point &x,const Point &y)
{
    return x.dis>y.dis;
}

int n,m,c1,d1,c2,d2;
char G[1010][1010];
bool vis[1010][1010];
int dis[1010][1010];

void pri_dij()
{
    priority_queue<Point> pq;
    while(!pq.empty()) pq.pop();
    memset(dis,0x3f,sizeof(dis)); 
    dis[c1][d1]=0;
    pq.push(Point(c1,d1,0));
    while(!pq.empty())
    {
        int x=pq.top().nx,y=pq.top().ny;
        pq.pop();
        if(vis[x][y]) continue;
        vis[x][y]=true;
        for(int nx=x-2;nx<=x+2;nx++)
        {
            if(nx<1 || nx>n) continue;
            for(int ny=y-2;ny<=y+2;ny++)
            {
                if(ny<1 || ny>m) continue;
                if(G[nx][ny]=='#') continue;
                if(abs(nx-x)+abs(ny-y)==1)
                {
                    if(dis[nx][ny]>dis[x][y])
                    {
                        dis[nx][ny]=dis[x][y];
                        pq.push(Point(nx,ny,dis[nx][ny]));
                    }
                }
                else 
                {
                    if(dis[nx][ny]>dis[x][y]+1)
                    {
                        dis[nx][ny]=dis[x][y]+1;
                        pq.push(Point(nx,ny,dis[nx][ny]));
                    }
                }
            }
        }
    }
}

int main()
{
    scanf("%d%d%d%d%d%d",&n,&m,&c1,&d1,&c2,&d2);
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
            cin>>G[i][j];
    pri_dij();
    if(dis[c2][d2]==0x3f3f3f3f) puts("-1");
    else printf("%d",dis[c2][d2]);
    return 0;
}

Measured memory_bytes: 9664
#include<bits/stdc++.h>
 // #include <ext/pb_ds/tree_policy.hpp>
 // #include <ext/pb_ds/assoc_container.hpp>
 // #include<chrono>
 using namespace std;
 using namespace std::chrono;      
 // using namespace __gnu_pbds; 
 #define fastio     ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
 #define fi         first
 #define se         second
#define int         long long 
 #define pb         push_back
 #define emp        emplace_back
 #define vv(x)      vector<x>
 #define mp(x,y)    map<x,y>
 #define dq(x)      deque<x>
 #define pql(x)     priority_queue<x>
 #define pqs(x)     priority_queue<x,vv(x),greater<x> >
 #define mod        1000000007
 #define forf(i,a,b) for(int i=a;i<b;i++)
 #define it(x)      x::iterator
 #define ll         long long 
 #define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
 #define time__(d)  for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false); debug("%s time : %.4fs", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
 #define vii        vector<int>
 #define big        2e18
 #define sm         -1e9
 #define mkr        make_pair
 #define vpi        vector<pair<int,int> >
 #define pii        pair<int,int>
 #define rng        500005
 #define sz(x)      (int)x.size()
 #define rv(x)      reverse(x.begin(),x.end())
 #define out(x)     cout<<x.fi<<" "<<x.se<<endl;

//#define ordered_set tree<pii, null_type,less<pii>, rb_tree_tag,tree_order_statistics_node_update> 
  
void pr_init()
{
   
    #ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
   
    #endif
}

void solve()
{
 
 int n,m;
 cin >> n >> m;

 int a[n],s=0;

 forf(i,0,n) cin >> a[i],s+=a[i];

 sort(a,a+n,greater<int>());
double th = (double)s/(double)(4*m);

if(a[m-1]>=th) cout<<"Yes\n";
else cout<<"No\n";



}

int32_t main()
{
  pr_init();
  fastio;
  solve();

 }


Measured memory_bytes: 3656