akhauriyash/Code-Regression huggingface dataset:
// AOJ 2039: Space Coconut Crab II
// 2017.11.6 bal4u@uu

#include <stdio.h>
#define TM 0
#if TM
#include <time.h>
#endif

#define MAX  30000
char table[MAX+1] = {1,1,0,0};		// zero: if prime

int prime[3250] = {					// prime[39] = 173 = sqrt(MAX), max sz = 3245
  2, 3,  5,  7, 11, 13, 17, 19, 23, 29, 
 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 
 73, 79, 83, 89, 97,101,103,107,109,113, 
127,131,137,139,149,151,157,163,167,173 }; int sz;

void mkprime()
{
	int i, j, k;
	for (i = 0; i < 40; i++) {
		k = prime[i];
		for (j = k<<1; j < MAX; j += k) table[j] = 1;
	}
	for (sz = 39, i = 173; i <= MAX; i += 2) if (!table[i]) prime[sz++] = i;
}

int main()
{
	int t, i, j, k, m, ans;
#if TM
	clock_t start, end;
	start = clock();
#endif
	mkprime();
	while (scanf("%d", &t) && t > 0) {
		if (!(t & 1)) {
			putchar('1' - table[(t>>1)-1]), putchar('\n');
		} else {
			ans = 0, m = t/3;
			for (i = 0; i <= m; i++) for (j = i; j < sz; j++) {
				if ((k = prime[i]+prime[j]) >= t) continue;
				if ((k<<1) > t && !table[t-k] && t-k >= prime[j]) ans++;
			}
			printf("%d\n", ans);
		}
	}
#if TM
	end = clock();
	printf("time %lf\n", (double)(end-start)/CLOCKS_PER_SEC);
#endif
	return 0;
}

Measured memory_bytes: 1744
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <cstdio>

using namespace std;

void dfs(vector<vector<int>>& tree, vector<int>& cs, int i, int c){
    cs[i]+=c;
    for(auto child : tree[i]){
        dfs(tree, cs, child, cs[i]);
    }
}

int main(){
    int n, q; cin >> n >> q;
    vector<vector<int>> tree(n, vector<int>());
    for(int i=0; i<n-1; ++i){
        int a, b; cin >> a >> b;
        tree[a-1].push_back(b-1);
    }
    vector<int> cs(n);
    for(int i=0; i<q; ++i){
        int p, x; cin >> p >> x;
        cs[p-1]+=x;
    }
    dfs(tree, cs, 0, 0);
    for(int i=0; i<n; ++i){
        cout << cs[i] << (i==n-1 ? '\n' : ' ');
    }
    return 0;
}



Measured memory_bytes: 23424
using System;

namespace ABC057C
{
    class Program
    {
        static void Main(string[] args)
        {
            long N = Int64.Parse(Console.ReadLine());

            int sqrt = (int)Math.Sqrt(N);

            for (int i = sqrt; i > 0; i--)
            {
                long mod = N % i;
                if (mod == 0)
                {
                    Console.WriteLine((int)Math.Log10(N / i) + 1);
                    return;
                }
            }

        }
    }
}


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

