akhauriyash/Code-Regression huggingface dataset:
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: usize = read();
    let mut cnt: Vec<i64> = vec![0; 100001];
    for _ in 0..n {
        let ai: i64 = read();
        cnt[ai as usize] += 1;
    }

    let mut cnt_two = 0;
    let mut cnt_kind = 0;

    for i in cnt {
        if i != 0 {
            cnt_kind += 1;
        }
        if i % 2 == 0 && i != 0 {
            cnt_two += 1;
        }
    }
    // println!("two:{}, kind:{}", cnt_two, cnt_kind);

    if cnt_two % 2 == 1 {
        println!("{}", cnt_kind - 1);
    } else {
        println!("{}", cnt_kind);
    }
}


Measured memory_bytes: 4476
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(t) t.begin(), t.end()
#define inrange(i, a, b) (((i)>= min((a), (b))) && ((i) <= max((a), (b))))
typedef vector<ll> vi;
#define fi first
#define se second
const ll inf = 9e18;
const ll mod = 1e9 + 7;

void print(ll a[], ll n){for(ll i=0;i<n;i++){cout<<a[i]<<" ";}cout<<"\n";}
ll power(ll x, ll y, ll M = inf){
    ll ans = 1;
    x %= M;
    while(y){
        if(y&1)
            ans = (x * ans) % M;

        x = (x * x) % M;
        y >>= 1;
    }
    return ans;
}
ll modInverse(ll n) {return power(n, mod-2, mod);}
inline ll mul(ll a, ll b){ return (a * b) % mod; }
inline ll sub(ll a, ll b){ ll c = a - b; if(c < 0) c += mod; return c; }
inline ll add(ll a, ll b){ ll c = a + b; if(c > mod) c -= mod; return c; }
inline ll divi(ll a, ll b){ return mul(a, modInverse(b)); }

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

	ll n;
	cin>>n;
	ll a[n];
	for(int i=0;i<n;i++)
		cin>>a[i];
	sort(a, a+n);
	cout<<a[n/2] - a[n/2-1];
	return 0;
}


Measured memory_bytes: 1024
// Q1
import java.io.*;
import java.lang.Integer;
public class Main {
	public static void main(String[] args) {
		try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
			String in  = br.readLine() ;
			String[] numStr = in.split(" ");
			int[] num = new int[4];
			num[0] = Integer.parseInt(numStr[0]);
			num[1] = Integer.parseInt(numStr[1]);
			num[2] = Integer.parseInt(numStr[2]);
			if ( num[0] < num[1] && num[1] < num[2] ) {
				System.out.println( "Yes");
			} else  {
				System.out.println( "No");
			} 
		} catch ( IOException e ) {
			System.out.println("??¨??????????????????????????????");
		}
	}
}

Measured memory_bytes: 24224
// 解答不能.
// outline氏.
// https://atcoder.jp/contests/abc144/submissions/8181484
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e+12 + 1;

int n;
ll k;
vector<ll> a, f;

bool C(ll x){
    ll res = 0;
    for(int i = 0; i < n; ++i){
        ll tx = a[i], ty = f[i];
        if(tx * ty > x) res += (ll)ceil((double)(tx * ty - x) / ty);
    }
    return res <= k;
}

int main(){
    scanf("%d %lld", &n, &k);
    for(int i = 0; i < n; ++i){
        int tmp;
        scanf("%d", &tmp);
        a.push_back(tmp);
    }
    for(int i = 0; i < n; ++i){
        int tmp;
        scanf("%d", &tmp);
        f.push_back(tmp);
    }
    sort(a.begin(), a.end());
    sort(f.begin(), f.end(), greater<ll>());
    
    ll lb = -1, ub = INF;
    while(ub - lb > 1){
        ll mid = (ub + lb) / 2;
        if(C(mid)) ub = mid;
        else       lb = mid;
    }
    printf("%lld\n", ub);
    return 0;
}

Measured memory_bytes: 4848
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fo(a,b) for(int a=0;a<b;a++)
#define Sort(a) sort(a.begin(),a.end())
#define rev(a) reverse(a.begin(),a.end())
 int wari(int a,int b) {
   if(a%b==0)
     return a/b;
   else
     return a/b+1;
 }
 int keta(int a){
  double b=a;
  b=log10(b);
  int c=b;
  return c+1;
 }
 int souwa(int a){
  return a*(a+1)/2;
 }
 int lcm(int a,int b){
  int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return d*e/f;
    }
  int gcm(int a,int b){
      int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return f;
  }
signed main(){
  int a,e=1000000000000000;
  cin>>a;
  vector<int> b(a),c(a,0),d(a,0);
  fo(i,a)
    cin>>b[i];
  c[0]=b[0];
  d[0]=b[a-1];
  for(int i=1;i<a;i++)
    c[i]=c[i-1]+b[i];
  for(int i=1;i<a;i++)
    d[i]=d[i-1]+b[a-1-i];
  c.pop_back();
  d.pop_back();
  rev(d);
  fo(i,a-1)
    e=min(e,abs(c[i]-d[i]));
  cout<<e<<endl;
}


Measured memory_bytes: 4992
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int[] c = new int[n-1];
		int[] s = new int[n-1];
		int[] f = new int[n-1];
		for(int i=0;i<n-1;i++){
			c[i] = sc.nextInt();
			s[i] = sc.nextInt();
			f[i] = sc.nextInt();
		}
		
		
		for(int i=0;i<=n-1;i++){
			int t = 0;
			for(int j=i;j<n-1;j++){
				if(t<=s[j])
					t = s[j];
				else if(t%f[j]!=0){
					t+=(f[j]-t%f[j]);
				}
				
				t+=c[j];
			}
			System.out.println(t);
		}

	}

}


Measured memory_bytes: 26948
#include <bits/stdc++.h>
#define l_ength size
const int inf = (1<<30);
const int mod = 1000000007;
using ll = long long;
using namespace std;

