akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#include <time.h>
#include <functional>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<ll, ll, ll, ll> tlglglglg;
typedef tuple<double, double, double> tddd;
typedef complex<double> xy_t;
typedef vector<ll> vll;
typedef vector< vector<ll> > matrix;
typedef unsigned int uint;
typedef unsigned long long ull;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
template <class T> using VVV = V<VV<T>>;
#define REP(i, x, y) for(ll i = (ll)x; i < (ll)y; i++)
#define DREP(i, x, y, d) for(ll i = (ll)x; i < (ll)y; i += (ll)d)
#define PER(i, x, y) for(ll i = (ll)x; i > (ll)y; i--)
#define DPER(i, x, y, d) for(ll i = (ll)x; i > (ll)y; i -= (ll)d)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-12;
void yesno(bool ok, string yes = "Yes", string no = "No") {
    if (ok) {
        cout << yes << endl;
    } else {
        cout << no << endl;
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll A;
    cin >> A;
    string B;
    cin >> B;
    ll BB = 0;
    BB += (B[0] - '0') * 100 + (B[2] - '0') * 10 + (B[3] - '0');
    ll ans = BB * A / 100;
    cout << ans << endl;
}


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

namespace For_Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] HWD = ReadLine().Split(' ').Select(int.Parse).ToArray();
            int[] Points = new int[HWD[0] * HWD[1] + 1];
            for(int iy = 0; iy < HWD[0]; iy++)
            {
                int[] numw = ReadLine().Split(' ').Select(int.Parse).ToArray();
                for (int ix = 0; ix < HWD[1]; ix++)
                {
                    Points[numw[ix]] = iy * HWD[1] + ix;
                }
            }

            int Q = int.Parse(ReadLine());

            int[] UsedCosts = new int[HWD[0] * HWD[1] + 1];
            for(int i = HWD[2]; i < UsedCosts.Length; i++)
            {
                UsedCosts[i] = Math.Abs(Points[i - HWD[2]] % HWD[1] - Points[i] % HWD[1]) + Math.Abs(Points[i - HWD[2]] / HWD[1] - Points[i] / HWD[1]) + UsedCosts[i - HWD[2]];
            }

            int[][] LR = new int[Q][];
            for (int i = 0; i < Q; i++)
            {
                LR[i] = ReadLine().Split(' ').Select(int.Parse).ToArray();
            }

            for (int i = 0; i < Q; i++)
            {
                WriteLine(UsedCosts[LR[i][1]] - UsedCosts[LR[i][0]]);
            }
        }
    }
}

Measured memory_bytes: 25260
using System;
using System.Linq;

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var X = Console.ReadLine().Split().Select(int.Parse).ToArray();

            Func<int[], int, int> calc = (A, i) => A.Sum(x => (x - i) * (x - i));
            var ave = (int)X.Average();

            Console.WriteLine(Math.Min(calc(X, ave), calc(X, ave + 1)));
        }
    }
}


Measured memory_bytes: 13396
#include <iostream>
using namespace std;

int main(){
  int A, B;
  cin >> A >> B;
  
  if (A == 1)
  {
    if (B == 2)
    {
      cout << 3;
    }else
    {
      cout << 2;
    }
  }else if(A == 2)
  {
    if (B == 1)
    {
      cout << 3;
    }else
    {
      cout << 1;
    }
  }else
  {
    if (B == 1)
    {
      cout << 2;
    }else
    {
      cout << 1;
    }
  }
  
  return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<iostream>
#include<algorithm>
#include<vector>
#include<stdio.h>
#include<string.h>
#include<cmath>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ll long long
using namespace std;


int main()
{
    int a, b, h, m;
    double hdig, mdig, res;
    cin >> a >> b >> h >> m;
    hdig = (double)360 / 12 * h + (double)360 / (12 * 60) * m;
    mdig = (double)360 / 60 * m;
    res = sqrt(a * a + b * b - 2 * a * b * cos(abs(hdig - mdig) * M_PI / 180.0));
    printf("%.10lf\n", res);
}

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

int main(){
  int a,b;
  cin >> a >> b;
  
  if((a + b) % 2 == 0){
    cout << (a + b) / 2 << endl;
  }
  else{
    cout << (a + b) / 2 + 1 << endl;
  }
}


Measured memory_bytes: 3600
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val s = sc.next()
    var judge = 0
    s.forEachIndexed { index, c ->
        if (index > 0) {
            var prev = s[index - 1]
            if (prev == c) {
                judge = 1
            }
        }
    }
    if (judge == 0) {
        println("Good")
    } else {
        println("Bad")
    }
}

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

int main() {
	cin.tie(0);
  ios::sync_with_stdio(false);
 
	int n,k,i,j,r;
  vector<int> v;
  cin>>n>>r;
  
  if(n>=10)
    cout<<r;
  else
    cout<<r+100*(10-n);


  return 0;
}

Measured memory_bytes: 888
# %%time
# import numpy as np
n = int(input())
a = list(map(int, input().split()))

# n = 2 * 10 ** 5
# a = np.random.randint(0, 10**9, n)

x = a[0]
for k in range(n - 1):
    x = x ^ a[k + 1]

bb = []
for k in range(n):
    b = x ^ a[k]
    bb.append(b)
print(" ".join(map(str, bb)))

Measured memory_bytes: 113508
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include<map>
#include<set>
#define MAX 300005
using namespace std;

typedef long long ll;
int a[MAX];
int vis[MAX];
int main()
{
	int n,m;
	cin>>n>>m;
	int minn=m;
	for(int t=1;t<n;t++)
	{
		scanf("%d",&m);
		minn=__gcd(m,minn);
	}
	cout<<minn<<endl;
	return 0;
 } 

Measured memory_bytes: 256
#include <iostream>
#include <cstdint>
#include <vector>

std::vector<uint32_t> a;
uint32_t n;

std::vector<uint32_t> maxAns;
std::vector<uint32_t> maxNum;

