akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <cmath>
#include <cctype>
#include <ctime>
#include <cassert>

using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define eps 1e-9

typedef long long ll;
typedef pair<int, int> pii;

const int INF = 0x7fffffff;
const int maxn = 200;
char s1[maxn], s2[maxn];

int main() {
#ifdef __AiR_H
    freopen("in.txt", "r", stdin);
//    freopen("out.txt", "w", stdout);
#endif // __AiR_H
    scanf("%s %s", s1, s2);
    int len1 = strlen(s1), len2 = strlen(s2);
    int t;
    if (len1 > len2) { t = 1; }
    else if (len1 < len2) { t = -1; }
    if (len1 == len2) { t = strcmp(s1, s2); }
    if (t > 0) { printf("GREATER\n"); }
    else if (t == 0) { printf("EQUAL\n"); }
    else { printf("LESS\n"); }
#ifdef __AiR_H
    printf("Time used = %.2fs\n", (double)clock() / CLOCKS_PER_SEC);
#endif // __AiR_H
    return 0;
}


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

int main(){
  int N,K;
  string S;
  cin>>N>>K>>S;
  int s = S[K-1];
  S[K-1]=s+32;
  
  for(int i=0;i<N;i++){
   cout<<S[i];
  }
  cout<<"\n";
  
  return 0;
}

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

int main(){
  int a,b;
  cin >> a >> b;
  int c = a * b;
  
  if (c % 2 == 0){
    cout << "Even" << endl;
  }
  else {
    cout << "Odd" << endl;
  }

}

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

int N, M, dp[100000], ans;
vector<int> G[100000];

int rec(int v){
	if(dp[v] != -1) return dp[v];
	int ma = -1;
	for(int i=0; i<G[v].size(); i++){
		if(ma < rec(G[v][i])) ma = rec(G[v][i]);
	}
	ma++;
	return dp[v] = ma;
}

int main(){
	cin >> N >> M;
	for(int i=0; i<M; i++){
		int x, y; cin >> x >> y;
		x--; y--;
		G[x].push_back(y);
	}
	fill(dp, dp+N, -1);
	for(int i=0; i<N; i++)
		if(ans < rec(i)) ans = rec(i);
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 8192
n = int(input())
a = "abcdefghijklmnopqrstuvwxyz"
d = 0
while n > 0:
    d += 1
    n -= 26 ** d
n += 26 ** d-1
s = ""
while d:
    s = s + a[n % 26]
    n = n // 26
    d -= 1
print(s[::-1])

Measured memory_bytes: 9144
def bfs(adj, s):
    n = len(adj)
    d = [-1 for _ in range(n)]
    c = [0 for _ in range(n)]

    d[s] = 0
    c[s] = 1

    queue = [s]

    while len(queue) > 0:
        u = queue.pop(0)
        for v in adj[u]:
            if c[v] == 0:
                c[v] = 1
                d[v] = d[u] + 1
                queue.append(v)

    return d


n = int(input())
adj = [[] for _ in range(n)]
for _ in range(n):
    s = [int(x) for x in input().split()]
    u = s[0]
    for v in s[2:]:
        adj[u - 1].append(v - 1)

d = bfs(adj, 0)

for i in range(n):
    print(str(i + 1) + " " + str(d[i]))


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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;


int main() {
    int N; cin >> N;
    vector<int> A(N); REP(i,N) cin >> A[i];

    
    vector<int> d(N+1);
    d[0] = abs(A[0]);
    d[N] = abs(A[N-1]);
    FOR(i,1,N){
        d[i] = abs(A[i] - A[i-1]);
    }

    int sum = 0;
    REP(i,N+1){
        sum += d[i];
    }

    vector<int> dd(N);
    dd[0] = abs(A[1]);
    dd[N-1] = abs(A[N-2]);
    FOR(i,1,N-1){
        dd[i] = abs(A[i+1] - A[i-1]);
    }

    REP(i,N){
        cout << sum - d[i] - d[i+1] + dd[i] << endl;
    }


    return 0;
}

Measured memory_bytes: 4588
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        final Scanner lineScanner = new Scanner(System.in);
        final int inputLineNum = lineScanner.nextInt();
        double sum = 0;
        for (int i = 0; i < inputLineNum; i++) {
            double value = lineScanner.nextDouble();
            String money = lineScanner.next();
            if (money.equals("BTC")) {
                sum += value * 380000.0;
            } else {
                sum += value;
            }
        }
        System.out.println(sum);
    }
}

Measured memory_bytes: 24144
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし


from collections import defaultdict

N = I()
D = LI()
d1 = defaultdict(int)
for d in D:
    d1[d] += 1

M = I()
T = LI()
d2 = defaultdict(int)
for t in T:
    d2[t] += 1

for key in d2.keys():
    if d2[key] > d1[key]:
        print('NO')
        break
else:
    print('YES')


