akhauriyash/Code-Regression huggingface dataset:
D = [
    (1, 5, 2, 3, 0, 4), # 'U'
    (3, 1, 0, 5, 4, 2), # 'R'
    (4, 0, 2, 3, 5, 1), # 'D'
    (2, 1, 5, 0, 4, 3), # 'L'
]

*L1, = map(int, input().split())
*L2, = map(int, input().split())

p = (0, 0, 0, 1, 1, 2, 2, 3)*3
ok = 0
for k in p:
    if L1 == L2:
        ok = 1
    L2[:] = [L2[e] for e in D[k]]

print("Yes" if ok else "No")



Measured memory_bytes: 5604
n, m = (int(x) for x in input().split())
x = [int(x) for x in input().split()]
if n >= m:
    print(0)
else:
    x.sort()
    dis = [abs(x[i+1] - x[i]) for i in range(m-1)]
    dis.sort()
    for _ in range(n-1): dis.pop(-1)
    print(sum(dis))

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

#define DEBUG(x) cerr << #x << " = " << x << endl

struct Node {
    int a, b, c;
    bool state;
    Node(int a, int b, int c, bool state) : a(a), b(b), c(c), state(state) { }
};

int main() {
    for(int A, B, C; cin >> A >> B >> C, A || B || C; ) {
        vector<int> stateA(A, -1);
        vector<int> stateB(B, -1);
        vector<int> stateC(C, -1);
        int N; cin >> N;
        vector<Node> nodes;
        for(int i = 0; i < N; i++) {
            int p, q, r;
            int s;
            cin >> p >> q >> r >> s;
            p--, q--, r--;
            q -= A;
            r -= A + B;
            nodes.push_back(Node(p, q, r, s));
        }
        for(int i = 0; i < N; i++) {
            if(nodes[i].state) {
                stateA[nodes[i].a] = 1;
                stateB[nodes[i].b] = 1;
                stateC[nodes[i].c] = 1;
            }
        }

#if 0
        for(int i = 0; i < A; i++) DEBUG(stateA[i]);
        for(int i = 0; i < B; i++) DEBUG(stateB[i]);
        for(int i = 0; i < C; i++) DEBUG(stateC[i]);
#endif

        for(int i = 0; i < N; i++) {
            if(nodes[i].state == false) {
                if(stateA[nodes[i].a] == 1 && stateB[nodes[i].b] == 1) stateC[nodes[i].c] = 0;
                if(stateB[nodes[i].b] == 1 && stateC[nodes[i].c] == 1) stateA[nodes[i].a] = 0;
                if(stateC[nodes[i].c] == 1 && stateA[nodes[i].a] == 1) stateB[nodes[i].b] = 0;
            }
        }
        for(int i = 0; i < A; i++) {
            if(stateA[i] == -1) stateA[i] = 2;
            cout << (int)stateA[i] << endl;
        }
        for(int i = 0; i < B; i++) {
            if(stateB[i] == -1) stateB[i] = 2;
            cout << (int)stateB[i] << endl;
        }
        for(int i = 0; i < C; i++) {
            if(stateC[i] == -1) stateC[i] = 2;
            cout << (int)stateC[i] << endl;
        }
    }
}

Measured memory_bytes: 1228
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ;
#endif

#define equals(a,b) (fabs((a)-(b)) < EPS)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

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

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

template <typename T>
void print_array(const T &ary, int size){
    REP(i,size){
        cout << ary[i] << " ";
    }
    cout << endl;
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;
const double EPS = (1e-10);

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(12);
    int N,X,T; cin >> N >> X >> T;
    int cnt = (N+X-1) / X;
    cout << T*cnt << endl;

}

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

int main()
{
  int N, M;
  cin >> N >> M;
  int road[N];
  
  for (int i = 0; i < N; i++)
  {
    road[i] = 0;
  }
  
  for (int i = 0; i < M; i++)
  {
    int a, b;
    cin >> a >> b;
    road[a - 1]++;
    road[b - 1]++;
  }
  
  for (int i = 0; i < N; i++)
  {
    cout << road[i] << endl;
  }
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <cmath>
#include <set>
#include <stack>
#include <queue>
#include <numeric>
#include <deque>
#include <cstring>
#include <iterator>
#include <map>
#include <cstdlib>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <complex>
#include <bitset>
#include <chrono>
#include <random>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define eb emplace_back
typedef  long long  ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<pll> vpll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;

const int mod=1000000007;
//const int mod=998244353;




int main()
{   ios_base::sync_with_stdio(false);cin.tie(NULL);
    ll t,n,m,k,q,x,a,b,c,d;
    cin>>n;
    vi nn(n);
    map<int,int> map;
    for(int i=0; i<n-1; i++) {
        cin>> nn[i];
        map[nn[i]]++;
    }
    for(int i=1; i<=n; i++)
        cout<< map[i]<< '\n';
    
    
    return 0;
}


Measured memory_bytes: 13556
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)

template<typename T>
class BIT
{
    vector<T> val;
public:
    BIT(int num)
    {
        val = vector<T>(num+1, 0);
    }
    BIT(vector<T> &init)
    {
        val = vector<T>(init.size()+1, 0);
        for (int i=0; i<init.size(); i++) q_add(i, init[i]);
    }
    void q_add(int pos, T v)
    {
        pos++;
        while (pos < val.size())
        {
            val[pos] += v;
            pos += pos & -pos;
        }
    }
    T q_sum(int pos)
    {
        pos++;
        T res = 0;
        while (pos > 0)
        {
            res += val[pos];
            pos -= pos & -pos;
        }
        return res;
    }
};

lint N, M, Q;
using tpl = tuple<int, int, int>; // R, L, querynum

vector<tpl> query;
int main()
{
    cin >> N >> M >> Q;
    BIT<int> bit(N + 1);
    REP(_, M) {
        int l, r;
        cin >> l >> r;
        query.push_back(tpl(r, -1, l));
    }
    REP(q, Q) {
        int l, r;
        cin >> l >> r;
        query.push_back(tpl(r, q, l));
    }

    sort(query.begin(), query.end());
    vector<int> ans(Q);

    for (tpl t : query) {
        int l, r, q;
        tie(r, q, l) = t;
        if (q < 0)
            bit.q_add(l, 1);
        else {
            ans[q] = bit.q_sum(r) - bit.q_sum(l - 1);
        }
    }
    for (auto v : ans) cout << v << endl;
}


