akhauriyash/Code-Regression huggingface dataset:
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    ll n = (ll)s.size()+1;
    vll a(n,-1LL);
    ll ans = 0;
    vll v;
    if(s[0]=='<'){
        v.pb(0);
    }
    REP(i,n-2){
        if(s[i]=='>'&&s[i+1]=='<'){
            v.pb((ll)i+1);
        }
    }
    if(s[n-2]=='>'){
        v.pb(n-1);
    }
    for(ll i:v){
        a[i]=0;
        ll now = i-1;
        while(now>=0){
            if(s[now]=='<')break;
            a[now]=max(a[now+1]+1,a[now]);
            now--;
        }
        now=i+1;
        while(now<n){
            a[now]=max(a[now],a[now-1]+1);
            if(s[now]=='>') break;
            now++;
        }
    }
    /*
    REP(i,n){
        cout << a[i] << endl;
    }
    */
    REP(i,n) ans+=a[i];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6172
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;

namespace AOJV0
{
    class P0002
    {
        static void Main()
        {
            foreach(var s in EnumerateInputs()
                            .Select(x => x.Split(' '))
                            .Select(x => x.Select(int.Parse))
                            .Select(x => new {X = x.First(), Y = x.Skip(1).First()}))
                Console.WriteLine((s.X + s.Y).ToString().Length);
        }

        static IEnumerable<string> EnumerateInputs()
        {
            while(true)
            {
                var s = Console.In.ReadLine();
                if(s == null)
                    break;
                yield return s;
            }
        }
    }
}

Measured memory_bytes: 5960
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007

int main() {

  int H,W;
  cin >> H >> W;

  vector<vector<int>> A(H,vector<int>(W)),B(H,vector<int>(W));
  bool dp[90][90][13000] = {false};

  for(int i = 0;i < H;i++) {
    for(int j = 0;j < W;j++) {
      cin >> A.at(i).at(j);
    }
  }

  for(int i = 0;i < H;i++) {
    for(int j = 0;j < W;j++) {
      cin >> B.at(i).at(j);
    }
  }

  dp[0][0][abs(A[0][0]-B[0][0])] = true;

  for(int i = 0;i < H;i++) {
    for(int j = 0;j < W;j++) {
      for(int k = 0;k < 13000;k++) {
        if(dp[i][j][k]) {

          if(i < H-1) {
            dp[i+1][j][k+abs(A[i+1][j]-B[i+1][j])] = true;
            dp[i+1][j][abs(k-abs(A[i+1][j]-B[i+1][j]))] = true;
          }
          
          if(j < W-1) {
            dp[i][j+1][k+abs(A[i][j+1]-B[i][j+1])] = true;
            dp[i][j+1][abs(k-abs(A[i][j+1]-B[i][j+1]))] = true;
          }

        }
      }
    }
  }

  for(int i = 0;i < 13000;i++) {
    if(dp[H-1][W-1][i]) {
      cout << i << endl;
      return 0;
    }
  }

}


Measured memory_bytes: 103168
import java.util.Scanner;
import java.lang.Math;

class Main{
	static public  void main(String args[]){
		Scanner sc = new Scanner(System.in);
		sc.useDelimiter("\\s");
		double x1 = sc.nextDouble();
		double y1 = sc.nextDouble();
		double x2 = sc.nextDouble();
		double y2 = sc.nextDouble();

		double distance=0;

		double distance_x = Math.pow((x2-x1),2.0);
		double distance_y = Math.pow((y2-y1),2.0);
		distance = Math.sqrt(distance_x+distance_y); 
		System.out.printf("%.8f\n",distance);
		
	}
}

Measured memory_bytes: 28148
#![allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}
fn read_vec2<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
fn main() {
    let a: Vec<i64> = read_vec();
    println!("{}", vec![a[0] * a[2], a[0] * a[3], a[1] * a[2], a[1] * a[3]].into_iter().max().unwrap());
}


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

using namespace std;

struct unionfind
{
	//rankのオーバーフローに注意
	vector<int> par, rank;
	unionfind(int n)
	{
		par.resize(n);
		rank.resize(n);
		for (int i = 0; i < n; i++)
		{
			par[i] = i;
			rank[i] = 1;
		}
	}

	bool same(int u, int v)
	{
		return root(u) == root(v);
	}

	void unite(int u, int v)
	{
		u = root(u), v = root(v);
		if (u == v) return;
		if (rank[u] > rank[v]) swap(u, v);
		par[u] = v;
		rank[v] += rank[u];
	}

	int root(int v)
	{
		if (par[v] == v) return v;
		return par[v] = root(par[v]);
	}
};

void solve(void)
{
	int n, m;
	cin >> n >> m;
	unionfind uf(n);
	while(m--)
	{
		int x, y, z;
		cin >> x >> y >> z;
		uf.unite(x-1, y-1);
	}
	set<int> s;
	for (int i = 0; i < n; i++)
	{
		s.insert(uf.root(i));
	}
	cout << (int)s.size() << endl;
}

