akhauriyash/Code-Regression huggingface dataset:
/*Function Template*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pint;
const int MAX = 510000;
const int MOD = 1000000007;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define Rep(i, n) for(ll i = 1; i < (n); i++)
#define ALL(a)  (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll fac[MAX], finv[MAX], inv[MAX];


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

}
ll Len(ll n) {
  ll s=0;
  while(n!=0) s++, n/=10;
  return s;
}


ll Sint(ll n) {
  ll m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(ll i=s-1;i>=0;i--) m+=n/((ll)pow(10,i))-(n/((ll)pow(10,i+1)))*10;
  return m;
}


ll Svec(vector<ll> v){
  ll n=0;
  for(ll i=0;i<v.size();i++) n+=v[i];
  return n;
}


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


ll Factorial(ll n){
  ll m=1;
  while(n>=1) m*=n,n--;
  return m;
}

void runlength(string s,vector<pair<char,ll>> &p){
  ll x=1;
  if(s.size()==1){
    p.push_back(pair<char,ll>(s[0],1));
  }
  for(ll i=0;i<s.size()-1;i++){
    if(s[i]==s[i+1]){
      x++;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[i],x));
      }
    }else{
      p.push_back(pair<char,ll>(s[i],x));
      x=1;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[s.size()-1],x));
      }
    }
  }
}




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

const int MAX_N=100010;
vector<bool> sieve_of_eratosthenes(){
  vector<bool> isPrime(MAX_N+1,true);
  for(int i=2;i<=MAX_N;i++){
    if(isPrime[i]){
      for(int j=2*i;j<=MAX_N;j+=i){
        isPrime[j]=false;
      }
    }
  }
  return isPrime;
}

vector<pint> prime_factorize(ll n){
  vector<pint> ans;
  for(ll p=2;p<=sqrt(n);p++){
    if(n%p!=0) continue;
    ll cnt=0;
    while(n%p==0){
      n/=p;
      cnt++;
    }
    ans.push_back(make_pair(p,cnt));
  }
  if(n!=1) ans.push_back(make_pair(n,1));
  return ans;
}

/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
int main() {
  IOS;
  string s;
  cin>>s;
  map<char,ll> mp;
  rep(i,26) mp['a'+i]=0;
  rep(i,s.size()) mp[s[i]]++;
  
  for(auto c:mp){
    if(c.second==0){
      cout<<c.first<<endl;
      return 0;
    }
  }
  cout<<"None"<<endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define f(i,a,n) for(int i=a ; i<n ; i++)
#define F first
#define S second
#define vll vector<ll>
#define fast ios:: sync_with_stdio(false),cin.tie(0);
#define COUT cout<<fixed<<setprecision(12)
#define SET set<ll,greater<ll>>gquiz
#define ITERATOR set<ll,greater<ll>> :: iterator itr
#define V vector<ll>vector
#define sz size()
//#define A vector<pair<ll,ll>>vect
ll N=100000,M=100000;
#define B vect.push_back(make_pair(N,M));
ll MOD=1000000007;
 
bool isprime(ll n){if(n==1 || (n!=2 && n%2==0))return false; if(n==2)return true; 
		for(ll i=3;i<=sqrt(n);i+=2)if(n%i==0)return false; return true; }
ll gcd(ll a,ll b) 
{ 
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
} 

void solve()
{
	string s;
	cin>>s;
	for(ll i=0;i<s.size();i++)
	{
		if(s[i]=='7')
		{
			cout<<"Yes";
			return;
		}
	}
	cout<<"No";
}
int main()
{
	fast;
	ll t=1;
	//cin>>t;
	while(t--)
	{
		solve();
	}
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
typedef  long long int ll;
typedef  long double ld;
#define sync ios_base::sync_with_stdio(false); cin.tie(NULL) 
#define input(arr,n) for(ll i1=0;i1<n;i1++ )cin>>arr[i1]
#define mod 1000000007
#define F first
#define S second 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
//recursions\
#pragma comment(linker, "/stack:200000000")
//loops\
#pragma GCC optimize("unroll-loops")
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,greater_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>//s.order_of_key(val) *s.find_by_order(ind)
using namespace std;

int main()
{
	sync;
	ll n;string s;
	cin>>n>>s;
	ll low=0,high=n/2,ans=0;
	while(low<=high)
	{
		ll mid=(low+high)/2;
		map<string,ll>m;
		int flag=0;
		for(ll i=0;i+mid-1<n;i++)
		{
			string aux=s.substr(i,mid);
				
			if(m.find(aux)!=m.end()&&m[aux]+mid<=i)
			{
				flag=1;
				break;
			}
			if(m.count(aux))
			continue;
			m[aux]=i;
		}
		
		if(flag)
		{
			ans=mid;
			low=mid+1;
		}
		else
		high=mid-1;
	}
	cout<<ans;
}

Measured memory_bytes: 6656
#![allow(non_snake_case, unused_imports)]

// Input macros
macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); let mut next = || { iter.next().unwrap() }; input_inner!{next, $($r)*} }; ($($r:tt)*) => { let stdin = std::io::stdin(); let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock())); let mut next = move || -> String{ bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect() }; input_inner!{next, $($r)*} }; }
macro_rules! input_inner { ($next:expr) => {}; ($next:expr, ) => {}; ($next:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($next, $t); input_inner!{$next $($r)*} }; ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => { let mut $var = read_value!($next, $t); input_inner!{$next $($r)*} }; }
macro_rules! read_value { ($next:expr, ( $($t:tt),* )) => { ( $(read_value!($next, $t)),* ) }; ($next:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() }; ($next:expr, [ $t:tt ]) => { { let len = read_value!($next, usize); (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() } }; ($next:expr, chars) => { read_value!($next, String).chars().collect::<Vec<char>>() }; ($next:expr, bytes) => { read_value!($next, String).into_bytes() }; ($next:expr, usize1) => { read_value!($next, usize) - 1 }; ($next:expr, $t:ty) => { $next().parse::<$t>().expect("Parse error") }; }

// Module
use std::cmp::{min,max};
use std::collections::{HashSet,HashMap,VecDeque,BinaryHeap};

// Functions

// Main
fn main(){
    input!{
        N: usize,
        TXY: [(i64,i64,i64); N]
    }
    let (mut t0, mut x0, mut y0) = (0,0,0);
    for i in 0..N{
        let (t,x,y) = (TXY[i].0, TXY[i].1, TXY[i].2);
        if t-t0 >= (x-x0).abs()+(y-y0).abs() && (t-t0)%2 == (x-x0+y-y0).abs()%2{
            t0 = t;
            x0 = x;
            y0 = y;
            continue;
        }else{
            println!("No");
            return;
        }
    }
    println!("Yes");
}


Measured memory_bytes: 8444
#include <time.h>

#include <stdlib.h>
#include <cstdint>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <limits>
#include <cstdint>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <limits>
#include <vector>
#include <map>
#include <set>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <bitset>
#include <iterator>
#include <deque>
#include <string>
#include <queue>
#include <omp.h>
#include <fstream>   // ifstream, ofstream
typedef int64_t ll;
using namespace std;
const ll INF=1e10;

int main(){
	ll n;
	cin>>n;
	vector<ll> weight;
	ll ans=INF;
	for(ll i1=0;i1<n;i1++){
		ll temp;
		cin>>temp;
		weight.push_back(temp);
	}
	for(ll i1=0;i1<n-1;i1++){
		ll left = accumulate(weight.begin(),weight.begin()+i1+1,0);
		ll right=accumulate(weight.begin()+i1+1,weight.end(),0);
		if(abs(left-right)<ans){
			ans=abs(left-right);
		}
	}
	cout<<ans<<endl;
}


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

def solve():
    MOD = 10**9+7
    N, K = list(map(int, input().split()))

    def total(mn, mx):
        """mnからmxまでの和を返す"""
        n = mx-mn+1
        ret = int((mn+mx)*n/2)
        return ret%MOD

    ans = 0
    for k in range(K, N+2):
        ans += total(N-k+1, N) - total(0, k-1) + 1
        ans = ans%MOD

    print(int(ans))


if __name__ == "__main__":
    solve()


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

int main() {
  int N,K;
  cin >> N >> K;
  int kaijyou =1;
  
  for(int i=0;i<N-1;i++){
      kaijyou*=(K-1);
  }
  cout << K*kaijyou << endl;
}


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

int main(){

	int w,a,b;
	int tmp=0;
	cin >> w >> a >> b;
	if( a == b ){
		cout << 0 << endl;
	}
	else if( a <= b ){
		tmp = b - (a+w);
		if(tmp <= 0 ){
			cout << 0 << endl;
		}
		else{
			cout << tmp << endl;
		}
	}
	else if( b <= a ){
		tmp = a - (b+w);
		if(tmp <= 0 ){
			cout << 0 << endl;
		}
		else{
			cout << tmp << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 256
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>
#include <iomanip>

using namespace std;

#define FOR(i, a, b) for(int (i)=(a);(i)<(b);(i)++)
#define IFOR(i, a, b) for(int (i)=(a);(i)<=(b);(i)++)
#define RFOR(i, a, b) for(int (i)=(a);(i)>=(b);(i)--)
#define REP(i, n) FOR((i), 0, (n))

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template<class T>
void print_container(T &container, string delim=" ") {
    bool first = true;
    for(auto &t: container){
        if(!first){
            cout << delim;
        }
        first = false;
        cout << t;
    }
    cout << endl;
}

const int MOD = 998244353;

ll factorial(int n){
    ll ans = 1;
    IFOR(i, 1, n){
        ans = (ans * i) % MOD;
    }
    return ans;
}

ll power(int n, int p)
{
    if (p == 0)
        return 1;
    long long res = 1;
    long long add = n;
    while (p > 0)
    {
        if (p & 1)
            res = (res * add) % MOD;
        p >>= 1;
        add = add*add%MOD;
    }
    return res;
}

      
int main() {
    int n;
    cin >> n;
    vector<int> d(n);
    REP(i, n)
        cin >> d[i];
    if(d[0] != 0){
        cout << 0 << endl;
        return 0;
    }

    vector<int> dist(n, 0);
    REP(i, n){
        dist[d[i]]++;
    }

    ll ans = 1;
    REP(i, n){
        if(i == 0 && dist[i] != 1){
            cout << 0 << endl;
            return 0;
        }
        if(i >= 1){
            ans = (ans * power(dist[i-1], dist[i])) % MOD;
        }
    }

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

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp setprecision
#define pb(x) push_back(x)
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ld, ld> pdd;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = 1e8;
const ll INF = 1e16;
const string alpha = "abcdefghijklmnopqrstuvwxyz";

int main(){
    int N, K;
    cin >> N >> K;
    if(N%K == 0) cout << 0 << endl;
    else cout << 1 << endl;
}

Measured memory_bytes: 256
from math import gcd
import sys
#import numpy as np

sys.setrecursionlimit(10 ** 9)

K = int(input())

ans = 0
for i in range(1,K+1):
    for j in range(1,K+1):
        tmp = gcd(i,j)
        for k in range(1,K+1):
            ans += gcd(tmp, k)
print(ans)

Measured memory_bytes: 9148
import java.util.Scanner;

public class Main {

    public static final int MOD = 1000000007;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        if (n == 0) {
            System.out.println(1);
            return;
        }
        int n1 = Integer.parseInt(sc.next());
        if (n1 == 0) {
            System.out.println(2);
            return;
        }
        int n2 = Integer.parseInt(sc.next());
        if (n2 == 0) {
            System.out.println(3);
            return;
        }
        int n3 = Integer.parseInt(sc.next());
        if (n3 == 0) {
            System.out.println(4);
            return;
        }
        int n4 = Integer.parseInt(sc.next());
        if (n4 == 0) {
            System.out.println(5);
        }
    }
}

Measured memory_bytes: 35668
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
#include <tuple>
#include <iomanip>
#include <math.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007 // 10^9 + 7
#define INF 1000000000 // 10^9
#define LLINF 1LL<<60
const double PI = 3.14159265358979323846;

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

	ll A, B, K; cin >> A >> B >> K;
	if (A >= K) cout << A - K << " " << B << endl;
	else if (A + B >= K) cout << 0 << " " << B - (K - A) << endl;
	else cout << 0 << " " << 0 << endl;

	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
using namespace std;
int main(){
	int n;
	cin>>n;
	int sum=0;
	for(int j=1;j<=n;j+=2){
		int s=0;
		for(int i=1;i*i<=j;i++){
			if(j%i == 0)s+=2;
		}
		if(s==8){
			sum++;
		}
	}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 256
//starusc
#include<bits/stdc++.h>
using namespace std;
#define int long long
inline int read(){
	int x=0,f=1;char c=getchar();
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c)){x=(x<<1)+(x<<3)+(c^48);c=getchar();}
	return f==1?x:-x;
}
#define min_(a,b) (a>b?b:a)
#define pai pair<int,int>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
const int N=1e5+4,inf=1e18,mod=1e9+7;
int fei[100],cn;
vector<pai>a[100];
inline void init(){
	fei[1]=fei[2]=1;
	cn=2;
	while(fei[cn]<inf){
		++cn;
		fei[cn]=fei[cn-1]+fei[cn-2];
	}
	a[1].pb(mp(1,2));
	for(int i=2;i<=cn;i++){
		for(int j=0;j<(signed)a[i-1].size();j++){
			a[i].pb(mp(a[i-1][j].se,a[i-1][j].fi+a[i-1][j].se));
		}
		a[i].pb(mp(a[i][0].se,a[i][0].se*2-a[i][0].fi));
	}
}
signed main(){
	init();
	int u,v,mu,mv,mx,ans,T=read();
	while(T--){
		u=read();v=read();
		mu=upper_bound(fei+2,fei+cn+1,u)-fei-1;//<= 
		mv=upper_bound(fei+2,fei+cn+1,v)-fei-1;
		if(mu==mv)mv--;
		mx=min_(mu,mv);
		if(mx>1)mx--;
		cout<<mx<<" ";
		if(mx==1)cout<<(u%mod)*(v%mod)%mod;
		else{
			ans=0;
			for(int i=0,x,y;i<(signed)a[mx].size();i++){
				x=a[mx][i].fi;y=a[mx][i].se;
//				printf("%d %d sdlk\n",x,y);
				ans=(ans+((u>=y&&v>=x)?((u-y)/x+1):0)+((v>=y&&u>=x)?((v-y)/x+1):0))%mod;
			}
			cout<<ans;
		}
		puts("");
	}
	return (0-0);
}

Measured memory_bytes: 4096
import collections
n = int(input())
v = list(map(int, input().split()))

x = []
y = []
for i in range(n):
    if (i + 1) % 2 == 1:
        x.append(v[i])
    else:
        y.append(v[i])

xcnt = collections.Counter(x)
ycnt = collections.Counter(y)

x_max = []
if len(xcnt) > 1:
    x_max.append(xcnt.most_common()[0])
    x_max.append(xcnt.most_common()[1])
else:
    x_max.append(xcnt.most_common()[0])
    x_max.append(xcnt.most_common()[0])

y_max = []
if len(ycnt) > 1:
    y_max.append(ycnt.most_common()[0])
    y_max.append(ycnt.most_common()[1])
else:
    y_max.append(ycnt.most_common()[0])
    y_max.append(ycnt.most_common()[0])

ans = float("inf")
for i in range(2):
    for j in range(2):
        if x_max[i][0] != y_max[j][0]:
            sub = n - x_max[i][1] - y_max[j][1]
            ans = min(ans, sub)
if ans == float("inf"):
    ans = n // 2
print(ans)

Measured memory_bytes: 20576
#include<bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define pb push_back
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define fi first
#define se second
#define endl "\n"
#define all(v) v.begin(),v.end()
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define go_t int t;cin>>t;for(int tt=1;tt<=t;tt++)
#define set_ar(arr,v) memset(arr,v,sizeof(arr))
#define trace2(x, y)             cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define trace3(x, y, z)          cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)       cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define trace5(a, b, c, d, e)    cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<endl;
typedef tree<pair<ll,ll>,null_type,less<pair<ll,ll>>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; // order_of_key
typedef pair<int,int>pi;
typedef pair<ll,ll>pl;
const ll inf = 0x3f3f3f3f3f3f3f3fll;//4x10e18
const int maxx = 3000000 , mod = 1000000007;
#define PI 3.14159265
string s,t;
int dp[3002][3002];
int solve(int i,int j)
{
    if(i==-1 || j==-1)
    return 0;
    if(dp[i][j]!=-1)
        return dp[i][j];
    if(s[i]==t[j])
        return dp[i][j] = 1 + solve(i-1,j-1);
    else
        return dp[i][j] = max(solve(i-1,j),solve(i,j-1));
}
int main()
{
    fastio;
    cin>>s>>t;
    int n = s.size();
    int m = t.size();
    set_ar(dp,-1);
    int mx = solve(n-1,m-1);
    string ans;
    for(int i=n-1;i>=0;i--)
    {
        for(int j=m-1;j>=0;j--)
        {
            if(dp[i][j]==mx && s[i]==t[j])
            {
                ans = ans + s[i];
                mx--;
                break;
            }
        }   
    }
    reverse(all(ans));
    for(char c : ans)
    cout<<c;
    cout<<endl;
    return 0;
}

Measured memory_bytes: 35712
#include <iostream>
#include <string>
#include <cmath>
#include <cstdio>
#include <vector>
#include <complex>
#include <algorithm>
#define rep(i,n) for(int (i)=0;(i)<(int)n;(i)++)
#define each(i,o) for (__typeof((o).begin()) i = (o).begin(); i != (o).end(); ++i)
#define mp make_pair
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define SORT(x) sort((x).begin(), (x).end())

using namespace std;

const double EPS = 1e-8;
const double INF = 1e12;

class Point
{
public:
  double y,x;
  Point(){y = x = 0.0;}
  Point(double iy, double ix){y = iy; x = ix;}
  Point(double theta){y = sin(theta); x = cos(theta);}
  Point operator+(const Point& p) const{return Point(y+p.y,x+p.x);}
  Point operator-(const Point& p) const{return Point(y-p.y,x-p.x);}
  void operator+=(const Point& p) {y+=p.y;x+=p.x;}
  void operator-=(const Point& p) {y-=p.y;x-=p.x;}
  Point operator*(double a) const{return Point(y*a,x*a);}
  Point operator/(double a) const{return Point(y/a,x/a);}
  bool operator<(const Point& p) const{return y!=p.y ? y<p.y : x<p.x;}
  double length() const{return sqrt(x*x+y*y);}
  double dist(const Point& p) const{return sqrt(pow(y-p.y,2)+pow(x-p.x,2));}
  double dot(const Point& p) const{return y*p.y+x*p.x;}
  double cross(const Point& p) const{return y*p.x-x*p.y;}
  double angle() const{return atan2(y,x);}
};

double ccw(const Point& a, const Point& b, const Point& c){return (b-a).cross(c-a);}

template<class IN>
void walk_cw(IN begin, IN end, vector<Point>& v) {
    IN cur = begin;
    v.push_back(*cur++);
    vector<Point>::size_type s = v.size();
    v.push_back(*cur++);
    while(cur != end) {
        if (v.size() == s || ccw(v[v.size()-2], v.back(), *cur) > EPS)
            v.push_back(*cur++);
        else
            v.pop_back();
    }
    v.pop_back();
}

vector<Point> convex_hull(vector<Point> vp){
  int n = vp.size();
  int k = 0;
  vector<Point> ret;
  sort(vp.begin(),vp.end());

  walk_cw(vp.begin(), vp.end(), ret);
  walk_cw(vp.rbegin(), vp.rend(), ret);

  return ret;
}

int main(int argc, char const *argv[]){
  int n;
  while(true){
    cin >> n;
    if(n==0) break;

    vector<Point> vp(n);
    rep(i,n) scanf("%lf,%lf",&(vp[i].x),&(vp[i].y));

    vector<Point> ans = convex_hull(vp);
    cout << (vp.size()-ans.size()) << endl;
  }
  return 0;
}

Measured memory_bytes: 1268
#include<iostream>
#include<utility>
#include<algorithm>
#include<queue>

using namespace std;

priority_queue<pair<pair<pair<int, int>,int>,char>> results;

int main() {
	int n;
	while (true) {
		cin >> n; if (n == 0)break;
		char name;
		int win, lose;
		for (int i = 0; i < n;++i) {
			cin >> name;
			win = 0;lose = 0;
			for (int j = 0; j < n - 1; ++j) {
				int r;
				cin >> r;
				if (r == 2)continue;
				else if (r == 0)win++;
				else lose++;
			}results.emplace(make_pair(make_pair(make_pair(win,-lose),-i),name));
		}
		while(!results.empty()) {
			cout << results.top().second << endl;
			results.pop();
		}
	}
	return 0;
}

Measured memory_bytes: 1192
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<list>
#include<set>
#include<string>
#include <iomanip>
using namespace std;
typedef long long ll;

int Tmax, V, E, u, v, d, dis[444][444], Nnew, new_id, dst,order[11111],check[444],par[444];
vector<vector<pair<int, int>>> li(444);
queue<pair<int,int>> route;

void dfs(int now,int distance) {
	route.push(make_pair(now,distance));
	for (auto &e : li[now]) {
		if (par[e.first] == now) {
			dfs(e.first, e.second);
			route.push(make_pair(now, e.second));
		}
	}
}

int main() {
	cin >> V >> E;
	for (int i = 0; i < E; i++) {
		cin >> u >> v >> d;
		li[u].push_back(make_pair(v, d));
		li[v].push_back(make_pair(u, d));
		dis[u][v] = d;
		dis[v][u] = d;
	}
	cin >> Tmax;
	for (int i = 0; i < Tmax; i++) {
		cin >> Nnew;
		if (Nnew)
			cin >> new_id >> order[i];
		else
			order[i] = -1;
	}
	for (int i = 1; i <= V; i++)
		check[i] = 0;
	priority_queue<pair<pair<int, int>,int>,vector<pair<pair<int, int>, int>>,greater<pair<pair<int, int>, int >>> que;
	que.push(make_pair(make_pair(0, 1),-1));
	while (!que.empty()) {
		int now = que.top().first.second, nd = que.top().first.second,npar=que.top().second;
		que.pop();
		if (!check[now]) {
			check[now]++;
			par[now] = npar;
			for (auto &e : li[now]) {
				int next = e.first, dnext = e.second;
				if (!check[next])
					que.push(make_pair(make_pair(nd + dnext, next), now));
			}
		}
	}
	dfs(1,0);
	route.pop();
	int count = 0,ndst;
	for (int i = 0; i < Tmax; i++) {
		if (!count) {
			ndst = route.front().first;
			count = route.front().second;
			route.pop();
			route.push(make_pair(ndst, count));
		}
		cout << ndst << endl;
		count--;
	}
}


Measured memory_bytes: 1152
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;


int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int a,b,c,d;
  bool ans=false;
  cin>>a>>b>>c>>d;
  if(abs(a-c)<=d){
    ans=true;
  }else if(abs(a-b)<=d && abs(b-c)<=d){
    ans=true;
  }
  if(ans){
    cout<<"Yes";
  }else{
    cout<<"No";
  }

  return 0;
}

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

const int INF = 100000000;
typedef pair<int,int> P;
typedef pair<int,P> P2;

int main(){
  int n,m,l,k,a,h;
  int dis[110][110];
  bool hos[110];
  bool v[110][110];
  int x,y,t;
  vector<P> g[110];

  while(cin >> n >> m >> l >> k >> a >> h ,n){
    for(int i=0;i<n;i++){
      hos[i] = false;
      g[i].clear();
      for(int j=0;j<=m;j++){
	dis[i][j] = INF;
	v[i][j] = false;
      }
    }

    for(int i=0;i<l;i++){
      cin >> t;
      hos[t] = true;
    }

    for(int i=0;i<k;i++){
      cin >> x >> y >> t;
      g[x].push_back(P(y,t));
      g[y].push_back(P(x,t));
    }

    priority_queue<P2,vector<P2>,greater<P2> > q;
    dis[a][m] = 0;
    q.push(P2(0,P(a,m)));

    int ans = INF;
    while(q.size()){
      P2 p = q.top(); q.pop();
      int d = p.first;
      int c = p.second.first, f = p.second.second;
      
      //cout << c << " " << f << endl;
      if(c == h){
	ans = d;
	break;
      }

      if(v[c][f])continue;
      v[c][f] = true;

      for(int i=0;i<(int)g[c].size();i++){
	int nf = f - g[c][i].second;
	if(nf<0)continue;
	int nc = g[c][i].first;
	int nd = d + g[c][i].second;	

	for(int j=0;j+nf<=m;j++){
	  if(j && !hos[nc])break;
	  if(!v[nc][nf+j] && dis[nc][nf+j] > nd+j){
	    dis[nc][nf+j] = nd+j;
	    q.push(P2(nd+j,P(nc,nf+j))); 
	  }
	}
      }
    }
    /*
    for(int i=0;i<n;i++){
      for(int j=0;j<=m;j++)cout << dis[i][j] << " ";
      cout << endl;
    }
    */

    if(ans == INF)cout << "Help!\n";
    else cout << ans << endl;
  }
}

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