int main(){
  string S;
  int K;
  cin >> S >> K;
  int i = 0;
  bool check = true;
  while(i < K && i < S.size()){
  	if(S[i] != '1'){
      cout << S[i];
      check = false;
      break;
    }
    i++;
  }
  if(check){
    cout << 1;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll =long long;
using ld =long double;
int main(){
    ll a,b;
    cin >> a >> b;
    if((a<=0)&&(b>=0))cout << "Zero" <<endl;
    else if(a<0&&b<0&&(b-a)%2==0)cout << "Negative" <<endl;
    else cout << "Positive" <<endl;

    return 0;
}

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

#define ld long double
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define MP make_pair
ll MOD = 1e9+7;
//ll MOD = 998244353;
ll INF = 1e18;
void chmin(ll &a, ll b) { if (a > b) a = b; }
void chmax(ll &a, ll b) { if (a < b) a = b; }
void ans1(bool x){
  if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){
  if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){
  if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
void ans(bool x, ll y, ll z){
  if(x) cout<<y<<endl;else cout<<z<<endl;}   


int main(){
  ll i,j,ii,jj;
  ll result=0,buf=0,buf1=0,buf2=0,buf3=0,buf4=0;
  bool judge = true;
  string s,t;cin>>s>>t;
  ans2(s[0]==t[2]&&s[1]==t[1]&&s[2]==t[0]);


  return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main {
    public static void main(String[] args) {
        new Solver().run();
    }
}

class Solver {

    private Set<Integer> createSet(int M) {
        Set<Integer> set = new HashSet<Integer>();
        for (int i = 1; i <= M; i++) {
            set.add(i);
        }
        return set;
    }

    public void run() {
        Scanner sc = new Scanner(System.in);
        String w = sc.next();

        int[] cnt = new int[26];

        for (char ch : w.toCharArray()) {
            cnt[ch - 'a']++;
        }

        for (int c : cnt) {
            if (c % 2 != 0) {
                System.out.println("No");
                return;
            }
        }
        System.out.println("Yes");

        return;
    }

}

Measured memory_bytes: 21844
def f_d():
    import heapq
    x, y, z, k = map(int, input().split())
    *a, = sorted(list(map(int, input().split())), reverse=True)
    *b, = sorted(list(map(int, input().split())), reverse=True)
    *c, = sorted(list(map(int, input().split())), reverse=True)

    m = set((0, 0, 0))
    q = [[-1*(a[0]+b[0]+c[0]), 0, 0, 0]]
    heapq.heapify(q)
    for _ in range(k):
        ans, ai, bi, ci = heapq.heappop(q)
        if ai+1<x and (ai+1, bi, ci) not in m:
            m.add((ai+1, bi, ci))
            heapq.heappush(q, [-1*(a[ai+1]+b[bi]+c[ci]), ai+1, bi, ci])
        if bi+1<y and (ai, bi+1, ci) not in m:
            m.add((ai, bi+1, ci))
            heapq.heappush(q, [-1*(a[ai]+b[bi+1]+c[ci]), ai, bi+1, ci])
        if ci+1<z and (ai, bi, ci+1) not in m:
            m.add((ai, bi, ci+1))
            heapq.heappush(q, [-1*(a[ai]+b[bi]+c[ci+1]), ai, bi, ci+1])
        print(-1*ans)

if __name__ == "__main__":
    f_d()


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

long long MOD = 1e9+7;
int MAX_INT = 1e9;

// 最大公約数
long long gcd(long long a, long long b){
  if(b == 0) return a;
  return gcd(b, a % b);
}
// 最小公倍数
long long lcm(long long a, long long b) {
  return a / gcd(a, b) * b;
}

int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  int n;
  cin >> n;
  vector<int> a(n), b;
  for(int i = 0; i < n; i++) {
    cin >> a[i];
  }

  for(int i = 0; i < n; i++) {
    if(i%2 == 0) {
      b.push_back(a[i]);
    }
    else {
      b.insert(b.begin(), a[i]);
    }
  }
  if(n%2!=0) {
    reverse(b.rbegin(),b.rend());
  }

  for(int i = 0; i < n; i++) {
    cout << b[i];
    if(i != n-1) {
      cout << ' ';
    }
    else {
      cout << endl;
    }
  }

  return 0;
}


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

#define dump(a) (cerr << (#a) << " = " << (a) << endl)
#define FOR(it,c) for(__typeof((c).begin())it=(c).begin(); it!=(c).end();++it)
#define RFOR(it,c) for(__typeof((c).rbegin())it=(c).rbegin(); it!=(c).rend();++it)
#define exist(c, v) (find((c).begin(), (c).end(), (v)) != (c).end())

template<class T> inline void chmax(T& a, const T& b) { if(b > a) a = b; }
template<class T> inline void chmin(T& a, const T& b) { if(b < a) a = b; }

template<typename T, typename U> ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os << '(' << p.first << ", " << p.second << ')';
	return os;
}

template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	copy(v.begin(), v.end(), ostream_iterator<T>(os, " "));
	return os;
}

long long memo[20][20];
long long combination(int n, int k) {
	if(k < 0 || k > n)
		return 0;

	if(k == 0)
		return 1;

	if(k * 2 > n)
		k = n - k;

	if(memo[n][k] > 0)
		return memo[n][k];

	return memo[n][k] = combination(n - 1, k - 1) + combination(n - 1, k);
}

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

	string s;
	cin >> s;

	int cnt[127] = {};
	for(int i = 0; i < (int)s.size(); ++i)
		++cnt[s[i]];

	bool odd = false;
	for(int i = 'a'; i <= 'z'; ++i) {
		if(cnt[i] & 1) {
			if(odd) {
				cout << 0 << endl;
				return EXIT_SUCCESS;
			}

			odd = true;
		}

		cnt[i] /= 2;
	}

	int rest = s.size() / 2;
	long long ans = 1;
	for(int i = 'a'; i <= 'z'; ++i) {
		ans *= combination(rest, cnt[i]);
		rest -= cnt[i];
	}

	cout << ans << endl;

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1188
#include <stdio.h>
#include <iostream>
#include <algorithm>
using namespace std;

int main(void) {
	int N, L;
	cin >> N >> L;
	string s[101];
	for (int i = 0; i < N; i++) {
		cin >> s[i];
	}
	sort(s, s + N);
	string ans;
	for (int i = 0; i < N; i++) {
		ans += s[i];
    }
  cout << ans <<endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  int m,n;
  scanf("%d %d",&m,&n);
  //奇数偶数双方2個以上
  if(m>1&&n>1){
  	int a = m*(m-1)/2;
  	int b = n*(n-1)/2;
  	printf("%d\n",a+b);
  }
  //奇数1個以下偶数2個以上
  else if(m<=1&&n>1)
    printf("%d\n",n*(n-1)/2);
  //奇数2個以上偶数1個以下
  else if(m>1&&n<=1)
    printf("%d\n",m*(m-1)/2);
  //奇数偶数双方1個
  else if(m&&n)
    printf("%d\n",0);
  else
    printf("%d",0);
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N; cin >> N;
    vector<int> S(N), T(N);
    for(int i = 0; i < N; ++i) {
        int x,l;
        cin >> x >> l;
        S[i] = x - l;
        T[i] = x + l;
    }

    vector<pair<int,int>> itv(N);
    for(int i = 0; i < N; ++i) {
        itv[i].first = T[i];
        itv[i].second = S[i];
    }
    sort(itv.begin(), itv.end());
    int ans = 0, t = -1e9+10;
    for(int i = 0; i < N; ++i){
        if(itv[i].second >= t) {
            ans++;
            t = itv[i].first;
        }
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 4776
#include "bits/stdc++.h"
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define FOR(i,init,a) for(int i=init; i<a; i++)
#define rep(i,a) FOR(i,0,a)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N, nums[109];
    cin>>N;
    
    rep(i,N) cin>>nums[i];
    int pre=-1, cnt=0;
    rep(i,N){
        if(nums[i]==pre){
            cnt++;
            pre=-1;
        }else pre=nums[i];
    }
    cout1(cnt);
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }
#define INF 1LL<<60

int G, D;

int dfs(int from, int res_cost, vector<bool> visited, vector<int>& p, vector<int>& c) {
    visited[from] = true;
    int total_score_from = p[from] * (from+1) + c[from];
    if(res_cost - total_score_from <= 0 ) {
        int tmp = 0, n = 0;
        while(tmp < res_cost) {
            tmp += from + 1;
            n++;
            if(n==p[from]) break;
        }
        return n;
    }

    int n_min = 100000;
    for(int i=0; i<D; i++) {
        if(!visited[i]) {
            int n = dfs(i, res_cost - total_score_from, visited, p, c);
            if(n_min > n) n_min = n;
        }
    }
    return p[from] + n_min;
}

int main() {
    cin >> D >> G;
    vector<bool> visited(D, false);
    vector<int> p(D), c(D);
    REP(i, D) {
        cin >> p[i] >> c[i];
        c[i] /= 100;
    }
    G /= 100;
    int ans = 1000, ans_from = 0;

    REP(i, D) {
        int n = dfs(i, G, visited, p, c);
        if(ans > n) {
            ans = n;
            ans_from = i;
        }
    }
    cerr << "from: " << ans_from << endl;
    cout << ans << endl;

    return 0;
}

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

namespace ConsoleApplication2
{
    class Program
    {

        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');

            int l = int.Parse(input[0]);
            int r = int.Parse(input[1]);
            long min = 2019;

            // 差が2019以上の場合、必ず間に2019の倍数があるため、あまりはゼロになる
            if (2019 < r - l)
            {
                min = 0;
            }
            else
            {
                for (long i = l; i < r; i++)
                {
                    for (long j = i + 1; j < r + 1; j++)
                    {
                        long amari = (i * j) % 2019;
                        if (min > amari)
                        {
                            min = amari;
                        }
                        if (min == 0) break;
                    }
                }

            }

            Console.WriteLine(min);
        }
    }
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
#define rep(i,a,n) for(int i=int (a);i<int (n);i++)
#define FAST ios::sync_with_stdio(0);cin.tie(0);
#define OUT  freopen("output.txt", "w", stdout)
#define IN  freopen("input.txt", "r", stdin)
#define mem(a,b) memset((a),(b),sizeof(a))
#define NumofDigits(n) ((int)log10(n)+1)
#define NumofBits(n) ((int)log2(n)+1)
#define PI 3.14159265358979323846264
#define vii vector<pair<int,int>>
#define all(x) x.begin(),x.end()
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vi  vector<ll>
#define nl  cout<<"\n"
#define pb  push_back
#define mp  make_pair
#define ll  long long 
#define ss  second 
#define ff  first
#define endl "\n"
#define sp  " "
using namespace std;
ll mod=1000000007;
int main(){
FAST;

int t=1;// cin>>t; 
while(t--){
  ll n,k,m;
	cin>>n>>k>>m;
	ll a=n/k;
	if(n%k!=0)a++;
	cout<<a*m;
	
}

}


Measured memory_bytes: 3628
n,k=map(int,input().split())
d=list(map(int,input().split()))
d=d*2
ans=0
for i in range(1,min(k+1,n+1)):
  
  for j in range(i+1):
    have=[d[n+c-j] for c in range(i)] #ここにi個の宝石を入れる
    have.sort()
    if i!=k:
      for h in range(k-i):
        if have==[] or have[0]>=0:
          break
        del have[0]
      #いらない宝石を可能な限り詰めた状態
    if sum(have)>ans:
      ans=sum(have)
print(ans)


Measured memory_bytes: 3064
package main

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

type vector struct {
	x, y int
}

func (v *vector) end(startx, starty int) (int, int) {
	return v.x + startx, v.y + starty
}

func (v *vector) rotate() {
	v.x, v.y = -v.y, v.x
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	var x1, x2, x3, x4 int
	var y1, y2, y3, y4 int
	scanner.Scan()
	fmt.Sscanf(scanner.Text(), "%d %d %d %d", &x1, &y1, &x2, &y2)

	v := vector{x2 - x1, y2 - y1} // vec12

	v.rotate() // vec23
	x3, y3 = v.end(x2, y2)
	v.rotate() // vec34
	x4, y4 = v.end(x3, y3)

	fmt.Println(x3, y3, x4, y4)
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
struct edge {
    int to;     // 辺の行き先
    int weight; // 辺の重み
    edge(int t, int w) : to(t), weight(w) { }
};
using Graph = vector<vector<int>>;
using dou =long double;
string Yes="Yes";
string YES="YES";
string NO="NO";
string No="No";
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(int i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(int i = m; i < (int)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define res resize
#define as assign
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum(a) accumulate(all(a),0)
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
 
typedef long long ll;
const int INF = 2000000000;
const ll INF64 = 922337203685477580ll;
const int mod = 1000000007ll;
const ll  MOD = 1000000007LL;
const double pi=3.1415926535897932384626;
int main(){
    int n;
    std::cin >> n;
    std::vector<dou> x(n),y(n);
    rep(i,n)std::cin >> x[i]>>y[i];
    std::vector<int> a(n);
    dou ans=0;
    rep(i,n){
        a[i]=i;
    }
    do {
        rep(i,n-1){
            ans+=sqrt(pow(x[a[i+1]]-x[a[i]],2)+pow(y[a[i+1]]-y[a[i]],2));
        }
    }while(next_permutation(all(a)));
    rep(i,n){
        ans/=(i+1);
    }
    std::cout <<keta(10)<< ans << std::endl;
}

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

int main(){
    int n,a;
    cin >> n;
    map<int,int> m;
    while(n--){
		cin >> a;
		m[a+1]++;
		m[a]++;
		m[a-1]++;
	}
	int maxi=0;
	for(auto x:m){
		maxi=max(maxi,x.second);
	}
	cout << maxi;
}


Measured memory_bytes: 4736
import sys

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


x1,y1,x2,y2 = MI()
dx,dy = y1-y2,x2-x1
print(x2+dx,y2+dy,x1+dx,y1+dy)


Measured memory_bytes: 61816
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pll = pair<ll, ll>;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define Rep(i, m, n) for(ll i = m; i < n; i++)
#define all(vec) vec.begin(), vec.end()
#define tmax(x, y, z) max((x), max((y), (z)))
#define tmin(x, y, z) min((x), min((y), (z)))
#define MINUS(a) memset(a, 0xff, sizeof(a))
#define ZERO(a) memset(a, 0, sizeof(a))
const ll INF = 1LL << 60;
const ll MM = 1000000000; const ll MOD = MM + 7; const ll MMM=9223372036854775807;//2^63 -1
#define ADD(a,b) a = (a + ll(b)) % MOD
#define MUL(a,b) a = (a * ll(b)) % MOD
ll GCD(ll x, ll y){ if(y == 0) return x; else return GCD(y, x % y);}
ll LCM(ll x, ll y){ return x / GCD(x, y) * y;}
template<class T> inline bool chmin(T& a, T b){ if(a > b){ a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b){ if(a < b){ a = b; return true;} return false;}
template<typename A, size_t N, typename T> void FILL(A (&array)[N], const T &val){ fill( (T*)array, (T*)(array+N), val );}
using Graph = vector<vector<ll>>;
ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
ll ddx[8] = {1, 1, 0, -1, -1, -1, 0, 1}, ddy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//cout << fixed << setprecision(10);


int main(){
    ll n, k; cin >> n >> k;
    cout << (n-1 + k-2)/(k-1) << endl;
}


Measured memory_bytes: 3636
#include <iostream>
#include <sstream>
#include <algorithm>
#include <functional>
#include <iterator>
#include <numeric>
#include <cstdint>
#include <cmath>
#include <bitset>
#include <string>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>

#define N_TIMES(i, n)     for ( uint64_t i = 0;     i <  n; ++i )
#define N_TIMES_REV(i, n) for (  int64_t i = n - 1; i >= 0; --i )
#define SQRTI(n) static_cast<uint64_t>(::floor(::sqrt(static_cast<double>(n))))

const uint64_t MOD = 1e+9 + 7;

#ifdef __DEBUG__
template<typename T, typename U>
std::ostream& operator<<(std::ostream &os, const std::pair<T, U> &pair)
{
  os << pair.first << ": " << pair.second;
  return os;
}

template<class ForwardIterator>
std::ostream& _iterator_to_display(
  std::ostream &os, 
  ForwardIterator begin, ForwardIterator end, 
  const std::string &delim = ", "
)
{
  auto itr = begin;
  while (itr != end) {
    os << *itr;
    ++itr;
    if (itr != end) os << delim;
  }
  return os;
}

template<typename T>
std::ostream& operator<<(std::ostream &os, const std::list<T> &list)
{
  _iterator_to_display(os, list.begin(), list.end());
  return os;
}

template<typename T>
std::ostream& operator<<(std::ostream &os, const std::vector<T> &vector)
{
  _iterator_to_display(os, vector.begin(), vector.end());
  return os;
}

template<typename T, class C=std::less<T>>
std::ostream& operator<<(std::ostream &os, const std::set<T> &set)
{
  _iterator_to_display(os, set.begin(), set.end());
  return os;
}

template<typename T, typename U, class C=std::less<T>>
std::ostream& operator<<(std::ostream &os, const std::map<T, U> &map)
{
  _iterator_to_display(os, map.begin(), map.end());
  return os;
}
#endif /* __DEBUG__ */

int main(int argc, char **argv)
{
  std::string S;
  std::cin >> S;
  
  std::vector<std::vector<uint64_t>> dp(S.size() + 1);
  N_TIMES(i, S.size() + 1) {
    dp[i] = std::vector<uint64_t>(4, -1);
  }
  
  dp[S.size()][3] = 1;
  N_TIMES_REV(j, 3) {
    dp[S.size()][j] = 0;
  }
  
  N_TIMES_REV(i, S.size()) {
    uint64_t m1 = (S[i] == '?') ? 3 : 1;
    dp[i][3] = (m1 * dp[i + 1][3]) % MOD;
    
    N_TIMES_REV(j, 3) {
      const std::string T = "ABC";
      uint64_t m2 = (S[i] == '?' || S[i] == T[j]) ? 1 : 0;
      
      uint64_t s1 = (m1 * dp[i + 1][j]) % MOD;
      uint64_t s2 = (m2 * dp[i + 1][j + 1]) % MOD;
      
      dp[i][j] = (s1 + s2) % MOD;
    }
  }
  
  std::cout << dp[0][0] << std::endl;
  
  return 0;
}

Measured memory_bytes: 7424
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)


function main()
N, D = parseMap(split(readline()))

count = 0
for _ in 1:N
    x, y = parseMap(split(readline()))
    d = x^2 + y^2
    if d <= D^2
        count += 1
    end
end


println(count)
end

main()

Measured memory_bytes: 202868
# Distance II

dimension = int(input())
vectors = [[float(i) for i in input().rstrip().split()] for j in range(2)]
x = vectors[0]
y = vectors[1]

absoluteValues = [abs(x[k] - y[k]) for k in range(dimension)]
# print(absoluteValues)

# xとyのミンコフスキー距離を求める関数(a: 有限)
def mink(a):
    totalValue = 0
    for i in range(dimension):
        totalValue += absoluteValues[i] ** a
    distance = totalValue ** (1 / a)
    return distance

# xとyのChebyshev距離を求める関数
def chev():
    maxValue = 0
    for i in range(dimension):
        # print(absoluteValues[i])
        if absoluteValues[i] > maxValue:
            maxValue = absoluteValues[i]
    print(maxValue)


for i in range(1, 3 + 1):
    dist = mink(i)
    print(dist)
chev()



Measured memory_bytes: 5668
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <utility>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <limits.h>
#define int long long
using namespace std;
using P = pair<int, int>;
using ll = long long;
using prique = priority_queue<int>;
const int INF = LLONG_MAX/3;
const int MOD = 1000000007;
signed main(){
    int n,k;
    cin>>n>>k;
    int a[2000];
    for(int i=0;i<n;i++)cin>>a[i];
    int s=k*(k+1)/2%MOD;
    int ans=0;
    for(int i=0;i<n;i++){
        int cnta=0;
        int cntal=0;
        for(int j=0;j<n;j++){
            if(i==j)continue;
            else if(j<i){
                if(a[j]<a[i]){
                    cnta++;
                    cntal++;
                }
            }else{
            if(a[j]<a[i]){
                    cntal++;
                }
            }
        }
        ans+=cntal*s%MOD-cnta*k;
        if(ans<0)ans+=MOD;
        ans%=MOD;
    }
    if(ans<0)ans+=MOD;
    cout<<ans<<endl;
    return 0;
}



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

using namespace std;

typedef long long ll;

const int maxn=1e5+5,mod=998244353;

ll f(int a,int b)
{
    ll base=a,sum=1;
    while(b)
    {
        if(b%2)
            sum=sum*base%mod;
        base=base*base%mod;
        b/=2;
    }
    return sum%mod;
}

int main()
{
    int n;
    while(cin>>n)
    {
        int a[maxn]= {0},dep=0,flag=1;
        for(int i=1; i<=n; i++)
        {
            int m;
            scanf("%d",&m);
            if(i==1&&m)
                flag=0;
            a[m+1]++;
            dep=max(dep,m+1);
        }
        if(!a[1]||a[1]>1||!flag)
            printf("0\n");
        else if(n<3)
            printf("1\n");
        else
        {
            ll num=1;
            for(int i=3; i<=dep; i++)
                num=num*f(a[i-1],a[i])%mod;
            printf("%lld\n",num%mod);
        }
    }
    return 0;
}


Measured memory_bytes: 768
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CSumOfProductOfPairs solver = new CSumOfProductOfPairs();
        solver.solve(1, in, out);
        out.close();
    }

    static class CSumOfProductOfPairs {
        static final int mod = 1000000007;

        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int N = Integer.parseInt(in.next());
            int[] A = new int[N];
            for (int i = 0; i < N; i++) {
                A[i] = Integer.parseInt(in.next());
            }


            // 累積和
            long s[] = new long[N + 1];
            for (int i = 0; i < N; ++i) {
                s[i + 1] = s[i] + A[i];
                s[i + 1] %= mod;
            }

            long ans = 0;

            for (int i = 0; i < N; i++) {
                s[N] -= A[i];
                if (s[N] < 0) s[N] += mod;
                ans += A[i] * s[N];
                ans %= mod;
            }

            // 出力
            out.println(ans);

        }

    }
}



Measured memory_bytes: 61388
#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i, n) for(int i=(n); i>=0; --i)
#define FOR(i, n, m) for(int i=(m), i##_len=(n); i<i##_len; ++i)
#define EACH(i, v) for(const auto& i : v)
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
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 Value>using vec = vector< Value >;
using ll = long long;
using P = pair< long long, long long >;
#define fi first
#define se second
#define el endl
#pragma endregion

void Main();

int main(){
    std::cin.tie(nullptr);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}

void Main(){
    ll N;
    cin >> N;
    cout << N*(N-1)/2 << el;
}



Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
using namespace std;
#define MAX_N 105
struct data{int to,ay,ax,by,bx;};

int n,h,w;
string str[MAX_N];
vector<data> t[MAX_N];
vector<string> u[MAX_N];
map<string,int> mp;

void init(){
  for(int i=0;i<MAX_N;i++){
    t[i].clear();
    u[i].clear();
  }
  mp.clear();
}

int main(){
  while(1){
    cin>>n;
    if(n==0)break;
    init();
    cin>>h>>w;
    for(int i=0;i<n;i++){
      int size;
      cin>>str[i]>>size;
      mp[str[i]]=i;
      t[i].resize(size);
      u[i].resize(size);
      for(int j=0;j<size;j++)cin>>t[i][j].ay>>t[i][j].ax>>t[i][j].by>>t[i][j].bx>>u[i][j];
    }
    for(int i=0;i<n;i++)
      for(int j=0;j<(int)t[i].size();j++)
	t[i][j].to=mp[u[i][j]];
    vector<int> l,r;
    string s;
    int q,pos=0;
    cin>>q;
    while(q--){
      cin>>s;
      if(s=="show"){
	cout<<str[pos]<<endl;
      }else if(s=="back"){
	if(l.size()){
	  int x=l[l.size()-1];
	  l.pop_back();
	  r.push_back(pos);
	  pos=x;
	}
      }else if(s=="forward"){
	if(r.size()){
	  int x=r[r.size()-1];
	  r.pop_back();
	  l.push_back(pos);
	  pos=x;
	}
      }else{
	int y,x;
	cin>>y>>x;
	int I;
	for(I=0;I<(int)t[pos].size();I++){
	  data d=t[pos][I];
	  if(d.ay<=y&&y<=d.by&&d.ax<=x&&x<=d.bx){
	    l.push_back(pos);
	    r.clear();
	    pos=d.to;
	    break;
	  }
	}
      }
    }
  }
  return 0;
}

Measured memory_bytes: 1272
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    int [] n = new int [10000];
    int m = 0;
    Scanner sc = new Scanner(System.in);
    for(int i=0;;i++){
      int x = sc.nextInt();
      if(x == 0) break;
      m++;
      n[i]=x;
    }
    for(int j=0;j<m;j++){
      System.out.println("Case " + (j + 1) + ": " +n[j]);
    }
  }
}