Measured memory_bytes: 8560
# /usr/bin/env python3


def count_blue_balls(n, a, b):
    d, m = divmod(n, a + b)
    num_blues = d * a + min(a, m)
    return num_blues


def main():
    n, a, b = (int(z) for z in input().split())
    res = count_blue_balls(n, a, b)
    print(res)


if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fod(i,a,b) for(int i=a;i>=b;i--)
using namespace std;
typedef long long LL;
const int N=100500;
int read(int &n)
{
	char ch=' ';int q=0,w=1;
	for(;(ch!='-')&&((ch<'0')||(ch>'9'));ch=getchar());
	if(ch=='-')w=-1,ch=getchar();
	for(;ch>='0' && ch<='9';ch=getchar())q=q*10+ch-48;n=q*w;return n;
}
int m,n,ans;
int a[N];
int g[N];
int gcd(int x,int y){return y?gcd(y,x%y):x;}
int main()
{
	int w;
	LL q;
	read(n);
	fo(i,1,n)q+=(LL)read(a[i]);
	if(n==1&&a[1]==1)
	{
		printf("Second\n");
		return 0;
	}
	if(n==1)
	{
		printf("First\n");
		return 0;
	}
	if(!(n&1))
	{
		if(q&1)printf("First\n");
		else printf("Second\n");
		return 0;
	}
	if(!(q&1))
	{
		printf("First\n");
		return 0;
	}
	for(bool I=0;1;I=!I)
	{
		g[n]=a[n];
		LL t=a[n]-1;
		fod(i,n-1,1)g[i]=gcd(g[i+1],a[i]),t+=(LL)a[i];
		bool OK=0;
		q=a[1];
		if(a[1]-1&&(1&(t/(ans=gcd(g[2],a[1]-1)))))OK=1,--a[1];
		else fo(i,2,n)if(a[i]-1)
		{
			w=gcd(q,a[i]-1);
			if(i<n)w=gcd(w,g[i+1]);
			if((1&(t/(ans=w))))
			{
				OK=1,--a[i];
				break;
			}
			q=gcd(q,a[i]);
		}else break;
		if(!OK)
		{
			if(I)printf("First\n");
			else printf("Second\n");
			return 0;
		}
		fo(i,1,n)a[i]/=ans;
	}
	return 0;
}

Measured memory_bytes: 896
#include<stdio.h>
#include <string.h>

int main(void)
{
  char s[100];
  int ans;
  scanf("%s", s);
  
  if(strcmp(s, "SAT") == 0){
    ans = 1;
  }else if(strcmp(s, "FRI") == 0){
    ans = 2;
  }else if(strcmp(s, "THU") == 0){
    ans = 3;
  }else if(strcmp(s, "WED") == 0){
    ans = 4;
  }else if(strcmp(s, "TUE") == 0){
    ans = 5;
  }else if(strcmp(s, "MON") == 0){
    ans = 6;
  }else{
    ans = 7;
  }
      
  printf("%d\n", ans);

  return 0;
}

Measured memory_bytes: 128
// 21:35
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 300000+10;
int x,y,z,n;
struct Item{
	int a,b,c;
	bool operator<(const Item&o)const{
		return b-c>o.b-o.c;
	}
	void read(){
		scanf("%d%d%d",&a,&b,&c);
	}
} it[N];
LL sum[N<<2],cnt[N<<2];
vector<int> v;
int id(int x){
	return lower_bound(v.begin(),v.end(),x)-v.begin()+1;
}
void build(){
	memset(sum,0,sizeof(sum)); 
	memset(cnt,0,sizeof(cnt));
}
void update(int l,int r,int rt,int pos){
	if(l==r){
		cnt[rt]++; sum[rt]+=v[pos-1]; return;
	}
	int mid=(l+r)>>1;
	if(pos<=mid)update(l,mid,rt<<1,pos);
	else update(mid+1,r,rt<<1|1,pos);
	sum[rt]=sum[rt<<1]+sum[rt<<1|1];
	cnt[rt]=cnt[rt<<1]+cnt[rt<<1|1];
}
LL query(int l,int r,int rt,int pos){
	if(l==r) return min((LL)pos,cnt[rt])*v[l-1];
	int mid=(l+r)>>1;
	if(pos<=cnt[rt<<1|1])return query(mid+1,r,rt<<1|1,pos);
	return sum[rt<<1|1]+query(l,mid,rt<<1,pos-cnt[rt<<1|1]);
}
LL pre[N],suf[N];
int main() {		
	scanf("%d%d%d",&x,&y,&z);
	n=x+y+z;
	for(int i=1;i<=n;i++)it[i].read();
	sort(it+1,it+1+n);
	
	for(int i=1;i<=n;i++){
		//printf("i = %d, %d %d %d\n", i,it[i].a,it[i].b,it[i].c);
	}

	{
		v.clear(); for(int i=1;i<=n;i++)v.push_back(it[i].b-it[i].a);
		sort(v.begin(),v.end());
		v.erase(unique(v.begin(),v.end()),v.end());
		LL sum=0;
		for(int i=1;i<=n;i++){
			sum+=it[i].a;
			update(1,n,1,id(it[i].b-it[i].a));
			if(i>=y){
				pre[i]=sum+query(1,n,1,y);
				//printf("pre[%d] = %d\n", i,pre[i]);
			}
		}
	}
	build();
	{
		v.clear(); for(int i=1;i<=n;i++)v.push_back(it[i].c-it[i].a);
		sort(v.begin(),v.end());
		v.erase(unique(v.begin(),v.end()),v.end());
		LL sum=0;
		for(int i=n;i>=1;i--){
			sum+=it[i].a;
			update(1,n,1,id(it[i].c-it[i].a));
			//printf("add %d\n", it[i].c-it[i].a);
			if(n-i+1>=z){
				suf[i]=sum+query(1,n,1,z);
				//printf("suf[%d] = %d\n", i,suf[i]);
			}
		}
	}
	LL res=0;
	for(int i=1;i<=n;i++){
		if(i>=y && n-(i+1)+1>=z){
			res=max(res,pre[i]+suf[i+1]);
		}
	}
	cout<<res<<endl;
}


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

