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

#define int           long long
#define S             second
#define F             first
#define pb            push_back
#define all(c)        (c).begin(),(c).end()
#define rall(c)       (c).rbegin(),(c).rend() 
#define lb            lower_bound
#define si(c)         (int)((c).size())
#define lcm(a, b)      (a * (b / __gcd(a,b)))  
#define inf           (long long )(1e10+1)
#define endl          '\n'
#define mp            make_pair
#define time(s)       (double(clock()-s)/double(CLOCKS_PER_SEC))
#define debug(args...)    _F(#args, args)
#define vi            std::vector<int>
#define pii           pair<int, int> 
#define vpi           vector<pii>

clock_t start;
mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());

template<typename T> void _F(const char *name, T arg1){
    cerr << name << " = " << arg1 << endl;
}
template<typename T, typename... Args> void _F(const char *names, T arg1, Args... args){
    const char *name = strchr(names, ',');cerr.write(names, name-names) << " = " << arg1 << endl;_F(name+2, args...);
}
template<typename T1, typename T2> istream& operator>>(istream& in, pair<T1, T2> &q){ 
    in >> q.F >> q.S; return in;
}
template<typename T1, typename T2> ostream& operator<<(ostream& out, pair<T1, T2> &q){
    out << q.F << " " << q.S; return out;
}
template< typename T1, typename T2> pair<T1, T2> operator+(pair<T1, T2> p1, pair<T1, T2> p2){
    return {p1.F+p2.F, p1.S+p2.S};
}
template< typename T1, typename T2> pair<T1, T2> operator-(pair<T1, T2> p1, pair<T1, T2> p2){
    return {p1.F-p2.F, p1.S-p2.S};
}

const int N = 1e3+1;

void solve() {
    int x;
    cin >> x;
    for(int i = 0; i < N; i++){
        for(int j = 0; j < N; j++){
            int A = i*i*i*i*i;
            int B = j*j*j*j*j;
            if(B-A == x){
                cout << j << " " << i << endl;
                return;
            }
            if(A+B == x){
                cout << j << " " << -i << endl;
                return;
            }
        }
    }
}


signed main(){

    ios_base::sync_with_stdio(0); 
    cin.tie(0); cout.tie(0);   

    int t = 1;
    start = clock(); 

    cout << fixed << setprecision(20);

    // #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin); 
    // freopen("output.txt", "w", stdout);
    // freopen("error.txt", "w", stderr);
    // #endif
   
    //cin >> t;

    
    for(int i = 1; i <= t; ++i){
        //cout << "Case #" << i << ": "; 
        solve();
        //cout << endl;
    }
    //cerr << time(start);
    return 0;
}


Measured memory_bytes: 3640
import java.util.Scanner;

class Main {

    public static void main(String[] args) {
        Scanner stdIn=new Scanner(System.in);
        
        double x;
        double y=Math.PI;
        do{
            
            
           x=stdIn.nextInt(); 
        }while(x<=1&&x>=100);
        
        System.out.println(x*2*y);
        
    }

}

