akhauriyash/Code-Regression huggingface dataset:
#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
#include <cstdint>
using namespace std;
using LL = long long;

int N;
string S;
vector<int>A;
vector<int>imo[9];
vector<int>G[123456 * 3];
const LL MOD = 998244353;
int main() {
	cin >> N;
	cin >> S;
	map<pair<char, int>, int>H;
	H[{'R', 0}] = 0;
	H[{'R', 1}] = 1;
	H[{'R', 2}] = 2;
	H[{'G', 0}] = 3;
	H[{'G', 1}] = 4;
	H[{'G', 2}] = 5;
	H[{'B', 0}] = 6;
	H[{'B', 1}] = 7;
	H[{'B', 2}] = 8;
	for (int i = 0; i < 9; ++i)imo[i].resize(N * 4);
	map<char, vector<int>>mp;
	A.resize(3 * N);
	for (int i = 0; i < 3 * N; ++i) {
		mp[S[i]].push_back(i);
	}
	for (int i = 0; i < N; ++i) {
		vector < pair<int, int >> vec;
		vec.push_back({ mp['R'][i], 0 });
		vec.push_back({ mp['G'][i], 1 });
		vec.push_back({ mp['B'][i], 2 });
		sort(vec.begin(), vec.end());
		G[vec[0].first].push_back(vec[1].first);
		//G[vec[1].first].push_back(vec[2].first);
		G[vec[2].first].push_back(vec[1].first);
		for (int j = 0; j < 3; ++j) {
			A[vec[j].first] = j;
			imo[vec[j].second * 3 + j][vec[j].first + 1]++;
		}
	}
	for (int i = 0; i < 9; ++i) {
		for (int j = 0; j < 3 * N; ++j) {
			imo[i][j + 1] += imo[i][j];
		}
	}
	LL ans = 1;
	for (int i = 0; i < 3 * N; ++i) {
		for (int nxt : G[i]) {
			if (nxt > i) {
				auto& im = imo[H[{S[i], A[i]}]];
				LL cnt = im[nxt] - im[i];
				ans *= cnt;
				ans %= MOD;
			}
			else {
				auto& im = imo[H[{S[i], A[i]}]];
				LL cnt = im[i] - im[nxt] + 1;
				ans *= cnt;
				ans %= MOD;
			}
		}
	}
	for (int i = 1; i <= N; ++i) {
		ans *= i;
		ans %= MOD;
	}
	cout << ans << endl;
	return 0;
}

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

#define CH(N,A,B) (A<=N&&N<B)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define RREP(i,a,b) for(int i=(b-1);a<=i;i--)
#define F first
#define S second

using namespace std;

const long long INF = 1e18;

int N,M;
long long road[1010][1010];
/*重み1e2000000000のときは、つながっていない*/

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

  REP(i,0,N){
    REP(j,0,N){
      if(i==j) road[i][j] = 0;
      else road[i][j] = (-1)*INF;
    }
  }

  REP(i,0,M){
    int a, b, c;
    cin>>a>>b>>c;
    road[a-1][b-1] = c;
  }

  REP(k,0,N){
    REP(i,0,N){
      REP(j,0,N){
        road[i][j] = max(road[i][j],road[i][k] + road[k][j]);
      }
    }
  }
  if(road[N-1][N-1] > 0){
    cout<<"inf"<<endl;
    //return 0;
  }else{
    cout<<road[0][N-1]<<endl;
  }

  return 0;
}


Measured memory_bytes: 8192
#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll=long long;
using vi=vector<int>;
using vl=vector<long long>;
using pii=pair<int,int>;
using pll=pair<long long,long long>;
#define ITR(i,c) for(auto i=begin(c);i!=end(c);++i)
#define FORE(x,c) for(auto &x:c)
#define FOR(i,a,n) for(int i=a,i##_len=(int)(n);i<i##_len;++i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i=(int)(n);i>=0;--i)
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)   // c++14
#define SZ(c) ((int)c.size())
#define EXIST(c,x) (c.find(x)!=end(c))
#define dump(...)
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
#define INF (1001001001)
#define INFLL (1001001001001001001ll)
template<class T> ostream& operator << (ostream &os,const vector<T> &v) {
    ITR(i,v) os << *i << (i==end(v)-1 ? "" : " "); return os; }
template<class T> istream& operator >> (istream &is,vector<T> &v) {
    ITR(i,v) is >> * i; return is; }
template<class T> istream& operator >> (istream &is, pair<T,T> &p) {
        is >> p.first >> p.second; return is; }
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
//------------------------------------------------------------------------------
struct before_main_function {
    before_main_function() {
        #ifdef int
            #undef INF
            #define INF INFLL
            #define stoi stoll
        #endif
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
    }
} before_main_function;
//------------------------------------------------------------------------------

