akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;

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

  ll x;
  cin >> x;
  int numberOf500 = x / 500;
  int numberOf5 = (x - (numberOf500 * 500)) / 5;
  cout << (numberOf500 * 1000) + (numberOf5 * 5) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
 
int main (void){
  int n,d,x,a;
  int i;
  int eaten;
  
  scanf("%d",&n);
  scanf("%d %d",&d,&x);
  
  for( i=0, eaten=0, d--; i<n; i++){
    scanf("%d",&a);
    eaten = d / a;
    
    x += eaten+1;
  }
  
  printf("%d",x);
  
  return 0;
}

Measured memory_bytes: 128
def spaceinput():
    return list(map(int,input().split(" ")))

def interval(t):
    pass

N=int(input())
T=spaceinput()
v=spaceinput()

Tmax=0

for i in range(N):
    Tmax+=(T[i])
#mv=[0]*(Tmax+1)
mv={}

frange=[x for x in range(2*Tmax+1)]

k=0
sT=T[0]
d=0.5

mv[0]=0
for t in [x/2 for x in range(1,2*Tmax)]:

    if sT<t:
        k+=1
        if k<len(T):
            sT+=T[k]
        else:
            break

    mv[t]=min(v[k],mv[t-0.5]+d)

mv[Tmax]=0

k=N-1
sT=Tmax-T[-1]
for t in reversed([x/2 for x in range(1,2*Tmax)]):
    if sT>t:
        k-=1
        sT-=T[k]

    mv[t]=min(v[k],mv[t],mv[t+d]+d)


res=0
k=0
sT=T[0]
for t in [x/2 for x in range(1,2*Tmax)]:
    if sT<t:
        if t==Tmax-1:
            break
        k+=1
        if k<len(T):
            sT+=T[k]
    res+=mv[t]*0.5

print(res)


Measured memory_bytes: 8308
#include<cstdio>
#include<algorithm>
using namespace std;

int a[100005];
bool f[100005];

int main(){
	int n;
	scanf("%d",&n);
	int sum=0;
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		sum+=a[i]>a[i-1]?a[i]-a[i-1]:a[i-1]-a[i];
	}
	sum+=a[n]>0?a[n]:-a[n];
	for(int i=1;i<=n;i++){
		int tmp1=a[i]>a[i-1]?a[i]-a[i-1]:a[i-1]-a[i];
		int tmp2=a[i+1]>a[i]?a[i+1]-a[i]:a[i]-a[i+1];
		int tmp3=a[i+1]>a[i-1]?a[i+1]-a[i-1]:a[i-1]-a[i+1];
		printf("%d\n",sum-tmp1-tmp2+tmp3);
	}
	return 0;
}

Measured memory_bytes: 1536
#include<bits/stdc++.h>
// #include<boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
using namespace std;
#define BEGIN ios_base::sync_with_stdio(0);cin.tie(0);
#define END return EXIT_SUCCESS;
#define FOR(I,A,B) for((I)=(A);(I)<(B);(I)++)
#define REP(I,N) FOR((I),0,(N))
#define UP(I,A,B) for((I)=(A);(I)<=(B);(I)++)
#define DW(I,A,B) for((I)=(A);(I)>=(B);(I)--)
#define IN(P) cin>>(P)
#define IN2(P1,P2) cin>>(P1)>>(P2)
#define IN3(P1,P2,P3) cin>>(P1)>>(P2)>>(P3)
#define INS(I,N,V) REP((I),(N)) cin>>(V[I])
#define INS2(I,N,V1,V2) REP((I),(N)) cin>>(V1[I])>>(V2[I]);
#define INS3(I,N,V1,V2,V3) REP((I),(N)) cin>>(V1[I])>>(V2[I])>>(V3[I]);
#define OUT(P) cout<<(P)<<endl
#define OUT2(P1,P2) cout<<(P1)<<" "<<(P2)<<endl
#define OUT3(P1,P2,P3) cout<<(P1)<<" "<<(P2)<<" "<<(P3)<<endl
#define OUTS(I,N,V) REP((I),(N)) cout<<(V[i])<<endl
#define ALL(C) (C).begin(),(C).end()
#define RALL(C) (C).rbegin(),(C).rend()
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}

int A,B,C;
inline void solve(){
  IN3(A,B,C);
  OUT(min(B/A,C));
}

int main(int argc,char**argv){
  BEGIN
  solve();
  END
}


Measured memory_bytes: 256
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
#if DEBUG
            ReadLine();
#endif
        }
        struct Dish
        {
            public int id;
            public long a;
            public long b;

            public Dish(int id, long a, long b)
            {
                this.id = id;
                this.a = a;
                this.b = b;
            }
        }

        void Solve(ConsoleInput cin)
        {
            int n = cin.ReadInt;
            List<Dish> dish = new List<Dish>();

            for (int i = 0; i < n; i++)
            {
                long a = cin.ReadLong;
                long b = cin.ReadLong;

                dish.Add(new Dish(i, a, b));
            }

            dish = dish.OrderByDescending(x => x.a + x.b).ToList<Dish>();

            long ans = 0;
            for (int i = 0; i < n; i++)
            {
                if (i % 2 == 0)
                {
                    ans += dish[i].a;
                }
                else
                {
                    ans -= dish[i].b;
                }
            }

            Console.WriteLine(ans);
        }

        class ConsoleInput
        {
            private readonly System.IO.TextReader _stream;
            private char _separator = ' ';
            private Queue<string> inputStream;

            public ConsoleInput(System.IO.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; }
        }
    }
}


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

