akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;

ll A, B;
int a[63], b[63];

int main() {
	scanf("%lld%lld", &A, &B); swap(A, B);
	
	if (A == B) {puts("1"); return 0;}
	
	for (int i = 60; i >= 0; --i)
		if ((A >> i) & 1)
			a[i] = 1;
	for (int i = 60; i >= 0; --i)
		if ((B >> i) & 1)
			b[i] = 1;
	
	int tmp = 60;
	while (a[tmp] == b[tmp]) --tmp;
	
	A &= ((1ll << tmp) - 1);
	B &= ((1ll << tmp) - 1);
	
	ll ans = (1ll << tmp) - B;
	
	ll lb = 1;
	while (A) {A >>= 1; lb <<= 1;}
	--lb;
	
	if (B <= lb)
		ans += (1ll << tmp);
	else
		ans += (1ll << tmp) - (B - lb - 1);
	
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main()
{long long int k;
 string s;
 cin>>k>>s;
 if(s.size()<=k)
   cout<<s;
 else
 {string s1=s.substr(0,k);
  string s2="...";
  s1=s1+s2;
  cout<<s1;
 }
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
typedef complex<double> P; //Point
typedef pair<P,P> L; //Line, Segment

const double EPS = 1e-9;
const double PI = 6.0 * asin(0.5);

namespace std {
  bool operator < (const P& a, const P& b){
    return fabs(real(a)-real(b)) < EPS ? imag(a) < imag(b) : real(a) < real(b);
  }
}

double dot(P a, P b){ return real(conj(a)*b); }
double cross(P a, P b){ return imag(conj(a)*b); }

int ccw(P a, P b, P c){
  b -= a;
  c -= a;
  if(cross(b,c) > EPS) return 1;
  if(cross(b,c) < -EPS) return -1;
  if(dot(b,c) < -EPS) return 2;
  if(norm(b) < norm(c)) return -2;
  return 0;
}

bool isIntersect(L s1, L s2){
  return ( ccw(s1.first,s1.second,s2.first) * ccw(s1.first,s1.second,s2.second) <= 0 &&
           ccw(s2.first,s2.second,s1.first) * ccw(s2.first,s2.second,s1.second) <= 0 );
}

vector<P> convex_hull(vector<P> v){
  vector<P> c; 
  sort(v.begin(),v.end());
  c.assign(v.begin(),v.begin()+2);
    
  for(int i=2;i<v.size();i++){
    P a = c[c.size()-1] - c[c.size()-2];
    P b = v[i] - c[c.size()-2];
        
    while(cross(a,b) > EPS){
      c.pop_back();
      if(c.size() < 2) break;
      a = c[c.size()-1] - c[c.size()-2];
      b = v[i] - c[c.size()-2];
    }
    c.push_back(v[i]);
  }
	
  int n = c.size();
  c.push_back(v[v.size()-2]);
	
  for(int i=v.size()-3;i>=0;i--){
    P a = c[c.size()-1] - c[c.size()-2];
    P b = v[i] - c[c.size()-2];
        
    while(cross(a,b) > EPS){
      c.pop_back();
      if(c.size() < n + 1) break;
      a = c[c.size()-1] - c[c.size()-2];
      b = v[i] - c[c.size()-2];
    }
    c.push_back(v[i]);
  }
  c.pop_back();
  return c;
}


vector<P> p1,p2;
int n,m;
int solve(){
  if(n+m<3) return 1;
  if(m==1&&n==2) return ccw(p1[0],p1[1],p2[0])!=0;
  if(n==2&&m==2) return !isIntersect(L(p1[0],p1[2]),L(p2[0],p2[1]));

  if(n<3) return 0;
  vector<P> t=convex_hull(p1);
  for(int i=0;i<=(int)t.size();i++){
    int flg=1;
    for(int j=0;j<m&&flg;j++)
      if(ccw(t[i],t[(i+1)%t.size()],p2[j])!=1)flg=0;
    if(flg) return 1;
    
  }
  return 0;  
}


int main(){
  while(1){
    cin>>n>>m;
    if(!n&&!m)return 0;
    p1.resize(n),p2.resize(m);
    for(int i=0,a,b;i<n;i++)cin>>a>>b,p1[i]=P(a,b);
    for(int i=0,a,b;i<m;i++)cin>>a>>b,p2[i]=P(a,b);
    int ans=solve();
    swap(p1,p2);
    swap(n,m);
    ans|=solve();
    cout<<(ans?"YES":"NO")<<endl;
  }
  return 0;
}

Measured memory_bytes: 3124
/******************************************
* AHAM BRAHMASHMI ;) *
******************************************/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define sz(x) ((int)(x).size())
#define F first
#define S second


int main()
{

#ifndef ONLINE_JUDGE
	// for getting input from input.txt
	freopen("input.txt", "r", stdin);
	// for writing output to output.txt
	freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
//ios_base& scientific (ios_base& str);

	string s, t;
	cin >> s;
	cin >> t;
	int found = 1;
	if (s.length() + 1 == t.length())
	{
		for (int i = 0; i < s.length(); i++)
		{
			if (s[i] != t[i])
			{
				found = 0;
				break;
			}
		}
		if (found)
			cout << "Yes\n";
		else
			cout << "No\n";
	}
	else
	{
		cout << "No\n";
	}

	return 0;
}

Measured memory_bytes: 3660
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#include<set>
#include<complex>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define CC puts("-------ok--------");
#define all(in) in.begin(), in.end()
#define bv vector<bool>
using namespace std;
typedef pair<int, int>PA;
using namespace std;
#define MAX 1000
int main(){
    vi v(10,0);
    int n;char c; string s;
    while(cin>>n>>c>>s){
        if(s == "A")v[0]++;
        if(s == "B")v[1]++;
        if(s == "AB")v[2]++;
        if(s== "O")v[3]++;
    }
    rep(i,4)cout<<v[i]<<endl;
    
}

Measured memory_bytes: 2968
import math

def main():
    N = int(input())
    T, A = map(int, input().split())
    H = list(map(int, input().split()))
    i = 1
    for Hi in H:
        Hi_t = T - Hi * 0.006
        temp = math.fabs(A - Hi_t)
        if i == 1:
            result = temp
            answer = i
        else:
            if result > temp:
                result = temp
                answer = i
        i += 1

    print(answer)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define int long long
#define F first
#define S second
using namespace std;
const int N=1e+6;
pair<int,int> a[101];
int dp[101][N+1];
main()
{
    int n,w,goal=0;
    scanf("%lld%lld",&n,&w);
    for(int i=1; i<=n; i++)
        scanf("%lld%lld",&a[i].S,&a[i].F);
    sort(a+1,a+n+1);
    for(int i=0; i<=n; i++){
        for(int j=1; j<=N; j++)
            dp[i][j]=1e11;
    }
    for(int i=1; i<=n; i++){
        goal+=a[i].F;
        for(int j=1; j<=goal; j++){
            if(a[i].F>=j)
                dp[i][j]=min(a[i].S,dp[i-1][j]);
            else
                dp[i][j]=min(a[i].S+dp[i-1][j-a[i].F],dp[i-1][j]);
        }
    }
    int it=0;
    while(dp[n][it]<=w&&it<=N){
        it++;
    }
    printf("%lld\n",it-1);
}


Measured memory_bytes: 792772
program main
  implicit none

  integer :: n, d, a(10,10), i, j, c, k, di

  read(*,*)n,d
  do i = 1, n
    read(*,*)(a(i,j),j = 1, d)
  end do
  c = 0
  do i = 1, n - 1
    do j = i + 1, n
      di = 0
      do k = 1, d
        di = di + (a(i,k) - a(j,k))**2
      end do
      if ((di - nint(sqrt(real(di)))**2) == 0) then
        c = c + 1
      end if
    end do
  end do

  write(*,*)c

end program main

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <set>

using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
int h[5];
void solve() {
    set<int> s;
    rep(i, 5) s.insert(h[i]);
    if (s.size() == 3 || s.size() == 1) {
        rep(i, 5) cout << "3" << endl;
    } else {
        int a1 = *max_element(h, h + 5);
        int a2 = *min_element(h, h + 5);
        int b1, b2;
        if ((a1 + 1) % 3 == a2) {
            b1 = 1;
            b2 = 2;
        } else {
            b1 = 2;
            b2 = 1;
        }
        rep(i, 5) {
            if (h[i] == a1)
                cout << b1 << endl;
            else
                cout << b2 << endl;
        }
    }
}
int main() {
    while (cin >> h[0], h[0]) {
        rep(i, 4) cin >> h[i + 1];
        solve();
    }
}

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

namespace ABC048
{
    public class QuestionB
    {
        public static void Main(string[] args)
        {
            var abx = Console.ReadLine().Split().Select(long.Parse).ToArray();
            var (a, b, x) = (abx[0], abx[1], abx[2]);

            var count = F(b, x) - F(a - 1L, x);

            Console.WriteLine(count);
        }

        private static long F(long n, long x)
        {
            if (n >= 0)
            {
                return n / x + 1;
            }
            else
            {
                return 0;
            }
        }
    }
}


Measured memory_bytes: 28228
import os
import sys

import numpy as np


def solve(inp):
    def dfs(links, s, checked, postorder):
        stack = [0, s]
        while stack:
            i, v = stack[-2:]
            if i == 0 and checked[v]:
                stack.pop()
                stack.pop()
                continue
            checked[v] = 1
            if i == len(links[v]):
                postorder.append(v)
                stack.pop()
                stack.pop()
                continue
            stack[-2] += 1
            stack.append(0)
            stack.append(links[v][i])

    def dfs2(rev_links, s, checked):
        q = [s]
        checked[s] = 1
        scc = [s]
        while q:
            v = q.pop()
            for u in rev_links[v]:
                if checked[u] == 0:
                    q.append(u)
                    checked[u] = 1
                    scc.append(u)
        return scc

    n = inp[0]
    m = inp[1]
    aaa = inp[2::2]
    bbb = inp[3::2]

    int_list = [0]
    int_list.clear()
    links = [int_list.copy() for _ in range(n)]
    rev_links = [int_list.copy() for _ in range(n)]

    for i in range(m):
        a = aaa[i]
        b = bbb[i]
        if a != b:
            links[a].append(b)
            rev_links[b].append(a)

    checked = np.zeros(n, np.int8)
    postorder = []

    for v in range(n):
        if checked[v]:
            continue
        dfs(links, v, checked, postorder)

    postorder.reverse()
    checked = np.zeros(n, np.int8)
    sccs = []

    for v in postorder:
        if checked[v]:
            continue
        sccs.append(dfs2(rev_links, v, checked))

    return sccs


if sys.argv[-1] == 'ONLINE_JUDGE':
    from numba.pycc import CC

    cc = CC('my_module')
    cc.export('solve', '(i8[:],)')(solve)
    cc.compile()
    exit()

if os.name == 'posix':
    # noinspection PyUnresolvedReferences
    from my_module import solve
else:
    from numba import njit

    solve = njit('(i8[:],)', cache=True)(solve)
    print('compiled', file=sys.stderr)

inp = np.fromstring(sys.stdin.read(), dtype=np.int64, sep=' ')
ans = solve(inp)
print(len(ans))
for scc in ans:
    print(len(scc), *scc)


Measured memory_bytes: 246256
N=int(input())
A=list(map(int,input().split()))
A.sort(reverse=True)
ans=0
half=N//2+N%2
for i in range(1,N):
    if i<half:
        ans+=A[i-1]
    elif i==N-1:
        ans+=A[half-1]
    else:
        ans+=A[i-half+1]

print(ans)

Measured memory_bytes: 31440
import java.util.*;

public class Main {
    public static double solve(int n, int[] amount) {
      int limit = 301;
      // Mr. new int[1001], idk how to calc it properly, 301 should be enough
      double[][][] dp = new double[limit][limit][limit];
      
      for(int i = 0; i < limit; i++) {
        for(int j = 0; j < limit; j++) {
            Arrays.fill(dp[i][j],-1);
        }
      }
      
      double result = dfs(dp, n, amount[1], amount[2], amount[3]);
      
      return result;
    }
  
  	private static double dfs (double[][][] dp, int n, int oneSushi, int twoSushi, int threeSushi){
      if(oneSushi == 0 && twoSushi == 0 && threeSushi == 0){
        return 0;
      }
      if(dp[oneSushi][twoSushi][threeSushi] != -1) {
        return dp[oneSushi][twoSushi][threeSushi];
      }
      
      double prob = (double) n / (oneSushi + twoSushi + threeSushi);
      double result = 0;
      
      int sum = oneSushi + twoSushi + threeSushi;
      if (oneSushi > 0){
        result += (prob + dfs(dp, n, oneSushi - 1, twoSushi, threeSushi)) * oneSushi / sum;
      }
      
      if (twoSushi > 0) {
        //if we take one sushi from the plate with two, there would be one additional 
        //table with one sushi, hence oneSushi+1, twoSushi -1
        result += (prob + dfs(dp, n, oneSushi + 1, twoSushi - 1, threeSushi)) * twoSushi / sum;
      }
      if(threeSushi > 0) {
        //same logic here, once we pick up from c, the result would be twoSushi+1, threeSushi-1
        result += (prob + dfs(dp, n, oneSushi, twoSushi + 1,threeSushi-1)) * threeSushi / sum; 
      }
      
      dp[oneSushi][twoSushi][threeSushi] = result;
      return result;
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        
      	int[] vals = new int[4];
        for (int i = 0; i < n; i++) {
          int val = scanner.nextInt();
          vals[val]++;
        }

      	double result = solve(n, vals);
      
        System.out.println(result);
    }
}


Measured memory_bytes: 307784
#include "bits/stdc++.h"
using namespace std;

int main()
{
  int x,n,ans,a,b;
  cin>>x>>n;
  if(n==0)
  {
    ans=x;
  }
  else
  {
    vector<int> p(n);
    for(int i=0;i<n;i++)
    {
      cin>>p.at(i);
    }
    for(int i=x;i<=101;i++)
    {
      int h=0;
      for(int j=0;j<n;j++)
      {
        if(p.at(j)==i)
        {
          h=1;
          break;
        }
      }
      if(h==0)
      {
        a=i;
        break;
      }
    }
    for(int i=x;i>=-100;i--)
    {
      int h=0;
      for(int j=0;j<n;j++)
      {
        if(p.at(j)==i)
        {
          h=1;
          break;
        }
      }
      if(h==0)
      {
        b=i;
        break;
      }
    }
    if(a-x>=x-b)
      ans=b;
    else
      ans=a;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3632
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner scanner = new Scanner(System.in);

		//入力表示
		int N = scanner.nextInt();

		//配列に箱を作る
		int[] d = new int[N];
		int A = 0;
		
		//d表示をする
		for (int i = 0; i < N; i++) {
			d[i] = scanner.nextInt();
		}
        //Aの中にi.jを入れる
		for (int i = 0; i < N; i++) {
			for (int j = i + 1; j < N; j++) {
				A = A + d[i] * d[j];
			}
		}
		System.out.println(A);
	}
}

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

int main(){
    double r; cin >> r;
    double ans = r * 2 * 3.14159265358979;
    printf("%.10f\n",ans);
}

Measured memory_bytes: 3784
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9;
const int MOD = 1e9 + 7;

struct Edge
{
  int from, to, cost;
};

int main()
{
  int n, m;
  cin >> n >> m;
  int dist[110][110] = {};

  vector<Edge> es(m);

  for (int i = 0; i < m; ++i)
  {
    cin >> es[i].from >> es[i].to >> es[i].cost;
  }

  for (int i = 1; i <= n; ++i)
  {
    for (int j = 1; j <= n; ++j)
    {
      if (i == j)
        dist[i][j] = 0;
      else
        dist[i][j] = INF;
    }
  }

  for (int i = 0; i < m; ++i)
  {
    dist[es[i].from][es[i].to] = min(dist[es[i].from][es[i].to], es[i].cost);
    dist[es[i].to][es[i].from] = min(dist[es[i].to][es[i].from], es[i].cost);
  }

  for (int k = 1; k <= n; ++k)
  {
    for (int i = 1; i <= n; ++i)
    {
      for (int j = 1; j <= n; ++j)
      {
        dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
      }
    }
  }

  int ans = m;
  for (int i = 0; i < m; ++i)
  {
    bool shortest = false;
    for (int j = 1; j <= n; ++j)
    {
      if (dist[j][es[i].from] + es[i].cost == dist[j][es[i].to])
        shortest = true;
    }
    if (shortest)
      ans--;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i = 0; i < N; i++)
using vi = vector<int>;
using vvi = vector<vi>;

int main() {
    int N, X, Y;
    scanf("%d %d %d", &N, &X, &Y);
    vvi graph(N);
    graph[X - 1].push_back(Y - 1);
    graph[Y - 1].push_back(X - 1);

    rep(i, N - 1) {
        graph[i].push_back(i + 1);
        graph[i + 1].push_back(i);
    }
    queue<int> seen;

    vi dist(N, -1);
    vi cnt(N, 0);

    rep(i, N) {
        seen.push(i);
        dist[i] = 0;
        while (seen.size()) {
            int v = seen.front(); seen.pop();
            for (auto x : graph[v]) {
                if (dist[x] != -1) continue;
                seen.push(x); dist[x] = dist[v] + 1;
                cnt[dist[x] - 1]++;
            }
        }
        dist.assign(N, -1);
    }
    rep(i, N - 1) {
        printf("%d\n", cnt[i] / 2);
    }
}

Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <cmath>
#include <queue>
#include <map>
#include <cstring>
#include <string>
#include <set>
#include <vector>
#include <list>
#include <deque>
#include <algorithm>
#include <stack>
#include <numeric>
#include <time.h>
#include<iomanip>
#pragma warning(disable:4996)
using namespace std;
const int inf = 0x7f7f7f7f;
const long long mod = 1e9 + 7;
int main()
{
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	cout << min(a, b) + min(c,d) << endl;
}
// 运行程序: Ctrl + F5 或调试 >“始执行(不调试)”菜单
// 调试程序: F5 或调试 >“开始调试”菜单
// 入门提示:
//   1. 使用解决方案资源管理器窗口添 加/管理文件
//   2. 使用团队资源管理器窗口连接到源代码管理
//   3. 使用输出窗口查看生成输出和其他消息
//   4. 使用错误列表窗口查看错误
//   5. 转到“项目”>“添加新项”以创建新的代码文件，或转到“项目”>“添加现有项”以将现有代码文件添加到项目
//   6. 将来，若要再次打开此项目，请转到“文件”>“打开”>“项目”并选择 .sln 文件

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

int main() {
  ll N,M,ans = 0; cin >> N >> M;
  vector<ll>A(2*N);
  rep(i,2*N){
    cin >> A[i];
  }
  rep(i,N){
    if(A[i*2]*A[i*2] + A[i*2+1]*A[i*2+1] <= M*M){
      ans++;
    }
  }
  cout << ans;
}

  

Measured memory_bytes: 6428
import java.util.Scanner;

public class Main {
        public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            int a = sc.nextInt();
            int b = sc.nextInt();
            int area =a * b;
            int length = 2 * (a + b);
            System.out.println(area + " " + length);
            sc.close();
        }
}


Measured memory_bytes: 26204
/*  ***  In The Name of God ... ***  */ 
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

#define int long long
#define all(v) v.begin() , v.end()
#define pb push_back
#define endl '\n' 
template<typename T> inline bool smin(T &a, const T &b){ return b < a ? a = b,1:0;}
template<typename T> inline bool smax(T &a, const T &b){ return a < b ? a = b,1:0;}

int n , a , b ;  

int32_t main()
{
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n >> a >> b ;
	if ( abs ( a - b ) & 1 )
		cout << "Borys" ;
	else
		cout << "Alice" ; 
}


Measured memory_bytes: 256
n = int(input())
s = input()

i = 0
ee = []
ww = []

while i < n:
    j = i
    count = 1
    while j < n-1 and s[j] == s[j+1]:
        count += 1
        j += 1
    if s[j] == 'E':
        ee.append(count)
        ww.append(0)
    else:
        ww.append(count)
        ee.append(0)
    i = j+1
acume = [0 for _ in range(len(ee)+1)]
acumw = [0 for _ in range(len(ww)+1)]
for i, w in enumerate(ww):
    acumw[i+1] = acumw[i] + w
for i, e in enumerate(ee[::-1]):
    acume[i+1] = acume[i] + e
acume = acume[::-1]

minp = 10**6
for i in range(len(acume)):
    minp = min(minp, max(acumw[i]+acume[i], 0))
print(minp)

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

int Koyakusu(int a,int b)
{
  if(a<b)
  {
    int temp=b;
    b=a;
    a=temp;
  }
  if(a%b==0)
    return b;
  else
  {
    return Koyakusu(b,a%b);
  }
}

int main()
{
  int n;
  cin>>n;
  
  int64_t sum=0;
  
  for(int i=1;i<n+1;i++)
  {
    for(int j=1;j<n+1;j++)
    {
      for(int k=1;k<n+1;k++)
      {
        sum+=Koyakusu(Koyakusu(i,j),k);
      }
    }
  }
  cout<<sum<<endl;
}
  
  
  

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

using namespace std;

int main(){
    int n,m;
    cin>>n>>m;
    vector<string> fv(n);
    vector<string> bv(n);
    for (int i = 0; i < n; ++i) {
        cin>>fv[i];
        bv[i]=string(fv[i].rbegin(),fv[i].rend());
    }
    sort(fv.begin(),fv.end());
    sort(bv.begin(),bv.end());
    for (int i = 0; i < m; ++i) {
        long long ans=0;
        string t;
        cin>>t;
        int f=0;
        if(t.back()=='*'){
            f=1;
            t=t.substr(0,t.size()-1);
        }
        if(t[0]=='*'){
            f=2;
            t=t.substr(1,t.size()-1);
        }
        int wpos=-1;
        for (int j = 0; j < t.size(); ++j) {
            if(t[j]=='?'){
                wpos=j;
                break;
            }
        }
        if(wpos==-1){
            if(f==2){
                string s=string(t.rbegin(),t.rend());
                auto itl=lower_bound(bv.begin(),bv.end(),s);
                s.back()++;
                auto itr=lower_bound(bv.begin(),bv.end(),s);
                ans+=itr-itl;
            }
            else if(f==1){
                auto itl=lower_bound(fv.begin(),fv.end(),t);
                t.back()++;
                auto itr=lower_bound(fv.begin(),fv.end(),t);
                ans+=itr-itl;
            }
            else{
                auto itl=lower_bound(fv.begin(),fv.end(),t);
                if(itl!=fv.end()&&t==*itl)++ans;
            }
        }
        else{
            if(f==2){
                for (char c = 'a'; c <= 'z'; ++c) {
                    t[wpos]=c;
                    string s = string(t.rbegin(), t.rend());
                    auto itl = lower_bound(bv.begin(), bv.end(), s);
                    s.back()++;
                    auto itr = lower_bound(bv.begin(), bv.end(), s);
                    ans += itr - itl;
                }
            }
            else if(f==1){
                for (char c = 'a'; c <= 'z'; ++c) {
                    t[wpos]=c;
                    string tt=t;
                    auto itl = lower_bound(fv.begin(), fv.end(), tt);
                    tt.back()++;
                    auto itr = lower_bound(fv.begin(), fv.end(), tt);
                    ans += itr - itl;
                }
            }
            else{
                for (char c = 'a'; c <= 'z'; ++c) {
                    t[wpos]=c;
                    auto itl=lower_bound(fv.begin(),fv.end(),t);
                    if(itl!=fv.end()&&t==*itl)++ans;
                }
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}


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

#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//以降 cin の入力元が 'input.txt' になる
//std::ifstream in("input.txt");
//std::cin.rdbuf(in.rdbuf());

signed main()
{
    gearup;
    int n; cin >> n;
    vl a(n);
    int odd = 0;
    rep(i,n){
        cin >> a[i];
        if(a[i] & 1)odd++;
    }
    if(odd % 2 == 0)out("YES");
    else out("NO");
}

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

int main() {
    int n;cin>>n;
    int MAX_N=10000007;
    int s[MAX_N];
    int tmp;
    s[0]=0;
    
    for(int i=1;i<=n+100;++i){
        s[i]=s[i-1]+i;
        if(s[i]>n){
            tmp=s[i]-n;
            for(int j=1;j<=i;++j){
                if(j!=tmp)cout<<j<<endl;
            }
            return 0;
        }
    }

	return 0;
}

Measured memory_bytes: 256
from itertools import product
N = int(input())
A = [[] for _ in range(N)]
for i in range(N):
    na = int(input())
    for j in range(na):
        x, y = map(int, input().split())
        A[i].append((x-1, y))
ans = 0
for pat in product((0, 1), repeat=N):
    num = pat.count(1)
    mujun = False
    for i, shogen in enumerate(A):
        if pat[i] == 0:
            continue
        for s in shogen:
            x, y = s
            if pat[x] != y ^ (1 - pat[i]):
                mujun = True
                break
        if mujun:
            break
    if mujun:
        continue
    ans = max(ans, num)
print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main(){
    int H,W;
    cin>>H>>W;
    string s[H];
    for(int i=0;i<H;i++){
        cin>>s[i];
    }
    for(int i=0;i<H;i++){
        cout<<s[i]<<endl;
        cout<<s[i]<<endl;
    }
}

Measured memory_bytes: 384
# まずDPを使う理由はあるs[i]=t[j]の時 そのs[i],t[j]を追加した時に増える部分列の場合の数は前の部分列の場合の数+1増えるから
# 前の要素を利用するということはDPを疑う
import sys
input=sys.stdin.readline

mod = 10**9 + 7
n,m = map(int, input().split())
s = input().split()
t = input().split()

dp = [[0] * (m+1) for i in range(n+1)]
S = [[0] * (m+1) for i in range(n+1)]

for i in range(n):
    for j in range(m):
        if s[i] == t[j]:
            dp[i+1][j+1] += (S[i][j] + 1)
            dp[i+1][j+1] %= mod
        else:
            dp[i+1][j+1] = 0 # i番目,j番目を追加すると増える場合の数 iとjが等しくないならば場合の数は増えないから0
        S[i+1][j+1] = S[i][j+1] + S[i+1][j] + dp[i+1][j+1] - S[i][j]
        S[i+1][j+1] %= mod

print(S[n][m]+1)

Measured memory_bytes: 104540
from itertools import product
import random

def solve(n,dl):
    # n = int(input())
    # dl = list(map(int, input().split()))

    if 0 in dl:
        return 0

    doubles = []
    dl1 = []
    dl2 = []
    for i in range(1,13):
        i_cnt = dl.count(i)
        if i_cnt > 2:
            return 0
        elif i_cnt == 2:
            dl2.append(24-i)
            dl2.append(i)
        elif i_cnt == 1:
            dl1.append(i)        

    ans = 0
    ite = list(product(range(2),repeat=len(dl1)))
    for pattern in ite:
        dl24 = [0,24]
        for i, v in enumerate(pattern):
            if v == 1:
                dl24.append(24-dl1[i])
            else:
                dl24.append(dl1[i])
        dl24 = dl24 + dl2
        dl24.sort()
        diff_min = 24
        # print(dl24)
        if len(dl24) == 1:
            ans = max(ans, min(dl24[0], 24-dl24[0]))
        else:
            for a,b in zip(dl24[:-1],dl24[1:]):
                diff = b-a
                if diff != 24:
                    diff_min = min(diff_min,diff)
            ans = max(diff_min,ans)
    return ans


def solve2(n,dl):
    ite = list(product(range(2),repeat=len(dl)))
    ans = 0
    for pattern in ite:
        dl_new = [0]
        for i, v in enumerate(pattern):
            if v == 1:
                dl_new.append(24-dl[i])
            else:
                dl_new.append(dl[i])
        dl_new.sort()
        diff_min = 24
        for a,b in zip(dl_new[:-1], dl_new[1:]):
            diff = b-a
            diff_min = min(diff_min, diff)
        ans = max(ans,diff_min)
    return ans


if __name__ == "__main__":
    n = int(input())
    dl = list(map(int, input().split()))
    ans = solve(n,dl)
    print(ans)
    # for _ in range(10):
    #     n = random.randint(1,10)
    #     dl = [random.randint(1,12) for _ in range(n)]
    #     ans1 = solve(n, dl[:])
        # ans2 = solve2(n,dl[:])
        # if ans1 != ans2:
        #     print(n)
        #     print(dl)
        #     print(ans1)
        #     print(ans2)
        #     print('----')

Measured memory_bytes: 83368
h,w,m = map(int,input().split())
hw = [list(map(int,input().split())) for i in range(m)]
hb = [0] * h
wb = [0] * w

for i in range(m):
    hb[hw[i][0]-1] += 1
    wb[hw[i][1]-1] += 1

max_h = max(hb)
max_w = max(wb)
ans = max_h + max_w
count = hb.count(max_h) * wb.count(max_w)
for i in range(m):
    if hb[hw[i][0]-1] == max_h and wb[hw[i][1]-1] == max_w:
        count -= 1
if count <= 0:
    ans -= 1
print(ans)

Measured memory_bytes: 68356
//Created by Kira

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

#define IOS cin.sync_with_stdio(0);cin.tie(0); cout.tie(0);
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define pii pair<int,int> 
#define pb push_back
#define vi vector<int> 
using ll = long long;

const int mod = 1e9 + 7;

ll pwr(ll a, ll b);
    



int main(){
   IOS

    int a , b; cin>>a>>b;

    for(int i = 1; i <= 1262; i++){
        if(floor(i*0.08)==a and floor(i*0.1)==b)
            return cout<<i<<"\n", 0;
    }

    cout<<-1;

   



}

ll pwr(ll a, ll b){
   a %= mod;	//Remove mod if not required
   ll res = 1;
   while(b > 0){
    if(b&1)
        res = res * a % mod;
        a = a * a % mod;
    b >>= 1;
    }

    return res;
}



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

int main(){
  vector<long long> ry(100);
  int N;
  cin >>N;
  ry.at(0)=2; ry.at(1)=1;
  for(int i=2; i<=86;i++){
    ry.at(i)=ry.at(i-1)+ry.at(i-2);
  }
  cout << ry.at(N) << endl;
}

Measured memory_bytes: 256
dig, cnt = map(int, input().split())
ans = [-1]*dig
 
for i in range(cnt):
  place, num = map(int, input().split())
  place -= 1
  if ans[place] != -1:
    if ans[place] != num:
      
      print(-1)
      exit()
  elif place == 0 and num == 0 and dig > 1:
    print(-1)
    exit()
  else:
    ans[place] = num
    
for i in range(dig):
  if ans[i] == -1:
    if dig > 1 and i == 0:
      ans[i] = 1
    else:
      ans[i] = 0
  print(ans[i], end="")

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  vector< vector< pair<int, long long> > > v(10);
  for (int x = 0; x < 10; x++) {
    int next = x;
    while (1) {
      next += x;
      int tmp = next / 10;
      next = (next % 10) + (next / 10);
      v[x].push_back({next, (v[x].empty() ? 0 : v[x].back().second) + tmp + 1});
      if (next == x) {
        break;
      }
    }
  }  
  int m;
  cin >> m;
  stack<int> st;
  long long ans = 0;
  while (m--) {
    int d;
    long long c;
    cin >> d >> c;
    if (c == 1) {
      st.push(d);
      continue;
    }
    c -= 2; 
    st.push(v[d][c % (long long) v[d].size()].first);
    ans += (c / (long long) v[d].size()) * v[d].back().second;
    ans += v[d][c % (long long) v[d].size()].second;
  }
  while ((int) st.size() > 1) {
    int a = st.top(); st.pop();
    int b = st.top(); st.pop();
    ans++;
    if (a + b >= 10) {
      st.push(1);
    }
    st.push((a + b) % 10);
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(rng(v),x)!=v.end()
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
typedef vector<pii> vp;
typedef vector<tiii> vt;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
inline int in() { int x; scanf("%d",&x); return x;}
//cout << fixed << setprecision(10);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int n, m;
vvi to;
int dp[100100];

int rec(int v) {
  if (dp[v] != -1) return dp[v];
  int res = 0;
  for (auto nv : to[v]) {
    chmax(res, rec(nv)+1);
  }
  return dp[v] = res;
}

int main () {
  cin >> n >> m;
  to = vvi(n,vi());
  rep(i,m) {
    int x, y;
    cin >> x >> y;
    x--, y--;
    to[x].pb(y);
  }

  rep(v,n) dp[v] = -1;

  int ans = 0;
  rep(v,n) chmax(ans, rec(v));
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 8192
#include <bits/stdc++.h>
 
typedef long long ll;
using namespace std;
 
int main() {
    // s = "SCR" expected
    // t = "CRR" actual
    string s, t;
    cin >> s >> t;
 
    int res = 0;
    for (int i = 0; i < 3; i++) {
        if (s[i] == t[i]) ++res;
    }
 
    cout << res << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] a = new int[m];
		int k, idx, cnt = 0;
		for (int i = 0; i < n; i++) {
			k = sc.nextInt();
			for (int j = 0; j < k; j++) {
				idx = sc.nextInt() - 1;
				a[idx]++;
			}
		}

		for (int i = 0; i < m; i++) {
			if (a[i] == n) {
				cnt++;
			}
		}
		System.out.println(cnt);
	}
}


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

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var W = new Dictionary<string, int>();
            for(var i = 0; i < N; i++)
            {
                var s = Console.ReadLine();
                if (W.ContainsKey(s))
                {
                    W[s]++;
                }else
                {
                    W.Add(s, 1);
                }
            }
            var M = int.Parse(Console.ReadLine());
            for (var i = 0; i < M; i++)
            {
                var s = Console.ReadLine();
                if (W.ContainsKey(s))
                {
                    W[s]--;
                }
            }
            var ans = 0;
            foreach(var val in W.Values)
            {
                if (val > 0 && val > ans) ans = val;
            }

            Console.WriteLine(ans);
        }
    }
}

Measured memory_bytes: 11220
#include<bits/stdc++.h>
using namespace std;
int n,a,b,c;
char miti[10][10];
void bobm(int x,int y){
    for(int s=1;s<=3;s++){
     if(x+s<9){
        if(miti[x+s][y]=='1'){
                miti[x+s][y]='0';
                bobm(x+s,y);
                }
     }
     if(y-s>0){
        if(miti[x][y-s]=='1'){
                miti[x][y-s]='0';
                bobm(x,y-s);
                }
     }
     if(x-s>0){
        if(miti[x-s][y]=='1'){
                miti[x-s][y]='0';
                bobm(x-s,y);
                }
     }
     if(y+s<9){
        if(miti[x][y+s]=='1'){
                miti[x][y+s]='0';
                bobm(x,y+s);
                }
     }
                        }
}

int main(){

    cin >> n;
    for(int k=1;k<=n;k++){

    for(int i=1;i<9;i++){
        for(int j=1;j<9;j++){
            cin >> miti[j][i];
        }
    }

    cin >> a >> b;
    miti[a][b]='0';
    bobm(a,b);

    cout << "Data " << k << ":" << endl;
    for(int i=1;i<9;i++){
        for(int j=1;j<9;j++){
            cout << miti[j][i];
        }
        cout << endl;
        }
    }

return 0;
}

Measured memory_bytes: 1160
N = int(input())
S = input()
ans = S.count("R")*S.count("G")*S.count("B")

for i in range(N-2):
  for j in range(i+1,N-1):
      k = 2*j-i
      if k>=N:
        break
      if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
        ans-=1
          
print(ans)

Measured memory_bytes: 9200
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<(n);++i)
#define rep2(i,a,b) for (ll i=(a);i<(b);++i)
#define debug(x) cout << #x << '=' << x << endl
#define all(v) (v).begin(),(v).end()
const ll MOD=1e9+7;
//const ll MOD=998244353;
const ll INF=1e9;
const ll IINF=1e18;

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,Q; string S; cin >> N >> S >> Q;
    vector<set<int>> pos(26);
    rep(i,N) pos[S[i]-'a'].insert(i);
    rep(_,Q){
        int t; cin >> t;
        if (t==1){
            int k; char c; cin >> k >> c; --k;
            rep(i,26) if (pos[i].count(k)) pos[i].erase(k);
            pos[c-'a'].insert(k);
        } else {
            int l,r,ans=0; cin >> l >> r; --l,--r;
            rep(i,26){
                if (pos[i].upper_bound(r)!=pos[i].lower_bound(l)) ++ans;
            }
            cout << ans << '\n';
        }
    }
}

