akhauriyash/Code-Regression huggingface dataset:
use proconio::{fastout, input};
use std::cmp::max;

const N_MAX: usize = 1e5 as usize;

#[fastout]
fn main() {
    input!{
        n: usize,
        t: [(i32, i32, i32); n],
    };

    let mut dp = [[0; N_MAX + 1]; 3];

    for k in 1..n+1 {
        for i in 0..3 {
            if i == 0 {
                dp[i][k] = max(dp[1][k-1] + t[k-1].1, dp[2][k-1] + t[k-1].2);
            } else if i == 1 {
                dp[i][k] = max(dp[0][k-1] + t[k-1].0, dp[2][k-1] + t[k-1].2);
            } else {
                assert_eq!(i, 2);
                dp[i][k] = max(dp[1][k-1] + t[k-1].1, dp[0][k-1] + t[k-1].0);
            }
            //dp[i][k] = max(dp[][k-1])
        }
    }

    println!("{}", max(dp[0][n], max(dp[1][n], dp[2][n])));
}


Measured memory_bytes: 5992
s = input()
if len(s) % 2 == 0:
    l = s[:len(s)//2]
    r = s[len(s)//2:len(s)][::-1]
else:
    l = s[:len(s)//2]
    r = s[len(s)//2+1:len(s)][::-1]
cnt = 0
for li, ri in zip(l, r):
    if li != ri:
        cnt += 1
print(cnt)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define endl '\n'
#define all(x) (x).begin(),(x).end()
const int INF=500+5;
const int N=2e5+5;
const ll oo=1e18+5;
const ll mod=998244353;


int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin>>n;
	string s;
	cin>>s;
	vector<int> a(n);
	bool have_one=0;
	for(int i=0;i<n;++i){
		a[i]=s[i]-'1';
		if(a[i]==1) have_one=1;
	}
	if(!have_one){
		for(int i=0;i<n;++i) a[i]>>=1;
	}
	int ans=0;
	for(int i=0;i<n;++i){
		if(((n-1)&i)!=i) continue;
		ans^=(a[i]&1);
	}
	if(!have_one) ans<<=1;
	cout<<ans;
	return 0;
}


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

template<typename Ty>
class Queue
{
  std::vector<Ty> vec;
  typename std::vector<Ty>::iterator cur;
  typename std::vector<Ty>::iterator end;
public:
  Queue(): vec(),cur(),end() {}
  void set(size_t n) { vec.assign(n,Ty()); cur=vec.begin(); end=cur; }
  bool empty() const { return cur==end; }
  size_t size() const { return end-cur; }
  Ty &front() { return *cur; }
  Ty &back() { return *(end-1); }
  void push_back(Ty x) { *end++=std::move(x); }
  void pop_front() { cur++; }
};

struct BFS
{
  size_t N;
  size_t M;
  std::vector<std::vector<size_t>> Graph;
  std::vector<int> dist;
  Queue<size_t> queue;
  std::vector<size_t> arrow;
  
  BFS()
  {
    std::cin>>N>>M;
    
    Graph.resize(N);
    for(size_t i=0;i!=M;i++)
    {
      size_t A;
      size_t B;
      std::cin>>A>>B;
      A--;
      B--;
      Graph[A].push_back(B);
      Graph[B].push_back(A);
    }
    
    dist.assign(N,-1);
    queue.set(N);
    arrow.assign(N,-1);
  }
  
  void find(size_t pos)
  {    
    dist[pos]=0;
    queue.push_back(pos);
    
    while(queue.empty()==false)
    {
      pos=queue.front();
      queue.pop_front();
      
      for(size_t i=0;i!=Graph[pos].size();i++)
      {
        size_t nextPos=Graph[pos][i];
        
        if(dist[nextPos]!=-1)
          continue;
        
        dist[nextPos]=dist[pos]+1;
        queue.push_back(nextPos);
        arrow[nextPos]=pos;
      }
    }
  }
};

int main()
{
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  
  BFS f;
  f.find(0);
  
  for(size_t i=1;i!=f.arrow.size();i++)
  {
    if(f.arrow[i]==-1)
    {
      std::cout<<"No"<<std::endl;
      return 0;
    }
  }
  
  std::cout<<"Yes\n";
  for(size_t i=1;i!=f.arrow.size();i++)
  {
    std::cout<<f.arrow[i]+1<<"\n";
  }
  std::cout<<std::endl;
  
  return 0;
}

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

const long mod = 998244353;
const long inv = mod / 2 + 1;
int n, s;
int a[3000];
long dp[3001];
int main() {
  cin >> n >> s;
  for (int i = 0; i < n; ++i) cin >> a[i];
  
  dp[0] = 1;
  for (int i = 0; i < n; ++i) dp[0] = dp[0] * 2 % mod;
  for (int i = 0; i < n; ++i) {
    for (int k = s; k >= 0; --k) {
      if (k + a[i] > s) continue;
      dp[k + a[i]] = (dp[k + a[i]] + dp[k] * inv) % mod;
    }
  }
  cout << dp[s] << endl;
}

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

int main() {
  string S;
  long long K;
  cin >> S >> K;
  int cnt = 0;
  char a;
  for (int i = 0; i<S.size();i++) {
    if (S.at(i) == '1') cnt++;
    else {
      a = S.at(i);
      break;
    }
  }
  if (K<=cnt) cout << 1 << endl;
  else cout << a << endl;
}

  

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

// int/long:		-2,147,483,648 - 2,147,483,648 (-2^31 <= int < 2^31)
// long/long long:	-9,223,372,036,854,775,808 - 9,223,372,036,854,775,807 (-2^63 <= long < 2^63)

#define	INF (1<<29)
//536,870,912

// lower_bound(A.begin(), A.end(), N)
// upper_bound(...

// A.erase(unique(A.begin(), A.end()), A.end())

// bit: &/and, |/or, ^/xor, ~/not

// getline(cin, String)
// while (getline(cin, S)) {}

// cout <<fixed <<setprecision(10)

// priority_queue<int> q;
// priority_queue<int, vector<int>, less<int>> q; // Default: vector, less
// priority_queue<vector<int>, vector<vector<int>>, greater<vector<int>>> q;

// Graph
// Warshall-Floyd: Distance between each node, N^3
// Dijkstra: Distance from the start node, N^2
// DFS(Depth-First Search)

/*
int	gcd(int A, int B) {
	while (0!=B) {
		A %=B;
		swap(A, B);
	}
	return A;
}
*/

const int MAX = 100000;
#define	MOD 1000000007

void	ComInit(vector<long> &fac, vector<long> &finv, vector<long> &inv) {
	fac.at(0) = 1;
	fac.at(1) = 1;
	finv.at(0) = 1;
	finv.at(1) = 1;
	inv.at(1) = 1;
	for (int i=2; i<MAX; i++) {
		fac.at(i) = (fac.at(i-1)*i) %MOD;
		inv.at(i) = MOD - (inv.at(MOD%i)*(MOD/i)) %MOD;
		finv.at(i) = (finv.at(i-1)*inv.at(i)) %MOD; 
	}
}

long	COM(int N, int K, vector<long> &fac, vector<long> &finv) {
	if (N<K)
		return 0;
	if ((N<0)||(K<0))
		return 0;
	return (fac.at(N) * ((finv.at(K)*finv.at(N-K)) %MOD)) %MOD;
}

int	main() {
	// Array
	vector<long> fac(MAX);
	vector<long> finv(MAX);
	vector<long> inv(MAX);
	// Initialize
	ComInit(fac, finv, inv);
	// Start
	long N, K;
	cin >>N >>K;
	vector<long> A(N, 0);
	for (long i=0; i<N; i++)
		cin >>A.at(i);
	sort(A.begin(), A.end());
	long S=0;
	for (long i=K-1; i<N; i++) {
		S +=((A.at(i)-A.at(N-1-i))*COM(i, K-1, fac, finv))%MOD;
		S %=MOD;
	}
	cout <<S <<endl;
	return 0;
}



Measured memory_bytes: 3328
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

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

		BufferedReader bfr=new BufferedReader(new InputStreamReader(System.in));
		String str="";
		StringTokenizer stk;
		String moji="";
		int yoko,tate;
		String[] hata;

		try {
			str=bfr.readLine();
			if(str==null) {
				System.exit(0);
			}
			else {
				stk=new StringTokenizer(str," ");
				yoko=Integer.parseInt(stk.nextToken());
				tate=Integer.parseInt(stk.nextToken());
				moji=stk.nextToken();
				hata=new String[tate];

				for(int i=0; i<tate; i++) {
					hata[i]="";
				}


				for(int i=0; i<yoko; i++) {
					if(i==0 || i==yoko-1) {		// hata no +
						hata[0]=hata[0]+"+";
						hata[tate-1]=hata[tate-1]+"+";
						for(int j=1; j<tate-1; j++) {
							hata[j]=hata[j]+"|";
						}
					}
					else {
						hata[0]=hata[0]+"-";
						hata[tate-1]=hata[tate-1]+"-";

						for(int j=1; j<tate-1; j++) {
							if(j!=(tate-1)/2) {
								hata[j]=hata[j]+".";
							}
							else {
								if(i==(yoko-1)/2) {
									hata[j]=hata[j]+moji;
								}
								else {
									hata[j]=hata[j]+".";
								}
							}
						}
					}
				}
				for(int l=0; l<tate; l++) {
					System.out.println(hata[l]);
				}

			}
		}catch(IOException e){}
	}
}


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

int main(){
	int n,a,b;
	cin>>n>>a>>b;
	int ans=0;
	for (int i=1;i<=n;i++){
		int x=i,sum=0;
		while(x){
			sum+=x%10;
			x/=10;
		}
		if(sum>=a&&sum<=b)
			ans+=i;
		
	}
	cout<<ans<<endl;
}


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

int main(){
    int n;
    cin >> n;
    int a1, a2, a3, a4, a5, b1, b2, b3, b4, b5;
    int sum = 100000;
    for(int i = 1;  i < n; i++){
        int a = i;
        int b = n - i;
        a1 = a % 10;
        a2 = (a % 100) / 10;
        a3 = (a % 1000) / 100;
        a4 = (a % 10000) / 1000;
        a5 = a / 10000;
        b1 = b % 10;
        b2 = (b % 100) / 10;
        b3 = (b % 1000) / 100;
        b4 = (b % 10000) / 1000;
        b5 = b / 10000;
        sum = min(sum, a1 + a2 + a3 + a4 + a5 + b1 + b2 + b3 + b4 + b5);
        //cout << a1 << ' ' << a2 << ' ' << b1 << ' ' << b2 << endl;
    }
    cout << sum << endl;
    //cout << a4 << ' ' << a3 << ' ' << b4 << ' ' << b3 << endl;
    return 0;
}

Measured memory_bytes: 256
N,K,L=map(int,input().split())
PQ=[list(map(int,input().split())) for i in range(K)]
RS=[list(map(int,input().split())) for i in range(L)]

def find_root(root,x):
    y = root[x]
    if x == y:
        return x
    z = find_root(root,y)
    root[x] = z
    return z
 
def merge(root,size,x,y):
    x = find_root(root,x)
    y = find_root(root,y)
    if x == y:
        return
    sx,sy = size[x],size[y]
    if sx < sy:
        sx,sy = sy,sx
        x,y = y,x
    root[y] = x
    size[x] += sy
    
def UF_make(graph,n):
    Root=list(range(n+1))
    Size=[1] * (n+1)
    for i in range(len(graph)):
        merge(Root,Size,graph[i][0],graph[i][1])
    for i in range(n+1):
        Root[i] = find_root(Root,i)
    Root.pop(0)  #
    return Root

PQN=UF_make(PQ,N)
RSN=UF_make(RS,N)
PQRS=[PQN[i]*10**6+RSN[i] for i in range(N)]
D=len(set(PQRS))
PQRS=[[PQRS[i],i,0] for i in range(N)]
PQRS.sort()

p=0
while p<N:
    i=1
    c=0
    if p+i>N-1:
        break
    while PQRS[p][0]==PQRS[p+i][0]:
        c+=1
        i+=1
        if p+i>N-1:
            break
    for j in range(p,p+i):
        PQRS[j][2]=c
    p+=i
PQRS.sort(key=lambda x:x[1])
for i in range(N):
    print(PQRS[i][2]+1,end=' ')

Measured memory_bytes: 91772
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int y = sc.nextInt();
		boolean a = false;
		for(int i = 0; i <= x; i++) {
			if(2*x+2*i == y) {
				a = true;
			}
		}
		if(a == true) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}

}

