akhauriyash/Code-Regression huggingface dataset:
n=int(input())
A=list(map(int, input().split()))

s=A[0]
S=sum(A)
ans=abs(sum(A) - 2*s)
for i in range(1,n-1):
	s += A[i]
	ans = min(ans, abs(S - 2*s))

if n > 3:
	print(ans)
else:
	print(abs(A[1]-A[0]))

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

using namespace std;

bool isprime(int v){
	for(int i = 2; i <= sqrt(v); i++){
		if(v % i == 0) return 0;
	}
	return 1;
}

int n;

int main(){
	scanf("%d", &n);
	
	vector <int> prime;
	
	for(int i = 6; i <= 55555; i += 5){
		if(isprime(i))
		prime.push_back(i);
	}
	
	for(int i = 0; i < n; i++){
		if(i == 0)
		printf("%d", prime[i]);
		else
		printf(" %d", prime[i]);
	}
	
	printf("\n");
}


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

count = 0
for a in range(len(A)-1):
    index_min = A[(a+1):].index(min(A[(a+1):]))+a+1
    # print(f'{min(A[a+1:])} {index_min}')
    if A[a] > A[index_min]:
        A[a],A[index_min] = A[index_min],A[a]
        count += 1
        # print(*A)
print(*A)
print(count)



Measured memory_bytes: 5608
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (int i = 0; i < sz(v); i++) {
        os << v[i];
        if (i < sz(v) - 1) os << " ";
    }
    return os;
}
int main() {
    string s;
    cin >> s;
    int ans = 0;
    for (char c : s) ans += (c == '+' ? 1 : -1);
    cout << ans << endl;
}

Measured memory_bytes: 3628
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		
		if (n == 1) {
			System.out.println(0);
			return;
		}
		
		long ans = n * (n - 1) / 2;
		System.out.println(ans);
	}
}


Measured memory_bytes: 21844
import sys
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

XY = np.array(read().split(), np.int64)[1:]

X, Y = XY[::2], XY[1::2]

A = X + Y
B = X - Y

a = A.max() - A.min()
b = B.max() - B.min()
print(max(a, b))

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

using namespace std;

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

typedef long long ll; typedef vector<int> VI; typedef pair<ll,int> pii;
const ll mod = 1e9+7;

int main()
{
	
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int a,b;
	cin >> a >>b;
	if(a+b>=10) puts("error");
	else printf("%d\n", a+b);
}



Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque, defaultdict
#deque(l), pop(), append(x), popleft(), appendleft(x)
#q.rotate(n)で → にn回ローテート
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate,combinations,permutations,product#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
from functools import reduce,lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率
from decimal import Decimal
from argparse import ArgumentParser

args=ArgumentParser()
args.add_argument('-loc', '--local', type=bool,default=False)
LOCAL=args.parse_args().local

def input(): 
    x=sys.stdin.readline(); 
    if x[-1]=="\n": 
        return x.rstrip() 
    return x
    
def printe(*x):_=print("## ",*x,file=sys.stderr) if LOCAL else 0
def printl(li): _=print(*li, sep="\n") if li else None
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def binr(x): return bin(x)[2:]
def bitcount(x): #xは64bit整数
    x= x - ((x >> 1) & 0x5555555555555555)
    x= (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x= (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f 
    x+= (x >> 8); x+= (x >> 16); x+= (x >> 32) 
    return x & 0x7f

def main():
    mod = 1000000007
    #w.sort(key=itemgetter(1),reverse=True)  #二個目の要素で降順並び替え

    #N = int(input())
    A,B,K = map(int, input().split())
    #A = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列

    if A>=K:
        print(A-K,B)
    elif B-(K-A)>=0:
        print(0,B-(K-A))
    else:
        print(0,0)


if __name__ == "__main__":
    main()

Measured memory_bytes: 77480
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int ans = 0;
    for (int i = 1; i <= n; i++){
      int a = sc.nextInt();
      if (a%2!=0 && i%2!=0) ans++;
    }
    System.out.println(ans);
  }
}


Measured memory_bytes: 35616
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define LLMAX (1ll << 60) - 1
#define INTMAX (1 << 30) - 1
#define MOD 1000000007 
#define NMAX 1000*100+1

#define numberOfSetBits(S) __builtin_popcount(S) // __builtin_popcountl(S) __builtin_popcountll(S)
#define MSET(x,y) memset(x,y,sizeof(x))
#define gcd(a,b) __gcd(a,b)
#define all(x)  x.begin(),x.end()
#define isOn(S, j) (S & (1 << j))
#define endl '\n'
#define setBit(S, j) (S |= (1 << j))
#define clearBit(S, j) (S &= ~(1 << j))
#define toggleBit(S, j) (S ^= (1 << j))
#define print(x)    for(auto it:x) cout<<it<<' '; cout<<endl;
#define printii(x)  for(auto it:x) cout<<it.F<<' '<<it.S<<'\t';  cout<<endl;
#define in(x,n)   for(int e=0;e<n;e++){ll y;cin>>y;x.pb(y);}

#define vi vector<ll>
#define vvi vector<vi>
#define ii pair<ll,ll>
#define pll pair<ll,ll>
#define vii vector<ii>
#define vvii vector<vii>
#define viii vector<pair<ii,ll>>
#define pb push_back
#define F first
#define S second
#define mp make_pair
#define mc(a,b,c) mp(mp(a,b),c)
struct DSU
{
    int n,x;
    vi p,r,sz;
    DSU(int N){
        n=N;x=N-1;sz.assign(N,1);p.assign(N,0);r.assign(N,1);
        for(int i=0;i<N;i++)p[i]=i;
    }
    int find(int i){return (p[i]==i)?i:(p[i]=find(p[i]));}
    bool sameset(int i,int j){return find(i)==find(j);}
    void join(int i,int j)
    {
        int p1=find(i);int p2=find(j);
        if(p1!=p2){
            x--;
            if(r[p1]>=r[p2]){
                p[p2]=p1;
                sz[p1]+=sz[p2];
                if(r[p1]==r[p2])
                    r[p1]++;
            }
            else{
                p[p1]=p2;
                sz[p2]+=sz[p1];
            }
        }
    }
    void debug(){for(int it:p)cout<<it<<' ';cout<<endl;}
    int getsize(int i){return sz[find(i)];}
    int noOfSets(){return x;}
};

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,x,t,m,y,z;
    cin>>n>>m;
    DSU foo(n);
    vvi lang(m);
    for(int i=0;i<n;i++){
        cin>>x;
        for(int j=0;j<x;j++){
            cin>>y;
            y--;
            lang[y].pb(i);
        }
    }
    for(int i=0;i<m;i++){
        for(int j=1;j<lang[i].size();j++){
            foo.join(lang[i][j], lang[i][j-1]);
        }
    }
    cout<<(foo.noOfSets()?"NO":"YES");
    


    return 0;
}

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

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

