akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define int long long

int32_t main(){
    int n,k;cin>>n>>k;vector<int>v(n);
    for(int i=0;i<n;i++) cin>>v[i],v[i]--;


    if(k<=n){
        int curr=0;
        if(k==0){
        cout<<curr+1<<"\n";
        exit(0);
        }
        int ans=v[curr];
        for(int i=0;i<k-1;i++){
            ans=v[ans];
        }
        cout<<ans+1<<"\n";
        exit(0);
    }

    if(v[0]==0){
        cout<<1<<"\n";
        exit(0);
    }

   map<int,int> mp;
   int curr=v[0];
   int len_of_cycle=0;mp[0]=0;
    while(mp.count(curr)==0){
        mp[curr]=++len_of_cycle;
        curr=v[curr];
    }
    k-=mp[curr];
    len_of_cycle=len_of_cycle+1-mp[curr];
    k%=len_of_cycle;
    // cout<<curr+1<<" "<<mp[curr]<<" "<<len_of_cycle<<" "<<k<<"\n";
    if(k==0){
        cout<<curr+1<<"\n";
        exit(0);
    }
    int ans=v[curr];
    for(int i=0;i<k-1;i++){
        ans=v[ans];
    }
    cout<<ans+1<<"\n";
    return 0;
}

Measured memory_bytes: 15048
h,w,m=map(int,input().split())
HH=[]
WW=[]
HW=set()
lh=[0]*(h+1)
lw=[0]*(w+1)
for _ in range(m):
    h1,w1=map(int,input().split())
    lh[h1]+=1
    lw[w1]+=1
    HW.add((h1,w1))
lhmax=max(lh)
lwmax=max(lw)
maxh=[]
maxw=[]
for i in range(1,h+1):
    if lh[i]==lhmax:
        maxh.append(i)
for i in range(1,w+1):
    if lw[i]==lwmax:
        maxw.append(i)

if len(maxh)*len(maxw)>m:
    print(lhmax+lwmax)
else:
    flag=True
    for i in maxh:
        for j in maxw:
            if (i,j) not in HW:
                flag=False
                break
    if flag==True:
        print(lhmax+lwmax-1)
    else:
        print(lhmax+lwmax)

Measured memory_bytes: 83756
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


int N;
set<string> SET;

int main(){

	scanf("%d",&N);

	for(int i = 0; i < N; i++){

		string tmp_str;
		cin >> tmp_str;

		SET.insert(tmp_str);
	}

	printf("%lld\n",SET.size());

	return 0;
}


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

#define LL long long

#define FOR(INDEX, START, END) for (LL INDEX = (START); INDEX < (END); ++INDEX)
#define REP(INDEX, COUNT) for (LL INDEX = 0; INDEX < (COUNT); ++INDEX)

int main()
{
	LL N, K;
	cin >> N >> K;

	if ((N + 1) / 2 >= K) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}

	return 0;
}


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

#define int long long
template<typename T>
void chmin(T &a,T b){
  if(a>b)a=b;
}

signed main(){
  int a,b,c;cin>>a>>b>>c;
  int ans=1e18;
  if(c>1)chmin(ans,a*b*((c+1)/2-c/2));
  if(a>1)chmin(ans,b*c*((a+1)/2-a/2));
  if(b>1)chmin(ans,c*a*((b+1)/2-b/2));
  cout<<ans<<endl;
}


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

int main() {
    int n, k, l;
    cin >> n >> k >> l;
    pair<int, int> component[n + 1];
    vector<int> road[n + 1], rail[n + 1];
    for (int i = 0, p, q; i < k; i++) {
        cin >> p >> q;
        road[p].emplace_back(q);
        road[q].emplace_back(p);
    }
    for (int i = 0, p, q; i < l; i++) {
        cin >> p >> q;
        rail[p].emplace_back(q);
        rail[q].emplace_back(p);
    }
    vector<bool> visited(n + 1);
    for (int i = 1, count = 0; i <= n; i++) {
        if (!visited[i]) {
            visited[i] = true;
            stack<int> stack;
            stack.emplace(i);
            do {
                auto top = stack.top();
                component[top].first = count;
                stack.pop();
                for (int j : road[top]) {
                    if (!visited[j]) {
                        visited[j] = true;
                        stack.emplace(j);
                    }
                }
            } while(!stack.empty());
            count++;
        }
    }
    fill(begin(visited), end(visited), false);
    for (int i = 1, count = 0; i <= n; i++) {
        if (!visited[i]) {
            visited[i] = true;
            stack<int> stack;
            stack.emplace(i);
            do {
                auto top = stack.top();
                component[top].second = count;
                stack.pop();
                for (int j : rail[top]) {
                    if (!visited[j]) {
                        visited[j] = true;
                        stack.emplace(j);
                    }
                }
            } while(!stack.empty());
            count++;
        }
    }
    map<pair<int, int>, int> count;
    for (int i = 1; i <= n; i++) {
        count[component[i]]++;
    }
    for (int i = 1; i <= n; i++) {
        cout << count[component[i]] << ' ';
    }
    return 0;
}

Measured memory_bytes: 27816
#include <iostream>
#include <cstdio>
#include <algorithm> 
#include <cstring>
#include <map>
#include <queue>
#define INF 0x3f3f3f3f
#define LL long long
using namespace std;
char s[105];
int main(){
	scanf("%s", s);
	int len = strlen(s);
	for(int i = 0; i < len; i++)
		printf("x");
	return 0;
}

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

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

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

	if(n < 15) cout << 800 * n << "\n";
	else {
		int ans = 800 * n  - 200 * (n / 15);
		cout << ans << "\n";
	}

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <bitset>
#include <queue>
using namespace std;
int main() {
	int N, M;
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> N >> M;
	vector<vector<int> > V(3 * N + 1);
	for(int i = 0; i < M; i++) {
		int u, v;
		cin >> u >> v;
		V[u].push_back(v + N);
		V[u + N].push_back(v + 2 * N);
		V[u + 2 * N].push_back(v);
	}

	vector<int> s(3 * N + 1, -1);

	int S, T;
	cin >> S >> T;
	s[S] = 0;

	queue<int> q;
	q.push(S);
	while(!q.empty()) {
		int p = q.front();
		q.pop();
		for(auto x: V[p]) {
			if(s[x] >= 0) continue;
			s[x] = s[p] + 1;
			if(x == T) {
				cout << s[x] / 3<< endl;
				return 0;
			}
			q.push(x);
		}
	}
	cout << -1 << endl;
}


