akhauriyash/Code-Regression huggingface dataset:
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <queue>
#define rg register
using namespace std;
typedef long long ll;
const int maxn=1000010;
template <typename Tp> inline int getmin(Tp &x,Tp y){return y<x?x=y,1:0;}
template <typename Tp> inline int getmax(Tp &x,Tp y){return y>x?x=y,1:0;}
template <typename Tp> inline void read(Tp &x)
{
    x=0;int f=0;char ch=getchar();
    while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
    if(ch=='-') f=1,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    if(f) x=-x;
}
struct data{int v,nxt;}edge[maxn<<1];
int n,m,p,rt,head[maxn],rem[maxn],bot[maxn],top[maxn];
queue<int> q;
inline void insert(int u,int v)
{
	edge[++p]=(data){v,head[u]};head[u]=p;
	edge[++p]=(data){u,head[v]};head[v]=p;
}
void input()
{
	int x,y;
	read(n);
	for(rg int i=1;i<n;i++)
	{
		read(x);read(y);
		insert(x,y);
	}
	read(m);
	memset(rem,0xff,sizeof(rem));
	for(rg int i=1;i<=m;i++)
	{
		read(x);read(top[x]);bot[x]=top[x];
		rem[x]=top[x]&1;q.push(x);
	}
}
void bfs()
{
	int x,b;
	while(!q.empty())
	{
		x=q.front();q.pop();
		for(int i=head[x];i;i=edge[i].nxt)
		{
			if(~rem[edge[i].v])
			{
				b=0;
				if(getmin(top[edge[i].v],top[x]+1)) b=1;
				if(getmax(bot[edge[i].v],bot[x]-1)) b=1;
				if(rem[edge[i].v]==rem[x]||top[edge[i].v]<bot[edge[i].v])
				  {puts("No");exit(0);}
				if(b) q.push(edge[i].v);
			}
			else
			{
				top[edge[i].v]=top[x]+1;bot[edge[i].v]=bot[x]-1;
				rem[edge[i].v]=rem[x]^1;
				q.push(edge[i].v);
			}
		}
	}
}
int main()
{
	input();
	bfs();
	puts("Yes");
	for(rg int i=1;i<=n;i++)
	  printf("%d\n",top[i]);
	return 0;
}