int main()
{
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


Measured memory_bytes: 5760
import Data.List
import qualified Data.Set as S

main = do
    [a,b,c] <- sort.map read.words<$>getLine :: IO [Int]
    print $ sol 0 [[a,b,c]]

sol n as =
    case findIndex (\[a,b,c] -> a==b && b==c) as of
        Just _ -> n
        Nothing ->
            sol (n+1) nas
            where
                nas = S.toList $ S.fromList ops
                ops = concatMap (\[a,b,c] -> [sort [a+1,b+1,c], sort [a+2,b,c]]) as



Measured memory_bytes: 892
#include<stdio.h>
int f(int n){
	for(int i=2;i*i<=n;i++)if(n%i==0)return 0;
	return 1;
}
int main(){
	int n,ans=0,t;
	scanf("%d",&n);
	while(n--){
		scanf("%d",&t);
		ans+=f(t);
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 2104
fn main() {
  let (n, m): (usize, usize) = get::tuple();

  let ans = (1900*m + 100*(n-m)) * 2usize.pow(m as u32);
  println!("{}", ans)
}

#[allow(dead_code)]
mod get {
  use std::io::*;
  use std::str::*;

  pub fn val<T: FromStr>() -> T {
    let mut buf = String::new();
    let s = stdin();
    s.lock().read_line(&mut buf).ok();
    buf.trim_right().parse::<T>().ok().unwrap()
  }

  pub fn vals<T: FromStr>(n: usize) -> Vec<T> {
    let mut vec: Vec<T> = vec![];
    for _ in 0 .. n {
      vec.push(val());
    }
    vec
  }

  pub fn tuple<T1: FromStr, T2: FromStr>() -> (T1, T2) {
    let mut buf = String::new();
    let s = stdin();
    s.lock().read_line(&mut buf).ok();
    let mut it = buf.trim_right().split_whitespace();
    let x = it.next().unwrap().parse::<T1>().ok().unwrap();
    let y = it.next().unwrap().parse::<T2>().ok().unwrap();
    (x, y)
  }

  pub fn tuples<T1: FromStr, T2: FromStr>(n: usize) -> Vec<(T1, T2)> {
    let mut vec: Vec<(T1, T2)> = vec![];
    for _ in 0 .. n {
      vec.push(tuple());
    }
    vec
  }

  pub fn tuple3<T1: FromStr, T2: FromStr, T3: FromStr>() -> (T1, T2, T3) {
    let mut buf = String::new();
    let s = stdin();
    s.lock().read_line(&mut buf).ok();
    let mut it = buf.trim_right().split_whitespace();
    let x = it.next().unwrap().parse::<T1>().ok().unwrap();
    let y = it.next().unwrap().parse::<T2>().ok().unwrap();
    let z = it.next().unwrap().parse::<T3>().ok().unwrap();
    (x, y, z)
  }

  pub fn tuple3s<T1: FromStr, T2: FromStr, T3: FromStr>(n: usize) -> Vec<(T1, T2, T3)> {
    let mut vec: Vec<(T1, T2, T3)> = vec![];
    for _ in 0 .. n {
      vec.push(tuple3());
    }
    vec
  }

  pub fn list<T: FromStr>() -> Vec<T> {
    let mut buf = String::new();
    let s = stdin();
    s.lock().read_line(&mut buf).ok();
    buf.trim_right().split_whitespace().map(|t| t.parse::<T>().ok().unwrap()).collect()
  }

  pub fn lists<T: FromStr>(h: usize) -> Vec<Vec<T>> {
    let mut mat: Vec<Vec<T>> = vec![];
    for _ in 0 .. h {
      mat.push(list());
    }
    mat
  }

  pub fn chars() -> Vec<char> {
    let mut buf = String::new();
    let s = stdin();
    s.lock().read_line(&mut buf).ok();
    buf.trim_right().chars().collect()
  }
}


Measured memory_bytes: 4352
import numpy as np
n, k = map(int, input().split())
m = n**2
mod = 10**9+7
dp = np.zeros((n+1, n+1, m+1), dtype=np.int64)
dp[0,0,0] = 1
for i in range(1, n+1):
  for j in range(i+1):
    dp[i,j,2*j:] = (2*j+1)*dp[i-1,j,:m+1-2*j]
    if j+1 <= i-1:
      dp[i,j,2*j:] += (j+1)*(j+1)*dp[i-1,j+1,:m+1-2*j]
    if j:
      dp[i,j,2*j:] += dp[i-1,j-1,:m+1-2*j]
    dp[i,j,2*j:] %= mod
ans = dp[n,0,k]
print(ans)

Measured memory_bytes: 52872
#include <iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<string>
#include<map>
#include<queue>
using namespace std;

int main() {
	long long n;
	cin >> n;
	long long a = 0;
	long long b = 0;
	for (long long i = 1; i * i <= n; i++) {
		if (n % i == 0) {
			a = i;
			b = n / i;
		}
	}
	if (a == 0 && b == 0) {
		a = n;
		b = 1;
	}
	long long ans = (a - 1) + (b - 1);
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

int main()
{
  string s1, s2, s3;
  cin >> s1 >> s2 >> s3;
  s1[0] = s1[0] + 'A' - 'a';
  s2[0] = s2[0] + 'A' - 'a';
  s3[0] = s3[0] + 'A' - 'a';

  cout << s1[0] << s2[0]  << s3[0] << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
using ll = long long;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll ai, ao, aj, al, tmp;
  rep(i, 7) cin >> ai >> ao >> tmp >> aj >> al >> tmp >> tmp;
  ll k = ao+ai/2*2+aj/2*2+al/2*2+min({ai%2, aj%2, al%2})*3;
  if (min({ai, aj, al}) > 0) {
    ll res = 3;
    --ai, --aj, --al;
    res += ao+ai/2*2+aj/2*2+al/2*2+min({ai%2, aj%2, al%2})*3;
    chmax(k, res);
  }
  cout << k << endl;
  return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define UM unordered_map
#define ALL(a) (a).begin(), (a).end()
typedef vector<ll> vi;
typedef vector<vector<ll>> vvi;
typedef pair<ll, ll> pii;
const long long INF = 1LL << 58;
struct Edge
{
    ll s, t, d;
};
typedef vector<vector<Edge>> Graph;
typedef vector<pii> vpii;
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}

signed main()
{
    int N;
    cin >> N;
    vi b;
    b.resize(N);
    REP(i, N)
    cin >> b[i];

    int tmp;
    vi ans;
    while (true)
    {
        if (ans.size() == N)
            break;
        tmp = -1;
        REP(i, b.size())
        {
            if (b[i] == i + 1)
                tmp = i;
        }
        if (tmp == -1)
            break;

        ans.push_back(b[tmp]);
        b.erase(b.begin() + tmp);
    }
    if (ans.size() == N)
    {
        REP(i, N)
        cout << ans[N - 1 - i] << endl;
    }
    else
        cout << -1 << endl;

    // system("pause");
}


Measured memory_bytes: 256
//https://atcoder.jp/contests/abc137/tasks/abc137_e
#include<bits/stdc++.h>
using namespace std;
const int N=3000;
int n,m,p;
struct edge
{
	int u,v,w;
};
vector<int>G[N];
vector<edge>es;
bool vis[N]; 
int dis[N]; 
int dfs(int x)//判断能否走到终点 
{
	vis[x]=1;
	if(x==n)return 1;
	for(auto y:G[x])
	{
		if(vis[y]==0&&dfs(y))
		 return 1; 
	}
	return 0;
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0); 
	cin>>n>>m>>p;
	for(int i=1,x,y,w;i<=m;i++)
	{
		cin>>x>>y>>w;
		es.push_back({x,y,-(w-p)});//负权相当于求最短路 
		G[x].push_back(y);
	}
	memset(dis,0x3f,sizeof dis);
	dis[1]=0;
	for(int i=1;i<=2*n-1;i++)
	{
		for(auto & e:es)
		{
			int v=e.v,w=e.w,u=e.u; 
			if(dis[u]==0x3f3f3f3f) continue;
			if(dis[v]>dis[u]+w)
			{
				dis[v]=dis[u]+w; 
				if(i>=n&&vis[v]==0&&dfs(v))
				{
					cout<<-1<<endl;
					return 0;
				} 
			} 
		}
	}
	cout<<max(0,-dis[n])<<endl;
	return 0;
} 

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

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;

using namespace std;
using ll = long long;

template<typename T=int>
T in(){T x; cin >> x; return (x);}

vector<int> l;
int N,A,B,C;
const int INF=1e9;

int MP(int pos,int a,int b,int c){
  if(pos==N){
    return min({a,b,c})>0 ? abs(a-A)+abs(b-B)+abs(c-C)-30 : INF;
  }
  int res0 = MP(pos+1,a,b,c);
  int res1 = MP(pos+1,a+l[pos],b,c)+10;
  int res2 = MP(pos+1,a,b+l[pos],c)+10;
  int res3 = MP(pos+1,a,b,c+l[pos])+10;
  return min({res0,res1,res2,res3});
}

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

  N=in(),A=in(),B=in(),C=in();
  l.resize(N);
  REP(i,N){
    l[i]=in();
  }
  
  cout << MP(0,0,0,0) << endl;
  return 0;
}


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

#define rep(i,n) for(int i=0;i<(n);i++) 
#define rep1(i,n) for(int i=1;i<(n);i++)
#define co(x) cout << x << endl
#define cosp(x) cout << x << " "

using namespace std;
using ll = long long;

int main(int argc, const char *argv[]){
    int n ;
    cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    ll ans = 0;
    ll m = abs(a[0]); 
    bool zero = false;
    rep(i,n){
        m = min(m,abs(a[i]));
        ans += abs(a[i]);
        if((i!=(n-1))&&(a[i]<0)) a[i+1] *= -1;
    }
    if(a[n-1]<0) ans -= 2*m;
    co(ans);
    return 0;
}

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

//

#define RESIDUE(u,v) (capacity[u][v] - flow[u][v])
#define RCOST(u,v) (cost[u][v] + h[u] - h[v])
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define LL long long

int n;
int a[10000];

int main(){
  cin>>n;
  REP(i,n)
    cin>>a[i];

  int ret=0,ind=1;

  while(ind<n){
    if(a[ind]==a[ind-1]){
      ret++;
      a[ind]=-1;
    }
    ind++;
  }
  
  cout<<ret<<endl;
  
  return 0;
}


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

int main() {
    int N;
    cin >> N;
    vector<int> h(N);
    for (int i=0;i<N;i++){
        cin >> h.at(i);
    }
    int cnt=0;
    for (int i=1;i<N;i++){
        int flg=0;
        for (int j=0;j<i;j++){
            if(h.at(i)<h.at(j)) flg=1;
        }
        if(flg==0) cnt++;
    }
    cout << cnt+1 << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main {

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

    int N = sc.nextInt();
    int Y = sc.nextInt();
    for (int a = 0; a <= N; a++) {
      for (int b = 0; a + b <= N; b++) {
        int c = N - (a + b);
        if (10000 * a + 5000 * b + 1000 * c == Y) {
          System.out.println(a + " " + b + " " + c);
          return;
        }
      }
    }
    System.out.println("-1 -1 -1");
  }
}


Measured memory_bytes: 21972
#include<stdio.h>

int main(){
  int N;
  int a[100];
  int i;
  
  scanf("%d",&N);
  for(i=0;i<N;i++){
    scanf("%d",&a[i]);
  }

  int pa=0;
  int pb=0;
  int j=0;

  for(j=0;j<N;j++){
    int max=a[0];
    int max_index=0;
    for(i=1;i<N;i++){
      if(a[i]>max){
		max=a[i];
		max_index=i;
      }
    }
    if(j%2){
      pb+=a[max_index];
    }else{
      pa+=a[max_index];
    }
    a[max_index]=0;
  }

  printf("%d",pa-pb);
  return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<typeinfo>
#include<vector>
#include<algorithm>
#include<map>
#include<iomanip>
using namespace std;
int main()
{
	char c[4];
  	for(int i=0; i<4; i++){
		cin >> c[i];
    }
	if(c[0]==c[1] && c[1]==c[2]){
		cout << "Yes" << endl;
    }else if(c[1]==c[2] && c[2]==c[3]){
		cout << "Yes" << endl;
    }else{
		cout << "No" << endl;
    }

	return 0;
}

Measured memory_bytes: 768
// Reads multiple ints in a line, separate by a space.
// It works even if the actual number of ints is smaller than n.
// WARNING: This function does not work for -2^31.
// NOTE: This function does not handle error cases.
fun fastReadInts(n: Int): IntArray {
  val xs = IntArray(n)
  val s = readLine()!!
  var currentValue = 0
  var isNegative = false
  var currentIndex = 0
  for (c in s) {
    if (c == ' ') {
      xs[currentIndex] = currentValue * if (isNegative) -1 else 1
      currentValue = 0
      isNegative = false
      currentIndex++
    } else if (c == '-') {
      isNegative = true
    } else {
      currentValue *= 10
      currentValue += c - '0'
    }
  }
  xs[currentIndex] = currentValue * if (isNegative) -1 else 1
  return xs
}

fun filterList(es: List<IndexedValue<Int>>): List<IndexedValue<Int>> {
  val sortedEs = es.toMutableList().sortedByDescending { it.value }
  val output = mutableListOf<IndexedValue<Int>>()
  output.add(sortedEs[0])
  output.add(sortedEs.first { it.index != sortedEs[0].index })
  return output
}

fun main(args: Array<String>) {
  val n = readLine()!!.toInt()
  val xs = fastReadInts(1 shl n)
  val ys = Array(1 shl n , { listOf<IndexedValue<Int>>() })
  ys[0] = listOf(IndexedValue(0, xs[0]))
  ys[1] = listOf(IndexedValue(0, xs[0]), IndexedValue(1, xs[1]))
  for (k in 2 until (1 shl n)) {
    val list = mutableListOf(IndexedValue(k, xs[k]))
    for (i in 0 until 20) {
      if (k or (1 shl i) == k) {
        list.addAll(ys[k - (1 shl i)])
      }
    }
    // println("k: $k list: $list")
    val filtered = filterList(list)
    ys[k] = filtered
  }

  val zs = ys.map { it.sumBy { it.value } }
  val ws = IntArray(1 shl n)
  for (k in 1 until (1 shl n)) {
    ws[k] = Math.max(ws[k - 1], zs[k])
  }

  val output = StringBuilder()
  for (k in 1 until (1 shl n)) {
    output.append(ws[k])
    output.append('\n')
  }

  print(output)
}

Measured memory_bytes: 154068
#!/usr/bin/env python

from collections import deque
import itertools as it
import sys
import math

sys.setrecursionlimit(1000000)

N, K = map(int, raw_input().split())
DP = [[0] * (K + 1) for i in range(K + 1)]
bias = 0

for i in range(N):
    x, y, c = raw_input().split()
    x, y, c = int(x), int(y), (c == 'W')
    p = (x / K + y / K + c) % 2
    DP[y % K + 1][x % K + 1] += 1 - 2 * p
    bias += p

for i in range(K):
    for j in range(K + 1):
        DP[i + 1][j] += DP[i][j]

for i in range(K + 1):
    for j in range(K):
        DP[i][j + 1] += DP[i][j]

ans = 0

for i in range(K + 1):
    for j in range(K + 1):
        S = DP[i][K] + DP[K][j] - DP[i][j] * 2
        ans = max(ans, S, DP[K][K] - S)

print ans + bias

Measured memory_bytes: 23268
/* author: jeetganatra */

#include<bits/stdc++.h>
using namespace std;
 
#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define fo(i,n)         for(int i=0;i<n;i++)
#define Fo(i,k,n)       for(int i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define tr(it, a)       for(auto it = a.begin(); it != a.end(); it++)
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             998244353
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define pw(b,p)         pow(b,p) + 0.1
#define deb(x)          cout << #x << "=" << x << endl
#define deb2(x, y)      cout << #x << "=" << x << "," << #y << "=" << y << endl
#define all(x)          x.begin(), x.end()
#define clr(x)          memset(x, 0, sizeof(x))
#define sortall(x)      sort(all(x))
#define endl            "\n"
#define PI              3.14159265
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

 
void jpg()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}

int mpow(int base, int exp); 


                                                                                                                                                                                                                             
int32_t main()
{
	jpg();
	int n,k;
	cin>>n>>k;
	vi a(n);
	fo (i,n)cin>>a[i];
	sortall(a);
	int ans=0;
	fo (i,k)
	{
		ans+=a[i];
	}

	cout<<ans<<endl;
}


int mpow(int base, int exp) {
  base %= mod;
  int result = 1;
  while (exp > 0) {
    if (exp & 1) result = ((int)result * base) % mod;
    base = ((int)base * base) % mod;
    exp >>= 1;
  }
  return result;
}



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

#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define for1(i, n) for (int i = 1; i <= int(n); ++i)
#define ms(a, x) memset(a, x, sizeof(a))
#define F first
#define S second
#define all(x) (x).begin(),(x).end()

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 0x3f3f3f3f;
mt19937 gen(random_device{}());
template<typename... Args> void write(Args... args) { ((cout << args << " "), ...); cout<<endl;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin>>n;
    vector<int> a(n);
    for(auto& it:a) cin>>it;
    int buf=(n&1?3:2);
    vector<vector<ll>> dp(n+1,vector<ll>(buf,-1e18));
    dp[0][0]=0;
    forn(i,n){
        forn(j,buf){
            dp[i+1][j]=max(dp[i+1][j],dp[i][j]+((i+j)%2==0?a[i]:0));
            if(j+1<buf) dp[i+1][j+1]=max(dp[i+1][j+1],dp[i][j]);
        }
    }
    cout<<dp[n][buf-1];
    return 0;
}



Measured memory_bytes: 15060
#include <stdio.h>
int main() {int RideBack[605];int i,j;for (i=0;i<600;RideBack[i]=i*i,i++);while (scanf("%d",&i)!=EOF) {int ans=0;for (j=0;j<600;j+=i) ans+=RideBack[j]*i;printf("%d\n",ans);}return 0;}

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

public class Hello
{
    public static void Main()
    {
        while (true)
        {
            string[] line = Console.ReadLine().Trim().Split(' ');
            var n = int.Parse(line[0]);
            var m = int.Parse(line[1]);
            if (n == 0 && m == 0) break;
            var q = new Queue<int>();
            foreach (var x in Enumerable.Range(1, n))  q.Enqueue(x);
            while (q.Count()>=2)
            {
                for (int i = 0; i < m - 1; i++)
                    q.Enqueue(q.Dequeue());
                q.Dequeue();
            }
            Console.WriteLine(q.Dequeue());
        }
    }
}

Measured memory_bytes: 10480
#import numpy as np
n = int(input())
#ds = np.array([int(x) for x in input().split()])
ds = [int(x) for x in input().split()]
ds2 = [x*x for x in ds]
#dss = ds * sum(ds)
#print((sum(ds * sum(ds)) - sum(ds ** 2)) / 2 )
print(int((sum(ds * sum(ds)) - sum(ds2)) / 2 ))

Measured memory_bytes: 4980
#include<stdio.h>
#include<string.h>
int main()
{
    int n,i,h=0;
    char s[101];
    scanf("%s",&s);
    n=strlen(s);
    for(i=0;i<n/2;i++)
    {
        if(s[i]!=s[n-1-i])
            h++;
    }
    printf("%d",h);
    return 0;
}

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

#define int long long

#define _   int v, int tl, int tr, int l, int r
#define tm  (tl + tr >> 1)
#define sol v+v, tl, tm, l, r
#define sag v+v+1, tm+1, tr, l, r
#define pb push_back
#define mp make_pair
#define st first
#define nd second
typedef pair < int , int > pp;
const int mod = 1e9 + 7;
const int N   = 2e5 + 5;

int A[N],n;

int f(int k){
    int ret = 0;
    for(int i=1; i<=n; i++)
        ret += abs(k+i-A[i]);
    return ret;
}

signed main(){
    cin >> n;
    for(int i=1; i<=n; i++){
        scanf("%lld", &A[i]);
    }
    
    int l = -N;
    int r = mod;
    for(; l<r ;){
        int m = l+r >> 1;
        int a = f(m);
        int b = f(m+1);
        if(a > b) l = m+1;
        else r = m;
    }
    
    cout << f(l);
    return 0;
}

Measured memory_bytes: 1792
import java.util.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main {

	int INF = 1 << 28;
	int MAX = 8;
	int OFS = 3;
	boolean map[][];
	
	void run() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		for(int c = 1;c<=n;c++) {
			map = new boolean[MAX+2*OFS][MAX+2*OFS];
			for(int i=0;i<MAX;i++) {
				String str = sc.next();
				for(int j=0;j<MAX;j++) map[i+OFS][j+OFS] = str.charAt(j) == '1';
			}
			int x = sc.nextInt() - 1, y = sc.nextInt() - 1;
			dfs(x+OFS, y+OFS);
			System.out.println( "Data " + c + ":");
			for(int i=0+OFS;i<MAX+OFS;i++) for(int j=0+OFS;j<MAX+OFS;j++) {
				System.out.print( (map[i][j]? "1": "0") + (j == MAX+OFS-1? "\n": "") );
			}
		}
	}
	int dx[] = {-1,0,1,0};
	int dy[] = {0,-1,0,1};
	
	void dfs(int x, int y) {
		if( !map[y][x] ) return;
		map[y][x] = false;
		for(int i=0;i<4;i++) for(int j=0;j<4;j++) {
			dfs( x + j*dx[i], y + j*dy[i] );
		}
	}

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

	void debug(Object... os) {
		System.err.println(Arrays.deepToString(os));
	}
}

Measured memory_bytes: 12000
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String[] s = new String[n];
		for(int i = 0; i < n; i++) s[i] = sc.next();
		boolean ok = true;
		for(int i = 0; i < n; i++) {
			for(int j = i + 1; j < n; j++) {
				if(i == j - 1) {
					if(s[i].charAt(s[i].length() - 1) != s[j].charAt(0)) ok = false;
				}
				if(s[i].equals(s[j])) ok = false;
			}
		}
		System.out.println(ok ? "Yes" : "No");
	}
}


