akhauriyash/Code-Regression huggingface dataset:
// http://kmjp.hatenablog.jp/entry/2019/09/28/1030

import java.util.*;

public class Main {
  static Map<Integer, List<Integer>> edgeE = new HashMap<>();
  static List<Integer> vStack = new ArrayList<>(); // stack in DFS
  static int[] vStackState; // state of DFS.
  static List<Integer> cycle = new ArrayList<>();
  static Integer[] cycleSeqId; // id of cycle member.

  // Find cycle
  static void dfs(int cur) {
    if (vStackState[cur] == 2) { // Found node visited in current dfs. (a cycle)
      if (cycle.isEmpty()) {
        for (int i = 0; i < vStack.size(); i++) {
          if (vStack.get(i) == cur) { // Find starting point to avoid circle shape of `6`.
            for (int j = i; j < vStack.size(); j++) {
              cycle.add(vStack.get(j));
              cycleSeqId[vStack.get(j)] = j - i;
            }
            break;
          }
        }
      }
      return;
    }
    if (vStackState[cur] == 1) return;
    vStackState[cur] = 2;
    vStack.add(cur);
    for (Integer e : edgeE.get(cur)) {
      dfs(e);
    }
    vStack.remove(vStack.size() - 1);
    vStackState[cur] = 1;
  }

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    for (int i = 1; i <= N; i++) {
      edgeE.put(i, new ArrayList<>());
    }
    int M = sc.nextInt();
    for (int i = 0; i < M; i++) {
      int a = sc.nextInt();
      int b = sc.nextInt();
      edgeE.get(a).add(b);
    }
    cycleSeqId = new Integer[N + 1];
    vStackState = new int[N + 1]; // 1-indexed (skip 0-th)
    Arrays.fill(cycleSeqId, -1);
    /* Search cycle. */
    for (int i = 1; i <= N && cycle.isEmpty(); i++) {
      Arrays.fill(vStackState, 0);
      vStack.clear();
      dfs(i);
    }
    if (cycle.isEmpty()) {
      System.out.println("-1");
      return;
    }
    retry:
    for (int idxStart = 0; idxStart < cycle.size(); idxStart++) {
      Integer nodeIdxFrom = cycle.get(idxStart);
      for (Integer to : edgeE.get(nodeIdxFrom)) {
        if (
        /*member of cycle */ cycleSeqId[to] != -1
            && /* If path split. This is smaller cycle. */
          cycleSeqId[to] != (cycleSeqId[nodeIdxFrom] + 1) % cycle.size()) {
          List<Integer> C2 = new ArrayList<>();
          int newCycleSeqStartIdx = cycleSeqId[to]; // New starting point to avoid circle shape of `6`.
          Arrays.fill(cycleSeqId, -1);
          for (int j = 0; j < cycle.size(); j++) {
            Integer nodeIdx = cycle.get((newCycleSeqStartIdx + j) % cycle.size());
            C2.add(nodeIdx);
            cycleSeqId[nodeIdx] = j;
            if (nodeIdx.equals(nodeIdxFrom)) break;
          }
          cycle = C2;
          idxStart = -1;
          continue retry;
        }
      }
    }
    System.out.println(cycle.size());
    for (Integer c : cycle) {
      System.out.println(c);
    }
  }
}


Measured memory_bytes: 29716
n = int(input())
wlist = []
for i in range(n):
    wlist.append(input())
if len(wlist) != len(set(wlist)):
    print('No')
else:
    flag = True
    for i in range(n-1):
        flag = flag and (wlist[i][-1] == wlist[i+1][0])
    if flag == False:
        print('No')
    else:
        print('Yes')

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define ls rt<<1
#define rs rt<<1|1
#define lson rt<<1,l,M
#define rson rt<<1|1,M+1,r
#define PI acos(-1)
#define MM int M=(l+r)>>1;
#define fu(i,r,t) for(int i=r;i<=t;i++)
#define fd(i,r,t) for(int i=r;i>=t;i--)
#define fh(i,be,e) for(int i=head[be];~i;i=e[i].next)
#define fa(i,V) for(auto i:V)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define endl '\n'
#define lcm(a,b) (a*b)/__gcd(a,b)
#define cp(i,ans) printf("%.if",ans);
#define cpp(i,ans) cout<<setprecision(i)<<fixed<<ans<<endl;
#define ppb pop_back
#define ppf pop_front
#define pb push_back
#define pf push_front
#define pq priority_queue
#define lowbit(x) (x)&(-x)
#define all(V) V.begin(),V.end()
#define ms multiset
#define mod(x) ((x+mo_num)%mo_num)
#define vc vector
#define vct vector<int>
#define out(i) cout<<(i)<<endl;
#define fi first
#define se second
#define fun(i) fu(i,1,n)
#define fut(i) fu(i,1,t)
#define fum(i) fu(i,1,m)
#define ld long double
#define umap unordered_map
#define P pair<int,int>
#define SET set<int>
#define mp map<int,int>
#define mk make_tuple
#define low lower_bound
#define upp upper_bound
#define yn(key) out(key?"YES":"NO")
#define in(i) i+1,i+1+n
#define im(i) i+1,i+1+m
#define bffs(i) __builtin_ffs(i)
#define bcount(i) __builtin_popcount(i)
#define bone(i) ((1<<i)-1)
using namespace std;
const int INF=LLONG_MAX/2;
const int dx[]={0,0,-1,1},dy[]={-1,1,0,0};//up down left right
const int maxn=1e6+1e5;
const int mo_num=1e9+7;
int n,m,t,a[maxn],b[maxn],ans;
double c[maxn];
main()
{
    IOS
    fu(i,1,4)cin>>a[i];
    cout<<setprecision(9)<<fixed;
    a[3]%=12;
    c[3]=(double)(a[3]+(double)a[4]/(double)60)*(double)PI/(double)6;
    c[4]=(double)a[4]/(double)60*(double)2*(double)PI;
    double tt=abs(c[3]-c[4]);
    out(sqrt(a[1]*a[1]+a[2]*a[2]-2*a[1]*a[2]*cos(tt)))
    return 0;
}

Measured memory_bytes: 4248
#include<iostream>
#include<string>
#include<numeric>
#include<vector>
using namespace std;

int out(vector<int> &A,int n){
	int i;
	for (i=0;i<=n-2;i++){
		cout << A[i] <<" ";
	}
	cout << A[n-1] <<endl;
}

