akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Deque;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;
import java.util.Set;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		int N = sc.nextInt();
		int M = sc.nextInt();
		int[] p = new int[N];
		List<Integer>[] adj = new List[N];
		for (int i = 0; i < adj.length; i++) {
			adj[i] = new ArrayList<>();
		}
		for (int i = 0; i < p.length; i++) {
			p[i] = sc.nextInt() - 1;
		}
		int a, b;
		for (int i = 0; i < M; i++) {
			a = sc.nextInt() - 1;
			b = sc.nextInt() - 1;
			adj[a].add(b);
			adj[b].add(a);
		}
		int ans = 0;
		int[] vis = new int[N];
		int id = 1;
		for (int i = 0; i < N; i++) if (vis[i] == 0) {
			Deque<Integer> cola = new ArrayDeque<>();
			Set<Integer> got = new HashSet<>();
			cola.addFirst(i);
			vis[i] = id;
			while (!cola.isEmpty()) {
				int cur = cola.removeFirst();
				got.add(p[cur]);
				for (int vec : adj[cur]) {
					if (vis[vec] == 0) {
						vis[vec] = id;
						cola.addLast(vec);
					}
				}
			}
			for (int val : got) {
				if (vis[val] == id) ans++;
			}
			id++;
		}
		System.out.println(ans);
	}
}


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

// chmin, chmax関数
template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) {
        xmax = x;
        return true;
    }
    return false;
}
template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x;
        return true;
    }
    return false;
}

// Yes-Noを出力する問題で楽をする
void Ans(bool f){
    if(f) cout << "Yes" << endl;
    else cout << "No" << endl;
}

//---------------------------

int main(){
    ll n,k; cin >> n >> k;
    VL snuke(n,0);
    rep(i,k){
        ll d;
        cin >> d;
        rep(j,d){
            ll a; cin >> a;
            snuke[a-1]++;
        }
    }

    ll ans=0;
    rep(i,n){
        if(snuke[i]==0) ans++;
    }
    cout << ans << endl;
    return 0;
}

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

typedef pair<int, int> ii;
const int N = 1000005;

int n, m, cnt[N];
int a[N], res[N];
int val[N];
vector<int> p[N];

int main() {
	ios::sync_with_stdio(false);
	cin >> n >> m;
	if (m == 1) {
		cout << "0\n"; return 0;
	}
	for (int i = 1; i <= n; ++i) {
		cin >> a[i], cnt[a[i]]++, p[a[i]].push_back(i);
	}
	set<ii> s;
	for (int i = 1; i <= m; ++i) s.insert(ii(cnt[i], i));
	for (int i = 1; i <= m; ++i) {
		res[i] = 1e9;
		for (int j = 0; j < 2; ++j) {
			vector<int> go;
			int sum = 0;
			for (int k = 0; k < p[i].size(); ++k) {
				if (p[i][k] % 2 == j) {
					int cur = a[p[i][k] - 1];
					if (p[i][k] > 1 && cur != i) {
						if (++val[cur] == 1) go.push_back(cur);
					}
				}
				else {
					int cur = a[p[i][k] + 1];
					if (p[i][k] < n && cur != i) {
						if (++val[cur] == 1) go.push_back(cur);
					}
				}
			}
			for (int k = 0; k < go.size(); ++k) {
				s.erase(s.find(ii(cnt[go[k]], go[k])));
				s.insert(ii(cnt[go[k]] - val[go[k]], go[k]));
			}
			s.erase(s.find(ii(cnt[i], i)));
			res[i] = min(res[i], n - ((*(--s.end())).first + cnt[i]));
			for (int k = 0; k < go.size(); ++k) {
				s.erase(s.find(ii(cnt[go[k]] - val[go[k]], go[k])));
				s.insert(ii(cnt[go[k]], go[k]));				
			}
			s.insert(ii(cnt[i], i));
			for (int k = 0; k < go.size(); ++k) val[go[k]] = 0;
		}
		cout << res[i] << '\n';
	}
}

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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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

const ll INF = 1e9;
const ll MOD = 998244353;
const ll LINF = 1e18;

ll modpow(ll a, ll n) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % MOD;
    (a *= a) %= MOD;
    n >>= 1;
  }
  return res;
}

const ll maxf = 10000000;
ll fact[maxf+5];
ll ifact[maxf+5];

void fact_init(){
  fact[0] = 1;
  for(ll i=1; i<=maxf; i++) fact[i] = (fact[i-1] * i) % MOD;
  ifact[maxf]=modpow(fact[maxf],MOD-2);
  for(ll i=maxf; i>=1; i--) ifact[i-1] = (ifact[i] * i) % MOD;
}

ll comb(ll n, ll r){
  if(n<r || n<0 || r<0) return 0;
  if(fact[0] == 0) fact_init();
  return ((fact[n] * ifact[n-r]) % MOD * ifact[r]) % MOD;
}

ll naive_comb(ll n, ll r){
  ll res = 1;
  for (ll i = n; i > n - r; i--) res = res * i % MOD;
  for (ll i = 1; i <= r; i++) res = (res * modpow(i, MOD-2)) % MOD;
  return res;
}

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  
  ll n,m,k; cin>>n>>m>>k;
  ll ans=0;
  rep(i,k+1){
    ll tmp=comb(n-1,i)*(m*modpow(m-1,n-i-1)%MOD)%MOD;
    // cout<<tmp<<endl;
    (ans+=tmp)%=MOD;
  }
  cout<<ans<<endl;
}

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

ll X, Y, Z, K, A[1009], B[1009], C[1009];
vector<ll> vec;

int main() {
    cin >> X >> Y >> Z >> K;
    for (int i = 0; i < X; i++) cin >> A[i];
    sort(A, A + X, greater<ll>());
    for (int i = 0; i < Y; i++) cin >> B[i];
    sort(B, B + Y, greater<ll>());
    for (int i = 0; i < Z; i++) cin >> C[i];
    sort(C, C + Z, greater<ll>());

    for (int i = 0; i < X; i++) {
        for (int j = 0; j < Y; j++) {
            for (int k = 0; k < Z; k++) {
                if ((i+1) * (j+1) * (k +1) <= K) {
                    vec.push_back(A[i] + B[j] + C[k]);
                } else {
                    break;
                }
            }
        }
    }
    sort(vec.begin(), vec.end(), greater<ll>());
    for (int i = 0; i < K; i++) cout << vec[i] << endl;
    return 0;
}