using namespace std;

using ll = long long;

ll solve() {

    int N;
    cin >> N;
    vector<int> A(N + 1);
    REP(i, N + 1) cin >> A[i];

    if (N == 0) {
        return A[0] == 1 ? 1 : -1;
    }

    if (A[0] > 0) {
        return -1;
    }

    ll n_leaves = accumulate(all(A), 0ll);
    if (n_leaves == 0) {
        return -1;
    }

    ll result = 1;

    ll k = 1; // number of vertices that are not leaves and in depth d.

    FOR(d, 1, N + 1) {
        ll n_children = min(n_leaves, 2 * k);
        if (n_children < A[d]) {
            return -1;
        }
        result += n_children;
        n_leaves -= A[d];
        k = n_children - A[d];
    }

    return result;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << solve() << endl;
    return 0;
}


Measured memory_bytes: 3760
#include <bits/stdc++.h>
using namespace std;
//T+N
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")
#define endl "\n"
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template<class T, class T2> inline bool chkmax(T &x, const T2 &y) { return x < y ? x = y, 1 : 0; }
template<class T, class T2> inline bool chkmin(T &x, const T2 &y) { return x > y ? x = y, 1 : 0; }
const ll mod = 1e9 + 7;
template<class T> inline void fix(T &x) {if(x >= mod | x <= -mod) {x %= mod;} if(x < 0) {x += mod;}}
#define out(x) cout << __LINE__ << ": " << (#x) << " = " << (x) << endl

signed main() {
    //ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    ld a, b, c, d;
    cin >> a >> b >> c >> d;
    const ld PI = 3.1415926535897;
    ld full = 12 * 60;
    ld real = c * 60 + d;
    ld frac1 = real / full * 2.f * PI;
    ld frac2 = d / 60.f * 2.f * PI;
    ld x1 = sin(frac1) * a;
    ld y1 = cos(frac1) * a;
    ld x2 = sin(frac2) * b;
    ld y2 = cos(frac2) * b;
    ld ans = sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
    cout << fixed << setprecision(12) << ans << endl;
    return 0;
}




Measured memory_bytes: 4168
N,A,B,C,D=map(int,input().split())

for i in range(1,N):
    if A*i<N:
        continue
    else:
        E=i
        break

for j in range(1,N):
    if C*j<N:
        continue
    else:
        F=j
        break

if E*B<F*D:
    print(E*B)
else:
    print(F*D)


Measured memory_bytes: 5596
#include<bits/stdc++.h>
#define F first
#define S second
#define MP make_pair
#define pb push_back
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;
typedef pair< int, P > iP;
typedef pair< P, P > PP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 100005;

int dx[] = {0, -1, 1, 0};
int dy[] = {-1, 0, 0, 1};

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

    int n, a, b;
    cin >> n >> a >> b;
    if( a * n > b ) cout << b;
    else cout << a * n;
    cout << endl;
    return 0;
}



Measured memory_bytes: 256
#include <string.h>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
// #include <unordered_map>
// #include <unordered_set>
#include <utility>
#include <vector>

#define pb push_back
#define mp make_pair

#ifdef ONLINE_JUDGE
#define link renamelink
#define next renamenext
#define prev renameprev
#endif

using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
typedef long double ld;

inline void EnableFileIO(const string& fileName, bool local = 0) {
  if (fileName.empty()) return;
  if (local) {
    freopen((fileName + ".in").c_str(), "r", stdin);
    freopen((fileName + ".out").c_str(), "w", stdout);
    return;
  }
#ifdef ONLINE_JUDGE
  freopen((fileName + ".in").c_str(), "r", stdin);
  freopen((fileName + ".out").c_str(), "w", stdout);
#endif
}

const int INF = (1 << 30) - 1;
const LL LINF = (1LL << 61) - 1;
const double EPS = 1e-10, PI = acos(-1);

int n;
LL a, b, c, d;

int main() {
  // srand((int)time(0));
  // printf("Hello, world!\n");
  // EnableFileIO("");

  cin >> n >> a >> b >> c >> d;
  LL k = b - a;
  n -= 1;
  k = abs(k);
  if (c * n <= k && k <= n * d) {
    puts("YES");
    return 0;
  }
  for (int nega = 0; nega <= n; nega++) {
    LL lb = (n - nega) * c, rb = (n - nega) * d;
    LL lb2 = nega * c, rb2 = nega * d;
    if (lb - rb2 <= k && k <= rb - lb2) {
      // cerr << lb << ' ' << rb << ' ' << nega << endl;
      puts("YES");
      return 0;
    }
  }

  puts("NO");
  return 0;
}

Measured memory_bytes: 256
s = input()
space = len(s) - 1

for i in range(2 ** space):
    f = s[0]
    for j in range(space):
        f += "+" if (i >> j) & 1 else "-"
        f += s[j + 1]

    if eval(f) == 7:
        print(f + "=7")
        exit()

Measured memory_bytes: 3060
#include <algorithm>
#include <bitset>
#include <iomanip>
#include <ios>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>

using namespace std;