Measured memory_bytes: 27036
#include <stdio.h>
int main(void){    
    int a,b,d,r;  
    double f;  
    scanf("%d %d", &a, &b);    
    d=a/b;  
    r=a%b;  
    f=1.00000*a/b;    
    printf("%d %d %.5lf\n", d, r, f);    
    return 0;  
    
}


Measured memory_bytes: 2084
for t in xrange(input()):
    h, w = map(int, raw_input().split())
    A = [list(raw_input()) for i in xrange(h)]
    xmin = {}; xmax = {}
    ymin = {}; ymax = {}
    obj = set()
    for i in xrange(h):
        for j in xrange(w):
            c = A[i][j]
            if c == '.': continue
            xmin[c] = min(xmin.get(c, 99), j)
            xmax[c] = max(xmax.get(c, -1), j)
            ymin[c] = min(ymin.get(c, 99), i)
            ymax[c] = max(ymax.get(c, -1), i)
            obj.add(c)
    if not obj:
        print "SAFE"
        continue
    ok = 1
    g = {e: set() for e in obj}
    deg = {e: 0 for e in obj}
    for q in obj:
        for i in xrange(ymin[q], ymax[q]+1):
            for j in xrange(xmin[q], xmax[q]+1):
                c = A[i][j]
                if c == '.':
                    ok = 0
                    break
                if c != q:
                    g[q].add(c)
            if not ok: break
        if not ok: break
    if not ok:
        print "SUSPICIOUS"
        continue
    for e in obj:
        for t in g[e]:
            deg[t] += 1
    cnt = len(obj)
    used = set()
    for e in obj:
        for e in obj:
            if not deg[e] and e not in used:
                for t in g[e]:
                    deg[t] -= 1
                used.add(e)
                cnt -= 1
    if cnt:
        print "SUSPICIOUS"
    else:
        print "SAFE"

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

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define MIN(a) *min_element(all(a))
#define MAX(a) *max_element(all(a))
#define SUM(a, b) accumulate(all(a), b)
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define FOR(i, m, n) for(int (i)=(m); (i)<(n); i++)
#define FORR(i, m, n) for(int (i)=(n)-1; (i)>=(m); i--)
#define ios() cin.tie(0), ios::sync_with_stdio(false)
#define debug(x) cerr << #x << " = " << x << endl
//#define int long long

