akhauriyash/Code-Regression huggingface dataset:
//write：Sakura
//id：
//problem：
//note：

#include <cstdio>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
using namespace std;

typedef long long ll;

double n,m,d;
double ans=0;

int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	scanf("%lf %lf %lf",&n,&m,&d);
	if(d==0){
		ans=(m-1)/n;
	}
	else{
		ans=2*(n-d)*(m-1)/(n*n);
	}
	printf("%.10lf\n",ans);
	return 0;
}


Measured memory_bytes: 256
n,k = map(int, input().split())
p = list(map(lambda x: (int(x)+1)/2, input().split()))

s = sum(p[:k])
ans = s
for i in range(k, n):
  s -= p[i-k]
  s += p[i]
  ans = max(ans, s)
print(ans)

Measured memory_bytes: 32008
def main():
    K, T = map(int, input().split())
    A = list(map(int, input().split()))
    A.append(0)
    A.sort(reverse=True)
    ans =max(0, max(A) - sum(A[1:]) - 1)
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 9180
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (ll)(n); i++)

int main() {
  ll n, p; cin >> n >> p;
  if (n==1) cout << p << endl;
  else {
    ll res = 1;
    for (ll i = 2; i*i <= p; i++) {
      if (p%i == 0) {
        ll tmp = 0;
        while (p%i == 0) {
          tmp++;
          p /= i;
        }
        if (tmp >= n) res *= (ll)pow(i, (tmp/n));
      }
    }
    cout << res << endl;
  }
}

Measured memory_bytes: 4064
#include <bits/stdc++.h>
using namespace std;  
typedef long long ll;
#define pb push_back
#define mod 1e9+7;
#define rep(i,n) for(int i=0; i<n; i++)
#define repa(i,start,end) for(int i=start; i<=end; i++)
#define repd(i,start,end) for(int i=start; i>=end; i--)
void solve()
{
   ll n,x,y,z;
   ll ans=0;
   cin>>n;
   ll a[n];
   rep(i,n)
   {
       cin>>a[i];
   }
   for(int i=0;i<=n-3;i++)
   {
       for(int j=i+1;j<=n-2;j++)
       {
           for(int k=j+1;k<=n-1;k++)
           {
              x=a[i];
              y=a[j];
              z=a[k];
              if(x==y || y==z || x==z)
              {
                  continue;
              }
              if(x+y>z && y+z>x && x+z>y)
              {
                  ans++;
              }
           }
       }
   }
   cout<<ans<<endl;
}

int main() {
	ios_base::sync_with_stdio(false);
	cout.tie(0); cin.tie(0);
	solve();
}  





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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]B - Strings with the Same Length
            int N = int.Parse(Console.ReadLine());
            var arr = Console.ReadLine().Split(' ');
            var S = arr[0];
            var T = arr[1];
            var ans = "";

            for(int i = 0; i < N; i++)
            {
                ans += S[i].ToString() + T[i].ToString();
            }

            Console.WriteLine(ans);
        }
    }
}

Measured memory_bytes: 11092
N,M = map(int, input().split())
if M==0:
    print("0 0")
    exit()

log = [input().split() for i in range(M)]

ac_lis =[0]*N
wa_lis =[0]*N

for i in log:
    p,s = int(i[0])-1,i[1]
    if s=="AC":
        ac_lis[p]=1
    elif s=="WA" and not ac_lis[p]:
        wa_lis[p] +=1
for i in range(N):
    if not ac_lis[i]:
        wa_lis[i] = 0
        
print(sum(ac_lis), sum(wa_lis))