Measured memory_bytes: 35896
#include <string>
#include <iostream>
using namespace std;
int main() {
	int N;
	cin >> N;
	double ans = 0;
	for (int i = 0; i < N; ++i) {
		double x; string s;
		cin >> x >> s;
		if (s == "JPY") ans += x;
		else ans += x * 380000.0;
	}
	cout.precision(15);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
using System;

class Program
{
	static void Main(string[] args)
        {
		    var line = System.Console.ReadLine();
            int N = Convert.ToInt16(line);
            int ans = 2;
            if (N < 2) { ans = N; }
            else if (N < 4) { ans = 2; }
            else if (N < 8) { ans = 4; }
            else if (N < 16) { ans =  8; }
            else if (N < 32) { ans = 16; }
            else if (N < 64) { ans = 32; }
            else if (N <= 100) { ans = 64; }     

            Console.WriteLine(ans);
        } 
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef set<int> si;


#define pb push_back
#define mp make_pair
#define F first
#define S second
const int inf = (int) 1e9;
const int maxn = 2 * 1e5 + 10 ;


int n,m;
int ans;




void solve(){
	scanf("%d\n" , &n);
	for(int i = 0; i < n; ++i){
		scanf("%d ", &m);
		ans += m - 1;
	}
	printf("%d\n", ans );
	
}

int main() 
{ 
	
   solve() ;   
} 








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

int main(){
  int64_t a,b,c,d;
  cin >> a >> b >> c >> d;
  int64_t g=max(c,d),l=min(c,d),n=l;
  while(g%l!=0){
    n=g%l;
    g=l;
    l=n;
  }
  n=c*d/n;
  cout << b-a+1-b/c+(a-1)/c-b/d+(a-1)/d+b/n-(a-1)/n << endl;
  return 0;
}

Measured memory_bytes: 3592
#include <iostream>

using namespace std;

int main(void){
  bool flag = true;
  while(flag){
    int x, y;
    cin >> x >> y;
    if(x == 0 && y == 0) break;
    if(x < y){
      cout << x << " " << y << endl;
    } else {
      cout << y << " " << x << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 3068
#include <stdio.h>
#include <string.h>
int main(void){
    // Your code here!
    char c[11],s[11]={'\0'};
    int i;
    scanf("%s",c);
    for(i=0;c[i]!='\0';i++){
        if(c[i]=='B')
            s[strlen(s)-1]='\0';
        else
            s[strlen(s)]=c[i];
    }
    for(i=0;s[i]!='\0';i++)
        printf("%c",s[i]);
    printf("\n");
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <sstream>
#include <set>
#include <tuple>
#include <algorithm>
#include <memory>
#include <numeric>
#include <queue>
#include <functional>
#include <cmath>
#include <cstring>
#include <map>
#include <unordered_map>
#include <sstream>
#include <iomanip>

using namespace std;
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; }

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;

const ll INF = 1LL << 60;
const ll MOD = 1000000007;

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

	string S;
	cin >> S;

	if (S[2] == S[3] && S[4] == S[5])
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}
}


Measured memory_bytes: 256
/*
 * c.cc: 
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

/* typedef */

/* global variables */

/* subroutines */

/* main */

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

  int an = 0, bn = 0;

  for (int i = 0; i < n; i++) {
    string sa, sb;
    cin >> sa >> sb;

    if (sa > sb) an += 3;
    else if (sa < sb) bn += 3;
    else an++, bn++;
  }

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

Measured memory_bytes: 1212
#include <bits/stdc++.h>
using namespace std;
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define dbv(v) cerr << #v << "="; for (auto _x : v) cerr << _x << ", "; cerr << endl
#define dba(a, n) cerr << #a << "="; for (int _i = 0; _i < (n); ++_i) cerr << a[_i] << ", "; cerr << endl
typedef long long ll;
typedef long double ld;
vector<pair<int, int>> ans;
vector<int> E[100005];
int used[100005];
int go(int x, int p = -1) {
	int out = 0;
	used[x] = 1;
	for (int y : E[x]) {
		if (!used[y]) {
			int v = go(y, x);
			if (v & 1) ans.emplace_back(y, x);
			else {
				ans.emplace_back(x, y);
				out ^= 1;
			}
		} else if (used[y] == 1 && y != p) {
			ans.emplace_back(x, y);
			out ^= 1;
		}
	}
	used[x] = 2;
	return out;
}
int main() {
	int n, m;
	scanf("%d%d", &n, &m);
	for (int i = 0; i < m; ++i) {
		int a, b;
		scanf("%d%d", &a, &b);
		E[a].push_back(b);
		E[b].push_back(a);
	}
	int v = go(1);
	if (v == 1) printf("-1\n");
	else {
		assert(ans.size() == m);
		for (auto& a : ans) printf("%d %d\n", a.first, a.second);
	}
}


Measured memory_bytes: 15988
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T,class U> using P = pair<T,U>;
template<class T> using vec = vector<T>;
template<class T> using vvec = vector<vec<T>>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
 
int main(){
    ll h, w;
    cin >> h >> w;
    if (h==1 || w==1) {
        cout << 1 << endl; 
        return 0;
    }
    ll ans = ceil(h * w / 2.0);
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val input = sc.nextInt()
    var sum = 0

    var n = input
    sum += n % 10
    while (n / 10 != 0) {
        n /= 10
        sum += n % 10
    }

    if (input % sum == 0) {
        println("Yes")
    } else {
        println("No")
    }
}

Measured memory_bytes: 29604
min = 9999999
input()
balances = list(map(int, input().split()))
for i in range(1, len(balances)):
    S1=sum(balances[:i])
    S2=sum(balances[i:])

    if min > abs(S1-S2):
        min = abs(S1-S2)
print(min)


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

char judge()
{
  char cmap[3][3];
  for(int i=0;i<3;i++)
    for(int j=0;j<3;j++)
      cmap[i][j] = s[i*3+j];

  if(cmap[0][0] == cmap[1][0] && cmap[1][0] == cmap[2][0] && cmap[2][0] != 's')
    return cmap[0][0];

  if(cmap[0][1] == cmap[1][1] && cmap[1][1] == cmap[2][1] && cmap[2][1] != 's')
    return cmap[1][1];

  if(cmap[0][2] == cmap[1][2] && cmap[1][2] == cmap[2][2] && cmap[2][2] != 's')
    return cmap[0][2];

  if(cmap[0][0] == cmap[0][1] && cmap[0][1] == cmap[0][2] && cmap[0][0] != 's')
    return cmap[0][0];

  if(cmap[1][0] == cmap[1][1] && cmap[1][1] == cmap[1][2] && cmap[1][0] != 's')
    return cmap[1][0];

  if(cmap[2][0] == cmap[2][1] && cmap[2][1] == cmap[2][2] && cmap[2][0] != 's')
    return cmap[2][0];

  if(cmap[0][0] == cmap[1][1] && cmap[1][1] == cmap[2][2] && cmap[0][0] != 's')
    return cmap[0][0];

  if(cmap[2][0] == cmap[1][1] && cmap[1][1] == cmap[0][2] && cmap[2][0] != 's')
    return cmap[2][0];

  return 'd';
}

int main()
{
  while(cin >> s)
    {
      cout << judge() << endl;
    }
  return 0;
}

Measured memory_bytes: 1172
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;

void solve(int m){
    int up = m/100, down = m%100;
    if(up>=1 && up<=12 && down>=1 && down <=12){
        cout << "AMBIGUOUS" << endl;
    }
    else if((up>=1 && up<=12) && (down==0 || down>=13)){
        cout << "MMYY" <<endl;
    }
    else if((down>=1 && down<=12) && (up==0 || up>=13)){
        cout << "YYMM" <<endl;
    }
    else cout << "NA" << endl;
}

int main(){
    int n;
    cin >> n;
    solve(n);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef bool boool;
typedef long long ll;
#define vl vector<ll>
#define vb vector<boool>
#define vs vector<string>
#define vp vector<pair<ll, ll>>
#define vvl vector<vector<ll>>
#define vvp vector<vector<pair<ll, ll>>>
#define mod 1000000007
#define all(x) x.begin(), x.end()
#define rep1(i, n) for (long long i=0; i<(long long)(n); i++)
#define rep2(i, s, e) for (long long i=(s); i<(long long)(e); i++)
#define GET_MACRO(_1,_2,_3,NAME,...) NAME
#define rep(...) GET_MACRO(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)

int main(){
  int h, w, m;
  cin >> h >> w >> m;
  map<int, int> row;
  map<int, int> col;
  vector<map<int, int>> vec(300000);
  rep(i, m){
    int a, b;
    cin >> a >> b;
    a--; b--;
    row[a]++;
    col[b]++;
    vec[b][a]++;
  }
  int br = 0, bc = 0;
  vector<int> y, x;
  for(auto p : row){
    if(br<p.second){
      br = p.second;
      y.clear();
      y.push_back(p.first);
    }else if(br==p.second) y.push_back(p.first);
  }
  for(auto p : col){
    if(bc<p.second){
      bc = p.second;
      x.clear();
      x.push_back(p.first);
    }else if(bc==p.second) x.push_back(p.first);
  }
  for(auto dy : y){
    for(auto dx : x){
      if(vec[dx][dy] == 0){
        cout << br+bc << endl;
        return 0;
      }
    }
  }
  cout << br+bc-1 << endl;
  return 0;
}
    
    


Measured memory_bytes: 63696
#include <iostream>
#include <stack>
#include <vector>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
    long long int n;
    long long int k;
    while(cin>>n>>k){
    long long int sum=0;
    long long int i;
    if(k==0)cout<<n*n<<endl;
    else{
    for(i=k+1;i<=n;i++)
    {
        long long int q=n/i;
        long long int r=n%i;
        sum+=q*max((long long int)0,i-k);
        sum+=max((long long int)0,r-k+1);
    }
    cout<<sum<<endl;
    }
    }
    return 0;
}


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

  
int main(){
 int n;
  cin >> n;
  bool a=false;
 rep(i,26){
   rep(j,16){
     if(n==4*i+7*j) a=true;
   }
 }
  if(a) cout << "Yes" <<endl;
  else cout << "No" <<endl;
 }
  

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

int main(){
    int n;
    cin >> n;
    vector<int> S(n);
    for(int i = 0; i < n; i++){
        cin >> S[i];
    }
    int q;
    cin >> q;
    vector<int> T(q);
    for(int i = 0; i < q; i++){
        cin >> T[i];
    }
    int ans = 0;
    for(int i = 0; i < q; i++){
        for(int j = 0; j < n; j++){
            if(T[i] == S[j]){
                ans++;
                break;
            }
        }
    }

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


Measured memory_bytes: 3172
#include <iostream>
using namespace std;
int main(){
    int n;
    int in[200000];
    cin >> n;
    for(int i =0;i<n;i++){
        cin >> in[i];
    }
    int max;
    int minv = in[0];
    max = in[1] - in[0];
    for(int i=1;i<n-1;i++){
        if(minv > in[i]){
            minv = in[i];
        }
        int maxn = in[i+1] - minv;
        if(maxn > max){
            max = maxn;
        }
    }
    cout << max << endl;
    return 0;
}


Measured memory_bytes: 3864
from math import sqrt
n = int(input())
X = [0] * (n+1)
for x in range(1, int(sqrt(n)) + 1):
    for y in range(1, int(sqrt(n)) + 1):
        if x**2 + y**2 + x*y + 3 > n:
            break
        t = x**2 + y**2 + x*y
        for z in range(1, int(sqrt(n)) + 1):
            s = t + z**2 + y*z + z*x
            if s <= n:
                X[s] += 1
            else:
                break
print(*X[1:], sep='\n')

Measured memory_bytes: 9328
import bisect
s = input()
t = input()
d = { c: [] for c in t }
for i, c in enumerate(s):
  if c in d:
    d[c].append(i)
for dc in d.values():
  dc.sort()

n = -1
ans = 0


for j, c in enumerate(t):
  l = d[c]
  if l:
    i = bisect.bisect_right(l, n)
    if i == len(l):
      ans += len(s)
      n = l[0]
    else:
      n = l[i]
    if j == len(t) - 1:
      if i == len(l):
        ans += l[0] + 1
      else:
        ans += l[i]+1
  else:
    ans = -1
    break

print(ans)


Measured memory_bytes: 7540
#!/usr/bin/env python3
import sys


def solve(N: int, S: str):
    ord("Z")
    result = ""
    for s in S:

        if ord(s) + N > ord("Z"):
            result += chr(ord(s) + N - 26)
        else:
            result += chr(ord(s) + N)
    print(result)

    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    solve(N, S)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
typedef long long lint;
using namespace std;

lint a[55];
lint p[55];

lint ans(lint n,lint x)
{
	if(n==0)return 1;
	if(x==1)return 0;
	else if(x<=1+a[n-1])return ans(n-1,x-1);
	else if(x==1+a[n-1]+1)return p[n-1]+1;
	else if(x<=2*a[n-1]+2)return p[n-1]+1+ans(n-1,x-(1+a[n-1]+1));
	else if(x==2*a[n-1]+3)return 2*p[n-1]+1;
}

int main()
{
	lint N,X;
	
	cin >> N >> X;
	
	a[0]=1;
	p[0]=1;
	for(lint i=0;i<N;i++)
	{
		a[i+1]=2*a[i]+3;
		p[i+1]=2*p[i]+1;
	}
	
	cout << ans(N,X) << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-8;
const int inf=1e8;
int main(){
	int n,m;
	cin>>n>>m;
	vi dp(m+1);
	rep(i,n){
		int a,b;
		cin>>b>>a;
		for(int j=m+1;j>=0;j--)if(j+a<m+1){
			dp[j+a]=max(dp[j+a],dp[j]+b);
		}
	}
	cout<<dp[m]<<endl;
}

Measured memory_bytes: 3152
#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <set>
#include <string>
#include <iostream>
#include <cassert>
#include <cmath>
using namespace std;

int main() {
	int a, b;
	scanf("%d%d", &a, &b);
	puts(a <= 8 && b <= 8 ? "Yay!" : ":(");
        return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#pragma warning(disable : 4996)
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<time.h>
#include<random>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;++i)
#define REPR(i, n) for(int i = n-1;i >= 0;--i)
#define FOR(i, m, n) for(int i = m;i < n;++i)
#define FORR(i, m, n) for(int i = m-1;i >= n;--i)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define pb(a) push_back(a)
#define print(x) cout<<(x)<<'\n'
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define lb(v,n) lower_bound(v.begin(), v.end(), (n))
#define ub(v,n) upper_bound(v.begin(), v.end(), (n))
#define int long long
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i,v.size())cout << v[i] << ((i == v.size() - 1) ? "\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; }
typedef pair<int, int>P;
const int MOD = 1e9 + 7; const int MAX = 200020;
const double pi = acos(-1); const double EPS = 1e-12;
const ll INF = 1e18;

void solve() {
	int N; cin >> N;
	map<int, int>mp;
	REP(i, N) {
		int a; cin >> a;
		mp[a]++;
	}
	vector<int>v;
	for (auto x : mp) {
		int cnt = x.second;
		REP(i, cnt / 2) {
			v.push_back(x.first);
		}
	}
	VSORT(v); VREVERSE(v);
	if (v.size() < 2)print(0);
	else print(v[0] * v[1]);
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//int q; cin >> q;
	//while (q--)
	solve();
}


Measured memory_bytes: 6528
/*input
3
0 1 1
1 0 1
1 1 1
*/
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<long long, null_type, less_equal<long long>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#pragma GCC optimize("unroll-loops,no-stack-protector")
//order_of_key #of elements less than x
// find_by_order kth element
using ll = long long;
using ld = long double;
using pii = pair<ld,ld>;
#define f first
#define s second
#define pb push_back
#define REP(i,n) for(ll i=0;i<n;i++)
#define FILL(n,x) memset(n,x,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
#define sz(x) (int)x.size()
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
const ll INF64=4e18;
const int INF=1e6+1;
const ll MOD=1e9+7;
const ld PI=acos(-1);
const ld eps=1e-9;
#define lowb(x) x&(-x)
#define MNTO(x,y) x=min(x,(__typeof__(x))y)
#define MXTO(x,y) x=max(x,(__typeof__(x))y)
ll sub(ll a,ll b){
    ll x=a-b;
    while(x<0) x+=MOD;
    while(x>MOD) x-=MOD;
    return x;
}
ll mult(ll a,ll b){
    return ((a%MOD)*(b%MOD))%MOD;
}
ll mypow(ll a,ll b){
    if(b<=0) return 1;
    ll res=1LL;
    while(b){
        if(b&1) res=(res*a);
        if(res>1e10) return 1e11;
        a=(a*a);
        b>>=1;
    }
    return res;
}
const ll maxn=(1<<20);
const ll maxlg=__lg(maxn)+2;

int can[25][25];
int main(){
    int n;
    cin>>n;
    REP(i,n){
        REP(j,n){
            cin>>can[i][j];
        }
    }
    vector<ll> dp((1<<n),0);
    dp[0]=1;
        REP(msk,(1<<n)-1){
            int i=__builtin_popcount(msk);
            REP(b,n){
                if(can[i][b] and !(msk&(1<<b))){
                    int z=msk^(1<<b);
                    dp[z]+=dp[msk];
                    dp[z]%=MOD;
                }
            }
        }
    
    cout<<dp[(1<<n)-1];
}

Measured memory_bytes: 16640
#include<stdio.h>
#define WHITE 0
#define GRAY 1
#define BLACK 2
#define NUM 100

int M[NUM][NUM],color[NUM],d[NUM],f[NUM],time,n;

void visit(int u){
  int v;

  color[u] = GRAY;
  d[u] = time++;

  for(v = 0; v < n; v++){
    if(M[u][v] == 0)
       continue;
    
    if(color[v] == WHITE)
      visit(v);
  }

  color[u] = BLACK;
  f[u] = time++;
}

void dfs(){
  int u;

  for(u = 0; u < n; u++)
    color[u] = WHITE;

  time = 0;

  for(u = 0; u < n; u++){
    if(color[u] == WHITE)
      visit(u);
  }

   for(u = 0; u < n; u++)
    printf("%d %d %d\n", u+1, d[u]+1, f[u]+1);
}

int main(){
  
  int a,i,j,k,v;

  scanf("%d", &n);

  for(i = 0; i < n; i++){
    for(j = 0; j < n; j++){
      M[i][j] = 0;
    
    }
  }

  for(i = 0; i < n; i++){
    scanf("%d",&a);
    scanf("%d",&k);

    for(j = 0; j < k; j++){
      scanf("%d",&v);
      M[a-1][v-1] = 1;
    }
  }

  dfs();

 

  return 0;
}

Measured memory_bytes: 636
use std::io::Read;
use std::cmp::{max, min};

fn main(){
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    let s:Vec<char> = iter.next().unwrap().chars().collect();
    let n = s.len();
    let mut boundary = vec![];
    let mut last:char = 'L';
    for i in 0..n{
        if last == 'L' && s[i] == 'R'{
            boundary.push(i);
        }
        last = s[i];
    }
    let mut ans = vec![0usize;n];
    boundary.push(n);
    for i in 0..boundary.len()-1{
        let mut cnt = vec![0,0];
        let mut r = 0;
        let mut l = 0;
        for j in boundary[i]..boundary[i+1]{
            cnt[j%2] += 1;
            if s[j] == 'R' && s[j+1] == 'L'{
                r = j;
                l = j+1;
            }
        }
        ans[l] = cnt[l%2];
        ans[r] = cnt[r%2];
    }
    for v in ans{
        print!("{} ",v);
    }
}


Measured memory_bytes: 6524
# -*- coding: utf-8 -*-

import sys
import copy

sys.setrecursionlimit(1000000)


# input = sys.stdin.readline

# ~~~~~~~~~~~~~~~~~~~~~_(＾～＾ ｣ ∠)_~~~~~~~~~~~~~~~~~~~~~

def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x % y)


N = int(input())

A = [int(x) for x in input().split()]
B = list(reversed(A))

L = [0] * (N + 1)
R = [0] * (N + 1)

for i in range(N):
    L[i + 1] = gcd(L[i], A[i])

for i in range(N):
    R[i + 1] = gcd(R[i], B[i])

ans = 0
for i in range(N):
    ans = max(ans, gcd(L[i], R[N - i - 1]))

print(ans)


Measured memory_bytes: 67948
#include<iostream>
#include<string>
#include<algorithm>    
#include<cmath>
#include<map>
#include<vector>
#include<math.h>
#include<stdio.h>
#include<stack>
#include<queue>
#include<tuple>
#include<cassert>
#include<set>
//#include<bits/stdc++.h>
using ll = long long;
using namespace std;
const ll INF = 10000000000000000;
const ll mod = 1000000007;
signed main() {
	ll n, ans = 0; cin >> n;
	for (int h = 1; h <= 3500; h++) {
		for (int i = 1; i <= 3500; i++) {
			ll atai = 4 * h * i - n * i - n * h;
			if (atai > 0 && (n * h * i) % atai == 0) {
				cout << h << ' ' << i << ' ' << n * h * i / atai << endl;
				cin >> n; return 0;
			}
		}
	}
	cin >> n; return 0;
}

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

using namespace std;

#define MAX_N 101
#define MAX_M 21
typedef long long ll;

int main()
{
    int N;
    cin >> N; N--;
    vector<int> a(N);
    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }

    int x;
    cin >> x;
    
    ll dp[MAX_N][MAX_M] = {{}};
    dp[0][a[0]] = 1;

    for (int i = 1; i < N; i++) {
        for (int j = 0; j <= 20; j++) {
            if (j - a[i] >= 0) {
                dp[i][j-a[i]] += dp[i-1][j];
            }
            if (j + a[i] <= 20) {
                dp[i][j+a[i]] += dp[i-1][j];
            }
        }
    }
    cout << dp[N-1][x] << endl;
    return 0;
}

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

using namespace std;


const int MAX = 100005;
const int NIL = -1;
typedef long long ll;

struct Node { int p, l, r; };
Node T[MAX];
int n, D[MAX];

void print(int u) {
    cout << "node " << u << ": ";
    cout << "parent = " << T[u].p << ", ";
    cout << "depth = " << D[u] << ", ";
    
    if (T[u].p == NIL) cout << "root, ";
    else if (T[u].l == NIL) cout << "leaf, ";
    else cout << "internal node, ";

    cout << "[";
    for (int i = 0, c = T[u].l; c != NIL; i++, c = T[c].r) {
        if (i) cout << ", ";
        cout << c;
    }
    cout << "]" << endl;
}

int rec(int u, int p) {
    D[u] = p;
    if (T[u].r != NIL) rec(T[u].r, p);
    if (T[u].l != NIL) rec(T[u].l, p + 1);
}


int main() {
    cin >> n;
    for (int i = 0; i < n; i++)
        T[i].p = T[i].l = T[i].r = NIL;

    int l, r;
    for (int i = 0; i < n; i++) {
        int v, d;
        cin >> v >> d;
        for (int j = 0; j < d; j++) {
            int c;
            cin >> c;
            if (j == 0)
                T[v].l = c;
            else
                T[l].r = c;
            l = c;
            T[c].p = v;
        }
    }

    for (int i = 0; i < n; i++) {
        if (T[i].p == NIL)
            r = i;
    }

    rec(r, 0);
    for (int i = 0; i < n; i++)
        print(i);
    return 0;
}


Measured memory_bytes: 7708
import java.util.*;
 
class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    
    long sum = 0;
    
    for(int i=1;i<N+1;i++) {
      if(i%3 != 0 && i%5 != 0) {
        sum += i;
      }
    }
    System.out.println(sum);
  }
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
const int N = 3e5+50;
const ll oo = 1e18;
const ll mod = 1e9+7;

int main(){
    int n,m;
    scanf("%d%d",&n,&m);
    vector< pair < int , int > > v;
    for(int i=0;i<n;i++){
        int a,b;
        scanf("%d%d",&a,&b);
        v.push_back(make_pair(a,b));
    }
    int a[10];
    for(int i=0;i<10;i++)
        a[i]=i;
    int mn=1e9;
    do{
        int need=m;
        int S=0;
        for(int i=0;i<n;i++){
            for(int j=0;j<v[a[i]].first;j++){
                if(need-(ll((a[i]+1)*100)*ll(v[a[i]].first))>0){
                    need-=(ll((a[i]+1)*100)*ll(v[a[i]].first));
                    S+=v[a[i]].first;
                    need-=v[a[i]].second;
                    break;
                }
                if(need>0){
                    need-=((a[i]+1)*100);
                    S++;
                }
                else{
                    break;
                }
                if(j==v[a[i]].first-1)
                    need-=(v[a[i]].second);
            }
            if(need<=0)
                break;
        }
        mn=min(mn,S);
    }
    while(next_permutation(a,a+n));
    cout<<mn<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LOG(...) printf(__VA_ARGS__)
using namespace std;

int arr[100001];

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

    for (int i = 1; i <= N; ++i) {
        cin >> arr[i];
    }

    int swaps = 0;

    for (int i = 1; i <= N; ++i) {
        /*
        if (arr[i] == i && arr[i + 1] == i + 1) {
            int temp = arr[i + 1];
            arr[i + 1] = arr[i];
            arr[i] = temp;
            ++swaps;
        }
        */
        if (arr[i] == i) {
            int temp = arr[i + 1];
            arr[i + 1] = arr[i];
            arr[i] = temp;
            ++swaps;
        }
    }

    if (arr[N] == N) {
        ++swaps;
    }

    cout << swaps << endl;

    return 0;
}


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

using namespace std;
ll intpow(ll N, ll P){
    if(P==0) return 1;
    if(P%2==0){
        ll t = intpow(N, P/2);
        return t*t;
    }
    return N * intpow(N, P-1);
}
ll modpow(ll N, ll P,ll k){
    if(P==0) return 1;
    if(P%2==0){
        ll t = modpow(N, P/2,k)%k;
        return t*t%k;
    }
    return N * modpow(N, P-1,k)%k;
}
ll modkai(ll n,ll m,ll k){//n*(n-1)*(n-2)*...(m+1)%k
    if(n == m)return 1;
    return modkai(n-1,m,k)*n%k;
}
ll mod_cnb(ll n,ll m,ll k){//nCm%k,kは十分大きい素数
  int m_=modkai(m,0,k);
  return modkai(n,n-m,k)*modpow(m_,k-2,k)%k;
}
ll gcd(ll n,ll m){
    ll n_ = max(n,m);
    ll m_ = min(n,m);
    if(n_%m_ == 0)return m_;
    return gcd(m_,n_%m_);
}
ll lcm(ll n,ll m){
    return n*m/gcd(n,m);
}
int main(){
    ll x;cin>>x;
    cout << x/500*1000+x%500/5*5 <<endl;
}

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

int main() {

    
int h ,m,h2,m2,k,ans(0);
cin >> h >> m >> h2>> m2>>k;

  m = h * 60 + m;
  
  m2 = h2 * 60 + m2;
  
 ans = (m - m2)*-1 ;
  
   
    cout << ans - k;
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
//#define int long long
//io
#define s(x) scanf(" %d",&x)
#define si(x) scanf(" %d",&x)
#define sll(x) scanf(" %lld",&x)
#define sf(x) scanf(" %lf",&x)
#define ss(x) scanf(" %s",x)
#define sl(x) scanf(" %[^\n]",x)
#define sc(x) scanf("%c",&x)
#define p(x) printf(x)
#define pi(x) printf("%d",x)
#define ps(x) printf("%s",x)
#define pll(x) printf("%lld",x)
#define pf(x) printf("%lf",x)
#define pc(x) printf("%c",x)
#define endl "\n"
#define pn() printf("\n")
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL)
//loops
#define F(x,n) for(int i=x;i<n;i++)
#define Fr(x,n,c) for(int i=x;i<n;i+=c)
#define R(x,n) for(int j=x;j<n;j++)
#define Rr(x,n,c) for(int j=x;j<n;j+=c)
#define V(x,n) for(int k=x;k<n;k++)
#define Vr(x,n,c) for(int k=x;k<n;k+=c)
//ds
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
#define vi vector<int>
#define pb push_back
#define all(x) x.begin(),x.end()
#define test() int __T;scanf("%d",&__T);for(int __t=1;__t<=__T;__t++)
#define mem0(x) memset(x,0,sizeof(x))
#define memdp(x) memset(x,-1,sizeof(x))
#define mp(x,y) make_pair(x,y)

int32_t main() {
	int a,b;
 	cin>>a>>b;
  	if(a%b==0) cout<<a/b; else cout<<a/b+1;
	return 0;
}























Measured memory_bytes: 256
#define dbg(fmt,...) fprintf(stderr,fmt,__VA_ARGS__)
#define dpri(x) dbg(#x ": %d\n", x)
#define dprs(x) dbg(#x ": %s\n", x)
#include <stdio.h>
#include <stdlib.h>
typedef long long ll;
const int MYINF = 1e9+7;

const int nrtry = 30;

const int prtable[] = {
	2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61,
	67, 71, 73, 79, 83, 89, 97,
};
const int prtable_size = sizeof(prtable)/sizeof(int);

int gcd_rec(int x, int y) {
	if (y == 0) return x;
	return gcd_rec(y, x % y);
}

int gcd(int x, int y) {
	if (x < y) return gcd_rec(y, x);
	else return gcd_rec(x, y);
}

ll expmod(ll n, ll e, ll m) {
	ll nx;
	if (e == 1) {
		return n % m;
	} else if ((e % 2) == 0) {
		nx = expmod(n, e/2, m);
		return nx*nx % m;
	} else {
		nx = expmod(n, e - 1, m);
		return nx*(n%m) % m;
	}
}

int is_prime(int x) {
	int i, a;
	if (x < 2) return 0;
	for (i = 0; i < prtable_size && prtable[i] <= x; i++) {
		if (x == prtable[i]) return 1;
	}

	for (i = 0; i < nrtry; i++) {
try_again:
		a = random() % x;
		if (a < 3) goto try_again;
		if (gcd(a, x) != 1) return 0;
		if (expmod(a, x - 1, x) != 1LL) return 0;
	}

	return 1;
}

int main(int argc, char **argv)
{
	int i, n, x, count = 0;

	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%d", &x);
		if (is_prime(x)) count++;
	}
	printf("%d\n", count);

	return 0;
}

Measured memory_bytes: 596
#include <iostream>

using namespace std;

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

	int ans = 0;
	for (int x = 0; x <= k; x++) {
		for (int y = 0; y <= k; y++) {
			int z = s - x - y;
			if (z < 0 || z > k)  continue;
			ans++;
		}
	}
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B,C,D,E;
  cin >> A >> B >> C >> D >> E;
  if(A==0){
    cout << 1 <<endl;
  }
  if(B==0){
    cout << 2 <<endl;
  }
  if(C==0){
    cout << 3 <<endl;
  }
  if(D==0){
    cout << 4 <<endl;
  }
  if(E==0){
    cout << 5 <<endl;
  }
}

Measured memory_bytes: 3592
import * as fs from "fs";

let [N_str, ...uvw_str] = fs.readFileSync("/dev/stdin", "utf8").trim().split('\n');

let N = Number(N_str);
let colors: boolean[] = new Array(N).fill(false);


type weight = number;
let tree: Map<number, [number, weight][]> = new Map();

for(let i=0; i<N-1; i++) {
    // u < v
    let [u, v, w] = uvw_str[i].split(' ').map(Number);
    u -= 1;
    v -= 1;
    for(let [p, child] of [[u, v], [v, u]]) {
        if (!tree.has(p)) {
            tree.set(p, []);
        }
        tree.get(p).push([child, w]);
    }
}

let stack: [number, number | null][] = [[0, null]]; // list of pair of (node, parent)

while (stack.length != 0) {
    let [node, prev] = stack.pop()
    if (tree.has(node)) {
        for(let [child, weight] of tree.get(node)) {
            if (child == prev)
                continue;
            if (weight%2 == 0) {
                colors[child] = colors[node];
            } else {
                colors[child] = !colors[node];
            }
            stack.push([child, node]);
        }
    }
}

for(let i=0; i<N; i++) {
    console.log((colors[i]?0:1));
}


Measured memory_bytes: 113388
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define mod 1000000007
#define pb push_back
#define endl "\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)

signed main(){
	fast;
	int a,b;
	cin>>a>>b;
	int k=(a+b)/2;
	if(abs(a-k)==abs(b-k)){
		cout<<k;
	}
	else{
		cout<<"IMPOSSIBLE";
	}
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
#define ll long long
#define FOR(i, n, m) for(int i=n; i<m; ++i)

int main(){
  int N, A, B;
  cin >> N >> A >> B;

    
  cout << min(N*A, B) << endl;
}

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

int main() {
  
  string a;
  cin >> a;
  
  if (a=="SUN"){
    cout << 7 << endl;
  }
  else if (a=="MON"){
    cout << 6 << endl;
  }
  else if (a=="TUE"){
    cout << 5 << endl;
  }
  else if (a=="WED"){
    cout << 4 << endl;
  }
  else if (a=="THU"){
    cout << 3 << endl;
  }
  else if (a=="FRI"){
    cout << 2 << endl;
  }
  else {
    cout << 1 << endl;
  }
}


Measured memory_bytes: 256
def seach (place, ary, dist, top, last)
  half = (last+top)/2
  if place < ary[half]
    seach(place, ary, dist, top, half-1)
  elsif ary[half+1] < place
    seach(place, ary, dist, half+2, last)
  else 
    pa = place - ary[half]
    ap = ary[half+1] - place
    if pa < ap
      return pa
    end
    return ap
  end
end

d = gets.chomp.to_i #??¨???
while d != 0  
  n = gets.chomp.to_i #????????°
  m = gets.chomp.to_i #??¨?????°

  dAry = [] #????????????
  dAry[0] = 0
  for i in 1..n-1
    dAry[i] = gets.chomp.to_i
  end
  dAry[dAry.length] = d
  dAry = dAry.sort

  sum = 0
  kAry = [] #?????????
  for i in 0..m-1
    j = gets.chomp.to_i
    sum += seach(j, dAry, d, 0, dAry.length-1)
  end
  
  puts sum

  d = gets.chomp.to_i #??¨???
end

Measured memory_bytes: 11104
#include<bits/stdc++.h>
using namespace std;
int is_palindrome(int n){
	vector<int >nos(5,0);
  int i=0;
  while(i<=4){
  	nos[i] = n%10;
    n/=10;
    i++;
  }
  if(nos[0]!=nos[4] || nos[1]!=nos[3])return 0;
  else return 1;
}
int main(){
	int a,b;
  cin>>a>>b;
  int tot=0;
  for(int i=a;i<=b;i++){
  	if(is_palindrome(i))tot++;
  }
  cout<<tot;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n int
	fmt.Scan(&n)
	if n < 3 {
		fmt.Println(0)
		return
	}
	l := make([]int, n)
	for i := range l {
		fmt.Scan(&l[i])
	}
	var ans int
	ansArr := map[[3]int]int{}
	for i := range l {
		for j := range l {
			for z := range l {
				if l[i] == l[z] || l[z] == l[j] || l[i] == l[j]{
					continue
				}
				xxxx := []int{l[i], l[j], l[z]}
				temp_xxxx := []int{xxxx[0], xxxx[1], xxxx[2]}
				sort.Ints(temp_xxxx)
				if temp_xxxx[0] + temp_xxxx[1] > temp_xxxx[2] {
					ansArr[[3]int{i, j, z}]++
				}
			}
		}
	}

	for _ = range ansArr {
		ans++
	}

	fmt.Println(ans/6)
}

Measured memory_bytes: 170848
#include <iostream>
#include <vector>
#include <cassert>
#include <cmath>

using ll = long long;
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) < (b)) ? (b) : (a))

