akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include<algorithm>
#include<vector>
#include<string>

using namespace std;

template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

int c[1048576];
bool is_prime[100001];
int l[100001];
bool ans_prime[100001];

int main(){
    for (int i=0;i<=100000;i++){
        is_prime[i]=true;
    }
        is_prime[0]=is_prime[1]=false;
    for (int i=2;i<=100000;i++){
        if (is_prime[i]) {
            for (int j=2*i;j<=100000;j+=i){
                is_prime[j]=false;
            }
        }
    }
    for (int i=1;i<=100000;i++) {
        if (is_prime[i] && is_prime[(i+1)/2]) {
            ans_prime[i]=true;
        } else {
            ans_prime[i]=false;
        }
    }
    ans_prime[0]=false;
    int cnt=0;
    for (int i=0;i<=100000;i++){
        if (ans_prime[i]) {
            cnt++;
        }
        l[i]=cnt;
    }
    int q;
    int r1,r2;
    cin>>q;
    for (int i=0;i<q;i++) {
        cin>>r1>>r2;
        printf("%d\n",l[r2]-l[r1-1]);
    }
}

Measured memory_bytes: 1280
#include <stdio.h>

int main(){
	int i,j,k,n;
	scanf("%d",&n);
	int data[200][3],flg[200][3],sum[200] ={0};
	for(i = 0;i < n;i++){
			scanf("%d%d%d",&data[i][0],&data[i][1],&data[i][2]);
	}
	for(i = 0;i < n-1;i++){
		for(j = i+1;j < n;j++){
			for(k = 0;k < 3;k++){
				if(data[i][k] == data[j][k]){
					flg[i][k] = -1;flg[j][k] = -1;
				}
			}
		}
	}
	for(i = 0;i < n;i++){
		for(j = 0;j < 3;j++){
			if(flg[i][j] != -1){
				sum[i] += data[i][j];
			}
		}
		printf("%d\n",sum[i]);
	}
	return 0;
}

Measured memory_bytes: 600
n = int(input())
p = [int(input()) for _i in range(n)]

visit = [-1 for _i in range(n+1)]
for i in p:
    if visit[i-1] < 0:
        visit[i] = 1
    else:
        visit[i] = visit[i-1]+1
print(n-max(visit))

Measured memory_bytes: 18916
#include<bits/stdc++.h>
using namespace std;
const int N=15;
int n,m,k[N],s[N][N],p[N],ans;
int main()
{
    cin>>n>>m;
    for(int i=0;i<m;i++){
        cin>>k[i];
        for(int j=0;j<k[i];j++)cin>>s[i][j];
    }
    for(int i=0;i<m;i++)cin>>p[i];
    for(int i=0;i<1<<n;i++){
        int v=0;
        for(int j=0;j<m;j++){
            int sum=0;
            for(int l=0;l<k[j];l++)sum+=((1<<(s[j][l]-1))&i)>0;
            // cout<<i<<" "<<j<<" "<<sum<<" "<<p[j]<<endl;
            v+=(sum%2)==p[j];
        }
        ans+=v==m;
    }
    cout<<ans<<endl;
    return 0;
}

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

using namespace std;
using ll=long long;

void solve() {
    int n; cin >> n;
    vector<pair<int, int>> a;
    for (int i = 1; i <= n; i++) {
        int x,y;
        cin >> x >> y;
        a.emplace_back(x,i);
        a.emplace_back(y,-i);
    }
    sort(a.begin(), a.end());

    vector<bool> trk(n);
    ll res = 0;
    int pos = 0, neg = 0;
    for (int i = 0; i < n; i++) {
        res += a[i].first;
        int j = a[i].second;
        trk[abs(j)-1] = true;
        j>0?pos++:neg++;
    }
    
    int cnt = 0;
    for (int x: trk) cnt+=x;
    if (cnt == n && (pos > 0 && neg > 0)) {
        int j0 = a[n-1].second, j1 = a[n].second;
        if (abs(j0) != abs(j1)) {
            res -= a[n-1].first;
            res += a[n].first;
        } else {
            j0>0?pos--:neg--;
            j1>0?pos++:neg++;
            if (pos == n || neg == n) {
                res -= a[n-1].first;
                res += a[n].first;
            } else {
                ll d0 = a[n].first - a[n-2].first;
                ll d1 = a[n+1].first - a[n-1].first;
                res += min(d0,d1);
            }
        }
    }
    cout << res;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


Measured memory_bytes: 2420
#include<bits/stdc++.h>
 
#define lol long long
#define gcd(x,y) __gcd(x,y)
#define mt make_tuple
#define mp make_pair
#define fi first
#define se second
#define fixed(x) fixed<<setprecision(x)
using namespace std;
using pii=pair<int,int>;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
template <class A> inline lol abs(A &a) { return (a < 0 ? -a : a); }
bool inLine(int x,int y,int mx,int my){return (x>=0&&y>=0&&x<mx&&y<my);}
const lol inf=(1LL<<62);
const int MOD=(1e9)+7;
const int mod=998244353;
const int dx[]={1,0,-1,0,1,1,-1,-1};
const int dy[]={0,1,0,-1,1,-1,1,-1};
lol n,m,k;
lol sum[1010][1010];
lol rui[1010][1010];
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string t,b;
  cin >>t>>b;
  int T=t.size(),B=b.size();
  
  for(int i=1;i<=B;i++){
    for(int j=1;j<=T;j++){
      rui[i][j]=rui[i][j-1];
      if(b[i-1]==t[j-1]) rui[i][j]++;  
      //cout <<rui[i][j]<<' ';
    }
    //cout <<'\n';
  }

  lol ans=0;
  for(int i=0;i<B;i++){
    for(int j=0;j<T;j++){
      if(b[i]==t[j]){
        if(i==0) sum[i+1][j+1]=sum[i+1][j]+1;
        else{
          sum[i+1][j+1]=sum[i+1][j]+sum[i][j];
        }
      }else sum[i+1][j+1]=sum[i+1][j];
      sum[i+1][j+1]%=MOD;
    }
  }
  /*
  for(int i=0;i<=B;i++){
    for(int j=0;j<=T;j++) cout <<' '<<sum[i][j];
    cout <<'\n';
  }*/
  cout <<sum[B][T]<<'\n';
  return (0);
}


Measured memory_bytes: 19008
import math
K = int(input())
sum = 0

for i in range(1, K + 1):
  for j in range(1, K + 1):
    gcd1 = math.gcd(i, j)
    for k in range(1, K + 1):
      gcd2 = math.gcd(k, gcd1)
      sum += gcd2

print(sum)

