akhauriyash/Code-Regression huggingface dataset:
// https://atcoder.jp/contests/abc047/tasks/arc063_b
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define EPS (1e-9)
#define INF (1e9)
#define INFL (1e18)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = (n - 1); i >= 0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define BIT(n) (1LL << (n))
// ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
// ll lcm(ll c, ll d) { return c / gcd(c, d) * d; }

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    vector<int> v(n), vm(n);
    int minv = INF;
    REP(i, n) {
        cin >> v[i];
        minv = min(minv, v[i]);
        vm[i] = v[i] - minv;
    }
    sort(ALLR(vm));
    // 差分が一番大きいものを数える
    int ans = 0;
    REP(i, n) {
        if (vm[i] != vm[0])
            break;
        ans++;
    }
    // for (auto x : vm) {
    //     cout << x << " ";
    // }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
# Author: cr4zjh0bp
# Created: Tue Mar 10 14:07:32 UTC 2020
import sys
 
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni = lambda: int(ns())
nin = lambda y: [ni() for _ in range(y)]
na = lambda: list(map(int, stdin.readline().split()))
nan = lambda y: [na() for _ in range(y)]
nf = lambda: float(ns())
nfn = lambda y: [nf() for _ in range(y)]
nfa = lambda: list(map(float, stdin.readline().split()))
nfan = lambda y: [nfa() for _ in range(y)]
ns = lambda: stdin.readline().rstrip()
nsn = lambda y: [ns() for _ in range(y)]
ncl = lambda y: [list(ns()) for _ in range(y)]
nas = lambda: stdin.readline().split()

N = ni()
s = str(N)
p = 0
for i in range(len(s)):
    p += int(s[i])

if N % p == 0:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
n=int(input())
a=list(map(int,input().split()))
ans=0
i=0
while i<=n-2:
  j=0
  while i+j<=n-2:
    if a[i+j]>=a[i+j+1]:
      j+=1
    else:
      break
  i+=j+1
  if j>ans:
    ans=j
print(ans)

Measured memory_bytes: 20292
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;cin>>N;long long int x=0;
  vector<int>A
    (3*N);
  for(int i=0;i<3*N;i++)cin>>A.at(i);
  sort(A.begin(),A.end());
  for(int i=N;i<3*N;i+=2)x+=A.at(i);
  cout<<x<<endl;
}

Measured memory_bytes: 1408
#D問題
A,B,Q = map(int,(input().split()))
si = [-(10**10)]+[int(input()) for _ in range(A)]+[2*(10**10)] # 範囲外に追加して、xの左右に常にデータがあるようにする
ti = [-(10**10)]+[int(input()) for _ in range(B)]+[2*(10**10)]
xi = [int(input()) for i in range(Q)]
A +=2
B +=2

for x in xi:
    l = 0
    r = A-1
    while l+1<r:
        i = (l+r)//2
        if si[i]<x:
            l = i
        else:
            r = i
    sl = si[l]
    sr = si[r]
    
    l = 0
    r = B-1
    while l+1<r:
        i = (l+r)//2
        if ti[i]<x:
            l = i
        else:
            r = i
    tl = ti[l]
    tr = ti[r]
    dsl = x-sl
    dsr = sr-x
    dtl = x-tl
    dtr = tr-x
    print(min(max(dsr,dtr),max(dsl,dtl),dsl+dtr+min(dsl,dtr),dsr+dtl+min(dsr,dtl)))

Measured memory_bytes: 17536
#include<iostream>
#include<cstdio>
#include<stack>
#include<queue>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<vector>
#include<math.h>
using namespace std; 
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define pp(...) "\033[94m [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define dg1(x) debug() << pp(x)
#define dg2(x,y) debug() << pp(x) pp(y)
#define dg3(x,y,z) debug() << pp(x) pp(y) pp(z)
#define dg4(w,x,y,z) debug() << pp(w) pp(x) pp(y) pp(z)
#define msg(x) debug() << x
#define int long long
const int xx = 2e5;
const int MOD = 1e9 + 7;