signed main() {
    int N,K;
    cin>>N>>K;
    vi a(N);
    cin>>a;

    vi sum(N,0),sum2(N,0);
    sum[0]=a[0];
    sum2[0]=max(0ll,a[0]);
    FOR(i,1,N) {
        sum[i]=sum[i-1]+a[i];
        sum2[i]=sum2[i-1]+max(0ll,a[i]);
    }

    int ans=0;
    REP(i,N-K+1) {
        int S=sum[i+K-1];
        if(i>0) S-=sum[i-1];
        if(S<0) S=0;
        int T=S+sum2[N-1]-sum2[i+K-1];
        if(i>0) T+=sum2[i-1];
        chmax(ans,T);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 2560
#pragma GCC optimize("O3")

#include "bits/stdc++.h"
#include "ext/pb_ds/tree_policy.hpp"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/rope"

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for(int i = 0; i < (a); ++i)
#define pb push_back
#define mp make_pair
#define sz(x) (int)x.size()
#define f first
#define s second

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

struct custom_hash 
{
    static uint64_t splitmix64(uint64_t x) 
    {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const 
    {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
int n, k;
vector<int> a;
vector<bool> w;
int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> k;
    a.assign(n, 0);
    w.assign(k + 1, false);
    F0R(i, n) cin >> a[i];
    sort(a.begin(), a.end());
    F0R(i, k + 1)
    {
        bool v = false;
        F0R(j, n)
        {
            if(i - a[j] < 0) continue;
            if(w[i - a[j]] == false) v = true;
        }
        w[i] = v;
    }
    cout << (w[k] ? "First" : "Second");
    return 0;
}

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

namespace ABC085D
{
    class Program
    {
        static void Main(string[] args)
        {
            var line1 = Console.ReadLine().Split().Select(long.Parse).ToArray();
            long N = line1[0];
            long H = line1[1];
            Katana[] katanas = new Katana[N];
            for(int i = 0; i < N; i++)
            {
                var line = Console.ReadLine().Split().Select(long.Parse).ToArray();
                katanas[i] = new Katana(line[0], line[1]);
            }

            long amax = katanas.Max(x => x.a);
            Katana[] b = katanas.Where(x => x.b >= amax).OrderByDescending(x => x.b).ToArray();
            long count = 0;
            foreach(Katana k in b)
            {
                H -= k.b;
                count++;
                if (H <= 0) break;
            }
            if (H > 0) count += (H-1) / amax + 1;

            Console.WriteLine(count);
            Console.ReadKey();
        }
    }

    class Katana
    {
        public long a;
        public long b;
        public Katana(long a, long b)
        {
            this.a = a;this.b = b;
        }
    }
}


Measured memory_bytes: 29116
N,M = map(int, input().split())

onazi = [[] for i in range(N+1)] 
chigau = [[] for i in range(N+1)]

def tuika(l,a,b):
    l[a].append(b)
    l[b].append(a)

for i in range(M):
    X,Y,Z = map(int, input().split())
    if Z%2 == 0:
        tuika(onazi, X, Y)
    else:
        tuika(chigau, X, Y)
        


colors = [0 for i in range(N+1)]

def func(i):
    stack = [i]
    colors[i] = 1

    while stack:
        node = stack.pop()
        for next_node in onazi[node]:
            if colors[next_node]==0:
                stack.append(next_node)
                colors[next_node] = colors[node]

        for next_node in chigau[node]:
            if colors[next_node]==0:
                stack.append(next_node)
                colors[next_node] = - colors[node]

result = 0
for i in range(1,N+1):
    if colors[i] == 0:
        result += 1
        func(i)
print(result)

Measured memory_bytes: 73504
#B - Resale(ABC125)
N=int(input())
V=list(map(int, input().split()))
C=list(map(int, input().split()))
M=[]
X=0
for i in range(N):
    M.append(V[i]-C[i])
for i in range(N):
    if M[i]>0:
        X+=M[i]
print(X)

Measured memory_bytes: 3060
/*
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif
// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
*/
#include <bits/stdc++.h>
using namespace std;

#define DEBUG(x) cout << #x << ": " << x << endl;
#define DEBUG_VEC(v)                                      \
  cout << #v << ":";                                      \
  for (int i = 0; i < v.size(); i++) cout << " " << v[i]; \
  cout << endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector<vector<int> >
#define vll vector<vector<ll> >
#define vs vector<string>
#define pii pair<int, int>
#define pis pair<int, string>
#define psi pair<string, int>
const int inf = 1000000001;
const ll INF = 1e18;
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout << setprecision(15) << fixed << p << endl;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dx2[8] = {1, 1, 0, -1, -1, -1, 0, 1}, dy2[8] = {0, 1, 1, 1, 0, -1, -1, -1};

int main(){
  int n, i, j;
  cin >> n;
  vector<pii> a(n);
  for (i = 0; i < n; i++){
    cin >> a[i].first;
    a[i].second = i;
  }
  sort(a.begin(), a.end());
  vi b(n);
  for (i = 0; i < n; i++){
    b[a[i].second] = i;
  }
  //DEBUG_VEC(b);
  int cnt = 0;
  for (i = 1; i < n; i += 2){
    if (b[i] % 2 == 0){
      cnt++;
    }
  }
  cout << cnt << endl;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL)
typedef long long ll;
typedef double dd;
#define pb push_back
#define mp make_pair
#define endl "\n"
#define M 1000000007
#define pi acos(-1)
/*ll power(ll a,ll b)
{
    ll res = 1;
    while(b > 0)
    {
        if(b & 1)
            res = (res*a)%M;
        a = (a*a)%M;
        b = b >> 1;
    }
    return res;
}*/
/*ll modinv(ll a)
{
   return power(a,M - 2); 
}*/
/*vector<ll> primes(ll n)
{
    bool *sieve = new bool[n + 1];
    ll i,j;
    vector<ll> v;
    for(i = 3; i <= n; i+=2)
        sieve[i] = true;
    sieve[2] = true;
    for(i = 3; i*i <= n; i+=2)
    {
        if(sieve[i])
            for(j = i*i; j <= n; j+=i)
                sieve[j] = false;
    }
    if(n >= 2)
    {
        v.pb(2);
        for(i = 3; i <= n; i+=2)
        {
            if(sieve[i])
                v.pb(i);
        }
    }
    return v;
}*/

/*class graph{
public:
    vector<ll> *g;
    ll n;
    graph(ll v)
    {
        n = v + 1;
        g = new vector<ll> [n];
    }
    void addegde(ll f,ll s)
    {
        g[f].pb(s);
        g[s].pb(f);
    }
    void dfs(bool *visited,ll sv)
    {
        visited[sv] = true;
        for(auto x: g[sv])
        {
            if(!visited[x])
            {
                dfs(visited,x);
            }
        }
    }
    void bfs(ll sv){
       queue<ll> q;
       bool visited[n] = {};
       q.push(sv);
       visited[sv] = true;
       while(!q.empty())
       {
           ll node = q.front();
           q.pop();
           for(auto x : g[node])
           {
               if(!visited[x])
               {
                   visited[x] = true;
                   q.push(x);
               }
           }
       }
    }
};*/
int main()
{
    fast;
    ll n,i;
    cin >> n;
    bool flag = true;
    map<ll,bool> m;
    for(i = 0; i < n; i++)
    {
        ll temp;
        cin >> temp;
        if(!m[temp])
            m[temp] = true;
        else
        {
            m[temp] = false;
            flag = false;
        }
    }
    if(flag)
        cout<<"YES"<<endl;
    else
        cout<<"NO"<<endl;
    return 0;
}



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



signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);
    
    string s;
    cin>>s;
    int n=s.size();
    bool pos = 1;
    if(n%2)pos=false;
    for(int i=0;i<n;i++){
        if(i%2==0 && s[i]!='h')pos=false;
        if(i%2 && s[i]!='i')pos=false;
    }
    if(pos){
        cout << "Yes\n";
    }
    else cout << "No\n";
    
}

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

using namespace std;

#define int long long 
#define endl '\n'
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define SIZE 100005

int32_t main()
{
	int n;
	cin >> n;
	int ans = 0;
	for(int i = 1 ;i <= n;i++)
	{
		int lo = i;
		int hi = (n/i) * i;
		int coun = hi/i - lo/i + 1;
		ans += (coun*(lo+hi))/2;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3580
#include <cstdio>
#include <cstring>

char s[200000],ap[30]={"abcdefghijklmnopqrstuvwxyz"};
int ap2[30];
int main()
{
    scanf("%s",&s);
    for(int i=0;i<strlen(s);i++)
    {
        for(int j=0;j<26;j++)
            if(s[i]==ap[j])
                ap2[j]=1;
    }
    for(int i=0;i<26;i++)
        if(ap2[i]==0)
        {
            printf("%c",ap[i]);
            return 0;
        }
    printf("None");
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
 
int p = 700;
string s;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin>>s;
	for(int i=0;i<3;i++){
		if(s[i] == 'o')
			p += 100;
	}
	cout<<p;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int scount = 0; int c; int count = 0;
  while((c = getchar()) != EOF) {
    if(c == 'S') {
    	scount++;
    } else if(c == 'T') {
      if(scount > 0) scount--;
      else count++;
    }
  }
  printf("%d\n", count + scount);
  return 0;
}

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

int main() {
  int a,b,c,d,e,time;
  cin>>a>>b>>c>>d>>e;
  if(d>=b) time=60*(c-a)+d-b;
  else time=60*(c-a-1)+d-b+60;
  cout<<time-e<<endl;
}

Measured memory_bytes: 3620
using System.Linq;
using System.Collections.Generic;
using System;

public class Hello
{
    public static void Main()
    {
        var sd = Console.ReadLine().Trim();
        var t = Console.ReadLine().Trim();
        var a = sd.ToCharArray();
        var tL = t.Length;
        var aL = sd.Length;
        var ss = new List<string>();
        for (int i = 0; i <= aL - tL; i++)
        {
            for (int j = 0; j < tL; j++)
                if (sd[i + j] != '?' && sd[i + j] != t[j]) goto next;
            ss.Add(createS(sd, t, i));
            next:;
        }
        Console.WriteLine(ss.Count() == 0 ? "UNRESTORABLE" : ss.OrderBy(x => x).First());
    }
    public static string createS(string sd, string t, int d)
    {
        var a = sd.ToCharArray();
        for (int i = 0; i < t.Length; i++) a[i + d] = t[i];
        return new string(a).Replace('?', 'a');
    }
}



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

signed main()
{
  int a, b, c;
  int d;
  cin >> a >> b >> c;
  
  if (a > b){
    d = a;
    a = b;
    b = d;
  }
  if (b > c){
    d = b;
    b = c;
    c = d;
  }
  if (a > b){
    d = a;
    a = b;
    b = d;
  }

  cout << a << " " << b << " " << c << endl;

  return (0);
}

Measured memory_bytes: 3072
// A.

#include <iostream>
#include <sstream>
#include <algorithm>

using namespace std;

int main(int argc, char* argv[]) {
	int r, g, b;
	cin >> r >> g >> b;
	int n = r * 100 + g * 10 + b;
	cout << (n % 4 ? "NO" : "YES") << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

int main(){
    Init();
    string s; cin >> s;
    set<char> st;
    ll n = s.size();
    rep(i, n) st.insert(s[i]);
    if(st.size() == 1){
        cout << 0 << endl;
        return 0;
    }
    
    ll ans = INFLL;
    for(auto c: st){
        ll cnt = 0;
        string t = s;
        while(t.size() > 1){
            bool chk = true;
            bool allSame = true;
            for(ll i=0; i<t.size()-1; i++){
                if(t[i] != c && t[i+1] == c){
                    t[i] = c;
                    chk = false;
                }
                if(t[i] != c) allSame = false;
            }
            if(t[t.size()-1] != c) allSame = false;
            t = t.substr(0, t.size()-1);
            if(!chk || !allSame) cnt++;
            else break;            
        }
        chmin(ans, cnt);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3620
n,m=map(int,input().split())
h=list(map(int,input().split()))
ab=[]
for i in range(n):
    ab.append(0)
for i in range(m):
    ai,bi=map(int,input().split())
    if h[ai-1]>=h[bi-1]:
        ab[bi-1]+=1
    if h[ai-1]<=h[bi-1]:
        ab[ai-1]+=1
print(ab.count(0))

Measured memory_bytes: 20108
N=input()
N=list(N)
Key=False
while Key==False:
    if N[0]==N[1] and N[1]==N[2]:
        break
    else:
        N=''.join(N)
        N=int(N)
        N+=1
        N=str(N)
        N=list(N)

N=''.join(N)
print(N)

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

struct Way {
    int from, to, distance;
};

int main()
{
    long long min_distances[300][300], sum{};
    std::vector<Way> a;
    int n;
    scanf("%d", &n);
    std::fill(min_distances[0], min_distances[0] + 90000, 2000000000);
    for (int i = 0; i < n; i++)
        min_distances[i][i] = 0;
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            int tmp;
            scanf("%d", &tmp);
            if (j <= i) continue;
            a.push_back((Way){i, j, tmp});
        }
    }
    std::sort(a.begin(), a.end(),[](const Way& s, const Way& t){ return s.distance < t.distance; });
    for (auto &e : a)
    {
        if (min_distances[e.from][e.to] < e.distance) break;
        if (min_distances[e.from][e.to] == e.distance)
            continue;
        sum += e.distance;
        for (int i = 0; i < n; i++)
            for (int j = 0; j < n; j++)
                min_distances[i][j] =
                    std::min(min_distances[i][j],
                        std::min(min_distances[i][e.to] + e.distance + min_distances[e.from][j],
                                min_distances[i][e.from] + e.distance + min_distances[e.to][j])
                );
    }

    for (auto &e : a)
    {
        if (min_distances[e.from][e.to] < e.distance)
        {
            printf("-1\n");
            return 0;
        }
    }
    printf("%lld\n", sum);

    return 0;
}

Measured memory_bytes: 1788
#include <iostream>
#include <vector>
#include <array>
#include <algorithm>
#include <cmath>
#include <queue>
#include <limits>
#include <map>
#include <cassert>
#include <iterator>
using namespace std;
using P = pair<int, int>;
using VI = vector<double>;
using VP = vector<P>;

void compress(VI& v) {
    assert(v.size() > 1);
    VI ret;
    ret.push_back(v[0]);
    ret.push_back(v[1]);
    for (int i = 2; i < v.size(); i++) {
        if (int(v[i]) != v[i]) {
            if (ret.back() == v[i] - 0.5) {
                ret.pop_back();
            } else {
                ret.push_back(v[i]);
            }
        } else {
            ret.push_back(v[i]);
        }
    }
    v = VI(ret);
}

int main() {
    int n, c;
    cin >> n >> c;
    vector<VI> v(c);
    for (int i = 0; i < n; i++) {
        int s, t;
        cin >> s >> t >> c;
        c--;
        v[c].push_back(s + 0.5);
        v[c].push_back(t);
    }
    for (int i = 0; i < v.size(); i++) {
        sort(v[i].begin(), v[i].end());
    }
    
    for (int i = 0; i < v.size(); i++) {
        if (v[i].size()) {
            compress(v[i]);
        }
    }
    int ans = 0;
    int cnt = 0;
    
    VP w;
    for (int i = 0; i < v.size(); i++) {
        for (auto j: v[i]) {
            if (int(j) != j) {
                w.push_back(P(j - 0.5, 0));
            } else {
                w.push_back(P(j, 1));
            }
        }
    }
    sort(w.begin(), w.end());
    
    for (auto p: w) {
        if (p.second == 0) {
            cnt++;
        } else {
            cnt--;
        }
        ans = max(ans, cnt);
    }
    cout << ans << endl;
}


Measured memory_bytes: 4600
#include <iostream>
#include <vector>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;

struct unionfind {
	vector<int> d;	// 親：連結のサイズ×(-1)、子：親のID（非負）
	unionfind(int n = 0): d(n, -1) {}
	int find(int x) {
		if(d[x] < 0) return x;
		return d[x] = find(d[x]);
	}
	bool unite(int x, int y) {
		x = find(x); y = find(y);
		if(x == y) return false;
		if(d[x] > d[y]) swap(x, y);
		d[x] += d[y];
		d[y] = x;
		return true;
	}
	bool same(int x, int y) { return find(x) == find(y); }
	int size(int x) { return -d[find(x)]; }
};

int main() {
	int n, m, k;
	cin >> n >> m >> k;
	unionfind uf(n);
	vector<vector<int>> friends(n), blocks(n);
	rep(i, m) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		friends[a].push_back(b);
		friends[b].push_back(a);
		uf.unite(a, b);
	}
	rep(i, k) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		blocks[a].push_back(b);
		blocks[b].push_back(a);
	}
	rep(i, n){
		int ans = uf.size(i) - 1 - friends[i].size();
		for(int u: blocks[i]) {
			if (uf.same(i, u)) ans--;
		}
		cout << ans << " ";
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 12152
#include<bits/stdc++.h>
using namespace std;
#define INF (1LL<<30)
#define DEKAI 1000000007
#define lp(i,n) for(int i=0;i<n;i++)
#define int long long


signed main(){
	int n;
	cin>>n;
	int a[100000];
	lp(i,n){
		cin>>a[i];
	}
	sort(a,a+n);
	n/=2;
	cout<<a[n]-a[n-1]<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<ctime>
#include<cstdio>
#include<string>
//#include<string>
//#include<sstream>
using namespace std;

int main()
{
	int w,a,b;
	scanf("%d%d%d",&w,&a,&b);
	int num=abs(a-b);
	num=num-w;
	if(num>=0){
		printf("%d\n",num);
	}
	else{
		printf("0\n");
	}
}

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

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

using ll = long long;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int INF = 1<<30;
const ll mod = 1000000007LL;

int main() {
  int N,M;
  cin>>N>>M;
  vector<map<int,bool>> g(N);
  for(int i = 0; i < M; i++){
    int x,y;
    cin>>x>>y;
    g[x-1][y-1]=true;
    g[y-1][x-1]=true;
  }
  vector<int> v(N-1);
  for(int i = 0; i < N-1; i++) v[i]=i+1;
  int ans = 0;
  do{
    for(int i = 0; i < N-1; i++){
      if(i==0){
        if(!g[0][v[i]]) break;
      }
      else {
        if(!g[v[i-1]][v[i]])break;
      }
      if(i==N-2) ans++;
    }
  }while(next_permutation(v.begin(),v.end()));
  cout<<ans<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String s = in.next();
        int same = 0;
        int diff = 0;
        for (int i = 1; i < s.length(); i++) {
            if (s.charAt(i) != s.charAt(i - 1)) {
                diff++;
            } else same++;
        }

        if (same == s.length() - 1) {
            System.out.println(0);
        } else System.out.println(diff);
    }
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef double dd;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;

const int mx=1e6+11;
const double PI = acos(-1);
#define MOD 1000000007

#define nl '\n'
#define pb push_back
#define F first
#define S second
#define I insert
#define mp make_pair

#define sz(x) x.size()
#define tt int t; cin>>t; while(t--)
#define be(a) (a).begin(),(a).end()
#define rbe(a) (a).rbegin(),(a).rend()
#define mem(a,b) memset(a,b,sizeof(a))
#define yes cout<<"YES"<<nl
#define no cout<<"NO"<<nl

#define su ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define frac cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);

template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p )
{
    return os << "(" << p.first << ", " << p.second << ")";
}

template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v )
{
    os << "{";
    for(auto it = v.begin(); it != v.end(); ++it)
    {
        if( it != v.begin() )
            os << ", ";
        os << *it;
    }
    return os << "}";
}

template < typename T >
ostream &operator << ( ostream & os, const set< T > &v )
{
    os << "[";
    for(auto it = v.begin(); it != v.end(); ++it)
    {
        if( it != v.begin() )
            os << ", ";
        os << *it;
    }
    return os << "]";
}

template < typename T >
ostream &operator << ( ostream & os, const multiset< T > &v )
{
    os << "[";
    for(auto it = v.begin(); it != v.end(); ++it)
    {
        if( it != v.begin() )
            os << ", ";
        os << *it;
    }
    return os << "]";
}

template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v )
{
    os << "[";
    for(auto it = v.begin(); it != v.end(); ++it)
    {
        if( it != v.begin() )
            os << ", ";
        os << it -> first << " = " << it -> second ;
    }
    return os << "]";
}

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)

void faltu ()
{
    cerr << endl;
}

template <typename T>
void faltu( T a[], int n )
{
    for(int i = 0; i < n; ++i)
        cerr << a[i] << ' ';
    cerr << endl;
}

template <typename T, typename ... hello>
void faltu( T arg, const hello &... rest)
{
    cerr << arg << ' ';
    faltu(rest...);
}


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)));
}