Measured memory_bytes: 1400
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <utility>
#include <vector>
#include <cmath>
#include <map>
#include <string>

using namespace std;

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

    int n, m;
    cin >> n >> m;

    int s[10];
    int p[10];

    for (size_t i = 0; i < m; i++)
    {
        s[i] = 0;

        int k;
        cin >> k;
        for (size_t j = 0; j < k; j++)
        {
            int si;
            cin >> si;
            s[i] |= 1 << (si - 1);
        }
    }

    for (size_t i = 0; i < m; i++)
    {
        cin >> p[i];
    }

    int ans = 0;

    for (size_t sw = 0; sw < (1 << n); sw++)
    {
        bool fail = false;

        for (size_t i = 0; i < m; i++)
        {
            int x = sw & s[i];
            int y = 0;
            
            for (size_t j = 0; j < (1 << n); j++)
            {
                y += x & 1;
                x >>= 1;
            }
            
            if (y % 2 != p[i]) {
                fail = true;
                break;
            }
        }
        
        if (!fail) ans++;
    }

    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 256
/*
!لَا أَبْرَحُ حَتَّىٰ أَبْلُغَ
فَصَبْرٌ جَمِيلٌ
*/
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define endl                         '\n'	
#define Ceil(x,y)             ((x+y-1)/y)
#define sz(s)               (int)s.size()
#define RT(x)           return cout<<x,0;
#define mem(x,y)    memset(x,y,sizeof(x))
#define all(v) ((v).begin()), ((v).end())
#define vi                    vector<int>
#define Tesla              file();
#define fr(x,y) for(int x=0; x<(y); ++x)
#define fe(x,z,y) for(int x=z; x<(y); ++x)
const double PI = acos(-1), EPS = 1e-7;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int dr[] { -1, -1, 0, 1, 1, 1, 0, -1 };
const int dc[] { 0, 1, 1, 1, 0, -1, -1, -1 };
ll gcd(ll x, ll y) { return (!y) ? x : gcd(y, x%y); }
ll lcm(ll x, ll y) { return ((x / gcd(x, y))*y); }
ll mod = 998244353;
ll power(ll x, ll y)
{
	if (y == 0)return 1;
	if (y == 1)return x;
	ll r = power(x, y / 2) % mod;
	return r%mod*r%mod*power(x, y % 2) % mod;
}
void file() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif  !ONLINEJUDGE
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

}

int main()
{
	Tesla
		ll ans = 0;
		int n; cin >> n;
		fe(i, 1, n + 1)
			fe(j, 1, n + 1)
			fe(k, 1, n + 1)
			ans += gcd(i, gcd(j, k));
		cout << ans;

		
}

Measured memory_bytes: 3608
#include<iostream>
using namespace std;
int main(void){
int n,r,c[1000],t[1000];
int a = 0;
int s = 0;
cin >> n >> r;

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

    if(t[i] <= r){
        s++;
        if(s == 1)
            a = c[i];
        else if(c[i] <= a)
            a = c[i];        
        }
}
    if(s == 0)
        cout << "TLE" << "\n";
    else
        cout << a << "\n";
    
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int array[5];
int ret[4];
void p(int a,int b,int c){

  for(int i = 0 ; i < 5 ; i++){
    if(array[i] == a)cout << 1 << endl;
    else if(array[i] == b)cout << 2 << endl;
    else cout << 3 << endl;
  }
}
int main(){

  while(cin >> array[0] ,array[0]){
    fill(ret,ret + 4,0);
    ret[array[0]] = 1;
    for(int i = 1 ; i < 5 ; i++ ){
      cin >> array[i];
      ret[array[i]] = 1;
  }
    if(ret[1] != 0 && ret[2] != 0 && ret[3] == 0){
      p(1,2,3);
    }else if(ret[2] != 0 && ret[3] != 0 && ret[1] == 0){
      p(2,3,1);
    }else if(ret[1] != 0 && ret[3] != 0 && ret[2] == 0){
      p(3,1,2);
    }else p(4,4,4);
  }
}

Measured memory_bytes: 1160
#include <iostream>
#include <string>
#include <vector>
typedef unsigned int UINT;
using namespace std;
bool isHoner(bool A, bool B)
{
    /*
        1 1 =1
        0 1 =0
        0 0 =1
        1 0 =0
    */
    if (A == B)
        return true;
    else
        return false;
}
bool Trans(string say)
{
    if (say[0] == 'H')
        return true;
    else
        return false;
}