Measured memory_bytes: 42900
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		String S = scanner.nextLine();

		int num0 = 0;
		for(char x : S.toCharArray()) {
			if(x == '0')
				num0++;
		}

		int num1 = 0;
		for(char x : S.toCharArray()) {
			if(x == '1')
				num1++;
		}

		System.out.println(Math.min(num0, num1)*2);

	}

}


Measured memory_bytes: 26928
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>

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

using namespace std;

typedef pair<int, int> P;

int dp[500];
int main(){
	int n, m;
	while(cin >> n >> m){
		vector<int> c(n);
		vector<vector<int> > v(3, vector<int>(n));
		rep(i, n){
			cin.ignore();
			string s;
			getline(cin, s);
			cin >> c[i] >> v[0][i] >> v[1][i] >> v[2][i];
		}
		int ans = 0;
		rep(j, 3){
			memset(dp, -1, sizeof(dp));
			dp[0] = 0;
			for(int k = 0; k < n; k++){
				for(int i = c[k]; i <= m; i++){
					if(dp[i-c[k]] != -1) dp[i] = max(dp[i], dp[i-c[k]]+v[j][k]);
				}
			}
			ans = max(ans, *max_element(dp, dp+500));
		}
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 1236
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())

using namespace std;
typedef long long ll;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const int INF = 1001001001;
const long long INFL = (1LL<<60);
const double eps = (1e-9);

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

  string s;
  cin >> s;
  if (s.find('7') == string::npos) {
    puts("No");
  } else {
    puts("Yes");
  }

  return 0;
}