Measured memory_bytes: 16000
a,b,c=map(int,input().split())
a,b,c=sorted([a,b,c])
if (a+b+c)%2==1:
    if c%2==1:
        print((c*3-sum([a,b,c]))//2)
        exit()
    else:
        print((c*3+3-sum([a,b,c]))//2)
        exit()

else:
    if c%2==1:
        print((c*3+3-sum([a,b,c]))//2);exit()
    else:
        print((c*3-sum([a,b,c]))//2)
        exit()

Measured memory_bytes: 9224
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>

#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>

#include <cmath>
#include <numeric>
#include <random>
#include <cstring>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
#include <stack>

// type
#include <cstdint>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
#define P pair<ll, ll>

/* ---------- Constants  */
const double PI = 3.141592653589793238462643383279;
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;

char table[305][305];
int ans[305][305];

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */
signed main() {
    int H, W, K;
    cin >> H >> W >> K;
    int k = 0;
    for (int i = 0; i < H; i++) {
        string line;
        cin >> line;
        for (int j = 0; j < W; j++) {
            table[i][j] = line[j];
        }
    }

    bool empty = true;

    for (int i = 0; i < H; i++) {
        bool found = false;

        for (int j = 0; j < W; j++) {
            if (table[i][j] == '#') {
                ++k;
                ans[i][j] = k;

                if (!found) {
                    for (int p = j-1; p >= 0; p--) ans[i][p] = k;
                }

                found = true;
            } else {
                if (found) {
                    ans[i][j] = k;
                }
            }

            if (found) empty = false;
        }

        if (!found && !empty) {
            for (int j = 0; j < W; j++) {
                ans[i][j] = ans[i-1][j];
            }
        }
    }

    for (int i = H-1; i >= 0; i--) {
        if (ans[i][0] > 0) continue;
        for (int j = 0; j < W; j++) {
            ans[i][j] = ans[i+1][j];
        }
    }

    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            cout << ans[i][j];
            if (j != W-1) cout << " ";
        }
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 1536
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define INF 0x6fffffff
#define INFL 0x6fffffffffffffffLL

int main() {
	ll		a,b,c,d,i,j,k,n,m,x,y,ans = 0;
	string	s;

	cin >> n >> k;
	vector<ll>	dp(n+1);

	for(i=0;i<k;i++) {
		cin >> d;
		for(j=0;j<d;j++) {
			cin >> a;
			dp[a] = 1;
		}
	}
	for(i=1;i<=n;i++) {
		if (dp[i]==0) ans++;
	}

	cout << ans << endl;

}


Measured memory_bytes: 3636
object Main extends App {
  val NN = io.Source.stdin.getLines.toIndexedSeq.head.toInt
  private def func(i:Int):String={
    var t=i
    var str=""
    do{
      val rem = t%4
      val c = if(rem==1) "3" else if(rem==2) "5" else if(rem==3) "7" else "x"
      str = c + str
      t = t/4
    }while(t>0)
    str
  }
  private def check(s:String):Boolean={
    s.contains('3') && s.contains('5') && s.contains('7') //&& !s.contains('x')
  }  
  //println(NN)
  
  var ii=1
  var ret=0
  var n=0L
  do{
    val str = func(ii)
    if(!str.contains('x')){
      n = str.toLong
      if(n <= NN && check(str)){
        //println(str + "+")
        ret += 1
      } //else println(str)
    }
    ii += 1
  }while(n <= NN)

  println(ret)
}


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

typedef long long ll;

const int MAX_N = 1e5 + 5, MOD = 1e9 + 7;
int n, m;
string s;

int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> n >> s;
	for (int i = 0; i + 2 < s.size(); i++)
		m += s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C';

	cout << m << endl;
	return 0;
}

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

#define maxn 100005
#define inf (int) 2e9
#define ll long long
#define ii pair <int, int>
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define REP(i, a, b) for(int i = a; i >= b; i--)

int n, W;
int w[maxn], v[maxn];
ll f[maxn];

int main() {
    //freopen("main.inp", "r", stdin);
    cin >> n >> W;
    FOR(i, 1, n)
        cin >> w[i] >> v[i];
    FOR(i, 1, n)
        REP(j, W, w[i])
           f[j] = max(f[j], f[j - w[i]] + v[i]);
    cout << f[W];
}


Measured memory_bytes: 4392
#include <stdio.h>
#include <vector> 
#include <algorithm>
#include <functional>
#include <string>
#include <iostream>
#include <cmath>

using namespace std;

long long int input;
long long int kari;
int S[12];
int pl[12];
int co=0;
long long int S2[11];
long long int sum;


void henkan(int decimal){
	for(int z=0;z< 10;z++){
			pl[z]=0;
	}
	int i=0;
 while(decimal>0){
		pl[i] = decimal % 2;
		decimal = decimal / 2;
		i++;
	}	
}


int main(){
	cin >>input;
	kari=input;
	for(int i=0;i< std::to_string(input).length()-1;i++){
		S[i]=(kari%(int)pow(10,i+1))/(int)pow(10,i);
		kari-=kari%(int)pow(10,i+1);
		S2[i]=S[i];
	}
	S[std::to_string(input).length()-1]=kari/(int)pow(10,std::to_string(input).length()-1);
	S2[std::to_string(input).length()-1]=S[std::to_string(input).length()-1];
	for(int i=0;i< pow(2,to_string(input).length()-1);i++){
		henkan(i);		
		for(int i2=std::to_string(input).length()-2;i2>=0;i2--){
			if(pl[i2]==0){
				S2[i2]+=S2[i2+1]*10;
			//	printf("%d を足した",S2[i2]);
				co++;
			}
			else {
		//		printf("%d ",S2[i2+1]);
				sum+=S2[i2+1];
				co=0;
			}		
		}
		sum+=S2[0];
		for(int i3=0;i3< std::to_string(input).length();i3++){
			S2[i3]=S[i3];
		}
	}
	printf("%lld\n",sum);

return 0;
}


Measured memory_bytes: 512
#include <iostream>

using namespace std;

int main()
{
 int n;
 cin >> n;
 int *a = new int[n];
 for (int i = 0; i < n; i++)
 {
  cin >> a[i];
 }
 for (int i = n - 1; i > 0; i--)
 {
  cout << a[i] << " ";
 }
 cout << a[0] << endl;
}
  


Measured memory_bytes: 3100
#include<stdio.h>
#include<string.h>

char s[11],t[11],u[11];
int a,b;

int main(){
  scanf("%s%s%d%d%s",s,t,&a,&b,u);
  if(strcmp(s,u))printf("%d %d",a,b-1);
  else printf("%d %d",a-1,b);
  return 0;
}

Measured memory_bytes: 128
import java.util.*;
import java.io.*;
import java.util.function.*;

class Main {
    static Scanner scanner = new Scanner();
    static int mod = 1000000007;
    static int inf = 0x7ffffff;

    void solve() {
        int n = scanner.nextInt();
        char[] s = scanner.next().toCharArray();
        for (int i = 0; i < s.length; i++) {
            s[i] = (char)((s[i] - 'A' + n) % 26 + 'A');
        }
        System.out.println(s);
    }

    public static void main(String[]$) throws Exception {
        new Main().solve();
        System.out.flush();
    }
}

class System {
    static PrintWriter out = new PrintWriter(java.lang.System.out);

    static void exit() {
        java.lang.System.exit(0);
    }
}

class Scanner {
    private BufferedReader reader = new BufferedReader(new InputStreamReader(java.lang.System.in), 0x10000);
    private StringTokenizer tokenizer;

    String next() {
        try {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                tokenizer = new StringTokenizer(reader.readLine());
            }
        } catch (IOException ignored) {
        }
        return tokenizer.nextToken();
    }

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

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

    char[][] nextCharArray(int n, int m) {
        char[][] a = new char[n][m];
        for (int i = 0; i < n; i++) {
            a[i] = next().toCharArray();
        }
        return a;
    }

    int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = nextInt();
        }
        return a;
    }

    int[] nextIntArray(int n, IntUnaryOperator op) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = op.applyAsInt(nextInt());
        }
        return a;
    }

    long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++) {
            a[i] = nextLong();
        }
        return a;
    }

    long[] nextLongArray(int n, LongUnaryOperator op) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++) {
            a[i] = op.applyAsLong(nextLong());
        }
        return a;
    }
}


Measured memory_bytes: 21588
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define endl '\n'
#define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const int maxn=2*1e5+5;
bool vis[maxn];
int main()
{
    FAST
    ll a,b,c;
    cin>>a>>b>>c;
     cout<<max((ll)0,a-c)<<" ";
     c-=a;
     if(c<=0)
        return cout<<b,0;
     cout<<max((ll)0,b-c)<<endl;



    return 0;
}


Measured memory_bytes: 256
# D - Banned K
from collections import Counter