void f()
{
    int n,k,cnt=0,a;
    cin>>n>>k;
    for(int i=0; i<n; i++)
    {
        cin>>a;
    }
    for(int i=0;i<n;i+=k-1)
    {
      if(i==n-1)
        break;
      cnt++;
    }
    cout<<cnt<<nl;
}

int main()
{
    su;
    f();
    return 0;
}


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

#include <algorithm>
int main()
{
    int n;
    cin>>n;
    vector <int> a(n);
    rep(i,n)
    {
        cin>>a[i];
    }
    int min_count=10010;
    for(int i=0;i<n;i++)
    {
        bool flag = 1;
        int count=0;
        while(flag)
        {   
            if(a[i]%2==0)
            {
                a[i]/=2;
                count++;
            }
            else
            {
                flag = false;
            }
        }
        min_count = min(min_count,count);
    }
    cout<<min_count<<endl;
    return 0;

}

Measured memory_bytes: 3608
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << endl;}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << endl;
}
const int mod = 1e9 + 7;

int main(){
	double l; cin >> l;
	l = l / (double)3;
	double ans = l * l * l;
	printf("%.10f\n",ans);
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
 
  char S[100]={"0"};
  int N=0;
  int count=0;
  scanf("%d",&N);
  scanf("%s",S);
  
  for(int i=0;i<N;i++){
  	if(S[i]=='A'&&S[i+1]=='B'&&S[i+2]=='C'){
    	count++;
    }
  }
  
  printf("%d",count);
 
 
 return 0;
}

