akhauriyash/Code-Regression huggingface dataset:
N = gets.to_i
x,y = N.times.map { gets.split.map(&:to_i) }.transpose

routes = (1..N).to_a.permutation(N).to_a

sum = 0
routes.each do |r|
  (N-1).times do |i|
    d = Math.sqrt(((x[r[i]-1]-x[r[i+1]-1]) ** 2) + ((y[r[i]-1]-y[r[i+1]-1]) ** 2))
    sum += d
  end
end
p sum/routes.size

Measured memory_bytes: 8828
N, A, B, C = map(int, input().split(" "))
l = [int(input()) for i in range(N)]
INF = 10 ** 9
def dfs(cnt, a, b, c):
    if cnt == N:
        return abs(a-A)+abs(b-B)+abs(c-C)-30 if min(a,b,c)>0 else INF
    ret1=dfs(cnt+1,a+l[cnt],b,c)+10
    ret2=dfs(cnt+1,a,b+l[cnt],c)+10
    ret3=dfs(cnt+1,a,b,c+l[cnt])+10
    ret4=dfs(cnt+1,a,b,c)
    return min(ret1,ret2,ret3,ret4)

print(dfs(0,0,0,0))

Measured memory_bytes: 3064
/*input
1 1000000000
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#pragma GCC optimize("unroll-loops,no-stack-protector")
//order_of_key #of elements less than x
// find_by_order kth element
using ll = unsigned long long;
using ld = long double;
using pii = pair<ll,ll>;
#define f first
#define s second
#define pb push_back
#define REP(i,n) for(int i=0;i<n;i++)
#define FILL(n,x) memset(n,x,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
#define sz(x) (int)x.size()
#define REP1(i,n) for(int i=1;i<=n;i++)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
const ll INF64=1e18;
const int INF=1e6+1;
const ll MOD=1e9+7;
const ld PI=acos(-1);
const ld eps=1e-9;
#define lowb(x) x&(-x)
#define MNTO(x,y) x=min(x,(__typeof__(x))y)
#define MXTO(x,y) x=max(x,(__typeof__(x))y)
ll mult(ll a,ll b){
    return ((a%MOD)*(b%MOD))%MOD;
}
ll mypow(ll a,ll b){
    if(b<=0) return 1;
    ll res=1LL;
    while(b){
        if(b&1) res=mult(res,a);
        a=mult(a,a);
        b>>=1;
    }
    return res;
}
const ll maxn=2e5+5;
const ll maxlg=__lg(maxn)+2;
int main(){
    ios::sync_with_stdio(false),cin.tie(0);
    ll a,b;
    cin>>a>>b;
    if(a==1 or b==1){
        cout<<1;
        return 0;
    }
    cout<<(a*b+1)/2;
}


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

void solve(long long N){
    if(N==1){
        cout << 0 << endl;
        return;
    }
    vector<ll> sum;
    ll t = 1;
    sum.push_back(t);
    for(int i=0;i<100;i++){
        t++;
        sum.push_back(sum.back()+t);
        // cerr <<"sum=" << sum.back() << endl;
    }
    //素因数分解
    t = 2;
    vector<ll> sieve;
    while(N != 1){
        if(t >(1e7)){
            sieve.push_back(1);
            break;
        }
        ll num =0;
        while(N%t==0){
            num++;
            N /= t;
        }
        // cerr<<"Num=" << num <<endl;
        if(num>0){
            sieve.push_back(num);
        }
        t++;
    }
    ll ans =0;
  
    for(ll s:sieve){
        auto itr = upper_bound(sum.begin(),sum.end(),s);
        ll p = itr -sum.begin();
        // cerr <<"p=" << p << endl;
        ans += p;
    }
    
    cout << ans << endl;

}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    solve(N);
    return 0;
}


Measured memory_bytes: 3700
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9 + 7);

int main(void) {
	int n;
	cin >> n;
	
	int ans = 0;
	for(int i = 0; i < n; ++i) {
		int a;
		cin >> a;
		
		if( (i + 1) % 2 == 1 && a % 2 == 1 ) ans++;
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 3608
#include <stdio.h>
#include <string.h>
int main(void){
 int i,j;
 char c;
 char s[101];
 char t[101];
 scanf("%s",s);
 scanf("%s",t);
 for(i=1;i<strlen(s);i++){
  for(j=i;j>0;j--){
   if(s[j-1]>s[j]){
    c=s[j-1];
    s[j-1]=s[j];
    s[j]=c;
   }
  }
 }
 for(i=1;i<strlen(t);i++){
  for(j=i;j>0;j--){
   if(t[j-1]<t[j]){
    c=t[j-1];
    t[j-1]=t[j];
    t[j]=c;
   }
  }
 }
 printf(strcmp(s,t)<0?"Yes":"No");
 return 0;
}

Measured memory_bytes: 128
from collections import defaultdict

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

dic = defaultdict(lambda:(N,0))
for i,a in enumerate(src):
    m,n = dic[a]
    dic[a] = (min(m,i), n+1)
order = sorted(list(dic.items()))

hist = [0] * N
while True:
    a1, (m1, n1) = order.pop()
    if not order:
        hist[m1] += n1 * a1
        break
    a2, (m2, n2) = order[-1]
    hist[m1] += n1 * (a1-a2)
    order[-1] = (a2, (min(m1,m2), n1+n2))

print(*hist, sep='\n')


Measured memory_bytes: 35592
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // uint64_t

#define BUF_SIZE 30

// size: specify sizeof(str)
int get_str(char *str, int size) {
    if(!fgets(str, size, stdin)) return -1;
    return 0;
}

int get_int(void) {
  int num;
#ifdef BUF_SIZE
  char line[BUF_SIZE];
  if(!fgets(line, BUF_SIZE, stdin)) return 0;
  sscanf(line, "%d", &num);
#else
#error
#endif
  return num;
}

int get_int2(int *a1, int *a2) {
#ifdef BUF_SIZE
  char line[BUF_SIZE];
  if(!fgets(line, BUF_SIZE, stdin)) return -1;
  sscanf(line, "%d %d", a1, a2);
#else
#error
#endif
  return 0;
}

#define VERTEXES_MAX 200000
#define LPOOL_MAX (VERTEXES_MAX*3+50)

struct list {
    struct list *next;
    int dst;
    uint64_t point;
};


struct list lpool[LPOOL_MAX];
int lpos = 0;

struct list *create_graph(int vs) {
    struct list *graph = &lpool[lpos];
    lpos += vs;
    int i;
    // initialization
    for(i = 0; i < vs; i++) {
        graph[i].next = &graph[i];
        graph[i].dst = i;
        graph[i].point = 0;
    }
    return graph;
}

void add_list(struct list *head, int v) {
    struct list *elem = &lpool[lpos++];
    elem->next = head->next;
    elem->dst = v;
    head->next = elem;
}

static char checked[VERTEXES_MAX];

void dfs(struct list *graph, int size, int root, uint64_t point) {
    struct list *head = &graph[root];
    head->point += point;
    struct list *elem;
    checked[root] = 1;
    for(elem = head->next; elem != head; elem = elem->next) {
        int dst = elem->dst;
        if(checked[dst]) continue;
        dfs(graph, size, elem->dst, head->point);
    }
}

int main(void) {
    int vs, qs;
    get_int2(&vs, &qs);
    int es = vs - 1;
    struct list *graph = create_graph(vs);
    int i;
    for(i = 0; i < es; i++) {
        int v1, v2;
        get_int2(&v1, &v2);
        // 1-indexed -> 0-indexed
        v1--; v2--;
        add_list(&graph[v1], v2);
        add_list(&graph[v2], v1);
    }
    for(i = 0; i < qs; i++) {
        int v; int p;
        get_int2(&v, &p);
        // 1-indexed -> 0-indexed
        v--;
        graph[v].point += p;
    }
    dfs(graph, vs, 0, 0);
    for(i = 0; i < vs; i++) {
        printf("%llu%c", graph[i].point, (i==(vs-1))?'\n':' ');
    }
    return 0;
}

Measured memory_bytes: 25984
#include<bits/stdc++.h>
using namespace std;
int main() {
  int n, count = 0;
  cin >> n;
  vector<int> vec(n);
  vector<int> backet(101);
  for (int i = 0; i < n; i++) {
    cin >> vec.at(i);
    backet.at(vec.at(i)) += 1;
  }
  for (int i = 0; i < backet.size(); i++) {
    if (backet.at(i) != 0) count++;
  }
  cout << count << endl;
}

Measured memory_bytes: 256
N = int(input())
S = list(map(str,input()))

num=[]
for i in range(0,N-1):
	icchi=[]
	p_list=[]
	q_list=[]
	for p in range(0,i+1):
		p_list.append(S[p])
	for q in range(i+1,N):
		q_list.append(S[q])
	for x in range(0,len(p_list)):
		for y in range(0,len(q_list)):
			if(p_list[x]==q_list[y]):
				icchi.append(p_list[x])
				break
	num.append(len(set(icchi)))
print(max(num))

Measured memory_bytes: 3064
package main

import (
	"fmt"
)

func main() {
	var A, B, C, X int
	fmt.Scan(&A)
	fmt.Scan(&B)
	fmt.Scan(&C)
	fmt.Scan(&X)

	c := 0
	for i := 0; i <= A; i++ {
		for j := 0; j <= B; j++ {
			for k := 0; k <= C; k++ {
				if 500 * i + 100 * j + 50 * k  == X {
					c++
				}
			}
		}
	}

	fmt.Println(c)
}

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

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
typedef long double ld;

const int INF = 1e9;
const ld EPS = 1e-8;

string solve(const vector<string> &A, const vector<string> &B) {
  int N = A.size();
  int M = B.size();

  for(int i = 0; i + M - 1 < N; ++i) {
    for(int j = 0; j + M - 1 < N; ++j) {
      bool flag = true;
      REP(k,M) if(A[i + k].substr(j, M) != B[k]) flag = false;
      if(flag) return "Yes";
    }
  }
  return "No";
}

int main(){
  int N, M;
  cin >> N >> M;
  vector<string> A(N), B(M);
  REP(i,N) cin >> A[i];
  REP(i,M) cin >> B[i];
  cout << solve(A, B) << endl;
  return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define mod 1000000007 //10^9+7
#define P pair<int,int>
#define rep(i,n) for(int i=0;i<n;i++)
int n,m=1;
double sum=0;
int x[10],y[10];
bool went[10];

signed main(){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)m*=i;
    rep(i,n){
        cin>>x[i]>>y[i];
    }
    rep(i,n-1){
        for(int j=i+1;j<n;j++){
            sum+=1.000000000*sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));
        }
    }
    sum*=2*(m/n);
    sum/=m;
    printf("%.8LF",sum);
    cout<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}


int main(){
  double n,t,a;
  cin >> n;
  cin >> t >> a;
  double h[(int)n];
  rep(i,n) cin >> h[i];

  int bestH;
  double diff = 100000;
  rep(i,n){
    if(diff > abs(a - (t - h[i] * 0.006))){
      diff = abs(a - (t - h[i] * 0.006));
      bestH = i+1;
    }
  }
  cout << bestH << endl;
  return 0;
}


Measured memory_bytes: 256
// D - Xor Sum 4
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rp(i,s,e) for(int i=(s);i<(e);++i)
#define MOD 1000000007
 
ll O[60];

ll in(){ll x; scanf("%lld",&x); return x;}

int main(){
	int N; cin>>N;
	rp(i,0,N){ for(ll j=0, a=in(); a; a>>=1) O[j++]+=a&1; }
	ll ans = 0;
	rp(i, 0, 60) ans = (ans + (O[i]*(N-O[i]) % MOD) * ((1LL<<i) % MOD)) % MOD;
	cout<< ans <<endl;
}

Measured memory_bytes: 256
N = int(input())
S = input()

a = 'ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ'

N = N % 26
new_S = []
for i in S:
    for j in range(len(a)):
        if i == a[j]:
            new_S.append(a[j + N])
            break
print(''.join(new_S))


Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {


		Scanner sc = new Scanner(System.in);
		int k = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		long bisket = 1;
		long money = 0;
		if(a >= b || b-a<=2) {
			// この場合は、ひたすらビスケットをたたく
			bisket += k;
		}else {
			for(int i =0;i < k;i++) {
				if(money >0) {
					// お金があったらビスケットと交換
					bisket += b;
					money =0;
					continue;
				}

				if(bisket >= a && i != k-1) {
					money++;
					bisket -= a;
				}else {
					bisket++;
				}
			}
		}
		System.out.println(bisket);
	}
}

Measured memory_bytes: 21972
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <climits>
#include <numeric>
#include <cmath>
#include <queue>
#include <sstream>
#include <string.h>
#include <bitset>
#include <stack>

using namespace std;
typedef long long ll;

int main() {
  int N, Q;
  cin >> N >> Q;
  vector<tuple<int, int, int>> e(N);
  for (int i = 0; i < N; i++) {
    cin >> get<1>(e[i]) >> get<2>(e[i]) >> get<0>(e[i]);
  }
  sort(e.begin(), e.end());
  
  set<pair<int, int>> d;
  for (int i = 0; i < Q; i++) {
    int x;
    cin >> x;
    d.insert({x, i});
  }
  
  vector<ll> l(Q, -1);
  for (int i = 0; i < N; i++) {
    auto first = d.lower_bound({get<1>(e[i]) - get<0>(e[i]), 0});
    auto end = d.upper_bound({get<2>(e[i]) - get<0>(e[i]) - 1, Q});
    
    for (auto it = first; it != end; it++) {
      l[it->second] = get<0>(e[i]);
    }
    d.erase(first, end);
  }
  for (int i = 0; i < Q; i++) {
    cout << l[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 15232
#include<bits/stdc++.h>
using namespace std;
 
int main() {
  string s, t;
  cin >> s >> t;
  for (int i = 0; i < s.size(); i++) {
    if (s == t) {
      cout << "Yes" << endl;
      return 0;
    }
    rotate(s.begin(), s.begin() + 1, s.end());
  }
  cout << "No" << endl;
}

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

const int N = 105;

int n, m;
vector<int> c, p;
vector<bool> cov;
vector<int> vmi, vpmi;

bool chk0() {
  int mx = *max_element(c.begin(), c.end());
  int mi = *min_element(c.begin(), c.end());
  return mx <= 2 * mi;
}

int main() {
  scanf("%d", &m);
  c.resize(m);
  for (auto& x : c) {
    scanf("%d", &x);
    n += x;
  }
  if (!chk0()) {
    puts("-1");
    return 0;
  }
  p.resize(n);
  cov.resize(n, false);
  vmi.resize(n + 1, 0);
  vpmi.resize(n + 1, 0);
  for (int i = 0; i < n; i++) {
    for (int x = 0; x < m; x++) {
      if (!c[x]) continue;
      auto bc = c;
      auto bcov = cov;
      bc[x]--;
      p[i] = x;
      if (i >= m - 1) {
        vector<bool> vis(m, false);
        for (int j = 0; j < m; j++) {
          vis[p[i - j]] = true;
        }
        if (*min_element(vis.begin(), vis.end())) {
          fill(bcov.begin() + (i - m + 1), bcov.begin() + i + 1, true);
        }
      }
      int pr = i - 1;
      while (~pr && p[pr] != x)
        pr--;
      if (pr >= 0 && !*min_element(bcov.begin(), bcov.begin() + pr + 1)) {
        continue;
      }
      int R = i + 1;
      while (R && !bcov[R - 1])
        R--;
      bool flg = false;
      vector<bool> vis(m, false);
      int L = i + 1;
      while (L && !vis[p[L - 1]])
        vis[p[--L]] = true;
      int mi = 114514, mx = 0;
      for (int j = 0; j < m; j++) {
        mi = min(bc[j] - !vis[j], mi);
        mx = max(bc[j] - 1, mx);
      }
      int mip = i + 1;
      for (int j = L; j <= i; j++) {
        int y = p[j];
        if (bc[y] == mi) {
          mip = min(mip, j);
        }
      }
      vmi[L] = mi;
      vpmi[L] = mip;
      for (int j = L; j <= i; j++) {
        int y = p[j];
        if (bc[y] - 1 < mi) {
          vmi[j + 1] = bc[y] - 1; 
          vpmi[j + 1] = i + 1;
        } else {
          vmi[j + 1] = vmi[j];
          vpmi[j + 1] = vpmi[j];
        }
      }
      int mxp = i + 1;
      for (int j = i; j >= L; j--) {
        int y = p[j];
        if (bc[y] > mx) {
          mxp = j;
          mx = bc[y];
        }
        if (j <= R) {
          if (vmi[j] >= 0 && mx <= 2 * vmi[j] || (mx == 2 * vmi[j] + 1 && mxp <= vpmi[j])) {
            flg = true;
            break;
          }
        }
      }
      if (L > i && *max_element(bc.begin(), bc.end()) <= 2 * *min_element(bc.begin(), bc.end())) {
        flg = true;
      }
      if (flg) {
        cov = bcov;
        c = bc;  
        break;
      }
    }
  }
  assert(!*max_element(c.begin(), c.end()));
  assert(*min_element(cov.begin(), cov.end()));
  for (auto x : p) {
    printf("%d ", x + 1);
  }
  return 0;
}

Measured memory_bytes: 3800
N,K = gets.chomp.split.map(&:to_i)
As = gets.chomp.split.map(&:to_i)

As.sort!
Bs = []
tmp_arr = []

As.each{ |x|
    if tmp_arr == [] || tmp_arr.last == x then
        tmp_arr << x
    else
        Bs << tmp_arr
        tmp_arr = [x]
    end
}

Bs << tmp_arr if tmp_arr != []

Bs.sort!{ |a, b|
    b.length <=> a.length
}

ans = 0
(Bs.length - K).times{
    ans += Bs.pop.length
}

puts ans


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

int main(){
    pair<int,int> p[5];
    for(int i = 0; i < 5; ++i){
        cin >> p[i].first;
        p[i].second=i;
    }
    sort(p,p+5);
    cout << p[0].second+1;
    return 0;
}

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

#define int long long

using namespace std;

const int maxn = 1e6 + 10, mod = 1e9 + 7;
int fac[maxn], dp[maxn], h, w, n;

int pw(int base, int power)
{
    base %= mod;
    power %= mod - 1;
    int res = 1;
    while (power)
    {
        if (power & 1)
            (res *= base) %= mod;
        (base *= base) %= mod;
        power >>= 1;
    }
    return res;
}

int inv(int x)
{
    return pw(x, mod - 2);
}

int C(int n, int k)
{
    return fac[n] * inv(fac[k]) % mod * inv(fac[n - k]) % mod;
}

int path(int x1, int y1, int x2, int y2)
{
    if (x1 > x2 || y1 > y2)
        return 0;
    return C(x2 - x1 + y2 - y1, x2 - x1);
}

signed main()
{
    ios::sync_with_stdio(false);
    cin >> h >> w >> n;

    fac[0] = 1;
    for (int i = 1; i < maxn; i++)
        fac[i] = (fac[i - 1] * i) % mod;

    vector<pair<int, int>> block(n + 1);
    for (int i = 0; i < n; i++)
        cin >> block[i].first >> block[i].second;
    block[n] = {h, w};

    sort(block.begin(), block.end());
    for (int i = 0; i <= n; i++)
    {
        int x = block[i].first, y = block[i].second;
        dp[i] = path(1, 1, x, y);
        for (int j = 0; j < i; j++)
            (dp[i] -= dp[j] * path(block[j].first, block[j].second, x, y) % mod - mod) %= mod;
    }

    cout << dp[n];

    return 0;
}


Measured memory_bytes: 9856
#include <bits/stdc++.h>
#include <string>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
using namespace std;



int main(){
    int N;
    string S;
    cin >> N >> S;
    int ans = 0;
    int count = 0;
    for(int i = 0;i<N;i++){
        if(S.at(i) == 'I'){
            count++;
        }
        else{
            count--;
        }
        if(ans <= count){
            ans = count;
        }
    }
    cout << ans << endl;
}

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

int main() {
    int x;
    cin >> x;
    for(;; x++) {
        for(int i = 2; i * i <= x; i++)
            if(x % i == 0)
                goto p;
        break;
    p:;
    }
    cout << x << endl;
    return 0;
}


Measured memory_bytes: 256
<?php
fscanf(STDIN, "%d%d", $N, $X);

$dp[0] = 1;
for($i = 1; $i <= 50; $i++){
    $dp[$i] = $dp[$i - 1] * 2 + 3;
}

echo dfs($N, $X);

function dfs($N, $X){
    global $dp;
    static $memo;
    if($X >= $dp[$N]){
        if($memo[$N]){
            return $memo[$N];
        }
    }
    if($X <= 0)return 0;
    if($N == 0)return 1;
    $sum = 0;
    $sum += dfs($N - 1, $X - 1);
    if($X >= $dp[$N - 1] + 2)$sum++;
    $sum += dfs($N - 1, $X - 1 - $dp[$N-1] - 1);
    if($X >= $dp[$N]){
        $memo[$N] = $sum;
    }
    return $sum;
}

Measured memory_bytes: 4604
#include<bits/stdc++.h>
using namespace std;
int main()
{
    //ifstream cin("input.in");
    //ofstream cout("output2.out");
    ios::sync_with_stdio(0);cin.tie(0);
    long long A,B,C;
    cin>>A>>B>>C;
    for(long i=1;i<=1000000;i++)
        if((i*A)%B==C)
        {
            cout<<"YES";
            return 0;
        }
    cout<<"NO";
    return 0;
}

Measured memory_bytes: 256
import sys
input=lambda: sys.stdin.readline().rstrip()
n=int(input())
A=[int(i) for i in input().split()]
mon=1000
stk=0
for i in range(n-1):
  if A[i]<=A[i+1]:
    stk+=mon//A[i]
    mon%=A[i]
  else:
    mon+=stk*A[i]
    stk=0
mon+=stk*A[-1]
print(mon)

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


int main(void){
    int n;
    while(true){
        cin >> n;
        if(n==0){
            break;
        }
        int number_A, number_B;
        int sum_A, sum_B;
        sum_A = sum_B = 0;
        for(int i = 0; i < n; i++){
            cin >> number_A >> number_B;
            if(number_A > number_B){
                sum_A += number_A + number_B;
            }else if(number_A == number_B){
                sum_A += number_A;
                sum_B += number_B;
            }else{
                sum_B += number_A + number_B;
            }
        }
        cout << sum_A << " " << sum_B << endl;


    }
    return 0;
}


Measured memory_bytes: 2988
#include <bits/stdc++.h>
        #define int long long
        //#define endl '\n'
        #define modulo 1000000007
        ///I am the backupguy!
        using namespace std;
        int maxer,m,counter=0;
        vector<vector<int>>lolz(11);
        void BT(int n,vector<int>result){
        if(n==maxer){
        for(int i=0;i<result.size();i++){
        if(result[i]%2==0||result[i]==0)
        return;
        }
        counter++;
        return;
        }
        BT(n+1,result);
        for(int i=0;i<lolz[n].size();i++){
        result[lolz[n][i]]++;
        }
        BT(n+1,result);
        }
        int32_t main()
        {
        iostream::sync_with_stdio(0);
        cin.tie(0);
        cin>>maxer>>m;
        for(int i=0;i<m;i++){
        int a,buff;
        cin>>a;
        for(int l=0;l<a;l++){
        cin>>buff;
        lolz[buff-1].push_back(i);
        }
        }
        int arr2[11];
        for(int i=0;i<m;i++){
        cin>>arr2[i];
        }
        vector<int>lolq;
        for(int i=0;i<m;i++)
        lolq.push_back(0-(!(arr2[i]%2)));
        BT(0,lolq);
        cout<<counter;
        return 0;
    }


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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

#define file "I1"

const double EPS = 1e-9;
const double PI = acos(-1.);
const int INF = 1e9;
const ll MOD = 1e9 + 7;

const int MAXN = 2e5 + 5;

int cnt[MAXN];

int pp[MAXN];

void solve(){
	int n, k, a;
	scanf("%d%d", &n, &k);
	REP(i, 0, n){
		scanf("%d", &a);
		a--;
		cnt[a]++;
	}
	sort(cnt, cnt + n);
	reverse(cnt, cnt + n);
	int ans = n;
	REP(i, 0, k){
		ans -= cnt[i];
	}
	printf("%d\n", ans);
}   

int main(){

    //freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();    
    }
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;

int main() {
  lint N;
  cin >> N;
  vector<lint> A(N);
  for(auto& elem : A) cin >> elem;

  lint ans = 0;
  lint mx = 0;
  for(auto a : A) {
    mx = max(mx, a);
    ans += mx - a;
  }
  cout << ans << endl;
}

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

int main(){
    int n;
    long int s = 0;
    int max = 0;
    int min = 0;

    cin >> n;

    int x[n];

    for(int i=0; i<n; i++){
        cin >> x[i];
    }

    for(int i=0; i<n; i++){
        if(x[max] < x[i]){
            max = i;
        }
    }

    for(int i=0; i<n; i++){
        if(x[min] > x[i]){
            min = i;
        }
    }

    for(int i=0; i<n; i++){
        s = s + x[i];
    }

    cout << x[min] << " " << x[max] << " " << s << endl;

    return 0;
}


Measured memory_bytes: 3128
#include<stdio.h>
int main()
{
	int n, c[500], s[500], f[500];
	scanf("%d", &n);
	int i = 0;
	for ( i = 0; i < n - 1; i++)
		scanf("%d%d%d", &c[i], &s[i], &f[i]);
	for (i = 0; i < n; i++)
	{
		int t = 0;
		int j;
		for (j = i; j < n - 1; j++)
		{
			if(t < s[j])t = s[j];
			else if (t%f[j] == 0);
			else t = t + f[j] - t % f[j];
			t += c[j];
		}
		printf("%d\n", t);
	}
}

Measured memory_bytes: 128
package main

import (
	"fmt"
	"strconv"
)

func main() {
	var a, b string
	var toInt int

	fmt.Scanf("%s %s", &a,&b)

	toInt, _ = strconv.Atoi(a+b)

	for i := 1; i < 1000 ; i++ {
		sqrt := i * i

		if sqrt == toInt {
			fmt.Printf("%s", "Yes\n")
			return
		}
	}
	fmt.Printf("%s", "No\n")
}


Measured memory_bytes: 1840
//writer：Sakura

#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;

int n; 

int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	scanf("%d",&n);
	if(n>=0 && n<=999){
		puts("ABC");
	}
	else{
		puts("ABD");
	}
	return 0;
}



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

using namespace std;

int main() {
  int n, t_score = 0, h_score = 0;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    string t, h;
    cin >> t >> h;
    int order = t.compare(h);
    if      (order > 0) t_score += 3;
    else if (order < 0) h_score += 3;
    else { ++t_score; ++h_score; }
  }
  cout << t_score << ' ' << h_score << endl;
  return 0;
}



Measured memory_bytes: 3144
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <sstream>
#include <string>
#include <map>
#include <set>
#include <stdlib.h>
#include <cmath>
#include <math.h>
#include <fstream>
#include <bitset>
#define int long long
using namespace std;
int K = 10000;
int32_t main(){
	int a, b, c, d, e, f;
	cin >> a >> b >> c >> d >> e >> f;
	double pb = -1;
	int ff, s;
	for (int i=0; i < K; i++){
		if (100*i*a > f) break;
		for (int j=0; j < K; j++){
			if (100*(i*a+j*b) > f) break;
			for (int k=0; k < K; k++){
                if (100*(i*a+j*b) + k*c > f) break;
                int can = e * (i*a+j*b);
                int cc = can - k*c;
                if (cc <= 0) break;
                int mm = f - 100*i*a - 100*j*b - k*c;
                if (mm <= 0) break;
                int nn = ((min(mm, cc)) / d * d) + k*c;
                double pp = (double) 100*nn / (double) (nn + 100*i*a+100*j*b);
                if (pp > pb){
					pb = pp;
					ff = 100*i*a+100*j*b+nn;
					s = nn;
                }
			}
		}
	}
	cout << ff << " " << s << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define COUT(x) cout<<(x)<<"\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define REP(i, n) for(int i=0;i<n;i++)
#define YES(x) cout<<(x?"YES":"NO")<<"\n"
#define Yes(x) cout<<(x?"Yes":"No")<<"\n"
#define dump(x) cout<<#x<<" = "<<(x)<<"\n"
#define endl "\n"
using G = vector<vector<int>>;
using M = map<int,int>;
using P = pair<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int,vector<int>,greater<int>>;
using V = vector<int>;
using ll = long long;
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; }
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main() {
  IOS;
  int n,a; cin >> n;
  M m;
  int sum=0;
  REP(i,n) {
    cin >> a;
    m[a]++;
    if (m[a]>1) sum++;
  }
  int ans = n-sum;
  if (sum % 2) ans--;

  COUT(ans);
  return 0;
}

Measured memory_bytes: 4992
#include"bits/stdc++.h"
using namespace std;

int main() {
	int N;
	cin >> N;
	vector<int> a(N);
	for (int i = 0;i < N;++i) {
		cin >> a[i];
	}
	int count = 0;
	while (true) {
		for (int i = 0;i < N;++i) {
			if (a[i] % 2 != 0) {
				cout << count << endl;
				return 0;
			}
			a[i] /= 2;
		}
		count++;
	}
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	double res = 0;
	double a, b;
	a = b = 0;
	for(int i = 1; i <= n; ++i){
		if(i % 2 == 0)a++;
		else b++;
	}
	cout<<setprecision(12);
	cout<<(b / n)<<endl;
	
	return 0;
}


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

int main(){
    string week;
    int answer = 0;
    cin >> week ;

    if(week == "SUN") answer = 7;
    if(week == "MON")  answer = 6;
    if(week == "TUE")  answer = 5;
    if(week == "WED")  answer = 4;
    if(week == "THU")  answer = 3;
    if(week == "FRI")  answer = 2;
    if(week == "SAT")  answer = 1;

    cout << answer << endl;
    return 0;
} 

Measured memory_bytes: 256
import java.io.FileNotFoundException;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws FileNotFoundException {

		//    	File file = new File("src/in.txt");
		//    	Scanner sc = new Scanner(file);

		Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();
		String s = sc.next();
		sc.close();

		if(a>=3200) {
			System.out.println(s);
		} else {
			System.out.println("red");
		}

	}
}

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

int INF = 1001001001;

vector<vector<P> > to(100005);
vector<int> A(100005, INF);

void dfs(int n, int d){
    A[n] = d;
    int s = to[n].size();
    rep(i, s){
        int x = to[n][i].first;
        if(A[x] != INF)continue;
        dfs(x, d+to[n][i].second);
    }
}

int main() {
    int N, M; cin >> N >> M;
    vector<int> L(M), R(M), D(M);
    rep(i, M){
        cin >> L[i] >> R[i] >> D[i];
        L[i]--;
        R[i]--;
        to[L[i]].push_back(make_pair(R[i], D[i]));
        to[R[i]].push_back(make_pair(L[i], -D[i]));
    }

    rep(i, N){
        if(A[i] == INF){
            dfs(i, 0);
        }
    }

    rep(i, M){
        if(A[R[i]] - A[L[i]] != D[i]){
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 17196
import scala.collection.mutable.Stack
import scala.io.StdIn.{readInt, readLine}

object Main extends App {

  class Node {
    var id = -1
    var parent = -1
    var left = -1
    var right = -1
    var preOrderPos = -1
    var inOrderPos = -1
  }

  val n = readInt
  val nodes = Array.fill[Node](n)(new Node)
  val pre = readLine.split(" ").map(_.toInt)
  val in = readLine.split(" ").map(_.toInt)
  for (i <- 0 to n - 1) {
    nodes(i).id = pre(i)
    nodes(i).preOrderPos = i
    for (j <- 0 to n - 1) {
      if (nodes(i).id == in(j)) {
        nodes(i).inOrderPos = j
      }
    }
  }

  val root = nodes(0)
  for (i <- 1 to n - 1) {
    addChild(nodes, 0, i)
  }

  postOrderTraversal(nodes)

  def addChild(nodes: Array[Node], parentIdx: Int, idx: Int): Unit = {
    val parent = nodes(parentIdx)
    val left = nodes(parentIdx).left
    val right = nodes(parentIdx).right
    val node = nodes(idx)
    if (parent.inOrderPos > node.inOrderPos) {
      if (left == -1) parent.left = idx
      else addChild(nodes, left, idx)
    } else {
      if (right == -1) parent.right = idx
      else addChild(nodes, right, idx)
    }
  }

  def postOrderTraversal(nodes: Array[Node]): Unit = {
    val n = nodes.length
    val visited = Array.fill[Boolean](n)(false)
    val postOrder = Array.fill[Int](n)(-1)
    var cnt = 0
    val stack = new Stack[Int]
    stack.push(0)
    while(!stack.isEmpty) {
      val idx = stack.top
      val left = nodes(idx).left
      val right = nodes(idx).right
      if (right != -1 && !visited(right)) {
        stack.push(right)
      }
      if (left != -1 && !visited(left)) {
        stack.push(left)
      }
      if (isLeaf(left, right) || childrenVisited(visited, left, right)) {
        postOrder(cnt) = nodes(idx).id
        cnt += 1
        visited(idx) = true
        stack.pop
      }
    }
    println(postOrder.mkString(" "))
  }

  def isLeaf(left: Int, right: Int): Boolean = {
    left == -1 && right == -1
  }

  def childrenVisited(visited: Array[Boolean], left: Int, right: Int): Boolean = {
    val leftVisited = if (left == -1) true else visited(left)
    val rightVisited = if (right == -1) true else visited(right)
    leftVisited && rightVisited
  }
}



Measured memory_bytes: 44192
import sys

stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

def divisor(n):
    ass = []
    for i in range(1, int(n**0.5)+1):
        if n%i == 0:
            ass.append(i)
            ass.append(n//i)
    return ass

n = ni()
p = divisor(n)
q = divisor(n-1)
s = set()
ans = 0
for x in p + q:
  m = n
  if x == 1: continue
  while m % x == 0:
    m //= x
  if m % x == 1:
    s.add(x)
print(len(s))

Measured memory_bytes: 3316
# 初期入力
import sys
input = sys.stdin.readline  #文字列では使わない
N = int(input())
T,A = (int(i) for i in input().split())
H = list(map(int, input().split()))


#Hi mの気温
#T_H =[-100]*N
dif =[100]*N
for i in range(N):
    T_H =T -H[i] *0.006
    dif[i] =abs(T_H -A)

ans =dif.index(min(dif)) #最小値のインデックス
print(ans +1)

Measured memory_bytes: 9184
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
long long abs1(long long a){
	if(a>0)return a;
	else return -a;
}
int main(){
long long a[1001],n,m,sum=0;
cin>>n>>m;
for(int i=1;i<=n;i++)cin>>a[i];
sort(a+1,a+n+1);
for(int i=n;i>n-m;i--)sum+=a[i];
cout<<sum;
} 

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

int yukiti,higuti,hideo;

void isHonest(bool b) {
	if (b) cout << yukiti << " " << higuti << " " << hideo <<endl;
	else cout << "-1 -1 -1";
}

int main() {
	int n, y;
	cin >> n >> y;
	y /= 1000;

	if (10 * n < y) isHonest(false);
	else {
		// 9x+4y = y-n を満たせばおけ
		int max = (y - n) / 9;
		for (int i = 0; i <= max; ++i) {
			if ((y - n - 9 * i) % 4 == 0) {
				yukiti = i;
				higuti = (y - n - 9 * i) / 4;
				hideo = n - yukiti - higuti;
				if (hideo >= 0) {
					isHonest(true);
					break;
				}
			}
			if (i == max) isHonest(false);
		}
	}

	system("pause");
	return 0;
}



Measured memory_bytes: 504
#

import sys
input=sys.stdin.readline

def main():
    S=input().strip("\n")
    Q=int(input())
    sign=True
    head=[]
    tail=[]
    for i in range(Q):
        q=tuple(input().split())
        if q[0]=="1":
            sign^=True
        else:
            if (q[1]=="1" and sign==True) or (q[1]=="2" and sign==False):
                head.append(q[2])
            else:
                tail.append(q[2])
    if sign==True:
        print("".join(head[::-1])+S+"".join(tail))
    else:
        print("".join(tail[::-1])+S[::-1]+"".join(head))
    
if __name__=="__main__":
    main()


Measured memory_bytes: 88220
#include <bits/stdc++.h>
#define int long long int
#define endl "\n"
#define mod 1000000007
#define ps(x,noOfDecimal) fixed<<setprecision(noOfDecimal)<<x
  
using namespace std;
signed main()
{
  std::ios::sync_with_stdio(false);
  cin.tie(); cout.tie();
   int a ,b,c,d;
   cin>>a>>b>>c>>d;

   int val1 = a*c;
   int val2 = a*d;
   int val3 = b*c;
   int val4 = b*d;

   int ans = max(val1,max(val2,max(val3,val4)));
   cout<<ans;

  return 0;
}

Measured memory_bytes: 3648
#include<stdio.h>
#define NMMAX 100000
int ufp[NMMAX], ufr[NMMAX];
int UF_find(int);
void UF_union(int, int);
int main(void)
{
  int i, n, m, x, y, ans = 0, p[NMMAX];
  scanf("%d %d", &n, &m);
  for (i = 0; i < n; i++) {
    scanf("%d", &p[i]);
    ufp[i] = i;
    ufr[i] = 0;
  }
  for (i = 0; i < m; i++) {
    scanf("%d %d", &x, &y);
    UF_union(x, y);
  }
  for (i = 0; i < n; i++) {
    if (UF_find(p[i]) == UF_find(i + 1)) ans++;
  }
  printf("%d\n", ans);
}
int UF_find(int a)
{
  if (ufp[a] == a) return a;
  else {
    ufp[a] = UF_find(ufp[a]);
    return ufp[a];
  }
}
void UF_union(int a, int b)
{
  a = UF_find(a);
  b = UF_find(b);
  if (ufr[a] < ufr[b]) ufp[a] = b;
  else {
    ufp[b] = a;
    if (ufr[a] == ufr[b]) ufr[a]++;
  }
}

Measured memory_bytes: 1408
from bisect import bisect
N=int(input())
A=sorted(list(map(int,input().split())))
B=sorted(list(map(int,input().split())))
B_reverse=B[::-1]
C=sorted(list(map(int,input().split())))
cnt=0
dict={}
val=0
for b in B_reverse:
    c_min=bisect(C,b)
    val+=N-c_min
    dict[b]=val
for a in A:
    b_min=bisect(B,a)
    if b_min==N:
        pass
    else:
        cnt+=dict[B[b_min]]
print(cnt)

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

int main(){
    int n;
    cin >> n;
    
    int count = 0;
    int ans = 0;
    
    for (int i=0; i<n; i++){
        int d1, d2;
        cin >> d1 >> d2;
        
        if (d1 == d2){
            count += 1;
            if (count == 3){
                ans += 1;
            }
        }
        else{
            count = 0;
        }
    }
    if (ans != 0){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3632
#https://atcoder.jp/contests/dp/tasks/dp_a

def a_frog1(l):
    dp=[0]*len(l)
    dp[0],dp[1]=l[0],abs(l[1]-l[0])
    dp[2]=min(abs(l[2]-l[2-2])+0,abs(l[2]-l[2-1])+dp[2-2])
    for i in xrange(3,len(l)):
        dp[i]=min(abs(l[i]-l[i-2])+dp[i-2],abs(l[i]-l[i-1])+dp[i-1])
    return dp[-1]    
n=int(input())
l=list(map(int,raw_input().split()))
if n==2:
    print abs(l[1]-l[0])
else:
    print a_frog1(l)

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

class Main{
    public static void main(String[] args){
        FastScanner fsc=new FastScanner();
        int a=fsc.nextInt();
        int b=fsc.nextInt();
        fsc.close();
        for(int i=1;i<=3;i++){
            if(a!=i && b!=i){
                System.out.println(i);
            }
        }
    }
    static class FastScanner {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;
        private boolean hasNextByte(){
            if(ptr<buflen) return true;
            else{
                ptr = 0;
                try{
                    buflen = in.read(buffer);
                }
                catch(IOException e){
                    e.printStackTrace();
                }
                if(buflen<=0) return false;
            }
        return true;
        }
        private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
        private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
        public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
        public String next() {
            if (!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while(isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }
        public long nextLong() {
            if (!hasNext()) throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) throw new NumberFormatException();
            while(true){
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                }
                else if(b == -1 || !isPrintableChar(b)) return minus ? -n : n;
                else throw new NumberFormatException();
                b = readByte();
            }
        }
        public int nextInt() {
            long nl = nextLong();
            if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
            return (int) nl;
        }
        public double nextDouble() { return Double.parseDouble(next());}
        public void close(){
            try{in.close();}
            catch(IOException e){e.printStackTrace();}
        }
    }
}


Measured memory_bytes: 22996
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int K,S ;
  cin >> K >> S;
  int d =0;
  
  for(int X = 0; X<=K; X++){
    for(int Y = 0; Y<=K; Y++){
     int Z = S - X - Y;
     if(Z>=0 && Z<=K) d++;
      }
    }
  cout <<  d << endl;
 
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=1005;
const long long inf=6000000000000000000ll;
int Q,n,m,D,c[27],a[N][27],t[N],su[27],ans,i,j,x,y,as[N],s;
set<int> p[27];
int cal(int x,int y)
{
	int sum=ans;
	sum-=a[x][t[x]];
	sum+=a[x][y];
	auto it=p[t[x]].find(x);
	auto e=it;
	--e;
	++it;
	sum+=c[t[x]]*(-(*it-*e)*(*it-*e-1)/2+(x-*e)*(x-*e-1)/2+(*it-x)*(*it-x-1)/2);
	it=p[y].lower_bound(x);
	e=it;
	--e;
	sum-=c[y]*(-(*it-*e)*(*it-*e-1)/2+(x-*e)*(x-*e-1)/2+(*it-x)*(*it-x-1)/2);
	return sum;
}
void Change(int x,int y)
{
	ans-=a[x][t[x]];
	ans+=a[x][y];
	auto it=p[t[x]].find(x);
	auto e=it;
	--e;
	++it;
	ans+=c[t[x]]*(-(*it-*e)*(*it-*e-1)/2+(x-*e)*(x-*e-1)/2+(*it-x)*(*it-x-1)/2);
	p[t[x]].erase(x);
	t[x]=y;
	p[t[x]].insert(x);
	it=p[t[x]].find(x);
	e=it;
	--e;
	++it;
	ans-=c[t[x]]*(-(*it-*e)*(*it-*e-1)/2+(x-*e)*(x-*e-1)/2+(*it-x)*(*it-x-1)/2);
}
void up()
{
	if(s<ans)
	{
		s=ans;
		for(int i=1;i<=D;++i)
			as[i]=t[i];
	}
}
mt19937 rnd(time(0));
double rand_f() {return double(rnd())/double(RAND_MAX);}
void SA()
{
	double T=1000;
	while(T>0.001)
	{
		int a=rnd()%D+1,b=rnd()%26+1;
		while(b==t[a])
			b=rnd()%26+1;
		int tmp=cal(a,b);
		if(tmp>ans||rand_f()<exp((tmp-ans)/T))
		{
			Change(a,b);
			up();
		}
		T=T*0.999;
	}
}
void Find()
{
	int i,j;
	for(i=1;i<=n;++i)
	{
		int tmp=t[i],mx=s;
		for(j=1;j<=26;++j)
			if(j!=t[i])
			{
				int tp=cal(i,j);
				if(mx<tp)
				{
					mx=tp;
					tmp=j;
				}
			}
		if(tmp!=t[i])
			Change(i,j);
	}
}
int main()
{
	scanf("%d",&D);
	for(i=1;i<=26;++i)
	{
		scanf("%d",&c[i]);
		p[i].insert(D+1);
		p[i].insert(0);
	}
	for(i=1;i<=D;++i)
		for(j=1;j<=26;++j)
			scanf("%d",&a[i][j]);
	for(i=1;i<=D;++i)
	{
		for(j=1;j<=26;++j)
			++su[j];
		t[i]=1;
		for(j=2;j<=26;++j)
			if(su[t[i]]*c[t[i]]+a[i][t[i]]<su[j]*c[j]+a[i][j])
				t[i]=j;
		ans+=a[i][t[i]];
		su[t[i]]=0;
		for(j=1;j<=26;++j)
			ans-=su[j]*c[j];
		p[t[i]].insert(i);
		as[i]=t[i];
	}
	s=ans;
	while(1.0*clock()/CLOCKS_PER_SEC<1.85)
	{
		SA();
		SA();
		SA();
		SA();
		SA();
		SA();
		SA();
		SA();
		SA();
		SA();
		Find();
		up();
		//cout<<s<<endl;
	}
	//cout<<s<<endl;
	for(i=1;i<=D;++i)
		cout<<as[i]<<endl;
}

Measured memory_bytes: 4392
n = int(input())
L = list(map(int, input().split()))
ans = 0
for i in range(n):
    for j in range(i+1, n):
        for k in range(j+1, n):
            if L[i] == L[j] or L[j] == L[k] or L[k] == L[i]:
                pass
            elif L[i] + L[j] > L[k] and L[j] + L[k] > L[i] and L[k] + L[i] > L[j]:
                ans += 1
print(ans)

Measured memory_bytes: 9212
//
//  atcoder.cpp
//
//
///
#include <bits/stdc++.h>
#include <boost/optional.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/bimap/bimap.hpp>
#include <boost/bimap/multiset_of.hpp>
#include <boost/multi_array.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/icl/interval_map.hpp>

#define REP(i, N) for(int i=0; i<(N); i++)
#define REC(f, ...) (void)0; const auto f = [&](const auto f, __VA_ARGS__)
using namespace std;
using namespace boost::integer;

using ll = long long;
namespace bst = boost;
namespace icl = boost::icl;
template<typename T> class in {
    T value;
public:
    in() { cin >> value; }
    operator const T&() const { return value; }
    operator T&() { return value; }
    in& operator=(T source) { value = source; return *this; }
};
template<> class in<string> : public string {
public:
    in() { cin >> *this; }
};
template<class T> class inseq : public T {
public:
    template<typename... Arg> inseq(Arg... arg) : T(forward<Arg>(arg)...) { for (auto&& i : *this) cin >> i; }
};
template<class T> using invec = inseq<vector<T>>;

auto solve() {
  in<ll> N;
  invec<ll> A(N);
  
  ll now = 1000;
  REP(i, N-1) {
    ll nex = now % A[i] + now / A[i] * A[i+1];
    now = max(now, nex);
  }


  return now;
}

template<typename T> void plot(const T& func) { cout << setprecision(9) << func() << endl; }
template<> void plot<void()>(void(&func)()) { func(); }

int main() {
  plot(solve);

  return 0;
}



Measured memory_bytes: 3628
#include <iostream>
#include <algorithm>
using namespace std;
int n;
int f[100][10],joi[10];
int p[100][11];
int ans=-1000000000;

int main(){
    cin>>n;
    for(int i=0;i<n;i++)
        for(int j=0;j<10;j++)
            cin>>f[i][j];
    for(int i=0;i<n;i++)
        for(int j=0;j<=10;j++)
            cin>>p[i][j];
    for(int i=1;i<1024;i++){
        int tmp=0;
        for(int j=0;j<n;j++){
            int cnt=0;
            for(int k=0;k<10;k++) if(i>>k&1&&f[j][k]) cnt++;
            tmp+=p[j][cnt];
        }
        ans=max(ans,tmp);
    }
    cout<<ans;
}

Measured memory_bytes: 256
// 有點不耐煩會破壞偉大的計劃

#include <bits/stdc++.h>

#define append push_back

using namespace std;
using ll = long long;

const int N = 1e5 + 3;
const int M = 1e6 + 7;
const long long MOD = 1e9 + 7;
const long long INF = 1e14 + 9;
const int SM = 1e3 + 5;
const int logN = 22, BL = 400;
const double EPS = 1e-9, PI = acos(-1);
const int dx[] = {1, 0, 0, -1, -1, 1, -1, 1};
const int dy[] = {0, 1, -1, 0, -1, 1, 1, -1};

void debug() {
	cerr << "\n";
}
template<typename Type1, typename... Type2>
void debug(Type1 a, Type2... b) {
    cerr << a << " ";
    debug(b...);
}

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

    string s; cin >> s;

    long long n = s.size();

    if(n & 1) return cout << "No", 0;

    map<char, long long> c;

    for(auto i : s) {
        c[i]++;
    }

    for(auto i : c) {
        if(i.second & 1) {
            return cout << "No", 0;
        }
    }

    cout << "Yes";

    return 0;
}


Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
#define ELEM(array)  (sizeof (array) / sizeof *(array))
#define MOD 1000000007
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;

int main(){
    ll n;
    cin>>n;
    cout<<n*(n-1)/2;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>

using std::cout;
using std::cin;
using std::endl;
using std::string;

class Stack{
private:
  int top;
  int *p;
public:
  Stack();
  void print();
  void push(int x);
  int pop();
};

Stack::Stack(){
  top=0;
  p = new int[1000]; 
}

int Stack::pop(){
  return p[top--];
}

void Stack::push(int x){
  //cout << x << endl;
  p[++top]=x;
}

void Stack::print(){
  //for(int i=0;i<=top;i++)
  cout << p[1] << endl;
}

int main(){
  int i,j,a,b,ic;
  Stack calc;
  string tmp;

  while(cin>>tmp) {
    if(tmp=="+"){
      a = calc.pop();
      b = calc.pop();
      calc.push(a+b);
    }
    else if(tmp=="-"){
      a = calc.pop();
      b = calc.pop();
      calc.push(b-a);
    }
    else if(tmp=="*"){
      a = calc.pop();
      b = calc.pop();
      calc.push(a*b);
    }
    else{
      ic=atoi(tmp.c_str());
      calc.push(ic);
    }
  }
  //calc.pop();
  calc.print();
}



Measured memory_bytes: 3208
#include<stdio.h>
#include<math.h>

int main()
{
	long long int N;
	scanf("%ld", &N);
	
	long long int r;
	long long int ans = N+2;
	
	for(r=0; r<sqrt(N); r++){
		if(N%(r+1) == 0 && (r+1)+N/(r+1) <= ans) ans = (r+1)+N/(r+1);
	}
	
	printf("%ld", ans-2);
	
	return 0;
}



Measured memory_bytes: 128