akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Program
{
    void Run()
    {
        var sc = new Scanner();
        int n = sc.NextInt();
        int m = sc.NextInt();
        int[] a = new int[n + 1];
        for (int i = 0; i < m; i++)
        {
            a[sc.NextInt() - 1]++;
            a[sc.NextInt()]--;
        }
        int ans = 0;
        for (int i = 1; i < n; i++)
        {
            a[i] += a[i - 1];
        }
        for (int i = 0; i < n; i++)
            if (a[i] == m) ans++;
        Console.WriteLine(ans);
    }

    static void Main(string[] args)
    {
        new Program().Run();
    }

    static long Gcd(long a, long b)
    {
        if (a < b) return Gcd(b, a);
        if (b == 0) return a;
        return Gcd(b, a % b);
    }
}

class Scanner
{
    int index = -1;
    string[] buf;

    public Scanner()
    {
    }

    public int NextInt()
    {
        CheckNext();
        return int.Parse(buf[index++]);
    }

    public long NextLong()
    {
        CheckNext();
        return long.Parse(buf[index++]);
    }

    public double NextDouble()
    {
        CheckNext();
        return double.Parse(buf[index++]);
    }

    public string NextString()
    {
        CheckNext();
        return buf[index++];
    }

    private void CheckNext()
    {
        if (index >= 0 && index < buf.Length) return;

        buf = Console.ReadLine().Split(' ');
        index = 0;
    }
}


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

using namespace std;

#define x first
#define y second
#define mp make_pair
#define pb push_back
#define sqr(a) ((a) * (a))
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define forn(i, n) for(int i = 0; i < int(n); i++) 
#define fore(i, l, r) for(int i = int(l); i < int(r); i++)

typedef long long li;
typedef long double ld;
typedef pair<int, int> pt;
typedef pair<li, li> pli;

template <class A, class B> ostream& operator << (ostream& out, const pair<A, B> &a) {
	return out << "(" << a.x << ", " << a.y << ")";
}

template <class A> ostream& operator << (ostream& out, const vector<A> &v) {
	out << "[";
	forn(i, sz(v)) {
		if(i) out << ", ";
		out << v[i];
	}
	return out << "]";
}

mt19937 rnd(time(NULL));

const int INF = int(1e9);
const li INF64 = li(4e18);
const int MOD = INF + 7;
const ld EPS = 1e-9;
const ld PI = acos(-1.0);

const int N = 200 * 1000 + 13;
const int M = 1000 * 1000 + 13;

int n;
li c;
int a[N];

bool read () {
	if (scanf("%d%lld", &n, &c) != 2)
		return false;
	forn(i, n)
		scanf("%d", &a[i]);
	return true;
}

li dp[N];
pli t[4 * M];

pli get(int x){
	return mp(-2 * a[x], dp[x] + sqr(li(a[x])));
}

void build(int v, int l, int r){
	t[v] = mp(0, INF64);
	if (l == r - 1)
		return;
	int m = (l + r) / 2;
	build(v * 2, l, m);
	build(v * 2 + 1, m, r);
}

li f(pli f, int x){
	return f.x * x + f.y;
}

void upd(int v, int l, int r, pli fx){
	int m = (l + r) / 2;
	bool b1 = f(fx, l) < f(t[v], l);
	bool b2 = f(fx, m) < f(t[v], m);
	if (b2) swap(t[v], fx);
	if (l == r - 1)
		return;
	else if (b1 != b2)
		upd(v * 2, l, m, fx);
	else
		upd(v * 2 + 1, m, r, fx);
}

li get(int v, int l, int r, int x){
	if (l == r - 1)
		return f(t[v], x);
	int m = (l + r) / 2;
	if (x < m)
		return min(f(t[v], x), get(v * 2, l, m, x));
	else
		return min(f(t[v], x), get(v * 2 + 1, m, r, x));
}

void solve(){
	build(1, 0, M);
	upd(1, 0, M, get(0));
	fore(i, 1, n){
		dp[i] = get(1, 0, M, a[i]) + c + sqr(li(a[i]));
		upd(1, 0, M, get(i));
	}
	printf("%lld\n", dp[n - 1]);
}

int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
	
	int tt = clock();
	
#endif
	
	cerr.precision(15);
	cout.precision(15);
	cerr << fixed;
	cout << fixed;

	while(read()) {	
		solve();
		
#ifdef _DEBUG
	cerr << "TIME = " << clock() - tt << endl;
	tt = clock();
#endif

	}
}

Measured memory_bytes: 38528
#include <stdio.h>

void process(int n) {
    int i;

    for (i=1; i<=n; i++) {
        if (i % 3 == 0) {
	    printf(" %d", i);
	} else if (i % 10 == 3) {
	    printf(" %d", i);
	} else if (i / 10 % 10 == 3) {
	    printf(" %d", i);
	} else if (i / 100 > 0) {
	    if (i / 100 % 10 == 3) {
		printf(" %d", i);
	    } else if (i / 100 / 10 == 3) {
	        printf(" %d", i);
	    }
	} else if (i / 1000 > 0) {
	    if (i / 1000 % 10 == 3) {
		printf(" %d", i);
	    } else if (i / 1000 % 100 ==3) {
	        printf(" %d", i);
	    }
	}
    }
    printf("\n");
}

void scanner() {
    int n;
    scanf("%d", &n);
    process(n);
}

int main(void) {
    scanner();
    return 0;
}


Measured memory_bytes: 2100
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
const double EPS = 1e-10;
using namespace std;
class Edge{
public:
    int from,to,value;
    Edge(LL a,LL b,LL c){
        from = a;
        to = b;
        value = c;
    }
    Edge(LL a,LL b){
        from = a;
        to = b;
    }
};



int main(){
    int r,W,C,R;
    while(cin >> r >>W >> C >> R){
        if(r == 0 && W == 0 && C == 0 && R == 0)return 0;
        for(int i = 0;;i++){
            int q = r + R * i;
            if(q / W >= C){
                cout<<i<<endl;
                break;
            }
        }
    }
}