int main(){
	ios::sync_with_stdio(false);
	vector<char> C_list;
	char c;
	while(cin >> c){
		C_list.push_back(c);
	}
	
	vector<int> A_list;
	int n=C_list.size();
	int i=0;
	while(i<n){
		char s=C_list[i];
		if (s=='\\'){
			int j=i;
			int A2=1;
			int height=-1;
			while (height<0){
				j++;
				if (j==n){
					break;
				}
				char s2 = C_list[j];
				if (s2=='/'){
					A2+=(-2*height-1);
					height+=1;
				}else if(s2=='\\'){
					A2+=(-2*height+1);
					height-=1;
				}else{
					A2+=(-2*height);
				}
			}
			if (height ==0 ){
				A_list.push_back(A2/2);
				i=j;
			}
		}
		i++;
	}
	int A=accumulate(A_list.begin(),A_list.end(),0);
	cout << A << endl;
	if (A==0){
	cout << 0 << endl;	
	}else{
		int m = A_list.size();
		cout << m <<" ";
		out(A_list,m);
	}
	return 0;
}

Measured memory_bytes: 1272
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl

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

const int MOD = 1e9 + 7;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a, b; cin >> a >> b;
    cout << max({a + b, a - b, a * b});

    return 0;
}


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

int plate[5678][5678];

int n, m;

int main()
{
	memset(plate, 0, sizeof(plate));
	scanf("%d %d", &n, &m);
	for (int i = 0; i < m; ++i)
	{
		int a, b, x;
		scanf("%d %d %d", &a, &b, &x);
		--a; --b;
		++plate[a][b];
		--plate[a][b + 1];
		--plate[a + x + 1][b];
		++plate[a + x + 2][b + 1];
		++plate[a + x + 1][b + x + 2];
		--plate[a + x + 2][b + x + 2];
	}
	for (int i = 1; i <= n + 2; ++i)
	{
		for (int j = 1; j <= n + 2; ++j)
		{
			plate[i][j] += plate[i - 1][j - 1];
		}
	}
	for (int i = 0; i <= n + 2; ++i)
	{
		for (int j = 1; j <= n + 2; ++j)
		{
			plate[i][j] += plate[i][j - 1];
		}
	}
	for (int i = 1; i <= n + 2; ++i)
	{
		for (int j = 0; j <= n + 2; ++j)
		{
			plate[i][j] += plate[i - 1][j];
		}
	}

	int ans = 0;
	for (int i = 0; i <= n + 2; ++i)
	{
		for (int j = 0; j <= n + 2; ++j)
		{
			if (plate[i][j] > 0)++ans;
		}
	}

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

Measured memory_bytes: 128656
#include <iostream>

using namespace std;

int main(){
	int n;
	cin >> n;
	
	bool odd = false;
	long long pair = 0;
	
	for(int i = 0;i < n;i++){
		int x;
		cin >> x;
		
		if(x > 0 && odd){
			x--;
			pair++;
		}
		
		pair += x/2;
		if(x%2 == 1){
			odd = true;
		}else{
			odd = false;
		}
	}
	
	cout << pair << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){ 
    int n;
    cin>>n;
    int ans=0;
    if(n%10==7)ans++;
    if((n/10)%10==7)ans++;
    if(n/100==7)ans++;

    if(ans!=0)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
 
    return 0;
}

Measured memory_bytes: 3624
import java.util.Scanner;

class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        String a = sc.next();
        String b = sc.next();
        String c = sc.next();

        if (a.charAt(a.length() - 1) == b.charAt(0) && b.charAt(b.length() - 1) == c.charAt(0)) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }
    }
}

Measured memory_bytes: 23764
import re
for i in range(int(input())):
 s=input().replace(" ","")
 print(''.join(re.sub(r'0\w','',''.join([i+j for(i,j)in zip(str(10000+eval('+'.join([i[0]+{'m':'*1000','c':'*100','x':'*10','i':''}[i[1]]for i in ['1'+i for i in''.join(re.split(r'\d\w',s))]+re.findall(r'\d\w',s)])))[1:],list('mcxi'))])).split('1')))

Measured memory_bytes: 6584
#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;
using llong = long long;

llong n;
llong sum;
llong m;

int main() {

    while (scanf("%lld", &n), n != 0) {
        llong minv = 1ll << 60ll;
        llong maxv = -1;
        sum = 0;
        
        for (int i = 0; i < n; i++) {
            cin >> m;

            sum += m;

            minv = min(minv, m);
            maxv = max(maxv, m);
        }

        cout << (sum - maxv - minv) / (n - 2) << endl;
    };

    return 0;
}



Measured memory_bytes: 3132
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
int n,a,arr[4];
double dp[301][301][301];
int vis[301][301][301];
double f(double o,double t,double h){
	if(o+t+h==0)return 0;
	double &res=dp[(int)o][(int)t][(int)h];
	if(vis[(int)o][(int)t][(int)h])return res;
	if(o)res+=(f(o-1,t,h)*o);
	if(t)res+=(f(o+1,t-1,h)*t);
	if(h)res+=(f(o,t+1,h-1)*h);
	res+=n;
	res/=(o+t+h);
	vis[(int)o][(int)t][(int)h]=1;
	return res;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a;
		arr[a]++;
	}
	cout<<setprecision(10)<<fixed<<f(arr[1],arr[2],arr[3])<<endl;
	return 0;
}

Measured memory_bytes: 319744
#include<stdio.h>

int main(){
    long long int a,b,x;
    scanf("%lld%lld%lld",&a,&b,&x);

    long long int sum;
    if(a%x==0){
        sum=(b/x)-(a/x)+1;
    }else{
        sum=(b/x)-(a/x);
    }
    printf("%lld\n",sum);
    return 0;
}

Measured memory_bytes: 1732
#include<bits/stdc++.h>
            using namespace std;
            #define rep(i,b) for(i=0;i<b;++i)
            #define repp(i,a,b) for(i=a;i<b;++i)
            #define endl "\n"
            #define LLONG_MAX 99999999999999
            typedef long long int lli;
            int main(){
                lli i,t,n,m,k,q;
                cin>>n>>k>>q;
                vector<lli> v(n+1,0);
                rep(i,q){
					cin>>m;
					v[m]++;
                }
                repp(i,1,n+1){
					if(k-q+v[i]>0){
						cout<<"Yes"<<endl;
					}
					else{
						cout<<"No"<<endl;
					}
                }

                return 0;
            }

