Measured memory_bytes: 3648
l=list(map(int,input().strip().split(' ')))
a=l[0]
b=l[1]
c=l[2]
d=l[3]
l1=[x for x in range(a,b+1)]
l2=[x for x in range(c,d+1)]
l3=[]
ans=0
for i in l2:
    if i in l1:
        ans+=1
print(max(0,ans-1))

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

#define REP(i,n) for(ll i=0; i<(ll)(n); i++)
#define FOR(i,n,m) for (ll i=n; i<(ll)(m); i++)
#define pb push_back
#define INF 1000000007LL
#define all(a) (a).begin(),(a).end()
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)

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

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

ll str_to_ll(string &s) {
    ll ret;
    stringstream ss;
    ss << s;
    ss >> ret;
    return ret;
}

string str_to_ll(ll &n) {
    string ret;
    stringstream ss;
    ss << n;
    ss >> ret;
    return ret;
}

ll N;
ll dfs(string s) {
    ll ret = 0;
    if (N < str_to_ll(s)) {
        
        return ret;
    }
    if (s.find('3') != std::string::npos && s.find('5') != std::string::npos && s.find('7') != std::string::npos) {
        ret++;
    }
    return ret + dfs(s + "3") + dfs(s + "5") + dfs(s + "7");
}

int main(){
    ios::sync_with_stdio(false);
    cin >> N;
    cout << dfs("3") + dfs("5") + dfs("7") << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <unordered_set>
#include <cstring>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <bitset>
using namespace std;
typedef long long ll;
const int maxn = 100005;

int n;
vector<int>e[maxn];

int dfs(int x,int fa){
  int ret=0;
  for(int i=0;i<e[x].size();i++){
    int v=e[x][i];
    if(v==fa)continue;
    ret^=(1+dfs(v,x));
  }
  return ret;
}

int main() {
#ifdef suiyuan2009
  freopen("in.cpp","r",stdin);
#endif
  cin>>n;
  for(int i=1;i<n;i++){
    int x,y;
    cin>>x>>y;
    e[x].push_back(y);
    e[y].push_back(x);
  }
  if(dfs(1,0))cout<<"Alice"<<endl;
  else cout<<"Bob"<<endl;
  return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<pair<int, pair<int, int>>> a(n);
  for (auto &e : a) {
    int x, y;
    cin >> x >> y;
    e = {x + y, {x, y}};
  }
  sort(rbegin(a), rend(a));
  ll r = 0;
  for (int i = 0; i < n; i++) {
    r += i % 2 ? -a[i].second.second : a[i].second.first;
  }
  cout << r << endl;
}


Measured memory_bytes: 1408
#include <iostream>
#define ull unsigned long long
using namespace std;
ull gcd(ull x, ull y)
{
	ull r;
	do
	{
		r = x % y;
		x = y;
		y = r;
	} while (r != 0);
	return x;
}
ull hcd(ull x, int y, ull z)
{
	return (x * y / z);
}
int main()
{
	ull a, b, c, d, i, c1 = 0, g, h;
	cin >> a >> b >> c >> d;
	c1 += b / c - a / c;
	if (a % c == 0) c1++;
	c1 += b / d - a / d;
	if (a % d == 0) c1++;
	g = gcd(c, d); 
	h = hcd(c, d, g);
	ull l, r;
	l = a / h;
	r = b / h;
	c1 -= r - l;
	if (a % h == 0) c1--;
	cout << b - a - c1 + 1 << endl;
}

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

int main(){
  char c[55][55];
  int h, w, i, j, count;
  for(i = 0; i < 55; i++){
    for(j = 0; j < 55; j++){
      c[i][j] = '.';
    }
  }
  cin >> h >> w;
  
  for (i = 1; i <= h; i++ ){
    for (j = 1; j <= w; j++ ){
      cin >> c[i][j];
    }
  }
  
  for (i = 1; i <= h; i++){
    for (j = 1; j <= w; j++){
      if(c[i][j] == '#'){
        cout << '#';
      }else{
        count = 0;
        for(int k = -1; k <= 1; k++){
          for(int l = -1; l <= 1; l++){
            if(c[i + k][j + l] == '#'){
              count++;
            }
          }
        }
        cout << count;
      }
    }
    cout << endl;
  }
}

Measured memory_bytes: 256
program main
      
      implicit none
     
      integer :: n
      integer(8), allocatable :: b(:),c(:)
      integer(4), allocatable :: a(:)
     
      integer :: i,j
      integer(8) :: sumb
     
      read(*,*) n
      allocate( a(n) )
      allocate( b(n) )
      allocate( c(n) )
      read(*,*) a
     
      b = 0  
      c = 0  
      do i = 1, n
        c(a(i)) =  c(a(i)) + 1
      end do
      sumb = 0
      do i = 1, n
        b(i) =  c(i)*(c(i)-1)/2
        sumb = sumb + b(i)
      end do
     
      do i = 1, n
        print*, sumb - b(a(i)) + (c(a(i))-2)*(c(a(i))-1)/2
      end do
      
      
    end program main


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

using namespace std;

int main() {

	string str;
	cin >> str;

	int n;
	cin >> n;

	string it;
	int a, b;
	string rp;
	char str2[1000] = {};
	for (int i = 0; i < n; i++) {
		cin >> it >> a >> b;
		if (it == "print") {
			for (int j = a; j <= b; j++) {
				cout << str[j];
			}
			cout << endl;
		}
		else if (it == "reverse") {
			//str2 = ' ';
			for (int j = a; j <= b; j++) {
				str2[j] = str[b - (j - a)];
			}
			for (int j = a; j <= b; j++) {
				str[j] = str2[j];
			}
		}
		else if (it == "replace") {
			cin >> rp;
			for (int j = a; j <= b; j++) {
				str[j] = rp[j - a];
			}

		}
	}
}


Measured memory_bytes: 3208
<?php
fscanf(STDIN, "%d", $N);
for ($i = 0; $i < $N; $i++) {
    fscanf(STDIN, "%d %d", $A[], $B[]);
}
array_multisort($B, $A);
$sum = 0;
$ret = "Yes";
foreach ($A as $key => $val) {
    $sum += $val;
    if ($sum > $B[$key]) {
        $ret = "No";
        break;
    }
    // printf("%d %d\n", $A[$key], $B[$key]);
}
echo $ret;


Measured memory_bytes: 49644
#include <bits/stdc++.h>
using namespace std;
typedef int64_t ll;
int nm[1000001];

int main(){
  int n,cnt=0;
  cin>>n;
  int a[n];
  set<int> s;
  for(int i=0;i<n;i++){
    cin>>a[i];
    s.insert(a[i]);
    nm[a[i]]++;
  }
  vector<bool> era(1e6+1,true);
  int b,c;
  for(auto i:s){
    b=i;c=2*b;
    while(c<=1e6){
      era[c]=false;
      c+=b;
    }
  }
  for(int i=0;i<n;i++){
    if(era[a[i]] && nm[a[i]]==1)cnt++;
  }
  cout<<cnt<<endl;
}


Measured memory_bytes: 16808
#include<bits/stdc++.h>
using namespace std;
constexpr int64_t mod=1e9+7;

int main()
{
  int h,w,n;
  cin>>h>>w>>n;
  int div=(h>w?h:w);
  cout<<(n%div==0?n/div:n/div+1);
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <stack>


typedef long long ll;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define _GLIBCXX_DEBAC
/*map<Keyの型, Valueの型> 変数名;
queue<型> 変数名;
priority_queue<型> 変数名;
priority_queue<型, vector<型>, greater<型>> 変数名;*/
//copy(v1.begin(), v1.end(), back_inserter(v2));
using namespace std;

ll gcd(ll a, ll b) {
	ll c;
	if (a < b) {
		c = a; a = b; b = c;
	}
	while (b != 0) {
		c = a % b; a = b; b = c;
	}
	return a;
}

ll lcm(ll a, ll b) {
	ll c;
	c = a * b / gcd(a, b);
	return c;
}

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

int bubblesort(int a[], int n) {
	int sw = 0;
	bool flag = 1;
	for (int i = 0; flag; i++) {
		flag = 0;
		for (int j = n - 1; j >= i + 1; j--) {
			if (a[j] < a[j - 1]) {
				swap(a[j], a[j - 1]);
				flag = 1;
				sw += 1;
			}
		}
	}
	return sw;
}

int a_z()
{
	for (int i = 0; i <= ('Z' - 'A'); i++) {
		cout << (char)('A' + i);
	}
	return 0;
}

int selecttionsort(int a[], int n) {
	int t,sw = 0, minj;
	for (int i = 0; i < n - 1; i++) {
		minj = i;
		for (int j = 0; j < n - 1; j++) {
			if (a[j] < a[minj]) {
				minj = j;
			}
		}
		t = a[i]; a[i] = a[minj]; a[minj] = t;
		if (i != minj) sw += 1;

	}
	return sw;
}

bool is_prime(int x) {
	if (x <= 1) return false;
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0) return false;
	}
	return true;
}