typedef long long ll;
typedef unsigned long long ull;
//ll const MOD = 998244353;
ll const MOD = 1e9+7;
ll const INF = 1e18;

template<typename T> int size(const T& a){return (int)a.size();}
template<typename T> T Div(T a, T b){return (a + b - 1) / b;}
template<typename T> bool chmin(T& a, const T& b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, const T& b){if(a < b){a = b; return true;} return false;}



signed main(){
    int n, m;
    cin >> n >> m;
    vector<vector<bool>> v(m, vector<bool>(n, false));
    REP(i, m){
        int k;
        cin >> k;
        REP(j, k){
            int a;
            cin >> a;
            v[i][a-1] = true;
        }
    }

    vector<int> p(m);
    for(auto& i : p) cin >> i;
    int ans = 0;

    for(int bit = 0; bit < (1 << n); bit++){
        bool flag = true;
        REP(i, m){
            int cnt = 0;
            REP(j, n){
                if(((bit >> j) & 1) && v[i][j]){
                    cnt++;
                }
            }
            if(cnt%2 != p[i]){
                flag = false;
                break;
            }
        }
        if(flag){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
N = int(input())
A = [input() for _ in [0]*N]

for i,a in enumerate(A):
    b = a.split(".")
    if len(b)==1:
        A[i] = int(a)*10**9
        continue
    c = b[1]
    n = len(c)
    c += "0"*(9-n)
    A[i] = int(b[0] + c)

cnt = [[0]*50 for _ in [0]*50]
B = [(0,0)]*N
for k,a in enumerate(A):
    i = 0
    j = 0
    while a%2==0:
        a//=2
        i+=1
    while a%5==0:
        a//=5
        j+=1
    B[k] = (i,j)
    cnt[i][j] += 1

for i in range(1,50):
    i = 49-i
    for j in range(50):
        j = 49-j
        cnt[i][j] += cnt[i+1][j]

for i in range(50):
    i = 49-i
    for j in range(1,50):
        j = 49-j
        cnt[i][j] += cnt[i][j+1]

ans = 0
for i,j in B:
    me = int(i>=9 and j>=9)
    ans += cnt[max(0,18-i)][max(0,18-j)]-me

print(ans//2)

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

using namespace std;

#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define show(x) cerr << #x << " " << x << endl

typedef long long ll;
typedef unsigned long long ull;

constexpr const int INT_INF=0x3f3f3f3f; // 1061109567
constexpr const ll LL_INF=0x3f3f3f3f3f3f3f3f; // 4557430888798830399

template <typename T> bool chmin(T &a, T b) {
    if (a > b) {a = b;return true;}return false;
}

template <typename T> bool chmax(T &a, T b) {
    if (a < b) {a = b;return true;}return false;
}

// INT
#define GCD(a, b) __gcd(a, b)
template <typename T> T LCM(T a, T b) {return a / GCD(a, b) * b;}
template <typename T> T EXTGCD(T a, T b, T& x, T& y) {
    T d = a;
    if (b != 0) {d=EXTGCD(b,a%b,y,x);y-=(a/b)*x;}
    else x=1,y=0;
    return d;
}
template <typename T> bool is_prime(T a) {
    for(int i=2;i*i<=a;i++)if(a%i==0)return 1;
    return 0;
}

// MOD
const ll MOD = 1000000000 + 7;
#define add(a, b) ((a % MOD) + (b % MOD)) % MOD
#define mul(a, b) ((a % MOD) * (b % MOD)) % MOD
#define sub(a, b) ((a % MOD) + MOD - (b % MOD)) % MOD
template <typename T> T mod_inverse(T a, T mod, bool prime){ // if mod is prime, "prime" is true.
    if(prime){
        T tmp=mod-2,now=a,res=1;while(tmp){if(tmp&1)res=mul(res,now);now=mul(now,now);tmp>>=1;}
        return res;
    }else{T x,y;EXTGCD(a,mod,x,y);return (mod+x%mod)%mod;}
}
#define divide(a, b) ((a % MOD) * (mod_inverse(b, MOD, true))) % MOD

//LLの数値をつかう時は最後にLをつける癖をつけよう
//
//  　　┓　　　┏
//  　＊┗┓　┏┛
//  　　　┫　┣　＊
//  　┏┳┻━┻┳┓
//  　┗┫　　　┣┛
//  ＊　┣　　━┃　＊        Merry Christmas!!
//  　┏┛　　〃┃
//  　┃●　　　┣━┳┓
//  　┗┻┳━━┛　┣┛
//  　＊　┃┏┓┣┓┃
//WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW

const int maxn = 100001;
int a[maxn];
int n, m;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(10);
    cout << fixed;
#ifdef LOCAL_DEFINE
    FILE *stream1;
    //FILE *stream2;
    stream1 = freopen("/Users/aim_cpo/CLionProjects/competitive/in.txt", "r", stdin);
    //stream2 = freopen("out.txt", "w", stdout);
    if (stream1 == nullptr) return 0;
    //if (stream2 == NULL) return 0;
#endif
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        int from, to; cin >> from >> to;
        a[from]++;
        a[to]++;
    }
    for (int i = 1; i <= n; i++) {
        if (a[i] & 1) {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
#ifdef  LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << "s.\n";
#endif
    return 0;
}

Measured memory_bytes: 640
module Main where

import Data.Functor

main :: IO ()
main = do
  { [a,b] <- getInts
  ; putStrLn (hikaku (a,b))
  }

hikaku :: (Int, Int) -> String
hikaku (x,y)
  | x < y  = "a < b"
  | x == y = "a == b"
  | x > y  = "a > b"

getInts :: IO [Int]
getInts = map read . words <$> getLine

Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SZ(x) ((int)(x).size())
#define debug(x) cerr << #x << ": " << x << '\n'
#define INF 999999999
typedef long long int Int;
typedef pair<int,int> P;
using ll = long long;
using VI = vector<int>;
int s=-1;
int main(){

  int n;cin >> n;
  vector<int> a(n);
  int ab=0;
  int num=0;
  int numi=-1;
  rep(i,n){
    cin >> a[i];
    if(ab<abs(a[i])){
      ab = abs(a[i]);
      num = a[i];
      numi = i+1;
    }
  }
  int ans=0;
  bool flag = false;
  rep(i,n-1) if(a[i]>a[i+1]) flag = true;
  if(flag){
    cout << n-1+n-1 << endl;
    rep(i,n){
      if(i==numi-1){}
      else{
        a[i]+=num;
        cout << numi << " " << i+1 << endl;
      }
    }
    if(a[0]>=0){
      for(int i=1;i<n;i++){
        a[i]+=a[i-1];
        cout << i << " " << i+1 << endl;
      }
    }else{
      for(int i=n-2;i>=0;i--){
        a[i]+=a[i+1];
        cout << i+2 << " " << i+1 << endl;
      }
    }
  }else{
    cout << 0 << endl;
    return 0;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repn(i, n) for (int i = 0; i <= (int)(n); i++)
#define srep(i, l, n) for (int i = l; i < (int)(n); i++)
#define srepn(i, l, n) for (int i = l; i <= (int)(n); i++)
#define pb push_back 
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

const int MOD = 1000000007;
const int INF = 1e9;
#define PI 3.14159265369;
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main(){
	int n, m;
	cin >> n >> m;
	priority_queue<int, vector<int>, greater<int>> q;
	rep(i,n){
		int a;
		cin >> a;
		q.push(a);
	}
	vector<P> b(m);
	rep(i,m) cin >> b[i].second >> b[i].first;
	sort(b.rbegin(), b.rend());
	rep(i,m){
		rep(j, b[i].second){
			if(q.top()<b[i].first) {
				q.pop();
				q.push(b[i].first);
			}else{
				break;
			}
		}
	}
	ll ans = 0;
	while(q.size()){
		ans += q.top();
		q.pop();
	}
	cout << ans << endl;
}

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

//template
typedef long long int ll;
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<n;i++)
#define repr(i,n) for(ll i=n;i>0;i--)
#define all(v) v.begin(),v.end()
#define in cin>>
#define out cout<<
#define en <<endl
const ll INF = 10000000000000;

int main()
{
	int h, w, n, x, y;
	in h >> w >> n;
	if (h >= w)
	{
		x = h;
		y = w;
	}
	else
	{
		x = w;
		y = h;
	}
	int ans = 1;
	rep(i, y)
	{
		if (x*ans >= n)
			break;
		else
			ans++;
	}
	out ans en;
}


Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))

anker=-10
ans=0
for i in range(1,n+1):
    cuisine=a.index(i)
    if cuisine-anker==1:
        ans += c[i-2]
    anker = cuisine
ans += sum(b)
print(ans)


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

template <typename T, typename U>
std::vector<std::pair<T, U>> prime_factorization(T x)
{
    std::vector<std::pair<T, U>> ret;
    for (T i = 2; i * i <= x; i++)
    {
        U count = 0;
        while (x % i == 0)
        {
            count++;
            x /= i;
        }
        if (count > 0)
        {
            ret.push_back(make_pair(i, count));
        }
    }
    if (x != 1)
    {
        ret.push_back(make_pair(x, 1));
    }
    return ret;
}

int main()
{
    size_t N;
    cin >> N;

    vector<int> A(N);
    for (int &a : A)
    {
        cin >> a;
    }

    int global_gcd = A.front();
    for (int a : A)
    {
        global_gcd = gcd(global_gcd, a);
    }
    if (global_gcd != 1)
    {
        cout << "not coprime" << endl;
        return 0;
    }
    set<int> prime;
    for (int a : A)
    {
        for (pair<int, size_t> p : prime_factorization<int, size_t>(a))
        {
            if (prime.find(p.first) != prime.end())
            {
                cout << "setwise coprime" << endl;
                return 0;
            }
            prime.insert(p.first);
        }
    }
    cout << "pairwise coprime" << endl;
}


Measured memory_bytes: 7296
#include <stdio.h>
int main()
{
int i, n;
while (scanf("%d", &n) != EOF){
for (i = 1; i <= 512; i *= 2){
if (n % (i * 2) != 0){
printf("%d", i);
n -= i;
if (n != 0){
printf(" ");
}
}
if (n == 0){
puts("");
break;
}
}
}
return 0;
}

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

int main() {
    int ABC[5];
    for(int i=0;i<5;i++)cin>>ABC[i];
    int min=10;
    int sum=0;
    for(int i=0;i<5;i++){
        int r=ABC[i]%10;
        if(r!=0){
            if(min>r)min=r;
        }
        if(r!=0)ABC[i]+=10-r;
        sum+=ABC[i];
    }
    int ans;
    if(min==0){
        cout<<sum<<endl;
        return 0;
    }
    //cout<<min<<endl;
    cout << sum+min-10<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <tuple>
#include <set>
#include <map>
#include <unordered_map>
#include <complex>
#include <iomanip>
#include <cmath>
using namespace std;
typedef long long ll;

int main()
{
  int a, n;
  cin >> n >> a;
  cout << max(n * n - a, 0) << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
/*int a,b[100],c,d,e,f,max=0,min=100;
	cin>>a>>b;
	for(int i=0;i<b.size();i++){
		if(b[i]==1){
			c++;
		}
		if(b[i]==2){
			d++;
		}
		if(b[i]==3){
			e++;
		}
		if(b[i]==4){
			f++;
		}
	}
		if(max<c){
		max=c;
		}
		if(max<d){
		max=d;
		}
		if(max<e){
		max=e;
		}
		if(max<f){
		max=f;
		}
		if(min>c){
		min=c;
		}
		if(min>d){
		min=d;
		}
		if(min>e){
		min=e;
		}
		if(min>f){
		min=f;
		}
		cout<<max<<min<<endl;*/
		
	string a;
	cin>>a;
	a[5]=' ';
	a[13]=' ';
	cout<<a<<endl;
}

Measured memory_bytes: 256
/*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Code author: Saurabh Singhal
Code copy karne vaale tera muh kaala
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/

#include<bits/stdc++.h>
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define ppb pop_back

using namespace std;
typedef long long int ll;
typedef vector<int> vi_t;
typedef vector<ll> vll_t;
int t=1;
vll_t a,b;
int  main(){
	// #ifndef ONLINE_JUDGE
 //    // for getting input from input.txt
 //    freopen("input.txt", "r", stdin);
 //    // for writing output to output.txt
 //    freopen("output.txt", "w", stdout);
	// #endif
	int a,b,c,x,y;
	cin>>a>>b>>c>>x>>y;
	int cost1 =x*a+y*b;
	int cost2=min(x,y)*2*c;
	if(x>y){
		cost2+=a*(x-y);
	}
	else{
		cost2+=b*(y-x);
	}
	int cost3=max(x,y)*2*c;
	cout<<min(cost1,min(cost2,cost3))<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
//#include <stdio.h>
//#include <stack>
//#include <queue>
#include <cstdio>
#include <cmath>
#include <iterator>
#include <map>
//#include <fstream>
//#include <list>
//#include <iomanip>
#include <stdlib.h>
#include <cctype>

using namespace std;

#define MOD 1000000007
#define Int int64_t
#define PI 3.14159265358979
#define ssort(z) sort(z.begin(),z.end())
#define rsort(z) sort(z.rbegin(),z.rend())
#define eerase(z) z.erase(unique(z.begin(),z.end()),z.end())
#define ccnt(z,w) count(z.begin(),z.end(),w)


void printVec(std::vector<int> & vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}
void printVec1(std::vector<string>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}
void printVec2(std::vector<Int>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}

Int gcd(Int a, Int b) {
	return b != 0 ? gcd(b, a % b) : a;
}
Int lcm(Int a, Int b) {
	return a / gcd(a, b) *b;
	//a*bは64bit integer overflow
}

bool comp(const string a, const string b) {
	return a.length() < b.length();
}

bool integer(double num) {
	return floor(num) == num;
}

string gen(int num) {
	string str = "";
	for (int i = 0; i < num; i++) str += ".";
	return str;
}
Int fact(int num) {
	if (num == 0) return 1;
	else return num * fact(num - 1);
}


int main() {
	vector<int> n(5);
	for (int i = 0; i < 5; i++) {
		cin >> n[i];
	}
	int k; cin >> k;
	ssort(n);
	if (n[4] - n[0] <= k)cout << "Yay!";
	else cout << ":(";
	

	cout << endl;
	return 0;
}

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

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

    int n;
    cin >> n;
    vector<int> G(n);
    for(int i = 0; i < n - 1; i++){
        int a;
        cin >> a;
        G[a - 1]++;
    }

    for(int i = 0; i < n; i++){
        cout << G[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 3976
import Data.List

main = interact $ show . sol . read

sol :: Int -> Int
sol = sum . map (f . length) . group . primeFactors

f n = truncate $ sqrt (2*fromIntegral n+0.25)-0.5

primes = 2:filter ((==1) . length . primeFactors) [3,5..]

primeFactors 1 = []
primeFactors n = factor n primes

factor n (p:ps) 
  | p*p > n      = [n]
  | n `mod` p==0 = p:factor (n `div` p) (p:ps)
  | otherwise    = factor n ps

Measured memory_bytes: 11520
#include<bits/stdc++.h>
using namespace std;
int a[200005];
int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>a[i];
    int curr=1;
    for(int i=0;i<n;i++)
        if(a[i]==curr)
            curr++;
    if(curr==1)
        cout<<-1<<endl;
    else
        cout<<n-curr+1<<endl;
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <iterator>
#include <stack>
typedef long long int lli;
using namespace std;

/*
int dp[101][4][4];
int sche[101];

int main(){
	for(int i=0; i<101; ++i){
		sche[i]=-1;
		for(int j=0; j<4; ++j){
			for(int k=0; k<4; ++ k){
				dp[i][j][k]=-1;
			}
		}
	}
	int N,K;
	cin >> N >> K;
	for(int i=0; i<K; ++i){
		int A,B;
		cin >> A >> B;
		sche[A]=B;
	}
	for(int i=1; i<2; ++i){
		if(sche[i]!=-1){
			dp[i][sche[i]][0]=1;
		}else{
			for(int j=1; j<4; ++j){
				for(int k=1; k<4; ++k){
					dp[i][j][k]=1;
				}
			}
		}
	}
	for(int i=3; i<=N; ++i){
		if(sche[i]!=-1){
			for(int j=1; j<4; ++j){
				dp[i][sche[i]][j]=1;;
			}
		} else {
			for(int j=1; j<4; ++j){
				for(int k=1; k<4; ++k){
						
				}
			}
		}
	}
	return 0;
}
*/

long long int dp[101][4][3];
int sche[101];
int main(){
	for(int i=0; i<101; ++i){
		sche[i]=-1;
		for(int j=0; j<4; ++j){
			for(int k=0; k<3; ++k){
				dp[i][j][k]=0;
			}
		}
	}
	int N,K;
	cin >> N >> K;
	for(int i=0; i<K; ++i){
		int A,B;
		cin >> A >> B;
		sche[A]=B;
	}
	if(sche[1]!=-1){
		dp[1][sche[1]][1]=1;
	} else {
		for(int i=1; i<4; ++i){
			dp[1][i][1]=1;
		}
	}
	for(int i=2; i<=N; ++i){
		if(sche[i]!=-1){
			for(int j=1; j<4; ++j){
				if(sche[i]!=j){
					/*if(dp[i][sche[i]][1]+dp[i-1][j][1]+dp[i-1][j][2]>=dp[i][sche[i]][1])*/ dp[i][sche[i]][1]+=(dp[i-1][j][1]+dp[i-1][j][2])%10000;
					//if(dp[i][sche[i]][2]+dp[i-1][j][1]+dp[i-1][j][2]>=dp[i][sche[i]][2]) dp[i][sche[i]][2]+=dp[i-1][j][1]+dp[i-1][j][2];
				}else {
					/*if(dp[i][sche[i]][2]+dp[i-1][j][1]>=dp[i][sche[i]][2])*/ dp[i][sche[i]][2]+=dp[i-1][j][1]%10000;
				}
			}
		} else	{
			for(int j=1; j<4; ++j){
				for(int k=1; k<4; ++k){
					if(j!=k){
						/*if(dp[i][j][1]+dp[i-1][k][1]+dp[i-1][k][2]>=dp[i][j][1])*/ dp[i][j][1]+=dp[i-1][k][1]+dp[i-1][k][2]%10000;
						//if(dp[i][j][2]+dp[i-1][k][1]+dp[i-1][k][2]>=dp[i][j][2]) dp[i][j][2]+=dp[i-1][k][1]+dp[i-1][k][2];
					} else{
						/*if(dp[i][j][2]+dp[i-1][k][1]>=dp[i][j][2])*/dp[i][j][2]+=dp[i-1][k][1]%10000;
					}
				}
			}
		}
	}
	long long int ans=0;
	for(int i=1;i<4; ++i){
		for(int j=1; j<3; ++j){
			//cout << dp[N][i][j] << "\n";
			/*long long int tmp=ans;
			tmp+=dp[N][i][j];
			ans=tmp%10000;*/
			ans+=dp[N][i][j]%10000;
		}
	}
	cout << ans%10000 << "\n";
	return 0;
}

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

using namespace std;

const int maxn=1e6+5;

typedef long long ll;

const ll mod=1e9+7;

ll a[maxn];

int main(){
	int n,m;
	scanf("%d%d",&m,&n);
	int sum=0; 
	for(int i=0;i<n;i++){
		int x;
		scanf("%d",&x);
		sum+=x;
	}
	if(m>sum){
		printf("No");
	}
	else printf("Yes");
	return 0;
} 

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		int A = scan.nextInt();
		int B = scan.nextInt();
		int K = scan.nextInt();
		for(int i = Math.min(A, B); i >= 1; i--) {
			if(A % i == 0 && B % i == 0) {
				K--;
				if(K == 0) {
					System.out.println(i);
				}
			} 
		}
	}
}

Measured memory_bytes: 27040
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
	ll n,m;
	scanf("%lld%lld",&n,&m);
	if(m==0)
	{
		ll ans=n*n;
		printf("%lld\n",ans);
		return 0;
	}
	ll ans=(n-m+1)*(n-m)/2;
	for(int i=m+1;i<=n-m;i++)
	{
		int k=i+m;
		while(k<=n)
		{
			ans+=min(k-m+i,n+1)-k;
			k+=i;
		}
	}
	printf("%lld\n",ans);
	return 0;
}

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


string delete_s(string s, char t){
    string ans;
    //printf("a\n");
    for(long long i = 0; i < s.size()-1; i++){
        if(s[i] == t || s[i+1] == t){
            ans.push_back(t);
        }
        else{
            ans.push_back(s[i]);
        }
    }

    //cout << "ans : " << ans << endl;

    return ans;
}

int main(){
    string s;
    cin >> s;

    long long min_ans = 100;

    for(long long i = 0; i < s.size(); i++){
        char delete_c = s[i];

        long long count = 0;
        string s2 = s;
        while(1){
            //cout << "s2 : " << s2 << endl;
            if(s2.find_first_not_of(delete_c) == string::npos){
                break;
            }
            s2 = delete_s(s2, delete_c);
            
            count++;
        }

        min_ans = min(min_ans, count);
    }

    cout << min_ans << endl;

    return 0;
}

Measured memory_bytes: 256
program ABC060C
    implicit none
    integer(8)::N,T,i,result,ls,le
    integer(8),allocatable,dimension(:)::L
    read(5,*)N,T
    allocate(L(N))
    read(5,*)(L(i),i=1,N)
    result=0
    ls=L(1)
    le=L(1)

    if(N>=2)then
        do i=1,N-1
            if(L(i+1)-L(i)<=T)then
                le=L(i+1)
            else
                result=result+le-ls+T
                ls=L(i+1)
                le=L(i+1)
            end if
        end do
        result=result+le-ls+T
        print'(i0)',result
    else
        print'(i0)',T
    end if
            
end program ABC060C

Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
#define MAX 1000000

/*bool dfs(int a, int b, int n, int sum){
  if (sum >= b || n >= a) return sum == b;
  
  for (int i = 5; i > 0; i--)
    if (dfs(a, b, n + 1, sum + i)) return true;
  
  return false; 
}*/

int main(){
  int x;
  cin >> x;
  int a, b;
  a = x / 100;
  b = x % 100;
  
  if (a * 5 >= b) cout << 1;
  else cout << 0;
  //else if (dfs(a, b, 0, 0)) cout << 1;
  //else cout << 0;
  
  return 0;
}




Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author tatsumack
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

using namespace std;

typedef pair<int, int> P;

class DLine {
public:
    map<int, int> cnt;
    vector<vector<int>> G;

    void solve(std::istream& cin, std::ostream& cout) {
        int N, X, Y;
        cin >> N >> X >> Y;
        X--, Y--;
        G.resize(N);
        REP(i, N - 1) {
            G[i].push_back(i + 1);
            G[i + 1].push_back(i);
        }
        G[X].push_back(Y);
        G[Y].push_back(X);
        REP(i, N) {
            queue<pair<int, int>> q;
            q.push({i, 0});
            set<int> used;
            while (!q.empty()) {
                auto kv = q.front();
                q.pop();
                int p = kv.first;
                int d = kv.second;
                if (used.count(p)) continue;
                used.insert(p);
                cnt[d]++;
                for (auto to : G[p]) {
                    if (used.count(to)) continue;
                    q.push({to, d + 1});
                }
            }
        }

        FOR(k, 1, N - 1) {
            cout << cnt[k] / 2 << endl;
        }
    }
};


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);

    DLine solver;
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 640
use std::io::stdin;
use std::string::String;

