akhauriyash/Code-Regression huggingface dataset:
use proconio::marker::Usize1;
fn main() {
    proconio::input! {
        r: usize,
        c: usize,
        k: usize,
        rcv: [(Usize1,Usize1,i64);k],
    }
    let mut g=vec![vec![0;c];r];
    for (r,c,v) in rcv {
        g[r][c]=v;
    }
    let mut dp=vec![vec![0;3];c];
    for i in 0..r {
        for j in 0..c {
            let w=g[i][j];
            for k in 0..3 {
                let mut v=w+dp[j][2];
                if j>0 {
                    v=v.max(dp[j-1][k]);
                    if k>0 && w!=0 {
                        v=v.max(dp[j-1][k-1]+w);
                    }
                }
                dp[j][k]=v;
            }
        }
    }
    println!("{}",dp[c-1][2]);
}


Measured memory_bytes: 80656
#include <cstdio>
#include <iostream>
#include <cstring>
#include <vector>
#include <cmath> 
#include <algorithm> 
using namespace std;
const int maxn=2e5+5;
typedef long long ll;
ll a[maxn];
ll n,temp;
int main()
{
	while(cin>>n)
	{
		ll sum=0,ave,ans;
		for(int i=1;i<=n;i++)
		{
			cin>>temp;
			a[i]=temp-i;	
			sum+=a[i];
		}
		sort(a+1,a+n+1);
		if(n&1)
		{
			ave=a[(n+1)/2];
			sum=0;
			for(int i=1;i<=n;i++)
				sum+=abs(ave-a[i]);
			cout<<sum<<endl;
		}	
		else
		{
			ave=a[n/2];
			sum=0;
			for(int i=1;i<=n;i++)
				sum+=abs(ave-a[i]);
			ans=sum;
			sum=0;
			ave=a[n/2+1];
			for(int i=1;i<=n;i++)
				sum+=abs(ave-a[i]);
			ans=min(ans,sum);
			cout<<ans<<endl;	
		}
	}
}

Measured memory_bytes: 1920
//------------------------------------------
// C++ templete 
//------------------------------------------
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

#define endl "\n"

//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

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

//container util
//------------------------------------------
#define pb push_back
#define paired make_pair
#define ALL(a) (a).begin(),(a).end()
#define PRINT(V) for (auto v : (V)) cout << v << " "
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())

//constant
//------------------------------------------
const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

//math
//------------------------------------------
int QP(int a,int b){int ans=1;do{if(b&1)ans=1ll*ans*a%MOD;a=1ll*a*a%MOD;}while(b>>=1);return ans;}
int QP(int a,int b,int MOD){int ans=1;do{if(b&1)ans=1ll*ans*a%MOD;a=1ll*a*a%MOD;}while(b>>=1);return ans;}
int GCD(int a,int b){return b?GCD(b,a%b):a;}

//debug
//------------------------------------------
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//grobal variable
//------------------------------------------
int N,M;
VI Vec;

//動的計画法で役に立つ関数
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; }

//最大公約数と最小公倍数
ll gcd(ll a, ll b) {
    if(b==0)return a;
    return gcd(b, a%b);
}

ll lcm(ll a, ll b) {
  ll g = gcd(a, b);
  return a/g*b;
}

ll f(ll x, ll y)
{
    ll ans = x / y;
    return ans + 1;
}

int main() 
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
  
    ll A, B, C, D;cin >> A >> B >> C >> D;
    ll l = lcm(C, D);
    
    ll n_c, n_d, n_c_d;

    //c
    n_c = f(B, C) - f(A, C);
    if (A%C==0) n_c++;

    //d
    n_d = f(B, D) - f(A, D);
    if (A%D==0) n_d++;
    //
    //c_d
    n_c_d = f(B, l) - f(A, l);
    if (A%l==0) n_c_d++;
    
    cout << B-A+1 -(n_c + n_d - n_c_d) << endl;
    return 0;
}



Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
A = sorted(A,reverse = True)
ans = 0
incircle = []
for i in range (N):
    if incircle == []:
        incircle.append(A[i])
    else:
        num = (i//2)
        if  num == -1:
            num = 0
        ans += incircle[num]
        incircle.append(A[i])
print(int(ans))

Measured memory_bytes: 31760
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		
		String S = scan.next();
		
        if(S.equals("Sunny")) {
    		System.out.println("Cloudy");
        } else if(S.equals("Cloudy")) {
    		System.out.println("Rainy");
        } else if(S.equals("Rainy")) {
    		System.out.println("Sunny");
        } else {
    		scan.close();
        	return;
        }
		
		scan.close();
	}

}


Measured memory_bytes: 21716
import math as mt
#import numpy as np

def ro(n):
  return mt.floor(mt.sqrt(n))
def ya():
  print("Yes")
  return
def na():
  print("No")
  return


#a,b=map(int,input().split())
#lis=list(map(int,input().split()))
#n=int(input())
s=input()

n=(len(s)+1)//2
if s[:n-1]!=s[n:] or s!=s[::-1]:
  na()
else:
  ya()

Measured memory_bytes: 3060
import java.util.Scanner;

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

		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int X = sc.nextInt();

		/*
		List<String> lines1 = Arrays.asList(line1.split(" "));
		List<String> lines2 = Arrays.asList(line2.split(" "));
		*/

		int ans = 0;
		for (int i = 0; i <= A; i++) {
			for (int j = 0; j <= B; j++) {
				for (int k = 0; k <= C; k++) {
					if (i*500 + j*100 + k*50 == X) {
						ans++;
					}

				}
			}

		}
		System.out.println(ans);
	}

}

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


signed main() 
{
  int n;
  cin >> n;
  int a[200];
  bool check=true;
  for(int i=0;i<n;i++)
  {
    cin >> a[i];
  }
  int count=0;
  int i=100;
  while(check)
  {
    for(int i=0;i<n;i++)
    {
      int tmp=a[i]%2;
      a[i]=a[i]/2;
      if(tmp==1)
      {
        check=false;
        break;
      }
    }
    if(!check)
      break;
    count++;
  }
  cout << count << endl;
 
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define rep(i,n) for(int i=0; i<(n); i++)
#define per(i,n) for(int i=(n)-1; i>=0; i--)
#define all(v) v.begin(), v.end()
#define debug(var) do{cout << #var << " : "; print(var); } while(0)
using namespace std;
typedef long long ll;
void print() { cout << endl; }
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) { cout << head; if (sizeof...(tail) != 0) cout << " "; print(forward<Tail>(tail)...); }
template <class T> void print(vector<T> &vec) { for (auto& a : vec) { cout << a; if (&a != &vec.back()) cout << " "; } cout << endl; }
template <class T> void print(vector<vector<T>> &df) { for (auto& vec : df) { print(vec); } }
const int INF = 1e9;
const int MOD = 1e9+7;

