akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		long power = 1;

		for (int i = 1; i <= N; i++) {
			power *= i;
			power %= 1000000007;
		}
		System.out.println(power);
	}
}


Measured memory_bytes: 23764
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
 
using namespace std;
 
typedef long long ll;
typedef pair<int,int> pii;
const int INF = 987654321;
const int MOD = 1000000007;
 
ll XOR(ll x){
  if(x % 4 == 0) return x;
  if(x % 4 == 1) return 1;
  if(x % 4 == 2) return x^1;//改変部
  if(x % 4 == 3) return 0;
  return -1;
}
 
int main(){
  ll A,B;
  scanf("%lld %lld",&A,&B);
  if(A == 0) A = 1;
  ll ans = XOR(A-1)^XOR(B);
  if(A == 0) printf("%lld\n",ans^0);
  else printf("%lld\n",ans);
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <math.h>
#include <numeric>

using namespace std;

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

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


int main(){
	int N;

	cin >>N;

	cout << (N-2) * 180 << endl;


}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

vector<int> a(1001,1);
void prime_factor(int n){
	for(int i = 2; i*i <= n; i++) {//約数列挙
		while(n % i == 0){
			a[i]++;
			n /= i;
		} 
	}
	if (n != 1){
		a[n]++;
	}
}
int main(){
	int n;
	cin >> n;
	for(int i = 1; i <= n; i++) {//n!の要素についてそれぞれ素因数分解
		prime_factor(i);
	}
	ll ans = 1;
	for(int i = 0; i <= 1000; i++) {//掛け合わせる
		ans *= a[i];
		ans %= mod;
	}
	cout << ans % mod << endl;
	return 0;
}

Measured memory_bytes: 256
N = int(input())
matrix = [[0 for _ in range(9)] for _ in range(9)]
# print(matrix)
for i in range(1, N + 1):
    s = str(i)
    row = int(s[0])
    column = int(s[-1])
    if row == 0 or column == 0:
        continue
    matrix[row - 1][column - 1] += 1
# pprint(matrix)
ans = 0
for i in range(9):
    for j in range(9):
        # if i == j:
        #     ans += matrix[i][j]
        # else:
        #     ans += matrix[i][j] * matrix[j][i]
        ans += matrix[i][j] * matrix[j][i]
print(ans)


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

#define REP(i, n) for(int i = 0;i < n;i++)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define ALL(a) (a).begin(), (a).end()

using namespace std;

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

    int sum = 0;

    bool before = false;

    REP(i, N)
    {
        int n;
        cin >> n;

        if( i + 1 == n )
        {
            if( before )
            {
                sum++;
                before = false;
            }
            else
            {
                before = true;
            }
        }
        else
        {
            if( before )
            {
                sum++;
                before = false;
            }
        }
    }

    if( before ) sum++;

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll
#define INF 1e16
#define mod 1000000007
int main(){
    ll x,y,z,k;
    cin>>x>>y>>z>>k;
    vector<ll> a,b,c,ab,abc;
    a.resize(x);b.resize(y);c.resize(z);
    rep(i,x) cin>>a[i];
    rep(i,y) cin>>b[i];
    rep(i,z) cin>>c[i];
    rep(i,x)rep(j,y) ab.push_back(a[i]+b[j]);
    sort(all(ab));
    reverse(all(ab));
    ll cnt =0;
    if(3000<x*y) cnt = 3000;
    else cnt = x*y;
    rep(i,cnt)rep(j,z) abc.push_back(ab[i]+c[j]);
    sort(all(abc));
    reverse(all(abc));    
    rep(i,k) cout<<abc[i]<<endl;
    return 0;
}

Measured memory_bytes: 42984
/* 
* ID: juryc
* PROG: Flatten
* LANG: C++
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod=1e9+7;
const int N = 1e6+1;
vector<int> mp(N,0);
vector<int> primes(N); 
ll gcd(ll a,ll b){
if(b==0) return a;
return gcd(b,a%b); 
}
ll powmod(ll a,ll b){
ll res=1; a%=mod;
while(b){
if(b&1) res=(res*a)%mod;
a=(a*a)%mod;
b>>=1;
}
return res;
} 
ll sieve(){
ll res=1;
fill(primes.begin(),primes.end(),1); 
primes[0]=primes[1]=0; 
for(int i=2;i<N;i++){
if(primes[i]){
ll mx=0;
for(int j=i;j<N;j+=i){
primes[j]=0;
if(mp[j]){
ll cnt=0; ll tmp=j;
while(tmp%i==0){
cnt++,tmp/=i;
}
mx=max(mx,cnt); 
}
}
res=(res*powmod(i,mx))%mod;
}
}
return res;
}
int main(){
ll n; cin>>n;
vector<ll> v(n); 
for(ll& i : v) {cin>>i; mp[i]=1; }
ll lcm=sieve(),ans=0;
for(ll i: v){
ans=(ans+(lcm*powmod(i,mod-2))%mod)%mod;
}
cout<<ans<<"\n"; 
return 0;
}

 


Measured memory_bytes: 10956
#include <iostream>
#include <map>
#include <set>
#include <vector>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;

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

template<class T, class U> inline int divCount(T &num, U divisor) {
    int count = 0;
    while (num % divisor == 0) {
        num /= divisor;
        count++;
    }
    return count;
}

void solve(long long N, std::vector<long long> A){
    int ans = 1001001001;
    REP(i, N)
        chmin(ans, divCount(A[i], 2));
    cout << ans << '\n';
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, std::move(A));
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String key = in.next().toLowerCase();
        int count = 0;
        while(true) {
            String input = in.next();
            if(input.equals("END_OF_TEXT")) break;
            if(input.equalsIgnoreCase(key)) count++;
        }
        System.out.println(count);
    }
}

Measured memory_bytes: 18056
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class Main {

	/**
	 * @param args
	 * @throws IOException 
	 * @throws NumberFormatException 
	 */
	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		System.out.println("ABC"+Integer.parseInt(br.readLine()));
	}

}


Measured memory_bytes: 22996
fun main(args: Array<String>) {
    agc005a()
}

fun agc005a() {
    val x = readLine()!!.map { it == 'T' }

    var remainS = 0
    var remainT = 0
    x.forEach { isT ->
        if (isT) {
            if (remainS > 0) remainS-- else remainT++
        } else {
            remainS++
        }
    }

    println(remainS + remainT)
}


