akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
#define PI 3.141592653589793


const int maxV = 211111;
vector<int> G[211111];// 頂点情報のみのグラフ
int tmp[211111];

// treeDFS(親, 現在地, 根から現在地までの距離, 根からの最大の距離, 根から最大の距離となる頂点
void treeDFS(int from, int current, int dist, int &maxDist, int &maxVertex) {
    // 距離と終点を更新
    if (dist > maxDist) {
        maxDist = dist;
        maxVertex = current;
    }

    for (auto to : G[current]) {
        // 逆流を防ぐ
        if (to == from) continue;
        treeDFS(current, to, dist + 1, maxDist, maxVertex);
    }
}

void getTreeDiameter() {
    int start = 0, end = 0, maxDist = 0;
    treeDFS(-1, start, 0, maxDist, end);
    start = end, end = 0, maxDist = 0;
    treeDFS(-1, start, 0, maxDist, end);
    printf("start: %d, end: %d, diameter: %d\n", start, end, maxDist);
}

void DFS(int a, int b, int c){
  tmp[a] = c;
  for(int k:G[a]){
    if(k==b) continue;
    DFS(k, a, 1-c);
  }
}
    
int main(){
  int N; cin >> N;
  rep(i, N-1){
    int a, b; cin >> a >> b; a--; b--;
    G[a].push_back(b); G[b].push_back(a);
  }
  DFS(0, -1, 0);
  int cnta=0, cntb=0, cntc=1, ki=0, gu=0; int ans[N];
  bool kyokutan = false;
  rep(i, N){
    if(tmp[i]%2 && 3*cnta+1<=N){
      ans[i] = 3*cnta + 1; cnta++;
    }
    else if(tmp[i]%2==0 && 3*cntb+2<=N){
      ans[i] = 3*cntb + 2; cntb++;
    }
    else if(3*cntc<=N){
      ans[i] = 3*cntc; cntc++;
    }
    else{
      kyokutan = true; break;
    }
  }
  cnta=0, cntb=0, cntc=1;
  int cnt = 0, check;
  if(kyokutan){
    rep(i, N){
      if(tmp[i]%2) ki++;
      else gu++;
    }
    if(ki>gu) check = 0;
    else check = 1;
    rep(i, N){
      if(tmp[i]%2==check){
        ans[i] = 3*cntc;
        cntc++;
      }
      else{
        if(cnt%2==0 && 3*cnta+1<=N){ans[i] = 3*cnta + 1; cnta++;}
        else if(cnt%2 && 3*cntb+2<=N){ans[i] = 3*cntb + 2; cntb++;}
        else if(3*cntc<=N){
          ans[i] = 3*cntc; cntc++;
        }
        else{
          cout << -1 << endl; return 0;
        }
        cnt++;
      }
    }
  }
  rep(i, N){
    cout << ans[i] << endl;
  }
}

Measured memory_bytes: 18688
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n, k = list(map(int, readline().split()))
    h = list(map(int, readline().split()))
    cnt = 0
    for i in range(n):
        if h[i] >= k:
            cnt += 1
    print(cnt)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 50160
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <cmath>

#define mst(a,b)memset(a, b, sizeof(a))
#define repi(a,b)for(ll i = a; i < b; i++)
#define repj(a,b)for(ll j = a; j < b; j++)
#define pii pair<int,int>

#ifdef LOCAL
#define fre()freopen("in.txt","r",stdin)
#endif
#ifndef LOCAL
#define fre()
#endif

//static int x = []() {
//	std::ios::sync_with_stdio(false);
//	std::cin.tie(NULL);
//	return 0;
//}();

#define FASTIO
#ifdef FASTIO
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
//#define scanf abcabc
//#define printf abcabc
#endif
//#ifndef FASTIO
//#define cin abcabc
//#define cout abcabc
//#endif

typedef long long ll;
typedef unsigned long long ull;
const int INF = 0x3f3f3f3f;
const ll LLINF = 0x3f3f3f3f3f3f3f3f;

using namespace std;


int rifa[20][20];
int main() {
	fre(); IOS;
	int n, m; cin >> n >> m;
	repi(0, m) {
		int k; cin >> k;
		repj(0, k) {
			int tmp; cin >> tmp;
			rifa[i][tmp] = 1;
		}
	}
	int ans = 0;
	repi(0, m)cin >> rifa[i][0];
	int M = 1 << n;
	repi(0, M) {
		int tmp = i, f = 1;
		repj(0, m) {
			int c = 0;
			for (int k = 0; k < n; k++) {
				if ((tmp & (1 << k)) && (rifa[j][k + 1]))c++;
			}
			if ((c & 1) != rifa[j][0]) {
				f = 0;
				break;
			}
		}
		if (f)ans++;
	}
	cout << ans << endl;
	return 0;
}

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

const int M = 30000;
const int N = 20005;

int n, r[N], p[N];
int a[N], b[N];

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> n;
	for (int i = 1; i <= n; ++i) cin >> p[i], r[p[i]] = i;

	for (int i = 1; i <= n; ++i) a[i] = M * i, b[i] = M * (n - i) + r[i];

	for (int i = 1; i <= n; ++i) printf("%d ", a[i]); printf("\n");
	for (int i = 1; i <= n; ++i) printf("%d ", b[i]); printf("\n");
}

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

int main()
{
  int x,y,t;

  while(1)
  {
    cin >> x >> y;
    if(x == 0 && y == 0) break;
    if(x > y)
    {
     t = x;
     x = y;
     y = t;
    }
    cout << x << " " << y << endl;
   }

  return 0;
}

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

typedef long long ll;

const int MAX_N = 1e5 + 5;;
int n, m, ans;
bool red[MAX_N];
int cnt[MAX_N];

int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> n >> m;
	red[0] = true;
	for (int i = 0; i < n; i++)
		cnt[i] = 1;

	for (int i = 0; i < m; i++) {
		int v, u;
		cin >> v >> u;
		v--, u--;

		cnt[v]--;
		cnt[u]++;
		if (red[v] == false)
			continue;

		red[u] = true;
		if (cnt[v] == 0)
			red[v] = false;
	}

	for (int i = 0; i < n; i++)
		ans += red[i];

	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 888
#include<iostream>

int main(){
    int A, B, C;
    std::cin >> A >> B >> C;
    int rA = A % B;
    for(int resSum = 0; resSum < B; resSum++){
        if((rA * resSum) % B == C){
            std::cout << "YES" << std::endl;
            return 0;
        }
    }
    std::cout << "NO" << std::endl;
    return 0;
}


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