Measured memory_bytes: 1408
n = int(input())
A = 0
B = 0
for i in range(n):
    animals = list(input().split())
    if animals[0] == animals[1]:
        A += 1
        B += 1
    else:
        A_sorted = sorted(animals)
        if animals[0] == A_sorted[1]:
            A +=3
        else:
            B += 3
print(A, B)


Measured memory_bytes: 5596
#include <iostream>

 

using namespace std;

 

int main()
{
    int a, b;
    cin >> a >> b;
    if (a > b)
       cout << "a > b" << endl;
    else if (a < b)
       cout << "a < b" <<endl;
    else
       cout << "a == b" << endl;
     
    return 0;
}


Measured memory_bytes: 3076
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll n,m=0,i,j,k,ans=1,MOD=1000000007;
  cin>>n;
  ll t[n],a[n];
  for(i=0;i<n;i++) cin>>t[i];
  for(i=0;i<n;i++) cin>>a[i];
  ll l=n-1,r=0;
  for(i=n-1;i>=0;i--){
    if(t[i]==t[l]) l=i;
  }
  for(i=0;i<n;i++){
    if(a[i]==a[r]) r=i;
  }
  //cout << l <<":"<<a[l]<<"/"<<r<<":"<<a[r]<<endl;
  if(r<l) ans*=0;
  if(t[l]!=a[r]) ans*=0;
  else m=a[l];

  k=-1;
  for(i=0;i<l;i++){
    if(k==t[i]) ans=(ans*k)%MOD;
    k=t[i];
  }
  for(i=l+1;i<r;i++){
    ans=(ans*m)%MOD;
  }
  k=-1;
  for(i=n-1;i>r;i--){
    if(k==a[i]) ans=(ans*k)%MOD;
    k=a[i];
  }
  cout << ans%MOD << endl;
  return 0;
}


Measured memory_bytes: 1792
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author yosiiii
 */


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

class BEcho {
public:
	void solve(std::istream& in, std::ostream& out) {
        string s;
        int n;
        in >> n >> s;
        if(n%2==0){
            rep(i,n/2){
                if(s[i]!=s[i+n/2]){
                    out << "No" << endl;
                    return ;
                }
            }
            out << "Yes" << endl;
            return ;
        }
        out << "No" << endl;
	}
};


int main() {
	BEcho solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <algorithm>
#include <numeric>
#include <fstream>
#include <iomanip>

typedef long double ld;
typedef long long ll;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1e9 + 7;

// Output
template<class T, class S> std::ostream& operator <<(std::ostream& os, std::pair<T, S> p)
{
  return os << "(" << p.first << " " << p.second << ")";
}

template<class T> std::ostream& operator <<(std::ostream& os, std::vector< T > v)
{
  for (ll i = 0; i < (ll)v.size(); i++){ os << " [" << i << "]" << v[i]; if (i % 10 == 9) os << std::endl; }
  //os << v[0]; for (ll i = 1; i < (ll)v.size(); i++){ os << " " << v[i]; }
  return os;
}

template<class T, class S> std::ostream& operator <<(std::ostream& os, std::map< T, S > m)
{
  ll i = 0; for (auto p : m){ os << " [" << i << "]" << p.first << "->" << p.second; i++;}
  return os;
}

template<class T> std::ostream& operator <<(std::ostream& os, std::vector< std::vector<T> > vv)
{
  for (auto& vec : vv){ os << vec << std::endl; }
  os << "--------" << std::endl;
  return os;
}

void print(){ std::cout << std::endl; }
template<typename H> void print(H&& head){ std::cout << head << std::endl; }
template<typename H, typename... T> void print(H&& head, T&&... tail){
  std::cout << head << " ", print(std::forward<T>(tail)...);
}

typedef enum {
  VERT,
  HORI,
} E_TYPE;

ll get_num_type(E_TYPE pre, E_TYPE now)
{
  if (pre == HORI && now == VERT) return 1;
  if (pre == HORI && now == HORI) return 3;
  return 2;
}

void solve()
{
  ll N;
  std::cin >> N;

  std::string S1, S2;
  std::cin >> S1 >> S2;

  std::vector<E_TYPE> vt;
  bool is_pre_checked = false;
  for (ll i = 0; i < N; i++) {
    if (S1[i] == S2[i]) {
      vt.push_back(VERT);
    } else {
      if (is_pre_checked) {
        vt.push_back(HORI);
        is_pre_checked = false;
      } else {
        is_pre_checked = true;
      }
    }
  }

  ll ans = (vt[0] == VERT) ? 3 : 6;
  ll M = vt.size();
  for (ll i = 1; i < M; i++) {
    ans = (ans * get_num_type(vt[i-1], vt[i])) % MOD;
  }

  print(ans);
  return;
}

int main()
{
  solve();
  return 0;
}



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

int main() {
  int N = 0;
  cin >> N;
  vector<int> W(N);
  for (int i = 0; i < N; ++i) {
    cin >> W.at(i);
  }

  int ans = INT_MAX;
  for (int t = 1; t < N; ++t) {
    int a1 = 0;
    int a2 = 0;
    int diff = 0;
    // t番目の重りのインデックスはt-1
    for (int i = 0; i < t; ++i) {
      a1 += W.at(i);
    }
    for (int i = t; i < N; ++i) {
      a2 += W.at(i);
    }
    diff = abs(a1-a2);
    ans = min(ans, diff);
  }
  cout << ans << endl;
  return 0;
}


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

int main(){
 int n, m, l;
 long long A[100][100], B[100][100], C[100][100];

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

 for ( int i = 0; i < n; i++ ){
  for ( int j = 0; j < l; j++ ){
   C[i][j] = 0;
   for ( int k = 0; k < m; k++ ){
    C[i][j] += A[i][k]*B[k][j];
   } 
  }
}

for ( int i = 0; i < n; i++){
for ( int j = 0; j < l; j++){
if (j) cout << " ";
cout << C[i][j];
}

cout << endl;
}

return 0;
}


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

        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();

        sc.close();
        System.out.println(C + " " + A + " " + B);
    }
}

Measured memory_bytes: 21844
S = input()