int main(void) {
    string say1,say2;
    cin >> say1 >> say2;
    if (isHoner(Trans(say1), Trans(say2)))
        cout << 'H' << endl;
    else
        cout << 'D' << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main()
{
    int i, n;
    scanf("%d\n",&n);
    int card[4][14];
    for (i=0;i<4;i++){
       for(int j=0;j<14;j++){
            card[i][j]=0;
       }
    }
    char s;
    int r;
    for (i=0;i<n;i++){
        scanf("%c %d\n",&s,&r);
        if (s=='S') card[0][r]=1;
        else if (s=='H')card[1][r]=1;
        else if (s=='C')card[2][r]=1;
        else card[3][r]=1;
    }
    for (i=1;i<=13;i++){
        if (card[0][i]==0){
            printf("S %d\n",i);
        }
    }
    for (i=1;i<=13;i++){
        if (card[1][i]==0){
            printf("H %d\n",i);
        }
    }for (i=1;i<=13;i++){
        if (card[2][i]==0){
            printf("C %d\n",i);
        }
    }for (i=1;i<=13;i++){
        if (card[3][i]==0){
            printf("D %d\n",i);
        }
    }
    return 0;
}


Measured memory_bytes: 2048
#include <stdio.h>
int main()
{
	int N, K;
	char string[52];
	
	
	scanf("%d %d\n", &N, &K);
	scanf("%s", &string); 

	string[K-1] += 32;
	
 
	printf("%s\n",  string);
 
	return 0;
}

Measured memory_bytes: 1632
<?php
$N = trim(fgets(STDIN));
$A[] = explode(' ', trim(fgets(STDIN)));
$A[] = explode(' ', trim(fgets(STDIN)));

$B[0][-1] = $B[1][$N] = 0;
for ($i = 0; $i < $N; $i++) {
    $B[0][$i] = $B[0][$i-1] + $A[0][$i];
    $B[1][$N-$i-1] = $B[1][$N-$i] + $A[1][$N-$i-1];
}

$max = 0;
for ($i = 0; $i < $N; $i++) {
    $max = max($max, $B[0][$i] + $B[1][$i]);
}
print "{$max}\n";

Measured memory_bytes: 4856
def main():
    N, A, B = map(int, input().split())
    if N == 1 and A != B:
        print(0)
        return
    if A > B:
        print(0)
        return
    min_sum = A * (N - 1) + B
    max_sum = A + (N - 1) * B
    ans = max_sum - min_sum + 1
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
import java.util.*;
public class Main  {
   public static void main(String[] args) throws java.lang.Exception  {
      Scanner sc = new Scanner(System.in);
      
      String  a = sc.next();
         
      char aa = a.charAt(0);
      char bb = a.charAt(1);
      char cc = a.charAt(2);
         
      if (aa == bb && bb == cc) {
         System.out.println("No");
      } else {
         System.out.println("Yes");
      }
   }        
}


Measured memory_bytes: 21844
#include <valarray>
#include <cstdio>
using namespace std;
typedef valarray<int>V;
int n,m,a,b,c,t;
V M(const V &x,const V &y){
	V z(n*n);
	int i=0,j;
	for(;i<n;i++)for(j=0;j<n;j++)z[i*n+j]=(x[slice(i*n,n,1)]*y[slice(j,n,n)]).sum()%m;
	return z;
}
V E(const V &x,const int &n){
	if(n==1)return x;
	if(n&1)return M(E(x,n-1),x);
	V y=E(x,n>>1);
	return M(y,y);
}
V s,x;
void O(const V &r){
	int i=0;
    for(;i<n-1;i++)printf("%d ",(r[slice(i*n,n,1)]*s).sum()%m);
    printf("%d\n",(r[slice(i*n,n,1)]*s).sum()%m);
}
main(){
	int i;
	for(;scanf("%d%d%d%d%d%d",&n,&m,&a,&b,&c,&t),n;){
		s.resize(n);
		for(i=0;i<n;i++)scanf("%d",&s[i]);
		x.resize(0);
		x.resize(n*n);
		if(t){
			x[0]=b;
			x[1]=c;
			for(i=1;i<n-1;i++){
				x[i*n+i-1]=a;
				x[i*n+i]=b;
				x[i*n+i+1]=c;
			}
			x[i*n+i-1]=a;
			x[i*n+i]=b;
			O(E(x,t));
		}else{
			for(i=0;i<n;i++)x[i*n+i]=1;
			O(x);
		}
	}
}

Measured memory_bytes: 1084
# -*- coding: utf-8 -*-
"""
Created on Sat Mar  9 20:50:37 2019

@author: Yamazaki Kenichi
"""

N,M = map(int,input().split())
A = [list(map(int,input().split())) for i in range(N)]

A.sort()
counta = M
i = 0
ans = 0
while counta > 0:
    if A[i][1] < counta:
        ans += A[i][0]*A[i][1]
        counta -= A[i][1]
        i += 1
    else:
        ans += A[i][0]*counta
        counta = 0
#    print(i,counta)
print(ans)

Measured memory_bytes: 27880
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <tuple>
using namespace std;
typedef pair<int,double> P;//to,cost

vector<P> G[100000];
double e1,p;

double dfs1(int v,int par=-1){
    double ret=0;
    for(auto g:G[v]){
        int to; double cost;
        tie(to,cost)=g;
        if(to==par)continue;
        ret+=p*(cost+dfs1(to,v));
    }
    return ret;
}

double dfs2(int v,int par=-1){
    double ret=e1;
    for(auto g:G[v]){
        int to; double cost;
        tie(to,cost)=g;
        if(to==par)continue;
        ret+=p*(cost+dfs2(to,v));
    }
    return ret;
}

int main(){
    cin>>p;
    int N;
    cin>>N;
    for(int i=0;i<N-1;i++){
        int x,y,c;
        cin>>x>>y>>c;
        G[x-1].emplace_back(y-1,c);
        G[y-1].emplace_back(x-1,c);
    }
    e1=dfs1(0);
    double ans = dfs2(0);
    cout.precision(12);
    //cout<<fixed;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 16480
import java.util.Scanner;

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

		int n = sc.nextInt();
		int d = sc.nextInt();
		int count = 0;
		for (int i = 0; i < n; i++) {
			int x = sc.nextInt();
			int y = sc.nextInt();

			double dt = Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2));
			if (dt <= d) {
				count++;
			}
		}
		System.out.println(count);
	}
}

Measured memory_bytes: 60312
#x = int(input())
#A = list(map(int, input().split()))
n, d = map(int, input().split())
import math
l = 0
ans = 0

for i in range(n):
  x, y = map(int, input().split())
  l = math.sqrt(x**2+y**2)
  if l <= d:
    ans += 1

print(ans)

Measured memory_bytes: 9120
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<utility>
#include<string>
#include<stack>
#include<queue>
#include<set>
#include<math.h>
#include <map>
using namespace std;
typedef long long int ll;
#define repi(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,a) repi(i,0,a)
#define all(u) u.begin(),u.end()

ll H[1000];

ll Min(ll l, ll r){
    ll m = 10000;
    repi(i,l,r){
        if (H[i] <= m) m = H[i];
    }
    return m;
}

ll solve(ll l, ll r){
    if (l == r) return 0;
    ll d = Min(l,r);
    repi(i,l,r) H[i] -= d;
    ll dif[1000];
    dif[0] = l-1;
    ll c = 1;
    repi(i,l,r){
        if (H[i] == 0) {
            dif[c] = i;
            c ++;
        }
    }
    dif[c] = r;
    c ++;
    ll rep = d;
    rep(i,c-1){
        rep += solve(dif[i]+1,dif[i+1]);
    }
    return rep;
}

int main() {
    ll N; scanf("%lld",&N);
    rep(i,N) scanf("%lld",&H[i]);
    cout << solve(0,N) << endl;
    return 0;
}


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

int main() {
  string s, t;
  cin >> s >> t;
  
  if (s[0] == t[2] && s[1] == t[1] && s[2] == t[0]) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}


Measured memory_bytes: 256
import itertools

n = int(input())
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))