Measured memory_bytes: 18552
int check[30];

int c, n, a;

int main() {
  n = 0;
  while (1) {
    c = getchar_unlocked();
    if ('0' <= c && c <= '9')
      n = n * 10 + c - '0';
    else
      break;
  }

  int xor_sum = 0;
  for (int i = 0; i < n; i++) {
    a = 0;
    while (1) {
      c = getchar_unlocked();
      if ('0' <= c && c <= '9')
        a = a * 10 + c - '0';
      else
        break;
    }
    xor_sum ^= a;
    a = a ^ (a - 1);

    check[__builtin_popcount(a) - 1] = 1;
  }

  int ans = 0;
  for (int bit = 29; bit >= 0; bit--) {
    if (((1 << bit) & xor_sum) == 0) {
      continue;
    }
    int x = (1 << (bit + 1)) - 1;

    if (check[bit]) {
      xor_sum ^= x;
      ans += 1;
    }
  }

  if (xor_sum != 0) {
    printf("-1\n");
  } else {
    printf("%d\n", ans);
  }
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
	string s;
	cin >> s;
	
	string s1(s);
	reverse(s1.begin(), s1.end());
	
	const int slen = s1.length();
	
	for (int i = 0; i < slen; i++)
	{
		if (s1[i] == 'b') s1[i] = 'd';
		else if (s1[i] == 'd') s1[i] = 'b';
		else if (s1[i] == 'p') s1[i] = 'q';
		else if (s1[i] == 'q') s1[i] = 'p';
	}
	
	if (s == s1) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 512
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <queue>
using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef pair<int, int> P;
const int c_INF = 11111111111;
const int c_mINF = -11111111111;
const int c_YET = -1;
const int c_Dx[4] = { 0,0,1,-1 };
const int c_Dy[4] = { 1,-1,0,0 };

int compare_int(const void *p, const void *q) {
	return *(int*)p - *(int*)q;
}

int main() {
	int N, D[100005];
	scanf("%d", &N);
	//scanf("%d", D);
	for (int i = 0; i < N; i++)	scanf("%d", &D[i]);
	//printf("%d\n", D[0]);

	//昇順ソート
	qsort(D, N, sizeof(int), compare_int);


	//for (int i = 0; i < N; i++)	printf("%d ", D[i]);
	//printf("\n%d,%d\n", D[N / 2 - 1], D[N / 2 ]);

	
	if (D[N / 2-1] == D[N / 2 ])printf("0");
	else printf("%d", D[N / 2] - D[N / 2-1]);
	




}


/*         提出前の確認事項

・デバッグ用の関数は＜＜コメント化＞＞しているか？
・すべての＜＜入力例＞＞は試したか？
・＜＜限界値分析＞＞はしたか？
・＜＜出力の改行＞＞の有無は確認したか？
　　　　　　　　↓
	 ＜＜提出先＞＞に注意して提出！！
*/

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

int main(){
  vector<int> ant(6,0);
  for(int i =0;i<ant.size();i++){
  //cout << ant.at(i) << endl;
  cin >> ant.at(i);
  }
  
  bool tusin =true;
  
  if((ant.at(4)-ant.at(0)) > ant.at(5)){
    tusin = false;
  }
  
  if(tusin){
    cout << "Yay!" << endl;
  }else{
    cout << ":(" <<endl;
  }
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;
    
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 
#define U_MAP unordered_map<ll,ll>
#define pq priority_queue<ll>
#define rpq priority_queue<ll,vector<ll>,greater<ll>>
#define p_b push_back
    
ll n,cnt,ans,a[2000][2000],b,c,d,tmp,tmpp,m,h[ohara],w,x,y,sum,pos,k,q;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};
map<P,ll> mp;
V g[ohara];
ll come[ohara];
vector<int> res;
bool used[ohara];
ll dp[ohara];
    
//------ Believe yourself as a genius!!!!!! ------
    
int main(void){
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    
    cin>>n;
    rep(i,n){
        rep(j,n-1){
            cin>>a[i][j];
            a[i][j]--;
        }
    }
    rep(i,n){
        rrep(j,i+1,n){
            mp[{i,j}]=cnt;
            mp[{j,i}]=cnt;
            cnt++;
        }
    }
    rep(i,n){
        rep(j,n-2){
            ll fr,to;
            fr=mp[{i,a[i][j]}];
            to=mp[{i,a[i][j+1]}];
            g[fr].p_b(to);
            h[to]++;
            //cout<<fr<<" "<<to<<"\n";
        }
    }

    stack<int> st;

  //入次数が0の頂点であればstに追加
  //cntは頂点数
  rep(i, cnt) if(h[i] == 0) st.push(i);

  //ソートされた後のグラフ
  vector<ll> res;
  //stがなくなるまでループ
  while(st.size()) {
    //stの集合のから一つ取り出す
    int i = st.top(); st.pop();
    res.push_back(i);
    for(auto& j: g[i]) {
      //隣接する頂点の入次数をマイナス1
      h[j]--;
      //これによって入次数が0になればstに追加
      if(h[j] == 0) st.push(j);
    }
  }

    if(Size(res)!=cnt)Cout(-1);
    else{
        for(int i : res){
            rep(j,Size(g[i])){
                dp[g[i][j]]=max(dp[i]+1,dp[g[i][j]]);
                ans=max(ans,dp[g[i][j]]);
            }
        }
        Cout(ans+1);
    }
    return 0;
}

Measured memory_bytes: 133488
#include <stdio.h>
#include <ctype.h>

int main(){
    int count[26]={0};
    char ch;
    int i, num;

    while(scanf("%c", &ch)!=EOF){
        if(islower(ch)){
            num=ch-'a';
        }else if(isupper(ch)){
            num=ch-'A';
        }else{
            continue;
        }
        count[num]++;
    }
    for(i=0;i<26;i++){
        printf("%c : %d\n", 'a'+i, count[i]);
    }

    return 0;
}



Measured memory_bytes: 2128
def solve():
  N = int(input())
  A = [int(input()) for _ in range(N)]
  ans = sum(A)
  if ans%10!=0:
    return ans
  A.sort()
  for i in range(N):
    if A[i]%10!=0:
      return ans-A[i]
  return 0
print(solve())

Measured memory_bytes: 9080
#include <bits/stdc++.h>
using namespace std;
using LL = long long int;
#define incID(i, l, r) for(int i = (l)    ; i <  (r); ++i)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); --i)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); ++i)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define dec(i, n)  decID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define FI first
#define SE second
#define FR front()
#define BA back()
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
auto setmin   = [](auto & a, auto b) { return (b <  a ? a = b, true : false); };
auto setmax   = [](auto & a, auto b) { return (b >  a ? a = b, true : false); };
auto setmineq = [](auto & a, auto b) { return (b <= a ? a = b, true : false); };
auto setmaxeq = [](auto & a, auto b) { return (b >= a ? a = b, true : false); };
#define SI(v) static_cast<int>(v.size())
#define RF(e, v) for(auto & e: v)
#define until(e) while(! (e))
#define if_not(e) if(! (e))
#define ef else if
#define UR assert(false)
#define IN(T, ...) T __VA_ARGS__; IN_(__VA_ARGS__);
void IN_() { };
template<typename T, typename ... U> void IN_(T &  a, U &  ... b) { cin >> a; IN_(b ...); };
template<typename T                > void OUT(T && a            ) { cout << a << endl; }
template<typename T, typename ... U> void OUT(T && a, U && ... b) { cout << a << " "; OUT(b ...); }

// ---- ----

int main() {
	IN(LL, n, d);
	int ans = 0;
	inc(i, n) {
		IN(LL, x, y);
		if(x * x + y * y <= d * d) { ans++; }
	}
	OUT(ans);
}


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

int main()
{
  // 入力値
  int N, sum;
  sum = 0;
  cin >> N;
  
  sum += N % 10;
  
  switch( sum )
  {
    case 3:
      cout << "bon" << endl;
      break;
    case 0:
    case 1:
    case 6:
    case 8:
      cout << "pon" << endl;
      break;
    default:
      cout << "hon" << endl;
      break;
  }

  return 0;
}

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

using namespace std;
const int N = 200000 + 77;
int n , a[N] , t[N] , Mx;
long long A;
int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);
	cin >> n;
	for(int i = 1;i <= n;i++){cin >> a[i];}
	if(a[1] > 0){return cout << -1 , 0;}
	for(int i = 2;i <= n;i++){
		if(a[i] > a[i - 1] + 1){return cout << - 1 , 0;}
		if(a[i] == a[i - 1] + 1){A ++;continue;}
		A += a[i];
	}
	cout << A;
 	return 0;
}	

Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<stack>
#include<cmath>
#include<algorithm>
#include<map>
typedef long long ll;
using namespace std;
#define INF 0x3f3f3f3f
/**
*超时有可能是输入的问题
*注意边界
*仔细读题
*没思路试试逆向思维
**加油，奥利给！！！ 
**/
map<int,int>p;
/*struct knd{
	int x,y,z;
}s[200000];*/ 
int a[200000];
int main()
{
	int m,n,i,j,t,k;
	cin>>n>>m;
	cout<<n*m;
	/*for(i=1;i<=n;i++)
	{
		cin>>a[i];
	 } */
 } 

