akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;

#define N 26

const int INF = 1 << 30;

int c[N];
int s[365][N];
int last[N];

struct ContestInfo {
	int D;
	int score;
	vector<int> t;
	set<int> held[N];
	ContestInfo(int dd) : D(dd), score(0) {
		t.resize(D, -1);
		for (int i = 0; i < N; i++) {
			held[i].insert(-1);
			held[i].insert(D);
			score -= c[i] * D * (D + 1) / 2;
		}
	}

	void add(int dd, int qq) {
		if (t[dd] != -1) {
			cout << "Add faild!" << endl;
			exit(1);
		}

		t[dd] = qq;
		score += s[dd][qq];
		held[qq].insert(dd);
		auto itr = held[qq].find(dd);
		auto ritr = next(itr);
		auto litr = prev(itr);
		auto range = [](int l, int r) {
			int k = r - l - 1;
			return -k * (k + 1) / 2;
		};
		score -= c[qq] * range(*litr, *ritr);
		score += c[qq] * (range(*litr, *itr) + range(*itr, *ritr));
	}

	void erase(int dd) {
		if (t[dd] == -1) {
			cout << "Erase faild!" << endl;
			exit(1);
		}
		int qq = t[dd];
		t[dd] = -1;
		score -= s[dd][qq];
		auto itr = held[qq].find(dd);
		auto ritr = next(itr);
		auto litr = prev(itr);
		auto range = [](int l, int r) {
			int k = r - l - 1;
			return -k * (k + 1) / 2;
		};
		score += c[qq] * range(*litr, *ritr);
		score -= c[qq] * (range(*litr, *itr) + range(*itr, *ritr));
		held[qq].erase(itr);
	}

	void change(int dd, int qq) {
		erase(dd);
		add(dd, qq);
	}
};

int main() {
	int d;
	cin >> d;
	for (int i = 0; i < N; i++)
		cin >> c[i];
	for (int i = 0; i < d; i++) {
		for (int j = 0; j < N; j++) {
			cin >> s[i][j];
		}
	}

	int t;
	ContestInfo ci(d);
	for (int i = 0; i < d; i++) {
		cin >> t;
		t--;
		ci.add(i, t);
	}

	int current_score = ci.score;

	int m, dd, qq;
	cin >> m;
	for (int i = 0; i < m; i++) {
		cin >> dd >> qq;
		dd--, qq--;
		// int old_q = ci.t[dd];
		ci.change(dd, qq);
		int new_score = ci.score;
		current_score = new_score;
		// if (new_score < current_score) ci.change(dd, old_q);
		// else current_score = new_score;
		cout << current_score << endl;
	}
}

Measured memory_bytes: 3596
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {

    public static void main(String[] args) throws Exception {

        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

        while(true)
        {
            String line[] = reader.readLine().split(" ");
            int a = Integer.parseInt(line[0]);
            int b = Integer.parseInt(line[2]);
            
            if(line[1].equals("+")) System.out.println(a + b);
            else if(line[1].equals("-")) System.out.println(a - b);
            else if(line[1].equals("*")) System.out.println(a * b);
            else if(line[1].equals("/")) System.out.println(a / b);
            else break;
        }
    }
}

Measured memory_bytes: 24208
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) {
		FastScanner sc = new FastScanner(System.in);
		int n = sc.nextInt();
		int a[] = new int[n];

		for(int i=0;i<n;i++) {
			a[i] = sc.nextInt();
		}

		Arrays.sort(a);

		for(int j =0 ;j<n-1;j++) {
			if(a[j] == a[j+1]) {
				System.out.println("NO");
				return;
			}
		}

		System.out.println("YES");

	}

	static class FastScanner {
        private BufferedReader reader = null;
        private StringTokenizer tokenizer = null;

        public FastScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
            tokenizer = null;
        }

        public String next() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public String nextLine() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    return reader.readLine();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }

            return tokenizer.nextToken("\n");
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public double nextDouble() {
             return Double.parseDouble(next());
         }

        public int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = (int) nextInt();
            return a;
        }

        public long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = nextLong();
            return a;
        }
    }

}

Measured memory_bytes: 47496
#include<bits/stdc++.h>
#define lld         long long int
#define llf         long double
#define pb          push_back
#define mp          make_pair
#define IN          insert
#define loopN(n)    for(lld i=0;i<n;i++)
#define loop(p,n)   for(lld i=p;i<=n;i++)
#define rloop(p,n)  for(lld i=n;i>=p;i--)
#define loop2(p,n)  for(lld j=p;j<=n;j++)
#define all(v)      v.begin(),v.end()
#define F1          first
#define F2          second
#define INF         2e18
#define FILE        freopen("input.txt","r",stdin);freopen("output.txt","w",stdout)
#define PI          2*acos(0.0)
#define ISO         ios::sync_with_stdio(false);cin.tie(0)
#define mem(a,b)    memset(a,b,sizeof(a))
#define case(z)     cout<<"Case "<<z<<": ";
using namespace std;
const lld mod=1e9+7;

lld n,k;
lld a[100005];
lld dp[100005];

lld fun(lld p)
{

    if(p>=n-1)
    {
        return 0;
    }
    if(n-1-p<=k)
    {
        return abs(a[p]-a[n-1]);
    }
    if(dp[p]!=-1)
    {
        return dp[p];
    }
    lld ans=INF;
    loop(1,k)
    {
        ans=min(abs(a[p]-a[p+i])+fun(p+i),ans);
    }
    return dp[p]=ans;


}

int main()
{
    ISO;

    //lld t;cin>>t;while(t--)
    mem(dp,-1);
    cin>>n>>k;
    loopN(n)cin>>a[i];
    cout<<fun(0)<<endl;

    return 0;
}



Measured memory_bytes: 12924
#include<bits/stdc++.h>
#define forr(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define ALL(a) (a.begin()),(a.end())
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll, ll> LP;
const ll LINF = 1LL<<60;
const int INF = 1001001001;
const int MOD = 1000000007;

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