Measured memory_bytes: 3088
n=int(input())
a1=list(map(int,input().split()))
a2=list(map(int,input().split()))

ans=0
all=sum(a1)+sum(a2)

for i in range(n):
  temp=all-sum(a2[:i])-sum(a1[i+1:])
  ans=max(ans,temp)
print(ans)

Measured memory_bytes: 3064
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

s = input()
if s == "ABC":
  print("ARC")
else:
  print("ABC")

Measured memory_bytes: 9348
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        HashMap <String,Integer> map = new HashMap<>();
        ArrayList <String> list = new ArrayList<>();
        int max = 0;
        
        for(int i= 0; i<N; i++){
            String tmp = sc.next();
            if(map.containsKey(tmp)){
                map.put(tmp,map.get(tmp)+1);
            }else{
                map.put(tmp,1);
            }
        }
        
        for(String key : map.keySet()){
            if(map.get(key)>max){
                max = map.get(key);
            }
        }
        
        for(String key : map.keySet()){
            if(max == map.get(key)){
                list.add(key);
            }
        }
        
        Collections.sort(list);
        
        for(String str : list){
            System.out.println(str);
        }
        
    }
}


Measured memory_bytes: 81312
#include <bits/stdc++.h>
typedef long long ll;
#define mod 1000000007
using namespace std;
int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("outp.txt","w",stdout);
    #endif
    ll n;cin>>n;
    string s;cin>>s;
    if(n%2==1)
        cout<<"No";
    else
    {
        if(s.substr(0,n/2)==s.substr(n/2))
            cout<<"Yes";
        else
            cout<<"No";
    }
}

    


Measured memory_bytes: 3576
#include <algorithm>
#include<iostream>
#include<vector>
#include<map>
#include<string>

#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>