Measured memory_bytes: 3588
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n; cin>>n;
  int l[n];
  for (int i=0;i<n;i++){
    int e; cin>>e;
    l[i]=e;
  }
  int ans=0;
  for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++){
      if(l[i]==l[j]){continue;}
      for(int k=j+1;k<n;k++){
        if(l[j]==l[k] || l[i]==l[k]){continue;}
        if(l[i]+l[j]>l[k] & l[i]+l[k]>l[j] & l[k]+l[j]>l[i]){
          ans+=1;
        }
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define f first
#define s second
using namespace std;
const int N = 5005;
int dp[N][N], n, k, a[N], tmp, x, z[N];
int sol(int i, int cur)
{
	if(i == n || cur >= k-x) return cur;
	int &ret = dp[i][cur];
	if(ret != -1) return ret;
	ret = 0;
	if(cur + a[i] < k && tmp != i) ret = sol(i+1, cur+a[i]);
	if(ret >= k-x) return ret;
	ret = max(ret, sol(i+1, cur));
	return ret;
}
bool check(int i)
{
	x = a[i];
	if(z[x] != -1) return z[x];
	if(x >= k) return z[x] = 1;
	tmp = i;
	memset(dp, -1, sizeof dp);	
	if(sol(0, 0) >= k-x) return z[x] = 1;
	return z[x] = 0;
}
int main()
{
	memset(z, -1, sizeof z);
	cin >> n >> k;
	for(int i=0; i<n; i++) scanf("%d", &a[i]);
	sort(a, a+n);
	while(a[n-1] >= k) n--;
	int s = 0, e = n-1;
	while(s <= e)
	{
		int mid = (s+e)>>1;
		if(check(mid)) e = mid-1;
		else s = mid+1;
	}
	cout << s << endl;
}

Measured memory_bytes: 98304
#include<iostream>
#include<string>
using namespace std;
#define REP(i,n) for(int i=0; i<n; i++)
int n;
int mem;
int count1;
int count2;
string s[40];
bool check;

void test(int k, int l){
  count1 = 0;
  for(int j=0; j+k<n; j++){
    count1 += s[k+j].length();
    if(count1 > l)return;
    if(count1==l){
      count2++;
      if(l==5&&count2==1){
        mem = k;
      }
      if(l==7){
        if(count2==5){
          check = true;
          return;
        }
      }
      switch(count2){
        case 1: return test(k+j+1,7);
        case 2: return test(k+j+1,5);
        case 3: return test(k+j+1,7);
        case 4: return test(k+j+1,7);
      }
    }
  }
}

int main(){
  while(cin>>n&&n){
    check = false;
    REP(i,n){
      cin >> s[i];
    }
    REP(i,n){
      count1 = 0;
      count2 = 0;
      test(i,5);
      if(check==true){
        cout << mem+1 << endl;
        break;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(void){
  ll n;
  cin >> n;
  ll row[n];
  ll result=1;
  for(int i=0;i<n;i++){
    cin >> row[i];
    if(row[i] == 0){
      cout << 0 << endl;
      return 0;
    }
  }  
  for(int i=0;i<n;i++){
    if(row[i] <= 1000000000000000000/result){
      result *= row[i];
    }else{
      cout << -1 << endl;
      return 0;
    }
  }  
  cout << result << endl;
  return 0;
  
}       

Measured memory_bytes: 4420
#include <stdio.h>

int gcd(int x, int y){
	
	if( y == 0 ) return x;
	if( x >= y ) gcd(y, x%y);
	else gcd(y,x);
	
}

int main(void){
	
	int x,y;
	
	scanf("%d %d", &x, &y);
	
	printf("%d\n", gcd(x,y));
	
}


Measured memory_bytes: 2144
import sys
input = sys.stdin.readline

def print_ans(A, B, K):
    """Test Case
    >>> print_ans(2, 3, 3)
    0 2
    >>> print_ans(500000000000, 500000000000, 1000000000000)
    0 0
    """
    if K <= A:
        print(str(A-K) + " " + str(B))
    elif K <= A + B:
        print("0 " + str(A + B - K))
    elif K > A + B :
        print("0 0")


if __name__ == '__main__':
    A, B, K = map(int, input().rstrip().split())
    print_ans(A, B, K)




Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <set>
#include <algorithm>
#include <iomanip>

typedef long long ll;
const ll MOD = 1e9 + 7;
const long long INF = 1LL<<60;
const double PI=3.14159265358979323846;
const int NMAX=200005;
using namespace std;


struct UnionFind{
    ll parent[NMAX];
    ll count[NMAX];

    void Create(int n){
        for(int i = 0; i <= n; i++){
            parent[i] = i;
            count[i] = 1;
        }
    }

    int Root(int i){
        if(parent[i] == i){
            return i;
        } else {
            parent[i] = Root(parent[i]);
            return parent[i];
        }
    }

    void Unite(int x, int y){
        int px = Root(x);
        int py = Root(y);
        if(px != py){
            if (count[px] > count[y]) swap(px, py);
            parent[px] = py;
            count[py] += count[px];
        }
    }

    bool Same(int x, int y){
        if(Root(x) == Root(y)){
            return true;
        } else {
            return false;
        }
    }

    ll Count(int x){
        ll c = count[Root(x)];
        return c;
    }
};

int main(){
    int n,m;
    cin >> n >> m;
    UnionFind uf;
    uf.Create(n);
    for(int i = 0; i < m; i++){
        int a, b;
        cin >> a >> b;
        uf.Unite(a,b);
    }
    ll ans = 1;
    for(int i = 1; i <= n; i++){
        ll cnt = uf.Count(i);
        ans = max(ans, cnt);
    }

    cout << ans << endl;

    return 0;
}

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

int main() {
    string A, B, C; cin >> A >> B >> C;
    if (A[A.length() - 1] == B[0] && B[B.length() - 1] == C[0]) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define F first
#define S second

using namespace std;
typedef pair<int,int> P;

const int MOD=1000000007;
int INF=100100100100100;

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

Measured memory_bytes: 256
import java.util.*;
	import java.util.Map.Entry;
	 
	 
	 class Main {
		 static int mod =  (int) (Math.pow(10,9)+7);
//		 static int mod =  (int) 998244353;
		 public static void main(String[] args) {
	    	
	        Scanner sc = new Scanner(System.in);

	        int N = sc.nextInt();
	        int[] a = new int[N];
	        int[] m = new int[1000000];
	        long sum=0;
	        for (int i=0 ; i<N; i++) {
	            a[i] = sc.nextInt();
	            m[a[i]]++;
	            sum=sum+a[i];
	        }
	        StringBuffer ans = new StringBuffer();
	        int Q = sc.nextInt();
	        for(int i=0;i<Q;i++) {
	        	int b = sc.nextInt();
	        	int c = sc.nextInt();
	        	sum=sum+m[b]*(c-b);
	        	m[c]=m[c]+m[b];
	        	m[b]=0;
	        	ans.append(sum);
	        	ans.append("\n");
	        }
	        

	        System.out.println(ans);
	    }
	}

Measured memory_bytes: 65536
#include<stdio.h>
int main()
{
	int a,b;
	while(scanf("%d%d",&a,&b)!=EOF&&a&&b)
	{
		int i,j;
		for(i=0;i<a;i++)
		{
			for(j=0;j<b;j++)
			{
				
				if((i+1)%2)
				{
					if((j+1)%2)
					{
						printf("#");
					}
					else
					{
						printf(".");
					}
				}
				else
				{
					if((j+1)%2)
					{
						printf(".");
					}
					else
					{
						printf("#");
					}
					
				}
			}
			printf("\n");
		}
		printf("\n");
	}
	return 0;
 } 

Measured memory_bytes: 1000
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
#define DEBUG 0
typedef long long LL;

struct Point {
  int r;
  int c;
};

int main() {
  int H, W, N; std::cin >> H >> W >> N;
  Point s; std::cin >> s.r >> s.c;
  std::string S, T; std::cin >> S >> T;

  int l = 0, r = 0, u = 0, d = 0;
  for (int i = 0; i < N; ++i) {
    // Takahashi action
    switch (S[i]) {
      case 'L':
        ++l; break;
      case 'R':
        ++r; break;
      case 'U':
        ++u; break;
      case 'D':
        ++d; break;
    }

#if DEBUG
    std::cout << "T:" << l << ", " << r << ", " << u << ", " << d << std::endl;
#endif

    if (s.r - u < 1 || s.r  + d > H || s.c - l < 1 || s.c + r > W) {
      std::cout << "NO" << std::endl;
      return 0;
    }

    // Aoki Action
    switch (T[i]) {
      case 'L':
        if (s.c + r > 1) --r; break;
      case 'R':
        if (s.c - l < W) --l; break;
      case 'U':
        if (s.r + d > 1) --d; break;
      case 'D':
        if (s.r - u < H) --u; break;
    }

#if DEBUG
    std::cout << "A:" << l << ", " << r << ", " << u << ", " << d << std::endl;
#endif
  }

  std::cout << "YES" << std::endl;
}


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

int main() {
  int N;
  cin >> N;
  
  vector<int> vec(N);
  for(int i = 0; i < N; i++) {
    cin >> vec[i];
  }
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  int alice = 0;
  int bob = 0;
  for(int i = 0; i < vec.size(); i++) {
    if(i % 2 == 0) {
      alice += vec.at(i);
    } else {
      bob += vec.at(i);
    }
  }
  cout << alice - bob << endl;
}


Measured memory_bytes: 3152
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i < n; i++)
#define elif else if
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll MOD2 = 998244353;
const ll INF = 1e18;

int main(){
    int N;
    cin >> N;
    ll a[N+1], b[N+1];
    rep2(i, 1, N+1){
        cin >> a[i];
        b[a[i]] = i;
    }
    set<ll> s;
    s.insert(0), s.insert(N+1);
    ll ans = 0;
    rep2(i, 1, N+1){
        s.insert(b[i]);
        set<ll>::iterator ite, ite1, ite2;;
        ite = s.find(b[i]);
        ite1 = ite, ite2 = ite;
        ite1--, ite2++;
        ans += i*(*ite-*ite1)*(*ite2-*ite);
    }
    cout << ans << endl;
}

Measured memory_bytes: 12800
// Aaradhya Beri
#pragma GCC optimze("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef long double f80;
#define double long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define sz(x) ((long long)x.size())
#define fr(a,b,c) for(int a=b; a<=c; a++)
#define rep(a,b,c) for(int a=b; a<c; a++)
#define trav(a,x) for(auto &a:x)
#define all(con) con.begin(),con.end()
#define w(x) int x; cin>>x; while(x--)
const ll infl=0x3f3f3f3f3f3f3f3fLL;
const int infi=0x3f3f3f3f;
//const int mod=998244353;
const int mod=1000000007;
typedef vector<int> vi;
typedef vector<ll> vl;

int powm(int a, int b) {
    int res=1;
    while(b) {
        if(b&1)
            res=(res*a)%mod;
        a=(a*a)%mod;
        b>>=1;
    }
    return res;
}
 

signed main() {
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    cout<<fixed<<setprecision(8);
    int W, a, b;
  cin >> W >> a >> b;
  int diff;
  if (abs(a-b)<=W)
    diff = 0;
  else if(b>a)
    diff = b-(a+W);
  else
    diff = a-(b+W);
  cout << diff << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void) {
	int i = 0, n = 0, a = 0,b=0;
	scanf("%d",&n);
	if (n == 1) {
		printf("Hello World\n");
	}
	if (n == 2) {
		scanf("%d %d", &a,&b);
		printf("%d", a + b);
	}
	return 0;
}

Measured memory_bytes: 128
import os
import sys
import math
import heapq
from decimal import *
from io import BytesIO, IOBase
from collections import defaultdict, deque

def r():
    return int(input())
def rm():
    return map(int,input().split())
def rl():
    return list(map(int,input().split()))

n = r()
print('Yes' if n>=30 else 'No')


Measured memory_bytes: 71056
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int n,m,i,x,ima=0,wa=0,mini;
  cin>>n;
  int a[2*n];
  for(i=0;i<2*n;i++){
    cin>>a[i];
    wa+=a[i];
  }
  for(i=1;i<n;i++){
    ima+=a[i];
  }
  mini=ima;
  for(i=1;i<n;i++){
    ima=ima-a[i]+a[n+i-1];
    mini=min(mini,ima);
  }
  cout<<wa-mini;
}

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

vector<vector<bool>> Consistency;
vector<vector<int>>  Testimony;
int N;

int main(void){
    int Abuf, Xbuf, Ybuf;
    cin >> N;
    vector<int> A;
    Testimony.assign(N, vector<int>(N, -1));
    for(int i=0; i<N; i++){
        cin >> Abuf;
        A.push_back(Abuf);
        for(int j=0; j<Abuf; j++){
            cin >> Xbuf >> Ybuf;
            Testimony[i][Xbuf-1] = Ybuf;            
        }
    }
    
    int maxCases = 1<<N;
    vector<bool> bolCases(maxCases, true);
    for(int numCase=0; numCase < maxCases; numCase++){
        for(int i=0; i<N; i++){
            int iHonesty = (numCase >> i) & 1;
            if(iHonesty == 1){
                for(int j=0; j<N; j++){
                    int jHonesty = (numCase >> j) & 1;
                    if((jHonesty != Testimony[i][j])&&(Testimony[i][j]!=-1)){
                        bolCases[numCase] = false;
                        break;
                    }
                }
                if(!bolCases[numCase])break;
            }
        }
    }

    int res = 0;

    for(int numCase=0; numCase < maxCases; numCase++){
        if(!bolCases[numCase])continue;
        res = max(res, __builtin_popcount((unsigned int)numCase));
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
a, b = gets.split.map(&:to_i)
t = a
i = 2
if a % b == 0
  puts -1
else
  loop do
    a += t
    if a % b != 0
      puts a
      exit
    end
    if a >= 1e18+1
      puts -1
      exit
    end
  end
end
  

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> Pii;

int H, W;
char s[110][110];

struct Edge {
    int dst, weight;
};
int V, E;
const int MAX_V = 1.0e5 + 10;
vector<Edge> G[MAX_V];
int d[MAX_V];
const int INF = 1.0e9;

void dijkstra(int s) {
    using P = pair<int, int>;

    priority_queue<P, vector<P>, greater<P> > que;
    fill(d, d+V+1, INF);
    d[s] = 0;
    que.push(P(0, s));

    while (!que.empty()) {
        P p = que.top();
        que.pop();
        int v = p.second;
        if (d[v] < p.first) continue;

        for (int i = 0; i < G[v].size(); i++) {
            Edge e = G[v][i];
            if (d[e.dst] > d[v] + e.weight) {
                d[e.dst] = d[v] + e.weight;
                que.push(P(d[e.dst], e.dst));
            }
        }
    }
    return;
}

int main() {
    cin >> H >> W;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            cin >> s[i][j];
        }
    }

    V = H*W-1;

    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W-1; j++) {
            if (s[i][j] == '.' && s[i][j+1] == '#') {
                Edge e = {i*W + j + 1,1};
                G[i*W + j].push_back(e);
            }
            else {
                Edge e = {i*W + j + 1, 0};
                G[i*W + j].push_back(e);
            }
        }
    }
    for (int j = 0; j < W; j++) {
        for (int i = 0; i < H; i++) {
            if (s[i][j] == '.' && s[i+1][j] == '#') {
                Edge e = {(i+1)*W + j, 1};
                G[i*W + j].push_back(e);
            }
            else {
                Edge e = {(i+1)*W + j, 0};
                G[i*W + j].push_back(e);
            }
        }
    }

    dijkstra(0);

    if (s[0][0] == '#') cout <<  d[(H-1)*W + (W-1)] + 1 << endl;
    else cout << d[(H-1)*W + (W-1)] << endl;
    
    return 0;
}

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

#if defined(DEBUG)

#include <unistd.h>
#include <sys/fcntl.h>
#define DLOG(...)        cerr << dbgFormat(__VA_ARGS__) << endl
#define DCALL(func, ...) func(__VA_ARGS__)

template <class... Args>
string dbgFormat(const char* fmt, Args... args) {
  size_t len = snprintf(nullptr, 0, fmt, args...);
  char buf[len + 1];
  snprintf(buf, len + 1, fmt, args...);
  return string(buf);
}

#else  // defined(DEBUG)

#define DLOG(...)
#define DCALL(func, ...)

#endif // defined(DEBUG)

// sieve(upto) returns the list of prime numbers up to upto.
vector<ll> sieve(ll upto) {
  vector<ll> res;
  vector<bool> tbl(upto+1);
  ll lim = (ll)(sqrt((double)upto)) + 1;
  for (ll x = 2; x <= upto; x++) {
    if (tbl.at(x))  continue;
    res.push_back(x);
    if (x > lim)  continue;
    for (ll y = x * 2; y <= upto; y += x) tbl.at(y) = true;
  }
  return res;
}


// prime factorization
//      primes should contain prime numbers at least up to sqrt(n)
vector<pair<ll, ll>> prfac(ll n, const vector<ll>& primes) {
  DLOG("prfac %lld", n);
  vector<pair<ll, ll>> res;
  ll x = n;
  for (ll p : primes) {
    if (x == 1)  break;
    if (p * p > x)  break;
    if (x % p != 0)  continue;
    ll c = 1;
    x /= p;
    while (x % p == 0) {
      c += 1;
      x /= p;
    }
    res.push_back(make_pair(p, c));
  }
  if (x != 1)  res.push_back(make_pair(x, 1));
  DLOG("prfac returns result.");
  return res;
}

vector<int> gdsub(int i, int n, auto fs) {
  if (i == n) { return vector<int>({1}); }
  auto part = gdsub(i+1, n, fs);
  int len = part.size();
  auto t = fs.at(i);
  ll p = t.first;
  ll r = t.second;
  ll pp = p;
  for (int m = 1; m <= r; m++) {
    for (int j = 0; j < len; j++) {
      part.push_back(pp * part.at(j));
    }
    pp *= p;
  }
  return part;
}

vector<int> getDivisors(int n) {
  auto primes = sieve(1e5);
  vector<pair<ll, ll>> fs = prfac(n, primes);
  return gdsub(0, fs.size(), fs);
}

bool allow(int N, int K, int d, auto A) {
  vector<int> r(N);
  for (int i = 0; i < N; i++) {
    r.at(i) = A.at(i) % d;
  }
  sort(r.begin(), r.end());
  int p = 0;
  int j = 0;
  for ( ; j < N && p + r.at(j) <= K; j++) p += r.at(j);
  int q = 0;
  int k = N-1;
  for ( ; k >= 0 && q + (d - r.at(k)) <= K; k--) q += d - r.at(k);
  return k < j;
}

int main(int argc, char *argv[]) {
#if defined(DEBUG)
  // GDB on Cygwin ignores redirection at run command.
  if (argc == 2) dup2(open(argv[1], 0), 0);
#else
  // For performance.  We should not use C-style stdio functions
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
#endif
  cout << setprecision(20);

  int N, K; cin >> N >> K;
  vector<int> A(N);
  int sum = 0;
  for (int i = 0; i < N; i++)  {
    cin >> A.at(i);
    sum += A.at(i);
  }
  vector<int> divisors = getDivisors(sum);
  sort(divisors.begin(), divisors.end(), greater<int>());
  for (int d : divisors) {
    if (allow(N, K, d, A)) {
      cout << d << endl;
      return 0;
    }
  }
  return 0;
}



Measured memory_bytes: 512
#include <iostream>
#include <queue>
#include <iomanip>
#include <map>
#include <algorithm>

using namespace std;

using ll = long long;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;


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

    int lv = 0;
    int curJ = (S[0] == 'J'), curO = (S[0] == 'O'), curI = (S[0] == 'I');
    bool valid = (S[0] == 'J');
//    cout << curJ << " " << curO << " " << curI << " " << endl;
    for (int i = 1; i < S.length(); i++) {
        if (S[i] == 'J') {
            if (S[i-1] == 'J') {
                curJ++;
            } else if (S[i-1] == 'O') {
                valid = false;
                curO = 0;
                curJ = 1;
            } else if (S[i-1] == 'I'){
                if (valid && curO <= curJ && curO <= curI) {
                    lv = max(lv, min(curJ, min(curO, curI)));
                }

                curJ = 1;
            }
        } else if (S[i] == 'O') {
            if (S[i-1] == 'J') {
                valid = true;
                curO = 1;
            } else if (S[i-1] == 'O') {
                curO++;
                if (curJ < curO) {
                    valid = false;
                    curJ = 0;
                    curO = 0;
                }
            } else if (S[i-1] == 'I'){
                if (valid && curO <= curJ && curO <= curI) {
                    lv = max(lv, min(curJ, min(curO, curI)));
                }

                valid = false;
                curI = 0;
                curO = 1;
            }
        } else if (S[i] == 'I') {
            if (S[i-1] == 'J') {
                valid = false;
                curJ = 0;
                curI = 1;
            } else if (S[i-1] == 'O') {
                if (!valid) {
                    curO = 0;
                }
                curI = 1;
            } else if (S[i-1] == 'I'){
                curI++;
            }
        }

//        cout << curJ << " " << curO << " " << curI << " " << endl;
    }
    if (valid && curO <= curJ && curO <= curI) {
        lv = max(lv, min(curJ, min(curO, curI)));
    }

    cout << lv << endl;

    return 0;
}

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

const int N = 100005;

int n, k;
int a[N];
long long f[N], s[N];
long long ans;

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> n >> k;
	for (int i = 1; i <= n; ++i) cin >> a[i];
	for (int i = 1; i <= n; ++i) {
		f[i] = f[i - 1] + max(0, a[i]);
		s[i] = s[i - 1] + a[i];
	}

	for (int i = k; i <= n; ++i) {
		long long add = max(0LL, s[i] - s[i - k]);
		ans = max(ans, add + f[i - k] + f[n] - f[i]);
	}
	cout << ans << endl;
}

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

int main() {
  int N[5];
  int argMinNRes = -1;
  int minNRes = 10;
  
  for(int i=0; i<5; i++) {
    cin >> N[i];
    if(N[i]%10 != 0 && N[i]%10 < minNRes) {
      minNRes = N[i]%10;
      argMinNRes = i;
    }
  }
    
  int total_minute = 0;
  if(argMinNRes == -1) {
    for(int i=0; i<5; i++) {
      total_minute += N[i];
    }
  } else {
    for(int i=0; i<5; i++) {
      if(i != argMinNRes) {
        total_minute += ceil(N[i]/10.0)*10;
      } else {
        total_minute += N[i];
      }
    }
  }
  
  cout << total_minute << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <algorithm>
#include <cmath>
#include <cstring>

using namespace std;

#define REP(i,n) for(int i = 0; i < n; i++)
#define RREP(i,n) for(int i = n - 1; i >= 0; i--)

#define ALL(v) v.begin(),v.end()
#define pb push_back
#define mp make_pair
#define F first
#define S second

#define UNIQUE(v) do{sort(v.begin(), v.end()); v.erase( unique(v.begin(), v.end()), v.end() );} while(0)


#define y0 y3487465
#define y1 y8687969

#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,63,sizeof(x))

typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pi> vpi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

double EPS = 1e-9;
int INFi = 1000000005;
long long INFll = 1000000000000000005ll;
double PI = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};
ll MOD = 1000000007;

int n;
const int MAX_N = 20;
int p[MAX_N];

int main(){
  cin >> n;
  REP(i, n) cin >> p[i];

  int ans = 0;
  for(int i = 1; i < n - 1; i++) {
    if(min({p[i - 1], p[i], p[i + 1]}) != p[i] && max({p[i - 1], p[i], p[i + 1]}) != p[i]) ans++;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cassert>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define rep(i,n) FOR(i,0,n)
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define vint vector<int>
#define vdouble vector<double>
#define vstring vector<string>
using namespace std;

#include<map>
#include<set>
#include<queue>

typedef long long ll;
typedef unsigned long long ull;

const int MAX_N = 1000000;

int N;
ll a[100000];

ll solve(int sign){
    ll sum = 0;
    ll ct = 0;

    rep(i, N){
        sum += a[i];
        if(sign == 1){
            if(sum <= 0) {ct += (1 - sum); sum = 1;}
        }
        else{
            if(sum >= 0) {ct += (1 + sum); sum = -1;}
        }
        sign *= -1;
    }

    return ct;
}

int main() {
	cin >> N;
	rep(i, N) cin >> a[i];
	cout << min(solve(1), solve(-1)) << endl;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define SORT(v) sort(v.begin(), v.end());
#define RSORT(v) sort(v.rbegin(), v.rend());
#define REVERSE(v) reverse(v.begin(), v.end());

template <typename T>
void printlnVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << endl;
  }
}

template <typename T>
void printVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << " ";
  }
  cout << endl;
}