Measured memory_bytes: 34500
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;

typedef pair<int, int> P;
typedef pair<int, P> PP;
int num[111];

int main()
{
  int n, m, a;
  while(cin >> n >> m >> a, n || m || a) {
    vector<PP> amida(m);
    FOR(i,0,m) {
      int h, p, q; cin >> h >> p >> q;
      amida[i] = PP(h, P(p, q));
    }
    sort(amida.begin(), amida.end());
    FOR(i,0,n+1) num[i] = i;
    FOR(i,0,m) {
      swap(num[amida[i].second.first], num[amida[i].second.second]);
    }
    cout << num[a] << endl;
  }
  return 0;
}

Measured memory_bytes: 3100
class BinaryIndexedTree:
  def __init__(self, size):
    self.data = [0] * (size+1)
    self.size = size
  
  def add(self, i, w):
    while i <= self.size:
      self.data[i] += w
      i += i & -i

  def sum(self, i):
    result = 0
    while i > 0:
      result += self.data[i]
      i -= i & -i
    return result

from itertools import accumulate,repeat

N,K = map(int, input().split())

B = [0] + [sa-sk for sa,sk in zip(accumulate(int(input()) for _ in range(N)), accumulate(repeat(K)))]

lookup = dict(((b,i+1) for i,b in enumerate(sorted(B))))

result = 0
bit = BinaryIndexedTree(N+1)

for b in B:
  c = lookup[b]
  result += bit.sum(c)
  bit.add(c,1)

print(result)

Measured memory_bytes: 39576
#include <stdio.h>
#include <algorithm>
using namespace std;
typedef long long ll;
int arr[3][100001];
int ptr[3];
int siz[3];
int len[2];
int main(){
	scanf("%d %d %d %d %d",len,len+1,siz,siz+1,siz+2);
	for(int j=0;j<3;j++){
		for(int i=0;i<siz[j];i++) scanf("%d",arr[j]+i);
		sort(arr[j],arr[j]+siz[j]);
	}
	ptr[0] = siz[0] - len[0];
	ptr[1] = siz[1] - len[1];
	for(int i=siz[2]-1;i>=0;i--){
		if(ptr[0]<siz[0]&&ptr[1]<siz[1]){
			if(arr[0][ptr[0]]<arr[1][ptr[1]]){
				if(arr[2][i]>arr[0][ptr[0]]){
					arr[0][ptr[0]++] = arr[2][i];
				}
			}
			else{
				if(arr[2][i]>arr[1][ptr[1]]){
					arr[1][ptr[1]++] = arr[2][i];
				}
			}
		}
		else if(ptr[0]<siz[0]){
			if(arr[2][i]>arr[0][ptr[0]]){
				arr[0][ptr[0]++] = arr[2][i];
			}
		}
		else if(ptr[1]<siz[1]){
			if(arr[2][i]>arr[1][ptr[1]]){
				arr[1][ptr[1]++] = arr[2][i];
			}
		}
	}
	ll sum = 0;
	for(int j=0;j<2;j++){
		for(int i=0;i<len[j];i++) sum += arr[j][siz[j]-1-i];
	}
	printf("%lld",sum);
}

Measured memory_bytes: 1280
/*
phu lki ...
*/

#include<bits/stdc++.h>
#define mod 1000000007
#define pp pair<long long,long long>
#define ll long long
#define ff first
#define ss second
#define horse_power ios_base::sync_with_stdio(false); cin.tie(NULL);

using namespace std;
ll n,k;

void solve(){
   cin>>n;
   ll h[n+1][3],dp[n+1][3]={0};
   for(int i=1;i<=n;i++)
      cin>>h[i][0]>>h[i][1]>>h[i][2];

   for(int i=1;i<=n;i++)
   {   dp[i][0]=h[i][0]+max(dp[i-1][1],dp[i-1][2]);
       dp[i][1]=h[i][1]+max(dp[i-1][0],dp[i-1][2]);
        dp[i][2]=h[i][2]+max(dp[i-1][0],dp[i-1][1]);
   }
   cout<<max(max(dp[n][0],dp[n][1]),dp[n][2])<<"\n";


}

int main(){
horse_power
int t=1;
//cin>>t;
while(t--){
solve();
}


}


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

int main() {
  int A, B;
  cin >> A >> B;
  cout << 6 - A - B << endl;
}


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

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

int main() {
	ll w, h, n, x, y, a;
	ll ans = 0;

	cin >> w >> h >> n;

	ll x1 = 0;
	ll x2 = w;
	ll y1 = 0;
	ll y2 = h;

	REP(i, n) {
		cin >> x >> y >> a;

		if (a == 1) {
			x1 = max(x1, x);
		}
		else if (a == 2) {
			x2 = min(x2, x);
		}
		else if (a == 3) {
			y1 = max(y1, y);
		}
		else if (a == 4) {
			y2 = min(y2, y);
		}
	}

	if (x2 - x1 > 0 && y2 - y1 > 0) {
		ans = (x2 - x1) * (y2 - y1);
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
k, n = map(int, input().split())
a = list(map(int, input().split()))

d = [0]*n
for i in range(n):
    if i == n-1:
        d[n-1] = (k-a[n-1]) + a[0]
        
    else :
        d[i] = a[i+1] - a[i]

d.sort()
d[n-1] = 0

print(sum(d))

Measured memory_bytes: 32288
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
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;
  }
};

int main() {
  mint ans=1;
  int n;
  cin >> n;
  int now=0;
  string s;
  cin >> s;
  rep(i,n){
    if(s[i]==s[i+1]){
      if(now==0) ans*=6;
      if(now==1) ans*=2;
      if(now==2) ans*=3;
      now=2;
      i++;
    }
    else{
      if(now==0) ans*=3;
      if(now==1) ans*=2;
      if(now==2) ans*=1;
      now=1;
    }
  }
  cout << ans.x << endl;
      
  
}


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

#define REP(i, n) for(ll i = 0; i < n; i++)
#define ALL(x) (x).begin(),(x).end()
#define MSG(x) cout << x << endl;
#define YN(x) x ? cout << "YES" << endl : cout << "NO" << endl;
#define Yn(x) x ? cout << "Yes" << endl : cout << "No" << endl;
#define yn(x) x ? cout << "yes" << endl : cout << "no" << endl;

using namespace std;
using ll = long long;