a = 1
b = 1
idx = 1
for tp in itertools.permutations(range(1, n+1)):
    if tp == p:
        a = idx
    if tp == q:
        b = idx
    idx += 1

print(abs(a-b))

Measured memory_bytes: 3064
import sys
from heapq import heappop, heappush
from operator import itemgetter

N, d = map(int, sys.stdin.readline().split())
x_max, x_min, y_max, y_min = [], [], [], []

ans = 0
for x, y, b in sorted([list(map(int, l.split())) for l in sys.stdin.readlines()], key=itemgetter(2)):
    heappush(x_max, (-x, b))
    heappush(x_min, (x, b))
    heappush(y_max, (-y, b))
    heappush(y_min, (y, b))
    for _a in (x_max, x_min, y_max, y_min):
        while _a[0][1] < b-d:
            heappop(_a)

    area = (-x_max[0][0]-x_min[0][0])*(-y_max[0][0]-y_min[0][0])
    if area > ans:
        ans = area
print(ans)



Measured memory_bytes: 121836
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <cstring>
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <numeric>
#include <float.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef unsigned long long ll;

int main(){
int N,K; cin >> N >> K;
set<int> s;
vector<int> A(N);
vector<int> B(N,0);
rep(i,N) cin >> A[i];
rep(i,N) {
	B[A[i]-1]++;
	s.insert(A[i]-1);
}
vector<pair<int, int>> c(N);//配列の宣言
for(int i = 0; i < N ; i++){
  int a,b;
  a = i;
  b = B[i];
  c[i] = make_pair(b,a);//配列型のpairに代入
}
  sort(c.begin(),c.end());//pair.firstを小さい順にsort




if (s.size() <= K){
	cout << 0 << endl;
}
else {
	int sum = 0;
	int i = 0;
	while(s.size() != K){
		if(s.count(c[i].second)){
			sum += c[i].first;
			s.erase(c[i].second);
		}
		i++;
	}
	cout << sum << endl;
}
}

Measured memory_bytes: 12800
n,k = map(int,input().split())
P = list(map(int,input().split()))
P = [(p+1)/2 for p in P]
s = 0
for i in range(k):
    s += P[i]
    
ans = s
for i in range(k,n):
    s += P[i]
    s -= P[i-k]
    ans = max(ans,s)
    
print(ans)
    

Measured memory_bytes: 25060
#include<bits/stdc++.h>
using namespace std;
const int md=1e9+7;
inline void add(int &x,int y){x+=y;if(x>=md)x-=md;}
int n;
int a[610];
int typ[610];
int cnt;
int dp[2][610][610];
int t[610],tot;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n+n;i++)scanf("%d",a+i);
	for(int i=1;i<=n;i++)
	{
		if(a[i+i-1]==-1 && a[i+i]==-1)cnt++;
		else
		{
			if(a[i+i-1]==-1)typ[a[i+i]]=1;
			else if(a[i+i]==-1)typ[a[i+i-1]]=1;
			else typ[a[i+i-1]]=typ[a[i+i]]=2;
		}
	}
	for(int i=n+n;i>=1;i--)
	{
		if(typ[i]==2)continue;
		t[++tot]=typ[i];
	}
	dp[0][0][0]=1;
	for(int i=1;i<=tot;i++)
	{
		int ii=i&1;
		memset(dp[ii],0,sizeof(dp[ii]));
		for(int j=0;j<=i;j++)
		{
			for(int k=0;k<=i;k++)
			{
				int tmp=dp[ii^1][j][k];
				if(!tmp)continue;
				if(t[i])
				{
					add(dp[ii][j][k+1],tmp);
					if(j)add(dp[ii][j-1][k],tmp);
				}
				else
				{
					add(dp[ii][j+1][k],tmp);
					if(j)add(dp[ii][j-1][k],tmp);
					if(k)add(dp[ii][j][k-1],1LL*k*tmp%md);
				}
			}
		}
	}
	int ans=dp[tot&1][0][0];
	for(int i=1;i<=cnt;i++)ans=1LL*ans*i%md;
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 3200
#include <iostream>

using namespace std;

int main()
{
    int k;
    string s;
    cin >> k >>s;
    if ( k >= s.length()){
        cout << s;
        return 0;
    }
    s+=" ";
    for(int i = 0 ; i < k ; i ++ )
    {
        if (s[i]==' ') break;
        cout << s[i];
    }
     cout << "...";
    return 0;
}


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

int main(){
    double r , a , c ;
    cin >> r;
    a = r * 3.141592653589793832 * 2;
    c = r * r * 3.141592653589793832;
    printf("%.6lf %.6lf\n", c , a);
    return 0;
}



Measured memory_bytes: 3296
#include <bits/stdc++.h>
using namespace std;
#define repl(i, l, r) for (ll i = (l); i < (r); i++)
#define rep(i, n) repl(i, 0, n)
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define CST(x) cout << fixed << setprecision(x)
using ll = long long;
const ll MOD = 1000000007;
const int inf = 1e9 + 10;
const ll INF = 4e18 + 10;
int a[505][505];
int main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);

	int n, m, q;
	cin >> n >> m >> q;
	rep(i, m) {
		int l, r;
		cin >> l >> r;
		a[l][r]++;
	}
	rep(i, 505) rep(j, 504) a[i][j + 1] += a[i][j];
	rep(i, 505) rep(j, 504) a[j + 1][i] += a[j][i];
	rep(i, q) {
		int p, q;
		cin >> p >> q;
		cout << a[q][q] - a[p - 1][q] - a[q][p - 1] + a[p - 1][p - 1] << endl;
	}
	return 0;
}

Measured memory_bytes: 4604
a,b = map(int,input().split())
f = 0
for i in range(a+1):
    if f == 1: break
    for j in range(a+1-i):
        if f == 1: break
        k = a-i-j
        if (i*10000 + j*5000 + k*1000) == b:
                f = 1
                print(i,j,k)
if f == 0: print(-1,-1,-1)

Measured memory_bytes: 3064
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-12;