int n,q,d[500010],a[500010],b[500010];

void work()
{
	scanf("%d %d",&n,&a[0]),b[n+1]=1;
	for (int i=1; i<=n; i++)
		scanf("%d",&d[i]),a[i]=min(a[i-1],abs(a[i-1]-d[i]));
	for (int i=n; i; i--)
		if (d[i]/2>=b[i+1])  b[i]=b[i+1];
		else  b[i]=min(int(1e9),b[i+1]+d[i]);
	scanf("%d",&q);
	for (int i=1,x; i<=q; i++)
		scanf("%d",&x),puts(a[x-1]>=b[i+1]?"YES":"NO");
}

int main()
{
	work();
	return 0;
}


Measured memory_bytes: 7808
// B.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>

using namespace std;

int main(int argc, char *argv[]) {
	int a[3][3];
	for (int i = 0; i < 3; ++i) {
		for (int j = 0; j < 3; ++j) {
			cin >> a[i][j];
		}
	}
	int n, x;
	cin >> n;
	for (int k = 0; k < n; ++k) {
		cin >> x;
		for (int i = 0; i < 3; ++i) {
			for (int j = 0; j < 3; ++j) {
				if (x == a[i][j]) {
					a[i][j] = -1;
				}
			}
		}
	}
	bool ans = false;
	for (int i = 0; i < 3; ++i) {
		int cnt = 0;
		for (int j = 0; j < 3; ++j) {
			cnt += a[i][j] < 0;
		}
		if (cnt >= 3) {
			ans = true;
		}
		cnt = 0;
		for (int j = 0; j < 3; ++j) {
			cnt += a[j][i] < 0;
		}
		if (cnt >= 3) {
			ans = true;
		}
	}
	int cnt = 0;
	for (int i = 0; i < 3; ++i) {
		cnt += a[i][i] < 0;
	}
	if (cnt >= 3) {
		ans = true;
	}
	cnt = 0;
	for (int i = 0; i < 3; ++i) {
		cnt += a[2-i][i] < 0;
	}
	if (cnt >= 3) {
		ans = true;
	}
	cout << (ans ? "Yes" : "No") << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;

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

    int64_t N;
    cin >> N;

    vector<int64_t> cnt(60);
    for (int i = 0; i < 60; i++) cnt[i] = 0;

    int64_t a;
    for (int i = 0; i < N; i++) {
        cin >> a;
        for (int j = 0; j < 60; j++) {
            if (a & (1ll << j)) {
                cnt[j]++;
            }
        }
    }

    int64_t ret = 0;
    for (int i = 0; i < 60; i++) {
        ret += (((((1ll << i) % MOD) * cnt[i]) % MOD) * (N - cnt[i])) % MOD;
        ret %= MOD;
    }
    cout << ret << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define dup(x,y) (((x)+(y)-1)/(y))
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const double EPS = 1e-10;
const int INF = 1e9;
const ll LINF = 1e15;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

int main() {
	int n;
	cin >> n;
	n %= 10;
	if (n == 3) cout << "bon" << endl;
	else if (n == 0 || n == 1 || n == 6 || n == 8) cout << "pon" << endl;
	else cout << "hon" << endl;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,a,b,ans=0;
	cin>>n>>a>>b;
	for(int i=1;i<=n;i++){
		string s=to_string(i);
		int sum=accumulate(s.begin(),s.end(),0)-s.size()*'0';
		if(a<=sum&&sum<=b)
			ans+=i;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <stdlib.h>

using namespace std;
int main(void){
    int a,b;
    cin >> a >> b;
    a--;
    b--;
    string res[100][100];
    for(int i=0;i<100;i++){
        for(int j=0;j<50;j++){
            res[i][j]="#";
        }
        for(int j=50;j<100;j++){
            res[i][j]=".";
        }
    }
    
    //左側
    int cols=floor(a/50);
    for(int i=0;i<100;i+=2){
        for(int j=0;j<cols*2;j+=2){
            res[i][j]=".";
        }
    }
    //やり残し分
    for(int i=0;i<a-cols*50;i++){
        res[i*2][cols*2]=".";
    }
    
    // 右側
    cols=floor(b/50);
    for(int i=0;i<100;i+=2){
        for(int j=99;j>100-cols*2;j-=2){
            res[i][j]="#";
        }
    }
    //やり残し分
    for(int i=0;i<b-cols*50;i++){
        res[i*2][99-cols*2]="#";
    }
    
    string result="";
    for(int i=0;i<100;i++){
        for(int j=0;j<100;j++){
            result+=res[i][j];
        }
        result+="\n";
    }
    cout << "100 100" << endl;
    cout << result << endl;
}

Measured memory_bytes: 768
#include <stdio.h>

int main(void)
{
	int x;
	int y;
	int temp;
	
	while (1)
	{
		scanf("%d %d", &x, &y);
		
		if ((x == 0) && (y == 0))
		{
			break;
		}
		
		if (x > y)
		{
			temp = y;
			y = x;
			x = temp;
		}
		
		printf("%d %d\n", x, y);
	}
	
	return 0;
}

Measured memory_bytes: 600
from scipy.misc import comb
mod = 1000000007

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

for i in range(1,K+1):
    if N-K+1<i:
        print(0)
    else:
        print(comb(N-K+1,i,exact=True)*comb(K-1,i-1,exact=True)%mod)



Measured memory_bytes: 25072
#include<bits/stdc++.h>
using namespace std;
int main(){
  int A,B;
  cin>>A>>B;
  int p=A+B;
  int m=A-B;
  int t=A*B;
  int ans[3]={p,m,t};
  sort(ans,ans+3);
  cout<<ans[2]<<endl;
  return 0;
}


Measured memory_bytes: 256
#28 B - Two Anagrams
s = list(input())
t = list(input())

s = sorted(s,reverse = False)
t = sorted(t,reverse = True)

result = 'No'
rang = min(len(s),len(t))
for i in range(rang):
    if ord(s[i]) < ord(t[i]):
        result = 'Yes'
        break
else:
    # 文字が一緒で t の方が文字数が多いとき
    if (s[:rang] == t[:rang]) and len(s) < len(t):
        result = 'Yes'
print(result)

Measured memory_bytes: 9036
module.exports=function(t){var e={};function r(n){if(e[n])return e[n].exports;var i=e[n]={i:n,l:!1,exports:{}};return t[n].call(i.exports,i,i.exports,r),i.l=!0,i.exports}return r.m=t,r.c=e,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var i in t)r.d(n,i,function(e){return t[e]}.bind(null,i));return n},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=0)}([function(t,e,r){"use strict";var n=r(1);r(2)(n.readFileSync("/dev/stdin","utf8"))},function(t,e){t.exports=require("fs")},function(t,e,r){"use strict";var n=r(3),i=r(5);t.exports=function(t){var e=new n(t);i(e)}},function(t,e,r){"use strict";var n=r(4);t.exports=class{constructor(t){var e=t.trim().split(/\s+/g);this.inp=new n(e)}inr(){return this.inp.deq()}in(){return parseInt(this.inp.deq(),10)}fin(){this.inp.clear()}}},function(t,e,r){"use strict";t.exports=class{constructor(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];this.size=t.length,this.items=t,this.ind=0}enq(t){this.size+=1,this.items.push(t)}deq(){var t=this.items[this.ind];return this.size-=1,this.ind+=1,t}clear(){this.items=[],this.size=0,this.ind=0}}},function(t,e,r){"use strict";t.exports=function(t){for(var e=t.in(),r=new Array(e),n=0;n<e;n++){var i=t.in(),o=t.in();r[n]={a:i,b:o}}r.sort(function(t,e){return t.b-e.b});for(var s=0,u=0;u<e;u++)if((s+=r[u].a)>r[u].b)return void console.log("No");console.log("Yes")}}]);