const string button[] = {".,!? ", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};

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

	int n; cin >> n;
	rep(nn, n) {
		string s; cin >> s;
		string ans;
		int loc = -1;
		int pushed = 0;

		rep(i, s.size()) {
			char c = s[i];
			int num = c - '0';
			if (num==0) {
				if (loc==-1) continue;
				pushed %= button[loc].size();
				ans += button[loc][pushed];
				loc = -1;
				pushed = 0;
			}
			num--;
			if (loc==-1) loc=num;
			else pushed++;
		}

		cout << ans << endl;
	}
}


Measured memory_bytes: 3188
#include <iostream>
#include <set>
#include <stack>
#include <vector>
#include <map>
#include <string>
#include <string.h>
#include <cstring>
#include <queue>
#include <algorithm>
#include <math.h>

using namespace std;

typedef long long ll;

int main()
{
	ll N,temp,max=0;
	vector<ll> monsters, heroes;
	cin >> N;
	for (int i = 0; i <= N; i++) 
	{
		cin >> temp;
		monsters.push_back(temp);
	}
	for (int i = 0; i < N; i++)
	{
		cin >> temp;
		heroes.push_back(temp);
	}
	for (int i = 0; i <= N; i++) 
	{
		if (i != N) {
			if (heroes[i] > monsters[i])
			{
				max += monsters[i];
				heroes[i] -= monsters[i];
				if (monsters[i + 1] - heroes[i] >= 0)
				{
					max += heroes[i];
					monsters[i + 1] -= heroes[i];
				}
				else
				{
					max += monsters[i + 1];
					monsters[i + 1] = 0;
				}
			}
			else
			{
				max += heroes[i];
			}
		}
	}
	cout << max;
}

Measured memory_bytes: 2548
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n,m = na()
c = []

for i in range(n):
    a,b = na()
    c.append([a,b])

import heapq

c = sorted(c)
k = 0
d = 1
h = []
ans = 0
while d < m+1:
    while k < len(c) and c[k][0] <= d:
        heapq.heappush(h, -c[k][1])
        k+=1
    if len(h) > 0:
        j = heapq.heappop(h)
        ans -= j
    d += 1

print(ans)

Measured memory_bytes: 24656
function Main(input) {
  "use strict"
	const temp = input.split("\n");

	const a = parseInt(temp.shift());
	const s = temp.shift();
  const color = (a >= 3200) ? s: "red";
  console.log(color)
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 21064
#include <iostream>

typedef long long ll;

int main(){
   ll K;
   std::cin >> K;

   int N = 50;
   ll a[N];
   for(int i=0; i<N; ++i){
      a[i] = i + K/N;
   }

   for(int i=0; i<K%N; ++i){
      ++a[N-i-1];
   }

   std::cout << N << std::endl;
   for(int i=0; i<N; ++i)
      std::cout << a[i] << ' ';
   std::cout << std::endl;

   return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
s, _, *q = open(0)
g = ""
s = s.strip()
for q in q:
  q = q.strip().split()
  if q[0] == "1":
    g, s = s, g
  else:
    if q[1] == "1":
      g += q[2]
    else:
      s += q[2]
print(g[::-1] + s)

Measured memory_bytes: 16160
import java.util.Scanner;
public class Main{
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        boolean can=true;

        while(can){
            int H=sc.nextInt();
            int W=sc.nextInt();
            if((H==0)&&(W==0)) can=false;
            else {
                for(int i=0;i<H;i++){
                    for(int j=0;j<W;j++){
                        if((i==0)||(i==H-1))System.out.print("#");
                        else{
                        if((j==0)||(j==W-1))System.out.print("#");
                        else System.out.print(".");
                       }
                    }
                    System.out.println();
                }
                System.out.println();
            }
        }
    }
}


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

int main()
{
  while(true)
  {
    int h, w;
    cin >> h >> w;
    if ( h == 0 && w == 0) return 0;
    for (int i=0; i<h; i++)
    {
      if ( i == 0 || i == h-1)
      {
        for (int j=0; j<w; j++)
        {
          cout << '#' << flush;
        }
      }else
      {
        cout << '#' << flush;
        for (int j=0; j<w-2; j++)
        {
          cout << '.' << flush;
        }
        cout << '#' << flush;
      }
      cout << endl;
    }
    cout << endl;
  }
}

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

// Union-Find Tree
struct UnionFind {
  vector<int> par;
  
  UnionFind(int n): par(n, -1) {
  }
  
  void init(int n) {
    par.assign(n, -1);
  }
  
  // 根の検索
  int find(int x) {
    if (par[x] < 0) return x;
    return par[x] = find(par[x]);
  }
  
  // xとyの属する集合を併合
  bool unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return false;
    if (par[x] > par[y]) swap(x, y);
    par[x] += par[y];
    par[y] = x;
    return true;
  }
  
  // xとyが同じ集合に属するか
  bool same(int x, int y) {
    return find(x) == find(y);
  }
  
  int size(int x) {
    return -par[find(x)];
  }
};

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n, m;
  cin >> n >> m;
  
  UnionFind uf(n);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    uf.unite(a, b);
  }
  
  int ans = 0;
  for (int i = 0; i < n; i++) ans = max(ans, uf.size(i));
  
  cout << ans << '\n';
}

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

using namespace std;

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

typedef int64_t ll; typedef vector<int> VI; typedef pair<int,int> pii;
const ll mod = 1e9+7;

vector<VI> r;
VI usd;
void dfs(int s, int a, int b){
	usd[s] = 1;
	for(auto x: r[s]){
		if(s==a && x==b) continue;
		if(s==b && x==a) continue;
		if(usd[x] ==0) dfs(x,a,b);
	}
}