Measured memory_bytes: 68696
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
using namespace std;
int main() {
int N, L;
cin >> N >> L;
vector<string> S(N);
for (int i = 0; i < N; ++i) cin >> S[i];
sort(S.begin(), S.end());
cout << accumulate(S.begin(), S.end(), string()) << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main () {
    long long int a,b,c;cin>>a>>b>>c;
    string s[a];
    long long int r[a]={0},k=0,p=0,count=0,m;
    for (long long int i=0;i<a;i++) cin>>s[i];
    for (long long int i=0;i<a;i++) {
        for (long long int j=0;j<b;j++) {
            if (s[i][j]=='#') {k++;}
        }
        if (k==0) r[i]=-1;
        if (k==1) r[i]=1;
        k=0;
    }
    //m=1;
    long long int d[a][b];
    for (long long int i=0;i<a;i++) {
        for (long long int j=0;j<b;j++) d[i][j]=0;
    }
    for (long long int i=0;i<a;i++) {
        //cout<<r[i]<<endl;
      if (r[i]==1) {
          p++;
          for (long long int j=0;j<b;j++) {
              d[i][j]=p;
          }
      }
      count=0;
      if (r[i]==0) {
          p++;
          for (long long int j=0;j<b;j++) {
              if (s[i][j]=='#') { count++;
                                 if (count>=2) p++;}
              d[i][j]=p;
          }
      }
      
    }
    //cout<<endl;
    for (long long int i=0;i<a;i++) {
        if (r[i]==-1) {
            for (long long int o=i+1;o<a;o++) {
                if (r[o]!=-1) {
                    r[i]=0;
                    for (long long int j=0;j<b;j++) d[i][j]=d[o][j];
                
                break;}
            }
        }
    }
   // for (long long int i=0;i<a;i++) cout<<r[i]<<endl;
    /* for (long long int i=0;i<a;i++) {
        for (long long int j=0;j<b;j++) cout<<d[i][j]<<" ";
        cout<<endl;
    }*/
    for (long long int i=a-1;i>=0;i--) {
        if (r[i]==-1) {
            for (long long int o=i-1;o>=0;o--) {
                if (r[o]!=-1) {
                    r[i]=0;
                    for (long long int j=0;j<b;j++) d[i][j]=d[o][j];
                
                break;}
            }
        }
    }
    for (long long int i=0;i<a;i++) {
        for (long long int j=0;j<b;j++) cout<<d[i][j]<<" ";
        cout<<endl;
    }
}


Measured memory_bytes: 1664
#include<bits/stdc++.h>
#define maxn 200010
#define ll long long
using namespace std;
char s[maxn];
int main()
{
	scanf("%s", s + 1);
	ll res = 0;
	int n = strlen(s + 1), cur = 1, s1 = 0;
	while (cur <= n)
	{
		if (s[cur] == 'A') {s1++; cur++;}
		else if (s[cur] == 'B' && s[cur + 1] == 'C') {res += s1; cur += 2;}
		else {s1 = 0; cur++;}
	}
	cout << res << endl;
}

Measured memory_bytes: 384
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;
use std::iter::FromIterator;

#[allow(unused_macros)]
macro_rules! vecs {
    ($init:expr; $($dim:expr);*) => {
        vecs!($($dim);* => $init)
    };
    ($head:expr; $($tail:expr);* => $init:expr) => {
        vec![vecs!($($tail);* => $init); $head]
    };
    ($head:expr => $init:expr) => {
        vec![$init; $head]
    };
}

fn main() {
    let cin = stdin();
    let mut scan = Scanner::new(cin.lock());
    let h = scan.read::<usize>();
    let w = scan.read::<usize>();
    let n = scan.read::<usize>();
    let a = scan.readn::<i64>(n);
    let mut c = vecs![0usize;h;w];
    let mut cnt = 0i64;
    let mut color = 0;
    for y in 0..h {
        for x in 0..w {
            let rx = if y%2 == 0 {x} else {w-1-x};
            c[y][rx] = color+1;
            cnt += 1;
            if a[color] == cnt {
                cnt = 0;
                color += 1;
            }
        }
    }
    for y in 0..h {
        println!("{}", join(&c[y], " "));
    }
}

// region template
#[allow(dead_code)]
fn iu(i: isize) -> usize { i as usize }

#[allow(dead_code)]
fn ui(i: usize) -> isize { i as isize }

#[allow(dead_code, deprecated)]
fn join<T: std::fmt::Display>(slice: &[T], sep: &str) -> String {
    let strings = slice.iter().map(|t| format!("{}", t)).collect::<Vec<_>>();
    strings.connect(sep)
}

#[allow(dead_code)]
fn arr<'a, S, T>(n: usize, mut f: S) -> Vec<T> where S: FnMut(usize) -> T + 'a {
    (0..n).map(|i| f(i)).collect::<Vec<T>>()
}

#[allow(dead_code)]
fn alt<S, T>(v: Vec<S>) -> T where T: FromIterator<S> {
    v.into_iter().collect::<T>()
}

#[allow(dead_code)]
fn dup<S, T>(v: &[S]) -> T where T: FromIterator<S>, S: Clone {
    v.iter().cloned().collect::<T>()
}

struct Scanner<'a> {
    cin: StdinLock<'a>,
}

#[allow(dead_code)]
impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }

    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }

    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }

    fn readn<T: FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read::<T>()).collect()
    }

    fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}
// endregion

Measured memory_bytes: 4352
#include <iostream>
#include <iomanip>
#include <vector>
typedef long long ll;
using namespace std;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
#define repi(i, n, init) for (ll i = init; i < (n); i++)