int main(){
	string s; cin >> s;
	if( s == "SUN" ) cout << 7 << endl;
	if( s == "MON" ) cout << 6 << endl;
	if( s == "TUE" ) cout << 5 << endl;
	if( s == "WED" ) cout << 4 << endl;
	if( s == "THU" ) cout << 3 << endl;
	if( s == "FRI" ) cout << 2 << endl;
	if( s == "SAT" ) cout << 1 << endl;
}

Measured memory_bytes: 256
formula = gets.split()
stuck = []

formula.each do |value|
  if value =~ /^[0-9]+$/
    stuck.push(value.to_i)
  else
    num2 = stuck.pop
    num1 = stuck.pop
    case value
    when "+" then
      stuck.push(num1 + num2)
    when "-" then
      stuck.push(num1 - num2)
    when "*" then
      stuck.push(num1 * num2)
    else
    end
  end
end

puts stuck.pop


Measured memory_bytes: 6864
#include <cstdio>
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;

char a[4];

int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	int ans=0;
	scanf("%s",a+1);
	for(int i=1;i<=3;i++){
		if(a[i]=='1')ans++;
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 256
n=int(input())
a=[int(i)-1 for i in input().split()]
b=[int(i) for i in input().split()]
c=[int(i) for i in input().split()]

res = 0
prev = -2
for i in range(n):
    res += b[a[i]]
    if prev+1 == a[i]:
        res += c[prev]
    prev = a[i]

print(res)


Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <algorithm>

int main() {
  std::cout<<std::fixed<<std::setprecision(10);
double N,p,pcoin,K,s,i,j;
  p=0.0;
  cin>>N>>K;
  for(i=1;i<(N+1);i++){
    s=i;
    pcoin=1;
  for(j=1;;j++){
  if(s>(K-1)) {
//   cout<<pcoin/N<<endl;
    p=p+pcoin/N;
  break;
  }
    s=s*2;
    pcoin=pcoin/2.0;
  }
  }
  cout<<p<<endl;
}

Measured memory_bytes: 256
#include <atcoder/lazysegtree>
#include <atcoder/modint>
#include <iostream>
#include <vector>
using namespace std;

using mint = atcoder::modint998244353;

struct S {
    mint value;
    mint base;
};
using F = int;

S op(S a, S b) { return {a.value + b.value, a.base + b.base}; }
S default_data() { return {0, 0}; }
S apply_lazy(F lazy, S data) {
    if (lazy == 0) {
        return data;
    }
    return {lazy * data.base, data.base};
}
F push_lazy(F root, F child) {
    if (root == 0) {
        return child;
    }
    return root;
}
F default_lazy() { return 0; }

using SegTree = atcoder::lazy_segtree<S, op, default_data, F, apply_lazy,
                                      push_lazy, default_lazy>;

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

    int N, Q;
    cin >> N >> Q;

    auto leaves = vector<S>(N);
    mint base = 1;
    for (int i = 0; i < N; i++) {
        leaves[i] = {base, base};
        base = base * 10;
    }
    auto tree = SegTree(leaves);

    while (Q--) {
        int l, r, d;
        cin >> l >> r >> d;
        l--;
        r--;
        tree.apply(N - 1 - r, N - l, d);
        cout << tree.all_prod().value.val() << "\n";
    }

    return 0;
}

Measured memory_bytes: 10092
import java.util.*;
	class Main{
      public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();
        int x = sc.nextInt();
        int n = 1+x-k;
        for(int i = 0;i < 2*k-1; i++){
          System.out.println(n+i);
        }
      }
    }


Measured memory_bytes: 22612
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())
num = [a,b,c,d,e]
flag = 0
for i in range(4):
    for j in range(i+1,5):
        if num[j] - num[i] > k:
            flag = 1
            break
    if flag == 1:
        break
if flag == 1:
    print(":(")
else:
    print('Yay!')


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll, int> plli;
typedef pair<int, pii> pipii;
typedef vector<vector<int> > mati;
typedef vector<vector<double> > matd;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)
#define RFOR(i,x,y) for(ll i=(ll)x; i>=(ll)y; --i)
#define RREP(i,x) RFOR(i, x, 0)

template <typename T>
void vec_print(vector<T> VEC){
  REP(i, VEC.size()){
    cout << VEC[i] << " ";
  }
  cout << "\n";
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  REP(i, MAT.size()){
    REP(j, MAT[i].size()){
      cout << MAT[i][j] << " ";
    }
    cout << "\n";
  }
};

template <typename CLASS1, typename CLASS2>
class HOGE{
  public:
    CLASS1 key;
    CLASS2 value;
    HOGE(void){
      return;
    };
    HOGE(CLASS1 key, CLASS2 value){
      this->key = key;
      this->value = value;
    };
    ~HOGE(void){
      return;
    };

    void print(void){
      cout << "key : " << key << ", value : " << value << "\n";
      return;
    };
    
    bool operator==(const HOGE &obj){
      return (this->value == obj.value);
    };
    bool operator<(const HOGE &obj){
      return (this->value < obj.value);
    };
    bool operator>(const HOGE &obj){
      return (this->value > obj.value);
    };
};

template <typename CLASS1, typename CLASS2>
bool operator==(const HOGE<CLASS1, CLASS2> &hoge1, const HOGE<CLASS1, CLASS2> &hoge2){
  return hoge1.value == hoge2.value;
};

template <typename CLASS1, typename CLASS2>
bool operator<(const HOGE<CLASS1, CLASS2> &hoge1, const HOGE<CLASS1, CLASS2> &hoge2){
  return hoge1.value < hoge2.value;
};

template <typename CLASS1, typename CLASS2>
bool operator>(const HOGE<CLASS1, CLASS2> &hoge1, const HOGE<CLASS1, CLASS2> &hoge2){
  return hoge1.value > hoge2.value;
};

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;
constexpr ll MOD = (ll)((1E+9)+7);

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  ll N, K;
  cin >> N >> K;

  double ans = 0.0;
  REP(i, N){
    double tmp = 1.0/N;
    ll point = i+1;
    while(point<K){
      tmp/=2.0;
      point*=2;
    }
    ans += tmp;
  }

  printf("%.10lf\n", ans);

  return 0;
}


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