int main()
{
  int N;
  cin >> N;
  int ans = (N - 1) / 2;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
typedef long long ll;
#include<bits/stdc++.h>
using namespace std;
ll maxl(ll a, ll b){ return ((a<b)?b:a);}
ll minl(ll a, ll b){ return ((a>b)?b:a);}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int n,k;
    cin >> n >> k;
    int p[n];
    int c[n];
    for(int i=0;i<n;i++){
        cin >> p[i];
        p[i] -= 1;
    }
    for(int i=0;i<n;i++){
        cin >> c[i];
    }
    vector<bool> visited(n,false);
    ll ans = LONG_MIN;
    for (int i=0;i<n;i++){
        if (visited[i] == false){
            int temp = p[i];
            vector<int> v;
            ll count = 0;
            bool flag = true;
            while (flag || temp != p[i]){
                v.push_back(c[temp]);
                temp = p[temp];
                flag = false;
                visited[temp] = true;
            }
            vector<ll> prefix_sum(v.size()+1,0);
            for (int j=1;j<=v.size();j++){
                prefix_sum[j] = prefix_sum[j-1] + v[j-1];
            }
            for (int j=0;j<=v.size();j++){
                for (int l=0;l<=v.size();l++){
                    if (j<=l){
                        int surplus = l - j;
                        if (surplus>k)
                            continue;
                        int rem = k - surplus;
                        int cycles = rem / (v.size());
                        ll temp1, temp2;
                        if (surplus != 0)
                            temp1 = prefix_sum[l] - prefix_sum[j];
                        else
                            temp1 = LONG_MIN;
                        if (surplus !=0)
                            temp2 = temp1 + prefix_sum[v.size()]*cycles;
                        else{
                            if (cycles!=0)
                                temp2 = prefix_sum[v.size()]*cycles;
                            else
                                temp2 = LONG_MIN;
                        }
                        ll temp3 = maxl(temp1, temp2);
                        ans = max(ans,temp3);
                    } else {
                        int surplus = v.size() - j + l;
                        if (surplus>k)
                            continue;
                        int rem = k - surplus;
                        int cycles = rem / (v.size());
                        ll temp1,temp2;
                        if (surplus!=0)
                            temp1 = prefix_sum[l] + (prefix_sum[v.size()] - prefix_sum[j]);
                        else
                            temp1 = LONG_MIN;
                        if (surplus!=0)
                            temp2 = temp1 + prefix_sum[v.size()]*cycles;
                        else{
                            if (cycles!=0)
                                temp2 = prefix_sum[v.size()]*cycles;
                            else
                                temp2 = LONG_MIN;
                        }
                        ll temp3 = maxl(temp1, temp2);
                        ans = max(ans,temp3);
                    }
                }
            }
        }
    }
    cout << ans << "\n";
}