Measured memory_bytes: 152072
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
ll GetDigit(ll num){ return log10(num)+1; } //numの桁数を求める

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    ll ans = 1000;
    int mi = a[0];
    ll k = 0;
    for (int i = 0; i < n-1; i++)
    {
        if(a[i+1] > mi){
            k = ans/mi;
            //cout << k << " " <<  mi<< endl;
            ans -= k*mi;
            //cout << ans << endl;
            ans += a[i+1]*k;
            //cout << ans << endl;
            mi = a[i+1];
        }else{
            mi = a[i+1];
        }
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 3616
#define _USE_MATH_DEFINES
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<iomanip>
#include<cassert>

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

	int a, b;
	std::cin >> a >> b;

	if (a % 2 != 0 && b % 2 != 0){//aもbも奇数
		std::cout << "Yes\n";
	}
	else{
		std::cout << "No\n";
	}

	return 0;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
x = list(map(int, input().split()))
ans = float('inf')
for i in range(N-K+1):
    ans = min(ans, abs(x[i]) + abs(x[i]-x[i+K-1]))
    ans = min(ans, abs(x[i+K-1]) + abs(x[i]-x[i+K-1]))
print(ans)

Measured memory_bytes: 14224
#include <iostream>
#include <bits/stdc++.h>
#define mod 1000000007
typedef long long ll;

using namespace std;

void Fastio(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

ll fact[1000006], inv[1000006];

ll fp(ll base, ll exp)
{
    if (exp == 0)
        return 1;
    ll ans = fp(base, exp / 2);
    ans = (ans * ans) % mod;
    if (exp % 2 != 0)
        ans = (ans * (base % mod)) % mod;
    return ans;
}

void calcFacAndInv(ll n)
{
    fact[0] = inv[0] = 1;
    for (ll i = 1; i <= n; i++)
    {
        fact[i] = (i * fact[i - 1]) ;
        inv[i] = fp(fact[i], mod - 2);
    }
}

ll ncr(ll n, ll r)
{
    return ((fact[n] * inv[r]) % mod * inv[n - r]) % mod;
}

ll npr(ll n, ll r)
{
    return (fact[n] * inv[n - r]) % mod;
}

long double  NCR(int n, int m){
    long double res = 1;
    m = min(m, n - m);
    for(int i = 0; i < m; i++){
        res = res * ( n - i) / (i + 1);
 }
    return res;
}
ll tol(string a){
    ll res=0;
    while(a[0]=='0'){
        a.erase(a.begin());
    }
    if(a=="")a="0";
    for(int i=0; i<a.size(); i++){
        res*=10; res+=a[i]-'0';
    }
    return res;
}
int check(string a, string b){
    for(int i=0; i<a.size(); i++){
        if(a[i]>b[i])return 1;
        if(b[i]>a[i])return -1;
    }
    return 0;
}
class data{
public:
    ll v,d,p;
    data(){}
    data(ll vv, ll dd, ll pp){
        v=vv;  d=dd; p=pp;
    }
};

int primeFactors(int n)
{
    ll c=0;
    while (n % 2 == 0)
    {
        c++;
        n = n/2;
    }
    for (int i = 3; i*i <= n; i = i + 2)
    {
        while (n % i == 0)
        {
            c++;
            n = n/i;
        }
    }
    if (n > 2)
        c++;
    return c;
}
ll d, dp[100005][105][2][2];
string a;
ll solve(int i, int x, int st, int z){
    if(i==a.size())
        return (x==0 && z);
    if(dp[i][x][st][z]!=-1)return dp[i][x][st][z];
    ll res=0, mx=a[i]-'0';
    if(st)mx=9;
    for(int y=0; y<=mx; y++){
        if(y<a[i]-'0')
            res+=solve(i+1,(x+y)%d,1,(z||y>0));
        else res+=solve(i+1,(x+y)%d,st,(z||y>0));
        res%=mod;
    }
    return dp[i][x][st][z]=res;
}

int main()
{
    Fastio();
    cin>>a>>d;
    memset(dp,-1,sizeof(dp));
    cout<<solve(0,0,0,0)<<'\n';

    return 0;
}


Measured memory_bytes: 331136
#![allow(unused_imports)]
#![allow(unused_variables)]
use proconio::input;
use proconio::marker::*;
use std::cmp::{min, max};
use std::collections::{HashSet, HashMap, BinaryHeap};

fn main() {
    input! {
        s: Chars,
        t: Chars,
    }
    let ans = s.windows(t.len())
        .map(|x| x.iter().zip(t.iter()).filter(|(xi, ti)| xi != ti).count())
        .min()
        .unwrap();
    println!("{}", ans);
}


Measured memory_bytes: 2200
/*
author: Apoorv Singh
*/

#include <bits/stdc++.h>
using namespace std;

typedef vector <long long> vi;
typedef pair <long long, long long> pii;
#define pb push_back   
#define all(c) c.begin(), c.end()
#define watch(x) cout << (#x) << " " << (x) << endl;
#define FOR(i, a, b) for (long long i = a; i < b; ++i)
#define FORR(i, a, b) for (long long i = a; i > b; --i)
#define um unordered_map
#define F first
#define S second
#define int long long
#define inf LLONG_MAX
#define endl "\n"

int modulo = 1e9 + 7;

template <class X>

void printarr(X arr[], int n)
{
    for (int i = 0; i < n; ++i)
        cout << arr[i] << " ";
    cout << endl;
}

int fpow(int a, int n)
{
    int ans = 1;
    while (n)
    {
        if (n&1)
            ans = (ans * a)%modulo;
        a = (a*a)%modulo;
        n = n >> 1;
    }
    return ans;
}

/*
const int M = 1e6 + 10;
int composite[M] = {0};

void sieve()
{
    FOR(i,2,M)
    {
        if (!composite[i])
        {
            for (int j = 2*i; j < M; j += i)
                composite[j] = max(composite[j], i);
        }
    }
}
*/

string s;
const int M = 100002;
int n, powers[M];

int solve(int i)
{
    if (i == n-1)
    {
        if (s[i] == '0') return 1;
        else return 3;
    }

    if (s[i] == '0') return (solve(i+1))%modulo;

    return (((2*solve(i+1))%modulo + powers[n-1-i])%modulo);
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    powers[0] = 1;
    FOR(i,1,M) powers[i] = (powers[i-1]*3)%modulo;
    cin >> s;
    n = s.length();
    cout << solve(0);
    return 0;
}

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

int main() {
  int n;
  cin >> n;
  int ans = 0;
  rep(i,n) {
    int l, r;
    cin >> l >> r;
    ans += r - l + 1;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import math

def koch(d, p1, p2):
    if d == 0:
        return

    s_x = (2 * p1[0] + 1 * p2[0])/3
    s_y = (2 * p1[1] + 1 * p2[1])/3
    s = [s_x, s_y]
    t_x = (1 * p1[0] + 2 * p2[0])/3
    t_y = (1 * p1[1] + 2 * p2[1])/3
    t = [t_x, t_y]
    rotated = math.pi * 60 / 180
    u_x = (t_x - s_x) * math.cos(rotated) - (t_y - s_y) * math.sin(rotated) + s_x
    u_y = (t_x - s_x) * math.sin(rotated) + (t_y - s_y) * math.cos(rotated) + s_y
    u = [u_x, u_y]

    koch(d-1, p1, s)
    print(' '.join(map(str, s)))
    koch(d-1, s, u)
    print(' '.join(map(str, u)))
    koch(d-1, u, t)
    print(' '.join(map(str, t)))
    koch(d-1, t, p2)
    

def main():
    n  = int(input())
    p1 = [0.00000000,0.00000000]
    p2 = [100.00000000,0.00000000]
    print(' '.join(map(str, p1)))
    koch(n, p1, p2)
    print(' '.join(map(str, p2)))
if __name__=='__main__':
    main()


Measured memory_bytes: 5744
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
typedef long long ll;
#define pb push_back
#define mii map <int, int>
#define mll map <ll, ll>
#define pii pair <int, int>
#define pll pair <ll, ll>
#define vi vector <int>
#define vd vector <double>
#define vll vector <ll>
#define fi first
#define se second
#define si set <int>
#define sll set <ll>
#define spii set <pii>
#define vs vector <string>
#define vpii vector <pair <int,int> >
#define vpll vector <pair <long long,long long> >
#define vvi vector <vector <int> >
#define vvpii vector <vector <pii > >
#define forn(i, n) for (int i = 0; i < (n); i++)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define for1(i, n) for (int i = 1; i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(),(x).rend()


using namespace std;
const ll INFLL = 1e18;
const int MAXN = 1e6+100;
const ll INF = 1e9;
const ll mod1=1e9+7;
const ll mod2=2e9+11;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    #ifdef LOCAL
    freopen("a.in","r",stdin);
    #endif
    ll k;
    int n;
    cin>>k>>n;
    vector <ll> a(n);
    ll sum=0;
    rep(i,n)
    cin>>a[i];
    for (int i=0;i<n-1;i++)
        sum+=a[i+1]-a[i];
    sum+=a[0];
    sum+=k-a[n-1];
    ll ans=0;
    for (int i=0;i<n-1;i++)
        ans=max(ans,a[i+1]-a[i]);
    ans=max(ans,a[0]+k-a[n-1]);
    cout<<k-ans;





}

Measured memory_bytes: 1792
//==========================================
// ABC131b
//
// 2019/08/20
//==========================================

#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <map>
#include <algorithm>
#include <functional>

using namespace std;

int main(int argc, char* argv[])
{
  int n, l;
  cin >> n >> l;

  int min=999;
  int ans=0;
  for(int i=1; i<=n; i++)
  {
    int temp;
    temp = l + i -1;
    ans += temp;
    if(abs(temp)< abs(min)) min = temp;
  }
  ans -= min; 
  cout << ans << endl;

  return 0;
}

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

int main() {
  int n, m;
  cin >> n >> m;
  int k[n];
  vector<vector<int> > a;
  for ( int i = 0; i < n; i++ ) {
    cin >> k[i];
    vector<int> tmp;
    for ( int j = 0; j < k[i]; j++ ) {
      int t;
      cin >> t;
      tmp.push_back(t);
    }
    a.push_back(tmp);
  }

  int ch[m];
  for ( int i = 0; i < m; i++ ) { ch[i] = 0; }
  for ( int i = 0; i < n; i++ ) {
    for ( int j = 0; j < k[i]; j++ ) {
      ch[a[i][j]-1]++;
    }
  }

  int ans = 0;
  for ( int i = 0; i < m; i++ ) {
    if ( ch[i] == n ) { ans++; }
  }

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


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

let input = (fs.readFileSync("/dev/stdin", "utf8") as string).split("\n");
const [n, k] = input[0].split(" ").map((x: string): number => +x);
const a = input[1].split(" ").map((x: string): number => +x).sort((a, b) => a - b);

const m = new Map<number, number>();
for (const v of a) {
	if (!m.has(v)) {
		m.set(v, 1);
	}
	else {
		m.set(v, m.get(v)! + 1);
	}
}

const z = Array.from(m.entries()).sort((a, b) => a[1] - b[1]);
let s = m.size; // syurui
let result = 0;
for (const [non_used, v] of z) {
	if (s <= k) break;
	result += v;
	s -= 1;
}

console.log(result);


Measured memory_bytes: 73220
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>

#define rep(i,a,b) for(int i=(a);i<=(b);i++)

using namespace std;

const int N=100000 + 10;

int n,m,t;

struct edge{
	int v,nxt; 
}e[N*2]; int len,adj[N]; 

void addedge(int u,int v){
	e[++len].v=v; e[len].nxt=adj[u]; adj[u]=len; 
	e[++len].v=u; e[len].nxt=adj[v]; adj[v]=len; 
}

void input(){
	 int u,v; 
	scanf("%d%d",&n,&m); 
	len=0; memset(adj,-1,sizeof adj);
	rep(i,1,m){
		scanf("%d%d",&u,&v);
		addedge(u,v);
	}
}

int p1,p2; 
bool mark,vis[N]; 
int c[N],f[N],g[N]; 

void dfs(int u,int fa,int col){
	c[u]=col; 
	vis[u]=1;
	for(int k=adj[u];k!=-1;k=e[k].nxt){
		int v=e[k].v;
		if(v==fa) continue; 
		if(!vis[v]) dfs(v,u,-col);
		else {
			p1=u,p2=v; 
			if(c[u]==c[v]) mark=1;
			else mark=0; 
		}
	}
}

void dp(int u,int fa){
	f[u]=c[u];
	for(int k=adj[u];k!=-1;k=e[k].nxt){
		int v=e[k].v;
		if(v==fa) continue;
		if(u==p1 && v==p2) continue;
		if(u==p2 && v==p1) continue; 
		dp(v,u);  
		f[u]+=f[v];
		g[u]+=g[v]; 
	}
}

int list[N],p; 

void solve(){
	mark=p1=p2=0; 
	rep(i,1,n) vis[i]=c[i]=g[i]=f[i]=0; 
	if(m==n-1){
		dfs(1,0,1); 
		dp(1,0); 
		if(f[1]) printf("-1\n"); 
		else{
			int res=0;
			rep(i,1,n) res+=abs(f[i]);
			printf("%d\n",res); 
		}
	}	else{
		int res=0; 
		dfs(1,0,1);
		dp(1,0);
		if(mark){
			if(f[1]%2==1) printf("-1\n");
			else{
				c[p1]-=(f[1]/2);
				c[p2]-=(f[1]/2);
				res+=(abs(f[1])/2); 
				rep(i,1,n) f[i]=0;
				dp(1,0); 
				rep(i,1,n) res+=abs(f[i]);
				printf("%d\n",res); 
			}
		}	else{
			if(f[1]) printf("-1\n");
			else{
				rep(i,1,n) g[i]=f[i]=0;
				g[p1]--; g[p2]++;
				dp(1,0);
				rep(i,1,n){
					if(g[i]==0) res+=abs(f[i]);
					if(g[i]==-1) list[++p]=f[i];
					if(g[i]==1) list[++p]=-f[i]; 
				}
				sort(list+1,list+p+1);
				rep(i,1,p) res+=abs(list[i]-list[(p+1)>>1]);
				res+=abs(list[(p+1)>>1]);
				printf("%d\n",res);  
			}
		}
	}	
}

int main(){
	input();
	solve(); 
	return 0; 
}

Measured memory_bytes: 8576
// https://atcoder.jp/contests/dp/tasks/dp_m

#include <iostream>
#include <vector>
#include <array>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <algorithm>
#include <iomanip>

using namespace std;

int main (int argc, char* argv[]) {
	int a, b;
	cin >> a >> b;

	cout << max(max(a + b, a - b), a * b) << endl;
}


Measured memory_bytes: 256
import math
N = int(input())
A = list(map(int, input().split()))

n2 = 0
n4 = 0
n0 = 0

for a in A:
    if a % 2 == 0 and a // 2 % 2 == 0:
        n4 += 1
    elif a % 2 == 0:
        n2 += 1
    else:
        n0 += 1

if n2 == 0:
    print("Yes" if n4 * 2 + 1 >= N else "No")
else:
    print("Yes" if n4 * 2 + n2 >= N else "No")


Measured memory_bytes: 62704
package main

/*
青木君は任意の整数xに対し、以下の操作を行うことができます。
操作:xをxとKの差の絶対値で置き換える。
整数Nの初期値が与えられます。
この整数に上記の操作を0回以上好きな回数行った時にとりうるNの最小値を求めてください。
*/

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())
	sc.Scan()
	k, _ := strconv.Atoi(sc.Text())

	res := n % k
	if k-res < res {
		fmt.Println(k - res)
		return
	}
	fmt.Println(res)
}


Measured memory_bytes: 640
def main():
  N=int(input())
  A=list(map(int,input().split()))
  s=sum(A)
  Q=int(input())
  d=[0]*(10**5 +1)#各数字の個数
  for i in A:
    d[i]+=1

  for i in range(Q):
    B,C=map(int,input().split())
    s += (C-B)*d[B]
    print(s)
    d[C]+=d[B]
    d[B]=0

if __name__ == "__main__":
    main()

Measured memory_bytes: 21044
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))