int main() {
    string s;
    cin >> s;
    int a, b, c;
    a = b = c = 0;
    rep(i, s.size()) {
        if(s[i] == 'a') a++;
        else if(s[i] == 'b') b++;
        else c++;
    }
    int n = max(max(a, b), c);
    int m = min(min(a, b), c);
    if(n - m == 0 || n - m == 1) {
        puts("YES");
    } else {
        puts("NO");
    } 

    return 0;
}

Measured memory_bytes: 512
import java.io.PrintWriter
import java.util.ArrayDeque

fun main(args: Array<String>) {
    PrintWriter(System.out).use { out ->
        solve(out)
        out.flush()
    }
}


/** edge info */
data class Edge<T>(val to: Int, var cost: T, var index: Int)

fun solve(out: PrintWriter) {
    val n = readInteger()
    val edges = Array(n) { mutableListOf<Edge<Int>>() }
    repeat(n - 1) {
        val (a, b) = readIntegerList().map { it - 1 }
        edges[a].add(Edge(b, 1, it))
        edges[b].add(Edge(a, 1, it))
    }

    val ansArray = IntArray(n - 1)
    val usedColorSetList = Array(n) { mutableSetOf<Int>() }
    val isUnchecked = BooleanArray(edges.size) { true }
    val nodeQueue = ArrayDeque<Int>()
    nodeQueue.addLast(0)
    isUnchecked[0] = false
    while (nodeQueue.isNotEmpty()) {
        val node = nodeQueue.removeFirst()

        var unusedColor = 0
        for (edge in edges[node]) {
            if (isUnchecked[edge.to]) {
                for (i in (unusedColor + 1)..n) {
                    if (usedColorSetList[node].contains(i) == false) {
                        unusedColor = i
                        break
                    }
                }
                ansArray[edge.index] = unusedColor
                usedColorSetList[node].add(unusedColor)
                usedColorSetList[edge.to].add(unusedColor)

                isUnchecked[edge.to] = false
                nodeQueue.addLast(edge.to)
            }
        }
    }
    println(ansArray.max())
    println(ansArray.joinToString("\n"))
}

fun readInteger() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntegerList() = readStringList().map(String::toInt)
fun readLongList() = readStringList().map(String::toLong)
fun readDoubleList() = readStringList().map(String::toDouble)


Measured memory_bytes: 109892
#include <iostream>
#define llint long long
#define mod 1000000007

using namespace std;

llint n, m, l, r;
const int FACT_MAX = 600005;
llint fact[FACT_MAX], fact_inv[FACT_MAX];

llint modpow(llint a, llint n)
{
	if(n == 0) return 1;
	if(n % 2){
		return ((a%mod) * (modpow(a, n-1)%mod)) % mod;
	}
	else{
		return modpow((a*a)%mod, n/2) % mod;
	}
}

void make_fact()
{
	llint val = 1;
	fact[0] = 1;
	for(int i = 1; i < FACT_MAX; i++){
		val *= i;
		val %= mod;
		fact[i] = val;
	}
	fact_inv[FACT_MAX-1] = modpow(fact[FACT_MAX-1], mod-2);
	for(int i = FACT_MAX-2; i >= 0; i--){
		fact_inv[i] = fact_inv[i+1] * (i+1) % mod;
	}
}

llint comb(llint n, llint k)
{
	llint ret = 1;
	ret *= fact[n];
	ret *= fact_inv[k], ret %= mod;
	ret *= fact_inv[n-k], ret %= mod;
	return ret;
};

llint calc(llint R, llint lb, llint ub)
{
	llint ret = 0, rem = R-lb*m;
	for(int i = 0; rem >= 0 && i <= n-m; i++){
		llint tmp = comb(rem+n, n) * comb(n-m, i) % mod;
		if(i % 2) ret += mod - tmp, ret %= mod;
		else ret += tmp, ret %= mod;
		rem -= ub+1;
	}
	return ret;
}

llint solve(llint R)
{
	llint ret = 0;
	for(int i = 1; i <= R/m; i++){
		ret += calc(R, i, i-1), ret %= mod;
		ret += mod - calc(R, i+1, i-1), ret %= mod;
	}
	ret *= comb(n, m), ret %= mod;
	ret = comb(R+n, n) - ret + mod, ret %= mod;
	return ret;
}