def main():
    N, *A = map(int, open(0).read().split())
    counter = Counter(A)
    patterns, less_patterns = {}, {}
    for k, v in counter.items():
        patterns[k] = max(0, v * (v - 1) // 2)
        less_patterns[k] = max(0, (v - 1) * (v - 2) // 2)
    total = sum(patterns.values())
    ans = [total - patterns[a] + less_patterns[a] for a in A]
    print("\n".join(map(str, ans)))


if __name__ == "__main__":
    main()


Measured memory_bytes: 52756
import std.stdio, std.string, std.range, std.conv, std.array, std.algorithm, std.math, std.typecons;

void main() {
    const tmp = readln.split.to!(long[]).sort!((a,b) => a < b).array;
    const K = readln.chomp.to!long;
    writeln(tmp[0] + tmp[1] + tmp[2] * 2^^K);
}



Measured memory_bytes: 256
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline void rd(char &c){
  int i;
  for(;;){
    i = getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c = i;
}
inline int rd(char c[]){
  int i;
  int sz = 0;
  for(;;){
    i = getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c[sz++] = i;
  for(;;){
    i = getchar_unlocked();
    if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF){
      break;
    }
    c[sz++] = i;
  }
  c[sz]='\0';
  return sz;
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(const char c[]){
  int i=0;
  for(i=0;c[i]!='\0';i++){
    putchar_unlocked(c[i]);
  }
}
char c;
int main(){
  rd(c);
  c++;
  wt_L(c);
  wt_L('\n');
  return 0;
}
// cLay varsion 20200112-1

// --- original code ---
// char c;
// {
//   rd(c);
//   c++;
//   wt(c);
// }


Measured memory_bytes: 256
using System;

namespace Atc_0019
{
    class Program
    {
        static void Main(string[] args)
        {
            string str = Console.ReadLine();
            int A = int.Parse(str.Split(' ')[0]);
            int B = int.Parse(str.Split(' ')[1]);
            Console.WriteLine(A * B);
        }
    }
}


Measured memory_bytes: 27468
#include <bits/stdc++.h>
#define rep(i,n) for(long long i=0; i<n; i++)
#define Rep(i,n) for(long long i=1; i<n; i++)
#define ll long long
#include <math.h>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <set>
#include <vector>


using namespace std;
#define PI acos(-1)
using P =pair<int,int>;

int main(){
    ll n;
    cin>>n;
    map<string,ll> s;
    rep(i,n){
        string a;
        cin>>a;
        s[a]++;
    }
    ll mn=0;
    for(auto p:s)mn=max(mn,p.second);
    for(auto p:s){
        if(p.second==mn)cout<<p.first<<endl;
    }
    }


Measured memory_bytes: 19232
#include <iostream>
#include <fstream>
#include <string>
#include <unordered_map>
#include <stdio.h>
#include <list>
#include <vector>
#include <algorithm>
#include <stack>
#include <climits>
#include <cmath>
#include <map>
#include <queue>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

int main()
{
	ll l,r;
	cin >> l >>r;
	r=min(l+2019,r);
	//cout<<r<<endl;
	ll ans = 2019;
	for(ll i = l ; i < r; ++i)
	{
		for(ll j=l+1;j <= r;++j)
		{
			ans = min((1LL)*ans, (1LL)*(j*i)%2019);
		}
	}
	cout << ans << endl;
	return 0;
}


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

using namespace std;

#define YES cout << "YES" << endl;
#define NO  cout << "NO"  << endl;
#define Yes cout << "Yes" << endl;
#define No  cout << "No"  << endl;
 
#define INF INT_MAX
#define MOD 1000000007
#define PI  acos(-1)

using ll  = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rrep(i, n) for (ll i = (n)-1; i >= 0; i--)

int main(int argc, char *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    string S;
    cin >> S;

    ll ans = 0;
    rep (i, 4) {
        if (S[i] == '2') {
            ans++;
        }
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define pi 3.141592653589793238
#define int long long
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;


bool comp(pair<int,int>a,pair<int,int>b)
{
    long double x=(a.second*1.0)/a.first;
    long double y=(b.second*1.0)/b.first;
    return (x>y);
}
vector<int> pp[6];
int pre[100][6];

signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);  
cout.tie(0);   

#ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
    freopen ("INPUT.txt" , "r" , stdin);
    freopen ("OUTPUT.txt" , "w" , stdout);
    }
#endif  

    int n,w;
    cin>>n>>w;
    pair<int,int>p[n+1];
    int mn=1e10;
    for(int i=1;i<=n;i++)
    {
        cin>>p[i].first>>p[i].second;        
        mn=min(mn,p[i].first);
    }
    sort(p+1,p+n+1,comp);
    for(int i=1;i<=n;i++)
    {
        pp[p[i].first-mn].push_back(p[i].second);
    }

    for(int i=0;i<4;i++)
    {
        int sz=pp[i].size();
        for(int j=0;j<sz;j++)
        {
            pre[j+1][i]=pre[j][i]+pp[i][j];
        }
    }

    int mx=0;
    for(int i=0;i<=pp[0].size();i++)
        for(int j=0;j<=pp[1].size();j++)
            for(int k=0;k<=pp[2].size();k++)
                for(int l=0;l<=pp[3].size();l++)
                {
                    int sum=i*(mn)+j*(mn+1)+k*(mn+2)+l*(mn+3);
                    if(sum<=w)
                    {
                        mx=max(mx,pre[i][0]+pre[j][1]+pre[k][2]+pre[l][3]);
                    }
                }

    cout<<mx;
} 


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
const ll INF=1e18;
const int MOD=1e9+7;
const double pi=acos(-1);

int main(){
  ll h,w;
  cin >> h >> w;
  ll vec[h][w]={};
  rep(i,h){
    rep(j,w){
      cin >> vec[i][j];
    }
  }
  ll ans[h*w][4]={};
  ll cnt=0;
  rep(i,h){
    rep(j,w){
      if(i%2==0){
        ll num=vec[i][j];
        if(num%2==0)continue;
        else{
          if(j!=w-1){
            cnt++;
            vec[i][j]--;
            vec[i][j+1]++;
            ans[cnt-1][0]=i+1;
            ans[cnt-1][1]=j+1;
            ans[cnt-1][2]=i+1;
            ans[cnt-1][3]=j+2;
          }
          else{
            if(i==h-1)break;
            cnt++;
            vec[i][j]--;
            vec[i+1][j]++;
            ans[cnt-1][0]=i+1;
            ans[cnt-1][1]=j+1;
            ans[cnt-1][2]=i+2;
            ans[cnt-1][3]=j+1;
          }
        }
      }
      else{
        ll num=vec[i][w-1-j];
        if(num%2==0)continue;
        else{
          if(j!=w-1){
            cnt++;
            vec[i][w-1-j]--;
            vec[i][w-1-j-1]++;
            ans[cnt-1][0]=i+1;
            ans[cnt-1][1]=w-j;
            ans[cnt-1][2]=i+1;
            ans[cnt-1][3]=w-1-j;
          }
          else{
            if(i==h-1)break;
            cnt++;
            vec[i][w-1-j]--;
            vec[i+1][w-1-j]++;
            ans[cnt-1][0]=i+1;
            ans[cnt-1][1]=w-j;
            ans[cnt-1][2]=i+2;
            ans[cnt-1][3]=w-j;
          }
        }
      }
    }
  }
  cout << cnt << endl;
  rep(i,cnt){
    rep(j,4){
      if(j!=0)cout<<" ";
      cout << ans[i][j];
    }
    cout << endl;
  }
  return 0;
}


Measured memory_bytes: 11904
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <tuple>
using namespace std;
const int INF = (int)1e9 + 7;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

template<class T>
vector<T> make_v(size_t size, const T &init) {
    return vector<T>(size, init);
}
template<class... Ts>
auto make_v(size_t size, Ts... rest) {
    return vector<decltype(make_v(rest...))>(size, make_v(rest...));
}

int main() {
    int w, h;
    while (cin >> w >> h, w) {
        vector<vector<int>> field(h, vector<int>(w));
        vector<pair<int, int>> starts, goals;
        for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) {
            char c; cin >> c;
            int time = 0;
            if (c == 'X') time = -1;
            else if (c == 'S') starts.emplace_back(i, j);
            else if (c == 'T') goals.emplace_back(i, j);
            else time = c - '0';
            field[i][j] = time;
        }
        auto dist = make_v(h, w, 2, INF);
        using P = tuple<int, int, int, int>;
        priority_queue<P, vector<P>, greater<P>> que;
        for (auto &p: starts) for (bool b: {true, false}) {
            dist[p.first][p.second][b] = 0;
            que.emplace(0, p.first, p.second, b);
        }
        while (!que.empty()) {
            int d, i, j, b; tie(d, i, j, b) = que.top(); que.pop();
            if (dist[i][j][b] < d) continue;
            for (int di = -2; di <= 2; di++) for (int dj = 1; dj <= 3; dj++) {
                if (abs(di) + dj > 3) continue;
                int ni = i + di, nj = j + (b ? dj : -dj);
                if (ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
                if (field[ni][nj] == -1) continue;
                if (chmin(dist[ni][nj][!b], d + field[ni][nj])) {
                    que.emplace(dist[ni][nj][!b], ni, nj, !b);
                }
            }
        }
        int ans = INF;
        for (auto &p: goals) for (bool b: {true, false}) {
            chmin(ans, dist[p.first][p.second][b]);
        }
        if (ans == INF) ans = -1;
        cout << ans << endl;
    }
    return 0;
}



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

#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define for1(i, a, b) for (int i = (int)a; i < (int)(b); ++i)
#define rfor1(i, a, b) for (int i=(int)b-1;i>=(int)a;i--)
#define for2(i, a, b) for (int i = (int)a; i <= (int)(b); ++i)
#define for3(i, a, b) for (int i = (int)a; i < (int)(b); i=i+2)
#define for4(i, a, b) for (int i = (int)a; i <= (int)(b); i=i+2)
#define tc(t) int t; cin>>t; while(t--)
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a, b;
    cin >> a >> b;
    if (a >= 1 && a <= 9 && b >= 1 && b <= 9) {
        cout << a * b << endl;
    } else {
        cout << "-1" << endl;
    }
}






Measured memory_bytes: 3468
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		String T = scan.next();
		String[] array = T.split("");

		for (int i = 0; i < array.length; i++) {
			if (array[i].equals("?")) {

					array[i] = "D";
				}

		}
		System.out.println(String.join("",array));

	}
}