int main()
{
    int N;
    cin >> N;
    if (N % 10 == 9 || N / 10 == 9) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 99999999

using namespace std;


int dy[4] = { 0,0,1,-1 };
int dx[4] = { 1,-1,0,0 };
int dxx[8] = { 0,0,1,1,1,-1,-1,-1 };
int dyy[8] = { 1,-1,0,1,-1,0,1,-1 };




ll m = 1000000007;

ll gcd(ll x, ll y) {
	ll m = max(x, y), n = min(x, y);
	if (m%n == 0)return n;
	else return gcd(m%n, n);
}

ll myPow(ll x, ll n, ll m) {
	if (n == 0)
		return 1;
	if (n % 2 == 0)
		return myPow(x * x % m, n / 2, m);
	else
		return x * myPow(x, n - 1, m) % m;
}




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

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

using namespace std;
#define ll long long int

int main(){
    ll n , w;
    cin >> n >> w;
    ll weight[n] , value[n];
    for(int i =0 ; i < n ; i ++)
    {
        cin >> weight[i] >> value[i];
    }
    ll dp[n + 1][w + 1];
    memset(dp , 0 , sizeof(dp));
    for(int i = 1; i <=n ; i ++)
    {
        for(int j = 1; j <=w ; j ++)
        {
            if(j >= weight[i - 1])
            dp[i][j] = max(dp[i - 1][j] , value[ i- 1 ] + dp[i - 1][j - weight[ i - 1]]);
            else
            dp[i][j] = max(dp[i][j] , dp[i - 1][j]);
            
        }
    }
    cout << dp[n][w] << endl;

}

Measured memory_bytes: 79104
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		long k = scanner.nextLong();
		List<P> list = new ArrayList<>();

		for(int i = 0; i < n; i++){
			list.add(new P(scanner.nextInt(), scanner.nextInt()));
		}

		list.sort((a,b) -> a.n - b.n);
		long count = 0;
		for(int i = 0; i < n; i++){
			count += list.get(i).k;
			if(count > k - 1){
				System.out.println(list.get(i).n);
				break;
			}
		}
	}
}

class P{
	int n;
	int k;
	public P(int n, int k) {
		this.n = n;
		this.k = k;
	}
}

Measured memory_bytes: 65912
#include<bits/stdc++.h>
using namespace std;
int a[100005][4];
int dp[100005][4];
int n;
 
int func(int ind, int flag) {
 
	if (ind == n) return 0;
 
	if (dp[ind][flag] != -1) return dp[ind][flag];
 
	int maxi = 0;
	if (flag == 0) {
		maxi = max(maxi, a[ind][1] + func(ind + 1, 1));
		maxi = max(maxi, a[ind][2] + func(ind + 1, 2));
		maxi = max(maxi, a[ind][3] + func(ind + 1, 3));
	}
	else if (flag == 1) {
		maxi = max(maxi, a[ind][2] + func(ind + 1, 2));
		maxi = max(maxi, a[ind][3] + func(ind + 1, 3));
	}
	else if (flag == 2) {
		maxi = max(maxi, a[ind][1] + func(ind + 1, 1));
		maxi = max(maxi, a[ind][3] + func(ind + 1, 3));
	}
	else {
		maxi = max(maxi, a[ind][1] + func(ind + 1, 1));
		maxi = max(maxi, a[ind][2] + func(ind + 1, 2));
	}
 
	return dp[ind][flag] = maxi;
}
 
int main() {
 
	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 1; j <= 3; j++) {
			cin >> a[i][j];
		}
	}
 
	memset(dp, -1, sizeof dp);
 
	cout << func(0, 0);
 
	return 0;
}

Measured memory_bytes: 14552
#include <cstdio>
#include <cmath>

using namespace std;

int main() {
    double x1, y1, x2, y2;
    scanf("%lf %lf %lf %lf", &x1, &y1, &x2, &y2);

    double dx=x2-x1, dy=y2-y1;

    printf("%.12g\n", sqrt(dx*dx+dy*dy));
    return 0;
}

Measured memory_bytes: 2716
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPl(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define REPRl(i, n) for(ll i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < (int)n; i++)
#define FORl(i, m, n) for(ll i = m; i < (ll)n; i++)
#define ALL(v) v.begin(), v.end()
ll gcd(ll a,ll b) {
  return b? gcd(b,a%b): a;  
}
ll lcm(ll a,ll b) {
  return a*b/gcd(a,b);
}
int main() {
  int a,b;cin>>a>>b;
  int ans;
  if(a<10&&b<10){
  	ans=a*b;
  }else{
    ans=-1;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int n = sc.nextInt();
        int[] p = new int[n];
        Set<Integer> set = new HashSet<>();
        for (int i = 0; i < n; i++) {
            p[i] = sc.nextInt();
            set.add(p[i]);
        }
        if (n == 0) {
            System.out.println(x);
            return;
        }
        for (int i = 0; i <= 100; i++) {
            if (!set.contains(x - i)) {
                System.out.println(x - i);
                return;
            }
            if (!set.contains(x + i)) {
                System.out.println(x + i);
                return;
            }
        }
    }

}


Measured memory_bytes: 35804
#include <stdio.h>

int main(){
    int n;scanf("%d",&n);
    int a[n];
    int ans;
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
        while(a[i]%2==0){a[i]/=2;ans++;}
    }
    printf("%d",ans);
    return 0;
}   

Measured memory_bytes: 256
def gcd(a,b):
    if b == 0:
        return a
    return gcd(b, a % b)


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

def m():
    N = int(input())
    T = [int(input()) for _ in range(N)]
    ans = T[0]
    for i in range(1,N):
        ans = lcm(ans,T[i])
    return ans

print(m())

Measured memory_bytes: 3060
#include <stdio.h>
#include <ctype.h>
#include <string.h>

#define LENGTH 1200

int main()
{
  int i;
  char ch;

  for( ; ; )
  {
    scanf("%c", &ch);
    if( isupper(ch) )
    {
      ch += 32;
    }
    else if( islower(ch) )
    {
      ch -= 32;
    }
    printf("%c", ch);
    if( ch == '\n' )
      break;
  }
}



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

int main(){
  int x,y,z;
  cin >>x>>y>>z;
  swap(x,y);
  swap(x,z);
  cout << x<<" "<<y<<" "<<z;
}