Measured memory_bytes: 24220
#include <bits/stdc++.h>
using namespace std;
#define print printf("==================\n")
#define ll long long
#define pi acos(-1.0)
#define eps 1e-16
#define max3(a,b,c) max(a,max(b,c))
const ll INF = 1 << 30;
#define mod 1000000007
typedef pair<double, double  > payar;
typedef struct
{
    ll  x, y;
} point;
priority_queue<payar, vector<payar>,  greater<payar> > pq; ///accending
vector< pair<double,payar  > > vpp;
vector < payar >  vp;
int n, k;
ll ara[100005];
ll dp[3001][3001][3];
ll rec(int i,int j,int player=1)
{
    if(i>j)
        return 0;
    if(i>n)
        return 0;
    if(j<1)
        return 0 ;
    ll maxi =-1;
    ll maxi2=-1;
    if(dp[i][j][player] != -1)
        return dp[i][j][player];
    ll &ans = dp[i][j][player];
    if(player==1)
        ans=max(ara[i]+rec(i+1,j,2), ara[j]+rec(i,j-1,2));
    if(player==2)
        ans =min(-ara[j]+rec(i,j-1,1),-ara[i]+rec(i+1,j,1));
    return ans ;


}
int main()
{

    cin>>n;
    for(int i = 1 ; i<=n ; i++)
        cin>>ara[i];
    for(int i = 0 ; i<=n ; i++)
    {
        for(int j  = 0 ; j<=n ; j++)
        {

            dp[i][j][0]=-1;
            dp[i][j][1]=-1;
            dp[i][j][2]=-1;
        }
    }
    cout<< rec(1,n,1);
    return 0 ;
}




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