void input() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(nullptr);

	std::cin >> n;
	a.resize(1U << n);
	for (uint32_t &i : a) {
		std::cin >> i;
	}
}

void calc_ans() {
	maxAns.resize(a.size(), 0);
	maxNum.resize(a.size(), 0);

	for (uint32_t i = 0;i < a.size();i++) {
		maxNum[i] = i;
		for (uint32_t j = 0;j < n;j++) {
			if (((1u << j) & i) == 0) {
				continue;
			}
			uint32_t k = i ^ (1u << j);
			maxAns[i] = std::max(maxAns[i], a[i] + a[maxNum[k]]);

			if (a[maxNum[k]] > a[maxNum[i]]) {
				maxNum[i] = maxNum[k];
			}

			for (uint32_t l = 0;l < n;l++) {
				if (((1u << l) & maxNum[k]) == 0) {
					continue;
				}
				maxAns[i] = std::max(
					maxAns[i],
					a[maxNum[k]] + a[maxNum[i ^ (1u << l)]]
				);
			}
		}
	}
	for (uint32_t i = 1;i < a.size();i++) {
		maxAns[i] = std::max(maxAns[i], maxAns[i - 1]);
	}
}

int main() {
	input();
	calc_ans();
	for (uint32_t i = 1;i < maxAns.size();i++) {
		std::cout << maxAns[i] << "\n";
	}

}


Measured memory_bytes: 6144
#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>;
const int INF = 1 << 29;
 