Measured memory_bytes: 65884
#include <iostream>
#include <cstring>
#include <string>
 
using namespace std;
 
string sa,sb;
int a[501],b[501];
int m,mod=10000;
int dp[502][501][10][4][2];
 
int solve(int d[],int sz,bool low){
    memset(dp,0,sizeof(dp));
    dp[0][0][0][0][0]=1;
    for(int i=0;i<sz;++i){
        for(int j=0;j<m;++j){
            for (int k=0;k<10;++k){
                for(int l=0;l<4;++l){
                    for(int p=0;p<2;++p){
                        int lim=p?9:d[i];
                        for(int q=0;q<=lim;++q){
                            if(l==0)(dp[i+1][q%m][q][q!=0][p||q<lim] +=dp[i][j][k][l][p])%=mod;
                            else if(l==1&&q!=k)(dp[i+1][(j*10+q)%m][q][q<k?2:3][p||q<lim] +=dp[i][j][k][l][p])%=mod;
                            else if(l==2&&q>k)(dp[i+1][(j*10+q)%m][q][3][p||q<lim] +=dp[i][j][k][l][p])%=mod;
                            else if(l==3&&q<k)(dp[i+1][(j*10+q)%m][q][2][p||q<lim] +=dp[i][j][k][l][p])%=mod;
                        }
                    }
                }
            }
        }
    }
    int res=0;
    for(int i=0;i<10;++i){
        for(int j=0;j<4;++j){
            for(int k=0;k<2;++k){
                if(low&&k==0) continue;
                (res += dp[sz][0][i][j][k])%=mod;
            }
        }
    }
    return res;
}
 
int main(){
    cin>>sa>>sb>>m;
    for(int i=0;i<sb.size();++i) b[i]=sb[i]-'0';
    for(int i=0;i<sa.size();++i) a[i]=sa[i]-'0';
    cout<<(solve(b,sb.size(),false)-solve(a,sa.size(),true)+mod)%mod<<endl;
    return 0;
}

Measured memory_bytes: 81756
(defun solve (balls1 balls2 a b u)
  (if (equal u balls1)
      (list (1- a) b)
      (list a (1- b))))