n,k =iim()
if n%2 == 0:
    if k <= n//2:
        print('YES')
    else:
        print('NO')
elif k <= (n-1)//2+1:
    print('YES')
else:
    print('NO')

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

int main(){
    long long N; cin >> N;
    long long a[N];
    for(int i=0;i<N;i++) cin >> a[i];
    vector<pair<long long,long long>> res;
    for(long long i=0;i<N;i++){
        res.push_back({a[i],i+1});
    }
    sort(res.begin(),res.end());
    long long ans=0;
    set<long long> st;
    st.insert(0);
    st.insert(N+1);
    for(int i=0;i<N;i++){
        st.insert(res[i].second);
        auto tmp=st.upper_bound(res[i].second);
        long long r=*tmp;
        auto tmp2=st.lower_bound(res[i].second);
        long long l=*(--tmp2);
        //cout << l << " " << r << endl;
        ans+=res[i].first*(r-res[i].second)*(res[i].second-l);
    }
    cout << ans << endl;
}

Measured memory_bytes: 15084
#include <iostream>

using namespace std;

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    
    if(a == b && b == c) cout << 1;
    else if (a == b || b == c || c == a) cout << 2;
    else cout << 3;
    cout << "\n";
    return 0;
}

Measured memory_bytes: 256
n = int(input())
#a = list(map(int, input().split()))
a = []
for i in range(n):
    a.append(int(input()))