Measured memory_bytes: 9184
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
using namespace std;
typedef long long int ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define yes cout << "yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define no cout << "no" << endl

const int INF = 1001001001;
const int mod = 1000000007;
#define PI 3.14159265359;

void P(int x) {cout << x << endl;}
void P(long x) {cout << x << endl;}
void P(double x) {cout << x << endl;}
void P(ll x) {cout << x << endl;}
void P(string x) {cout << x << endl;}
void P(char x) {cout << x << endl;}

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


int main() {
  double r, g;
  cin >> r >> g;
  P(2 * g - r);

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
inline int read()
{
	register int number_read=0,if_ok_read=1;
	char ch_read=getchar();
	while(ch_read<'0'||ch_read>'9')
	{
		if(ch_read=='-')
			if_ok_read=-1;
		ch_read=getchar();
	}
	while(ch_read>='0'&&ch_read<='9')
	{
		number_read=number_read*10+ch_read-'0';
		ch_read=getchar();
	}
	return number_read*if_ok_read;
}
inline void write(register int x_write)
{
    if(x_write<0)
	{
    	putchar('-');
		x_write=-x_write;
	}
    if(x_write>9)
		write(x_write/10);
    putchar(x_write%10+'0');
    return ;
}
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	int n=read(),k=read(),sum=0;
    while(n--)
    {
        int a=read();
        if(a<=k/2)
            sum+=a*2;
        else
            sum+=(k-a)*2;
    }
    write(sum);
	putchar('\n');
	return 0;
}


Measured memory_bytes: 256
def binsearch(l, r, fn):
    while r - l > 1:
        m = (l + r) // 2
        if fn(m):
            l = m
        else:
            r = m
    return l

def main():
    N, M, V, P = list(map(int, input().split()))
    A = sorted(list(map(int, input().split())), reverse=True)
    def ss(k):
        t = A[k] + M
        if A[P - 1] > t:
            return False
        r = M * (V - (N - k) - (P - 1))
        for i in range(P - 1, k):
            r -= min(M, max(0, t - A[i]))
            if r <= 0:
                return True
        return False
    return binsearch(P - 1, N, ss) + 1


print(main())


Measured memory_bytes: 62576
/*#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
#define el "\n" ;

ll f(ll n , vector<long> v , vector<ll> dp){
    if(n <= 1){
        return 0 ;
    }
    if(dp[n] >= 0 ){
        return dp[n] ;
    }
    else
    {
        dp[n] = min(f(n-1,v,dp) + abs(v[n] - v[n-1]) ,f(n-2 , v, dp) + abs(v[n] - v[n-2]) ) ;

    }
    return dp[n] ;
    
}
int main(){
    ios_base::sync_with_stdio(0) ;
    cin.tie(0) ;
    ll  n ; 
    cin >> n  ; 
    vector<ll> dp(n  + 2 , -1 ) ;
    vector<long> v(n + 1) ;
    for( ll i = 1 ; i <= n ; i++){
        cin >> v[i] ;
    }
    v[0] = v[1] ;
    cout << f( n , v , dp) << el ;
    return 0 ;
}*/


#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
#include<math.h>
#include<map> 
#include<bits/stdc++.h> 
typedef long long ll ; 
#define el '\n' 
#define fr(n) for(ll i =0 ; i<n ; i++) 
using namespace std ;
ll a[100005] ; ll dp[100005] ;
ll k  ; 
ll solve(ll n){
    if (n < 1 ) return 0 ; 
    if (dp[n] != -1 )
    {
        return dp[n] ; 
    }
    
    //ll min = INT64_MAX ;
    //return min(abs(solve(n-1) - solve(n)) , abs(solve(n - 2) - solve(a[n])) ) ;
    ll left , right ;
    left = solve(n-1) + abs(a[n] - a[n-1])  ;
    right = INT64_MAX ;
    if(n - 2 >= 0 ){
        right = solve(n-2) + abs(a[n]  - a[n-2]) ; 
    }
    return dp[n] =  min(right , left ) ; 
    
}
int main() 
{ 
    ios_base::sync_with_stdio(0) ;
    cin.tie(0) ;
    cin >> k ;
    dp[0] = - 1  ;
    fr(k){
        cin >> a[i+1] ;
        dp[i + 1 ] = - 1 ; 
    }
    a[0] = a[1] ;
    cout << solve(k) << el ;
    return 0; 
} 

Measured memory_bytes: 9856
#include<iostream>
#include<functional>
#include<utility>
#include<cmath>
#include<iomanip>
#include<algorithm>
#include<string>
#include<vector>

using namespace std;
const auto MOD = 1000000007;
const int INF = 1e9;
const long long LINF = 1e18;
#define rep(i,n) for(int i = 0; i < (n);i++)
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef vector<int> VI;
typedef vector<long long> VLL;

long long mod(const long long &a) {
	if (a >= 0)return a % 1000000007;
	return 1000000007 - (-a) % 1000000007;
}
int mod(const int &a) {
	if (a >= 0)return a % 1000000007;
	return 1000000007 - (-a) % 1000000007;
}
long long modpow(long long a, long long b) {//mod(a^b)を求める
	if (!b)
	{
		return 1;
	}
	if (b < 0) {
		long long ret = 1;
		b = mod(-b);
		ret = modpow(a, MOD - 1 - b);
		return ret;
	}
	long long ret = 1;
	vector<long long> mem(100);//a^(2^k)をメモる
	mem[0] = a;
	for (int i = 1; i < 100; i++)
	{
		mem[i] = mod(mem[i - 1] * mem[i - 1]);
	}
	int now = 0;
	while (b) {
		if (b & 1)
		{
			ret = mod(ret*mem[now]);
		}
		b >>= 1;
		now++;
	}
	return ret;
}
long long fact(long long a) {
	long long ret = 1;
	for (int i = 1; i <= a; i++)
	{
		ret = mod(ret*i);
	}
	return ret;
}


long long combi[100300];//kCi
long long rev[100300];
long long fac[100300];
long long n, k, a, b;
string s;
vector<int> hen[100020];
int used[100020];

long long com(int a, int b) {
	return mod(fac[a]*rev[a - b]);
}

long long dfs(int a,int b,long long now) {//辺aを探索 同僚b
	used[a] = 1;
	int siz = hen[a].size();
	long long cnt = 0;
	for (int i = 0; i < siz; i++)
	{
		if (used[hen[a][i]] == 1)continue;
		cnt++;
	}
	for (int i = 0; i < siz; i++)
	{
		if (used[hen[a][i]] == 1)continue;
		now = dfs(hen[a][i], 1, now);
	}
	now = mod(now*com(k  - b -1, cnt));
	return now;
}