Measured memory_bytes: 24276
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REP(i,b) FOR(i,0,b)
#define RFOR(i,a,b) for (int i = a-1; i >= b; i--)
#define RREP(i,a) RFOR(i,a,0)
#define REPALL(i,v) for (int i = 0; i < v.size(); i++)
#define RREPALL(i,v) for (int i = v.size()-1; i >= 0; i--)
#define SORT(v) sort(v.begin(), v.end())
#define MIN_ELEMENT(v) min_element(v.begin(), v.end())
#define MAX_ELEMENT(v) max_element(v.begin(), v.end())
#define COUNT(v,n) count(v.begin(), v.end(), n);
void YES(bool flag) {cout<<(flag ? "YES" : "NO")<<endl;}
void Yes(bool flag) {cout<<(flag ? "Yes" : "No")<<endl;}
void yes(bool flag) {cout<<(flag ? "yes" : "no")<<endl;}
typedef long long ll;
typedef unsigned long long ull;
const int INF = 1e7;
const ll MOD = 1e9 + 7;

int main()
{
    string s;
    cin>>s;
    if (s[0] == s[1] || s[1] == s[2] || s[2] == s[3])
        cout<<"Bad"<<endl;
    else
        cout<<"Good"<<endl;

    return 0;
}


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

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int N = int.Parse(input[0]);
            int T = int.Parse(input[1]);
            int Answer = 0;

            List<int> ListCost= new List<int>();
            List<int> ListTime = new List<int>();

            for (int i = 0; i < N; i++)
            {
                string[] CostTime = Console.ReadLine().Split(' ');
                ListCost.Add(int.Parse(CostTime[0]));
                ListTime.Add(int.Parse(CostTime[1]));

                if (ListTime[i] <= T)
                {
                    if (Answer==0)
                    {
                        Answer = ListCost[i];
                    }else if (ListCost[i] < Answer)
                    {
                        Answer = ListCost[i];
                    }
                }

                if (i==N-1)
                {
                    if (Answer==0)
                    {
                        Console.WriteLine("TLE");
                    }
                    else
                    {
                        Console.WriteLine(Answer);
                    }
                }

            }
        }
    }
}


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