int main()
{

	//cin.tie(0); ios_base::sync_with_stdio(false);
	int n,m;
	cin >>n >>m;
	r.resize(n);
	set<pii> st;
	rep(i,m){
		int a,b;
		cin >>a>>b;

		r[a-1].push_back(b-1);
		r[b-1].push_back(a-1);
		st.insert(pii(a-1,b-1));
	}
	usd.resize(n);
	int ans=0;
	for(auto z: st){
		//if(sz(r[i])==0) continue;
		int ng =0;
		int a,b;
		tie(a,b) = z;
		fill(all(usd),0);
		dfs(0,a,b);
		rep(k,n) if(usd[k]==0) ng=1;
		if(ng==1) ans++;
		//cout<<a<<":: ";for(auto x :usd) printf("%d, ",x); puts("");
	}
	cout << ans <<"\n";
	return 0;

}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <functional>
#include <queue>
using namespace std;
typedef long long ll;
const int MAX = 1e5+5;
int X, Y, A, B, C, p[MAX], q[MAX];
priority_queue<int, vector<int>> pq;
int main() {
  scanf("%d %d %d %d %d", &X, &Y, &A, &B, &C);
  for(int i = 1; i <= A; ++i) scanf("%d", &p[i]);
  for(int i = 1; i <= B; ++i) scanf("%d", &q[i]);
  for(int i = 1, r; i <= C; ++i) {
    scanf("%d", &r);
    pq.push(r);
  }
  sort(p+1, p+A+1, greater<>());
  sort(q+1, q+B+1, greater<>());
  for(int i = 1; i <= X; ++i) pq.push(p[i]);
  for(int i = 1; i <= Y; ++i) pq.push(q[i]);
  ll ans = 0LL, cnt = 1LL*X+1LL*Y;
  while(cnt > 0) { 
    ans += 1LL*pq.top();
    pq.pop();
    --cnt;
  }
  printf("%ld\n", ans);
}

Measured memory_bytes: 3316
#include<stdio.h>
  int h,w,i,j,k,a,m=0,d[4][2010][2010]={};
int main(){
  char s[2010][2010];
  scanf("%d %d",&h,&w);
  for(i=0;i<h;i++)scanf("%s",s[i+1]+1);
  for(i=1;i<=h;i++){
    for(j=1;j<=w;j++){
      if(s[i][j]=='#')continue;
      d[0][i][j]=d[0][i-1][j]+1;
      d[1][i][j]=d[1][i][j-1]+1;
    }
  }
  for(i=h;i;i--){
    for(j=w;j;j--){
      if(s[i][j]=='#')continue;
      d[2][i][j]=d[2][i+1][j]+1;
      d[3][i][j]=d[3][i][j+1]+1;
    }
  }
  for(i=1;i<=h;i++){
    for(j=1;j<=w;j++){
      for(k=a=0;k<4;k++)a+=d[k][i][j];
      if(m<a)m=a;
    }
  }
  printf("%d\n",m-3);
  return 0;
}
      


Measured memory_bytes: 67200
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int N=5, i ;
    vector<int> x(N);
    for (i=1;i<N;i++){
        cin >> x[i];  
    }
    for (i=1;i<=N;i++){
        if (x[i]==0){
            cout << i << endl;
            break;
        }
    }
}


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

#define rep( i, n ) for( int i = 0; i < ( n ); i++ )
#define PI 3.14159265

int main( void ) {
    int n;
    cin >> n;
    vector<int> S( 13, 0 ), H( 13, 0 ), C( 13, 0 ), D( 13, 0 );

    while( n > 0 ) {
        char t;
        int  v;
        cin >> t >> v;
        switch( t ) {

            case 'S':
                S.at( v - 1 )++;
                break;
            case 'H':
                H.at( v - 1 )++;
                break;
            case 'C':
                C.at( v - 1 )++;
                break;
            case 'D':
                D.at( v - 1 )++;
                break;
        }
        n--;
    }

    for( int i = 0; i < 13; i++ ) {
        if( S.at( i ) == 0 ) cout << "S " << i + 1 << endl;
    }
    for( int i = 0; i < 13; i++ ) {
        if( H.at( i ) == 0 ) cout << "H " << i + 1 << endl;
    }
    for( int i = 0; i < 13; i++ ) {
        if( C.at( i ) == 0 ) cout << "C " << i + 1 << endl;
    }

    for( int i = 0; i < 13; i++ ) {
        if( D.at( i ) == 0 ) cout << "D " << i + 1 << endl;
    }

    return 0;
}



Measured memory_bytes: 3092
import sys
from functools import reduce
import copy
import math
from pprint import pprint
import collections
import bisect
import itertools


sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def int_inputs(num_of_input):
    ins = [int(input()) for i in range(num_of_input)]
    return ins


def solve(T, PX):
    T = string_to_int(T)
    DRINKS = list(map(string_to_int, PX))
    sum_t = reduce(lambda acc, x: acc+x, T, 0)

    ret = []
    for d in DRINKS:
        i = d[0] - 1
        x = d[1]
        ret.append(sum_t - (T[i] - x))
    return ret


def string_to_int(string):
    return list(map(lambda x: int(x), string.split()))


if __name__ == "__main__":
    input()
    T = input()
    M = int(input())
    ret = solve(T, inputs(M))
    for r in ret:
        print(r)


Measured memory_bytes: 38384
package main

import (
	"fmt"
	"strconv"
)

func main() {
	var H, W int
	fmt.Scan(&H, &W)
	arr := make([][]string, H)
	for i := 0; i < H; i++ {
		var s string
		fmt.Scan(&s)
		for _, str := range s {
			arr[i] = append(arr[i], string(str))
		}
	}
	for i := 0; i < H; i++ {
		for j := 0; j < W; j++ {
			if arr[i][j] == "#" {
				continue
			}
			var count int
			if i-1 >= 0 && j-1 >= 0 && arr[i-1][j-1] == "#" {
				count++
			}
			if i-1 >= 0 && arr[i-1][j] == "#" {
				count++
			}
			if i-1 >= 0 && j+1 < W && arr[i-1][j+1] == "#" {
				count++
			}
			if j-1 >= 0 && arr[i][j-1] == "#" {
				count++
			}
			if j+1 < W && arr[i][j+1] == "#" {
				count++
			}
			if i+1 < H && j-1 >= 0 && arr[i+1][j-1] == "#" {
				count++
			}
			if i+1 < H && arr[i+1][j] == "#" {
				count++
			}
			if i+1 < H && j+1 < W && arr[i+1][j+1] == "#" {
				count++
			}
			arr[i][j] = strconv.Itoa(count)
		}
	}
	for i := 0; i < H; i++ {
		for _, v := range arr[i] {
			fmt.Print(v)
		}
		fmt.Println()
	}
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace __gnu_pbds;
using namespace std;
 
typedef long long int ll;
typedef unsigned long long int sll;
typedef long double ld;
#define A 1000000007
#define D 100000000000000ll
#define B 998244353ll
#define C 1000000000000000000ll
#define M 4000
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define oset tree<pair<ll,ll>, null_type,less_equal<pair<ll,ll>>, rb_tree_tag,tree_order_statistics_node_update> 
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v) *min_element(v.begin(),v.end())
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define ve vector
#define br break
#define PI acos(-1)
#define subt cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n" 

ll po[12];