int main() {
	long long ans = 1;
	cin >> n >> k;
	rev[k] = modpow(fact(k), -1);
	for (int i = k-1; i >= 0; i--)
	{
		rev[i] = mod(rev[i + 1] * (i+1));
	}
	fac[0] = 1;
	for (int i = 1; i <= k; i++)
	{
		fac[i] = mod(fac[i - 1] * i);
	}
	for (int i = 0; i < n-1; i++)
	{
		cin >> a >> b;
		hen[a].push_back(b);
		hen[b].push_back(a);
	}
	cout << dfs(1,0,k) << endl;;
}


Measured memory_bytes: 11008
<?php
    list($N, $K) = explode(" ", trim(fgets(STDIN)));
    $enemy = explode(" ", trim(fgets(STDIN)));
    rsort($enemy);
	for($i = 0; $i < $K; $i++){
        $enemy[$i] = 0;
    }
    $ans = 0;
    foreach($enemy as $val){
        $ans += $val;
    }
    echo $ans;
?>

Measured memory_bytes: 23200
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mset(x, y) memset((x), (y), sizeof(x))
#define sz(x) ((int)(x).size())
#define rep(i, a, b) for(i = a; i < b; i++)
#define per(i, a, b) for(i = a; i >= b; i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define cerr cout
#define endl '\n'
using namespace std;

string to_string(string s) { return '"' + s + '"';}
string to_string(char s) { return string(1, s);}
string to_string(const char* s) { return to_string((string) s);}
string to_string(bool b) { return (b ? "true" : "false");}
template <typename A> string to_string(A);
template <typename A, typename B>string to_string(pair<A, B> p) {return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}
template <typename A> string to_string(A v) {bool f = 1; string r = "{"; for (const auto &x : v) {if (!f)r += ", "; f = 0; r += to_string(x);} return r + "}";}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {cerr << " " << to_string(H); debug_out(T...);}
#define pr(...) cerr << "[" << #__VA_ARGS__ << "] :", debug_out(__VA_ARGS__)

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
const ld eps = 1e-7;
const ll mod = 1000000007;
const ll N = 998244353;

ll binpow(ll b, ll p){ ll ans = 1; while(p > 0){if(p & 1) ans = (ans * b) % mod; b = (b * b) % mod; p >>= 1;}return ans;}
ll modinv(ll x){return binpow(x, mod - 2);}

ll f[2005], in[2005];

ll ncr(ll n, ll r)
{
	if(r > n)
		return 0;
	return ((f[n] * in[n - r]) % mod * in[r]) % mod;
}

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

	ll i, ans = 0;
	f[0] = f[1] = in[0] = in[1] = 1;
	for(i = 2; i < 2005; i++)
	{
		f[i] = f[i - 1] * i % mod;
		in[i] = modinv(f[i]);
	}

	ll s;
	cin >> s;
	for(i = 1; i <= s; i++)
	{
		ans = (ans + ncr(s - 2 * i - 1, i - 1)) % mod;
	}
	cout << ans;
}

Measured memory_bytes: 3644
#include<stdio.h>
#include<string.h>

int main(void){
    char S[101];
    int n,i,res=0;    
    scanf("%s",S);
    n = strlen(S);
    for(i=0 ;i<n ;i++ ){
        if (S[i] != S[n-1-i]){
            res++;
        }
    }

    printf("%d\n",res/2);
    return 0;
}

Measured memory_bytes: 128
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;

#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

fn find_path(graph: &Vec<Vec<usize>>,
             cur_v: usize, goal: usize
             , traced_path: &mut Vec<usize>) -> Vec<usize>{

    if cur_v == goal{
        let mut res = traced_path.clone();
        res.push(cur_v);
        return res;
    }

    for &next_v in &graph[cur_v]{
        //ensure infinit loop
        if traced_path.len() > 0 && *traced_path.last().unwrap() == next_v{
            continue;
        }
        traced_path.push(cur_v);
        let res = find_path(graph, next_v, goal, traced_path);
        traced_path.pop();
        if res.len() > 0{
            return res;
        }

    }
    return vec![];
}

fn calc_num_nodes(graph: &Vec<Vec<usize>>, cur_v: usize, prev_v: usize) -> usize{
    let mut sum = 1;
    for &next_v in &graph[cur_v]{
        if next_v == prev_v{
            continue;
        }

        sum += calc_num_nodes(graph, next_v, cur_v);
    }
    return sum;

}
//18:34
fn main(){
    let n: usize = read_as_vec()[0];

    let mut graph: Vec<Vec<usize>> = vec![vec![];n];

    for _ in 0..n-1{
        let line = read_as_vec::<usize>();
        let (a, b) = (line[0]-1, line[1]-1);
        graph[a].push(b);
        graph[b].push(a);
    }
    //find route between 0 and N
    let mut traced_path = vec![];
    let path = find_path(&graph, 0, n-1, &mut traced_path);
    let fenec_last = (path.len()+1)/2-1;

    let fenec_op = n - calc_num_nodes(&graph, path[fenec_last+1], path[fenec_last]) -1;
    let snake_op = n -2 - fenec_op;

    if snake_op >= fenec_op{
        println!("Snuke");
    }else{
        println!("Fennec");
    }
}


Measured memory_bytes: 27004
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n,T=map(int,input().split())
    AB=[tuple(map(int,input().split())) for _ in range(n)]
    AB.sort()

    dp=[0]*T
    ans=-INF
    for i in range(n):
        a,b=AB[i]
        ndp=dp[:]
        for t in range(T):
            if(t+a<T):
                ndp[t+a]=max(ndp[t+a],dp[t]+b)
            else:
                ans=max(ans,dp[t]+b)
        dp=ndp
    print(ans)
resolve()