signed main(){

  ios::sync_with_stdio(false);cin.tie(0);

  string a,b,ans="";
  int n;
  cin >> n;
  cin >> a >> b;
  for(int i=0;i<a.size();i++){
    ans += a[i];
    ans += b[i];
  }

  cout << ans << '\n';

  
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <algorithm>
#include <sstream>
#include <bitset>
#include <math.h>
#include <vector>
#include <set>
using namespace std;

int main (){
    int D;
    cin >> D;
    if(D==25) cout << "Christmas" << endl;
    else if(D==24) cout << "Christmas Eve" << endl;
    else if(D==23) cout << "Christmas Eve Eve" << endl;
    else if(D==22) cout << "Christmas Eve Eve Eve" << endl;

}

Measured memory_bytes: 256
import bisect
R = 100001/2
p = [1]*R
p[0] = p[1] = 0
for i in range(2,int(R**0.5)+1):
    if p[i]:
        p[2*i::i] = [0]*len(p[2*i::i])
p = [i for i in range(R) if p[i]]
n = len(p)
pxp = []
for i in range(n):
    for j in range(i,n):
        if p[i]*p[j] > 100000: break
        pxp.append([p[i]*p[j],p[i],p[j]])
pxp = sorted(pxp)
p,xyr = [e[0] for e in pxp],[[e[1],e[2],e[1]*1.0/e[2]] for e in pxp]
while 1:
    m,a,b = map(int,raw_input().split())
    if m == 0: break
    ab = a*1.0/b

    sp = bisect.bisect(p,m)
    for i in range(sp)[::-1]:
        if 1 >= xyr[i][2] >= ab:
            print xyr[i][0],xyr[i][1]
            break

Measured memory_bytes: 11700
#include<iostream>
#include<string>
#include <vector>
#include<map>
#include<algorithm>
#include<iomanip>
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using vs = vector<string>;
using pii = pair<int, int>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define vsort(v) sort(v.begin(), v.end())
#define rv(v) reverse(v.begin(), v.end())
#define ll long long
const ll MOD = 1e9 + 7;

int main() {
	int n;
	cin >> n;
	vector<ll> h(n);
	int c = 0;
	int m = 0;
	rep(i, n) cin >> h[i];
	rep(i, n-1) {
		if (h[i] >= h[i + 1]) {
			c++;
			m = max(m, c);
		}
		else c = 0;
	}
	cout << m << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <utility>
#include <vector>
#include <queue>
#include <stack>
#include <array>
#include <algorithm>
#include <numeric>
#include <limits>
#include <string>
#include <regex>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

int main()
{
    string s;
    cin >> s;

    for (int i = 0; i < s.length() - 1; i++) {
        if (s[i] == s[i + 1]) {
            printf("%d %d\n", i + 1, i + 2);
            return 0;
        }
    }
    for (int i = 0; i < s.length() - 2; i++) {
        if (s[i] == s[i + 2]) {
            printf("%d %d\n", i + 1, i + 3);
            return 0;
        }
    }
    printf("-1 -1\n");
    return 0;
}


Measured memory_bytes: 512
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Text;

class Simple {
    int N, Z, W;
    int[] a;
    void Solve() {
        //input
        N = io.Int;
        Z = io.Int;
        W = io.Int;
        a = new int[N];
        for (int i = 0; i < N; ++i)
            a[i] = io.Int;
        //cal
        var ans1 = Math.Abs(a.Last() - W);
        if(N==1){
            Console.WriteLine(ans1);
            return;
        }            
        var ans2 = Math.Abs(a[N-2]-a.Last());
        var ans = new int[]{ans1,ans2}.Max();
        Console.WriteLine(ans);    
    }


    SimpleIO io = new SimpleIO();
    public static void Main(string[] args) { new Simple().Stream(); }
    void Stream() { Solve(); io.writeFlush(); }
}

class SimpleIO {
    string[] nextBuffer;
    int BufferCnt;
    char[] cs = new char[] { ' ' };
    StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
    public SimpleIO() {
        nextBuffer = new string[0];
        BufferCnt = 0;
        Console.SetOut(sw);
    }
    public string Next() {
        if (BufferCnt < nextBuffer.Length)
            return nextBuffer[BufferCnt++];
        string st = Console.ReadLine();
        while (st == "")
            st = Console.ReadLine();
        nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        BufferCnt = 0;
        return nextBuffer[BufferCnt++];
    }
    public string String => Next();
    public char Char => char.Parse(String);
    public int Int => int.Parse(String);
    public long Long => long.Parse(String);
    public double Double => double.Parse(String);
    public void writeFlush() { Console.Out.Flush(); }
}




Measured memory_bytes: 13352
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>   
using namespace std;
using namespace __gnu_pbds;
typedef long long ll; 
#define int long long
typedef unsigned long long lu;
typedef vector<ll> v;
typedef vector<vector<ll> > vv;
typedef vector<string>  vs;
typedef vector<pair<ll,ll>> vpr;
typedef vector<bool>vb;
typedef vector<double>vd;
typedef long double ld;
#define f(i,n) for(ll i = 0; i < n; i++)
#define ff(i,n) for(ll i=1;i<=n;i++)
#define pb push_back
#define mp make_pair
#define endl "\n"
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define amax(x,y) if(y>x) x=y;
#define amin(x,y) if(y<x)x=y;
#define bg(x) x.begin()
#define sz(x) (ll)x.size()
#define in(x,n) for(ll i=0;i<n;i++)cin>>x[i]
#define out(x,n) for(ll i=0;i<n;i++)cout<<x[i]<<" " 
#define mxt(a) *(max_element(a.begin(),a.end()))
#define mnt(a) *(min_element(a.begin(),a.end())
#define tc ll t;cin>>t;while(t--)
typedef pair<ll,ll> pi;
#define yes cout<<"YES\n";
#define no cout<<"NO\n";
#define yesno(f) if(f) yes else no
const v dx = {1, -1, 0, 0};
const v dy = {0, 0, 1, -1};
const ld PI = 2 * acos(0.0);
ll cel(ll x1,ll y1){if((x1%y1)==0)return x1/y1;else return x1/y1+1;}
ll power(ll a,ll b,ll m)
{
    if(b==0)
        return 1;
    ll d=power(a,b/2,m);
    d=(d*d)%m;
    if(b&1)
        d=(d*a)%m;
    return d;
}
const ll mod=1e9+7;
int MOD(int a)
{
    if(a<0)
        a+=mod;
    if(a>=mod)
        a%=mod;
    return a;
}
// set_name.find_by_order(k) It returns to an iterator to the kth element (counting from zero) in the set in O(logn) time
// set_name.order_of_key(k) It returns to the number of items that are strictly smaller than our item k in O(logn) time.
/*string operations :
str.substr (x,y) : returns a substring str[x],str[x+1],...str[x+y-1]
str.substr (x) : returns a substring str[x],... end of string
str.find(qtr) : returns the first occurenece of qtr in str */
int32_t main()
{
    ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    int s;cin>>s;
    v dp(s+1,0);
    dp[0]=1;
    dp[3]=1;
    for(int i=4;i<=s;i++)
    {
        for(int j=3;j<=i;j++)
        {
            dp[i]+=dp[i-j];
            dp[i]=MOD(dp[i]);
        }
    }
    cout<<dp[s]<<endl;
    return 0;
}

Measured memory_bytes: 3668
N,M=map(int,input().split())
z=[list(map(int,input().split())) for i in range(N)]
c=[list(map(int,input().split())) for i in range(M)]
for i in z:
    d=10**9
    ans=C=0
    for j in c:
        C+=1
        k=abs(i[0]-j[0])+abs(i[1]-j[1])
        if d>k:
            ans=C
            d=k
    print(ans)


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

typedef pair<ll, ll> pairs;
typedef vector<pairs> p;

struct edge{
    ll to, cost;
};


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

ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

// 素数
vector<bool> IsPrime;
void sieve(size_t max){
    if(max+1 > IsPrime.size()){
        IsPrime.resize(max+1,true);
    } 
    IsPrime[0] = false;
    IsPrime[1] = false;

    for(size_t i=2; i*i<=max; ++i){
        if(IsPrime[i]){
            for(size_t j=2; i*j<=max; ++j){
                IsPrime[i*j] = false;
            }
        }
    }
}

// べき乗の余り
ll modpow(ll a, ll n){
    ll res = 1;
    while(n){
        if(n & 1){
            res = res * a % MOD;
        }
        a = a * a % MOD;
        n = n >> 1;
    }
    return res;
}

// コンビネーション
ll MAXN = 2e5+10;
vector<ll> inv(MAXN);
ll nCk(ll n, ll k) {
	ll res = 1;
	for(ll i = 1; i <= k; i++) {
		res = res*(n-i+1) % MOD;
	}
 
	for(ll i = 1; i <= k; i++) {
		res = res*inv[i] % MOD;
	}
	return res;
}

// 回文
bool kai(string S){
    bool flag = true;
    for(ll i=0;i<S.size()/2;++i){
        if(S[i] != S[S.size()-i-1]){
            flag = false;
            break;
        }
    }
    return flag;
}
// ---------------------------------------------

ll dx[4] = {0, 1, 0, -1};
ll dy[4] = {1, 0, -1, 0};

int main(){
    ll h, w;
    cin>>h>>w;
    vector<string> s(h);
    for(ll i=0;i<h;++i){
        cin>>s[i];
    }

    ll ans = 0;
    for(ll i=0;i<h;++i){
        for(ll j=0;j<w;++j){
            if(s[i][j] == '#')continue;
            vector<vector<ll>> d(h, vector<ll> (w, INF));
            queue<pair<ll, ll>> que;
            que.push(make_pair(i, j));
            d[i][j] = 0;
            ll sum = 0;
            while(!que.empty()){
                pair<ll, ll> x = que.front();
                ll a = x.first;
                ll b = x.second;
                que.pop();
                for(ll k=0;k<4;++k){
                    if(a + dx[k] < 0 or a + dx[k] >= h or b + dy[k] < 0 or b + dy[k] >= w){
                        continue;
                    }
                    if(s[a+dx[k]][b+dy[k]] == '#' or d[a+dx[k]][b+dy[k]] != INF){
                        continue;
                    }
                    d[a+dx[k]][b+dy[k]] = d[a][b] + 1;
                    sum = max(sum, d[a+dx[k]][b+dy[k]]);
                    que.push(make_pair(a+dx[k], b+dy[k]));
                }
            }
            ans = max(ans, sum);
        }
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 4680
import sys;input=lambda:sys.stdin.readline().rstrip();aint=lambda:int(input());ints=lambda:list(map(int,input().split()))
import math;floor,ceil=math.floor,math.ceil
from collections import deque
Yes=lambda b:print('Yes')if b else print('No');YES=lambda b:print('YES')if b else print('NO')
is_even=lambda x:True if x%2==0 else False

def main():
    n,k = ints()
    print(min(n%k,k-n%k))

if __name__ == '__main__':
    main()

Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007



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

  unordered_map<string,int> mp;

  for(int i = 0;i < N;i++) {
      string s;
      cin >> s;
      sort(s.begin(),s.end());
      mp[s]++;
  }
 
  long long ans = 0;
  for(auto it = mp.begin();it != mp.end();it++) {
      long long count = it->second;
      ans += count * (count - 1) / 2;
  }

  cout << ans << endl;

  }


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

namespace AtCorder
{
	public class Program
	{
		static void Main(string[] args)
		{
			long[] kab = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
			long k = kab[0];
			long a = kab[1];
			long b = kab[2];

			if (b <= a + 2) {
				Console.WriteLine(k + 1);
				return;
			}

			long ans = a + ((k - a + 1) / 2) * (b - a) + ((k - a + 1) % 2);
			Console.WriteLine(ans);
		}
	}
}


Measured memory_bytes: 13396
#include <iostream>
#include <string>

using namespace std;

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    string s;
    cin >> s;
    long long k;
    cin >> k;

    rep(i, 0, k)
    {
        if (s[i] != '1')
        {
            cout << s[i];
            return 0;
        }
    }
    cout << 1;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
pref=[[] for i in range(n)]
id_number=[0 for i in range(m)]
for i in range(m):
	p,y=map(int,input().split())
	pref[p-1].append([y,i])

for i in range(n):
	pref_data=sorted(pref[i])
	for j in range(len(pref_data)):
		id_number[pref_data[j][1]]=str(1000000000000+1000000*(i+1)+j+1)

for i in range(len(id_number)):
	print(id_number[i][1:])

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

namespace AtCoderCore
{
    public class Program
    {
        static void Main(string[] args)
        {
            int[] temp = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            int a = temp[0];
            int b = temp[1];
            int t = temp[2];
            Console.WriteLine(t / a * b);
        }
    }
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
typedef long long ll;

using namespace std;

int main() {
	vector<int> a(3);
	cin >> a[0] >> a[1] >> a[2];

	sort(a.begin(), a.end());

	int res = 0;
	for (int i = 1; i < 3; i++) {
		res += a[i] - a[i - 1];
	}

	cout << res << endl;
	return 0;
}


Measured memory_bytes: 256
using System;
namespace AtConderCSharp
{
    class Program
    {
        public static void Main()
        {
            bool count;
            var md1 = Console.ReadLine().Split(' ');
            int m1 = int.Parse(md1[0]);
            int d1 = int.Parse(md1[1]);

            var md2 = Console.ReadLine().Split(' ');
            int m2 = int.Parse(md2[0]);
            int d2 = int.Parse(md2[1]);
            if(m1 == 2 || m1 == 4 || m1 == 6 || m1 == 9 || m1 == 11)
            {
                if(m1 == 2 && d1 == 28)
                {
                    if(d2 == 29)
                    {
                        Console.WriteLine('0');
                    }
                    else
                    {
                        Console.WriteLine('1');
                    }

                }
                else if(d1 == 30)
                {
                    Console.WriteLine('1');
                }
                else
                {
                    Console.WriteLine('0');
                }
            }
            else
            {
                if(d1 == 31)
                {
                    Console.WriteLine('1');
                }
                else
                {
                    Console.WriteLine('0');
                }
            }
        }
    }
}

Measured memory_bytes: 13140
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) ((int)(x).size())
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{
    int N,M; cin>>N>>M;
    vector<pint> a(N);
    REP(i,N) cin>>a[i].first>>a[i].second;
    sort(ALL(a));

    int cost=0;
    REP(i,N){
        int c=min(M,a[i].second);
        cost+=a[i].first*c;
        M-=c;
    }
    cout<<cost<<endl;
}


Measured memory_bytes: 1792
package main

import (
	"fmt"
	"math"
)

func max(a, b int) int {
	if a >= b {
		return a
	}
	return b
}

func main() {
	var x, ans int
	fmt.Scan(&x)
	ans = 0

	for b := 1; b < 32; b++ {
		for p := 2; p < 10; p ++ {
			y := int(math.Pow(float64(b), float64(p)))
			if y <= x {
				ans = max(ans, y)
			}
		}
	}
	fmt.Println(ans)
}

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

int main(){
    int r,c,a;
    cin >> r >> c;
    int graph[r+1][c+1]={};
    for(int i = 0;i<r;i++){
        int sum1 = 0;
        for(int j = 0;j<=c;j++){
            if(j<c){
                cin >> a;
                sum1 += a;
                graph[i][j]=a;
                graph[r][j]+=a;
            }else if(j==c){
                graph[i][j]=sum1;
                graph[r][j]+=sum1;
            }
        }
    }
    for(int k = 0;k<=r;k++){
        for(int l = 0; l<=c;l++){
            if(l<c){
                cout << graph[k][l]<<" ";
            }else{
                cout << graph[k][l]<<endl;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 3124
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main()
{
	double n;

	scanf("%lf", &n);
	if(n==1){
		printf("1");
		return 0;
	}
	if(n==2){
		printf("8");
		return 0;
	}

	if(n>=3){
		printf("%0.f", round(pow(n, 3)));
		return 0;
	}

    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
/* clang-format on */

int main() {
  int N;
  while (cin >> N) {
    vector<int> x(N), y(N);
    vector<ll> h(N);
    for (int i = 0; i < N; i++) cin >> x[i] >> y[i] >> h[i];
    for (int cx = 0; cx <= 100; cx++) {
      for (int cy = 0; cy <= 100; cy++) {
        bool ok = true;
        ll candH = -1, upperH = 1e9 + 10000ll;
        for (int i = 0; i < N; i++) {
          int dist = abs(x[i] - cx) + abs(y[i] - cy);
          if (h[i] == 0) {
            upperH = min(upperH, (ll)dist);
          } else {
            ll H = h[i] + dist;
            if (candH == -1 || candH == H) {
              candH = H;
            } else {
              ok = false;
            }
          }
        }
        if (!ok) continue;
        if (candH != -1 && candH <= upperH) {
          cout << cx << " " << cy << " " << candH << endl;
          goto end;
        }
      }
    }
    assert(false);
  end:;
  }
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define MAX 100
#define INF (1<<21)
#define W 0
#define G 1
#define B 2

int n, M[MAX][MAX];

void dijkstra(){
  int i, u, v, minv, d[MAX], color[MAX];

  for(i=0; i<n; i++){
    d[i]=INF;
    color[i]=W;
  }

  d[0]=0;
  color[0]=G;

  while(1){
    minv=INF;
    u=-1;
    for(i=0; i<n; i++){
      if(minv>d[i] && color[i] != B){
        u=i;
        minv=d[i];
      }
    }
    if(u==-1) break;
    color[u]=B;
    for(v=0; v<n; v++){
      if(color[v]!=B && M[u][v] != INF){
        if(d[v]>d[u]+M[u][v]){
          d[v]=d[u]+M[u][v];
          color[v]=G;
        }
      }
    }
  }
  for(i=0; i<n; i++){
    if(d[i]==INF) d[i]=-1;
    else d[i]=d[i];
    printf("%d %d\n",i,d[i]);
  }
}


int main(){

  int i, j, k, c, u, v;

  scanf("%d",&n);
  for(i=0; i<n; i++){
    for(j=0; j<n; j++){
      M[i][j]=INF;
    }
  }

  for(i=0; i<n; i++){
    scanf("%d%d",&u,&k);
    for(j=0; j<k; j++){
      scanf("%d%d",&v,&c);
      M[u][v]=c;
    }
  }

  dijkstra();

  return 0;
}

Measured memory_bytes: 632
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define PII pair<int,int>
#define VI vector<int>
#define VPII vector<pair<int,int> >
#define PLL pair<long long,long long>
#define VPLL vector<pair<long long,long long> >
#define F first
#define S second
typedef long long LL;
using namespace std;
const int MOD = 1e9+7;
const int SIZE = 1e6+10;
char s[SIZE];
int main(){
    DRI(n);
    RS(s);
    REP(st,200){
        int now=st;
        bool fail=0;
        REP(i,n){
            if(s[i]=='(')now++;
            else now--;
            if(now<0)fail=1;
        }
        if(!fail){
            REP(i,st)printf("(");
            printf("%s",s);
            REP(i,now)printf(")");
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 256
D = int(input())
c = list(map(int, input().split()))
s = []
for i in range(D):
  s.append(list(map(int, input().split())))
  
sdictlist = []
sdictlistsorted = []
for i in range(D):
  onedict = {}
  for j in range(26):
    onedict[j] = s[i][j]
  sdictlist.append(onedict)
  onesorteddict = sorted(onedict.items(), key=lambda x:x[1], reverse=True)
  sdictlistsorted.append(onesorteddict)

lenpastmax = 26 #26まで設定できる
pastlist = []
for i in range(D):
  j = 0
  while(sdictlistsorted[i][j][0] in pastlist):
    j += 1
  print(sdictlistsorted[i][j][0]+1)
  pastlist.append(sdictlistsorted[i][j][0])
  if(len(pastlist)==lenpastmax):
    pastlist.pop(0)

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

const int N = 1e6 + 10, mod = 1e9 + 7;

long long pref[N];

int main() {
    // ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int tc = 1; 
    //scanf("%d", &tc);
    while(tc--) {
        int n; cin >> n;
        for(int i = 1; i < N; i++) {
            pref[i] = pref[i - 1];
            if(i % 3 && i % 5) pref[i] += i;
        }
        cout << pref[n];
    }    
    return 0;
}

Measured memory_bytes: 11460
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
#include <algorithm>
//#include <tuple>

//#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back

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

  int cnt = 1;
  bool flag = false;
  for (int i = 0 ; i < N - 1; i++) {
    if (s.at(i) == s.at(i + 1)) {
      continue;
    } else {
      cnt++;      
    }
  }
  
  cout << cnt << endl;

}


Measured memory_bytes: 512
#include<iostream>
using namespace std;
#define INF 1 << 20
int main() {
    int n;
    cin >> n;
    int a[200] = {0};
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    int tmp = 0;
    int have = INF;
    for (int i = 0; i < n; i++) {
        while(a[i] % 2 == 0 && a[i] != 0) {
            a[i] /= 2;
            tmp++;
        }
        if (have > tmp) {
            have = tmp;
        }
        tmp = 0;
    }
    cout << have << endl;
    return 0;
}


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

int n, A[20];

bool solve(int i, int m){
   if(m == 0) return true;
   if(i >= n) return false;
   return solve(i + 1, m) || solve(i + 1, m - A[i]); //i番目の要素を使う:左 使わない:右
}

int main()
{
   int q, m;
   cin >> n;
   for(int i=0; i<n; i++) cin >> A[i];
   cin >> q;
   for(int i=0; i<q; i++){
      cin >> m;
      if(solve(0, m)) cout << "yes" << endl;
      else cout << "no" << endl;
   }
}


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

using namespace std;

#define all(x) x.begin(), x.end()
#define sz(x) (int) x.size()
#define pb push_back
#define endl '\n'
#define snd second
#define fst first
#define fastio cin.tie(NULL),cout.sync_with_stdio(true)

typedef long long int ll;
typedef unsigned long long int ull;
typedef vector <int> vi;
typedef pair <int, int> ii;

const ll mod = 1e9 + 7;
const ll INF = (1LL<<50);
const double EPSILON = 0.001;
const int N = 1000005;
int divi[N], prime[N];
void divv(){
	prime[1] = 1;

	for(int i = 1; i < N; i++){
		divi[i]++;
		for(int j = i+i; j < N; j+=i){
			divi[j]++;
			prime[j] = 1;
		}
	}
}
int main(){
	fastio;
	divv();
	int n, ans = 0;
	cin >> n;
	for(int i = 1; i < n; i++){
		ans += (divi[n-i]);
	}
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 11440
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
using namespace std;
typedef vector <double> vd;
typedef vector <vd> vvd;

int equation(vvd &A){
    int n1=3;
	for (int i1=0; i1<n1; i1++){
		int j1=i1;
		if (A[j1][i1]==0)
			for (int j2=j1+1; j2<n1; j2++)
				if (A[j2][i1]!=0){
					for (int i3=0; i3<n1+1; i3++)
						swap(A[j2][i3], A[j1][i3]);
					break;
				}
		double tmp = A[j1][i1];
		for (int i2=0; i2<n1+1; i2++)
			A[j1][i2]/=tmp;

		for (int j2=0; j2<n1; j2++){
			if (j2==j1) continue;
			tmp = A[j2][i1];
			for (int i2=0; i2<n1+1; i2++)
				A[j2][i2] -= tmp * A[j1][i2];
		}
	}

    return 0;
}

int main(void){
    int n=0;
	double x=0, y=0, x0=0, y0=0, r=0;
	vvd A(3, vd(4));

	cin>>n;
	for (int i=0; i<n; i++){
		for (int j=0; j<3; j++){
			cin>>x>>y;
			A[j][0] = x;
			A[j][1] = y;
			A[j][2] = 1;
			A[j][3] = -(x*x + y*y);
		}
		equation(A);

		x0 = -A[0][3] / 2;
		y0 = -A[1][3] / 2;
		r = sqrt(pow(x-x0, 2) + pow(y-y0, 2));

		cout<<fixed<<setprecision(3);
		cout<<x0<<" "<<y0<<" "<<r<<endl;
	}
    return 0;
}

Measured memory_bytes: 1304
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()]

sat = sum(B)
for a, n_a in zip(A, A[1:]):
  if n_a - a == 1:
    sat += C[a]

print(sat)

Measured memory_bytes: 3188
#include<stdio.h>

int main()
{
	int n;
	scanf("%d",&n);
	
	int f[45];
	
	f[0]=f[1]=1;
	
	int i;
	for(i=2;i<=n;i++)
	{
		f[i]=f[i-1]+f[i-2];
	}
	
	printf("%d\n",f[n]);
	
	return 0;
}


Measured memory_bytes: 2116
def main():
    MOD = 10 ** 9 + 7

    N, K = map(int, input().split())

    ans = 0
    low = sum(range(K - 1))
    high = sum(range(N - K + 2, N + 1))
    for take in range(K, N + 2):
        low += take - 1
        high += N - (take - 1)
        ans = (ans + high - low + 1) % MOD
    print(ans)


if __name__ == '__main__':
    main()

# import sys
# input = sys.stdin.readline
# 
# sys.setrecursionlimit(10 ** 7)
# 
# (int(x)-1 for x in input().split())
# rstrip()


Measured memory_bytes: 67124
import java.util.Scanner;

public class Main {
    public static void main(String... args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        for (int i = 1; i <= n; i++) {
            if (i % 3 == 0) {
                System.out.print(" " + i);
                continue;
            }

            int x = i;
            while (x != 0) {
                if (x % 10 == 3) {
                    System.out.print(" " + i);
                    break;
                }
                x /= 10;
            }

        }
        System.out.println();
    }
}


Measured memory_bytes: 29096
from collections import*
n, *v = map(int, open(0).read().split())
a, b = [Counter(v[i::2]).most_common() + [(0,0)] for i in (0,1)]
s, x = a[0]
t, y = b[0]
print(n - [x+y, max(x+b[1][1], y+a[1][1])][s==t])

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

using namespace std;
#define int long long
#define MOD 1000000007
#define pb push_back
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int N,K;
    cin>>N>>K;
    vector<vector<int> >A(N,vector<int> (N,0));
    for(int i=0;i<N;i++)
    {
        for(int j=0;j<N;j++)
        {
            cin>>A[i][j];
        }
    }
    vector<vector<int> >ANS(N,vector<int> (N,0));
    
    for(int i=0;i<N;i++)
    {
        ANS[i][i]=1;
    }
    
    while(K)
    {
        if(K&1)
        {
            vector<vector<int> >temp(N,vector<int> (N,0));
    
            for(int i=0;i<N;i++)
            {
                for(int j=0;j<N;j++)
                {
                    int p=0;
                    for(int k=0;k<N;k++)
                    {
                        p+=(ANS[i][k]*A[k][j])%MOD;
                        p%=MOD;
                    }
                    temp[i][j]=p;
                }
            }
            ANS=temp;
        }
        
        K=K/2;
        vector<vector<int> >temp(N,vector<int> (N,0));
    
            for(int i=0;i<N;i++)
            {
                for(int j=0;j<N;j++)
                {
                    int p=0;
                    for(int k=0;k<N;k++)
                    {
                        p+=(A[i][k]*A[k][j])%MOD;
                        p%=MOD;
                    }
                    temp[i][j]=p;
                }
            }
            A=temp;
    }
    int cnt=0;
    for(int i=0;i<N;i++)
    {
        for(int j=0;j<N;j++)
        {
            cnt+=ANS[i][j];
            cnt%=MOD;
        }
    }
    cout<<cnt;
    return 0;
}

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

typedef long long ll;
ll N;
int K;

ll psum[200010];
const ll MOD = 1e9 + 7;
int main()
{
    cin >> N;
    cin >> K;
    psum[0] = 0;
    for(int i = 0; i <= N; i++) psum[i + 1] = psum[i] + i;

    ll res = 0;
    for(int k = K; k <= N + 1; k++)
    {
        ll left = psum[k];
        ll right = psum[N + 1] - psum[N + 1 - k];
        res += right - left + 1;
        res %= MOD;
    }

    cout << res << endl;


}

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

const string YES = "Yes";
const string NO = "No";

void solve(long long A, long long B, long long C) {
    if ((A == B && A != C) || (B == C && B != A) || (A == C && A != B)) {
        printf("Yes\n");
    } else {
        printf("No\n");
    }
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can
// remove this line by using your custom template)
int main() {
    long long A;
    scanf("%lld", &A);
    long long B;
    scanf("%lld", &B);
    long long C;
    scanf("%lld", &C);
    solve(A, B, C);
    return 0;
}


Measured memory_bytes: 256
#ifdef  DEBUG
#define MAXN 10
#else
#define MAXN 100007
#endif
#include <bits/stdc++.h>
using namespace std;
#define rep(i, l, r) for (int i = l; i<r;i++)
#define vi vector<int>
#define all(v) v.begin(),v.end()
#define pb(c) push_back(c)
#define vii vector<pair<int,int>>
#define vvi vector<vector<int>>
#define ii pair<int,int>
#define mp(i, j) make_pair(i,j)
#define ull unsigned long long int
#define ll  long long int
#define endl '\n'
#define PI  3.141592653589793238
#define MOD (1000000007)
#define INF (2000000000)
#define EPS (0.00000001)

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
#ifdef DEBUG
    freopen("input", "r", stdin);
#endif
    string s;
    cin>>s;

    if (s.length()>3 && s[0]=='Y' && s[1]=='A' && s[2]=='K' && s[3]=='I')cout<<"Yes";
    else cout<<"No";
    return 0;
}





















Measured memory_bytes: 256
import math
while True:
    h,w=map(int,input().split())
    if w==0 and h==0:
        break
    tikk=w*w+h*h
    
    min=151*151
    minw=0
    minh=0
    for ih in reversed(range(1,int(math.sqrt(tikk))+2)):
        for iw in reversed(range(ih+1,int(math.sqrt(tikk))+2)):
            itikk=iw*iw+ih*ih
            if tikk>itikk:
                continue
            if itikk<=min and (iw!=w or ih!=h):
                if itikk==tikk and ih<h:
                    continue
                min=itikk
                minw=iw
                minh=ih
    print("{} {}".format(minh,minw))
        


Measured memory_bytes: 5664
#include<stdio.h>

int main(){
	int i,j;
	int H,W;
	
	for(;scanf("%d%d",&H,&W),H,W;){
		for(i=0;i<H;i++){
			for(j=0;j<W;j++){
				if(i%2==0){
					if(j%2==0){
						printf("#");
					}else{
						printf(".");
					}
				}else{
					if(j%2!=0){
						printf("#");
					}else{
						printf(".");
					}
				}
			}
			printf("\n");
		}
		printf("\n");
	}
	
	return 0;
}

Measured memory_bytes: 572
import math
import sys

def getinputdata():

    # 配列初期化
    array_result = []
    
    data = input()

    
    array_result.append(data.split(" "))

    flg = 1

    try:


        while flg:

            data = input()

            array_temp = []

            if(data != ""):
                
                array_result.append(data.split(" "))

                flg = 1

            else:

                flg = 0
    finally:


        return array_result





arr_data = getinputdata()

a = int(arr_data[0][0])
b = int(arr_data[0][1])
c = int(arr_data[0][2])


if(a==b):
    
    print(c)
    

elif(a==c):
    
    print(b)
    
elif(b==c):
    
    print(a)
    


Measured memory_bytes: 3064
#include <iostream>
#include <bits/stdc++.h>
#include <set>
#define vi vector<int>
#define vll vector<long long>
#define pii pair<int, int>
#define vii vector<pair<int, int> >
#define si stack<int>
#define pb push_back
#define mp make_pair
#define ALL(T) (T).begin(), (T).end()
#define MODU 1000000007
typedef long long ll;
using namespace std;

ll intmax = (1LL<<32)-1;
ll llmax = (1LL<<60)-1;

const int INF = 1e9 + 5;

class fastio{
public:
	fastio(){
		ios_base::sync_with_stdio(false);
		cin.tie(NULL);
	}
} __fastio;

template <typename T>
T abs(T x){
	if(x < 0) return -x;
	else return x;
}

void DFSVisit(int u, vector<int> g[], vector<bool> &visited){
    visited[u] = true;
    for(int i=0; i<(int)g[u].size(); i++){
        if(!visited[g[u][i]]){
            DFSVisit(g[u][i], g, visited);
        }
    }
}

void DFS(vector<int> adj[], int V){
    vector<bool> visited(V, false);
    for(int u=0; u<V; u++)
        if(!visited[u])
            DFSVisit(u, adj, visited);
}


int main(){
    int n;
    cin >> n;
    vector<int> b(n-1);
    for(int i=0; i<n-1; i++)
        cin >> b[i];
    vector<int> a(n, 0);
    a[0] = b[0];
    for(int i=1; i<n-1; i++){
        a[i] = min(b[i-1], b[i]);
    }
    a[n-1] = b[n-2];
    cout << accumulate(a.begin(), a.end(), (long long)(0));
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ll long long int
const int INF = 2147483647;

using namespace std;

int main()
{
  string x;
  cin >> x;
  int n = 0, w = 0, s = 0, e = 0;
  REP(i, x.length())
  {
    if (x[i] == 'N')
    {
      n++;
    }
    if (x[i] == 'W')
    {
      w++;
    }
    if (x[i] == 'S')
    {
      s++;
    }
    if (x[i] == 'E')
    {
      e++;
    }
  }
  if (n == 0 && s > 0)
  {
    cout << "No" << endl;
    return 0;
  }
  if (n > 0 && s == 0)
  {
    cout << "No" << endl;
    return 0;
  }
  if (w > 0 && e == 0)
  {
    cout << "No" << endl;
    return 0;
  }
  if (w == 0 && e > 0)
  {
    cout << "No" << endl;
    return 0;
  }
  cout << "Yes" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const string YES = "Yes";
const string NO = "No";
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;


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

    int a[3][3] = {};
    int n;
    REP(i,3) REP(j,3) cin >> a[i][j];
    cin >> n;
    int b[n] = {};
    REP(i,n) cin >> b[i];
    REP(i,3){
        REP(j,3){
            REP(k,n){
                if(a[i][j] == b[k]) a[i][j] = 0;
            }
        }
    }

    if (a[0][0]==a[1][1] && a[1][1]==a[2][2] && a[1][1]==0){
        cout << YES;
        return 0;
    }
    if (a[0][2]==a[1][1] && a[1][1]==a[2][0] && a[1][1]==0){
        cout << YES;
        return 0;
    }
	REP(i,3){
		if(a[i][0]==a[i][1] && a[i][1]==a[i][2] && a[i][2]==0){
		cout << "Yes\n";
		return 0;
		} 
	}
	REP(i,3){
		if(a[0][i]==a[1][i] && a[1][i]==a[2][i] && a[2][i]==0){
		cout << "Yes\n";
		return 0;
		} 
	}
    // REP(i,3) REP(j, 3) cout << a[i][j];
    cout << NO;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define nl "\n"
using namespace std;
typedef unsigned long long ull;

void solve() {
	string s;
	unsigned int k;
	cin >> k >> s;
	if (k >= s.length()) {
		cout << s << endl;
	}
	else {
		cout << s.substr(0,k) << "..." << endl;
	}
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	solve();
	return 0;
}


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

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  int now = 1;
  rep(i, n) {
    if (now <= k) now *= 2;
    else now += k;
  }
  cout << now << endl;
  return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n int
	fmt.Scan(&n)
	nums := make([]int, n)
	sum := 0
	for i:=0; i<len(nums); i++{
		fmt.Scan(&nums[i])
		sum += nums[i]
	}

	sort.Ints(nums)
	fmt.Println(nums[0], nums[n-1], sum)
}


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

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main(){
    int n,m;
    cin>>n>>m;

    UnionFind UF(n);
    for (int i = 0; i < m; i++)
    {
        int a,b ;
        cin >> a >> b;
        a -= 1; b -= 1;
        UF.unite(a, b);
    }
    vector<int> a(n);
    rep(i,n){
        a[i]=UF.root(i);
    }
    sort(a.begin(),a.end(),greater<int>());
    int ans=0;
    rep(i,n-1){
        if(a[i]>a[i+1])ans++;

    }

 
    cout << ans << endl;

}

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

int main() {
  int N, K;
  cin >> N >> K;
  int A[N]={0};
  int D[K]={0};
  for(int i=0; i<K; i++) {
    cin >> D[i];
    for(int j=0; j<D[i]; j++) {
      int E[D[i]]={-1};
      cin >> E[j];
      A[E[j]-1]=1;
    }
  }
  int ans=0;
  for(int i=0; i<N; i++) {
    if(A[i]==0) {
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3632
def d(x):
    dl=[]
    for i in range(1, int(x**0.5)+1):
        if x%i==0:
            dl.append(i)
            if i!=x//i:
                dl.append(x//i)
    return dl

n=int(input())
ans=0
t=d(n)
for i in t:
    if i==1:
        continue
    tn=n
    while tn>=i:
        if tn%i==0:
            tn//=i
        else:
            tn%=i
    if tn==1:
        ans+=1
ans+=len(d(n-1))-1
print(ans)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define INF 1e9
#define EPS 1e-9
#define MOD (1e9+7)
void put(string d){}template<class H,class...T>void put(string d,H&h,T&...t){cout<<h;if(sizeof...(t))cout<<d;put(d,t...);}
template<class T>void puti(T&a,string d=" "){bool f=1;for(auto&_:a)cout<<(exchange(f,0)?"":d)<<_;cout<<endl;}
template<class T>void putii(T&a,string d=" "){for(auto&_:a)puti(_,d);}

int main(){
    int n;
    cin>>n;
    vector<ll> a(n),b(n);
    ll sum=0,ans=0;
    rep(i,n) cin>>a[i];
    
    while(1){
        bool ok=true;
        sum=0;
        rep(i,n) {
            if(a[i]>=n)ok=false;
            sum+=a[i]/n;
            b[i]=a[i]%n;
        }
        if(ok) break;
        ans+=sum;
        rep(i,n) a[i]=b[i]+sum-a[i]/n;
    }
    
    cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
n=int(input())
alist=list(map(int,input().split()))

cnt1=0
asum=0
#a0>0
for i in range(n):
  asum+=alist[i]
  if i%2==0:
    if asum<=0:
      cnt1+=1-asum
      asum+=1-asum
  else:
    if asum>=0:
      cnt1+=asum+1
      asum-=asum+1
      
cnt2=0
asum=0
#a0<0
for i in range(n):
  asum+=alist[i]
  if i%2==0:
    if asum>=0:
      cnt2+=asum+1
      asum-=asum+1
  else:
    if asum<=0:
      cnt2+=1-asum
      asum+=1-asum

#print(cnt1,cnt2)      
print(min(cnt1,cnt2))

Measured memory_bytes: 14468
def inpf() a=gets.chomp.split(" ").map(&:to_f)end

def inps() a=gets.chomp.split(" ")end

def copy(a) Marshal.load(Marshal.dump(a)) end

def kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end

def na(n,d=0) Array.new(n,d)end

def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end

def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end

def inp() a=gets.chomp.split(" ").map(&:to_i)end

def r_up(a, b) (a+b-1)/b end

def r_sort(a) a.sort{|a,b|b<=>a} end
n = inp[0]
ti = []
n.times do |i|
  on = inp
  ti[i] = on.join.to_i(2)
end
pr = []
n.times do |i|
  pr[i] = inp
end
ans = -1e20
(1..1023).each do |d|
  now = 0
  n.times do |i|
    pand = ti[i]&d
    c = pand.to_s(2).count("1")
    now += pr[i][c]
  end
  ans = [now,ans].max
end
p ans

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

int main() {
	int m, d;
	cin>>m>>d;
	
	int ans = 0;
	
	for(int i = 1; i<=m; i++) {
		for(int j = 22; j<=d; j++) {
			int a = j%10;
			int b = j/10;
			if(a>=2 && b >=2 && i == a*b) {
				ans++;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
n=gets.to_i
l=[0]*100
n.times do |mm|
  m=mm+1
  k=m.to_s[0].to_i*10+m%10
  l[k]+=1
end
c=0
100.times do |i|
  if i%11==0
    c+=l[i]**2
  else
    c+=l[i]*l[i%10*10+i/10]
  end
end
puts c



Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll dfs(ll idx,vector <ll> g[],vector <ll> &dp){
	if(dp[idx]>0){
		return dp[idx];
	}
	ll val=0;
	for(auto itr:g[idx]){
		val=max(val,dfs(itr,g,dp)+1);
	}
	dp[idx]=val;
	return val;
}
int main()
{

	ios::sync_with_stdio(false);cin.tie(0);
    ll n,m;cin>>n>>m;
    vector <ll> g[n+1];
    for(int i=0;i<m;i++){
		ll x,y;
		cin>>x>>y;
		g[x].push_back(y);
    }
    ll ans=0;
    vector <ll> dp(n+1,0);
    for(int i=1;i<=n;i++){
		ans=max(ans,dfs(i,g,dp));
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 9216
import java.util.* 
fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val N = sc.nextInt()
    val Q = sc.nextInt()
    val S = sc.next()
    val DP = IntArray(N+1){0}
    var isA = false
    for ((i,c) in S.withIndex()) {
        if (c == 'C' && isA) {
            isA = false
            DP[i+1] = DP[i]+1
        }
        else {
            if (c == 'A') isA = true
            else isA = false
            DP[i+1] = DP[i]
        }
    }
    //DP.forEach{println("$it ")}
    
    for (i in 0 until Q) {
        val l = sc.nextInt()
        val r = sc.nextInt()
    
        println(DP[r]-DP[l])
    }
}

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

int main(void){
	int n, k;
	cin >> n >> k;
	vector<vector<int>> e(n);
	for(int i = 0; i < n-1; ++i){
		int a, b;
		cin >> a >> b;
		a--; b--;
		e[a].push_back(b);
		e[b].push_back(a);
	}
	queue<int> q;
	q.push(0);
	ll ans = k;
	vector<bool> v(n,false);
	while(!q.empty()){
		int now = q.front();
		q.pop();
		ans %= MOD;
		int tmp = now?k-2:k-1;
		v[now] = true;
		for(auto x : e[now]){
			if(!v[x]){
				q.push(x);
				ans *= tmp;
				tmp--; ans %= MOD;
			}
		}
	}
	cout << ans%MOD << endl;
	return 0;
}

Measured memory_bytes: 6520