fn main() {
    let mut line = String::new();
    stdin().read_line(&mut line).unwrap();
    let mut split = line.split_whitespace();
    let x: i64 = split.next().unwrap().parse().unwrap();
    let y: i64 = split.next().unwrap().parse().unwrap();
    let min = vec![(y - x, 0), (-y - x, 1), (-y + x, 2), (y + x, 1)]
        .iter()
        .filter(|&&(n, _)| n >= 0)
        .map(|&(n, i)| n + i)
        .min()
        .unwrap();
    println!("{}", min);
}


Measured memory_bytes: 380
#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<stack>
#include<array>
using namespace std;

#define FOR(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define rep(i,n) FOR((i),0,(n))

typedef long long ll;
map<string,array<int,256> >data;
const int INF=1e9+7;
int main(){
	int m;
	bool f=true;
	cin>>m;
	rep(i,m){
		string str;
		cin>>str;
		int l,u;
		cin>>l>>u;
		FOR(i,l,u+1){
			data[str][i]=1;
		}
	}
	int n;
	cin>>n;
	stack<array<int,256> > st;
	rep(k,n){
		string str;
		cin>>str;
		if(str=="0" || atoi(str.c_str())>0){
			int num=atoi(str.c_str());
			array<int,256>num_a;
			rep(i,256)num_a[i]=0;
			num_a[num]=1;
			st.push(num_a);
		}
		else if(str=="+"){
			array<int,256> ne,l,r;
			fill(ne.begin(),ne.end(),0);
			r=st.top();st.pop();
			l=st.top();st.pop();
			rep(i,256){
				rep(j,256){
					ne[(i+j)%256]|=(r[i]&l[j]);
				}
			}
			st.push(ne);
		}
		else if(str=="-"){
			array<int,256> ne,l,r;
			fill(ne.begin(),ne.end(),0);
			r=st.top();st.pop();
			l=st.top();st.pop();
			rep(i,256){
				rep(j,256){
					ne[(i-j+256)%256]|=(l[i]&r[j]);
				}
			}
			st.push(ne);
		}
		else if(str=="*"){
			array<int,256> ne,l,r;
			fill(ne.begin(),ne.end(),0);
			r=st.top();st.pop();
			l=st.top();st.pop();
			rep(i,256)rep(j,256)ne[(i*j)%256]|=(r[i]&l[j]);
			st.push(ne);
		}
		else if(str=="/"){
			array<int,256> ne,l,r;
			fill(ne.begin(),ne.end(),0);
			r=st.top();st.pop();
			l=st.top();st.pop();
			if(r[0]==1){
				f=false;
			}
			rep(i,256)FOR(j,1,256)ne[(i/j)%256]|=(l[i]&r[j]);
			st.push(ne);
		}
		else {
			st.push(data[str]);
		}
	}
	if(f)cout<<"correct"<<endl;
	else cout<<"error"<<endl;
}