int main()
{
    int n;
    cin >> n;
    vector<int> h(n, 0);
    repi(i, n, 0) cin >> h[i];
    int ans = 0,prev = -1;
    bool ok = false;
    while(ans != prev){
        prev = ans;
        repi(i,n,0){
            if(h[i]){
                h[i]--;
                ok = true;
            }else if(ok){
                ans++;
                ok = false;
            }
        }
        if(ok){
            ok = false;
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define repn(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i, a) for(int i = 0; i < (a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define endl '\n'

const int maxn = 100005;

vi g[maxn];
int dp[maxn];
int in[maxn];

int dfs(int cur){
	if(!dp[cur]){
		for(int v : g[cur]){
			dp[cur] = max(dfs(v) + 1, dp[cur]);
		}
	}
	return dp[cur];
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int n, m;
	cin >> n >> m;
	rep(i, m){
		int a, b;
		cin >> a >> b;
		a--, b--;
		g[a].pb(b);
		in[b]++;
	}
	int ans = 0;
	rep(i, n) if(!in[i]){
		ans = max(ans, dfs(i));
	}
	cout << ans << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


Measured memory_bytes: 9600
#include<iostream>
#include<vector>
#include<climits>

using namespace std;

int main(){
    int n;

    cin >> n;
    int a[n], b[n], c[n];

    //set point values for each activity per day
    for(int i = 0;i<n;i++){
        cin >> a[i] >> b[i] >> c[i];
    }

    int dp[n][3]; //i represents the day and j represents the activity

    dp[0][0] = a[0];
    dp[0][1] = b[0];
    dp[0][2] = c[0];

    //dp[i][x] = current day's optimal value
    //max(1st previous day's activity not equal to current day's, 2nd previous day's activity not equal to current day's) + current day's activity's val
    for(int i = 1;i<n;i++){
        dp[i][0] = max(dp[i-1][1], dp[i-1][2]) + a[i];
        dp[i][1] = max(dp[i-1][0], dp[i-1][2]) + b[i];
        dp[i][2] = max(dp[i-1][0], dp[i-1][1]) + c[i];
    }

    cout << max(dp[n-1][0], max(dp[n-1][1], dp[n-1][2]));
}

Measured memory_bytes: 5984
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
typedef vector<int> vi;
typedef vector<ll> vl;

const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define IN cin >> 
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i = (m-1); i >= (int)(n); i--)
#define inrep(n,a) for(int i = 0; i < (int)(n); i++)cin >> a[i];
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.end(), v.begin());
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - a) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

///////////////////////////////////////////////////////////////////////////


int main(){

    int n,m,x;
    cin >> n >> m >> x;
    itn a[m];
    inrep(m,a);

    int p = lb(a,m,x) ;
    P(min(p, m - p  ));
    return  0;
}


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

int n,minx;string S;

int main(){
	cin>>S;n=S.size();S="0"+S+"0";
	
	minx=n;
	for(int i=0;i<S.size()-1;i++){
		if(S[i]!=S[i+1]){
			minx=min(minx,max(n-i,i));
		}
	}
	cout<<minx<<endl;
	return 0;
}


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

using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define FOR(k,m,n) for(ll (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define WAITING(str) int str;std::cin>>str;
#define DEBUGING(str) cout<< #str << " " str<<endl

constexpr int INF = (1 << 30);
constexpr ll INFL = (1ll << 60);
constexpr ll MOD = 1000000007;// 10^9+7

int n, u, v, m;
vector<vector<int>> usa, neko;
vector<int> card;

void paint(vector<vector<int>>& tile, int lim) {
	set<int> cand;
	REP(i, lim) cand.insert(card[i]);
	REP(i, n)REP(j, n) {
		int num = tile[i][j];
		if (cand.find(num) == cand.end()) {
			tile[i][j] = 0;
		}
	}
}

int judge(vector<vector<int>> tile, int lim) {
	paint(tile, lim);

	int res = 0;
	// ud
	REP(i, n) {
		REP(j, n)if (tile[i][j] == 0)goto end;
		res++;
	end:;
	}
	// lr
	REP(j, n) {
		REP(i, n)if (tile[i][j] == 0)goto end2;
		res++;
	end2:;
	}
	// slash
	REP(i, n) if (tile[i][i] == 0)goto end3;
	res++;
end3:;
	REP(i, n)if (tile[i][n - 1 - i] == 0)goto end4;
	res++;
end4:;
	return res;
}

void single() {
	int uidx = find(card.begin(), card.end(), usa[0][0]) - card.begin();
	int nidx = find(card.begin(), card.end(), neko[0][0]) - card.begin();

	if (u == 1 && v == 1) {
		if (uidx == nidx)cout << "DRAW" << endl;
		else cout << (uidx < nidx ? "USAGI" : "NEKO") << endl;
	}
	else if (u == 1) {
		cout << (uidx < m ? "USAGI" : "DRAW") << endl;
	}
	else if (v == 1) {
		cout << (uidx < m ? "NEKO" : "DRAW") << endl;
	}
	else {
		cout << "DRAW" << endl;
	}

}

int main()
{
	cin >> n >> u >> v >> m;
	usa.resize(n, vector<int>(n));
	neko.resize(n, vector<int>(n));
	card.resize(m);
	REP(i, n) REP(j, n)cin >> usa[i][j];
	REP(i, n) REP(j, n)cin >> neko[i][j];
	REP(i, m)cin >> card[i];
	if (n == 1) {
		single();
		return 0;
	}
	int l = 0, r = m;
	while (r - l > 1) {
		int mid = (l + r) / 2;
		bool res1 = judge(usa, mid) >= u;
		bool res2 = judge(neko, mid) >= v;
		if (res1 && res2)r = mid;
		else if (!res1 && !res2) l = mid;
		else {
			cout << (res1 ? "USAGI" : "NEKO") << endl;
			return 0;
		}
	}


	bool res1 = judge(usa, r) >= u;
	bool res2 = judge(neko, r) >= v;
	if (res1 == res2)cout << "DRAW" << endl;
	else cout << (res1 ? "USAGI" : "NEKO") << endl;
	return 0;
}



Measured memory_bytes: 6016
#include<iostream>
#include<string>
using namespace std;
#define MAX 100000
#define NIL -1

struct Node {
  int parent;
  int left;
  int right;
};

Node T[MAX];
int n, D[MAX];

void setDepth(int u, int p) {
  D[u] = p;
  if (T[u].right != NIL) {
    setDepth(T[u].right, p);
  }
  if (T[u].left != NIL) {
    setDepth(T[u].left, p+1);
  }
}

string attr(int u) {
  if (T[u].parent == NIL) {
    return "root, ";
  } else if (T[u].left == NIL) {
    return "leaf, ";
  } else {
    return "internal node, ";
  }
}

void print(int u) {
  cout << "node " << u << ": ";
  cout << "parent = " << T[u].parent << ", ";
  cout << "depth = " << D[u] << ", ";

  cout << attr(u);

  cout << "[";
  int c = T[u].left;
  int i = 0;
  while (c != NIL) {
    if (i>0) {
      cout << ", ";
    }
    cout  << c;
    c = T[c].right;
    i++;
  }
  cout << "]" << endl;
}

int main() {
  int n;
  cin >> n;
  for (int i=0; i<n; i++) {
    T[i].parent = T[i].left = T[i].right = NIL;
  }

  int id, k, tmp, c;
  for (int i=0; i<n; i++) {
    cin >> id >> k;
    tmp = id;
    for (int j=0; j<k; j++) {
      cin >> c;
      if (j==0) {
        T[id].left = c;
      } else {
        T[tmp].right = c;
      }
      tmp = c;
      T[tmp].parent = id;
    }
  }
  int root;
  for (int i=0; i<n; i++) {
    if (T[i].parent == NIL) {
      root = i;
    }
  }

  setDepth(root, 0);

  for (int i=0; i<n; i++) {
    print(i);
  }

  return 0;
}



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

#define input_i(x) scanf("%d", &x)
#define input_lli(x) scanf("%lld", &x)
#define input_s(x) scanf("%s", x)

#define BUFSIZE 4

int main(int argc, char const *argv[]) {
    char S[BUFSIZE], T[BUFSIZE];
    int i, ans= 0;
    input_s(S);
    input_s(T);
    for(i= 0; i < BUFSIZE - 1; i++) {
        if(S[i] == T[i]) ans++;
    }
    printf("%d\n", ans);

    return 0;
}


Measured memory_bytes: 128
import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T

main :: IO ()
main = do
  (n : _) <- map unsafeTextToInt . T.words <$> T.getLine :: IO [Int]
  mapM_ putStrLn . map (map toLEL) . f n $ 0

f :: Int -> Int -> [[Int]]
f 0 _ = [[]]
f l m = [0..m] >>= map <$> (:) <*> f (pred l) . max m . succ

toLEL :: Int -> Char
toLEL = toEnum . (fromEnum 'a' +)

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


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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define LL long long

class UnionFind{
private:
  std::vector<int> par;
  std::vector<int> rnk;
public:
  UnionFind(int n):par(n),rnk(n){
    for(int i=0;i<n;i++){
      par[i]=i;
      rnk[i]=0;
    }
  }
  
  int find(int x){
    if(par[x] == x)
      return x;
    else
      return find(par[x]);
  }

  void unite(int x,int y){
    x=find(x);
    y=find(y);
    if(x==y)
      return;
      
    if(rnk[x] < rnk[y])
      par[x] = y;
    else{
      par[y] = x;
      if(rnk[x]==rnk[y]) rnk[x]++;
    }
  }

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

int n,k,l;

int main(){
  cin>>n>>k>>l;
  int a,b;
  UnionFind road(n);
  UnionFind train(n);
  unordered_map<string,int> mp;
  
  REP(i,k){
    cin>>a>>b;
    road.unite(a-1,b-1);
  }
  REP(i,l){
    cin>>a>>b;
    train.unite(a-1,b-1);
  }
  REP(i,n)
    mp[to_string(road.find(i))+" "+to_string(train.find(i))]++;
  
  REP(i,n)
    cout<<mp[to_string(road.find(i))+" "+to_string(train.find(i))]<<((i==n-1)?"":" ");
  cout<<endl;
  return 0;
}


Measured memory_bytes: 25672
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <vector>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<P,int> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

ll gcd(ll a,ll b){
	if(!b) return a;
	return gcd(b,a%b);
}

const int M=1000000;
int n;
bool a[M];

int main(){
	scanf("%d",&n);
	int g=0;
	bool B=1;
	for(int i=0;i<n;i++){
		int x;
		scanf("%d",&x);
		g=gcd(g,x);
		for(int j=2;j*j<=x;j++) if(x%j==0){
			while(x%j==0) x/=j;
			if(a[j]) B=0;
			a[j]=1;
		}
		if(x>1){
			if(a[x]) B=0;
			a[x]=1;
		}
	}
	if(B) cout<<"pairwise coprime"<<endl;
	else if(g==1) cout<<"setwise coprime"<<endl;
	else cout<<"not coprime"<<endl;
}

Measured memory_bytes: 4708
#define _DEBUG
#include "bits/stdc++.h"
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,a4,x,...) x
#define debug_1(x1) cout<<#x1<<": "<<x1<<endl
#define debug_2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl
#define debug_3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl
#define debug_4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<endl
#define debug_5(x1,x2,x3,x4,x5) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<endl
#ifdef _DEBUG
#define debug(...) CHOOSE((__VA_ARGS__,debug_5,debug_4,debug_3,debug_2,debug_1,~))(__VA_ARGS__)
#else
#define debug(...)
#endif
#define rep(index,num) for(int index=0;index<(int)num;index++)
#define rep1(index,num) for(int index=1;index<=(int)num;index++)
#define brep(index,num) for(int index=(int)num-1;index>=0;index--)
#define brep1(index,num) for(int index=(int)num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=(ll)1e+18+1;
int INF=1e+9+1;
int main(){
	ll A;
	long double B;
	scan(A>>B);
	ll ans=(ll)(A*B+eps);
	prin(ans);
	return 0;
}


Measured memory_bytes: 3748
#include<bits/stdc++.h>
#define enld '\n'
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[6] = {1, 0, -1, 0,1,1};
const int dy[6] = {0, 1, 0, -1,1,-1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ---------------------------------------------------------------------------


int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N;
    cin >> N;
    while(N != 0){
        int x0,y0;
        cin >> x0 >> y0;
        vector<P> hosi(N-1);
        for(int i=0; i<N-1; i++){
            int a,b;
            cin >> a >> b;
            a -= x0;
            b -= y0;
            hosi[i] = P(a,b);
        }
        int M;
        cin >> M;
        set<P> suzu;
        for(int i=0; i<M; i++){
            int a,b;
            cin >> a >> b;
            suzu.emplace(a,b);
        }
        int ans_x,ans_y;
        for(auto ken: suzu){
            int x = ken.first;
            int y = ken.second;
            bool can = true;
            for(int i=0; i<N-1; i++){
                if(!suzu.count(P(x+hosi[i].first,y+hosi[i].second))) can = false;
            }
            if(can){
                ans_x = x;
                ans_y = y;
            }
        }
        cout << ans_x-x0 << " " << ans_y-y0 << enld;
        cin >> N;
    }
    return 0;
}



Measured memory_bytes: 3080
#######################################
import numpy as np
#######################################
n = int(input())
a = np.array(list(map(int, input().split())))
ret = [0]*(n+1)
ret2 = []

for i in reversed(list(range(n))): 
  if sum(ret[::i+1][1:])%2 != a[i]:
    ret[i+1] = 1
    ret2.append(i+1)

print(sum(ret[1:]))
print(" ".join(list(map(str, ret2[::-1]))))

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

  vector<int> a;
  a.resize(n);
  ll sum = 0;
  for(int i = 0; i < n; i++){
    cin >> a[i];
    sum+=a[i];
  }

  if(sum >= h){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }


}

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

using namespace std;

typedef long long int lli;

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

    int n, b0 = 1e+9, b1, ans = 0;

    cin >> n;
    for (int i=0; i<n-1; i++) {
        cin >> b1;
        ans += min(b0, b1);
        b0 = b1;
    }
    ans += b1;

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long n;
  cin >> n;
  
  vector<long long> v(n);
  for (long long i = 0; i < n; i++) {
    cin >> v.at(i);
    if (v.at(i) == 0) {
      cout << 0 << endl;
      return 0;
    }
    if (v.at(i) >= 1000000000000000000) {
      cout << -1 << endl;
      return 0;
    }
  } 
  long long ans = 1;
  for (long long i = 0; i < n; i++) {
    if (ans > 1000000000000000000 / v.at(i)) {
      cout << -1 << endl;
      return 0;
    }
    ans *= v.at(i);
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 4048
n = int(input())
a = list(map(int, input().split()))
import sys
ans = 1
if 0 in a:
    print(0)
    sys.exit()
for i in a:
    if ans <= 1000000000000000000:
        ans = ans * i
      
    else:
        print(-1)
        sys.exit()
if ans <= 1000000000000000000:
    print(ans)
else:
    print(-1)

Measured memory_bytes: 21596
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i = 0;i<((ll)(n));i++)
#define reg(i,a,b) for(ll i = ((ll)(a));i<=((ll)(b));i++)
#define irep(i,n) for(ll i = ((ll)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(ll i = ((ll)(b));i>=((ll)(a));i--)
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

/*
*/

ll n;

int main(void){
	cin>>n;
	cout<<(n-1)/2<<endl;
	return 0;
}

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

using namespace std;

void swap(int &a, int &b)
{
    int temp = a;
    a = b;
    b = temp;
}

int main()
{
    int n;
    cin >> n;
    bool flag = false;
    vector<int> array1(n), dummy(n);
    for (int i = 0; i < n; i++)
    {
        cin >> array1[i];
    }

    vector<int> array2 = array1;

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

    if (array1 == array2)
    {
        flag = true;
    }
    else
    {
        for (int i = 0; i < n; i++)
        {
            for (int j = i + 1; j < n; j++)
            {
                dummy = array2;
                swap(dummy[i], dummy[j]);
                if (dummy == array1)
                    flag = true;
            }
            if (flag)
                break;
        }
    }

    if (flag)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<cmath>
#include<vector>
#include<algorithm>
using namespace std;

long long cnt;
int R[1000000];
vector<int> G;
int n;

void insertionSort(int R[], int n, int g){
	int key, j;
	for (int i = g; i < n; i++){
		key = R[i];
		j = i - g;
		while (j >= 0 && R[j] > key){
			R[j + g] = R[j];
			j -= g;
			cnt++;
		}
		R[j + g] = key;
	}
}

void shellSort(int R[], int n){
	for (int h = 1;;){
		if (h > n)
			break;
		G.push_back(h);
		h = 3 * h + 1;
	}
	for (int i = G.size() - 1; i >= 0; i--){
		insertionSort(R, n, G[i]);
	}
}

int main(){
	cin >> n;
	int j;
	for (int i = 0; i < n; i++){
		scanf("%d", &R[i]);
	}
	int key;
	cnt = 0;
        shellSort(R,n);
	cout << G.size() << endl;
	for (int i = G.size()-1; i >= 0; i--){
		printf("%d", G[i]);
		if (i != 0)
			printf(" ");
	}
	printf("\n");
	printf("%d\n", cnt);
	for (int i = 0; i < n; i++){
		printf("%d\n", R[i]);
	}
}

Measured memory_bytes: 7104
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")

K = k()
m = 0

for i in range(1, K+1):
  if i == 1:
    m = 7
  else:
    m = (m*10 + 7) % K
  if m % K == 0:
    print(i)
    exit()

print('-1')


Measured memory_bytes: 10416
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
ll mod = 1e9+7;


int main(){
    ll n; cin >> n;
    if(n%2==1) {cout << 0 << endl; return 0;}
    else{
    ll five=0;
    
    for(ll i=5; i<n; i*=5){
        five+=(n/i)/2;
    }
  
    cout << five << endl;
    }
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
const int INF = 1000000009;
const ll LINF = 1e18;

int main() {
  char alpha;
  cin >> alpha;
  if (alpha >= 'A' && alpha <= 'Z') {
    cout << "A\n";
  } else {
    cout << "a\n";
  }
}


Measured memory_bytes: 3052
#include <stdio.h>
#define SIZE 50
int field[SIZE][SIZE];
int v1[] = {-1,-1,-1,0,0,1,1,1};
int v2[] = {-1,0,1,-1,1,-1,0,1};
void dfs(int y,int x){
  int i,ny,nx;
  field[y][x]=0;
  for(i=0;i<8;i++){
    ny=y+v1[i];
    nx=x+v2[i];
    if(ny<0 || ny >= SIZE || nx < 0 || nx >= SIZE)continue;
    if(field[ny][nx]==1){
      dfs(ny,nx);
    }
  }
}

int main(void){
  int w,h,i,j,ans;
  while(1){
    scanf("%d %d", &w, &h);
    if(w==0 && h==0)break;
    ans=0;
    for(i=0;i<h;i++){
      for(j=0;j<w;j++){
	scanf("%d\n", &field[i][j]);
      }
    }
    for(i=0;i<h;i++){
      for(j=0;j<w;j++){
	//	printf("aaa%d\n", field[i][j]);
	if(field[i][j]==1){
	  dfs(i,j);
	  ans++;
	}
      }
    }
    printf("%d\n", ans);
  }
}

Measured memory_bytes: 684
n = int(input())
nums = list(map(int, input().split()))
chk = True
for i in nums:
    if i%2==0:
        if i%3==0 or i%5==0:
            pass
        else:
            chk = False
    else:
        pass
if chk == True:
    print('APPROVED')
else:
    print('DENIED')

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

#define ll long long int
#define f(i,x,n)  for(int i=x;i<n;i++)
#define FASTIO cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false);
#define sz(a) int((a).size())
#define mod 1000000007
#define inf LLONG_MAX
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
template <typename T>
inline T gcd(T a, T b) { while (b != 0) swap(b, a %= b); return a; }

template <typename T>
inline void seethis(vector<T>vect)
{
    for(T x:vect)
        cout<<x<<" ";
    cout<<"\n";
}

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}
//LCM
int lcm(int a, int b) {  return a * (b / gcd(a, b)); }

//For sort by second
bool cmp(const pair<int,int> &a)
{ return a.first<a.second; }

//Tree
/* const int MAXN = 1e5 + 5;
vector<ll> adj[MAXN];*/

//ModPower
ll modpower(ll a,ll b,ll c)
{
	ll res=1;
	while(b)
	{
		if(b&1LL)
			res=(res*a)%c;
		a=(a*a)%c;
		b>>=1;
	}
	return res;
}

int main()
{
	FASTIO;
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
	ll n;
	cin>>n;

	string s;
	 cin>>s;

	 int len=s.length();
	 string t="";

	 for(int i=0;i<len/2;i++)
	 {
	 	t.push_back(s[i]);
	 }
	 error(t);
	 bool flag=true;

	 for(int i=len/2;i<len;i++)
	 {
	 	if(s[i]!=t[i-len/2])
	 	{
	 		flag=false;
	 		break;
	 	}
	 }

	 if(flag)
	 	cout<<"Yes\n";
	 else
	 	cout<<"No\n";
	
	return 0;
}

Measured memory_bytes: 3612
a = int(input())
b = 1
while a !=4 and a !=2 and a != 1:
    if a%2 == 0 :
        a=a//2
        b+=1 
    elif a%2!=0 :
        a=a*3+1
        b+=1 
else :
  print(b+3)



Measured memory_bytes: 2940
#include <stdio.h>

int main()
{
  char s[200001];
  int i = 0;
  scanf("%s",&s);
  long long sum = 0;
  while (s[i])
  {
    sum += s[i] - '0';
    i++;
  }
  if (sum % 9 == 0)
    printf("Yes");
  else
    printf("No");
}

Measured memory_bytes: 1924
import java.util.HashSet;
import java.util.Scanner;

public class Main {

	public static String Y = "Yes";
	public static String N = "No";
	public static String I = "IMPOSSIBLE";
	public static String B = "Bad";
	public static String G = "Good";
	public static long MOD = (long) (Math.pow(10, 9) + 7);
	public static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {

		int n = ni();
		int k = ni();
		HashSet<Integer> hs = new HashSet<>();

		int a;

		for (int i = 0; i < k; i++) {
			a = ni();
			for (int j = 0; j < a; j++) {
				hs.add(ni());
			}
		}

		out(n - hs.size());
	}

	public static int count(String search, String text) {
		int nsearch = search.length();
		int ntext = text.length();
		int count = 0;

		for (int i = 0; i <= ntext - nsearch + 1; i++) {
			for (int j = i + nsearch - 1; j < ntext; j++) {
				if (search.equals(text.substring(i, j + 1))) {
					count++;
				}
			}
		}

		return count;
	}

	/*
	 * 以下メソッド集
	 */
	static int ni() {
		return sc.nextInt();
	}

	static long nl() {
		return sc.nextLong();
	}

	static String n() {
		return sc.next();
	}

	static char[] nc() {
		return sc.next().toCharArray();
	}

	static int kaijo(int n) {
		if (n == 0 || n == 1) {
			return 1;
		} else {
			return n * kaijo(n - 1);
		}
	}

	static int fib(int n) {
		return (n == 1 || n == 0) ? n : fib(n - 2) + fib(n - 1);
	}

	static long lcm(long m, long n) {

		return m * n / gcd(m, n);
	}

	static int lcm(int m, int n) {

		return m * n / gcd(m, n);
	}

	static long gcd(long a, long b) {
		return (b == 0) ? a : gcd(b, a % b);
	}

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

	static void out(String info) {
		System.out.println(info);
	}

	static void out(int info) {
		System.out.println(info);
	}

	static void out(double info) {
		System.out.println(info);
	}

	static void out(long info) {
		System.out.println(info);
	}

	static void out(char info) {
		System.out.println(info);
	}

	static void outn(String info) {
		System.out.print(info);
	}

	static void outn(int info) {
		System.out.print(info);
	}

	static void outn(double info) {
		System.out.print(info);
	}

	static void outn(long info) {
		System.out.print(info);
	}

	static void outn(char info) {
		System.out.print(info);
	}

	static int max(int a, int b) {
		return Math.max(a, b);
	}

	static long max(long a, long b) {
		return Math.max(a, b);
	}

	static int min(int a, int b) {
		return Math.min(a, b);
	}

	static long min(long a, long b) {
		return Math.min(a, b);
	}
}


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

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

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

    // reverse(A.begin(), A.end());

    int ans = 0, bef = 0, cnt = 0;
    for(int i = 0; i < n; i++){
        if(i == 0){
            bef = A[i];
            continue;
        }else{
            if(bef >= A[i]){
                cnt++;
                ans = max(ans, cnt);
            }else{
                cnt = 0;
            }
        }
        bef = A[i];
    }

    cout << ans << endl;

    return 0;
}

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

int comp(const void* a, const void* b){
	return *(int*)a - *(int*)b;
}

int main() {
	int a, b;
	char op;
	cin >> a >> op >> b;
	if(op == '+'){
		cout << a+b << endl;
	}else{
		cout << a-b << endl;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
vector<ll> adj[100001];
void dfs(ll cur,ll par,vector<bool> &vis)
{
	vis[cur]=true;
	for(ll i=0;i<adj[cur].size();i++)
	{
		if(adj[cur][i]!=par&&vis[adj[cur][i]]==false)
		{
			dfs(adj[cur][i],cur,vis);
		}
	}
}

int main() {
	cin.tie(NULL);
	cout.tie(NULL);
	ll n,m;
	cin>>n>>m;
	
	for(ll i=0;i<m;i++)
	{
		ll a,b;
		cin>>a>>b;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
	ll cnt=0,ans=0;
	vector<bool> vis(n+1,false);
	for(ll i=1;i<=n;i++)
	{
		if(vis[i]==false)
		{
			ans++;
			dfs(i,0,vis);
		}
	}
	cout<<ans-1<<endl;
	return 0;
}


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

int main() {

    int n;
    long long a[50];

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


    long long cnt = 0;
    bool update = true;
    while(update) {
        update = false;
        for(int i = 0; i < n; i++) {
            if(a[i] >= n) {
                cnt += a[i] / n;
                for(int j = 0; j < n; j++) if(i != j) a[j] += a[i] / n;
                a[i] %= n;
                update = true;
            }
        }
    }
    cout << cnt << endl;
}


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

int N, A[400009], nx[200009], c[200009], P[200009];
long long K, L, fi[200009], a, b;

void putans(int x) {
	vector<int> S;
	vector<bool> chk(200009, 0);
	for(int i=x; i<N; i++) {
		if(chk[A[i]]) {
			while(chk[A[i]]) {
				chk[S.back()] = 0;
				S.pop_back();
			}
		}
		else {
			chk[A[i]] = 1;
			S.push_back(A[i]);
		}
	}
	for(auto& it: S) printf("%d ", it);
	exit(0);
}

void go(int i, long long d) {
	if(fi[i] != -1) {
		a = fi[i];
		b = d - fi[i];
		return;
	}
	fi[i] = d;
	go(nx[i], d + c[i]);
}

void Do(int i, long long d) {
	if(d + c[i] <= L) Do(nx[i], d + c[i]);
	else putans(i);
}

int main() {
	scanf("%d%lld",&N,&K);
	L = K*N;
	for(int i=0; i<N; i++) {
		scanf("%d",&A[i]);
		A[i+N] = A[i];
		fi[i] = -1;
	}
	for(int i=2*N-1; i>=0; i--) {
		if(i < N) nx[i] = (P[A[i]] + 1) % N, c[i] = P[A[i]] - i + 1;
		P[A[i]] = i;
	}
	go(0, 0);
	if(L <= a) Do(0, 0);
	else {
		L -= a;
		L %= b;
		if(L == 0) return 0;
		Do(0, 0);
	}
	return 0;
}

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

int dp[100001];
bool visited[100001];
vector<int> graph[100001];
int ans;
void dfs(int node){
    visited[node] = true;
    if(graph[node].empty()){ dp[node] = 0; return;}
    int maxa =0;
    for(auto i : graph[node]){
        if(!visited[i]){
            dfs(i);
        }
        maxa = max(maxa, dp[i]);
    }
    dp[node] = 1 + maxa;
}
int n, m;
int main(){
    cin>>n>>m;
    while(m--){
        int u, v;
        cin>>u>>v;
        graph[u].push_back(v);
    }
    int ans = 0;
    for(int x=1;x<=n;x++){
        dfs(x);
        ans = max(ans, dp[x]);
    }
    cout<<ans;

}


Measured memory_bytes: 12264
#include<bits/stdc++.h>
using namespace std;
const int maxN=403;
const int INF=1e9+12;
int n,ma,mb;
int a[maxN],b[maxN],c[maxN];
int dp[maxN][maxN][maxN];
int main(){
  cin>>n>>ma>>mb;
  for(int i=1;i<=n;i++){
    cin>>a[i]>>b[i]>>c[i];
  }
  for(int i=0;i<=n;i++)
    for(int j=0;j<=400;j++)
      for(int k=0;k<=400;k++)
	dp[i][j][k]=INF;
  dp[0][0][0]=0;
  for(int i=1;i<=n;i++){
    for(int j=0;j<=400;j++){
      for(int k=0;k<=400;k++){
	dp[i][j][k]=dp[i-1][j][k];
	if(j>=a[i]&&k>=b[i])
	  dp[i][j][k]=min(dp[i][j][k],dp[i-1][j-a[i]][k-b[i]]+c[i]);
      }
    }
  }
  int mn=INF;
  for(int j=0;j<=400;j++)for(int i=0;i<=400;i++){
      //cout<<i<<' '<<j<<' '<<dp[n][i][j]<<endl;
      int aa=i/ma,bb=j/mb;
      if(aa==bb&&aa>=1&&i%ma==0&&j%mb==0&&dp[n][i][j]!=INF){
	//cout<<i<<' '<<j<<' '<<aa<<' '<<bb<<' '<<dp[n][i][j]<<endl;
	mn=min(mn,dp[n][i][j]);
      }
    }
  if(mn==INF)cout<<-1<<endl;
  else
    cout<<mn<<endl;
}


Measured memory_bytes: 26240
import java.io.*;
import java.util.*;
import java.lang.*;

public class Main {
    static class FastReader
        {
            BufferedReader br;
            StringTokenizer st;

            public FastReader()
            {
                br = new BufferedReader(new
                        InputStreamReader(System.in));
            }

            String next()
            {
                while (st == null || !st.hasMoreElements())
                {
                    try
                    {
                        st = new StringTokenizer(br.readLine());
                    }
                    catch (IOException e)
                    {
                        e.printStackTrace();
                    }
                }
                return st.nextToken();
            }

            int nextInt()
            {
                return Integer.parseInt(next());
            }

            long nextLong()
            {
                return Long.parseLong(next());
            }

            double nextDouble()
            {
                return Double.parseDouble(next());
            }

            String nextLine()
            {
                String str = "";
                try
                {
                    str = br.readLine();
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
                return str;
            }
        }
    public static void main(String[] args) {
        FastReader ob = new FastReader();
        int t = ob.nextInt();
        while(t>0){
            if(t%10==7){
                System.out.println("Yes");
                return;
            }
            t=t/10;
            
        }
        System.out.println("No");
    }
}

Measured memory_bytes: 32572
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val inputs = readLine()!!.split(" ").map { it.toInt() }

    var ans = Int.MAX_VALUE

    for ( i in 1 until n){

        val left = inputs.subList(0, i)
        val right = inputs.subList(i, n)
        ans = Math.min(ans, Math.abs(left.sum() - right.sum()))
    }


    println(ans)

}

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

int main(){
	int a, b, c;
	cin >> a >> b >> c;
	if(2 * b == a + c) cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}

Measured memory_bytes: 256
import sys

def main():
    n, *a = map(int, sys.stdin.read().split())

    l = 0
    r = sum(a)
    m = sum(a)
    for i in range(n):
        l += a[i]
        r -= a[i]
        m = min(m, abs(l - r))
    
    print(m)


if __name__ == '__main__':
    main()

Measured memory_bytes: 25124
-module('Main').
-export([main/1]).

ccase(X, DIDI, Ans) ->
	case X of
      X when X =:= DIDI -> 1;
      X -> 0
  	end.

loop(Le, Ri, Di, Now, Ans) ->
    
	DIDI = Now rem Di,
    case Now of
        Now when Now >= Ri -> io:format("~B~n", [Ans + ccase(0, DIDI, Ans)]);
        Now when Now < Ri -> loop(Le, Ri, Di, Now + 1, Ans + ccase(0, DIDI, Ans))
	end.


solve() ->
	[L, R, D] = input("~d~d~d"),
    A = 42,
    loop(L, R, D, L, 0),
    ok.

main(_) ->
    solve(),
    halt().

input(Pat) ->
    {ok, L} = io:fread("", Pat),
    L.




Measured memory_bytes: 21712
#include<bits/stdc++.h>//万能头文件
using namespace std;
int a,b,ans;
int main(){//主函数
    cin>>a>>b;//输入
    if((a+b)%2==0)
    ans=(a+b)/2;
    else 
    ans=(a+b)/2+1;//向上取整
    cout<<ans<<endl;//输出
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define REP(i, n) for(int i = 1; i < (int)(n); ++i)
using namespace std;

int main() {
    int N, Y;
    cin >> N >> Y;
    
    rep(i, N + 1) rep(j, N + 1) {
        int k = N - i - j;
        if (k < 0) continue;
        if (1000 * i + 5000 * j + 10000 * k == Y) {
            printf("%d %d %d\n", k, j, i);
            return 0;
        }
    }
    printf("%d %d %d\n", -1, -1, -1);
    return 0;
}


Measured memory_bytes: 256
#include<iostream> 
#include<iomanip> 
#include<vector> 
#include<map> 
#include<set> 
#include<algorithm> 
#include<numeric> 
#include<limits> 
#include<bitset> 
#include<functional> 
#include<type_traits> 
#include<queue> 
#include<stack> 
#include<array> 
#include<random> 
#include<utility> 
#include<cstdlib> 
#include<ctime>
#define INT_MAX 2147483647
#define _LIBCPP_DEBUG 0
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (n); ++i)	
using namespace std;


int max(int a,int b) {
	int max;
	if (a > b) max = a;
	else max = b;
	return max;
}
int min(int a, int b) {
	int min;
	if (a < b) min = a;
	else min = b;
	return min;
}


int main() {
	string s, t;
	cin >> s >> t;
	bool f = false;

	rep(i, s.size()) {
		if (s[i] == t[i]) {
			continue;
		}
		f = true;
	}

	if ((s.size() == (t.size() - 1)) && !f) {
		cout << "Yes" << endl;
	}
	else
		cout << "No" << endl;

}

Measured memory_bytes: 3056
#include <iostream>
#include <string>
using namespace std;
int main(){
  string s,t;
  cin >> s>>t;
  int ss,tt;
  cin >>ss>>tt;
  string u;
  cin >>u;
  if (u==s) ss=ss-1;
  if (u==t) tt=tt-1;
  cout << ss << " "<<tt;}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
int n,A[50];
struct P{
	double x;
	double y;
}; 
void print(struct P p){
	printf("%.8f %.8f\n",p.x,p.y);
}
void koch(int n,struct P p1,struct P p2){
	if(n==0)
		return;
	double th = M_PI * 60.0 / 180.0;
	struct P s,u,t;
	s.x=(2.0*p1.x+1.0*p2.x)/3.0;
	s.y=(2.0*p1.y+1.0*p2.y)/3.0;
	t.x=(1.0*p1.x+2.0*p2.x)/3.0;
	t.y=(1.0*p1.y+2.0*p2.y)/3.0;	
	u.x=(t.x-s.x)*cos(th)-(t.y-s.y)*sin(th)+s.x;
	u.y=(t.x-s.x)*sin(th)+(t.y-s.y)*cos(th)+s.y;
	
	koch(n-1,p1,s);
	print(s);
	koch(n-1,s,u);
	print(u);
	koch(n-1,u,t);
	print(t);
	koch(n-1,t,p2);
}

int main() {
	struct P a,b;
	int n;
	
	scanf("%d",&n);
	
	a.x=0;a.y=0;
	b.x=100;b.y=0;
	
	print(a);
	koch(n,a,b);
	print(b);
	
	return 0;
}

Measured memory_bytes: 2680
import java.util.*;
public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int m = sc.nextInt();
		int c = sc.nextInt();
		int[] b = new int[m];
		int count = 0;

		for (int i = 0;i<m ;i++ ) {
			b[i] = sc.nextInt();
		}

		for (int i = 0;i<n ;i++ ) {
			int sum =0;
			for (int j = 0;j<m ;j++ ) {
				int	a = sc.nextInt();
				sum += b[j]*a;
			}

			if (sum+c>0) {
				count++;
			}
		}

		System.out.println(count);
	}
}


Measured memory_bytes: 23892