int main(){
    cout.precision(12);
    cout.setf(ios_base::fixed, ios_base::floatfield);
    
    int n;
    int A[100];
    double invsum = 0.0;

    cin >> n;
    for(int i=0;i<n;i++) cin >> A[i];

    for(int i=0;i<n;i++){
        invsum += 1.0 / A[i];
    }
    cout << 1.0/invsum << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include<math.h>

int main(void){
    
    unsigned long int n;
    char ans[20];
    int i = 1;

    scanf("%lu",&n);
    for(;;){
        if(n%26 == 0){
            ans[i] = 'z';
            
        n -= 26;
        }
        else ans[i] = (n%26-1)+'a';
        n = n/26;
        if(n == 0)break;
        i ++;
    }

    for(;i>0;i--)printf("%c",ans[i]);

    return 0;
}

Measured memory_bytes: 1664
#include<stdio.h>
#include<algorithm>
#include<math.h>
using namespace std;
int b[110000];
double c[11000];
int main(){
	int a;scanf("%d",&a);
	for(int i=0;i<a;i++)scanf("%d",b+i);
	c[0]=(double)b[0];
	for(int i=1;i<a;i++){
		c[i]=(double)b[i];
		for(int j=0;j<i;j++){
			c[i]=max(c[i],c[j]+2.0*sqrt(b[i]*b[j]));
		}
	}
	double ret=0;
	for(int i=0;i<a;i++)ret=max(ret,c[i]+(double)b[i]);
	printf("%.12f\n",ret);
}

Measured memory_bytes: 1072
import math

A, B, H, M = map(int, input().split())

m = M * 6
h = H * 30 + M / 2 

ms = B * math.sin(math.radians(m))
mc = B * math.cos(math.radians(m))
hs = A * math.sin(math.radians(h))
hc = A * math.cos(math.radians(h))

ans = ((ms - hs) ** 2 + (mc - hc) ** 2) ** 0.5

print(ans)

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

using namespace std;
#define pb push_back
#define db(x) cerr << #x << " = " << x << endl;
#define INF 0x3f3f3f3f3f3f3f3f
#define fi first
#define se second
#define vi vector<int>
#define vll vector<ll>
#define all(x) x.begin(), x.end()
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vii vector<pii>
#define ll long long
#define ull unsigned long long
typedef long double ld;

/*
	LIS nlgn DP + Binary Search
	[COMPLEX] O(NlgN)
	[USAGE]
		[ARGS] vetor values que queremos obter o LIS
	[OUT]
		Vetor res que nos diz o maior LIS que termina na posição i
*/

#define MAXN 212345

int n;
int h[MAXN];
ll a[MAXN];
ll dp[MAXN];
ll tree[4 * MAXN];

void update(int node, int l, int r, int pos, ll val)
{
    if (l == r)
    {
        tree[node] = val;
        return;
    }

    int mid = (l + r)/2;

    if (pos <= mid)
        update(node * 2 + 1, l, mid, pos, val);
    else
        update(node * 2 + 2, mid + 1, r, pos, val);

    tree[node] = max(tree[node * 2 + 1], tree[node * 2 + 2]);
}

ll query(int node, int l, int r, int tl, int tr)
{
    if (r < tl || l > tr)
        return 0;
    
    if (tl <= l && r <= tr)
        return tree[node];

    int mid = (l + r)/2;
    return max(query(node * 2 + 1, l, mid, tl, tr),
               query(node * 2 + 2, mid + 1, r, tl, tr));
}

int main()
{
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
    {
        scanf("%d", &h[i]);
    }
    for (int i = 0; i < n; i++)
    {
        scanf("%lld", &a[i]);
    }

    for (int i = 0; i < n; i++)
    {
        ll v = query(0, 0, n - 1, 0, h[i]);
        update(0, 0, n - 1, h[i], v + a[i]);
    }

    printf("%lld\n", query(0, 0, n - 1, 0, n - 1));
    
}

Measured memory_bytes: 8960
import java.io.BufferedReader;
import java.io.*;
import java.util.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Collections;
public class Main {
	public static void main(final String[] args){
    
    Scanner sc = new Scanner(System.in);

    int l = sc.nextInt();

    if((double)l % 3.0 == 0.0){
        System.out.println((double)l*l*l/27);
    }else{
        System.out.println((double)l/3*(double)l/3*(double)l/3);
    }
    
    
    
    
	}
}

Measured memory_bytes: 23124
import java.util.Scanner;

public class Main {
	private void calc(){
		Scanner scanner = new Scanner(System.in);
		int size = scanner.nextInt();
		int[] array = new int[size];
		int min=1000000, max=-1000000;
		long sum=0;
		
		if(0<=size && size<=10000){
			for(int i=0; i<array.length; i++){
				array[i] = scanner.nextInt();
				if(-1000000<=array[i] && array[i]<=1000000){
					if(min>array[i])min=array[i];
					if(max<array[i])max=array[i];
					sum +=array[i];	
				}
			}	
		}
		System.out.println(min+" "+max+" "+sum);
	}
	
	public static void main(String[] args) {
		Main run =new Main();
		run.calc();

	}
}

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

int main(void){
  int N;
  vector<int> a;

  cin >> N;
  a.resize(N);

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

  int ans = 0;

  for(auto val : a){
    ans += val;
  }
  ans -= N;

  cout << ans << endl;
}


Measured memory_bytes: 256
// AOJ 1633 On-Screen Keyboard
// bal4u 2019.8.12

#include <stdio.h>

//// 入出力関係
#if 1
#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)
#else
#define gc() getchar()
#define pc(c) putchar(c)
#endif

int in() {   // 非負整数の入力
	int n = 0, c = gc();
	do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0');
	return n;
}

void ins(char *s) { // 文字列の入力　スペース以下の文字で入力終了
	do *s = gc();
	while (*s++ > ' ');
	*(s-1) = 0;
}

void out(int n) { // 正整数の表示（出力）
	int i; char b[20];
	i = 0; while (n) b[i++] = n % 10 + '0', n /= 10;
	while (i--) pc(b[i]);
	pc('\n');
}

//// 本問題関連
#define ABS(x) ((x)>=0?(x):-(x))
int ch[128][2];
char s[1005];
		
int main()
{
	int h, w, r, c, ans;
	char *p;
	
	while (h = in()) {
		w = in();
		for (r = 0; r < h; r++) {
			for (c = 0; c < w; c++) {
				int a = gc();
				ch[a][0] = r, ch[a][1] = c;
			}
			gc();
		}
		ins(s), ans = 0, r = c = 0;
		for (p = s; *p; p++) {
			ans += 1 + ABS(ch[*p][0] - r) + ABS(ch[*p][1] - c);
			r = ch[*p][0], c = ch[*p][1];
		}
		out(ans);
	}
	return 0;
}


Measured memory_bytes: 2048
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <map>
#include <set>
#include <queue>
using namespace std;
#define lowbit(x) (x&(-x))
#define max(x,y) (x>y?x:y)
#define min(x,y) (x<y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.141592653589793238462
#define INF 0x3f3f3f3f3f
#define mem(a) (memset(a,0,sizeof(a)))
typedef long long ll;
ll gcd(ll a,ll b){
    return b?gcd(b,a%b):a;
}
bool cmp(int x,int y)
{
    return x>y;
}
const int N=10005;
const int mod=1e9+7;
int main()
{
    std::ios::sync_with_stdio(false);
    int n,s=0;
    cin>>n;
    for(int i=1;i<=n;i++)
        s+=i;
    cout<<s<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)
using namespace std;
using lli = long long int;
#define int long long int
void YESNO(bool), YesNo(bool);
template <class T1, class T2>
bool chmin(T1 &l, const T2 &r);
template <class T1, class T2>
bool chmax(T1 &l, const T2 &r);

void solve(std::vector<long long> A)
{
  lli a = accumulate(A.begin(), A.end(), 0);
  if (a >= 22)
  {
    cout << "bust";
  }
  else
  {
    cout << "win";
  }
}

signed main()
{
  std::vector<long long> A(3);
  for (int i = 0; i < 3; i++)
  {
    scanf("%lld", &A[i]);
  }
  solve(std::move(A));
  return 0;
}

// -- lib
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }

