akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i,a,b) for (ll i=(a);i<(ll)b; i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define INF 1LL << 60
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll,ll> p;
const long long MOD=1000000007;

// vector<p> cut(M); vector<vector<ll> > v(4);
// cut[i].second
// cut[i].first;
// REP(i,M){
//     int a,b;cin>>a>>b;
//     cut[i] = make_pair(b,a);//last first の順番
// }
// for(int i=0; i<N;i++){
// }
// sort(cut.begin(),cut.end()), sort(v.rbegin(), v.rend()); //sort
// char '' str ""
int main(void)
{
    int N,D; cin>>N>>D; vector<vector<int> > x(N);
    for(int i=0;i<N;i++){
      for(int j=0;j<D;j++){
        int xx; cin>>xx; x[i].push_back(xx);
      }
    }
    int cnt=0;
    for(int i=0;i<N;i++){
      for(int j=0;j<N;j++){
        if(i != j){
          float d=0;
          for(int k=0;k<D;k++){
            float dd = abs(x[i][k]-x[j][k])* abs(x[i][k]-x[j][k]);
            d+= dd;
          }
          int m = sqrt(d);
          // cout<<m<<endl;
          if(abs(m*m-d) < 1e-10) cnt++;
        }
      }
    }
    cout<<cnt/2<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>

#define lli long long int
#define llf long double

int main(void)
{
	lli k, n;
	scanf("%lld %lld",&n, &k);

	lli p[n];
	lli index =0;
	lli sum = 0;
	while (index <n)
	{
		scanf("%lld", &p[index]);
		p[index] = p[index] + 1;
		sum = sum + p[index];
		index++;
	}

	llf output = 0;
	lli chunk_sum = 0;
	lli chunk_max = 0;
	index = 0;
	while (index < k)
	{
		chunk_sum = chunk_sum + p[index];

		index++;
	}
	chunk_max = chunk_sum;
	while (index < n)
	{
		chunk_sum = chunk_sum + p[index] - p[index-k];
		if (chunk_sum > chunk_max)
		{
			chunk_max = chunk_sum;
		}
		index++;
	}
	output = chunk_max / 2.0;
	printf("%.12Lf\n", output);
	return (0);


}


Measured memory_bytes: 1664
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#define LL long long
#define M 100020
using namespace std;
const int BS=1<<19;char BF[BS],OT[BS],*SZ=OT,*HD,*TL;
const char *ED=OT+BS-1; char SS[20]; int Top;
char Getchar(){if(HD==TL) TL=(HD=BF)+fread(BF,1,BS,stdin);return *HD++;}
void flush(){fwrite(OT,1,SZ-OT,stdout);}
void Putchar(char c){*SZ++ =c;if(SZ==ED) flush(),SZ=OT;}
void write(LL x){
	if(!x){Putchar(x),Putchar('\n');}
	while(x) SS[++Top]=(x%10+'0'),x/=10;
	while(Top) Putchar(SS[Top]),Top--; Putchar('\n');
}
LL read(){
	LL nm=0,fh=1; char cw=Getchar();
	for(;!isdigit(cw);cw=Getchar()) if(cw=='-') fh=-fh;
	for(;isdigit(cw);cw=Getchar()) nm=nm*10+(cw-'0');
	return nm*fh;
}
LL n,T,m,p[M],N,G[M],F[M],K[M],tmp;
int main(){
//	freopen("data.in","r",stdin);
//	freopen("data.out","w",stdout);
	n=read(),T=read();
	while(T--){LL x=read(); while(m&&p[m]>=x) m--; p[++m]=x;}
	if(m&&p[1]<n){N=n,n=p[1];for(LL i=1;i<m;i++) p[i]=p[i+1];m--;}
	G[0]=p[0]=n,F[m]=1;
	for(LL i=m;i>=0;i--){
		LL res=p[i],now=i-1;
		while(res>n){
			LL k=res/p[now]; F[now]+=F[i]*k,res-=k*p[now];
			now=upper_bound(p,p+now,res)-p-1;
		} G[i]=res,K[1]+=F[i],K[G[i]+1]-=F[i];
	}
	for(LL i=1;i<=n;i++) K[i]+=K[i-1],write(K[i]);
	while(n<N) n++,Putchar('0'),Putchar('\n'); flush(); return 0;
}

Measured memory_bytes: 5888
import java.util.Scanner;

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

    char[] S = scanner.next().toCharArray();
    int max = 0;
    for (int i = 0; i < S.length; i++) for (int j = i + 1; j <= S.length; j++) if (isACGT(S, i, j)) max = Math.max(max, j - i);
    System.out.println(max);
  }

  private static boolean isACGT(char[] S, int left, int right) {
    for (int i = left; i < right; i++) {
      char ch = S[i];
      switch (ch) {
        case 'A':
        case 'C':
        case 'G':
        case 'T':
          continue;
        default:
          return false;
      }
    }
    return true;
  }
}


Measured memory_bytes: 23636
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
typedef vector<unsigned int>vec;
typedef vector<vec> mat;
typedef vector<vector<int>> Graph;

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

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; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<string> S(N);
    vector<int> P(N);
    REP(i,N) cin >> S[i] >> P[i];
    vector<int> idx(N);
    iota(idx.begin(),idx.end(),0);
    sort(idx.begin(),idx.end(),
         [&](int x, int y){return S[x] == S[y] ? P[x] > P[y] : S[x] < S[y];}
         );
    REP(i,N) cout << idx[i] + 1 << endl;
}


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