Measured memory_bytes: 3164
#include <iostream>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#include <string>
#include <iomanip>
#include <functional>
#include <map>
#include <math.h>
#include <list>


using namespace std;

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

	list<string> str;
	string input;
	int n; cin >> n;
	while (n--) {

		cin >> input;
		str.push_back(input);

	}
	str.sort();
	str.unique();

	cout << str.size() << endl;

	return 0;
}


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

class DisjointSet {
public:
  vector<int> p, rank, size;
  DisjointSet(int n) {
    p.assign(n, 0);
    rank.assign(n, 0);
    size.assign(n, 0);
    for (int i = 0; i < n; i++) {
      make_set(i);
    }
  }

  void make_set(int x) {
    p[x] = x;
    rank[x] = 0;
    size[x] = 1;
  }

  bool same(int x, int y) {
    return true;
  }

  int find_set(int x) {
    if (x != p[x]) {
      p[x] = find_set(p[x]);
    }
    return p[x];
  }

  int union_size(int x) {
    if (x != p[x]) {
      size[x] = union_size(find_set(x));
    }
    return size[x];
  }

  void link(int x, int y) {
    if(rank[x]  > rank[y]) {
        p[y] = x;
        size[x] = size[x] + size[y];
    }else if(rank[x] < rank[y]){
        p[x] = y;
        size[y] = size[x] + size[y];
    }else if(x != y) {
      p[y] = x;
      rank[x]++;
      size[x] = size[x] + size[y];
    }
  }