template <class T1, class T2>
bool chmin(T1 &l, const T2 &r)
{
  return (l > r) ? (l = r, true) : false;
}

template <class T1, class T2>
bool chmax(T1 &l, const T2 &r)
{
  return (l < r) ? (l = r, true) : false;
}


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

using namespace std;

#define ll long long
#define mod 1000000007

ll r[1010][1010];

main()
{
    ll i, j, k, n, h, w;

    char s[1010][1010];

    cin>>h>>w;

    for(i=0; i<h; i++) scanf("%s", s[i]);

    for(i=0; i<h; i++)
    {
        for(j=0; j<w; j++)
        {
            if(i==0 && j==0) r[i][j]=1;

            if(s[i][j]=='#') continue;

            if(i>0) r[i][j]+=(r[i-1][j])%mod;
            if(j>0) r[i][j]+=(r[i][j-1])%mod;

            r[i][j]=r[i][j]%mod;
        }

    }

    cout<<r[h-1][w-1]<<endl;
}


Measured memory_bytes: 9088
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define BIG 1000000010
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
typedef long long int ll;


int main(){
  int sx,sy,tx,ty;
  cin>>sx>>sy>>tx>>ty;
  bool up=true,left=true;
  if(sy>ty) up=false;
  if(sx<tx) left=false;
  rep(i,abs(sy-ty)){
    if(up) cout<<'U';
    else cout<<'D';
  }
  rep(i,abs(sx-tx)){
    if(left) cout<<'L';
    else cout<<'R';
  }
  rep(i,abs(sy-ty)){
    if(up) cout<<'D';
    else cout<<'U';
  }
  rep(i,abs(sx-tx)){
    if(left) cout<<'R';
    else cout<<'L';
  }
  
  if(left) cout<<'R';
  else cout<<'L';
  rep(i,abs(sy-ty)+1){
    if(up) cout<<'U';
    else cout<<'D';
  }
  rep(i,abs(sx-tx)+1){
    if(left) cout<<'L';
    else cout<<'R';
  }
  if(up) cout<<'D';
  else cout<<'U';
  if(left) cout<<'L';
  else cout<<'R';
  rep(i,abs(sy-ty)+1){
    if(up) cout<<'D';
    else cout<<'U';
  }
  rep(i,abs(sx-tx)+1){
    if(left) cout<<'R';
    else cout<<'L';
  }
 if(up) cout<<'U';
  else cout<<'R';
 cout<<endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.HashSet;
import java.util.Iterator;
import java.util.ArrayList;
class Main
{
	public static void main(String args[])
	{
		Scanner sc = new Scanner(System.in);
		while (true)
		{
			int n = sc.nextInt(),
				m = sc.nextInt();
			if (n == 0 && m == 0) break;
			ArrayList<HashSet<Integer>> friends = new ArrayList<HashSet<Integer>>(n);
			for (int i = 0; i < n; i++) friends.add(new HashSet<Integer>());
			for (int i = 0; i < m; i++)
			{
				int a = sc.nextInt() - 1,
					b = sc.nextInt() - 1;
				friends.get(a).add(b);
				friends.get(b).add(a);
			}
			HashSet<Integer> invite = new HashSet<Integer>();
			invite.add(0);
			Iterator<Integer> it0 = friends.get(0).iterator();
			while (it0.hasNext())
			{
				int a = it0.next();
				invite.add(a);
				Iterator<Integer> itx = friends.get(a).iterator();
				while (itx.hasNext())
				{
					invite.add(itx.next());
				}
			}
			System.out.println(invite.size() - 1);
		}
	}
}

Measured memory_bytes: 13000
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <functional>
#include <cmath>
#include <complex>
#include <cctype>
#include <cassert>
#include <sstream>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }

typedef long long ll;
typedef complex<double> P;
typedef complex<double> Vec;
typedef pair<int, int> pii;
typedef pair<int, pii> p;

#define INF (1<<29)
#define INFL (1ll<<60)
#define EPS (1e-8)
#define PI (acos(-1))
const ll MOD = 1000000007ll;

int main() {
	int n;
	cin >> n;
	int cnt = 0;
	REP(i, n) {
		int a;
		scanf("%d", &a);
		if (a % 2 == 1) cnt++;
	}
	
	puts(cnt % 2 == 0 ? "YES" : "NO");
	return 0;
}

Measured memory_bytes: 764
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
#include <cstring>
using namespace std;

using ll = long long;
using P = pair<int, int>;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

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

template<int mod>
struct ModInt{
    int x;

    ModInt() : x(0) {}
    
    ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
    
    ModInt &operator+=(const ModInt &p){
        if((x += p.x) >= mod)   x -= mod;
        return *this;
    }
    
    ModInt &operator-=(const ModInt &p){
        if((x += mod - p.x) >= mod) x -= mod;
        return *this;
    }

    ModInt &operator*=(const ModInt &p){
        x = (int)(1LL * x * p.x % mod);
        return *this;
    }

    ModInt &operator/=(const ModInt &p){
        *this *= p.inverse();
        return *this;
    }
    
    ModInt operator-() const {return ModInt(-x);}

    ModInt operator+(const ModInt &p) const {return ModInt(*this) += p;}

    ModInt operator-(const ModInt &p) const {return ModInt(*this) -= p;}

    ModInt operator*(const ModInt &p) const {return ModInt(*this) *= p;}

    ModInt operator/(const ModInt &p) const {return ModInt(*this) /= p;}

    bool operator==(const ModInt &p) const {return x == p.x;}

    bool operator!=(const ModInt &p) const {return x != p.x;}

    ModInt inverse() const{
        int a = x, b = mod, u = 1, v = 0, t;
        while(b > 0){
            t = a / b;
            swap(a -= t * b, b);
            swap(u -= t * v, v);
        }
        return ModInt(u);
    }

    ModInt pow(int64_t n) const{
        ModInt ret(1), mul(x);
        while(n > 0){
            if(n & 1)   ret *= mul;
            mul *= mul;
            n >>= 1;
        }
        return ret;
    }

    friend ostream &operator<<(ostream &os, const ModInt &p){
        return os << p.x;
    }

    friend istream &operator>>(istream &is, ModInt &a){
        int64_t t;
        is >> t;
        a = ModInt<mod>(t);
        return (is);
    }

    static int get_mod() {return mod;}
};

using modint = ModInt<mod>;

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

    int N;
    cin >> N;
    vector<modint> A(N), S(N + 1);
    for(int i = 0; i < N; ++i){
        cin >> A[i];
        S[i + 1] = S[i] + A[i];
    }
    modint ans = 0;
    for(int i = 0; i < N - 1; ++i){
        ans += A[i] * (S[N] - S[i + 1]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 4792
n,a,b,c,d=map(int,input().split(" "))
s=input()
pathA=s[a-1:c-1]
pathB=s[b-1:d-1]
isBlockCont = pathA.count("##") == 0 and pathB.count("##") == 0
if c < d :
    if isBlockCont:
        print("Yes")
    else:
        print("No")
else:
    if isBlockCont and s[b-2:d+1].count("...") > 0:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 3636
#include<stdio.h>
#include<string.h>
int main()
{
 char a[15],b[15];
 scanf("%s",a);
 scanf("%s",b);
 	b[strlen(b)-1]='\0';
 	if(strlen(b)==strlen(a)&&strcmp(a,b)==0)
 	printf("Yes");
 	else
 	printf("No");
 	
}

Measured memory_bytes: 1684
import math

N = int(input())
AB = [list(map(int, input().split())) for _ in range(N)]
ans = 0
for a, b in AB[::-1]:
  if (a+ans)%b == 0:
    continue
  if a+ans >= b:
    ans += math.ceil(abs(a+ans)/b)*b-a-ans
  else:
    ans += b-a-ans
print(ans)

Measured memory_bytes: 86564
import java.util.*;
 
public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		Map<String, Long>map =  new HashMap<>();
      
      long count = 0;
      for(int i = 0;i < n;i++){
        char[] s= sc.next().toCharArray();
        Arrays.sort(s);
        String key=new String(s);
      if(map.containsKey(key)) {
          count+=map.get(key);
          map.put(key, map.get(key)+1);
      }else{
          map.put(key, (long)1);
        }
      }
      System.out.print(count);
	}
}


Measured memory_bytes: 53884
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <functional> // std::function<void(int)>
using namespace std;
#define int long long
#define All(v) (v).begin(),(v).end()
int dy[4] = {-1,0,1,0};
int dx[4] = {0,1,0,-1};
int Dy[8] = {-1,-1,0,1,1,1,0,-1};
int Dx[8] = {0,1,1,1,0,-1,-1,-1};
const int mod = 1000000007;
const int inf = mod*mod;
const int d5 = 111111;
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int m,d;
    cin>>m>>d;
    int res=0;
    for(int i=1;i<=m;i++){
        for(int j=22;j<=d;j++){
            int l=j;
            int w=l%10;
            if(w<=1)continue;
            l/=10;
            w*=l;
            if(i==w){
                res++;
                //cout<<i<<' '<<j<<endl;
            }
        }
    }
    cout<<res<<endl;
}

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