int main(int argc, char *argv[]) {
    ll x;
    cin >> x;

    ll ans = 1;
    for (int b = 2; b <= sqrt(x); ++b) {
        ll p = 2;
        while (pow(b, p) <= x) p++;
        p--;

        ans = max(ans, (ll)pow(b, p));
    }

    MSG(ans)
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <vector>
#include <algorithm>
#include <set>

using namespace std;

int main(){
    int h,w,m;
    scanf("%d %d %d", &h, &w, &m);
    vector<pair<int,int>> viiMine;
    vector<int> viHeightCount(h+1, 0);
    vector<int> viWidthCount(w+1, 0);
    for(int i = 0; i < m; i++){
        int a,b;
        scanf("%d %d", &a, &b);
        viHeightCount[a]++;
        viWidthCount[b]++;
        viiMine.push_back(make_pair(a,b));
    }
  
    int hMax = 0;
    long hCount = 0;
    for(int i = 1; i <= h; i++){
        hMax = max(hMax, viHeightCount[i]);
    }
    set<int> siHeightMaxPoint;
    for(int i = 1; i <= h; i++){
        if(hMax == viHeightCount[i]){
            siHeightMaxPoint.insert(i);
            hCount++;
        }
    }
    
    int wMax = 0;
    long wCount = 0;
    for(int i = 1; i <= w; i++){
        wMax = max(wMax, viWidthCount[i]);
    }
    set<int> siWidthMaxPoint;
    for(int i = 1; i <= w; i++){
        if(wMax == viWidthCount[i]){
            siWidthMaxPoint.insert(i);
            wCount++;
        }
    }
    
    long iIntersectionCount = 0;
    for(int i = 0; i < m; i++){
        int a = viiMine[i].first;
        int b = viiMine[i].second;
        if(siHeightMaxPoint.find(a) != siHeightMaxPoint.end() && 
           siWidthMaxPoint.find(b) != siWidthMaxPoint.end()){
            iIntersectionCount++;
        }
    }

    if(iIntersectionCount == hCount * wCount){
        printf("%d", hMax+wMax-1);
    } else {
        printf("%d", hMax+wMax);
    }
    return 0;
}


Measured memory_bytes: 35772
#include <iostream>
#include <vector>
#include <algorithm>
int dp[200001][2] = { 0 };

int main() {
	int n, m;
	std::vector<std::pair<int, int>> robot;

	std::cin >> n >> m;
	robot.reserve(m);
	for (int i = 0; i < m; i++) {
		int x, y; std::cin >> x >> y;
		robot.push_back(std::make_pair(x, y));
	}
	std::sort(robot.begin(), robot.end());

	for (auto& x : robot) {
		dp[x.second][1] = dp[x.second + 1][1] + 1;
		dp[x.second + 1][0] = dp[x.second][0] + 1;
	}

	for (int i = 1; i <= n; i++) {
		std::cout << dp[i][0] + dp[i][1] + 1;
		if (i != n) std::cout << " ";
	}
	std::cout << std::endl;
	return 0;
}


Measured memory_bytes: 5268
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#include <cmath>
#include <chrono>

using namespace std;

const int64_t INF = 1e+18;

struct edge {
    int from, to;
    int64_t weight;
};

bool Bellman_Ford(int s, vector<edge> &es, vector<int64_t> &d) {
    fill(d.begin(), d.end(), INF);
    d[s] = 0;
    for (int i = 0; i < d.size(); i++) {
        for (int j = 0; j < es.size(); j++) {
            edge e = es[j];
            if (d[e.from] != INF && d[e.to] > d[e.from] + e.weight) {
                d[e.to] = d[e.from] + e.weight;
                if (i == d.size() - 1) return true;
            }
        }
    }
    return false;
}

int main(int argc, const char * argv[]) {
    
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int V, E, s; cin >> V >> E >> s;
    vector<edge> es(E);
    for (int i = 0; i < E; i++) {
        cin >> es[i].from >> es[i].to >> es[i].weight;
    }
    
    vector<int64_t> d(V);
    
    if (Bellman_Ford(s, es, d)) {
        cout << "NEGATIVE CYCLE" << endl;
    } else {
        for (int i = 0; i < V; i++) {
            cout << (d[i] == INF ? "INF" : to_string(d[i])) << endl;
        }
    }
    
    return 0;
}



Measured memory_bytes: 3304
#include <bits/stdc++.h>
using namespace std;
#define ll                  long long int
#define ull                 unsigned long long int
#define ld                  long double
#define fi                  first
#define se                  second
#define pb                  push_back
#define pbb                 pop_back
#define mp                  make_pair
#define popcount            __builtin_popcountll
#define pii     	        pair<int,int>
#define all(x)              x.begin(), x.end()
#define uniq(x)             x.erase(unique(x.begin(),x.end()),x.end())
#define mem(array, value)   memset(array, value, sizeof(array))
#define lcm(a,b)            (abs(a)/gcd(a,b))*abs(b)
#define random(a, b)        ((((rand() << 15) ^ rand()) % ((b) - (a) + 1)) + (a))
#define PI      	        2*acos(0.0)
#define EPS     	        1e-8
#define line                cout << "\n==========\n"
#define fastRead 	        ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define trace(...)          __f( #__VA_ARGS__ , __VA_ARGS__ )
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << "\n";
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << " , ";
    __f(comma + 1, args...);
}
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> orderedSet;

//int dx[] = {-1, 0, 1, 0},                  dy[] = {0, 1, 0, -1};                  // 4 Direction
//int dx[] = {-1, 0, 1, 0, -1, 1, 1, -1},    dy[] = {0, 1, 0, -1, -1, 1, -1, 1};    // 8 Direction
//int dx[] = {-2, -1, 1, 2, 2, -1, 1, -2},   dy[] = {1, 2, 2, 1, -1, -2, -2, -1};   // Knight Direction

const int INF = 1e9+9;



int main ()
{
    #ifdef Lollipop
        freopen ("input.txt", "r", stdin);
        //freopen ("output.txt", "w", stdout);
    #endif
    int n;
    cin >> n;
    int ara[n];
    vector<int> v;
    for (int i = 0; i < n; i++){
        cin >> ara[i];
        v.pb(ara[i]);
    }
    sort(all(v), greater<int>());
    for (int i = 0; i < n; i++){
        if (ara[i] == v[0]){
            cout << v[1] << endl;
        }
        else{
            cout << v[0] << endl;
        }
    }
    return 0;
}