int32_t main()
{
 int n; cin>>n;
 int A[n]; int ct=0;
 for(int i=0;i<n;i++)
 {
     cin>>A[i];
     if((i+1)%2!=0 && A[i]%2!=0)ct++;
 }
 cout<<ct;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repf(i, a, b) for(ll i = (a); i < (b) ; i++ )
const ll mo = 1000000007;
const double INF = 9223372036854775807; //MAX 9223372036854775807
double ans = 922337203685477580;
struct point{ll x, y;char h;};
ll n;

double solve(point *p,double time){
    double xmax=-INF,xmin=INF,ymax=-INF,ymin=INF;
    rep(i,n){
        double x=p[i].x,y=p[i].y;
        if(p[i].h=='R')x+=time;
        if(p[i].h=='L')x-=time;
        if(p[i].h=='U')y+=time;
        if(p[i].h=='D')y-=time;
        if(xmax<x)xmax=x;
        if(ymax<y)ymax=y;
        if(xmin>x)xmin=x;
        if(ymin>y)ymin=y;
    }
return (xmax-xmin)*(ymax-ymin);

}

int main()
{

cin >> n;
ll t[n] = {};

point p[n];
rep(i, n){
    cin >> p[i].x>> p[i].y>> p[i].h;
}
double udl=INF,udr=-INF;
double lru=-INF,lrd=INF;
double lr[4]={INF,-INF,INF,-INF};
double ud[4]={INF,-INF,INF,-INF};
rep(i,n){
    double x=p[i].x,y=p[i].y;

    if(p[i].h=='U'||p[i].h=='D'){
        if(udl>x)udl=x;
        if(udr<x)udr=x;
    }
        if(p[i].h=='R'||p[i].h=='L'){
        if(lrd>y)lrd=y;
        if(lru<y)lru=y;
    }
    if(p[i].h=='R'&&lr[0]>x)lr[0]=x;
    if(p[i].h=='R'&&lr[1]<x)lr[1]=x;
    if(p[i].h=='L'&&lr[2]>x)lr[2]=x;
    if(p[i].h=='L'&&lr[3]<x)lr[3]=x;
    if(p[i].h=='U'&&ud[0]>y)ud[0]=y;
    if(p[i].h=='U'&&ud[1]<y)ud[1]=y;
    if(p[i].h=='D'&&ud[2]>y)ud[2]=y;
    if(p[i].h=='D'&&ud[3]<y)ud[3]=y;
}
vector<double> v;
v.push_back(0);
rep(i,4){
    if(abs(lr[i])!=INF&&udl!=INF)v.push_back(abs(lr[i]-udl));
    if(abs(lr[i])!=INF&&udr!=-INF)v.push_back(abs(lr[i]-udr));
    if(abs(ud[i])!=INF&&lru!=-INF)v.push_back(abs(ud[i]-lru));
    if(abs(ud[i])!=INF&&lrd!=INF)v.push_back(abs(ud[i]-lrd));
}
rep(i,2)rep(j,2){
    if(abs(lr[i])!=INF&&abs(lr[j+2])!=INF)v.push_back((double)abs(lr[i]-lr[j+2])/2);
    if(abs(ud[i])!=INF&&abs(ud[j+2])!=INF)v.push_back((double)abs(ud[i]-ud[j+2])/2);
}
double tim;
rep(i,v.size()){
    double val=solve(p,v[i]);
    if(ans>val){ans=val;tim=v[i];}
}



cout<<fixed<<setprecision(10)<<ans<<endl;
return 0;
}

Measured memory_bytes: 3328
#include <iostream>
#include <stdio.h>
#include <cstring>
using namespace std;

typedef long long LL;
const LL mod = 1e9 +7;
const int MAX_N = 1e3 + 6;

int ala[MAX_N];

LL __(int _,int ___) {
	int ret=0;
	while (___%_==0) {
		___ /= _;
		ret++;
	}
	return ret;
}

int main () {
	int n;
	while (scanf("%d",&n) != EOF) {
		LL ans=1;
		memset(ala,0,sizeof(ala));
		for (LL i=2;n>=i;i++) {
			if (ala[i]==0) {
				LL _=0;
				for (int j=i;n>=j;j+=i) {
					_ += __(i,j);
					ala[j]=1;
				}
				ans *= (_+1);
				ans %= mod;
			}
		}
		printf("%lld\n",ans);
	}
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[] cnt = new int[26];
		while (sc.hasNext()) {
			String str = sc.nextLine();
			for (int i = 0; i < str.length(); ++i) {
				char c = str.charAt(i);
				if (Character.isUpperCase(c))
					++cnt[c - 'A'];
				else if (Character.isLowerCase(c))
					++cnt[c - 'a'];
			}
		}
		for (int i = 0; i < 26; ++i) {
			System.out.printf("%c : %d\n", 'a' + i, cnt[i]);
		}
	}
}


