akhauriyash/Code-Regression huggingface dataset:
def resolve():
  N, X, M = map(int, input().split(" "))
  checked = [False] * M
  val = X
  ans = 0
  val_list = []

  base = M
  for i in range(N):
    if checked[val] != False:
      loop_start_index = checked[val]
      loop_vals = val_list[loop_start_index:]
      loop_val = sum(loop_vals)
      loop_length = len(val_list[loop_start_index:])
      
      if loop_length != 0:
        ans += ((N - i) // loop_length) * loop_val

        for i in range(((N - i) % loop_length)):
          ans += loop_vals[i]
      break
    ans += val
    checked[val] = i
    val_list.append(val)

    val*=val
    if val >= base:
      val %= base


  print(ans)

if __name__ == "__main__":
  resolve()

Measured memory_bytes: 72300
#include<iostream>
#include<string>
using namespace std;
int main(){
  string S;
  cin>>S;
  int N=S.size();
  bool t=true;
  for (int i=0; i<N; i+=2){
    if (S[i]=='L'){t=false;}
  }
  for (int i=1; i<N; i+=2){
    if (S[i]=='R'){t=false;}
  }
  if(t) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<vi> vvi;

int main() {
  cin.tie(0)->sync_with_stdio(0);
  cin.exceptions(cin.failbit);
  int n,k; cin >> n >> k;
  vi v(n), p(n,0); for(int& i: v) cin >> i;
  rep(i,1,n){
    p[i] = p[i-1] + abs(v[i]-v[i-1]);
    for(int j = 2; j <= i && j <= k; j++){
      p[i] = min(p[i], p[i-j] + abs(v[i]-v[i-j]));
    }
  }
  cout << p[n-1] << "\n";
}


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

int div2(int n){
  int ret = 0;
  while(n %2 == 0){
    ret++;
    n = n / 2;
  }
  return ret;
}

typedef pair<int,int> pii;

bool compare(pii x, pii y){
  return x.second > y.second;
}

int main(){
  int n;
  cin >> n;
  
  vector<pii> v;
  for(int i = 1; i <= n; i++){
    v.push_back(make_pair(i, div2(i)));
  }
  sort(v.begin(), v.end(), compare);
  cout << v[0].first << endl;
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  bool b = false;
  int K, A, B;
  cin >> K >> A >> B;
  int C = A;
  for (int i = 0; i < B - A + 1; i++) {
    if (C % K == 0) {
      b = true;
      break;
    }
    C++;
  }
  if (b) {cout << "OK" << endl;}
  else {cout << "NG" << endl;}
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

#define eps (1e-12)
int main(){
    double x1,y1,x2,y2,x3,y3;
    cin>>x1>>y1>>x2>>y2>>x3>>y3;
    double xa=x2-x1,ya=y2-y1,xb=x3-x1,yb=y3-y1;
    double area=0.5*abs(xa*yb-xb*ya);
    double a=sqrt(xa*xa+ya*ya),b=sqrt(xb*xb+yb*yb),c=sqrt((xa-xb)*(xa-xb)+(ya-yb)*(ya-yb));
    double r1=area*2/(a+b+c);
    double mx=max(a,max(b,c));
    double r2=mx*r1/(2.0*r1+mx);
    cout<<fixed<<setprecision(12)<<r2<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
	int rank,n,i,S[14]={0},H[14]={0},C[14]={0},D[14]={0},j;
	char kind;

	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%s %d",&kind,&rank);
		getchar();
    	if(kind=='S'){
			S[rank]=1;
    	}
    	if(kind=='H'){
      		H[rank]=1;
    	}
    	if(kind=='C'){
      		C[rank]=1;
    	}
    	if(kind=='D'){
      		D[rank]=1;
		}
	}
	
	for(j=1;j<=13;j++){
		if(S[j]==0){
			printf("S %d\n",j);
		}
	}
	for(j=1;j<=13;j++){
		if(H[j]==0){
			printf("H %d\n",j);
		}
	}
	for(j=1;j<=13;j++){
		if(C[j]==0){
			printf("C %d\n",j);
		}
	}
	for(j=1;j<=13;j++){
		if(D[j]==0){
			printf("D %d\n",j);
		}
	}
	
	return 0;
}

Measured memory_bytes: 2684
use std::collections::HashSet;
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("filed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let mut s: usize = read();
    let mut hash = HashSet::new();
    hash.insert(s);
    for i in 2..=100000 {
        if s % 2 == 0 {
            s /= 2;
        } else {
            s = 3 * s + 1;
        }
        let tmp = hash.len();
        hash.insert(s);
        if tmp == hash.len() {
            println!("{}", i);
            break;
        }
    }
}


Measured memory_bytes: 2152
import java.util.Scanner;

public class Main {

	static int n;
	public static void main(String[] args) {

		Scanner in = new Scanner(System.in);
		Point p1 = new Point(0, 0);
		Point p2 = new Point(100, 0);
		n = in.nextInt();

		System.out.println(p1);

		koch(n, p1, p2);

		System.out.println(p2);
		in.close();


	}
	static void koch(int i, Point p1, Point p2) {
		if (i == 0) {
			return;
		}
		double th = Math.toRadians(60);

		double sx = (p1.x * 2 + p2.x) / 3;
		double sy = (p1.y * 2 + p2.y) / 3;
		double tx = (p1.x + p2.x * 2) / 3;
		double ty = (p1.y + p2.y * 2) / 3;

		// TODO: 回転後の座標の求め方
		double ux = (tx - sx) * Math.cos(th) - (ty - sy) * Math.sin(th) + sx;
		double uy = (tx - sx) * Math.sin(th) + (ty - sy) * Math.cos(th) + sy;

		Point s = new Point(sx, sy);
		Point u = new Point(ux, uy);
		Point t = new Point(tx, ty);

		koch(i-1, p1, s);
		System.out.println(s);

		koch(i-1, s, u);
		System.out.println(u);

		koch(i-1, u, t);
		System.out.println(t);

		koch(i-1, t, p2);
	}
	static class Point {
		double x;
		double y;
		public Point(double x, double y) {
			this.x = x;
			this.y = y;
		}

		@Override
		public String toString() {
			return String.format("%.8f", this.x) + " " + String.format("%.8f", this.y);
		}
	}

}



Measured memory_bytes: 42868
example = ('5', '7', '5')
five = 0
seven = 0
ipt = []
s = input()
s = s.split()

for i in s:
    if i == '5':
        five += 1
    elif i == '7':
        seven += 1

if five == 2 and seven == 1:
    print("YES")
else:
    print("NO")

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

using namespace std;

#define ll long long
#define rep(i, n) for (ll i = 1; i < (n+1); i++)
#define req(j, n) for (ll j = 1; j < (n+1); j++)
#define rer(k, n) for (ll k = 1; k < (n+1); k++)


ll gcd(ll p, ll q) {
    if (q == 0) {
        return p;
    } else
    {
        return gcd(q, p % q);
    }
    
}


int main()
{
    ll N;
    cin >> N;
    int ans = 0;
    rep(i, N) {
        req(j, N) {
            rer(k, N) {
                ll anan, ikuiku;
                anan = gcd(i,j);
                ikuiku = gcd(anan, k);
                ans += ikuiku;
            }
        }
    }
    cout << ans << endl;
}

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

int main() {
  int A , B , C , D , E , F , G , H , J , K;
  cin >> A >> B;
  C = B - A + 1;
  //D = A;
  K = 0;
  for ( int i = 0; i < C; i++ ){
     E = A / 10000;
     F = ( A - E * 10000 ) / 1000;
     G = ( A - E * 10000 -  F * 1000 ) / 100;
     H = ( A - E * 10000 -  F * 1000 - G * 100 ) / 10;
     J = A - E * 10000 -  F * 1000 - G * 100 - H * 10;
    if ( E * 10000 +  F * 1000 + G * 100 + H * 10 + J == J * 10000 + H * 1000 + G * 100 + F * 10 + E ){
      K = K + 1;
    }
    A = A + 1;
  }
  cout << K << endl;
}

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

#define ll long long

using namespace std;

ll ans;
main()
{
    int a, b, c, x, y;

    cin >> a >> b >> c >> x >> y;

    if (x < y)
    {
        swap(a, b);
        swap(x, y);
    }

    if (c * 2 >= a + b)
    {
        cout << a * x + b * y << endl;
        return 0;
    }

    ans = y * 2 * c;

    x -= y;
    y = 0;

    if (c * 2 >= a)
    {
        cout << ans + a * x;
        return 0;
    }

    cout << ans + x * 2 * c;
}




Measured memory_bytes: 256
a, b = map(int, input().split())
def kaibun(n):
    n = list(str(n))
    if n[0] == n[4] and n[1] == n[3]:
        return 1
    else:
        return 0
cnt = 0
for i in range(a, b+1):
    if kaibun(i):
        cnt += 1
print(cnt)

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

char maze[10][10]; //迷路の文字列
int N, M; 
int sx, sy; //スタートの座標
int gx, gy; //ゴールの座標

int d[10][10]; //各点までの最短距離の配列

//移動の4方向のベクトル
int dx[2] = {1, 0 }, dy[2] = {0, 1 };
int bfs(){
    queue<P> que;
    rep(i, N) rep(j, M) d[i][j] = INF; //全ての点を初期化
    //スタート地点をキューに入れ、その点の距離を0にする
    que.push(P(sx, sy)); 
    d[sx][sy] = 0;

    //キューが空になるまでループ
    while(que.size()){
        //キューの先頭を取り出す(ゴールなら探索終了)
        P p = que.front(); que.pop();
        if(p.first == gx && p.second == gy) break;
        //移動4方向をループ
        rep(i, 2){
            //移動先の点を仮において移動可能か既に訪れたか判定
            int nx = p.first + dx[i], ny = p.second + dy[i];
            if (0 <= nx && nx < N && 0 <= ny && ny < M && maze[nx][ny] != '.' && d[nx][ny] == INF){
                que.push(P(nx, ny));
                //移動可能ならキューに入れ、距離を今の地点+1する
                d[nx][ny] = d[p.first][p.second] + 1;
            }
        }
    }
    return d[gx][gy];
}

int main(){
  cin>>N>>M;
  int count=0;
  rep(i,N) rep(j,M){
      cin>>maze[i][j];
      if(maze[i][j]=='#') count++;
  } 
 sx=0, sy=0; 
 gx=N-1, gy=M-1;
  int ans=bfs();

  if(ans!=count-1) cout<<"Impossible"<<endl;
  else cout<<"Possible"<<endl;




}

Measured memory_bytes: 256
'''
ABC050 A - Addition and Subtraction Easy
https://atcoder.jp/contests/abc050/tasks/abc050_a
'''
def main():
    a, op, b = input().split()
    a, b = int(a), int(b)

    if op == '+':
        ans = a+b
    elif op == '-':
        ans = a-b
    print(ans)


main()


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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'

// n回繰り返し
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順
#define rep1(i,n) for(int i = 1; i <= ((int)(n)); i++) // 1-indexed昇順
#define rrep(i,n) for(int i = ((int)(n)-1); i >= 0; i--)  // 0-indexed降順
#define rrep1(i,n) for(int i = ((int)(n)); i >= 1; i--)   // 1-indexed降順
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii;  // 2次元配列
typedef vector<ll> vll;
typedef vector<double> vd;
typedef pair<int, int> PII;

template<typename T>
using vec = vector<T>;
template<class T>
using maxheap = std::priority_queue<T>;
template<class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

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

const ld Pi = std::acos(-1.0L);
const ll infll = (1LL<<62)-1;
const int inf = (1<<30)-1;
const int mod = 1000000007;
// const int mod = 998244353;


/*FUNCs=================================================*/


/*MAIN==================================================*/
signed main() {
    int START_TIME = clock();
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
    // cout << fixed << setprecision(15);

    string s, sub;
    cin >> s;
    int k;
    cin >> k;
    int n = s.size();
    /**
     * k <= 5 より、小さい順に貪欲に試していって大丈夫そう
     */
    set<string> st;
    // st.size() == kになるよう調整する. 先頭は常にk番目に小さい数となる
    // stの大きさは高々5なので、eraseも十分高速
    rep1(range, n) {
        for (int i = 0; i < n - range + 1; i++) {
            sub = s.substr(i, range);

            if(st.size() < k) {
                st.insert(sub);
            }
            else {  // hp.size() == k
                if(*--st.end() > sub) {
                    st.erase(*--st.end());
                    st.insert(sub);
                }
            }
        }
    }

    cout << *--st.end() << '\n';

    // printf("ExecutionTime: %d /ms\n",1000*(int)((clock()-START_TIME)/CLOCKS_PER_SEC));
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MOD 1000000007
#define INF 2000000000
#define ull unsigned long long

int Min(int a, int b) { return a < b ? a : b; }

int main(){
    int i,j,n,m,x,c[13]={},a[13][13]={},bit,money=0,ans=INF;
    scanf("%d%d%d",&n,&m,&x);
    for (i=0; i<n; i++) {
        scanf("%d",&c[i]);
        for (j=0; j<m; j++) scanf("%d",&a[i][j]);
    }
    for (bit=0; bit<(1<<n); bit++) {
        int sum[13]={};
        money=0;
        for (i=0; i<n; i++) {
            if (bit & (1<<i)) {
                for (j=0; j<m; j++) sum[j]+=a[i][j];
                money+=c[i];
            }
        }
        for (i=0; i<m; i++) if (sum[i]<x) break;
        if (i==m) ans=Min(ans, money);
    }
    if (ans==INF) printf("%d",-1);
    else printf("%d",ans);
    return 0;
}



Measured memory_bytes: 1696
#include<cmath>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define gt getchar()
#define ll long long
#define File(s) freopen(s".in","r",stdin),freopen(s".out","w",stdout)
inline int in()
{
	int k=0;char ch=gt;
	while(ch<'-')ch=gt;
	while(ch>'-')k=k*10+ch-'0',ch=gt;
	return k;
}
const int N=4005,YL=998244353;
int fac[N],fnv[N],tot[N];
inline int MO(const int &x){return x>=YL?x-YL:x;}
inline int C(int x,int y){return y>x?0:1ll*fac[x]*fnv[y]%YL*fnv[x-y]%YL;}
inline int ksm(int a,int k){int r=1;while(k){if(k&1)r=1ll*r*a%YL;a=1ll*a*a%YL,k>>=1;}return r;}
int main()
{
	int k=in(),n=in();fac[0]=1;
	for(int i=1;i<=n+k;++i)fac[i]=1ll*fac[i-1]*i%YL;fnv[n+k]=ksm(fac[n+k],YL-2);
	for(int i=n+k;i>=1;--i)fnv[i-1]=1ll*fnv[i]*i%YL;
	for(int i=1;i<=k;++i)++tot[i+1],--tot[i+k+1];
	for(int i=2;i<=k+k;++i)tot[i]+=tot[i-1];
	for(int i=2;i<=k+k;++i)
	{
		int t=tot[i]+1>>1,ans=0;
		for(int j=0,d=1;j<=t;++j,d=YL-d)
			ans=MO(ans+1ll*d*C(t,j)%YL*C(n-2*j+k-1,k-1)%YL);
		printf("%d\n",ans);
	}
	return 0;
}


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

int main()
{
    int64_t s[2001];
    for (int64_t n = 0; n < 2001; ++n)
    {
        s[n] = 1;
    }
    
    s[0] = s[1] = s[2] = 0;

    int64_t S;
    std::cin >> S;

    for (int64_t i = 4; i < 2001; ++i)
    {
        for (int64_t j = 0; j <= i - 3; ++j)
        {
            if (i == j) {
                s[i] += 1;
            }
            else {
                s[i] += s[j];
            }
            s[i] %= 1000000007LL;
        }
    }

    std::cout << s[S] << std::endl;

    return 0;
}


Measured memory_bytes: 3580
import sys
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()
def resolve():
    n, k = map(int, input().split())
    b = list(map(lambda x : int(x) - 1, input().split()))

    now = 0
    while k:
        if k & 1: now = b[now]
        b = [b[b[i]] for i in range(n)]
        k >>= 1
    print(now + 1)
resolve()

Measured memory_bytes: 170356
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <functional>
using namespace std;
using Int = long long;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,f,t) for(int i=f;i<t;i++)
int main()
{
    int N; cin >> N;
    int ns[9] = {};
    REP(i, N) {
        int a; cin >> a;
        ns[min(a / 400, 8)]++;
    }
    int cnt = 0;
    REP(i, 8) if (ns[i]) cnt++;
    cout << max(1, cnt) << " " << cnt + ns[8] << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>
#include <set>
#include <random>


using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}

using int64 = long long;

int main() {
    int d;
    cin >> d;

    vector c(27, 0);
    for (int i=1; i<27; i++) cin >> c[i];
    vector index(26, 0);
    iota(index.begin(), index.end(), 1);

    sort(index.begin(), index.end(), [&](const int&x, const int&y){return c[x]>c[y];});
    
    vector<int> ans;
    for (int i=0; i<d; i++) {
        ans.push_back(index[i%26]);
    }

    reverse(ans.begin(), ans.end());
    for (auto a : ans) cout<<a<<endl;
}

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

int main()
{
    int A, B, total;
    cin >> A >> B;
    total = 0;
    for (int i = A; i < B + 1; i++)
    {
        int k1, k2, k3, k4, k5, tmp;
        k1 = i / 10000;
        tmp = i - k1 * 10000;
        k2 = tmp / 1000;
        tmp = tmp - k2 * 1000;
        k3 = tmp / 100;
        tmp = tmp - k3 * 100;
        k4 = tmp / 10;
        k5 = tmp - k4 * 10;
        if (k1 == k5 && k2 == k4)
        {
            //           cout << i << endl;
            total++;
        }
    }
    cout << total << endl;
}


Measured memory_bytes: 256
import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter
import kotlin.concurrent.timerTask
import kotlin.math.max
import kotlin.math.min

val br = BufferedReader(InputStreamReader(System.`in`))
val out = PrintWriter(System.out)

fun main() {
    br.use { out.use {
        solve()
        out.flush()
    } }
}

fun solve() {
    val (a, b, c, x, y) = readLongList()
    var ans = Long.MAX_VALUE
    for (cTmp in 0..max(x * 2, y * 2)) {
        val tmp = cTmp / 2
        val atmp =  max(x - tmp, 0)
        val btmp =  max(y - tmp, 0)
        ans = min(ans, c * cTmp + a * atmp + b * btmp)
    }
    out.println(ans)
}

fun readInteger() = Integer.parseInt(br.readLine())
fun readLong() = java.lang.Long.parseLong(br.readLine())
fun readStringList() = br.readLine()!!.split(' ')
fun readIntegerList() = readStringList().map(Integer::parseInt)
fun readLongList() = readStringList().map(java.lang.Long::parseLong)
fun readDoubleList() = readStringList().map(java.lang.Double::parseDouble)


Measured memory_bytes: 36504
#[test]
fn test_solve() {
   assert_eq!(solve("4\n2 5 4 6\n"), "5\n");
   assert_eq!(solve("9\n0 0 0 0 0 0 0 0 0\n"), "45\n");
   assert_eq!(solve("19\n885 8 1 128 83 32 256 206 639 16 4 128 689 32 8 64 885 969 1\n"), "37\n");
}
fn solve(src: &str) -> String {
    let mut sc = Scanner::from_str(src);

    let n: usize = sc.read();
    let a: Vec<usize> = (0..n).map(|_| sc.read()).collect();

    let mut ans = 0;
    let mut usd = 0;
    let mut r = 0;
    for l in 0..n {
        while r < n && usd & a[r] == 0 {
            usd |= a[r];
            r += 1;
        }
        ans += r-l;
        usd &= !a[l];
    }

    format!("{}\n", ans)
}
fn main() {
    let mut buf = String::new();
    use std::io::{Read, Write};
    std::io::stdin().read_to_string(&mut buf).unwrap();
    std::io::stdout().write_all(solve(&buf).as_bytes()).unwrap();
}
struct Scanner<'a>(std::str::SplitWhitespace<'a>);
impl<'a> Scanner<'a> {
    fn from_str(src: &str) -> Scanner {
        Scanner(src.split_whitespace())
    }
    fn get(&mut self) -> &str {
        self.0.next().unwrap()
    }
    fn read<T: std::str::FromStr>(&mut self) -> T {
        self.get().parse().ok().unwrap()
    }
}

Measured memory_bytes: 8444
#include<iostream> 
#include<iomanip> 
#include<vector> 
#include<map> 
#include<set> 
#include<algorithm> 
#include<numeric> 
#include<limits> 
#include<bitset> 
#include<functional> 
#include<type_traits> 
#include<queue> 
#include<stack> 
#include<array> 
#include<random> 
#include<utility> 
#include<cstdlib> 
#include<ctime>
//#define _LIBCPP_DEBUG 0
//#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define all(a) (a).begin(),(a),end()
#define rep(i,n) for (ll i = 0; i < (ll)(n); ++i)	

int max(int a, int b) {
	int max;
	if (a > b) max = a;
	else max = b;
	return max;
}
int min(int a, int b) {
	int min;
	if (a < b) min = a;
	else min = b;
	return min;
}


int main(){
	int n, m;
	cin >> n >> m;
	cout << n * (n - 1) / 2 + m * (m - 1) / 2 << endl;

} 

Measured memory_bytes: 384
using System;
using System.Collections;
using System.Collections.Generic;

class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().run();
        return 0;
    }

    void run()
    {
        int T = int.Parse(Console.ReadLine());
        for (int test = 0; test < T; test++)
        {
            string[] st = Console.ReadLine().Split(' ');
            int[] x = new int[3];
            int[] y = new int[3];
            for (int i = 0; i < 3; i++)
            {
                x[i] = int.Parse(st[i * 2]);
                y[i] = int.Parse(st[i * 2 + 1]);
            }

            int[] tx = new int[2];
            int[] ty = new int[2];
            tx[0] = int.Parse(st[3 * 2]);
            ty[0] = int.Parse(st[3 * 2 + 1]);
            tx[1] = int.Parse(st[4 * 2]);
            ty[1] = int.Parse(st[4 * 2 + 1]);

            int[] flag = new int[2];
            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 2; j++)
                {
                    int x1 = x[i] - tx[j];
                    int x2 = x[(i + 1) % 3] - tx[j];
                    int y1 = y[i] - ty[j];
                    int y2 = y[(i + 1) % 3] - ty[j];
                    if (x1 * y2 > x2 * y1) flag[j] |= 1 << i;
                }
            }

            //Console.WriteLine(flag[0] + " " + flag[1]);
            int r = 0;
            for (int j = 0; j < 2; j++)
            {
                if (flag[j] % 7 == 0) r++;
            }
            if (r % 2 == 0) Console.WriteLine("NG");
            else Console.WriteLine("OK");
        }
    }
}