answer = 0
count = 0
for i in range(len(S)):
  if S[i] == 'A' or S[i] == 'C' or S[i] == 'G' or S[i] == 'T':
    count += 1
  else:
    count = 0
  answer = max(answer, count)
print(answer)

Measured memory_bytes: 61812
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int main(void){
  int N;
  cin >> N;
  vector<int> x(N);
  int sum = 0;

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

  double mean = static_cast<int>(std::round((double)sum / (double)N));
  int ret = 0;

  for(int i = 0; i < N; i++)
    ret += (x[i] - mean) * (x[i] - mean);

  cout << ret << endl;
  
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(begin, i, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int gcd(int a, int b)
{
    if (b == 0)
    {
        return a;
    }

    return gcd(b, a % b);
}

int main()
{
    int N;
    cin >> N;
    vector<int> X(N + 1);
    rep(0, i, N + 1)
    {
        cin >> X[i];
    }
    sort(all(X));
    int ans = 0;
    rep(0, i, N)
    {
        ans = gcd(X[i + 1] - X[i], ans);
    }
    cout << ans << endl;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int INF = 0x3f3f3f3f;
const ll inf = 0x3f3f3f3f3f3f3f3f;
const ll mod = 1e9 + 7;
const int N = 1e6 + 10;
int n;
char c[N];
int cnt[10];
int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%s", c);
		if (c[0] == 'A')cnt[0]++;
		else if (c[0] == 'W')cnt[1]++;
		else if (c[0] == 'T')cnt[2]++;
		else cnt[3]++;
	}
	printf("AC x %d\n", cnt[0]);
	printf("WA x %d\n", cnt[1]);
	printf("TLE x %d\n", cnt[2]);
	printf("RE x %d\n", cnt[3]);
	return 0;
}

Measured memory_bytes: 3824
// #pragma GCC optimize("Ofast,unroll-loops")
// #pragma GCC target("avx,avx2,fma")

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ull unsigned long long
#define dd double
#define ld long double
#define sl(n) scanf("%lld", &n)
#define si(n) scanf("%d", &n)
#define sd(n) scanf("%lf", &n)
#define pll pair <ll, ll>
#define pii pair <int, int>
#define mp make_pair
#define pb push_back
#define all(v) v.begin(), v.end()
#define inf (1LL << 61)
#define loop(i, start, stop, inc) for(ll i = start; i <= stop; i += inc)
#define for1(i, stop) for(ll i = 1; i <= stop; ++i)
#define for0(i, stop) for(ll i = 0; i < stop; ++i)
#define rep1(i, start) for(ll i = start; i >= 1; --i)
#define rep0(i, start) for(ll i = (start-1); i >= 0; --i)
#define ms(n, i) memset(n, i, sizeof(n))
#define casep(n) printf("Case %lld:", ++n)
#define pn printf("\n")
#define pf printf
#define EL '\n'
#define fastio std::ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

const ll sz = 2e5 + 10;

ll par[sz], siz[sz];

ll findPar(ll u)
{
    if(par[u] == u)
        return u;

    return par[u] = findPar(par[u]);
}

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

    for1(i, n) par[i] = i, siz[i] = 1;

    for1(i, m) {
        ll u, v;
        sl(u), sl(v);

        ll pu = findPar(u), pv = findPar(v);

        if(pu == pv)
            continue;

        par[pv] = pu;
        siz[pu] += siz[pv];
    }

    ll ans = 0;
    for1(i, n) ans = max(ans, siz[i]);

    cout << ans << EL;

    return 0;
}


Measured memory_bytes: 6880
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[] r = new int[n];
		int[] c = new int[m*2];
		for(int i=0; i<m*2; i++){
			c[i] = sc.nextInt();
		}
		for(int i=0; i<m*2; i++){
			r[c[i]-1]++;
		}
		for(int i=0; i<n; i++){
			System.out.println(r[i]);
		}
	}
}

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

template<typename T>
T get_value(std::istream& is);

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

  int N;
  string S;
  cin >> N >> S;

  auto res {0};
  for (auto it {S.begin()}; it != prev(S.end(), 2); ++it) {
    auto tar {"ABC"};
    if (equal(it, next(it, 3), tar, tar + 3))
      ++res;
  }

  cout << res << '\n';

  return 0;
}

template<typename T>
inline T get_value(std::istream& is)
{
  T v;
  is >> v;
  return v;
}


Measured memory_bytes: 892
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>
#include<deque>
#include<tuple>
#include<queue>
#include<map>
#include<cstdint>
#include<unordered_map>
#include<boost/multiprecision/cpp_int.hpp>


#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define Endl endl
#define F first
#define S second

namespace mp = boost::multiprecision;

using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;
int a[10] = { 7,11,13,14,19,21,22,25,26,28 };

int main() {
	int n;
	cin >> n;
	vector<int>MARCH(5);
	string m = "MARCH";
	rep(i, n) {
		char s[10];
		scanf("%s",s);
		rep(j, 5) {
			if (s[0] == m[j]) {
				MARCH[j]++;
				j = 5;	
		    }
	    }
	}
	ll ans = 0;
	rep(k, 10) {
		ll tmp = 1;
		rep(m, 5) {
			if (a[k]&(1 << m)) {
				tmp *= MARCH[m];
			}
		}
		ans += tmp;	
	}
		
		
	cout << ans << endl;
}



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

int d, e, q, t1, t2, cnt, con[10005];
vector <int> v[10005], vr[10005], order;
bool vis[10005], vis1[10005];

void dfs0(int u) {
	vis[u] = 1;
	for (int i : v[u]) {
		if (!vis[i]) dfs0(i);
	}
	order.push_back(u);
}

void dfs1(int u, int com) {
	con[u] = com, vis1[u] = 1;
	for (int i : vr[u]) {
		if (!vis1[i]) dfs1(i, com);
	}
}

int main() {
	cin >> d >> e;
	for (int i = 0; i < e; i++) {
		cin >> t1 >> t2;
		v[t1].push_back(t2);
		vr[t2].push_back(t1);
	}
	for (int i = 0; i < d; i++) {
		if (!vis[i]) dfs0(i);
	}
	for (int i = 0; i < d; i++) {
		t1 = order[d - i - 1];
		if (!vis1[t1]) dfs1(t1, cnt++);
	}
	cin >> q;
//	for (int i = 0; i < d; i++) cout << con[i] << ' ';
//	cout << endl;
	for (int i = 0; i < q; i++) {
		cin >> t1 >> t2;
		if (con[t1] == con[t2]) cout << 1 << endl;
		else cout << 0 << endl;
	}
}