  void unite(int x, int y) {
      link(find_set(x), find_set(y));
  }
};

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int H, W;
  cin >> H >> W;
  char c[H][W];
  int n = H * W;
  int d[n];
  for (int i = 0; i < H; i++) {
    string s;
    cin >> s;
    for (int j = 0; j < W; j++) {
      c[i][j] = s[j];
      int idx = i * W + j;
      if (c[i][j] == '#') d[idx] = 0;
      else d[idx] = 1;
    }
  }
  DisjointSet ds(n);
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (i + 1 < H && c[i][j] != c[i + 1][j]) {
        ds.unite(W * i + j, W * (i + 1) + j);
      }
      if (j + 1 < W && c[i][j] != c[i][j + 1]) {
        ds.unite(W * i + j, W * i + j + 1);
      }
    }
  }
  ll ans = 0;
  ll b[n]{};
  ll w[n]{};
  for (int i = 0; i < n; i++) {
    if (d[i] == 0) b[ds.find_set(i)]++;
    else  w[ds.find_set(i)]++;
  }
  for (int i = 0; i < n; i++) {
    ans += b[i] * w[i];
  }
  cout << ans << "\n";
  return 0;
}

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

int main() {
  vector<int> vec(5);
  for(int i = 0; i < 5; i++) {
    cin >> vec.at(i);
  }
  for(int i = 0; i < 5; i++) {
    if(vec.at(i) == 0) {
    cout << i+1 << endl;
    }
  }
}