string fun(ll x, ll y)
{
    if(x==1)
    {
        string s;
        s.pb('a'+y-1);
        return s;
    }
    ll z=po[x-1],val=ceil(y/(ld)z)-1;
    string s=fun(x-1,((y-1)%z)+1);
    string fi;
    fi.pb('a'+val);
    fi=fi+s;
    return fi;
}

int main() 
{
    FAST;
    ve<ll> v;
    v.pb(0);
    ll x=26,y=0;
    po[0]=1;
    for(int i=1;i<12;i++)
    {
        v.pb((y+1)*x);
        y=(y+1)*x;
        po[i]=po[i-1]*x;
    }
    ll n;
    cin>>n;
    x=lb(v.begin(),v.end(),n)-v.begin();
    y=n-v[x-1];
    cout<<fun(x,y);
    subt;
    return 0;
}

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

#define maxn 100010
#define maxm 200010
#define INF 0x7f7f7f7f

inline void read(int &x) {
  x = 0;
  bool sign = false;
  char ch = 0;
  while (!isdigit(ch)) { sign |= (ch == '-'); ch = getchar(); }
  while (isdigit(ch)) { x = x * 10 + (ch ^ 48); ch = getchar(); }
  x = sign ? -x : x;
}

int n, m, Li, Ri, Di, ans = 0;
int fa[maxm], r[maxn];

inline int get(int x) {
  if (x == fa[x]) return x;
  else {
    int l = get(fa[x]);
    r[x] = r[fa[x]] + r[x];
    fa[x] = l;
    return l;
  }
}

int main() {
  read(n); read(m);
  for (int i = 1; i <= n; ++i) fa[i] = i, r[i] = 0;
  for (int i = 1; i <= m; ++i) {
    read(Li); read(Ri); read(Di);
    int fl = get(Li), dl = r[Li];
    int fr = get(Ri), dr = r[Ri];
    if (fl == fr) {
      if (dl + Di != dr) {
        printf("No");
        return 0;
      }
    } else {
      fa[fr] = fl;
      r[fr] = dl + Di - dr;
    }
  }
  printf("Yes");
  return 0;
}

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

int n, m;
bool visited[100010] = {};
vector<int> v[100010];

void dfs(int cur, int par){
    if(visited[cur]) return;
    visited[cur] = true;

    for(auto child: v[cur]){
        if(child == par) continue;
        dfs(child, cur);
    }
}

int main(){
    cin >> n >> m;
    for(int i = 0; i < m; ++i){
        int x, y, z;
        scanf("%d %d %d", &x, &y, &z);
        x--; y--;
        v[x].push_back(y);
        v[y].push_back(x);
    }

    int ret;
    for(int i = 0; i < n; ++i){
        if(visited[i]) continue;
        dfs(i, i);
        ret++;
    }

    cout << ret << endl;
}


Measured memory_bytes: 10496
def main():
	S = input()
	T = input()
	ls = len(S)
	lt = len(T)
	ans = []
	for i in range(ls - lt + 1):
		cnt = 0
		for j in range(lt):
			if S[i + j] != T[j]:
				cnt += 1
		ans.append(cnt)
	print(min(ans))

main()

Measured memory_bytes: 9036
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define FOR(n) for(int i=0;i<n;i++)
#define FORJ(n) for(int j=0;j<n;j++)
#define PRN(n) printf("%d\n",n)
#define PRF(n) printf("%lf\n",n)
#define PRL(n) printf("%lld\n",n)
#define PRS(s) printf("%s\n",s)
#define PRC(c) printf("%c",c)
#define mod 1000000007
typedef long long int ll;
int u(const void *a, const void *b){
    return *(ll*)a-*(ll*)b;
}
int d(const void *a, const void *b){
    return *(ll*)b-*(ll*)a;
}
int z(int a){
  if(a<1)a*=-1;
  return a;
}
int min(int a,int b){
  if(a>b)return b;
  return a;
}
int max(int a,int b){
  if(a>b)return a;
  return b;
}
int gcd(int a,int b){
  if(!b)return a;
  return gcd(b,a%b);
}
int main(void){
  int h,a,b,ans=0;
  scanf("%d %d %d",&h,&a,&b);
  for(int i=a;i<=b;i++)ans+=(h%i<1);
  PRN(ans);
}



Measured memory_bytes: 2104
import collections

N=int(input())
l=list(map(int,input().split()))
c=collections.Counter(l)

c=sorted(c.items(),key=lambda x:x[0])

item=[]
num=[]

for i,n in c:
    item.append(i)
    num.append(n)
    
count=0

if N<3:
    print(0)
else:
    for i in range(len(item)-2):
        for j in range(i+1,len(item)-1):
            k=j+1
            sumij=item[i]+item[j]
            mulij=num[i]*num[j]
            while k<len(item) and item[k]<sumij:
                count+=mulij*num[k]
                k+=1
    print(count)

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

int main(){
  int n; 
  cin >> n;
  double ans = 0;
  for(int i = 0; i < n; ++i){
    double x;
    string s;
    cin >> x >> s;
    if(s == "BTC") x *= 380000.0;
    ans += x;
  }
  
  cout << fixed << setprecision(8) << ans << endl;
}

Measured memory_bytes: 256
import java.io.*
import java.util.*

fun solve(S: String, K: Long){
    if (S.all{ it == '1' }) {
        println('1')
        return
    }
    val i = S.indexOfFirst{ it != '1' }!!
    println(if (K <= i.toLong()) 1 else S[i])
    return
}


fun main(args: Array<String>) {
    fun StringArray(size: Int, init: (Int) -> String = { "\u0000" }): Array<String> {
        return Array<String>(size, init)
    }
    class Scanner(stream: InputStream) {
        private val reader = BufferedInputStream(stream).bufferedReader()
        private var st: StringTokenizer? = null
        fun next(): String {
            while (!(st?.hasMoreTokens() ?: false)) st = StringTokenizer(reader.readLine())
            return st!!.nextToken()
        }
    }
    val sc = Scanner(System.`in`)
    val S = sc.next()
    val K = sc.next().toLong()
    solve(S, K)
}



Measured memory_bytes: 31388
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    int a=2000,b=2000;
    int c;
    for(int i=0;i<3;++i) {
        cin>>c;
        a=min(a,c);
    }
    for(int i=0;i<2;++i) {
        cin>>c;
        b=min(c,b);
    }
    cout<<a+b-50<<endl;
    return 0;
}