int main() {
	int a, b;
	string s;
	cin >> a >> b >> s;
	bool ok = true;
	if (s[a] != '-') ok = false;
	rep(i, a+b+1) {
		if (i == a) continue;
		if (!isdigit(s[i]))  ok = false;
	} 
	if (ok) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
import itertools
def LI():return list(map(int,input().split()))
n,m,q=LI()
abcd=[]
for _ in range(q):
  a,b,c,d=LI()
  a-=1
  b-=1  
  abcd.append((a,b,c,d))
As=itertools.combinations_with_replacement(range(1,m+1),n)
#重複組み合わせ [1,2,3,4...m]から重複を許してn個取ってくる
ans=0

for A in As:
  cnt=0
  for a,b,c,d in abcd:
    if A[b]-A[a]==c:cnt+=d
  ans=max(ans,cnt)
print(ans)


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

int main() {
  int n, l;
  cin >> n >> l;
  int sum = 0;
  for (int i = 1; i <= n; i++) sum += l + i - 1;
  int a = 10000000;
  int b;
  for (int i = 1; i <= n; i++) {
    if (abs(l + i - 1) < a) {
      a = abs(l + i - 1);
      b = l + i - 1;
    } 
  } 
  cout << sum - b << endl; 
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>
#include<math.h>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<map>
#include<numeric>
#include<stack>
#include<queue>
#include<functional>
#include<cassert>
#include<set>
#include<time.h>
#include<cmath>
#include<functional>
#include<cassert>
#define rep(a,b) for(int a=0;a<b;++a)
#define REP(a,b,c,d) for(int a=b;a<c;a+=d)
#define yes cout<<"Yes"<<endl
#define no cout<<"No"<<endl
#define mod 1000000007
using namespace std;
using ll = long long;
using p_i = pair<int, int>;
int main() {
    string S;cin>>S;
    int ans=0;
    rep(i,S.size())if(S[i]=='2')++ans;
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;
int main(){
	long long int n,a;
	cin >> n;
	a=1;
	for (int i=1;i<=n;i++){

		a*=i;
			a=a%(10*10*10*10*10*10*10*10*10+7);
		//cout<<a<<endl;
	}
	cout<<a;
	
	return 0;
}

Measured memory_bytes: 256
import numpy as np

n, m = list(map(int, input().split()))
a = 0

if n == 1 or m == 1:
    if n == m:
        a = 1
    else:
        a = n + m - 3
elif n == 2 or m == 2:
    a = 0
else:
    a = (n - 2) * (m - 2)

print(a)


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

const int INF = 1e9;

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

  int W[N];
  int totalSum=0;
  for (int i = 0; i < N; i++) {
    cin >> W[i];
    totalSum += W[i];
  }

  int ans = INF;
  int S1 = 0;
  for (int i = 0; i < N-1; i++) {
    S1+=W[i];
    int S2=totalSum-S1;
    ans = min(ans,abs(S2-S1));
  }

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

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
constexpr int kMod = 1000000007;
typedef long long LL;

int main() {
  int N; std::cin >> N;

  std::vector<LL> A(N);
  for (int n = 0; n < N; ++n) {
    std::cin >> A[n];
  }

  LL total = 0;
  for (LL i = 0; i <= 60; ++i) {
    LL zeros = 0, ones = 0;
    LL mask = 1LL << i;
    for (LL a : A) {
      if (a & mask) ++ones;
      else          ++zeros;
    }
    LL tmp1 = ones*zeros%kMod;
    LL tmp2 = mask%kMod;
    LL tmp = tmp1 * tmp2 % kMod;
    total = total + tmp;
    total %= kMod;
  }
  std::cout << total << std::endl;
}



Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define rep(i, a) for(int i = 0; i < a; i++)
#define all(v) v.begin(), v.end()
#define dcout cout << fixed << setprecision(15)
#define arep(i, a) for(auto i : a)
#define F first
#define S second
#define VE vector<int>
#define pb(x) push_back(x)
#define MOD 1000000007
#define INF 10000000000
#define int long long
#define KETA(n) floor(log10(n) + 1)
using namespace std;
signed main() {
    int n, m;
    cin >> n >> m;
    int a = 0;
    rep(i, m) {
        int enter;
        cin >> enter;
        a += enter;
    }
    if(n < a)
        cout << -1;
    else
        cout << n - a << endl;

    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
using namespace std;

int main() {
    int R;
    cin >> R;

    if (R < 1200) {
        cout << "ABC" << endl;
    } else if (R < 2800) {
        cout << "ARC" << endl;
    } else {
        cout << "AGC" << endl;
    }
}

Measured memory_bytes: 256
import java.util.Scanner;

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

    void solve(Scanner sc) {
        int x = sc.nextInt();
        int y = sc.nextInt();

        int xAbs = Math.abs(x);
        int yAbs = Math.abs(y);
        int ans = 0;
        if (x > 0 && xAbs >= yAbs || x < 0 && xAbs < yAbs) {
            ans++;
        }

        ans += Math.abs(xAbs - yAbs);

        if (y > 0 && xAbs >= yAbs || y < 0 && xAbs < yAbs) {
            ans++;
        }

        System.out.println(ans);
    }
}


Measured memory_bytes: 23636
#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>

#define REP(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 0
//#ifdef LOCAL
//#define DEBUG(s) cout << (s) << endl
//#define dump(x)  cerr << #x << " = " << (x) << endl
//#define BR cout << endl;
//#else
//#define DEBUG(s) do{}while(0)
//#define dump(x) do{}while(0)
//#define BR
//#endif


//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 20)
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね

//ここから編集する


int main() {
    ll ok,ng;
    ll N;
    cin >> N;
    ok = 0;
    ng = N+1;

    while(ng - ok > 1){
        ll mid = (ok + ng)/2;
        if(mid * mid > N){
            ng = mid;
        }else{
            ok = mid;
        }
    }
    cout << ok * ok << endl;
    return 0;
}


Measured memory_bytes: 256
A, B, C, D = map(int, input().split())
MOD = 998244353

a = 1
arr = []
for j in range(D-B+1):
    arr.append(a)
    a *= A
    a %= MOD
dp = [arr]

b = B
for i in range(1, C-A+1):
    arr = [b]
    for j in range(1, D-B+1):
        # tate: A+i  yoko: B+j
        x = arr[-1]
        y = dp[-1][j]
        z = dp[-1][j-1]
        h = A+i
        w = B+j
        arr.append((x*h + y*w - z*((h-1)*(w-1))) % MOD)
    b *= B
    b %= MOD
    dp.append(arr)
print(dp[C-A][D-B])

Measured memory_bytes: 139160
a, b = map(int, input(). split())
while a != 0 and b != 0:
  for i in range(b):
    print("#", end="")
  print("")
  for i in range (a-2):
      print("#", end="")
      for j in range (b-2):
          print(".", end="")
      print("#")
  for i in range(b):
    print("#", end="")
  print("")
  print("")
  a, b= map(int, input(). split())



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

int main(){
	int n;
	cin >> n;
	vector<int> p(n);
	rep(i, n) cin >> p.at(i);

	int cnt = 0;
	rep(i, n){
		if(p.at(i) != i+1) cnt++; 
	}

	if(cnt == 2 || cnt == 0) cout << "YES" << endl;
	else cout << "NO" << endl;

	return 0;
}


Measured memory_bytes: 256
n = int(input())
a = [0 for _ in range(n+1)]
for i in range(1,n+1):
  if i*i>n:
    break
  for j in range(1,n+1):
    if i*i + j*j +i*j > n:
      break
    for k in range(1,n+1):
      tmp = i*i + j*j + k*k + i*j + j*k + k*i
      if tmp<=n:
        a[tmp]+=1
      else:
        break
for i in range(1,n+1):
  print(a[i])

Measured memory_bytes: 9196
#include <iostream>
using namespace std;

int main() {
    int width, height, x, y, radius;
    cin >> width >> height >> x >> y >> radius;
    if (x + radius > width || y + radius > height) {
        cout << "No" << endl;
    } else if (x < 0 || y < 0) {
        cout << "No" << endl;
    }else {
        cout << "Yes" << endl;
    }
    return 0;
}


Measured memory_bytes: 3112
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;
typedef long long ll;
int main() {
  int N; cin >> N;
  vector<int> b(N); 
  for(int i=0; i<N-1;i++) cin >> b[i];
  vector<int> a(110);
  for(int i=0; i<N-1;i++) {
    if(i==0) {a[i]=b[i]; a[i+1]=b[i];}
    else if(b[i]<b[i-1]) {a[i]=b[i]; a[i+1]=b[i];}
    else a[i+1]=b[i];
     }
int sum=0;
rep(i, N) sum+= a[i];
cout << sum << endl;

}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.regex.Pattern;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int[] t = createListInt(br);
        int n = t[0];
        int m = t[1];
        int[] list = new int[n];
        int sum = 0;
        int max = 0;
        for (int i = 0; i < n; i++) {
            list[i] = ip(br);
            sum += list[i];
            max = Math.max(max, list[i]);
        }
        int left = max;
        int right = sum;
        while (left < right) {
            int mid = (left + right) / 2;
            int id = 0;
            sum = 0;
            for (int i = 0; i < n; i++) {
                if (sum + list[i] > mid) {
                    sum = list[i];
                    id++;
                } else {
                    sum += list[i];
                }
                if (id == m) {
                    break;
                }
            }
            if (id == m) {
                left = mid + 1;
            } else {
                right = mid;
            }
        }
        System.out.println(left);

    }

    static boolean isNumber(String num) {
        return Pattern.compile("^\\-?[0-9]*\\.?[0-9]+$").matcher(num).find();
    }

    static int[] createListInt(BufferedReader br) throws IOException {
        String[] lines = br.readLine().split(" ");
        int n = lines.length;
        int[] list = new int[n];
        while (n-- > 0) {
            list[n] = Integer.parseInt(lines[n]);
        }
        return list;
    }

    static int ip(BufferedReader s) throws IOException {
        return Integer.parseInt(s.readLine());
    }
}

Measured memory_bytes: 34932
#include <bits/stdc++.h>
using namespace std;
struct jh {
    vector <int> num;
    jh (int n) :num(n) {
        for (int i=0;i<n;i++) num[i]=i;
    }
    int zhao (int x) {
        if (num[x]==x) return x;
        return num[x]=zhao(num[x]);
    }
    bool jiehe (int x,int y) {
        x=zhao(x); y=zhao(y);
        if (x==y) return false;
        num[x]=y;
        return true;
    }
};
struct bian {
    long long u,v,w;
};
bool operator < (const bian &a,const bian &b) {
    return a.w<b.w;
}
int main () {
    int n,q;
    cin>>n>>q;
    vector <bian> bian_new;
    vector <long long> zxhf(n*2,1e10);
    for (int i=0;i<q;i++) {
        long long a,b,c;
        cin>>a>>b>>c;
        bian_new.push_back ({a,b,c});
        zxhf[a]=min(zxhf[a],c+1);
        zxhf[b]=min(zxhf[b],c+2);
        zxhf[a+n]=min(zxhf[a+n],c+1);
        zxhf[b+n]=min(zxhf[b+n],c+2);
    }
    for (int i=1;i<n*2;i++) zxhf[i]=min(zxhf[i],zxhf[i-1]+2);
    for (int i=0;i<n;i++) bian_new.push_back({i,(i+1)%n,zxhf[i+n]});
    sort(bian_new.begin(),bian_new.end());
    jh uf(n);
    long long jg=0;
    for (bian e:bian_new) {
        if (uf.jiehe(e.u,e.v)) jg+=e.w;
    }
    cout<<jg<<endl;
    return 0;
}

Measured memory_bytes: 17772
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t

const int N=1e5+5;
int n,m,a[N],r[N],p[N];

int getroot(int u){
	return p[u]==u?u:p[u]=getroot(p[u]);
}

void joint(int u,int v){
	u=getroot(u);
	v=getroot(v);
	if(u==v) return;
	if(r[u]>r[v]) r[u]+=r[v],p[v]=u;
	else r[v]+=r[u],p[u]=v;
}

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin>>n>>m;
	for(int i=1;i<=n;++i) cin>>a[i];
	for(int i=1;i<=n;++i) r[i]=1,p[i]=i;
	for(int i=0;i<m;++i){
		int x,y;
		cin>>x>>y;
		joint(x,y);
	}
	int res=0;
	for(int i=1;i<=n;++i)
		if(getroot(i)==getroot(a[i])) res++;
	cout<<res<<'\n';
}