Measured memory_bytes: 68872
#include <bits/stdc++.h>
#include <iterator>
using namespace std;
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ALL(v) begin(v), end(v)
#define rreps(i, a, n) for (ll i = (a); i <= (ll)(n); ++i)
#define rrep(i, n) rreps(i, 0, n)
#define reps(i, a, n) for (ll i = (a); i < (ll)(n); ++i)
#define rep(i, n) reps(i, 0, n)
#define each(i, n) for (auto&& i : n)
#define fill(x, y) memset(x,y,sizeof(x))
#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using D = double;
using P = complex<D>;
using vs = vector<string>;
template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;
const D EPS = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
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; }
template <typename T> inline void print(const T& x) {cout << x << '\n';}

signed main()
{ 
  int n,r;
  vi ans;
  while(cin>>n>>r, n||r)
  {
    vi card(n);
    rep(i,n) card[i]=n-i-1;
    rep(k,r)
    {
      int p,c; cin>>p>>c;
      p--; c--;
      for(int j=p; j<p+c+1;j++)
      {
        for(int i=j; i>j-p; i--)
        {
          swap(card[i],card[i-1]);
        }
      }
    }
    ans.push_back(card[0]);
  }
  each(v,ans) print(v+1);
  return 0;
}



Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
//const int mod=998244353;
using P = pair<int,int>;
using Pll = pair<ll,ll>;
using ld=long double;
using V=vector<int>;
using Vl=vector<ll>;
using VV=vector<vector<int>>;
using VVl=vector<vector<ll>>;