Measured memory_bytes: 3112
#include <bits/stdc++.h>
#define rep(i,n,s)		for(i=s;i<n;i++)
#define repr(i,n,s)		for(i=s;i>=n;i--)
#define remax(x,y)		x = max(x,(y))
#define remin(x,y)		x = min(x,(y))
#define all(c)			(c).begin(),(c).end()
#define allr(c)         (c).rbegin(),(c).rend()
#define loop(c,i)       for(typeof(c.begin()) i = c.begin(); i != c.end(); i++)
#define loopr(c,i)      for(typeof(c.end()) i = c.end(); i != c.begin(); )
#define ittr(v) typeof(v)::iterator
#define pb	push_back
#define mp 	make_pair
#define vi 	vector<int>
#define vl 	vector<long>
#define vpii 	vector< pair<int,int> >
#define vpil 	vector< pair<int,long> >
#define vpll 	vector< pair<long,long> >
#define pii 	pair<int,int>
#define piii	pair< pair<int,int>,int >
#define pll 	pair<long,long>
#define plll 	pair< pair<long,long>,long >
#define umii 	unordered_map<int,int>

using namespace std;

int main()
{
	int k,i;
	cin>>k;
	long a[k],g=2,l=2;
	rep(i,k,0)
		cin>>a[i];
	repr(i,0,k-1)
	{
		l = l + (a[i] - l%a[i])%a[i];
		g = g - g%a[i] + a[i] - 1;
		if(l>g)
			break;
	}
	if(l>g)
		cout<<-1;
	else
		cout<<l<<" "<<g;
}

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

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	
	string s, t;
	cin >> s >> t;
	int ans{};
	for (int i = 0; i < s.length(); i++) ans += (s[i] != t[i]);
	cout << ans;
	
	return 0;
}

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

int main()
{
    char s[1000000];
    scanf("%s", s);
    int len = strlen(s);
    int ans = 0;
    for(int i = 0, j = len - 1; i <= j; i++, j--){
        if(s[i] == s[j]){
            continue;
        }
        while(s[i] == 'x'){
            i++;
            ans++;
        }
        while(s[j] == 'x'){
            j--;
            ans++;
        }
        if(s[i] != s[j]){
            printf("-1");
            return 0;
        }
    }
    printf("%d", ans);
    return 0;
}


Measured memory_bytes: 256
N = int(input())
# = map(int, input().split())
A = list(map(int, input().split()))
# = [int(input()) for i in range(N)]
# = [list(map(int, input().split())) for i in range(N)]

A = list(sorted(A))
mark = [0]*(10**6+1)

for i in A:
    mark[i] += 1
    if mark[i] == 1:
        for j in range(2*i, len(mark), i):
            mark[j] += 2

print(mark.count(1))


Measured memory_bytes: 32188
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
  int a,b,c,x;
  cin >> a >> b >> c >> x;
  
  int count = 0;
  
  for (int i = 0; i <= a; ++i)
  {
    for (int j = 0; j <= b; ++j)
    {
      for (int k = 0; k <= c; ++k)
      {
        if (500*i + 100*j + 50*k == x) count++;
      }
    }
  }
  
  cout << count << endl;
  
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
#define int long long
#define mod 1000000007
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl
#define trace2(x, y) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z) cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define sa(a,n) for(int i =0 ; i<n ; i++) cin>>a[i]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define pb push_back
#define inf 2e18
#define scan() int n; cin>>n ; int a[n]; for(int i = 0 ; i<n ; i++) cin>>a[i]
#define print(a,n) for(int i = 0 ; i < n ; i++) cout<<a[i]<<' '
#define mem(a,v) memset(a,v,sizeof(a))
#define pii pair<int,int>
#define mkp make_pair
using namespace std;
#define N 200005
int n,k;
int a[100000];
int catche[N];
int dp(int k){
    int  ans=catche[k];
    if(ans!=-1){
        return ans;
    }
    //if(k<=0)return 0;
    ans=0;
    for(int i=1; i<=n; i++){
       if(k-a[i] <0) break;
        if(!dp(k-a[i])){
            catche[k]=1;
            ans=1;
            return 1;
        }
    }
    catche[k]=ans;
    return ans;

}

int32_t main(){
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);
        mem(catche,-1);
        cin >> n >> k;
        int i;
        for(i=1; i<=n; i++) cin >> a[i];
        if(dp(k)){
            cout << "First" << '\n';
        }
        else{
            cout << "Second" << '\n';
        }



        
        

}