Measured memory_bytes: 5536
#include "bits/stdc++.h"

using namespace std;

int main() {
    /*int a,b,h,s;
    cin >> a >> b >> h;
    
    s=(a+b)*h/2;
    
    cout << s << endl;*/
    
    /*int N,A,B;
    cin >> N >> A;
    B=N*N-A;
    
    cout << B << endl;*/
    
   /* int A,B,C,D,s1,s2;
    cin >> A >> B >> C >> D;
    
    s1=A*B;
    s2=C*D;
    
    if(s1>s2){
        cout << s1 << endl;
    }
    else if(s1<s2){
        cout << s2 << endl;
    }
    else{
        cout << s1 << endl;
    }*/
    
    int a,b,c,s;
    cin >> a >> b >> c;
    
    s=0;
    if(a!=b){
        s=s+1;
    }
    if(a!=c){
        s=s+1;
    }
    if(b!=c){
        s=s+1;
    }
    if(a==b&&a==c&&b==c){
        s++;
    }
    cout << s << endl;
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    return 0;
}

Measured memory_bytes: 256
n = gets.to_i
a = gets.chomp.split(" ").map(&:to_i)
color = Array.new(8,0)
pro = 0
a.each do |num|
  if num < 3200
    color[num/400] = 1
  else
    pro += 1
  end