int main() {
  int n;
  std::cin >> n;
  int even = 0, odd = 0;
  for(int i = 1;i <= n; i++) {
    int val;
    std::cin >> val;
    if(val % 2 == 0)
      even++;
    else
      odd++;
  }
  even += odd / 2;
  odd %= 2;
  if(0 < even && 0 < odd)
    std::cout << "NO";
  else
    std::cout << "YES";
  return 0;
}


Measured memory_bytes: 3600
#include<iostream>
#include<cstdio>
using namespace std;
struct Tree{
	int father,weight;
} node[200001];
int main(){
	node[1].father=-1;
	int n,q;
	scanf("%d %d",&n,&q);
	for(int i=1;i<n;i++){
		int a,b;
		scanf("%d %d",&a,&b);
		node[b].father=a;
	}
	for(int i=1;i<=q;i++){
		int v,w;
		scanf("%d %d",&v,&w);
		node[v].weight+=w;
	}
	for(int i=1;i<=n;i++){
		node[i].weight+=node[node[i].father].weight;
		printf("%d ",node[i].weight);
	}
	return 0;
}

Measured memory_bytes: 3968
import kotlin.math.abs

fun main() = Thread(null, ::abc173e, "(^o^)", 128 * 1024 * 1024).apply { start() }.join()