int main()
{
  long long n,min,max,sum=0;
  long long N[10001];
  cin>>n;
  cin>>N[0];
  max=min=sum=N[0];
  for(int i=1;i<n;i++){
    cin>>N[i];
    if(max<N[i])max=N[i];
    if(min>N[i])min=N[i];
    sum+=N[i];
  }
  cout<<min<<" "<<max<<" "<<sum<<endl;
  return 0;
}
  

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

const int D = 60;
const int MAX_N = 200005;
int to[D][MAX_N];

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

  vector<int> a(N);
  for (int i = 0; i < N; i++) {
    cin >> to[0][i];
    to[0][i]--;
  }
  for (int i = 0; i < D - 1; i++) {
    for (int j = 0; j < N; j++) {
      to[i + 1][j] = to[i][to[i][j]];
    }
  }

  int v = 0;
  for (int i = D - 1; i >= 0; i--) {
    long long l = 1LL << i;
    if (l <= K) {
      v = to[i][v];
      K -= l;
    }
  }
  cout << v + 1 << endl;
}

Measured memory_bytes: 51048
import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T
import Data.Bool (bool)
import Data.Bits
import qualified Data.Vector.Unboxed as V

main :: IO ()
main = do
  n <- unsafeSignedDecimal <$> T.getLine :: IO Int
  as <- map unsafeSignedDecimal . T.words <$> T.getLine :: IO [Int]
  print . h . V.map (uncurry (*)) . g . map f $ as