Measured memory_bytes: 3316
#include <iostream>
#include <iomanip>
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>
#include <limits.h>

using namespace std;

typedef long long LL;

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define dumpMap(m) { for (auto it: m) cout << it.first << "=>" << it.second << ' '; }

const int MOD = 1000000007;

double dp[3000][3000];

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

    double ans = (N - N/2) / (double) N;

    cout << setprecision(10) << ans << endl;

    return 0;
}


Measured memory_bytes: 256
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#define SIZE 300005
#define MOD 1000000007LL
#define EPS 1e-10
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define DOWN(i,b,a) for(int i=b;i>=a;i--)
#define SET(a,c) memset(a,c,sizeof a)
#define BIT(i,j) ((i)>>(j))&1
#define ALL(o) (o).begin(), (o).end()
#define ERASE(o) (o).erase(unique((o).begin(),(o).end()), (o).end())
#define SQ(x) ((x)*(x))
using namespace std;
typedef int_fast64_t ll;
typedef pair<ll,ll> Pll;
typedef pair<int, int> Pii;
typedef pair<double, double> Pdd;
typedef complex<double> dcomplex;
template<typename T> inline void priv(vector<T>a){REP(i,a.size()){cerr<<a[i]<<((i==a.size()-1)?"\n":" ");}}
inline void fastio(){cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15);}
ll gcd(ll a,ll b){ll c=max(a,b);ll d=min(a,b);return c==0||d==0?c:gcd(c%d,d);}
ll lcm(ll a,ll b){return a==0||b==0?0:a*b/gcd(a,b);}

template<int N, typename T, T M>
struct ModFact {
    T inv[N+1];
    T fact[N+1];
    T ifact[N+1];
    constexpr ModFact() : fact(), ifact() {
        fact[0] = 1;
        for (int i = 0; i < N; i++)
            fact[i+1] = (fact[i]*(i+1))%M;
        ifact[N] = power(fact[N], M-2);
        for (int i = N-1; i >= 0; i--)
            ifact[i] = (ifact[i+1]*(i+1))%M;
        inv[0] = 0;
        for (int i = 0; i < N; i++)
            inv[i+1] = (fact[i]*ifact[i+1])%M;
    }
    constexpr T power(T a, T b) {
        T r = 1;
        while (b>0) {
            if((b&1)!=0) r = (r*a)%M;
            a = (a*a)%M;
            b >>= 1;
        }
        return r;
    }
    constexpr T comb(T n, T r) {
        return (((fact[n]*ifact[r])%M)*ifact[n-r])%M;
    }
};
 
ModFact<100000, ll, MOD> fact;

ll N;
ll X[100001];

int main() {
    fastio();
    ll N, ans = 0;
    cin >> N;
    REP(i, N) cin >> X[i];
    ll a = 0;
    REP(i, N-1) {
        a = (a + fact.fact[N-1] * fact.inv[i+1]) % MOD;
        ans = (ans + a * (X[i+1] - X[i])) % MOD;
    }
    cout << ans << "\n";
	return 0;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int s;
  cin >> s;
  if (s == 111) {
    cout << 3;
  } else if (s == 0) {
    cout << 0;
  } else if (s % 3 == 1) {
    cout << 1;
  } else {
    cout << 2;
  }
}

Measured memory_bytes: 3604
#include<iostream>
#include<cmath>
#include <iomanip>
#include<string>
#include<algorithm>
#include<vector>

using namespace std;
using LL = long long;

LL n, a[200000], k,now=0,nowhis[200001];

int main() {

	nowhis[0] = 0;

	cin >> n >> k;
	for (LL i = 0; i < n; i++) {
		cin >> a[i];
	}

	if(k<=500000){
		for (LL i = 0; i < k; i++) {
			now = a[now]-1;
		}
	}
	else {
		for (LL i = 1; i <= n; i++) {
			nowhis[i] = a[nowhis[i - 1]]-1;
		}
		for (LL i = n - 1; i >= 0; i--) {
			if (nowhis[n] == nowhis[i]) {
				now = nowhis[(k-i) % (n - i) + i];
			}
		}
	}

	cout << now+1 << endl;

	return 0;
}

Measured memory_bytes: 6760
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>

using namespace std;

typedef long long ll;
typedef double db;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef string S;
typedef queue<int> qi;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define sort(a) sort(a.begin(),a.end())
#define reverse(a) reverse(a.begin(),a.end())
#define pb push_back
#define ft first
#define sd second
#define elif else if
#define unique(a) a.erase(unique(a.begin(),a.end()),a.end())
#define mp make_pair
#define fr(i,n)for(ll i=0;i<(n);i++)
#define ifr(i,n)for(ll i=(n)-1;i>=0;i--)
const int MOD = 1e9+7;
const ll INF =1e18;

int main(){
    ll n, m, k; cin>>n>>m>>k;
    bool t = false;
    fr(a,n+1){
        fr(b,m+1){
            if (b*(n-a)+a*(m-b) == k){
                t = true;
            }
        }
    }
    if(t) cout << "Yes"<< endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#define N 202
using namespace std;
char s[N][N];
int n,m,i,j,k,l,c,f[2][N][N][N],sum[N][N],x,ans;
int get(int x1,int y1,int x2,int y2)
{
	int tmp=sum[x2][y2]-sum[x2][y1-1]-sum[x1-1][y2]+sum[x1-1][y1-1];
	if(tmp==0||tmp==(x2-x1+1)*(y2-y1+1)) return 1;
	return 0;
}
int main()
{
	scanf("%d%d",&n,&m);
	for(i=1;i<=n;i++) scanf("%s",s[i]+1);
	for(i=1;i<=n;i++){
		for(j=1;j<=m;j++){
			sum[i][j]=sum[i][j-1]+sum[i-1][j]-sum[i-1][j-1]+(s[i][j]=='#');
		}
	}
	for(i=1;i<=n;i++){
		for(j=i;j<=n;j++){
			int p=0;
			for(k=1;k<=m;k++){
				while(p<m&&get(i,k,j,p+1)) p++;
				if(p>=k) f[0][i][j][k]=p;
				else f[0][i][j][k]=k-1,p++;
			}
		}
	}
	for(c=1;f[x][1][n][1]<m;c++){
		x^=1;
		for(i=1;i<=n;i++){
			for(j=i;j<=n;j++){
				for(k=1;k<=m;k++){
					if(f[x^1][i][j][k]<m){
						f[x][i][j][k]=f[x^1][i][j][f[x^1][i][j][k]+1];
						int l=i,r=j-1,mid,tmp=0;
						while(l<=r){
							mid=(l+r)/2;
							tmp=max(tmp,min(f[x^1][i][mid][k],f[x^1][mid+1][j][k]));
							if(f[x^1][i][mid][k]<f[x^1][mid+1][j][k]) r=mid-1;
							else l=mid+1;
						}
						f[x][i][j][k]=max(f[x][i][j][k],tmp);
					}
					else f[x][i][j][k]=m;
				}
			}
		}
		if(f[x][1][n][1]>=m){
			ans=c;
			break;
		}
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 63488
package main

import (
	"bufio"
	"fmt"
	"log"
	"os"
	"strconv"
)

func main() {
	log.SetFlags(log.Lshortfile)
	// log.Println("hello")
	sc := newScanner()
	N := sc.nextInt()
	A := sc.nextInt()
	B := sc.nextInt()
	var ans int
	if A > B || N == 0 || (N == 1 && (A != B)) {
		ans = 0
	} else if A == B {
		ans = 1
	} else {
		n := N - 2
		ans = n*B - n*A + 1
	}
	fmt.Println(ans)
}

type scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func newScanner() *scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &scanner{r: rdr}
}
func (s *scanner) next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *scanner) nextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *scanner) nextInt() int {
	v, _ := strconv.Atoi(s.next())
	return v
}