end
puts "#{[color.count(1),1].max} #{color.count(1)+pro}"

Measured memory_bytes: 3836
#include<bits/stdc++.h>
using namespace std;
#define FasterIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

typedef unsigned long long ull;
typedef long long ll;
typedef double db;

#define mem(a,x) memset(a,x,sizeof(a))
#define pb push_back
#define ff first
#define ss second
#define mk make_pair
#define pi pair<int,int>
#define vi vector<int>
#define pL pair<ll,ll>
#define vL vector<ll>
#define vp vector<pi>
#define vpL vector<pL>

const int MX=1000000;
const ll inf=1e9;
const ll mod=(1LL<<32);


string s[MX], s1;
int t[MX];

int main()
{
    FasterIO;

    int n;
    cin>>n;
    for(int i=0; i<n; i++) cin>>s[i]>>t[i];
    cin>>s1;
    int sm=0;
    for(int i=n-1; i>=0; i--)
    {
        if(s1==s[i]) break;
        sm+=t[i];
    }
    cout<<sm<<endl;
    return 0;
}


Measured memory_bytes: 9984
# -*- coding: utf-8 -*-
N = int(input())
A = []
for _ in range(N):
    A.append(int(input()))

As = sorted(A)
Ar = sorted(A)
Ar.reverse()