h :: V.Vector Int -> Int
h = V.foldr step 0
  where
    step k l = (k + 2 * l) `mod` modulus

g :: [V.Vector Bool] -> V.Vector (Int, Int)
g = foldl (V.zipWith op) (V.replicate 60 (0, 0))
  where
    op (cf, ct) = bool (succ cf, ct) (cf, succ ct)

f :: Int -> V.Vector Bool
f = V.generate 60 . testBit

modulus :: Int
modulus = 10 ^ 9 + 7

unsafeSignedDecimal :: T.Text -> Int
unsafeSignedDecimal s = case T.signed T.decimal s of
  Right (n, _) -> n


Measured memory_bytes: 32508
line = int(input())
a = list(input())
b = list(input())
c = list(input())
count = 0
for i in range(line):
    list =[]
    list.append(a[i])
    list.append(b[i])
    list.append(c[i])
    a_w = list.count(list[0])
    b_w = list.count(list[1])
    if a_w + b_w == 2:
        count+=2
    elif a_w + b_w == 3:
        count+=1
    elif a_w + b_w == 4:
        count+=1
print(count)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
	ll n;
	cin>>n;

	ll ans = (n * (n + 1) * (n + 2)) / 6;
	//cout<<ans<<endl;

	ll x,y;
	for(ll i = 0;i < n -1;i++) {
		cin>>x>>y;
		if(x > y)
			swap(x,y);
		ans-=(x * (n - y + 1));
	}

	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 3596