Measured memory_bytes: 764
#include <cstdio>
#include <iostream>
#include <vector>
#include <sstream>
#include <string>
#include <iterator>
#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n;
    string line;
    vector<int> v;
    v.push_back(0);
    cin >> n >> ws;
    getline(cin, line);
    stringstream ss(line);
    int ti;
    while(ss >> ti)
        v.push_back(ti);
    
    int c = 0;
    for (int i = 1; i <= n; i++){
        if (v[i] == i)
            continue;
        if (v[v[i]] == i) {
            iter_swap(v.begin() + i, v.begin() + v[i]);
            c++;
        } else {
            cout << "NO" << endl;
            return 0;
        }
    }
    if (c < 2)
        cout << "YES" << endl;
    else
    {
         cout << "NO" << endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string>
#include <cmath>
using namespace std;
#define MOD 998244353
#define INF 1<<30
#define LINF (ll)1<<62
#define MAX 510000
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
#define uni(q) unique(all(q)),q.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;
const int mod = 1e9 + 7;

int main(){
    string s; cin >> s;
    map<char,ll> mp;
    rep(i,s.size()) mp[s[i]]++;
    if(mp.size()==s.size()) puts("yes");
    else puts("no");
}


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

int num[9];

bool eval(int depth, bool two) {
	if (depth == 0) return true;

	int n = 0;
	while (num[n] == 0) n++;

	if (num[n] >= 2 && !two) {
		num[n] -= 2;
		bool p = eval(depth-1, true);
		num[n] += 2;
		if (p) return true;
	}

	if (num[n] >= 3) {
		num[n] -= 3;
		bool p = eval(depth-1, two);
		num[n] += 3;
		if (p) return true;
	}

	if (n > 7) return false;
	if (num[n+1] < num[n] || num[n+2] < num[n]) return false;
	int k = num[n];
	num[n] -= k, num[n+1] -= k, num[n+2] -= k;
	bool p = eval(depth-k, two);
	num[n] += k, num[n+1] += k, num[n+2] += k;
	return p;
}

int main() {
	char s[13+1];
	while (cin >> s) {
		for (int i = 0; i < 9; i++) num[i] = 0;
		for (int i = 0; i < 13; i++) num[s[i]-'1']++;

		bool first = true;
		for (int i = 0; i < 9; i++) {
			if (num[i] == 4) continue;
			num[i]++;
			if (eval(5, false)) {
				if (first) cout << (i+1), first = false;
				else cout << " " << (i+1);
			}
			num[i]--;
		}

		if (first) cout << 0;
		cout << endl;
	}
	return 0;
}

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  string s, t, u;
  int a, b;
  cin >> s >> t >> a >> b >> u;
  if (u == s) --a;
  else --b;
  cout << a << ' ' << b << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define r(i,a,n) for(int i=a;i<=n;i++)
using namespace std;
int main(){
	int a,b,c,p;
	while(cin>>a>>b>>c,a){
		vector<int>s;c--;
		r(i,1,a)s.push_back(i);
		while(s.size()!=1){
			s.erase(s.begin()+c);
			c=(c+b-1)%(s.size());
			//cout<<c;
		}
		cout<<s[0]<<endl;
	}
}

Measured memory_bytes: 3260
N=int(input())
A=[int(x) for x in input().split()]
P,Q,R,S=A[0],0,A[1]+A[2],sum(A[3:])
l,r=1,3
ans=float("inf")
for i in range(2,N-1):
  Q+=A[i-1]
  while l<i-1:
    if abs(P-Q)>abs(P+A[l]-(Q-A[l])):
      P+=A[l]
      Q-=A[l]
      l+=1
    else:
      break
  R-=A[i-1]
  if i==r:
    R+=A[r]
    S-=A[r]
    r+=1
  while r<N-1:
    if abs(R-S)>abs(R+A[r]-(S-A[r])):
      R+=A[r]
      S-=A[r]
      r+=1
    else:
      break
  ans=min(ans,(max(P,Q,R,S)-min(P,Q,R,S)))
print(ans)

Measured memory_bytes: 24180
import java.util.*;
import java.io.*;
class Main {
	public static void main(String[] args){
    
    		Scanner sc = new Scanner(System.in);
      		int n = sc.nextInt();
      		float sum = 0;
      		for(int i=0;i<n;i++){
            
            	float x = sc.nextFloat();
            	
            	sum += (1/x);
            }
    		System.out.println(1/sum);
    
    }



}

Measured memory_bytes: 23252
#include <bits/stdc++.h>
using namespace std;
#define tag "spoj"
#define maxn 100007
#define oo 1000000007LL
#define mid ((l+r)>>1)
#define getbit(x,i) ((x)>>(i)&1)
#define onbit(x,i) ((x)|(1<<(i)))
#define offbit(x,i) ((x)&~(1<<(i)))
#define cntbit(x) (__builtin_popcount(x))
#define meset(a,x) memset(a,x,sizeof(a))
#define forinc(i,a,b) for(int i=a;i<=b;i++)
#define fordec(i,a,b) for(int i=a;i>=b;i--)
#define debug(x) cerr<<#x<<" = "<<x<<"\n"
#define runtime(stime) ((clock() - stime) / CLOCKS_PER_SEC * 1000)
#define checkfile(FiLeNaMe) { if(fopen(FiLeNaMe".inp","r")) freopen(FiLeNaMe".inp","r",stdin),freopen(FiLeNaMe".out","w",stdout); }
///my data:
#define long long long
#define mxlg 17
///>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
int n,m;
int a[maxn],b[maxn];
void enter(){
    cin>>n>>m;
    forinc(i,1,n) cin>>b[i]>>a[i];
}

void solve(){
    set<int,greater<int>> setpos;

    vector<int> id;forinc(i,1,n) setpos.insert(i),id.push_back(i);
    sort(id.begin(),id.end(),[](int i,int j){  return (a[i]>a[j]) || (a[i]==a[j] && b[i]<b[j]); });

    int ans=0;

    for(int i: id){
        int x=a[i],y=b[i];
        auto pos=setpos.lower_bound(m-y+1);

        if(pos==setpos.end()) continue;

        ans+=x;
        setpos.erase(pos);
    }

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

int main()
{
    checkfile(tag);
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    enter();
    solve();

    return 0;
}


Measured memory_bytes: 6136
using System;
 
public class Test
{
	public static void Main()
	{
		// your code goes here
		int count = 0, n = int.Parse(Console.ReadLine());
		int[,] red = new int[n,2];
		int[,] blue = new int[n,2];
		bool[] check = new bool[n];
		red = Read(n);
		blue = Read(n);
		red = Sort(n, red);
		blue = Sort(n, blue);
		
		for(int i=0;i<n;i++)
		{
			int a=0, b=0, j;
			bool c = false;
			for(j=0;j<n;j++)
			{
				if(check[j]==false&&red[j,0]>blue[i,0])
				{
					break;
				}
			}
			//Console.WriteLine(blue[i,1]);
			for(j=j-1;j>=0;j--)
			{
				if(check[j]==false&&red[j,1]<blue[i,1]&&a<=red[j,1])
				{
					//Console.WriteLine(red[j,1]);
					a = red[j,1];
					b = j;
					c = true;
				}
			}
			if(c)
			{
				count++;
				check[b]=true;
			}
			//Console.WriteLine();
		}
		Console.WriteLine(count);
	}
	public static int[,] Read(int n)
	{
		int[,] point = new int[n,2];
		for(int i=0;i<n;i++)
		{
			string[] line = Console.ReadLine().Split(' ');
			point[i,0] = int.Parse(line[0]);
			point[i,1] = int.Parse(line[1]);
		}
		return point;
	}
	public static int[,] Sort(int n, int[,] point)
	{
		for(int i=0;i<n;i++)
		{
			for(int j=i+1;j<n;j++)
			{
				if(point[i,0]>point[j,0])
				{
					int a = point[i,0], b = point[i,1];
					point[i,0] = point[j,0];
					point[i,1] = point[j,1];
					point[j,0] = a;
					point[j,1] = b;
				}
			}
		}
		return point;
	}
}

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

namespace _1_6_a
{
    class Program
    {
        static void Main(string[] args)
        {
            int s = int.Parse(Console.ReadLine());//何枚のカードがあるか

            string[] str = {"S 1","S 2","S 3","S 4","S 5","S 6","S 7","S 8","S 9","S 10","S 11","S 12","S 13"
            ,"H 1","H 2","H 3","H 4","H 5","H 6","H 7","H 8","H 9","H 10","H 11","H 12","H 13"
            ,"C 1","C 2","C 3","C 4","C 5","C 6","C 7","C 8","C 9","C 10","C 11","C 12","C 13"
            ,"D 1","D 2","D 3","D 4","D 5","D 6","D 7","D 8","D 9","D 10","D 11","D 12","D 13" };

            var list = new List<string>();
            list.AddRange(str);             //52枚のカードList

            //カードの枚数分ループ
            for (int i = 0; i < s; i++)
            {
                string t = "";
                t = Console.ReadLine();

                list.Remove(t);

            }
            foreach (string r in list)
            {
                Console.WriteLine(r);
            }
            Console.ReadKey();

        }
    }
}



Measured memory_bytes: 17752
s = list(input())
n = len(s)

s_r = list(reversed(s))
#print(s,n,s_r)

a = int((n-1)/2)
b = int((n+3)/2)-1


if s == s_r:
    x = s[:a]
    y = s[b:]
#    print(x,y,reversed(x))
    if x == list(reversed(x)) and y == list(reversed(y)):
        print('Yes')
        exit()
print('No')


Measured memory_bytes: 3060
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

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

        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();

        int money = 0;

        money = Math.min(a,b) + Math.min(c,d);

        System.out.println(money);
    }
}