const int mod = 1000000007;
struct mint {
	ll x;
	mint(ll x = 0):x(x%mod){}
	mint& operator+=(const mint a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a) {
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint a) const {
		mint res(*this);
		res -= a;
	}
	mint operator*(const mint a)const {
		mint res(*this);
		return res *= a;
	}
};

map<string, int> memo;

using P=pair<int, int>;

struct Clock {
	int hour, minute, second;
	void set(int h, int m, int s) {
		hour = h; minute = m; second = s;
	}
	string to_str() {
		string h, m, s;
		h = to_string(hour);
		m= to_string(minute);
		s= to_string(second);
		if (h.size() < 2) h = "0" + h;
		if (m.size() < 2) m = "0" + m;
		if (s.size() < 2) s = "0" + s;
		return h + ":" + m + ":" + s;
	}
	void shift(int diff_second) {
		int h, m;
		h = diff_second / 3600;
		m = diff_second / 60;
		diff_second %= 60;
		second += diff_second;
		
	}
};


/*void dfs(int v, int p = -1) {
	for (int u : to[v]) {
		if (u == p) continue;
		ans[u] += ans[v];
		dfs(u, v);
	}
}*/
int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i, n) cin >> a[i];
	int s = 0,b=0,c;
	rep(i, n) s += a[i];
	c = s;
	rep(i, n) {
		b += a[i];
		c = min(c, abs(b - (s - b)));
	}
	cout << c;
	return 0;
}