int main(void)
{
	cin >> n >> m >> l >> r;
	make_fact();
	llint ans = (solve(r) - solve(l-1) + mod) % mod;
	//ans *= comb(n, m), ans %= mod;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 9600
s = input()
sum_ = 0
if s[0] == 'R':
  sum_ += 1
  if s[1] == 'R':
    sum_ += 1
    if s[2] == 'R':
      sum_ += 1
  else:
    sum_ = 1
else:
  if s[1] == 'R':
    sum_ += 1
    if s[2] == 'R':
      sum_ += 1
  else:
    if s[2] == 'R':
      sum_ = 1
print(sum_)

Measured memory_bytes: 9104
#include "bits/stdc++.h"
#include "math.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef vector<pair<ll,ll> > vp;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
const int INF=1e9+7;

int main(){
  ll n,ans1=0,ans2=0,ans;cin>>n;
  vll a(n);
  rep(i,0,n){
    cin>>a[i];
    a[i]-=(i+1);
  }
  sort(a.begin(),a.end());
  ll c;
  c=a[(n/2)];
  rep(i,0,n){
    ans1+=abs(a[i]-c);
  }
  cout<<ans1<<endl;
}

Measured memory_bytes: 1792
import sys
read = sys.stdin.readline
import time
import math
import itertools as it
def inp():
    return int(input())
def inpl():
    return list(map(int, input().split()))
start_time = time.perf_counter()
# ------------------------------

k = inp()
if k % 2 == 0:
    print(-1)
    sys.exit()
if k % 7 == 0:
    k //= 7
n = 1
cnt = 1
for i in range(1001001):
    n = n % k
    if n == 0:
        print(cnt) 
        sys.exit()
    cnt += 1
    n *= 10
    n += 1 
print(-1)

# -----------------------------
end_time = time.perf_counter()
print('time:', end_time-start_time, file=sys.stderr)


Measured memory_bytes: 9060
#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,ll> pll;
const int inf=1e9+7;
const ll longinf=1LL<<60;
const ll mod=1e9+7 ;

int main(){
  string s;
  cin >> s;
  ll ans=0,ans1=1;
  int n=s.size();
  rep(i,n){
    int x=s[i]-'0';
    ll temp=min(ans+x,ans1+10-x);
    ll temp1;
    if(x==9)temp1=ans1;
    else temp1=min(ans+x+1,ans1+10-x-1);
    ans=temp;
    ans1=temp1;
  }
  cout << ans << endl;
return 0;}

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

class MainClass
{
    static void Main()
    {
        var r = ReadLine().Split().Select(int.Parse).ToArray();
        int R = r[0], G = r[1], B = r[2], N = r[3];
        long ans = 0;
        for (int i = 0; i <= N; i++)
        {
            for (int j = 0; j <= N; j++)
            {
                if (N-(i*R + j*G)>=0&&(N-(i*R+j*G))%B==0) ans++;
            }
        }
        WriteLine(ans);
    }
}


Measured memory_bytes: 28044
#include <bits/stdc++.h>
#define N 1000005
#define ll long long int 	
#define MP make_pair
#define pb push_back
#define ppb pop_back
#define sp " "
#define endl "\n"
#define fi first
#define se second
#define ii pair<int,int>
#define lli pair<ll,ll>
#define fast cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(false)
#define fast2 freopen ("badhair.gir","r",stdin);freopen ("badhair.cik","w",stdout);
#define mod 1000000007
#define fs(x,y) for(ll i=1;i<=y;i++) cin>>x[i]
#define fo(i,x,y) for(ll i=x;i<=y;i++)
#define INF 1000000000005
using namespace std;

ll n,m,ar[N],sum,t;



int main()
{
	fast;
	cin>>n;
	n*=2;
	fs(ar,n);
	sort(ar+1,ar+n+1);
	for(int i=1;i<=n;i+=2)
		sum+=ar[i];
	cout<<sum;

}



/*     cd onedrive\desktop\kod
cls

Sinav:21-22 aralik
Aciklama: Muhtemelen 25 aralik
*/

Measured memory_bytes: 256
from functools import reduce
import operator

while True:
  n = int(input())
  if n == 0:break
  def fix(x):
    if x[-1] in ("+", "*"):
      return (x.count("."), x[-1])
    else:
      return (x.count("."), int(x[-1]))

  lst = [fix(input()) for _ in range(n)]
  while True:
    if len(lst) == 1:
      print(lst[0][1])
      break
    
    max_depth = -1
    index = 100
    op = "-"
    for i, t in enumerate(lst):
      d, v = t
      if d > max_depth and v in ("+", "*"):
        max_depth = d
        index = i
        op = v

    pop_lst = []
    acc_lst = []
    i = index + 1
    while i < len(lst) and lst[i][0] == max_depth + 1:
      pop_lst.append(i)
      acc_lst.append(lst[i][1])
      i += 1
    if op == "+":
      new_value = reduce(operator.add, acc_lst)
    else:
      new_value = reduce(operator.mul, acc_lst)

    for i in reversed(pop_lst):
      lst.pop(i)
    lst.pop(index)
    lst.insert(index, (max_depth, new_value))


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

int main()
{
	int n, m;
	cin >> n >> m;
	auto h = vector<int>(n + 1);
	for(int i = 1; i <= n; ++i){
		cin >> h[i];
	}
	int ans = n;
	auto p = vector<bool>(n + 1);
	for(int i = 0; i < m; ++i){
		int a, b;
		cin >> a >> b;
		bool al = h[a] <= h[b];
		bool bl = h[b] <= h[a];
		if(al && !p[a]){
			p[a] = true;
			--ans;
		}
		if(bl && !p[b]){
			p[b] = true;
			--ans;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3784
#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;

using u128 = __uint128_t;

#define int long long
#define idxSet tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
#define atIdx find_by_order
#define idxOf order_of_key
#define MOD 1000000007
#define MAX 200005
#define endl '\n'

typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

int dp[MAX];

void solve() {
    int n , k , x ,y;
    cin>>n>>k>>x>>y;
    if(n <= k){
        cout<<n * x<<endl;
    }else cout<<k * x + (n - k) * y<<endl;
}

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;
    //cin>>t;
    while (t--)
        solve();
    return 0;
}

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

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

  int n, ac = 0, wa = 0, tle = 0, re = 0;
  string s;

  cin >> n;

  for (int i = 0; i < n; i++)
  {
    cin >> s;
    if(s == "AC") ac++;
    if(s == "WA") wa++;
    if(s == "TLE") tle++;
    if(s == "RE") re++;
  }
  
  cout << "AC x " << ac << endl;
  cout << "WA x " << wa << endl;
  cout << "TLE x " << tle << endl;
  cout << "RE x " << re << endl;
  
  return 0;
}

Measured memory_bytes: 3652
#include<iostream>
using namespace std;
int main()
{
    int a,b,c;
    cin >> a >> b >> c;

    int cont=0;

    for(int i=a;i<=b;i++){
        if(c%i==0){
            cont++;
        }
    }
    
    cout << cont << endl;

    return 0;

}


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

using namespace std;

char PS(int x){
  char f='a';
for (int i=0;i<x;i++) {
  
  f++;
}
return f;
}
int InversePS(char y){
  char g='a';
  int count=0;
  for(char p=g;p<'z';p++) {
    if(p!=y) {
      count++;
    }
    if(p==y) {
      break;
    }
  }
  return count;
}
    
  
  
  
  
int main() {
string S;
  cin >>S;
  int x=S.size();
  vector<int> vec(26);
  
  for(char p='a';p<='z';p++)  {
    int count=0;
    for(int k=0;k<x;k++) {
      
      if(S.at(k)==p) {
        count++;
      }
    }
    if(count>0) {
      
      vec.at(InversePS(p))=1;
      count=0;
    }
  }
  
  
  int counting=0;
  for(int j=0;j<26;j++) {
    if(vec.at(j)==0) {
      cout<<PS(j)<< endl;
      
      break;
    }
  }
  
  
  
    for(int j=0;j<26;j++) {
    if(vec.at(j)==1) {
      counting++;
    }
    }

  if(counting==26) {
    cout<<"None"<< endl;
  }
  
  
  







}



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

int par[50];
int find(int x) {
    if (par[x] == x) return x;
    else return par[x] = find(par[x]);
}
int same(int x, int y) {
    return find(x) == find(y);
}
void unit(int x, int y) {
    x = find(x);
    y = find(y);
    if (x!=y) par[y] = x;
}

int main() {
    int N, M;
    cin >> N >> M;

    vector<pair<int, int>> G;
    int ai, bi;
    rep(i, M) {
        cin >> ai >> bi;
        ai--, bi--;
        G.push_back(make_pair(ai, bi));
    }

    int ans = 0;
    for (int i=0; i<M; i++) {
        rep(n, N) par[n] = n;
        int cnt_unit = 0;
        for (int j=0; j<G.size(); j++) {
            if (i==j)  continue;
            if (!same(G[j].first, G[j].second))  {
                unit(G[j].first, G[j].second);
                cnt_unit++;
            }
        }
        if (cnt_unit < N-1) ans++;
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <map>
#include <math.h>
#include <vector>

#define INF 100000000

int n,m,k;

int main(){
  scanf("%d%d%d", &n, &m, &k);
  for(int i = 0; i < 100000000; i++){
    if(k == (n*i) % m){
      printf("YES\n");
      return 0;
    }
  
  }
  printf("NO\n");
}



Measured memory_bytes: 256
while 1:
    n,s=map(int,input().split())
    if n==0:break
    r=[0]*101
    for _ in [0]*n:r[int(input())]+=1
    a=0
    for i in range(101):
        if i*2>s:a+=(r[i]**2-r[i])//2
        a+=r[i]*sum(r[j] for j in range(max(i+1,s+1-i),101))
    print(a)

Measured memory_bytes: 7772
import sys
arr_S = []
S = str(input())

for i in range(0,len(S)):
  arr_S.append(S[i])
for i in range(0,-1+len(S)):
  if sorted(arr_S)[i+1] == sorted(arr_S)[i]:
    print("no")
    sys.exit()
print("yes")

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int n;
  cin>>n;
  int A[n];
  for(int i=0;i<n;i++) cin>>A[i];
  int ans=0;
  bool flag=1;
  while(flag){
    flag=0;
    for(int j=n-1;j>0;j--){
      if(A[j]<A[j-1]){
	swap(A[j],A[j-1]);
	flag=1;
	ans++;
      }
    }
  }
  for(int i=0;i<n;i++) cout<<A[i]<<" \n"[i==n-1];
  cout<<ans<<endl;
  return 0;
}


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

int main() {
	string a="";
	int cnt=0;
	getline(cin,a);
	for(int c=0;c<a.size();c++){
		if(a[c]=='1'){
			cnt=cnt+1;
	}
	}
	printf("%d\n",cnt);
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 

typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
using namespace std;

ll dp[20001];

int main(int argc, char* argv[])
{
    int n;
    scanf("%d", &n);

    vector<int> w(n),s(n),v(n);
    vector<pair<int,int> > z;
    int i;
    for(i=0; i<n; i++) {
        scanf("%d%d%d", &w[i], &s[i], &v[i]);
        z.push_back(make_pair(w[i]+s[i],i));
    }
    sort(z.begin(), z.end());

    int j;
    for(j=1; j<=20000; j++) {
        dp[j]=-1;
    }

    for(i=0; i<n; i++) {
        int id=z[i].second;
        for(j=s[id]; j>=0; j--) {
            if(dp[j]>=0) dp[j+w[id]]=MAX(dp[j+w[id]], dp[j]+v[id]);
        }
    }

    ll ans=0;
    for(j=20000; j>=0; j--) {
        ans=MAX(ans,dp[j]);
    }
    printf("%lld\n", ans);

    return 0;
}


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

using namespace std;
using ll = long long;

//container util
#define SORT(c) sort((c).begin(),(c).end())

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

//print
#define pv(val) cerr << #val << '=' << (val) << endl

const int INF = 1e9;

int main(void){

	ll N, K; cin >> N >> K;
	vector<ll> cnt(100005, 0);

	REP(i,N){
		int a, b; cin >> a >> b;
		cnt[a] += b;

	}

	ll sum = 0;
	REP(i,100005){
		if(sum + cnt[i] < K) sum += cnt[i];
		else{
			cout << i << endl;
			break;
		}
	} 



	return 0;

}


Measured memory_bytes: 1024
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <set>
#include <vector>
#include <cmath>
#include <unordered_map>
#include <string>
#define ll long long
#define read(x) scanf("%d",&x);
#define readll(x) cin>>x;
#define FOR(x,a,b) for(int x=a;x<b;x++)
#define MP make_pair
#define PB push_back
#define pii pair<int,int>
#define readN(N,X) for(int i=0;i<N;i++) cin>>X[i];
#define pff pair<double,double>
using namespace std;

long long fastpow(int a, int b, int MOD)
{
    long long x=1,y=a; 
    while(b > 0)
    {
        if(b%2 == 1)
        {
            x=(x*y) % MOD;
        }
        y = (y*y) % MOD;
        b /= 2;
    }
    return x;
}

long long InverseEuler(int n, int MOD)
{
    return fastpow(n,MOD-2,MOD);
}
 
long long f[300000];
bool init;
long long C(int n, int r, int MOD)
{
    if (!init){
        init=1;
        f[0]=1;
        for (int i=1; i<300000;i++)
            f[i]= (f[i-1]*i) % MOD;
        
    }
    return (f[n]*((InverseEuler(f[r], MOD) * InverseEuler(f[n-r], MOD)) % MOD)) % MOD;
}

int N,M;
string S[20];
vector<int> ind;
unordered_map<string, int> kagi;

inline string wow(string& ori){
    string res = "";
    for (int i=0;i<M;i++) res+=ori[ind[i]];
    return res;
}

bool udah[99];


void verify(){
    kagi.clear();
    int dev = 0;
    for (int i=0;i<N;i++){
        string tmp = wow(S[i]);
        string tmp2 = wow(S[i]);
        reverse(tmp2.begin(), tmp2.end());
        // if (tmp == tmp2) continue;
        if (kagi[tmp]) {
            kagi[tmp]--;
            dev--;
        }
        else {
            dev++;
            kagi[tmp2]++;
        }
    }
    if (dev == 1 && N % 2) {
        for (auto& x: kagi){
            if (x.second == 0) continue;
           string tmp = x.first;
           reverse(tmp.begin(), tmp.end());
           if (tmp == x.first) dev--;
        }
    }

    if (dev == 0) {
        cout<<"YES"<<endl;
        exit(0);
    }
}

void coba(int pos){
    int next = -1;
    for (int i=0;i<M;i++){
        if (udah[i] == 0){
            next = i;
            break;
        }
    }
    if (next == -1) {
        verify();
        return;
    }
    udah[next] = 1;

    ind[pos] = next;

    for (int i=0;i<M;i++){
        if (udah[i]) continue;
        udah[i] = 1;
        ind[M - pos - 1] = i;
        coba(pos + 1);
        udah[i] = 0;
    }
    udah[next] = 0;
}

int main(){
  std::ios::sync_with_stdio(false);    
  cin>>N>>M;
  for (int i=0;i<N;i++){
    cin>>S[i];
  }
  for (int i=0;i<M;i++) ind.push_back(i);
  if (M % 2 == 0){
    coba(0);
  } else {
    for (int i=0;i<M;i++){
        ind[M/2] = i;
        udah[i] = 1;
        coba(0);
        udah[i] = 0;
    }
  }
  cout<<"NO"<<endl;
  //do {
    /*
    

  //}while (next_permutation(ind.begin(), ind.end()));
}*/
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**7)
from collections import Counter
def input(): return sys.stdin.readline().rstrip()

def main():
    list = []
    for _ in range(0, int(input())):
        list.append(input())
    counter = Counter(list)

    for str in ['AC', 'WA', 'TLE', 'RE']:
        print(str, 'x', counter[str])

if __name__ == '__main__':
    main()

Measured memory_bytes: 16452
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll n;
ll a[100005][4];
ll dp[100005][4];
ll ans(ll day,ll flag){
    if(day==n){
        return 0;
    }
    if(dp[day][flag]!= -1){
        return dp[day][flag];
    }
    ll maxx = -1e10;
    if(flag==0){
        maxx = max(maxx, a[day][1] + ans(day+1,1));
        maxx = max(maxx, a[day][2] + ans(day+1,2));
        maxx = max(maxx, a[day][3] + ans(day+1,3));
    }
    else if(flag == 1){
        maxx = max(maxx, a[day][2] + ans(day+1,2));
        maxx = max(maxx, a[day][3] + ans(day+1,3));
    }
    else if(flag == 2){
        maxx = max(maxx, a[day][1] + ans(day+1,1));
        maxx = max(maxx, a[day][3] + ans(day+1,3));
    }
    else{
        maxx = max(maxx, a[day][2] + ans(day+1,2));
        maxx = max(maxx, a[day][1] + ans(day+1,1));
    }
    return dp[day][flag] = maxx;
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>n;
    memset(dp,-1,sizeof(dp));
    for(ll i=0;i<n;i++){
        for(ll j=1;j<=3;j++){
            cin>>a[i][j];
        }
    }
    cout<<ans(0,0)<<"\n";
    
}

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

int main(){
	int k,n,a[10][10]={0},i,j,p,sum,count=0;
	float b,c;
	scanf("%d%d",&k,&n);
	for(i=0;i<k;i++)
		for(j=0;j<n;j++)
			scanf("%d",&a[i][j]);
			
	for(i=0;i<k-1;i++)
		for(j=i+1;j<k;j++){
			sum=0;
			for(p=0;p<n;p++){
				sum=sum+(a[i][p]-a[j][p])*(a[i][p]-a[j][p]);
			}
			b=floor(sqrt(sum));
			c=sqrt(sum);
			if(b==c)count++;
		}
	printf("%d\n",count);		
	return 0;
}

Measured memory_bytes: 128
//Solution by Tima
#include <bits/stdc++.h>
 
#define f first
#define s second
#define ll long long
#define ull unsigned long long
#define mp make_pair
#define pb push_back
#define vi vector <int>
#define ld long double
#define pii pair<int, int>
#define y1 sda
#define all(x) x.begin(), x.end()
 
using namespace std;    
const int N = 2020, mod = int(1e9)  + 7; 

int n;
pair<int,int> a[N];

ll dp[N][N];

ll calc(int l,int r){
	if(l > r) return 0;
	if(dp[l][r] != -1) return dp[l][r];
	ll v = a[r - l + 1].f, id = a[r - l + 1].s;
	dp[l][r] = max(calc(l + 1, r) + v * abs(id - l), calc(l, r - 1) + v * abs(id - r));
	return dp[l][r];
}

int main () {
	scanf("%d", &n);
	for(int i = 1; i <= n; i++){
		scanf("%d", &a[i].f);
		a[i].s = i;
	}
	sort(a + 1, a + n + 1);

	memset(dp, -1, sizeof(dp));

	cout << calc(1,n);


return 0;
}

Measured memory_bytes: 35780
#include <iostream>
#include <cstdlib>

using namespace std;

int main() {
  int x1, y1, x2, y2;
  cin >>  x1 >> y1 >> x2 >> y2;
  int x3, y3, x4, y4;
  int hen = 0;
  int x_diff, y_diff;
  x_diff = x2 - x1;
  y_diff = y2 - y1;
  // hen = sqrt(pow(x_diff, 2)) + pow(y_diff, 2)));

  x3 = x2 - y_diff;
  y3 = y2 + x_diff;

  x4 = x1 - y_diff;
  y4 = y1 + x_diff;


  cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;
}


Measured memory_bytes: 256
def f(h, w)
	h1=h/2
	h2=h-h1
	(1...w).map do |x|
		w1=(w-x)/2
		w2=(w-x)-w1
		a, b=[x*h, (w-x)*h1, (w-x)*h2].minmax
		c, d=[x*h, w1*h, w2*h].minmax
		[b-a, d-c].min
	end.min
end

h,w=gets.split.map &:to_i
p [f(h, w), f(w, h)].min


Measured memory_bytes: 3452
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define forever for (;;)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
template<typename A> using V = std::vector<A>;
template<typename A> using F = std::function<A>;
template<typename A, typename B> using P = std::pair<A, B>;
using pii = P<int, int>;
using vi = V<int>;
using vd = V<double>;
using vs = V<std::string>;
using vpii = V<pii>;
using vvi = V<vi>;
using vvpii = V<vpii>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
template<typename T> std::istream &operator>>(std::istream &is, std::vector<T> &v) { for (T &x : v) is >> x; return is; }
using namespace std;
// clang-format on

using Weight = int;
struct Edge {
  int src, dst;
  Weight weight;
  Edge(const int &s = 0, const int &d = 0, const Weight &w = 0) : src(s), dst(d), weight(w) {}
};

using Edges = std::vector<Edge>;
using Array = std::vector<Weight>;
using Matrix = std::vector<Array>;

class Graph {
  std::vector<Edges> g;
  using iterator = std::vector<Edges>::iterator;
  using const_iterator = std::vector<Edges>::const_iterator;

public:
  Graph(const int &size = 0) : g(size) {}
  int size() const { return g.size(); }
  const Edges &operator[](const int &i) const { return g[i]; }
  void addArc(const int &src, const int &dst, const Weight &w = 1) { g[src].emplace_back(src, dst, w); }
  void addEdge(const int &node1, const int &node2, const Weight &w = 1) {
    addArc(node1, node2, w);
    addArc(node2, node1, w);
  }
  iterator begin() { return g.begin(); }
  const_iterator begin() const { return g.begin(); }
  iterator end() { return g.end(); }
  const_iterator end() const { return g.end(); }
};

template<int inf = std::numeric_limits<Weight>::max() / 8> std::pair<std::vector<Weight>, bool> bellmanFord(const Graph &g, int src) {
  int n = g.size();
  Edges es;
  for (auto &adj : g) {
    for (auto &e : adj) es.emplace_back(e);
  }
  std::vector<Weight> dist(n, inf);
  dist[src] = 0;
  bool negCycle = false;
  for (int i = 0;; i++) {
    bool updated = false;
    for (auto &e : es) {
      if (dist[e.src] != inf) {
        if (cmin(dist[e.dst], dist[e.src] + e.weight)) updated = true;
      }
    }
    if (!updated) break;
    if (i > n) {
      negCycle = true;
      break;
    }
  }
  return {dist, negCycle};
}

main {
  int v, e, r;
  cin >> v >> e >> r;
  Graph g(v);
  while (e--) {
    int s, t, d;
    cin >> s >> t >> d;
    g.addArc(s, t, d);
  }
  V<Weight> dist;
  bool negCycle;
  tie(dist, negCycle) = bellmanFord<INF>(g, r);
  if (negCycle) {
    cout << "NEGATIVE CYCLE" << endl;
    return 0;
  }
  for (auto &x : dist) cout << (x == INF ? "INF" : to_string(x)) << endl;
}

Measured memory_bytes: 3368
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
#include<iomanip>
#include<tuple>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<LL,int> LP;
const int INF=1<<30;
const LL MAX=1e9+7;

void array_show(int *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(LL *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(vector<int> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%d%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}
void array_show(vector<LL> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%lld%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}

string sa;
int pos[110000];
vector<int> v1;

int main(){
	int n,m;
	int i,j,k;
	int a,b,c;
	
	cin>>n>>m;
	cin>>sa;
	for(i=n;i>=0;i--){
		if(sa[i]=='0')a=i;
		pos[i]=a;
	}
	for(i=n;i>0;i=a){
		a=max(i-m,0);
		a=pos[a];
		if(a==i){
			cout<<-1<<endl;
			return 0;
		}
		v1.push_back(i-a);
	}
	reverse(v1.begin(),v1.end());
	array_show(v1);
}

Measured memory_bytes: 1528
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
#define fo(i,a,b) for(i=a;i<=b;i++)
using namespace std;
typedef long long ll;
const int maxn=1e5+7;
ll i,j,l,k,t,n,m,ans,an[maxn];
ll a[maxn],b[maxn],c[maxn],x,d[maxn],e[maxn];
void gao(ll *x,ll *y){
    ll i;
    fo(i,1,n)d[i]=x[y[i]];
    fo(i,1,n)x[i]=d[i];
}
int main(){
//	freopen("fan.in","r",stdin);
    scanf("%lld",&n);
    fo(i,1,n)scanf("%lld",&a[i]),a[i]=a[i]-x,x=a[i]+x,b[i]=c[i]=e[i]=i;
    scanf("%lld%lld",&m,&k);
    fo(i,1,m)scanf("%lld",&l),swap(b[l],b[l+1]);
    for(;k;k/=2,gao(b,b)){
    	if(k&1)gao(e,b);
	}
	x=0;fo(i,1,n)x+=a[e[i]],printf("%lld.0\n",x);
}

Measured memory_bytes: 5504
def main():
	n=int(input())
	a=list(map(int, input().split()))
	a.sort()
	c=0
	for i in range(n-1):
		if a[i] == a[i+1]:
			print('NO')
			c+=1
			break
	if c==0:
		print('YES')
main()

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

int main(){
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  if(abs(a-c)<=d || (abs(b-a)<=d && abs(c-b) <= d)){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}
      
  
        
        
        
    
  

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using vs = vector<string>;
using in6 = int64_t;
using ind = double;
using pii = pair<int,int>;
using psi = pair<string,int>;
using vpi = vector<pii>;
using vps = vector<psi>;
#define rep(i, n) for (in6 i = 0; i < (in6)(n); i++)
#define repa(i,a,n) for(in6 i = a; i < (in6)(n); i++)
#define repdown(i,n) for(in6 i = n; i > 0; i--)
#define kyun ios::sync_with_stdio(false)
#define hinata cout << "\n"
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define inf 2147483647
#define dset(n) cout << fixed << setprecision(n)

void yes() {
  cout << "Yes";
}

void no() {
  cout << "No";
}

int main() {
  kyun;
  string s;
  cin >> s;
  if(s == "ABC") cout << "ARC";
  else cout << "ABC";
  hinata;
}

Measured memory_bytes: 3616
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

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

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

    int h, w; cin>>h>>w;
    vector<string> s(h);
    for(int i=0; i<h; i++) cin>>s[i];

    int ans = 0;
    for(int sh=0; sh<h; sh++){
        for(int sw=0; sw<w; sw++){
            if(s[sh][sw] == '#') continue;
            for(int gh=0; gh<h; gh++){
                for(int gw=0; gw<w; gw++){
                    if(s[gh][gw] == '#') continue;
                    if(sh == gh && sw == gw) continue;
                    
                    queue<T> que;
                    que.emplace(sh, sw, 0);
                    vector<vector<bool>> visited(h, vector<bool>(w, false));
                    visited[sh][sw] = true;
                    while(que.size()){
                        int cy, cx, cnt;
                        tie(cy, cx, cnt) = que.front();
                        que.pop();

                        if(cy == gh && cx == gw){
                            chmax(ans, cnt);
                            break;
                        }

                        for(int i=0; i<4; i++){
                            int ny = cy + dy[i], nx = cx + dx[i];

                            if(!(0 <= ny && ny < h && 0 <= nx && nx < w)) continue;
                            if(visited[ny][nx]) continue;
                            if(s[ny][nx] == '#') continue;

                            visited[ny][nx] = true;
                            que.emplace(ny, nx, cnt + 1);
                        }
                    }
                }
            }
        }
    }

    cout << ans << endl;

    return 0;
}

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

template <class T, class F = multiplies<T>>
T power(T a, long long n, F op = multiplies<T>(), T e = {1}) {
  assert(n >= 0);
  T res = e;
  while (n) {
    if (n & 1) res = op(res, a);
    if (n >>= 1) a = op(a, a);
  }
  return res;
}

template <unsigned Mod> struct Modular {
  using M = Modular;
  unsigned v;
  Modular(long long a = 0) : v((a %= Mod) < 0 ? a + Mod : a) {}
  M operator-() const { return M() -= *this; }
  M& operator+=(M r) { if ((v += r.v) >= Mod) v -= Mod; return *this; }
  M& operator-=(M r) { if ((v += Mod - r.v) >= Mod) v -= Mod; return *this; }
  M& operator*=(M r) { v = (uint64_t)v * r.v % Mod; return *this; }
  M& operator/=(M r) { return *this *= power(r, Mod - 2); }
  friend M operator+(M l, M r) { return l += r; }
  friend M operator-(M l, M r) { return l -= r; }
  friend M operator*(M l, M r) { return l *= r; }
  friend M operator/(M l, M r) { return l /= r; }
  friend bool operator==(M l, M r) { return l.v == r.v; }
};

template <class Z> map<Z, int> factorize(Z n) {
  map<Z, int> res;
  for (Z i = 2; i * i <= n; ++i) while (n % i == 0) ++res[i], n /= i;
  if (n != 1) ++res[n];
  return res;
}

auto chmax = [](auto&& l, auto r) { return l < r ? l = r, 1 : 0; };

constexpr long long mod = 1e9 + 7;
using Mint = Modular<mod>;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> a(n);
  map<int, int> mp;
  for (auto&& e : a) {
    cin >> e;
    for (auto f : factorize(e)) {
      chmax(mp[f.first], f.second);
    }
  }
  Mint res;
  for (int e : a) {
    res += 1 / Mint(e);
  }
  for (auto e : mp) {
    res *= power(Mint(e.first), e.second);
  }
  cout << res.v << '\n';
}


Measured memory_bytes: 768
n = int(input())
s = [input() for i in range(n)]

cnt = 0

def is_symmetry(s_):
    for k in range(n):
        for l in range(k+1, n):
            if s_[k][l] != s_[l][k]:
                return False
    return True

for i in range(n):
    i_ = (n+i)%n
    s_ = s[i_:] + s[:i_]
    if is_symmetry(s_):
        cnt += 1

print(cnt*n)

Measured memory_bytes: 3064
using System;
class test{
	static void Main(){
		Int64 num1 = Int64.Parse(Console.ReadLine());
    	string[] tmp = Console.ReadLine().Split();
		Int64[] nums = new Int64[num1];
		for(Int64 cnt=0;cnt<num1;cnt++){nums[cnt]=Int64.Parse(tmp[cnt]);}
		for(Int64 cnt=0;cnt<num1;cnt++){
        	if((cnt+1)!=nums[cnt]){
        	  	Int64 change;
        	    change = nums[cnt];
        		nums[cnt]=nums[change-1];
        		nums[change-1]=change;
        		break;
        	}
      	}
        bool yes_flg=true;
        for(Int64 cnt=0;cnt<num1;cnt++){
          if((cnt+1)!=nums[cnt]){
            yes_flg=false;
            break;
          }
        }
        if(yes_flg==true){
          Console.Write("YES");
        }else{
          Console.Write("NO");
        }
    }
}

Measured memory_bytes: 13140
// AtCoder165 C

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <math.h>
#include <assert.h>
#include <string.h>
#include <memory.h>
#include <malloc.h>
#include <stdlib.h>

// qsortで用いる比較用関数．*a<*bならaが先になる．
int compare(const void* a, const void* b) {
    return *(int*)a - *(int*)b;
}

int revcompare(const void* a, const void* b) {
    return *(int*)b- *(int*)a;
}


int main() {
    int i,j;
    int n;
    int* a;
    int result=0;
    
    scanf("%d", &n);
    a = (int*)malloc(sizeof(int) * n);

    for(i=0;i<n;i++){
        scanf("%d", a+i);
    }

    qsort(a, n, sizeof(int), revcompare);


    for(i=0;i<n;i++){
        if(i%2==0){
            result += *(a+i);
        }else{
            result -= *(a+i);
        }
    }
    printf("%d", result);
    return 0;
}

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

int main() {
  int k;
  cin >> k;
  int ans = -1;
  if(k % 2 != 0 && k % 5 != 0) {
    int idx = 1;
    int trm = 7;
    while(idx <= k) {
      int rst = trm % k;
      if(rst == 0) {
        ans = idx;
        break;
      }
      trm = rst * 10 + 7;
      idx++;
    }
  }
  cout << ans;
}

Measured memory_bytes: 3636
#include<cstdio>
#include<algorithm>
#include<functional>
#include<vector>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)

typedef long long ll;

int t;

int main()
{
  scanf( "%d", &t );
  while( t-- )
  {
    int n, k;
    std::vector<int> xs;
    std::vector<int> ps;
    
    scanf( "%d%d", &n, &k );

    rep( i, n )
    {
      int x;
      scanf( "%d", &x );

      xs.push_back( x );

      if( i )
	ps.push_back( xs[i]-xs[i-1] );
    }

    std::sort( ps.begin(), ps.end(), std::greater<int>() );

    ll ans = 0;

    repi( i, k-1, ps.size() )
      ans += ps[i];

    printf( "%lld\n", ans );
  }
  
  return 0;
}

Measured memory_bytes: 3624
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

N = I()

def trial_division(n):
    d = defaultdict(int)
    while n%2 == 0:
        d[2] += 1
        n = n//2
    p = 3
    while p**2 <= n:
        while n%p == 0:
            d[p] += 1
            n = n//p
        p += 2
    if n != 1:
        d[n] += 1
    return d


d = trial_division(N)
ans = 0
for k in d.keys():
    ok = 0
    ng = 2*d[k]
    while abs(ok-ng) > 1:
        mid = (ok+ng)//2
        if mid*(mid+1) <= 2*d[k]:
            ok = mid
        else:
            ng = mid
    ans += ok

print(ans)

Measured memory_bytes: 67872
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vb = vector<bool>;

const ll MOD = 1e9 + 7;

vll fact;

ll extgcd(ll a, ll b, ll& x, ll& y) {
  ll d = a;
  if (b != 0) {
    d = extgcd(b, a % b, y, x);
    y -= (a / b) * x;
  } else {
    x = 1, y = 0;
  }
  return d;
}

ll mod_inverse(ll a, ll m) {
  ll x, y;
  extgcd(a, m, x, y);
  return (m + x % m) % m;
}

ll mod_fact(ll n, ll p, ll& e) {
  e = 0;
  if (n == 0) return 1;
  ll res = mod_fact(n / p, p, e);
  e += n / p;
  ll s = (n / p % 2 != 0) ? p - fact[n % p] : fact[n % p];
  return res * s % p;
}

ll mod_comb(ll n, ll k, ll p) {
  if (n < 0 || k < 0 || n < k) return 0;
  ll e1, e2, e3;
  ll a1 = mod_fact(n, p, e1),
      a2 = mod_fact(k, p, e2),
      a3 = mod_fact(n - k, p, e3);
  if (e1 > e2 + e3) return 0;
  return a1 * mod_inverse(a2 * a3 % p, p) % p;
}

main() {
  ll n; cin >> n;
  vll a(n + 1);
  vb used(n + 1, false);
  ll l, r;
  rep(i, n + 1) {
    cin >> a[i];
    if (used[a[i]]) r = i;
    used[a[i]] = true;
  }
  rep(i, n + 1) {
    l = i;
    if (a[i] == a[r]) break;
  }
  fact.resize(n + 2);
  rep(i, n + 2) fact[i] = (i == 0) ? 1 : fact[i - 1] * i % MOD;
  rep(i, n + 1) cout << (mod_comb(n + 1, i + 1, MOD) - mod_comb(l + n - r, i, MOD) + MOD) % MOD << endl;
}

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

using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> Vi;
//typedef tuple<int, int, int> T;
#define FOR(i,s,x) for(int i=s;i<(int)(x);i++)
#define REP(i,x) FOR(i,0,x)
#define ALL(c) c.begin(), c.end()
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl

const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = {0, 1, 0, -1};

int main() {
  // use scanf in CodeForces!
  cin.tie(0);
  ios_base::sync_with_stdio(false);

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

  ll ans = A[0]-1, lb = 2;
  FOR(i, 1, N) {
    if (A[i] < lb) {
      continue;
    } else if (A[i] == lb) {
      lb++;
    } else if (A[i] % lb == 0) {
      ans += A[i] / lb - 1LL;
    } else {
      ans += A[i] / lb;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <cmath>
#include <map>
#include <cstdio>
#define INF 1<<27
#define MAX_N 501
using namespace std;
struct edge{double x,y,z,r;};
int V;
double cost[MAX_N][MAX_N];
double mincost[MAX_N];
bool used[MAX_N];

double centerdistance(edge&p,edge&q)
{
  return sqrt(pow(p.x - q.x,2) + pow(p.y - q.y,2) + pow(p.z - q.z,2));
}

double getcost(edge p[],int i,int j)
{
  if( centerdistance(p[i],p[j]) <= (p[i].r + p[j].r))return 0;
  else return centerdistance(p[i],p[j]) - (p[i].r + p[j].r);  
}
double prim()
{
  mincost[0] = 0;
  double res = 0;
  while(true)
    {
      int v = -1;
      for(int i = 0 ; i < V ; i++ )
	{
	  while(!used[i] && (v == -1 || mincost[i] < mincost[v]) )v = i;
	}
      if(v == -1)break;
      used[v] = true;
      res += mincost[v]; 

      for(int i = 0 ; i < V ; i++  )
	{
	  mincost[i] = min(mincost[i],cost[v][i]);
	}
    }
  return res;
}

int main()
{

  while(cin >> V,V)
    {
      fill(mincost,mincost + MAX_N,INF);
      fill(cost[0],cost[MAX_N],INF);
      fill(used,used+MAX_N,false);
      edge p[V];
      for(int i = 0 ; i < V ; i++ )
	{
	  cin >> p[i].x >> p[i].y >> p[i].z >> p[i].r;
	}
      for(int i = 0 ; i < V-1 ; i++ ){
	for(int j = i+1 ; j < V ; j++ ){
	  cost[j][i] = cost[i][j] = getcost(p,i,j);
	}
      }

      double res = prim();
      printf("%.3f\n",res);
    }
  return 0;
}

Measured memory_bytes: 3212
n,m=map(int,input().split())
N="a"*n
for _ in range(m):
    s,c=map(int,input().split())
    s-=1
    if (s==0 and c==0 and n!=1) or (N[s]!="a" and N[s]!=str(c)):
        print(-1)
        exit()        
    else:
        N=N[:s]+str(c)+N[s+1:]
if N[0]=="a" and n!=1:N="1"+N[1:]
N=N.replace("a","0")
print(int(N))

Measured memory_bytes: 3064