//int N, M, K, T, H, W, L, R;
long long int N, M, K, T, H, W, L, R;



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

	while (cin >> N >> M, N) {
		vector<vector<int>>v(N);
		vector<int>sum(N);
		int num = 0;
		for (auto&i : v) {
			cin >> K;
			num += K;
			i.resize(K);
			for (auto &j : i)cin >> j;
		}
		int mx = 0;
		int mi = MOD;
		for (int i = 0; i < N; i++) {
			sum[i] = accumulate(v[i].begin(), v[i].end(), 0);
			mx = max(mx, sum[i]);
			mi = min(mi, sum[i]);
		}
		while (1) {
			int nx = -1;
			for (int i = 0; i < N; i++) {
				if (v[i].empty())continue;
				if (sum[i] - v[i].back() + M >= mx) {
					nx = i;
				}
			}
			if (nx == -1) {
				for (int i = 0; i < N; i++) {
					if (v[i].empty())continue;
					if (sum[i] == mx) {
						if (nx == -1)nx = i;
						if (v[nx].back() > v[i].back())nx = i;
					}
				}
			}
			if (nx == -1)break;
			sum[nx] -= v[nx].back();
			v[nx].pop_back();
			mi = *min_element(sum.begin(), sum.end());
			mx = *max_element(sum.begin(), sum.end());
			if (mx - mi > M)break;
			num--;
		}
		if (num)cout << "No\n";
		else cout << "Yes\n";
	}
}


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

using namespace std;

int main(){

	int n, tmp;
	vector<int> v;

	cin>> n;
	v.resize(n, 0);
	for (int i = 0;i < n-1;i++) {
		cin >> tmp;
		v[tmp-1]++;
	}

	for(int i=0;i<v.size();i++) cout<< v[i] << endl;

	return 0;
}


Measured memory_bytes: 3988
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Main
{
    public static class Program
    {
        static void Main(string[] arg)
        {
            var answer = "Yay!";
            var line = GetIntList(Console.ReadLine());
            int a = line[0];
            int b = line[1];

            if(a > 8 || b > 8)
            {
                answer = ":(";
            }
            

            Console.WriteLine(answer);
            Console.ReadLine();

        }
        #region libraries
        private static int[] GetIntList(string line)
        {
            return line.Split(' ').Select(x => int.Parse(x)).ToArray();

        }
        private static int SearchNearest(this IEnumerable<int> list, int target)
        {
            var min = list.Min(c => Math.Abs(c - target));
            return list.First(c => Math.Abs(c - target) == min);
        }
        public static int Gcd(int a,int b)
        {
            if(a < b)
            {
                Gcd(b, a);
            }
            while (b != 0)
            {
                var rm = a % b;
                a = b;
                b = rm;
            }
            return a;
        }
        #endregion
    }
}


Measured memory_bytes: 11220
#include <iostream>
#include <vector>
#define END 1000000001
using namespace std;

int main(){

	int n, q;
	cin >> n >> q;
	vector< vector<int> > a(n);
	int querynum = 0;
	while (querynum < q) {
		int var1;
		cin >> var1;
		if (var1 == 0) {
			int var2, var3;
			cin >> var2 >> var3;
			a[var2].push_back(var3);
		}
		else if (var1 == 1) {
			int var2;
			cin >> var2;
			for (int i = 0; i < (int)a[var2].size(); i++) cout << (i == 0 ? "" : " ") << a[var2][i];
			cout << endl;
		}
		else {
			int var2;
			cin >> var2;
			a[var2].clear();
		}
		querynum++;
	}
	
	return 0;
}


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

int now[10001];
int idx[10001];

signed main(){
	memset(now,-1,sizeof(now));
	int n;
	cin>>n;
	int a[n][n];
	r(i,n)r(j,n-1)cin>>a[i][j],a[i][j]--;

	queue<P>q;
	r(i,n)q.push(P(i,a[i][0]));

	int cnt=0,px=0;

	while(1){
		int upd=0;
		queue<P>Q;
		while(!q.empty()){
			P p=q.front();q.pop();
			int id=p.first;
			int to=p.second;
			//cout<<cnt<<' '<<id<<' '<<to<<endl;
			if( now[to] == id ){ px++; upd++;
				idx[to]++;
				idx[id]++;
				if(idx[to]<n-1)Q.push(P(to,a[to][idx[to]]));
				if(idx[id]<n-1)Q.push(P(id,a[id][idx[id]]));
			}
			else now[id] = to;
		}
		//r(i,n)cout<<idx[]
		if( !upd ) break;
		cnt++;
		q=Q;
	}
	if(px!=n*(n-1)/2)cout<<-1<<endl;
	else cout<<cnt<<endl;
}

Measured memory_bytes: 8192
use std::collections::HashMap;
use std::io::*;
use std::str::FromStr;

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

fn main() {
    let n = read::<usize>();
    let m = read::<usize>();
    let mut seq = vec![0; n];
    let mut cnts = HashMap::<usize, usize>::new();
    cnts.insert(0, 1);
    let mut ans = 0;
    let mut sum = 0;
    for i in 0..n {
        seq[i] = read::<usize>();
        sum = (sum + seq[i]) % m;
        ans += *cnts.entry(sum).or_insert(0);
        *cnts.entry(sum).or_insert(0) += 1;
    }
    println!("{}", ans);
}


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

using namespace std;

int n, k;
vector<int> a;
vector<int> dp;
int main() {
	cin>>n>>k;
	a.resize(n);
	dp.resize(k, -1);
	for(int i=0;i<n;i++) {
		cin>>a[i];
	}
	for(int i=0; i<=k; i++) {
		dp[i]=0;
		for(int j=0;j<n;j++) {
			if(i-a[j]>=0) {
				if(dp[i-a[j]]==0)
					dp[i]=1;
			}
		}	
	}
	// for(int i=0; i<=k; i++) {
	// 	cout<<dp[i]<<" ";
	// }
	// cout<<endl;
	if(dp[k]==0)
		cout<<"Second"<<endl;
	else
		cout<<"First"<<endl;
	return 0;
}

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

using namespace std;

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

#define all(x) (x).begin(), (x).end()
#define fap(x) cerr << __LINE__ << " says: " << #x << " = " << (x) << "\n"
#define FastIO ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

const int inf = 0x3f3f3f3f;
const ll INF = 2e18;

vector<vector<bool>> g;
vector<bool> vis;
vector<int> dsum;

int dfs(int u) {
	int ret = 1;
	vis[u] = true;
	for(int v=1; v<(int) g[u].size(); ++v) {
		if(g[u][v] and !vis[v]) ret += dfs(v);
	}
	return ret;
}