N = int(input())
fq = [0] * int(10**5 + 10)
A = list(map(int, input().split()))
for a in A:
    fq[a] += 1
fq = [f if f % 1 == 0 else 1 for f in fq]
cnt_even = 0
cnt_odd = 0
for f in fq:
    if f & 1 == 0 and f != 0:
        cnt_even += 1
    if f & 1 == 1:
        cnt_odd += 1
if cnt_even & 1 == 0:
    print(cnt_even + cnt_odd)
else:
    print(cnt_even - 1 + cnt_odd)

Measured memory_bytes: 14776
#include <bits/stdc++.h>
using namespace std;
#define pr(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define all(v) (v).begin(), (v).end()
#define int long long
#define sz(v) (int)(v).size()
#define mod 1000000007 // ((a- b)% mod+ mod)% mod

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

int dx[]= {0, 0, 1, -1};
int dy[]= {1, -1, 0, 0};
int dist[1001][1001];

void solve() {
        int n, m; cin >> n>> m;
        int sx, sy; cin >> sx>> sy;
        int ex, ey; cin >> ex>> ey;
        sx--, sy--, ex--, ey--;

        vector<string> v(n);

        for (auto& i: v) cin >> i;

        for (int i= 0; i<= n; i++) for (int j= 0; j<= m; j++) dist[i][j]= 2e9;

        deque<pair<pair<int, int>, int>> dq;
        dist[sx][sy]= 0;
        dq.push_back({{sx, sy}, 0});

        while (dq.size()) {
                int x= dq.front().first.first;
                int y= dq.front().first.second;
                int cst= dq.front().second;
                dq.pop_front();

                if (cst> dist[x][y]) continue;

                for (int i= 0; i< 4; i++) {
                        int tox= x+ dx[i];
                        int toy= y+ dy[i];

                        if (tox< 0|| toy< 0|| tox>= n|| toy>= m|| v[tox][toy]== '#') {
                                continue;
                        }
                        if (dist[tox][toy]> dist[x][y]) {
                                dist[tox][toy]= dist[x][y];
                                dq.push_front({{tox, toy}, cst});
                        }
                }
                for (int j= -2; j<= 2; j++)
                for (int i= -2; i<= 2; i++) {
                        int tox= x+ j;
                        int toy= y+ i;

                        if (tox< 0|| toy< 0|| tox>= n|| toy>= m|| v[tox][toy]== '#') {
                                continue;
                        }

                        if (dist[tox][toy]> dist[x][y]+ 1) {
                                dist[tox][toy]= dist[x][y]+ 1;
                                dq.push_back({{tox, toy}, cst+ 1});
                        }

                }
        }

        cout << (dist[ex][ey]== 2e9? -1: dist[ex][ey])<< "\n";

}