#define int				long long
#define FOR( i, m, n )  for( int (i) = (m); (i) < (n); (i)++ )
#define REP( i, n )     FOR( i, 0, n )
#define REPR( i, m )	for( int (i) = (m); (i) >= 0; (i)-- )
#define REPONE( i, n )	FOR( i, 1, n + 1 )
#define ALL( a )        (a).begin(), (a).end()
#define MP				make_pair
#define X				first.first
#define Y				first.second

typedef pair<int, int> P;

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

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

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

char tile[21][21];
int W, H;
int ans;

void dfs( int x, int y ) {
	REP( i, 4 ) {
		int nx = x + dx[i];
		int ny = y + dy[i];

		if( nx >= 0 && nx < W && ny >= 0 && ny < H && tile[nx][ny] == '.' ) {
			tile[nx][ny] = '#';
			ans++;
			dfs( nx, ny );
		}
	}
}

signed main() {
	while( cin >> W >> H, W, H ) {
		
		int sx, sy;
		REP( i, H ) {
			REP( j, W ) {
				cin >> tile[j][i];
				if( tile[j][i] == '@' ) {
					sx = j;
					sy = i;
					tile[j][i] = '#';
				}
			}
		}

		
		ans = 1;
		dfs( sx, sy );
		cout << ans << endl;
		
	}
}