int main(){
    int n,a,b;cin >>n>>a>>b;
    cout <<min(a,b)<<endl;
    cout <<max(a+b-n,0)<<endl;
}


Measured memory_bytes: 3588
#include<stdio.h>
#include<math.h>
int n,m,all,a[10100];
int main(){
	int i;
	scanf("%d%d",&n,&m);
	for(i=1;i<=m;++i){
		scanf("%d",&a[i]);
		all+=a[i];
	}
	if(all>n){
		printf("-1");
	}
	else{
		printf("%d",n-all);
	}	
	return 0;
}

Measured memory_bytes: 1768
#include<iostream>
using namespace std;
int main(){
	int h, w, i, j;
	while (cin >> h >> w, h || w){
		for (i = 0; i < h;++i){
			for (j = 0; j < w;++j)
				cout << ((i != h-1&&i != 0) ? ((j != w-1&&j != 0) ? "." : "#") : "#");			
			cout << endl;
		}
		cout << endl;
	}
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>

#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i, s, n) for(int i=s; i<n; i++)
#define dup(x,y) (((x)+(y)-1)/(y)) // dup * y >= x なる最小のdup.
using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;
//	std::cout<<std::fixed<<std::setprecision(10);


int main() {
  ll N, A, B;
  cin >> N >> A >> B;
  ll ans = 0;
  ll itr = N / (A + B);
  ans = itr * A + min(A, N - (itr * (A + B)));

  cout << ans << endl;

  return 0;
}


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

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;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (b == 0) return a;
  return gcd(b, a%b);
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}
bool is_prime(ll n) {
  for (ll i = 2; i*i <= n; i++) {
    if (n%i == 0) return false;
  }
  return n != 1;
}
ll mod_pow(ll x, ll n, ll mod) {
  if (n == 0) return 1;
  ll res = mod_pow(x*x%mod, n/2, mod);
  if (n & 1) res = res * x % mod;
  return res;
}