Measured memory_bytes: 23124
// AOJ 2437 DNA
// 2018.4.7 bal4u

#include <stdio.h>
#include <string.h>

// 文字列のハッシュ関数
#define HASHSIZ 503
typedef struct { char *s; int id; } HASH;
HASH hash[HASHSIZ+2], *hashend = hash + HASHSIZ;

int insert(char *s, int id)
{
	unsigned long long i;
	char *p;
	HASH *tp;

	i = 0, p = s; while (*p) i = (i<<5) + *p++;
	tp = hash + (int)(i % HASHSIZ);
	while (tp->s != NULL) {
		if (!strcmp(tp->s, s)) return tp->id;
		if (++tp == hashend) tp = hash;
	}
	tp->s = s, tp->id = id;
	return -1;
}

char buf[300], *p;
int in()
{
	int n = 0;
	while (*p >= '0') n = 10*n + (*p++ & 0xf);
	p++;
	return n;
}

#define M 1000000007

int  na, nt, ng, nc, sum;
int  sz;
int  rule[52][12];
int  dp[202][52][52][52];
char text[52][300];
char tr['Z'];
int  token[250];

int together(int id)
{
	int i, j;

	for (i = 0; j = rule[id][i]; i++) {
		if (j > 0) { if (together(j)) return 1;	}
		else {
			token[sz] = -j;
			if (++sz > sum) return 1;
		}
	}
	return 0;
}