Measured memory_bytes: 4992
# どの文字を持っているかを二進数で1000101010...と表す
# or で足していく
class SegmentTree:
  arr=None
  tree=None
  n=0
  # 結果に影響を与えないdefault value
  DEF=0

  def __init__(self,arr):
  #  print("arr",arr)
    self.arr=arr
    size=len(arr)
    # n階層目は2**(n-1)要素
    self.n=1
    while self.n<size:
      self.n*=2
    self.tree=[self.DEF]*(2*self.n-1)
    # 親=(n-1)//2
    # 子=2*n+1,2*n+2
    # 最下階層の要素を埋めていく
    for i in range(size):
    #  print(arr[i])
      self.tree[i+self.n-1]=arr[i]
    for i in range(self.n-2,-1,-1):
      self.tree[i]=self.__choose__(self.tree[2*i+1],self.tree[2*i+2])
    
    
  # 区間からの代表値の選び方を定義する（最小値を選ぶ場合はminなど）
  def __choose__(self,a,b):
    #print("a",a,"b",b)
    return a | b
  
  # 添字xをvalで更新する
  def update(self,x,val):
    x+=self.n-1
  #  print("x",x,"val",val)
    self.tree[x]=val
    while x>0:
      x=(x-1)//2
      self.tree[x]=self.__choose__(self.tree[2*x+1],self.tree[2*x+2])
      
  # 対象区間[a,b)の値を求めるクエリ (bは含まないので注意)
  # k:自分がいるノードのindex
  # [l,r):検査する区間
  def get_val(self,a,b,k=0,l=0,r=-1):
    # 最初に呼び出されたときは対象区間が[0,N)
    if r<0:
      r=self.n
      
    # 要求区間と対象区間が交わらない
    if r<=a or b<=l:
      return self.DEF
    
    # 要求区間が対象区間を完全に満たす->対象区間を計算に使用する
    if a<=l and r<=b:
      return self.tree[k]
    
    # 要求区間が対象区間の一部を満たす->子を探索
    ll=self.get_val(a,b,2*k+1,l,(l+r)//2)
    rr=self.get_val(a,b,2*k+2,(l+r)//2,r)
    
    return self.__choose__(ll,rr)
    
  def show(self):
    print("----")
    print(list(map(bin,self.tree)))
    print(self.tree)
    
base=ord("a")
ALPHA="abcdefghijklmnopqrstuvwxyz"
def change_alpha_to_num(c):
  if c not in ALPHA:
    return 0
  # print("c",c,"ord(c)",ord(c),"base",base)
  return 1<<(ord(c)-base)

import sys
readline=sys.stdin.readline

N=int(readline())
S=readline()
Sarr=list(map(change_alpha_to_num,list(S)))
ST=SegmentTree(Sarr)
#ST.show()
Q=int(readline())
for i in range(Q):
  q=list(readline().split())
  if q[0]=="1":
    #print("q",q)
    i,c=int(q[1])-1,q[2]
    ST.update(i,change_alpha_to_num(c))
    #ST.show()
  elif q[0]=="2":
    l,r=int(q[1])-1,int(q[2])-1
  #  print(ST.get_val(l,r+1))
    print(bin(ST.get_val(l,r+1)).count("1"))
  

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

typedef long long LL;

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(x) (x).begin(),(x).end()
const int IINF = 1e9;
const LL LINF = 1e18;
const LL MOD = 1e9+7;

int main() {
    string s, t;
    cin >> s >> t;
    int n, m;
    n = s.size();
    m = t.size();

    int r = 10000;
    REP(i, n - m + 1) {
        int x = 0;
        REP(j, m) {
            x += s[i + j] != t[j];
        }
        r = min(r, x);
    }
    cout << r << endl;
    return 0;
}


Measured memory_bytes: 3624
fun main(args: Array<String>) {
    val n = readInputLine().toInt()
    
    val ps = readInputLine().split(" ").map { it.toInt() }
    
    var ans = 0
    
    for (i in 1 until n - 1) {
        if (ps[i - 1] < ps[i] && ps[i] < ps[i + 1]) {
            ans++
            continue
        }
        if (ps[i + 1] < ps[i] && ps[i] < ps[i - 1]) {
            ans++
            continue
        }
    }
    
    println(ans)
}
 
fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 37924
import java.util.Scanner;

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

		Scanner sc = new Scanner(System.in);

		String s1 = sc.next();
		String s2 = sc.next();
		String s3 = sc.next();

		String S1 = s1.toUpperCase();
		String S2 = s2.toUpperCase();
		String S3 = s3.toUpperCase();

		System.out.print(String.valueOf(S1.charAt(0)) + String.valueOf(S2.charAt(0)) + String.valueOf(S3.charAt(0)));

		sc.close();
	}
}

Measured memory_bytes: 22100
# 時間tにおいて行動a,b,cを取った時の幸福度の最大値を求める

N = int(input())
abc = [list(map(int, input().split())) for _ in range(N)]

happy = [[0 for _ in range(3)] for _ in range(N)]
happy[0] = abc[0] # 最初の日はその行動の幸福度によってのみ決まる

for i in range(1, N):
    for j in range(3):
        if j == 0:
            s, t = 1, 2
        elif j == 1:
            s, t = 0, 2
        else:
            s, t = 0, 1  
        happy[i][j] = max(abc[i][j] + happy[i-1][s],
                          abc[i][j] + happy[i-1][t])

print(max(happy[N-1]))

Measured memory_bytes: 47344
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <iomanip>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cstdint>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
#define MP make_pair
#define PB push_back
#define inf 1000000007
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
 
template<class T> inline bool chmax(T &a, T b){
    if(a<b){
        a = b;
        return true;
    }
    return false;
}