Measured memory_bytes: 3628
import sys


def resolve(in_):
    a, b, c = map(int, next(in_).split())
    k = int(next(in_))
    for _ in range(k):
        if a >= b:
            b *= 2
        elif b >= c:
            c *= 2
        else:
            break
    return 'Yes' if a < b and b < c else 'No'


def main():
    answer = resolve(sys.stdin.buffer)
    print(answer)


if __name__ == '__main__':
    main()

Measured memory_bytes: 9240
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n=0,best_n=0,T=0,A=0,height_i,temp_average=0,temp_diff_from_a=0;
    scanf("%d",&n);
    scanf("%d %d",&T,&A);

    for(int i=0;i<n;i++){
	scanf("%d",&height_i);
	temp_average=1000*T-height_i*6;

	if(i==0 || abs(1000*A-temp_average)<temp_diff_from_a){
	    temp_diff_from_a=abs(1000*A-temp_average);
	    best_n=i;
	}

    }
    printf("%d",best_n+1);
    return 0;
}



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

int main()
{
   ios::sync_with_stdio(false);
    int a,b,c,x,y;
    int ans=0,cnta=0,cntb=0;;
    cin>>a>>b>>c>>x>>y;
    float ma,mb;
    ma=(a)/(float)(a+b)*c;
    mb=(b)/(float)(a+b)*c;
    if((2*c)<(a+b))
        {
            if(x<y)
            {
                int cc=cnta;
                cnta+=(x-cc);
                cntb+=(x-cc);
                ans+=x*2*c;
            }
           else
           {
                int cc=cntb;
                cnta+=(x-cc);
                cntb+=(x-cc);
                ans+=y*2*c;
           }
        }
        else
        {
             cout<<x*a+y*b;
             return 0;
        }

        if(x>y){
        int cc=min(2*c,a);
        ans+=(cc*(x-y));
    }
    else{
        int cc=min(2*c,b);
        ans+=(cc*(y-x));
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(N: int, A: "List[int]"):
    A.sort(reverse=True)
    sm = A[0]
    dw = (N - 2) // 2
    for i in range(1, dw + 1):
        sm += A[i] * 2
    if (N - 2) % 2 == 1:
        sm += A[dw + 1]  
    print(sm)

    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()

Measured memory_bytes: 93252
#include <iostream>
#include<string>
using namespace std;
int main(){
	int k;
	string s;
	cin >> k >> s;
	int n = s.size() - k ;
	if (k < s.size()) {
		for (int i = 0; i<n; i++)
			s.pop_back();
		cout << s << "...";
	}
	else
		cout << s;
}

Measured memory_bytes: 3616
N = int(input())
S = input()
table_e = []
count_e = 0
table_w = []
count_w = 0
for s in S:
    if s == 'E':
        count_e += 1
    else:
        count_w += 1
    table_e.append(count_e)
    table_w.append(count_w)
ans = float('inf')
for i in range(N):
    tmp = table_w[i - 1] if i else 0
    tmp += count_e - table_e[i]
    ans = min(ans, tmp)
print(ans)


Measured memory_bytes: 17628
fn main() {
    let (a, b, c, d) = input();
    println!("{}", solve(a,b,c,d));
}

fn input() -> (i32, i32, i32, i32) {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    let a: i32 = iter.next().unwrap().parse().unwrap();
    let b: i32 = iter.next().unwrap().parse().unwrap();
    let c: i32 = iter.next().unwrap().parse().unwrap();
    let d: i32 = iter.next().unwrap().parse().unwrap();
    (a,b,c,d)
}

fn solve(a: i32, b: i32, c: i32, d: i32) -> String {
    let mut takahashi: (i32, i32) = (a, b); // hp, attack
    let mut aoki: (i32, i32) = (c, d);

    loop {
        aoki.0 -= takahashi.1;
        if aoki.0 <= 0 {
            return String::from("Yes");
        }
        takahashi.0 -= aoki.1;
        if takahashi.0 <= 0 {
            return String::from("No");
        }
    }
}


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

vector<int> g[100001];
int cache[100001];
int dfs(int node) {
	if(cache[node]!=-1) {
		return cache[node];
	}
	
	int mx_depth = 0;
	for (int i=0; i<g[node].size(); i++) {
		int nei = g[node][i];
		mx_depth = max(mx_depth, dfs(nei)+1);
	}
	
	return cache[node] = mx_depth;
}

int main() {
	int n,m;
	cin>>n>>m;
	for (int i=0; i<m; i++) {
		int x,y;
		cin>>x>>y;
		x--;y--;
		g[x].push_back(y);
	}
	
	for (int i=0; i<100001; i++) {
		cache[i]=-1;
	}
	
	int mx = 0;
	for (int i=0; i<n; i++) {
		mx = max(mx, dfs(i));
	}
	
	cout << mx;
	return 0;
}

Measured memory_bytes: 8192
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
#include <set> 
int main(){
  int n;
  cin>>n;
  vector<int> a(n);
  rep(i,n){
    cin>>a.at(i);
  }
  set<int> s;
  rep(i,n){
    s.insert(a.at(i));
  }
  if(s.size()==n)cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
  
  



}

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

//s[i]まで探索している
//i:探索位置　sum:iの時点での合計 split:一つ前の区切り(splitからiまでが切り出される) s:文字列
// long long じゃないと処理できない
long long int dfs(int i, long long int sum, int split, const string s) {
    int next_split = i - split + 1;
    //区切りを入れた時点で足す分
    long long int sum_plus = 0;
    if (next_split > 0) {
        sum_plus = stoll(s.substr(split,next_split));
        /*if(sum_plus<0) {
            cout << sum_plus << endl;
        }*/
    }
    //末端の折り返し
    if (i == s.size()-1) {
        sum += sum_plus;
    } else {
        //区切らない場合＋区切った場合
        sum = dfs(i+1, sum, split, s) + dfs(i+1, sum + sum_plus, i+1, s);
    }
    //if (i==9) cout << 9 << " " << split << " " << sum << endl;
    //if (sum<0) cout << i << " " << split << " " << sum << endl;
    return sum;
}

int main() {
    string s;
    cin >> s;
    long long int ans;
    ans = dfs(0,0,0,s);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input()) + 1
l = list(map(int, input().split()))
l.append(0)

count = 0

for i in range(n):
	while(l[i] > 0):
		for j in range(i + 1, n):
			if l[j] == 0:
				break
		for k in range(i, j):
			l[k] -= 1
		count += 1
print(count)

Measured memory_bytes: 3060
#!/usr/bin/env python3

def main():
    n = int(input())
    i = list(map(int,input().split()))
    j = list(map(int,input().split()))
    ans=[]

    for k in range(1,n+1):
        #print(i[0:k] , j[k-1:n+1] , sep=' ' , end=">")
        #print(sum(i[0:k]),sum(j[k-1:n+1]),sep=' ',end="=")
        total = sum(i[0:k]) + sum(j[k-1:n+1])
        #print(total)
        ans.append(total)

    print(max(ans))
main()


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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////
ll N,M,A[101010], B[101010];
ll ans;
vector<pll> dv;
ll i, j,k,l;

int main(){
    scanf("%lld%lld", &N,&M);
    fornum(i,0,N){
        ll a, b;
        scanf("%lld%lld", &a,&b);
        dv.push_back(mp(a, b));
    }
    sort(dv.begin(), dv.end());
    fornum(i,0,N){
        auto d = dv[i];
        if(M>d.second){
            ans += d.second * d.first;
            M -= d.second;
        }else{
            ans += d.first * M;
            break;
        }
    }
    printf("%lld", ans);

    return 0;
}

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


using namespace std;

#define M 1000000007
#define pb push_back
#define f first
#define s second
#define rep(i, st, ed) for(int i=st; i<ed; i++)
#define repn(i, st, ed) for(int i=st; i<=ed; i++)
#define repb(i, ed, st) for(int i=ed; i>=st; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;
typedef unsigned long long int llt;
typedef long double ld;

const long double PI  = 3.141592653589793238463;
const int N = 1e5+10;
const ll INF = 1LL << 60;

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


// Main Code


int main()
{
	ll n, k;
	cin>>n>>k;
	vector<ll> pos, neg;
	ll z = 0;
	pos.pb(0);
	rep(i, 0, n)
	{
		ll x;
		cin>>x;
		if(x < 0)
			neg.pb(x);
		else if(x > 0)
			pos.pb(x);
		else 
			z++;
	}
	ll ans = INF;
	k = k - z;
	neg.pb(0);
	reverse(all(neg));
	repn(i, 0, k)
	{
		if(k-i >= neg.size()) continue;
		ll left = neg[k-i];
		if(i >= pos.size()) continue;
		ll right = pos[i];
		//cout<<left<<" "<<right<<endl;
		ll tans = abs(left) + 2*abs(right);
		chmin(ans, tans);
		ll ttans = 2*abs(left) + abs(right);
		chmin(ans, ttans);
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 1656