@OptIn(ExperimentalStdlibApi::class)
fun abc173e() {
    val (n, k) = readLine()!!.split(' ').map { it.toInt() }
    val aList = readLine()!!.split(' ').map { it.toLong() }

    if (k == n) return println(aList.fold(Mint(1), Mint::times))

    val (positives, negatives) = aList
        .sortedByDescending { abs(it) }.partition { it > 0 }.toList().map { ArrayDeque(it) }

    var answer = Mint(1)

    if (k % 2 != 0) {
        if (positives.isEmpty()) return println(negatives.takeLast(k).fold(Mint(1), Mint::times))
        else answer *= positives.removeFirst()
    }

    repeat(k / 2) {
        when {
            positives.size >= 2 && negatives.size >= 2 -> {
                val pos = positives.take(2).reduce(Long::times)
                val neg = negatives.take(2).reduce(Long::times)
                if (pos > neg) {
                    answer *= pos
                    repeat(2) { positives.removeFirst() }
                } else {
                    answer *= neg
                    repeat(2) { negatives.removeFirst() }
                }
            }
            positives.size >= 2 -> answer *= positives.removeFirst() * positives.removeFirst()
            negatives.size >= 2 -> answer *= negatives.removeFirst() * negatives.removeFirst()
            else -> error("なんで？")
        }
    }

    println(answer)
}