int main() {
  ll n;
  cin >> n;
  vector <ll> v(n);
  rep(i, n) cin >> v.at(i);
  vector <ll> tmp = v;
  sort(v.begin(), v.end());
  ll med1 = v.at(n/2-1), med2 = v.at(n/2);
  rep(i, n) {
    if (tmp.at(i) <= med1) cout << med2 << endl;
    else cout << med1 << endl;
  }
}

Measured memory_bytes: 5376
A,B = map(int, input().split())

def divisor(n):
    i = 1
    table = []
    while i * i <= n:
        if n%i == 0:
            table.append(i)
            table.append(n//i)
        i += 1
    return set(table)

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return set(divisors)


G=list(make_divisors(A) & make_divisors(B))
G=sorted(G)

for i,g in enumerate(G):
    if g==1:
        continue
    for j,g_right in enumerate(G[i+1:]):
        if g_right%g == 0:
            G.remove(g_right)
print(len(G))

Measured memory_bytes: 5064
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const ll MOD = 1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b, const ll mod=MOD) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b, const ll mod=MOD) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b, const ll mod=MOD) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b, const ll mod=MOD) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n; cin >> n;
    vi d(n); for(auto& e : d) cin >> e;

    int res = 0;
    rep(i, n){
        rep(j, i + 1, n){
            res += d[i] * d[j];
        }
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 256
import sys

def main(inp):
    r,g,b,n = map(int,next(inp).split())
    box = sorted([r,g,b],reverse = True)
    
    ans = 0
    for i in range(int(n/box[0])+1):
        for j in range(int((n-i*box[0])/box[1])+1):
            if((n-i*box[0]-j*box[1])%box[2] == 0):
                ans += 1
    
    return ans
  
print(main(sys.stdin))

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

using namespace std;

long long a,b,c;
long long x,y,tmpx,tmpy;
long long ans,ans2;

int main()
{
	scanf("%I64d%I64d%I64d%I64d%I64d",&a,&b,&c,&x,&y);
	tmpx=x,tmpy=y;
	
	while(x&&y)
	{
		if(a+b<c*2&&x&&y)
		{
			ans+=(a+b);
			x--;
			y--;
		}
		else if(a+b==c*2&&x&&y)
		{
			ans+=c*2;
			x--;
			y--;
		}
		else
		{
			ans+=c*2;
			x--;
			y--;
		}
	}
	
	ans=ans+(x*a)+(y*b);
	ans2=max(tmpx,tmpy)*2;
	
	cout<<min(ans,ans2*c);	
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int k = sc.nextInt();
		sc.close();
		
		if(a>=k) {
			System.out.println(k);
			return;
		}
		
		if(a+b>=k) {
			System.out.println(a);
			return;
		}

		System.out.println(a-(k-a-b));

	}

}


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