Measured memory_bytes: 3124
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <string>
#include <map>
#include <cstring>

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define Rep(i, sta, n) for (int i = sta; i < (n); ++i)
#define all(x) (x).begin(), (x).end()

using namespace std;
typedef long long ll;
const int mod = 1000000007;

vector<int> to[100100];
int color[100100];

bool dfs(int s, int c) {
    color[s] = c; 
    for(int t: to[s]) {
        if (color[t]==c) return false;
        if (color[t]==0 && !dfs(t,-c)) return false;
    }
    return true;
}

struct UnionFind {
    vector<int> par, rank;

    UnionFind(int n) : par(n, -1), rank(n, 0) {};
    void init(int n) { par.assign(n, -1), rank.assign(n, 0); }

    int root(int x) {
        if (par[x] == -1) return x;
        else return par[x] = root(par[x]);
    }

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

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y);
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        return true;
    }
    
};

int main() {
    int n, m;
    cin >> n >> m;
    int a, b;
    UnionFind uf(n);

    rep(i, m) {
        cin >> a >> b;
        --a, --b;
        to[a].push_back(b);
        to[b].push_back(a);
        uf.merge(a, b);
    }
    map<int, int> cnt;
    rep(i, n) cnt[uf.root(i)]++;

    set<int> done;
    ll total = 0;
    rep(i, n) {
        int r = uf.root(i);
        auto itr = done.find(r);
        if (itr!=done.end()) continue;
        done.insert(r);

        memset(color, 0, sizeof(color));
        bool isBG = true;
        rep(i, n) {
            if (color[i]==0 && uf.root(i)==r) {
                isBG = dfs(i,1);
                if (!isBG) {
                    total += (ll)cnt[r]*(cnt[r]-1)/2;
                    break;
                }
            }
        }
        if (!isBG) continue;

        int g1=0;
        int g2=0;
        rep(i, n) {
            if(color[i]==1 && uf.root(i)==r) g1++;
            else if (color[i]==-1 && uf.root(i)==r)g2++;
        }
        total += (ll)g1*g2;
    }
    cout << (total-(ll)m) << endl;
    return 0;
}



Measured memory_bytes: 7296
#include<iostream>
#include<iomanip>

using namespace std;
int main()
{
    long a,b;
    cin>>a>>b;
    double z;
    long x = a/b;
    long y = a%b;
    z = (double)a/(double)b;
    cout<<x<<" "<<y<<" "<<fixed << setprecision(8)<<z<<endl;
    return 0;
}

Measured memory_bytes: 3224
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<iostream>
#define db double
#define LL long long
#define inf 0x3f3f3f3f
#define N 105
using namespace std;
int gi()
{
    int res=0,s=1; char ch;
    for(ch=getchar();(ch<'0'||ch>'9')&&ch!='-';ch=getchar());
    if(ch=='-') s=-1,ch=getchar();
    for(;ch>='0'&&ch<='9';ch=getchar()) res=res*10+ch-48;
    return res*s;
}

int n,head[N],to[N<<1],ne[N<<1],num,que[N],h,t,dis[N],vis[N],d1,d2,ans,mid,pre[N];
int mx[N],dep[N];
LL res,tmp;

void adde(int u,int v) {
    to[++num]=v,ne[num]=head[u],head[u]=num;
    to[++num]=u,ne[num]=head[v],head[v]=num;
}
void dfs(int p,int f,int d) {
    int ch=0;
    for(int i=head[p];i;i=ne[i]) {
	if(to[i]==f) continue;
	ch++;
	dfs(to[i],p,d+1);
    }
    mx[d]=max(mx[d],ch);
}
int main()
{
    n=gi();
    for(int i=1;i<n;++i) adde(gi(),gi());
    que[h=t=1]=1,vis[1]=dis[1]=1;
    while(h<=t) {
	int p=que[h];
	for(int i=head[p];i;i=ne[i])
	    if(!vis[to[i]]) que[++t]=to[i],dis[to[i]]=dis[p]+1,vis[to[i]]=1;
	h++;
    }
    for(int i=1;i<=n;++i) if(dis[i]>dis[d1]) d1=i;
    memset(vis,0,sizeof(vis));
    que[h=t=1]=d1,vis[d1]=dis[d1]=1;
    while(h<=t) {
	int p=que[h];
	for(int i=head[p];i;i=ne[i])
	    if(!vis[to[i]]) que[++t]=to[i],dis[to[i]]=dis[p]+1,vis[to[i]]=1,pre[to[i]]=p;
	h++;
    }
    for(int i=1;i<=n;++i) if(dis[i]>dis[d2]) d2=i,ans=dis[i];
    printf("%d ",(ans+1)/2);
    if(ans&1) {
	mid=d2;
	for(int i=ans/2;i;--i) mid=pre[mid];
	for(int i=1;i<=n;++i) mx[i]=1;
	dfs(mid,0,1);
	res=1;
	for(int i=1;i<=n;++i) res=res*mx[i];

	for(int i=head[mid];i;i=ne[i]) {
	    for(int j=1;j<=n;++j) mx[j]=1;
	    dfs(to[i],mid,1),dfs(mid,to[i],1);
	    tmp=1;
	    for(int i=1;i<=n;++i) tmp=tmp*mx[i]; tmp*=2;
	    res=min(res,tmp);
	}
    }
    else {
	mid=d2;
	for(int i=ans/2-1;i;--i) mid=pre[mid];
	for(int i=1;i<=n;++i) mx[i]=1;
	dfs(mid,pre[mid],1);
	dfs(pre[mid],mid,1);
	res=1;
	for(int i=1;i<=n;++i) res=res*mx[i]; res*=2;
    }
    printf("%lld",res);
    return 0;
}


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