int main()
{
	int m, i, j, k, l, b, a, t, g, c;
	char *q;

	tr['A'] = 1, tr['T'] = 2, tr['G'] = 4, tr['C'] = 8;
	fgets(p=buf, 20, stdin);
	na = in(), nt = in(), ng = in(), nc = in();
	sum = na+nt+ng+nc;
	fgets(p=buf, 10, stdin), m = in();
	sz = 0;
	for (i = 0; i < m; i++) {
		fgets(p=text[i], 300, stdin);
		q = p; while (*p != ':') p++; *p = 0, p+=2;
		j = insert(q, sz);
		if (j < 0) j = sz++;
		k = 0;
		while (*p >= ' ') {
			q = p; while (*p > ' ') p++; *p++ = 0;
			if (*q != '[') {
				l = insert(q, sz);
				if (l < 0) l = sz++;
				rule[j][k++] = l;
			} else {
				b = 0;
				while (*++q != ']') b |= tr[*q];
				rule[j][k++] = -b;
			}
		}
	}
#if 0
	printf("m %d, sz %d\n", m, sz);
	for (i = 0; i < sz; i++) {
		printf("[%d] --> ", i);
		for (j = 0; rule[i][j]; j++) printf("%d ", rule[i][j]);
		printf("\n");
	}
#endif
	sz = 0;
	if (together(0) || sz != sum) { puts("0"); return 0; }
#if 0
	printf("sz %d\n", sz);
	for (i = 0; i < sz; i++) printf("[%d] %d\n", i, token[i]);
#endif

	dp[0][0][0][0] = 1;
	for (i = 0; i < sz; i++) {
		b = token[i];
		for (a = 0; a <= na; a++) for (t = 0; t <= nt; t++) for (g = 0; g <= ng; g++) {
			c = i - (a+t+g);
			if (c < 0 || c > nc) continue;
			if (b & 1) {
				dp[i+1][a+1][t][g] += dp[i][a][t][g];
				if (dp[i+1][a+1][t][g] >= M) dp[i+1][a+1][t][g] -= M;
			}
			if (b & 2) {
				dp[i+1][a][t+1][g] += dp[i][a][t][g];
				if (dp[i+1][a][t+1][g] >= M) dp[i+1][a][t+1][g] -= M;
			}
			if (b & 4) {
				dp[i+1][a][t][g+1] += dp[i][a][t][g];
				if (dp[i+1][a][t][g+1] >= M) dp[i+1][a][t][g+1] -= M;
			}
			if (b & 8) {
				dp[i+1][a][t][g] += dp[i][a][t][g];
				if (dp[i+1][a][t][g] >= M) dp[i+1][a][t][g] -= M;
			}
		}
	}
	printf("%d\n", dp[sz][na][nt][ng]);
	return 0;
}


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

int main()
{
  int n;
  scanf("%d", &n);
  vector<int> a(n+1), b(n);
  for(int i = 0; i <= n; ++i)
    scanf("%d", &a[i]);
  long long s = 0;
  for(int i = 0; i < n; ++i){
    scanf("%d", &b[i]);
    if (b[i] >= a[i] + a[i+1]){
      s += a[i]+a[i+1];
      a[i+1] = 0;
    }
    else if (b[i] >= a[i]){
      s += b[i];
      a[i+1] -= b[i] - a[i];
    }
    else s += b[i];
  }
  printf("%lld", s);
  return 0;
}

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

int main(){
	int h,w; cin>>h>>w;
	vector<vector<string>> vv(h,vector<string>(w));
	
	vector<int> vh;
	rep(i,h){
		string s; cin>>s;
		bool flg=false;
		rep(j,w){
			if(s[j]=='.') flg=true;
			else {flg=false; break;}
		}
		rep(j,w) vv[i][j]=s[j];
		if(flg) continue;
		else vh.push_back(i);
	}

	vector<int> vw;
	rep(i,w){
		bool flg=false;
		rep(j,h){
			if(vv[j][i]==".") flg=true;
			else {flg=false; break;}
		}
		if(!flg) vw.push_back(i);
	}

	h=vh.size();
	w=vw.size();
	rep(i,h){
		rep(j,w) cout<<vv[vh[i]][vw[j]];
		cout<<endl;
	}
}

Measured memory_bytes: 3940
//----------BHAVIK DIWANI(PICT_COMP)---------------
#include<bits/stdc++.h>
#include<stdlib.h>
#include<stdio.h>
#define test ll t; cin>>t; while(t--)
#define FOR(p,n) for(ll i=p;i<(ll)n;i++)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define mod 1000000007
#define ll long long
#define int long long
#define ull unsigned long long
#define MAX 1000005
#define pb push_back
#define mkp make_pair
#define vi vector<int>
#define pii pair<int,int>
#define endl '\n'
#define vs vector<string>
#define mii map<int,int>
#define msi map<string,int>
#define vpii vector< pair<int, int > >
#define vpsi vector< pair< string ,int > >
#define forci(p,q) for(int i=p;i<q;i++)
ll gcd(ll a,ll b){ if(b==0) return a;    return gcd(b,a%b);}
ll lcm(ll a,ll b) { return (a/gcd(a,b)*b);}
ull power(ull a, ull b) {a %= mod;  ull res = 1;  while (b > 0) { if (b & 1) res = res * a % mod;  a = a * a % mod;  b >>= 1; }  return res%mod; }
ll modmul(ll x, ll y){return (x*y)%mod;}
ll modadd(ll x, ll y){return (x+y)%mod;}
ll modsub(ll x, ll y){return (x-y+mod)%mod;}
ll fact[1000007]={0};
void facto() {fact[0]=1;fact[1]=1;for(int i=2;i<100007;i++)fact[i]=(fact[i-1]*i)%mod;}
ll ncr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(power(fact[r],mod-2)))%mod; res=(res*(power(fact[n-r],mod-2)))%mod; return res;}
ll npr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(power(fact[n-r],mod-2)))%mod; return res;}
inline long long toint(const std::string &s) {std::stringstream ss; ss << s; long long x; ss >> x; return x;}
inline std::string tostring(long long number) {std::stringstream ss; ss << number; return ss.str();}
inline std::string tobin(long long x) {return std::bitset<63>(x).to_string();}
/*bool prime[MAX];
ull sieve(){memset(prime,true,sizeof(prime));for(ull p=2;p*p<MAX;p++){if(prime[p]==true){for(ull i=2*p;i<MAX;i+=p){prime[i]=false;}}}prime[0]=0;prime[1]=0;
}*/
using namespace std;
signed main()
{
	fastio;
	int n,m;
	cin>>n>>m;
	int dp[n+1][m+1];
	for(int i=0;i<=n;i++)
		dp[i][0]=0;
	for(int i=0;i<=m;i++)
		dp[0][i]=0;
	char s[n+1][m+1];
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
			cin>>s[i][j];
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			if(i==1 && j==1)
			{
				dp[i][j]=1;
				continue;
			}
			if(s[i][j]=='#')
				dp[i][j]=0;
			else 
				dp[i][j]=(dp[i-1][j]+dp[i][j-1])%mod;
		}
	}
	cout<<dp[n][m]<<endl;
		
}












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