using namespace std;



int main()
{
	int a, b, c,d;
	cin >> a >> b >> c >> d;
	
	int a1 = c- b;
	int a2 = a - d;
	
	while(1)
	{
		c = c - b;
		if(c <= 0) 
		{
		cout << "Yes" << "\n"; break;
		}
		a = a - d;
		if(a <= 0)
		{
			cout << "No" << "\n"; break;
		}
	}
    
    return 0;
}

Measured memory_bytes: 3580
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
    
    Scanner sc = new Scanner(System.in);
      
      //入力
      int N =sc.nextInt();//数列の長さ
      int count =0; 
      
      //回数と数列番号を比較
      for(int i =1; i<N; i++){
        int p =sc.nextInt();

          //入れ替えるならカウントする
          if(p!=i){
            	count++;
          }
      }
         //１度だけ入れ替え可能だから(2か所) 
          if(count>2){
            	System.out.println("NO");
          }
      	  else {
            	System.out.println("YES");
          }
    }
}	

Measured memory_bytes: 35752
#include <iostream>
#include <cstdio>
#include <string>
#include <sstream>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <vector>
#include <set>
#include <map>
#include <queue>
using namespace std;

int main() {
    long long A, B, C, K;
    cin >> A >> B >> C >> K;
    long long plus = 0;
    long long minus = 0;
    if (A <= K) {
        plus = A;
    }
    else{
        plus = K;
    }
    
    if (A+B < K) {
        minus = K - (A+B);
    }
    else{
        minus = 0;
    }
    
    long long ans = plus - minus;
    cout << ans << endl;
}


Measured memory_bytes: 3632
def cal(i):
    return sum(w[i:n]) - sum(w[0:i])


n = int(input())
w = list(map(int, input().split()))
minNum = 100000
wSum = sum(w)
for i in range(n):
    if cal(i) <= 0:
        print(min(abs(cal(i)), abs(cal(i-1))))
        break


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pi=pair<int,int>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (int i = j; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//余りを切り上げる =>  (a + b - 1) / b 
int a,b;
bool ok=false;

void f(pi p,int cnt,vector<vector<char>> &vec){
	if(p==pi(a-1,b-1)){
		if(cnt==0) ok=true;
	}
	int n,m; tie(n,m) = p;
	if(n+1<a){
		if(vec[n+1][m]=='#'){
			f(make_pair(n+1,m),cnt-1,vec);
		}
	}
	if(m+1<b){
		if(vec[n][m+1]=='#'){
			f(make_pair(n,m+1),cnt-1,vec);
		}
	}
}
	
	
signed main(){
	cin>>a>>b;
	vector<vector<char>> vec(a,vector<char>(b));
	int cnt=0;
	rep(i,0,a){
		rep(j,0,b){
			cin>>vec[i][j];
			if(vec[i][j]=='#') ++cnt;
		}
	}
	--cnt;
	//cout<<"cnt:"<<cnt;
	f(pi(0,0),cnt,vec);
	if(ok) cout<<"Possible";
	else cout<<"Impossible";
	
	return 0;
}

Measured memory_bytes: 256
P=2019
S = input()
N=len(S)
count=[0]*P
ans = 0
count[0] = 1
u = 0
for i, s in enumerate(reversed(S)):
  u = (int(s) * pow(10, i, P) + u) % P
  ans += count[u]
  count[u] += 1
 
print(ans)

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

int main(){
    int n,p,ans=0,p_max=0;
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> p;
        ans+=p;
        if(p_max<p) p_max = p;
    }
    ans-=p_max/2;
    cout << ans << endl;
    return 0; 
}

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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007

vector<vector<int>> v(100100);
vector<int> col(100100,-1);
ll g[] = {0,0};
bool dfs(int ov,int pre){
  if(col[ov] != -1 && ov != pre){
    if(col[ov] == col[pre])return false;
    else return true;
  }
  bool is = true;
  col[ov] = 1-col[pre];
  g[col[ov]]++;
  for(auto nv: v[ov])is = is && dfs(nv,ov);
  return is;
}

int main(){
  
  ll n,m;
  cin >> n >> m;
  rep(i,m){
    int a,b;cin >> a >> b;
    a--,b--;
    v[a].push_back(b);
    v[b].push_back(a);
  }
  col[0] = 0;
  bool is = dfs(0,0);
  cout << (is ? g[1]*g[0]-m : n*(n-1)/2-m) << endl;
  


  return 0;
}

Measured memory_bytes: 6400
import java.util.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int[] a = new int[n+1];
        Map<Integer, int[][]> xy = new HashMap<>();
        for(int i=1; i<=n; i++) {
            a[i] = Integer.parseInt(sc.next());
            int[][] x = new int[a[i]][2];
            for(int j=0; j<a[i]; j++) {
                x[j][0] = Integer.parseInt(sc.next());
                x[j][1] = Integer.parseInt(sc.next());
            }
            xy.put(i, x);
        }
        
        int max = 0;
        for(int x=0; x<Math.pow(2,n); x++) {
            boolean hantei = true;
            int count = 0;
            Map<Integer, Integer> map = new HashMap<>();
            for(int y=0; y<n; y++) {
                if((1&x>>y)==1) {
                    count++;
                    for(int i=0; i<a[y+1]; i++) {
                        if(map.containsKey(y+1)) {
                            if(map.get(y+1) == 0) {
                                hantei = false;
                                break;
                            }
                        }else {
                            map.put(y+1, 1); 
                        }
                        if(map.containsKey(xy.get(y+1)[i][0])) {
                            if(map.get(xy.get(y+1)[i][0]) != xy.get(y+1)[i][1]) {
                                hantei = false;
                                break;
                            }
                        }else {
                            map.put(xy.get(y+1)[i][0], xy.get(y+1)[i][1]); 
                        }
                    }
                }else {
                    if(map.containsKey(y+1)) {
                        if(map.get(y+1) == 1) {
                            hantei = false;
                            break;
                        }
                    }else {
                        map.put(y+1, 0); 
                    }
                }
                if(hantei == false) break;
            }
            if(hantei) {
                if(max < count) max = count;
            }
                
        }
        System.out.println(max);
        
    }
    
    public static int min(int a, int b) {
        if(a <= b) return a;
        else return b;
    }
    static int sa(int a, int c) {
        if(a <= c) return c-a;
        else return a-c;
    }
}

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