private const val MOD = 1_000_000_007L

@Suppress("unused")
private class Mint(value: Long = 0L) {
    constructor(other: Mint) : this(other.value)

    private val value = if (value < 0) (value % MOD) + MOD else value % MOD
    operator fun unaryPlus() = this
    operator fun unaryMinus() = Mint(MOD - this.value)
    operator fun inc() = this.plus(1)
    operator fun dec() = this.minus(1)
    operator fun plus(other: Long) = Mint(this.value + other)
    operator fun plus(other: Mint) = this.plus(other.value)
    operator fun minus(other: Long) = Mint(this.value - other)
    operator fun minus(other: Mint) = this.plus(-other)
    operator fun times(other: Long) = Mint(this.value * (other % MOD))
    operator fun times(other: Mint) = this.times(other.value)
    operator fun div(other: Long) = this.times(modPow(other, MOD - 2))
    operator fun div(other: Mint) = this.div(other.value)
    fun mod(mod: Long) = Mint(this.value % mod)
    fun modPow(other: Long) = Mint(modPow(this.value, other))
    fun toLong() = this.value
    override fun toString() = this.value.toString()
    override fun hashCode() = value.hashCode()
    override fun equals(other: Any?): Boolean {
        if (this === other) return true
        if (javaClass != other?.javaClass) return false
        other as Mint
        return value == other.value
    }