int main()
{
  int a, b, k;
  cin >> a >> b >> k;

  for(int i = a; i <= b; i++)
  {
    if(i < (a+k) || i > (b-k))
    {
      cout << i << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 256
x, y = map(int, input().split())

ans = 0

for i in range(x):
#  print (i, x-i, i * 2 + (x-i) * 4, i * 4 + (x-1) *2)
  if i * 2 + (x-i) * 4 == y:
    ans = 1
    break
  elif i * 4 + (x-i) *2 == y:
    ans = 1
    break

if ans == 0:
  print("No")
else:
  print("Yes")

Measured memory_bytes: 9176
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

int main()
{
	int N, L;
	cin >> N >> L;
	int num = mod;
	int ans = 0;
	for (int i = L; i < L + N; i++) {
		ans += i;
		num = min(num, abs(i));
	}
	if (L + N <= 0) ans += num;
	else ans -= num;
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <list>
#define ll long long
using namespace std;
int main()
{
  ios_base::sync_with_stdio(0);
  string str;
  cin >> str;
  for(int i=0;i<str.length();i+=2)
  {
    cout << str[i];
  }
  cout << endl;
  return 0;
}


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

using namespace std;

typedef long long ll;
typedef pair<ll,ll> pll;

void solve() {
	string s;
	int k;
	cin >> k;
	cin >> s;
	cout << s.substr(0,k) << (s.length() > k ? "..." : "") << endl;
}

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

Measured memory_bytes: 3612
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c[] = { 1, 10, 100, 1000, 10000 };
		int total = 0;
		int k;
		for (int i = 1; i <= n; i++) {
			int sum = 0;
			k = i;
			for (int j = 0; j < 5; j++) {
				sum += k % 10;
				k = k / 10;
			}
			if (sum >= a && sum <= b) {
				total += i;
			}
		}
		System.out.println(total);
	}
}


Measured memory_bytes: 21840
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pi = pair<int, int>;


const ll mod = 998244353;
int n;
ll a[200002];
ll dp[1000003];
ll w[1000003];
ll inv[1000003];
ll d_sqsum[1000003];
ll d_sum[1000003];
ll cnt[1000003];
ll mexp(ll x, ll y)
{
    if(!y) return 1;
    if(y & 1) return x * mexp(x*x%mod, y >> 1) % mod;
    return mexp(x*x%mod, y >> 1);
}
ll minv(int x)
{
    if(!inv[x]) return inv[x] = mexp(x, mod-2);
    return inv[x];
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n;
    for(int i=0;i<n;i++)
    {
        cin >> a[i];
        cnt[a[i]]++;
    }
    ll ma = *max_element(a, a+n);
    for(int i=1;i<=ma;i++)
    {
        for(int j=i;j<=ma;j+=i)
        {
            d_sqsum[i] = (d_sqsum[i] + cnt[j] * j * j) % mod;
            d_sum[i] = (d_sum[i] + cnt[j] * j) % mod;
        }
    }

    ll ans = 0;
    for(int i=1;i<=ma;i++)
    {
        w[i] = (w[i] + minv(i)) % mod;
        for(int j=2*i;j<=ma;j+=i)
        {
            w[j] = (w[j] - w[i] + mod) % mod;
        }
        ll tmp = ((d_sum[i] * d_sum[i]) % mod - d_sqsum[i] + mod) % mod;
        ans = (ans + w[i] * tmp) % mod;
    }
    cout << (ans * minv(2) % mod) << "\n";
}

Measured memory_bytes: 44672
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
 
typedef long long ll;
ll mod=1e9+7;
 
const int MX=100000;
ll f[MX+1],g[MX+1],inv[MX+1];
void precalc(){
	f[0]=1;
	rep1(i,MX) f[i]=f[i-1]*i%mod;
	inv[1]=1;
	for(int i=2;i<=MX;i++) inv[i]=mod-mod/i*inv[mod%i]%mod;
	g[0]=1;
	rep1(i,MX) g[i]=g[i-1]*inv[i]%mod;
}
ll C(int x,int y){
	return f[x]*g[y]%mod*g[x-y]%mod;
}
ll ex(ll x,int p){
	ll a=1;
	while(p){
		if(p&1) a=a*x%mod;
		x=x*x%mod;
		p/=2;
	}
	return a;
}
int gcd(int x,int y){
	if(y==0) return x;
	return gcd(y,x%y);
}
 
 
typedef pair<int,int> P;
const int MV=20000;
vector<int> G[MV];
int ord[MV],low[MV];
int I;
 
stack<P> st;
typedef vector<P> VP;
vector<VP> biedges;
 
vector<P> vp;
void dfs(int v,int p){
	ord[v]=++I;
	low[v]=ord[v];
	for(int u:G[v]) if(u!=p){
		if(ord[u]<ord[v]) st.push(P(v,u));
		if(ord[u]) chmin(low[v],ord[u]);	//back edge
		else{
			dfs(u,v);
			chmin(low[v],low[u]);
 
			if(low[u]>=ord[v]){
				vp.clear();
				while(true){
					P p=st.top();st.pop();
					vp.pb(p);
					if(p.fs==v && p.sc==u) break;
				}
				biedges.pb(vp);
			}
		}
	}
}
void arti(int N){
	rep(i,N) if(ord[i]==0){
		while(!st.empty()) st.pop();
		dfs(i,-1);
	}
}
 
 
int N,M,K;
 
int main(){
	precalc();
	cin>>N>>M>>K;
	assert(N<=20000);
	assert(M<=40000);
	assert(K<=40000);
	rep(i,M){
		int a,b;
		cin>>a>>b;
		a--,b--;
		G[a].pb(b);
		G[b].pb(a);
	}
	arti(N);
	ll ans=1;
	for(VP& vp : biedges){
		set<int> st;
		for(P p : vp){
			st.insert(p.fs);
			st.insert(p.sc);
		}
		int n=st.size(),m=vp.size();
		if(n==2){
			assert(m==1);
			ans=ans*K%mod;
		}else if(n==m){	//cycle
			ll sum=0;
			rep(i,m){
				int g=gcd(m,i);
				sum=(sum+ex(K,g))%mod;
			}
			sum=sum*inv[m]%mod;
			ans=ans*sum%mod;
		}else{		//free
			assert(n<m);
			ans=ans*C(m+K-1,m)%mod;
		}
	}
	cout<<ans<<endl;
}

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

num = list(input())

op = ['+','-']

for op1 in op:
    if op1 == '+':
        res1 = int(num[0]) + int(num[1])
    else:
        res1 = int(num[0]) - int(num[1])
    for op2 in op:
        if op2 == '+':
            res2 = res1 + int(num[2])
        else:
            res2 = res1 - int(num[2])
        for op3 in op:
            if op3 == '+':
                res3 = res2 + int(num[3])
            else:
                res3 = res2 - int(num[3])

            if res3 == 7:
                ans = num[0]+op1+num[1]+op2+num[2]+op3+num[3]+"=7"
                print(ans)
                exit() 


Measured memory_bytes: 9156
#include<iostream>
#include<algorithm>
using namespace std;
bool cmp(string a,string b)
{
    return a+b<b+a;
}
string a[110];
int main()
{
    int n,l;
    cin>>n>>l;
    for(int i=0;i<n;i++) cin>>a[i];
    sort(a,a+n,cmp);
    string str;
    for(int i=0;i<n;i++) str+=a[i];
    cout<<str<<endl;
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ITR(x,c) for(__typeof(c.begin() x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin() x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

#define lf double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll a, b; cin >> a >> b;
	if (b%a ==0){
		cout << a+b << "\n";
	}else{
		cout << b-a << "\n";
	}
	return 0;
}

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

typedef long long int  lli;
typedef unsigned long long int ulli;
typedef long double ldb;

#define pb push_back
#define popb pop_back
#define si size()
#define be begin()
#define en end()
#define le length()
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second

#define forz(i,n) for( int i=0;i<n;i++)
#define forl(i, n) for(int i = 1; i<= n; i++)
#define deci(n)  fixed<<setprecision(n)
#define high(n) __builtin_popcount(n)
#define parity(n) __builtin_parity(n)
#define ctz(n)  __builtin_ctz(n)
#define mod 1000000007
#define mod2 998244353
#define kira ios::sync_with_stdio(0), cin.tie(0),cout.tie(0)

using namespace std;


int main() {
// #ifndef ONLINE_JUDGE
// 	freopen("input.txt", "r", stdin);
// 	freopen("output.txt", "w" , stdout);
// #endif
	lli n, k;
	cin >> n >> k;
	if (n < k)
	{
		cout << min(n, k - n) << endl;
		return 0;
	}
	else
		cout << min(n % k, k - (n % k)) << endl;
	return 0;
}




Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int n;
  scanf("%d",&n);
  int a[n];
  for (int i = 0; i < n; i++)
  {
    scanf("%d",&a[i]);
  }
  
  if (n%2==0)
  {
    for (int i = n-1; i > 0; i-=2)
    { 
      printf("%d ",a[i]);
    }
    for (int i = 0; i < n; i+=2)
    {
      printf("%d ",a[i]);
    }
  }else{
    for (int i = n-1; i >= 0; i-=2)
    { 
      printf("%d ",a[i]);
    }
    for (int i = 1; i < n; i+=2)
    {
      printf("%d ",a[i]);
    }
  }

  return 0;
}

Measured memory_bytes: 3092
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <tuple>
#include <unordered_map>
#include <list>
#include <numeric>
#include <utility>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <ctime>
#include <cassert>
#include <random>

#define INF 1000000000
#define LINF 9000000000000000000
#define mod  1000000007

#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<long long>vll;
typedef pair<int,int> pi;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
bool debug=false;

/*---------------------------------------------------*/

int graph[55][55];
int N, M;
  
bool check(vector<bool> used){
  for(int i = 0; i < N; i++){
    if(!used[i]) return true;
  }
  return false;
}

void dfs(vector<bool> &used, int now){
  for(int i = 0; i < N; i++){
    if(graph[now][i] && !used[i]){
      used[i] = true;
      dfs(used, i);
    }
  }
}

int main(){
  int a, b, ans = 0;
  
  cin >> N >> M;
  for(int i = 0; i < M; i++){
    cin >> a >> b;
    a--, b--;
    graph[a][b] = graph[b][a] = 1;
  }

  for(int i = 0; i < N; i++){
    for(int j = i; j < N; j++){
      if(i == j || !graph[i][j])continue;
      
      graph[i][j] = graph[j][i] = 0;
      vector<bool> used(N + 1);
      dfs(used, 0);
      if(check(used)){
	ans++;
      }
      graph[i][j] = graph[j][i] = 1;
    }
  }

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


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

int main(){
  int A,B,C,D;
  cin >> A >> B >> C >> D;
  int turn = 0;
  
  while(A > 0 && C > 0){
    if(0 != turn % 2){
      A = A - D;
    }
    else{
      C = C - B;
    }
    turn++;
  }
  
  if(A <= 0){
    cout << "No" << endl;
  }else{
    cout << "Yes" << endl;
  }
}

Measured memory_bytes: 3636
#include <array>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
using namespace std;


typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
	stringstream ss;
	ss << f;
	ss >> t;
}


#define REP(i,n) for(int i=0;i<int(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define RALL(v) (v).rbegin(),(v).rend()
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define PB push


#define MOD 1000000007LL
#define EPS 1e-10

int main()
{
    int N;
    cin >> N;
    set<int> s;
    int A;
    REP(i, N)
    {
        cin >> A;
        if (s.erase(A) == 0)
        {
            s.insert(A);
        }
    }
    cout << s.size() << endl;
    return 0;
}


Measured memory_bytes: 4864