using namespace std;

using ll = long long;

const ll MOD = 1000000007;

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

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    ll n, d; cin >> n >> d;
    ll pos[n][d];
    for(int i=0;i<n;i++){
        for(int j=0;j<d;j++){
            cin >> pos[i][j];
        }
    }
    ll cnt = 0;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            ll dist = 0;
            for(int k=0;k<d;k++){
                dist += (pos[i][k] - pos[j][k])*(pos[i][k] - pos[j][k]);
            }
            double x = sqrt(dist);
            if(x - floor(x) < 1e-6 || ceil(x) - x < 1e-6){
                cnt++;
            }
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define vv(T) std::vector<std::vector<T>>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;

int		main(void)
{
	ll n, d;
	cin >> n >> d;

	int ans = 0;
	for (ll i = 0; i < n; ++i)
	{
		ll x, y;
		cin >> x >> y;
		if (x*x + y*y <= d*d)
			++ans;
	}
	cout << ans << endl;
}



Measured memory_bytes: 3616
import java.util.*;
import java.io.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
 
public class Main{
    static final long mod=1000000007;
    static int dx[]={-1,0,1,0};
    static int dy[]={0,-1,0,1};

    public  static void main(String[] args)   throws Exception, IOException{        
        Reader sc = new Reader(System.in);
        PrintWriter out=new PrintWriter(System.out);
        // int n=sc.nextInt();
        // char c[][] = new char[h][w];
        // char c[]=sc.nextString().toCharArray();
        // int d[]=new int[n];
        // for(int i=0; i<n; i++) {d[i]=sc.nextInt();}

        
        int n=sc.nextInt(),c=0;
        long a[]=new long[n];
        for (int i = 0; i < n; i++) {
			a[i] = sc.nextLong();
		}

        HashMap<Long, Integer> map = new HashMap<Long, Integer>();
        HashMap<Long, Integer> id = new HashMap<Long, Integer>();
        ArrayList<Long> lis = new ArrayList<Long>();
        sort(a);
  
        for (int i = a.length-1; 0<=i; i--) {
        	if(map.containsKey(a[i])) {
        		int k=map.get(a[i])+1;
        		map.put(a[i], k);
        	}
        	else {
            	lis.add(a[i]);
        		map.put(a[i],1);
        		id.put(a[i],c++);
        	}
		}
        
        int ans=0;

        for(int i = 0; i < lis.size() ; i++) {
        	long A=lis.get(i);
        	int r=map.get(A);
//        	db(A,r,ans);
        	if(r==0)continue;
        	long b=1L<<32;
        	while(b/2>A) {
        		b/=2;
        		long p=b-A;
        		if(map.containsKey(p)) {
        			int k=map.get(p);
        			if(k<1)continue;
        			if(p==A && k<2)continue;
        			ans++;
        			r--;
        			if(A==p) {
            			map.put(A, r-1);
        			}
        			else {
	        			map.put(A, r);
	        			k--;
	        			map.put(p, k);
        			}
        			if(r>0)i--;
        			break;
        		}
        	}
		}

        
        out.println(ans);
        out.flush();
    }



    static boolean validpos(int x,int y,int r, int c){
        return x<r && 0<=x && y<c && 0<=y;
    }


    static void db(Object... os){
        System.err.println(Arrays.deepToString(os));
    }  
}


//class P implements Comparable<P>{
//    int id, d;
//    P(int  id, int d) {
//        this.id=id;
//        this.d=d;
//    }
//    public int compareTo(P p){
//        return d-p.d; //des
//    }
//}

class Reader
{ 
    private BufferedReader x;
    private StringTokenizer st;
    
    public Reader(InputStream in)
    {
        x = new BufferedReader(new InputStreamReader(in));
        st = null;
    }
    public String nextString() throws IOException
    {
        while( st==null || !st.hasMoreTokens() )
            st = new StringTokenizer(x.readLine());
        return st.nextToken();
    }
    public int nextInt() throws IOException
    {
        return Integer.parseInt(nextString());
    }
    public long nextLong() throws IOException
    {
        return Long.parseLong(nextString());
    }
    public double nextDouble() throws IOException
    {
        return Double.parseDouble(nextString());
    }
}


Measured memory_bytes: 112148
#include<iostream>

using namespace std;


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

	for (int i = 0; i < 1000; i++) {
		if (100 * i > X) {
			break;
		}
		for (int j = 0; j < 1000; j++) {
			if (100 * i + 101 * j > X) {
				break;
			}
			for (int k = 0; k < 1000; k++) {
				if (100 * i + 101 * j + 102 * k > X) {
					break;
				}
				for (int l = 0; l < 1000; l++) {
					if (100 * i + 101 * j + 102 * k + 103 * l > X) {
						break;
					}
					for (int m = 0; m < 1000; m++) {
						if (100 * i + 101 * j + 102 * k + 103 * l + 104 * m > X) {
							break;
						}
						for (int n = 0; n < 1000; n++) {
							if (100 * i + 101 * j + 102 * k + 103 * l + 104 * m + 105 * n > X) {
								break;
							}
							else if (100 * i + 101 * j + 102 * k + 103 * l + 104 * m + 105 * n == X) {
								cout << 1;
								return 0;
							}
						}
					}
				}
			}
		}
	}

	cout << 0;

	return 0;
}


Measured memory_bytes: 256
def m(L,R):
 global c;c+=len(L)+len(R)
 T=[]
 for l in L[::-1]:
  while R and R[-1]>l:T+=[R.pop()]
  T+=[l]
 return R+T[::-1]
def d(A):l=len(A);s=l//2;return m(d(A[:s]),d(A[s:]))if l>1 else A
c=0
input()
print(*d(list(map(int,input().split()))))
print(c)


Measured memory_bytes: 61872
#include<bits/stdc++.h>
#include<limits>
#define ll long long
#define F first
#define S second
#define pb push_back
#define oo (1LL<<63-1)
#define endl '\n'
#define si size()
#define all(v) v.begin(),v.end()
#define FASTIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define Matrix vector< vector < long long > >

using namespace std;

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

const long double Pi=acos(-1),e=2.718;
const int N=2e5+10,mod=1e9+7;