Measured memory_bytes: 128
parseInt(x) = parse(Int, x)
parseFloat(x) = parse(Float64, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
function main()
    s=chomp(readline())
    n=length(s)
    ans=10^9
    for i in 1:n-3+1
        ans=min(ans,abs(753-parseInt(s[i:i+2])))
    end
    println(ans)
end
main()

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

typedef long long ll;
typedef vector<ll> vll;
typedef vector<int> vi;
const ll MOD = 1e9 + 7;
const int maxn = 1e6 + 10;

struct edge {
    int s;
    int e;
    int w;
    edge(int s, int e, int w) {
        this->s = s;
        this->e = e;
        this->w = w;
    }
};

int main() {
    int L;
    cin >> L;
    vector<edge> graph;
    int r = log2(L);
    int n = r + 1;
    int x = 1;
    for (int i = 1; i < n; ++i) {
        graph.push_back(edge(i, i + 1, 0));
        graph.push_back(edge(i, i + 1, x));
        x <<= 1;
    }
    int w = 0;
    while (L & (x - 1)) {
        L = L & (x - 1);
        w += x;
        r = log2(L);
        graph.push_back(edge(r + 1, n, w));
        if (r <= 0) break;
        x = 1 << r;
    }
    cout << n << " " << graph.size() << endl;
    for (auto& e : graph) {
        cout << e.s << " " << e.e << " " << e.w << endl;
    }
    return 0;
}

static int speedUp = []() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    return 0;
}();

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