Measured memory_bytes: 3788
import math
x = int(input())
b = 0

"""
def calc(b, b5):
    a = (x+b5)**0.2

    if a.real.is_integer():
        print(int(a), b)
        exit()

while True:
    b5 = b ** 5
    calc(b, b5)
    if x-b5 >= 0:
        calc(-b, -b5)
    b += 1
    """

for i in range(-120,120):
    for j in range(-120,120):
        if i**5 - j**5 == x:
            print(i, j)
            exit()


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

//配列出力処理
void output(int a[], int n) {
  rep(i, n) {
    if (i > 0) printf(" ");  //要素間に空白を入れる
    printf("%d", a[i]);  //フォーマット指定子 %c char %d int10進数
  }
  printf("\n");
}

// Insertion Sort
void insertionSort(int a[], int n) {
  for (int i = 1; i < n; i++) {
    int duf = a[i];
    int j = i - 1;
    while (j >= 0 && duf < a[j]) {
      a[j + 1] = a[j];
      j--;
    }
    a[j + 1] = duf;
    output(a, n);
  }
}

// O(n^2)
int main() {
  int n;
  int a[1000];
  cin >> n;
  rep(i, n) cin >> a[i];
  output(a, n);
  insertionSort(a, n);
  return 0;
}



Measured memory_bytes: 3216
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef vector<int> vi;
const ll M = 1e9 + 7;