using namespace std;
int main(){
  string s;
  int sum = 0;
  long num;
  cin >> s;
  for(char c : s){
	sum += c - '0';
  }
  sscanf(s.c_str(),"%ld",&num);

  //cout << "sum:" << sum << endl;
  if(num % sum == 0){
	cout << "Yes" << endl;
  }
  else{
	cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
function Main (S) {
  S = S.split("\n")[0].split("");
  var stid = -1;
  var enid = -1;
  S.forEach(function (element, index) {
    if (stid == -1 && element == "A") stid = index;
    if (stid != -1 && element == "Z") enid = index;
  });
  console.log(enid - stid + 1);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 9676
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <cfloat>

using std::cerr;
using std::cin;
using std::cout;
using std::endl;

struct Path{
  int town_a,town_b,cost;
  Path(int a,int b,int c):town_a(a),town_b(b),cost(c){}
  bool operator<(const Path& another)const{
    return cost<another.cost;
  }
  bool operator>(const Path& another)const{
    return cost>another.cost;
  }
};

// Manages Union-Find Forest.
class UnionFindForest {
  std::vector<int> parent_;
  std::vector<int> rank_;
  std::vector<int> size_;

public:
  // Initialize forest.
  // parent_[i]=i, rank_[i]=0, size_[i]=1.
  UnionFindForest(const int &n);
  // Get the number of the root of the node q.
  int Root(const int &q);
  // Return true if the roots of x and y is same.
  bool IsSame(const int &x, const int &y);
  // Unite the tree x and tree y.
  void Unite(int x, int y);
  // Get the number of nodes which are the same group as node q.
  int Size(const int &q);
};
UnionFindForest::UnionFindForest(const int &n) {
  parent_.resize(n);
  rank_.resize(n);
  size_.resize(n);
  for (int i = 0; i < n; i++) {
    parent_[i] = i;
    rank_[i]   = 0;
    size_[i]   = 1;
  }
}
int UnionFindForest::Size(const int &q) {
  return size_[Root(q)];
}

int UnionFindForest::Root(const int &q) {
  if (parent_[q] == q) {
    return q;
  } else {
    return parent_[q] = Root(parent_[q]);
  }
}

bool UnionFindForest::IsSame(const int &x, const int &y) {
  return Root(x) == Root(y);
}

void UnionFindForest::Unite(int x, int y) {
  x = Root(x);
  y = Root(y);
  if (x == y) return;
  if (rank_[x] < rank_[y]) {
    parent_[x] = y;
    size_[y] += size_[x];
    size_[x] = 0;

  } else {
    parent_[y] = x;
    size_[x] += size_[y];
    size_[y] = 0;
    if (rank_[x] == rank_[y]) rank_[x]++;
  }
}

struct Node{
  int x, y;
  int node_num;
  Node(int a,int b,int num):x(a),y(b),node_num(num){}
};

int main(){
  cout << std::fixed << std::setprecision(16);
  cin.tie(nullptr);
  std::ios::sync_with_stdio(false);

  int n;
  cin>>n;
  std::vector<Path> path;
  std::vector<Node> node;
  for(int i=0;i<n;i++){
    int x,y;
    cin>>x>>y;
    node.push_back(Node(x,y,i));
  }
  std::sort(node.begin(), node.end(),[](Node a,Node b){
    return a.x>b.x;
  });
  for(int i=0;i<n-1;i++){
    path.push_back(Path(node[i].node_num,node[i+1].node_num,std::min(std::abs(node[i].x-node[i+1].x),std::abs(node[i].y-node[i+1].y))));
  }
  std::sort(node.begin(), node.end(),[](Node a,Node b){
    return a.y>b.y;
  });
  for(int i=0;i<n-1;i++){
    path.push_back(Path(node[i].node_num,node[i+1].node_num,std::min(std::abs(node[i].x-node[i+1].x),std::abs(node[i].y-node[i+1].y))));
  }
  
  UnionFindForest uf(n);
  std::sort(path.begin(), path.end());
  int result=0;
  for(auto p:path){
    if(uf.Root(p.town_a)!=uf.Root(p.town_b)){
      uf.Unite(p.town_a,p.town_b);
      result+=p.cost;
    }
  }
  cout<<result<<endl;



  return 0;
}

Measured memory_bytes: 6132
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <numeric>
#define REP(i,n) for(int i=0;i<(n);++i)
using namespace std;
typedef long long LL;

vector<int> divisors(int n) {
  vector<int> ret;
  for(int i=1; i*i<=n; ++i) {
    if(n % i != 0) continue;
    ret.push_back(i);
    if(i * i != n) {
      ret.push_back(n/i);
    }
  }
  sort(ret.begin(), ret.end(), greater<int>());
  return ret;
}

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  REP(i, N) { cin >> A[i]; }
  for(const auto& d : divisors(accumulate(A.begin(), A.end(), 0))) {
    vector<int> b(N);
    REP(i, N) { b[i] = A[i] % d; }
    sort(b.begin(), b.end());
    int k = N - accumulate(b.begin(), b.end(), 0) / d;
    int sum = accumulate(b.begin(), b.begin() + k, 0);
    if(sum <= K) {
      cout << d << endl;
      break;
    }
  }
}

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

using namespace std;  

int main(){
  string s,t;
  cin >> s >> t;
  sort(s.begin(), s.end());
  sort(t.rbegin(), t.rend());

  if(s < t) cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

int top, stack[1000];

void push(int x)
{
	stack[++top] = x;
}

int pop()
{
	top--;
	return stack[top+1];
}

int main(int argc, char const *argv[])
{
	int a, b;
	top = 0;
	char s[10];
	while(scanf("%s",s)!=EOF) {
	    if(s[0]=='+')
	    {
	    	a = pop();
	    	b = pop();
	    	push(a+b);
	    }else if(s[0]=='-')
	    {
	    	a = pop();
	    	b = pop();
	    	push(b-a);
	    }else if(s[0]=='*')
	    {
	    	a = pop();
	    	b = pop();
	    	push(a*b);
	    }else
	    {
	    	push(atoi(s));
	    }
	}
	printf("%d\n", pop());
	return 0;
}

Measured memory_bytes: 548
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF (1<<30)
#define LINF (1LL<<60)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
typedef unsigned long long int ull;
typedef long long lint;
 
int main(void){
    int N,K;
    cin >> N >> K;
    int A[N];
    rep(i,N) cin >> A[i];
    cout << (int)(1+ceil((double)(N-K)/(K-1))) << endl;
}

Measured memory_bytes: 640
using System;
using static System.Console;
using static System.Int32;
using static System.Math;
using System.Linq;
using System.Collections.Generic;

class Solution
{
    static void Main()
    {
    lb:
        var sp = ReadLine().Split();
        int k = Parse(sp[1]);
        sp = ReadLine().Split();
        int nr = Parse(sp[2]), ns = Parse(sp[0]), np = Parse(sp[1]);
        var t = ReadLine().ToCharArray();
        int result = 0;
        for (int i = 0; i < t.Length; ++i)
        {
            int mae = i - k;
            if (0 <= mae && t[mae] == t[i])
            {
                t[i] = '_';
            }
            else
            {
                switch (t[i])
                {
                    case 'r': result += nr; break;
                    case 's': result += ns; break;
                    case 'p': result += np; break;
                }
            }
        }
        WriteLine(result);
    }
}


Measured memory_bytes: 13208
#!/mnt/c/Users/moiki/bash/env/bin/python
N = int(input())
h = list(map(int, input().split()))

suml = [1e5 for i in range(N)]
suml[0] = 0
suml[1] = abs(h[1] - h[0])

for e in range(2, N):
    suml[e] = min(
        abs(h[e]-h[e-1]) + suml[e-1],
        abs(h[e]-h[e-2]) + suml[e-2],
    )

# print(suml)
print(suml[N-1])


Measured memory_bytes: 13980
x = int(input())

lp = [0] * 1000005
for i in range(2, 100005):
    if lp[i] == 1:
        continue
    if x <= i:
        print(i)
        break

    k = i*i
    while k < 1000005:
        lp[k] = 1
        k += i


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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine(solve());
            return;
        }

        private static long solve()
        {
            Console.ReadLine();
            var strS = Console.ReadLine();
            var strT = Console.ReadLine();

            long lenS = strS.Length;
            long lenT = strT.Length;

            var arrS = strS.ToCharArray();
            var arrT = strT.ToCharArray();

            if (lenS < lenT)
            {
                lenS = strT.Length;
                lenT = strS.Length;

                arrS = strT.ToCharArray();
                arrT = strS.ToCharArray();
            }

            long gcm = Gcd(lenS, lenT);
            long lcm = lenS / Gcd(lenS, lenT) * lenT;

            //if (gcm == 1) return lcm;

            for (long i = 0; i < lenT; i++)
            {
                if (i * lenS / gcm >= lenS || i * lenT / gcm >= lenT) break;
                if (arrS[i * lenS / gcm] != arrT[i * lenT / gcm]) return -1;
            }
            return lcm;
        }

        public static long Gcd(long a, long b)
        {
            if (a < b)
                return Gcd(b, a);
            while (b != 0)
            {
                long r = a % b;
                a = b;
                b = r;
            }
            return a;
        }
    }
}




Measured memory_bytes: 13208
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

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

const char c1[4] = { '.', '#', '.', '#' };
const char c2[4] = { '.', '.', '#', '#' };

int N;
bool found;