using namespace std;

int main(){
    string s,t;
    cin >> s >> t;
    int tL=t.length();
    int sL=s.length();
    int ans=tL;

    for(int i=0;i<sL-tL+1;i++){
        int num=0;
        for(int j=0;j<tL;j++){
            if(s[i+j]!=t[j]) num++;
        }
        if(ans>num) ans=num;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define all(c) c.begin(),c.end()
#define init(c) memset(c,0,sizeof c)
#define S second
#define F first
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
const int N=20000005;
int n,k,x,t,a,b,m,c,d;
string s;
vi v;
int main(){

	cin >> a >> b >> c >> d;
	int x = 1;
	while(true){
		if(x){
			c-=b;
			if(c<=0){
				cout << "Yes";
				return 0;
			}
		}else{
			a-=d;
			if(a<=0){
				cout << "No";
				return 0;
			}
		}
		x^=1;
	}

	
	return 0;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<int,int> ii;
typedef pair<ii,int> iii;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define RST(i,n) memset(i,n,sizeof i)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(),a.end()
#define X first
#define Y second
#define eb emplace_back
#ifdef cold66
#define debug(...) do{\
    fprintf(stderr,"LINE %d: (%s) = ",__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<", ";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // cold66
//}
template<class T> inline bool chkmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, true : false; }

const ll MAXn=3e5+5,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=0x3f3f3f3f;

int zkw[MAXn*2];
int n,m,k;
ii d[MAXn];
void build(){
	for (int i=m-1; i>0; i--) {
		zkw[i] = max(zkw[i<<1],zkw[i<<1|1]);
	}
}

void modify(int pos, int value) {
	for (zkw[pos+=m]+=value; pos>1; pos>>=1) {
		zkw[pos>>1] = max(zkw[pos],zkw[pos^1]);
	}
}

int query(int l, int r) {
	int ret = -0x3f3f3f3f;
	for (l+=m, r+=m; l<r; l>>=1, r>>=1) {
		if (l&1) ret = max(ret,zkw[l++]);
		if (r&1) ret = max(ret,zkw[--r]); 
	}
	return ret;
}


int main(){
    IOS();
    cin >> n >> m >> k;
    for (int i=0;i<k;++i) {
        debug("HI");
        cin >> d[i].X >> d[i].Y;
        d[i].X--, d[i].Y--;
        zkw[d[i].Y+m]++;
    }
    sort(d,d+k);
    build();
    debug("ALIVE"); 
    int ans = 0;
    for (int i=0;i<k;++i) {
        debug(d[i]);
        int idx = i;
        while (idx < k && d[idx].X == d[i].X) {
            idx++;
        }
        for (int j=i;j<idx;++j) {
            modify(d[j].Y,-1);
        }
        ans = max(ans,idx-i + query(0,m));
        for (int j=i;j<idx;++j) {
            modify(d[j].Y,1);
        }
        i = idx-1;
    }
    cout << ans << endl;
}


Measured memory_bytes: 8296
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define pi 3.141592653589793
using namespace std;



int main() {
//    cout << setprecision(10);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    ll n;
    cin >> n;
    ll ans = n - 1;
    for (ll i = 1; i <= 1000000; i++) {
        if (n % i == 0) {
            ll j = n / i;
            ans = min(ans, i + j - 2);
        }
    }

    cout << ans;

}





Measured memory_bytes: 256
//inlclude前用define 
#define _USE_MATH_DEFINES

//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<type_traits>
#include<numeric>
//#include<deque>
#include<iomanip>
#include<set>
#include<tuple>
#include<map>

using namespace std;

//typedef
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef long long int ll;

//define
#define INF 1e9 
#define NUM 1000000007
#define all(x) begin(x), end(x)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
int dp[110][10010]={}; //[v][w]

int main() {
    int a,b,c;
    cin>>a>>b>>c;

    cout<<min({a+b,b+c,c+a})<<endl;
}



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

int main() {
  int N,X,Y;
  cin >> N >> X >> Y;
  vector<int> cnt(N);
  
  for(int i=1;i<N;i++){
    for(int j=i+1;j<=N;j++){
      int k;
      k=min(j-i,min(abs(i-X)+abs(j-Y)+1,abs(i-Y)+abs(j-X)+1));
      cnt[k]++;
    }
  }
    for(int i=1;i<N;i++){
      cout << cnt[i] << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <stdio.h>

using namespace std;

int main()
{
	char s;
	cin >> s;
	if (s == 'a' || s == 'i' || s == 'e' || s == 'o' || s == 'u')
		cout << "vowel";
	else
		cout << "consonant";
}

Measured memory_bytes: 256
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
L = [-1 for _ in range(N)]
R = [-1 for _ in range(N)]

for i in range(N):
  L[i] = A[i] - i-1
  R[i] = A[i] + i+1

# L = -R となる物のうち、i>jになりゃいいんだけど、最後にいくつかで破れば良い気がす
# i > 0 なので、自分自身を２回選んでL＝Rみたいにはならない・・・？

LC = Counter(L)
RC = Counter(R)

ans = 0
for k,v in LC.items():
  if (-1) * k in RC:
    ans += v * RC[(-1)*k]
    #print(k,v,(-1)*k,RC[(-1)*k], ans)
print(ans)



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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define repr(i,n) for(int i=(int)(n-1);i>=0;i--)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout << #x" = " << x << endl
#define print(x) cout << x << endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<int, P> PIP;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;
typedef set<int> S;

#define INF INT_MAX/3
#define MAX_N 1000000001

char c[1000000];

string rec(string s, int v) {
    int i = 0, tmp = 1;
    string original = "";
    while(i < s.length() && original.length() < v) {
        if ('0' <= s[i] && s[i] <= '9') {
            tmp = 0;
            while(i < s.length() && '0' <= s[i] && s[i] <= '9') {
                tmp = tmp * 10 + (s[i] - '0');
                i++;
            }
            i--;
        } else if (s[i] == '(') {
            int flag = 1, j = i + 1;
            while(j < s.length() && flag > 0) {
                if (s[j] == '(') flag++;
                else if (s[j] == ')') flag--;
                j++;
            }
            j--;
            string sub = rec(s.substr(i + 1, j - i - 1), v);
            rep(j, tmp) {
                if (original.length() + sub.length() < v) {
                    original += sub;
                } else {
                    original += sub.substr(0, v - original.length());
                    break;
                }
            }
            tmp = 1;
            i = j;
        } else if ('A' <= s[i] && s[i] <= 'Z') {
            rep(j, tmp) {
                if (original.length() >= v) break;
                original += s[i];
            }
            tmp = 1;
        }
        i++;
    }
    return original;
}


int main(){
    cin.sync_with_stdio(false);
    string s;
    int i;
    while(cin >> s >> i, s[0] != '0') {
     string ans = rec(s, i + 1);
     if (ans.length() - 1 < i) cout << 0 << endl;
     else cout << ans[i] << endl;
 }

 return 0;
}

Measured memory_bytes: 7852
#include<iostream>
#define ll long long
using namespace std;
int main(){
	ll a,b,x,ans;
	cin>>a>>b>>x;
	if(a%x==0||b%x==0)
		ans=(b-a)/x+1;
	else{
		a-=a%x;
		b=b-b%x+x;
		ans=(b-a)/x-1;
	}
	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
write = sys.stdout.write
# template


def solve():
    ofs = 6400
    h, w = map(int, readline().split())
    A = [list(map(int, readline().split())) for i in range(h)]
    B = [list(map(int, readline().split())) for i in range(h)]
    dp = [0 for _ in range(w+1)]
    x = abs(A[0][0]-B[0][0])
    dp[0] = 1 << ofs

    for i in range(h):
        for j in range(w):
            x = abs(A[i][j]-B[i][j])
            t = (dp[j] | dp[j-1])
            dp[j] = ((t << x) | (t >> x))

    b = list(map(lambda s: s == '1', list(bin(dp[w-1])[-ofs-1:-ofs+100])))
    for i, s in enumerate(b):
        if(s):
            print(i)
            return


if __name__ == "__main__":
    solve()


Measured memory_bytes: 43248
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i,n,m) for(int i=(n);i<(m);i++)
#define REP(i,n) FOR(i,0,n)
ll t[101];

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

// 最小公倍数
ll lcm(ll a,ll b){
  ll g = gcd(a,b);
  return a / g * b;
}

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

  ll ans = t[0];
  for(int i=1;i<n;i++){
    ans = lcm(ans , t[i]);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        Set<Integer> set = new HashSet<Integer>();
        List<Integer> list = new ArrayList<Integer>();
        
        while (n-- > 0) {
            int num = sc.nextInt();
            if (set.contains(num)) {
                list.add(num);
                set.remove(num);
            } else {
                set.add(num);
            }
            
        }
        if (list.size() < 2) {
            System.out.println("0");
            return;
        }
        list.sort(Comparator.reverseOrder());
        
        long answer = (long)list.get(0) * list.get(1);
        
        System.out.println(answer);
    }
}

Measured memory_bytes: 61212
#include<iostream>
#include<algorithm>
using namespace std;
int N,K;
int dp[61][61][3001];
int a[60],r[60],b[60];
main()
{
	cin>>N>>K;
	int sa=0;
	for(int i=0;i<N;i++)
	{
		cin>>a[i];
		sa+=a[i];
	}
	sort(a,a+N);
	reverse(a,a+N);
	int sr=0;
	for(int i=0;i<K;i++)
	{
		cin>>r[i];
		sr+=r[i];
	}
	sort(r,r+K);
	reverse(r,r+K);
	int sb=0;
	for(int i=0;i<K;i++)
	{
		cin>>b[i];
		sb+=b[i];
	}
	sort(b,b+K);
	reverse(b,b+K);
	for(int i=0;i<=N;i++)for(int j=0;j<=K;j++)for(int k=0;k<=3000;k++)dp[i][j][k]=1e9;
	dp[0][0][0]=0;
	for(int i=0;i<N;i++)for(int j=0;j<K;j++)for(int k=0;k<=3000;k++)
	{
		if(dp[i][j][k]==1e9)continue;
		dp[i+1][j+1][k+a[i]]=min(dp[i+1][j+1][k+a[i]],dp[i][j][k]+(a[i]>r[j]?a[i]-r[j]:0));
		dp[i+1][j][k]=min(dp[i+1][j][k],dp[i][j][k]+(a[i]>b[i-j]?a[i]-b[i-j]:0));
	}
	int ans=1e9;
	for(int j=0;j<=K;j++)for(int k=0;k<=3000;k++)
	{
		if(dp[N][j][k]==1e9)continue;
		if(k<=sr&&sa-k<=sb)ans=min(ans,dp[N][j][k]);
	}
	cout<<(ans<1e9?ans:-1)<<endl;
}



Measured memory_bytes: 46764
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <climits>
#include <cfloat>

using namespace std;
using ll = long long int;

const ll MOD = 1000000007;

template <typename T>
int cin_vec(vector<T> &vec) {
    for (auto &i : vec) {
        cin >> i;
    }
    return 0;
}

template <typename T>
int cout_vec(vector<T> vec, bool insertNewLine = true) {
    if (insertNewLine) {
        for (const auto &i : vec) {
            cout << i << endl;
        }
    } else {
        for (const auto &i : vec) {
            cout << i << flush;
        }
    }
    return 0;
}

template <typename T>
ll min_vec(std::vector<T> vec) {
    auto iter = min_element(vec.begin(), vec.end());
    ll index = distance(vec.begin(), iter);
    return index;
}

template <typename T>
ll max_vec(std::vector<T> vec) {
    auto iter = max_element(vec.begin(), vec.end());
    ll index = distance(vec.begin(), iter);
    return index;
}

int main() {
    char b;
    cin >> b;
    switch (b) {
    case 'A':
        cout << "T" << endl;
        break;
    case 'C':
        cout << "G" << endl;
        break;
    case 'G':
        cout << "C" << endl;
        break;
    case 'T':
        cout << "A" << endl;
        break;
    default:
        break;
    }
    return 0;
}


Measured memory_bytes: 256
for _ in range(3):
    t=list(map(int,input().split()))
    tt=(t[3]-t[0])*3600+(t[4]-t[1])*60+t[5]-t[2]
    h,tt=divmod(tt,3600)
    m,s=divmod(tt,60)
    print(h,m,s)

Measured memory_bytes: 7600
#include<stdio.h>
int main(void){
    int min,mid,max,result,n,x;
    while(1){
        result = 0;
        scanf("%d %d", &n, &x);
        if(n == 0 && x == 0) break;
        for (min = 1; min < n-1; min++){
            for(mid = min + 1; mid < n; mid++){
                max = x - (min + mid);
                if(mid < max && max <= n) result++;
            }
        }
        printf("%d\n", result);
    }


    return 0;
}


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

using namespace std;


void solve() {
    int p; cin >> p;
    vector<int> a(p);
    for (auto& x: a) {
        cin >> x;
    }
    vector<int> res(p, 0);
    for (int i = 0; i < p; i++) {
        if (a[i] == 0) continue;
        vector<int> wil(p, 0);
        wil[p-1] = -1;
        if (i == 0) wil[0] = 1;
        else {
            for (int k = p-2; k >= 1; k--) {
                wil[k] = (wil[k+1] * i) % p;
            }
        }
        for (int k = 0; k < p; k++) {
            res[k] = (res[k] + wil[k]) % p;
        }
    }
    res[0] = a[0];
    for (int k = 0; k < p; k++) {
        res[k] = (res[k] + p) % p;
        cout << res[k] << ' ';
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


Measured memory_bytes: 256