akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstring>
#include<vector>
#include<queue>
#include<cstdio>
#include<sstream>
#include<cmath>
#include<set>
#include<algorithm>
#include<map>
#include<ctime>
#define mp make_pair
#define pii pair<int,int>
#define pdd pair<double,double>
#define pll pair<ll,ll>
#define mst(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long ll;
const double eps = 1e-8;
const int maxn = 209;
const int inf = 100000009;
const ll mod = 1e9 + 7;
char a[maxn], b[maxn], c[maxn];
int main()
{
	int n;
	cin >> n;
	scanf("%s%s", a, b);
	for (int i = 0; i < n; ++i) {
		c[2 * i] = a[i];
		c[2 * i + 1] = b[i];
	}
	c[2 * n] = 0;
	cout << c;
	//system("pause");
	return 0;
}

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

bool binarysearch(int A[],int n,int key){
    int left = 0;
    int right = n;
    int mid;
    while(left < right){
        mid = (left + right)/2;
        if(A[mid] == key)
            return true;
        else if(A[mid] > key)
            right = mid;
        else
            left = mid + 1;
    }
    return false;
}

int main()
{
    int n,A[100000],q,key,sum = 0;
    scanf("%d",&n);
    for(int i=0;i<n;i++) scanf("%d",&A[i]);
    scanf("%d",&q);
    for(int i=0;i<q;i++){
        scanf("%d",&key);
        if(binarysearch(A,n,key))sum++;
    }
    printf("%d\n",sum);
    return 0;
}
 


Measured memory_bytes: 3524
import  numpy as np

np.set_printoptions(precision=10)

A,B,H,M=map(int,input().split())

dh=H/12*360+30*M/60
dm=M/60*360
sita=np.abs(dh-dm)

x=np.sqrt(A**2+B**2-2*A*B*np.cos(np.deg2rad(sita)))
print(x)

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

public class Main {

	public static final int RECT_COUNT = 0;
	public static final int Q_NUMBER = 1;


	public static void main(String[] args) throws IOException {

		BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));

		String beforeStr = bufferedReader.readLine();
		String afterAtr = "";

		for(int i = 0; i < beforeStr.length(); i++) {
			switch(getStringCharAt(beforeStr, i)) {
				case "A" : afterAtr += "X"; break;
				case "B" : afterAtr += "Y"; break;
				case "C" : afterAtr += "Z"; break;
				default:
					afterAtr += String.valueOf((char)(beforeStr.charAt(i) - 3));
			}
		}

		System.out.println(afterAtr);
	}

	public static String getStringCharAt(String str, int position) {
		return String.valueOf(str.charAt(position));
	}

	public static String[] getStringCharArr(String str) {

		String[] arrResult = new String[str.length()];

		for(int i = 0; i < str.length(); i++) arrResult[i] = getStringCharAt(str, i);

		return arrResult;
	}

	public static boolean isInnerPosition(int x1, int x2, int searchPosition) {
		return x1 <= searchPosition && searchPosition <= x2;
	}

}

Measured memory_bytes: 28524
from math import isinf

N = int(input())
A = list(map(int, input().split()))

ans = float('inf')
broke = 0
cur = 0
for i, a in enumerate(A):
    if a == cur + 1:
        cur += 1
        ans = min(ans, broke + N - i - 1)
    else:
        broke += 1
if isinf(ans):
    print(-1)
else:
    print(ans)


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

class Vector2{
  public:
  int x, y;
  Vector2(){}
  Vector2(int x, int y): x(x), y(y) {}

  Vector2 operator + (Vector2 v) {
    return Vector2(x + v.x , y + v.y);
  }
  Vector2 operator - (Vector2 v) {
    return Vector2(x - v.x , y - v.y);
  }

};

int dot(Vector2 a, Vector2 b){
  return a.x * b.x + a.y * b.y; 
}

int cross(Vector2 a, Vector2 b){
  return a.x * b.y - a.y*b.x;
}

int main(){
  Vector2 v_1, v_2,p_1,p_2;
  int n,dot_, cross_;
  cin >> n;
  rep(i,n){
    cin >> p_1.x >> p_1.y >> p_2.x >> p_2.y;
    v_1 = p_2 - p_1;
    cin >> p_1.x >> p_1.y >> p_2.x >> p_2.y;
    v_2 = p_2 - p_1;
    dot_ = dot(v_1, v_2);
    cross_ = cross(v_1, v_2);
    if(dot_ == 0) cout << 1;
    else if(cross_ == 0) cout << 2;
    else cout << 0;
    cout << endl;
  }

  return 0;
}


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

using namespace std;

const int SENTINEL = 1e9;

int c = 0;

void merge(int A[], int left, int mid, int right)
{
	int n1 = mid - left;
	int n2 = right - mid;
	
	int L[n1], R[n2];
	
	for(int i = 0; i < n1; i++)
		L[i] = A[left + i];
	
	for(int i = 0; i < n2; i++)
		R[i] = A[mid + i];
	
	L[n1] = SENTINEL;
	R[n2] = SENTINEL;
	
	int i = 0, j = 0;
	
	for(int k = left; k < right; k++)
	{
		if(L[i] <= R[j])
			A[k] = L[i++];
		else
			A[k] = R[j++];
		c++;
	}
}

void mergeSort(int A[], int left, int right)
{
	if(left+1 < right)
	{
		int mid = (left + right) / 2;
		mergeSort(A, left, mid);
	   	mergeSort(A, mid, right);
	   	merge(A, left, mid, right);
	}
}

void printArray(int A[], int n)
{
	int i;
	for(i = 0; i < n-1; i++)
		printf("%d ", A[i]);
	printf("%d\n", A[i]);
}

int main()
{
	int n;
	scanf("%d", &n);
	
	int A[n];
	
	for(int i = 0; i < n; i++)
		scanf("%d", &A[i]);
	
	mergeSort(A, 0, n);
	
	printArray(A, n);
	printf("%d\n", c);
	
	return 0;
}


Measured memory_bytes: 7128
n,y = map(int, input().split())