template<class T,class F>
struct segment_tree{
  std::vector<T> data;int n;F f;T identity;segment_tree(){}
  segment_tree(int sz,T ide,F _f):f(_f),identity(ide){n=1;while(n<sz)n<<=1;data.resize(2*n,identity);}
  segment_tree(std::vector<T> const& v,T ide,F _f):f(_f),identity(ide){int sz=v.size();n=1;while(n<sz)n<<=1;data.resize(2*n,identity);for(int i=0;i<sz;++i)data[i+n]=v[i];for(int i=n-1;i>0;--i)data[i]=f(data[i<<1|0],data[i<<1|1]);}
  void set(int i,T x){i+=n;data[i]=x;while(i,i>>=1)data[i]=f(data[i<<1|0],data[i<<1|1]);}
  T fold(int l,int r)const{l=(l<0?n:l+n),r=(r<n?r+n:n<<1);T fold_l=identity,fold_r=identity;while(l<r){if(l&1)fold_l=f(fold_l,data[l++]);if(r&1)fold_r=f(data[--r],fold_r);l>>=1,r>>=1;}return f(fold_l,fold_r);}
  T fold()const{return data[1];}
  T operator[](int i)const{return data[i+n];}
  template<class Cond>int bserch(int l,Cond& cond){l+=n;T x=identity;do{while(!l&1)l>>=1;if(cond(f(x,data[l]))){while(l<n){l<<=1;if(!cond(f(x,data[l])))x=f(x,data[l++]);}return l-n;}x=f(x,data[l++]);}while((l&-l)!=l);return -1;}
};
template<class T,class F>auto make_segtree(int n,T ide,F f){return segment_tree<T,F>(n,ide,f);}

int main(){
  
  int n,k;
  std::cin>>n>>k;
  std::vector<int> a(n);
  for(auto& ai:a)std::cin>>ai;

  const int amax = 3e5;
  const auto max = [](int a,int b){return a<b?b:a;};
  auto dp = make_segtree<int>(amax+1,0,max);

  for(auto ai:a){
    int l = ai-k;
    int r = ai+k;
    int tmp = dp.fold(l,r+1)+1;
    dp.set(ai,tmp);
  }

  std::cout<<dp.fold()<<std::endl;

}

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

	public static void main(String[] args) 
	{
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int y = sc.nextInt();
		int z = sc.nextInt();
		if(x<y && y<z){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}
}
 

Measured memory_bytes: 26344
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>
#include <functional>
#include <complex>
#include <list>
/*多倍長整数/cpp_intで宣言
#include <boost/multiprecision/cpp_int.hpp>

using namespace boost::multiprecision;
*/

//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printin(a) printf(a ? "possible\n" : "inposible\n")
#define printdb(a) printf("%.50lf\n", a)//少数出力
#define printdbd(a) printf("%.16lf\n", a)//少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str())//string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2)//等差数列の和、初項,末項,項数
#define pb push_back
#define priq priority_queue
#define rpriq priq<int, vector<int>, greater<int>>
#define deg_to_rad(deg) (((deg)/360.0)*2.0*PI)
#define rad_to_deg(rad) (((rad)/2.0/PI)*360.0)
#define Please return
#define AC 0
#define addf(T) [](T a, T b){return (a + b);}
#define minf(T) [](T a, T b){return min(a, b);}
#define maxf(T) [](T a, T b){return max(a, b);}


using ll = long long;

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1000000007;
const long double PI = acos(-1.0L);

using namespace std;

void scans(string& str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);//最初の改行対策
	while (c != '\n' && c != -1) {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

ll lcm(ll number1, ll number2) {//lcmを求める
	return number1 / gcd(number1, number2) * number2;
}

ll LSB(ll n) { return (n & (-n)); }

/*-----------------------------------------ここからコード-----------------------------------------*/



int main() {

	int n, k, s;
	scanf("%d%d%d", &n, &k, &s);
	if (s == 1e9) {
		rep(i, k) {
			printf("%d\n", s);
		}
		rep(i, n - k) {
			printf("%d\n", s - 1);
		}
	}
	else {
		rep(i, k) {
			printf("%d\n", s);
		}
		rep(i, n - k) {
			printf("%d\n", s + 1);
		}
	}

	Please AC;
}


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

using namespace std;

int main(void) {
    double a, b, x;
    cin >> a >> b >> x;

    double p = M_PI;
    double t = atan(a / b);

    cout << setprecision(20);
    if( x/a > a*b/2 ) {
        /* double u = t, l = 0; */
        /* // x/a/a == b - a*tan(m) / 2 */
        /* // a * tan(m) /2 == b - x/a/a */
        /* // tan(m) == 2*(b - x/a/a)/a */
        /* for(int i=0; i<1000000; i++) { */
        /*     double m = (u+l)/2; */
        /*     if( x > a*a*(b - a * tan(m) / 2)) */
        /*         u = m; */
        /*     else */
        /*         l = m; */
        /* } */
        double l = atan(2/a * (b - x / a / a));
        printf("%.16f\n", l/p*180);
    } else {
        /* double u = p/2, l = t; */
        /* for(int i=0; i<1000000; i++) { */
        /*     double m = (u+l)/2; */
        /*     // tan(m) == a*b*b/2/x */
        /*     if( x > a*(b * b / tan(m) / 2)) */
        /*         u = m; */
        /*     else */
        /*         l = m; */
        /* } */
        double l = atan(a*b*b/2/x);
        printf("%.16f\n", l/p*180);
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ull unsigned long long int
#define MAXX 1000000000000000000

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ull n;
    cin>>n;
    ull arr[n];
    ull ans=1;
    for(ull i=0;i<n;i++){
        cin>>arr[i];
        if(arr[i]==0){
            ans=0;
        }
    }
    if(ans==0){
        cout<<ans;
        return 0;
    }

    for(ull i=0;i<n;i++)
    {
        ull ok=MAXX/ans;
        if(arr[i]>(ok+1)){
            ans=-1;
            break;
        }
        ans*=arr[i];
    }
    if(ans<=MAXX)
    cout<<ans;
    else
    cout<<-1;
    return 0;
}




Measured memory_bytes: 4372
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
#define eb emplace_back
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
constexpr ll INF = (1LL << 60) - 1LL;
constexpr ll MOD = 1e9 + 7;
template <class T>
void chmin(T &a, T b) { a = min(a, b); }
template <class T>
void chmax(T &a, T b) { a = max(a, b); }
void ok() { cerr << "ok" << endl; }
int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    ll k;
    cin >> k;
    ll ok = 3234566670, ng = 0;
    auto check = [&](ll x) {
        string s = to_string(x);
        vector<vector<vector<ll>>> dp(s.length() + 5, vector<vector<ll>>(10, vector<ll>(2)));
        for (int i = 0; i <= s[0] - '0'; i++) {
            if (i == s[0] - '0') {
                dp[1][i][1] = 1;
            } else {
                dp[1][i][0] = 1;
            }
        }
        for (int i = 1; i < s.length(); i++) {
            for (int j = 0; j < 10; j++) {
                if (j > 1) {
                    dp[i + 1][j][0] = 1;
                }
                if (j > 0) {
                    dp[i + 1][j][0] += dp[i][j - 1][0];
                    if (j < s[i] - '0') {
                        dp[i + 1][j][0] += dp[i][j - 1][1];
                    }
                    if (j == s[i] - '0') {
                        dp[i + 1][j][1] += dp[i][j - 1][1];
                    }
                }
                if (j < 9) {
                    dp[i + 1][j][0] += dp[i][j + 1][0];
                    if (j < s[i] - '0') {
                        dp[i + 1][j][0] += dp[i][j + 1][1];
                    }
                    if (j == s[i] - '0') {
                        dp[i + 1][j][1] += dp[i][j + 1][1];
                    }
                }
                dp[i + 1][j][0] += dp[i][j][0];
                if (j < s[i] - '0') {
                    dp[i + 1][j][0] += dp[i][j][1];
                }
                if (j == s[i] - '0') {
                    dp[i + 1][j][1] += dp[i][j][1];
                }
            }
        }
        ll res = -1;
        for (int i = 0; i < 10; i++) {
            //cout << dp[s.length()][i][0] + dp[s.length()][i][1] << endl;
            res += dp[s.length()][i][0] + dp[s.length()][i][1];
        }
        //   cout << x << " " << res << endl;
        return res >= k;
    };
    while (ok - ng > 1) {
        ll mid = (ok + ng) / 2LL;
        if (check(mid)) {
            ok = mid;
        } else {
            ng = mid;
        }
    }
    cout << ok << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;





int main(){

	int N;
	scanf("%d",&N);

	if(N <= 999){

		printf("ABC\n");

	}else{

		printf("ABD\n");
	}

	return 0;
}


Measured memory_bytes: 3736
N, M, C = map(int, input().split(' '))

B = list(map(int, input().split(' ')))

result = 0

for i in range(1, N+1):
  values = list(map(int, input().split(' ')))
  count = 0
  for idx, v in enumerate(values):
    count += v * B[idx]
  count += C

  if count > 0:
    result += 1

print(result)


Measured memory_bytes: 9012
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
      String[] sn=sc.nextLine().split(" ");
int mae=Integer.parseInt(sn[0]);
int usi=Integer.parseInt(sn[1]);

int min=Math.min(mae,usi);


long num=0;

while(true){

num+=min;


if(num%mae==0 && num%usi==0){
System.out.println(num);
break;
}

}



	}
}

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

