akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.StringTokenizer;

public class Main  implements Runnable {
	public static void main(String[] args) {
		new Thread(null, new Main(), "", 32 * 1024 * 1024).start(); //
	}
	public void run() {
		FastScanner sc = new FastScanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		int n = Integer.parseInt(sc.next());
		int m = Integer.parseInt(sc.next());
		ArrayList<T_node> ar = new ArrayList<T_node>();
		for (int i = 0; i < m; i++) {
			ar.add(new T_node(i, i));
		}
		for (int i = 0; i < n; i++) {
			int k = Integer.parseInt(sc.next());
			ar.add(new T_node(i+m, i+m));
			for (int j = 0; j < k; j++) {
				int lang = Integer.parseInt(sc.next())-1;
				ar.get(m+i).ar.add(lang);
				union(ar, i+m, lang);
			}
		}
		int ans = 1;
		int tmp = getp(ar, m);
		for (int i = 1; i < n; i++) {
			if(tmp != getp(ar, m+i))
			{
				ans = 0;
			}
		}
		if(ans == 1)
		{
			out.println("YES");
		}
		else {
			out.println("NO");
		}
		
		out.flush();
	}
	void union(ArrayList<T_node> ar, int x, int y)
	{
		int xp = getp(ar,x);
		int yp = getp(ar,y);
		if(xp == yp)
		{
			
		}
		else {
			ar.get(xp).p = yp;
		}
	}
	int getp(ArrayList<T_node> ar, int x)
	{
		int p = x;
		if(ar.get(x).p == x)
		{
			return x;
		}
		else {
			p = getp(ar, ar.get(x).p);
			ar.get(x).p = p;
			return p;
		}
	}
    static class FastScanner {
        private BufferedReader reader = null;
        private StringTokenizer tokenizer = null;
        public FastScanner(String in) {
        	StringReader sr = new StringReader(in);
            reader = new BufferedReader(new BufferedReader(sr));
            tokenizer = null;
        }
        public FastScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
            tokenizer = null;
        }
        public String next() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }
    }
}

class T_node {

	int n;
	int p;
	ArrayList<Integer> ar;

	T_node(int tn, int tp) {
		n = tn;
		p = tp;
		ar = new ArrayList<Integer>();
	}
}

Measured memory_bytes: 56316
#include<stdio.h>

int main(){

	int n,i,max,min;
	int total;
	int s[100];

	while(1){
		scanf("%d",&n);

		if(n==0){
			break;
		}

		scanf("%d",&s[0]);
		max=min=s[0];

		for(i=1;i<n;i++){
			scanf("%d",&s[i]);
			if(s[i]>max){
				max=s[i];
			}
			if(s[i]<min){
				min=s[i];
			}
		}

		total=0;

		for(i=0;i<n;i++){
			total= total+s[i];
		}
		total-=max;
		total-=min;
		total=total/(n-2);

		printf("%d\n",total);
	}

	return(0);
}

Measured memory_bytes: 600
#include <iostream>

using namespace std;

struct Rect {
	int w, h;
	bool operator <(Rect& r) {
		if (w*w+h*h == r.w*r.w+r.h*r.h) {
			return h < r.h;
		}
		else {
			return w*w+h*h < r.w*r.w+r.h*r.h;
		}
	}
};

int main() {
	int W, H;
	while (cin >> H >> W, H || W) {
		Rect in = {W, H};
		Rect ans = {150, 150};
		for (int w = 1; w <= 150; ++w) {
			for (int h = 1; h < w; ++h) {
				Rect r = {w, h};
				if (in < r && r < ans) ans = r;
			}
		}
		cout << ans.h << " " << ans.w << endl;
	}
}

Measured memory_bytes: 1160
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=3e5+5;
int n,a[N],foo,bar;
bool check(int mid){
	int mn=0;
	for(int i=2;i<n;i+=2)
		if(a[i-1]-mn>=mid)
			mn=min(mn,a[i]);
	return a[n]-mn>=mid;
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i){
		scanf("%d",&a[i]);
		if(i&1)foo+=a[i];
		else bar+=a[i],a[i]=-a[i];
		a[i]+=a[i-1];
	}
	if(~n&1)return printf("%d %d\n",max(foo,bar),min(foo,bar)),0;
	int l=0,r=3e8,res;
	while(l<=r){
		int mid=l+r>>1;
		if(check(mid))res=mid,l=mid+1;
		else r=mid-1;
	}
	printf("%d %d\n",bar+res,foo-res);
	return 0;
}


Measured memory_bytes: 1280
import Foundation

let input = readLine()!.components(separatedBy: " ").map{ Int($0)! }
let N = input[0]
let D = input[1]
let distance = D * D
var count = 0
for i in 1...N {
    let inputs = readLine()!.components(separatedBy: " ").map{ Int($0)! }
    if distance >= inputs[0] * inputs[0] + inputs[1] * inputs[1]{
        count += 1
    }
}
    print(count)

Measured memory_bytes: 14200
#include <iostream>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <string>
#include <cstdlib>
#include <cctype>
#include <ctime>
using namespace std;
#define EPS 1e-9
#define INF 0x3f3f3f
#define N 100000 + 5
#define M 10000 + 5
#define MM(X) memset(X , 0 , sizeof(X))
#define MZ(X) memset(X , 0xff , sizeof(X))
#define MI(X) memset(X , 0x3f , sizeof(X))
#define Fi(n) for( int i = 0 ; i < n  ; i ++ )
#define Fj(n) for( int j = 0 ; j < n  ; j ++ )
#define Fk(n) for( int k = 0 ; k < n  ; k ++ )
int main(){
    // freopen("in.txt","r",stdin);
    // freopen("out.txt","w",stdout);
    int n ;
    while(cin >> n ){
        int first_MinNum = 0, last_MaxNum = -0x7f3f3f3f;
        n -- ;
        cin >> first_MinNum ;
        while(n--){
            int t ;
            cin >> t ;
            last_MaxNum = max(last_MaxNum,t - first_MinNum);
            if( first_MinNum > t ){
                first_MinNum = t ;
            }
        }
        cout << last_MaxNum  << endl;
    }
    return 0 ;
}



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