void dfs(string s1, string s2, bool f){
	if (s1.size() == N) return;
	if (found) return;

	bool f2 = false;
	rep (i, 4){
		string t1 = "", t2 = "";
		if (f){
			t1 = s1 + c1[i];
			t2 = s2 + c2[i];
		}else{
			t1 = c1[i] + s1;
			t2 = c2[i] + s2;
		} // end if
		cout << t1 << endl;
		cout << t2 << endl;
		fflush(stdout);
		string res; cin >> res;
		if (res == "end"){
			found = true;
			break;
		}else
		if (res[0] == 'T'){
			dfs (t1, t2, f);
			f2 = true;
		} // end if
	} // end rep

	if (!f2) dfs(s1, s2, !f);
}	
		
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	found = false;
	cin >> N;

	dfs ("", "", true);

	return 0;
}

Measured memory_bytes: 724
# Template 1.0
import sys, re
from collections import deque, defaultdict, Counter, OrderedDict
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from heapq import heappush, heappop, heapify, nlargest, nsmallest
def STR(): return list(input())
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def list2d(a, b, c): return [[c] * b for i in range(a)]
def sortListWithIndex(listOfTuples, idx):   return (sorted(listOfTuples, key=lambda x: x[idx]))
def sortDictWithVal(passedDic):
    temp = sorted(passedDic.items(), key=lambda kv: (kv[1], kv[0]))
    toret = {}
    for tup in temp:
        toret[tup[0]] = tup[1]
    return toret
def sortDictWithKey(passedDic):
    return dict(OrderedDict(sorted(passedDic.items())))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

n,m = MAP()

a = ["-1"]*n
flag = 0

if(n==1 and m==0):
    print(0)
else:
    for _ in range(m):
        s,c = MAP()
        c = str(c)
        if(a[s-1]=="-1" or a[s-1]==c):
            a[s-1] = c
        else:
            flag = 1
            break
    if(flag==1):
        print(-1)
    else:
        ans = 0
        if(a[0]=="-1"):
            a[0] = "1"

        for i in range(1, n):
            if(a[i]=="-1"):
                a[i] = "0"
        ans = int("".join(a))
        # print(ans)
        if(len(str(ans))==n):
            print(ans)
        else:
            print(-1)

Measured memory_bytes: 70872
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size,n=1,init=nil) #nに配列の次元数、sizeに配列の大きさ、initに初期値を投げることでその配列を返す
  if n==1
    return Array.new(size){init}
  else
    return Array.new(n).map{Array.new(size){init}}
  end
end


s=gets.chomp
if s=~/^(hi)+$/
  puts "Yes"
else
  puts "No"
end

Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pcc pair<char,char>
#define vi vector <int>
#define vl vector <ll>
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define pd(x) printf("%d",x)
#define plld(x) printf("%lld",x)
#define pds(x) printf("%d ",x)
#define pllds(x) printf("%lld ",x)
#define pdn(x) printf("%d\n",x)
#define plldn(x) printf("%lld\n",x)
#define INF 2e9
#define INFLL 4e18
using namespace std;
ll powmod(ll base,ll exponent,ll mod){ // with mod < 1e9
	ll ans=1;
	while(exponent){
		if(exponent&1)ans=(ans*base)%mod;
		base=(base*base)%mod;
		exponent/=2;
	}
	return ans;
}
ll gcd(ll a, ll b){
	if(b==0) return a;
	else return gcd(b,a%b);
}
const int upperlimit = 1e7+100;
const int mod = 1e9+7;
ll arr[upperlimit];
ll tr(int n){
	ll ans=n;ans*=n+1;ans>>=1;
	return ans;
}
int main() {
//	freopen(".in","r",stdin);freopen(".out","w",stdout);
	int n;
	sd(n);
	ll ans=0;
	for(int i = 1; i <= n; i++){
		ll calc=tr(n/i);
		calc*=i;
		ans+=calc;
	}
	plld(ans);
	return 0;
}

Measured memory_bytes: 3836
fun bd097(args: Array<String>) {
    val numList = args[1].split(" ").map { it.toInt() }
    val numPairList = args.drop(2).map { line -> line.split(" ").map { it.toInt() } }
    val unionFind = UnionFind(numList.size)
    numPairList.forEach {
        unionFind.union(it[0], it[1])
    }
    val ans = numList.filterIndexed { index, num -> unionFind.same(index + 1, num) }.count()
    println(ans)
}

class UnionFind(n: Int) {
    private var parentList: MutableList<Int> =
            (0 until n).map { it }.toMutableList()
    private var rankList: MutableList<Int> =
            (0 until n).map { 1 }.toMutableList()

    fun union(x: Int, y: Int) {
        val xRoot = root(x - 1)
        val yRoot = root(y - 1)
        if (rankList[xRoot] > rankList[yRoot]) {
            parentList[yRoot] = xRoot
        } else {
            parentList[xRoot] = yRoot
        }
    }

    fun same(x: Int, y: Int): Boolean {
        return root(x - 1) == root(y - 1)
    }

    private fun root(x: Int): Int {
        val parent = parentList[x]
        return if (x == parentList[x]) {
            x
        } else {
            val root = root(parent)
            parentList[x] = root
            root
        }
    }
}

fun main(args: Array<String>) {
    bd097(readLineList())
}

fun readLineList(): Array<String> {
    val lineList = mutableListOf<String>()
    while (true) {
        val line = readLine()
        if (line.isNullOrBlank()) {
            break
        } else {
            lineList.add(line!!)
        }
    }
    return lineList.toTypedArray()
}

Measured memory_bytes: 107044
import math