    companion object {
        private fun modPow(n: Long, p: Long): Long {
            var x = n % MOD
            var y = p
            var result = 1L
            while (y > 0) {
                if (y % 2 == 1L) result = (result * x) % MOD
                y = y shr 1
                x = (x * x) % MOD
            }
            return result
        }
    }
}


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

using namespace std;

const long long INF = 1e18+5;

int main(){
	int n; int W; scanf("%d%d",&n,&W);
	vector<int> w(n), v(n);

	long long sum = 0;
	for(int i = 0; i < n; i++){
		scanf("%d%d",&w[i],&v[i]);
		sum += v[i];
	}
    //cout << sum << endl;
	vector<long long> dp(sum+1,INF);
    dp[0] = 0;
	//dp[i] -> minimum weight required to attain value i exactly
	for(int i = 0; i < n; i++){
		for(int j = sum-v[i]; j >= 0; j--){
            //cout << min(dp[j+v[i]], dp[j]+w[i]) << endl;
			dp[j+v[i]] = min(dp[j+v[i]], dp[j]+w[i]);
		}
	}
    
    //for(int i = 0; i <= sum; i++) cout << dp[i] << endl;

	long long res = -1;
	for(long long i = 0; i <= sum; i++){
		if(dp[i] <= W)
			res = max(res,i);
	}

	cout << res << endl;
}

Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int main()
{
    int i, j, k, A[3]={0}, n, m;
    m=101;
    for (i=0; i<3; i++)
    {
        cin >> A[i];
    }
    for (i=0; i<3; i++)
    {
        for (j=0; j<3; j++)
        {
            for (k=0; k<3; k++)
            {
                n=0;
                if (A[i]-A[j]<0)
                {
                    n=n-(A[i]-A[j]);
                }
                else
                {
                    n=n+(A[i]-A[j]);
                }
                if (A[j]-A[k]<0)
                {
                    n=n-(A[j]-A[k]);
                }
                else
                {
                    n=n+(A[j]-A[k]);
                }
                if (n<m && i!=j && j!=k && i!=k)
                {
                    m=n;
                }
            }
        }
    }
    cout << m;
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace a
{
    class Program
    {
        static void Main(string[] args)
        {

            var a = int.Parse(Console.ReadLine());
            var b = int.Parse(Console.ReadLine());
            var c = int.Parse(Console.ReadLine());
            var d = int.Parse(Console.ReadLine());
            var e = int.Parse(Console.ReadLine());
            var k = int.Parse(Console.ReadLine());

            List<int> v = new List<int> { a, b, c, d, e };

            bool ok = true;
            foreach (int i in v)
            {
                foreach (int j in v)
                {
                    if (Math.Abs(i - j) > k)
                        ok = false;
                }
            }
            Console.WriteLine(ok ? "Yay!" : ":(");
        }
    }
}


Measured memory_bytes: 13140
from collections import deque

n = int(input())

dlist = deque()

for i in range(n):
    arr = input().split()
    cmd = ''
    key = 0
    cmd = arr[0]
    if len(arr) > 1:
        key = arr[1]
    if cmd == 'insert':
        dlist.appendleft(key)
    elif cmd == 'delete':
        try:
            dlist.remove(key)
        except:
            continue
    elif cmd == 'deleteFirst':
        dlist.popleft()
    elif cmd == 'deleteLast':
        dlist.pop()

print(' '.join(dlist))




Measured memory_bytes: 69736
import static java.lang.Math.*;
import static java.util.Arrays.*;
import java.util.*;//ScannerNXÌC|[g

public class Main {
	
	static Scanner sc = new Scanner(System.in);
	static int[] a;
	//static int n;
	
	public static void main(String[] args) {
	//n = sc.nextInt();
	//while(n-- > 0 && read()) {
		read();
		solve();
		
		/*while(read()) {
			solve();
		}*/
		
	}
	
	static boolean read() {
	//±±ÅüÍðÇÝÞ
		a = new int[10];
		Scanner sc = new Scanner(System.in);	
		int sum = 0;
		for(int i = 0; i < 10; i++) {
			a[i] = sc.nextInt();
		}
		return true;
	}
	
	static void solve() {
			//±±Åâèðð¢ÄoÍ·é
	sort(a);

	for(int i = 9; i > 6; i--){
		System.out.println(a[i]);
	}
	
	}
}

Measured memory_bytes: 11000
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>
#include <numeric>

using namespace std;

#define mod 1000000007

int main()
{
	int n;
	cin >> n;
	char s[301][301];
	for(int i = 0; i < n; i++){
		for(int j = 0; j < n; j++){
			cin >> s[i][j];
		}
	}
	long long int ans = 0;
	for(int a = 0; a < n; a++){
		bool ok = true;
		for(int i = 0; i < n; i++){
			for(int j = 0; j < n; j++){
				if(s[(i - a + n) % n][j] != s[(j - a + n) % n][i]) ok = false;
			}
		}
		if(ok) ans += n;
	}
	cout << ans << endl;
}

Measured memory_bytes: 384
require 'set'; require 'prime'; require 'pp'
INF=Float::INFINITY; MOD=10**9+7
n = gets.chomp.to_i
a = gets.chomp.split.map(&:to_i)

r = 0
ans = 0
sum = 0

n.times do |l|
  while r < n && (sum ^ a[r]) == (sum + a[r])
    sum += a[r]
    r += 1
  end

  ans += r - l
  if l == r
    r += 1
  else
    sum -= a[l]
  end
end
puts ans




Measured memory_bytes: 28668
#include <stdio.h>
#include <algorithm>
#include <math.h>

using namespace std;

bool rangeCheck(int row,int col){
	if(row >= 0 && row <= 7 && col >= 0 && col <= 7)return true;
	else{
		return false;
	}
}

void bomb(char table[8][9],int row,int col){
	table[row][col] = '0';

	for(int i=1; i <=3; i++){
		if(rangeCheck(row,col-i)&&table[row][col-i] == '1')bomb(table,row,col-i);
		if(rangeCheck(row,col+i)&&table[row][col+i] == '1')bomb(table,row,col+i);
		if(rangeCheck(row-i,col)&&table[row-i][col] == '1')bomb(table,row-i,col);
		if(rangeCheck(row+i,col)&&table[row+i][col] == '1')bomb(table,row+i,col);
	}
}

int main(){

	int n,row,col,count = 1;
	char table[8][9];

	scanf("%d",&n);
	getchar();

	for(int i=0;i<n;i++){
		for(int k=0;k < 8; k++){
			scanf("%s",table[k]);
		}

		scanf("%d",&col);
		scanf("%d",&row);
		getchar();
		row = row-1;
		col = col-1;
		bomb(table,row,col);

		printf("Data %d:\n",count++);
		for(int k = 0; k < 8; k++){
			printf("%s\n",table[k]);
		}
	}

	return 0;
}

Measured memory_bytes: 2616