Measured memory_bytes: 26376
#include<bits/stdc++.h>
#include<string.h>
 
typedef long long int ll;
#define all(x) (x).begin(), (x).end()
 
using namespace std;

int nxt() {
    int x;
    cin >> x;
    return x;
}

ll nxtl(){
    ll x;
    cin>>x;
    return x;
}
 
void SieveOfEratosthenes(int n,vector <int> &primes) 
{ 
    // Create a boolean array "prime[0..n]" and initialize 
    // all entries it as true. A value in prime[i] will 
    // finally be false if i is Not a prime, else true. 
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
    // Print all prime numbers 
    for (int p=2; p<=n; p++) 
       if (prime[p]) 
          primes.push_back(p);
} 
 
ll max(ll a,ll b)
{
    if(a>b)
        return a;
    return b;
}
 
ll power(ll x, ll y,ll mod) 
{ 
    ll temp; 
    if( y == 0) 
        return 1; 
    temp = power(x, y/2,mod); 
    if (y%2 == 0) 
        return (temp*temp)%mod; 
    else
        return (((x*temp)%mod)*temp)%mod; 
}

ll binomialCoeff(ll n, ll k) 
{ 
    ll C[k+1]; 
    memset(C, 0, sizeof(C)); 
  
    C[0] = 1;  // nC0 is 1 
  
    for (ll i = 1; i <= n; i++) 
    { 
        // Compute next row of pascal triangle using 
        // the previous row 
        for (ll j = min(i, k); j > 0; j--) 
            C[j] = C[j] + C[j-1]; 
    } 
    return C[k]; 
} 

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n=nxt();
    if(n%10==n/100)
        cout<<"Yes\n";
    else
        cout<<"No\n";
    
    
    return 0;   
}




 
 


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main (void)
{
	ios_base::sync_with_stdio(0);
    cin.tie(0);
    string s;
    cin >> s;
    if(s[2] == s[3] && s[4] == s[5])
		cout << "Yes\n";
	else
		cout << "No\n";
    return 0;
}
// date_time : 31.03.2020 15:11:46 IST 
// Author : Aditya Kumar Maurya <adityakrmaurya03@gmail.com>


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(long long i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;

int main(){
  int n,a=0;
  cin >> n;
  if(n==10 || n== 100 || n == 1000 || n == 10000 || n == 100000) {
    cout <<10;
  }else {
    while (n>0) {
      a += n%10;
      n/=10;
    }
    cout << a;
  }
}

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

int main()
{
  int N;
  long long K;
  cin >> N >> K;
  vector<pair<int,int> > ab(N);
  for(int i=0;i<N;i++) cin >> ab[i].first >> ab[i].second;
  sort((ab).begin(),(ab).end());

  int ret = 0;

  for(int i=0;i<N;i++)
  {
    if(ab[i].second < K)
    {
      K -= ab[i].second;
      continue;
    }

    cout << ab[i].first << endl;
    return 0;
  }

  return 0;
}

Measured memory_bytes: 1024
N=int(input())
P=list(map(int, input().split()))
Q=list(map(int, input().split()))
A=[]
for n in range(1,N+1):
    A.append(n)
import itertools
cnt=0
a=0;b=0
for i in list(itertools.permutations(A)):
    cnt+=1
    i=list(i)
    if P==i:
        a=cnt
    if Q==i:
        b=cnt
    if (a!=0) and (b!=0):
        print(abs(a-b))
        break

Measured memory_bytes: 8052
#include<bits/stdc++.h>
#define pb  push_back
using namespace std;
typedef long long ll;
int main(){
    int n; cin >> n;
    ll a[n];
    for(int i=0;i<n;i++) cin >> a[i];
	   
    map<ll,ll> m;
    m[0] = a[0];
   
   for(int i=1;i<n;i++){
   	m[i]+=m[i-1]+a[i];
   }
   
   ll ans = 1LL<<60;
   
   for(int i=0;i<n-1;i++){
   	 ans = min(ans, abs(m[i]-(m[n-1]-m[i])));
   }
   
    cout << ans;
	return 0;
}

Measured memory_bytes: 14336
#!/usr/bin/perl
use Data::Dumper;

my ($n,$m) = map {$_ - 0} split(/\s+/o,<STDIN>);
my $s = <STDIN>;

my @d = ();
$#d = $n - 1;
for(my $i=0;$i<$n;$i++){
  $d[$i]->{a} = substr($s,$i,1);
}

for(my $i=0;$i<$m;$i++){
  my ($a,$b) = map {$_ - 0} split(/\s+/o,<STDIN>);
  $d[$a-1]->{substr($s,$b-1,1)}->{($b-1)} = 1;
  $d[$b-1]->{substr($s,$a-1,1)}->{($a-1)} = 1;
}

while(1){
  my $do_del = undef;
  for(my $i=0;$i<$n;$i++){
    if( ( $d[$i]->{A} and not $d[$i]->{B} ) or ( $d[$i]->{B} and not $d[$i]->{A} ) ){
      &rm_tree($i,100000);
      $do_del = 1;
    }
  }
  last unless $do_del;
}

my @dd = grep { $_->{A} and $_->{B} } @d;

my $ans = 'No';
$ans = 'Yes' if @dd;
print "$ans\n";

exit(0);

sub rm_tree {
  my $ind = shift;
  my $maxrm = shift;
  my $rmcnt = 0;
  my @nx = ($ind);
  my @nnx;
  while( @nx and $rmcnt < $maxrm ){
    @nnx = ();
    foreach my $i (@nx){
      if( ( $d[$i]->{A} and not $d[$i]->{B} ) or ( $d[$i]->{B} and not $d[$i]->{A} ) ){
        if( $d[$i]->{A} ){
          foreach my $k (map {$_ - 0} keys %{$d[$i]->{A}}){
            delete $d[$k]->{$d[$i]->{a}}->{$i};
            unless( keys %{$d[$k]->{$d[$i]->{a}}} ){
              delete $d[$k]->{$d[$i]->{a}};
              push(@nnx,$k) if $d[$k]->{( $d[$i]->{a} eq 'A' ? 'B' : 'A')};
            }
          }
          delete $d[$i]->{A};
        }
        if( $d[$i]->{B} ){
          foreach my $k (map {$_ - 0} keys %{$d[$i]->{B}}){
            delete $d[$k]->{$d[$i]->{a}}->{$i};
            unless( keys %{$d[$k-0]->{$d[$i]->{a}}} ){
              delete $d[$k]->{$d[$i]->{a}} ;
              push(@nnx,$k) if $d[$k]->{( $d[$i]->{a} eq 'A' ? 'B' : 'A')};
            }
          }
          delete $d[$i]->{B};
        }
        $rmcnt++;
      }
    }
    @nx = (@nnx);
  }
}



Measured memory_bytes: 123904
import Data.Functor((<$>))

main :: IO ()
main = do 
        q  <- (read :: String -> Int).last.words <$> getLine
        xs <- map ((\[n, t] -> (n, (read :: String -> Int) t)).words).lines <$> getContents
        mapM_ (putStrLn.f) $ solve xs [] [] q 0
    where f (n, t) = n ++ (' ' : show t) 

solve                        :: [(String, Int)] -> [(String, Int)] -> [(String, Int)] -> Int -> Int -> [(String, Int)]
solve []            [] zs _ _   = reverse zs
solve []            ys zs q cnt = solve (reverse ys) [] zs q cnt
solve ((n, t) : xs) ys zs q cnt = let t'   = t - q
                                      cnt' = cnt + q
                                      m    = cnt' + t'
                                  in if t' > 0 then solve xs ((n, t') : ys) zs q cnt'
                                               else solve xs ys  ((n, m) : zs) q m