int main() {

    int N; cin >> N;
    vector<int> A(N);
    forn(i,N) cin >> A[i];
    vector<int>::iterator maxIt = max_element(A.begin(), A.end());
    size_t maxIndex = distance(A.begin(), maxIt);
    int max = A[maxIndex];
    A.erase(A.begin() + maxIndex);
    vector<int>::iterator maxIt2 = max_element(A.begin(), A.end());
    forn(i, N) {
        if (i == maxIndex) {
            cout << *maxIt2 << endl;
        } else {
            cout << max << endl;
        }
    }
}

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

int main(){
    string S;
    int ans=0;
    cin >>S;
    string bef="";
    for(long long int i=0;i<S.size();i++){
      string temp={S.at(i)};
      if(bef!=temp){
        ans++;
        bef=temp;
      }else if(bef==temp){
        i++;
        if(i==S.size())break;
        bef.push_back(S.at(i));
        ans++;
      }
      //cout<<bef<<endl;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 640
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.util.StringTokenizer;

public class Main {

	public static void main(String args[]) throws Exception {
		MyScanner sc = new MyScanner();
		PrintWriter pr = new PrintWriter(System.out);

		long a = sc.nextLong();
		double b = sc.nextDouble();
		
		BigDecimal x = new BigDecimal(Double.toString(b));
		x = x.multiply(new BigDecimal(Long.toString(a)));
		
		String res = x.toString();
		//System.out.println(res);
		StringBuilder temp = new StringBuilder("");
		
		for(int i = 0; i < res.length(); i++) {
			
			if(res.charAt(i) == '.')
				break;
			temp.append(res.charAt(i));
		}
		
		pr.println(temp);
		pr.close();
	}

	public static class MyScanner {
		BufferedReader br;
		StringTokenizer st;

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

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

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

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

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

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}
}


Measured memory_bytes: 33740
#include<iostream>
#include<cstdio>
using namespace std;
const int N=20005;
long long n,k,w,k1,t,cnt,p,p1[N],kl[N],l[N],r[N],v[N];
int main()
{
    scanf("%d",&n);
    k=1;
    if(n==1)
    {
        printf("2 1\n1 2 0\n");
        return 0;
    }
    t=1;
    while(t*2<=n)
    {
        l[++cnt]=k;
        r[cnt]=k+1;
        v[cnt]=0;
        l[++cnt]=k;
        r[cnt]=k+1;
        v[cnt]=t;
        k++;
        t=t*2;
    }
    k1=k;
    n=n-t;
    w=t;
    while(n>0)
    {
        t=1;
        k=1;
        while(t*2<=n) 
            t=t*2,k++;
        l[++cnt]=k;
        r[cnt]=k1;
        v[cnt]=w;
        w=w+t;
        n=n-t;
    }
    printf("%d %d\n",k1,cnt);
    for(int i=1;i<=cnt;i++)
        printf("%d %d %d\n",l[i],r[i],v[i]);
    return 0;
}

Measured memory_bytes: 256
INT_MAX=10**19+7
MOD=10**12+7
def INPUT():return list(int(i) for i in input().split())
def LIST_1D_ARRAY(n):return [0 for _ in range(n)]
def LIST_2D_ARRAY(m,n):return [[0 for _ in range(n)]for _ in range(m)]
#=======================================================================
import math as M
a,b,n=INPUT()
i=min(b-1,n)
ans=int(a*i/b)-a*int(i/b)
print(ans)


Measured memory_bytes: 62140
import fractions
A,B,C,D = [int(i) for i in input().split()]
def lcm(a,b):
    return a*b // fractions.gcd(a,b)
lcm = lcm(C,D)
aa = ((B//C)-(1 if A%C != 0 else 0))-(A//C)+1
bb = ((B//D)-(1 if A%D != 0 else 0))-(A//D)+1
ll = ((B//lcm)-(1 if A%lcm != 0 else 0))-(A//lcm)+1
print(int((B-A+1)-(aa+bb-ll)))

Measured memory_bytes: 66412
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector> 
#include <cstring>
#include <queue>
#include <ctime>
#include <set>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef pair<ll,pii> item;
const ll INF = 10e8;
const int maxN = 210;
const int maxD = 15;
const int maxH = 1010; 
const int MOD = 1000000007;
const int maxK = 12;
int n,m,R;
ll path[maxN][maxN];
int r[maxD];
void init(int n)
{
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			path[i][j] = INF;
}
ll _min(ll a,ll b)
{
	if(a>b)
		return b;
	else
		return a;
}
ll get()
{
	ll cnt = 0;
	for(int i=1;i<R;i++)
	{
		int x = r[i];
		int y = r[i+1];
		cnt += path[x][y];
	}
	return cnt; 
}
int main()
{
	scanf("%d%d%d",&n,&m,&R);
	init(n);
	for(int i=1;i<=R;i++)
	{
		scanf("%d",&r[i]);
	}
	sort(r+1,r+1+R); 
	for(int i=1;i<=m;i++)
	{
		int a,b,c;
		scanf("%d%d%d",&a,&b,&c);
		path[a][b] = (ll)c;
		path[b][a] = (ll)c;
	}
	for(int k=1;k<=n;k++)
		for(int i=1;i<=n;i++)
			for(int j=1;j<=n;j++)
			{
				if(i==j)
					path[i][j] = 0;
				else
					path[i][j] = _min(path[i][j],path[i][k] + path[k][j]);
			} 
	ll minc = INF;
	while(1)
	{
		ll ans = get();
		if(ans < minc)
			minc = ans;
		if (!next_permutation(r+1, r+R+1)) break;
	}
	printf("%lld\n",minc);
	return 0;
}  

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

public class Main {
	static long[] a;
	static long[] p;
	private static void solve(){
		//Implement solution here.
		int d = ni();
		if(d == 25) {
			System.out.println("Christmas");
		} else if(d == 24) {
			System.out.println("Christmas Eve");
		} else if(d == 23) {
			System.out.println("Christmas Eve Eve");
		} else {
			System.out.println("Christmas Eve Eve Eve");
		}	
	}

	//Switch input source (stdin/file)
	private static BufferedReader br  = new BufferedReader(new InputStreamReader(System.in));
	public static void main(String[] args){
		String debugDataPath = System.getenv("DD_PATH");        
		if(debugDataPath != null){
			try{
				br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(debugDataPath))));
			}catch(Exception e){
				throw new RuntimeException(e);
			}
		}
		solve();
	}

	//Input read utility
	private static StringTokenizer tokenizer = null;
	public static String next() {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}
	//Get next single int
	private static int ni() {
		return Integer.parseInt(next());
	}
	//Get next single long
	private static long nl() {
		return Long.parseLong(next());
	}
	//Get next single double
	private static double nd() {
		return Double.parseDouble(next());
	}
	//Get next int array from one line
	private static int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}
	//Get next char array from one line
	private static char[] ns() {
		return next().toCharArray();
	}
	//Get next long array from one line
	private static long[] nal(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nl();
		return a;
	}
}


Measured memory_bytes: 21332
#include <iostream>

using namespace std;

const int MAXN=13;
const int MAXS=1000111;
const int INF=1034567890;

int N;
int P[MAXN];
int C[MAXN];
int G;
int Sum;
int MinP[MAXS];

int main(){
	ios_base::sync_with_stdio(false);
	
	cin >> N >> G;G/=100;
	for(int i=1;i<=N;++i){
		cin >> P[i] >> C[i];
		C[i]/=100;
	}
	
	for(int i=1;i<=N;++i){
		Sum+=C[i];
		Sum+=P[i]*i;
	}
	
	MinP[0]=0;
	for(int i=1;i<=Sum;++i)	MinP[i]=INF;
	
	for(int i=1, v;i<=N;++i){
		for(int k=Sum;k>=0;--k){
			for(int j=0;j<P[i];++j){
				v=j*i;
				if(k>=v)	MinP[k]=min(MinP[k], MinP[k-v]+j);
			}
			v=P[i]*i+C[i];
			if(k>=v)	MinP[k]=min(MinP[k], MinP[k-v]+P[i]);
		}
	}
	
	int Ans=INF;
	for(int i=G;i<=Sum;++i){
		if(Ans>MinP[i]){
			Ans=MinP[i];
		}
	}
	
	
	cout << Ans << endl;
	
	return 0;
}

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

int main(void) {
  int N;
  cin >> N;
  int A[N];
  double sum=0.0;
  
  for(int i=0; i<N; i++) cin >> A[i];
  
  for(int i=0; i<N; i++){
    sum += 1.0 / A[i];
  }
  
  cout << 1.0 / sum << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,_7,_8,NAME,...) NAME
#define pr(...) cerr<< GET_MACRO(__VA_ARGS__,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__) <<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
#define prArr(a) {cerr<<(#a)<<"={";int i=0;for(auto t:(a))cerr<<(i++?", ":"")<<t;cerr<<"}"<<endl;}
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<60)+1e9; // ~ 1.15 * 1e18
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){
  return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}


string erase(string s){
  string res;
  int n = s.size();
  int i = 0;
  while( i < n ){
    if(s[i] != '\"') res += s[i];
    else {
      while(s[++i] != '\"');
      res += ',';
    }
    i++;
  }
  return res;
}

vector<string> get(string s){
  vector<string> res;
  int n = s.size();
  int i = 0;
  while( i < n ){
    string tmp;
    if(s[i] != '\"');
    else while(s[++i] != '\"') tmp += s[i];
    i++;
    res.push_back(tmp);
  }
  return res;
}

int diff(vector<string> a,vector<string> b){
  int n =a.size();
  int cnt = 0;
  for(int i=0;i<n;i++) cnt += a[i] != b[i];
  return cnt;

}

signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  while(1){
    string s1, s2;
    cin>>s1;
    if(s1 == ".") return 0;
    cin>>s2;
  
    auto a1 = erase(s1), a2 = erase(s2);
    auto b1 = get(s1), b2 = get(s2);

    if(a1 == a2 && b1 == b2){
      cout<<"IDENTICAL"<<endl;
    }
    else if(a1 == a2 && diff(b1, b2) == 1){
      cout<<"CLOSE"<<endl;
    }
    else cout <<"DIFFERENT"<<endl;
  }
  
  return 0;
}



Measured memory_bytes: 3244
#include <bits/stdc++.h>
#define ll long long

using namespace std;

int n;
int a[60];

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

	cin>>n;
	for(int i=1;i<=n;i++)
        cin>>a[i];
    int maxi=a[1];
    int mini=a[1];
    int maxind=1,minind=1;
    for(int i=1;i<=n;i++)
    {
        if(a[i]>maxi)
            maxind=i,maxi=a[i];
        if(a[i]<mini)
            minind=i,mini=a[i];
    }

    if(maxi>=0 && mini>=0)
    {
        cout<<n-1<<endl;
        for(int i=1;i<n;i++)
            cout<<i<<" "<<i+1<<endl;
        return 0;
    }

    if(maxi<=0 && mini<=0)
    {
        cout<<n-1<<endl;
        for(int i=n;i>1;i--)
            cout<<i<<" "<<i-1<<endl;
        return 0;
    }

    if(maxi+mini>=0)
    {
        cout<<2*n-2<<endl;
        for(int i=1;i<=n;i++)
            if(i!=maxind)
                cout<<maxind<<" "<<i<<endl;

        for(int i=1;i<n;i++)
            cout<<i<<" "<<i+1<<endl;
        return 0;
    }

    cout<<2*n-2<<endl;
    for(int i=1;i<=n;i++)
        if(i!=minind)
            cout<<minind<<" "<<i<<endl;

    for(int i=n;i>1;i--)
            cout<<i<<" "<<i-1<<endl;


	return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {

  int num;
  int s;

  int rand;

  
  cin >> num;

  for(int i=0;i<num;i++) {
    
    cin >> s;

    cout << "Case " << i+1 << ":" << endl;

    rand=s;

    for(int j=0;j<10;j++) {

      rand=rand*rand;

      if(rand>=1000000) rand%=1000000;

      rand/=100;

      cout << rand << endl;

    }

  }

  return 0;

}

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

int main() {
  int n,q;
  vector<int> S,T;

  cin >> n;
  for(int i=0;i<n;i++) {
    int s;
    cin >> s;
    S.push_back(s);
  }
  cin >> q;
  for(int i=0;i<q;i++) {
    int t;
    cin >> t;
    T.push_back(t);
  }

  // O(n^2)
  int C = 0;
  for(int t_itr=0;t_itr<q;t_itr++) {
    int key = T[t_itr];
    for(int s_itr=0;s_itr<n;s_itr++) {
      if(S[s_itr] == key) {
        C++;
        break;
      }
    }
  }

  cout << C << endl;
}

Measured memory_bytes: 1320
n = int(input())
d_L = [list(map(int, input().split())) for i in range(n)]  
from collections import OrderedDict
def make_p(d):
    p = OrderedDict()
    for k, v in zip(["T", "N", "S", "E", "W", "B"], [d[0], d[4], d[1], d[2], d[3], d[5]]):
        p[k] = v
    return p
def judge_dice(d, d2):
    p, p2 = make_p(d), make_p(d2)
    for c in "SSSWNNNWNNNESSSWNNNESSSX":       
        t, n, s, e, w, b = p["T"], p["N"], p["S"], p["E"], p["W"], p["B"]
        if p == p2:
            return 0
            break
        if c == "N":
            p["N"], p["T"], p["S"], p["B"]= t, s, b, n
        if c == "S":
            p["N"], p["T"], p["S"], p["B"]= b, n, t, s
        if c == "E":
            p["E"], p["T"], p["W"], p["B"]= t, w, b, e
        if c == "W":
            p["E"], p["T"], p["W"], p["B"]= b, e, t, w       
         
for i, d in enumerate(d_L):
    if d == d_L[-1]:
        print("Yes")
    for d2 in d_L[i+1:]:
        if judge_dice(d, d2) == 0:
            print("No")
            break
    else:
        continue
    break


Measured memory_bytes: 6020
#include <cstdio>
#include <cmath>
#include <iostream>
#include <cstdlib>
#include <string>
#include <iomanip>
#include <ctime>
#include <set>
#include <sstream>
#include <map>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
int n;
int main(){
//freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	cin>>n;
	if((n/100)==(n%10))
	{
		printf("Yes\n");
	}
	else
	printf("No\n");
    return 0;
}



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

struct UnionFind{
    vector<int> r;
    
    UnionFind(int N){
        r = vector<int>(N, -1);
    }
    
    int root(int x){
        if(r[x]<0)  return x;
        return r[x] = root(r[x]);
    }
    
    bool unite(int x, int y){
        x = root(x);
        y = root(y);
        if(x==y)    return false;
        if(r[x]>r[y])   swap(x,y);
        r[x]+=r[y];
        r[y]=x;
        return true;
    }
    
    int size(int x){
        return -r[root(x)];
    }
};



int main(void){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(15);

    int n,m;
    cin>>n>>m;
    
    UnionFind UF(n);
    for(int i=0; i<m; i++){
        int a,b;
        cin>>a>>b;
        a -= 1;
        b -= 1;
        UF.unite(a,b);
    }
    
    int ans=0; 
    for(int i=0; i<n; i++){
        ans = max(ans, UF.size(i));
    }

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

Measured memory_bytes: 3964
def getN():
    return int(input())

def getlist():
    return [(int(x), i) for i, x in enumerate(input().split())]

n = getN()
nums = getlist()
nums.reverse()

buffer = []
tmp = 0
used = {}

def insertcheck(n, k):
    if sum(mask[:k]) < n-1:
        return False

    return True

ans = []
mask = [0 for i in range(n)]
flag = 1


def search(nums):
    for num in nums:
        val, idx = num
        if mask[num[1]] == 0:
            if insertcheck(val, idx):
                ans.append((val,idx))
                used[num[0]] = num[1]
                mask[num[1]] = 1
                return 1

    return 0

while(flag):
    flag = search(nums)

if len(ans) != n:
    ans = [(-1, -1)]

for an in ans:
    print(an[0])


"""
9
1 1 1 2 2 1 2 4 2
"""

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

long modpow(long a, long n, long m){
  long r = 1;
  while(n){
    if(n & 1)  r = r * a % m;
    a = a * a % m;
    n >>= 1;
  }
  return r;
}

int main(){
  int n;  cin >> n;
  vector<int> table(n, 0);
  for(int i=0; i<n; i++){
    int a;  cin >> a;
    table[a]++;
  }
  table[0]++;
  long ans = 1;
  for(int i=(n+1)%2; i<n; i+=2)
    if(table[i] != 2)  ans = 0;
  
  ans = ans * modpow(2, n/2, 1e9+7);

  cout << ans << endl;

  return 0;
}


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

int main() {
  int N,K,kekka;
  cin >> N >> K;
  kekka = 1;
  for(int i = 0;i < N;i++)
  {
  if(kekka < K)
  {
  	kekka *= 2;
  }
  else
  {
  	kekka += K;
  }
  }
  cout << kekka << endl;
}


Measured memory_bytes: 256
s=[int(j) for j in input()][::-1]
c=[0]*2019
tmp=0
c[0]+=1
t=1
import numpy as np
for i in s:
    tmp+=t*i
    c[tmp%2019]+=1
    t=t*10%2019
c=np.array(c)
ans=c*(c-1)//2
print(ans.sum())

Measured memory_bytes: 27896
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Jul  7 18:46:49 2020

@author: naoki
"""
N, K = map(int, input().split())
red_num = N-K

mod = 1000000007

kai = [1 for _ in range(2001)]
for i in range(2,2001):
    kai[i] = kai[i-1]*i%mod


for i in range(1,min(K, red_num+1)+1):
    place_option = kai[red_num+1]*pow(kai[i],mod-2,mod)*pow(kai[red_num+1-i],mod-2,mod)
    devide_option = kai[K-i+(i-1)]*pow(kai[K-i],mod-2,mod)*pow(kai[i-1],mod-2,mod)
    answer = (place_option%mod * devide_option%mod)%mod

    print(answer)

if red_num+1<K:
    for i in range(red_num+1,K):
        print(0)

Measured memory_bytes: 74464
#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<stack>
#include<map>
#include<set>
#include<cstdint>
#include<unordered_map>
#include<sstream>
#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 vll vector<ll>
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
#define pb push_back

namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

typedef pair<string, int> P;

bool ps1(const P& element1, const P& element2)
{//first昇順
	return element1.first < element2.first;
}
bool ps2(const P& element1, const P& element2)
{//first降順
	return element1.first > element2.first;
}
bool ps3(const P& element1, const P& element2)
{//second昇順
	return element1.second < element2.second;
}
bool ps4(const P& element1, const P& element2)
{//second降順
	return element1.second > element2.second;
}



int main()
{
	int n;
	cin >> n;
	vector<pair<string, int>>res(n);
	map<int, int>num;
	rep(i, n) {
		cin >> res[i].F >> res[i].second;
	
		num[res[i].S] = i + 1;
	}

	stable_sort(all(res),ps4);
	stable_sort(all(res), ps1);


	rep(i, n) {
		cout << num[res[i].S] << endl;
	}
}



Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <iostream>
#include <vector>
#include <set>
using namespace std;
set<int> n;
int tmp;
int main(){
    for(int i=0;i<3;i++) {
        cin>>tmp;
        n.insert(tmp);
    }
    cout<<n.size();


    return 0;
}



Measured memory_bytes: 384
#include <stdio.h>
int n,q;
int a,b;
int i;
int to[500000]={0},next[500000]={0};
int last;
int cnt[200000]={0};
int inc[200000]={0};
int p,x;
int stack[200000]={0};
int slast=0;
void dfs(int node,int inc2){
    inc2+=inc[node];
    //printf("%d\n",inc2);
    cnt[node]+=inc2;
    int p=next[node];
    while(p){
        dfs(to[p],inc2);
        p=next[p];
    }
    
}

int main(void){

    scanf("%d%d",&n,&q);
    last=n+1;
    for(i=0;i<n-1;i++){
        scanf("%d%d",&a,&b);
        to[last]=b;
        next[last]=next[a];
        next[a]=last;
        last++;
    }
    for(i=0;i<q;i++){
        scanf("%d%d",&p,&x);
        inc[p]+=x;
    }

    /*int t,point,inc2=0;
    stack[slast]=1;
    slast++;
    inc2=inc[1];
    cnt[1]=inc[1];
    while(slast){
        slast--;
        t=stack[slast];
        inc2-=inc[t];
        t=next[t];
        while(t){
            inc2+=inc[to[t]];
            cnt[to[t]]+=inc2;
            stack[slast]=to[t];
            t=next[t];
            slast++;
        }
    }*/
    dfs(1,0);
    for(i=1;i<=n;i++){
        printf("%d ",cnt[i]);
    }
    return 0;
}

Measured memory_bytes: 13696
# -*- coding: utf-8 -*-
# E
# 文字列比較をローリングハッシュを用いると高速
# 用いなくてもpypy使わなくえれば通る

import sys
from collections import defaultdict, deque
from heapq import heappush, heappop
import math
import bisect
input = sys.stdin.readline

# 再起回数上限変更
# sys.setrecursionlimit(1000000)

n = int(input())
s = input()[:-1]
# s = list(map(ord, list(input()[:-1])))
# print(s)

lb = 0
ub = n//2 + 1


def check(len):
    # これはTLE
    for l1 in range(n-len):
        for l2 in range(l1+len, n-len+1):
            if s[l1:l1+len] == s[l2:l2+len]:
                return True
    return False


def check3(m):
    # これはOK(pypyではなくpython3）
    dic = defaultdict(str)
    # dic = {}
    for i in range(n-m+1):
        s_ = s[i:i+m]
        if s_ in dic.keys():
            if dic[s_]+m<=i:
                return True
        else:
            dic[s_] = i
    return False


mod = 10**9+7
base = 1234
power = [1]*(n+1)
for i in range(1, n+1):
    power[i] = power[i-1]*base%mod

def check2(m):
    res = 0
    for i in range(m):
        res+=s[i]*power[m-i-1]
        res%=mod

    dic = {res: 0}
    # defaultdictが早い
    # dic = defaultdict(int)
    # dic[res] = 0

    for i in range(n-m):
        res = ((res-s[i]*power[m-1])*base
                             +s[i+m])%mod
        if res in dic.keys():
            index = dic[res]
            if index +m<=i+1:
                return True
        else:
            dic[res] = i+1
    return False


while ub > lb+1:
    x = (lb + ub)//2
    if check3(x):
        lb = x
    else:
        ub = x
    # print(lb, ub)


'''
print(3, check(3))
print(4, check(4))
print(5, check(5))
'''

print(lb)

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

int main()
{
    int N; cin >> N;
    int W; cin >> W;
    vector<int> v(N), w(N); F(i,N) cin >> w[i] >> v[i];
    vector<vector<int long>> DP(N+1,vector<int long>(W+1,0));

    for(int i=0; i<N; i++)
    {
        for(int j=0; j<=W; j++)
        {   
            if(j >= w[i])
            {
                DP[i+1][j] = max(DP[i][j-w[i]] + v[i], DP[i][j]);
            }
            else
            {
                DP[i+1][j] = DP[i][j];
            }
        }
    }
    cout << DP[N][W];
}

Measured memory_bytes: 80256
#pragma warning(disable:4996)

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

//int s_dsort(const void* a, const void* b);

int main(void) {
	int N,K,i,cnt=0;
	int A;
	
	scanf("%d %d", &N, &K);
	for (i = 0; i < N; i++) {
		scanf("%d", &A);
		if (A < K)continue;
		cnt++;
	}
	
	printf("%d", cnt);
	return 0;
}

Measured memory_bytes: 128
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V)) //小さい方からソート
#define REV(V) reverse(ALL(V)) //リバース
#define RSORT(V) SORT(V);REV(V) //大きい方からソート
#define NPN(V) next_permutation(ALL(V)) //順列
#define pb(n) push_back(n)
#define endl '\n'
#define Endl '\n'
#define DUMP(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define Yay(n) cout << ((n) ? "Yay!": ":(") << endl
#define RAPID cin.tie(0);ios::sync_with_stdio(false)
#define IN(n) cin >> n
#define IN2(a,b) cin >> a >> b
#define IN3(a,b,c) cin >> a >> b >> c 
#define IN4(a,b,c,d) cin >> a >> b >> c >> d
#define VIN(V) for(int i = 0; i < (V).size(); i++) {cin >> (V).at(i);}
#define OUT(n) cout << n << endl
#define VOUT(V) REP(i, (V).size()) {cout << (V)[i] << endl;}
#define VOUT2(V) REP(i, (V).size()) {cout << (V)[i] << " ";} cout<<endl;

// 型マクロ定義
#define int long long
#define P pair<ll,ll>
#define Vi vector<ll>
#define Vd vector<double>
#define Vs vector<string>
#define Vc vector<char>
#define M map<ll,ll>
#define S set<ll>
#define PQ priority_queue<ll>
#define PQG priority_queue<ll,V,greater<ll>
//

const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int gcd(int a,int b){return b?gcd(b,a%b):a;} //最小公倍数

// デフォルト変数定義
int n,m,a,b,c,d,x,y,z;
string s,t;
//

signed main() {
  RAPID;
  IN3(a,b,c);
  if(a==b) OUT(c);
  else if(a==c) OUT(b);
  else OUT(a);
}

Measured memory_bytes: 256
n = int(input())
h = list(map(int, input().split()))
table = [0] * (n+2)

table[1] = abs(h[0] - h[1])

for i in range(2,n):
    table[i] += min(table[i-2] + abs(h[i-2] - h[i]), table[i-1] + abs(h[i-1] - h[i]))
print(table[n-1])

Measured memory_bytes: 13980
#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;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2012&lang=jp>
 問題文============================================================
 =================================================================
 解説=============================================================
 
 x+y*y+z*z*z = e
x = e - y*y - z*z*z >= 0
 ================================================================
 */

ll solve(ll e){
    ll res = LINF;
    for(ll y = 0; y*y <= e; y++){
        for(ll z = 0; z*z*z <= e; z++){
            ll x = e - y*y - z*z*z;
            if(x >= 0) res = min(res,x+y+z);
        }
    }
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    int e;
    while(cin >> e,e){
        cout << solve(e) << endl;
    }
    return 0;
}



Measured memory_bytes: 3112
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
typedef long long ll;


int main()
{

    int x,flag=0;
    scanf("%d",&x);
    ll a=0,b=0;
    ll c,d;
    double y;
    int k;

    while(flag==0)
    {
        k=0;
        y=x;
        c=a*a*a*a*a;
        y=y-c;
        if(y<0)
        {
            y=-y;
            k=1;
        }
        b=pow(y,0.2);
        if(y==b*b*b*b*b)
        {
            flag=1;
        }
        else
        {
            a=a+1;
        }
        
    }
    

    if(k==1)
    {
        printf("%lld %lld\n",a,b);
    }
    else
    {
        printf("%lld %lld\n",a,-b);
    }
    

    return 0;
}

Measured memory_bytes: 2592
#include <iostream>
using namespace std;
int main(){
    int a,b;
    string s;
    cin >> a >> b;
    if(a > b) s = " > ";
    else if(a < b) s = " < ";
    else s = " == ";
    
    cout << "a" << s << "b" << endl;
    return 0;
}


Measured memory_bytes: 3160
k,n = map(int,input().split())
mx = 0
a = list(map(int,input().split()))
for i in range(n-1):
  if a[i+1]-a[i] > mx:
    mx = a[i+1]-a[i]
if (k-(a[n-1]-a[0])) > mx:
  mx = (k-(a[n-1]-a[0])) 
print(k-mx)
  

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

int a[101];

int main(){
	int x, n;

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

	}

	int res = x;
	int dis = 102;

	for(int i=x; i<= 101; i++){
		if (a[i] == 0){
			dis = i-x;
			res = i;
			break;
		}
	}

	for(int i=x; i>=0; i--){
		if (a[i] == 0 and x-i <= dis){
			res = i;
			break;
		}
	}


	cout << res << endl;
}

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

#define ll long long
#define vecll vector<long long>
#define vec2ll vector<vector<long long>>
#define vecpairll vector<pair<long long,long long>>
#define forll(s,a,b) for(long long s = a;s < b;s++)
#define forllde(s,a) for(long long s = a;s > 0;s--)


int main()
{
  ll n, k, d, c=0, ap;
  cin >> n >> k;
  vecll a(n, 0);
  forll(i, 0, k){
	cin >> d;
	forll(j, 0, d){
	  cin >> ap;
	  a[ap-1]++;
	}
  }
  forll(i, 0, n){
	if (a[i] != 0)
	  c++;
  }
  cout << n - c << endl;
}


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

using ll = long long;

#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 rrng(a) a.rbegin(), a.rend()
#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 vl = vector<ll>;
using vvl = vector<vl>;
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 h = 3, w = 3;
  vector<string> grid(h); rep(i, h) std::cin >> grid[i];
  rep(i, 3) std::cout << grid[i][i] << (i+1 < h ? "" : "\n");
}


Measured memory_bytes: 256
from itertools import combinations
from bisect import bisect_left, bisect_right

N = int(input()) #2*10**3
L_list = [int(e) for e in input().split()]
index_list = [i for i in range(N)]

L_list.sort(reverse=False)
#print(L_list)

ans = 0

for comb in combinations(index_list, 2): #(2*10*3)*(2*10*3 -1)/2 ≒ 2*10*6
    a = L_list[comb[0]]
    b = L_list[comb[1]]
    
    #a < b+c ∴a-b < c
    #b < c+a ∴b-a < c
    if a-b > 0:
        low_limit = a-b
    else:
        low_limit = b-a
    index_left = bisect_right(L_list, low_limit) #log(2*10**6)≒6.3

    #c < a+b
    index_right = bisect_left(L_list, a+b) #log(2*10**6)
    
    #print(a,b,low_limit,a+b)
    #print(L_list[index_left:index_right])
    
    OK_c = index_right - index_left
    
    if index_left <= comb[0] <= index_right:
        OK_c -= 1
    if index_left <= comb[1] <= index_right:
        OK_c -= 1
        
    #print(OK_c)
    ans += OK_c
    
print(ans//3)

Measured memory_bytes: 49152
#include <algorithm>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
const ll INF = 1ll << 60;

int main() {
  int X, Y, Z;
  while (cin >> X >> Y >> Z) {
    int N = X + Y + Z;
    vector<pair<ll, ll>> AB(N);
    ll csum = 0;
    for (int i = 0; i < N; i++) {
      ll A, B, C;
      cin >> A >> B >> C;
      AB[i] = make_pair(A - C, B - C);
      csum += C;
    }
    sort(AB.begin(), AB.end(), [&](const auto& a, const auto& b) {
      return a.first - a.second < b.first - b.second;
    });
    vector<ll> dpY(N);
    {
      priority_queue<ll, vector<ll>, greater<ll>> pq;
      ll sum = 0;
      for (int i = 0; i < Y; i++) {
        pq.push(AB[i].second);
        sum += AB[i].second;
      }
      dpY[Y - 1] = sum;
      for (int i = Y; i < N; i++) {
        sum += AB[i].second;
        pq.push(AB[i].second);
        sum -= pq.top();
        pq.pop();
        dpY[i] = sum;
      }
    }
    vector<ll> dpX(N);
    {
      priority_queue<ll, vector<ll>, greater<ll>> pq;
      ll sum = 0;
      for (int i = 0; i < X; i++) {
        pq.push(AB[N - i - 1].first);
        sum += AB[N - i - 1].first;
      }
      dpX[N - X] = sum;
      for (int i = X; i < N; i++) {
        sum += AB[N - i - 1].first;
        pq.push(AB[N - i - 1].first);
        sum -= pq.top();
        pq.pop();
        dpX[N - i - 1] = sum;
      }
    }
    ll ans = -INF;
    for (int i = Y - 1; i + X < N; i++) {
      ans = max(ans, dpY[i] + dpX[i + 1]);
    }
    ans += csum;
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 4508
#include<iostream>
using namespace std;
 
int main(){
  int N;
  cin >> N;
  bool in = false;
  int Np = N;
  for (int i = 0; i < 3; i++){
    if (Np %10 == 7){
      in = true; break;
    }
    Np /= 10;
  }
  if (in) cout << "Yes" << endl;
  else cout << "No" << endl;
}
      

Measured memory_bytes: 3580
#include <stdio.h>
int main(void){
  int n,a[100001],sh=1,cnt=0,flag[100001];
  for(int i=0; i<100000; i++)
    flag==0;
  scanf("%d",&n);
  for(int i=0; i<n; i++)
    scanf("%d",&a[i]);
  
  for(int i=0; i<n; i++){
    sh=a[sh-1];
    cnt++;
    if(sh==2){
      printf("%d\n",cnt);
      return 0;
    }
  }
  puts("-1");
  return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define fi first
#define sec second 
#define MOD 1000000007
#define pb push_back
#define test cout<<"debuged\n";
#define INF 10000000000
#define si 1000000
#define debug(x) cout<<x<<"\n";

vector<ll> adj[si];
bool vis[si];
ll dp[si]={0};
void dfs(ll i)
{
    
        vis[i]=true;
        for(auto x:adj[i])
        {
          if(!vis[x])
          {
            dfs(x);
            dp[i]=max(dp[i],dp[x]+1);
          }
           dp[i]=max(dp[i],dp[x]+1);
        }
   
}


int main()
{
    ios_base::sync_with_stdio(false);
   
    ll n,m;
    cin>>n>>m;
    ll x,y;
    for(ll i=0;i<m;i++)
    {
      cin>>x>>y;
      adj[x].pb(y);
    }
    memset(vis,false,n+1);
    for(ll i=1;i<=n;i++)
    {
      if(!vis[i])
        dfs(i);
    }
   cout<<*max_element(dp+1,dp+n+1);
   
}

Measured memory_bytes: 32256
#pragma GCC optimize("O2")
#include <bits/stdc++.h>
// #include <iostream>
// #include <array>
// #include <cmath>
// #include <array>
// #include <vector>
// #include <set>
// #include <algorithm>
// #include <functional>
// #include <numeric>
// #include <map>
// #include <unordered_map>
// #include <queue>
using namespace std;
// #define MOD  998244353
// #define MOD ll(1e9) + 7
#define ll long long
const double PI = atan(1.0) * 4;
// const int N = 1e5 + 5 ;
// const ll INF = (int)1e9 ;
const int dx[4] = { -1, 0, 1, 0} ;
const int dy[4] = {0, -1, 0, 1} ;
// const ll INF = (ll)2e18 + 50;
const ll INF = 1e9 ;
const ll MOD = 1e9 + 7 ;

ll power(ll a , ll e) {
	ll res = 1LL ;
	while (e > 0) {
		if (e % 2 == 1) res = res * a % MOD ;
		a =  a * a % MOD ;
		e /= 2 ;
	}
	return res ;
}
vector<int> complement(const vector<int> &vec) {
	int n = vec.size() ;
	vector<bool> occur(n + 1 , true) ;
	vector<int> ans ;
	for (int i = 0 ; i < (int)vec.size() ; i++) {
		occur[vec[i]] = false ;
	}
	for (int i = 1 ; i <= n ; i++) {
		if (occur[i]) ans.push_back(i) ;
	}
	return ans ;
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	// int t ;
	// cin >> t;
	// while (t--) {
	int x , n ;
	cin >> x >> n ;
	vector<int> a(n) ;
	set<int> s ;
	for (int i = 0 ; i <  n ; i++) {
		cin >> a[i] ;
		s.insert(a[i]) ;
	}
	if (n == 0) cout << x << "\n";
	else {
		int mn , mn1;
		for (int i = x  ; i <= 200 ; i++) {
			if (s.find(i) == s.end()) {
				mn = i ;
				break ;
			}
		}
		// cout << mn << "\n";
		for (int i = x  ; i >= -200 ; i--) {
			if (s.find(i) == s.end()) {
				mn1 = i ;
				break ;
			}
		}
		// cout << mn1 << "\n";
		if (abs(x - mn) > abs(x - mn1)) cout << mn1 << "\n";
		else if (abs(x - mn) < abs(x - mn1)) cout << mn << "\n";
		else {
			cout << mn1 << "\n";
		}
	}



	// }
	return 0;
}


Measured memory_bytes: 3656
#include<bits/stdc++.h>
#define ll long long
const int N=200005;
using namespace std;
map<ll,ll>mp;
int a[N],n;
ll ans;
int main(){
	cin>>n;
	for(int i=1;i<=n;i++) cin>>a[i];
	for(int i=1;i<=n;i++)
		if(i-a[i]>0) mp[i-a[i]]++;
	for(int i=1;i<=n;i++)
		if(mp[i+a[i]]>0) ans+=mp[i+a[i]];
	cout<<ans;
    return 0;
}

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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]A - abc of ABC
            var S = Console.ReadLine();
            var abc = new Dictionary<char, int>();
            abc.Add('a', 0);
            abc.Add('b', 0);
            abc.Add('c', 0);

            foreach(var c in S)
            {
                abc[c]++;
            }

            if(IsAbc(abc))
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }

        static bool IsAbc(Dictionary<char, int> abc)
        {
            foreach(var v in abc.Values)
            {
                if(v != 1)
                {
                    return false;
                }
            }

            return true;
        }
    }
}


Measured memory_bytes: 13152
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
	        int[] n =new int[10];
	        int m;
	        int i=0;
	        while(stdIn.hasNext()){
	            m=stdIn.nextInt();
	            if(m!=0){
	                n[i]=m;
	                i++;
	            }
	            else{
	                i--;
	                System.out.println(n[i]);
	            }
	        }
	    }
	 
	}

Measured memory_bytes: 26084
#include <stdio.h>
#include <algorithm>
using ll = long long;
int main() {
	ll N, A, B;
	scanf("%lld %lld %lld", &N, &A, &B);
	if (B < A || ((A != B) && N == 1)) {
		printf("%lld\n", 0ll);
	} else {
		ll Min = (N - 1) * A + B;
		ll Max = (N - 1) * B + A;
		ll Pa = Max - Min + 1;
		printf("%lld\n", Pa);
	}
}

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

#ifdef DEBUG
#define PRINT(x)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#x<<" = "<<(x)<<endl;
#define PRINTA(a,first,last)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#a<<"["<<(first)<<", "<<(last)<<")"<<endl;\
    for (int _i=(first);_i<(last);++_i){cout<<#a<<"["<<_i<<"] = "<<(a)[_i]<<endl;}
#define PRINTP(p)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#p<<" = ("<<(p.first)<<", "<<(p.second)<<")"<<endl;
#define PRINTI(a,i)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#a<<"["<<#i<<"] = "<<#a<<"["<<(i)<<"] = "<<(a)[i]<<endl;
#else
#define PRINT(x)
#define PRINTA(a,first,last)
#define PRINTP(p)
#define PRINTI(a,i)
#endif

#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 RREP(i,n) for (int i=(n)-1;i>=0;--i)
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define MOD 1000000007
//#define MOD 998244353

using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

template <class T, class U> void amax(T& x, U y) {if (x < y) x = y;}
template <class T, class U> void amin(T& x, U y) {if (x > y) x = y;}

template <class T>
using vec2 = vector<vector<T>>;

template <class T>
using vec3 = vector<vector<vector<T>>>;

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

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

    int D;
    cin >> D;
    vector<int> c(26);
    REP(i, 26) cin >> c[i];
    vector<vector<int>> s(D, vector<int>(26));
    REP(i, D) REP(j, 26) cin >> s[i][j];
    vector<int> t(D);
    REP(i, D) {
        cin >> t[i];
        --t[i];
    }


    int score = 0;
    vector<int> last(26, -1);
    REP(d, D) {
        score += s[d][t[d]];
        last[t[d]] = d;
        REP(i, 26) {
            score -= c[i] * (d - last[i]);
        }
    }


    vector<set<int>> se(26, {-1, D});
    REP(d, D) {
        se[t[d]].insert(d);
    }

    int M;
    cin >> M;
    REP(_, M) {
        int d, q;
        cin >> d >> q;
        --d;
        --q;
        auto it = se[t[d]].find(d);
        int L1 = *it - *prev(it);
        int L2 = *next(it) - *it;
        PRINT(*it);
        PRINT(*prev(it));
        PRINT(*next(it));
        se[t[d]].erase(d);
        se[q].insert(d);
        it = se[q].find(d);
        int L3 = *it - *prev(it);
        int L4 = *next(it) - *it;
        PRINT(*it);
        PRINT(*prev(it));
        PRINT(*next(it));
        PRINT(L3);
        PRINT(L4);
        int L12 = L1 + L2;
        int L34 = L3 + L4;
        //score += s[d][q] - s[d][t[d]] + c[t[d]] * (L1 * (L1 - 1) / 2 + L2 * (L2 - 1) / 2 - L12 * (L12 - 1) / 2) + c[q] * (L34 * (L34 - 1) / 2 - L3 * (L3 - 1) / 2 - L4 * (L4 - 1) / 2);
        score += s[d][q] - s[d][t[d]] + ((c[t[d]] * (L1 * (L1 - 1) + L2 * (L2 - 1) - L12 * (L12 - 1)) + c[q] * (L34 * (L34 - 1) - L3 * (L3 - 1) - L4 * (L4 - 1))) >> 1);
        t[d] = q;
        cout << score << '\n';
    }
    cout << flush;

    return 0;
}


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

int main() {
    int N;
    double ans = 0.0, A;
    cin >> N;
    for (int i=1; i<=N; ++i) {
        cin >> A;
        ans += 1.0 / A;
    }
    cout << setprecision(16) << 1.0 / ans << endl;
    return 0;
}

Measured memory_bytes: 256