#-swank
(let* ((balls (read-line))
       (a (read))
       (b (read))
       (u (read-line))
       (balls1 (subseq balls 0 (position #\Space balls)))
       (balls2 (subseq balls (1+ (position #\Space balls)))))
  (format t "~{~A~^ ~}~%" (solve balls1 balls2 a b u)))


Measured memory_bytes: 12900
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int[] a=new int[3];
		for(int i=0;i<3;i++)
		{
			a[i]=scan.nextInt();
		}
		System.out.print(a[a.length-1]+" ");
		for(int i=0;i<3-1;i++)
		{
			System.out.print(a[i]+" ");
		}
		

	}

}


Measured memory_bytes: 27032
#include <bits/stdc++.h>
#define case(t) printf("Case #%d: ", (t))
#define pii pair<int, int>
#define vii vector<pii>
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define f first
#define s second
typedef long long ll;
const double pi = acos(-1);
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const int MAXN = 1e5 + 5;
const double eps = 1e-9;
using namespace std;
char tmp[MAXN];
 
int main()
{
    int a, b, c, d;
    scanf("%d %d %d %d", &a, &b, &c, &d);
    int l = a + b;
    int r = c + d;
    if (l < r) printf("Right\n");
    else if (l > r) printf("Left\n");
    else printf("Balanced\n");
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#define r(i,n) for(int i=0;i<n;i++)

using namespace std;



int main(){
    long long n,a=2,b=1,c;      	
  	//cin>>n;
  	scanf("%lld",&n);

    if(n==0)cout<<a<<endl;
    else if(n==1)cout<<b<<endl;
    else{
        for(int i=2;i<=n;i++){
            c=a+b;
          //cout<<c<<endl;
            if(i==n){cout<<c<<endl;break;}
            a=b;b=c;
        }
        
        

    }


    return 0;
}



Measured memory_bytes: 256
#!/usr/bin/python3
# -*- coding: utf-8 -*-
n, k, s = map(int, input().split())
if s == 10**9:
    for i in range(0, n):
        if i < k:
            print(s, end=" ")
        else:
            print(s - 1, end=" ")
else:
    for i in range(0, n):
        if i < k:
            print(s, end=" ")
        else:
            print(10**9, end=" ")

Measured memory_bytes: 4340
n, k = map(int, input().split())
p = list(map(int, input().split()))
add = [None]*(n-k+1)
add[0] = sum(p[:k])

for i in range(n-k):
    add[i+1] = add[i] - p[i] + p[i+k]

print((max(add)+k)/2)


Measured memory_bytes: 25060
#include<bits/stdc++.h>
#include<tr1/unordered_map>
#define pb push_back
#define pii pair<int,int>
#define SZ(x) (int)x.size()
#define mem(a,b) memset(a,b,sizeof(a))
#define  For(i,a,b) for(int i=a,i##E=b;i<=i##E;++i)
#define rFor(i,a,b) for(int i=a,i##E=b;i>=i##E;--i)
typedef long long LL;
using namespace std;
const int N=100010;
template<typename T>inline bool chkmin(T &a,const T &b){return a>b?a=b,1:0;}
template<typename T>inline bool chkmax(T &a,const T &b){return a<b?a=b,1:0;}
template<typename T>inline void read(T &x)
{
	x=0;int _f(0);char ch=getchar();
	while(!isdigit(ch))_f|=(ch=='-'),ch=getchar();
	while( isdigit(ch))x=x*10+ch-'0',ch=getchar();
	x=_f?-x:x;
}
inline void file()
{
#ifdef ztzshiwo
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
#endif
}
int a[N],n,ans;
int main()
{
	int x;
	file();
	read(n);
	For(i,1,n)read(a[i]);
	int flag=0;
	For(i,1,n+1)
	{
		if(a[i]==i)
		{
			if(flag)
				flag=0,ans++;
			else
				flag=1;
		}
		else
		if(flag)flag=0,ans++;
	}
	printf("%d\n",ans);
	return 0;
}


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

int main()
{
    long long n;
    cin >> n;
    if (n % 2 == 1)
    {
        cout << 0 << endl;
        return 0;
    }
    long long ans = 0;
    long long x = 2;
    while (1)
    {
        x *= 5;
        if (x > n)
            break;
        ans += (n / x);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
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);}
int abs(int x){return x>0?x:-x;}
 
//const int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
//const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main()
{
	int n;
	cin >> n;
	int a;
	map<int, int> mp;

	REP(i, n){
		cin >> a;
		mp[a-1]++;
		mp[a]++;
		mp[a+1]++;
	}

	int ans = 0;
	for (auto x : mp){
		if (x.second > ans) ans = x.second;
	}

	cout << ans << endl;
}


Measured memory_bytes: 4736
#include <stdio.h>

int main(void)
{
    int a,b;
    int product;

    scanf("%d %d", &a, &b);
    product = a * b;

    if( (product%2) == 0 ){
        printf("Even\n");
    }
    else{
        printf("Odd\n");
    }
}

Measured memory_bytes: 128
#include <cstdio>
#include <cstdlib>

using namespace std;
const int Max_N(100050);
typedef long long int LL;

template<typename Type>
void Get_Val(Type &Ret)
{
	Ret = 0;
	char ch;
	while (ch = getchar(), ch > '9' || ch < '0')
		;
	do
	{
		(Ret *= 10) += ch - '0';
	}
	while (ch = getchar(), ch >= '0' && ch <= '9');
}

int N, root, Head[Max_N], Total, To[Max_N << 1], Next[Max_N << 1], Deg[Max_N];
LL A[Max_N];

inline void Add_Edge(const int &s, const int &t)
{
	++Total, To[Total] = t, Next[Total] = Head[s], Head[s] = Total;
}

void init()
{
	Get_Val(N);
	for (int i = 1;i <= N;++i)
		Get_Val(A[i]);
	for (int i = 1, u, v;i != N;++i)
		Get_Val(u), Get_Val(v), Add_Edge(u, v), Add_Edge(v, u), ++Deg[u], ++Deg[v];
	for (int i = 1;i <= N;++i)
		if (Deg[i] > 1)
			root = i;
}

inline void GG()
{
	puts("NO"), exit(0);
}

/*
首先选择一个不是叶子的点root作为根 
考虑从下往上处理。那么考虑一个点u和它儿子时，它的每个儿子都会伸出一些的路径，期望在上面得到匹配
设u的儿子总共伸出了Sum条路径，假设当前点的权值是v。设有x(0 <= 2x <= Sum)对路径是在u处得到匹配，有(Sum - 2x) + x = v，同时u会向上伸出Sum - 2x条路径
x是固定的可以直接解出。现在问题转化成，从每个儿子处选一些向上走的路径、总共选Sum - 2x条，使得剩下的路径可以两两匹配
这是一个经典问题。具体而言是：有n个集合，每个集合中有若干个点，判断能否让这些点两两匹配，使得匹配的点对不在同一个集合中
可以证明，当2 * Max <= Sum且Sum是偶数时能存在这样的匹配。必要性显然，充分性可以考虑去掉一个最大值后构造
贪心判定能否使得Max <= floor(Sum / 2)即可，这里Sum = 2x 
*/

void dfs(const int &u, const int &fa)
{
	if (Deg[u] == 1)
		return;
	LL Sum(0LL), X;
	for(int i = Head[u], v;i;i = Next[i])
		if ((v = To[i]) != fa)
			dfs(v, u), Sum += A[v];
	X = Sum - A[u];
	if (!(0LL <= 2LL * X && 2LL * X <= Sum))
		GG();
	LL need(0LL);
	for (int i = Head[u], v;i;i = Next[i])
		if ((v = To[i]) != fa)
			if (A[v] > X)
				need += A[v] - X;
	if (need > (A[u] = Sum - 2LL * X))
		GG();
}

void work()
{
	dfs(root, -1);
	puts(A[root] ? "NO" : "YES");
}

int main()
{
	init();
	if (root)
		work();
	else
		puts(A[1] == A[2] ? "YES" : "NO");
	return 0;
}

Measured memory_bytes: 8960
#include <bits/stdc++.h>
#define rep(i,x,n) for(int i=x; i<(int)(n); i++)
#define rep_eq(i,x,n) for(int i=x; i<=(int)(n); i++)
using namespace std;

using ll=long long;

int main() {
  int X,Y; cin >>X >>Y;
  string ans="No";
  rep_eq(i,0,X) {
    int j=X-i;
    if (i*2+j*4==Y) {
      ans="Yes";
      break;
    }
  }
  cout <<ans <<endl;
  return 0;
}


Measured memory_bytes: 3620
#include <stdio.h>
typedef long long ll;
using namespace std;

int main(void) {
  int i, j, k, n, m, x, y, ans = 0;
  scanf("%d%d", &n, &m);
  int p[n], u[n];
  for(i = 0; i < n; ++i) scanf("%d", &p[i]);
  for(i = 0; i < n; ++i) u[i] = i;
  for(i = 0; i < m; ++i) {
    scanf("%d%d", &x, &y);
    x--, y--;
    int rx = 0, ry = 0, nx = x, ny = y;
    while(nx != u[nx]) nx = u[nx], rx++;
    while(ny != u[ny]) ny = u[ny], ry++;
    if(rx < ry) u[nx] = ny;
    else u[ny] = nx;
  }
  for(i = 0; i < n; ++i) {
    int t = i;
    while(t != u[t]) t = u[t];
    u[i] = t;
  }
  for(i = 0; i < n; ++i) if(u[p[i] - 1] == u[i]) ++ans;
  printf("%d", ans);
  return 0;
}

Measured memory_bytes: 896
#include <stdio.h>
int main(void){
  int ans=0;
  long n,i=1,a,b,e=1;
  scanf("%ld",&n);
  while (i*i<=n){
    if (n%i==0) a=i;
    i++;
  }
  b=n/a;
  while (e<=b){
    e*=10;
    ans++;
  }
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 128
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int n = scanner.nextInt();
    int m = scanner.nextInt();
    int[] k = new int[n];
    BitSet all = new BitSet(m);
    all.flip(0, m);
    for (int i = 1; i <= n; i++) {
      k[i - 1] = scanner.nextInt();
      BitSet a = new BitSet();
      for (int j = 1; j <= k[i - 1]; j++) {
        a.set(scanner.nextInt() - 1);
      }
      all.and(a);
    }
    System.out.println(all.cardinality());
  }
}

Measured memory_bytes: 24020
n,l=map(int,input().split())
arr=[0]*n
for i in range(n):
  arr[i]=l+i+1-1
s=sum(arr)
ans=0
diff=10**10
for i in range(n):
  tmp=arr[:i]+arr[i+1:]
  tmps=sum(tmp)
  if diff>abs(s-tmps):
    ans=tmps
    diff=abs(s-tmps)
print(ans)

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

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>

#include <bits/stdc++.h>
#include <cmath>
#include <limits>

using namespace std;
typedef long long LL;

long long N;
long long v[100000+2] = {0};

map<long long, int> mpodd;
map<long long, int> mpeven;

int main(int argc, char* argv[]){
	cin.tie(0);
	ios::sync_with_stdio(false);

	cin >> N;
	for(int i=1; i<=N; i++){
		cin >> v[i];
	}
	for(int i=1; i<=N; i++){
		if((i % 2) == 1){
			if(mpodd.count(v[i]) == 0){
				mpodd[v[i]] = 1;
			}
			else{
				mpodd[v[i]]++;
			}
		}
		else{
			if(mpeven.count(v[i]) == 0){
				mpeven[v[i]] = 1;
			}
			else{
				mpeven[v[i]]++;
			}
		}
	}
	int odd_max = 0, even_max = 0;
	long long odd_key = 0, even_key = 0;
	vector<int> vo, ve;
	for(auto itr = mpodd.begin(); itr != mpodd.end(); itr++){
		long long key = itr->first;
		int val = itr->second;
		vo.push_back(val);
		if(odd_max < val){
			odd_key = key;
			odd_max = val;
		}
	}
	for(auto itr = mpeven.begin(); itr != mpeven.end(); itr++){
		long long key = itr->first;
		int val = itr->second;
		ve.push_back(val);
		if(even_max < val){
			even_key = key;
			even_max = val;
		}
	}

	sort(vo.begin(), vo.end());
	sort(ve.begin(), ve.end());

	int ans = 0;
	int osz = (int)vo.size();
	int esz = (int)ve.size();
	int o1, o2, e1, e2;
	o1 = vo[osz-1], e1 = ve[esz-1];
	if(osz == 1){
		o2 = 0;
	}
	else{
		o2 = vo[osz-2];
	}
	if(esz == 1){
		e2 = 0;
	}
	else{
		e2 = ve[esz-2];
	}
	int a1, a2, a3, a4;
	if(odd_key == even_key){
		a1 = (N/2) - o1 + (N/2) - e2;
		a2 = (N/2) - o2 + (N/2) - e1;
		ans = min(a1, a2);
	}
	else{
		ans = (N/2) - odd_max;
		ans += ((N/2) - even_max);
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 7936
import math , sys, bisect

N , M , K = list( map( int , input().split() ))
A = list( map( int , input().split() ))
B = list( map( int , input().split() ))
if N > M:
    N , M = M , N
    A, B = B , A

Asum=[0]
Bsum=[]
if A[0] > K and B[0] > K:
    print(0)
    sys.exit()

for i in range(N):
    if i ==0:
        tot = A[i]
    else:
        tot += A[i]
    Asum.append(tot)

for i in range(M):
    if i ==0:
        tot = B[i]
    else:
        tot += B[i]
    Bsum.append(tot)

#ans=bisect.bisect(Bsum,K)
ans=0
for i in range(N+1):
    tot = Asum[i]
    if tot > K:
        print(ans)
        sys.exit()
    num = bisect.bisect(Bsum,K-tot)
    if i + num >ans:
        ans=i+num
print(ans)

Measured memory_bytes: 132776
#include<bits/stdc++.h>
#define PI 3.141592653589793238462
using namespace std;
typedef long long ll;
typedef long double db;
int main(){
    ll d,t,s;cin>>d>>t>>s;
    if(t*s>=d) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
} 

Measured memory_bytes: 3668
n,k=gets.split.map &:to_i
a=$<.map{|e|e.split.map &:to_i}.sort_by{|e|-e[1]}
s=r=f=0
c=[0]*-~n
f=0
l=[]
i=k-1
a.each{|m,v|
	if l.size>=k
        next if c[m]>0
		i=i.downto(0).find{|j|c[l[j][0]]>1}
		break if !i
		s-=l[i][1]
		c[l[i][0]]-=1
		l.delete_at(i)
	end
	s+=v
    f+=1 if c[m]==0
	c[m]+=1
	l<< [m,v]
	r=[r,s+f**2].max
}
p r

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

int main(){
    int flag;
    int a,b,c;
    int ans=0;

    cin >>a>>b>>c;
    
    if(a+b >= c)flag=1;
    else flag=0;

    //cout << ans <<endl;
    //cout <<fixed<<setprecision(16)<< ans <<endl;

    if(flag==1)cout << "Yes" <<endl;
    else cout << "No" <<endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm> // algorithm header is required at AOJ
using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)

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

    int n;
    cin >> n;
    char kind;
    int rank;
    vector<int> cards;

    int c = 0;
    while (c < n && cin >> kind >> rank)
    {
        switch (kind)
        {
        case 'S':
            cards.push_back(rank);
            break;
        case 'H':
            cards.push_back(rank + 13);
            break;
        case 'C':
            cards.push_back(rank + 26);
            break;
        case 'D':
            cards.push_back(rank + 39);
            break;
        }
    }
    sort(cards.begin(), cards.end());

    int current_count = 1;
    int index = 0;
    vector<int> missing_cards;

    while (current_count < 53)
    {
        if (index > cards.size() - 1)
        {
            missing_cards.push_back(current_count);
            current_count += 1;
            continue;
        }

        if (cards[index] != current_count)
        {
            missing_cards.push_back(current_count);
        }
        else
        {
            ++index;
        }
        ++current_count;
    }

    // printf("nya-n: %lu\n", missing_cards.size());

    if (missing_cards.size() == 0)
    {
        return 0;
    }
    else
    {
        int rank;
        int adjust = 0;
        REP(i, missing_cards.size())
        {
            if (missing_cards[i] % 13 == 0)
            {
                rank = 13;
                adjust = -1;
            }
            else
            {
                rank = missing_cards[i] % 13;
                adjust = 0;
            }

            switch (missing_cards[i] / 13 + adjust)
            {
            case 0:
                cout << "S " << rank << endl;
                break;
            case 1:
                cout << "H " << rank << endl;
                break;
            case 2:
                cout << "C " << rank << endl;
                break;
            case 3:
                cout << "D " << rank << endl;
                break;
            case 4:
                cout << "D " << rank << endl;
            }
        }
    }

    return 0;
}


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

using namespace std;
using ll = unsigned long long;
ll mo=1e9+7;
string s;
vector<pair<string,string>> query(200100);
int n,q;
bool outL(int cur){
    if(cur >= n)return false;
    
    for(int i=0;i<q;++i){
        if(s[cur] == query[i].first[0]){
            if(query[i].second == "R") cur++;
            else cur--;
        }
        if(cur < 0)return true;
        if(cur >= n) return false;
    }
    return false;
}
bool outR(int cur){
    if(cur < 0)return false;
    
    for(int i=0;i<q;++i){
        if(s[cur] == query[i].first[0]){
            if(query[i].second == "R") cur++;
            else cur--;
        }
        if(cur >= n)return true;
        if(cur < 0) return false;
    }
    return false;
}
int main() {
    cin>>n>>q;
    cin>>s;
    for(int i=0;i<q;++i){
        cin>>query[i].first>>query[i].second;
    }
    int l=-1;
    for(int i=20;i>=0;i--)if(outL(l+(1<<i)))l+=(1<<i);
    int r = n+1;
    for(int i=20;i>=0;i--)if(outR(r-(1<<i)))r-=(1<<i);
    
    cout << r - l -1 << endl;
    return 0;
}



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

long long int gcd(long long int x, long long int y)
{
	if (y == 0) { return x; }
	return gcd(y, x % y);
}

int main(void)
{
	long long int n, k,n2;
	cin >> n >> k;
	if (n == 0 || k == 1) { cout << 0 << "\n"; }
	else {
		n2 = n % k;
		if (abs(n2 - k) < n2) { cout << abs(n2 - k) << endl; }
		else {
			cout << n2 << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 3580
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <cstring>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <math.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ld INF = 1e18;
typedef pair< ld, int > P;

struct Graph {

  struct edge {
    int to; ld cost;
  };

  int V;
  vector< vector< edge > > Es;

  Graph(int v) {
    init(v);
  }

  void init(int v) {
      V = v;
      Es.resize(v);
  }

  void add(int from, int to, ld cost) {
    Es[from].push_back((edge){to, cost});
  }

  void show() {
    for (int v = 0; v < V; v++) {
      cout << "v = " << v << endl;
      for (auto e : Es[v]) {
        cout << e.to << " " << e.cost << endl;
      }
      cout << endl;
    }
  }

  vector< ld > dijkstra(int s) {
    vector< ld > dist(V, INF);
    dist[s] = 0.0;
    priority_queue< P, vector< P >, greater< P > > que;
    que.push(P(0.0, s));
    while (!que.empty()) {
      P p = que.top();
      que.pop();
      int v = p.second;
      if (dist[v] < p.first) continue;
      for (auto e : Es[v]) {
        ld d = dist[v] + e.cost;
        if (d < dist[e.to]) {
          dist[e.to] = d;
          que.push(P(d, e.to));
        }
      }
    }
    return dist;
  }

  vector< ld > bellmanford(int s) {
    vector< ld > dist(V, INF);
    dist[s] = 0.0;
    int loopCnt = 0;
    while (true) {
      bool update = false;
      for (int v = 0; v < V; v++) {
        if (dist[v] == INF) continue;
        for (auto e : Es[v]) {
          ld d = dist[v] + e.cost;
          if (d < dist[e.to]) {
            dist[e.to]= d;
            update = true;
          }
        }
      }
      if (!update) break;
      if (loopCnt == V+1) return vector< ld >(V, -INF);
      loopCnt += 1;
    }
    return dist;
  }

};

ld dist(ld x0, ld y0, ld x1, ld y1) {
  ld xd = x0-x1, yd = y0-y1;
  return sqrt(xd*xd+yd*yd);
}

int main() {
  ld xs, ys, xt, yt, N;
  cin >> xs >> ys >> xt >> yt >> N;
  vector< ld > x(N+2), y(N+2), r(N+2);
  x[0] = xs; y[0] = ys; r[0] = 0;
  x[N+1] = xt; y[N+1] = yt; r[N+1] = 0;
  for (int i = 1; i <= N; i++) cin >> x[i] >> y[i] >> r[i];
  Graph G(N+2);
  for (int i = 0; i < N+1; i++) {
    for (int j = i+1; j < N+2; j++) {
      ld d = max((ld)0.0, dist(x[i],y[i],x[j],y[j])-r[i]-r[j]);
      G.add(i, j, d);
      G.add(j, i, d);
    }
  }
  cout << fixed << setprecision(12) << G.bellmanford(0)[N+1] << endl;
}


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

#define lli long long int
#define ld long double
#define DEFO(n) lli n = 0;
#define MAX_L lli max = 9000000000000000000;
#define MIN_L lli min = 9000000000000000000;
#define MAX_D ld max = 4500;
#define MIN_D ld min = -4500;
#define LLI(n) \
  lli n;       \
  cin >> n;
#define LD(n)  \
  ld n;        \
  cin > n;
#define LLIV(a, n)            \
  vector<lli> a(n);           \
  for (lli i = 0; i < n; i++) \
  {                           \
    cin >> a.at(i);           \
  };
#define LLIV2(a, b, n)            \
  vector<lli> a(n), b(n);           \
  for (lli i = 0; i < n; i++) \
  {                           \
    cin >> a.at(i) >> b.at(i);           \
  };
#define LDV(a, n)            \
  vector<ld> a(n);           \
  for (lli i = 0; i < n; i++) \
  {                           \
    cin >> a.at(i);           \
  };
#define STR(n) \
  string n;    \
  cin >> n;
#define sum(n) accumulate(n.begin(), n.end(), 0);
#define Sort(n) sort(n.begin(), n.end());
#define Reve(n) reverse(n.begin(), n.end());
#define yes cout << "Yes" << endl; return 0;
#define no cout << "No" << endl; return 0;
#define C45(n) (n + 1) / 2
#define OUT(n) cout << n << endl;
#define SRC(n, c)                    \
  for (lli i = 0; i < s.size(); i++) \
  {                                  \
    if (s.at(i) == c)                \
    {                                \
      n++;                           \
    }                                \
  };
//こぴー
/*#define ZISYO(s, S)                  \
  for (lli i = 0; i < s.size(); i++) \
  {                                  \
    S.at(i) = s.at(i);               \
  }                                  \
  Sort(S) Reve(S) for (lli i = 0; i < s.size(); i++) { s.at(i) = S.at(i); };
*/

//素数
bool IsPrime(lli num)
{
  if (num < 2)
    return false;
  else if (num == 2)
    return true;
  else if (num % 2 == 0)
    return false;
  long double sqrtNum = sqrt(num);
  for (lli i = 3; i <= sqrtNum; i += 2)
  {
    if (num % i == 0)
      return false;
  }
  return true;
}
//各桁の和
lli KSum(lli n)
{
  lli sum = 0;
  if (n < 0)
    return 0;
  while (n > 0)
  {
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

int main(void)
{
  ios::sync_with_stdio(false);
  LLI(K)LLI(S)DEFO(flag)
  for(lli x = 0;x <= K;x++) {
    for(lli y = 0;y <= K;y++) {
      lli ans;
      ans = x + y + K;
      if(S-ans<=0&&S-ans>=-K) flag++;
    }
  }
  OUT(flag)
}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
using namespace std;

#define endl '\n'
#define lfs cout<<fixed<<setprecision(10)
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define fi first
#define se second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = (ll)(m) - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD1 = 1e9+7;
const ll MOD9 = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T1, typename T2>
bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
template<typename T1, typename T2>
bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,-1,0,0,1,1,-1,-1};
vector<ll>dy={0,0,1,-1,1,-1,1,-1};
template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2>&p){
  return os << p.first << " " << p.second;
}
//mt19937 mt(chrono::steady_clock::now().time_since_epoch().count());

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ll res=0,buf=0;
  bool judge = true;
  ll n;cin>>n;
  vector<ll>v(n+1);
  rep(i,1,n+1){
    for(ll j=i;j<=n;j+=i){
      v[j]++;
    }
    res+=v[i]*i;
  }
  cout<<res<<endl;
  return 0;
}

Measured memory_bytes: 81340
#include <bits/stdc++.h>
#define ll long long
#define maxn 100005 /*rem*/
#define mod 998244353
#define db double
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define pi pair<int, int>
#define fi first
#define se second
using namespace std;
ll ksm(ll a, ll b) {
   if (!b) return 1;
   ll ns = ksm(a, b >> 1);
   ns = ns * ns % mod;
   if (b & 1) ns = ns * a % mod;
   return ns;
}
char a[maxn]; 
int main() {
	scanf("%s", a);
	int n = strlen(a);
	int k;
	cin >> k;
	int c0 = 0, c1 = 0;
	int a0 = 0, a1 = 0, al = 0;
	for (int i = 0; i < n; ) {
		int j = i;
		while (a[j] == a[i] && j < n) j++;
		if (i == 0) al += j - i, a1 += (j - i) / 2;
		else if (j == n) al += j - i, a1 += (j - i) / 2;
		a0 += (j - i) / 2;
		i = j;
	}
	if (a[0] != a[n - 1]) {
		printf("%lld\n", 1ll * k * a0);
		return 0;
	}
	else {
		if (al == n) {
			printf("%lld\n", (1ll * k * n) / 2);
			return 0;
		}
		else {
			ll ans = 1ll * k * a0;
			ans -= 1ll * (k - 1) * a1;
			ans += 1ll * (k - 1) * (al / 2);
			cout << ans << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int main(){
	int a[1009];
	int b;
	scanf("%d",&b);
	int sum = 0;
	for(int i = 0;i<b;i++){
		scanf("%d",&a[i]);
		sum+=a[i];
	}
	if(sum%10!=0){
		printf("%d\n",sum);
	}
	else{
		sort(a,a+b);
		int y = 0;
		for(int i = 0;i<b;i++){
			if(a[i]%10!=0){
				y = a[i];
				break;
			}	
		}
		if(y==0){
			printf("0\n");
		}
		else printf("%d\n",sum-y);
	}
	


}

Measured memory_bytes: 128