template<class T> inline bool chmin(T &a, T b){
    if(a>b){
        a = b;
        return true;
    }
    return false;
}
int res[531441];
int P[14];
int nn;
void dfs(int id,int p,int q,string s){
    if(id==nn){
        res[p] = q;
        return;
    }
    int n = s.size();
    string t;
    for(int i=0;i<n;i++){
        if(s[i]=='S'){
            if(t.size()!=0&&t.back()=='S'){
                t.pop_back();
            }else{
                t.push_back(s[i]);
            }
        }else{
            t.push_back(s[i]);
        }
    }
    for(int pp=0;pp<3;pp++){
        string nxt;
        int k = pp;
        for(int i=0;i<t.size();i++){
            if(t[i]=='S'){
                if(k==1||k==2){
                    k = 3-k;
                }
                nxt.push_back('S');
            }else if(t[i]=='R'){
                k++;
                if(k==3){
                    nxt.push_back('R');
                    k = 0;
                }
            }
        }
        dfs(id+1,p+P[id]*pp,q+P[id]*k,nxt);
    }
}
int main(){
    string s;
    cin >> nn >> s;
    P[0] = 1;
    for(int i=1;i<=12;i++){
        P[i] = P[i-1]*3;
    }
    dfs(0,0,0,s);
    int k = 1;
    for(int i=0;i<nn;i++){
        k*=3;
    }
    rep(i,k){
        cout << res[i] << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 7136
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <cstring>

using namespace std;

const int N=5005;
const int P=998244353;

struct node{
	int size;
	int len;
	node* son[26],*fail;
}pool[5*N],*root,*rf,*last;

int n,k,top=-1;
char str[N];

inline void addnode(int id,int len){
	node *now=&pool[++top]; now->len=len;
	node *p=last;
	while(p->son[id]==NULL) p->son[id]=now,p=p->fail;
	node *q=p->son[id];
	if(p->len+1==q->len) now->fail=q;
	else{
		//p->len+1 < q->len
		node *nq=&pool[++top]; nq->len=p->len+1;
		nq->fail=q->fail; q->fail=nq; now->fail=nq;
		for(int i=0;i<26;i++) nq->son[i]=q->son[i];
		while(p->son[id]==q) p->son[id]=nq,p=p->fail;
	}
	last=now;
}

void dfs_1(node* now){
	now->size=1;
	for(int i=0;i<26;i++){
		if(now->son[i]==NULL) continue;
		dfs_1(now->son[i]);
		now->size+=now->son[i]->size;
	}
}

void dfs_2(node *now,int id){
	if(id==1) return ;
	int cur=1;
	for(int i=0;i<26;i++){
		if(now->son[i]==NULL) continue;
		if(cur+now->son[i]->size>=id){
			printf("%c",i+'a');
			dfs_2(now->son[i],id-cur);
			return ;
		}
		cur+=now->son[i]->size;
	}
}

void init(){
	scanf("%s",str);
	n=strlen(str);
	rf=&pool[++top]; root=&pool[++top];
	rf->len=-1; root->len=0;
	root->fail=rf; for(int i=0;i<26;i++) rf->son[i]=root;
	last=root;
	for(int i=0;i<n;i++) addnode(str[i]-'a',i+1);
	dfs_1(root);
	scanf("%d",&k);
	dfs_2(root,k+1);
}

int main(){
	init();
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <utility>
#include <stack>

using namespace std;

typedef pair<int, int> P;

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

  int index = 0, A = 0;
  stack<int> start;
  stack<P>L;

  for (const auto& c : S) {
    if (c == '\\') {
      start.push(index);
    } else if (c == '/') {
      if (!start.empty()) {
        int s = start.top(); start.pop();
        int e = index;
        A += e - s;
        L.push(make_pair(e - s, s));
      }
    }
    ++index;
  }

  stack<int> res;
  while (!L.empty()) {
    P p = L.top(); L.pop();
    int l = p.first;
    while (!L.empty() && L.top().second > p.second) {
      l += L.top().first;
      L.pop();
    }
    res.push(l);
  }
  cout << A << endl;
  cout << res.size();
  while (!res.empty()) {
    cout << " " << res.top();
    res.pop();
  }
  cout << endl;

  return 0;
}



Measured memory_bytes: 3256
#include<iostream>
using namespace std;
long long int gcd(long long int a,long long int b)
{
  if(a==0)
    return b;
  if(b==0)
    return a;
  if(a==b)
    return a;
  if(a>b)
    return gcd(a-b,b);
  return gcd(a,b-a);
}
int main ()
{
  long long int k,sum=0;
  cin>>k;
  for(long long int i=1;i<=k;i++)
  {
    for(long long int j=1;j<=k;j++)
    {
      int d=gcd(i,j);
      for(long long int p=1;p<=k;p++)
      {
        sum+=gcd(d,p);
      }
    }
  }
  cout<<sum;
  return 0;
}

Measured memory_bytes: 3604
#include <iostream>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <cstring>
#include <string.h>
#include <sstream>
#include <iomanip>
#include <queue>
#include <stack>
#include <deque>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <vector>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
 
typedef unsigned long ul;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
const ll MOD = 1e9+7;
const double PI  = 3.14159265358;
const double EPS = 1e-8;

#define INT_MX 2147483647
#define INF ((int)1e9)
#define LLINF ((ll)1e18)
#define F first
#define S second
#define mp(x,y) make_pair(x,y)
#define sz(v) ((int)v.size())
#define rs(n) resize(n)
#define all(v) v.begin(),v.end()
#define reset(v) memset((v),0,sizeof(v))
#define EB emplace_back
#define pb push_back
#define pf push_front
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);


void solve(){
    ll n, ipt, a, b;
    map<int, int> mp;
    
    a = b = 0;
    
    cin >> n;
    rep(i, n){
        cin >> ipt;
        mp[ipt]++;
    }
    
    for(auto i:mp){
        if(i.S >= 2){
            b = a;
            a = i.F;
        }
        if(i.S >= 4){
            b = i.F;
        }
    }
    
    cout << a * b << '\n';
}

int main(){
    
    solve();
}





Measured memory_bytes: 4992
def main():
    s = input()
    t = input()
    lis = []
    for i in range(len(s)-len(t)+1):
        f=True
        for j in range(len(t)):
            if(s[i+j]==t[j] or s[i+j]=="?"):
                continue
            else:
                f=False
                break
        if(f):
            tmp = s[0:i]+t+s[i+len(t):]
            res = ""
            for k in range(len(tmp)):
                if(tmp[k]=="?"):
                    res += "a"
                else:
                    res+=tmp[k]
            lis.append(res)
    if(len(lis)==0):
        print("UNRESTORABLE")
    else:
        print(sorted(lis)[0])


if __name__ == '__main__':
    main()


Measured memory_bytes: 9096
import java.util.Scanner;

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

		String N = scan.nextLine();
		int n = Integer.parseInt(N);

		String L = scan.nextLine();
		String[] l = L.split(" ");
		long[] a = new long[n];
		for(int i = 0 ; i < n ; i++) {
			a[i] = Long.parseLong(l[i]);
		}

		long max = a[0];
		long total = 0;
		for(int i = 1 ; i < n ; i++) {
			if(a[i] < max) {
				total += max - a[i];
			}else {
				max = a[i];
			}
		}

		System.out.println(total);

		scan.close();


	}

}


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

int solve() {
    vector<vector<int>> F(N, vector<int>(10));
    vector<vector<int>> P(N, vector<int>(11));
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < 10; j++) {
            cin >> F[i][j];
        }
    }
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < 11; j++) {
            cin >> P[i][j];
        }
    }
    int ret = -1000000007;
    for (int bit = 1; bit < (1 << 10); bit++) {
        vector<int> S;
        for (int i = 0; i < 10; i++) {
            if (bit & (1 << i)) {
                S.push_back(i);
            }
        }
        int sumP = 0;
        for (int i = 0; i < N; i++) {
            int countF = 0;
            for (int j : S) {
                if (F[i][j] == 1) countF++;
            }
            sumP += P[i][countF];
        }
        ret = max(sumP, ret);
    }
    return ret;
}

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

    cin >> N;
    cout << solve() << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<numeric>
#include<math.h>
#include<algorithm>
#include<iomanip>
using namespace std;

int main() {

	int K;
	int X;
	cin >> K;
	cin >> X;

	int min = X - K + 1;
	int max = X + K - 1;

	if (min < -1000000) {
		min = -1000000;
	}

	if (max > 1000000) {
		max = 1000000;
	}

	int num = min;
	while (num <= max) {
		cout << num << " ";
		num += 1;
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using std::cin;
using std::cout;
#include <string>
using std::string;

int main(void) {
int k;
string s;

 cin >> k;
cin >> s;

if (s.size() > k) {
s = s.substr(0, k) + "...";
 }

cout << s << '\n';
return 0;
}

Measured memory_bytes: 3604
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,x,n) for(int i=x;i<n;i++)
#define ALL(v) (v).begin(),(v).end()
#define MP(a,b) make_pair(a,b)
typedef long long LL;
typedef pair<int, int> PI;
typedef vector<int> VI;
typedef pair<double, int> P;
const LL MOD = 1000000007LL;
int x[1002], y[1002], r[1002];
double G[1002][1002];
double dist[1002];
int main() {
	int xs, ys, xt, yt;
	cin >> xs >> ys >> xt >> yt;
	int N;
	cin >> N;
	REP(i, 1, N + 1) {
		cin >> x[i] >> y[i] >> r[i];
	}
	x[0] = xs;
	y[0] = ys;
	x[N + 1] = xt;
	y[N + 1] = yt;
	rep(i, N + 2) {
		rep(j, N + 2) {
			G[i][j] = max(sqrt(pow(x[i] - x[j], 2) + pow(y[i] - y[j], 2)) - r[i] - r[j], 0.0);
		}
	}
	fill(dist, dist + (N + 2), DBL_MAX);
	priority_queue<P, vector<P>, greater<P> > Q;
	dist[0] = 0;
	Q.push(MP(0, 0));
	while (!Q.empty()) {
		P p = Q.top(); Q.pop();
		if (p.first > dist[p.second]) continue;
		rep(i, N + 2) {
			if (dist[i] > dist[p.second] + G[p.second][i]) {
				dist[i] = dist[p.second] + G[p.second][i];
				Q.push(MP(dist[p.second] + G[p.second][i], i));
			}
		}
	}
	printf("%.15lf\n", dist[N + 1]);
}

Measured memory_bytes: 13936
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 7;
int dp[MAXN], h[MAXN];
int main()
{
    int n; scanf("%d", &n);
    for (int i = 1; i <= n; i++) scanf("%d", &h[i]);
    memset(dp, 0x3f3f3f3f, sizeof(dp));
    dp[1] = 0; dp[2] = min(dp[2], dp[1] + abs(h[2] - h[1]));
    for (int i = 3; i <= n; i++) 
        dp[i] = min(dp[i], min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2])));
    printf("%d\n", dp[n]);
    return 0;
}