Measured memory_bytes: 4696
#include <iostream>
#include <vector>
#include <map>
using namespace std;
using ll = long long;

int main(){
    int n,a;
    ll ans = 0LL;
    cin>>n;
    vector<ll> s(n,0);
    map<ll,ll> mp;
    for(int i=0;i<n;i++){
        cin>>a;
        s[i] += a+(i?s[i-1]:0);
        ++mp[s[i]];
    }
    for(auto el:mp){
        if(el.first==0){
            ans += 1LL*el.second;
        }
        ans += 1LL*el.second*(el.second-1)/2;
    }
    cout<<ans<<"\n";
    return 0;
}


Measured memory_bytes: 14336
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define F first
#define S second
#define PB push_back
#define REP(i,a,b) for (int i = a ; i <= b ; i++)
#define REPI(i,a,b) for (int i = a ; i >= b ; i--)
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

const int OO = 1e9+7;
const int MOD = 1e9+7;
const int N = 1e5+7;

map<int,int> mp;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    //freopen("teleport.in","r",stdin);
    //freopen("teleport.out","w",stdout);

    int n;
    int odd=0,even=0;
    cin >> n;
    int mn = OO;
    int g = -1;
    REP(i,0,n-1)
    {
        int ai;
        cin >> ai;
        if (g == -1) g = ai;
        else g = __gcd(ai,g);
        if (mp[ai]) continue;
        mp[ai]++;
        mn = min(mn,ai);
        if (ai&1) odd++;
        else even++;
    }

    cout << g << endl;
    return 0;
}


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

#define FOR(i,b,e) for(int i=(b); i <= (e); ++i)
#define FORD(i,b,e) for(int i=(b); i >= (e); --i)
#define SIZE(c) (int) (c).size()
#define FORE(i,c) FOR(i,0,SIZE(c)-1)
#define FORDE(i,c) FORD(i,SIZE(c)-1,0)

#define pb push_back
#define mp make_pair
#define st first
#define nd second


using namespace std;

typedef long long ll;
typedef pair <int,int> pii;
typedef pair <ll,ll> pll;

typedef vector <int> VI;
typedef vector <bool> VB;
typedef vector <pii> VP;
typedef vector <ll> VL;
typedef vector <pll> VPL;

typedef vector <VI> VVI;
typedef vector <VL> VVL;
typedef vector <VB> VVB;
typedef vector <VP> VVP;

const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000000000000001LL;


/*************************************************************************/

int main() {
    ios_base::sync_with_stdio(0);
    
    int h, w, d;
    cin >> h >> w >> d;
    
    char col[] = {'R', 'Y', 'G', 'B'};

    auto div = [&](int x) {
        const int T = 100000;
        
        x += T * d;
        x /= d;
        x -= T;
        
        return x;
    };

    FOR(i,0,h-1) FOR(j,0,w-1) {
        int index;
        
        if (d % 2) {
            index = 2 * (i % 2) + j % 2;
        } else {
            int x = i + j;
            int y = i - j;
            
            x = div(x);
            y = div(y);
            
            x %= 2; if (x < 0) x += 2;
            y %= 2; if (y < 0) y += 2;
            
            index = 2 * x + y;
        }
        
        cout << col[index];
        
        if (j == w-1) {
            cout << '\n';
        }
    }

    return 0;
}

/*************************************************************************/