func (s *scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 640
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

var stdInScanner = bufio.NewScanner(os.Stdin)

func nextInt() int {
	stdInScanner.Scan()
	i, _ := strconv.Atoi(stdInScanner.Text())
	return i
}

func nextFloat() float64 {
	stdInScanner.Scan()
	f, _ := strconv.ParseFloat(stdInScanner.Text(), 64)
	return f
}

func main() {
	stdInScanner.Split(bufio.ScanWords)

	A := nextInt()
	B := int(math.Round(nextFloat() * 100))

	fmt.Println((A * B) / 100)
}


Measured memory_bytes: 1724
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mit map<int,int>::iterator
#define sit set<int>::iterator
#define itrm(g,x) for(mit g=x.begin();g!=x.end();g++)
#define itrs(g,x) for(sit g=x.begin();g!=x.end();g++)
#define ltype int
#define rep(i,j,k) for(ltype (i)=(j);(i)<=(k);(i)++)
#define rap(i,j,k) for(ltype (i)=(j);(i)<(k);(i)++)
#define per(i,j,k) for(ltype (i)=(j);(i)>=(k);(i)--)
#define pii pair<int,int>
#define fi first
#define se second
#define mpr make_pair
#define pb push_back
#define fastio ios::sync_with_stdio(false)
const int inf=0x3f3f3f3f,
mod=1000000007;
const double pi=3.1415926535897932,
eps=1e-6;
int n,k;vector<pii > ans;
void out(){
    printf("%d\n",ans.size());
    rap(i,0,ans.size()) printf("%d %d\n",ans[i].fi,ans[i].se);
    exit(0);
}
int main()
{
    scanf("%d%d",&n,&k);
    rep(i,2,n) ans.pb(mpr(1,i));
    int res=(n-1)*(n-2)/2-k;
    if(res<0) {puts("-1");return 0;}
    if(res==0) {out();return 0;}
    rep(i,2,n)
    rep(j,i+1,n){
        ans.pb(mpr(i,j));res--;
        if(res==0) out();
    }
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
 
using namespace std;
 
int n, m, mx;
vector<vector<char>> grid;
 
struct point {
	int i, j;
  	point() {}
  	point(int _i, int _j)
      :i(_i)
      ,j(_j)
    {}
};
 
void BFS(point s) {
	vector<vector<int>> dist(1 + n + 1, vector<int>(1 + m + 1, -1));
  	queue<point> q;
    q.push(s);
    dist[s.i][s.j] = 0;
  	while (!q.empty()) {
    	int i = q.front().i;
      	int j = q.front().j;
      	q.pop();
        for (int di = -1; di <= 1; ++di)
          	for (int dj = -1; dj <= 1; ++dj) 
            	if (di * di + dj * dj == 1) {
            		int ni = i + di;
                	int nj = j + dj;
                	if (grid[ni][nj] == '#') continue;
              		if (dist[ni][nj] != -1) continue;
              		dist[ni][nj] = dist[i][j] + 1;
                	q.push(point(ni, nj));
            	}
    }
  	for (int i = 1; i <= n; ++i)
      	for (int j = 1; j <= m; ++j)
        	mx = max(mx, dist[i][j]);
  	return;
}
 
int main() {
  cin >> n >> m;
  grid.resize(1 + n + 1, vector<char>(1 + m + 1, '#'));
  
  for (int i = 1; i <= n; ++i)
    	for (int j = 1; j <= m; ++j) cin >> grid[i][j];
  
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j) 
    	if (grid[i][j] != '#') BFS(point(i, j));
  
  cout << mx << '\n';
  return 0;
}

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

int main(){
  int N; cin >>N;
  int d[N];
  for(int i=0;i<N;i++){
    cin >>d[i];
  }
  sort(d,d+N);

  int ans = d[N/2]-d[N/2-1];

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


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

ll N, K, A[200000], F[200000];

bool check(ll X){
    ll need = 0;
    for(int i=0; i<N; i++){
        ll ok = X/F[i];
        if(ok < A[i]) need += A[i] - ok;
    }
    return (need <= K);
}

int main(){
    cin >> N >> K;
    for(int i=0; i<N; i++) cin >> A[i];
    for(int i=0; i<N; i++) cin >> F[i];
    sort(A, A+N);
    sort(F, F+N, greater<>());
    ll ok = 1e18, ng = -1;
    while(ok-ng>1){
        ll mid = (ok+ng)/2;
        (check(mid) ? ok : ng) = mid;
    }
    cout << ok << endl;
    return 0;
}


Measured memory_bytes: 3328
import itertools

n = int(input())
p = [int(i) for i in input().split()]
q = [int(i) for i in input().split()]
p1 = ""
for i in p:
    p1 += str(i)

q1 = ""
for i in q:
    q1 += str(i)


a = list(map(list, itertools.permutations(p, n)))
a.sort()
b = []

for i in a:
    g = ""
    for j in i:
        g += str(j)
    b.append(g)

print(abs((b.index(p1)+1) - (b.index(q1)+1)))



Measured memory_bytes: 13536
a,b,c=map(int,input().split())
d=abs((b*c)*(a//2)-(b*c)*(a-a//2))
e=abs((a*c)*(b//2)-(a*c)*(b-b//2))
f=abs((a*b)*(c//2)-(a*b)*(c-c//2))
print(min(d,e,f))

Measured memory_bytes: 9116
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;

vi di = {1, 0};
vi dj = {0, 1};

int main() {
  int h, w;
  cin >> h >> w;
  vector<vi> mp(h + 2, vi(w + 2, -3));
  rep2(i, 1, h + 1) rep2(j, 1, w + 1) {
    char c;
    cin >> c;
    if(c == '#')
      mp[i][j] = -2;
    else
      mp[i][j] = -1;
  }
  vector<vi> cost(h + 2, vi(w + 2, 100000));
  deque<pair<int, int>> q;
  q.push_back(P(1, 1));
  cost[1][1] = mp[1][1] == -2 ? 1 : 0;
  while(!q.empty()) {
    int i = q.front().first;
    int j = q.front().second;
    q.pop_front();
    rep(k, 2) {
      int ni = i + di[k];
      int nj = j + dj[k];
      if(cost[ni][nj] < 100000 || mp[ni][nj] == -3) continue;
      if(mp[i][j] == mp[ni][nj]) {
        cost[ni][nj] = min(cost[ni][nj], cost[i][j]);
        q.push_front(P(ni, nj));
      } else {
        cost[ni][nj] = min(cost[ni][nj], cost[i][j] + 1);
        q.push_back(P(ni, nj));
      }
    }
  }
  cout << (cost[h][w] + 1) / 2 << endl;
}

Measured memory_bytes: 384
import math
import sys
import queue
from collections import Counter
from itertools import accumulate
from fractions import gcd
from functools import reduce

def lcm(a, b):
    return a * b // gcd(a, b)

def combination_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

mod = 1000000007

"""
# 標準入力取得
## 文字列
    = sys.stdin.readline().rstrip()
    = list(sys.stdin.readline().rstrip())

## 数値
    = int(sys.stdin.readline())
    = map(int, sys.stdin.readline().split())
    = list(map(int, sys.stdin.readline().split()))
    = [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
"""

if __name__ == "__main__":
    S = list(sys.stdin.readline().rstrip())
    if S[0] == "A":
        if "C" in S[2:len(S) - 1:]:
            S.remove("A")
            S.remove("C")
            if "".join(S).islower():
                print("AC")
                exit()
    print("WA")

Measured memory_bytes: 5200
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <cmath>

using namespace std;

long long dp[100050][3];
char sign[100050];
int val[100050];
int sgn[100050];

int main()
{
	int n; scanf("%d",&n);
	for(int i = 1;i <= n; ++ i)
	{
		scanf(" %d",&val[i]);
		if(i != n) scanf(" %c",&sign[i + 1]),sgn[i + 1] = sign[i + 1] == '-' ? -1 : 1;
	}
	sgn[0] = 1;
	memset(dp,-0x3f3f3f3f,sizeof(dp));
	dp[1][0] = val[1];
	for(int i = 2;i <= n; ++ i)
	{
		for(int j = 0;j <= 2; ++ j)
		{
			if(sgn[i] == -1)
			{
				if(j)
				{
					if(j == 2) 
						dp[i][j] = max(dp[i][j],dp[i - 1][j - 1] + val[i]);
					else
						dp[i][j] = max(dp[i][j],dp[i - 1][j - 1] - val[i]);
				}
				if(j % 2 == 0) dp[i][j] = max(dp[i][j],dp[i - 1][j] - val[i]);
				else dp[i][j] = max(dp[i][j],dp[i - 1][j] + val[i]);
				if(j != 2)
				{
					if(j == 1)
						dp[i][j] = max(dp[i][j],dp[i - 1][j + 1] - val[i]);
					else
						dp[i][j] = max(dp[i][j],dp[i - 1][j + 1] + val[i]);
				}
			}
			else
			{
				if(j % 2 == 0) dp[i][j] = max(dp[i][j],dp[i - 1][j] + val[i]);
				else dp[i][j] = max(dp[i][j],dp[i - 1][j] - val[i]);
				if(j != 2)
				{
					if(j == 1)
						dp[i][j] = max(dp[i][j],dp[i - 1][j + 1] + val[i]);
					else
						dp[i][j] = max(dp[i][j],dp[i - 1][j + 1] - val[i]);
				}
			}
		}
	}
	printf("%lld\n",max(dp[n][0],dp[n][1]));
}

Measured memory_bytes: 3456
#include <bits/stdc++.h>
using namespace std;
#define int long long

int x, y;
vector<int> ansx(0), ansy(0);

void put(int xx, int yy){
//	printf("put(%lld, %lld)\n", xx, yy);
	ansx.push_back(xx);
	ansy.push_back(yy);
	x -= xx;
	y -= yy;
}

signed main(){
	int K, X, Y, i;
	scanf("%lld%lld%lld", &K, &X, &Y);
	x = X + Y, y = X - Y;
	int d;
	if(x >= 0 && y >= 0){
		d = 0;
	}
	else if(x < 0 && y >= 0){
		d = 1;
	}
	else if(x < 0 && y < 0){
		d = 2;
	}
	else if(x >= 0 && y < 0){
		d = 3;
	}
	x = abs(x);
	y = abs(y);
	if(K % 2 == 0){
		if(x % 2 != 0 || y % 2 != 0){
			printf("-1\n");
			return 0;
		}
		K /= 2;
		x /= 2;
		y /= 2;
		while(1){
			if(max(x, y) == K){
				put(x, y);
				break;
			}
			else if(max(x, y) < K){
				put(x - K, K);
			}
			else if(x <= 2 * K){
				put(x - K, K);
			}
			else if(y <= 2 * K){
				put(K, y - K);
			}
			else{
				put(K, K);
			}
		}
		printf("%lld\n", (int)ansx.size());
		for(i = 0; i < ansx.size(); i++){
			if(i > 0){
				ansx[i] += ansx[i - 1];
				ansy[i] += ansy[i - 1];
			}
		}
		for(i = 0; i < ansx.size(); i++){
			if(d == 1 || d == 2){
				ansx[i] = -ansx[i];
			}
			if(d == 2 || d == 3){
				ansy[i] = -ansy[i];
			}
			printf("%lld %lld\n", ansx[i] + ansy[i], ansx[i] - ansy[i]);
		}
	}
	else{
//		printf("(x, y, K) = (%lld, %lld, %lld)\n", x, y, K);
		if(x % 2 != 0){
			if(max(x, y) == K){
				put(x, y);
			}
			else if(max(x, y) < K){
//				printf("test6\n");
				put(-K, -K);
			}
			else if(x <= K){
				put(x, K);
			}
			else if(y <= K){
				put(K, y);
			}
			else{
				put(K, K);
			}
		}
//		printf("(x, y) = (%lld, %lld)\n", x, y);
		while(1){
			if(x == 0 && y == 0){
				break;
			}
			else if(max(x, y) <= 2 * K){
				put(x - K, K);
				put(K, y);
				break;
			}
			else if(x <= 2 * K){
				put(K, K);
				put(x, K);
			}
			else if(y <= 2 * K){
				put(K, K);
				put(K, y);
			}
			else{
				put(K, K);
				put(K, K);
			}
		}
		printf("%lld\n", (int)ansx.size());
		for(i = 0; i < ansx.size(); i++){
			if(i > 0){
				ansx[i] += ansx[i - 1];
				ansy[i] += ansy[i - 1];
			}
		}
		for(i = 0; i < ansx.size(); i++){
			if(d == 1 || d == 2){
				ansx[i] = -ansx[i];
			}
			if(d == 2 || d == 3){
				ansy[i] = -ansy[i];
			}
//			printf("(ansx, ansy)[%lld] = (%lld, %lld)\n", i, ansx[i], ansy[i]);
			printf("%lld %lld\n", (ansx[i] + ansy[i]) / 2, (ansx[i] - ansy[i]) / 2);
		}
	}
	return 0;
}

Measured memory_bytes: 5860
#include <iostream>
#include <vector>

using namespace std;

#define MAX_N 100
#define MAX_W 10000
#define INF (1e9+1)

int main() {
	int N,W;
	cin>>N>>W;
	
	vector<int> v(N),w(N);
	for(int i=0;i<N;i++){
		cin>>v[i]>>w[i];
	}
	
	int dp[MAX_N+1][MAX_W+1];
	for(int i=0;i<MAX_N+1;i++){
		for(int j=0;j<MAX_W+1;j++){
			dp[i][j] = -INF;
		}
	}
	dp[0][0] = 0;
	
	for(int i=0;i<N;i++){
		for(int j=0;j<=W;j++){
			//i???????????????????????¨?????????????§?
			dp[i+1][j] = max( dp[i+1][j], dp[i][j] );
			
			if(j+w[i]<=W){	//??????????????§??????
				//i???????????????????????¨??????????§?
				dp[i+1][j+w[i]] = max( dp[i+1][j+w[i]], dp[i][j]+v[i] );
			}
		}
	}

	int ans = -INF;
	for(int j=0;j<=W;j++){
		ans = max( ans, dp[N][j] );
	}
	cout<<ans<<endl;
	return 0;
}

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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

const int MAX_N = (int)(2e1 + 5);

int n;
vector<vector<pair<int, int>>> data(MAX_N);

int tmp[MAX_N];

bool check() {
  for (int i = 0; i < n; ++i) {
    bool is_honest = tmp[i] == 1;

    if (!is_honest) continue;

    auto confess = data[i];

    for (auto &e : confess) {
      if (tmp[e.first] != e.second) {
        return false;
      }
    }
  }

  return true;
}

int main(void) {
  // Here your code !
  scanf("%d", &n);

  for (int i = 0; i < n; ++i) {
    int a;
    scanf("%d", &a);
    for (int j = 0; j < a; ++j) {
      int x, y;
      scanf("%d %d", &x, &y);
      data[i].push_back(make_pair(x - 1, y));
    }
  }

  int ans = 0;

  for (int i = 0; i < (1 << n); ++i) {
    for (int j = 0; j < n; ++j) {
      tmp[j] = (i >> j) & 1 ? 1 : 0;
    }

    if (!check()) continue;

    int cnt = 0;
    for (int j = 0; j < n; ++j) {
      cnt += tmp[j];
    }

    ans = max(ans, cnt);
  }

  printf("%d\n", ans);

  return 0;
}


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

int K, T;
int cake[105];

int main() {
	int i, max=0;
	ios_base::sync_with_stdio(0);

	cin >> K >> T;
	for (i = 0; i < T; i++) {
		cin >> cake[i];
		if (cake[i] > max)
			max = cake[i];
	}

	if (max * 2 - K - 1 > 0)
		cout << max * 2 - K - 1 << endl;
	else
		cout << 0;

	system("pause");
	return 0;
}

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

using namespace std;

int main() {
  int N; cin >> N;
  
  while(N--) {
    int a[9], b[9];
    for(int i=0; i<9; i++)
      cin >> a[i];
    for(int i=0; i<9; i++)
      cin >> b[i];
    sort(a, a+9);
    double A = 0, B = 0;
    do {
      int cntA=0, cntB=0;
      for(int i=0; i<9; i++) {
	if(a[i] < b[i]) cntB+=a[i]+b[i];
	else cntA+=a[i]+b[i];
      }
      if(cntA<cntB) B++;
      else A++;
    } while(next_permutation(a, a+9));
    cout << A / tgamma(10) << ' ' << B / tgamma(10) << endl;
  }
  
  return 0;
}

Measured memory_bytes: 1252
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep2(i,n) for(ll i=1;i<=(n);i++)
#define rep3(i,i0,n) for(ll i=i0;i<(n);i++)
#define pb push_back
#define MOD 1000000007
const ll INF = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}

bool comparex(tuple<ll,ll,ll> a, tuple<ll,ll,ll> b) {

    return get<1>(a) < get<1>(b);
        
}
bool comparey(tuple<ll,ll,ll> a, tuple<ll,ll,ll> b) {

    return get<2>(a) < get<2>(b);
        
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};

ll modpow(ll a,ll n, ll mod){
    ll res = 1;
    while(n>0){
        if(n&1){
            res= res*a%mod;
        }
        a = a*a%mod;
        n>>=1;
    }
    return res;
}


const int MAX = 5100000;


long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    COMinit();
    ll X,Y;
    ll ans;
    cin >>X>>Y;
    if((X*2-Y)%3 == 0 && (X*2-Y)>=0 && (Y*2-X)%3 == 0 && (Y*2-X)>=0){
        ans = COM((X+Y)/3,(X*2-Y)/3);
    }else{
        ans = 0;
    }
  
    cout << ans<<endl;
  
    return 0;
    

}


Measured memory_bytes: 123172
#include <bits/stdc++.h>
using namespace std;
//関数
const long INF=1000000000000000;

int main(void){
    string S;
    cin>>S;
    
    long ans=INF;
    for(int i=0;i<S.size()-2;i++){
        ans=min(ans,(long) abs((S.at(i)-'0')*100+(S.at(i+1)-'0')*10+(S.at(i+2)-'0')-753));
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 764
/*
 * abc152d.cpp
 * Copyright (C) 2020 itachi <itachi@itachi-Z510>
 *
 * Distributed under terms of the MIT license.
 */

#include <bits/stdc++.h>

using namespace std;

int main() {
    int n;
    cin >> n;
    long long c[10][10] = {{0}};
    for (int i=1;i<=n;i++) {
        string s = to_string(i);
        int x = s[0]-'0';
        int y = s[s.size()-1]-'0';
        c[x][y]++;
    }
    long long ans = 0;
    for (int i=1;i<10;i++) {
        for (int j=1;j<10;j++) {
            ans += c[i][j]*c[j][i];
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<ll,ll> P;
#define pb push_back
#define mp make_pair
#define fr(i,n) for(int i=0;i<n;i++)
#define Fr(i,n) for(int i=0;i++<n;)
#define ifr(i,n) for(int i=n-1;i>=0;i--)
#define iFr(i,n) for(int i=n;i>0;i--)

int main(){
  int n;
  cin>>n;
  if(n%2){
    cout<<(n*(n+1))/2-n-n/2<<endl;
    Fr(i,n){
      Fr(j,n){
        if(i>=j||i+j==n) continue;
        cout<<i<<" "<<j<<endl;
      }
    }
  }
  else{
    cout<<(n*(n-1))/2-n/2<<endl;
    Fr(i,n){
      Fr(j,n){
        if(i>=j||i+j==n+1) continue;
        cout<<i<<" "<<j<<endl;
      }
    }
  }
}

Measured memory_bytes: 256
N = int(input())
values = input()

V = list()
V = values.split()
V_num = list()

for i in range(N):
    V_num.append(float(V[i]))

V_num.sort()

for i in range(N-1):
    min1 = V_num.pop(0)
    min2 = V_num.pop(0)
    V_num.append((min1+min2)/2)
    V_num.sort()

print(V_num[0])

Measured memory_bytes: 3064
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc *bufio.Scanner

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

const MOD = 1000000007

func main() {
	sc = bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	n, k := nextInt(), nextInt()

	aArray := make([]int, n)
	for i := range aArray {
		aArray[i] = nextInt()
	}

	ans := 0
	for i := 0; i < n; i++ {
		for j := i; j < n; j++ {
			switch {
			case aArray[i] > aArray[j]:
				ans += (k * (k + 1) / 2) % MOD
			case aArray[i] < aArray[j]:
				ans += ((k - 1) * k / 2) % MOD
			default:
				continue
			}
			ans %= MOD
		}
	}

	fmt.Println(ans)
}


Measured memory_bytes: 640
#include <cstdio>
#include <algorithm>

using namespace std;

const int INF = 1000000000;
const int SIZE = 102;

int main(){
  int n, a, counter = 1, ans = 0;

  scanf("%d",&n);

  for(int i=0;i<n;i++){
    scanf("%d",&a);
    
    ans = max(ans, counter);
    if(a == 0) counter = 0;
    counter++;
  }
  ans = max(ans, counter);

  printf("%d\n",ans);

  return 0;
}



Measured memory_bytes: 2752
mod=10**9+7
fact=[1]
for i in range(1,5*10**5+1):
  fact.append((fact[-1]*i)%mod)
revfact=[1]
for i in range(1,5*10**5+1):
  revfact.append(pow(fact[i],mod-2,mod))
n,m=map(int,input().split())
patternA=(fact[m]*revfact[n]*revfact[m-n]*fact[n])%mod
patternB=0
for i in range(n+1):
  tmp=(fact[n]*revfact[i]*revfact[n-i])*(fact[m-i]*revfact[n-i]*revfact[m-n])*fact[n-i]
  if i%2==0:
    patternB+=tmp
    patternB%=mod
  else:
    patternB-=tmp
    patternB%=mod
print((patternA*patternB)%mod)


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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef long long ll;

const int MAX_N = 500000;
bool is_prime[MAX_N];

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

    rep(i, MAX_N) is_prime[i] = true;
    is_prime[0] = is_prime[1] = false;
    rep(i, MAX_N) {
        if (is_prime[i]) {
            if (X <= i) {
                cout << i << endl;
                return 0;
            }

            for (int j = i * 2; j < MAX_N; j += i) {
                is_prime[j] = false;
            }
        }
    }
}

Measured memory_bytes: 768
#include <stdio.h>
int main () {
  long int i=0 , a=100 ,x;
  
  scanf("%ld",&x);
  
  while(1){
    
     i++;
    
    if(a+a/100>=x){
      printf("%ld",i);
      break;
    }
    a=a+a/100;  
}
  return 0;
}

Measured memory_bytes: 1736
#include<bits/stdc++.h>
using namespace std;
const long long mod=1e9+7,INF=1e18;
#define ll long long
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t=1;
    // cin>>t;
    while(t--)
    {
        vector<int> a(3);
        cin>>a[0]>>a[1]>>a[2];
        sort(a.begin(),a.end());
        if(a[1]==a[2])
        {
            cout<<(a[2]-a[0])/2+2*((a[2]-a[0])%2)<<"\n";
        }
        else
        {
            int x=0;
            if((a[2]-a[1])%2==1&&(a[2]-a[0])%2==1)
            {
                x=1;
            }
            else if((a[2]-a[1])%2==1||(a[2]-a[0])%2==1)
            {
                x=2;
            }
            cout<<(a[2]-a[0])/2+(a[2]-a[1])/2+x<<"\n";
        }
    }
    return 0;
}

Measured memory_bytes: 3604