const int MOD = 1e9 + 7;

const int N = 5000001;
long long fact[N];
long long invfact[N];
long long inv[N];
void init() {
        fact[0] = fact[1] = 1;
        for (int i = 2; i < N; i ++) fact[i] = fact[i - 1] * i % MOD;
        inv[1] = 1;
        for (int i = 2; i < N; i ++) inv[i] = (MOD - MOD / i) * inv[MOD % i] % MOD;
        invfact[0] = invfact[1] = 1;
        for (int i = 2; i < N; i ++) invfact[i] = invfact[i - 1] * inv[i] % MOD;
}
long long C(long long n, long long r) {
        if (n < 0 || r < 0 || n < r) return 0;
        return fact[n] * invfact[n - r] % MOD * invfact[r] % MOD;
}

long long ModPow(long long x, long long n, long long m = MOD) {
        long long res = 1;
        while (n > 0) {
                if (n & 1) res = res * x % m;
                x = x * x % m;
                n >>= 1;
        }
        return res;

}

int main() {
        init();
        int k;
        cin >> k;
        string s;
        cin >> s;
        int n = s.size();
        long long ans = 0;
        for (int i = n - 1; i < n + k; i ++) {
                long long r = ModPow(26, n + k - i - 1);
                (r *= ModPow(25, i - n + 1)) %= MOD;
                (r *= C(i, n - 1)) %= MOD;
                (ans += r) %= MOD;
        }
        cout << ans << endl;
        return 0;
}