int main(void){
  int n, m; bool ok = true;
  scanf("%d %d", &n, &m);
  vi as(n), bs(m), cs(n * m, 0); vector<bool> seen(n * m, false);
  rep(i, n) {scanf("%d", &as[i]); as[i]--; if (seen[as[i]]) ok = false; seen[as[i]] = true;}
  fill(all(seen), false);
  rep(i, m) {scanf("%d", &bs[i]); bs[i]--; if (seen[bs[i]]) ok = false; seen[bs[i]] = true;}
  if (!ok){printf("%d\n", 0); return 0;}

  sort(all(as)); sort(all(bs));
  ll ans = 1;
  rep(i, n) rep(j, m) if (as[i] == bs[j]) cs[as[i]] = 1;
  for (int a: as) if (!cs[a]) cs[a] = m - (lower_bound(all(bs), a) - bs.begin());
  for (int b: bs) if (!cs[b]) cs[b] = n - (lower_bound(all(as), b) - as.begin());
  for (int x = n * m - 1; x >= 0; x--){
    if (!cs[x]){
      cs[x] = m - (lower_bound(all(bs), x) - bs.begin());
      cs[x] *= n - (lower_bound(all(as), x) - as.begin());
      cs[x] -= n * m - x - 1;
    }
    (ans *= cs[x]) %= M;
  }

  printf("%lld\n", ans);

  return 0;
}