Measured memory_bytes: 512
const input=require('fs').readFileSync('/dev/stdin', 'utf8').split(/[\s]/);const nin=()=>{const r = input[0];input.shift();return Number(r)};const nrin=(n)=>{const a:number[]=[];rep(n,()=>a.push(nin()));return a};const sin=()=>{const r = input[0];input.shift();return String(r)};const out=(...a)=>{console.log(...a)};const floor=(a)=>{return Math.floor(a)};const abs=(a)=>{return Math.abs(a)};const min=(...a)=>{return Math.min(...a)};const max=(...a)=>{return Math.max(...a)};const rep=(n, callback)=>{for(let i = 0;i < n; i++){callback()}};const strrep=(s, i, v)=>{return s.slice(0, i)+v+s.slice(i+1);};const permutation=({result=[],pre=[],post,n=post.length})=>{if(n>0){post.forEach((_,i)=>{const rest=[...post];const elem=rest.splice(i, 1);permutation({result, pre: [...pre,...elem],post:rest,n:n-1})})}else{result.push(pre)}return result};const sw=(s,a:any[],op:'=='|'>='|'>'|'<='|'<'='==')=>{for(let i=0;i<a.length;i+=2){if(op==='=='){if(s==a[i])return a[i+1]}else if(op==='>='){if(s>=a[i])return a[i+1]}else if(op==='<='){if(s<=a[i])return a[i+1]}else if(op==='>'){if(s>a[i])return a[i+1]}else if(op==='<'){if(s<a[i])return a[i+1]}}return a[a.length-1];};const or=(a,...b)=>{for(let i=0;i<b.length;i++)if(a==b[i])return true;return false};const maxindex=(...a)=>{return a.indexOf(Math.max.apply(null,a))};const asc=(ar:number[])=>{return ar.sort((a,b)=>{return a-b})};const desc=(ar:number[])=>{return ar.sort((a,b)=>{return b-a})};const ceil=a=>{return Math.ceil(a)};const srin=s=>{const a:string[]=[];rep(s,()=>a.push(sin()));return a};let ssinteger=-1;const ssin=()=>{ssinteger++;return input[0][ssinteger]};
const main = ()=>{
  let[a,b,c]=nrin(3)
  out(a-b-floor((a-b)/c)*c)
}
main()


Measured memory_bytes: 7372
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <cstdlib>
#define rep(i,n) for(int i = 0;i<(n);i++);
#define all(a) (a).begin(),(a).end()
using namespace std;
using ld = long double;
using ll = long long;
const ll INF = 100100100100100;
ll gcd(ll a,ll b) {//a>b
	if (a < b)swap(a, b);
	if (a % b == 0) return b;
	else return gcd(b, a % b);
}

int main() {
	ll a, b;
	cin >> a >> b;
	b--; a--;
	if (b % a == 0) cout << b / a << endl;
	else {
		cout << b / a + 1 << endl;
	}
}

Measured memory_bytes: 256
///بِسْمِ الّٰلهِ الرَّحْمٰنِ الرَحِيْمِ
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi acos(-1.0)
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    ll int i,n,t,j=0,p,x,a=0,b,l=0,r=0,y,k,c,sum=0,m,d,z;
    cin>>a>>b>>c>>d;
    x=b*c;
    r=b*d;
    y=a*c;
    l=a*d;
    x=max(x,r);
    x=max(y,x);
    x=max(x,l);
    cout<<x<<endl;


    return EXIT_SUCCESS;
}



Measured memory_bytes: 3648
#include <stdio.h>
void main(void){
	
	int x,y;
	
	while(1){
		scanf("%d%d",&x,&y);
		if(x==0 && y==0)break;
		if(x>y){
			printf("%d %d\n",y,x);
		}else{
			printf("%d %d\n",x,y);
		}
	}
}


Measured memory_bytes: 2048
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<tuple>
#include<list>
#include<unordered_map>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define INF (1 << 30) - 1
#define LLINF (1LL << 61) - 1
// #define int ll
using namespace std;
const int MOD = 1000000007;
const int MAX = 510000;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    vector<char> vs;
    cin>>s;
    rep(i,(ll)s.size()){
        if(s[i]=='B' &&s[i+1]=='C'){
            vs.pb('X');i++;
        }
        else{
            vs.pb(s[i]);
        }
    }
    ll now=0,ans=0;
    repr(i,(ll)vs.size()){
        if(vs[i]=='X') now++;
        if(vs[i]=='B'||vs[i]=='C') now=0;
        if(vs[i]=='A'){
            ans+=now;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 788
import java.util.*;

class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int p = sc.nextInt();
    int q = sc.nextInt();
    int r = sc.nextInt();
    int ab =p+q;
    int bc = q+r;
    int ca = r+p;
    System.out.print(Math.min(ab,Math.min(bc,ca)));
  }
}


Measured memory_bytes: 21972
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;