int32_t main(){
ios::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL);
        int T= 1;
        //cin >> T;
        while ( T-- ) {
                solve();
        }
return 0;
}


Measured memory_bytes: 12776
n = gets.to_i
array = readline.split(' ').map(&:to_i)

ans = 'No'
array.each_with_index do |e, i|
  if i == array.size - 1
    ans = "Yes"
    break
  end

  if e > array[i + 1]
    if e - array[i + 1] == 1
      array[i + 1] += 1
      next
    else
      ans = "No"
      break
    end
  end
end

if n == 1
  ans = "Yes"
end

puts ans


Measured memory_bytes: 8580
#include <bits/stdc++.h>
using namespace std;
string s;
unordered_map<int, int> M;
int main () {
	ios::sync_with_stdio(false);
	cin >> s;
	int stat = 0;
	int l = s.length();
	M[0] = 0;
	for (int i = 0; i < l; i++) {
		stat ^= (1 << (s[i] - 'a'));
		int mi = 123456789;
		for (int j = 0; j < 26; j++) {
			auto k = M.find(stat ^ (1 << j));
			if (k != M.end()) mi = min(mi, k -> second);
		}
		auto k = M.find(stat);
		if (k != M.end()) k -> second = min(k -> second, mi + 1);
		else M[stat] = mi + 1;
	}
	if (!stat) cout << 1 << endl;
	else cout << M[stat] << endl;
	return 0;
}