cent = (N+1)//2 - 1

ans = [0 for _ in range(N)]
for i in range(cent+1):
    if i == 0:
        ans[cent] = As[0]
    elif i % 2 == 1:
        ans[cent+i] = Ar[i-1]
        ans[cent-i] = Ar[i]
    else:
        ans[cent+i] = As[i-1]
        ans[cent-i] = As[i]

if N % 2 == 0:
    if cent % 2 == 0:
        ans[-1] = Ar[cent]
    else:
        ans[-1] = As[cent]

diff = 0
for i in range(N-1):
    diff += abs(ans[i] - ans[i+1])

# print(As)
# print(Ar)
# print(ans)
# print(diff)

ans = [0 for _ in range(N)]
for i in range(cent+1):
    if i == 0:
        ans[cent] = Ar[0]
    elif i % 2 == 1:
        ans[cent+i] = As[i-1]
        ans[cent-i] = As[i]
    else:
        ans[cent+i] = Ar[i-1]
        ans[cent-i] = Ar[i]

if N % 2 == 0:
    if cent % 2 == 0:
        ans[-1] = As[cent]
    else:
        ans[-1] = Ar[cent]

diff2 = 0
for i in range(N-1):
    diff2 += abs(ans[i] - ans[i+1])

# print(ans)
# print(diff2)