using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define FOR(k,m,n) for(ll (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define WAITING(str) int str;std::cin>>str;
#define DEBUGING(str) cout<< #str << " " str<<endl

constexpr int INF = (1 << 30);
constexpr ll INFL = (1ll << 60);
constexpr ll MOD = 1000000007;// 10^9+7



class UnionFind {
public:
	vector<int>rank, parent, cont;
	//初期化
	UnionFind(int size) {
		rank.resize(size, 0);
		parent.resize(size);
		cont.resize(size, 1);
		REP(i, size)parent[i] = i;
	}
	//木の根を求める
	int find(int x) {
		if (parent[x] == x)return x;
		else return parent[x] = find(parent[x]);
	}
	//xとyの属する集合を併合
	void unite(int x, int y) {
		x = find(x);
		y = find(y);
		if (x == y)return;

		int contx = cont[x];
		int conty = cont[y];
		cont[y] += contx;
		cont[x] += conty;

		if (rank[x] < rank[y])
			parent[x] = y;
		else {
			parent[y] = x;
			if (rank[x] == rank[y])rank[x]++;
		}
	}
	//xとyが同じ集合に属するか否か
	bool same(int x, int y) {
		return (find(x) == find(y));
	}
};

int main()
{
	ll N, M;
	cin >> N >> M;

	UnionFind uf(N);
	vector<ll> A(M), B(M), conf(M + 1);
	REP(i, M) {
		cin >> A[i] >> B[i];
		A[i]--;
		B[i]--;
	}
	reverse(A.begin(), A.end());
	reverse(B.begin(), B.end());

	REP(i, M) {
		if (uf.same(A[i], B[i])) {
			conf[i + 1] = conf[i];
			continue;
		}

		ll c1 = uf.cont[uf.find(A[i])];
		ll c2 = uf.cont[uf.find(B[i])];
		conf[i + 1] = conf[i] + c1 * c2;
		uf.unite(A[i], B[i]);
	}

	reverse(conf.begin(), conf.end());
	REP(i, M)cout << conf.front() - conf[i + 1] << endl;

	return 0;
}


Measured memory_bytes: 4864
#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++)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using pii = pair<int, int>;

//const ll INF = 1e18L + 5;
//const int INF = 1e9 + 5;
//const double pi = 3.14159265358979323846;

void	solve()
{
	int a, b;
	cin >> a >> b;
	cout << a * b << endl;
}

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

	solve();
}


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

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  int sum_0 = 0;
  for (int i=0; i<N;i++) {
    cin >> vec.at(i);
    sum_0 += vec.at(i)*vec.at(i);  //0で置き換える場合
  }
  sort(vec.begin(), vec.end());

  for (int i=vec.at(0); i<=vec.at(N-1); i++){
    int sum = 0;
    for (int j=0; j<N; j++){
      sum += (vec.at(j)-i)*(vec.at(j)-i);
    }
    sum_0 = min(sum_0, sum);
  }
  cout << sum_0 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <math.h>
#include <stack>
#include <climits>
#include <bitset>
#include <utility>


using namespace std;
typedef long long ll;

//最小公倍数
ll gcd(ll x, ll y) {
  ll tmp = 0;
  if (x < y){
    tmp=x;
    x=y;
    y=tmp;
  }
  while (y > 0) {
    ll r = x % y;
    x = y;
    y = r;
  }
  return x;
}

//最大公倍数
ll lcm(ll x,ll y){
  return x/gcd(x,y)*y;
}

//階乗
ll kaijo(ll k){
    ll sum = 1;
    for (ll i = 1; i <= k; ++i)
    {
        sum *= i;
        sum%=1000000000+7;
    }
    return sum;
}

//for(int i = ; i < ; i++){}

ll lmax(ll s,ll t){
  if(s>t){
    return s;
  }
  else{
    return t;
  }
}

ll lmin(ll s,ll t){
  if(s<t){
    return s;
  }
  else{
    return t;
  }
}
// ここから開始

int main(){
  string s,t;
  cin>>s>>t;
  string ans = "{";
  bool flag = false;
  if(s.length()<t.length()) {
    cout<<"UNRESTORABLE"<<endl;
    return 0;
  }
  else{
    for(int i = 0; i < s.length()-t.length()+1; i++){
      int c = 0;
     
      for(int j = 0; j < t.length(); j++){
        if(s[s.length()-t.length()+j-i] == t[j]||s[s.length()-t.length()+j-i] == '?'){
          c++;
        }
      }
      
      if(c==t.length()){
        flag = true;
        string tmp(s.length(),'{');
        for(int j = 0; j < s.length()-t.length()-i; j++){
          if(s[j]=='?'){
            tmp[j]='a';
          }
          else tmp[j]=s[j];
        }
        int k = 0;
        for(int j = s.length()-t.length()-i; j < s.length()-i; j++){
          tmp[j]=t[k];
          k++;
        }
        for(int j = 0; j < i; j++){
          if(s[j+s.length()-i]=='?'){
            tmp[j+s.length()-i]='a';
          }
          else tmp[j+s.length()-i]=s[j+s.length()-i];
        }
        if(ans>tmp) {
          ans = tmp;
         
        }
      }
    }
    if(flag){
    cout<<ans<<endl;
    return 0;
    }
    else{
      cout<<"UNRESTORABLE"<<endl;
      return 0;
    }
  }
}


Measured memory_bytes: 256
N, M = map(int, input().split())
from collections import defaultdict
def hoge():
    return "0"

d = defaultdict(hoge)

for i in range(M):
    s, c = input().split()
    s = int(s)
    if s == 1 and c == "0" and N >= 2:
        print(-1)
        exit()
    if s in d.keys():
        if d[s] != c:
            print(-1)
            exit()
    else:
        d[s] = c
ans = []
if N == 1:
    print(d[1])
else:
    if d[1] == "0":
        ans.append("1")
    else:
        ans.append(d[1])
    for i in range(2, N + 1):
        ans.append(d[i])
    print("".join(ans))

Measured memory_bytes: 3316
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		int area = a * b;
		int s = a * 2 + b * 2;
		System.out.println(area+" "+s);

	}

}

Measured memory_bytes: 25972
import java.util.*;
import java.util.Scanner;
import java.io.*;
import java.io.BufferedReader; 
import java.io.IOException; 
import java.io.InputStreamReader; 
import java.util.Scanner; 
import java.util.StringTokenizer;

import javax.lang.model.util.ElementScanner6; 

public class Main
{
    static class FastReader
    { 
        BufferedReader br; 
        StringTokenizer st; 

        public FastReader() 
        { 
            br = new BufferedReader(new
                    InputStreamReader(System.in)); 
        } 