b=sorted(a,reverse=True)
max_a=b[0]
max_a2=b[1]

for i in range(n):
    if a[i]==max_a:
        print(max_a2)
    else:
        print(max_a)

Measured memory_bytes: 70104
package main

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

func parseInt(s string) int {
	return int(parseInt64(s))
}

func parseInt64(s string) int64 {
	x, _ := strconv.ParseInt(s, 10, 64)
	return x
}

var reader *bufio.Reader

func readLine() string {
	if reader == nil {
		reader = bufio.NewReader(os.Stdin)
	}
	s, _ := reader.ReadString('\n')
	return strings.TrimSuffix(s, "\n")
}

func readFields() []string {
	return strings.Fields(readLine())
}

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

func max64(a, b int64) int64 {
	if a > b {
		return a
	} else {
		return b
	}
}

func min(a, b int) int {
	if a < b {
		return a
	} else {
		return b
	}
}

func sum(a []int) int {
	total := 0
	for _, x := range a {
		total += x
	}
	return total
}

var CYCLE int64 = 1000000007

var H, W, N int

type Point struct {
	r, c  int
	value int64
}

var w [3000]Point

var factinvCache [200000]int64
var factCache [200000]int64

func modinv(a int64, m int64) int64 {
	var b, u, v int64 = m, 1, 0
	for b != 0 {
		t := a / b
		a -= t * b
		a, b = b, a
		u -= t * v
		u, v = v, u
	}
	u %= m
	if u < 0 {
		u += m
	}
	return u
}

func fact(a int64) int64 {
	if c := factCache[a]; c > 0 {
		return c
	}

	if a == 0 || a == 1 {
		factCache[a] = 1
	} else {
		factCache[a] = (a * fact(a-1)) % CYCLE
	}

	return factCache[a]
}

func factinv(a int64) int64 {
	if c := factinvCache[a]; c > 0 {
		return c
	}

	factinvCache[a] = modinv(fact(a), CYCLE)
	return factinvCache[a]
}

func calc(a, b int) int64 {
	if a > b {
		a, b = b, a
	}

	n := int64(a + b - 2)
	r := int64(a - 1)

	return fit(fit(fact(n)*factinv(r)) * factinv(n-r))
}

func fit(a int64) int64 {
	if a < 0 {
		a += ((-a / CYCLE) + 1) * CYCLE
	}
	return a % CYCLE
}

type SortablePoints []Point

func (a SortablePoints) Len() int           { return len(a) }
func (a SortablePoints) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a SortablePoints) Less(i, j int) bool { return a[i].r+a[i].c < a[j].r+a[j].c }

func main() {
	fmt.Scan(&H, &W, &N)
	total := calc(H, W)
	for i := 0; i < N; i++ {
		fields := readFields()
		r, c := parseInt(fields[0]), parseInt(fields[1])
		w[i].r = r
		w[i].c = c
		w[i].value = calc(r, c)
	}

	sort.Sort(SortablePoints(w[:N]))

	for i := 0; i < N; i++ {
		for j := i + 1; j < N; j++ {
			if w[i].r <= w[j].r && w[i].c <= w[j].c {
				w[j].value = fit(w[j].value - w[i].value*calc(w[j].r-w[i].r+1, w[j].c-w[i].c+1))
			}
		}
		total = fit(total - w[i].value*calc(H-w[i].r+1, W-w[i].c+1))
	}

	fmt.Println(total)
}


Measured memory_bytes: 18048
#include <bits/stdc++.h>
using Int = int64_t;
using UInt = uint64_t;
using C = std::complex<double>;
#define rep(i, n) for(Int i = 0; i < (Int)(n); ++i)
#define guard(x) if( not (x) ) continue;
#ifndef LOCAL_
#define fprintf if( false ) fprintf
#endif