Measured memory_bytes: 7232
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
using iii = pair<ii, int>;
#define vt vector
#define pq priority_queue
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define __lcm(a, b) a * b / __gcd(a, b)
const int MOD = 1e9 + 7;
const int INF = 2e9;
const int N = 2e5 + 5;

int n, m, a, b, now, maxim;
int mark[N], freq[N];
bool vis[N];
vt<int> v[N];

void DFS(int x) {
    if(vis[x]) return;
    vis[x] = true;
    mark[x] = now;
    for(int u : v[x]) {
        DFS(u);
    }
}

void solve() {
    cin >> n >> m;
    while(m--) {
        cin >> a >> b;
        v[a].pb(b);
        v[b].pb(a);
    }
    now = 1;
    for(int i = 1; i <= n; i++) {
        if(mark[i]) continue;
        DFS(i);
        now++;
    }
    maxim = -INF;
    for(int i = 1; i <= n; i++) {
        freq[mark[i]]++;
        maxim = max(maxim, freq[mark[i]]);
    }
    cout << maxim << "\n";
}

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

Measured memory_bytes: 21752
/* ALDS1_1_D: Maximum Profit - http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_1_D
 
Maximum Profit
You can obtain profits from foreign exchange margin transactions. For example, if you buy 1000 dollar at a rate of 100 yen per dollar, and sell them at a rate of 108 yen per dollar, you can obtain (108 - 100) × 1000 = 8000 yen.

Write a program which reads values of a currency Rt at a certain time t (t=0,1,2,...n−1), and reports the maximum value of Rj−Ri where j>i .

Input
The first line contains an integer n. In the following n lines, Rt (t=0,1,2,...n−1) are given in order.

Output
Print the maximum value in a line.

Constraints
2≤n≤200,000
1≤Rt≤109
Sample Input 1
6
5
3
1
3
4
3
Sample Output 1
3
Sample Input 2
3
4
3
2
Sample Output 2
-1
*/