def Otoshidama(n):
    for i in range(0, y//10000 + 1):
        for j in range(0, (y - 10000*i)//5000 + 1):
            h = y - 10000*i - 5000*j
            if h%1000 == 0 and h >= 0 and i + j + h//1000 == n:
                return str(i) + " " + str(j) + " " + str(h//1000)
    return "-1 -1 -1"

print(Otoshidama(n))

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

using ll = long long;
using P = pair<ll, ll>;

const ll MOD = 1e9+7;
// const ll MOD = 998244353;
const ll INF = 1ll<<60;

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

ll N, M;
ll A[100010];

int main(int argc, char **argv)
{
	cin >> N >> M;
	REP(i, N) cin >> A[i];
	A[0] %= M;
	REP(i, N-1)
		(A[i+1] += A[i]) %= M;

	map<ll, ll> m;
	REP(i, N)
		++m[A[i]];

	ll res{0};
	for (auto &p : m)
	{
		if (p.first == 0)
			res += p.second;
		res += p.second * (p.second-1) / 2;
	}

	std::cout << res << std::endl;
}


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


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

const int MAX = 510000;


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

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

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


int main() {
    COMinit();
    ll N,M,K;
    cin >>N>>M>>K;
    ll ans = 0;
    rep(i,K+1){
        ans = (ans + COM(N-1,i)*((M*modpow(M-1,N-i-1,MOD))%MOD)+MOD) % MOD;
    }
    
    cout << ans<< endl;


    return 0;
    

}

Measured memory_bytes: 15568
#include <bits/stdc++.h>
using namespace std;
int main() {
  string str;
  cin >> str;
  int option = 0;
  for (int i = 0; i < 3; i++) {
    if (str.at(i) == 'o') {
      option += 100;
    }
  }
  cout << 700 + option << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

#define MAX_INPUT_SIZE  1024
#define INT_MIN -2147483648

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

    int line = atoi(fgets(input, sizeof(input), stdin));
    int max = INT_MIN, min = atoi(fgets(input, sizeof(input), stdin));

    //printf("line : %d, min : %d\n", line, min);

    for (int i = 1; i < line; i++) {
        int curNum = atoi(fgets(input, sizeof(input), stdin));

        int s = curNum - min;
        if (max < s) {
            max = s;
        }

        if (curNum < min) {
            min = curNum;
        }
    }


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

    return 0;
}

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

const int mod = 1000*1000*1000+7;

int N;
vector<int> A, B, invA, invB;
vector<vector<int> > Rev, Cnt;

int cc[402][402][140][2];
int dp(int a, int b, int n, int t) {
    if(a < 0 && b < 0 && n == N / 3) {
        return 1;
    }
    if(n == N) return 0;
    if(a < 0 || b < 0) return 0;
    int &ret = cc[a][b][n][t];
    if(ret != -1) return ret;

    ret = 0;
    if(t == 0) {
        ret += dp(a, b, n, 1);
        ret %= mod;
        ret += dp(a - 1, b, n, 0);
        ret %= mod;
    }
    if(t == 1) {
        if(Rev[ A[a] ][ B[b] ] && (Cnt[ A[a] ][ B[b] ] - 3*n) > 0) {
            ret += 1LL * (Cnt[ A[a] ][ B[b] ] - 3*n) * dp(a - 1, b - 1, n + 1, 0) % mod;
            ret %= mod;
        }
        ret += dp(a, b - 1, n, 1);
        ret %= mod;
    }
    return ret;
}

int po;

int main() {
    scanf("%d", &N);
    A.resize(N);
    for(int i = 0; i < N; i++) {
        scanf("%d", &A[i]);
        A[i]--;
    }
    B.resize(N);
    for(int i = 0; i < N; i++) {
        scanf("%d", &B[i]);
        B[i]--;
    }

    invA.resize(N);
    for(int i = 0; i < N; i++) {
        invA[ A[i] ] = i;
    }
    invB.resize(N);
    for(int i = 0; i < N; i++) {
        invB[ B[i] ] = i;
    }

    Rev = vector<vector<int> >(N, vector<int>(N, 0));
    for(int i = 0; i < N; i++) {
        for(int j = 0; j < N; j++) {
            if(i == j) continue;
            Rev[i][j] = (invA[i] < invA[j]) & (invB[i] > invB[j]);
        }
    }

    Cnt = vector<vector<int> >(N, vector<int>(N, 0));
    for(int i = 0; i < N; i++) {
        for(int j = 0; j < N; j++) {
            for(int k = 0; k < N; k++) {
                if(invA[i] < invA[k] && invB[j] < invB[k]) Cnt[i][j]++;
            }
        }
    }

    memset(cc, -1, sizeof(cc));

    int ans = dp(N - 1, N - 1, 0, 0);

    po = 1;
    for(int i = 1; i <= N / 3; i++) {
        po *= 2;
        po %= mod;
    }

    ans = 1LL * ans * po % mod;

    for(int i = 0; i < N / 3; i++) {
        int tmp = (3*i + 1);
        tmp += (1LL * (3*i + 1) * (3*i) / 2) % mod;
        tmp %= mod;
        ans = 1LL * ans * tmp % mod;
    }

    printf("%d", ans);
}


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

#ifdef ARTEM
	#define deb(x) x
#else
	#define deb(x)
	const int LIMIT = 2 * int(1e5) + 123;
#endif

void solve();

int main() {
	solve();
}

/* ================ actual code starts here ================ */

void solve() {
	string s;
	cin >> s;

	int maxi = 0;
	for(int i = 0; i < s.size(); i++) {
		if(s[ i ] != 'R')
			continue;

		int j = i;
		while(j < (int)s.size() && s[ i ] == s[ j ])
			++j;

		maxi = max(maxi, j - i);
		i = j;
	}
	printf("%d\n", maxi);
}

Measured memory_bytes: 3684
n = int(input())
t=[0]
x=[0]
y=[0]
for i in range(n):
    _t, _x, _y = map(int, input().split())
    t.append(_t)
    x.append(_x)
    y.append(_y)

flag = 0
for i in range(1,n+1):
    dt = t[i] - t[i-1]
    dx = x[i] - x[i-1]
    dy = y[i] - y[i-1]
    dist = abs(dx) + abs(dy)
    if dist > dt:
        flag = flag +1
    elif dist % 2 != dt % 2:
        flag = flag +1
else:
    print("Yes" if flag ==0 else "No")


Measured memory_bytes: 11760
N=int(input())
A=list(map(int,input().split()))

F=0
K=1
b=A[0]

for a in A:
    if F==0:
        if b<a:
            F=1
            b=a
        elif b>a:
            F=-1
            b=a
    elif F==1 and b>a:
        K+=1
        F=0
    elif F==-1 and b<a:
        K+=1
        F=0
    b=a
print(K)


Measured memory_bytes: 85280
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <string>
#include <cctype>
#include <map>
#include <limits>
#include <iomanip>

using namespace std;

const int mod = 1000000007;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
#define ll long long

int main()
{
	int n;
	cin >> n;
	string s, t;
	cin >> s >> t;

	string result;
	for (size_t i = 0; i < n * 2; i++)
	{
		result += (i % 2 == 0) ? s[i / 2] : t[i / 2];
	}

	cout << result << endl;
	return 0;
}

Measured memory_bytes: 3128
/*
 
@author
_      _          _                 _      _
\\    // /\    | | \  |     |    /\ \\    //     
 \\  // /__\   | |_/  |_____|   /__\ \\  //
  \\// /    \  | | \  |     |  /    \ \\//
   \/ /      \ | |_/  |     | /      \ \/
@ Indian Institute of Technology Bhilai
*/
 
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ul;
#define fr(i,start,end, inc) for(ll i=(start); i<(end); i+=inc)
#define rf(i,end,start, inc) for(ll i=(start-1); i>=(end); i-=inc)
#define rep(i,n) for(ll i=0; i<n; i++)
#define rep1(i,n) for(ll i=1; i<n; i++)
#define pb push_back
#define pl pair<ll, ll>
#define fi first
#define se second
#define all(v) v.begin(), v.end()
#define alla(arr,n) arr, arr+n
#define yes cout<<"Yes\n"
#define no cout<<"No\n"
#define fsync ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const ll maxx =  1e9+7;


bool compare(const pl &a, const pl &b){
    return a.fi<b.fi || (a.fi==b.fi && a.se<b.se);
}
ll inline power(ll a, ll b, ll p){
    a %= p;
    ll ans = 1;
    while(b>0){
        if(b & 1)
            ans = (ans*a)%p;
        a = (a*a)%p;
        b >>= 1;
    }
    return ans;
}

ll inv(ll n, ll p){
    return power(n,p-2, p);
}
inline vector<ll> allinv(ll n, ll p){
    vector<ll> arr(n);
    arr[1]=1;
    fr(i,2,n,1){
        arr[i] = (p - (p/i)*arr[p%i]%p)%p;
    }
    return arr;
}
vector<ll> inline allncr(ll n, ll p){
    vector<ll> nci(n+1);
    nci[0]=1;
    nci[n]=1;
    vector<ll> v = allinv(n,p);
    fr(i,1,n,1){
        nci[i]=(nci[i-1]*(n-i-1))%p;
    }
    return nci;
}

bool inline isPrime(ll n) { 
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
    if (n%2 == 0 || n%3 == 0) return false; 
    for (ll i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
    return true; 
}

template<class T>
void printv(T &v){
    ll n = v.size();
    rep(i,n)
        cout << v[i] << " ";
    cout << "\n";
}
//------------fenwick--------------
/*vector<ll> f(maxn,0);
void fenwick_update(ll idx, ll val){
    while(idx <= maxn){
        f[idx]+=val;
        idx += (idx & -idx);
    }
}
ll read_fenwick(ll idx){
    ll sum = 0;
    while(idx > 0){
        sum += f[idx];
        idx -= (idx & -idx);
    }
    return sum;
}*/


ll longestPrefixSuffix(string s) { 
    ll n = s.length(); 
    ll lps[n]; 
    lps[0] = 0; 
    ll len = 0, i=1;
    while (i < n){ 
        if (s[i] == s[len]){ 
            len++; 
            lps[i] = len; 
            i++; 
        } 
        else{ 
            if (len != 0) 
                len = lps[len-1]; 
            else
                lps[i] = 0,i++;
        } 
    } 
    ll res = lps[n-1]; 
    return (res > n/2)? n/2 : res; 
} 

bool pal(string x){
    string a = x;
    reverse(all(a));
    return a==x;
}
void solve(){
    string s;
    cin >> s;
    ll n = s.length();
    string x = s.substr(0,n/2);
    string y = s.substr(n/2+1);
    if(pal(x) && pal(y) && pal(s))
        yes;
    else
        no;       
}

int main(){
    fsync
    ll test=1;
    // cin >> test;
    while(test--){
        solve();

    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
string toString(int n)
{
    string str;
    stringstream ss;
    ss << n;
    ss >> str;
    return str;
}
string toNegativeBase(int n, int negBase)
{
    if (n == 0)
        return "0";

    string converted = "";
    while (n != 0)
    {
        int remainder = n % negBase;
        n /= negBase;
        if (remainder < 0)
        {
            remainder += (-negBase);
            n += 1;
        }
        converted = toString(remainder) + converted;
    }

    return converted;
}
int main()
{
    int n;
    cin>>n;
    int negBase = -2;
    cout << toNegativeBase(n, negBase); 
    return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define pint pair<int,int>
#define mk(x,y) make_pair(x,y)
#define fir first
#define sec second
#define Rep(x,y,z) for(int x=y;x<=z;++x)
#define Red(x,y,z) for(int x=y;x>=z;--x)
using namespace std;
const int MAXN=2e5+5,MAX=1e9;
char buf[1<<12],*p1=buf,*p2=buf,nc;int ny;
//inline char gc() {return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<12,stdin),p1==p2)?EOF:*p1++;}
inline char gc(){return getchar();}
inline int read(){
	int x=0;ny=1;while(nc=gc(),(nc<48||nc>57)&&nc!=EOF)if(nc==45)ny=-1;if(nc<0)return nc;
	x=nc-48;while(nc=gc(),47<nc&&nc<58&&nc!=EOF)x=(x<<3)+(x<<1)+(nc^48);return x*ny;
}
int n,a2[MAXN],a5[MAXN],cnt[30][30],Fpow[20];
int main(){
//	freopen("std.in","r",stdin);
//	freopen("std.out","w",stdout);
	n=read();
	Fpow[0]=1;Rep(i,1,10)Fpow[i]=Fpow[i-1]*10;
	Rep(i,1,n){
		int x=read(),y;
		if(nc=='.'){
			int x=0,len=0;while(nc=gc(),(nc<48||nc>57)&&nc!=EOF);len++;
			x=nc-48;while(nc=gc(),47<nc&&nc<58&&nc!=EOF)x=(x<<3)+(x<<1)+(nc^48),len++;
			y=x*Fpow[(9-len)];
		}else y=0;ll o=1ll*x*MAX+y;
		for(;o%2==0;a2[i]++,o/=2);
		for(;o%5==0;a5[i]++,o/=5);
		a2[i]=min(a2[i],18),a5[i]=min(a5[i],18);
	}ll ans=0;
	Rep(i,1,n){
		Rep(j,0,18)Rep(k,0,18)if(a2[i]+j>=18&&a5[i]+k>=18)ans+=cnt[j][k];
		cnt[a2[i]][a5[i]]++;
	}cout<<ans<<"\n";
	return 0;
}



Measured memory_bytes: 5196
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int k; string s;
  cin >> k >> s;
  if(s.size()>k){
    s = s.substr(0,k);
    s += "...";
  }
  cout << s << endl;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define ull unsigned long long int
#define ll long long int
#define LL_MAX 9223372036854775807
#define pb push_back
#define pf push_front
#define mp make_pair
#define popb pop_back
#define vl vector<ll>
#define bs(v, x) binary_search(v.begin(), v.end(), x)
#define popf pop_front
#define p() cout << '\n'
#define p0(x) cout << x << " "
#define p1(x) cout << x << '\n'
#define p2(x, y) cout << x << " " << y << '\n'
#define p3(x, y, z) cout << x << " " << y << " " << z << '\n'
#define printv(v)                   \
  for (ll i = 0; i < v.size(); ++i) \
    cout << v[i] << " ";            \
  cout << '\n'
#define pr1(x) cout << fixed << setprecision(15) << x << '\n'
#define mod 1000000007
#define mod1 998244353
#define fio                         \
  ios_base::sync_with_stdio(false); \
  cin.tie(NULL)
#define get(n) \
  ll n;        \
  cin >> n
#define getvec(v, n)         \
  vector<ll> v(n);           \
  for (ll i = 0; i < n; i++) \
    cin >> v[i];
#define getstr(s) \
  string s;       \
  cin >> s
#define all(x) x.begin(), x.end()
#define countBits(x) __builtin_popcount(x)
using namespace std;

void mainSolve()
{
  get(n);
  getvec(v, n);
  vl sum(n + 1, 0);
  sum[n - 1] = v[n - 1];
  for (int i = n - 2; i >= 0; i--)
    sum[i] = (sum[i + 1] + v[i]) % mod;
  ll ans = 0;
  for (int i = 0; i < n; i++)
  {
    ll term = (v[i] * (sum[i + 1])) % mod;
    ans = (ans + term) % mod;
  }
  p1(ans);
}

int main()
{
  fio;
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  //get(t);
  ll t = 1;
  while (t--)
  {
    mainSolve();
  }
  return 0;
}


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

const int INF = 1e18;

int getCost(int x){
  return 1LL<<x;
}

int n, a[55], b[55];
int c[55][55];

void solve(){
  
  int ans = 0;
  
  for(int i=0;i<n;i++){
    
    int maxk = 0;
    
    for(int j=0;j<n;j++){
      
      int cost = c[a[j]][b[j]];
      
      if( cost == INF ){
	ans = -1;
	break;
      }
      
      for(int k=1;k<=50;k++){
	if( cost >> k & 1 ) maxk = max( maxk, k );
      }
      
    }

    if( maxk == 0 || ans == -1 ) break;
    
    ans += getCost( maxk );
    
    for(int I=0;I<55;I++){
      
      int nI = I % maxk;
      
      if( I > nI ) c[I][nI] = 0;
      
    }
    
    for(int k=0;k<55;k++){
    
      for(int I=0;I<55;I++){
      
	for(int J=0;J<55;J++){
	  
	  c[I][J] = min( c[I][J], c[I][k] + c[k][J] );
	  
	}
      
      }
    
    }    
    
  }

  cout<<ans<<endl;
  
}

signed main(){
  
  cin>>n;
  
  for(int i=0;i<n;i++) cin>>a[i];
  
  for(int i=0;i<n;i++) cin>>b[i];
  
  for(int i=0;i<55;i++){
    for(int j=0;j<55;j++){
      if( i == j) c[i][j] = 0;
      else c[i][j] = INF;
    }
  }
  
  for(int i=0;i<55;i++){
    
    for(int k=1;k<=50;k++){
      
      int ni = i % k;
      
      if( i > ni ) c[i][ni] = min( c[i][ni], getCost(k) );
      
    }
    
  }
  
  for(int k=0;k<55;k++){
    
    for(int i=0;i<55;i++){
      
      for(int j=0;j<55;j++){
	
	c[i][j] = min( c[i][j], c[i][k] + c[k][j] );
	
      }
      
    }
    
  }
  
  solve();
  
  return  0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <ctype.h>

int main(int argc, char const *argv[])
{
    int n = 0;
    int k = 0;
    int i = 0;

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

    char s[n];

    scanf("%s", s);

    s[k - 1] = tolower(s[k - 1]);

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


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define debug(a) cerr << #a << ": " << a << endl
#define sz(a) int(a.size())
#define rep(i,n) for(int i=0;i<n;i++)
#define forr(i, st, en) for(int i = st; i <= en; i++)
#define all(v) (v).begin(),(v).end()
#define X first
#define Y second
#define pb push_back
#define fast cin.tie(0); ios::sync_with_stdio(false)
#define vi vector<int>
#define vii vector<vector<int>>


int32_t main(){ fast;
	int h, w, k; cin>>h>>w>>k;
	string s[6];
	rep(i, h){
		cin>>s[i];
	}
	int answer = 0;
	rep(a, 1 << h)
		rep(b, 1 << w){
			int cnt = 0;
			rep(i, h)
				rep(j, w)
					if((a >> i & 1)&&(b >> j & 1) && s[i][j] == '#'){
						cnt++;
					}
			if(cnt == k)
				answer++;
		}
	cout<<answer<<endl;
}


Measured memory_bytes: 3660
#include <stdio.h>

int max(int a,int b){
  if(a > b){
    return a;
  }
  return b;
}

int main(void){
  int N,K;
  scanf("%d%d",&N,&K);

  char S[N+1];
  scanf("%s",S);

  int array[N];
  char past = S[0];
  int cnt = 0,num = 0;
  for(int i = 0;i <= N;i++){
    if(S[i] == past){
      cnt++;
    }else{
      array[num++] = cnt;
      past = S[i];
      cnt = 1;
    }
  }
  array[num] = cnt;

  int sum[N];
  int ans = 0;
  sum[0] = 0;
  for(int i = 1;i <= num;i++){
    sum[i] = sum[i-1]+array[i-1];
  }

  //for(int i = 0;i <= num;i++) printf("i = %d ,sum[i] = %d\n",i,sum[i]);

  int start = 0;
  if(S[0] == '0'){
    start = 1;
    ans = sum[K*2];
    if(2*K-1 >= num){
      printf("%d\n",N);
      return 0;
    }
  }else{
    if(2*K+1 >= num){
      printf("%d\n",N);
      return 0;
    }
  }
  for(int i = start;i <= num;i += 2){
    if(i+K*2+1 <= num)
      ans = max(ans,sum[i+K*2+1]-sum[i]);
    else
      ans = max(ans,sum[num]-sum[i]);
  }

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

  return 0;
}

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

int main() {
    int a, b;
    cin >> a >> b;
    if(a == 1) a = 14;
    if(b == 1) b = 14;
    if(a > b) cout << "Alice" << endl;
    else if(a < b) cout << "Bob" << endl;
    else cout << "Draw" << endl;
}

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

int main() {

  int H, W;
  cin >> H >> W;

  vector<vector<string>> answer(H, vector<string>(W));

  for (int i = 0; i < H; i++) {
    string S;
    cin >> S;
    for (int j = 0; j < W; j++) {
      answer[i][j] = S[j];
    }
  }

  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (answer[i][j] == ".") {
        int count = 0;
        if (0 <= j - 1) {
          if (0 <= i - 1) {
            if (answer[i - 1][j - 1] == "#") {
              count++;
            }
          }
          if (answer[i][j - 1] == "#") {
            count++;
          }
          if (i + 1 <= H - 1) {
            if (answer[i + 1][j - 1] == "#") {
              count++;
            }
          }
        }

        if (0 <= i - 1) {
          if (answer[i - 1][j] == "#") {
            count++;
          }
        }

        if (i + 1 <= H - 1) {
          if (answer[i + 1][j] == "#") {
            count++;
          }
        }

        if (j + 1 <= W - 1) {
          if (0 <= i - 1) {
            if (answer[i - 1][j + 1] == "#") {
              count++;
            }
          }

          if (answer[i][j + 1] == "#") {
            count++;
          }

          if (i + 1 <= H - 1) {
            if (answer[i + 1][j + 1] == "#") {
              count++;
            }
          }
        }
        answer[i][j] = to_string(count);
      }
    }
  }

  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cout << answer[i][j];
    }
    cout << endl;
  }

}

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

struct UnionFind {
    vector<int> par;
    UnionFind(int n) : par(n) {
        init(n);
    }
    
    void init(int n) {
        for(int i = 0; i < n; ++i) par[i] = i;
    }
    
    int root(int x) {
        if(par[x] == x) return x;
        else return par[x] = root(par[x]);
    }
    
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
    
    void merge(int x, int y) {
        x = root(x);
        y = root(y);
        if(x == y) return;
        
        par[x] = y;
    }
};

int main() {
    int N, M; cin >> N >> M;
    vector<int> p(N);
    for(int i = 0; i < N; ++i) cin >> p[i];
    
    UnionFind tree(N);
    for(int i = 0; i < M; ++i) {
        int x, y; cin >> x >> y;
        --x, --y;
        tree.merge(p[x]-1, p[y]-1);
    }
    
    int res = 0;
    for(int i = 0; i < N; ++i) {
        if(tree.issame(i, p[i]-1)) ++res;
    }
    
    cout << res << endl;
}


Measured memory_bytes: 1024
def solve(string):
    n, m, *xyz = map(int, string.split())
    t = [-1] * (n + 1)
    for x, y, z in zip(*[iter(xyz)] * 3):

        def union(r1, r2):
            new_root = min(r1, r2)
            if r1 != r2:
                t[max(r1, r2)] = new_root

        def find(x):
            if t[x] < 0:
                return x
            t[x] = find(t[x])
            return t[x]

        union(find(x), find(y))
    return str(t[1:].count(-1))


if __name__ == '__main__':
    n, m = map(int, input().split())
    print(solve('{} {}\n'.format(n, m) + '\n'.join([input() for _ in range(m)])))


Measured memory_bytes: 34872
#include <stdio.h>
int main(void){
    // Your code here!
    int a,b;
    int i = 9;
    int c = 0;
    scanf("%d",&a);
    while(i >= 1){
        b = a / i;
        if(b < 10 && a%i == 0){
            c+=1;
            printf("Yes");
            break;
        }
        i--;
    }
    if(c == 0){
    printf("No");
    }
}

Measured memory_bytes: 128
// A - Diverse Word

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

bool is_in(char needle, string& haystack) {
	return (haystack.find(needle) != string::npos);
}

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

	if (S == "zyxwvutsrqponmlkjihgfedcba") {
		cout << -1 << endl;
		return 0;
	}

	string ans;
	bool found = false;
	for (char c='a'; c<='z'; c++) {
		if (!is_in(c, S)) {
			cout << S + c << endl;
			return 0;
		}
	}

	string T = S;
	vector<char> C;
	while(1) {
		C.push_back(T.back());
		T.pop_back();
		sort(C.begin(), C.end());
		for (char c : C) {
			T.push_back(c);
			if (T > S) {
				cout << T << endl;
				return 0;
			}
			T.pop_back();
		}
	}

	return 0;
}

Measured memory_bytes: 3604
def func(x):
    if x // 10 == 0:
        return x
    else:
        return x % 10 + func(x // 10)

n = int(input())
ans = float('inf')
for a in range(1, (n // 2) + 1):
    ans = min(ans, func(a) + func(n - a))
print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int a[1006][1006];
int sumb[1006];
int main()
{
	int h,w,A,b;cin>>h>>w>>A>>b;
	for(int j=1;j<=A;j++)
	for(int i=1;i<=b;i++) a[i][j]=1;
	for(int j=A+1;j<=w;j++)
	{
		for(int i=1;i<=b;i++) a[i][j]=0;
	}
	for(int i=1;i<=A;i++)for(int j=b+1;j<=h;j++) a[j][i]=0;
	for(int i=A+1;i<=w;i++)
	{
		for(int j=b+1;j<=h;j++) a[j][i]=1;
	}
	for(int i=1;i<=h;i++)
	{
		for(int j=1;j<=w;j++) cout<<a[i][j];
		cout<<endl;
	}
 } 

Measured memory_bytes: 5120
#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

const int INF = 1001001001;
const double EPS = 1e-10;

int main()
{
	int n;
	while(scanf("%d%*c", &n), n){
		char line[2048];
		map<string, int> dict;
		rep(i, n){
			fgets(line, sizeof(line), stdin);
			stringstream sstr(line);
			for(string word; sstr >> word;)
				dict[word]--;
		}
		
		vector<pair<int, string> > a;
		scanf("%s", line);
		for(map<string, int>::iterator itr=dict.begin(); itr!=dict.end(); ++itr){
			if(itr->first[0] == line[0])
				a.push_back(make_pair(itr->second, itr->first));
		}
		if(a.empty())
			puts("NA");
		else{
			sort(a.begin(), a.end());
			rep(i, min(5, (int)a.size()))
				printf("%s%s", i ? " " : "", a[i].second.c_str());
			puts("");
		}
	}
	return 0;
}

Measured memory_bytes: 1268
/* BISMILLAHIR RAHMANIR RAHIM */
#include<bits/stdc++.h>
using namespace std;
#define ll        long long
#define ull       unsigned long long
#define si(x)     scanf("%d", &x)
#define sll(x)    scanf("%lld", &x)
#define sd(x)     scanf("%lf", &x)
#define l0(i,n)   for(ll i=0; i<n; i++)
#define MAX       100000
#define maxn 	  200002
#define pb 		  push_back
#define mk 		  make_pair
#define endl	  "\n"
#define INF 	  1000000000
#define MOD		  1000000007
#define vll(a)	  vector<ll>a
#define imie(...) "[" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "


int main ()
{
		ios::sync_with_stdio(0);
		cin.tie(0);
		//CODE TONOY
		ll n;
		sll(n);
		vll(a);
		for (int i=0 ; i<n ; i++)
		{
			ll x;
			sll(x);
			a.pb(x);
		}
		ll res = 0;
		ll fact= 1;
		for (int d=0 ; d<60 ; d++)
		{
			ll even=0,odd=0;
			for (int i=0 ; i<n ; i++)
			{
				 if (a[i] & (1LL << d))
				 odd++;
				 else
				 even++;
			}
		    ll add = (odd * even) % MOD * fact % MOD;
			res = (res + add) % MOD;
			fact = (fact * 2) % MOD;
		}
		cout << res << endl;
		return 0;
}


Measured memory_bytes: 7488
import java.util.Scanner;

public class Main{
public static void main(String[] args){
Scanner scan=new Scanner(System.in);
String s=scan.next();
String t=scan.next();
int a=scan.nextInt();
int b=scan.nextInt();
String u=scan.next();

if(s.equals(u)){
   a=a-1; 
}else{
    b=b-1;
}




System.out.println(a+" "+b);
}
}

Measured memory_bytes: 23892
#include<bits/stdc++.h>
using namespace std ;
#define ll long long int 
#define pb push_back 
#define mp make_pair 
#define pii pair <int , int > 
#define pll pair < ll , ll >
int main(){
	ios_base::sync_with_stdio(false) ;
	cin.tie(NULL) ;
	int k , x ;
  cin >> x >> k ;
  for(int i = min(k - x + 1 , k + x - 1)  ; i <= max(k - x + 1 , k + x - 1) ; i++) cout << i << " " ; 
}

Measured memory_bytes: 256
#include <cctype>
#include <iostream>

int main() {
  int a, b, c, d, e, f;
  std::cout.precision(3);
  std::cout << std::fixed;
  while (!std::cin.eof()) {
    std::cin >> a >> b >> e >> c >> d >> f;

    double factor = a * d - b * c;
    double x = ( d * e + -b * f) / factor;
    double y = (-c * e +  a * f) / factor;
    if (x == 0.0) { x = 0.0; }
    if (y == 0.0) { y = 0.0; }
    std::cout << x << ' ' << y << std::endl;

    while (isspace(std::cin.peek())) { std::cin.ignore(); }
  }
}

Measured memory_bytes: 0
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <vector>
#include <utility>
#include <algorithm>
#include <string>
#include <queue>
#include <stack>
#include <tuple>
#include <set>
#include <map>
#include <functional>
#include <cmath>
#include <cstring>
#include <time.h>
using namespace std;
#define sci(n) scanf("%lld", &(n))
#define scd(n) scanf("%Ld", &(n))

typedef long long LL;
typedef pair<LL, LL> PLL;

LL cb[57][75];

LL c(LL n, LL k) {
	if (k > (n / 2)) { k = n - k; }
	if (k<0 || k>n) {
		return 0;
	}
	if (k < 1) {
		return 1;
	}
	if (n == k) {
		return 1;
	}
	LL& ret = cb[n][k];
	if (ret != -1) {
		return ret;
	}
	return ret = (c(n - 1, k) + c(n - 1, k - 1));
}

LL fac(LL n) {
	LL ret = 1;
	if (n == 0) { return 0; }
	while (n >= 1) {ret *= n; n--;}
	return ret;
}

bool isAllSame(vector<LL>& v,LL st, LL fin) {
	return v[st] == v[fin - 1];
}

int main(void)
{
	memset(cb, -1, sizeof(cb));
	LL n, a, b;
	sci(n), sci(a), sci(b);
	vector<LL> v(n,0),prefix(n,0);
	for (int i = 0; i < n; i++) sci(v[i]); 
	sort(v.begin(), v.end(), std::greater<LL>());
	prefix[0] = v[0];
	for (int i = 1; i < n; i++) prefix[i] = prefix[i - 1] + v[i];
	//for (int i = 0; i < v.size(); i++) {printf("%lld ", v[i]);}
	double avg = (double)prefix[a - 1] / a; printf("%lf\n", avg);
	LL ans = 0;
	LL pick = v[0], uni = 0, cnt = 1, samenumcnt = 0;
	map<LL, LL> mp;
	for (int i = 0; i < a; i++) {mp[v[i]]++;}

	for (int i = 0; i < v.size(); i++) {
		if (isAllSame(v, i, a)) {
			uni += 1; 
			if(i<a){
				samenumcnt += 1;
			}
		}
	}
	if (samenumcnt == a) {
		for (int i = a; i <= b; i++) {
			ans += c(uni, i);
		}
	}
	else {	
		ans += c(uni, samenumcnt); 
	}
	time_t st, fin;
	int moroje_ganbatte = 1;
	st = clock();
	for (;;) {
		fin = clock();
		if (fin - st > 1901000) {
			break;
		}
		moroje_ganbatte++;
	}
	printf("%lld", ans);
	
	return 0;
}

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

using Bit = int;

int H, W = 4, N;
vector<Bit> B;

bool test(Bit b, int i) {
  return (b >> i) & 1;
}

Bit set(Bit b, int i, int j) {
  return b | (1 << i) | (1 << j);
}

bool ok(Bit u, Bit d, int i) {
  if(test(u, i) || test(u, i + 1)) return false;
  if(test(d, i) || test(d, i + 1)) return false;
  return true;
}

int dfs(int y, Bit b) {
  static vector<vector<int>> memo(H, vector<int>(1 << W, -1));
  if(~memo[y][b]) return memo[y][b];
  if(H-1 <= y) return 0;
  auto res = dfs(y+1, B[y+1]);
  for(auto i = 0; i < W-1; ++i) if(ok(b, B[y+1], i)) res = max(res, 1 + dfs(y+1, set(B[y+1], i, i+1)));
  if(ok(b, B[y+1], 0) && ok(b, B[y+1], 2)) res = max(res, 2 + dfs(y+1, 0b1111));
  return memo[y][b] = res;
}

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

  B.resize(H);
  for(int i = 0; i < N; ++i) {
    int x, y;
    cin >> x >> y;
    B[y] |= 1 << x;
  }

  cout << dfs(0, B[0]) << endl;
}

Measured memory_bytes: 4988
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define puts(i) cout<<i<<endl
#define pi 3.14159265358979323846264338
#define pb push_back
#define mp make_pair
#define inf 10000
using ll = long long;
using P = pair<int,int>;
using Pll = pair<ll,ll>;

ll divisor=1000000007;

int main(){
	int n;
	string s;
	cin>>n>>s;
	int ans=0;
	rep(i,1000){
		vector<int> v;
		int a=i;
		rep(j,3){
			v.pb(a%10);
			a/=10;
		}
		a=2;
      	
		rep(j,n){
			if(s[j]=='0'+v[a])a--;
          	if(a==-1)break;
		}
		if(a==-1)ans++;
	}
  puts(ans);
}


Measured memory_bytes: 256
fun main(arg: Array<String>) {
    val (K, X) = listOfInt()
    val max = 1000000
    val min = -max
    var l = X - K + 1; if (l < min) l = min
    var r = X + K - 1; if (r > max) r = max
    val ans = mutableListOf<Int>()
    for (n in l..r) ans.add(n)
    println(ans.joinToString(separator = " "))
}
fun next() = readLine()!!
fun listOfString() = next().split(" ")
fun listOfInt(delta: Int = 0) = listOfString().map { Integer.parseInt(it) + delta }


Measured memory_bytes: 36116
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
using namespace std;

int main(){
	int n,m,i,x=0,y=100005,l[100005]={0},r[100005]={0};
	cin>>n>>m;
	for(i=1;i<=m;i++){
		cin>>l[i]>>r[i];
	}
	for(i=1;i<=m;i++){
		if(x<l[i]) x=l[i];
		if(y>r[i]) y=r[i];
		if(y<x) break;
	}
	if(y-x>=0) cout<<y-x+1;
	else cout<<0;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <cstdio>
#include <string>
#include <stack>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <numeric>
using namespace std;

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

    long ans = 0;
    
    if(N != 100){


        if(D == 0){
            ans = N;
        }else if(D == 1){
            ans = N * 100;
        }else{
            ans = N * 10000;
        }


    }else{
        if(D == 0){
            ans = N+1;
        }else if(D == 1){
            ans = (N+1) * 100;
        }else{
            ans = (N+1) * 10000;
        }
    }
        cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int K = in.nextInt();
        int A = in.nextInt();
        int B = in.nextInt();
        Boolean flag = true;
        for(int i = A; i <= B; i++){
            if(i%K==0){
                System.out.print("OK");
                flag = false;
                break;
            }
        }
        if(flag){
            System.out.print("NG");
        }
    }
}



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

int main() {
	long long N;
	cin >> N;
	double last = sqrt(N);
	int i_max = 1;
	for (int i = 1; i < last+1; i++) {
		if (N % i == 0) i_max = i;
	}
	int ans = 0;
	long long tmp = N / i_max;
	while (tmp > 0) {
		ans++;
		tmp /= 10;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define MOD (1000000007)
#define vi vector<int>
#define vl vector<ll>
#define vvi vector<vi>
#define vvl vector<vl>
#define pii pair<int, int>
#define pli pair<ll, int>
#define pb push_back

#define mp make_pair
#define all(a) (a).begin(),(a).end()

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

ll gcd(ll a, ll b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}

ll keta(ll n){
  string s = to_string(n);
  ll num = s.size();
  return num;
}

const ll INF = 1LL << 60;

const int dh[4] = {1,0,-1,0};
const int dw[4] = {0,1,0,-1};

struct Edge{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w){}
};
using Graph = vector<vector<Edge>>;
using P = pair<ll, int>;

void dfs(int v, vvi &G, vector<bool> &seen){
  if(seen[v]) return;
  seen[v] = true;
  for(auto nv : G[v]) {
    dfs(nv, G, seen);
  }
}

int main(){
  int n,m,p; cin >> n >> m >> p;
  vvi G(n),rG(n);
  vector<tuple<int, int, int>> edges;
  rep(i,m) {
    int a,b,c; cin >> a >> b >> c;
    a--; b--;
    c -= p;
    c = -c;
    edges.emplace_back(a,b,c);
    G[a].pb(b);
    rG[b].pb(a);
  }

  vector<bool> seen1(n,false);
  vector<bool> seen2(n,false);

  dfs(0, G, seen1);
  dfs(n-1, rG, seen2);

  vector<bool> ok(n);
  rep(i,n) ok[i] = seen1[i]&seen2[i];

  vi d(n,1e9);
  d[0] = 0;
  int step = 0;
  bool upd = true;
  while(upd){
    upd = false;
    rep(i,m) {
      int a,b,c;
      tie(a,b,c) = edges[i];
      if(!ok[a] || !ok[b]) continue;
      if(chmin(d[b], d[a] + c)) upd = true;
    }
    step++;
    if(step > n){
      cout << -1 << endl;
      return 0;
    }
  }
    
  int ans = -d[n-1];
  ans = max(ans,0);
  cout << ans << endl;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,a) for(int i=0;i<(a);++i)
#define MP make_pair
#define INF 1e9
#define F first
#define S second
using namespace std;
typedef long long LL;
#define int LL
typedef pair<int, int> P;
int N, M, ans = -1;
int dp[1010][3010][2], v[3010], h[3010], t[1010], s[1010], vrsk[3010];
signed main()
{
	cin >> N >> M;
	REP(i, N)
		scanf("%d%d", v + i, h + i);
	REP(i, M)
		scanf("%d%d", t + i, s + i);
	vrsk[0] = v[0];
	FOR(i, 1, N)
	{
		vrsk[i] = vrsk[i - 1] + v[i];
	}
	dp[0][0][1] = h[0];
	FOR(i, 1, N)
	{
		if(t[0] >= vrsk[i])
			dp[0][i][1] = dp[0][i - 1][1] + h[i] + abs(h[i] - h[i - 1]);
	}
	REP(i, N)
	{
		if(dp[0][i][0] < s[0])
			dp[0][i][0] = -1;
		if(dp[0][i][1] < s[0])
			dp[0][i][1] = -1;
	}
	FOR(i, 1, M)
	{
		REP(j, N)
			if(t[i] >= vrsk[j])
				dp[i][j][0] = max(dp[i - 1][j][0], dp[i - 1][j][1]);
		FOR(j, 1, N)
			if(t[i] >= vrsk[j])
				dp[i][j][1] = max(dp[i][j - 1][0] + h[j], dp[i][j - 1][1] + h[j] + abs(h[j] - h[j - 1]));
		REP(j, N)
		{
			if(dp[i][j][0] < s[i])
				dp[i][j][0] = -1;
			if(dp[i][j][1] < s[i])
				dp[i][j][1] = -1;
		}
	}
	REP(i, N)
	{
		if(dp[M - 1][i][0] > 0 || dp[M - 1][i][1] > 0)
		{
			ans = t[M - 1] - vrsk[i];
			break;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 50256
#include<cstdio>
#include<cstring>
using namespace std;

const int N = 3*1e5+10;

char s[N];
int root,last,sz,ch[N][26],fa[N],sum[N],l[N];
void add(int x) {
    int c=s[x]-'a';
    int p=last,np=++sz; last=np;
    l[np]=x+1;
    for(;p&&!ch[p][c];p=fa[p]) ch[p][c]=np;
    if(!p) fa[np]=root;
    else {
        int q=ch[p][c];
        if(l[p]+1==l[q]) fa[np]=q;
        else {
            int nq=++sz; l[nq]=l[p]+1;
            memcpy(ch[nq],ch[q],sizeof(ch[q]));
            fa[nq]=fa[q];
            fa[np]=fa[q]=nq;
            for(;p&&q==ch[p][c];p=fa[p]) ch[p][c]=nq;
        }
    }
}

int n,m,b[N],cnt[N];

void get_sum() {
    for(int i=1;i<=sz;i++) cnt[l[i]]++;
    for(int i=1;i<=n;i++) cnt[i]+=cnt[i-1];
    for(int i=1;i<=sz;i++) b[cnt[l[i]]--]=i;
    for(int i=sz;i;i--) {
        int p=b[i]; sum[p]=1;
        for(int j=0;j<26;j++)
            sum[p]+=sum[ch[p][j]];
    }
}

int main() {
    scanf("%s",s);
    n=strlen(s);
    root=last=++sz;
    for(int i=0;i<n;i++) add(i);
    get_sum();
    m = 1;
    while(m--) {
        int x,p=root; scanf("%d",&x);
        while(x) {
            for(int c=0;c<26;c++)if(ch[p][c]) {
                if(sum[ch[p][c]]>=x) {
                    putchar('a'+c);
                    x--; p=ch[p][c];
                    break;
                }
                else x-=sum[ch[p][c]];
            }
        }
        puts("");
    }
    return 0;
}

Measured memory_bytes: 6400
//
// Created by Myabu on 2020/01/26.
//

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <utility>
#include <math.h>
#include <stack>
#include <queue>
#include <cstdio>
#include <numeric>
#include <iomanip>

using namespace std;


int main(void){
    int A,B;
    
    cin>>A>>B;
    
    if(A<=5){
        cout<<0<<endl;
    }else if(A<=12){
        cout<<B/2<<endl;
    }else{
        cout<<B<<endl;
    }
    
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cstdint>
#include <cstdlib>
#include <algorithm>
#include <cmath>

typedef long long ll;

int main() {
    ll a,b,c,x,y;
    std::cin >> a >> b >> c >> x >> y;

    ll ooi_nedan = x > y ? a : b;
    ll ans1 = a * x + b * y;
    ll ans2 = c * 2 * std::max(x,y);
    ll ans3 = c * 2 * std::min(x,y) + ooi_nedan * std::abs(x-y);

    std::cout << std::min(ans1, std::min(ans2,ans3)) << std::endl;
    return 0;
}



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

using namespace std;

#define endl "\n"
#define f first
#define s second
typedef long long int ll;

inline void fastio(){ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);}
inline void setPrecision(int n){cout.precision(n);}

ll INF = 1e10;
int MOD = 1e9+7;

const int mxn = 3001;
int n;
double arr[mxn];

int main(){
	fastio();
	setPrecision(10);
	cin>>n;
	for(int i=1;i<=n;++i) cin>>arr[i];
	double dp[n+1][n+1],ans = 0;
	dp[0][0] = 1;
	for(int h=0;h<=n;++h){
		for(int t=0;t<=n-h;++t){
			if(h==0 && t==0) continue;
			else if(h==0) dp[0][t] = dp[0][t-1]*(1-arr[t]);
			else if(t==0) dp[h][0] = dp[h-1][0]*arr[h];
			else dp[h][t] = dp[h-1][t]*arr[h+t] + dp[h][t-1]*(1-arr[h+t]); 
			if(h > t && h+t == n) ans += dp[h][t];
		}
	}
	cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 49980
def v():
 for e in iter(input,'0 0'):
  r=int(e.split()[0])
  d=[int(''.join(x),2)for x in zip(*[input().split()for _ in[0]*r])]
  a=0
  for m in range(1<<~-r):
   t=0
   for s in d:
    c=bin(m^s).count('1')
    t+=max(c,r-c)
   if a<t:a=t
  print(a)
if'__main__'==__name__:v()


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

#define LL long long
#define pii pair<int,int>
using namespace std;
const int inf = 2147483647;
const int N = 100001;

int _max(int x, int y) {return x > y ? x : y;}
int _min(int x, int y) {return x < y ? x : y;}
inline LL read() {
    LL x = 0, f = 1; char ch = getchar();
    while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
    while(ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();
    return x * f;
}
void put(int x) {
	if(x < 0) putchar('-'), x = -x;
	if(x >= 10) put(x / 10);
	putchar(x % 10 + '0');
}

vector<pii> e[2];
int fa[N], tot[N];

int findfa(int x) {
	if(fa[x] ^ x) fa[x] = findfa(fa[x]);
	return fa[x];
}

int main() {
	int n = read();
	LL m = read(); int q = read();
	for(int i = 1; i <= q; i++) {
		int x = read() + 1, y = read() + 1, c = read();
		e[c].push_back(pii{x, y});
	} for(int i = 1; i <= n; i++) fa[i] = i, tot[i] = 1; LL cc = n;
	if(m == n - 1 && e[1].size() > 0) {puts("No"); return 0;}
	for(auto u : e[0]) {
		int x = u.first, y = u.second;
		int fx = findfa(x), fy = findfa(y);
		if(fx ^ fy) fa[fx] = fy, tot[fy] += tot[fx], cc--;
	} for(auto u : e[1]) {
		int x = u.first, y = u.second;
		int fx = findfa(x), fy = findfa(y);
		if(fx == fy) {puts("No"); return 0; }
	} if(m <= cc * (cc - 1) / 2 + n - cc) puts("Yes");
	else puts("No");
	return 0;
}


Measured memory_bytes: 2036
#include <algorithm>
#include <map>
#include <vector>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cctype>
#include <cstdlib>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <numeric>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define IREP(it,array) for(vector<int>::iterator it=array.begin(); it!=array.end(); ++it)
#define PREP(it,array) for(vector<P>::iterator it=array.begin(); it!=array.end(); ++it)
#define SREP(it,array) for(vector<string>::iterator it=array.begin(); it!=array.end(); ++it)

#define MP       make_pair
#define PB       push_back
#define ALL(x)   (x).begin(),(x).end()

const int INF = 1<<29;
const double EPS = 1e-9;
double zero(double d){
  return d < EPS ? 0.0 : d;
}

typedef long long LL;
typedef pair<int,int> P;


const int N=1000000;
int dp[N], oddDp[N];
const int M=200;
int p[M];


int main()
{
  cout.setf(ios::fixed, ios::floatfield);
  cout.precision(7);


  p[0]=INF;
  for(int i=1; i<M; i++){
    int num = i*(i+1)*(i+2)/6;
    p[i]=num;
  }

  fill( dp, dp+N, INF );
  fill( oddDp, oddDp+N, INF );
  dp[0] = 0;
  oddDp[0] = 0;

  REP(i,N){

    REP(j,M){
      if( i-p[j] >= 0 ){
	if( p[j] %2 == 1 )
	  oddDp[i] = min( oddDp[i], oddDp[i-p[j]]+1 );
	dp[i] = min( dp[i], dp[i-p[j]]+1 );
      }
    }

  }

  int n;
  while(cin>>n,n){
    cout << dp[n] << " " << oddDp[n] << endl;
  }
  

  return 0;
}

Measured memory_bytes: 8972