bool ok(const int n, const vector<pii> &e, const int mask) {
	g = vector<vector<bool>> (n + 1, vector<bool>(n + 1, false));
	dsum = vector<int>(n + 1, 0);
	for(int i=0; i<(int) e.size(); ++i) {
		if(mask & (1 << i)) {
			g[e[i].first][e[i].second] = true;
			g[e[i].second][e[i].first] = true;
			dsum[e[i].first] += e[i].second;
			dsum[e[i].second] += e[i].first;
		}
	}
	vis = vector<bool>(n+1, false);
	if(dfs(1) != n) return false;

	for(int i=2; i<=n; ++i) {
		if(dsum[i] != dsum[1]) return false;
	}

	return true;
}

void prnt(const int n, const vector<pii> &e, const int mask) {
	cout << dsum[n] << "\n";
	for(int i=0; i<(int) e.size(); ++i) {
		if(!(mask & (1 << i))) continue;
		cout << e[i].first << " " << e[i].second << "\n";
	}
}

void generate(int n) {
	vector<pii> e;
	for(int i=1; i<=n; ++i) {
		for(int j=i+1; j<=n; ++j) {
			e.push_back({i, j});
		}
	}

	int m = (int) e.size();
	for(int mask=0; mask<(1<<m); ++mask) {
		if(ok(n, e, mask)) {
			prnt(n, e, mask);
		}
	}
}

int main() {
	FastIO;

	int n;
	cin >> n;

	vector<pii> e;

	for(int i=1; i<=n; ++i) {
		int no = (n % 2 ? n - i : n + 1 - i);
		for(int j=i+1; j<=n; ++j) {
			if(no == j) continue;
			e.push_back({i, j});
		}
	}

	cout << (int) e.size() << "\n";
	for(auto &qq : e) cout << qq.first << " " << qq.second << "\n";

	return 0;
}

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

using namespace std;

const int DIM = 5e5 + 7;

char S[DIM];

int main()
{
    cin >> S;

    long long nr = 0;
    long long rez = 0;
    long long len = 0;
    for(int i = 0 ; i < strlen(S); i++)
    {
        if( S[i] == '<')
            if(len == 0)
            {
                if(S[i + 1] == '<' || i == strlen(S) - 1)
                {
                    nr++;
                    rez+=nr;
                }
            }
            else
            {
                rez += ((len - 1)* len) / 2 + max(nr + 1,len);
                nr = 0;
                i--;
                len = 0;
            }
        else
            len++;
    }

    if(len)
      rez += ((len - 1)* len) / 2 + max(nr + 1,len);

    cout << rez;

    return 0;
}


Measured memory_bytes: 768
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <functional>
#include <numeric>
#include <iomanip>
#define fi first
#define se second
#define fcout(n) cout<<fixed<<setprecision((n))
#define cinl(str) getline(cin,(str))
using namespace std;
bool value(int y,int x,int R,int C){return 0<=y&&y<R&&0<=x&&x<C;}
typedef pair<int,int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long > vll;
typedef vector< vi > vvi;
double pie=acos(-1);
int INF=1000000007;
int dx[4] = { 0,-1,0,1 };
int dy[4] = { -1,0,1,0 };


int main() {	
	int n;
	long long m;
	long long ans=0;
	int d[10005],p[10005];
	int c[15];
	while(true){
		cin>>n>>m;
		if(n+m==0) return 0;
		else{
			for(int i=0;i<15;i++){
				c[i]=0;
			}
			ans=0;
			for(int i=0;i<n;i++){
				cin>>d[i]>>p[i];
				c[p[i]] += d[i];
				ans += d[i]*p[i];
			}
			for(int i=10;i>0;i--){
				if(m-c[i]<=0){
					ans -= m*i;
					break;
				}
				else{
					ans -= c[i]*i;
					m -= c[i];
				}
			}
		}
		cout<<ans<<endl;

	}
}

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

int n;

double dp[310][310][310];
double rec(int a, int b,int c){
    if(dp[a][b][c]>=0)return dp[a][b][c];
    if(a==0 && b==0 && c==0) return 0.0;

    double res=0.0;
    if(a>0)res+=rec(a-1,b,c)*a;
    if(b>0)res+=rec(a+1,b-1,c)*b;
    if(c>0)res+=rec(a,b+1,c-1)*c;

    res+=n;
    res*=1.0/(a+b+c);
    return dp[a][b][c]=res;
}


int main(){
    cin>>n;
    vector<int>a(n);
    rep(i,n)cin>>a[i];
    int one=0,two=0,three=0;
    rep(i,n){
        if(a[i]==1)one+=1;
        if(a[i]==2)two+=1;
        if(a[i]==3)three+=1;
    }
    memset(dp,-1,sizeof(dp));
    cout<<fixed<<setprecision(10)<<rec(one,two,three)<<endl;
    
}

Measured memory_bytes: 236588
A = list(input().split())
B = []

for a in A:
    if a in ["+", "-", "*"]:
        y = B.pop()
        x = B.pop()
        
        if a == "+":
            B.append(x + y)
        elif a == "-":
            B.append(x - y)
        else:
            B.append(x * y)         
    else:
        B.append(int(a))
        
print(B[0])


Measured memory_bytes: 5596
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;

int main() {
	int S, W;
	cin >> S >> W;

	if (W >= S) {
		cout << "unsafe" << endl;
	}

	else {
		cout << "safe" << endl;
	}

}

Measured memory_bytes: 3568
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <deque>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
#define MAX_M 100000
using namespace std;

const int MAX = 100001;
const int MOD = 1000000007;

typedef long long ll;
typedef pair< int, int > pii;
typedef pair< ll, ll > pll;
typedef pair< ll, int > pli;
typedef pair< int, ll > pil;

int ceil(int x, int y){
  return (x % y == 0) ? x / y : x / y + 1;
}

int gcd(int x, int y){
  return y ? gcd(y, x % y) : x;
}

int lcm(int x, int y){
  return x / gcd(x, y) * y;
}

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

  int n, m;
  cin >> n >> m;
  ll x[m];
  for(int i = 0; i < m; i++) cin >> x[i];

  if(n >= m){
    cout << 0 << endl;
    return 0;
  }

  sort(x, x + m);

  ll d[m - 1];
  for(int i = 0; i + 1 < m; i++){
    d[i] = x[i + 1] - x[i];
  }

  sort(d, d + m - 1);

  ll sum = 0;
  for(int i = 0; i < m - n; i++){
    sum += d[i];
  }

  cout << sum << endl;

  return 0;
}