Measured memory_bytes: 256
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef list<int> liint;
typedef pair<int, int> pint;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }



int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll H , W;
    cin >> H >> W;
    
    ll ans;
    if (H == 1 || W == 1)
        ans = 1;
    else
        ans = (H * W) / 2 + (H * W) % 2;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.*;
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        String a = in.next();
        char p = a.charAt(a.length()-1);
        int s =0;
        for(int i = a.length()-2;i>=0;i--){
            if (a.charAt(i)!=p)
                s++;
            p = a.charAt(i);
        }
    System.out.println(s);

    }
}

Measured memory_bytes: 24148
n=int(input())
c,i=0,1
while i <= n:
    if c==0:
        x=i
        if x%3==0:
            print(' '+str(i), end='')
            i+=1
            continue
    c=0
    if x%10==3:
        print(' '+str(i), end='')
        i+=1
        continue
    x//=10
    if x == 0:
        i+=1
        continue
    else:
        c=1
print()

Measured memory_bytes: 8020
// AOJ 2845: Star in Parentheses
// 2017.11.23 bal4u@uu

#include <stdio.h>

char buf[102];

int main()
{
	int ans;
	char *p;

	scanf("%s", p=buf);
	ans = 0;
	while (*p != '*') {
		if (*p == '(') ans++;
		else if (*p == ')') ans--;
		p++;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 1812
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define MT make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define RT return
#define vv(a,b,c,d) vector<vector<a> >(b,vector<a>(c,d))
#define vvv(a,b,c,d,e) vector<vector<vector<a> > >(b,vv(a,c,d,e))
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;

int R, C, N;
vi G[200005];
int U[100005], V[100005], A[100005];
int vis[200005];
ll MI = LLONG_MIN / 3;
ll MA = LLONG_MAX / 3;
ll X[200005], rmi, cmi;

void dfs(int u) {
    if (vis[u]++)RT;
    if (u < R)smin(rmi, X[u]);
    else smin(cmi, X[u]);
    each(e, G[u]) {
        int v = U[e] ^ V[e] ^ u;
        int a = A[e];
        if (!vis[v]) {
            X[v] = a - X[u];
            dfs(v);
        } else {
            if (a != X[u] + X[v]) {
                rmi = cmi = MI;
            }
        }
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);
    
    cin >> R >> C >> N;
    
    rep(i, N) {
        cin >> U[i] >> V[i] >> A[i];
        --U[i];
        V[i] = (V[i] - 1) + R;
        G[U[i]].push_back(i);
        G[V[i]].push_back(i);
    }

    rep(i, R) if(!vis[i]){
        rmi = 0;
        cmi = MA;
        dfs(i);
        if (rmi + cmi < 0) {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
}

Measured memory_bytes: 16256