        String next() 
        { 
            while (st == null || !st.hasMoreElements()) 
            { 
                try
                { 
                    st = new StringTokenizer(br.readLine()); 
                } 
                catch (IOException  e) 
                { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 

        int nextInt() 
        { 
            return Integer.parseInt(next()); 
        } 

        long nextLong() 
        { 
            return Long.parseLong(next()); 
        } 

        double nextDouble() 
        { 
            return Double.parseDouble(next()); 
        } 

        String nextLine() 
        { 
            String str = ""; 
            try
            { 
                str = br.readLine(); 
            } 
            catch (IOException e) 
            { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
    } 
    

    
    public static void main(String args[])
    {  
        FastReader in=new FastReader();
        int t=1;
        //t=in.nextInt();
        while(t-->0)
        {
  
               long mod=1000000007;
            
               int n=in.nextInt();
               long arr[]=new long[n];
               long ans=0;
    
               for(int i=0;i<n;i++)
               {
                   arr[i]=in.nextLong();
               }
    
               long suffarr[]=new long[n];
               suffarr[n-1]=0;
    
               for(int i=n-2;i>=0;i--)
               {
                   suffarr[i]=suffarr[i+1]+arr[i+1];
                   
               }
               
               for(int i=0;i<n;i++)
               {
                   ans=(ans+(((arr[i]%mod)*(suffarr[i]%mod)))%mod)%mod;
                   
               }
              
               
                System.out.println(ans);
               
           
        }
    }
}

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

using namespace std;
typedef long long ll;

int main() {
	int N, M;
	cin >> N >> M;
	int l = 0, u = 1145141919;
	for (int i = 0; i < M; i++) {
		int a, b;
		cin >> a >> b;
		l = max(l, a);
		u = min(u, b);
	}
	if (l <= u) {
		cout << u - l + 1 << endl;
	}
	else cout << 0 << endl;
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

#include <bits/stdc++.h>
#include <fstream>
#include<string.h>
#include <algorithm>
#include<math.h>
#include<vector>
#include <queue>
#include <deque> 
#define ll long long
#define M 1000000007 
#define MM 998244353
using namespace std;

int main()
{
    std::ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    /*ll t,tcitr;
    cin>>t;
    tcitr=0;
    while(tcitr<t)
    {*/
        //cout<<"Case #"<<tcitr+1<<": ";
        ll n,x,t;
        cin>>n>>x>>t;
        ll trm=n/x;
        if(n%x)trm++;
        cout<<trm*t<<"\n";
        /*tcitr++;
    }*/
    return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<int,int>;

int main(void){
    int a, b, c, d; cin >> a >> b >> c >> d;
  if(a + b > c + d) cout << "Left" << endl;
  else if(a + b < c + d) cout << "Right" << endl;
  else cout << "Balanced" << endl;
    return 0;
}


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

int main(){
  int n;
  cin>>n;
  while(n>0) n-=1000;
  cout<<-n<<endl;
}

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

long long f(int n, int a) {
  long long x = 1;
  long long y = 1;
  for (int i = 0; i < a; i++) {
    x *= n - i;
    y *= i + 1;
  }
  return x / y;
}

int main() {

  int N;
  cin >> N;

  map<string, int> s;
  for (int i = 0; i < N; i++) {
    string s_;
    cin >> s_;
    sort(s_.begin(), s_.end());
    s[s_]++;
  }

  long long answer = 0;

  for (auto item:s) {
    answer += f(item.second, 2);
  }
  
  cout << answer << endl;

  return 0;

}

Measured memory_bytes: 11136
use std::io::stdin;

fn main() {
    let mut s = String::new();
    stdin().read_line(&mut s).ok();
    let mut itr = s.split_whitespace().map(|e| e.parse().unwrap());
    let k: i64 = itr.next().unwrap();
    let s: i64 = itr.next().unwrap();
    let mut ans = 0;

    for x in 0..k + 1 {
        for y in 0..k + 1 {
            let t = s - x - y;
            ans += if t <= k && 0 <= t { 1 } else { 0 };
        }
    }

    println!("{}", ans);
}


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

int main() {
	double	na;
	while (cin >> na, na != 0)
	{
		vector<int> vec(na);
		rep(i, na)
		{
			int	nb;
			cin >> nb;
			vec.at(i) = nb;
		}
		double	avrg;
		avrg = accumulate(vec.begin(), vec.end(), 0LL) / na;
		double	sum;
		sum = 0;
		rep(i, na)
			sum += (vec.at(i) - avrg) * (vec.at(i) - avrg);
		cout << fixed << setprecision(10) << sqrt(sum / na) << endl;
	}
}



Measured memory_bytes: 3236
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int N;
  long K;
  cin >> N >> K;

  int A[N];
  int visited[N];
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    A[i]--;
    visited[i] = -1;
  }

  int presentPoint = 0;
  int nextPoint = -1;
  vector<int> loop = {0};
  int loopstart = -1;
  int loopsize = -1;
  for (int i = 0; i < K; i++) {
    nextPoint = A[presentPoint];
    if (visited[nextPoint] != -1) {
      loopstart = visited[nextPoint];
      loopsize = i - visited[nextPoint];
      break;
    }
    presentPoint = A[presentPoint];
    visited[presentPoint] = i;
    loop.emplace_back(presentPoint);
  }

  int remaincount = (K - loopstart) % loopsize;
  if (remaincount != 0) {
    presentPoint = loop[loopstart + remaincount];
  }

  cout << presentPoint + 1 << endl;
  return 0;
}

Measured memory_bytes: 5720
#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++)
typedef long long ll;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;

int main(){
  string s;
  cin >> s;
  int len = s.length();
  
  int alph[26]={ 0 };
  rep(i,len){
    int id = s[i] - 'a';
    alph[id]++;
  }
  
  bool flag=true;
  rep(i,26){
    if(alph[i] > 1) flag=false;
  }
  
  if(flag) cout << "yes" << endl;
  else cout << "no" << endl;
  
  return 0;
}

Measured memory_bytes: 256
import math
N, = (int(x) for x in input().split())

sol = 0
for i in range(1, N+1):
    for j in range(1, N + 1):
        G = math.gcd(i, j)
        if G == 1:
            sol += N
            continue
        for k in range(1, N + 1):
            g = math.gcd(G, k)
            sol += g
print(sol)

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

int main(){
    string s;
    cin >> s;
    if(s.at(2) == s.at(3) && s.at(4) == s.at(5)){
        cout << "Yes" << endl;
        return 0;
    }
    else{
        cout << "No" << endl;
        return 0;
    }
}


Measured memory_bytes: 256
use proconio::{fastout, input};

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

    let mut r_ac = vec![0; n];
    let mut r_wa = vec![0; n];

    let mut ac_count = 0;
    let mut wa_count = 0;

    for _ in 0..m {
        input! {p: usize, s: String};

        let index = p - 1;

        if r_ac[index] == 0 {
            if s == "AC" {
                r_ac[index] = 1;
                // ac_count += 1;
                wa_count += r_wa[index];
            } else {
                r_wa[index] += 1;
            }
        }
    }

    print!("{} {}", r_ac.iter().sum::<usize>(), wa_count)
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

using namespace std;

template<class Abel> struct UnionFind {
    vector<int> par;
    vector<int> rank;
    vector<Abel> diff_weight;

    UnionFind(int n = 1, Abel SUM_UNITY = 0) {
        init(n, SUM_UNITY);
    }

    void init(int n = 1, Abel SUM_UNITY = 0) {
        par.resize(n); rank.resize(n); diff_weight.resize(n);
        for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0, diff_weight[i] = SUM_UNITY;
    }

    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            diff_weight[x] += diff_weight[par[x]];
            return par[x] = r;
        }
    }

    Abel weight(int x) {
        root(x);
        return diff_weight[x];
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y, Abel w) {
        w += weight(x); w -= weight(y);
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y), w = -w;
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        diff_weight[y] = w;
        return true;
    }

    Abel diff(int x, int y) {
        return weight(y) - weight(x);
    }
};

int main(){
  int N,M;
  cin >> N >> M;

  UnionFind<int> uf(N);

  rep(i,M){
    int l,r,d;
    cin >> l >> r >> d;
    l--; r--;
    if(uf.issame(l, r) && d != uf.diff(l,r)){
      cout << "No" << endl;
      return 0;
    }else{
      uf.merge(l,r,d);
    }
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 1408
#include <string>
#include<iostream>
#include<vector>
#include <bits/stdc++.h>
#include <stdio.h>
#include<math.h>
#include <ctype.h>
#include <algorithm> // sort
#include <map> // pair
using namespace std;

int main() {
  int n,k;
  string s;
  cin >> n >> s >> k;
  char t;
  t=s.at(k-1);
  for(int i=0;i<s.size();i++){
    if(s.at(i)!=t){
      s.at(i)='*';
    }
  }
  cout << s << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main()
{ int n, m, nc2, mc2;

  scanf("%d", &n);
  scanf("%d", &m);

  nc2= 0.5*n*(n-1);
  mc2= 0.5*m*(m-1);

  printf("%d", nc2+mc2);

    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using P = pair<int,int>;
const int inf = 1e8;

int main() {
    int h, w;
    cin >> h >> w;
    vector<string> field(h);
    rep(i,h) cin >> field[i];
    int sum = 0;
    rep(i,h)rep(j,w) if (field[i][j] == '#') sum++;
    
    int dis[h][w];
    rep(i,h)rep(j,w) dis[i][j] = inf;
    vector<int> dx = {1,0,-1,0};
    vector<int> dy = {0,1,0,-1};
    queue<P> q;
    q.push(P(0,0));
    dis[0][0] = 1;
    while (!q.empty()) {
        P v = q.front(); q.pop();
        rep(i,4) {
            int n_y = v.first + dy[i];
            int n_x = v.second + dx[i];
            if (n_x < 0 || w <= n_x || n_y < 0 || h <= n_y) continue;
            if (field[n_y][n_x] == '#') continue;
            if (dis[n_y][n_x] == inf) {
                dis[n_y][n_x] = dis[v.first][v.second] + 1;
                q.push(P(n_y,n_x));
            }
        }
    }
    sum += dis[h-1][w-1];
    if (dis[h-1][w-1] != inf) {
        cout << h*w - sum << endl;
    } 
    else cout << -1 << endl;
}  

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <cstring>
#include <string>
#include <stack>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <sstream>
#include <set>
using namespace std;

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define repp(i,k,n) for(int i=k;i<(int)n;i++)
#define rei(n) for(int i=0;i<(int)n;i++)
#define rel(n) for(int l=0;l<(int)n;l++)
#define all(s) s.begin(),s.end()
#define INT_MAX 2147483647
#define debug(x) cout<<#x<<": "<<x<<endl;
#define PI 2*acos(0,0)
#define pb push_back
#define inin(x) int x; cin>>x;
#define ll long long
#define pb push_back

typedef pair<int, int> pii;
typedef pair<int, pii> pipii;

struct Calendar
{
	long long year;
	long long month;
	long long day;
	long long dat[2][13];
	Calendar(long long y, long long m, long long d)
	{
		year = y;
		month = m;
		day = d;
		dat[0][0] = dat[1][0] = 0;
		dat[0][1] = dat[1][1] = 31;
		dat[0][2] = dat[1][2] = 28;
		dat[0][3] = dat[1][3] = 31;
		dat[0][4] = dat[1][4] = 30;
		dat[0][5] = dat[1][5] = 31;
		dat[0][6] = dat[1][6] = 30;
		dat[0][7] = dat[1][7] = 31;
		dat[0][8] = dat[1][8] = 31;
		dat[0][9] = dat[1][9] = 30;
		dat[0][10] = dat[1][10] = 31;
		dat[0][11] = dat[1][11] = 30;
		dat[0][12] = dat[1][12] = 31;
		dat[1][2] = 29;
	}
	int uruu()
	{
		if (year % 4 == 0)
		{
			if (year % 400 != 0 && year % 100 == 0)
			{
				return 0;
			}
			else
			{
				return 1;
			}
		}
		return 0;
	}
	int uruu(long long y)
	{
		if (y % 4 == 0)
		{
			if (y % 400 != 0 && y % 100 == 0)
			{
				return 0;
			}
			else
			{
				return 1;
			}
		}
		return 0;
	}
	long long pday(long long d)
	{
		day += d;
		for (;; month++)
		{
			if (month >= 13)
			{
				year++;
				month = 1;
			}

			if (dat[uruu()][month] < day)
			{
				day -= dat[uruu()][month];
			}
			else
			{
				break;
			}
		}
		pmonth(0);
		return d;
	}
	long long pmonth(long long m)
	{
		month += m;
		for (;; year++)
		{
			if (month > 12)
			{
				month -= 12;
			}
			else
			{
				break;
			}
		}
		return m;
	}
	long long pyear(long long y)
	{
		year += y;
		return y;
	}
	long long dif(Calendar c)
	{
		long long ans = 0;
		Calendar a(year, month, day);
		ans -= a.day;
		ans += c.day;
		a.day = 0;
		c.day = 0;
		for (; a.month >= 1; a.month--)
		{
			ans -= dat[a.uruu()][a.month - 1];
		}
		for (; c.month >= 1; c.month--)
		{
			ans += dat[c.uruu()][c.month - 1];
		}
		for (; a.year != c.year; a.year++)
		{
			ans += 365;
			if (a.uruu())ans++;
		}
		return ans;
	}


};


int main()
{
	string core; cin >> core;
	int ans = 0;
	inin(n);
	rep(i, n)
	{
		string a;
		cin >> a;
		a += a+a;
		if (a.find(core, 0)!=string::npos)
		{
			ans++;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 1216
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<string>
#include<vector>
#include<set>
#include<cctype>
using namespace std;
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 long long INF = 1LL << 60;

int main(void){
	ios::sync_with_stdio(false); cin.tie(0);
	
	int a,b,c,d;
	
	cin>>a>>b>>c>>d;
	cout<<min(a,b)+min(c,d)<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
 
using namespace std;
 
#define rep(i,n) for(int i=0 ; i<(n) ; i++)
#define repr(i,n) for(int i=(n) ; i>=0 ; i--)
#define ALL(x) (x).begin(),(x).end()
 
int GCD(int a,int b){ return b ? GCD(b,a%b) : a ;}
int LCM(int a,int b){ return a*b / GCD(a,b) ;}
 
typedef long long ll;
typedef unsigned long long ull;
 
const int INF = 1e9;

int main(){
      int n;
      cin >> n;
      vector<pair<string,int>> sp(n);
      vector<pair<string,int>> ans(n);
      rep(i,n){
            string s;
            int p;
            cin >> s >> p;
            sp[i] = make_pair(s,p);
            ans[i] = make_pair(s,p);
      }
      sort(ALL(sp),[](const auto &a,const auto &b){
            if(a.first != b.first)return a.first < b.first;
            else return a.second > b.second;
      });
     for(int i=0;i<n;i++){
           for(int j=0;j<n;j++){
                 if(sp[i] == ans[j]){
                       cout << j+1 << endl;
                       break;
                 }
           }
     }
      return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    if((a==b&&a!=c)||(a==c&&a!=b)||(b==c&&b!=a))
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
}


Measured memory_bytes: 256
n=int(input())
c=list(map(int, input().split()))
ans=0
f=0

for i in range(n):
    if c[i]%2!=0:
        print(0)
        exit()

while f==0:
    for i in range(n):
        c[i]=c[i]/2
        if c[i]%2!=0:
            ans+=1
            print(ans)
            exit()
    ans+=1

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

#define rep(i,n) for(int i=0 ; i<(n) ; i++)
#define repr(i,n) for(int i=(n) ; i>=0 ; i--)
#define ALL(x) (x).begin(),(x).end()

typedef long long ll;
typedef unsigned long long ull;
 
const ll INF = 1LL<<60;
const int MINF = 1e9;
const int MOD = 1e9+7;

using vi = vector<int>;
using vii = vector<vi>;

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

template<typename T>
T GCD(T a,T b){ return b ? GCD(b,a%b) : a ;}
template<typename T>
T LCM(T a,T b){ return a*b / GCD(a,b) ;}

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

int main() {
    int n,k;cin >> n >> k;
    ll s;cin >> s;
    vi ans;
    for(int i=0;i<k;i++){
        ans.push_back(s);
    }
    for(int i=0;i<n-k;i++){
        if(s==1000000000){
            ans.push_back(s-1);
        }else{
            ans.push_back(s+1);
        }
    }
    for(int i=0;i<n;i++){
        cout << ans[i];
        if(i!=n-1)cout << ' ';
    }
    return 0;
}


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

int main() {
  int N;
  int count = 0;
  cin >> N;
  
  int l;
  int r;
  for (int i=0;i<N;i++) {
    //団体ごとカウント
    cin >> l >> r;
    for (int j=l;j<=r;j++) {
      count +=1;
    }

  }
  cout << count << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long

using namespace std;

int other(int j) {
    int x;
    if(j == 1)  {
        x = 23;
        return x;
    }
    if(j == 2) {
        x = 31;
        return x;
    }
    if(j == 3) {
        x = 12;
        return x;
    }
}

int happiness_points[100001][4], v[4];

int main() {
    int n;
    cin >> n;
    cin >> happiness_points[1][1] >> happiness_points[1][2] >> happiness_points[1][3];

    for(int i = 2; i <= n; i++) {
        cin >> v[1] >> v[2] >> v[3];
        for(int j = 1; j <= 3; j++)
            happiness_points[i][j] = max(happiness_points[i - 1][other(j) / 10], happiness_points[i - 1][other(j) % 10]) + v[j];
    }

    cout << max(happiness_points[n][1], max(happiness_points[n][2], happiness_points[n][3]));
    return 0;
}


Measured memory_bytes: 5188
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using static System.Math;

namespace CsharpSpiral {
    partial class Program {
        static void Main(string[] args) {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = true };
            Console.SetOut(sw);
            new Program().Solve(new ConsoleInput(Console.In, ' '));
            Console.Out.Flush();
        }
        public void Solve(ConsoleInput cin) {
            var dim = cin.ReadInt;
            var X = cin.ReadIntArray(dim);
            var Y = cin.ReadIntArray(dim);
            var D = X.Zip(Y, (xj, yj) => Abs(xj - yj));
            var norm1 = D.Sum(s => (double)s);
            var norm2 = Sqrt(D.Sum(s => Pow(s, 2)));
            var norm3 = Pow(D.Sum(s => Pow(s, 3)), 1.0 / 3);
            var normInf = D.Max();
            Console.WriteLine(norm1);
            Console.WriteLine(norm2);
            Console.WriteLine(norm3);
            Console.WriteLine(normInf);
        }
        
    }

    static class ExtendClass {
        public static void Swap<T>(this T[] X, int i, int j) {
            T tmp = X[i];
            X[i] = X[j];
            X[j] = tmp;
        }
        public static string Join<T>(this T[] X, string separator = " ") => string.Join(separator, X);
        public static S[] Clone<S>(this S[] src) where S : struct {
            var res = new S[src.Length];
            Array.Copy(src, res, src.Length);
            return res;
        }
    }

    class ConsoleInput {
        private readonly TextReader _stream;
        private readonly char _separator = ' ';
        private readonly Queue<string> inputStream;
        public ConsoleInput(TextReader stream, char separator = ' ') {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read {
            get {
                if(inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for(int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) {
            var ret = new string[N];
            for(long i = 0; i < N; ++i)
                ret[i] = Read;
            return ret;
        }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for(long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for(long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
        public double[] ReadDoubleArray(long N) { var ret = new double[N]; for(long i = 0; i < N; ++i) ret[i] = ReadDouble; return ret; }
    }
}



Measured memory_bytes: 20848
#include <algorithm>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <string>
#include <string.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define eps LDBL_EPSILON
#define moder 1000000007
#define int long long
#define ll long long
#define double long double
#define INF LLONG_MAX/3
#define P pair<int,int>
#define prique priority_queue<int,vector<int>,greater<int>>
using namespace std;
int n, v[25], c[25];
signed main(){
	cin >> n;
	rep(i, n)cin >> v[i];
	rep(i, n)cin >> c[i];
	int ans = 0;
	rep(i, ((ll)1 << n)) {
		int cnt = 0;
		int sum = 0;
		rep(j, n) {
			if ((i >> j) & 1) {
				cnt += v[j];
				sum += c[j];
			}
		}
		ans = max(ans, cnt - sum);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
n = int(input())
l = list(map(int,input().split()))
l.sort(reverse=True)
a = 0
b = 0
check = -1
for i in range(n-1):
  if l[i]==l[i+1]:
    if check != i:
      if a == 0:
        a = l[i]
        check = i+1
      elif b == 0:
        b = l[i]
print(a*b)
  
  


Measured memory_bytes: 14224
#include <cstdio>
#include <iostream>
#include <vector>

class Card {
    public:
        Card() {};
        char suit;
        int value;
};

void swap(Card* a, Card* b)
{
    Card tmp;
    tmp.suit = a->suit;
    tmp.value = a->value;
    a->suit = b->suit;
    a->value = b->value;
    b->suit = tmp.suit;
    b->value = tmp.value;
}

void do_bubble_sort(std::vector<Card>& data)
{
    for(int i = 0; i < data.size() - 1; i++) {
        for(int j = 0; j < data.size() - i - 1; j++) {
            if(data[j + 1].value < data[j].value) {
                swap(&data[j], &data[j + 1]);
            }
        }
    }
}

void do_selection_sort(std::vector<Card>& data)
{
    int min_index;
    for(int i = 0; i < data.size() - 1; i++) {
        min_index = i;
        for(int j = i + 1; j < data.size(); j++) {
            if(data[j].value < data[min_index].value) {
                min_index = j;
            }
        }
        if(min_index != i) {
            swap(&data[i], &data[min_index]);
        }
    }
}

void show_data(std::vector<Card>& data)
{
    printf("%c%d", data[0].suit, data[0].value);
    for(int i = 1; i < data.size(); i++) {
        printf(" %c%d", data[i].suit, data[i].value);
    }
    puts("");
}

bool is_accidentally_stable(std::vector<Card>& stable_data, std::vector<Card>& unstable_data)
{
    for(int i = 0; i < stable_data.size() && i < unstable_data.size(); i++) {
        if(stable_data[i].suit != unstable_data[i].suit) {
            return false;
        }
    }
    if(stable_data.size() == unstable_data.size()) {
        return true;
    } else {
        return false;
    }
}

int main()
{
    int input_size;
    std::cin >> input_size;
    std::vector<Card> data1(input_size);
    std::vector<Card> data2(data1.size());
    for(int i = 0; i < data1.size(); i++) {
        std::cin >> data1[i].suit >> data1[i].value;
    }
    std::copy(data1.begin(), data1.end(), data2.begin());

    do_bubble_sort(data1);
    do_selection_sort(data2);

    show_data(data1);
    puts("Stable");
    show_data(data2);
    if(is_accidentally_stable(data1, data2)) {
        puts("Stable");
    } else {
        puts("Not stable");
    }

    return 0;
}

Measured memory_bytes: 3208
#include <bits/stdc++.h>
#define For(i,a,b) for(int i=a;i<=b;i++)
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define int ll
#define INF (ll)(1e18)
using namespace std;
using ll=long long;
using pii=pair<int,int>;

int32_t main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n,k; cin>>n>>k;
	vector<int> v(n);
	for(auto &i:v) cin>>i;
	sort(all(v));
	int ans=0;
	for(int i=n-1;i>=n-k;i--) ans+=v[i];
	cout<<ans<<"\n";
	return 0;
}











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

int main() {
    int n, k; cin >> n >> k;
    vector<double> p(n);
    rep(i,n){
        int pi; cin >> pi;
        p[i] = (pi+1)/2.0;
    }
    vector<double> s(n);
    double si = 0;
    rep(i,n){
        si += p[i];
        s[i] = si;
    }
    double ans = s[k-1];
    rep(i,n-k){
        ans = max(ans,s[k+i]-s[i]);
    }
    cout << fixed << setprecision(10);
    cout << ans << endl;
}


Measured memory_bytes: 3328
macro_rules! read_line {
    () => {{
        let mut input = String::new();
        std::io::stdin().read_line(&mut input).unwrap();
        input
    }};
}

pub fn read_and_parse<T: std::str::FromStr>() -> T {
    read_line!().trim().parse().ok().unwrap()
}

pub fn read_line_to_string() -> String {
    read_line!().trim().to_owned()
}

use std::collections::HashMap;

fn main() {
    let n: usize = read_and_parse();
    let s: Vec<char> = read_line_to_string().chars().collect();
    let mut ans = 0;
    let mut mem: HashMap<char, Vec<usize>> = HashMap::new();
    mem.insert('R', Vec::new());
    mem.insert('G', Vec::new());
    mem.insert('B', Vec::new());

    for v in mem.values_mut() {
        v.resize(n+1, 0);
    }

    for i in (0..n).rev() {
        for (&c, v) in mem.iter_mut() {
            *v.get_mut(i).unwrap()
                = *v.get_mut(i+1).unwrap()
                    + if c == s[i] {1} else {0};
        }
    }

    for i in (0..n-2).rev() {
        'inner: for j in (i+1..n-1).rev() {
            if s[i] == s[j] {continue 'inner;}
            let another: char = "RGB".chars().filter(|&c| c != s[i] && c != s[j]).next().unwrap();
            ans += mem.get(&another).unwrap()[j+1];
            if 2*j - i < n {
                if s[2*j - i] == another {
                    ans -= 1;
                }
            }
        }
    }
    println!("{}", ans);
}

Measured memory_bytes: 2284
N, M = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for _ in range(M)]

A.sort()
BC.sort(key=lambda x: x[1],reverse=True)

ans = 0
cnt = 0
for i in BC:
  for _ in range(i[0]):
#    print(len(A), cnt)
    if A[cnt] < i[1]:
      ans += i[1]
    else:
      ans += A[cnt]
    cnt += 1
    if len(A) < cnt+1:
      print(ans)
      exit()
#    print(i, _, ans, cnt)
if cnt  < len(A):
  ans += sum(A[cnt - len(A):])

#print(A)
#print(BC)
print(ans)

Measured memory_bytes: 32964
lst=[]
A=int(input())
B=int(input())
C=int(input())
X=int(input())//50
for a in range(A+1):
    for b in range(B+1):
        for c in range(C+1):
            if 10*a+2*b+c==X:
                lst.append([a,b,c])
print(len(lst))


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

using namespace std;

int main() {
	int ch[3] = { 0 };
	string str;
	bool flg = true;
	
	cin >> str;
	for (int i = 0; i < 3; i++) {
		if (str[i] == 'a') {
			ch[0] = 1;
		}
		if (str[i] == 'b') {
			ch[1] = 1;
		}
		if (str[i] == 'c') {
			ch[2] = 1;
		}
	}
	for (auto c : ch) {
		if (c == 0) {
			flg = false;
		}
	}
	cout << ((flg) ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <numeric>
#include <algorithm>
#include <stack>
using namespace std;
 
int x, y, s;
int main() {
    while(1){
        string str; getline(cin, str);
        
        if(str == ".") break;
        stack<char> stk;
        int n=str.size();
        bool ok = true;
        for(int i=0; i<n; ++i){
            if(str[i]=='('||str[i]=='[') stk.push(str[i]);
            
            if(str[i]==')'){
                if(stk.empty()) ok = false;
                else if(stk.top()=='('){
                    stk.pop();
                }else{
                    ok = false;
                }
            }
            if(str[i]==']'){
                if(stk.empty()) ok = false;
                else if(stk.top()=='['){
                    stk.pop();
                }else{
                    ok = false;
                }
            }
            if(str[i]=='.'||str[i]==' ') continue;
            if(!ok) break;
        }
        if(!ok||!stk.empty()) cout << "no" << endl;
        else cout <<"yes" << endl;
    }
    return 0;
}


Measured memory_bytes: 3160
#include<stdio.h>
#include<algorithm>

using namespace std;

int main(){
	int n,a,b,c;
	int m=0;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		int a[3];
		for(int j=0;j<3;j++)scanf("%d",&a[j]);
		std::sort(a,a+3);
		
		int d = 50;
		if(a[0]>d || a[1]>d || a[2]>d)puts("hogehogehoge");
		
		if(a[0]*a[0]+a[1]*a[1] == a[2]*a[2]){
			puts("YES");
		}else{
			puts("NO");
		}
	}
}

Measured memory_bytes: 0
a = 5*[0]
for i in range(5):
    a[i] = int(input())

h = 0
time = 0
for i in a:
    b = i // 10
    c = i % 10
    if(c == 0): time += i
    else:
        time += (b+1)*10
        if(h < 10-c): h = 10-c

print(time-h)

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

int N, W;
vector<int> values, weights;

int dfs(int i, int W, vector< vector<int> > &memo) {
    if (i < 0) {
        return 0;
    }
    if (memo[i][W]) {
        return memo[i][W];
    }

    int res = 0;
    if (W < weights[i]) {
        res = dfs(i - 1, W, memo);
    } else {
        res = max(dfs(i - 1, W, memo), dfs(i - 1, W - weights[i], memo) + values[i]);
    }
    return memo[i][W] = res;
}

int main() {
    cin >> N >> W;
    values.resize(N), weights.resize(N);
    for (int i = 0; i < N; i++) {
        cin >> values[i] >> weights[i];
    }

    vector< vector<int> > memo(N + 1, vector<int>(W + 1));
    int res = dfs(N - 1, W, memo);

    cout << res << endl;
    return 0;
}


Measured memory_bytes: 6760
#include <stdio.h>

int main(void)
{
	int time;
	int hour, min, sec;
	scanf("%d", &time);
	sec = time % 60;
	time = (time - sec) / 60;
	min = time % 60;
	time = (time - min) / 60;
	hour = time;
	printf("%d:%d:%d\n", hour, min, sec);
} 

Measured memory_bytes: 1020
#include<bits/stdc++.h>
typedef long long     ll;
#define fr            first
#define sc            second
#define com(i,n)      for(int i=0;i<n;i++)
#define dom(i,n)      for(int i=1;i<=n;i++)
#define mom(i,n)      for(int i=n;i>=0;i--)
#define sortI(a,n)    sort(a,a+n)
#define sortD(a,n)    sort(a,a+n,greater<int>())
#define sortvi(a)     sort(a.begin(),a.end())
#define sortvd(a)     sort(a.begin(),a.end(),greater<int>())
#define sumall(a,x)   accumulate(a.begin(),a.end(),x)
#define pi            3.14159265358979323846264338327950
using namespace std;
int main()
{
     string s;
     cin>>s;
     com(i,s.size()-1)
     {
          if(s[i]=='?')
          {
               if(s[i-1]=='P' || s[i+1]=='P')
                    s[i]='D';
               else
                    s[i]='P';
          }
     }
     if(s[s.size()-1]=='?') s[s.size()-1]='D';
     cout << s << endl;
}


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

using namespace std;

string Date;
long long int DateInfo[5];

const int DaysOfMonth[] = {
	31,28,31,
	30,31,30,
	31,31,30,
	31,30,31,
};
const int MayaAcc[] = { 144000,7200,360,20,1 };


bool isLeapYear(long long int year) {
	if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) {
		return true;
	}
	return false;
}

void convertToMaya() {
	long long int total;

	total = -356;
	for (int year = 2012; year < DateInfo[0]; ++year) {
		total += 365;
		if (isLeapYear(year)) {
			++total;
		}
	}
	for (int i = 1; i < DateInfo[1]; ++i) {
		total += DaysOfMonth[i - 1];
	}
	total += DateInfo[2];

	if (isLeapYear(DateInfo[0]) && (DateInfo[1] > 2)) {
		++total;
	}
	//cout << "total:" << total << endl;
	if (total < 0) {
		total += 13 * 144000;
	}

	for (int i = 0; i < 5; ++i) {
		DateInfo[i] = 0;
		if (total / MayaAcc[i] > 0) {
			DateInfo[i] = total / MayaAcc[i];
		}
		total %= MayaAcc[i];
	}

	DateInfo[0] %= 13;
	for (int i = 0; i < 5; ++i) {
		cout << (i == 0 ? "" : ".") << DateInfo[i];
	}
	cout << endl;
}

void convertToAD() {
	long long int total;
	int nowYear, nowMonth;
	int y, m, d;

	total = 0;
	for (int i = 0; i < 5; ++i) {
		total += DateInfo[i] * MayaAcc[i];
	}
	//cout << "total:" << total << endl;

	y = 2012;
	m = 12;
	d = 21;
	while (total > 0) {
		//++d;
		if (m == 1 && d == 1) {
			nowYear = 365;
			if (isLeapYear(y)) {
				++nowYear;
			}
			if (total > nowYear) {
				total -= nowYear;
				++y;
				continue;
			}
		}
		nowMonth = DaysOfMonth[m - 1];
		if (m == 2) {
			if (isLeapYear(y)) {
				++nowMonth;
			}
		}
		if (d == nowMonth) {
			d = 0;
			++m;
			if (m == 13) {
				m = 1;
				++y;
			}
		}
		++d;
		--total;
	}

	cout << y << "." << m << "." << d << endl;
}

int getDateInfo() {
	int cnt;
	char c;
	stringstream ss;

	cnt = 0;
	ss.str(Date);
	while (ss >> DateInfo[cnt]) {
		ss.clear();
		ss >> c;
		ss.clear();
		++cnt;
	}

	return cnt;
}

int main() {
	int cnt;

	while (cin >> Date, Date[0] != '#') {
		cnt = getDateInfo();
		if (cnt == 3) {
			convertToMaya();
		}
		else if (cnt == 5) {
			convertToAD();
		}
	}

	return 0;
}



Measured memory_bytes: 3188
import sys
readline = sys.stdin.buffer.readline

n,m = map(int,readline().split())
lst1 = list(map(int,readline().split()))
"""
lst1の全要素に対して、
X = lst1[i]*(p+0.5)となるXの個数を求めよ
↓問題文を言い換えると
X=(lst1[i]//2)*(2p+1)を満たすXの個数を求めよ。
※プログラミングでは大体の場合整数に置き換えて考えたほうが良い

これを考慮すると、2p+1部分より、Xはlst1[i]//2の奇数倍である事がわかり、
・任意のiに対して、Xはlst1[i]//2の倍数である。
・任意のiに対して、Xが2で割り切れる回数とlst1[i]//2が2で割り切れる回数は等しい

これを満たさなかった場合、半公倍数は1つも存在しないことになる。
そうでない場合、答えはlst1全ての最小公倍数をTとして、
ans = (X-T)//(2*T)+1 #XはTの奇数倍である為
"""
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b,a%b)
def lcm(a,b):
    return (a//gcd(a,b)*b)

tmp = lst1[0]//2 #最初の要素は手計算しておく
con = 0

while True:
    if tmp%2==0:
        tmp //= 2
        con += 1
    else:
        break

x = 1 #最小公倍数の単位元は1

for i in range(n):
    lst1[i] //= 2 #全要素は偶数である

    x = lcm(lst1[i],x)

    tmp = lst1[i]
    cnt = 0
    while True:
        if tmp%2==0:
            tmp //= 2
            cnt += 1
        else:
            break
    if cnt != con: #2で割り切れる回数が全て等しい必要がある
        print(0)
        exit()

if m < x: #最初に出てくる半公倍数が制約mより大きいなら、条件を満たすXは存在しないので
    print(0)
else:
    print((m-x)//(2*x)+1) #条件を満たす半公倍数の数は、(制約-最小公倍数)//(最小公倍数*2)+1個

Measured memory_bytes: 58224