int main()
{
    string S,A;
    cin>>S;
    A="No";
    for(int i=0;i<S.size()/2;i++){
        if(S.size()%2!=0){
            cout<<A<<endl;
            exit(0);
        }else{
            if(S.at(2*i)=='h'&&S.at(2*i+1)=='i'){
                A="Yes";
            }
        }
    }
    cout<<A<<endl;
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ITR(x,c) for(__typeof(c.begin() x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin() x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

#define lf double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll a, b, q; cin >> a >> b >> q;
	vll s(a), t(b);
	rep(i, a) cin >> s[i];
	rep(i, b) cin >> t[i];
	//番兵配置
	s.ins(s.begin(), -1e11);
	s.pb(1e11);
	t.ins(t.begin(), -1e11);
	t.pb(1e11);
	//q個の質問に答える
	while(q--){
		ll x; cin>>x;
		ll s1, s2, t1, t2;
		auto itr = lower_bound(all(s), x);
		s2 = *itr - x;
		itr=prev(itr);
		s1 = x - *itr;
		itr = lower_bound(all(t), x);
		t2 = *itr - x;
		itr=prev(itr);
		t1 = x - *itr;
		ll ans = LONG_LONG_MAX;
		ans = min(ans, max(s1, t1));
		ans = min(ans, max(s2, t2));
		ans = min(ans, s1+t2+min(s1, t2));
		ans = min(ans, s2+t1+min(s2, t1));
		cout << ans << "\n";
	}
	return 0;
}

Measured memory_bytes: 2912
n=int(input())
cnt=0
num=list(map(int,input().split()))
for j in range(len(num)-1):
	for i in range(len(num)-1,0,-1):
		if num[i]<num[i-1]:
			num[i],num[i-1]=num[i-1],num[i]
			cnt+=1
print(' '.join(list(map(str,num))))
print(cnt)


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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n, m, ans = 0;
    cin >> n >> m;
    
    
    if (m > 1)
        ans += (m * (m - 1)) / 2;
    if (n > 1)
        ans += (n * (n - 1)) / 2;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;

struct pro {
	string p;
	long int time;
};
int head,tail;
pro pp[100000];
void push(pro x) {
	pp[tail] = x;
	tail=(tail+1)% 100000;

}
pro pop() {
	pro p3 = pp[head];
	head=(head+1)% 100000;
	return p3;
}
bool isEmpty() {
	if (head == tail)
		return true;
	else
		return false;
}
int main()
{
	int stime;
	int n;
	pro pn,p1;
	long int ctime;
	while (cin >> n) {
		head = 1;
		tail = n + 1;
		ctime = 0;
		cin >> stime;
		for (int i = 1; i <= n; i++) {
			cin >> pp[i].p >> pp[i].time;
		}
		while (!isEmpty()) {
			pn = pop();
			if (pn.time <= stime) {
				ctime += pn.time;
				cout << pn.p << " " << ctime << endl;
			}
			else {
				ctime += stime;
				pn.time -= stime;
				push(pn);
			}
		}

	}
    return 0;
}


Measured memory_bytes: 7040
import java.util.*;

public class Main {

    static Scanner sc = new Scanner(System.in);

    static final int N = 100;
    static final int NOT_VISITED = -1;
    static int n;
    static int[][] mat = new int[N][N];
    static Queue<Integer> q = new ArrayDeque<Integer>();
    static int[] d = new int[N];

    public static void main(String[] args) {
        read();
        init();
        bfs();
        out();
    }

    static void read() {
        int u, k, v;

        n = sc.nextInt();
        for (int i = 0; i < n; i++) {
            u = sc.nextInt();
            k = sc.nextInt();
            for (int j = 0; j < k; j++) {
                v = sc.nextInt();
                mat[u - 1][v - 1] = 1;
            }
        }
    }

    static void init() {
        for (int i = 0; i < n; i++) {
            d[i] = NOT_VISITED;
        }
        d[0] = 0;
    }

    static void bfs() {
        q.add(0);
        while (!q.isEmpty()) {
            int e = q.element(); q.remove();
            for (int i = 0; i < n; i++) {
                if (mat[e][i] == 1) {
                    if (d[i] == NOT_VISITED) {
                        d[i] = d[e] + 1;
                        q.add(i);
                    }
                }
            }
        }
    }

    static void out() {
        for (int i = 0; i < n; i++) {
            System.out.println(String.format("%d %d", i + 1, d[i]));
        }
    }
}

Measured memory_bytes: 29684
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
const ll INF = 1e9+100;
const ll MOD = 1e9+7;
const bool debug = 0;
//-----------------------------------------------//

int N, H;
int a[112345], b[112345];
int main() {
	cin >> N >> H;
	REP(i, N) scanf("%d %d", a + i, b + i);
	
	int ma = *max_element(a, a + N);
	int ans = (H + ma - 1) / ma;
	
	sort(b, b + N, greater<int>());
	REP(i, N) {
		H -= b[i];
		if (H >= 0) chmin(ans, (H + ma - 1) / ma + i + 1);
		else chmin(ans, i + 1);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <limits>
#include <queue>
#include <iomanip>
#include <set>
//#include <bits/stdc++.h>

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

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

using namespace std;
#define ALL(X) X.begin(),X.end()
using ll = long long int;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
const int MOD=1000000007;
//const int MOD=998244353;
const int INTMAX=2147483647;
const ll LLMAX=9223372036854775807;


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    ll N;
    cin>>N;
    vector<string> S(N);
    for(ll i=0;i<N;i++)cin>>S[i];
    
    sort(ALL(S));
    
    ll ans=1;
    for(ll i=1;i<N;i++){
        if(S[i]!=S[i-1])ans++;
    }
    cout<<ans<<endl;
    
    return 0;
}


Measured memory_bytes: 9540
#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++)
#define INF 1000000000000
using ll = long long;


int main(){
  int n,m;
  cin >> n>> m;
  if(n==0)cout<<m*(m-1)/2<<endl;
  else if(m==0)cout<<n*(n-1)/2<<endl;
  else cout<<m*(m-1)/2+n*(n-1)/2<<endl;
  return 0;
}


Measured memory_bytes: 256
N = int(input())
D,X = map(int,input().split())
A = list()
for i in range(N):
	A.append(int(input()))

chocolate = list()

for i in range(N):
	# print(i+1,'人目')
	choco_count = 0
	for j in range(1,D+1):
		day_count = 1 + A[i]*(j-1) 
		if day_count <= D:
			choco_count += 1 
		else:
			break
	# print('choco_count:',choco_count)
	chocolate.append(choco_count)
print(sum(chocolate)+X)

Measured memory_bytes: 3064
#include <iostream>
#include<string>
using namespace std;

class Operator{
public:
    int a, b, j;
    char c;
    int cal(){
        if (c == '+') return a + b;
        else if (c == '-') return a - b;
        else if (c == '*') return a * b;
    }
};

int change(string s){
    int a = s.length(), b = 0;
    for (int i = 0; i < a; i++) {
        int c = s[i]-'0';
        if (a-i > 0) {for (int j = 1; j < a-i; j++) c *= 10;}
        b += c;
    }
    return b;
}

int main(){
    int o = 0, n = 0, m = 0, l = 0;
    string s;
    Operator O[100];
    int N[100];
    while (cin >> s){
        if (s[0] == '+' || s[0] == '-' || s[0] == '*') {
            O[o].c = s[0]; O[o].j = l;
            if (o == 0) {O[o].a = N[n-2]; O[o].b = N[n-1]; n -= 2;}
            else if (O[o].j == O[o-1].j+1) {
                if (o == 1 || (O[o].j == O[o-2].j+2 && n != 0) || O[o].j >= O[o-2].j+5) {
                    O[o].a = N[n-1]; O[o].b = O[o-1].cal(); n--;
                }
                else {
                    int y, z = 0;
                    if (O[o-1].j >= O[o-2].j+3) y = o-2;
                    else {
                        for (int x = o-2; x >= 0; x--){
                            if (O[x].j >= O[x-1].j+3) { y = x-1; break; }
                        }
                    }
                    O[o].a = O[y].cal(); O[o].b = O[o-1].cal();
                }
            }
            else if (O[o].j == O[o-1].j+2) {
                O[o].a = O[o-1].cal(); O[o].b = N[n-1]; n--;
            }
            else { O[o].a = N[n-2]; O[o].b = N[n-1]; n -= 2;}
            o++;
        }
        else { 
            if (n <= 0)  n = 0;
            N[n] = change(s); n++;
        }
        l++;
    }
    cout << O[o-1].cal() << endl;
    return 0;
}



Measured memory_bytes: 3216
($H,$W)=glob<>;
@a=glob`dd`;
for(1..$H*$W){
	if($a[$_-1]%2){
		if($_%$W){
			++$a[$_];
			push@_,$_-1,$_
		}elsif($_<$H*$W){
			++$a[$_-1+$W];
			push@_,$_-1,$_-1+$W
		}
	}
}
print@_/2,$/,map{$_/$W+1|0,$",$_%$W+1,--$|?$":$/}@_


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

using namespace std;
using ll = long long;

int main() {
    ll n;
    cin>>n;
    string ans="";
    while(n>0){
        --n;
        ans.push_back(n%26+'a');
        n/=26;
    }
    reverse(ans.rbegin(),ans.rend());
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3624
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#define fi first
#define se second
#define L(i,u) for (int i=head[u]; i!=0; i=nxt[i])
#define rep(i,a,b) for (register int i=a; i<=b; i++)
#define per(i,a,b) for (register int i=a; i>=b; i--)
typedef long long ll;
using namespace std;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
inline void read(int &x) {
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
const int N = 300033;
int n,l[N],r[N];
int a[N],b[N]; bool gg[N];
bool cmp1(int x, int y) {return r[x]<r[y];}
bool cmp2(int x, int y) {return l[x]>l[y];}
int Abs(int x) {return x>0?x:-x;}
ll getans() {
	ll res=0,p=0; memset(gg,0,sizeof(gg));
	rep(i,1,n) a[i]=i,b[i]=i;
	sort(a+1,a+n+1,cmp1);sort(b+1,b+n+1,cmp2);
	int p1=1,p2=1,now=0;
	while (p1<=n&&p2<=n) {
		if (!now) {
			while (p1<=n&&gg[a[p1]]) p1++;
			if (p1<=n&&!gg[a[p1]]) {
				int u=a[p1];
				if (r[u]<p) {res+=Abs(p-r[u]); p=r[u];}
				p1++;
			}
		}
		else {
			while (p2<=n&&gg[b[p2]]) p2++;
			if (p2<=n&&!gg[b[p2]]) {
				int u=b[p2]; 
				if (p<l[u]) {res+=Abs(p-l[u]); p=l[u];}
				p2++;
			}
		}
		now^=1;
	}
	return res+Abs(p);
}
int main() {
	read(n);rep(i,1,n)read(l[i]),read(r[i]);
	ll res=0; res=max(res,getans());
	rep(i,1,n) {int x=l[i],y=r[i];l[i]=-y;r[i]=-x;} 
	res=max(res,getans());
	/*rep(i,1,n)
		if (r[i]<0) a[++len1]=-r[i];
		else if (l[i]>0) b[++len2]=l[i];
	sort(a+1,a+len1+1); sort(b+1,b+len2+1); 
	ll res=0;
	if (len1<len2) {
		for (int i=len1,cnt=1; i>=1&&cnt<=len1; cnt++,i--) res+=a[i];
		for (int i=len2,cnt=1; i>=1&&cnt<=len1+1; cnt++,i--) res+=b[i];
	}
	else {
		for (int i=len1,cnt=1; i>=1&&cnt<=len2+1; cnt++,i--) res+=a[i];
		for (int i=len2,cnt=1; i>=1&&cnt<=len2; cnt++,i--) res+=b[i];
	}*/
	cout<<res;
	return 0;
}


Measured memory_bytes: 3456
#include<iostream>
#include<vector>
#include<string>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= (int)end; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    ll ans = 0;
    ll U, V;
    rep(i, 0, N - 1) {
        cin >> U >> V;
        if (U > V) {
            swap(U, V);
        }
        ans -= U * (N - V + 1);
    }
    rep(i, 0, N) {
        ans += (ll)(i + 1) * (N - i);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3652
import sys

def main():
  input = sys.stdin.readline
  N = int(input())
  W = [str(input().strip()) for _ in range(N)]
  
  if len(W) != len(set(W)):
    ans = 'No'
  else:
    ans = 'Yes'
    for i in range(N-1):
      a, b = W[i], W[i+1]
      if a[-1] != b[0]:
        ans = 'No'
        break
  
  print(ans)


if __name__ == '__main__':
  main()

Measured memory_bytes: 3064
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
namespace MF{
	#define MAXN 25252
	#define MAXM 364364//実際の辺の2倍必要！！
	#define wint lint
	const wint wEPS=0;
	const wint wINF=1001001001001001LL;
	int n,m,ptr[MAXN],next[MAXM],zu[MAXM];
	int from[MAXM];
	wint capa[MAXM],tof;
	int lev[MAXN],see[MAXN],que[MAXN],*qb,*qe;
	void init(int _n){
		n=_n;m=0;memset(ptr,~0,n*4);
	}
	void ae(int u,int v,wint w0,wint w1=0){
		from[m]=u;
		next[m]=ptr[u];ptr[u]=m;zu[m]=v;capa[m]=w0;++m;
		from[m]=v;
		next[m]=ptr[v];ptr[v]=m;zu[m]=u;capa[m]=w1;++m;
	}
	wint augment(int src,int ink,wint flo){
		if(src==ink) return flo;
		wint f;
		for(int &i=see[src];~i;i=next[i]) if(capa[i]>wEPS && lev[src]<lev[zu[i]]){
			if((f=augment(zu[i],ink,min(flo,capa[i])))>wEPS){
				capa[i]-=f;capa[i^1]+=f;return f;
			}
		}
		return 0;
	}
	bool solve(int src,int ink,wint flo=wINF){
		wint f;
		int i,u,v;
		for(tof=0;tof+wEPS<flo;){
			qb=qe=que;
			memset(lev,~0,n*4);
			for(lev[*qe++=src]=0,see[src]=ptr[src];qb!=qe;){
				for(i=ptr[u=*qb++];~i;i=next[i]) if(capa[i]>wEPS && !~lev[v=zu[i]]){
					lev[*qe++=v]=lev[u]+1;see[v]=ptr[v];
					if(v==ink) goto au;
				}
			}
			return 0;
		au:	for(;(f=augment(src,ink,flo-tof))>wEPS;tof+=f);
		}
		return 1;
	}
}
int a[110];
int main()
{
	int n;lint out=0;cin>>n;
	rep(i,n) cin>>a[i];
	int S=n,T=n+1,V=n+2;
	MF::init(V);
	rep(i,n){
		if(a[i]>0) out+=a[i],MF::ae(i,T,a[i]);
		else MF::ae(S,i,-a[i]);
	}
	rep(i,n) REP(j,i+1,n){
		if((j+1)%(i+1)==0) MF::ae(i,j,MF::wINF);
	}
	MF::solve(S,T);
	cout<<out-MF::tof<<endl;
}


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

using namespace std;

int main(){
  int n;
  cin>>n;
  int sum500= (n/500);
  n -= (sum500)*500;
  sum500*=1000;
  int sum50= n/5;
  sum50*=5;
  cout<<sum500+sum50;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(void){
  int i;
  char s[11], t[12];
  scanf("%s%s", &s ,&t);
  for(i=0;i<strlen(s);i++){
      if(s[i]!=t[i]) break;
  }
  if(i==strlen(s)){
    printf("Yes");
  }
  else{
    printf("No");
  }
  return 0;
}
  
  


Measured memory_bytes: 1736
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
const double eps = 1e-8;
const int MOD = 1000000007;
// int main() {
//     cin.tie(0);
//     ios::sync_with_stdio(false);
//     cout << fixed << setprecision(10);
//
// }
template<typename T>
struct edge {
    int src, to;
    T cost;
    // edge(int src, int to, T cost): src(src), to(to), cost(cost) {}
    // // G[i].push_back({src, to, cost}) requires no constructor
};
template<typename T>
using Graph = vector<vector<edge<T>>>;
struct UnionFind
{
    vector<int> par, sz;
    UnionFind(int n) : par(n), sz(n, 1) {
        for (int i = 0; i < n; ++i) par[i] = i;
    }
    int root(int x) {
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }
    void merge(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return;
        if (sz[x] < sz[y]) swap(x, y);
        par[y] = x;
        sz[x] += sz[y];
        sz[y] = 0;
    }
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
    int size(int x) {
        return sz[root(x)];
    }
};
template<typename T>
T kruskal(vector<edge<T>> &es, int V) {
    UnionFind uf(V);
    T ret = 0;
    // sort destructively
    sort(es.begin(), es.end(), [](edge<T> &a,edge<T> &b){
            return a.cost < b.cost;
            });
    for (auto &e : es) {
        if (!uf.issame(e.src, e.to)) {
            ret += e.cost;
            uf.merge(e.src, e.to);
        }
    }
    // // sort only the order to check
    // vector<int> ord(es.size());
    // iota(ord.begin(), ord.end(), 0);
    // sort(ord.begin(), ord.end(), [&](int i,int j){
    //         return es[i].cost < es[j].cost;
    //         });
    // for (auto i : ord) {
    //     auto &e = es[i];
    //     if (!uf.issame(e.src, e.to)) {
    //         ret += e.cost;
    //         uf.merge(e.src, e.to);
    //     }
    // }
    return ret;
}
int main() {
    int V, E;
    cin >> V >> E;
    vector<edge<int>> edges;
    for(int i = 0; i < E; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        edges.push_back({a, b, c});
    }
    cout << kruskal(edges, V) << endl;
}



Measured memory_bytes: 4588
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
using namespace std;
#define ALL(x) (x).begin(), (x).end()
#define OUT(x) cout << (x) << endl
typedef long long ll;

ll MOD = 1e9 + 7;
int main() {
    int n;
    cin >> n;
    ll a[n];
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

    ll ans = 0;
    for (int i = 0; i < 62; i++) {
        ll cnt0 = 0, cnt1 = 0;
        for (int j = 0; j < n; j++) {
            if (a[j] & (1LL << i))
                cnt1++;
            else
                cnt0++;
        }
        ll tmp = cnt0 * cnt1;
        for (int j = 0; j < i; j++) {
            tmp *= 2;
            tmp %= MOD;
        }
        ans += tmp;
        ans %= MOD;
    }
    OUT(ans);
}


Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <algorithm>

int main() {
	int a, b, m;
	std::cin >> a >> b >> m;

	std::vector<int> rs(a), es(b);
	for (auto&& e : rs)
		std::cin >> e;
	for (auto&& e : es)
		std::cin >> e;

	int ans = *std::min_element(rs.begin(), rs.end()) + *std::min_element(es.begin(), es.end());
	for (int i = 0; i < m; ++i) {
		int x, y, c;
		std::cin >> x >> y >> c;
		--x, --y;

		ans = std::min(ans, rs[x] + es[y] - c);
	}

	std::cout << ans << std::endl;
}

Measured memory_bytes: 1024