Measured memory_bytes: 1024
fun main(args: Array<String>) {
    val (n, m, c) = readLine()!!.split(' ').map(String::toInt)
    val b = readLine()!!.split(' ').map(String::toInt)
    val ans = (1..n).count {
        val ab = readLine()!!.split(' ')
            .map(String::toInt)
            .foldIndexed(0) { index, acc, a -> acc + a * b[index] }
        0 < ab + c
    }
    println(ans)
}


Measured memory_bytes: 36456
#include<stdio.h>
int main()
{
    int N,i;
    unsigned long long sum=0;
    scanf("%d",&N);
    for(i=1;i<=N;i++){
        if(i%3!=0&&i%5!=0)
           sum+=i;
    }
    printf("%llu\n",sum);
    return 0;
}


Measured memory_bytes: 1684
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF=INT_MAX;
struct segtree
{
    vector<int> node;
    vector<int> lazy;
    vector<bool> lflg;
    int n;
    segtree(int sz)
    {
        n=1;while(n<sz) n*=2;
        node.resize(2*n,INF);
        lazy.resize(2*n,0);
        lflg.resize(2*n,false);
    }
    void lazyupdate(int k, int l, int r)
    {
        if(lflg[k])
        {
            node[k]=lazy[k];
            push(lazy[k],k,l,r);
            lazy[k]=0;
            lflg[k]=false;
        }
    }
    void push(int v,int k,int l,int r)
    {
        if(r-l>0)
        {
            lazy[2*k]=lazy[2*k+1]=v;
            lflg[2*k]=lflg[2*k+1]=true;
        }
    }
    void update(int qa, int qb, int v, int k=1, int l=1,int r=-1)
    {
        if(r<0) r=n;
        lazyupdate(k, l, r);
        if(qb<l||r<qa) return;
        if(qa<=l&&r<=qb)
        {
            node[k]=v;
            push(v,k,l,r);
        }
        else
        {
            int m=(l+r)/2;
            update(qa,qb,v,2*k,l,m);
            update(qa,qb,v,2*k+1,m+1,r);
            node[k]=min(node[2*k],node[2*k+1]);
        }
    }
    int get(int qa, int qb, int k=1, int l=1, int r=-1)
    {
        if(r<0) r=n;
        lazyupdate(k ,l, r);
        if(qb<l||r<qa) return INF;
        if(qa<=l&&r<=qb) return node[k];
        else
        {
            int m=(l+r)/2;
            int lv=get(qa, qb, 2*k, l, m);
            int rv=get(qa, qb, 2*k+1, m+1, r);
            return min(lv,rv);
        }
    }
};

int main()
{
    int n,q;
    scanf("%d %d",&n,&q);
    segtree tree(n);
    for(int i=0;i<q;i++){
        int c;
        scanf("%d",&c);
        if(c){
            int x,y;
            scanf("%d %d",&x,&y);
            cout<<tree.get(x+1,y+1)<<endl;
        }else{
            int s,t,v;
            scanf("%d %d %d",&s,&t,&v);
            tree.update(s+1,t+1,v);
        }
    }
}


Measured memory_bytes: 4960
#include <stdio.h>
#include <iostream>
#include <queue>
#include <list>
using namespace std;

class Node
{
private:
	list<int> next_node_list;
	list<int> next_weight_list;
public:
	Node();
	void AddNextNode(int id, int weight);
	void SetWeight(int weight);
	void DistributeWeight();
	int weight_from_0;
	bool check;
};

Node::Node()
{
	weight_from_0 = -1;
	check = false;
}

Node *Node_list;

struct GreatNode
{
	bool operator()(const Node *n1, const Node *n2) const;
};
bool GreatNode::operator()(const Node *n1, const Node *n2) const
{
	return n1->weight_from_0 > n2->weight_from_0;
}
priority_queue<Node*, vector<Node*>, GreatNode > que;

void Node::AddNextNode(int id, int weight)
{
	next_node_list.push_back(id);
	next_weight_list.push_back(weight);
}

void Node::SetWeight(int weight)
{
	if (weight_from_0 == -1 || weight < weight_from_0) {
		weight_from_0 = weight;
	}
}

void Node::DistributeWeight()
{
	check = true;
	list<int>::iterator itr2 = next_weight_list.begin();
	for(list<int>::iterator itr = next_node_list.begin(); itr != next_node_list.end(); itr++){	
		if (Node_list[*itr].check == false) {
			Node_list[*itr].SetWeight(weight_from_0 + *itr2);
			que.push(&Node_list[*itr]);
		}
		itr2++;
	}
	next_node_list.clear();
	next_weight_list.clear();
}

int main(void)
{
	//input
	int n;
	cin >> n;
	Node_list = new Node[n]();
	for (int i = 0; i < n; i++) {
		int u, k;
		cin >> u >> k;
		for (int j = 0; j < k; j++) {
			int v, c;
			cin >> v >> c;
			Node_list[i].AddNextNode(v, c);
		}
	}

	//weight from 0 ?
	Node_list[0].check = true;
	Node_list[0].weight_from_0 = 0;
	Node_list[0].DistributeWeight();
	while (!que.empty()) {
		Node *node = que.top();
		que.pop();
		node->DistributeWeight();
	}

	//output
	for (int i = 0; i < n; i++) {
		cout << i << " " << Node_list[i].weight_from_0 << endl;
	}
	
	return 0;
}


Measured memory_bytes: 3260