def main():

    mod = 1000000007
    N = int(input())

    A = [0]
    B = [0]

    for n in range(N):
        a, b = map(int, input().split())
        A.append(a)
        B.append(b)

    calc = dict()
    non_count = 0

    for i in range(1, N + 1):

        if A[i] == 0 and B[i] == 0:
            non_count += 1
        elif A[i] == 0:
            k = (0, 1)
            if calc.get(k):
                calc[k][0] += 1
            else:
                calc[k] = [1, 0]
        elif B[i] == 0:
            k = (0, 1)
            if calc.get(k):
                calc[k][1] += 1
            else:
                calc[k] = [0, 1]
        else:
            r = math.gcd(A[i], B[i])
            m = 1
            if A[i] * B[i] < 0:
                m = -1
            k1 = (m * abs(A[i] // r), abs(B[i] // r))
            k2 = (-m * abs(B[i] // r), abs(A[i] // r))
            if calc.get(k1):
                calc[k1][0] += 1
            elif not calc.get(k2):
                calc[k1] = [1, 0]
            else:
                calc[k2][1] += 1

    N = N - non_count

    count = 0
    for k, v in calc.items():
        if not v[0] * v[1] == 0:
            count += v[0] + v[1]

    ans = pow(2, N - count, mod)
    for k, v in calc.items():
        if not v[0] * v[1] == 0:
            comb = (pow(2, v[0]) + pow(2, v[1]) - 1)
            ans = (ans * comb) % mod

    print((ans - 1 + non_count) % mod)


if __name__ == '__main__':
    main()


Measured memory_bytes: 79356
#include <stdio.h>
int main(void)
{
	int a,b;
	scanf("%d",&a);
	scanf("%d",&b);
	
	if(a>=0&&a<=8&&b>=0&&b<=8){
			printf("Yay!");
	}else if(a>8){
			printf(":(");
	}else if(b>8){
			printf(":(");
	}
	return 0;
}

Measured memory_bytes: 128
name1,a1,b1=map(str,input().split())
name2,a2,b2=map(str,input().split())
name3,a3,b3=map(str,input().split())
name4,a4,b4=map(str,input().split())
name5,a5,b5=map(str,input().split())
name6,a6,b6=map(str,input().split())
name7,a7,b7=map(str,input().split())
name8,a8,b8=map(str,input().split())
name9,a9,b9=map(str,input().split())

print(name1,int(a1)+int(b1),int(a1)*200+int(b1)*300)
print(name2,int(a2)+int(b2),int(a2)*200+int(b2)*300)
print(name3,int(a3)+int(b3),int(a3)*200+int(b3)*300)
print(name4,int(a4)+int(b4),int(a4)*200+int(b4)*300)
print(name5,int(a5)+int(b5),int(a5)*200+int(b5)*300)
print(name6,int(a6)+int(b6),int(a6)*200+int(b6)*300)
print(name7,int(a7)+int(b7),int(a7)*200+int(b7)*300)
print(name8,int(a8)+int(b8),int(a8)*200+int(b8)*300)
print(name9,int(a9)+int(b9),int(a9)*200+int(b9)*300)



Measured memory_bytes: 5604
yen500 = int(input(''))
yen100 = int(input(''))
yen50 = int(input(''))
total = int(input(''))
count = 0
for x in range(yen500 + 1):
  for y in range(yen100 + 1):
    for z in range(yen50 + 1):
      if 500 * x + 100 * y + 50 * z == total:
        count += 1

print(count)


Measured memory_bytes: 3060
import sys
input = sys.stdin.readline
inf = float('inf')
mod = 10**9+7


def INT_(n): return int(n)-1


def MI(): return map(int, input().split())


def MF(): return map(float, input().split())


def MI_(): return map(INT_, input().split())


def LI(): return list(MI())


def LI_(): return [int(x) - 1 for x in input().split()]


def LF(): return list(MF())


def LIN(n: int): return [input() for _ in range(n)]


def LLIN(n: int): return [LI() for _ in range(n)]


def LLIN_(n: int): return [LI_() for _ in range(n)]


def LLI(): return [list(map(int, l.split())) for l in input()]


def I(): return int(input())


def F(): return float(input())


def ST(): return input().replace('\n', '')


def main():

    class WeightedUnionFind():
        def __init__(self, n):
            self.nodes = [-1 for _ in range(n)]
            self.weight = [0] * n

        def get_root(self, x):
            if self.nodes[x] < 0:
                return x
            else:
                y = self.get_root(self.nodes[x])
                self.weight[x] += self.weight[self.nodes[x]]
                self.nodes[x] = y
                return y

        def unite(self, x, y, w):
            w += self.weight[x]-self.weight[y]
            root_x = self.get_root(x)
            root_y = self.get_root(y)
            if root_x != root_y:
                # 大きい木の方につないだほうが計算量が減る
                if self.nodes[root_x] > self.nodes[root_y]:
                    root_x, root_y = root_y, root_x
                    w *= -1
                self.nodes[root_x] += self.nodes[root_y]
                self.nodes[root_y] = root_x
                self.weight[root_y] = w

        def diff(self, x, y):
            return self.weight[y] - self.weight[x]

        def same(self, x, y):
            return get_root(x) == get_root(y)
    N, M = MI()
    edge = [[] for _ in range(N)]
    uf = WeightedUnionFind(N)
    get_root, unite, nodes, diff, same = uf.get_root, uf.unite, uf.nodes, uf.diff, uf.same
    distanse = [0] * N
    distanse[0] = 0
    rev_edge = [[]for _ in range(N)]
    for _ in range(M):
        l, r, d = MI_()
        d += 1
        edge[l].append((r, d))
        if same(l, r) and diff(l, r) != d:
            print("No")
            exit()
        else:
            unite(l, r, d)

    print("Yes")


if __name__ == '__main__':
    main()


Measured memory_bytes: 49564
use std::env;
use std::io::*;
use std::str::*;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let s = stdin.bytes().map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().ok().unwrap()
}

fn main() {
    // main の引数
    /*
        引数なしのときargs.len() = 1;
    */
    let args: Vec<String> = env::args().collect();

    let A = read::<i32>();
    let B = read::<i32>();
    let C = read::<i32>();
    let D = read::<i32>();

    if A+B > C+D {
        println!("Left");
    } else if A+B < C+D {
        println!("Right");
    } else {
        println!("Balanced");
    }
}



Measured memory_bytes: 4352
#include <iostream>
using namespace std;
int main(){
  int n,w,h,x,y,s,t,i,j,wcs,hcs,hce,wce,max,cnt,data[101][101];
  while(1){
    max=0;
    cin >> n;
    if(n==0) break;
    cin >> w >> h;
    for(i=0;i<=h;i++){
      for(j=0;j<=w;j++){
	data[i][j]=0;
      }
    }
    for(i=0;i<n;i++){
      cin >> x >> y;
      data[y][x]=1;
    }
    cin >> s >> t;
    hcs=1;
    wcs=1;
    hce=t;
    wce=s;
    while(1){
      while(1){
	cnt=0;
	for(i=hcs;i<=hce;i++){
	  for(j=wcs;j<=wce;j++){
	    if(data[i][j]==1){
	      cnt++;
	    }
	  }
	}
	if(cnt>max) max=cnt;
	wcs++;
	wce++;
	if(wce==w+1) break;
      }
      hcs++;
      hce++;
      wcs=1;
      wce=s;
      if(hce==h+1) break;
    }
    cout << max << endl;
  }
  return 0;
}

Measured memory_bytes: 1196
#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
map<long long, long long> ma;
long long n, a[N], s, ans;
main() {
	scanf("%lld", &n);
	for (int i = 1; i <= n; ++i)
		scanf("%lld", &a[i]);
	ma[0] = 1;
	for (int i = 1; i <= n; ++i) {
		s += a[i];
		ans += ma[s];
		ma[s]++;
	}
	printf("%lld\n", ans);
} 

Measured memory_bytes: 14336
import java.io.*;
import java.util.*;
class Main{
    public static void main(String[] args) throws Exception {
		hayami saori = new hayami();
		Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
		int num = n*(n-1)/2;
        int[] x = new int[n];
		int[] y = new int[n]; 
		double[] sa = new double[num];
		int count = 0;
        
        for(int i = 1;i <= n;i++){
            x[i-1] = sc.nextInt();
            y[i-1] = sc.nextInt();
		}
		for(int i = 0;i < n -1;i++){
			for(int j = i+1;j < n;j++){				
				sa[count] = Math.sqrt((x[i] - x[j])*(x[i] - x[j]) + (y[i] - y[j])*(y[i] - y[j]));
				count++;			
			}
		}
		int a = 1;
		for(int i = 1;i <= n;i++){
            a *= i;
		}
		int b = (a * (n-1))/num;
		double[] ans = new double[num];
		for(int i = 0;i < sa.length;i++){
			ans[i] = sa[i] * b;
		}
		double sum = 0;
		for( int i=0; i < ans.length; i++ ) {
				sum += ans[i];
		}
		double ave = sum / a;
		System.out.println(ave);		
    }
}

class hayami implements Closeable {
	private final InputStream in = System.in;
	private final byte[] hayami = new byte[1024];
	private int Hayami = 0;
	private int saori = 0;
	private boolean HayamiSaori() {
		if (Hayami < saori) {
			return true;
		}else{
			Hayami = 0;
			try {
				saori = in.read(hayami);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (saori <= 0) {
				return false;
			}
		}
		return true;
	}
	private int SaoriHayami() { 
		if (HayamiSaori()) {
            return hayami[Hayami++];
         }else{
             return -1;
         }
	}
	private static boolean hayami_saori(int hayami) { 
		return 33 <= hayami && hayami <= 126;
	}
	public boolean hayamisaori() { 
		while(HayamiSaori() && !hayami_saori(hayami[Hayami])) Hayami++; return HayamiSaori();
	}
	public String nextHayami() {
		if (!hayamisaori()) throw new NoSuchElementException();
		StringBuilder hayamin = new StringBuilder();
		int saori = SaoriHayami();
		while(hayami_saori(saori)) {
			hayamin.appendCodePoint(saori);
			saori = SaoriHayami();
		}
		return hayamin.toString();
	}
	public long saorihayami() {//nextLong
		if (!hayamisaori()) throw new NoSuchElementException();
		long hayami = 0;
		boolean misao = false;
		int saori = SaoriHayami();
		if (saori == '-') {
			misao = true;
			saori = SaoriHayami();
		}
		if (saori < '0' || '9' < saori) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= saori && saori <= '9') {
				hayami *= 10;
				hayami += saori - '0';
			}else if(saori == -1 || !hayami_saori(saori)){
				return misao ? -hayami : hayami;
			}else{
				throw new NumberFormatException();
			}
			saori = SaoriHayami();
		}
	}
	public int saori_hayami() {//nextInt
		long hayami = saorihayami();
		if (hayami < Integer.MIN_VALUE || hayami > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) hayami;
	}
	public double Hayamin() { //nextDouble
		return Double.parseDouble(nextHayami());
	}
	public void close() {
		try {
			in.close();
		} catch (IOException e) {
		}
    }
    
}

Measured memory_bytes: 23764
using System;

namespace AtCoder20190309
{
    class Program
    {
        static void Main(string[] args)
        {
            int H,W,h,w;
            //a = int.Parse(Console.ReadLine()); //標準入力
            string[] str1 = Console.ReadLine().Split(' ');//2つ以上のスペース区切り入力の取得
            string[] str2 = Console.ReadLine().Split(' ');//2つ以上のスペース区切り入力の取得
            H = int.Parse(str1[0]);  //数値で受け取りたい場合は変換する
            W = int.Parse(str1[1]);
            h = int.Parse(str2[0]);
            w = int.Parse(str2[1]);

            int h1 = H - h;
            int w1 = W - w;

            Console.Write(h1 * w1);
            //Console.Write("改行なし a = {0} b = {1} c = {2}", a, b, c);//改行なし出力
            //Console.WriteLine("改行あり a = {0} b = {1} c = {2}", a, b, c);//改行付き出力
        }
    }

}


Measured memory_bytes: 11092
use std::io;
use std::cmp;


/// N <= 10^5, K <= 100
/// dp[i] = 足場iまでのコストの総和の最小値
/// O(NK) <= 10^7
fn main() {
    let (n, k) = {
        let i = read::<usize>();
        (i[0], i[1])
    };
    let hn = read::<isize>();

    let mut dp = vec![::std::isize::MAX; n];
    dp[0] = 0;

    for i in 1..n {
        for j in 1..cmp::min(k, i) + 1 {
            dp[i] = cmp::min(
                dp[i],
                dp[i - j] + (hn[i] - hn[i - j]).abs(),
            );
        }
    }

    println!("{}", dp[n - 1]);
}


#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
std::str::FromStr,
T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
std::str::FromStr,
T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

Measured memory_bytes: 6396
n,k=map(int,input().split())
mod=10**9+7
fact=[1]*(max(n-k,k)+2)
inv=[1]*(max(n-k,k)+2)
for i in range(2,max(n-k,k)+2):
    fact[i]=i*fact[i-1]%mod
inv[-1]=pow(fact[-1],mod-2,mod)
for i in range(max(n-k,k)+1,1,-1):
    inv[i-1]=inv[i]*i%mod
def comb(x,y):return fact[x]*inv[y]%mod*inv[x-y]%mod if x>=y>=0 else 0
for i in range(1,k+1):
    print(comb(k-1,i-1)*comb(n-k+1,i)%mod)

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

int main() {
    int N, M, X;
    std::cin >> N >> M >> X;

    int C[N];
    int A[N][M];
    for (int i = 0; i < N; ++i) {
        std::cin >> C[i];
        for (int j = 0; j < M; ++j) {
            std::cin >> A[i][j];
        }
    }

    int min = INT32_MAX;
    for (int i = 1; i < (1 << N); ++i) {
        int p = 0; 
        int u[M] = {0};
        for (int j = 0; j < N; ++j) {
            if ((i >> j) & 1) {
                p += C[j];
                for (int k = 0; k < M; ++k) {
                    u[k] += A[j][k];
                }
            }
        }

        bool ok = true;
        for (int k = 0; k < M; ++k) {
            if (u[k] < X) {
                ok = false;
                break;
            }
        }

        if (ok) {
            min = std::min(min, p);
        }
    }

    if (min == INT32_MAX) {
        std::cout << -1 << std::endl;
    } else {
        std::cout << min << std::endl;
    }

    return 0;
}


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

#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,x,n) for(int i=x; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define all(X) (X).begin(),(X).end()
#define X first
#define Y second
#define pb push_back
#define eb emplace_back

using namespace std;
typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

template<class A, size_t N, class T> void Fill(A (&a)[N], const T &v){ fill( (T*)a, (T*)(a+N), v ); }

const ll INF = 1e9+7;


int sum_v[2005][2005] = {};
int sum_e[2][2005][2005] = {};
int N, M, Q;
string S[2005];
int main(){
	ios_base::sync_with_stdio(false);

	cin >> N >> M >> Q;
	rep(i,N) cin >> S[i];

	rep(i,N) rep(j,M){
		sum_v[i+1][j+1] = sum_v[i+1][j] + sum_v[i][j+1] - sum_v[i][j];
		rep(k,2) sum_e[k][i+1][j+1] = sum_e[k][i+1][j] + sum_e[k][i][j+1] - sum_e[k][i][j];
		if( S[i][j] == '1' ){
			sum_v[i+1][j+1]++;
			if( i>0 && S[i-1][j] == '1' ) sum_e[0][i+1][j+1]++;
			if( j>0 && S[i][j-1] == '1' ) sum_e[1][i+1][j+1]++;
		}
	}

	auto f = [&](int sum[2005][2005], int x1, int y1, int x2, int y2){
		return sum[x2][y2] - sum[x1][y2] - sum[x2][y1] + sum[x1][y1];
	};

	rep(i,Q){
		int x1, y1, x2, y2;
		cin >> x1 >> y1 >> x2 >> y2;
		int v  = f(sum_v, x1-1, y1-1, x2, y2);
		int e0 = f(sum_e[0], x1, y1-1, x2, y2);
		int e1 = f(sum_e[1], x1-1, y1, x2, y2);
		//cout << v << " " << e0 << " " << e1 << endl;
		cout << v - e0 - e1 << endl;
	}

	return 0;
}

Measured memory_bytes: 53120
#include <stdio.h>

int main(void)
{
    int a, b;
    int i;

    scanf("%d %d", &a, &b);

    if (a >= b) {
        for (i = 0; i < a; i++) {
            printf("%d", b);
        }
    } else {
        for (i = 0; i < b; i++) {
            printf("%d", a);
        }
    }

    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <string>
#include <map>
#include <math.h>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <set>
#include <queue>
#include <sstream>
#include <deque>
#include <memory.h>
#include <cassert>
#include <ctime>
#include <time.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define pb push_back
#define mp make_pair
#define FILE "file"
#define lc v << 1
#define rc (v << 1) + 1
#define inf 1e+9
#define linf ll(1e+18)
#define classname SubtreeSumHash

int a[60][26];

void solve()
{
    int n;
    cin >> n;
    for(int i = 0; i < n; i++)
    {
        string s;
        cin >> s;
        for(int k = 0; k < (int) s.length(); k++)
        {
            a[i][s[k] - 'a']++;
        }
    }
    
    for(int i = 0; i < 26; i++)
    {
        int temp = inf;
        for(int k = 0; k < n; k++)
        {
            temp = min(temp, a[k][i]);
        }
        for(int j = 0; j < temp; j++)
        {
           cout << char(i + 'a');
        }
    }
    //cout << "\n";
}


int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0), cout.tie(0);
    //freopen(FILE ".in", "r", stdin);freopen(FILE ".out", "w", stdout);
    solve();
    return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
from itertools import accumulate


def two_pointers(ary, l, r, split, ary_func, comb_func, comp_func):

    left = ary_func(ary, l, split)
    right = ary_func(ary, split, r)
    val = comb_func(left, right)

    for i in range(split + 1, r):
        tmp_left = ary_func(ary, l, i)
        tmp_right = ary_func(ary, i, r)
        tmp_val = comb_func(tmp_left, tmp_right)

        if comp_func(val, tmp_val):
            return i - 1, val, left, right
        else:
            left = tmp_left
            right = tmp_right
            val = tmp_val

    else:
        return r - 1, val, left, right


if __name__ == '__main__':
    n = int(input())
    a = [int(_) for _ in input().split()]
    cul_ary = [0] + list(accumulate(a))

    l_split = 1
    r_split = 3
    griefs = []

    for i in range(2, n - 1):
        l_split, l_diff, p, q = two_pointers(
            cul_ary, 0, i, l_split, lambda ary, l, r: ary[r] - ary[l],
            lambda left, right: abs(left - right),
            lambda val1, val2: True if val1 < val2 else False)

        r_split, r_diff, r, s = two_pointers(
            cul_ary, i, n, r_split, lambda ary, l, r: ary[r] - ary[l],
            lambda left, right: abs(left - right),
            lambda val1, val2: True if val1 < val2 else False)

        griefs.append(max(p, q, r, s) - min(p, q, r, s))

    print(min(griefs))


Measured memory_bytes: 28140
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<set>
#include<climits>

#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 llong long long
#define pb(a) push_back(a)

using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef tuple<ll, ll, ll, ll> lltpl;



/******************************************************************************************/


const ll INF = 1e9 + 7;
const ll MOD = 1e9 + 7;



template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}

int main() {

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

	int n;
	cin >> n;
	vector<ll> a(n);
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	sort(a.begin(), a.end(), greater<int>());

	ll ans = 0;
	if (n % 2 == 0) {
		for (int i = 0; i < n / 2 - 1; i++) {
			ans += 2 * a[i];
		}
		ans += a[n / 2 - 1];
		ans -= a[n / 2];
		for (int i = n / 2 + 1; i < n; i++) {
			ans -= 2 * a[i];
		}

	}
	else {
		
		ll cnt1 = 0;
		for (int i = 0; i < n / 2 - 1; i++) {
			cnt1 += 2 * a[i];
		}
		cnt1 += a[n / 2 - 1] + a[n / 2];
		for (int i = n / 2 + 1; i < n; i++) {
			cnt1 -= 2 * a[i];
		}

		ll cnt2 = 0;
		for (int i = 0; i < n / 2; i++) {
			cnt2 += 2 * a[i];
		}
		cnt2 -= (a[n / 2] + a[n / 2 + 1]);
		for (int i = n / 2 + 2; i < n; i++) {
			cnt2 -= 2 * a[i];
		}
		ans = max(cnt1, cnt2);
	}
	cout << ans << endl;


}


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

int main() {
    int N;
    cin >> N;
    vector<int> t(N + 1), x(N + 1), y(N + 1);
    t[0] = 0, x[0] = 0, y[0] = 0;
    for (int i = 1; i <= N; i++)
        cin >> t[i] >> x[i] >> y[i];

    for (int i = 1; i <= N; i++) {
        int time = t[i] - t[i - 1];
        int distance = abs(x[i] - x[i - 1]) + abs(y[i] - y[i - 1]);
        if (time < distance || time % 2 != distance % 2) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 1408
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

using namespace std;

// repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

// container util
#define all(x) (x).begin(), (x).end()

// debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x)                                         \
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
       << " " << __FILE__ << endl;

// typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

// constant
const int MOD = (int)1e9 + 7;
const int INF = (int)1e18;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

// conversion
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

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

int w, h;
int sx, sy;
int gx, gy;
int ans;
int field[22][22];

void dfs(int x, int y, int count) {
  if (ans <= count + 1) return;

  for (int i = 0; i < 4; i++) {
    int nx = x + dx[i];
    int ny = y + dy[i];

    if (0 <= nx && nx < w && 0 <= ny && ny < h && field[ny][nx] != 1) {
      while (0 <= nx && nx < w && 0 <= ny && ny < h) {
        if (nx == gx && ny == gy) {
          ans = min(ans, count + 1);
          return;
        }
        //ブロックにぶつかったら
        if (field[ny][nx] == 1) {
          //障害物を無くす
          field[ny][nx] = 0;
          dfs(nx - dx[i], ny - dy[i], count + 1);
          field[ny][nx] = 1;
          break;
        }

        nx += dx[i];
        ny += dy[i];
      }
    }
  }

  return;
}

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

  while (true) {
    cin >> w >> h;
    if (w == 0 && h == 0) break;
    ans = 11;
    rep(y, h) {
      rep(x, w) {
        cin >> field[y][x];
        if (field[y][x] == 2) {
          sx = x, sy = y;
          field[y][x] == 0;
        }
        if (field[y][x] == 3) {
          gx = x, gy = y;
          field[y][x] == 0;
        }
      }
    }

    dfs(sx, sy, 0);

    if (ans <= 10)
      cout << ans << "\n";
    else
      cout << -1 << "\n";
  }

  return 0;
}


Measured memory_bytes: 3036
import java.io.*;
import java.util.*;


public class Main {

	private static Scanner sc;
	private static Printer pr;

	private static void solve() {
		long n = sc.nextLong();

		int min = Integer.MAX_VALUE;
		for (long a = 1; a * a <= n; a++) {
			if (n % a != 0) {
				continue;
			}

			long b = n / a;

			min = Math.min(min, Math.max(Long.toString(a).length(), Long.toString(b).length()));
		}

		pr.println(min);
	}

	// ---------------------------------------------------
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		pr = new Printer(System.out);

		solve();

		pr.close();
		sc.close();
	}

	private static class Printer extends PrintWriter {
		Printer(PrintStream out) {
			super(out);
		}
	}
}


Measured memory_bytes: 21972