Measured memory_bytes: 122512
import math
from functools import reduce
def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

n=int(input())
l=list(map(int,input().split()))
    
print(reduce(lcm,l))



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

using namespace std;

long long n, p, res = 1;
map <long long, int> cnt;

long long Pow(long long a, long long b){
    if (b == 0) return 1;
    long long res = Pow(a, b / 2);
    res = res * res;
    if (b % 2 == 1) return (res * a);
    return res;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
//    freopen("test.inp", "r", stdin);
//    freopen("test.out", "w", stdout);
    cin >> n >> p;
    long long savep = p;
    for (int i = 2; i <= trunc(sqrt(savep)); i++)
        while (p % i == 0){
            cnt[i]++;
            p /= i;
        }
    if (p != 1) cnt[p]++;
    for (auto x: cnt){
        cerr << x.first << ' ' << x.second << endl;
        res = res * Pow(x.first, x.second / n);
    }
    cout << res;
}

Measured memory_bytes: 256
n = int(input())
s = [input() for i in range(n)]
for i in range(n):
    s[i] = sorted(s[i])
    s[i] = "".join(s[i])
    
memo = {}

for i in range(n):
    if s[i] not in memo:
        memo[s[i]] = 1
    else:
        memo[s[i]] += 1
ans = 0
for num in memo:
    num = memo[num]
    ans += num * (num - 1) // 2