Measured memory_bytes: 35348
n = int(input())
a = list(map(int, input().split()))
money = 1000
stock = 0
index = 0
while True:
    if stock == 0:
        if a[index] < a[index + 1]:
            stock += money // a[index]
            money -= stock * a[index]
        index += 1
    else:
        if a[index] > a[index + 1]:
            money += stock * a[index]
            stock = 0
        index += 1
    if index == n - 1:
        break
if stock != 0:
    money += stock * a[-1]
print(money)
        

Measured memory_bytes: 61892
N, M = list(map(int, input().split()))
A = [0] * M
B = [0] * M
R = [0] * N
for i in range(N):
    R[i] = set()

for i in range(M):
    A[i], B[i] = list(map(int, input().split()))
    R[A[i]-1].add(B[i]-1)
    R[B[i]-1].add(A[i]-1)

stack = set()
visited = set()
max_groups = 0

for i in range(N):
    if not i in visited:
        stack.add(i)
        groups = 0
        while True:
            current = stack.pop()
            visited.add(current)
            groups += 1
            stack |= (R[current] - visited)
            if not stack:
                break
        max_groups = max(max_groups,groups)

print(max_groups)

Measured memory_bytes: 101104
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
#define FOR(i,a,n) for(ll i=(ll)a;i<(ll)n;i++)
#define RFOR(i,a,n) for(ll i=(ll)n-1;i >= (ll)a;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,0,n)
#define ALL(v) v.begin(), v.end()
#define bra(first,second) '(' << first << ',' << second << ')'
ll MOD = 1000000007;
//ll INF = 21474836470000000;
ll INF = 100100100100100100;
long double EPS = 1e-11;
long double PI = 3.141592653589793238;
template<typename T>
void remove(std::vector<T>& vector, unsigned int index){
    vector.erase(vector.begin() + index);
}