int main() {
   Int n, m;
   std::cin >> n >> m;
   std::vector<Int> ls(m), rs(m), ds(m);
   rep(i,m) {
      std::cin >> ls[i] >> rs[i] >> ds[i];
      ls[i] -= 1, rs[i] -= 1;
   }
   std::vector<std::vector<std::pair<Int,Int>>> nexts(n);
   rep(i,m) {
      nexts[ls[i]].emplace_back(rs[i], ds[i]);
   }
   std::vector<Int> id(n,-1);
   Int nextId = 0;
   std::function<void(Int)> topSort = [&](Int i) {
      if( id[i] != -1 ) return;
      id[i] = -2;
      for(auto kw : nexts[i]) {
         Int k, w; std::tie(k, w) = kw;
         topSort(k);
      }
      id[i] = nextId;
      nextId += 1;
   };
   rep(i,n)
      topSort(i);
   rep(i,m) {
      if( not ( id[ls[i]] > id[rs[i]] ) ) {
         puts("No");
         return 0;
      }
   }
   std::vector<std::pair<Int,Int>> ys;
   rep(i,n) {
      ys.emplace_back(id[i],i);
   }
   std::sort(ys.begin(), ys.end());
   std::reverse(ys.begin(), ys.end());
   Int inf = (Int)1 << 53;
   std::vector<Int> zs(n,inf);
   bool res = true;
   rep(ii,n) {
      Int i = ys[ii].second;
      // fprintf(stderr, "topSort[%ld] = %ld\n", ii, i);
      if( nexts[i].size() <= 1 and zs[i] == inf ) continue;
      if( zs[i] == inf )
         zs[i] = 0;
      for(auto kw : nexts[i]) {
         Int k, w; std::tie(k, w) = kw;
         if( zs[k] != inf and zs[i] + w != zs[k] )
            res = false;
         else
            zs[k] = zs[i] + w;
      }
   }
   puts(res?"Yes":"No");
}



Measured memory_bytes: 17136
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int[] costArray = { scanner.nextInt(), scanner.nextInt(), scanner.nextInt() };
		Arrays.sort(costArray);
		int ans = 0 + Math.abs(costArray[1] - costArray[0]) + Math.abs(costArray[2] - costArray[1]);
		System.out.println(ans);
		scanner.close();
	}
}

Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
int main(){
int N, i, j, w, d, ans=1e9; cin >> N; int X[N];
for(i=0; i<N; i++){ cin >> X[i]; }
for(i=0; i<=100; i++){ 
  for(d=0, j=0; j<N; j++){ w=i-X[j]; d+=w*w; }
  ans=min(ans, d);
}

cout << ans << "\n";
}

Measured memory_bytes: 256
var
  s: array [0..200000] of int64;
  n, i: longint;
  x, ans: int64;
function min(x, y: int64): int64; inline;
begin
  if x < y then exit(x) else exit(y);
end;
begin
  read(n);
  for i := 1 to n do
  begin
    read(x);
    s[i] := s[i - 1] + x;
  end;
  ans := 1000000000000000000;
  for i := 1 to n - 1 do ans := min(ans, abs(s[i] shl 1 - s[n]));
  writeln(ans);
end.

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

using namespace std;

int main()
{
	int n;
	vector<double> vTalls;

	cin >> n;
	if(n == 0)
		return 0;

	for(int i = 0; i < n; ++i)
	{
		double t;
		cin >> t;
		vTalls.push_back( t );
	}

	sort( vTalls.begin(), vTalls.end() );

	for(int i = 0, h = 1; i < n && h <= 6; ++h)
	{
		const double ranks[] = {0.0,165.0,170.0,175.0,180.0,185.0};
		cout<<h<<":";
		for(int j = i; j < n; ++j)
		{
			if( vTalls[j] < ranks[h] )
				cout<<"*";
			else
			{
				i = j;
				break;
			}
		}
		if( h == 6 )
		{
			for(int j = i; j < n; ++j)cout<<"*";
		}
		cout<<'\n';
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#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 N; cin >> N;
  vector<int> a(N);
  rep(i,N) cin >> a[i];
  sort(a.rbegin(), a.rend());
  int alice = 0, bob = 0;
  rep(i,N) {
    if (i%2==0) alice += a[i];
    else bob += a[i];
  }
  cout << alice - bob << endl;
  return 0;
}

Measured memory_bytes: 3124
S=raw_input()
YY=int( S[:2] )
MM=int( S[2:] )

if 1<=YY<=12 and 1<=MM<=12:
	print "AMBIGUOUS"
elif 0<=YY<=99 and 1<=MM<=12:
	print "YYMM"
elif 1<=YY<=12 and 0<=MM<=99:
	print "MMYY"
else:
	print "NA"

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

long long comb(long long n, long long k) {
    if (k == 1) return n;

    return n * comb(n - 1, k - 1) / k;
}

int main() {
    int n, a, b;
    cin >> n >> a >> b;
    vector<long long> v(n);
    for (int i = 0; i < n; i++) {
        cin >> v.at(i);
    } 

    sort(v.begin(), v.end());
    reverse(v.begin(), v.end());

    bool same = true;
    for (int i = 1; i < a; i++) {
        if (v.at(i) != v.at(0)) {
            same = false;
            break;
        }
    }
    if (same) {
        int cnt = 0;
        for (int i = 0; i < n; i++) {
            if (v.at(i) == v.at(0)) cnt++;
        }

        long long ans = 0;
        for (int i = a; i <= b; i++) {
            if (cnt < i) break;
            ans += comb(cnt, i);
        }
        cout << v.at(0) << endl;
        cout << ans << endl;
        return 0;
    }

    int c = 0;
    double ans = 0;
    for (int i = 0; i < a; i++) {
        ans += v.at(i);
        if (v.at(i) == v.at(a - 1)) c++;
    }
    ans /= a;
    
    int cnt = c;
    for (int i = a; i < n; i++) {
        if (v.at(i) == v.at(a - 1)) cnt++;
    }
    
    printf("%.10f\n", ans);
    cout << comb(cnt, c) << endl;
}   

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    string s;
    cin>>s;
    map<char,bool> used;
    for(char c:s){
        if(used[c]){
            cout<<"no"<<endl;
            return 0;
        }
        used[c] = true;
    }
    cout<<"yes"<<endl;
    return 0;
}


Measured memory_bytes: 256
from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    elif n<r: return 0
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under
md=10**9+7

n,m=map(int,input().split())
s=[[0,0]]
for i in range(2,int(m**(0.5)+1)):
  k=0
  frag = 0
  if m%i!=0:
    frag = 1
  while m%i==0:
    m=int(m/i)
    k=k+1
  if frag == 0:
    s.append([i,k])
if m!=1:
  s.append([m,1])
q = [0]*(len(s)-1)
for i in range(1,len(s)):
  q[i-1] = s[i][1]