int c[110][110];
int n;
int a[11000];

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int h, w; cin >> h >> w;
	cin >> n;
	for(int i = 0; i < n; ++ i) cin >> a[i];
	int x = 0, y = 0, dir = 1;
	for(int i = 0; i < n; ++ i) {
		for(int j = 0; j < a[i]; ++ j) {
			c[x][y] = i + 1;
			if(y == w - 1 && dir == 1 || y == 0 && dir == -1) {
				dir *= -1;
				++ x;
			} else {
				y += dir;
			}
		}
	}
	for(int i = 0; i < h; ++ i) for(int j = 0; j < w; ++ j) cout << c[i][j] << " \n"[j == w - 1];
	return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
        Scanner s = new Scanner(System.in);
        int A = s.nextInt();
        int B = s.nextInt();

        int count = 0;
        for (int i = A; i <= B; i++){
            String start = String.valueOf(i);
            char[] a = start.toCharArray();
            String reverceA = "";
            for (int j = start.length(); j != 0; j--) {
                reverceA += a[j - 1];
            }

            if(start.equals(reverceA)){
                count ++;
            }
        }
        System.out.println(count);
    }
}


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

using namespace std;

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;
	}
};

struct miti{
	int index;
	int douro_root;
	int tetudo_root;
	int dt;
};
int q_sort(miti d[],int left,int right);

int main(void)
{
	int n,k,l; cin>>n>>k>>l;
	int p[k],q[k]; for(int i = 0; i < k; i++) cin>>p[i]>>q[i];
	int r[l],s[l]; for(int i = 0; i < l; i++) cin>>r[i]>>s[i];
	UnionFind d(n+1);
	UnionFind t(n+1);
	int ans[n+1]; for(int i = 0; i < n+1; i++) ans[i] = 1;
	miti w[n+1];
	for(int i = 0; i < k; i++){
		d.unite(p[i],q[i]);
	}
	for(int i = 0; i < l; i++){
		t.unite(r[i],s[i]);
	}
	for(int i = 0; i < n+1; i++){
		int dd = d.root(i);
		int tt = t.root(i);
		w[i].douro_root = dd;
		w[i].tetudo_root = tt;
		w[i].dt = dd+tt;
		w[i].index = i;
	}
	
	/*
	cout<<"\n"<<endl;
	for(int i = 0; i < n+1; i++){
		cout<<" i = "<< i <<", w[i].index = "<<w[i].index<< ", douro[i] = "<<w[i].douro_root<<", tetuod[i] = "<<w[i].tetudo_root<<endl;
	}
	*/
	
	q_sort(w,0,n);
	//cout<<"\n"<<endl;
	for(int i = 0; i < n; i++){
		int kk = w[i].dt;
		int j = i+1;
		while(j < n+1 && kk == w[j].dt){
			if(w[i].douro_root == w[j].douro_root && w[i].tetudo_root == w[j].tetudo_root){
				//cout<<"i = "<<i<<", j = "<<j<<endl;
				ans[w[i].index]++;
				ans[w[j].index]++;
			}
			j++;
		}
	}
	/*
	cout<<"\n"<<endl;
	for(int i = 0; i < n+1; i++){
		cout<<" i = "<< i << ", douro[i] = "<<w[i].douro_root<<", tetuod[i] = "<<w[i].tetudo_root<<endl;
	}
	cout<<"\n"<<endl;
	for(int i = 0; i < n+1; i++){
		cout<<"i = "<<i<<", ans[i] = "<<ans[i]<<endl;
	}
	*/
	for(int i = 1; i < n+1;i++){
		cout<<ans[i]<<" ";
	}
	cout<<endl;
	return 0;
}


int q_sort(miti d[],int left,int right){
	if(left >= right) return 0;
	int l = left, r = right;
	miti pipot = d[(left+right)/2],tmp;
	while(l<r){
		while(d[l].dt < pipot.dt) l++;
		while(d[r].dt > pipot.dt) r--;
		if( l <=  r){
			tmp = d[l];
			d[l] = d[r];
			d[r] = tmp;
			l++;
			r--;
		}
	}
	q_sort(d,left,r);
	q_sort(d,l,right);
}



Measured memory_bytes: 7680
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define PI 4*atan(1.0)
typedef long long ll;
typedef long double ld;
using namespace std;
int dx[4]={0,0,-1,1};
int dy[4]={-1,1,0,0};
const int SIZE=100050;
//int arr[SIZE]={};
//???????????§???????????¬
//???Binary Indexed Tree
struct BIT{
private:
	int n;
	vector<int> node;
public:
	//?????????v???BIT??§??¨?????????
	BIT(int N){
		node.resize(N+1,0);
		n=N;
	}
	int sum(int i){
		if(!i)
			return 0;
		return node[i]+sum(i-(i&-i));
	}
	void add(int i,int x){
		if(i>n)
			return;
		node[i]+=x;
		add(i+(i&-i),x);
	}
};
//???Binary Indexed Tree
int main(){
	int n,q;
	cin>>n>>q;
	BIT bit(n);
	for(int i=0;i<q;i++){
		int c,x,y;
		cin>>c>>x>>y;
		if(c){
			cout<<bit.sum(y)-bit.sum(x-1)<<endl;
		}
		else{
			bit.add(x,y);
		}
	}
	return 0;
}

Measured memory_bytes: 3064
#include<stdio.h>

int main(void){
    int N;
    scanf("%d", &N);
    int a, b;
    for(int i=1; i<10; i++){
        a=N/i;
        b=N%i;
        if(b==0&&a<10){
            printf("Yes");
            break;
        }else if(i==9&&b!=0){
            printf("No");
        }
    }
    return 0;
}

Measured memory_bytes: 128
import numpy as np
n,d=map(int,input().split())
nda=np.empty((0,d),int)
ans=0
for i in range(0,n):
  a=np.array([list(map(int,input().split()))])
  for j in range(i):
    chklen=np.linalg.norm(a-nda[j])
    if chklen==chklen//1:
      ans+=1
  nda=np.append(nda,a,axis=0)