Measured memory_bytes: 1792
fun main(args: Array<String>){
    val (k, n) = readLine()!!.split(" ").map { it.toInt() }
    val a = readLine()!!.split(" ").map { it.toInt() }
    var l = a[0] + k - a[n - 1]
    for(i in 1 until n){
        if (l < a[i] - a[i-1]){
            l = a[i] - a[i-1]
        }
    }
    println(k-l)
}

Measured memory_bytes: 80868
#include<stdio.h>

void trace(int A[],int N){
  int i;
  for (i = 0; i < N; i++ ){
    if( i > 0 ) printf(" ");
    printf("%d",A[i]);
  }
  printf("\n");
}

void insertionSort(int A[],int N){
  int j, i, v;
  for (i = 1; i < N; i++ ){
    v = A[i];
    j = i - 1;
    while (j >= 0 && A[j] > v ){
      A[j + 1] = A[j];
      j--;
    }
    A[j+1] = v;
    trace(A,N);
  }
}

int main(){
  int N,i,j;
  int A[100];
  
  scanf("%d",&N);
  for (i = 0;i < N; i++ ) scanf("%d",&A[i]);
  
  trace(A,N);
  insertionSort(A,N);
  
  return 0;
}


Measured memory_bytes: 2684
#include<bits/stdc++.h>
#define For(i,a,b) for(int i=(a);i<=(b);++i)
#define rep(i,a,b) for(int i=(a);i>=(b);--i)
#define ull unsigned long long
#define ll long long
#define  PII pair<int,int>
using namespace std;
ull read() {
	char c = getchar();
	ull x = 0, f = 1;
	for (; !isdigit(c); c = getchar())
		if (c == '-')
			f = -1;
	for (; isdigit(c); c = getchar())
		x = x * 10 + c - 48;
	return x * f;
}
ull a, b;
int main() {
	cin >> a;
	string s;
	cin >> s;
	b = s[0] - '0';
	b = b * 10 + s[2] - '0';
	b = b * 10 + s[3] - '0';
	a *= b;
	a /= 100;
	cout << a << endl;
	return 0;
}


Measured memory_bytes: 3644
int num;
int ans[200000];
int main(){
  int n;
  
  scanf("%d",&n);
  for(int i=2;i<=n;i++){
    scanf("%d",&num);
    ans[num]++;
  }
  for(int i=1;i<=n;i++){
    printf("%d\n",ans[i]);
  }
}


Measured memory_bytes: 2452
n = int(input())
a = list(map(int,input().split(" ")))

c_dic = {}
for i in a:
    if i not in c_dic:
        c_dic[i] = 1
    else:
        c_dic[i] += 1
    
    if i + 1 not in c_dic:
        c_dic[i + 1] = 1
    else:
        c_dic[i + 1] += 1

    if i - 1 not in c_dic:
        c_dic[i - 1] = 1
    else:
        c_dic[i - 1] += 1

print(max(c_dic.values()))

Measured memory_bytes: 23300
program main
    implicit none
    integer:: n,m, i,j,k
    integer, allocatable:: a(:), b(:)
    integer(8), allocatable:: c(:), sc(:)
    integer(8):: inf = 1000000000
    logical, allocatable:: is_updated(:)


    read*, n, m
    allocate(a(m), b(m), c(m), sc(n),is_updated(n))

    do i = 1, m
        read*, a(i),b(i),c(i)
    end do
    
    sc(1:n)=-inf*2000000
    sc(1)=0

    do i = 1,n-1
        do j = 1,m
            if (sc(a(j))+c(j) > sc(b(j))) then
                sc(b(j)) = sc(a(j))+c(j)
            end if
            ! print*, sc
        end do
    end do

    is_updated(1:n) = .false.

    do i = 1,n-1
        do j = 1,m
            if (sc(a(j))+c(j) > sc(b(j))) then
                sc(b(j)) = sc(a(j))+c(j)
                is_updated(b(j)) = .true.
            end if
            if (is_updated(a(j)))then
                is_updated(b(j)) = .true. 
            end if
            ! print*, sc
        end do
    end do

    if (is_updated(n)) then
        print*, 'inf'
    else
        print*, sc(n)
    end if




end program

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
bool prime[10000001];

int main(){
  //GgXelXÌâ¿Åf©Ç¤©Ì\ðì¬
  //f == 1, NOTf == 0
  memset(prime, 1, sizeof(prime));
  prime[0] = prime[1] = 0;
  for(int i = 2 ; i <= 10000000 ; i++){
    if(prime[i]){
      for(int j = i*2 ; j <= 10000000 ; j += i){
	prime[j] = 0;
      }
    }
  }
  
  int n;
  
  while(cin >> n && n){
    int i = n;
    while(!(prime[i] && prime[i-2] && prime[i-6] && prime[i-8])) i--;
    cout << i << endl;
  }
  return 0;
}

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

using ll = long long;
using namespace std;

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

int main(void) {
	string s, t;
	cin >> s >> t;
	
	int sn = (int)s.size();
	int tn = (int)t.size();
	vector< vector<int> >  dp(sn + 10, vector<int>(tn + 10, 0));
	
	for(int i = 1; i <= sn; ++i) {
		for(int j = 1; j <= tn; ++j) {
			if( s[i - 1] == t[j - 1] ) {
				dp[i][j] = dp[i - 1][j - 1] + 1;
			} else {
				dp[i][j] = max(dp[i][j - 1], dp[i - 1][j]);
			}
		}
	}
	
	int a = sn, b = tn;
	string ans = "";
	while( a && b ) {
		if( s[a - 1] == t[b - 1] ) {
			ans.push_back(s[a - 1]);
			a--; b--;
		} else {
			if( dp[a][b] == dp[a - 1][b] ) a--;
			else b--;
		}
	}
	
	reverse(ans.begin(), ans.end());
	
	cout << ans << endl;
	
	return 0;
}


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

int main(){
  long long A,B,g=0,c=0;
  cin >> A >> B;
  long long a, b;
  a=A;
  b=B;
  while(a != 0){
  if(B == 0){
    g = A;
    long long ans = a*b/A;
    cout << ans << endl;
    return 0;
  }else{
    c=B;
    B=A%c;
    A=c;}
  }
}

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

