akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using Library;
using System.Numerics;
using static Library.Input;

namespace AtCoderTemplate
{
    class ProgramC
    {
        static void Main()
        {
            long a = NextLong;
            decimal b = decimal.Parse(NextWord());

            System.Console.WriteLine(new BigInteger(b * a));
        }
    }
}

namespace Library
{
    class Input
    {
        static IEnumerator<string> enumerator = new string[] { }.AsEnumerable().GetEnumerator();

        public static string Line => Console.ReadLine();

        public static string[] StrArr => Line.Split(' ');

        public static int NextInt => int.Parse(NextWord());

        public static long NextLong => long.Parse(NextWord());

        public static List<int> IntList => StrArr.Select(int.Parse).ToList();

        public static List<long> LongList => StrArr.Select(long.Parse).ToList();

        public static IEnumerable<long[]> TakeLine(int N)
        {
            return Enumerable.Repeat(0, N).Select(_ => Console.ReadLine().Split(' ').Select(long.Parse).ToArray());
        }

        public static string NextWord()
        {
            while (!enumerator.MoveNext())
            {
                enumerator = StrArr.AsEnumerable().GetEnumerator();
            }
            return enumerator.Current;
        }
    }
}


Measured memory_bytes: 28072
#include<bits/stdc++.h>
using namespace std;
const int INF = 1e8;
int main() {
	
	int n;
	cin >> n;
	vector<int> l,a(n);
	for(int i=0; i<n; i++) cin >> a.at(i); 
	for(int i=0; i<n; i++){
		if(i==0) l.push_back(a.at(i));
		else {
			if(l.back()<a.at(i)) l.push_back(a.at(i));
			else{
				auto it = lower_bound(l.begin(),l.end(),a.at(i));
				*it = a.at(i);
			}
		}
		
	}
	cout << l.size() << endl;
	
}


Measured memory_bytes: 3828
#pragma warning disable

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using System.Text.RegularExpressions;
using System.Diagnostics;
using System.Numerics;
using System.Collections;
using System.Timers;

static class MainClass
{
    public static void Main(string[] args)
    {
        
        var N = Console.ReadLine().ToInt32();

        var edge = new List<Edge>[N];
        for (int i = 0; i < N; i++)
        {
            edge[i] = new List<Edge>();
        }
        for (int i = 0; i < N - 1; i++)
        {
            var abc = Console.ReadLine().SplittedStringToInt32List();
            var a = abc[0] - 1;
            var b = abc[1] -1 ;
            var c = abc[2];
            edge[a].Add(new Edge() { To = b, Cost = c });
            edge[b].Add(new Edge() { To = a, Cost = c });
        }
        
        var QK = Console.ReadLine().SplittedStringToInt32List();
        var Q = QK[0];
        var K = QK[1] - 1;

        var queue = new Queue<Point>();
        queue.Enqueue(new Point() { CostFromStart = 0, Number = K });
        var costs = new long[N];
        
        while (queue.Count() != 0)
        {
            var item = queue.Dequeue();
            foreach (var item2 in edge[item.Number])
            {
                if (costs[item2.To] != 0)
                    continue;
                costs[item2.To] += item2.Cost + costs[item.Number];
                var p = new Point() { Number = item2.To, CostFromStart = costs[item2.To] };
                queue.Enqueue(p);
            }
        }
        for (int i = 0; i < Q; i++)
        {
            var str = Console.ReadLine().SplittedStringToInt32List();
            var x = str[0] -1 ;
            var y = str[1] -1;
            Console.WriteLine(costs[x] + costs[y]);
        }

        Console.ReadLine();
    }

    public class Edge
    {
        public int To;
        public int Cost;
    }

    public class Point
    {
        public int Number;
        public long CostFromStart;
    }

    #region ライブラリ
    public static long ToInt64(this string str) => long.Parse(str);
    public static int ToInt32(this string str) => int.Parse(str);
    public static BigInteger ToBigInteger(this string str) => BigInteger.Parse(str);
    public static List<string> SplittedStringToList(this string str) => str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToList();
    public static List<int> SplittedStringToInt32List(this string str) => str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(x => int.Parse(x)).ToList();
    public static List<BigInteger> SplittedStringToBigInteger(this string str) => str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(x => BigInteger.Parse(x)).ToList();

    public const int INF = int.MaxValue / 2;
    #endregion
}


Measured memory_bytes: 41972
# -*- coding: utf-8 -*-
"""
Created on Mon Jan 27 23:19:24 2020

@author: H_Hoshigi
"""

import fractions

N = int(input())
T_list = []
for i in range(N):
    T_list.append(int(input()))

LCM = T_list[0]

for i in T_list:
    GCD = fractions.gcd(LCM, i)
    LCM = (LCM * i)//GCD

print(LCM)



Measured memory_bytes: 5048
#include <bits/stdc++.h>
#include <vector>
#include <string>

using namespace std;

vector<string> split(const string &s, char delim) {
  vector<string> elems;
  string item;
  for (char ch: s) {
    if (ch == delim) {
      if (!item.empty()) {
        elems.push_back(item);
      }
      item.clear();
    }
    else {
      item += ch;
    }
  }
  if (!item.empty()) {
    elems.push_back(item);
  }
  return elems;
}

string to_str_with_zero(int i, int w) {
  ostringstream sout;
  sout << std::setfill('0') << std::setw(w) << i;
  string s = sout.str();
  return s;
}

int letter_to_int(char c) {
  return tolower(c) - 'a';
}

bool array_equal(vector<int> a1, vector<int>a2) {
  if (a1.size() != a2.size()) {
    return false;
  }
  for (int i=0; i<a1.size(); i++) {
    if (a1.at(i) != a2.at(i)) {
      return false;
    }
  }
  return true;
}