print(max([diff,diff2]))


Measured memory_bytes: 10652
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
 
int main(void)
{
	int N;
	cin >> N;

	vector<int> S;
	int sum = 0;
	for (int loop = 0; loop < N; ++loop) {
		int x;
		cin >> x;
		S.push_back(x);
		sum += S[loop];
	}

  	bool isNon = false;
	if (0 != sum % 10) {
		cout << sum << endl;
	} else {
		sort(S.begin(), S.end());
		for (int loop = 0; loop < N; ++loop) {
			if (0 != S[loop] % 10) {
				S[loop] = 0;
	            isNon = true;
				break;
			}
		}
		sum = 0;
        if (isNon) {
          for (int loop = 0; loop < N; ++loop) {
              sum += S[loop];
          }
        }
		cout << sum << endl;
	}
	return 0;
}


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

typedef long long ll;

const int N = 1e5+1;

int main () {
	int n, m; cin >> n >> m;
	pair<int,int> arr[m];
	for (int i = 0; i < m; i++) 
		cin >> arr[i].first >> arr[i].second;
	
	// cut the tip instead
	sort(arr, arr+m);
	reverse(arr, arr+m);

	int r = N, ans = 0;
	for (int i = 0; i < m; i++) {
		if (r >= arr[i].second) {
			r = arr[i].first;
			ans++;
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include <algorithm>
#include<string>
#include <bitset>
#include <vector>
#include <functional>
#include <climits>
#include <iomanip>
#include <utility>
#include <stack>
#include <queue>
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <numeric>
using namespace std;
using ll = long long;
int main()
{

	ll a = 0, b = 0, c = 0, d = 0, e = 0;
	string s, t;
	ll n, m, h, w, X;
	ll k;
	ll A[60] = {};
	ll memo[4000] = {};
	ll memo2[4000] = {};
	cin >> a;
	cin >> b;
	cin >> c;
	if (a>=b&&a>=c)
	{
		cout << a*10+b+c << endl;

	}
	else if (b>=a&&b>=c)
	{
		cout << a  + b*10 + c << endl;

	}
	else
	{
		cout << a + b  + c*10 << endl;

	}

	//cout << sum << endl;
	//cout <<  endl;

	return 0;
}

//memcpy(x, visited, sizeof(ll)*n);
//void kansuu(ll num, ll visited[10]) {}
//kansuu(1, zz);
//cout << setprecision(15) << v << endl;

//int temp;
//for (int i = 0; i < n - 1; i++) {
//	for (int j = n - 1; j > i; j--) {
//		if (w[j - 1] < w[j]) {  /* 前の要素の方が大きかったら */
//			temp = w[j];        /* 交換する */
//			w[j] = w[j - 1];
//			w[j - 1] = temp;
//		}
//	}
//}



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

using namespace std;
int main(){
  string s1 {};
  cin >> s1;
  if(s1[s1.length()-1] == 's'){
    cout << s1 + "es" << endl;
  }
  else {
    cout << s1 + "s" << endl;
  }
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
#define MAX_N 100001
#define INF_INT 2147483647
#define INF_LL 9223372036854775807
#define REP(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
void init(int n);
int find(int n);
void unite(int x,int y);
bool same(int x, int y);
ll bpow(ll,ll,ll);
typedef vector<int> vec;
typedef vector<vec> mat;
mat mul(mat &A,mat &B);
mat pow(mat A,ll n);
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
const int MOD = 1000000007;

bool cmp_P(const P &a,const P &b){
  return a.second < b.second;
}
int main()
{
  ll N,dp[100001],h[100002];
  cin >> N;
  h[0] = 0;
  REP(i,N)cin >> h[i+1];
  dp[1] = 0;
  dp[2] = abs(h[2] -h[1]);
  for(int i=3;i<=N;i++){
    dp[i] = min(dp[i-1]+abs(h[i-1]-h[i]),dp[i-2]+abs(h[i-2]-h[i]));
  }
  cout << dp[N] << endl;
  return 0;
}



Measured memory_bytes: 1792
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

#define SORT(c) sort((c).begin(),(c).end())
#define ANS(ans) cout<<(ans)<<endl;
typedef vector<int> VI;

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


int main() {

	int n, x;
	cin >> n >> x;
	VI v(n);
	REP(i, n) {
		cin >> v[i];
	}

	SORT(v);
	int sum = 0;

	REP(i, n) {
		sum += v[i];
	}

	int p = (x - sum) / v[0];

	ANS(n + p);

	return 0;
}



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

int main(){
    int n, k;
    cin >> n >> k;
    long long H[n];
    long long ans[n];
    for(int i=0;i<n;i++)cin >> H[i];
    ans[0] = 0;

    for(int i=1;i<n;i++){
        long long tmp=1 << 30;
        for(int j=max(i-k,0);j<i;j++){
            if(tmp > ans[j]+abs(H[j]-H[i]))tmp=ans[j]+abs(H[j]-H[i]);
        }
        ans[i]=tmp;
        //cout << i << " " << ans[i] << endl;
    }
    cout << ans[n-1] << endl;

    return 0;
}

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

using namespace std;

void func_to_create(){
    unsigned int N, M;
     cin >> N >> M;
    unsigned int sum = 0;
    for(unsigned int i = 0 ; i < M ; i++){
        unsigned int a;
        cin >> a;
        sum += a;
    }

    if( sum > N){
        cout << -1 << endl;
    }else{
        cout << N - sum << endl;
    }
}
int main()
{
    //making data IO Fast
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    /****************************/

    func_to_create();
    
    return 0;
}


Measured memory_bytes: 3648
#include <iostream>
#include <vector>

using namespace std;

struct Node {
  int parent = -1;
  vector<int> childs;
};

int get_depth(int id, vector<Node> &tree) {
  int depth = 0;
  while (tree[id].parent != -1) {
    id = tree[id].parent;
    depth++;
  }
  return depth;
}

string get_info(int id, vector<Node> &tree) {
  if (tree[id].parent == -1) {
    return "root";
  }
  if ((tree[id].childs).size() == 0) {
    return "leaf";
  }
  return "internal node";
}

string show_child(int id, vector<Node> &tree) {
  string res = "";
  int child_num = tree[id].childs.size();
  for (int i = 0; i < child_num; i++) {
    res += to_string(tree[id].childs[i]);
    if (i != child_num - 1) {
      res += ", ";
    }
  }
  return res;
}

int main() {
  int n;
  cin >> n;

  vector<Node> tree(n);

  for (int i = 0; i < n; i++) {
    int id, k;
    cin >> id >> k;
    for (int j = 0; j < k; j++) {
      int c;
      cin >> c;
      tree[id].childs.push_back(c);
      tree[c].parent = id;
    }
  }

  for (int id = 0; id < n; id++) {
    cout << "node " << id << ": ";
    cout << "parent = " << tree[id].parent << ", ";
    cout << "depth = " << get_depth(id, tree) << ", ";
    cout << get_info(id, tree) << ", ";
    cout << "[" << show_child(id, tree) << "]";
    cout << endl;
  }
  return 0;
}


Measured memory_bytes: 7532
#include<iostream>
#include<complex>
#include<vector>
#include<cmath>
#define EPS 1e-8
using namespace std;

typedef complex<double> P;

class ufo{
public:
  P u;
  double r,v;
  ufo(double x,double y, double z,double w){u.real()=x;u.imag()=y;r=z;v=w;}
};

double dot(P a,P b){return real(conj(a)*b);}
double cross(P a,P b){return imag(conj(a)*b);}

int ccw(P a, P b, P c) {
  b-=a;c-=a;
  if(cross(b,c) > EPS)return +1;
  if(cross(b,c) < -EPS)return -1;
  if(dot(b,c) < -EPS)return +2;
  return 0;
}

bool cross_l_c(P a,P b,ufo c){
  double dis = abs(cross(b-a,c.u-a))/abs(b-a);
  if(dis>c.r+EPS)return false;
  P n = b*P(0,1) + c.u;
  P u = b/abs(b);
  P cp = a + (b-a)*cross(n-c.u,c.u-a) / cross(n-c.u,b-a);
  double len = sqrt(c.r*c.r-dis*dis);
  return (!ccw(a,b,cp+len*u) || !ccw(a,b,cp-len*u));
}

int main(){
  int n;
  double R,x,y,r,v;
  while(cin >> R >> n && (R || n)){
    vector<ufo> ob;
    for(int i=0;i<n;i++){
      cin >> x >> y >> r >>v;
      ob.push_back(ufo(x,y,r,v));
    }

    int ans = 0;
    while(ob.size()){
      P m(10000,10000);
      for(int i=0;i<(int)ob.size();i++){
	if(abs(ob[i].u)+EPS<ob[i].v)ob[i].u = P(0,0);
	else ob[i].u -= ob[i].u*ob[i].v/abs(ob[i].u);
      }

      for(int i=0;i<(int)ob.size();i++){
	if(abs(ob[i].u) < R+EPS){
	  ans++;
	  ob.erase(ob.begin()+i--);
	}else if(abs(ob[i].u)<abs(m)+EPS)m = ob[i].u;
      }

      P l = m*R/abs(m);
      for(int i=0;i<(int)ob.size();i++)
	if(cross_l_c(l,m,ob[i]))ob.erase(ob.begin()+i--);
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 0
from copy import deepcopy
N, A, B = map(int, input().split())
ABC = [tuple(map(int, input().split())) for _ in range(N)]
R = 500

dp = [[10**18] * R for _ in range(R)]
dp[0][0] = 0

for a, b, c in ABC:
    newDp = deepcopy(dp)
    for x in range(R):
        for y in range(R):
            if x + a < R and y + b < R:
                newDp[x + a][y + b] = min(newDp[x + a][y + b], dp[x][y] + c)
    dp = newDp

ans = 10**18
for x in range(1, R):
    for y in range(1, R):
        if B * x == A * y:
            ans = min(ans, dp[x][y])
print(ans if ans < 10**18 else -1)


Measured memory_bytes: 120412
#include <iostream>
#include <unordered_map>
using namespace std;
typedef long long int LLI;
int main()
{
	int n, max = 0, tmp, s1, s2, s3;
	cin >> n;
	unordered_map <int, int> arr;
	for(int i = 0; i < n; i++)
	{
		cin >> tmp;
		arr[tmp]++;
		s1 = arr[tmp-1] + arr[tmp] + arr[tmp+1];
		s2 = arr[tmp+2] + arr[tmp] + arr[tmp+1];
		s3 = arr[tmp-1] + arr[tmp] + arr[tmp-2];
		if( max < s1 )
			max = s1;
		if( max < s2 )
			max = s2;
		if( max < s3 )
			max = s3;
	}
	cout << max;
}

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

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

Measured memory_bytes: 3584
local s = io.read()
local n = #s
local a = {}
a.b, a.d, a.p, a.q = "d", "b", "q", "p"
if n % 2 == 1 then
  print("No")
else
  local r = true
  for i = 1, n // 2 do
    if a[s:sub(i, i)] ~= s:sub(n + 1 - i, n + 1 - i) then
      r = false
      break
    end
  end
  print(r and "Yes" or "No")
end


Measured memory_bytes: 760
#include<iostream>
#include<queue>
#include<string.h>
#include<limits.h>
#include<cstdio>
using namespace std;
const int MAXH = 1100;
const int INF = INT_MAX;
typedef pair<int, int> P;
int H,W,N;
char B[MAXH][MAXH];
int d[MAXH][MAXH];
int sx, sy;
int gx, gy;
int res;
int dx[5] = {1,0,-1,0};
int dy[5] = {0,1,0,-1};

void bfs()
{
	queue<P> que;
	que.push(P(sx,sy));
	d[sx][sy] = 0;
	
	while(que.size())
	{
		P p = que.front(); que.pop();
		
		if(p.first== gx && p.second == gy)break;
		for(int i = 0; i<4;i++)
		{
			int nx = p.first+ dx[i], ny = p.second + dy[i];

			if(B[nx][ny] != 'X' && d[nx][ny] ==INF)
				{
				que.push(P(nx,ny));
				d[nx][ny] = d[p.first][p.second] + 1;

				}
		}	
	}
	res+= d[gx][gy];
}

void rest()
{
	for(int i = 1; i<= W;i++)
		for(int j = 1; j<= H; j++)
			d[i][j] = INF;
}
void solve()
{
	for(int che = 1; che <= N; che++)
		for(int i = 1 ; i<= W;i++)
			for(int j = 1; j <= H; j++)
			{
				if(B[i][j] - '0' == che)
				{
					rest();
					gx = i; gy = j;
					bfs();
					sx = gx; sy = gy;
				}
			}	
	cout << res << endl;
}

int main()
{
	
	cin >>H>>W>>N;
	memset(B,'X',sizeof(B));
	for(int j = 1 ; j<= H;j++)
	{
		for(int i = 1; i <= W; i++)
		{
			cin >> B[i][j];
			if(B[i][j] == 'S')
				{sx = i; sy = j;}
		}	
		getchar();
	}

	res = 0;	
	solve();
	
}

Measured memory_bytes: 8624
using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApp23
{
    class Program
    {

        static void Main(string[] args)
        {
            // var line = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var line = Console.ReadLine().Split(' ');
            var r = line[0];
            var g = line[1];
            var b = line[2];


            if(int.Parse(r + g + b) % 4 == 0)
            {
                Console.WriteLine("YES");
            }
            else
            {
                Console.WriteLine("NO");
            }

        }


    }

}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f
#define CLR(x,y) memset(x,y,sizeof(x))
#define LC(x) (x<<1)
#define RC(x) ((x<<1)+1)
#define MID(x,y) ((x+y)>>1)
typedef pair<int, int> pii;
typedef long long LL;
const double PI = acos(-1.0);
const int N = 100010;
struct info
{
	int pre, d;
} A[N];

void init()
{
	for (int i = 0; i < N; ++i)
	{
		A[i].pre = i;
		A[i].d = 0;
	}
}
inline int Find(int n)
{
	if(A[n].pre == n)
		return n;
	int tpre = A[n].pre;
	A[n].pre = Find(A[n].pre);
	A[n].d += A[tpre].d;
	return A[n].pre;
}
inline int Merge(int a, int b, int c)
{
	int fa = Find(a), fb = Find(b);
	if(fa == fb)
		return abs(A[a].d - A[b].d) == c;
	else
	{
		A[fa].pre = fb;
		A[fa].d = (c + A[b].d - A[a].d);
		return 1;
	}
}
int main(void)
{
	int n, m, a, b, i;
	while (~scanf("%d%d", &n, &m))
	{
		init();
		int flag = 1;
		while (m--)
		{
			int c;
			scanf("%d%d%d", &a, &b, &c);
			if(flag)
				flag &= Merge(a, b, c);
		}
		puts(flag ? "Yes" : "No");
	}
	return 0;
}


Measured memory_bytes: 1024
def main():
    import sys
    input = sys.stdin.readline

    class Bit:
        def __init__(self, n):
            self.size = n
            self.tree = [0] * (n + 1)

        def sum(self, i):
            s = 0
            while i > 0:
                s += self.tree[i]
                i -= i & -i
            return s

        def add(self, i, x):
            while i <= self.size:
                self.tree[i] += x
                i += i & -i

    N = int(input())
    S = input().rstrip('\n')
    Q = int(input())

    S = [s for s in S]

    bit = [Bit(N) for _ in range(26)]
    for i, s in enumerate(S):
        j = ord(s) - 97
        bit[j].add(i+1, 1)
    for _ in range(Q):
        flg, l, r = input().split()
        if flg == '1':
            i = int(l)
            c = r
            si = S[i-1]
            bit[ord(si)-97].add(i, -1)
            bit[ord(c)-97].add(i, 1)
            S[i-1] = c
        else:
            l = int(l)
            r = int(r)
            ans = 0
            for j in range(26):
                if bit[j].sum(r) - bit[j].sum(l-1):
                    ans += 1
            print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 165996
<?php
$n = trim(fgets(STDIN));
if($n >= 64){
echo 64;
}elseif($n >= 32){
echo 32;
}elseif($n >= 16){
echo 16;
}elseif($n >= 8){
echo 8;
}elseif($n >= 4){
echo 4;
}elseif($n >= 2){
echo 2;
}else{
echo 1;
}

Measured memory_bytes: 3700
// scanf 等でエラーを出さないように追加
#define _CRT_SECURE_NO_WARNINGS 1

#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <math.h>
#include <limits.h>
#include <iostream>
#include <string>
#include <vector>
#include <memory>
#include <algorithm>
#include <numeric>
#include <set>

#include <functional>


using namespace std;


typedef long long ll;


int main() {

	int N;
	scanf("%d\n", &N);

	vector<int> L = vector<int>();
	for (int i = 1; i <= 2 * N; i++) {
		int l;
		scanf("%d", &l);
		L.push_back(l);
	}

	sort(L.begin(), L.end(), greater<int>());


	ll result = 0;
	for (int i = 1; i < 2 * N; i += 2) {
		result += L[i];
	}

	printf("%lld\n", result);

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define maxn 5010
using namespace std;
struct people{
	int h,p;
	void scan(){scanf("%d%d",&h,&p);}
	int operator<(const people& a)const{
		return p+h<a.p+a.h;
	}
}A[maxn];
int n,ans;
long long dp[maxn];
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i)A[i].scan();
	sort(A+1,A+n+1);
	memset(dp,0x3f,sizeof(dp));
	dp[0]=0;
	for(int i=1;i<=n;++i)
		for(int j=i;j>=0;--j)if(dp[j]<=A[i].h)
			dp[j+1]=min(dp[j+1],dp[j]+A[i].p);
	for(int i=n;i>=1;--i)if(dp[i]!=0x3f3f3f3f3f3f3f3fll)return printf("%d",i),0;
} 

Measured memory_bytes: 896
#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;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<long long int> vl;
typedef vector<vector<int>> vvi;
typedef vector<vector<long long int>> vvl;
typedef pair<int, int> pii;
typedef pair<long long int, long long int> pll;
typedef vector<pair<int, int>> vii;
typedef vector<pair<long long int, long long int>> vll;
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define test() long long int t; cin >> t; cin.ignore(); while(t--) 
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define MOD 1000000007
#define SMOD 998244353
#define pq priority_queue
#define all(x) x.begin(),x.end()
#define SP(x) setprecision(x)
#define sp " "
#define inp(a) ll a;cin>>a;cin.ignore()
#define inps(a,b) ll a,b;cin>>a>>b;cin.ignore()
#define out(a) cout<<SP(20)<<a<<'\n'
#define outs(a,b) cout<<SP(20)<<a<<" "<<b<<'\n'
#define ins insert
#define er erase
#define lb lower_bound
#define ub upper_bound
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
#define inpa(a,n) ll a[n]; for(int i=0; i<n; i++){cin>>a[i];}
#define inpv(a,n) vl a; for(int i=0; i<n; i++){inp(x);a.pb(x);}
#define outa(a,n) for(int i=0;i<n;i++){cout<<a[i]<<" ";}cout<<'\n';
#define outv(v) for(auto i:v){cout<<i<<" ";}cout<<'\n';
set<char> vow = {'a','e','i','o','u','A','E','I','O','U'};
ll xpow(ll n, ll m){if(m==0){return 1;}else{ll x = xpow(n, m/2);if(m&1){return x*x*n;}else{return x*x;}}}
ll xmod(ll a, ll m){return (((a%m)+m)%m);}
ll xmodpow(ll n, ll m, ll y){if(m==0){return 1;}else{ll x = xmodpow(n, m/2, y);if(m&1){return xmod((xmod((xmod(x,y)*xmod(x,y)),y)*xmod(n,y)),y);}else{return xmod((xmod(x,y)*xmod(x,y)),y);}}}
 
int main(){
    fast();
 
/* you get what you work for not what you wish for */
    
    inpv(a, 3);
    ll sum = 0;
    for(auto i:a){
        sum+=i;
    }
    if(sum>=22){
        cout << "bust" << endl;
    }
    else{
        cout << "win" << endl;
    }
}

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

int main()
{
    int N,K;
    cin >> N >> K;
    int j[N],dp[N];
    for(int i=0;i<N;i++)
    {
        cin >> j[i];
    }
    memset(dp,1000000,sizeof(dp));

    dp[0]=0;
    // dp[1]=abs(j[1]-j[0]);
    // int ind,val;
    for(int i=1;i<N;i++)
    {
        for(int r = 1; r<=min(i,K);r++)
        {
            dp[i] = min(dp[i-r] + abs(j[i] - j[i-r]), dp[i]);
        }
    }

    cout << dp[N-1] << endl;
    
    return 0;
}

Measured memory_bytes: 4380
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<string>
#include<map>
#include<cmath>
#include<iomanip>
#include<math.h>
#include<vector>
#define rep(i, n) for(int i=0; i<n; i++)
using namespace std;
typedef long long ll;

int main(){
    ll n; cin >> n;
    vector<int> p;
    ll ans = 0;
    ll limit = 1000001;
    // int(sqrt(n))+1;
    int sosu[limit];

    rep(i, limit) sosu[i]=1;
    
    // sosu[i] = 1 if i in prime_number else 0
    for(int i=2;i<limit;i++){
        ll j=i*2;
        while(j<limit){
            sosu[j]=0;
            j += i ;
        }
    }
    
    // prime factorization
    for(int i=2; i<limit; i++){
        if(sosu[i]==0) continue;
        if(n%i == 0){
            ll e = 0;
            while(n%i == 0){
                e++;
                n /= i;
            }
            // cout << "i=" << i <<" ee=" << ee << endl;
            p.push_back(e);
        }
    }

    if(n != 1) p.push_back(1);

    // if n in prime_number
    if(p.empty()){
        if(n==1) cout << 0 << endl;
        else cout << 1 << endl;
        return 0;
    }

    // get answer
    for(auto i : p){
        ll count = 0;
        while(count < i){
            count++;
            i -= count;
        }
        ans += count;
    }
    cout << ans << endl;
}

Measured memory_bytes: 7544
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int cnt=0,i,j;
    string s;
    cin>>s;
    int l=s.size();
    j=l-1;
    for(i=0; i<l/2; i++)
    {
        if(s[i]!=s[j])
        {
            cnt++;
        }
        j--;
    }
    cout<<cnt<<endl;
    return 0;
}


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

using namespace std;

typedef struct{
	int n;
	int species;
} coord_t;

typedef struct{
	int xl;
	int xr;
	int yl;
	int yr;
	int zl;
	int zr;
} fish_t;

int comp(const void *c1, const void *c2);

int main(){
	int N;
	int K;

	//魚の種類数と数える種類数を入力
	cin >> N >> K;

	coord_t *X = new coord_t[2*N];
	coord_t *Y = new coord_t[2*N];
	coord_t *Z = new coord_t[2*N];

	//座標を入力
	for(int i=0; i<N; i++){
		cin >> X[2*i].n >> Y[2*i].n >> Z[2*i].n >> X[2*i+1].n >> Y[2*i+1].n >> Z[2*i+1].n;
		X[2*i].species = 0;
		X[2*i+1].species = 0;
		Y[2*i].species = 0;
		Y[2*i+1].species = 0;
		Z[2*i].species = 0;
		Z[2*i+1].species = 0;
	}

	fish_t *fish = new fish_t[N];
	
	//各魚の生息領域を代入
	for(int i=0; i<N; i++){
		int L = 2*i;
		int R = 2*i+1;

		fish[i].xl = X[L].n;
		fish[i].xr = X[R].n;
		fish[i].yl = Y[L].n;
		fish[i].yr = Y[R].n;
		fish[i].zl = Z[L].n;
		fish[i].zr = Z[R].n;
	}

	//座標を小さい順に並べ替える
	qsort(X, 2*N, sizeof(coord_t), comp);
	qsort(Y, 2*N, sizeof(coord_t), comp);
	qsort(Z, 2*N, sizeof(coord_t), comp);

	int dim = 2*N - 1;

	//各ブロックの魚の種類を数え、K種類以上の体積を求める
	unsigned long long V = 0;
	for(int z=0; z<dim; z++){
		for(int y=0; y<dim; y++){
			for(int x=0; x<dim; x++){
				int k = 0;

				for(int i=0; i<N; i++){
					if( (fish[i].xl > X[x].n) || (fish[i].xr < X[x+1].n) || (fish[i].yl > Y[y].n) || (fish[i].yr < Y[y+1].n) || (fish[i].zl > Z[z].n) || (fish[i].zr < Z[z+1].n) ){ continue; }
					else{ k++; }
				}
				
				if(k < K){ continue; }
				else{
					V += (unsigned long long) (X[x+1].n - X[x].n) * (Y[y+1].n - Y[y].n) * (Z[z+1].n - Z[z].n);
				}
			}
		}
	}

	cout << V << endl;
	
	delete[] X;
	delete[] Y;
	delete[] Z;
	delete[] fish;

	return 0;
}

int comp(const void *c1, const void *c2){
	coord_t coord1 = *(coord_t*)c1;
	coord_t coord2 = *(coord_t*)c2;

	int tmp_n1 = coord1.n;
	int tmp_n2 = coord2.n;

	int tmp_s1 = coord1.species;
	int tmp_s2 = coord2.species;

	int c = tmp_n1 - tmp_n2;

	if(c == 0){ c = tmp_s1 - tmp_s2; }

	return c;
}

Measured memory_bytes: 1200
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>

using namespace std;

int main() {
    int n, x, m[100], mm = 1001;
    cin >> n >> x;
    for (int i = 0; i < n; ++i) {
        cin >> m[i];
        x -= m[i];
        mm = min(mm, m[i]);
    }

    cout << n + x / mm << endl;
    
    return 0;
}


Measured memory_bytes: 256