use std::io::*;
 
fn main() {
    let stdin = stdin();
    let mut lines = stdin.lock().lines().map(|l| l.unwrap());

    let n = lines.next().unwrap().parse().unwrap();
    let mut R = lines.take(n).map(|s| s.parse::<i32>().unwrap());

    // It would be good if we could just take max - min, but there is the
    // possibility that min comes after max... so we should consider both
    // the absolute max and min and the current one (which are candidates
    // for appearing in the final answer).
    // Notice that we do not use the absolute max, but calculate it for
    // completeness.
    let mut min;
    let mut max;
    let mut current_max;
    let mut current_min;

    let a = R.next().unwrap();
    let b = R.next().unwrap();
    current_max = b; current_min = a;
    if a > b { 
        min = b; max = a;
    } else {
        max = b; min = a;
    }
    
    for r in R {
        if r - min > current_max - current_min {
            current_max = r;
            current_min = min;
        }
        if r > max { max = r }
        if r < min { min = r }
    }

    let ans = current_max - current_min;
    println!("{}", ans);
}

// ------------------------------------------------------------------
// Auxiliary methods.
fn array_to_str(arr: &Vec<i32>) -> String {
    // Converts a numerical array to a string for output purposes.
    let mut ans = String::new();
    for a in arr {
        ans.push_str(&format!("{} ", *a));
    }
    return ans.trim().to_string();
}



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

int main()
{
  int n;cin>>n;
  vector<int> a(n);
  for(int i=0;i<n+1;i++)
    a.push_back(0);
  
  int b[n-1];
  for(int i=0;i<n-1;i++)
  {
    cin>>b[i];
    a[b[i]]++;
  }
  
  for(int i=1;i<=n;i++)
  {
    cout<<a[i]<<endl;
  }
  return 0;
}

Measured memory_bytes: 6280