Measured memory_bytes: 8668
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <numeric>
#include <queue>
using namespace std;

int64_t min(int64_t a,int64_t b) {
    if (a > b)
    {
        return b ;
    }else
    {
        return a ;
    }
}


int main(){
    string s ;
    cin >> s ;
    vector<bool> c(26,0) ;
    for (int i = 0; i < s.size(); i++)
    {
        int num = s.at(i) - 'a' ;
        c.at(num) = 1 ;
    }
    for (int i = 0; i < 26; i++)
    {
        if (c.at(i) == 0)
        {
            char ans = 'a' + i ;
            cout << ans << endl ;
            return 0 ;
        }
        
    }
    

    cout << "None" << endl;
    
    
}


Measured memory_bytes: 3736
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector<long long> a(n + 1);
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    a[i] += a[i - 1];
  }
  long long ans = 0;
  map<long long, int> mp;
  for (int i = 0; i <= n; i++) {
    if (i >= k) mp[(a[i - k] - (i - k) + k) % k]--;
    ans += mp[(a[i] - i + k) % k]++;
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 14336
s=int(input())
a=s//100
b=s%100
if a>0 and a<=12:
  if b>0 and b<=12:
    print("AMBIGUOUS")
  else:
    print("MMYY")
else:
  if b>0 and b<=12:
    print("YYMM")
  else:
    print("NA")

Measured memory_bytes: 9164