Measured memory_bytes: 43228
#include <iostream>
#include <cstring>
#include <queue>
using namespace std;
int main(void){
  int a, b, x;
  cin >> a >> b >> x;
  if(b > x-a){
    if (a>x) {
      cout << "NO" << endl;
    }else{
      cout << "YES" << endl;
    }
  }else{
    cout << "NO" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <algorithm>
 
using namespace std;
 
int main(){
 
	int R; cin>>R;
	double pi=6.28318530717958623200/2;
 
	cout<< 2*pi*R<<endl;
	return 0;
}

Measured memory_bytes: 3788
#include<stdio.h>
int main(void)
{
	int t,n,s,f,g,i;
	while(1){
		g=0;
		scanf("%d",&t);
		if(t==0){
			break;
		}
		scanf("%d",&n);
		for(i=0;i<n;i++){
			scanf("%d%d",&s,&f);
			g=g+(f-s);
		}
		if(t<=g){
			printf("OK\n");
		}
		else{
			printf("%d\n",t-g);
		}
	}
	return 0;
}

Measured memory_bytes: 612
#include <bits/stdc++.h>
#define N 16
using namespace std;
const int mod = (1e9)+7;
const double EPS = 1e-8;
const double PI = 6.0 * asin(0.5);
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}

const int TOP = 0,FRONT = 1,LEFT = 2, RIGHT = 3,BACK = 4,BOTTOM = 5;
class Dice{
public:
  int val[6];
  Dice(){for(int i=0;i<6;i++) val[i] = i;}
  Dice(int val[6]){for(int i=0;i<6;i++) this->val[i] = val[i];}
  Dice(int l,int r,int f,int b,int d,int u){
    val[LEFT] = l, val[RIGHT] = r;
    val[FRONT] = f, val[BACK] = b;
    val[BOTTOM] = d, val[TOP] = u;
  }
  void rot(string s){
    if(s == "N" || s == "B") rotN();
    else if(s == "S" || s == "F") rotS();
    else if(s == "E" || s == "R") rotE();
    else if(s == "W" || s == "L") rotW();
    else if(s == "CW") rotCW();
    else if(s == "CCW") rotCCW();
    else assert(!"rot error");
  }

  //?\\?????¢??????
  void rotN(){
    swap(val[TOP],val[FRONT]);
    swap(val[FRONT],val[BOTTOM]);
    swap(val[BOTTOM],val[BACK]);
  }

  //???????????¢??????
  void rotS(){
    //rotN(),rotN(),rotN();
    swap(val[TOP],val[BACK]);
    swap(val[BACK],val[BOTTOM]);
    swap(val[BOTTOM],val[FRONT]);
  }


  //????????¢??????
  void rotE(){
    swap(val[TOP],val[LEFT]);
    swap(val[LEFT],val[BOTTOM]);
    swap(val[BOTTOM],val[RIGHT]);
  }

  //????????¢??????
  void rotW(){
    //rotE(),rotE(),rotE();
    swap(val[TOP],val[RIGHT]);
    swap(val[RIGHT],val[BOTTOM]);
    swap(val[BOTTOM],val[LEFT]);
  }

  //???????????????????¨????????????????
  void rotCW(){
    swap(val[FRONT],val[RIGHT]);
    swap(val[RIGHT],val[BACK]);
    swap(val[BACK],val[LEFT]);
  }

  //??????????????????????¨???????????????????
  void rotCCW(){
    //rotCW(),rotCW(),rotCW();
    swap(val[FRONT],val[LEFT]);
    swap(val[LEFT],val[BACK]);
    swap(val[BACK],val[RIGHT]);
  }
};


int n;
struct dat{int x,y;Dice d;};
typedef pair<short,short> P;
typedef map<P,int> M;
typedef set<P> S;

M dice[N];
M getMove(int x,int y,Dice d,string rot){
  static int dx[1<<8]={},dy[1<<8]={};
  dx['L'] = -1, dx['R'] = 1,dy['F'] = -1, dy['B'] = 1;
  M res;
  res[P(x,y)] = d.val[BOTTOM];
  for(char ch:rot){
    x += dx[(int)ch], y += dy[(int)ch];
    d.rot(string(1,ch));
    res[P(x,y)] = d.val[BOTTOM];
  }
  return res;
}

int getScore(int idx,S &used){
  int res = 0;
  for(pair<P,int>const &p:dice[idx])
    if(!used.count(p.first))res += p.second;
  return res;
}

S getUsed(int idx,S used){
  for(pair<P,int>const &p:dice[idx]) used.insert(p.first);
  return used;
}


int DP(){
  S used[1<<N];
  int dp[1<<N] = {};
  for(int bit=0;bit<(1<<n);bit++)
    for(int i=0;i<n;i++) {
      if(bit>>i&1)continue;
      int nbit = bit | (1<<i);
      int nscore = dp[bit] + getScore(i,used[bit]);
      Max(dp[nbit],nscore);
      if(used[nbit].empty()) used[nbit] = getUsed(i,used[bit]);

    }
  return dp[(1<<n)-1];
}


signed main(){
  while(cin>>n,n){
    for(int i=0;i<n;i++){
      int x,y;
      int l,r,f,b,d,u;
      string rot;
      cin>>x>>y>>l>>r>>f>>b>>d>>u>>rot;
      dice[i] = getMove(x,y,Dice(l,r,f,b,d,u),rot);
    }
    cout<<DP()<<endl;
  }
  return 0;
}

Measured memory_bytes: 236884
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, a, b) for(int i = a; i < b; i++)
#define rrep(i, a, b) for(int i = b - 1; i >= a; i--)
#define ALL(a) a.begin(), a.end()
#define pii pair<int,int>
#pragma GCC optimize("Ofast")
#define pcnt __builtin_popcount
#define buli(x) __builtin_popcountll(x)
#define pb push_back
#define mp make_pair
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
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(a>b){a = b; return 1;} return 0; };
inline void IN(void){return;}
template <typename First, typename... Rest> void IN(First& first, Rest&... rest){cin >> first;IN(rest...);return;}
inline void OUT(void){cout << "\n";return;}
template <typename First, typename... Rest> void OUT(First first, Rest... rest){cout << first << " ";OUT(rest...);return;}
const double EPS = 1e-9;
const int mod = 1e9 + 7;
const int INF = 1e9;
const long long LLINF = 1e18;
long long lcm(ll a, ll b){return a * b / __gcd(a,b);}
struct IoSetup { IoSetup() {
    cin.tie(nullptr);ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
} } iosetup;
template< int mod > struct ModInt {
    int x; ModInt() : x(0) {}
    ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
    ModInt &operator+=(const ModInt &p) {if((x += p.x) >= mod) x -= mod;return *this;}
    ModInt &operator-=(const ModInt &p) {if((x += mod - p.x) >= mod) x -= mod;return *this;}
    ModInt &operator*=(const ModInt &p) {x = (int) (1LL * x * p.x % mod);return *this;}
    ModInt &operator/=(const ModInt &p) {*this *= p.inverse();return *this;}
    ModInt operator-() const { return ModInt(-x); }
    ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
    ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
    ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
    ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
    bool operator==(const ModInt &p) const { return x == p.x; }
    bool operator!=(const ModInt &p) const { return x != p.x; }
    ModInt inverse() const {int a = x, b = mod, u = 1, v = 0, t;
    while(b > 0) { t = a / b; swap(a -= t * b, b); swap(u -= t * v, v); }return ModInt(u);}
    ModInt pow(int64_t n) const {ModInt ret(1), mul(x); while(n > 0) {if(n & 1) ret *= mul;mul *= mul;n >>= 1;}return ret;}
    friend ostream &operator<<(ostream &os, const ModInt &p) { return os << p.x;}
    friend istream &operator>>(istream &is, ModInt &a) { int64_t t; is >> t; a = ModInt< mod >(t); return (is); }
    static int get_mod() { return mod; }
}; using modint = ModInt< mod >;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main(){
    iosetup;
    int N, M, X; IN(N, M, X);
    vector<int> A(M), S(N+1, 0);
    rep(i, 0, M){
        cin >> A[i];
        S[A[i]]++;
    }
    int cnt1 = 0;
    rep(i, X, N) if(S[i] > 0) cnt1++;
    int cnt2 = 0;
    rrep(i, 0, X) if(S[i] > 0) cnt2++;
    cout << min(cnt1, cnt2) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<string>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<cstdio>
#include<cmath>
#include<set>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<utility>
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
using namespace std;
#define DEBUG fprintf(stderr, "Passing function [%s] line %d\n", __FUNCTION__,__LINE__);
#define DE(sss) fprintf(stderr, "Passing function [%s] line %d  :  ", __FUNCTION__,__LINE__);cout<<sss<<endl;
int nn[11],a[11][11];
bool xx[11];
int m,n,ans=0;
bool check(int x)
{
	bool b=1;
	for(int i=1;i<=m;i++)
	{
		bool num=0;
		for(int j=1;j<=nn[i];j++)
			if(x/int(pow(2,a[i][j]-1))%2)
				num=!num;
		if(num!=xx[i])
		{
			b=0;
			break;
		}
	}
	return b;
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)
	{
		scanf("%d",&nn[i]);
		for(int j=1;j<=nn[i];j++)
			scanf("%d",&a[i][j]);
	}
	for(int i=1;i<=m;i++)
		cin>>xx[i];
	int x=pow(2,n);
	for(int i=0;i<x;i++)
		ans+=check(i);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
N = int(input())
import math
sqrtN = math.floor(math.sqrt(N))
list = range(1, sqrtN+1)
a=[]
for i in list[::-1]:
    while N%i == 0:
        a.append(int(i))
        a.append(int(N/i))
        break
    if not a:
        pass
    else:
        break
f = a[0]+a[1]-2
print(f)

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

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define st first
#define nd second
#define endl '\n'
#define what_is(x) cerr << #x << " is " << x << endl;
#define what_is_v(x) cerr << #x << " is "; for(auto&e: (x)) cerr << e << ' '; cerr << '\n'; //vector, set
#define what_is_a(x, n) cerr << #x << " is "; for(int i=0;i<n;i++) cerr << x[i] << ' '; cerr <<  '\n'; //n first element of array
#define cerr_pair(x) '{' << x.st << ", " << x.nd << '}'
#define pwhat_is(x) cerr << #x << " is " << cerr_pair(x) << endl;
#define pwhat_is_v(x) cerr << #x << " is "; for(auto&e: (x)) cerr << cerr_pair(e) << ' '; cerr << '\n'; //vector, set
#define pwhat_is_a(x, n) cerr << #x << " is "; for(int i=0;i<n;i++) cerr << cerr_pair(x[i]) << ' '; cerr <<  '\n'; //n first element of array
// #define int long long
// #define pow mypow

typedef pair<int,int> pii;
const int N = 6;
const int M = 6;
const int INF = 1e9+5;
const int MOD = 1e9+7;

int n, m, k;
char c[N][M];
int32_t main()
{
	IOS
	// freopen("input.txt", "r", stdin);
	cin >> n >> m >> k;
	for(int i=0; i<n; i++){
		for(int j=0; j<m; j++) cin >> c[i][j];
	}
	int ans = 0;
	for(int i=0; i<(1<<n); i++){
		for(int j=0; j<(1<<m); j++){
			int blacks = 0;
			for(int k=0; k<n; k++){
				for(int l=0; l<m; l++){
					if (i&(1<<k)) continue;
					if (j&(1<<l)) continue;
					if (c[k][l] == '#') blacks++;
				}
			}
			if (blacks == k) ans++;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3636
#include <math.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

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

int main(void) {
  int scan; // scanf result
  char *n; // to input 

  n = (char *)malloc(sizeof(char) *4);
  scan = scanf("%s", n);
  if (n[0] != '7') {
    if (n[1] != '7') {
      if (n[2] != '7') {
        printf("No");
        return (0);
      }
      printf("Yes");
      return (0);
    }
    printf("Yes");
    return (0);
  }
  printf("Yes");
  return (0);
}


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

int a, b;

int main() {
	scanf("%d %d", &a, &b);

	if (a <= 0 && b >= 0) return 0 * printf("Zero\n");
	if (a > 0 || (b - a + 1) % 2 == 0) return 0 * printf("Positive\n");

	puts("Negative");

	return 0;
}

Measured memory_bytes: 256
import Data.Int (Int32)

data Sign = Negative | Zero | Positive deriving (Enum, Show)

signOfProduct :: Integral a => a -> a -> Sign
signOfProduct a b
    | a <= 0 && 0 <= b = Zero
    | 0 < a && a <= b = Positive
    | a <= b && b < 0 = if even (b - a + 1) then Positive else Negative
    | otherwise = error "Unexpected"

main :: IO ()
main = do
    [a, b] <- fmap read . words <$> getLine :: IO [Int32]
    print $ signOfProduct a b


Measured memory_bytes: 508
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
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; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, ll> P;
int main()
{
    int N, D, A;
    cin >> N >> D >> A;
    vector<P> M(N);
    vector<int> X(N);
    rep(i, N) {
        int x, h;
        cin >> x >> h;
        M[i] = {x, h};
        X[i] = x;
    }

    D *= 2;
    sort(all(M));
    sort(all(X));

    vector<ll> R(N + 1);
    ll ans = 0;
    rep(i, N) {
        if (i > 0) R[i] += R[i - 1];
        ll hp = M[i].second + R[i];
        if (hp <= 0) continue;
        ll cnt = (hp + A - 1) / A;
        //cout << i << " " << cnt << endl;
        ans += cnt;
        int index = upper_bound(all(X), X[i] + D) - X.begin();
        R[index] += cnt * A;
        R[i] -= cnt * A;
    }
/*
    rep(i, N + 1) {
        cout << R[i] << endl;
    }
    */
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 8812
#include <iostream>
#include <cmath>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <string>

using namespace std;

typedef long long LL;
typedef unsigned int UI;

#define rSort(a) 		sort(a.rbegin(),a.rend())
#define Sort(a) 		sort(a.begin(),a.end())
#define Reverse(a) 		reverse(a.begin(),a.end())
#define Sum(a)  		accumulate(a.begin(), a.end(), 0)
#define REP(i, n) 		for(UI i = 0;i < n;i++)
#define REPR(i, n) 		for(UI i = n;i >= 0;i--)
#define FOR(i, m, n) 	for(UI i = m;i < n;i++)
#define pb(i) 			push_back(i)
#define SWAP(x,y) 		((x!=y)&&(x^=y,y^=x,x^=y))

#define MOD  			(LL)1e9 + 7;
#define INF  			(LL)1 << 62;

bool check(const vector<int>& w) {

	bool ret = true;

	for (int i = 0; i < w.size() - 1; i++) {
		if (w[i] > w[i + 1]) {
			ret = false;
			break;
		}
	}

	return ret;
}

int main(int argc, char* argv[]) {

	cin.tie(0);
	ios::sync_with_stdio(false);

	int N;
	int ret = 0;

	cin >> N;

	vector<int>p(N);
	vector<int>wrk(N);

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

	if (check(p)) {
		ret = 1;
		goto END;
	}

	for (int i = 0; i < N; i++) {
		for (int j = i + 1; j < N; j++) {
			wrk = p;
			SWAP(wrk[i], wrk[j]);
			if (check(wrk)) {
				ret = 1;
				goto END;
			}
		}
	}

END:

	if (ret) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}

	return 0;
}



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

int main() {
  int n;
  string s;
  cin >> n >> s;
  if (n % 2 != 0) {
    cout << "No" << endl;
    return 0;
  }
  int i;
  for (i = 0; i < n / 2; i++) {
    if (s.at(i) != s.at(n / 2 + i)) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}


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

using namespace std;
typedef long long ll;
typedef long double lb;
#define rep(i,j,n) for (ll i = j; i < (n); i++)
#define repr(i,j,n) for(ll i = j; i >= (n); i--)
#define each(i,mp) for(auto& i:mp)
#define all(x) (x).begin(),(x).end()
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const ll INF = 1LL<<60;
const ll m=1LL<<32;

int main(){

  ll n,p;cin>>n>>p;
  
  ll k=pow(p,(lb)1/n);
  repr(i,k,1){
    if(p%i==0&&p%((ll)pow(i,n))==0){
      out(i);
      return 0;
    }
  }


  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using  namespace std;
#define PB push_back
#define MP make_pair
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(a) (a).begin(),(a).end()
 
int main() {
	string s;
	cin>>s;
	int cnt=0;
	int ans=0;
	REP(i,s.size()){
		if(s[i]=='S'){
			cnt++;
		}else{
			if(cnt>0){
				cnt--;
			}else{
				ans++;
			}
		}
	}
	int t=s.size()-1;
	cout<<ans+cnt<<endl;
}

Measured memory_bytes: 640
n, m = map(int, input().split())
sc = [list(map(int, input().split())) for i in range(m)]
if n == 3:
    l = range(100, 1000)
if n == 2:
    l = range(10, 100)
if n == 1:
    l = range(0, 10)
flag = False
for i in l:
    num = str(i)
    if all([num[s-1] == str(c) for s, c in sc]):
        #print(num)
        #exit()
        flag = True
        ans = num
        break
if flag:
    print(num)
else:
    print(-1)


Measured memory_bytes: 3188
#include<iostream>
#include<utility>
#include<algorithm>
using namespace std;
int N, W;
int v, w;
pair<int, int> vw[110];
int Vic[110][10010];

int main()
{
	cin >> N >> W;
	for (int i = 0; i < N; i++)
	{		
		cin >>v>> w;
		vw[i] = make_pair(v, w);		
	}
	int ans;
	for (int i = 0; i < N; i++)
	{
		for (int c = 0; c < W+1; c++)
		{
			if (i==0&&vw[0].second>c) Vic[i][c] = 0;
			else if (i == 0 && vw[0].second <= c)Vic[i][c] = vw[0].first;
			else if (c - vw[i].second < 0)	Vic[i][c] = Vic[i - 1][c];
			else Vic[i][c] = max(vw[i].first + Vic[i -1][c - vw[i].second], Vic[i - 1][c]);			
		}
	}
	ans = Vic[N - 1][W];
	cout << ans << endl;
	return 0;
}


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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

void init() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}

const int N = 2e5+23;

int a[N];

void solve() {
  int n; scanf("%d", &n);
  int x = 0;
  for (int i = 0; i < n; ++i) {
    scanf("%d", a+i);
    x ^= a[i];
  }
  for (int i = 0; i < n; ++i) printf("%d ", x^a[i]);
}

int main() {
  int t = 1; //scanf("%d", &t);
  while (t--) {
    solve();
  }
  return 0;
}


Measured memory_bytes: 4428
n = int(input())
lst = list(map(int, input().split()))

def multi(lst):
  count = 1
  if 0 in lst:
    return 0
  for i in lst:
    if count*i > 10**18:
      return -1
    else:
      count *= i
  return count

print(multi(lst))
  

Measured memory_bytes: 21572
#include<stdio.h>
int main()
{
	int H,W,a,b,c=-1,d=0,e,f,g;
	char HW[101][101];
	scanf("%d %d",&H,&W);
		for(b=0;b<H;b++){
	scanf("%s",&HW[b]);
	}
	for(a=0;a<H;a++){
		for(b=0;b<W;b++){
			if(HW[a][b]=='c'){
				c=0;
				d=1;
			}
			printf("%d",c);
			if(d==1)
			c++;
			if(W-1==b){
			printf("\n");
			c=-1;
			d=0;
			}
			else
			printf(" ");
		}
	}
	return 0;
}

Measured memory_bytes: 612
object Main extends App {
  def calc(i: Int, c: Char, j: Int): Int = if (c == '+') i + j else i - j

  def duplicatePermutation[A](list: List[A], length: Int): List[List[A]] = {
    if (length == 1) {
      list.map(List(_))
    } else {
      list.flatMap(x => duplicatePermutation(list, length - 1).map(y => x :: y))
    }
  }

  val sc = new java.util.Scanner(System.in)
  val Array(a, b, c, d) = sc.next().toCharArray.map(_.toString)
  duplicatePermutation(List('+', '-'), 3).collectFirst {
    case Seq(ab, bc, cd) if calc(calc(calc(a.toInt, ab, b.toInt), bc, c.toInt), cd, d.toInt) == 7 =>
      Array(a, ab.toString, b, bc.toString, c, cd.toString, d, "=", "7").mkString
  }.foreach(println)
}


Measured memory_bytes: 55572
#include<bits/stdc++.h>
#include<ctype.h>
# define pb push_back
#define fst first
#define sec second
#define For(i,a,b) for(int i=a;i<b;i++)
#define ll long long int
#define ull unsigned long long int
#define mod 1000000007
#define fo(i,n) for(ll i=0;i<n;i++)
#define endl "\n"
#define rev(i,n) for(ll i=n-1;i>=0;i--)
#define fo1(i,n) for(ll i=1;i<=n;i++)
#define boolsize 1000001
#define pi pair<ll,ll>
#define vi vector<ll>
#define vii vector<pi>
using namespace std;
template<typename T>
void showvector(vector <T> v)
{
    for(T x:v)
        cout<<x<<" ";
    cout<<endl;

}
template<typename T>
void showvector1(vector <T> v)
{
    ll n=v.size();
    fo1(i,n-1)
        cout<<v[i]<<endl;

}
template<typename T>
void showset(set <T> s)
{
    for(T x: s)
        cout<<x<<" ";
    cout<<endl;
}
template<class T>
void showvectorpair(vector<T> v)
{
    for(auto it=v.begin();it!=v.end();it++)
        cout<<it->first<<" "<<it->second<<endl;
    cout<<endl;
}
template<typename T,typename P>
void showmap(map <T,P> m)
{
    for(auto it=m.begin();it!=m.end();it++)
        cout<<it->first<<" "<<it->second<<endl;
    cout<<endl;
}
template<typename T>
bool comp(T a,T b)
{
    return (a>b);
}
template<class T>
bool comppair(T a,T b)
{
    if(a.first==b.first)
        return(a.second>b.second);
    return (a.first>b.first);
}
bool sameparity(ll a,ll b)
{
    return (a%2==b%2);
}
bool difparity(ll a,ll b)
{
    return !(a%2==b%2);
}
bool isprime(ll x)
{   if(x<=1)
     return false;
    for(ll i=2;i<=sqrt(x);i++)
    {
        if(x%i==0)
            return false;
    }
    return true;
}
bool iseven(ll x)
{
    return !(x%2);
}
bool isodd(ll x)
{
    return (x%2);
}
/// check for test case before submitting
void vfun()
{
    ll n,k;
    cin>>n;
    vector <ll> v(n);
    fo(i,n)
    cin>>v[i];

}

int main()
{
//    #ifndef ONLINE_JUDGE
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
//    #endif
    ios_base::sync_with_stdio(0); ///cant use scanf, printf
    cin.tie(0);cout.tie(0); /// no longer auto flush cout before each cin, remove for interactive
    //cout << fixed << setprecision(11); /// no scientific output
    ll test=1;
    //cin>>test;
    while(test--)
    {
        ll x,y,tx,ty;
        cin>>x>>y>>tx>>ty;
        ll dx=tx-x,dy=ty-y;
        cout<<string(dy,'U')<<string(dx,'R')<<string(dy,'D')<<string(dx,'L');
        cout<<'L'<<string(dy+1,'U')<<string(dx+1,'R')<<'D'<<'R'<<string(dy+1,'D')<<string(dx+1,'L')<<'U';



//         if(vfun())
//            cout<<"YES\n";
//         else
//            cout<<"NO\n";
    }
}
///before sub
/// check for value of zero and single input in array
///loop vars,1LL in mult, equal, one, bounds, int v ll, endl, finish taking inputs
/// check whether test cases are given or not





Measured memory_bytes: 3668
#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
#ifdef __LOCAL
#define debug(x) cerr << __LINE__ << ": " << #x << " = " << x << endl
#define debugArray(x, n)                           \
  cerr << __LINE__ << ": " << #x << " = {";        \
  for (long long hoge = 0; (hoge) < (n); ++(hoge)) \
    cerr << ((hoge) ? "," : "") << x[hoge];        \
  cerr << "}" << endl
#else
#define debug(x) (void(0))
#define debugArray(x, n) (void(0))
#endif

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  long long L[N];
  for (int i = 0; i < N; i++) cin >> L[i];
  sort(L, L + N);
  long long ans = 0;
  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      debug(make_pair(i, j));
      long long a = lower_bound(L, L + N, L[i] + L[j]) - (L + j + 1);
      debug(a);
      ans += a;
    }
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 3624
#include<iostream>
#include<string>

using namespace std;

int main(){
  string a,b,la,lb;
  cin>>a>>b;

  la=a.length();
  lb=b.length();

  if(la>lb){
    cout<<"GREATER"<<endl;
  }else if(la<lb){
    cout<<"LESS"<<endl;
  }else {
    if (a > b) {
      cout << "GREATER" << endl;
    } else if (a < b || la < lb) {
      cout << "LESS" << endl;
    } else {
      cout << "EQUAL" << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 256
N = int(input())
A_s = list(map(int, input().split()))
is_up = []
for i, A in enumerate(A_s):
    if i == len(A_s)-1:
        break
    if A_s[i+1] >= A_s[i]:
        is_up.append(True)
    else:
        is_up.append(False)
wallet = 1000
stocks = 0
for i, A in enumerate(A_s):
    if i == len(A_s)-1:
        wallet += stocks * A
        stocks = 0
        break
    if is_up[i]:
        stocks += wallet // A
        wallet = wallet % A
    else:
        wallet += stocks * A
        stocks = 0


print(wallet)

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

int main() {
    int n, W;
    cin >> n >> W;
    vector<int> v(n), w(n);
    rep(i,n) cin >> v[i] >> w[i];
    int dp[105][10005];
    rep(i,W+1) dp[0][i] = 0;
    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= W; j++) {
            if (j >= w[i]) dp[i+1][j] = max(dp[i][j-w[i]]+v[i],dp[i][j]);
            else dp[i+1][j] = dp[i][j];
        }
    }
    cout << dp[n][W] << endl;
}


Measured memory_bytes: 7096
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

x, a, b = map(int, input().split())
print("A" if abs(x - a) < abs(x - b) else "B")

Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;

int main(){
    vector<int> vec(3);
    rep(i,3) cin >> vec[i];
    sort(ALL(vec));
    if(vec[0] == 5 && vec[1] == 5 && vec[2] == 7) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(void){
  int n,k,i,i1,i2,i3,i4,l,x[55],y[55],p;
  long s,ans=5e18;
  vector<int> xl,yl;
  cin >> n >> k;
  for (i=0;i<n;i++){
    cin >> x[i] >> y[i];
    xl.push_back(x[i]);
    yl.push_back(y[i]);
  }
  sort(xl.begin(),xl.end());
  sort(yl.begin(),yl.end());
  for (i1=0;i1<n-1;i1++) for (i2=i1+1;i2<n;i2++) for (i3=0;i3<n-1;i3++) for (i4=i3+1;i4<n;i4++){
    p=0;
    for (l=0;l<n;l++) if (x[l]>=xl[i1] && x[l]<=xl[i2] && y[l]>=yl[i3] && y[l]<=yl[i4])
      p++;
    s=(long)(xl[i2]-xl[i1])*(yl[i4]-yl[i3]);
    if (p>=k && ans>s) ans=s;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, hp=100000000, tmp=0;
  cin >> N;
  vector<int> X(N);
  for(int i=0; i<N; i++)
    cin >> X.at(i);
  for (int p=0; p<101; p++){
    for(int i=0; i<N; i++){
      tmp += (X.at(i) - p) * (X.at(i) - p);
    }
    if(tmp <= hp){
      hp = tmp;
    }
    tmp=0;
  }
  cout << hp << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<bitset>
#include<ext/pb_ds/priority_queue.hpp>
using namespace std;

const int maxn = 1E5 + 10;

int q,s1[maxn],s2[maxn];
char ch[maxn];

void Pre_Work(int *s)
{
	scanf("%s",ch + 1);
	int n = strlen(ch + 1);
	for (int i = 1; i <= n; i++)
		s[i] = (ch[i] == 'A' ? 1 : 2) + s[i - 1];
}

int main()
{
	#ifdef DMC
		freopen("DMC.txt","r",stdin);
	#endif
	
	Pre_Work(s1); Pre_Work(s2); cin >> q;
	while (q--)
	{
		int l1,r1,l2,r2;
		scanf("%d%d%d%d",&l1,&r1,&l2,&r2);
		int d1 = s1[r1] - s1[l1 - 1],d2 = s2[r2] - s2[l2 - 1];
		int d = abs(d1 - d2); puts(d % 3 == 0 ? "YES" : "NO");
	}
	return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <numeric>
#include <string>
#include <algorithm>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <utility>

#define repd(i,a,b); for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define ll long long int
 
 int gcm(int a, int b) {
	int result = a;
	int k = 0;
	int n = b;
	do {
		k = result % n;
		result = n;
		n = k;
	} while(k != 0);
	return result;
} 

using namespace std;
int main() {
  int n; cin >> n;
  int a[n]; 
  rep(i,n){
    cin >> a[i];
  }
  
  int g;
  rep(j,n){
    g = gcm(g,a[j]);
  }
  
  cout << g;
    

 return 0;
}

Measured memory_bytes: 640
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintStream;

class Main {

    public static void main(String[] args) throws IOException {
        doit(args, System.in, System.out);
    }

    static void doit(String[] args, InputStream in, PrintStream out)
            throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        while (true) {
            String line = reader.readLine();
            if (line == null || line.isEmpty()) {
                break;
            }
            int n = Integer.parseInt(line);
            boolean[] sieve = new boolean[50022];
            for (int i = 2; i < Math.sqrt(n) + 1; i++) {
                if (sieve[i]) {
                    continue;
                }
                for (int j = i * 2; j < sieve.length; j += i) {
                    sieve[j] = true;
                }
            }
            for (int i = n - 1; i >= 2; i--) {
                if (!sieve[i]) {
                    out.print(i);
                    break;
                }
            }
            for (int i = n + 1; i < sieve.length; i++) {
                if (!sieve[i]) {
                    out.println(" " + i);
                    break;
                }
            }

        }
    }
}

Measured memory_bytes: 9344
///God help me.

#include<bits/stdc++.h>

using namespace std;

vector<int>st;

int main()
{
    int n;
    st.push_back(0);
    cin >> n;
    for(int i = 1; i<=n; i++){
        int d; cin >> d;
        st.push_back(d);
    }
    st.push_back(0);
    long long ans = 0;
    for(int i = 0; i<st.size()-1; i++){
        ans += abs(st[i]-st[i+1]);
    }
    for(int i = 0; i<st.size()-2; i++){
        int need = abs(st[i]-st[i+2]);
        int dead = abs(st[i]-st[i+1]) + abs(st[i+1]-st[i+2]);
        cout << ans-dead+need<< endl;
    }
    return 0;
}


Measured memory_bytes: 1784
import java.util.ArrayList;
import java.util.Scanner;

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

		int n = Integer.parseInt(sc.next());

		ArrayList<Integer> hArrayList = new ArrayList<>();

		for (int i = 0; i < n; i++) {
			hArrayList.add(Integer.parseInt(sc.next()));
		}

		ArrayList<Integer> dp = new ArrayList<>();

		dp.add(0);
		dp.add(Math.abs(hArrayList.get(0) - hArrayList.get(1)));

		for (int i=2; i<n; i++){
			dp.add(Math.min(Math.abs(hArrayList.get(i) - hArrayList.get(i-1)) + dp.get(i-1), Math.abs(hArrayList.get(i) - hArrayList.get(i-2)) + dp.get(i-2)));
		}
		System.out.println(dp.get(n-1));
	}
}


Measured memory_bytes: 48020
M = int(input())
A = list(map(int,input().split()))
B = {}
C = [0]*2
D = [0]*2

for i in range(len(A)):
	a = str(A[i])
	# 存在したらカウントアップ
	if (a in B): B[ str(A[i]) ] += 1 # カウント
	# 存在しなかったら 1 で初期化
	else: B[ str(A[i]) ] = 1 # カウント
	# {"1":2, "2":3, "3":1}

for i in B:
	# 一個しかなかったら条件を満たさないのでスルー
	# i: string, B[i] = count
	if B[i] < 2: continue

	# 2個以上あれば長方形にスタック
	C.append(int(i))

	# 4個以上あれば正方形にスタック
	if B[i] >= 4: D.append(int(i))

# C を降順でソート
C = sorted(C, reverse=True)

rect = C[0] * C[1]
s = max(D)
square = s * s

print(max(rect,square))

Measured memory_bytes: 23436
#include <stdio.h>

void main()
{
long long int n,k,i,max,min,sum=0,ans;
  scanf("%lld",&n);
  scanf("%lld",&k);
  for(i=k;i<=n+1;i++)
  {
    min=i*(i-1)/2;
    max=(n*2-i+1)*i/2;
    sum=(sum+max-min+1);
  }
  ans=sum%1000000007;
  printf("%lld",ans);
}

Measured memory_bytes: 1724