int main ()
{
    FASTIO
    ll a , b , c , d;
    cin >> a >> b >> c >> d;
    bool T=0;
    while(1){
        if(T==0){
            c -= b;
            if(c<=0){
                return cout << "Yes" << endl,0;
            }
        }
        else{
            a -= d;
            if(a<=0){
                return cout << "No" << endl,0;
            }
        }
        T ^= 1;
    }
    return 0;
}
/**

*/


Measured memory_bytes: 3652
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;

/*
<url:https://abc064.contest.atcoder.jp/tasks/abc064_c>
問題文============================================================
 AtCoderでは、コンテストに参加すると「色」が付き、これはレートによって次のように変化します：
 
 レート 1-399：灰色
 レート 400-799：茶色
 レート 800-1199：緑色
 レート 1200-1599：水色
 レート 1600-1999：青色
 レート 2000-2399：黄色
 レート 2400-2799：橙色
 レート 2800-3199：赤色
 また、レートが 3200 以上になると色を自由に変えることができます。
 現在 N 人の人がAtCoderのコンテストに参加したことがあり、i 人目の人のレートは ai です。
 そのとき、色の種類数の最小値と最大値を求めなさい。
 

=================================================================

解説=============================================================

 レート3200人以上の人が全て（レート色以外も含む）の色を選べることに注意さえすれば
 あとはやるだけ
 
================================================================
*/
int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
    int N; cin >> N;
    vector<int> a(N); for(auto &in:a) cin >> in;
    int color[9] = {0};
    for(int i = 0; i < N;i++){
        color[min(8,a[i]/400)]++;
    }
    
    int color_cnt = 0;
    for(int i = 0; i < 8;i++) if(color[i] != 0) color_cnt++;
    if(color_cnt == 0){
        cout << 1 << " " << color[8] << endl;
    }else{
        cout << color_cnt << " " << color_cnt + color[8] << endl;
    }
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int  long long int
#define mod 1000000000000007
#define pb push_back
#define mp make_pair
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define gcd __gcd
#define fastio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define all(i) i.begin(),i.end()
#define rep(i,a,b) for(int i=a;i<b;i++)
#define set_bit __builtin_popcount //gives number of set_bits
#define ff first
#define ss second
#define cases(t) int t;cin>>t; rep(casn,1,t+1)
#define el cout<<"\n";
#define deci(n) int n; scanf("%lld",&n);
#define decs(n) string n; cin>>n;
#define sz(v) v.size()
#define repit(m) for(auto it=m.begin();it!=m.end();it++)
// #define find(m,i) (m.find(i)!=m.end())
// #define find(m,i) (m.find(i)==m.end())
#define cYES cout<<"YES\n";
#define cNO cout<<"NO\n";
#define ins insert
#define imax 1000000000000000000
#define imin -1000000000000000000
// #define NP 50000
//  cerr << "\nTime : " << (double)clock() / (double)CLOCKS_PER_SEC << "s\n";
 
//  IIITA
//SUNEET KUMAR -->  ਸੁਨੀਤ
 
// scanning numbers extremely fast/////////
void fs(int &number)
{
    bool negative = false;
    register int c;
    number = 0;
    c = getchar();
    if (c=='-')
    {
        negative = true;
        c = getchar();
    }
    for (; (c>47 && c<58); c=getchar())
        number = number *10 + c - 48;
    if (negative)
        number *= -1;
}
// ========================================
int power(int a,int x)
{
        a%=mod;
    int res=1;
    while(x>0)
    {
        if(x&1)
        res=res*a%mod;
        a=a*a%mod;
        x>>=1;
    }
    return res;
}
int max(int a,int b)
{
    if(a>b)
    {
        return a;
    }
    else
    {
        return b;
    }
}
int min(int a,int b)
{
    if(a>b)
    {
        return b;
    }
    else
    {
        return a;
    }
}
int madd(int a,int b)
{
    int ans;
    ans=(a%mod+b%mod)%mod;
    return ans;
}
int mmult(int a,int b)
{
    int ans=1;
    ans=((a%mod)*(b%mod))%mod;
    return ans%mod;
}
int modinverse(int a)
{
    return power(a,mod-2);
}
 
void nhi_degi()
{
   int n,k;cin>>n>>k;
   map<int,int>m;
   for(int i=1;i<=k;i++)
   {
       int x;cin>>x;
       for(int j=1;j<=x;j++)
       {
           int y;cin>>y;
           m[y]++;
       }
   }
   int count=0;
   for(int i=1;i<=n;i++)
   {
       if(m[i]==0)
       {
           count++;
       }
   }
   cout<<count;el
}
signed main()
{
    // cases(t)
    // {
        nhi_degi();
    // }
}

Measured memory_bytes: 3640
#include <stdio.h>