print(ans)

Measured memory_bytes: 80728
import java.util.*;

class Main{
	static int mod=1000000007;

	public static void main(String[] $){
		System.err.println();
		Scanner s=new Scanner(System.in);

		int n=s.nextInt();

		ArrayList<Long>a=new ArrayList<>();
		ArrayList<Long>b=new ArrayList<>();
		for(int i=0;i<n;++i) {
			int t=s.nextInt();
			a.add(t*1000000L+i);
			b.add(t*1000000L+i);
		}
		a.sort(null);

		//System.err.println(a);
		//System.err.println(b);

		for(int i=0;i<n;++i) {
			if(b.get(i)%1000000==a.get(n-1)%1000000) {
				System.out.println(a.get(n-2)/1000000);
			}else {
				System.out.println(a.get(n-1)/1000000);
			}
		}
	}
}

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

int main(){
    int n;
    cin>>n;
    int arr[10][10];
    memset(arr,0,sizeof(arr));
    for(int i=1;i<=n;i++){int x,r;
        x=i;
        r=x%10;
        while(x>=10) 
           x/=10;
        arr[r][x]++;
    }
    int ans = 0;
    for(int i=0;i<10;i++){
      for(int j=0;j<10;j++){
        ans+=arr[i][j]*arr[j][i];
      }
    }
    cout<<ans<<"\n";
}



Measured memory_bytes: 3632
n = int(input())
a = list(map(int,input().split()))
ball = [0]*n
for i in range(n, 0, -1):
    cnt = 0
    for j in range(i, n+1, i):
        cnt += ball[j-1]
    if a[i-1] != cnt % 2:
        ball[i-1] = 1
print(ball.count(1))
for i in range(n):
    if ball[i] == 1:
        print(i+1)


Measured memory_bytes: 7148
#include <iostream>
#include <algorithm>
#include <map>

using namespace std;

int main()
{
    int N;
    map<int, int> cards;

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

    int kind = cards.size();
    int b = 0;
    for (auto &card : cards)
    {
        card.second = card.second % 2 == 0 ? 2 : 1;
        if (card.second == 2)
        {
            b++;
        }
    }

    b = b % 2 == 0 ? 2 : 1;

    int result = b == 2 ? kind : kind - 1;

    cout << result << endl;

    return 0;
}

Measured memory_bytes: 4992
import sys
N,K=map(int, input().split())
a=list(map(int, input().split()))
sum=0
for i in range(0,N):
  sum+=a[i]
if sum<K:#全部不必要
  print(N)
  sys.exit()
if sum==K:#全部必要
  print(0)
  sys.exit()
a.sort()
a.reverse()
 
#K未満の最大の数字のラベルはどこ？
l=N
for i in range(N-1,-1,-1):
  if a[i]<K:
    l=i
  else:
    break
 
if l==N:
  print(0)
  sys.exit()
 
count=N
#lまでの要素が必要か不要かチェック(使いまわし可能)
sum=0
l_list=[]
for j in range(l,N):
  if sum+a[j]<K:
    sum+=a[j]
    l_list.append(a[j])
for i in range(0,l):  
  if sum+a[i]>=K:#必要ってことだ
    count-=1
#lからの要素は自分のことを抜かないといけないことに注意
for i in range(l,N):
  if a[i] in l_list:
    sum=0
    b=a[:]
    C=b.pop(i)
    for j in range(l-1,N-1):
      if sum+b[j]<K:
        sum+=b[j]
    if sum+C>=K:#必要ってことだ
      count-=1
  else:
    count-=1
print(count)

Measured memory_bytes: 3572
#include<bits/stdc++.h>
using namespace std;
string s;
stack<char>t;
int main(){
	cin>>s;
	int l=s.size(),ans=l;
	for(int i=0;i<l;i++){
		if(s[i]=='S')t.push(s[i]);
		else
			if(!t.empty())t.pop(),ans-=2;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 640
import Control.Applicative
import Data.List
import Data.Bool (bool)

main :: IO ()
main = solve <$> f <*> (getLine >> f) >>= print
  where
    f = map read <$> words <$> getLine

solve :: [Int] -> [Int] -> Int
solve [w, h] = fst . foldl' f (0, (0,0))
  where
    f (ct, (o, i)) p
      | co < w-1 = (ct + bool 0 1 (co == ci), (co, ci))
      | co == w-1 = (ct, (co, ci))
      | co < w+h-2 = (ct + bool 0 1 (co-2 == ci), (co, ci))
      | co == w+h-2 = (ct, (co, ci))
      | otherwise = (ct + bool 0 1 (co-4 == ci), (co, ci))
      where
        (co, ci) = if p == 0 then (o+1, i) else (o, i+1)



Measured memory_bytes: 4116
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=100005,INF=1<<30;

vector<int> rem(MAX),seen(MAX),G[MAX];

bool ok=true;

void DFS(int u,int p){
    
    if(G[u].size()==1){
        return;
    }
    
    int sum=0,maxi=0;
    
    for(int i=0;i<G[u].size();i++){
        int a=G[u][i];
        if(a==p) continue;
        
        DFS(a,u);
        sum+=rem[a];
        maxi=max(rem[a],maxi);
    }
    
    int x=sum-rem[u];//子同士の回数
    if(x<0) ok=false;
    if(x>sum-maxi) ok=false;
    if(x*2>sum) ok=false;
    rem[u]-=x;
    return;
}

int main(){
    
    int N;cin>>N;
    for(int i=0;i<N;i++){
        cin>>rem[i];
    }
    
    for(int i=0;i<N-1;i++){
        int a,b;cin>>a>>b;
        a--;b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    
    if(N==2){
        if(rem[0]==rem[1]) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }else{
        
        for(int i=0;i<N;i++){
            if(G[i].size()>=2){
                DFS(i,-1);
                if(rem[i]!=0) ok=false;
                break;
            }
        }
        
        if(ok) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
    
}



Measured memory_bytes: 14464