int main()
{
  int n, x;
  cin >> n >> x;
  int a[++n];
  a[0] = 0;
  for(int i = 1; i < n; i++) cin >> a[i];
  int sum = 0, ans = 1;
  for(int i = 1; i < n; i++){
    sum = a[i] + a[i - 1];
    a[i] += a[i - 1];
    if(sum <= x) ans++;
  }
  cout << ans << endl;
  
  return 0;
}

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

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;

#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()
constexpr auto INF = 5000000000000000;
constexpr auto MOD = 1000000007;

int main() {
	int sx,sy,tx,ty;
	cin >> sx >> sy >> tx >> ty;
	string s = {};
	int x = tx - sx, y = ty - sy;

	rep(i, x) s.push_back('R');
	rep(i, y) s.push_back('U');
	rep(i, x) s.push_back('L');
	rep(i, y + 1) s.push_back('D');

	rep(i, x + 1) s.push_back('R');
	rep(i, y + 1) s.push_back('U');
	s.push_back('L');
	s.push_back('U');
	rep(i, x + 1) s.push_back('L');
	rep(i, y + 1) s.push_back('D');
	s.push_back('R');

	cout << s << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, start, stop) for (int i = start; i < stop; i++)
#define FORR(i, start, stop) for (int i = start; i > stop; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define REMOVE(v,n) remove(vector<int> v,v+v.size(),int n)
#define ll long long
#define ull unsigned long long
#define pb(a) push_back(a)
#define INF 999999999
#define V(v,i,j) vector(v.begin() + i, v.begin() + j)
#define SUM(v) FOR(i,0,v.size())
#define INSERT(va,vb) va.insert(va.end(), vb.begin(), vb.end())
using namespace std;
typedef vector<int> vint;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

//vector< vector<int> > v (size1, vector<int>(size2) );

int main(){
    int n;
    cin >> n;
    vector< vector<int> > dp (n, vector<int>(3) );
    
    FOR(i,0,n){
        int a,b,c;
        cin >> a >> b >> c;
        if (i==0){
            dp[i][0] = a;
            dp[i][1] = b;
            dp[i][2] = c;
        }else{
            dp[i][0] = max(dp[i-1][1],dp[i-1][2])+ a;
            dp[i][1] = max(dp[i-1][0],dp[i-1][2])+ b;
            dp[i][2] = max(dp[i-1][1],dp[i-1][0])+ c;
        }
    }
    int ans = 0;

    FOR(i,0,3){
        ans = max(ans,dp[n-1][i]);
    }

    cout << ans << endl;
}

Measured memory_bytes: 5760
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
int L,n,m;
void Link(int x,int y,int z)
{
	printf("%d %d %d\n",x,y,z);
}
int main()
{
	int i,j,k=0;bool f=0;
	scanf("%d",&L);
	for(n=2;(1<<n)<=L;n++);
	m=2*(n-1)+__builtin_popcount(L)-1;
	printf("%d %d\n",n,m);
	for(i=1;i<n;i++)Link(i,i+1,0);
	for(i=1;i<n;i++)Link(i,i+1,1<<i-1);
	for(i=19;i>=0;i--)
	if(L>>i&1)
	{
		if(f)Link(i+1,n,k);
		f=1;k|=1<<i;
	}
}


Measured memory_bytes: 256
n, m = map(int, input().split())
a = [list(input()) for i in range(n)]
b = [list(input()) for i in range(m)]
ans = 'No'
for i in range(n-m+1):
    for j in range(n-m+1):
        cnt = m**2
        for k in range(m):
            for l in range(m):
                if a[i+k][j+l] == b[k][l]:
                    cnt -= 1
        if cnt == 0:
            ans = 'Yes'
print(ans)


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

int main(){
  int n, a;
  cin >> n;
  vector<int> c(n);
  for(int i = 0; i < n; i++){
    cin >> a;
    a--;
    c[a] = i + 1;
  }
  for(int i = 0; i < n; i++){
    cout << c[i];
    if(i != n - 1)
      cout << ' ';
  }
  cout << endl;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define REP(i, a, n) for (int i = (a); i < (int)(n); ++i)
#define REPC(i, a, n) for (int i = (a); i <= (int)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init)                                          \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T> using VEC = std::vector<T>;
template <class T> using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail> void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T> ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec)
    os << v << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m)
    os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}

int main() {
  int n,k,x,y;
  cin>>n>>k>>x>>y;
  int xd = min(n,k);
  int yd = max(n-k,0);
  cout<<xd*x+yd*y<<endl;



  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

fun main (args : Array<String>) {
  val input = Scanner(System.`in`)
  val OriginalDirection = true;
  
  while (input.hasNext()) {
    val S = StringBuilder(input.next()) 
    val Q = input.nextInt()
    var direction = OriginalDirection;
    
    for (i in 1..Q) {
      val q = input.nextInt()
      
      if (q == 1) {
        direction = !direction
      } else if (q == 2) {
        val F = input.nextInt()
        val C = input.next()
        
        if (direction == OriginalDirection) {
          if (F == 1) {
            S.insert(0, C)
          } else if (F == 2) {
            S.append(C)
          }
        } else {
          if (F == 1) {
            S.append(C)
          } else if (F == 2) {
            S.insert(0, C)
          }
        }
      }    
    }
    
    if (direction == OriginalDirection) {
      println(S)
    } else {
      println(S.reverse())
    }
  }
}

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

int main() {
	int n,p=0;
	std::cin >> n;

	std::vector<int> v(n);

	for (auto& x : v) {
		std::cin >> x;
	}

	for (int i = 0;i<v.size(); i++) {
		while (0 == v[i] % 2) {
			v[i] = v[i] / 2;
			p++;
		}
	}

	std::cout << p << std::endl;

	return 0;
}

Measured memory_bytes: 256
H,W,K = gets.split.map &:to_i
S = $<.read.split
T = S.map {_1.scan(?#).size}
n,C,R = 0, [*0...W], [*0...H]
H.times {|h|
  R.combination(h) {|r|
    s,t = S.dup, T.sum
    r.each {|y| t -= T[y]; s[y] = 0}
    next  if t < K
    W.times {|w|
      C.combination(w) {|c|
        u,v = t,s
        c.each {|x| u -= v.count { _1[x] == ?# } }
        n += 1  if u == K
      }
    }
  }
}
p n

Measured memory_bytes: 14372