int main(void)
{
	int n,d,x,memo,a[101];
	
	int count=0;
	
	scanf("%d%d%d",&n,&d,&x);
	
	for(int i=0;i<n;i++){
		scanf("%d",&(a[i]));
	}
	
	for(int i=0;i<n;i++){
		memo=a[i];
		while(1+memo<=d){
			memo=memo+a[i];
			count++;
		}
	}
	
	printf("%d\n",count+x+n);
	
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
 
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-funroll-loops")
#pragma GCC target("avx,sse4")
 
#define mms(a,n) memset(a,0,sizeof((a)[0])*(n))
#define mmp(a,b,n) memcpy(a,b,sizeof((b)[0])*(n))
#define lowbit(x) ((x)&-(x))
#define pb push_back
#define fi first
#define se second
#define debug(...) fprintf(stderr,__VA_ARGS__)
#define fo(i,l,r) for(register int i=l,_lim_=r;i<=_lim_;i++)
#define fd(i,r,l) for(register int i=r,_lim_=l;i>=_lim_;i--)
#define fos(i,l,r,d) for(register int i=l,_lim_=r;i<=r;i+=d)
#define fol(i,l,r) for(register ll i=l,_lim_=r;i<=_lim_;i++)
#define fdl(i,r,l) for(register ll i=r,_lim_=l;i>=_lim_;i--)
#define fosl(i,l,r,d) for(register ll i=l,_lim_=r;i<=r;i+=d)
#define Clear(a) memset(a,0,sizeof(a))
#define Copy(a,b) memcpy(a,b,sizeof(b))
#define ALL(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define sqr(x) ((x)*(x))
#define GCD __gcd

using namespace std;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ldb;
typedef double db;
typedef pair<int,int> pi;
typedef vector<int> VI;
typedef vector<VI> VII;

namespace io{
	const int L=(1<<21)+1;
	char ibuf[L],*iS,*iT,obuf[L],*oS=obuf,*oT=obuf+L-1,c,st[55];int f,tp;
	#ifdef whzzt
		#define gc()getchar()
	#else
		#define gc()(iS==iT?(iT=(iS=ibuf)+fread(ibuf,1,L,stdin),(iS==iT?EOF:*iS++)):*iS++)
	#endif
	inline void flush(){fwrite(obuf,1,oS-obuf,stdout);oS=obuf;}
	inline void putc(char x){*oS++=x;if(oS==oT)flush();}
	template<class I>
	inline void gi(I&x){
		for(f=1,c=gc();c<'0'||c>'9';c=gc())if(c=='-')f=-1;
		for(x=0;c<='9'&&c>='0';c=gc())x=x*10+(c&15);x*=f;
	}
	template<class I>
	inline void print(I x){
		if(!x)putc('0');if(x<0)putc('-'),x=-x;
		while(x)st[++tp]=x%10+'0',x/=10;
		while(tp)putc(st[tp--]);
	}
	inline void gs(char*s,int&l){
		for(c=gc();c<'a'||c>'z';c=gc());
		for(l=0;c<='z'&&c>='a';c=gc())s[l++]=c;
	}
	inline void ps(const char*s){
		fo(i,0,strlen(s)-1)putc(s[i]);
	}
};
using io::putc;
using io::gi;
using io::gs;
using io::ps;
using io::print;

const double PI=acos(-1),eps=1e-9; 
const int N=105;

int n,x[N],y[N];
double norm(double r){
	while(r>PI)r-=PI*2;
	while(r<-PI)r+=PI*2;
	return r;
}
bool in(double l,double r,double k){
	if(l<=r)return k>=l&&k<=r;
	return k<=r||k>=l;
}

struct node{
	double l,r;
	bool use;
	node(){
		use=false;
		l=r=0;
	}
	bool And(double s,double t){
		s=norm(s);t=norm(t);
		if(fabs(s-r)<eps&&fabs(t-l)<eps)return false;
		if(!use)return (l=s,r=t,use=true);
		if(in(l,r,s)&&in(l,r,t))return (l=s,r=t,true);
		if(in(s,t,l)&&in(s,t,r))return true;
		if(in(l,r,s)&&in(s,t,r))return (l=s,true);
		if(in(s,t,l)&&in(l,r,t))return (r=t,true);
		return false;
	}
	double part(){
		if(!use)return 1;
		double t=r-l,v=2*PI;
		return (t<0?t+v:t)/v;
	}
};

int main(){
	gi(n);
	fo(i,1,n)gi(x[i]),gi(y[i]);
	fo(i,1,n){
		node cur;
		bool ok=true;
		fo(j,1,n)if(i!=j){
			double k=atan2(y[j]-y[i],x[j]-x[i])+PI/2;
			if(!cur.And(k,k+PI)){
				ok=false;
				break;
			}
		}
		printf("%.14lf\n",ok?cur.part():0);
	}
	return 0;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
#define N 500005
using namespace std;
int n,dis,q;
int d[N],seg[N],ans[N];
int main(){
	scanf("%d%d",&n,&dis);
	for(int i=1;i<=n;i++) scanf("%d",&d[i]);
	seg[n+1]=0;
	for(int i=n;i>=1;i--)
		if( d[i]-seg[i+1]<=seg[i+1]+1 ) seg[i]=min(dis,seg[i+1]+d[i]);
		else seg[i]=seg[i+1];
	for(int i=1,pos=dis;i<=n;pos=min(pos,abs(pos-d[i])),i++)
		ans[i]=pos<=seg[i+1] ? 0:1;
	scanf("%d",&q);
	for(int i=1,t;i<=q;i++) scanf("%d",&t),puts(ans[t]?"YES":"NO");
	return 0;
} 

Measured memory_bytes: 7808
import * as fs from "fs";
const input = fs.readFileSync("/dev/stdin", "utf-8");

function Main(input: string) {
  const [A, B] = input.split("\n").map((str) => BigInt(Number(str)));
  if (A < B) console.log("LESS");
  else if (A === B) console.log("EQUAL");
  else if (A > B) console.log("GREATER");
}

Main(input);


Measured memory_bytes: 29700
#include <iostream>
#include <stdio.h>
#include <bits/stdc++.h>
#include <queue>
#include <math.h>
using namespace std;
#define N 10000

long gcd(long x, long y){
    if (y>x){
       swap(x,y); 
    }
    while (y!=0){
        long r=x%y;
        x=y;
        y=r;
    }
    return x;
}

int main(){
    long a,b,c,d;
    cin>>a>>b>>c>>d;
    long A1,B1,A2,B2;
    A1=(a-1)/c;
    A2=(a-1)/d;
    B1=b/c;
    B2=b/d;
    long ans_A=B1-A1;
    long ans_B=B2-A2;
    long lcm=c*d/gcd(c,d);
    long AB1,AB2;
    AB1=(a-1)/lcm;
    AB2=b/lcm;
    long ans_AB=AB2-AB1;
    long sum=ans_A+ans_B-ans_AB;
    cout<<b-a+1-sum<<endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
    #pragma GCC target ("avx")
    #include <bits/stdc++.h>
    constexpr int INF = 2147483647;
    constexpr long long int INF_LL = 9223372036854775807;
    constexpr int MOD = 1000000007;
    using namespace std;
    typedef long long int ll;
    typedef unsigned long long int ull;
     
    ll N, Q;
    vector<vector<int>> path;
    vector<int> parent,pl;
     
    void dfs(int pos, int prev) {
    	if(prev !=-1)pl[pos] += pl[prev];
    	for (int i = 0; i < path[pos].size(); i++) {
    		if (path[pos][i] != prev) {
    			dfs(path[pos][i], pos);
    		}
    	}
    }
     
    int main() {
    	cin >> N >> Q;
    	path = vector<vector<int>>(N+1, vector<int>());
    	parent = pl = vector<int>(N + 1, 0);
     
    	for (int i = 0; i < N - 1; i++) {
    		ll a, b;
    		cin >> a >> b;
    		path[a].push_back(b);
    		path[b].push_back(a);
    	}
    	for (int i = 0; i < Q; i++) {
    		int p, x;
    		cin >> p >> x;
    		pl[p] += x;
    	}
     
    	dfs(1, -1);
    	for (int i = 0; i < N; i++) {
    		cout << pl[i + 1] << endl;
    	}
     
    }

Measured memory_bytes: 21120
// #include "pch.h"
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <climits>
#include <string>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <ctime>
#include <cassert>
#include <fstream>
#include <stack>
#include <random>

typedef long long ll;
typedef std::pair<int, int> Pii;
typedef std::pair<long long, long long> Pll;
typedef std::pair<double, double> Pdd;

#define rip(i, n, s) for (int i = (s);i < (int)( n ); i++)
#define all(a) a.begin(), a.end()
#define MM << " " <<

template<typename T>
using MaxHeap = std::priority_queue<T>;
template<typename T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template<typename T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template<typename T>
void vdeb(std::vector<T> &da) {
    for (int i = 0;i < da.size();i++) {
        if (i == da.size() - 1) std::cout << da[i];
        else std::cout << da[i] << ' ';
    }
    std::cout << '\n';
}
template<typename T>
void vdeb(std::vector<std::vector<T>> &da) {
    for (int i = 0;i < da.size();i++) {
        std::cout << i << ' ';
        vdeb(da[i]);
    }
    std::cout << '\n';
}

using namespace std;

int main() {
    ll x, k ,d; cin >> x >> k >> d;
    x = abs(x);
    if(x/d >= k) cout << x-d*k << endl;
    else {
        k -= x/d;
        x -= x/d*d;
        // cout << x MM k << endl;
        if(k&1LL) cout << d-x << endl;
        else cout << x << endl;
    }
}

Measured memory_bytes: 3628
from collections import defaultdict
from collections import deque
from collections import Counter
import math
import itertools

def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()

n = readInt()
data = []
for i in range(n):
	x,y = readInts()
	data.append([x+y,x,y,x-y])
ans = 0
data.sort(key=lambda x:x[0])
ans = max(ans,abs(data[-1][1]-data[0][1])+abs(data[-1][2]-data[0][2]))
data.sort(key=lambda x:x[1])
ans = max(ans,abs(data[-1][1]-data[0][1])+abs(data[-1][2]-data[0][2]))
data.sort(key=lambda x:x[2])
ans = max(ans,abs(data[-1][1]-data[0][1])+abs(data[-1][2]-data[0][2]))
data.sort(key=lambda x:x[3])
ans = max(ans,abs(data[-1][1]-data[0][1])+abs(data[-1][2]-data[0][2]))
print(ans)

Measured memory_bytes: 136248
def get_input():
    S = list(input())
    return S

def solve(S):
    length = len(S)
    pattern1 = ["0" if i %2 ==0 else "1" for i in range(length)]
    pattern2 = ["1" if i %2 ==0 else "0" for i in range(length)]
    count1 = get_diff(S,pattern1)
    count2 = get_diff(S,pattern2 )
    return min(count1,count2) 

def get_diff(S1,S2):
    count =0
    for s1,s2 in zip(S1,S2):
        if s1 != s2:
            count +=1
    return count


if __name__ == "__main__":
    S = get_input()
    ans = solve(S)
    print(ans)

Measured memory_bytes: 5548
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define FL "a"
using namespace std;
typedef vector<int> VI;
typedef long long ll;
typedef double dd;
const int N=1e5+10;
const int mod=1e9+7;
inline ll read(){
  ll data=0,w=1;char ch=getchar();
  while(ch!='-'&&(ch<'0'||ch>'9'))ch=getchar();
  if(ch=='-')w=-1,ch=getchar();
  while(ch<='9'&&ch>='0')data=data*10+ch-48,ch=getchar();
  return data*w;
}
inline void file(){
  freopen(FL".in","r",stdin);
  freopen(FL".out","w",stdout);
}

inline void upd(int &a,int b){a+=b;if(a>=mod)a-=mod;}
inline void dec(int &a,int b){a-=b;if(a<0)a+=mod;}
inline int poww(int a,int b){
  int res=1;
  for(;b;b>>=1,a=1ll*a*a%mod)
    if(b&1)res=1ll*res*a%mod;
  return res;
}
inline void er(){puts("0");exit(0);}

int n,a[N],ans;
int d[N],head[N],nxt[N<<1],to[N<<1],cnt;
inline void add(int u,int v){to[++cnt]=v;nxt[cnt]=head[u];head[u]=cnt;}
int t[N],f[N];

int vis[N],line[N],dis[N],cal[N],top,cir[N],len;
void dfs(int u){
  vis[u]=1;cal[++top]=u;
  for(int i=head[u],v;i;i=nxt[i])
    if(~i&1){
      if(!vis[v=to[i]])dfs(v);
      else
	for(int j=top;cal[j]!=v;j--)
	  cir[++len]=cal[j];
    }
  top--;
}
inline void solve(int x){
  top=len=0;
  for(int p=0;!vis[x];vis[x]=1,cal[++top]=x,p=x,x=a[x]);
  for(int i=top,k=1;i;i--){
    k?cir[++len]=cal[i],dis[cal[i]]=len:vis[cal[i]]=0;
    if(cal[i]==x)k=0;
  }  
  reverse(cir+1,cir+len+1);
  for(int i=1;i<=len;i++)dis[cir[i]]=len-dis[cir[i]]+1;
  for(int k=1,u;k<=len;k++){
    u=cir[k];if(d[u]>2)er();line[u]=0;
    for(int i=head[u],v;i;i=nxt[i])
      if(!vis[v=to[i]])	
	for(line[u]++,vis[v]=1;d[v];v=to[head[v]],vis[v]=1,line[u]++)
	  if(d[v]>1)er();
  }
  for(int k=1;!line[cir[k]];k++)
    if(k==len){t[len]++;return;}
  if(len==1&&line[cir[1]]<=1)return;
  top=0;
  for(int k=1;k<=len;k++)
    if(line[cir[k]])cal[++top]=cir[k];
  if(line[cal[1]]>dis[cal[1]]+(len-dis[cal[top]]))er();
  else ans=1ll*min(2,dis[cal[1]]+(len-dis[cal[top]])-line[cal[1]]+1)*ans%mod;
  for(int i=2;i<=top;i++)
    if(line[cal[i]]>dis[cal[i]]-dis[cal[i-1]])er();
    else ans=1ll*min(2,dis[cal[i]]-dis[cal[i-1]]-line[cal[i]]+1)*ans%mod;
}
int main()
{
  n=read();cnt=1;ans=1;
  for(int i=1;i<=n;i++){
    a[i]=read();d[a[i]]++;add(a[i],i);
    if(a[i]>n)er();
  }
  for(int i=1;i<=n;i++)
    if(!vis[i])solve(i);
  for(int i=1;i<=n;i++)
    if(t[i]){
      f[0]=1;
      for(int j=1;j<=t[i];j++){
	f[j]=1ll*((i&1)&&i!=1?2:1)*f[j-1]%mod;
	upd(f[j],1ll*(j-1)*i%mod*f[j-2]%mod);
      }
      ans=1ll*ans*f[t[i]]%mod;
    }
  printf("%d\n",ans);
  return 0;
}


Measured memory_bytes: 5376
#pragma GCC target ("avx2") 
#pragma GCC optimization ("O3") 
#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
#define fast_az_fuk ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long 
#define int ll 
#define ull unsigned ll
#define ld long double 
#define pb push_back 
#define pf push_front
#define dll deque<ll> 
#define vll vector<ll> 
#define pll pair<ll,ll> 
#define mapll map<ll,ll>
#define endl "\n" 
#define all(v) v.begin(),v.end() 
#define ms(a,x) memset(a,x,sizeof(a))
using namespace std;
void swap(auto*,auto*);
const ll N=1e6; ll spf[N+1];
ll countPairs(ll n){
    vll v;
    while(1){
        if(n==1) break;
        ll c=0;
        ll fac=spf[n];
        while(spf[n]==fac) {c++; n/=fac;}
        v.pb(c);
    }
    ll c=1;
    for(ll x:v) c*=(x+1);
    return c;
}
int32_t main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    for(ll i=1;i<=N;i++) spf[i]=i;
    for(ll i=2;i*i<=N;i++){
        if(spf[i]==i){
            for(ll j=i*i;j<=N;j+=i) {
                if(spf[j]==j) spf[j]=i;
            }
        }
    }
    ll n; cin>>n; ll c=0;
    for(ll i=1;i<n;i++){
        c+=countPairs(n-i);
    }
    cout<<c;
    return 0;
}
void swap(auto &a,auto &b)
{
    auto temp=a; a=b; b=temp;}

Measured memory_bytes: 11424
local mma, mmi = math.max, math.min
local n, m = io.read("*n", "*n")
local edge = {}
local inf = n + 1
for i = 1, n do
  edge[i] = {}
end
for i = 1, m do
  local a, b = io.read("*n", "*n")
  table.insert(edge[a], b)
end

local len = {}
local function solve(z)
  for i = 1, n - 1 do
    len[i] = inf
  end
  len[n] = 0
  for idx = n - 1, 1, -1 do
    if #edge[idx] == 1 then
      len[idx] = 1 + len[edge[idx][1]]
    else
      local lensum, lenmax = 0, 0
      for i = 1, #edge[idx] do
        local v = len[edge[idx][i]]
        lensum = lensum + v
        lenmax = mma(lenmax, v)
      end
      if z == idx then
        len[idx] = 1 + (lensum - lenmax) / (#edge[idx] - 1)
      else
        len[idx] = 1 + lensum / #edge[idx]
      end
    end
  end
  return len[1]
end
local ret = solve(1)
for i = 2, n do
  ret = mmi(ret, solve(i))
end
print(string.format("%.9f", ret))


Measured memory_bytes: 2560
#include "bits/stdc++.h"
#include <set>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()
//#define int long long
#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
#define mod 1000000007
template <typename T>

void print(T x)
{
	std::cout << x << " ";
}
template <typename T>

void println(T x)
{
	std::cout << x << "\n";
}


int main() {
	int N, K;
	cin >> N >> K;
	int ans = 1;
	rep(i, N) {
		ans += min(K, ans);
	}
	print(ans);
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <queue>
#define N 10010
#define INF 0x3f3f3f3f
using namespace std;
typedef pair<int, int> ii;
vector<ii> m[N];
int n;
int used[N];
int d[N];
priority_queue<ii, vector<ii>, greater<ii> > td;
void dijk(){
    d[0] = 0;
    used[0] = 1;
    td.push(make_pair(0, 0));
    while(!td.empty()){
        ii temp = td.top(); td.pop();
        if(temp.first == INF) break;
        int du = temp.first;
        int u = temp.second;
        for(int j = 0; j < m[u].size(); j++){
            int v = m[u][j].second;
            if(!used[v] && d[u]+m[u][j].first < d[v]){
                d[v] = d[u] + m[u][j].first;
                td.push(make_pair(d[v], v));
            }
        }
    }
    for(int i = 0; i < n; i++){
        printf("%d %d\n", i, d[i]);
    }
}
int main(){
    scanf("%d", &n);
    for(int i = 0; i < n; i++) {
        d[i] = INF;
        used[i] = 0;
    }
    for(int p = 0; p < n; p++){
        int node, k;
        scanf("%d %d", &node, &k);
        for(int t = 0; t < k; t++){
            int a, b;
            scanf("%d %d", &a, &b);
            m[node].push_back(make_pair(b, a));
        }
    }
    dijk();
    return 0;
}



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

int main() {
	string S;
	cin >> S;
	set<char> t;

	rep(i,S.size())
		t.insert(S.at(i));
	
	if(t.size() < 26) {
		char x;
		for(char i='a'; i<='z'; ++i)
			if(!t.count(i)) {
				x = i;
				break;
			}
		cout << S << x;
	} else {
		int i = S.size()-1;
		char p=0, x='z';

		while(S.at(i) > p) {
			p = S.at(i--);
			if(i == -1) {
				cout << -1 << endl;
				return 0;
			}
		}

		rep(j,S.size()-i-1)
			if(S.at(i+1+j) > S.at(i))
				x = min(x, S.at(i+1+j));
		cout << S.substr(0,i) << x;
	}
	cout << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll MOD = 1000000007LL;

int main() {
	string S, T;
	cin >> S >> T;
	for (int i = 0; i < S.size(); i++) {
		if (S == T) {
			cout << "Yes" << endl;
			return 0;
		}
		char c = S.back();
		for (int j = S.size() - 1; j > 0; j--) {
			S[j] = S[j - 1];
		}
		S[0] = c;
	}
	cout << "No" << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
void visit(int**,int*,int*,int*,int,int);

int t = 0;

int main(){
  int i,j,n,u,k,v,*d,*f,*color,**G;
  scanf("%d",&n);
  G = malloc((n+1) * sizeof(int *));
  d = malloc((n+1) * sizeof(int));
  f = malloc((n+1) * sizeof(int));
  color = malloc((n+1) * sizeof(int));
  for(i=1;i<=n;i++){
    G[i] = malloc((n+1) * sizeof(int));
  }
  for(i=1;i<=n;i++){
    for(j=1;j<=n;j++){
      G[i][j] = 0;
    }
  }
  for(i=0;i<n;i++){
    scanf("%d %d",&u,&k);
    for(j=0;j<k;j++){
      scanf("%d",&v);
      G[u][v] = 1;
    }
  }
  for(i=1;i<=n;i++){
    color[i]=1;
  }
  for(i=1;i<=n;i++){
    if(color[i]==1){
      visit(G,d,f,color,n,i);
    }
  }
  for(i=1;i<=n;i++){
    printf("%d %d %d\n",i,d[i],f[i]);
  }
  return 0;
}

void visit(int **G,int *d,int *f,int *color,int n,int u){
  int i;
  color[u] = 0;
  d[u] = ++t;
  for(i=1;i<=n;i++){
    if(G[u][i]==1){
      if(color[i] == 1){
        visit(G,d,f,color,n,i);
      }
    }
  }
  color[u] = -1;
  f[u] = ++t;
}



Measured memory_bytes: 2044
k = 0
a = input()

lista = input().split()

for c in range(1, len(lista)-1):

    if int(lista[c-1]) > int(lista[c]) > int(lista[c + 1]) or int(lista[c - 1]) < int(lista[c]) < int(lista[c + 1]):
        k += 1

print(k)


Measured memory_bytes: 3060
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int count = 0;
        while (true) {
            String[] lines = br.readLine().split(" ");
            int a = Integer.parseInt(lines[0]);
            int b = Integer.parseInt(lines[1]);
            if(a==0 && b==0){
                break;
            }
            if (a > b) {
                System.out.println(b + " " + a);
            } else {
                System.out.println(a + " " + b);
            }
        }
    }
}

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

sys.setrecursionlimit(10**7)
inf = 10**3
eps = 1.0 / 10**10
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    rr = []

    def f(c):
        return c in 'qwertasdfgzxcvb'

    while True:
        s = S()
        if s == '#':
            break
        t = f(s[0])
        r = 0
        for c in s[1:]:
            ct = f(c)
            if t != ct:
                r += 1
                t = ct
        rr.append(r)

    return '\n'.join(map(str, rr))


print(main())




Measured memory_bytes: 9036
#include<iostream>
using namespace std;
int main(){
    string s,t;
    cin>>s >> t;
    
    int n = s.size() ,  m = t.size();
    int ans = m;

    for(int i=0 ; i <= n-m ; i++){
        int req = 0;
        for(int j=0;j<m;j++){
            if(s[i+j]!=t[j]){
                req++;
            }
        }
        ans = min(ans , req);
    }
    cout<<ans;
}


Measured memory_bytes: 3632
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <vector>
#include <limits.h>
#include <math.h>

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

using namespace std;

typedef unsigned long long ll;
typedef pair<int,int> Pii;
typedef vector<int> vint;
const ll INF = LONG_LONG_MAX;


int main() {
    // insert code here...    return 0;
    //////
    // input from txt
    /*
     std::ifstream in("input.txt");
     std::cin.rdbuf(in.rdbuf());
     std::ofstream out("output.txt");
     std::cout.rdbuf(out.rdbuf());
     ////
     */
    int N,A,B;
    cin >> N >> A >> B;
    ll v[60];
    repeat(i, N) cin >> v[i];
    ll dp[60];
    fill(dp,dp+N+1,0);
    ll cnt[60];
    cnt[0] = 1;
    repeat(i, N){
        repeat(j, N){
            ll value = dp[N-j-1]+v[i];
            if(dp[N-j] < value){
                dp[N-j] = value;
                cnt[N-j] = cnt[N-j-1];
            }else if(dp[N-j] == value){
                cnt[N-j] += cnt[N-j-1];
            }
        }
    }
    long double ans = 0;
    ll anscnt = 0;
    for(int i=A;i<=B;i++){
        long double ave = (long double)dp[i]/i;
        if(ans < ave){
            ans = ave;
            anscnt = cnt[i];
        }else if(ans == ave){
            anscnt += cnt[i];
        }
    }
    printf("%.8lf\n",(double)ans);
    cout << anscnt << endl;
    return 0;
}



Measured memory_bytes: 256
#include <stdio.h>		// standard input output
#include <iostream>		// input output stream, cin cout( console in console out)
#include <cmath>		// circle math ( sin, con, sinh
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>		// input output manipulation

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define rep3(i, a, n) for(int i = (int)(a); i < (int)(n); i++)
#define ll long long

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






int main() {
  int N; // 変数の宣言
  cin >> N; // 標準入力

  if(N ==0){
  cout << setprecision(12) << 1 << endl; // 標準出力
  }
  else{
    cout << setprecision(12) << 0 << endl; // 標準出力
  }
}



Measured memory_bytes: 3632
#include<cstdio>
#include<iostream>
#include<queue>
using namespace std;
const int N=1e5+10;
int n,m,U,V,h[N],head[N],tot,cnt,deg[N],root,ans[N];
struct edg{int nxt,to;}e[N];
struct edge{int nxt,to;}ed[N];
inline void Add(int x,int y){e[++tot].to=y;e[tot].nxt=h[x];h[x]=tot;}
inline void addedge(int x,int y){ed[++cnt].to=y;ed[cnt].nxt=head[x];head[x]=cnt;}
inline void topsort(){
	queue<int>q;
	for(register int i=1;i<=n;i++)
		if(!deg[i]){root=i;break;}
	q.push(root);
	while(!q.empty()){
		int u=q.front();q.pop();
		for(register int i=h[u];i;i=e[i].nxt){
			int v=e[i].to;
			if(--deg[v]==0){addedge(u,v);q.push(v);}
		}
	}
}
inline void DFS(int u,int fa){
	ans[u]=fa;
	for(register int i=head[u];i;i=ed[i].nxt)DFS(ed[i].to,u);
}
int main(){
	scanf("%d%d",&n,&m);
	for(register int i=1;i<n+m;i++)
		scanf("%d%d",&U,&V),Add(U,V),deg[V]++;
	topsort();DFS(root,0);
	for(register int i=1;i<=n;i++)printf("%d\n",ans[i]);
	return 0;
}

Measured memory_bytes: 5504