int main() {
    int n;
    cin >> n;
    int p[n];
    for(int i=0; i<n; i++) {
        cin >> p[i];
    }
    
    int m=0;
    for(int i=1; i<n-1; i++) {
        if(p[i] >= p[i-1]) {
            if(p[i] < p[i+1]) m++;
        }
        else {
            if(p[i] >= p[i+1]) m++;
        }
    }
    
    cout << m <<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
/*ここから上は消さないで*/

int main(){
	int a;
	int b;
	for(a = 1; a < 10; a++){
		for(b = 1; b < 10; b++){
			printf("%dx%d=%d\n", a, b, a*b);
		}
	}
	return 0;	//ここの行、重要
}

Measured memory_bytes: 524
//King's Inspection
#include<bits/stdc++.h>
using namespace std;

int into(char c, int d){
  int t;
  if('a'<=c&&c<='z')t=c-'a';
  else t=c-'A'+26;
  while(d--){
    if(t==0)t=51;
    else t--;
  }
  return t;
}

int main(){
  int n;
  while(true){
    cin>>n;
    if(n==0)break;
    vector<int> key;
    for(int i=0; i<n; i++){
      int tmp;
      cin>>tmp;
      key.push_back(tmp);
    }
    string s;
    cin>>s;
    string ans="";
    for(int i=0; i<s.length(); i++){
      int tmp=into(s[i], key[i%n]);
      if(tmp<26)ans+=(tmp+'a');
      else ans+=(tmp-26+'A');
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 1232
x=int(input())
j=0

while j==0:
    ans=0
    if x%2==0 and x!=2:
        x+=1
        continue
    for i in range(2,x//2):
        if x%i==0:
            ans+=1
    if ans==0:
        j=x

    x+=1

print(j)


Measured memory_bytes: 2940
I=lambda:map(int,input().split())
h,w,d=I()
H={}
W={}
for i in range(1,h+1):
  for j,k in enumerate(I(),1):
    H[k],W[k]=i,j
x=1+h*w
s=[0 for _ in range(x)]
for i in range(d+1,x):
  s[i]=s[i-d]+abs(H[i]-H[i-d])+abs(W[i]-W[i-d])

for _ in range(int(input())):
  a,b=I()
  print(s[b]-s[a])

Measured memory_bytes: 74708
def solve(H, W, N, As):
    # print(H, ",", W, ",", N, ",", As)
    field = [[0] * W for _ in range(H)]
    index = 0
    for color, a in enumerate(As):
        color += 1
        for _ in range(a):
            row = index // W
            if row % 2 == 0:
                field[row][index - row * W] = str(color)
            else:
                field[row][W - (index - row * W) - 1] = str(color)
            index += 1
    ans = "\n".join([" ".join(row) for row in field])
    return ans


# print(solve(2, 2, 3, [2, 1, 1]))

if __name__ == "__main__":
    H, W = tuple(map(int, input().split(" ")))
    N = int(input())
    As = list(map(int, input().split(" ")))
    print(solve(H, W, N, As))


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


int main()
{
	int h,w;
	char a[105][105]={};
	cin>>h>>w;
	for(int i=0;i<=h+1;i++)
	{
		for(int j=0;j<=w+1;j++)
		{
			if(i==0||i==h+1||j==0||j==w+1)cout<<"#";
			else
			{
				cin>>a[i][j];
				cout<<a[i][j];
			}
		}
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
fn main() {
    let n: usize = read();
    let v: Vec<isize> = read_vec();
    let c: Vec<isize> = read_vec();

    let mut d: Vec<isize> = Vec::new();
    for i in 0..n {
        d.push(v[i] - c[i]);
    }
    
    let mut ans = 0;
    for i in d {
        if i > 0 {
            ans += i;
        }
    }
    println!("{}", ans);
}

// ########################################################################################### //

// 標準入力から一行を読み取り、指定の型に変換する関数
pub fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

// 標準入力から一行を読み取り、空白文字で分割し、各要素を指定の型に変換する関数
pub fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

// 標準入力からn行を読み取り、各行を空白文字で分割し、各要素を指定の型に変換する関数
pub fn read_vec2<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

// 10進数での各桁の和
pub fn sum_dights(x: isize) -> isize {
    if x % 10 == 0 {
        return 0
    }
    let m = x % 10;
    m + sum_dights((x - m) / 10)
}


Measured memory_bytes: 4352
import java.util.*;

public class Main {

    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int d = sc.nextInt();
        int n = sc.nextInt();
        if (n == 100) {
            if (d == 0)
                System.out.println(101);
            else if (d == 1)
                System.out.println(10100);
            else
                System.out.println(1010000);
        } else {
            System.out.println(n * (int) Math.pow(100, d));
        }
    }

}


Measured memory_bytes: 23508
import sys
t1,t2=map(int,input().split())
a1,a2=map(int,input().split())
b1,b2=map(int,input().split())
n1=(b1-a1)*t1
n2=(b2-a2)*t2
if n1*n2>0 or abs(n1)>abs(n2):
  print(0)
  sys.exit()
if abs(n1)==abs(n2):
  print('infinity')
  sys.exit()
c=abs(n1)//abs(n1+n2)
while (c+1)*abs(n1+n2)<=abs(n1):
  c+=1
ans=2*c
if abs(n1)%(abs(n1+n2))!=0:
  ans+=1
print(ans)


Measured memory_bytes: 61244
#include <stdio.h>
#include <queue>
#include <utility>
using namespace std;
typedef pair<int,int> pi;
typedef long long int ll;
#define F first
#define S second
const int N=2e5+10;
int p[N],sz[N];
int find(int n){return p[n]==n?n:p[n]=find(p[n]);}
int main(){
    int n,a,b,c;
    pair<int,pi> temp;
    ll ans=0;
    priority_queue<pair<int,pi>,vector<pair<int,pi>>,greater<pair<int,pi>>>pq;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        p[i]=i;
        sz[i]=1;
    }
    for(int i=1;i<n;i++){
        scanf("%d%d%d",&a,&b,&c);
        pq.push({c,{a,b}});
    }
    while(!pq.empty()){
        temp=pq.top();
        pq.pop();
        a=find(temp.S.F);
        b=find(temp.S.S);
        ans+=(ll)sz[a]*(ll)sz[b]*(ll)temp.F;
        sz[a]+=sz[b];
        p[b]=a;
    }
    printf("%lld\n",ans);
}


Measured memory_bytes: 7028
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<map>
#include<set>

using namespace std;

typedef long long ll;
typedef vector<int> VI;

#define FOR(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR1(i,n) for(int (i)=1;(i)<(n);(i)++)
#define eFOR(i,n) for(int (i)=0;(i)<=(n);(i)++)
#define eFOR1(i,n) for(int (i)=1;(i)<=(n);(i)++)
#define SORT(i) sort((i).begin(),(i).end())

int main() {

	int n, cnt = 1;
	char k;
	string s;
	cin >> n;
	cin >> s;
	vector<ll> a, b;
	while (s[0] == '.')s.erase(s.begin());
	while (s[s.length() - 1] == '#')s.erase(s.begin() + s.length() - 1);
	n = s.length();
	if (n) {
		k = '#';
		FOR1(i, n) {
			if (s[i] == k)cnt++;
			else {
				if (k == '#')a.push_back(cnt);
				else b.push_back(cnt);
				k = s[i];
				cnt = 1;
			}
		}
		b.push_back(cnt);
		FOR1(i, a.size())a[i] += a[i - 1];
		FOR1(i, b.size())b[i] += b[i - 1];
		ll ans = min(a[a.size() - 1], b[b.size() - 1]);
		FOR(i, a.size()) {
			ans = min(ans, a[i] + b[b.size() - 1] - b[i]);
		}
		cout << ans << endl;
	}
	else cout << 0 << endl;


	return 0;
}


Measured memory_bytes: 2288
def c_ab_substrings(N, S):
    """
    N個の文字列を好きな順序で並べたあと、連結して1つの文字列を作る。
    作った文字列に 'AB' という部分文字列が含まれる個数として
    ありうる値のうち最大のものを求めよ。
    """

    num_start_b_end_a = 0
    num_start_b_not_end_a = 0
    num_not_start_b_end_a = 0
    ans = 0
    for s in S:
        if s[0] == 'B' and s[-1] == 'A':
            num_start_b_end_a += 1
        if s[0] == 'B' and s[-1] != 'A':
            num_start_b_not_end_a += 1
        if s[0] != 'B' and s[-1] == 'A':
            num_not_start_b_end_a += 1
        ans += s.count('AB')
    if num_start_b_end_a == 0:
        # 'B.*A' がない場合、'B.*^A' と '^B.*A' を結合して '.*AB.*' を生み出せる
        ans += min(num_start_b_not_end_a, num_not_start_b_end_a)
    else:
        # 'B.*A' がある場合、その後に 'B.*^A' を結合するか、その前に '^B.*A' を結合する
        # 'B.*^A' も '^B.*A' もない場合、 'B.*A' 同士で結合させる
        if num_start_b_not_end_a + num_not_start_b_end_a > 0:
            ans += num_start_b_end_a + min(num_start_b_not_end_a, num_not_start_b_end_a)
        else:
            ans += num_start_b_end_a - 1
    return ans

N = int(input())
S = [input() for _ in range(N)]
print(c_ab_substrings(N, S))

Measured memory_bytes: 3700
#define _CRT_SECURE_NO_WARNINGS // #pragma warning(disable:4996)
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <functional>
#include <sstream>
#include <cmath>
#include <set>
#include <map>
using namespace std; 

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define pb push_back
#define mp(a,b) make_pair(a,b)
#define all(a) a.begin(),a.end()
#define len(x) ((int)(x).size())
#define tmax(a,b,c) max((a),max((b),(c)))
#define tmin(a,b,c) min((a),min((b),(c)))
#define debug(x) cerr << #x << " is " << x << endl;

typedef pair<int, int> Pii;
typedef vector<int> Vi;
typedef vector<vector<int> > VVi;
typedef long long ll;
const int inf = 2e9;
const ll ll_inf = 1e17;
const int mod = 1e9 + 7;
const long double eps = 1e-10;

int p[201];

int main()
{
	while(1) {
		int m, nmin, nmax;
		cin >> m >> nmin >> nmax;
		if (!m && !nmin && !nmax) break;
		memset(p, 0, sizeof(p));
		rep(i,0,m) cin >> p[i];

		int ans = 0, d = 0;
		rep(n,nmin,nmax+1) {
			int a = p[n-1] - p[n];
			if (a >= d) {
				ans = n;
				d = a;
			}
		}
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 1160
DBG = !true
n,m = gets.split.map{|x| x.to_i}
x = gets.split.map{|x| x.to_i}
if n >= m
  puts "0"
  exit 0
end

x.sort!
mdif = []
for i in 0..(m-2)
  mdif << x[i+1] - x[i]
end
mdif.sort!
print mdif if DBG
ret = mdif[0...(m-n)].inject(:+)
puts "#{ret}"


Measured memory_bytes: 10252
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <string>
typedef long long ll;
using namespace std;

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

  int a, b, c;
  cin >> a >> b >> c;
  c = min(a + b + 1, c);
  cout << b + c << endl;

  return 0;
}


Measured memory_bytes: 3644
N = int(input())
A = list(map(int,input().split()))
max = 0
step_sum = 0
for i in range(N):
    diff = A[i] - max
    if diff <= 0:
        max = A[i] - diff
        step_sum -= diff
    else:
        max = A[i]
print(step_sum)

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

int n,m,k;
const int N = 1e5+5;
int a[N],b[N];

int main() {
    ios::sync_with_stdio(0);
	cin>>n>>m>>k;
	int M = 1e9;
	for(int i=0;i<n;i++) {
		cin>>a[i];
		M = min(a[i],M);
	}
	int ans = M;
	M = 1e9;
	for(int i=0;i<m;i++) {
		cin>>b[i];
		M = min(b[i],M);
	}
	ans += M;
	while(k--) {
		int x,y,c;
		cin>>x>>y>>c;
		x--, y--;
		ans = min(a[x]+b[y]-c,ans);
	}
	cout<<ans<<endl;
    return 0;
}


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

#define N 100000
#define Q 50000

int main() {
    
    int n, q, i, j, array_n[N], array_q[Q], cnt=0, tmp[Q], k, flg, high, low, middle;
    
    scanf("%d", &n);
    
    for (i = 0; i < n; i++) {
        scanf("%d", &array_n[i]);
    }
    
    scanf("%d", &q);
    
    for (i = 0; i < q; i++) {
        scanf("%d", &array_q[i]);
    }
    
    for (i = 0; i < q; i++) {
        high = n - 1;
        low = 0;
        while (low <= high) {
            middle = (low + high) / 2;
            if (array_n[middle] == array_q[i]) {
                flg = 1;
                for (k = 0; k < cnt; k++) {
                    if (array_q[i] == tmp[k]) flg = 0;
                }
                if (flg) {
                    tmp[cnt] = array_q[i];
                    cnt++; 
                }
                break;
            } else if (array_n[middle] < array_q[i]) {
                low = middle + 1;
            } else {
                high = middle - 1;
            }
        }
    }
    
    printf("%d\n", cnt);
    
    return 0;
}



Measured memory_bytes: 2356
def insertion_sort(alist):
    """sort alist by insertion sort.
    print the intermediate sequence for each step.

    >>> insertion_sort([5, 2, 4, 6, 1, 3])
    5 2 4 6 1 3
    2 5 4 6 1 3
    2 4 5 6 1 3
    2 4 5 6 1 3
    1 2 4 5 6 3
    1 2 3 4 5 6
    [1, 2, 3, 4, 5, 6]
    """
    for i, key in enumerate(alist):
        for j in reversed(range(i)):
            if alist[j] <= key:
                alist[j+1] = key
                break
            else:
                alist[j+1] = alist[j]
        else:
            alist[0] = key
        print(" ".join([str(i) for i in alist]))

    return alist


def run():
    _ = int(input())  # flake8: noqa
    nums = [int(i) for i in input().split()]

    insertion_sort(nums)


if __name__ == '__main__':
    run()



Measured memory_bytes: 5624
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int gi(){
	int x=0,w=1;char ch=getchar();
	while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
	if(ch=='-')w=0,ch=getchar();
	while(ch>='0'&&ch<='9')x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
	return w?x:-x;
}
const int N=2e5+5;
const int mod=1e9+7;
int inv[N],jc[N],jcn[N],f[N],g[N];
int C(int n,int m){
	if(n<m)return 0;
	return 1ll*jc[n]*jcn[m]%mod*jcn[n-m]%mod;
}
int main(){
	int n=gi(),m=gi();
	inv[1]=jc[0]=jcn[0]=1;
	for(int i=2;i<N;++i)inv[i]=1ll*inv[mod%i]*(mod-mod/i)%mod;
	for(int i=1;i<N;++i)jc[i]=1ll*jc[i-1]*i%mod,jcn[i]=1ll*jcn[i-1]*inv[i]%mod;
	for(int i=1,pw=inv[2];i<=n+m;++i,pw=1ll*pw*inv[2]%mod){
		f[i]=(f[i-1]+1ll*C(i-1,n-1)*pw)%mod;
		g[i]=(g[i-1]+1ll*C(i-1,m-1)*pw)%mod;
	}
	for(int i=1;i<=n+m;++i){
		int ans=(0ll+mod+mod+1-f[i-1]-g[i-1])*inv[2]%mod;
		ans=(ans+g[i-1])%mod;
		printf("%d\n",ans);
	}
	return 0;
}


Measured memory_bytes: 6016
#include<iostream>
using namespace std;
int main()
{
    int a;
    int i=1;

    while(1){
        cin >> a;
        if(a==0){
            break;
        }
        cout << "Case " << i << ": " << a << endl;
        i++; 
    }
    
    return 0;

}


Measured memory_bytes: 2980
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <queue>
#include <string>

#define reps(i,s,n) for(long long (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using vi = vector<int> ;
using vl = vector<ll>;

int main(){
    ll n,x,m;
    cin >> n >> x >> m;
    ll tmp = x;
    vector<bool> flag(100010,false);
    vl vec(100010,0);
    vec[0] = tmp;
    flag[tmp] = true;

    ll total_len = 0;
    ll l_start = 0;

    reps(i,1,100010){
        tmp = (tmp*tmp) % m;
        vec[i] = tmp;
        if(!flag[tmp]) flag[tmp]=true;
        else {
            total_len = i;
            break;
        }
    }
    
    rep(i,100010){
        if(vec[i] == vec[total_len]){
            l_start = i;
            break;
        }
    }

    ll len = total_len-l_start;
    ll ans = 0;
    ll lsum = 0;
    
    rep(i,l_start){
        ans += vec[i];
    }
    reps(i,l_start, total_len){
        lsum = (lsum+vec[i]);
    }

    ll lcnt = (n - l_start) / len;
    ans += lcnt * lsum;
    ll tmp2 = (n - l_start) % len;
    
    reps(i,l_start,l_start+tmp2){
        ans += vec[i];
    }

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

Measured memory_bytes: 3988
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define DEBUG
#ifdef DEBUG
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
	template <typename Arg1>
	void __f(const char* name, Arg1&& arg1){
		cerr << name << " : " << arg1 << std::endl;
	}
	template <typename Arg1, typename... Args>
	void __f(const char* names, Arg1&& arg1, Args&&... args){
		const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
	}
#else
#define debug(...)
#endif
#define FOR(i,a,b) 	for(int i=a;i<b;++i)
#define RFOR(i,a,b) 	for(int i=a;i>=b;--i)
#define ln 		"\n"
#define mp make_pair
#define pb push_back
#define sz(a)	ll(a.size())
#define F first
#define S second
#define all(c)	c.begin(),c.end()
#define rall(c) c.rbegin(), c.rend()
#define trace(c,x) for(auto &x:c)
#define pii pair<ll,ll>
#define init(a, x) memset(a,x,sizeof(a))
typedef long long ll;
typedef long double ld;
typedef	priority_queue<pii,std::vector<pii>,greater<pii> > revpr;

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> pbds;
// ordered_set X
//K-th smallest
//*X.find_by_order(k-1)
//NO OF ELEMENTS < A
//X.order_of_key(A)
const int L=1e6+7;
map<ll,ll> counter;
ll fastexpo(ll x,ll y,ll m)
{
	ll temp=1;
	while(y>0)
	{
		if(y&1)temp = ((temp%m)*(x%m))%m;
		x = ((x%m)*(x%m))%m;
		y>>=1;
	}return temp;
}
void fff()
{
	string s;
	cin >> s;
	int n = s.length();
	FOR(i,0,n)if(s[i]=='?')s[i] = 'D';
	cout<<s<<ln;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	// int t;cin >> t;while(t--)
	fff();
	return 0;
}

Measured memory_bytes: 3772
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using ll = long long;
using namespace std;

int main() {
    int n;
    int a;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a;
        if(a%2==0){
            if(a%3==0 ||a%5==0){
                //safe
            }else{
                cout<<"DENIED";
                exit(0);
            }
        }
    }
    cout<<"APPROVED";
}

Measured memory_bytes: 256
#include <stdlib.h>

int int_sort( const void * a , const void * b ) {
  return strcmp(( char * )a , ( char * )b );
}

int main()
{
  int n;
  scanf("%d", &n);
  int i;
  char s[n][11];
  for (i = 0; i < n; i++)
    scanf("%s", &s[i]);
  
  qsort((void*)s ,n ,sizeof(s[n]), int_sort);
  
  int cnt = 1;
  for (i = 0; i + 1 < n; i++)
  {
    if (strcmp(s[i], s[i + 1]) != 0)
      cnt++;
  }
  
  printf("%d", cnt);

}

Measured memory_bytes: 5740
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring> //memset(dp,0,sizeof(dp))
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<ll,ll> P;
typedef pair<ll,ll> Pll;
//小数点以下　cout << fixed << setprecision(10) << num << endl;
//桁数はlog10(mid)でやれ　log(mid)/log(10)はWA
//long*long<0で判定するな
//開区間と閉区間
//アルファベットが何番目かは x=s[i]-'a'
//bfsはmain()内で　rep(i,h)rep(j,w)rep(i,4)でバグ
//切り上げ：(a+(b-1))/b
//32bit以上は 1ull<<j]
// map 初期値0 for(auto itr=mp.begin();itr!=mp.end();++itr) itr->fi itr->se で全探索
// for(auto u:mp) u.fi u.se も可能
//n個のgcd,lcmは一つずつみて更新していく
//大きな数を扱うときは素因数分解した形で持っておく
// (l/a[i]) = l*powmod(a[i],MOD-2)%MOD;
//auto itr=lower_bound(ALL(a),key) a[itr-a.begin()]
const int INF = 1001001;
int main(){
    int n; cin >> n;
    int a[n];
    int ma=-INF,mi=INF;
    int maa,mii;
    bool m=0;
    rep(i,n){
        cin >> a[i];
        if(a[i]<0) m=1;
        if(ma<a[i]){
            ma=a[i]; maa=i;
        }
        if(mi>a[i]){
            mi=a[i]; mii=i;
        }
    }
    vector<P> v;
    if(m){
        if(abs(ma)>abs(mi)){
            rep(i,n){
                if(a[i]<0){
                    a[i]+=ma;
                    v.pb({maa,i});
                }
            }
            rep(i,n-1){
                v.pb({i,i+1});
            }
        }else{
            rep(i,n){
                if(a[i]>0){
                    a[i]+=mi;
                    v.pb({mii,i});
                }
            }
            rrep(i,n-1){
                v.pb({i+1,i});
            }
        }
    }else{
        rep(i,n-1){
            v.pb({i,i+1});
        }
    }
    cout << v.size() << endl;
    rep(i,v.size()){
        cout << v[i].fi+1 <<" "<< v[i].se+1 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <unordered_map>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

int f(int n) {
  if (n % 2 == 0)
    return n / 2;
  return 3 * n + 1;
}

int solve(int s) {
  vector<int> v(1000002);
  unordered_map<int, bool> mp;
  v[0] = s;
  mp[s] = true;
  int ans = -1;
  FOR(i, 1, 1000001) {
    v[i] = f(v[i - 1]);
    auto it = mp.find(v[i]);
    if (it == mp.end()) {
      mp[v[i]] = true;
    } else {
      ans = i + 1;
      break;
    }
  }
  // for (int i = 0 ; i <= 8; ++i)
  //   cout << v[i] << " ";
  // cout << endl;

  // for (auto e : mp)
  //   cout << e.first << " ";
  // cout << endl;
  return ans;
}

int main() {
  int s;
  cin >> s;
  cout << solve(s) << endl;
}


Measured memory_bytes: 4096
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

#define INF 1e9
#define ll long long
#define MAXS 8005
#define vi vector<int>
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

string S;
int X, Y;
vi vert, hori;
bool dp[MAXS][MAXS];

bool check(int goal, vi vec){
    int n = vec.size();

    rep(i,n+1)
        fill(dp[i], dp[i]+MAXS, 0);

    dp[0][0] = 1;

    for(int i = 1; i <= n; i++){
        int val = vec[i-1];
        
        rep(j,MAXS){
            if(dp[i-1][j] == 1){
                if(j-val>=0) dp[i][j-val] = 1;
                if(j+val<MAXS) dp[i][j+val] = 1;
            }
        }
    }

    return dp[n][goal];
}

int main(){
    cin >> S >> X >> Y;
    if(S[S.size()-1]!='T') S += 'T'; //パディング

    int tmp = 0;
    bool state = true;

    rep(i, S.size()){
        if(S[i] == 'F'){
            tmp++;
        } else {
            if(state)
                hori.push_back(tmp);
            else
                vert.push_back(tmp);
            tmp = 0;
            state = !state;
        }
    }

    X -= hori[0];
    hori.erase(hori.begin()); //初期値だけシフトして対称性を保つ
    X = abs(X);
    Y = abs(Y);
    // printf("goal: (%d,%d)\n",X,Y);

    // printf("vertical: ");
    // rep(i,vert.size())
    //     cout << vert[i] << " ";
    // cout << endl;

    // printf("horizontal: ");
    // rep(i,hori.size())
    //     cout << hori[i] << " ";
    // cout << endl;

    if(check(Y,vert) && check(X, hori)) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 33152
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<vector>
#include<cmath>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<algorithm>
#define LL long long
using namespace std;

const int inf=0x3f3f3f3f;
int n,m,d[10010];

struct edge{
    int to,dis,cost;
    edge(){}
    edge(int x,int y,int z){
        to=x;
        dis=y;
        cost=z;
    }
};

typedef pair<int,int> P;
priority_queue<P,vector<P>,greater<P> > pq;
vector<edge> G[10010];

void dijkstra(int s){
    while(!pq.empty()) pq.pop();
    memset(d,0x3f,sizeof(d));
    d[s]=0;
    pq.push(P(0,s));
    while(!pq.empty()){
        P p=pq.top();
        pq.pop();
        int u=p.second;
        if(d[u]<p.first) continue;
        int i,len=G[u].size();
        for(i=0;i<len;i++){
            edge e=G[u][i];
            if(d[e.to]>d[u]+e.dis){
                d[e.to]=d[u]+e.dis;
                pq.push(P(d[e.to],e.to));
            }
        }
    }
}

int main(void){
    while(scanf("%d %d",&n,&m)!=EOF && (n+m)){
        int i,j;
        for(i=1;i<=n;i++) G[i].clear();
        for(i=1;i<=m;i++){
            int u,v,l,c;
            scanf("%d %d %d %d",&u,&v,&l,&c);
            G[u].push_back(edge(v,l,c));
            G[v].push_back(edge(u,l,c));
        }
        dijkstra(1);
        int sum=0;
        for(i=2;i<=n;i++){
            int mini=inf,len=G[i].size();
            for(j=0;j<len;j++){
                edge e=G[i][j];
                if(d[i]==d[e.to]+e.dis) mini=min(mini,e.cost);
            }
            sum+=mini;
        }
        printf("%d\n",sum);
    }
    return 0;
}



Measured memory_bytes: 5024
def get_input():
    while True:
        try:
            yield ''.join(input())
        except EOFError:
            break

N = list(get_input())
for l in range(len(N)):
    p,q = [int(i) for i in N[l].split()]
    P,Q = p,q

    amari = [0 for i in range(q+1)]
    amari[p] = 1

    s = -1
    l = -1

    cnt = 2
    while True:
        p *= 10
        p1 = p // q
        p2 = p % q

        if p2 == 0:
            s = cnt
            l = 0
            break

        if amari[p2] == 0:
            amari[p2] = cnt
            cnt += 1
            p = p2
        else:
            s = amari[p2]
            l = cnt - amari[p2]
            break

    p,q = P,Q
    for i in range(s-1):
        print((p*10)//q, end="")
        p = (p*10) % q
    for i in range(l):
        print((p*10)//q, end="")
        p = (p*10) % q
    print("")

    if l > 0:
        for i in range(s-1):
            print(" ", end="")
        for i in range(l):
            print("^", end="")
        print("")


Measured memory_bytes: 26348
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <cmath>

using namespace std;
using ll = long long;
using ull = unsigned long long;

constexpr ll LLINF {1001002003004005006};//ll = 9*LLINF
constexpr int INTINF {1000000000};//int = 2*INTINF

#define  rep(i,n)   for(int i = 0; i < (n); ++i)
#define rrep(i,n)   for(int i = 1; i <= (n); ++i)
#define drep(i,n)   for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for(int i = s; i < t;  ++i)

template<typename T>
void maxs(T& x, T&& y) {
  x=std::max(x,y);
}
template<typename T>
void maxs(T& x, T& y) {
  x=std::max(x,y);
}

template<typename T>
void mins(T& x, T&& y) {
  x=std::min(x,y);
}
template<typename T>
void mins(T& x, T& y) {
  x=std::min(x,y);
}

int main() {
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
 
 int X;
 cin >> X;
 if (X == 3 || X == 5 || X==7) {
   cout << "YES\n";
  } else {
    cout << "NO\n";
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
	ll n, k;
	cin>>n>>k;
	vector<ll> arr(n);
	for(int i=0; i<n;i++)
	{
		cin>>arr[i];
	}
	vector<ll> next(n,-1);
	ll curr = 0;
	vector<ll> steps;
	while(next[curr]==-1)
	{
		next[curr] = arr[curr]-1;
		curr = next[curr];
		steps.push_back(curr);
	}
	ll cycle = curr;
	curr = next[cycle];
	ll len = 1;
	while(curr!=cycle)
	{
		curr = next[curr];
		++len;
	}
	ll withoutCycle = steps.size()-len;
	ll rem = (k-withoutCycle)%len;
	
	if(k<=steps.size())
		cout<<1+steps[k-1]<<"\n";
	else
	{
		curr = cycle;
		while(rem)
		{
			curr = next[curr];
			rem--;
		}
		cout<<1+curr<<"\n";
	}
}

Measured memory_bytes: 8416
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#define ll long long
using namespace std;

const int N=200005;

struct ST{
	int l,r;
	ll a,b;
}t[N<<2];
int n,T,p,x,y;
int a[N],b[N];

void update(int k){
	t[k].a=max(t[k<<1].a+t[k<<1|1].a,t[k<<1].b+t[k<<1|1].b);
	t[k].b=max(t[k<<1].a+t[k<<1|1].b,t[k<<1].b+t[k<<1|1].a);
}

void build(int k,int l,int r){
	t[k].l=l; t[k].r=r;
	if (l==r){
		t[k].a=1ll*a[l];
		t[k].b=1ll*b[l];
		return;
	}
	int mid=(l+r)>>1;
	build(k<<1,l,mid);
	build(k<<1|1,mid+1,r);
	update(k);
}

void modify(int k,int p){
	if (t[k].l==t[k].r){
		t[k].a=1ll*a[p];
		t[k].b=1ll*b[p];
		return;
	}
	int mid=(t[k].l+t[k].r)>>1;
	if (p<=mid) modify(k<<1,p);
	else modify(k<<1|1,p);
	update(k);
}

int main(){
	int i;
	scanf("%d%d",&n,&T);
	n<<=1;
	for (i=1;i<=n;i++) scanf("%d",&a[i]);
	for (i=1;i<=n;i++) scanf("%d",&b[i]);
	if (n==2){
		while (T--){
			scanf("%d%d%d",&p,&x,&y);
			a[p]=x; b[p]=y;
			printf("%d\n",a[1]+a[2]);
		}
		return 0;
	}
	build(1,2,n-1);
	while (T--){
		scanf("%d%d%d",&p,&x,&y);
		a[p]=x; b[p]=y;
		if (p>1&&p<n) modify(1,p);
		printf("%lld\n",t[1].a+1ll*(a[1]+a[n]));
	}
	return 0;
} 

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

struct node{
	struct node *right;
	struct node *left;
	struct node *parent;
	int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){


}

Node treeSearch(Node u, int k){


}

Node treeSuccessor(Node x){


}

void treeDelete(Node z){
	Node y; // node to be deleted
	Node x; // child of y



}

void insert(int k){
	Node y = NIL;
	Node x = root;
	Node z;

	z = (Node)malloc(sizeof(struct node));
	z->key = k;
	z->left = NIL;
	z->right = NIL;

	while(x != NIL){
		y = x;
		if(z->key < x->key)
			x = x->left;
		else
			x = x->right;
	}
	z->parent = y;
	if(y == NIL)
		root = z;
	else if(z->key < y->key)
		y->left = z;
	else
		y->right = z;


}

void inorder(Node u){
	if(u->left != NIL)
		inorder(u->left);
	printf(" %d",u->key);
	if(u->right != NIL)
		inorder(u->right);
}
void preorder(Node u){
	printf(" %d",u->key);
	if(u->left != NIL)
		preorder(u->left);
	if(u->right != NIL)
		preorder(u->right);
}


int main(){
	int n, i, x;
	char com[20];
	scanf("%d", &n);

	for ( i = 0; i < n; i++ ){
		scanf("%s", com);
		/*if ( com[0] == 'f' ){
		scanf("%d", &x);
		Node t = treeSearch(root, x);
		if ( t != NIL ) printf("yes\n");
		else printf("no\n");
		} else*/ if ( com[0] == 'i' ){
			scanf("%d", &x);
			insert(x);
		} else if ( com[0] == 'p' ){
			inorder(root);
			printf("\n");
			preorder(root);
			printf("\n");
		} /*else if ( com[0] == 'd' ){
		  scanf("%d", &x);
		  treeDelete(treeSearch(root, x));
		  }*/
	}

	return 0;
}

Measured memory_bytes: 24040
#include<iostream> 
#include<string> 
using namespace std;
int main()
{
	int n;
	cin >> n;
	string s,t;
	cin >> s  >> t;
	//w=""; 
	for(int i=0;i<n;i++){
		//w+=s[i]+t[i];
		cout <<s[i] <<t[i] ;
	}
	//cout <<w;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>

using namespace std;

int main() {

    // didn't hav to run b

    map<int, int> cnt;

    int n; 
    cin >> n;

    for (int i = 0; i < n; i++){
        int temp;
        cin >> temp;

        cnt[temp]++;
    }

    int res = 0;

    for ( auto it = cnt.begin(); it != cnt.end(); ++it  )
    {
        if (it->second % 2 != 0){
            res++;
        }
    }

    cout << res << endl;

    return 0;
}

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

int main(){
  ll x; cin>>x;
  for(int i=0;;++i){
    if(i!=0) ++x;
    ll sq=sqrt(x);
    bool f=1;
    for(int j=2; j<=sq; ++j){
      if(x%j==0){
        f=0;
        break;
      }
    }
    if(f==1) break;
  }
  cout<<x<<endl;
  return 0;
}


Measured memory_bytes: 256