print(ans)

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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

int ans=0;

int state[200]={0};
vector<int> G[200];

void dfs(int v)
{
    // visiting
    state[v]=2;

    rep(i,G[v].size())
    {
        int to=G[v][i];
        if(state[to]==0) dfs(to);
        else if(state[to]==2) ans=1;
    }

    // finish
    state[v]=1;
}

int main()
{
    int n;
    scanf(" %d", &n);
    rep(i,n)
    {
        int u,d;
        char s[10];
        scanf(" %d %s %d", &u, s, &d);
        --u;
        --d;
        d+=100;

        if(s[0]=='l') G[d].pb(u);
        else G[u].pb(d);
    }

    rep(i,200)
    {
        if(state[i]==0) dfs(i);
    }

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

Measured memory_bytes: 3296
N = int(input())
A = [input() for _ in range(N)]
pre = A[0]
for a in A[1:]:
  if A.count(pre) >= 2:
    print("No")
    exit()
  if pre[-1] == a[0]:
    pre = a
  else:
    print("No")
    exit()
print("Yes")    

Measured memory_bytes: 3060
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。
string upper(string str);       // 英字を大文字に変換する。
string lower(string str);       // 英字を小文字に変換する。

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define pb            push_back
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))
#define vi            vector<int>
#define GCD(a,b)      __gcd((a),(b))
#define LCM(a,b)      (a)/GCD((a),(b))*(b)

const int INF = 1e9;

// code
// ------------------------------------------------
int main() {

  int n;
  cin >> n;
  string s,t;
  cin >> s >> t;

  rep(i,sz(s))
  {
    cout << s[i] << t[i];
  }

  return 0;
}

// funcの実体
// ------------------------------------------------
int CalcSumOfDigit(int n)
{
  int s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

string upper(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(97 <= *itr && *itr <= 122)
    {
      *itr = *itr - 32;
    }
  }
  return str;
}

string lower(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(65 <= *itr && *itr <= 90)
    {
      *itr = *itr + 32;
    }
  }
  return str;
}


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

public class Program
{
	public static void Main()
	{
		long[] abx = Console.ReadLine().Split().Select(long.Parse).ToArray();
		long a = abx[0], b = abx[1], x = abx[2];
		Console.WriteLine(Func(b, x) - Func(a - 1, x));
	}
	
	public static long Func(long n, long x) => n >= 0 ? n / x + 1 : 0;
}

Measured memory_bytes: 2776
/*
 * atcoder/abc109_2nd/c.cpp
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template <class T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }

int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }

int N;
vector<ll> X, D;
void solve() {
  cin >> N;
  N++;
  ll x;
  loop(n,0,N) {
    cin >> x;
    X.push_back(x);
  }
  sort(X.begin(), X.end());
  loop(n,0,N-1) {
    D.push_back(X[n+1] - X[n]);
  }

  int gcd_ = 0;
  for (auto &&d: D) {
    gcd_ = gcd(gcd_, d);
  }
  cout << gcd_ << endl;
}
int main() {
  // cout.precision(15); cout << fixed;

  solve();

  return 0;
}


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

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

int main(){
	int n;
	cin>>n;
	string s;
	cin>>s;
	int c = 0;
	rep(i, n - 1){
		if(s[i] != s[i + 1]){
			c++;
		}
	}
	cout<<c + 1<<endl;
	return 0;
}

Measured memory_bytes: 512
using System;
class Program
 {
        static void Main(string[] args)
        {
    　　string a = Console.ReadLine(); //標準入力
    	
          int b= 0;
          switch(a){
            case "RRR":
              b=3;
              break;
            case "RRS":
            case "SRR":
              b=2;
              break;
            case "RSR":
            case "RSS":
            case "SRS":
            case "SSR":
              b=1;
              break;
            case "SSS":
              b=0;
           	  break;
          }
          
          Console.WriteLine("{0}", b);//改行付き出力
        }
 }

Measured memory_bytes: 25864
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <map>
#include <set>

using namespace std;

class UnionFind {
private:
public:
	// parents[i] >= 0 なら i の親
	// parents[i] < 0 で、根。abs(parents[i])がその木に属する頂点数
	vector<int> parents;
	int n_root;

	UnionFind();
	UnionFind(int n) {
		parents.assign(n, -1);
		n_root = n;
	}
	~UnionFind() {
		parents.clear();
	};

	int find(int x) {
		if (parents[x] < 0) {
			return x;
		} else {
			return parents[x] = find(parents[x]);
		}
	}

	void unite(int x, int y) {
		x = find(x);
		y = find(y);

		if (x == y) {
			return;
		}

		if (size(x) < size(y)) {
			swap(x, y);
		}

		parents[x] += parents[y];
		parents[y] = x;
		n_root--;
		return ;
	}

	bool same(int x, int y) {
		return find(x) == find(y);
	}

	// xが属する集団のサイズ
	int size(int x) {
		return -parents[find(x)];
	}

	// いくつの集団があるか
	int get_n_root() {
		return n_root;
	}
};

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

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

	UnionFind uf(n + 1);
	for (int i = 0; i < m; i++) {
		cin >> x >> y;
		uf.unite(x, y);
	}

	map<int, set<int>> group_map;
	vector<int> parents;
	for (int i = 1; i <= n; i++) {
		int parent = uf.find(i);
		if (group_map.count(parent) == 0) {
			parents.emplace_back(parent);
		}
		group_map[parent].insert(i);
		// cout << i << " -> " << parent << endl;
	}

	int ans = 0;
	for (auto parent: parents) {
		auto s_gr = group_map[parent];
		vector<int> v_gr(s_gr.begin(), s_gr.end());

		// cout << parent << ": ";
		// for (auto a: v_gr) {
		// 	cout << a << " ";
		// }
		// cout << endl;

		for (auto z: v_gr) {
			if (s_gr.count(p[z - 1]) > 0) {
				ans++;
			}
		}
	}

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


Measured memory_bytes: 15480