int main(){
    int N, M;
    cin >> N >> M;
    vector<vector<bool>> edge(N+1, vector<bool>(N+1, false));
    for (int i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;
        edge[a][b] = true;
        edge[b][a] = true;
    }
    vector<int> list;
    for (int i = 2; i <= N; i++) list.push_back(i);
    int ans = 0;
    while (true) {
        bool check = true;
        for (int i = 0; i < N-1; i++) {
            if (i == 0) {
                if (!edge[1][list[0]]) {
                    check = false;
                    break;
                }
            } else {
                if (!edge[list[i-1]][list[i]]) {
                    check = false;
                    break;
                }
            }
        }
        if (check) ans++;
        if (!next_permutation(list.begin(), list.end())) break;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
using System;
class ProgramA
    {
        static void Main(string[] args)
        {
            
            string s = Console.ReadLine();

            string now = "";
            string pre= "";
            int sum = 1;

            for(int i = 1;i < s.Length;i++)
            {
                now = s.Substring(i,1);
                pre = s.Substring(i-1,1);
                if(pre == now)
                {
                    if(i == s.Length - 1)
                    {
                        
                    }
                    else
                    {
                        if(i == s.Length -2)
                           sum += 1;
                        else
                           sum += 2;
                        i += 2;
                    }
                }
                else
                {
                    sum++;
                }
                
            }

            Console.WriteLine(sum);
    
        }
    }

Measured memory_bytes: 15712
import sys
n=int(input())
a=[]
for i in range(n):
  a.append(list(map(str,input())))
  
for j in range(1,n):
  if a[j][0]!=a[j-1][-1]:
    print("No")
    sys.exit()
  for l in range(j):
    if a[l]==a[j]:
      print("No")
      sys.exit()
  
print("Yes")


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <cmath>
#include <cstdio>
using namespace std;

const string LEFT_TYPES = "qwertasdfgzxcvb";

int main(void) {
	string str;
	while (getline(cin, str), str != "#") {
		int changeNum = 0;
		bool handIsLeft = LEFT_TYPES.find(str[0], 0) != string::npos;
		for (int i = 1; i < str.size(); i++) {
			bool now = LEFT_TYPES.find(str[i], 0) != string::npos;
			if (handIsLeft != now) {
				handIsLeft = now;
				changeNum++;
			}
		}
		cout << changeNum << endl;
	}

	return 0;
}

Measured memory_bytes: 1180
#include<cstdio>
using namespace std;
typedef long long ll;
const int N=200200,P=1000000007;
int i,j,k,n,m,ch,x,y,an,num;
int z[N],a[N],d[N],p[N],f[N],sz[N],Jc[N],Jc_[N];
struct edge { int s,n;};
void R(int &x) {
	x=0;ch=getchar();
	while (ch<'0' || '9'<ch) ch=getchar();
	while ('0'<=ch && ch<='9') x=x*10+ch-'0',ch=getchar();
}
struct graph {
	int En;
	int h[N],du[N];
	edge E[N<<1];
	void clear() {
		for (int i=1;i<=an;i++) h[a[i]]=0,du[a[i]]=0;
		En=0;
	}
	void add(int x,int y) {
		du[y]++;
		E[++En].s=y;E[En].n=h[x];h[x]=En;
	}
} G1,G2;
int ksm(int x,int y) {
	int z=1;
	for (;y;y>>=1,x=(ll) x*x%P) if (y&1) z=(ll) z*x%P;
	return z;
}
void pre(int n) {
	int i;
	Jc[0]=Jc_[0]=1;
	for (i=1;i<=n;i++) Jc[i]=(ll) Jc[i-1]*i%P;
	Jc_[n]=ksm(Jc[n],P-2);
	for (i=n-1;i;i--) Jc_[i]=(ll) Jc_[i+1]*(i+1)%P;
}
int C(int n,int m) {
	if (m>n) return 0;
	return (ll) Jc[n]*Jc_[m]%P*Jc_[n-m]%P;
}
void dfs(int x) {
	z[x]=1;a[++an]=x;
	for (int k=G1.h[x];k;k=G1.E[k].n) {
		num++;
		if (!z[G1.E[k].s]) dfs(G1.E[k].s);
	}
}
void Dfs(int x) {
	int sum=0;
	f[x]=1;sz[x]=0;
	for (int k=G2.h[x];k;k=G2.E[k].n) {
		Dfs(G2.E[k].s);
		sz[x]+=sz[G2.E[k].s];
		f[x]=(ll) f[x]*f[G2.E[k].s]%P*C(sz[x],sz[G2.E[k].s])%P;
	}
	sz[x]++;
}
int Js() {
	G2.clear();
	int i,j,k,ans=1;
	for (i=1;i<=an;i++)
		for (k=G1.h[a[i]];k;k=G1.E[k].n) if (G1.E[k].s<p[a[i]]) G2.add(a[i],G1.E[k].s);
	int sum=0;
	for (i=1;i<=an;i++) if (G2.du[a[i]]==0) {
		Dfs(a[i]);
		sum+=sz[a[i]];
		ans=(ll) ans*f[a[i]]%P*C(sum,sz[a[i]])%P;
	}
	return ans;
}
int work() {
	int i,j,k;
	j=0;
	for (i=1;i<=an;i++) if (G1.du[a[i]]==1) d[++j]=a[i];
	i=0;
	while (i<j) {
		i++;
		for (k=G1.h[d[i]];k;k=G1.E[k].n) {
			int t=--G1.du[G1.E[k].s];
			if (t>=1) p[d[i]]=G1.E[k].s;
			if (t==1) d[++j]=G1.E[k].s;
		}
	}
	for (k=1;k<=an;k++) if (G1.du[a[k]]==2) {
		d[++j]=a[k];
		break;
	}
	int st=d[j],ans=0,tmp=j;
	while (i<j) {
		i++;
		int t;
		for (k=G1.h[d[i]];k;k=G1.E[k].n) if (G1.du[G1.E[k].s]==2 && G1.E[k].s!=d[i-1]) { t=G1.E[k].s;break;}
		if (t!=st) d[++j]=t;
		p[d[i]]=t;
	}
	ans=(ans+Js())%P;
	j=tmp;i=tmp-1;
	while (i<j) {
		i++;
		int t;
		for (k=G1.h[d[i]];k;k=G1.E[k].n) if (G1.du[G1.E[k].s]==2 && G1.E[k].s!=d[i-1]) t=G1.E[k].s;
		if (t!=st) d[++j]=t;
		p[d[i]]=t;
	}
	ans=(ans+Js())%P;
	return ans;
}
int main() {
	R(n);m=n*2;
	pre(m);
	for (i=1;i<=m;i++) {
		R(x);R(y);
		G1.add(x,n+y);
		G1.add(n+y,x);
	}
	int sum=0,ans=1;
	for (i=1;i<=m;i++) if (!z[i]) {
		an=0;num=0;
		dfs(i);
		if (an*2!=num) return puts("0"),0;
		sum+=an;
		ans=(ll) ans*work()%P*C(sum,an)%P;
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 16640
# -*- coding: utf-8 -*-
# C - Candies
# 標準入力の取得
N = int(input())
A1 = list(map(int, input().split()))
A2 = list(map(int, input().split()))

# 求解処理
# 100通りの全探索を行う
result = 0
for n in range(1, N+1):
    candies = sum(A1[:n]) + sum(A2[n-1:])
    result = max(result, candies)

# 結果出力
print(result)

Measured memory_bytes: 3060
import collections
import sys

S1 = collections.deque()
S2 = collections.deque()
S3 = collections.deque()

for i, j in enumerate(sys.stdin.readline()):
    if j == '\\':
        S1.append(i)
    elif j == '/':
        if S1:
            left_edge = S1.pop()
            new_puddle = i - left_edge
            while S2 and (S2[-1] > left_edge):
                S2.pop()
                new_puddle += S3.pop()
            S2.append(left_edge)
            S3.append(new_puddle)
        else:
            pass


print(sum(S3))

print(len(S3), *S3)

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

int n;
map<string, int> conv;
vector<string> v[100];
vector<int> g[10000];
bool visit[10000];

vector<string> split(const string &str)
{
	vector<string> res;
	for (int l = 0, r = 0; r < str.size(); r++){
		if (str[r] < 'a' || 'z' < str[r]){
			res.emplace_back(string(str, l, r - l));
			l = r + 1;
		}
	}
	return res;
}

int calc(int v)
{
	visit[v] = true;
	if (!g[v].size()) return 1;
	int res = 0;
	for (int to : g[v]){
		if (!visit[to]) res += calc(to);
	}
	return res;
}

int main()
{
	while (scanf("%d", &n), n){
		conv.clear();
		for (int i = 0; i < 10000; i++) g[i].clear();
		
		for (int i = 0; i < n; i++){
			string str;
			cin >> str;
			v[i] = split(str);
			for (auto &t : v[i]){
				if (!conv.count(t)) conv[t] = conv.size() - 1;
			}
		}
		
		for (int i = 0; i < n; i++){
			for (int j = 1; j < v[i].size(); j++){
				g[conv[v[i][0]]].push_back(conv[v[i][j]]);
			}
		}
		
		memset(visit, 0, sizeof(visit));
		printf("%d\n", calc(conv[v[0][0]]));
	}
}

Measured memory_bytes: 1652
fun main(args: Array<String>) {
    val (n, q) = readLine()!!.split(" ").map(String::toLong)
    val s = readLine()!!
    val total = LongArray(n.toInt() + 1) { 0L }
    for (i in 0 until (n.toInt() - 1)) {
        total[i + 1] = total[i] + if (s[i] == 'A' && s[i + 1] == 'C') 1 else 0
    }
    total[n.toInt()] = total[n.toInt() - 1]
    for (i in 1..q) {
        val (l, r) = readLine()!!.split(" ").map(String::toInt)
        println(total[r-1] - total[l-1])
    }
}

Measured memory_bytes: 64344
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main()
{   ios_base::sync_with_stdio(0);
    cin.tie(0);
    long long t,n,k,x,y,z,b,c;
    cin >> t;
    cout << t+t*t+t*t*t <<endl;
    return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <cstdio>
#include <cmath>

using namespace std;

int main()
{
	const double pi = 4 * atan(1.0);

	double a, b, x;
	cin >> a >> b >> x;

	if (2 * x <= a * a * b) {
		double c = 2 * x / a / b;
		double ans = atan2(b, c) * 180 / pi;
		printf("%.10f\n", ans);
	}
	else {
		double c = 2 * (a * a * b - x) / a / a;
		double ans = atan2(c, a) * 180 / pi;
		printf("%.10f\n", ans);
	}
}


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

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

  int N, M;
  cin >> N >> M;
  vector<vector<int>> s(M, vector<int>(N));

  for (int i = 0; i < M; i++) {
    int k;
    cin >> k;
    for (int j = 0; j < k; j++) {
      int a;
      cin >> a;
      s[i].push_back(a);
    }
  }

  vector<int> p(M);
  for (int i = 0; i < M; i++) {
    cin >> p[i];
  }

  ll res = 0;
  for (int bit = 0; bit < (1 << N); bit++) {
    bool ok = true;
    for (int i = 0; i < M; i++) {
      int con = 0;
      for (auto v : s[i]) {
        if (bit & (1 << v - 1)) {
          con++;
        }
      }
      if (con % 2 != p[i]) {
        ok = false;
      }
    }
    if (ok) {
      res++;
    }
  }

  cout << res << endl;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define lp(i,n) for(int i=0;i<n;i++)
#include<bits/stdc++.h>

using namespace std;
int main() {
	int d;
	cin >> d;
	string E = " Eve";
	cout << "Christmas";
	lp(i, 25 - d)
		cout << E;
	cout << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main(void) {
    char s[100];
    int n, i, x, c, d;
    
    scanf("%s",s);
    n=strlen(s);
    
    d=1000;
    for(i=0;i<n-2;i++){
        x=(s[i]-'0')*100+(s[i+1]-'0')*10+(s[i+2]-'0');
        c=753-x;
        if(0>c) c=c*(-1);
        if(c<d) d=c;
    }
    printf("%d\n",d);
    return 0;
}

Measured memory_bytes: 128
n = int(input())
a = list(map(int, input().split()))
 
r=[0]*n
for i in range(n):
	a[i] *= 2

rst = 0
minus =a[n-1]
for i in range(n-1):

	rst = a[-i-2]-minus 
	minus = rst


r[0] = rst // 2
for i in range(n-1):
	r[i+1] = a[i] - r[i]

ans = ''
for i in range(n):
	ans += str(r[i])+" "
	
print(ans)

Measured memory_bytes: 14232
import java.util.*;
import java.math.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = Integer.parseInt(sc.next());
    ArrayList<BigInteger> list = new ArrayList<BigInteger>();
    BigInteger base = BigInteger.ONE;
    for(int i=0;i<N;i++){
      BigInteger bi = new BigInteger(sc.next());
      base = lcm(base, bi);
      list.add(bi);
    }
    base = base.subtract(BigInteger.ONE);
    BigInteger ans = BigInteger.ZERO;
    for(BigInteger bi:list){
      ans = ans.add(base.remainder(bi));
    }
    System.out.println(ans);
  }
  static BigInteger lcm (BigInteger a, BigInteger b) {
  	return a.multiply(b).divide(a.gcd(b));
  }
}


Measured memory_bytes: 46492
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<array>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<queue>
#include<vector>
using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define ALL(a) (a).begin(),(a).end()
#define DUMP(o) {cerr<<#o<<" "<<o<<endl;}
#define DUMPC(o) {cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
const int MOD = 1e9 + 7;

signed main() {
	for (string s; cin >> s;) {
		string ans = "";
		REP(i, s.size()) {
			if (s[i] == '@') {
				REP(j, s[i + 1] - '0') {
					ans += s[i + 2];
				}
				i += 2;
			}
			else {
				ans += s[i];
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3156
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>

using namespace std;

const int nmax = 1e9 + 7;
typedef long long ll;

int main(){
  int N; cin >> N;
  vector <ll> A(N), B(N);
  for (int i = 0; i < N; i++) cin >> A[i];
  for (int i = 0; i < N; i++) cin >> B[i];

  ll cnt = 0;
  for (int i = 0; i < N; i++){
    if (A[i] < B[i]){
      cnt += (B[i] - A[i]) / 2;
    }else if(A[i] > B[i]){
      cnt -= A[i] - B[i];
    }
  }

  if (cnt >= 0) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  
  return 0;
}


Measured memory_bytes: 384
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        a_list: [usize; n]
    }
    let mut four_count = 0;
    let mut two_count = 0;
    for a in a_list {
        if a % 4 == 0 {
            four_count += 1;
        } else if a % 2 == 0 {
            two_count += 1;
        }
    }
    let is_ok = four_count * 2 + 1 >= n
        || (two_count >= 2 && four_count * 2 + two_count >= n);
    println!("{}", if is_ok { "Yes" } else { "No" });
}


Measured memory_bytes: 6396
mod = 10**9 + 7


s = input()

n = len(s)
DP = [[0] * 13 for _ in range(n + 1)]

DP[0][0] = 1
for i in range(1, n + 1):
    for j in range(13):
        if DP[i - 1][j] == 0:
            continue
        a = DP[i - 1][j]
        if s[i - 1] == "?":
            for k in range(10):
                DP[i][(10 * j + k) % 13] += a
        else:
            k = int(s[i - 1])
            DP[i][(10 * j + k) % 13] += a
    for j in range(13):
        DP[i][j] %= mod

print(DP[n][5])


Measured memory_bytes: 61916
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)

using ll = long long;
using Pll = pair<ll, ll>;

class SuffixArray {
private:
    string s;
    int n;
    vector<int> rank;
    vector<int> sa;
public:
    SuffixArray(string _s) : s(_s) {
        n = s.size();
        rank.resize(n + 1);
        sa.resize(n + 1);
        construct();
    }
    vector<int> construct() {
        for (int i = 0; i <= n; ++i) {
            sa[i] = i;
            rank[i] = i < n ? s[i] : -1;
        }

        int k;
        auto compare = [&](int i, int j) {
            if (rank[i] != rank[j]) return rank[i] < rank[j];
            else {
                int ri = i + k <= n ? rank[i + k] : -1;
                int rj = j + k <= n ? rank[j + k] : -1;
                return ri < rj;
            }
        };

        vector<int> tmp(n + 1);
        for (k = 1; k <= n; k *= 2) {
            sort(sa.begin(), sa.end(), compare);

            tmp[sa[0]] = 0;
            for (int i = 1; i <= n; ++i) {
                tmp[sa[i]] = tmp[sa[i - 1]] + (compare(sa[i - 1], sa[i]) ? 1 : 0);
            }
            for (int i = 0; i <= n; ++i) {
                rank[i] = tmp[i];
            }
        }
        return sa;
    }
};

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

  int n;
  ll k;
  cin >> n >> k;
  string s;
  cin >> s;
  vector<ll> lead(n + 1); // leading zero
  rep2(i, 1, n + 1) {
    if (s[i - 1] == '0') {
      lead[i] = lead[i - 1] + 1;
    }
  }

  ll num_zero = accumulate(lead.begin(), lead.end(), 0ll);
  k -= num_zero;
  if (k <= 0) {
    cout << 0 << endl;
    return 0;
  }

  auto f = [&](ll m) {
    ll a = 0;
    rep(i, n) {
      if (s[i] != '0') {
        a += (lead[i] + 1) * min<ll>(n - i, m);
      }
    }
    return a;
  };

  ll l = 0, r = n;
  while (r - l > 1) {
    ll m = (l + r) / 2;
    if (k <= f(m)) r = m;
    else l = m;
  }

  ll len = r;
  ll kk = k - f(len - 1);
  SuffixArray suf(s);
  vector<int> sa = suf.construct();
  rep2(i, 1, sa.size()) {
    if (sa[i] == n || s[sa[i]] == '0' || n - sa[i] < len) continue;
    int num = lead[sa[i]] + 1;
    kk -= num;
    if (kk <= 0) {
      cout << s.substr(sa[i], len) << endl;
      return 0;
    }
  }
}



Measured memory_bytes: 5516
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N;
    int t[110000],x[110000],y[110000];
    cin>>N;
    t[0]=x[0]=y[0]=0;
    for(int i=0;i<N;i++) {
        cin >> t[i + 1] >> x[i + 1] >> y[i + 1];
    }
    bool can=true;
    for(int i=0;i<N;i++){
            int dt=t[i+1]-t[i];
            int dist=abs(x[i+1]-x[i])+abs(y[i+1]-y[i]);
            if(dt<dist)can=false;
            if(dist%2!=dt%2)can=false;
        }
     if(can)cout<<"Yes";
     else cout<<"No";
     return 0;
}

Measured memory_bytes: 1408
#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 = 1001001001;

int a[12][12];

int main() {
    int n, m, x;
    cin >> n >> m >> x;
    vector<int> c(n);
    rep(i, n){
        cin >> c[i];
        rep(j, m) cin >> a[i][j];
    }

    int ans = INF;
    rep(s, 1<<n){
        int cost = 0;
        vector<int> d(m);
        rep(i, n){
            if(s>>i&1){
                cost += c[i];
                rep(j, m) d[j] += a[i][j];
            }
        }
        bool ok = true;
        rep(j, m) if(d[j] < x) ok = false;
        if(ok) ans = min(ans, cost);
    }

    if(ans == INF) cout << -1 << endl;
    else cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 3584
a,b,c=map(int,input().split())
d,e,f=map(int,input().split())
g,h,i=map(int,input().split())
N=int(input())
L=[int(input()) for i in range(N)]
if a in L and b in L and c in L:
  print('Yes')
elif d in L and e in L and  f in L:
  print('Yes')
elif g in L and h in L and  i in L:
  print('Yes')
elif a in L and d in L and  g in L:
  print('Yes')
elif b in L and e in L and  h in L:
  print('Yes')
elif c in L and f in L and  i in L:
  print('Yes')
elif a in L and e in L and  i in L:
  print('Yes')
elif c in L and e in L and  g in L:
  print('Yes')
else:
  print('No')
 

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

typedef long long ll;

ll h,w;

ll solve()
{
	ll result = 1LL << 60;
	ll half1 = (h + 1) / 2;
	ll half2 = h - half1;
	for(int i = 1;i < w;i++)
	{
		ll area1 = h * i;
		ll remain = w - i;
		ll area2 = half1 * remain;
		ll area3 = half2 * remain;
		ll MI = min(area1 , min(area2 , area3));
		ll MA = max(area1 , max(area2 , area3));
		result = min(result , MA - MI);
	}
	return result;
}


ll solve2()
{
	ll result = 1LL << 60;
	for(int i = 1;i < w;i++)
	{
		ll a1 = h * i;
		ll remain = w - i;
		ll w1 = (remain + 1) / 2;
		ll w2 = remain - w1;
		ll a2 = h * w1;
		ll a3 = h * w2;
		ll MI = min(a1,min(a2,a3));
		ll MA = max(a1,max(a2,a3));
		result = min(result , MA - MI);
	}
	return result;
}


int main()
{
	cin >> h >> w;
	ll ans = solve();
	swap(h,w);
	ans = min(solve(),ans);
	ans = min(solve2(),ans);
	swap(h,w);
	ans = min(solve2(),ans);

	cout << ans << endl;
	return 0;

}


Measured memory_bytes: 256
def collatz(n,m):
    if n==1:
        return(m)
    if n % 2 == 0:
        return(collatz(n/2, m+1))
    else:
        return(collatz(3*n+1, m+1))

while True:
    n = int(input().strip())
    if n == 0:
        break
    print(collatz(n,0))

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

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

Node root;

Node treeMinimum(Node x){

  while(x->left != NIL){
    x = x->left;
  }
  return x;

}

Node find(Node u, int k){
  if(u == NIL || k == u->key){
    return u;
  }
 
  if(k < u->key){
    return find(u->left, k);
  }

  else{
    return find(u->right, k);
  }
}


Node treeSuccessor(Node x){
  Node y;
  if(x->right != NIL){
    return treeMinimum(x->right);
  }

  y = x->parent;

  while(y != NIL && x == y->right){
    x = y;
    y = y->parent;
  }
  return y;
}

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

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

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
  
  while(x != NIL){
    y = x;
    if(z->key < x->key){
      x = x->left;
    }
    else{
      x = x->right;
    }
  }
    z->parent = y;

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

}

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

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


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

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

  return 0;
}

Measured memory_bytes: 19364
//#include "bits/stdc++.h"

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<complex>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD =  (int)1e9 + 7;
const double EPS = 1e-9;

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

	int N, K;
	cin >> K >> N;
	vector<int> A(N);
	rep(i, 0, N)
	{
		cin >> A[i];
	}

	int ans = 0;
	int md = 0;
	rep(i, 0, N)
	{
		if (i < N - 1)
		{
			ans += A[i + 1] - A[i];
			chmax(md, A[i + 1] - A[i]);
		}
		else
		{
			ans += A[0] - (A[i] - K);
			chmax(md, A[0] - (A[i] - K));
		}
	}

	cout << ans - md << endl;

	return 0;
}

Measured memory_bytes: 1792
N = int(input())
BA = [[0,0]for i in range(N)]
flag = True
for i in range(N):
    A,B = map(int,input().split())
    BA[i] = [B,A]
BA.sort()
time = 0
for b,a in BA:
    time += a
    if time > b:
        flag =False
print(["No","Yes"][flag])

Measured memory_bytes: 35616
n= int(input())

a = list(map(int, input().split()))

m = None
suke_sum = 0
araiguma_sum = sum(a)

for suke_n in range(1, n):
    # araiguma_n = n - suke_n
    # suke_sum = sum(a[0:suke_n])
    suke_sum += a[suke_n - 1]
    # araiguma_sum = sum(a[suke_n:n])
    araiguma_sum -= a[suke_n - 1]
    ans = abs(suke_sum - araiguma_sum)
    if m is None or m > ans:
        m = ans

print(m)

Measured memory_bytes: 24832
#include <cmath>
#include <cstdlib>
#include <cstdio>
#include <climits>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstring>
#include <string>
#include <algorithm>
#include <vector>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <bitset>
using namespace std;

typedef long long ll;
int n, a, b, d[100001];
ll dp[100001];
int main() {
    cin>>n>>a>>b;
    for (int i=0; i<n; ++i) cin>>d[i];
    ll ans=0;
    for (int i=1; i<n; ++i) {
        int dist=d[i]-d[i-1];
        ll t=(ll)dist*a;
        t=min(t, (ll)b);
        ans+=t;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
#define int long
using pi=pair<int,int>;
signed main(){
    int n, m, d = 1;
    cin >> n >> m;
    map<int,bool> used;
    for(int i=0;i<m;++i){
        while(used[n-i*2-d]||used[i*2+d]||n-i*2-d==i*2+d)++d;
        used[n-i*2-d]=true;
        used[i*2+d]=true;
        cout << i + d << " " << n - i << endl;
        assert(i + d < n - i);
    }
}

Measured memory_bytes: 14792
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      	int K = sc.nextInt();
      	String S = sc.next();
      	if(K >= S.length()){
        	System.out.println(S);
        }else{
        	System.out.println(S.substring(0, K) + "...");
        }
    }
}

Measured memory_bytes: 38680
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

#ifdef _DEBUG
#include "../../library/library/debug_template.cpp"
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

struct init {
	init() {
		cin.tie(nullptr); ios::sync_with_stdio(false);
		cout << fixed << setprecision(10);
	}
} init_;

int main() {

	int N;
	cin >> N;

	vector<string> ans(1, "a");
	vector<char> M(1, 'a');
	for (int i = 1; i < N; i++) {
		vector<string> tmp;
		vector<char> tmpM;
		assert(ans.size() == M.size());
		for (int i = 0; i < ans.size(); i++) {
			const char b = M[i];
			for (char c = 'a'; c <= b + 1; c++) {
				tmp.emplace_back(ans[i] + c);
				tmpM.emplace_back(max(b, c));
			}
		}
		swap(ans, tmp);
		swap(M, tmpM);
	}
	DMP(ans.size());
	sort(ans.begin(), ans.end());
	for (const auto& s : ans) cout << s << "\n";

	return 0;
}



Measured memory_bytes: 7924
C_grid = [list(map(int, input().split())) for i in range(3)]
a1, a2, a3 = C_grid[0][1] - C_grid[0][0], C_grid[0][2] - C_grid[0][1], C_grid[0][0] - C_grid[0][2]
for i in range(1, 3):
    gyo = C_grid[i]
    k1, k2, k3 = gyo[1] - gyo[0], gyo[2] - gyo[1], gyo[0] - gyo[2]
    if a1 == k1 and a2 == k2 and a3 == k3:
        continue
    else:
        print('No')
        exit(0)

a1, a2, a3 = C_grid[1][0] - C_grid[0][0], C_grid[2][0] - C_grid[1][0], C_grid[0][0] - C_grid[2][0]
for i in range(1, 3):
    k1, k2, k3 = C_grid[1][i] - C_grid[0][i], C_grid[2][i] - C_grid[1][i], C_grid[0][i] - C_grid[2][i]
    if a1 == k1 and a2 == k2 and a3 == k3:
        continue
    else:
        print('No')
        exit(0)
print('Yes')


Measured memory_bytes: 9240
#ABC094-E
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return list(input())
n,m=IL()
#Union-Find木
par=[]
rank=[]
def init(a): #初期化
    for i in range(a):
        par.append(i)
        rank.append(0)
def find(x): #根を見つける
    if par[x]==x:
        return x
    else:
        par[x]=find(par[x])
    return par[x]
def unite(x,y): #併合
    x=find(x)
    y=find(y)
    if rank[x]==rank[y]:
        par[x]=y
    else:
        par[y]=x
        if rank[x]==rank[y]:
            rank[x]+=1
    return
def same(x,y): #同じ集合か判定
    return find(x)==find(y)

init(n)
gn=n
for i in range(m):
    x,y,z=IL()
    if find(x-1)!=find(y-1):
        n-=1
        unite(x-1,y-1)
print(n)

Measured memory_bytes: 117476
#include <stack>
using namespace std;

struct Rectangle {
  int height;
  int pos;
};
 

#include <stdio.h>
#define SIZ 1400
int m[SIZ+1][SIZ+1];
int st[SIZ];
char z[9999999];
int get(){
	static int input_count=0;
	int r=0;
	for(;'0'<=z[input_count]&&z[input_count]<='9';)r=r*10+z[input_count++]-'0';
	input_count++;
	return r;
}
int main(){
	fread(z,1,sizeof(z),stdin);
	int i,j,k,y=get(),x=get(),r,ptr;
	for(j=0;j<y;j++)for(r=i=0;i<x;m[j][i]=r,i++){
		int t=get();
		r=t==0?r+1:0;
	}
	r=0;
/*
	for(i=0;i<x;i++)for(ptr=j=0;j<=y;j++){
		//printf("%d %d %d %d\n",i,j,ptr,m[j][i]);
		if(!ptr || st[ptr-1]<m[j][i])st[ptr++]=m[j][i];
		else{
			for(;ptr && st[ptr-1]>m[j][i];){
				int _y=(j-(ptr-1)),_x=st[--ptr];
				//printf("%d %d\n",_x,_y);
				if(r<_x*_y)r=_x*_y;
			}
			st[ptr++]=m[j][i];
		}
	}
*/
	Rectangle rect;
	for(int i=0;i<x;i++){
		stack<Rectangle> stk;
		//rect.height = 0;
		//rect.pos = 0;
		//stk.push(rect);
		int pop=0;
		for(int j=0;j<=y;j++){
			rect.height = m[j][i];
			rect.pos = j;
			if(stk.empty() || stk.top().height < rect.height){
				stk.push(rect);
			}else{
				//printf("[-] %d %d\n",i,j);
				for(;!stk.empty() && stk.top().height > rect.height;){
					pop++;
					Rectangle pre = stk.top(); stk.pop();
					//pre.pos=stk
					int area = pre.height * (j - pre.pos);
					r = max(r, area);
					//printf("%d %d\n",target,pre.pos);
					rect.pos = pre.pos;
				}
				stk.push(rect);
			}
			if(rect.height==0)pop=0;
		}
	}

	printf("%d\n",r);
	return 0;
}

Measured memory_bytes: 14336
n, x = map(int, input().split())

cities= list(map(int, input().split()))

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

distances = []
for city in cities:
    distances.append(abs(city - x))

result = distances[0]

for d in distances:
  result = gcd(result, d)

print(result)

Measured memory_bytes: 63768
from _collections import deque
from _ast import Num


def parser():
    while 1:
        data = list(input().split(' '))
        for number in data:
            if len(number) > 0:
                yield (number)


input_parser = parser()


def gw():
    global input_parser
    return next(input_parser)


def gi():
    data = gw()
    return int(data)


MOD = int(1e9 + 7)

import numpy
from collections import deque
from math import sqrt
from math import floor
import heapq
# https://atcoder.jp/contests/agc033/tasks/agc033_b
# B - LRUD Game
"""
"""
N = gi()
M = gi()
parent = [[] for i in range(N + 1)]


def find(a):
    if parent[a] != a:
        parent[a] = find(parent[a])

    return parent[a]


def union(a, b):
    aP = find(a)
    bP = find(b)

    if (aP != bP):
        parent[max(aP, bP)] = min(aP, bP)


for i in range(N + 1):
    parent[i] = i

for i in range(M):
    x = gi()
    y = gi()
    z = gi()
    union(x, y)

ans = 0

for i in range(1, N + 1):
    if find(i) == i:
        ans += 1

print(ans)


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

int main() {
	int N;
	int k;
	cin >> N;
	cin >> k;
	int r = 0;
	int sum = 0;
    char a[N+1];
    for(int i = 1; i <= N; i++)
    cin >> a[i];
    for(int i = 1; i <= N; i++)
    {
    	if (a[i] == a[i+1])
     	sum++;
    	if ((a[i+1] != a[i]) && (i != N))
    	r++;
    }
    if((r+1)/2>k)
    sum += k*2;
    else 
    sum = N - 1;
	cout << sum;
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>

using namespace std;
using ll = long long;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }
template<typename S, typename T> ostream& operator<<(ostream &os, const pair<S, T> &p){ cout << "[" << p.first << ", " << p.second << "]"; return os; }

#define Sq(x) (x)*(x)
#define For(i, n) for(int i = 0; i < (n); i ++)
#define For1(i, n) for(int i = 1; i <= (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Unique(a) a.erase(unique(Range(a)), a.end())
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) { for(const auto &e : xs) cout << e << " "; cout << "\n"; }
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")
#define vc vector
#define Mini(a, x) a = min(a, x)
#define Maxi(a, x) a = max(a, x)