int gcd(int a, int b) {
  if (a == b) {
    return a;
  }
  else if (a > b) {
    return gcd(a - b, b);
  }
  else {
    return gcd(a, b - a);
  }
}

char int_to_char(int a) {
  if (a == -1) {
    return 'z';
  }
  else {
    return 'a' + a;
  }
}

long nCr(int n, int r) {
    long ans = 1;
    for (int i = n; i > n - r; --i) {
        ans = ans*i;
    }
    for (int i = 1 ; i < r + 1; ++i) {
        ans = ans / i;
    }
    return ans;
}

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
}

int divide_count(int a, int divider) {
  int r = 0;
  while(a % divider == 0) {
    a /= divider;
    r++;
  }
  return r;
}

int main() {
  std::cout << std::setprecision(9);
  int n;
  cin >> n;
  vector<long> nums(n + 1, 1);

  long ans = 1;
  for(int i=2; i<=n; i++) {
    if(nums.at(i) == 1) {
      ans += 2 * i;
      for(int j=2 * i; j<=n; j+=i) {
        nums.at(j) *= divide_count(j, i) + 1;
      }
    }
    else {
      ans += nums.at(i) * i;
    }
  }
  cout << ans << endl; 
}

Measured memory_bytes: 81404
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define rrep(i,n) for(int i=(int)n-1;i>=0;--i)
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T& a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U& u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U& u,const V... v){for(auto& e:u)fill_v<T>(e,v...);}

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

    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    int ans = 0;
    int mn = 1001001001;
    rep(i, n) {
        if (a[i] <= mn) ans++;
        chmin(mn, a[i]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 3996
//#include <tourist>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <iomanip>
#include <limits>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <tuple>
#include <deque>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <utility>
#include <complex>
#include <functional>
using namespace std;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
//setprecision(15)有効数字15桁
//-std=c++14
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b)
{
    return a * b / gcd(a, b);
}
struct edge {
    int to, cost;
};
int n;
int a[300][300];
int d[300][300];
void warshall_floyd(int n) {
  for (int k = 0; k < n; k++){       // 経由する頂点
    for (int i = 0; i < n; i++) {    // 始点
      for (int j = 0; j < n; j++) {  // 終点
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
      }
    }
  }
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;

    for (int i = 0; i < n; i++)
    {
        for(int j=0;j<n;j++){
            cin>>a[i][j];
            d[i][j]=a[i][j];
        }
    }
    
    ll ans=0;
    vector<bool> used(n*n,false);
    warshall_floyd(n);
    for (int i = 0; i < n; i++)
    {
        for(int j=i;j<n;j++){
          ans+=d[i][j];
            if(a[i][j]>d[i][j]){
              return cout<<-1<<"\n",0;
            }
        }
    }
    //cout << ans << "\n";
  for(int i=0;i<n;i++){
    for(int j=i;j<n;j++){
      if(i==j) continue;
      for(int k=0;k<n;k++){
        if(j==k||i==k) continue;
        if(d[i][k]+d[k][j]==d[i][j]){
          ans-=d[i][j];
          break;
        }
      }
    }
  }
    cout << ans << "\n";
}



Measured memory_bytes: 1024
import sys
from math import pi, cos, sqrt
from collections import defaultdict
readline = sys.stdin.buffer.readline
#sys.setrecursionlimit(10**8)


def geta(fn=lambda s: s.decode()):
    return map(fn, readline().split())


def gete(fn=lambda s: s.decode()):
    return fn(readline().rstrip())


def main():
    a, b, h, m = geta(int)

    ta = (h + m / 60) / 12 * 2 * pi
    tb = m / 60 * 2 * pi

    dist2 = a**2 + b**2 - 2 * a * b * cos(ta - tb)

    print(sqrt(dist2))


if __name__ == "__main__":
    main()

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

 
using namespace std;
 

 
int main()
{
    int n;
    cin >> n;
    int p[n];
    for (int i = 0; i < n; i++)
    {
        cin >> p[i];
    }
    sort(p,p+n);
    int ans = p[n-1]/2;

    for (int i = n-2; i >= 0; i--)
    {
        ans += p[i];
    }
    
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
//1は灰色２は茶色３は緑色４は水色
//５は青色６は黄色７は橙色８は赤色９は自由


#include <stdio.h>

int main(void)
{
	int ninzuu;
	int reto[4801];
	int i; /*繰り返し*/
	int iro[5000] = {0};
	int saisyou = 0;
	int saidai;
	
	scanf("%d",&ninzuu);
	
	for (i = 0;i < ninzuu;++i){
		scanf("%d",&reto[i]);
		if(reto[i] >= 1 && reto[i] <= 399){
			iro[1]++;
		}
		else if (reto[i] >= 400 && reto[i] <= 799){
			iro[2]++;
		}
		else if (reto[i] >= 800 && reto[i] <= 1199){
			iro[3]++;
		}
		else if (reto[i] >= 1200 && reto[i] <= 1599){
			iro[4]++;
		}
		else if (reto[i] >= 1600 && reto[i] <= 1999){
			iro[5]++;
		}
		else if (reto[i] >= 2000 && reto[i] <= 2399){
			iro[6]++;
		}
		else if (reto[i] >= 2400 && reto[i] <= 2799){
			iro[7]++;
		}
		else if (reto[i] >= 2800 && reto[i] <= 3199){
			iro[8]++;
		}
		else if(reto[i] >= 3200){
			iro[9]++;
		}
	}
	for(i = 1;i < 9;++i){
		if(iro[i] > 0){
			saisyou++;
		}
	}
	saidai = saisyou + iro[9];
	
	if(saisyou == 0){
		saisyou++;
	}
	
	printf("%d %d\n",saisyou,saidai);
	
	return(0);
}

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

using namespace std;
typedef long long ll;

const int N = 1e5 + 5 , OO = 0x3F3F3F3F;

int n , k , dp[N][3];
vector < int > a;

bool solve(int rem , bool p){ // rem = 100000 , 0

    //puts("beep beeep");
    if(rem < 0) return p;
    if(rem == 0) return !p;


    int& ret = dp[rem][p];
    if(~ret) return ret;

    //ret = 0;
    for(int i = 0 ; i < n ; ++i)
        if(solve(rem-a[i] , !p) == p)
            return ret = p;

    return ret = !p;


}


int main()
{


    scanf("%d %d",&n,&k);
    a.resize(n);
    for(int& x : a)
        scanf("%d",&x);
    /*if(n == 1){
        puts("Second");
        return 0;
    }
    */
    memset(dp , -1 , sizeof dp);
    bool ans = solve(k , 0);
    puts(ans ? "Second" : "First");



    return 0;
}


Measured memory_bytes: 9216
#include<stdio.h>
#include<string.h>
 
int main(){
  long a, b, r, x, tmp, e;
 
 
  e = scanf("%ld %ld", &a, &b);
 
  if (e==-1)
  {
    printf("%ld %ld",a,b);
  }
  
  x = a * b;
 
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }
 
  r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
 
  printf("%ld", x/b);
 
  return 0;
 
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <functional>
#include <ctime>
#include <cmath>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iomanip>
#include <float.h>
#include <math.h>
using namespace std;
using ll = long long;
unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

ll ll_gcd(ll a, ll b) {
    if (a < b) return ll_gcd(b, a);
    ll r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

class UnionFind {
public:
    vector <ll> par;
    vector <ll> siz;
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    ll root(ll x) {
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

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

    ll size(ll x) {
        return siz[root(x)];
    }
};

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

int main() {
    ll d;
    cin >> d;
    vector<ll> z(d);
    for (int i = 0; i < d; i++) {
        cin >> z[i];
    }
    vector<vector<ll>> x(d, vector<ll>(26));
    for (int i = 0; i < d; i++) {
        for (int j = 0; j < 26; j++) {
            cin >> x[i][j];
        }
    }
    vector<ll> ans(d);
    for (int j = 0; j < d; j++) {
        ll mx = 0;
        ll atai = 0;
        for (int k = 0; k < 26; k++) {
            mx = max(x[j][k], mx);
            if (mx == x[j][k])atai = k;
        }
        ans[j] = atai+1;
    }
    for (int i = 0; i < d; i++) {
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 3724
// #pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
#define String std::string
#define fir first
#define sec second
#define mp std::make_pair
#define Pair std::pair<int, int>
#define Map std::map< int, int >
#define Vector std::vector<int>

typedef long long ll;
typedef unsigned long long ull;

const int N = 100000 + 5;
const int M = 3000 + 5;
const int MOD = 1e9 + 7;
const int inv2 = 500000004;
const int dx[] = { 0, 1, -1, 0, 1, -1, 1, -1 };
const int dy[] = { 1, 0, 0, -1, 1, -1, -1, 1 };

template<class T>
inline T readT() {
    T res = 0, f = 1;
    char ch = getchar();
    for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;
    for (; isdigit(ch); ch = getchar()) res = (res << 1) + (res << 3) + ch - '0';
    return res * f;
}
#define read readT<int>

int n, min = INT_MAX, cnt;
ll sum;
int a[N];

int main() {
    std::cin >> n;
    for (int i = 1; i <= n; i++) {
        scanf("%d", &a[i]);
        sum += std::abs(a[i]);
        cnt += a[i] < 0;
        min = std::min(min, std::abs(a[i]));
    }
    if (!min || !(cnt % 2)) {
        printf("%lld\n", sum);
    } else {
        printf("%lld\n", sum - 2ll * min);
    }
    return 0;
}

Measured memory_bytes: 640
def readinput():
    n=input()
    return n

def main(n):
    if n[0]=='7' or n[1]=='7' or n[2]=='7':
        return 'Yes'
    else:
        return 'No'

if __name__=='__main__':
    n=readinput()
    ans=main(n)
    print(ans)


Measured memory_bytes: 9040
#include<bits/stdc++.h>
#define rep(i,k,n) for(int i=k;i<=n;i++)
#define rep2(i,k,n) for(int i=k;i>=n;i--)
using namespace std;
typedef long long ll;
const int inf=0x3f3f3f3f;
const int N=2e5+7;
ll ans=0x3f3f3f3f3f3f3f3full;
int n,Rmx,Rmi,Bmx,Bmi,tot;
struct data{
	int v,c;data(int v=0,int c=0):v(v),c(c){}
}a[N<<1];
bool operator < (const data& a,const data& b){
	return a.v < b.v;
}
void to_R(int x){
	Rmx=max(Rmx,x);
	Rmi=min(Rmi,x);
}
void to_B(int x){
	Bmx=max(Bmx,x);
	Bmi=min(Bmi,x);
}
int vis[N];
void solve1(){
	memset(vis,0,sizeof(vis));
	Rmx=0,Rmi=inf,Bmx=0,Bmi=inf;
	rep(i,1,tot){
		if(!vis[a[i].c])vis[a[i].c]=1,to_R(a[i].v);
		else to_B(a[i].v);
	}
	ans=min(ans,1ll*(Rmx - Rmi)*(Bmx - Bmi));
}
int cnt=0;
bool pan(int l,int r){
	memset(vis,0,sizeof(vis));
	cnt=0;
	rep(i,l,r){
		if(!vis[a[i].c])vis[a[i].c]=1,cnt++;
	}
	return cnt>=n;
}
bool ins(int x){
	if(cnt==n)return false;
	vis[a[x].c]++;
	if(vis[a[x].c]==1)cnt++;
	if(cnt==n)return false;
	return true;
}
void del(int x){
	vis[a[x].c]--;
	if(!vis[a[x].c])cnt--; 
}
void solve2(){
	Rmx=0,Rmi=inf,Bmx=0,Bmi=inf;
	to_R(a[1].v);
	to_R(a[tot].v);
	int L,R;
	rep(i,2,tot)if(a[i].c == a[1].c)L=i;
	rep(i,1,tot-1)if(a[i].c == a[tot].c)R=i;
	if(L>R)swap(L,R);
	if(pan(L,R)){
		ans=min(ans,1ll*(Rmx - Rmi)*(a[R].v - a[L].v));
	}else{
		memset(vis,0,sizeof(vis));
		int r=2;
		cnt=0;
		rep(l,2,tot-1){
			for(;r<=tot-1 && ins(r);)r++;
			if(cnt==n){
				if(l<=L && r>=R){
					ans=min(ans,1ll*(Rmx - Rmi)*(a[r].v - a[l].v));
				}
			}
			del(l);
		}
	}
}
int main(){
	scanf("%d",&n);
	rep(i,1,n){
		int x;
		rep(k,0,1){
			scanf("%d",&x);
			a[++tot]=data(x,i);
		}
	}sort(a+1,a+tot+1);
	solve1();
	if(a[1].c != a[tot].c)
		solve2();
	printf("%lld\n",ans);
} 

Measured memory_bytes: 4096
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

public class Main {
	final int INF = 1000000000;
	int h, w, n;
	int ans;
	char[][] board;
	class Pair {
		int h, w;
		Pair(int h, int w){
			this.h = h;
			this.w = w;
		}
		@Override
		public String toString(){
			return "(" + h + ", " + w + ")";
		}
	}
	public Pair bfs(int n, Pair p){
		int[][] min = new int[h][w];
		for(int i = 0; i < h; i++){
			Arrays.fill(min[i], INF);
		}
		int[][] d = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
		min[p.h][p.w] = 0;
		Queue<Pair> queue = new ArrayDeque<Pair>();
		queue.add(p);
		while(true){
			Pair pos = queue.poll();
			for(int i = 0; i < d.length; i++){
				int x = pos.w + d[i][1];
				int y = pos.h + d[i][0];
				if( x < 0 || x >= w || y < 0 || y >= h ){
					continue;
				}
				if( board[y][x] == 'X' || min[y][x] != INF ){
					continue;
				}
				min[y][x] = min[pos.h][pos.w]+1;
				if( board[y][x] == ('0' + n) ){
					ans += min[y][x];
					return new Pair(y, x);
				}
				queue.add(new Pair(y, x));
			}
		}
	}
	public int minPath(){
		Pair start = null;
	out:
		for(int i = 0; i < h; i++){
			for(int j = 0; j < w; j++){
				if( board[i][j] == 'S' ){
					start = new Pair(i, j);
					break out;
				}
			}
		}
		ans = 0;
		for(int i = 1; i <= n; i++){
			start = bfs(i, start);
		}
		return ans;
	}
	public void solve() throws IOException {
		h = nextInt();
		w = nextInt();
		n = nextInt();
		board = new char[h][w];
		for(int i = 0; i < h; i++){
			board[i] = nextToken().toCharArray();			
		}
		writer.println(minPath());
	}
	public static void main(String[] args){
		new Main().run();
	}
	BufferedReader reader;
	StringTokenizer tokenizer;
	PrintWriter writer;
	
	public void run() {
		try{
			reader = new BufferedReader(new InputStreamReader(System.in));
			tokenizer = null;
			writer = new PrintWriter(System.out);
			solve();
			reader.close();
			writer.close();
		} catch(Exception e){
			e.printStackTrace();
			System.exit(1);
		}
	}
	public String nextToken() throws IOException {
		if( tokenizer == null || !tokenizer.hasMoreTokens() ){
			tokenizer = new StringTokenizer(reader.readLine());
		}
		return tokenizer.nextToken();
	}
	public int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}
}

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

namespace ProgramingStudying2
{
    class Program
    {

        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var a = new HashSet<int>();
            
            for(int i = 0; i < n; i++)
            {
                var input = int.Parse(Console.ReadLine());
                if (a.Contains(input))
                {
                    a.Remove(input);
                }
                else
                {
                    a.Add(input);
                }
            }

            Console.WriteLine(a.Count);
        }
    }
}


Measured memory_bytes: 33800
S = input()
T = input()
s = len(S)
t = len(T)
ans = 10**10
for i in range(s-t+1):
    tmp = 0
    for j in range(t):
        if S[i+j] != T[j]:
            tmp += 1
    ans = min(tmp, ans)
print(ans)

Measured memory_bytes: 9052
using System;

class A
{
	static void Main()
	{
		var s = Console.ReadLine();

		var r = 0;
		var c = ' ';
		var is2 = false;
		var i = 0;
		for (; i < s.Length; i++)
		{
			if (is2 || c != s[i])
			{
				is2 = false;
				c = s[i];
			}
			else
			{
				is2 = true;
				i++;
			}
			r++;
		}
		if (i > s.Length) r--;
		Console.WriteLine(r);
	}
}


Measured memory_bytes: 11616
from collections import defaultdict
from heapq import heappop, heappush

YEN = 10**15
INF = float('inf')


class Graph:
    def __init__(self):
        self.__graph = defaultdict(list)

    def add_edge(self, source, destination, cost):
        self.__graph[source].append((destination, cost))
        self.__graph[destination].append((source, cost))

    @property
    def graph(self):
        return self.__graph


class Dijkstra:
    def __init__(self, graph, source):
        self.__costs = defaultdict(lambda: INF)
        costs = self.__costs
        costs[source] = 0
        g = graph.graph
        q = []
        heappush(q, (costs[source], source))

        while q:
            cp, p = heappop(q)
            if costs[p] < cp:
                continue
            for dst, cost in g[p]:
                alternative = cp + cost
                if costs[dst] > alternative:
                    costs[dst] = alternative
                    heappush(q, (alternative, dst))

    @property
    def costs(self):
        return dict(self.__costs)


def spline(func_=int, iter_=None):
    if iter_ is None:
        iter_ = input().split()
    return map(func_, iter_)


def main():
    n, m, s, t = spline()
    g_yen = Graph()
    g_snuuk = Graph()
    for _ in range(m):
        u, v, cost, b = spline()
        g_yen.add_edge(u, v, cost)
        g_snuuk.add_edge(u, v, b)
    d_s = Dijkstra(g_yen, s).costs
    d_t = Dijkstra(g_snuuk, t).costs
    costs = [INF] * n
    min_cost = INF
    for i in range(n, 0, -1):
        min_cost = min(min_cost, d_s[i] + d_t[i])
        costs[i - 1] = min_cost
    for cost in costs:
        print(YEN - cost)


if __name__ == "__main__":
    main()


Measured memory_bytes: 113872
/* 
    Author : Jeff Ahn
    Sun 02 Aug 2020 05:01:27 AM PDT 
*/
#include <bits/stdc++.h>
using namespace std;
#define rep(i,r) for(int i = 0; i < (r); i++)
#define pb push_back
#define all(a) a.begin(), a.end()
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define int long long
#define uint unsigned long long
#define endl '\n'

signed main() {
  fastio;
  int x;cin>>x;
  if (x >= 30) cout << "Yes" << endl;
  else cout << "No" << endl;
}


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

    using namespace std;
    template <typename T>
    void debug(string t, T input) {
        cout<<t<<"-> "<<input<<"\n";
    }
    template <typename T>
    void debug(int i,string t, T input) {
        cout<<"Case#"<<i<<" "<<t<<"-> "<<input<<"\n";
    }


    int main(){
        ios::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
        int n;
        cin>>n;
        long long val=0;
        for(int i=1;i<=n;i++){
            if(i%3==0 || i%5==0){
                
            }
            else{
                val+=i;
            }
        }
        cout<<val;
        return 0;
    }


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

using namespace std; 
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define forin(i, n) for ( i = 0; i < (int)n; ++i )
typedef long long ll;

int H, W, k;

int main()
{
    //IOS
    
    string from, to;
    cin >> from >> to;
    int i, cont = 0;
    forin(i, (int)to.size())
    {
        if ( from[i] != to[i] ) ++cont;
    }

    cout << cont;
    return 0;
}

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

int main() {
  int n;
  string s;
  cin >> n >> s;
  int x = 0;
  int ans = 0;
  for (int i=0; i<n; i++) {
    if(s.at(i) == 'I') {
      x++;
    } else {
      x--;
    }
    ans = max(ans, x);
  }
  cout << ans << endl;
}

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

typedef long long ll;

int main() {
  string t; cin >> t;
  int a[4];
  for ( int i = 0; i < 4; i++ ) a[i] = t[i] -'0';
  for ( int x = 0; x < 8;  x++ ) {
    int sum = a[0];
    string s;
    s += (char)('0'+a[0]);
    for ( int i = 0; i < 3; i++ ) {
      if ( x & (1<<i) ) {
	sum += a[i+1];
	s += '+';
	s += (char)('0'+a[i+1]);
      } else {
	sum -= a[i+1];
	s += '-';
	s += (char)('0'+a[i+1]);
      }
    }
    if ( sum == 7 ) {
      cout << s << "=7" << endl;
      return 0;
    }
  }
  return 0;
}


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

class Program
{
    static void Main()
    {
        var N = int.Parse(Console.ReadLine());
        var A = Console.ReadLine().Split().Select(int.Parse).ToList();
        for (var i = 0; i < A.Count-1; i++)
        {
            A[i + 1] = calc(A[i], A[i + 1]);
        }
        Console.WriteLine(A[A.Count-1]);
    }

    static int calc(int a, int b)
    {
        if (b == 0)
        {
            return a;
        }
        return calc(b, a % b);
    }
}



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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

#define file "I1"

const double EPS = 1e-9;
const double PI = acos(-1.);
const int INF = 1e9;
const ll MOD = 1e9 + 7;

const int MAXN = 3e5 + 5;

int v[MAXN];

void solve(){
	int n;
	scanf("%d", &n);
	REP(i, 0, 3 * n){
		scanf("%d", &v[i]);
	}
	sort(v, v + 3 * n);
	ll ans = 0ll;
	for(int i = 0, j = 3 * n - 2; i < n; i++, j -= 2){
		ans += v[j];
	}
	cout << ans << endl;
}   

int main(){

    //freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();    
    }
}


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

using namespace std;

int requirement[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
int A[9];

int digits[10'001];

int main()
{
    int N, M;
    cin >> N >> M;
    for (int i = 0; i < M; i++)
    {
        cin >> A[i];
    }
    sort(A, A + M, [](const int &lh, const int &rh) {
        return lh > rh;
    });

    for (int i = 0; i <= N; i++)
    {
        digits[i] = -10000;
        if (i == 0)
        {
            digits[i] = 0;
            continue;
        }
        for (int j = 0; j < M; j++)
        {
            int req = requirement[A[j]];
            if (i - req >= 0)
            {
                digits[i] = max(digits[i], digits[i - req] + 1);
            }
        }
    }

    for (int i = N; i > 0;)
    {
        for (int j = 0; j < M; j++)
        {
            int req = requirement[A[j]];
            if (i - req >= 0 && digits[i - req] + 1 == digits[i])
            {
                cout << A[j];
                i -= req;
                break;
            }
        }
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
struct Edge {
  ll to;
  ll cost;
};
int main() {
  ll x;
  cin >> x;
  ll num = 5;
  ll score = 0;
  ll i = 0;
  i = (x / 11) * 2;
  x %= 11;
  while (score < x) {
    i++;
    if (num == 5) {
      score += 6;
      num = 6;
    } else {
      score += 5;
      num = 65;
    }
  }
  cout << i << endl;
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  while(1){
  int n;
  cin>>n;
  if(n==0)break;
  string str;
  cin>>str;
  int A[101],B[101];
  for(int i=0;i<n;i++)cin>>A[i]>>B[i];

  for(int i=0;i<n;i++){
    int a = A[n-1-i],b = B[n-1-i];
    int s = b - a;
    a--,b--;
    str[a] = (str[a]-'a'+s)%26 + 'a';
    str[b] = (str[b]-'a'+s)%26 + 'a';
    swap(str[a],str[b]);
  }
  cout<<str<<endl;
  }  
  return 0;
}

Measured memory_bytes: 3136
#include<stdio.h>
#include<math.h>
#include<string.h>

int main()
{
	long long int N, A, B;
	scanf("%ld %ld %ld", &N, &A, &B);
	
	long long int K=0;
	long long int t = N / (A+B);
	
	if(N%(A+B) < A) printf("%ld", t*A + N%(A+B));
	else printf("%ld", (t+1)*A);
		

		return 0;
	
}

Measured memory_bytes: 128
fun main(args: Array<String>) {
    // Your code here!
    var x = readLine()!!.toInt()
    println(sigma(x))
}

fun gcd(a:Int,b:Int):Int{
    if(b===0){
        return a
    }
    return gcd(b,a%b)
}

fun sigma(k:Int):Int{
    var ans = 0
    for(i in 1..k){
        for(j in 1..k){
            for(l in 1..k){
                ans += gcd(gcd(i,j),l)                
            }
        }
    }
    return ans
}


Measured memory_bytes: 34496
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class GFG
{
    static public void Main()
    {
        try
        {

            var input1 = Console.ReadLine().Split(' ');
            var n = int.Parse(input1[0]);
            var k = int.Parse(input1[0]);
            var aar = Console.ReadLine().Split(' ').Select(x => Int32.Parse(x)).ToArray();

            IrohaObsession(n, k, aar);
        }
        catch (Exception ex)
        {
            Console.Write(ex);
        }
    }

    static void IrohaObsession(int n, int k, int[] digit)
    {
        int i;
        bool[] d = new bool[10];

        for (i = 0; i < digit.Length; ++i)
        {
            d[digit[i]] = true;
        }

        for (i = n; i < 1000000; ++i)
        {
            int flag = 0;
            int m = i;
            while (m > 0)
            {
                if (d[m % 10])
                {
                    flag = 1;
                    break;
                }
                m /= 10;
            }
            if (flag == 0)
            {
                Console.Write(i);
                break;
            }
        }


    }

}

Measured memory_bytes: 13268
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <utility>
#include <iomanip>

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

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

signed main(){
    int n;
    cin >> n;

    vector<int> a(n);
    rep(i, n) cin >> a[i];
    sort(a.begin(), a.end());

    double half = a[n-1] / 2.0;

    int left = 0;
    int right = n-1;
    while(right - left > 1){
        int mid = left + (right - left) / 2;
        if(a[mid] <= half){
            left = mid;
        }else{
            right = mid;
        }
    }
    int lh = left;

    left = 0;
    right = n-2;
    while(right - left > 1){
        int mid = left + (right - left) / 2;
        if(a[mid] >= half){
            right = mid;
        }else{
            left = mid;
        }
    }
    int rh = right;

    if(half - a[lh] < a[rh] - half){
        cout << a[n-1] << " " << a[lh] << endl;
    }else{
        cout << a[n-1] << " " << a[rh] << endl;
    }

    return 0;
}


Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long n,ans=0,f=5;
  cin>>n;
  if(n%2==0){
    for(;;){
      if(n/f>0){
	ans+=n/f/2;
	f*=5;
      }
      else
      break;
    }
  }
  cout<<ans<<endl;
  return(0);
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		new Main().run();
	}

	int n;
	int[] color;

	private void run() {
		Scanner scanner = new Scanner(System.in);
		n = scanner.nextInt();
		int m = scanner.nextInt();
		color = new int[n];
		for(int i = 0;i<n;i++){
			color[i] = i;
		}
		for (int i = 0; i < m; i++) {
			int s = scanner.nextInt();
			int t = scanner.nextInt();
			t = root(t);
			root(s, t);
		}

		int q = scanner.nextInt();
		for (int i = 0; i < q; i++) {
			int s = scanner.nextInt();
			int t = scanner.nextInt();
			s = root(s);
			t = root(t);
			if (s == t) {
				System.out.println("yes");
			} else {
				System.out.println("no");
			}
		}
	}

	private void root(int s, int t) {
		while (true) {
			if (s == t) {
				color[s] = t;
				return;
			}
			int tmp = color[s];
			color[s] = t;
			s = tmp;
		}
	}

	private int root(int t) {
		while (true) {
			if (t == color[t])
				return t;
			t = color[t];
		}
	}

}

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

using namespace std;
typedef long long ll;
//typedef unsigned long long ll;

#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define sz(x) ll(x.size())
//typedef pair<ll, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
//const ll INF = LONG_LONG_MAX / 10;
//const ll INF = 1e15;
const ll MINF = LONG_LONG_MIN;
const int INF = INT_MAX / 10;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
//typedef pair<int, int> P;
//typedef pair<double, double> P;

bool contain(set<P> &s, P a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);


void print_line(vector<int> &line) {
    if (line.size() == 0ll) {
        cout << endl;
        return;
    }
    for (ll i = 0; i < line.size(); i++) {
        cout << line[i];
        if (i == line.size() - 1) cout << endl;
        else cout << ' ';
    }
}


typedef priority_queue<long long, vector<long long>, greater<long long>> PQ_ASK;
const int mod = 1000000007;

int main() {
    vector<ll> v;
    int n;
    cin >> n;

    rep(i, n) {
        int q;
        cin >> q;
        if (q == 0) {
            int x;
            cin >> x;
            v.push_back(x);
        } else if (q == 1) {
            int x;
            cin >> x;
            cout << v[x] << endl;
        } else if (q == 2) {
            v.pop_back();
        } else {
            __throw_runtime_error("konai");
        }
    }

}


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

#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
#define FORA(i,I) for(const auto& i:I)
#define ALL(x) x.begin(),x.end() 
#define SIZE(x) ll(x.size()) 

int main(void)
{
    ll A, B,C;
    cin >> A >> B >> C;

    string ans ="NO";
    for (int i = 0; i < B; i++) {
        if (A*i % B == C) {
            ans = "YES";
            break;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3612
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


def main():
    N, M, *LR=map(int, read().split())
    Lmax = max(LR[::2])
    Rmin = min(LR[1::2])
    
    print(max(0, Rmin-Lmax + 1))
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 82800
use std::io::*;
use std::str::FromStr;
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}
fn main(){
    let n:i32 = read();
    let mut ans:i32 = n * 800 - n / 15* 200;
    println!("{}",ans);
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
#include <fstream>
using namespace std;
 
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define pvec(v) rep(i,v.size()){cout << v[i] << " ";};cout<<endl;
#define pb push_back
#define pf push_front
#define mod 1e9+7
#define m_p make_pair
 
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef vector<pii> vpii;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;
typedef vector<vector<int>> vvi;
const double pi = acos(-1.0);
 
ll gcd(ll x, ll y) { return (y == 0) ? x : gcd(y, x % y); }
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return false;
        }
    }
    return true;
}

int main()
{
    ll n,ans=0;
    cin >> n;
    vll v(n);
    rep(i,n) cin >> v[i];
    sort(all(v));
    cout << v[n-1] - v[0] << endl;
    return 0;
}


Measured memory_bytes: 256
from fractions import gcd


MOD = 10**9+7

N = int(input())
A = list(map(int,input().split()))
#%%
def modinv(x,mod):
    return pow(x,mod-2,mod)

B = []
for a in A:
    b = modinv(a,MOD)
    B.append(b)

def lcm(a,b):
    return a//gcd(a,b)*b

ans = 0

cur = 1
for a in A:
    cur =  lcm(cur,a)
for b in B:
    ans += cur*b
ans %= MOD
print(ans)



Measured memory_bytes: 68824
//============================================================================
// Name        : AtcoderDpI.cpp
// Author      : 
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int MAX = 3000;
int n;
double tot = 0.,
		dp[MAX][MAX], c[MAX];



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

	cin >> n;

	for (int i = 1; i <= n; ++i) {
		cin >> c[i];
	}

	dp[0][0] = 1;

	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j) {
			dp[i + 1][j + 1] += c[i + 1] * dp[i][j];
			dp[i + 1][j] += (1 - c[i + 1]) * dp[i][j];
		}
	}

	for (int i = n / 2 + 1; i <= n; ++i) {
		tot += dp[n][i];
	}

	printf("%.12f\n", tot);
}


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

int main(int argc, char *argv[]) {
    int N;
    std::cin >> N;

    std::vector<int> vec(N);

    for (int i = 0; i < N; i++) {
        std::cin >> vec[i];
    }

    std::sort(vec.begin(), vec.end());

    int Alice = 0;
    int Bob = 0;

    for (int i = vec.size() - 1; i >= 0; i--) {
        if (vec.size() % 2 == 0) {
            if (i % 2 != 0) {
                Alice += vec[i];
            } else {
                Bob += vec[i];
            }
        } else {
            if (i % 2 == 0) {
                Alice += vec[i];
            } else {
                Bob += vec[i];
            }
        }
    }

    std::cout << Alice - Bob;

    return 0;
}

Measured memory_bytes: 256
class UnionFind():
    # 作りたい要素数nで初期化
    # 使用するインスタンス変数の初期化
    def __init__(self, n):
        self.n = n
        # root[x]<0ならそのノードが根かつその値が木の要素数
        # rootノードでその木の要素数を記録する
        self.root = [-1]*(n+1)
        # 木をくっつける時にアンバランスにならないように調整する
        self.rnk = [0]*(n+1)

    # ノードxのrootノードを見つける
    def Find_Root(self, x):
        if(self.root[x] < 0):
            return x
        else:
            # ここで代入しておくことで、後の繰り返しを避ける
            self.root[x] = self.Find_Root(self.root[x])
            return self.root[x]
    # 木の併合、入力は併合したい各ノード

    def Unite(self, x, y):
        # 入力ノードのrootノードを見つける
        x = self.Find_Root(x)
        y = self.Find_Root(y)
        # すでに同じ木に属していた場合
        if(x == y):
            return
        # 違う木に属していた場合rnkを見てくっつける方を決める
        elif(self.rnk[x] > self.rnk[y]):
            self.root[x] += self.root[y]
            self.root[y] = x

        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            # rnkが同じ（深さに差がない場合）は1増やす
            if(self.rnk[x] == self.rnk[y]):
                self.rnk[y] += 1
    # xとyが同じグループに属するか判断

    def isSameGroup(self, x, y):
        return self.Find_Root(x) == self.Find_Root(y)

    # ノードxが属する木のサイズを返す
    def Count(self, x):
        return -self.root[self.Find_Root(x)]


N, M = map(int, input().split())
p = [int(i) for i in input().split()]
uf = UnionFind(N)

for _ in range(M):
    x, y = map(int, input().split())
    uf.Unite(x, y)

ans = 0
for i in range(N):
    if uf.isSameGroup(i+1, p[i]):
        ans += 1
print(ans)


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
typedef long long ll;

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

int main() {
    ll a,b,c,d; cin >> a >> b >> c >> d;
    ll cd = c * d / gcd(c,d);
    ll r = b / c + b / d - b / cd;
    ll l = (a-1) / c + (a-1) / d - (a-1) / cd;
    cout << b - a + 1 - r + l << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,a,b) for(int i=a;i<b;i++)
typedef vector<int > vi;
int p = 1e9+7;
ll exp(int a,int b){
	if(b==0)return 1;
	ll tde = exp(a,b/2);
	tde = (tde*tde)%p;
	if(b%2!=0)tde = (tde*a)%p;
	return tde;
}
int main(){
	int n;
	cin>>n;
	vector<int > nos(n+1,0);
	nos[0]=1;
	repl(i,3,n+1){
		repl(j,3,n+1){
			if(i-j>=0){
				nos[i]=(nos[i]+nos[i-j])%p;
			}
			else break;
		}
	}
	cout<<nos[n];
	
}


Measured memory_bytes: 3600
#include<iostream>
#include<string>
using namespace std;
# define maxn 100000 

int main(){
  int r,g,b,n,cnt(0);
  cin>>r>>g>>b>>n;
  for (int i(0);i<=n;i++){
    for (int j(0);j<=n;j++){
      int tmp=n-(r*i+g*j);
      if (tmp%b==0&&tmp>=0){
        cnt+=1;
      }
    }
  }
  cout<<cnt;
  return 0;
}


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

const double PI = 3.14159265358979323846;
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
//typedef pair<ll, ll> P;
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

std::istream &operator>>(std::istream &in, set<int> &o) {
    ll a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
const int mod = 1000000007;
//const ll mod = 1e10;
typedef priority_queue<string, vector<string>, greater<string> > PQ_ASK;

#include <iostream>
#include <vector>

using namespace std;

struct Food {
    ll time, good;
};

struct SegTreeMin {
    ll N, dat[4 * 100000];

    SegTreeMin() {}

    SegTreeMin(ll n) {
        N = 1;
        while (N < n) N *= 2;
        for (ll i = 0; i < 2 * N - 1; i++)
            dat[i] = INF;
    }

    // update k th element
    void update(ll k, ll a) {
        k += N - 1; // leaf
        dat[k] = a;
        while (k > 0) {
            k = (k - 1) / 2;
            dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
        }
    }

    // min [a, b)
    ll query(ll a, ll b) { return query(a, b, 0, 0, N); }

    ll query(ll a, ll b, ll k, ll l, ll r) {
        if (r <= a or b <= l) return INF;
        if (a <= l and r <= b) return dat[k];
        ll m = (l + r) / 2;
        return min(query(a, b, k * 2 + 1, l, m), query(a, b, k * 2 + 2, m, r));
    }
};

int main() {
    int n, m;
    string s;

    cin >> n >> m >> s;
    SegTreeMin st(n + 1);
    rep(i, n + 2) st.update(i, INF);
    st.update(n, 0);

    for (int i = n - 1; i >= 0; i--) {
        if (s[i] == '1') {
            continue;
        }
        ll start = i + 1;
        ll end = min(i + m + 1, n + 1);
        ll mi = st.query(start, end);
        if (mi == INF) {
            cout << -1 << endl;
            ret();
        }
        st.update(i, mi + 1);
    }
    ll ma = st.query(0, 1);
    vector<ll> shortness(n + 1);
    rep(i, n + 1) shortness[i] = st.query(i, i + 1);

    vector<ll> points(ma + 1);
    for (ll i = n; i >= 0; i--) {
        ll p = shortness[i];
        if (p == INF) continue;
        points[p] = i;
    }
    reverse(points.begin(), points.end());
    rep(i, ma) {
        cout << points[i + 1] - points[i] << ' ';
    }
    cout << endl;
}

Measured memory_bytes: 4224
def main():
    from builtins import int, map, list, print
    import sys
    sys.setrecursionlimit(10 ** 6)

    input = (lambda: (sys.stdin.readline()).rstrip())
    input_list = (lambda: input().split())
    input_number = (lambda: int(input()))
    input_number_list = (lambda: list(map(int, input_list())))

    N = input_number()
    print("AABBCD"[N > 999::2])


if __name__ == '__main__':
    main()


Measured memory_bytes: 9008