t = 1
for i in range(len(q)):
  c = cmb(n-1+q[i],q[i])
  t = t*(c%md)
  
print(t%md)

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

#define cn count
#define pb push_back
#define in insert
#define fs first
#define sc second
#define sz size
#define len length
#define forn(i, n) for (ll i = 0; i < (ll) (n); ++i)
#define forni(i, n) for (ll i = 1; i < (ll) (n); ++i)
#define IO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

using namespace std;
using ll = long long;
const ll inf = 1e9+7; 
const double PI =  3.141592653589793;

int main(){
	IO;
	ll a[2];
	forn(i,2)cin>>a[i];	
	sort(a,a+2);
	forn(i,a[1]){
		cout<<a[0];
	}
	cout<<'\n';
	return 0;
}


// _   .-')                .-. .-')                 .-')                                               
//( '.( OO )_              \  ( OO )               ( OO ).                                             
// ,--.   ,--.).-'),-----. ,--. ,--.  .-'),-----. (_)---\_) ,--. ,--.     .-----.  ,-.-')  .-'),-----. 
// |   `.'   |( OO'  .-.  '|  .'   / ( OO'  .-.  '/    _ |  |  | |  |    '  .--./  |  |OO)( OO'  .-.  '
// |         |/   |  | |  ||      /, /   |  | |  |\  :` `.  |  | | .-')  |  |('-.  |  |  \/   |  | |  |
// |  |'.'|  |\_) |  |\|  ||     ' _)\_) |  |\|  | '..`''.) |  |_|( OO )/_) |OO  ) |  |(_/\_) |  |\|  |
// |  |   |  |  \ |  | |  ||  .   \    \ |  | |  |.-._)   \ |  | | `-' /||  |`-'| ,|  |_.'  \ |  | |  |
// |  |   |  |   `'  '-'  '|  |\   \    `'  '-'  '\       /('  '-'(_.-'(_'  '--'\(_|  |      `'  '-'  '
// """    """     """""""" """  """"      """""""  """""""  """"""""      """"""   """         """""""



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

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

    vector<vector<int>> graph(n + 1);

    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;

        graph[a].push_back(b);
        graph[b].push_back(a);
    }

    vector<int> d(n + 1, -1);
    queue<int> q;
    q.push(1);
    d[1] = 0;

    while (!q.empty()) {
        int v = q.front();
        q.pop();

        for (auto to : graph[v]) {
            if (d[to] == -1) {
                d[to] = v;
                q.push(to);
            }
        }
    }

    for (int i = 2; i <= n; i++) {
        if (d[i] == -1) {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
    for (int i = 2; i <= n; i++) {
        cout << d[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 10116
use std::io::*;
use std::str::FromStr;

fn main(){
    let n: usize = read();
    let m: usize = read();
    let q: usize = read();
    //let (l, r): (usize, usize) = (read(), read());
    let mut rui: Vec<Vec<i64>> = vec![vec![0; n+1]; n+1];
    for _ in 0..m {
        let (l, r) = (read::<usize>(), read::<usize>());
        rui[l][r] += 1;
    }
    for i in 0..n {
        for j in 0..n+1 {
            rui[i+1][j] += rui[i][j];
        }
    }
    for i in 0..n {
        for j in 0..n+1 {
            rui[j][i+1] += rui[j][i];
        }
    }
    for _ in 0..q {
        let (p, q) = (read::<usize>(), read::<usize>());
        println!("{}", rui[q][q] - rui[q][p-1] - rui[p-1][q] + rui[p-1][p-1]);
    }
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

Measured memory_bytes: 7036
n,m,x = map(int, input().split())
dat = list(map(int, input().split()))
c_prev = 0
c_next = 0
for i in range(len(dat)):
    if dat[i] < x:
        c_prev += 1
    else:
        c_next += 1
print(min(c_prev, c_next))

Measured memory_bytes: 38256
#include <bits/stdc++.h>
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>*/
 
#define pll              pair <long long,long long>
#define pb               push_back
#define ll               long long
#define ff               first
#define ss               second
#define D(x)             cerr<<#x " = "<<(x)<<endl
#define vll              vector <ll>
#define IOS              ios_base::sync_with_stdio(0); cin.tie(NULL);
#define endl             '\n'   
using namespace std;


int main()
{
    IOS
    ll m,d;
    cin>>m>>d;
    ll ans=0;
    for(ll i=10;i<=d;i++)
    {
        ll temp=i;
        ll d1=i%10;
        temp/=10;
        ll d10=temp%10;
        if(d1>=2&&d10>=2)
        {
            if(1<=(d1*d10)&&(d1*d10)<=m)
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}


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

#A.sort()

ans = 1e9
for i in range(1,N):
  #print(i, sum(A[:i]), sum(A[i:]))
  ans = min(ans, abs(sum(A[:i]) - sum(A[i:])))
  
print(ans)

Measured memory_bytes: 2940
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
template<typename V> constexpr typename V::value_type sum(const V &v) { return accumulate(all(v), 0); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  double x, h;
  while (cin >> x >> h, x) {
    cout << prec(8) << x * x + x * hypot(h, x / 2) * 2 << endl;
  }
}

Measured memory_bytes: 3224
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner stdIn=new Scanner(System.in);
		int N=stdIn.nextInt();
		boolean key=false;
		for(int i=1;i<10;i++){
			if(N%i==0&&N/i<10)
				key=true;
		}
		if(key)
			System.out.println("Yes");
		else
			System.out.println("No");
	}
}

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

int gcd( int m, int n ){
  if(0 == m || 0 == n) return 0;
  while(m != n){
    if(m > n) m = m-n;
    else n = n-m;
  }
  return m;
}
 
int main(){
  int a,b,c;
  cin >>a>>b>>c;
  if(c%gcd(a,b) == 0) cout << "YES" << endl;
  else cout << "NO" << endl;
}

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

int main(){
	char c[2][3], i, j;
	for(i=0;i<2;i++){
		cin >> c[i][0] >> c[i][1] >> c[i][2];
	}
	if(c[0][0]==c[1][2]&&c[0][1]==c[1][1]&&c[0][2]==c[1][0]) cout << "YES";
	else cout << "NO";
}

Measured memory_bytes: 256
from collections import defaultdict

d = defaultdict(int)

n = int(input())

for i in range(1, n+1):
    start = str(i)[0]
    end = str(i)[-1]
    d[(start, end)] += 1

L = list(d.items())

ans = 0

for (start, end), i in L:
    ans += i * d[(end, start)]

print(ans)    

Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) FOR(i,0,b)
#define INF mugen
#define dump(x) cerr<<#x<<"="<<x<<endl
#define ALL(a) (a).begin(),(a).end()
#define EACH(e,v) for(auto& e:v)
#define SORT(v) sort(ALL(v))
#define PERM(v) SORT(v);for(bool c##p=1;c##p;c##p=next_permutation(ALL(v)))
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<vii> viii;
typedef pair<int,int> P;
template <class T> void chmin(T & a, T const & b) { if (b < a) a = b; }
template <class T> void chmax(T & a, T const & b) { if (b > a) a = b; }
template <typename T>
string to_string(const T &n){ostringstream stm;stm << n;return stm.str();}
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
using ll = long long;
const ll mod = 1000'000'007;

string s;

bool used[51];
vector<string> anss;
void init(){
    rep(i,30)used[i]=0;
    anss.clear();
}

void dfs(int now,string t){
    
    if(now==s.size()){
        //dump(t);
        //rep(i,5)dump(used[i]);
        anss.push_back(t);
    }else{
        //使ってない 一つ前にかならず
        if(used[s[now]-'a']==1 || s[now]=='a'){
            t[now]=s[now];
            dfs(now+1,t);
        }
        
        if(!used[s[now]-'a'+1] &&s[now]!='z'){
            
            t[now]=char(s[now]+1);
            used[s[now]-'a'+1]=1;
            dfs(now+1,t);
            used[s[now]-'a'+1]=0;
            

        }

    }
    return;
}
 
signed main(){
    while(cin>>s){
        if(s[0]=='#')break;
        init();

        dfs(0,s);

        cout<<anss.size()<<endl;

        if(anss.size()<=10){
            rep(i,anss.size())cout<<anss[i]<<endl;
        }else{
            rep(i,5)cout<<anss[i]<<endl;
            for(int i=anss.size()-5;i<anss.size();i++){
                cout<<anss[i]<<endl;
            }
        }



    }
 
}



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

int N;
vector<int> v;

int fact2(int n) {
    int result = 0;
    while (n > 0) {
        result += n/2;
        n /= 2;
    }
    return result;
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    
    cin >> N;
    string str;
    cin >> str;
    for (int i = 1; i < N; i++) v.push_back(abs(str[i] - str[i-1]));
    N--;
    
    int cntOne = 0;
    int isOdd = 0;
    for (int i = 0; i < N; i++) {
        if (v[i] == 1) {
            cntOne++;
            if (fact2(N-1) == fact2(i) + fact2(N-1-i)) isOdd ^= 1;
        }
    }
    if (isOdd) cout << 1 << "\n";
    else if (cntOne > 0) cout << 0 << "\n";
    else {
        int isOdd = 0;
        for (int i = 0; i < N; i++) {
            if (v[i] == 2) {
                if (fact2(N-1) == fact2(i) + fact2(N-1-i)) isOdd ^= 1;
            }
        }
        if (isOdd) cout << 2 << "\n";
        else cout << 0 << "\n";
    }
}


Measured memory_bytes: 8216
/* Ahmed Maher ( Acro_14 ) */
/*while(WA)try();*/
#include <bits/stdc++.h>
typedef long long ll;
const ll oo = 0x3f3f3f3f;
int const N = 1e6+5;
int const mod = 1e9+7;
using namespace std;
/*string Alphabet="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string alphabet="abcdefghijklmnopqrstuvwxyz";*/
 int fact[1000005];
bool f=false;
void gcd(int x){
        if(f==true)
            return;
        for(int i=1;i*i<=x;i++){
            if(x%i==0){
                int a=i;
                int b=x/i;
                if(a==b){
                    a=i;
                    b=1;
                }
                if(a!=1){
                    if(fact[a]){
                        f=true;
                        return;
                    }
                    fact[a]++;
                }
                if(b!=1){
                    if(fact[b]){
                        f=true;
                        return;
                    }
                    fact[b]++;
                }
            }
        }
}
int findGCD(int arr[], int n) 
{ 
    int result = arr[0]; 
    for (int i = 1; i < n; i++) 
    {
        gcd(arr[i]);
        result = __gcd(arr[i], result); 
    }
    return result; 
} 
void solve(){
	int n;
	cin>>n;
	int arr[n];	

	for(int i=0;i<n;i++)cin>>arr[i];

    int GCD = findGCD(arr,n);

    if(!f) cout<<"pairwise coprime";
    else if(GCD==1)cout<<"setwise coprime";
    else cout<<"not coprime";
   
  
	cout<<endl;
}

int main()
{
  int t;
	t=1;
     while(t--)
    {
       
		solve();
 
    }
	return 0;
}
 
//       int anss[t+1]; 
//            anss[j]=ans;
//     for(int j=1;j<=t;j++) printf("Case %d: %d\n",j,anss[j]);

Measured memory_bytes: 7764
def D(n, a):
    n = len(a)
    count = 0
    
    l = 0
    r = 0
    
    sum = 0
    for l in range(n):
        while r < n:
            if sum & a[r] == 0:
                sum += a[r]
                x = sum
                r += 1
            else:
                break
        count += r - l
        sum -= a[l]
        
    return count

n = int(input())
a = list(map(int, input().split()))
print(D(n, a))

Measured memory_bytes: 24840
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>

using namespace std;

long long dp[100010][2];
const long long MOD = (long long)1e9 + 7;
vector<vector<int>> e;
bool used[100010];

long long dfs(int p, int c){
    if(dp[p][c] > 0) return dp[p][c];
    used[p] = true;
    long long res = 1;
    for(int i = 0; i < e[p].size(); i++){
        if(used[e[p][i]]) continue;
        if(c == 0)
            res *= ((dfs(e[p][i], 0) + dfs(e[p][i], 1)) % MOD);
        else
            res *= dfs(e[p][i], 0);
        res %= MOD;
    }
    used[p] = false;
    return dp[p][c] = res;
}

int main(){
    int n;
    cin >> n;
    e = vector<vector<int>>(n + 1);
    for(int i = 0; i < n - 1; i++){
        int x, y;
        cin >> x >> y;
        e[x].emplace_back(y);
        e[y].emplace_back(x);
    }
    long long ans = dfs(1, 0) + dfs(1, 1);
    ans %= MOD;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 14336
IDENTIFICATION DIVISION.
 PROGRAM-ID. TEST079.

 DATA DIVISION.
 WORKING-STORAGE SECTION.
 
 01 INP.
  03 N1     PIC 9(1).
  03 N2     PIC 9(1).
  03 N3     PIC 9(1).
  03 N4     PIC 9(1).

 PROCEDURE DIVISION.

  ACCEPT INP.

  IF ((N1 = N2) AND (N2 = N3)) OR
     ((N2 = N3) AND (N3 = N4))
    DISPLAY 'Yes'
  ELSE
    DISPLAY 'No'
  END-IF.

  STOP RUN.

Measured memory_bytes: 512
import sys
import math
def get_array(): return list(map(int, sys.stdin.readline().strip().split()))
def get_ints(): return map(int, sys.stdin.readline().strip().split())
def input(): return sys.stdin.readline().strip()
x,k,d=get_ints()
x=abs(x)
a=x-k*d
ans=0
if a>=0:
    ans=a
else:
    c=k-x//d
    if c%2==0:
        ans=abs(x-(x//d)*d)
    else:
        ans=min(abs(x-(x//d)*d+d),abs(x-(x//d)*d-d))
print(ans)

Measured memory_bytes: 62184
#include<stdio.h>

int main(){
	int k, K;
	scanf("%d", &K);
	int A, B;
	scanf("%d %d", &A, &B);
	if(K <= B - A + 1)
		printf("OK");
	else{
		for(k = A; k <= B; k++){
			if(k % K == 0){
				printf("OK");
				break;
			}
		}
		if(k == B + 1)
			printf("NG");
	}
	return 0;
}

Measured memory_bytes: 1680
#include<bits/stdc++.h>
using namespace std;
int main(){
	char a,b;
	cin>>a>>b;
	if(a=='H'&&b=='H') puts("H");
	if(a=='H'&&b=='D') puts("D");
	if(a=='D'&&b=='H') puts("D");
	if(a=='D'&&b=='D') puts("H");	
	return 0;
}

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

namespace past10.Abc
{
    public class Question9
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            string S = Console.ReadLine();
            string revS = new string(S.Reverse().ToArray());
            string[] s = new string[] {"dream","dreamer","erase","eraser" };
            for(int i=0;i<4;++i) {
                s[i] = new string(s[i].Reverse().ToArray());
            }

            bool can = true;
            for(int i=0;i<revS.Length;){
                bool can2 = false;
                for(int k=0;k<4;++k){
                    if(revS.Length - i < s[k].Length) {
                        continue;
                    }
                    if(revS.Substring(i, s[k].Length) == s[k]){
                        can2 = true;
                        i+=s[k].Length;
                    }
                }
                if(!can2) {
                    can = false;
                    break;
                }
            }

            Console.WriteLine(can ? "YES" : "NO");

            Console.Out.Flush();
        }
    }
}

Measured memory_bytes: 28920
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int MOD =1e9+7;
using ll=long long;

int main() {
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    int ans = 0;
    if(a >= k)  ans = k;
    else if(a+b >= k) ans = a;
    else ans = a - (k-a-b);
    cout << ans << endl;
}

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

long n, k, a[1<<18];
long double b[1<<18], sum[1<<18];

int main(){
  cin >> n >> k;
  for(int i = 1; i <= n; i++) cin >> a[i];
  for(int i = 1; i <= n; i++) b[i] = b[i-1] + (long double)log10(a[i]);
  for(int i = k; i <= n; i++) sum[i] = b[i] - b[i-k];
  for(int i = k+1; i <= n; i++) cout << (sum[i-1] + 1e-20 < sum[i] ? "Yes" : "No") << endl;
  return 0;
}

Measured memory_bytes: 11712
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
const ll N=2000,p=1e9+7;
ll f[N+10][N+10],fac[N*N+10],ifac[N*N+10];

ll fpm(ll a,ll b)
{
	ll ret=1;
	for(;b;b>>=1) ret=(b&1)?ret*a%p:ret,a=a*a%p;
	return ret;
}

inline ll C(ll a,ll b){return fac[a]*ifac[b]%p*ifac[a-b]%p;}

inline void add(ll &a,ll b){a=a+b>=p?a+b-p:a+b;}

int main()
{
	fac[0]=1;
	for(ll i=1;i<=N*N;++i) fac[i]=fac[i-1]*i%p;
	ifac[N*N]=fpm(fac[N*N],p-2);
	for(ll i=N*N-1;i>=0;--i) ifac[i]=ifac[i+1]*(i+1)%p; 
	
	int n,k;scanf("%d %d",&n,&k);
	if(k==1){printf("1\n");return 0;};
	f[0][0]=1;
	for(int j=1;j<=n;++j) f[0][j]=f[0][j-1]*C(j*(k-1)-1,k-2)%p;
	for(int i=1;i<=n;++i)
		for(int j=i;j<=n;++j)
		{
			f[i][j]=f[i-1][j];
			if(j>i) add(f[i][j],f[i][j-1]*C(j*(k-1)+i-1,k-2)%p);
		};
	printf("%lld\n",f[n][n]*fac[n]%p);
	return 0;
}

Measured memory_bytes: 92800
//Heaplax
#include<bits/stdc++.h>
#define N 1000005
#define LL long long
#define LOG(x) cerr<<#x<<" = "<<x<<endl
#define add_edge(u,v) nxt[++cnt]=head[u],head[u]=cnt,to[cnt]=v
#define open(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout)
char ch;bool fs;void re(int& x)
{
	while(ch=getchar(),ch<33);
	if(ch=='-')fs=1,x=0;else fs=0,x=ch-48;
	while(ch=getchar(),ch>33)x=x*10+ch-48;
	if(fs)x=-x;
}
using namespace std;
const int mod=1000003;
int q;
int x,d,n;
int fac[N],ifac[N],inv[N];
int mi(int a,int b)
{
	int res=1;
	while(b)
	{
		if(b&1)res=1ll*res*a%mod;
		a=1ll*a*a%mod;
		b>>=1;
	}
	return res;
}
int main()
{
	inv[0]=inv[1]=ifac[0]=fac[0]=1;
	for(int i=1;i<N;++i)
	{
		if(i>1)inv[i]=1ll*(mod-mod/i)*inv[mod%i]%mod;
		fac[i]=1ll*fac[i-1]*i%mod;
		ifac[i]=1ll*ifac[i-1]*inv[i]%mod;
	}
	re(q);
	while(q--)
	{
		re(x),re(d),re(n);
		if(!d)
		{
			printf("%d\n",mi(x,n));
			continue;
		}
		int w=1ll*(mod-x)*mi(d,mod-2)%mod;
		if(n-1>=w || (!x && n>mod))
		{
			puts("0");
			continue;
		}
		x=1ll*x*mi(d,mod-2)%mod;
		if(x+n-1>=mod)
		{
			puts("0");
			continue;
		}
		int ans=1ll*mi(d,n)*(x?ifac[x-1]:1)%mod;
		ans=1ll*ans*fac[x+n-1]%mod;
		printf("%d\n",ans);
	}
}


Measured memory_bytes: 12544