Measured memory_bytes: 4840
#include <bits/stdc++.h>
#define lli long long int
#define pb push_back
#define mod2 998244353
#pragma GCC optimize("-O2")
#define mod3 127
#define mod 1000000007
#define MAXN 1000000000
#define v32 vector<int>
#define v64 vector<lli>
#define v1024 vector<vector<int>>
#define v4096 vector<vector<lli>>
#define vt vector
#define f(x, y, z) for (lli x = y; x < z; x++)
#define fd(x, y, z) for (lli x = y; x > z; x--)
#define lb lower_bound
#define ld long double
#define m64 map<lli, lli>
#define m32 map<int, int>
#define m64it map<lli, lli>::iterator
#define m32it map<int, int>::iterator
#define fastio                    \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0)
#define ist insert
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define p_q priority_queue
#define min_p_q priority_queue<int, vt<int>, greater<int>>
using namespace std;
using namespace __gnu_pbds;
lli tmod(lli x, lli y)
{
    return (x % y + y) % y;
}
template <typename T>
void DEBUG_ARR(vt<T> a)
{
    f(i, 0, a.size()) cout << a[i] << " ";
    cout << "\n";
}
lli power(lli x, lli y) 
{
    lli res = 1;  
    while (y > 0) 
    { 
        if (y & 1) 
            res = (res*x); 
        y = y>>1; 
        x = (x*x);
    }
    return res; 
}


int main()
{
    fastio;
    int n;
    cin>>n;
    v32 p(n),q(n);
    f(i,0,n)cin>>p[i];
    f(i,0,n)cin>>q[i];
    v32 x(n);f(i,0,n)x[i]=i+1;
    int a=0,b=0;
    while(1){
        if(p==x)break;
        a++;
        //DEBUG_ARR(x);
        next_permutation(x.begin(),x.end());
    }
    f(i,0,n)x[i]=i+1;
    while(1){
        if(q==x)break;
        b++;
       // DEBUG_ARR(x);
        next_permutation(x.begin(),x.end());
    }
    cout<<abs(a-b)<<"\n";

    return 0;
}


Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  n,k=LI()

  l=[]
  for _ in range(n):
    l.append(LI())

  l=sorted(l,key=lambda x:x[0])

  sm=0
  for i in range(n):
    sm+=l[i][1]

    if sm>=k:
      return l[i][0]

print(main())


Measured memory_bytes: 32304
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Map;
import java.util.Map.Entry;

import java.util.PriorityQueue;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class Main {
	
	public static void main(String[] args) throws IOException {
		try(final Scanner sc = new Scanner(System.in)){
			final int N = sc.nextInt();
			final int Q = sc.nextInt();
			final char[] chs = sc.next().toCharArray();
			
			int[] prefix_ACs = new int[N + 1];
			
			for(int i = 1; i < N; i++) {
				if(chs[i - 1] == 'A' && chs[i] == 'C') {
					prefix_ACs[i + 1] = 1;
				}
			}
			for(int i = 1; i <= N; i++) {
				prefix_ACs[i] += prefix_ACs[i - 1];
			}

			for(int q = 0; q < Q; q++) {
				final int l = sc.nextInt() - 1;
				final int r = sc.nextInt() - 1;
				
				System.out.println(prefix_ACs[r + 1] - prefix_ACs[l + 1]);
			}
		}
	}

	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;

		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}

		private void getLine() throws IOException {
			while(!hasNext()){
				tok = new StringTokenizer(br.readLine());
			}
		}

		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}

		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}

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

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

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

		public int[] nextIntArray(int n) throws IOException {
			final int[] ret = new int[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextInt();
			}
			return ret;
		}

		public long[] nextLongArray(int n) throws IOException {
			final long[] ret = new long[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextLong();
			}
			return ret;
		}

		public void close() throws IOException {
			br.close();
		}
	}
}

Measured memory_bytes: 65832
import sys,heapq
from collections import deque,defaultdict
printn = lambda x: sys.stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
DBG = True # and False
def ddprint(x):
  if DBG:
    print(x)

n,m = inm()
s = [0] * m
for i in range(m):
    z = inl()
    s[i] = z[1:]
p = inl()

sum = 0
for i in range(2**n):
    b = []
    for j in range(n):
        b.append((i>>j)%2)  # i to bits
    ok = True
    for j in range(m): # for each bulb
        x = 0
        for k in s[j]:  # switches for bulb J
            x += b[k-1]
        if x%2 != p[j]:
            ok = False
            break
    if ok:
        sum += 1

print(sum)