// constexpr int MOD = 1e9+7;
#include <set>
#include <queue>

int main(void){
    Cin(ll, n, a, b);
    Cins(int, n, x);
    
    ll ans = 0;
    For(i, n-1){
        ans += min(a*(x[i+1]-x[i]), b);
    }
    Cout(ans);
}


Measured memory_bytes: 640
import java.util.*;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String N = sc.nextLine();
		int N_int = Integer.parseInt(N);
		String A = sc.nextLine();
		// System.out.println(A);
		sc.close();

		long result=0;

		String[] num_str = A.split(" ");
		int[] num_int = new int[N_int];

		for(int i=0; i < N_int; i++){
			num_int[i] = Integer.parseInt(num_str[i]);
			}


		for(int j=0; j < N_int-1; j++){
				if (num_int[j] > num_int[j+1]){
					result += num_int[j]- num_int[j+1];
					num_int[j+1] = num_int[j];
				}
				else{
					continue;
				}
			}
		System.out.println(result);
	}
}


Measured memory_bytes: 83048
#include<bits/stdc++.h>
using namespace std;
signed main(){
  int r,c,sum[105]={},a,sum2=0;
  cin>>r>>c;
  for(int i=0;i<r+1;i++){
    sum2=0;
    for(int j=0;j<c;j++){
      if(i!=r){
	cin>>a;
	sum[j]+=a;
	sum2+=a;
	if(j!=c-1)
	  cout<<a<<' ';
	else{
	  cout<<a<<' ';
	  cout<<sum2<<'\n';
	}  
      }
      else{
	sum[101]+=sum[j];
	if(j!=c-1)
	  cout<<sum[j]<<' ';
	else{
	  cout<<sum[j]<<' ';
	  cout<<sum[101]<<'\n';
	}
      }
    }
  }
  return(0);
}



Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define PII pair<int,int>
#define PSI pair<string,int>
#define PIII pair< int, pair<int,int> >
const int MXN = 1e5;
const int INF = 1e9;
int a[MXN+5];
ll dp[MXN+5];
int N,K;

ll rec(int pos){

    if(pos==N) return 0;
    if(dp[pos]!=-1) return dp[pos];
    ll ret = INF;
    for(int i=1; i<=K; i++){
        int next = pos + i;
        if(next<=N){
            ret = min( ret , (ll) rec(next) + abs(a[next]-a[pos]) );
        }else
            break;
    }

    return dp[pos]=ret;
}

void solve(){

    cin>>N>>K;
    memset(dp,-1,sizeof(dp));
    for(int i=1; i<=N; i++) cin>>a[i];
    cout<< rec(1) << "\n";
}

int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
}

Measured memory_bytes: 11080