using Graph = vector<vector<ll>>;

ll dp[3010][3010];

int main(){
    ll N,T;
    cin >> N >> T;
    vector<pair<ll,ll>> D(N);
    vector<ll> A(N),B(N);
    rep(i,N){
        cin >> D[i].first >> D[i].second;
    }
    sort(ALL(D));
    rep(i,N){
        A[i] = D[i].first;
        B[i] = D[i].second;
    }
    ll ans = 0;
    rep(i,N){
        rep(j,T){
            ans = max(dp[i][j] + B[i],ans);
            if(A[i] <= j) dp[i+1][j] = max(dp[i][j],dp[i][j-A[i]]+B[i]);
            else dp[i+1][j] = dp[i][j];
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 70912
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <array>
#include <vector>
#include <functional>
#include <unordered_map> 
#include <map> 
#include <numeric>
#include <limits>
#include <utility>
#include <queue>
#include <random>
using namespace std;
typedef long long LL;

int main(void) {
	int a;
	cin >> a;
	cout << "ABC" << a << endl;
	return 0;
}

Measured memory_bytes: 256
import sys
import itertools

# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

ans = 0
A = [int(i) for i in readline().split()]
for i in range(A[0], A[1] + 1):
    if A[-1] % i == 0:
        ans += 1
print(ans)



Measured memory_bytes: 5616
#include<bits/stdc++.h>
using namespace std;
long long a[100001],n,k;
int main()
{
	cin>>n>>k;
	for(int i=1;i<=n;i++)cin>>a[i];
	long long f[100001];
	memset(f, 0x7F, sizeof(f));
	f[1]=0;
	for(int i=2;i<=n;i++)
		for(int j=1;j<=k&&j<i;j++)
			f[i]=min(f[i-j]+abs(a[i]-a[i-j]),f[i]);
	cout<<f[n]<<endl;
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>  // g++ -std=c++14 -o a a.cpp

using namespace std;

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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repto(i, n) for(int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;

__attribute__((constructor))
void initial() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

int main() {
    int N, T, A;
    cin >> N >> T >> A;

    double minDiff = INF;
    int minDiffIndex = INF;
    rep(i, N) {
        int hi;
        cin >> hi;
        double ave = T - (hi * 0.006);
        double diff = abs(A - ave);

        if(diff < minDiff) {
            minDiff = diff;
            minDiffIndex = i;
        }
    }
    cout << (minDiffIndex + 1) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp> 
//using boost::multiprecision::cpp_int;
using namespace std;
#define ll long long int
#define F first
#define S second
//#define endl "\n"
//#define nl cout<<endl;
#define pb push_back
#define ull unsigned long long 
#define f(i,a,b) for(ll i=a;i<b;i++)
#define Knucklehead ios_base::sync_with_stdio(false);cin.tie(NULL);
//#define mod 100000007
#define mat vector<vector<ll>>
mat cn(ll n, ll m){return vector< vector<ll> >(n, vector<ll>(m));}
bool compare(char &s1,char &s2){return s1 > s2;} 
bool sortmahstyle(const pair<ll,ll> &a,  const pair<ll,ll> &b) 
{ 
    if(a.second > b.second )
        return true;
    if( a.second==b.second && a.first > b.second )
       return true;
    return false;
}
bool cmp(int n, pair<int, int> const& p)
{
    return (p.first < n);
}
//me
ll const mod = 1e9+7;//998244353;
ll const inf = 1e18;
ll const maxn = 1e5+1;


void solve()
{    
     
     ll n,m; cin >> n >> m;
     ll a[n];
     map<ll,ll> cnt;
     f(i,0,n){
          ll xx; cin >> xx;
          cnt[xx]++;
     }
     f(i,0,m){
          ll b,c; cin >> b >> c;
          cnt[c]+=b;
     }

     ll tot = 0, sum = 0;
     for(auto i = cnt.rbegin(); i!= cnt.rend(); ++i){
          ll cur = min(n-tot, i->S);
          sum += i->F*cur;
          tot += cur;
          if(tot==n)
               break;
     }
     cout << sum << endl;

}

int main() {
Knucklehead 
//*
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
/**/ 
        
          ll t;
          /**/t=1;
          /*/cin>>t;/**/
          f(testcases,0,t){
               //cout << "Case #" <<testcases+1<<": ";
               solve();
          }
 
 
    return 0;
}

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

int main()
{
char a,b; 	
cin>>a>>b; 

if(a=='H' && b=='H') 
	cout<<'H';
if(a=='H' && b=='D') 
	cout<<'D';
if(a=='D' && b=='H') 
	cout<<'D';
if(a=='D'&& b=='D') 
	cout<<'H';
return 0;			
}



Measured memory_bytes: 256
#include <iostream>


#include <bits/stdc++.h>

#define FIXED_FLOAT(x) std::fixed <<std::setprecision(2)<<(x)
using namespace  std;

int main()
{
    int n;
    cin >> n;
    int l = n%10;
    if(l==3) {
        cout << "bon";
    }
    else if(l==0||l==1||l==6 || l==8) {
        cout << "pon";
    }
    else {
        cout << "hon";
    }


}

































Measured memory_bytes: 3636
// ABC046 A - AtCoDeerくんとペンキ
#include <stdio.h>

int main(void) {
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);

    int result = 1;
    if (a != b) {
        result += 1;
    }
    if (a != c && b != c) {
        result += 1;
    }

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

    return 0;
}

Measured memory_bytes: 128
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    System.out.println((a <= c && c <= b) ? "Yes" : "No");
  }
}

Measured memory_bytes: 23764
from collections import Counter


def solve(h, w, a):
    c = Counter(a)
    m1, m2 = 0, 0
    for v in c.values():
        if v & 3 == 0:
            continue
        elif v & 1 == 0:
            m2 += 1
        else:
            m1 += 1
            if (v - 1) & 3:
                m2 += 1

    if h & 1:
        if w & 1:
            if m1 > 1:
                return 'No'
            if m2 > h // 2 + w // 2:
                return 'No'
            return 'Yes'
        if m1 > 0:
            return 'No'
        if m2 > w // 2:
            return 'No'
        return 'Yes'
    if m1 > 0:
        return 'No'
    if w & 1:
        if m2 > h // 2:
            return 'No'
        return 'Yes'
    if m2 > 0:
        return 'No'
    return 'Yes'


h, w = map(int, input().split())
a = ''.join(input().strip() for _ in range(h))
print(solve(h, w, a))


Measured memory_bytes: 3444
mark = ['S', 'H', 'C', 'D']
ary = []

for mk in range(0, 4):
    for i in range(1, 14):
        ary.append("{} {}".format(mark[mk], i))

n = int(input())
x = 0

while True:
    card = str(input())
    ary.remove(card)

    x += 1

    if x == n:
        break
    
if len(ary) > 0:
    print("\n".join(ary))



Measured memory_bytes: 5604
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int k,t;
int a[110];
int main()
{
    int i,j;
    while(~scanf("%d%d",&k,&t))
    {
        for(i=1;i<=t;i++)
            scanf("%d",&a[i]);
        if(t==1){printf("%d\n",k-1);continue;}
        sort(a+1,a+1+t);
        int emp=0;
        for(i=1;i<=t-1;i++)
        {
            emp+=(t-i-1)*a[i];
            for(j=i+1;j<=t;j++) a[j]-=a[i];
            a[i]=0;
        }
        emp+=1;
        printf("%d\n",a[t]-emp<0?0:a[t]-emp);

    }

    return 0;
}


Measured memory_bytes: 128
def mp(): return map(int, input().split())
def lmp(): return list(map(int, input().split()))

n = int(input())
a_ar = []
b_ar = []
for i in range(n):
    a, b = mp()
    a_ar.append(a)
    b_ar.append(b)
a_ar.sort()
b_ar.sort()

if n % 2 == 1:
    print(b_ar[n//2]-a_ar[n//2]+1)
else:
    l = (a_ar[n//2-1] + a_ar[n//2])/2
    r = (b_ar[n//2-1] + b_ar[n//2])/2
    print(int((r-l)*2+1))



Measured memory_bytes: 101028