Measured memory_bytes: 3316
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;
int main() {
    int H, W;
    cin >> H >> W;
    int colorMap [H][W];
    int N;
    cin >> N;
    int _h=0, _w=0;

    bool reverse = false;
    for(int i=1; i <= N ; i++) {
        int A;
        cin >> A;
        for(int j = 0; j < A ; j++) {
            if( _w == W ) {
                _h++;
                _w = 0;
                reverse = !reverse;
            }
            if( reverse ) {
                colorMap[_h][W - 1 - _w ] = i;
            } else {
                colorMap[_h][_w] = i;
            }
            _w++;
            //反転
        }
    }

    // 出力
    for(int i=0; i < H ; i++) {
        for(int j=0; j < W ; j++) {
            if( j < W-1) {
                cout << colorMap[i][j] << " ";
            } else {
                cout << colorMap[i][j] << endl;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 384
#include <iostream>

int main(){
   int K, X;
   std::cin >> K >> X;

   int min = std::max(-1000000, X-K+1);
   int max = std::min( 1000000, X+K-1);
   for(int i=min; i<=max; ++i){
      std::cout << i << ' ';
   }
   std::cout << std::endl;
   return 0;
}


Measured memory_bytes: 256
using System;

namespace ABC082_A_Round_Up_the_Mean
{
	internal class Program
	{
		public static void Main(string[] args)
		{
			string[] input = Console.ReadLine().Split(' ');
			int a = int.Parse(input[0]);
			int b = int.Parse(input[1]);

			if ((a + b) % 2 == 0)
			{
				Console.WriteLine((a + b) / 2);
			}
			else
			{
				Console.WriteLine((a + b) / 2 + 1);
			}
		}
	}
}

Measured memory_bytes: 11092
#define NOMINMAX
#include <iostream>
#include <string>
#include <algorithm>
#include <iterator>
#include <functional>
#include <vector>
#include <iomanip>
#include <numeric>
using namespace std;

int main()
{
	int A, B, C;
	cin >> A >> B >> C;

	int sum = A + B + C;
	int mx = max(A, max(B, C));

	if (sum % 2 != mx * 3 % 2)
	{
		mx += 1;
	}

	int ans = (mx * 3 - sum) / 2;

	cout << ans << endl;

	return 0;
}

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

int main(){
  ll  n,d ; cin>>n>>d  ;
  
  
  if(n%(2*d+1)==0)
  cout<< n/(2*d+1)  <<endl;
  else cout<< n/(2*d+1) +1 <<endl;
}

Measured memory_bytes: 256
//#include<bits/stdc++.h>
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<string>
#include<cmath>
#include<cassert>
#include<map>
  using namespace std;

typedef long long ll;
typedef ll int__;
#define rep(i,j) for(int__ (i)=0;(i)<(j);(i)++)
#define repeat(i,j,k) for(int__ i=(j);i<(k);(i)++)
#define all(v) begin(v),end(v)


int main()
{
  while(true){
    int e;cin>>e;
    if(e==0)break;

    int m = 1<<30;
    for(int z=100;z>=0;z--){
      if(z*z*z>e)continue;
      for(int y=1000;y>=0;y--){
        if(z*z*z+y*y>e)continue;
        m=min(z+y+e-y*y-z*z*z,m);
      }
    }
    cout<<m<<endl;
  }
  return 0;
}

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

int main(void){

  char s[100];
  int i,N,flag=0;

  scanf("%s",s);
  N=strlen(s);

  for(i=0;i<N/2;i++){
    if(s[i]!=s[N-i-1])flag=1;
  }
  if(flag!=1){
    for(i=0;i<(N-1)/2;i++){
      if(s[i]!=s[(N-1)/2-i-1])flag=1;
    }
  }
  if(flag!=1){
    for(i=(N+3)/2-1;i<N;i++){
      if(s[i]!=s[N-i-1])flag=1;
    }
  }
  if(flag==1)printf("No");
  else printf("Yes");


  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define mods 1000000007
#define pb push_back
#define mp make_pair
#define st first
#define nd second
typedef long long int lint;
typedef unsigned long long int ulint;
list <lint> graph[100020];
lint hesap(lint a,bool b,lint ata);
lint n,k,dp[100020][2];
bool visit[100020][2];
int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    lint a,b,i,j,l,il;
    cin>>n;
    for(i=0;i<n-1;i++){
        cin>>a>>b;
        graph[a].pb(b);
        graph[b].pb(a);
        }
    cout<<(hesap(1,0,0)+hesap(1,1,0))%mods;
    return 0;
}
lint hesap(lint a,bool b,lint ata){
    if(visit[a][b]==true) return dp[a][b];
    visit[a][b]=true;
    lint cev=1;
    list <lint> :: iterator it;
    if(b==false){
        for(it=graph[a].begin();it!=graph[a].end();it++){
            if(*it!=ata) cev=cev*(hesap(*it , 0 ,a)+hesap(*it , 1 , a))%mods;
            }
        dp[a][b]=cev;
        return cev;
        
    }else{
        for(it=graph[a].begin();it!=graph[a].end();it++){
            if(*it!=ata) cev=cev*(hesap(*it,0,a))%mods;
            }
        dp[a][b]=cev;
        return cev;

        
    }
    
    
    
    }

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

typedef long long int ll;

int main()
{
    ll n, cnt = 0, ans = 1;
    bool f = true;
    cin >> n;
    vector<ll> a(n);
    for(ll i = 0;i < n;i++){
        cin >> a[i];
    }
    sort(a.begin(),a.end());

    if(n % 2 != 0){
        ll t = 2;
        for(ll i = 1;i < n - 1;i = i + 2){
            if(a[i] == a[i + 1] && t == a[i]){
                cnt++;
            }
            else{
                f = false;
            }
            t += 2;
        }
    }
    else{
        ll t = 1;
        for(ll i = 0;i < n - 1;i = i + 2){
            if(a[i] == a[i + 1] && t == a[i]){
                cnt++;
            }
            else{
                f = false;
            }
            t += 2;
        }
    }

    for(ll i = 0;i < cnt;i++){
        ans *= 2;
        ans %= 1000000007;
    }

    if(f){
        cout << ans;
    }
    else{
        cout << 0;
    }
    return 0;
}

Measured memory_bytes: 1024
#include<cstdio>
#include<algorithm>
#define fo(i,a,b) for(i=a;i<=b;i++)
#define fd(i,a,b) for(i=a;i>=b;i--)
using namespace std;
typedef long long ll;
const int maxn=500000+10,mo=998244353;
int fac[maxn*2],inv[maxn*2];
int i,j,k,l,t,n,m,ans;
int qsm(int x,int y){
	if (!y) return 1;
	int t=qsm(x,y/2);
	t=(ll)t*t%mo;
	if (y%2) t=(ll)t*x%mo;
	return t;
}
int C(int n,int m){
	if (n<m||m<0) return 0;
	return (ll)fac[n]*inv[m]%mo*inv[n-m]%mo;
}
int main(){
	scanf("%d%d",&n,&m);
	if (n<m) swap(n,m);
	fac[0]=1;
	fo(i,1,n*2) fac[i]=(ll)fac[i-1]*i%mo;
	inv[n*2]=qsm(fac[n*2],mo-2);
	fd(i,n*2-1,0) inv[i]=(ll)inv[i+1]*(i+1)%mo;
	fo(i,1,m)
		(ans+=(ll)C(2*i,i)*C(n+m-2*i,n-i)%mo)%=mo;
	ans=(ll)ans*qsm(2*C(n+m,n)%mo,mo-2)%mo;
	(ans+=n)%=mo;
	(ans+=mo)%=mo;
	printf("%d\n",ans);
}

Measured memory_bytes: 7936
import copy
def BubbleSort(C, N):
    for i in range(N):
        for j in reversed(range(i+1, N)):
            if C[j][1:2] <  C[j-1][1:2]:
                C[j], C[j-1] = C[j-1], C[j]

    print(*C)
    stableCheck(C, N)

def SelectionSort(C, N):
    for i in range(N):
        minj = i
        for j in range(i, N):
            if C[j][1:2] <  C[minj][1:2]:
                minj = j
        C[i], C[minj] = C[minj], C[i]
    print(*C)
    stableCheck(C, N)

def stableCheck(C, N):
    global lst
    flag = 1
    for i in range(N):
        for j in range(i+1, N):
            if lst[i][1:2] == lst[j][1:2]:
                fir = lst[i]
                sec = lst[j]
                for k in range(N):
                    if C[k] == fir:
                        recf = k

                    if C[k] == sec:
                        recs = k
                
                if recf > recs:
                    print("Not stable")
                    flag = 0
                    break
        
        if flag ==0:
            break

    if flag :
        print("Stable")

N = int(input())
lst = list(map(str, input().split()))
lst1 = copy.deepcopy(lst)
lst2 = copy.deepcopy(lst)

BubbleSort(lst1, N)
SelectionSort(lst2, N)


Measured memory_bytes: 6344
from collections import deque

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

b = deque([])

if n % 2 == 0:
    flag = True
else:
    flag = False

for i in range(n):
    if flag:
        b.append(a[i])
        flag = not flag
    else:
        b.appendleft(a[i])
        flag = not flag

print(' '.join(map(str, b)))

Measured memory_bytes: 117068
//Author- VMAX


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_multiset tree<long long , null_type,less_equal<long long >, rb_tree_tag,tree_order_statistics_node_update>
#define ordered_set tree<long long , null_type,less<long long >, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
#define ll long long int
#define YES cout<<"YES"<<"\n";
#define NO cout<<"NO"<<"\n";
#define ld     long double 
#define yes cout<<"yes"<<"\n";
#define no cout<<"no"<<"\n";
#define No cout<<"No"<<"\n";
#define Yes cout<<"Yes"<<"\n";
#define f(i,a) for(i=0;i<a;i++)
#define fo(i,a) for(i=1;i<=a;i++)
#define fa(i,a) for(auto i:a)
#define r(i,a) for(auto i=a.rbegin();i!=a.rend();i++)
#define en cout<<"\n";
#define ull unsigned long long int
#define o(x) cout<<x<<"\n";
#define o1(x) cout<<x<<" ";
#define pb push_back
#define F first
#define in insert
#define mp make_pair
#define S second
#define pre(n) cout<<fixed<<setprecision(n);
#define      gcd(a,b)    __gcd(a,b)
#define bs            binary_search
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define test ll t;cin>>t;while(t-->0)
const ll Mod = 998244353;
#define mod 1000000007
#define pi 3.14159265358979323846
#define all(x) x.begin(),x.end()
#define re return 0;
// *#######################################################################################*

/*
bool isp(ll n)
{
    ll i;
    for(i=2;i*i<=n;i++)
    {
        if(n%i==0)
        {
            return false;
        }
        
    }
}
  */      
       int main()
       
       {
        fast
        
        
       ll n,l;
       cin>>n>>l;
       ll i,s=0;
     fo(i,n)
     {
         s+=l+i-1;
     }
     ll mi=1e18,m=0;
     fo(i,n)
     {
         ll t=s;
         t-=l+i-1;
         if(abs(s-t)<mi)
         {
             mi=abs(s-t);
             m=t;
         }
     }
     
        o(m)
        
 
          re
}


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

public class Hello
{
    public static void Main()
    {
        var aL = "abcdefghijklmnopqrstuvwxyz";
        var d = new Dictionary<char, int>();
        for (int i = 0; i < 26; i++) d[aL[i]] = 26 - i;
        d['a'] = 0;
        var s = Console.ReadLine().Trim();
        var k = long.Parse(Console.ReadLine().Trim());
        var res = s.ToCharArray();
        for (int i = 0; i < s.Length; i++)
        {
            var w = d[s[i]];
            if (k - w >= 0) { res[i] = 'a'; k -= w; }
        }
        if (k > 0)
        {
            var w2 = d[res[res.Length - 1]] - (k % 26);
            if (w2 < 0) w2 += 26;
            var w3 = d.Where(x => x.Value == w2).First().Key;
            res[res.Length - 1] = w3;
        }
        Console.WriteLine(new string(res));
    }
}


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

using E = System.Linq.Enumerable;

public class Program
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine());
        var seqA = Console.In.ReadToEnd().Split(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries);

        var set = new HashSet<string>(seqA);

        Console.WriteLine(set.Count);
    }
}


Measured memory_bytes: 51220
#include<stdio.h>
int main()
{
    int A,B;
    scanf("%d",&A);
    scanf("%d",&B);
    if(A==1 && B==2)
    {
    printf("3\n");
    }
    else if(A==2 && B==3)
    {
    printf("1\n");
    }
    else if(A==3 && B==1)
    {
    printf("2\n");
    }
    else if(A==1 && B==3)
    {
        printf("2\n");
    }
    else if(A==2 && B==1)
    {
        printf("3\n");
    }
    else if(A==3 && B==2)
    {
        printf("1\n");
    }
    return 0;
}


Measured memory_bytes: 128
import sys
import math
import bisect

def solve(n, m):
    for i in range(m + 1):
        if i > n:
            break
        if (n - i) % 500 == 0:
            return True
    return False

def main():
    n = int(input())
    m = int(input())
    if solve(n, m):
        print('Yes')
    else:
        print('No')

if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
import Control.Monad
import Data.Array
main = do
  [n,q] <- map read . words <$> getLine
  s <- getLine
  lrs <- replicateM q (map read . words <$> getLine) :: IO [[Int]]
  let arr = array (1,n) . zip [1..n] $ ac 0 s
  mapM_ (\[l,r] -> print $ getLR l r arr) lrs

ac :: Int -> String -> [Int]
ac acc [] = []
ac acc [_] =  [acc]
ac acc (a:c:s)
  | [a,c] == "AC" = acc : (acc+1) : ac (acc+1) (s)
  | otherwise     = acc : ac acc (c:s)
  
getLR :: Int -> Int -> Array Int Int -> Int
getLR l r arr = (arr ! r) - (arr ! l)

Measured memory_bytes: 80252
n = int(input())
sp = [list(input().split()) for _ in range(n)]
for i in range(len(sp)):
    sp[i][1] = int(sp[i][1])
d = sorted(sp, key=lambda x:(x[0],-x[1]))
for i in range(len(sp)):
    print(sp.index(d[i])+1)

Measured memory_bytes: 3060
#include<iostream>
#include<stdio.h>
#include<string>
#include<cmath>
#include<math.h>
#include<vector>
#include<queue>
#include<algorithm>
#include<map>
#include<unordered_map>
#define rep(i,n) for(ll i = 0; i < (n); i++)
#define rep2(i,n) for(int i = (n - 1); i >= 0; i--)
#define PI 3.141592653589793

using namespace std;
using ll = long long;

int to[200000];
const int si[] = { -1,0,1,0 };
const int sj[] = { 0,-1,0,1 };

int main() {

	ll n;
	ll md = 1000000007;
	ll sum = 0;
	cin >> n;
	vector<int> a(n);
	rep(i, n) {
		cin >> a[i];
		sum += a[i];
		sum %= md;
	}
	ll ans = 0;
	rep(i, n) {
		sum -= a[i];
		if (sum < 0) sum += md;
		ans += (a[i] * sum);
		ans %= md;
	}
	cout << ans << endl;
	return 0;
}

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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

int main() {
	int n = ri();
	int one = ri();
	int score[3];
	for (int i = 0; i < 3; i++) score[i] = ri();
	std::string s;
	std::cin >> s;
	int te[n];
	for (int i = 0; i < n; i++) {
		if (s[i] == 'r') te[i] = 2;
		else if (s[i] == 's') te[i] = 0;
		else if (s[i] == 'p') te[i] = 1;
	}
	
	int dp[n][3];
	memset(dp, 0, sizeof(dp));
	int res = 0;
	for (int i = 0; i < one; i++) {
		dp[i][te[i]] = score[te[i]];
		int last = i;
		for (int j = i + one; j < n; j += one) {
			for (int k = 0; k < 3; k++) {
				for (int l = 0; l < 3; l++) {
					if (k == l) continue;
					dp[j][l] = std::max(dp[j][l], dp[j - one][k] + (l == te[j] ? score[l] : 0));
				}
			}
			last = j;
		}
		res += *std::max_element(dp[last], dp[last] + 3);
	}
	
	std::cout << res << std::endl;
	
	return 0;
}




Measured memory_bytes: 2048
#include <stdio.h>

int main(void) {
	int n,x,t;
	int count;
	int ans;
	
	scanf("%d%d%d",&n,&x,&t);
	count = (n/x);
	if(n%x == 0){
		ans = (count)*t;
	}
	else{
		ans = (count+1)*t;
	}
	printf("%d",ans);
	
	
}


Measured memory_bytes: 1732
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    int k = -1;
    REP(i, 2, 1000) {
        if (i * (i - 1) / 2 == N) k = i;
    }
    if(k == -1) {
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;
    cout << k << endl;
    vector<int> v[100010];
    int a = 0, b = 1;
    rep(i, N) {
        v[a].push_back(i + 1);
        v[b].push_back(i + 1);
        b++;
        if(b == k) {a++; b = a + 1;}
    }
    rep(i, k) {
        cout << v[i].size();
        for(auto& e: v[i]) {
            cout << " " << e;
        }
        cout << endl;

    }

    return 0;
}
// 1
// 1 1

// 3
// 1 2 3 x x
// 1 2 3 x   x
// 1 2 3   x x

// 6
// 1 2 3 4 5 6 x x x
// 1 2 3 4 5 6 x     x x 
// 1 2 3 4 5 6   x   x   x   
// 1 2 3 4 5 6     x   x x  

Measured memory_bytes: 4736
#include<bits/stdc++.h>
#define fo(i,a,b) for(int i=(a);i<(b);i++)
#define qi queue<int>
#define vi vector<int>
#define ll long long
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define fi first
#define se second
#define prq priority_queue
#define foreach(it,c) for(__typeof((c).begin()) it=c.begin();it!=c.end();it++)
//#define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1:0)
using namespace std;
inline ll read(){
	ll x=0;
	int f=1;
	char c=getchar();
	for(;!isdigit(c);c=getchar()) if(c=='-')f=-f;
	for(;isdigit(c);c=getchar())x=x*10+(c-'0');
	return x*f;
}
inline void out(int x){
	if(x>=10)out(x/10);
	putchar(x%10+'0');
}
string s,t; 
int main(){
	//freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
	cin>>s>>t;
	int ans=5555,c;
	fo(i,0,s.size()-t.size()+1){
		c=0;
		fo(j,0,t.size()) if(s[i+j]!=t[j])c++;
		ans=min(ans,c);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string>
#include <map>
#include <queue>
#include <vector>
#include <cstdlib>
#define mp make_pair
#define pb push_back
#define mem(i,a) memset(i,a,sizeof(i))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
const int DMAX=500010+5;
const int MOD=1000000000+7;
template<class T> inline void read(T &x){
    x=0;
    T f=1;
    char ch=getchar();
    while(ch<'0' || ch>'9'){
        if(ch=='-'){
            f=-1;
        }
        ch=getchar();
    }
    while(ch<='9' && ch>='0'){
        x=x*10+(ch-'0');
        ch=getchar();
    }
    x*=f;
}
ll n,m;
ll a[DMAX];
ll ans=0;
bool b[DMAX];
int main(){
    mem(b,1);
    read(n),read(m);
    for(ll i=1;i<=n;i++){
        read(a[i]);
    }
    ll x,y;
    for(ll i=1;i<=m;i++){
        read(x),read(y);
        if(a[x]>a[y]){
            b[y]=0;
        }
        if(a[x]<a[y]){
            b[x]=0;
        }
        if(a[x]==a[y]){
            b[x]=b[y]=0;
        }
    }
    for(ll i=1;i<=n;i++){
        if(b[i])
        {
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}

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

using ll = int64_t;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
  for (auto val : array)
    std::cout << val << ", ";
  std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << std::setprecision(10);

  int n; std::cin >> n;
  ll sum = 0;
  vi a(n);
  rep(i, n) std::cin >> a[i], sum += a[i];
  vi x(n, -sum);
  x[0] = sum;
  for (int i = 1; i < n; i+=2) x[0] -= 2*a[i];
  rep(i, n-1) x[i+1] = 2 * a[i] - x[i];
  rep(i, n) std::cout << x[i] << (i < n-1 ? ' ' : '\n');
}


Measured memory_bytes: 2176