akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define all(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,int> pli;
typedef pair<int,int> pii;
#define rep(i,a,b) for(ll i=a ; i<b ; i++)
#define qrep(que, ite) for(auto ite=begin(que) ; ite!=end(que) ; ite++)
const int max_n = 1e5;
const ll mod = 1e9+7;
const ll INF = 1e17;
const int inf = 1e5;
typedef long double ld;
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; }
ll gcd(ll a, ll b) { return a ? gcd(b%a, a) : b; }
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
ll mo = 998244353;
struct UnionFind {
    vector<int> par;

    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    int size(int x) {
        return -par[root(x)];
    }
};
struct SegmentTree{
  int N;
  vector<int> node;
  public :
    void intit(vector<int>v){
      int sz = v.size();
      N=1;
      while(N<sz) N*=2;
      node.resize(N);
      for(int i=0 ; i<sz ; i++) node[i+N-1] = v[i];
      for(int i=N-2 ; i>=0 ; i--) node[i] = min(node[i*2+1], node[i*2+2]);
    }
    void update(int x, int val){
      x += N-1;
      node[x+N-1] = val;
      while(x>0){
        x = (x-1)/2;
        node[x] = min(node[x*2+1], node[x*2+2]);
      }
    }
    int getmin(int a, int b, int k, int l, int r){
      if(b<=l || r<=a) return inf;
      else if(a<=l && r<=b) return node[k];
      else{
        int vl = getmin(a, b, 2*k+1, l, (l+r)/2);
        int vr = getmin(a, b, 2*k+2, (l+r)/2, r);
        return min(vl, vr);
      }
    }
};
int main(){
  string s; cin>>s;
  rep(i,0,s.size()){
    if(s[i]=='?') s[i] = 'D';
  }
  cout<<s<<endl;
  return 0;
}


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

typedef long long ll;

int main(){
    int n, x, y;
    cin >> n>>x>>y;
    x--;
    y--;
    int a[n], d[n][n];
    for(int i=1; i<n; i++) a[i] = 0;
    for(int i=0; i<n; i++){
        for(int j=i+1; j<n; j++){
            d[i][j] = j - i;
            d[i][j] = min(d[i][j], (int)fabs(x-i)+1+(int)fabs(y-j));
            a[d[i][j]]++;
        }
    }
    for(int i=1; i<n; i++) cout << a[i] << endl;
}

Measured memory_bytes: 15744
n=int(input())
a=list(map(int,input().split()))

odd = []
even = []
for i in range(n):
    if i%2==0:
        even.append(a[i])
    else:
        odd.append(a[i])
if n%2!=0:
    b=even[::-1]+odd
else:
    b=odd[::-1]+even

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


Measured memory_bytes: 32196
f=True
while True:
    for i in range(3):
        g=list(input())
        if g[0]=='0':
            f=False
            break
        a,b=0,0
        del g[0]
        for j in g:
            if j =='A':a+=1
            else:b+=1
        if a>b:
            a+=1
        else:
            b+=1
        print(a, b)
    if not f:break


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

void solve(int cnt,string str,int left,int right){
  if(cnt == -1){
    if(left == right) cout << str << endl;
  } else {
    solve(cnt-1,str+'+',left,right+(int)pow(3,cnt));
    solve(cnt-1,str+'0',left,right);
    solve(cnt-1,str+'-',left+(int)pow(3,cnt),right);
  }
  return;
}

int main(){
  int w; cin >> w;
  int cnt = 0;
  while(w > ((int)pow(3,cnt+1)-1)/2){
    cnt++;
  }
  solve(cnt,"",w,0);
}

Measured memory_bytes: 1244
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>



#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define all(x) (x).begin(),(x).end()

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

typedef long long ll;

using namespace std;

struct edge{ll to,from,cost;};
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,m;cin>>n>>m;
  vector<edge>ed(m);
  rep(i,m)
  {
    ll a,b,c;
    cin>>a>>b>>c;
    a--;b--;
    ed[i]={b,a,-c};

  }
  vector<ll>dist(n,1e18);
  dist[0]=0;
  rep(i,n){
    rep(j,m){
      auto te=ed[j];
      chmin(dist[te.to],dist[te.from]+te.cost);
    }
  }
  ll f=dist[n-1];
  rep(i,n){
    rep(j,m){
      auto te=ed[j];
      chmin(dist[te.to],dist[te.from]+te.cost);
    }
  }
  if(f>dist[n-1])cout<<"inf"<<endl;
  else cout<<-dist[n-1]<<endl;


  return 0;

}


Measured memory_bytes: 384
def f(x):
    return x*(x-1)//2

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

d = collections.defaultdict(int)
for i in a:
    d[i]+=1
c = collections.defaultdict(int)
ans=0
for i in set(a):
    ans+=f(d[i])

for i in a:
    print(ans-(d[i]-1))

Measured memory_bytes: 26780
#include <bits/stdc++.h>
#define log(x) cout<<x<<endl
#define pb push_back
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
typedef long long lint;
using namespace std;
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; }
const long long INF = 1LL << 60;
using Graph=vector<vector<int>>;

int gcd(lint x, lint y){
  return y==0 ? x:gcd(y,x % y);
}

int digsum(int n) {
  int res = 0;
  while(n > 0) {
    res += n%10;
    n /= 10;
  }
  return res;
}

int dignum(int n) {
  int res = 0;
  while(n > 0) {
    res++;
    n /= 10;
  }
  return res;
}

int stringcount(string s, char c) {
  return count(s.cbegin(), s.cend(), c);
}

int lcm(lint x, lint y){
  return x/ gcd(x, y) * y;
}

int combi(int n, int r){
  int num = 1;
  for(int i = 1; i <= r; i++){
    num = num * (n - i + 1) / i;
  }
  return num;
}

int main(){
  int n,x,t;
  cin>>n>>x>>t;
  int count=0;
  int i=0;
  while(count<n){
    count+=x;
    i++;
  }
  cout<<t*i<<endl;
}

Measured memory_bytes: 3632
N = int(input())
li = [list(map(int,input().split())) for _ in range(N)]
dp = [[0]*3 for _ in range(N+1)]

for i in range(N):
  for j in range(3):
    a = 0
    for k in range(3):
      if j == k:
        continue
      a = max(a,(dp[i][k]))
    dp[i+1][j] = max(dp[i+1][j],a + li[i][j])
  
print(max(dp[-1]))

Measured memory_bytes: 47364
#include<iostream>
#include<string>
#include<cstring>
#include<cstdio>
using namespace std;

int main(void){
    int a=0,b=0,n;
    char o[10010];
    while(scanf("%s",&o) !=EOF){
        a=0,b=0;
        n=strlen(o);
    for(int i=0;i<n-2;i++){
        if(o[i]=='J'&&o[i+1]=='O'&&o[i+2]=='I')a++;
        if(o[i]=='I'&&o[i+1]=='O'&&o[i+2]=='I')b++;
    }
    cout<<a<<endl<<b<<endl;




    }
    return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define fill( x, y ) memset( x, y, sizeof x )
#define copy( x, y ) memcpy( x, y, sizeof x )
using namespace std;

typedef long long LL;
typedef pair < int, int > pa;

inline int read()
{
	int sc = 0, f = 1; char ch = getchar();
	while( ch < '0' || ch > '9' ) { if( ch == '-' ) f = -1; ch = getchar(); }
	while( ch >= '0' && ch <= '9' ) sc = sc * 10 + ch - '0', ch = getchar();
	return sc * f;
}

const int MAXN = 200005;
const int mod = 1e9 + 7;

struct node { int x, v; bool operator < ( const node &b ) const { return x < b.x; } } a[MAXN];
int l[MAXN], r[MAXN], f[MAXN], n, v[MAXN], ans;
pa t[MAXN];

inline void inc(int &x, int y) { x += y; if( x >= mod ) x -= mod; }
inline void dec(int &x, int y) { x -= y; if( x < 0 ) x += mod; }

int main()
{
#ifdef wxh010910
	freopen( "data.in", "r", stdin );
#endif
	n = read();
	for( int i = 1 ; i <= n ; i++ ) a[ i ].x = read(), a[ i ].v = v[ i ] = read();
	sort( a + 1, a + n + 1 ); sort( v + 1, v + n + 1 );
	for( int i = 1 ; i <= n ; i++ ) r[ i ] = max( a[ i ].v, r[ i - 1 ] );
	for( int i = n ; i ; i-- ) l[ i ] = i == n ? a[ i ].v : min( a[ i ].v, l[ i + 1 ] );
	for( int i = 1 ; i <= n ; i++ ) t[ i ] = mp( lower_bound( v + 1, v + n + 1, l[ i ] ) - v, lower_bound( v + 1, v + n + 1, r[ i ] ) - v );
	sort( t + 1, t + n + 1 );
	for( int i = 1, j = 0 ; i <= n ; i++ )
	{
		while( t[ j + 1 ].yy < t[ i ].xx - 1 ) j++;
		f[ i ] = f[ i - 1 ]; dec( f[ i ], f[ j ] );
		if( t[ i ].xx == 1 ) inc( f[ i ], 1 );
		if( t[ i ].yy == n ) inc( ans, f[ i ] );
		inc( f[ i ], f[ i - 1 ] );
	}
	return printf( "%d\n", ans ), 0;
}


Measured memory_bytes: 6528
import java.util.Arrays;
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		long sum = 0;
		int max = 0;
		int min = 0;
		boolean flag = false;
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		sc.nextLine();
		if (n > 0 && n <= 10000) {
			int arr[] = new int[n];
			for (int i = 0; i < arr.length; i++) {
				arr[i] = sc.nextInt();
				if (arr[i] >= -1000000 && arr[i] <= 1000000) {
					sum += arr[i];
					flag = true;
				} else {
					break;
				}

			}
			if (flag == true) {
				Arrays.sort(arr);
				min = arr[0];
				max = arr[arr.length - 1];
				System.out.println(min + " " + max + " " + sum);
			}

		}

	}

}

Measured memory_bytes: 41268
#include<bits/stdc++.h>
#define N 105
using namespace std;
char s[N][N];
int n,m;
int x,y,ans;
int cnt[N][N];
void mmax(int &x,int v){
	x=max(x,v);ans=max(ans,v);
}
int get(int x1,int y1,int x2,int y2){
	return cnt[x2][y2]-cnt[x2][y1-1]-cnt[x1-1][y2]+cnt[x1-1][y1-1];
}
int dp[2][N][N][N];
int main(){
	scanf("%d%d",&n,&m);
	for (int i=1;i<=n;i++) scanf("%s",s[i]+1);
	for (int i=1;i<=n;i++)
		for (int j=1;j<=m;j++){
			cnt[i][j]=cnt[i-1][j]+cnt[i][j-1]-cnt[i-1][j-1]+(s[i][j]=='o');
			if(s[i][j]=='E') x=i,y=j;
		}
	int now=0;
	for (int i=0;i<=x-1;i++){
		memset(dp[now^1],0,sizeof(dp[0]));
		for (int j=0;j<=n-x;j++)
			for (int k=0;k<=y-1;k++)
				for (int L=0;L<=m-y;L++){
					int v=dp[now][j][k][L];
					int xl=max(x-i,j+1),yl=max(y-k,L+1),xr=min(x+j,n-i),yr=min(y+L,m-k);
					if (x-i-1>j) mmax(dp[now^1][j][k][L],v+get(x-i-1,yl,x-i-1,yr));
					if (x+j+1<n-i+1) mmax(dp[now][j+1][k][L],v+get(x+j+1,yl,x+j+1,yr));
					if (y-k-1>L) mmax(dp[now][j][k+1][L],v+get(xl,y-k-1,xr,y-k-1));
					if (y+L+1<m-k+1) mmax(dp[now][j][k][L+1],v+get(xl,y+L+1,xr,y+L+1));
				}
		now^=1;
	}
	printf("%d\n",ans);
	return 0;
}

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

#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define mem(x,val) memset((x),(val),sizeof(x))
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define PI acos(-1.0) 
#define N 211111

const int INF = 1 << 30 ;
typedef long long ll ;
typedef pair < int , int > pii ;

int a[N] ;
ll sum1[N] , sum2[N] , ans = 1LL<<60 ;

int main() {
  int n ;
  scanf("%d", &n) ;
  for(int i = 1 ; i<=n ;i++)
    scanf("%d", &a[i]) ;

  for(int i = 1 ; i<=n ;i++){
    sum1[i] = sum1[i-1]+a[i] ;
    sum2[n-i+1] = sum2[n-i+2]+a[n-i+1] ;
  }

  for(int i = 1; i<n ;i++){
    ans = min(ans, abs(sum1[i]-sum2[i+1])) ;
  }
  cout << ans << endl ;
	
  return 0 ;
}



Measured memory_bytes: 4224
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))

T = input()

n = len(T)

ans = []
for i in range(n):
    if T[i] == "?":
        ans.append("D")
    else:
        ans.append(T[i])

print("".join(ans))

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

int main(){
  int n,m;
  cin>>n>>m;
  vector<int>h(n+10);
  int ans;
  
  for(int i=1;i<=n;i++){
    cin >> h.at(i);
  }
  vector<int>t(n+10);
  for(int i=0;i<m;i++){
    int a,b;
    cin>>a>>b;
    if(h.at(a)>h.at(b))
      t.at(b)++;
    if(h.at(a)==h.at(b)){
      t.at(a)++;
      t.at(b)++;
    }
    if(h.at(a)<h.at(b)){
      t.at(a)++;
    }
  }
  for(int i=1;i<=n;i++){
    if(t.at(i)==0){
      ans++;
    }
  }
  cout<<ans<<endl; 
}

Measured memory_bytes: 3976
from collections import defaultdict

n = int(input())

d = defaultdict(int)
for i in range(1, n+1):
    top = int(str(i)[0])
    bot = int(str(i)[-1])
    d[(top, bot)] += 1

ans = 0
for (top, bot), value in d.items():
    if (bot, top) in d:
        ans += value*d[(bot, top)]
print(ans)

Measured memory_bytes: 42092
import java.util.*;

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

        String c_input        = scan.next();
        
        char c = c_input.charAt(0);
            
        if( c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' )
          System.out.println("vowel");
        else
          System.out.println("consonant");
        
	  }
}

Measured memory_bytes: 23636
#include <bits/stdc++.h>
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Weverything"
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/range/adaptors.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/irange.hpp>
#pragma clang diagnostic pop

using namespace std;

char solve(std::string s_a, std::string s_b, std::string s_c) {
  char player = 'A';
  while (true) {
    switch (player) {
      case 'A':
        if (s_a.empty()) {
          return player;
        }
        player = std::toupper(s_a.front());
        s_a.erase(0, 1);
        break;
      case 'B':
        if (s_b.empty()) {
          return player;
        }
        player = std::toupper(s_b.front());
        s_b.erase(0, 1);
        break;
      case 'C':
        if (s_c.empty()) {
          return player;
        }
        player = std::toupper(s_c.front());
        s_c.erase(0, 1);
        break;
    }
  }
}

int main() {
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  std::string s_a;
  std::cin >> s_a;
  std::string s_b;
  std::cin >> s_b;
  std::string s_c;
  std::cin >> s_c;
  auto const res = solve(s_a, s_b, s_c);
  std::cout << res << std::endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	int A, B;
	int ans;

	scanf("%d %d", &A, &B); 

	ans = A+B;

	if(ans <= A-B){
		ans = A - B;
	}

	if(ans <= A * B){
		ans = A * B;
	}

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

	return 0;
}


Measured memory_bytes: 128
import java.util.*;


import java.io.*;

public class Main {
	static boolean[] c;
	static Map<Integer,Long>[] ma;
	@SuppressWarnings("unchecked")
	private static void solve(){
		//Implement solution here.
		int n = ni();
		c = new boolean[n + 1];
		ma = new HashMap[n + 1]; 
		for(int i = 0; i < n + 1; i++) {
			ma[i] = new HashMap<Integer,Long>();
		}

		for(int i = 0; i < n - 1; i++) {
			int u = ni();
			int v = ni();
			long w = nl();
			ma[u].put(v, w);
			ma[v].put(u, w);
		}
		
		dfs(0,1,0);
		for(int i = 1; i < n + 1; i++) {
			System.out.println(c[i] ? "0":"1");
		}

	}
	
	static void dfs(long wsum, int target, int before) {
		if(wsum %2 == 0) {
			c[target] = true;
		}
		for(int next:ma[target].keySet()) {
			if(next != before) {
				dfs(wsum + ma[target].get(next), next, target);
			}
		}		
	}
	

	//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 int array from one line
	private static Integer[] nao(int n) {
		Integer[] a = new Integer[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: 95504
#include <iostream>
using namespace std;
int a[10];
int b[11];
int main(){
  cin>>a[0]>>a[1]>>a[2]>>a[3]>>a[4]>>a[5]>>a[6]>>a[7]>>a[8];
  int n;
  cin>>n;
  for(int i=0;i<n;++i){
    cin>>b[i];
  }
  int ans=1;
  for(int i=0;i<n;++i){
    if(b[i]==a[0]){
      ans*=2;
    }
    if(b[i]==a[1]){
      ans*=3;
    }
    if(b[i]==a[2]){
      ans*=5;
    }
    if(b[i]==a[3]){
      ans*=7;
    }
    if(b[i]==a[4]){
      ans*=11;
    }
    if(b[i]==a[5]){
      ans*=13;
    }
    if(b[i]==a[6]){
      ans*=17;
    }
    if(b[i]==a[7]){
      ans*=19;
    }
    if(b[i]==a[8]){
      ans*=23;
    }
  }
  if(ans%30==0||ans%(2*7*17)==0||ans%(2*11*23)==0||ans%(7*11*13)==0||ans%(17*19*23)==0||ans%(3*11*19)==0||ans%(5*13*23)==0||ans%(5*11*17)==0){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}
    


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iomanip>
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<list>

using namespace std;
typedef long long LL;
typedef unsigned long long ULL;

#define rep(i,k,n) for(int i=(k);i<=(n);i++)
#define red(i,k,n) for(int i=(k);i>=(n);i--)
#define sqr(x) ((x)*(x))
#define clr(x,y) memset((x),(y),sizeof(x))
#define mod 1000000007
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)>(b)?(b):(a))
//const int maxn = ;

struct Edge
{
    int u,v,w,id;
}e[200010];

bool cmp(const Edge &a,const Edge &b){return a.w<b.w;}

struct tE
{
    int v,ord,next;
}te[200010];

int head[100010];
int tet;
LL mst;
LL ans[200010];
int f[100010];
int n,m,cnt;
bool me[200010];
int dep[100010];
int fa[100010];
bool vis[100010];
int fae[100010];

vector<int> ne;

void add(int u,int v,int ord)
{
    te[++tet].v=v;
    te[tet].ord=ord;
    te[tet].next=head[u];
    head[u]=tet;
}

int getf(int x){return x==f[x]?x:f[x]=getf(f[x]);}

void dfs(int u)
{
    vis[u]=1;
    for(int i=head[u];~i;i=te[i].next)
    {
        int v=te[i].v;
        if(vis[v])continue;
        fa[v]=u;
        fae[v]=i;
        dep[v]=dep[u]+1;
        dfs(v);
    }
}

int main()
{
//#define LOCAL
#ifdef LOCAL
	freopen("e:\\read.txt","r",stdin);
	//freopen("e:\\write.txt","w",stdout);
#endif
    while(cin>>n>>m)
    {
        ne.clear();
        rep(i,1,m)
        {
            scanf("%d%d%d",&e[i].u,&e[i].v,&e[i].w);
            e[i].id=i;
        }
        sort(e+1,e+1+m,cmp);
        rep(i,1,n)f[i]=i;
        mst=cnt=0;
        int a,b;
        clr(me,0);
        clr(head,-1);
        tet=0;
        rep(i,1,m)
        {
            a=e[i].u;
            b=e[i].v;
            if(getf(a)!=getf(b))
            {
                cnt++;
                mst+=e[i].w;
                me[e[i].id]=1;
                f[getf(a)]=getf(b);
                add(a,b,i);
                add(b,a,i);
            }
            else
            {
                ne.push_back(i);
            }
        }
        if(cnt<n-1){rep(i,1,m)puts("-1");continue;}
        rep(i,1,m)if(!me[i])ans[i]=mst;else ans[i]=-1;
        rep(i,1,n)f[i]=i;
        clr(dep,0);
        clr(fa,0);
        clr(vis,0);
        dfs(1);
        for(int i=0;i<ne.size();i++)
        {
            a=e[ne[i]].u;
            b=e[ne[i]].v;
            while(getf(a)!=getf(b))
            {
                if(dep[a]>dep[b])swap(a,b);
                int k=te[fae[b]].ord;
                if(ans[e[k].id]==-1)ans[e[k].id]=mst-e[k].w+e[ne[i]].w;
                else ans[e[k].id]=MIN(ans[e[k].id],mst-e[k].w+e[ne[i]].w);
                f[getf(b)]=getf(fa[b]);
                b=getf(fa[b]);
            }
        }
        rep(i,1,m)
        {
            printf("%lld\n",ans[i]);
        }
    }


	return 0;
}

Measured memory_bytes: 13404
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

int main() {
    vec a(5);
    rep(i, 5) cin >> a[i];
    rep(i, 5) {
        if (a[i] == 0) cout << i+1 << endl;
    }
    return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <istream>
#include <sstream>
#include <cctype>
#define fore(i,x,y) for(ll i=(x);i<(y);i++)
#define disp(a) cout << a << endl;
typedef long long ll;
using namespace std;

int main()
{
	ll N, K,ANS=0;
	cin >> N >> K;
	while (N / K != 0) {
		N = N / K;
		ANS++;
	}
	cout << ANS+1 << endl;
}

Measured memory_bytes: 256
use std::io::*;

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let mut n: u64 = itr.next().unwrap().parse().unwrap();

    let mut i = 2;
    let mut ans = 0;
    while i * i <= n {
        let mut cnt = 0;
        while n % i == 0 {
            cnt += 1;
            n /= i;
        }
        if cnt > 0 {
            // i ^ cntが約数
            let mut s = 0;
            let mut p = 1;
            while s + p <= cnt {
                s += p;
                p += 1;
                ans += 1;
            }
        }
        i += 1;
    }
    if n != 1 {
        ans += 1;
    }
    println!("{}", ans);
}


Measured memory_bytes: 2148
// author-Shivam gupta

#include <bits/stdc++.h>


using namespace std;

#define MEM(a, b) memset(a, (b), sizeof(a))

#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)

#define IN(A, B, C) assert( B <= A && A <= C)

#define MP make_pair
#define FOR(i,a) for(int i=0;i<a;i++)

#define FOR1(i,j,a) for(int i=j;i<a;i++)

#define EB emplace_back

#define INF (int)1e9

#define EPS 1e-9

#define PI 3.1415926535897932384626433832795

#define MOD 1000000007

#define read(type) readInt<type>()
#define max1 100001
#define out(x) cout<<x<<'\n'
#define out1(x) cout<<x<<" "
#define END cout<<'\n'
#define int long long
void fast(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}

signed main(){

fast();
int n;
cin>>n;
string s;
cin>>s;
int i=0;
int j=n-1;
int cnt=0;
while(i<j){
    if(s[i]=='R'){i++;continue;}
    if(s[j]=='W'){j--;continue;}
    i++;
    j--;
    cnt++;
}
out(cnt);
}


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

using ll = long long int;
using P = std::pair<int, int>;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rag(con) std::begin(con), std::end(con)

int main()
{
    int x;
    std::cin >> x;

    std::cout << (!x) << std::endl;

    return 0;
}

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

int n, m, row[110], col[110];
char a[110][110];
bool vr[110], vc[110];

int main ()
{
	cin >> n >> m;
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= m; ++j)
		{
			cin >> a[i][j];
			if (a[i][j] == '#')
				++row[i], ++col[j];
		}
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= m; ++j)
			if (!row[i] && !col[j])
				vr[i] = 1, vc[j] = 1;
	for (int i = 1; i <= n; ++i)
		if (!vr[i])
		{
			for (int j = 1; j <= m; ++j)
				if (!vc[j])
					cout << a[i][j];
			cout << endl;
		}

}

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

int a[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

int main(void){
	int k;
	scanf("%d",&k);
	k--;
	printf("%d\n",a[k]);
	return 0;
}


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

int main(){
    int n;
    cin >> n;
    vector<int> d(n);
    int count=0;
    for(int i=0;i<n;i++) cin >> d[i];

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

    for(int i=0;i<n;i++){
        if(d[i]==d[i+1] && i!=n-1){
            
        }
        else{
            count++;
        }
    }

    cout << count << endl;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a) for(int i=0;i<(a);i++)
const ll MOD=1000000007;

int main(){
  int H,W; cin>>H>>W;
  int cnt=0;
  rep(i,H) rep(j,W){
    char x; cin>>x;
    if(x=='#') cnt++;
  }
  if(cnt==(H+W-1)) cout<<"Possible"<<endl;
  else cout<<"Impossible"<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define endl "\n"

#define rep(i,n) for (int i = 0; i < n; i++)
#define repd(i,n) for (int i = n-1; i >= 0; i--)
#define fo(i,a,b) for (int i = a; i < b; i++)
#define fod(i,a,b) for (int i = a; i >= b; i--)
#define umap unordered_map<int,int>
#define mii map<int,int>
#define pii pair<int,int>
#define vi vector<int>
#define vvi vector<vi>
#define vpii vector<pii>
#define pqMin priority_queue<int,vector<int>,greater<int>>
#define pqMax priority_queue<int>
#define pqpii priority_queue<pii>
#define all(v) v.begin(),v.end()
#define sortall(v) sort(all(v))
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define remax(a,b) a = max(a,b)
#define remin(a,b) a = min(a,b)
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define w(t) int t; cin>>t; while (t--)
#define out(x, y) cout << x << " " << y << endl
#define print(x) cout << x << endl
#define ps(x,y) fixed<<setprecision(y)<<x
#define pprint cout<<"Case #"<<tt<<": ";
const int mod = 1e9+7;
const int N = 2e5;
const int inf = 1e18;

int add(int a,int b){int res=(a+b)%mod;return (res<0)?res+mod:res;}
int mul(int a,int b){int res=(a*1LL*b)%mod;return (res<0)?res+mod:res;}
bool compare (int x, int y) { return x > y;}

struct Compare {
    bool operator () (pii A, pii B) {
        return A.first > B.first;
    }
};
 struct tri{
   int x,y,z;
 };
 struct cmp{
bool operator ()(tri a,tri b){
    if(a.x==b.x)
        return a.y>b.y;
    return a.x<b.x;

}};
bool comp(pii a,pii b){
    if(a.first>b.first) return true;
    else if(a.first==b.first) return a.second<b.second;
    else return false;

}
int binarySearch(vector<int>nums, int lo, int hi, int target) {
        while (lo < hi) {
            int mid = (lo + hi)/2;
            if (nums[mid] <= target) {
                lo = mid + 1;
            } else {
                hi = mid;
            }
        }
        return lo;
    }
void solve() {

    int t = 1;
    //cin >> t;
   while(t--){
        int i,j,k,n;
   map<int,int>m;

       cin>>n;
        for(i=1;i<=sqrt(n);i++){
          for(j=1;j<=sqrt(n);j++){
            for(k=1;k<=sqrt(n);k++){
                int x=((i+j)*(i+j))+((j+k)*(j+k))+((k+i)*(k+i));
                    m[x/2]+=1;
            }
          }
       }
       for(i=1;i<=n;i++){
            if(m.find(i)!=m.end())
            cout<<m[i]<<endl;
       else
        cout<<"0"<<endl;
       }

    }
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

   /* #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif*/

    solve();

    return 0;
}


Measured memory_bytes: 5976
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n1,n2;
    cin>>n1;
    vector<int> s(n1);
    for(int i=0;i<n1;i++){
        cin>>s[i];
    }
    cin>>n2;
    vector<vector<int>> t(2,vector<int>(n2,0));
    for(int i=0;i<n2;i++){
        cin>>t[0][i];
    }
    for(int i=0;i<n1;i++){
        for(int j=0;j<n2;j++){
            if(s[i]==t[0][j]){
                t[1][j]++;
            }
        }
    }
    cout<<t[1].size()-count(t[1].begin(),t[1].end(),0)<<endl;
}



Measured memory_bytes: 3220
#include <bits/stdc++.h>
using namespace std;
#define int long long int
int n,ar[205];
int32_t main(){
	int ans = (1<<30);
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>ar[i];
		ans = min(ans,ar[i]&-ar[i]);
	}
	int res = 0;
	while(ans/=2) res++;
	cout<<res;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
int main() {
  ll n,a,ans=0;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>a;
    while(a%2==0){
      ans++;
      a/=2;
    }
  }
  cout<<ans<<endl;
  return 0;
}


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

using namespace std;

int main(){
    int H, W;
    cin >> H >> W;

    vector <string> S(H + 2);
    for (int i = 0; i < W + 2; i++){
        S[0] += '.';
        S[H + 1] += '.';
    }

    for (int i = 1; i < H + 1; i++){

        string s;
        cin >> s;

        S[i] = '.' + s + '.';
    }
    
    
    for (int i = 1; i < H + 1; i++){
        for (int j = 1; j < W + 1; j++){
            if (S[i][j] == '.'){
                char count = '0';
                if (S[i - 1][j - 1] == '#'){
                    count ++;
                }
                if (S[i][j - 1] == '#'){
                    count ++;
                }
                if (S[i + 1][j - 1] == '#'){
                    count ++;
                }   
                if (S[i - 1][j] == '#'){
                    count ++;
                }
                if (S[i + 1][j] == '#'){
                    count ++;
                }
                if (S[i - 1][j + 1] == '#'){
                    count ++;
                }
                if (S[i][j + 1] == '#'){
                    count ++;
                }
                if (S[i + 1][j + 1] == '#'){
                    count ++;
                }  
                S[i][j] = count;                              
            }   
        }
    }

    for (int i = 1; i < H + 1; i++){
        for (int j = 1; j < W + 1; j++){
            cout << S[i][j];
        }
        cout << endl;
    }
     

    return 0;
}

Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
	/**
	 * Main method.
	 */
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		
		String[][] field = new String[3][3];
		for (int i = 0; i < 3; i++) {
			String line = s.next();
			for (int j = 0; j < 3; j++) {
				field[i][j] = line.substring(j, j+1);
			}
		}
		
		System.out.println(field[0][0] + field[1][1] + field[2][2]);
		
	}
}

Measured memory_bytes: 19924
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
A = LIST()
a = []

for i in range(0, N):
  a.append([i+1, A[i]])

a.sort(key = lambda x: x[1])  

for i in range(N):
  print(a[i][0],end="")
  print(" ",end="")
  
print()

Measured memory_bytes: 26708
/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		double a[]=new double[n];
		for(int i=0;i<n;i++)
		a[i]=sc.nextDouble();
		
		double p[][]=new double[n+1][n+1];
		p[0][0]=1;
		for(int i=1;i<=n;i++){
		    double h=a[i-1];
		    double t=1-h;
		    p[0][i]=t*p[0][i-1];
		    for(int j=1;j<=i;j++){
		        p[j][i]=h*p[j-1][i-1]+t*p[j][i-1];
		    }
		}
		double ans=0;
		for(int i=n/2 + 1;i<=n;i++){
		    ans+=p[i][n];
		}
		System.out.println(ans);
		
	}
}


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

int main() {
  
  long long N, Q;
  cin >> N >> Q;
  string S;
  cin >> S;
  
  vector<int> AC_sum(N);
  if(S.at(0)=='A' && S.at(1)=='C' ){ AC_sum.at(0)=1; }
  for(int i=1; i<N-1; i++){
    if(S.at(i)=='A' && S.at(i+1)=='C' ){ AC_sum.at(i)=AC_sum.at(i-1)+1; }
    else{ AC_sum.at(i)=AC_sum.at(i-1); }
  }
  AC_sum.at(N-1)=AC_sum.at(N-2);
  
  int l, r;
  for(int i=0; i<Q; i++){
    cin >> l >> r;
    l-=1; r-=1;
    if(l==0){ cout << AC_sum.at(r-1) - 0 << endl; }
    else{ cout << AC_sum.at(r-1) - AC_sum.at(l-1) << endl; }
  }
  
}

Measured memory_bytes: 1408
import java.util.*;
public class Main {
	public static boolean kaimono(int n) {
		for(int i = 0; i <= n/4; i++) {
			for(int j = 0; j <= n/7; j++) {
				if(n==(4*i)+(7*j)) {
					return true;
				}
			}
		}
		return false;
	}
	
	
	
	
	
	
	
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt();
		if(kaimono(n)) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
		
		
		
		
	}

}


Measured memory_bytes: 21844
#pragma GCC optimize "O3"

#include<bits/stdc++.h>

using namespace std;

constexpr int N = 20;

int n, ans;
string tmp, ans_rev;
vector<string> words[N+1], cands[N+1];
//vector<bool> vis[N+1];

bool valid(string &tar, string &s, string &rev) {
  for(size_t i = 0; i<s.size(); ++i) {
    if(rev[s[i]] != -1 && rev[s[i]] != tar[i])
      return false;
    if(rev[tar[i]] != -1 && rev[tar[i]] != s[i])
      return false;
  }
  return true;
}
void dfs(int l, size_t x, string &rev) {
  if(ans > 1)
    return;
  while(l && x >= words[l].size()) {
    x = 0;
    --l;
  }
  if(l == 0) {
    ans_rev = rev;
    ++ans;
    return;
  }
  string &tar = words[l][x];
  for(size_t j = 0; j<cands[l].size(); ++j) {
    //if(vis[l][j])
    //  continue;
    string &s = cands[l][j];
    if(valid(tar, s, rev)) {
      string nrev = rev;
      size_t i = 0;
      for(; i<s.size(); ++i)
        if(nrev[s[i]] == -1) {
          if(nrev[tar[i]] != -1)
            break;
          nrev[s[i]] = tar[i];
          nrev[tar[i]] = s[i];
        }
      if(i != s.size())
        continue;
      //vis[l][j] = true;
      dfs(l, x+1, nrev);
      //vis[l][j] = false;
    }
  }
}
void cleanup(vector<string> &v) {
  sort(v.begin(), v.end());
  v.resize(unique(v.begin(), v.end()) - v.begin());
}
void init() {
  for(int i = 0; i<=N; ++i)
    words[i].clear(), cands[i].clear();//, vis[i].clear();
  ans = 0;
}
void solve() {
  init();
  for(int i = 0; i<n; ++i) {
    cin >> tmp;
    for_each(tmp.begin(), tmp.end(), [](char &c) { c -= 'A'; });
    cands[tmp.size()].push_back(tmp);
  }
  //for(int i = 0; i<=N; ++i)
  //  vis[i].resize(cands[i].size());
  vector<string> sent;
  bool cont = true;
  while(cont) {
    cin >> tmp;
    if(tmp.back() == '.') {
      tmp.pop_back();
      cont = false;
    }
    sent.push_back(tmp);
    for_each(tmp.begin(), tmp.end(), [](char &c) { c -= 'A'; });
    words[tmp.size()].push_back(tmp);
  }
  for(int i = 0; i<=N; ++i)
    cleanup(words[i]);
  string rev(26, -1);
  dfs(N, 0, rev);
  if(ans == 1) {
    for(auto c : ans_rev)
      if(c != -1) {
        assert(c == ans_rev[ans_rev[c]]);
      }
    for(size_t i = 0; i<sent.size(); ++i) {
      for(auto c : sent[i]) 
        putchar(ans_rev[c - 'A'] == -1 ? c : ans_rev[c - 'A'] + 'A');
      putchar(i+1 == sent.size() ? '.' : ' ');
    }
    puts("");
  } else
    puts("-.");
}
int main() {
  while(scanf("%d", &n) == 1 && n)
    solve();
}

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

public class Main {
    static long cnt[];
    public static void main(String[] args) throws Exception {
        FastReader sc = new FastReader();
        int n=sc.nextInt(),k=sc.nextInt();
        cnt=new long[k+1];
        for (int i=1;i<=k;i++)p(i);
        int mod=1000000007;
        for (int i=1;i<=k;i++){
            cnt[i]=pow(cnt[i],n,mod);
        }
        long ans=0;
        for (int j=k;j>=1;j--){
            for (int i=2*j;i<=k;i+=j){
                cnt[j]=(cnt[j]-cnt[i]+mod)%mod;
            }
            ans=(ans+(j*cnt[j])%mod)%mod;
        }
        System.out.println(ans);
    }
    static void p(int x){
        for (int i=1;i*i<=x;i++){
            if (x%i==0){
                cnt[i]++;
                if (x/i==i)continue;
                cnt[x/i]++;
            }
        }
    }
    static long pow(long a,long p,int m){
        if (p==0)return 1;
        long res=pow(a,p/2,m)%m;
        if (p%2==0)return (res*res)%m;
        return (a*((res*res)%m))%m;
    }
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

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

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

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

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

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

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

Measured memory_bytes: 33560
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n");
while(true){
   var a0=Arr.shift()-0;
   if(a0==0)break;
   var a1=Arr.shift()-0;
   var a2=Arr.shift()-0;
   var a3=Arr.shift()-0;
   var a4=Arr.shift()-0;
   var arr=[a0,a1,a2,a3,a4];
   var rps=[1,2,3];
   rps=rps.filter(function(v){
      return (v!=a0 && v!=a1 && v!=a2 && v!=a3 && v!=a4);
   });
   if(rps.length==2 || rps.length==0){
      for(var i=0;i<5;i++)console.log(3);
   }else{
      arr.forEach(function(v){
         if(rps[0]==1)console.log((v==2)?1:2);
         if(rps[0]==2)console.log((v==1)?2:1);
         if(rps[0]==3)console.log((v==1)?1:2);
      });
}



}

Measured memory_bytes: 9772
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp> 
 
//using namespace __gnu_pbds;
using namespace std;
 
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define null 0
#define pi 3.14159265358979323846
#define all(x) x.begin(), x.end()
#define d0(x) cout<<x<<" ";
#define d1(x) cout<<x<<"\n";
#define d2(x,y) cout<<x<<" "<<y<<"\n";
#define d3(x,y,z) cout<<x<<" "<<y<<" "<<z<<"\n";
#define d4(x,y,z,w) cout<<x<<" "<<y<<" "<<z<<" "<<w<<"\n";
 
//#define ordered_set tree<pair<ll,ll>, null_type,less<pair<ll,ll>>, rb_tree_tag,tree_order_statistics_node_update> 
//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
 
template<typename T, typename U> static inline void amin(T &x, U y){if (y < x)x = y;} 
template<typename T, typename U> static inline void amax(T &x, U y){if (y > x)x = y;} 
 
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
const  ll mod= 1000000007  ; 
const long long inf = (ll)1e18+17;
const int inff = 1500000000;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};

int test_case=0;
void solve(){
    ll n;cin>>n;
    if(n==1)cout<<"0\n";
    else cout<<"1\n";
}
 
int main()
{  
    clock_t tt;tt = clock(); 
    //ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int t=1;
    if(test_case==1)
    cin>>t;
    //pre();
    for(int i=1;i<=t;i++){
       //cout<<"Case #"<<i<<": ";
       solve();
    }
    tt = clock() - tt; double time_taken = ((double)tt)/CLOCKS_PER_SEC;   
    //printf("code took %f seconds to execute \n", time_taken); 
    return 0;
}
 
// ============== Notes =============== //
// common bugs
// - remove ios_base for interactive problems
// - int overflow (especially intermediate expressionns)
// - array bounds (indices bigger than MAXN?)
// - special cases (n=1? graph not connected?)
// - re-initialize efficiently between test cases

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#include <boost/multi_array.hpp>
#include <boost/range/algorithm.hpp>
#define rep(i,n) for (int i=0; i< (n); ++i)
using namespace std;
typedef long long ll;

int main() {
  int n;
  string ans;
  cin >> n;
  vector<int> a(n);
  rep(i,n){
    cin >> a[i];
  }
  vector<int> zero(n,0);
  if(a==zero) ans = "Yes";
  else if(n%3!=0&&a!=zero) ans = "No";
  else{
    map<int,int> count{};
    rep(i,n){
      count[a[i]]++;
    }
    if (count.size()==3){
      vector<int> num, h;
      for(auto& p: count){
        num.push_back(p.first);
        h.push_back(p.second);
      }
      if((num[0]^num[1]^num[2])==0 && h[0]==h[1] && h[1]==h[2]) ans = "Yes";
      else{ans = "No";}
    }
    else if(count.size()==2){
      vector<int> num, h;
      for(auto& p: count){
        num.push_back(p.first);
        h.push_back(p.second);
      }
      if((num[0]==0&&2*h[0]==h[1])||(num[1]==0&&h[0]==2*h[1])) ans = "Yes";
      else{ans = "No";}
    }
    else ans = "No";
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 4480
import java.util.*;
import java.util.stream.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    try {
      int n = sc.nextInt();
      int[] a = IntStream.range(0, n).map(i -> sc.nextInt()).toArray();
      int mask = Arrays.stream(a).reduce(0, (acc,v) -> acc ^ v);
      int[] b = Arrays.stream(a).map(v -> v ^ mask).toArray();

      for (int i = 0; i < n; i++) {
        System.out.print(b[i]);
        System.out.print(" ");
      }
      System.out.println("\n");
    } finally {
      sc.close();
    }
  }
}


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


int main(){
  while(1){
    int n;
    cin>>n;
    if(n==0) break;
    int a[50];
    string memo;
    lp(i,n){
      cin>>memo;
      a[i]=memo.size();
    }
    lp(i,n){
      int ans=0;
      int count=0,stats=0;
      for(int j=i;j<n;j++){
	if(stats==0||stats==2){
	  count+=a[j];
	  if(count==5){
	    stats++;
	    count=0;
	  }
	  if(count>5) break;
	}
	else if(stats==1||stats==3||stats==4){
	  count+=a[j];
	  if(count==7){
	    stats++;
	    count=0;
	  }
	  if(count>7) break;
	}
	if(stats==5) {
	  ans=1;
	  break;
	}
      }
      if(ans==1) {
	cout<<i+1<<endl;
	break;
      }
    }
  }
  return 0;
}



Measured memory_bytes: 3008
n,m=map(int,input().split())
ab=[list(map(int,input().split())) for _ in range(n)]
k=0
c=0
ab.sort()
for i in range(n):
    if k+ab[i][1]>=m:
        c+=ab[i][0]*(m-k)
        k+=m-k
        print(c)
        exit()
    else:
        k+=ab[i][1]
        c+=ab[i][0]*ab[i][1]

Measured memory_bytes: 27884
a,b=map(int,input().split())
if a>0:
  print("Positive")
elif a==0 or b==0:
  print("Zero")
elif b<0:
  n=(-a)+b-1 
  if n%2==0:
    print("Positive") 
  else:
    print("Negative") 
else:
  print("Zero")
  

Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
typedef signed long long ll;
 
#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

int main(){
	int i,j,k,n,m,l,f,x,y,z; string s;
	cin >> s;
	n = s.size();
	string ans = "";
	rep(i, n){
		if(s[i] == '0') ans += '0';
		if(s[i] == '1') ans += '1';
		if(s[i] == 'B' && ans != "") ans.pop_back();
	}
	cout << ans << endl;
}

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

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    vector<int> odp;
    for (int i = 0; i < n; ++i)
    {
        int nr = -1;
        vector<int> usu;
        for (int j = 0; j < a.size(); ++j)
        {
            vector<int> t;
            for (int k = 0; k < a.size(); ++k)
                if (k != j)
                    t.push_back(a[k]);
            bool ok = true;
            for (int k = 0; k < t.size(); ++k)
                if (!(t[k] - 1 <= k))
                    ok = false;
            if (ok && a[j] - 1 <= j)
            {
                nr = j;
                usu = t;
                break;
            }
        }
        if (nr == -1)
        {
            cout << "-1";
            return 0;
        }
        odp.push_back(a[nr]);
        a = usu;
    }
    for (int i = n - 1; i >= 0; --i)
        cout << odp[i] << endl;
    return 0;
}


Measured memory_bytes: 256
use std::io::Read;

pub fn read_stdin() -> String {
    let mut s = String::new();
    ::std::io::stdin().read_to_string(&mut s).unwrap();
    s
}

pub trait Parse {
    fn to<T>(&mut self) -> T
    where
        T: std::str::FromStr;
}

impl<'a> Parse for std::str::SplitWhitespace<'a> {
    fn to<T>(&mut self) -> T
    where
        T: std::str::FromStr,
    {
        let word = self.next().unwrap();
        word.parse().ok().unwrap()
    }
}

fn main() {
    let source = read_stdin();
    let mut iter = source.split_whitespace();
    let n = iter.to();
    let m = iter.to();
    let x_pos: i32 = iter.to();
    let y_pos: i32 = iter.to();
    let xs: Vec<i32> = (0..n).map(|_| iter.to()).collect();
    let ys: Vec<i32> = (0..m).map(|_| iter.to()).collect();

    for i in (x_pos + 1)..(y_pos + 1) {
        let x_ok = xs.iter().all(|&x| x < i);
        let y_ok = ys.iter().all(|&y| y >= i);
        if x_ok && y_ok {
            println!("No War");
            return;
        }
    }
    println!("War");
}

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

using ll = long long;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n, K;
  cin >> n >> K;
  
  vector<ll> h(n);
  for (int i = 0; i < n; i++) cin >> h.at(i);
  
  vector<vector<vector<ll>>> dp(n, vector<vector<ll>>(n + 1, vector<ll>(n + 1, 1e18)));
  // dp[i][j][k]: i番目まで見て, 累計j個潰して, 連続k個潰しているときの最小操作回数
  dp[0][0][0] = h.at(0);
  dp[0][1][1] = 0;
  for (int i = 0; i < n - 1; i++) {
    for (int j = 0; j <= i + 1; j++) {
      for (int k = 0; k <= i + 1; k++) {
        if (k == 0) {
          if (h.at(i) < h.at(i + 1)) {
            dp[i + 1][j][0] = min(dp[i + 1][j][0], dp[i][j][k] + h.at(i + 1) - h.at(i));
            dp[i + 1][j + 1][k + 1] = min(dp[i + 1][j + 1][k + 1], dp[i][j][k]);
          }
          else {
            dp[i + 1][j][0] = min(dp[i + 1][j][0], dp[i][j][k]);
            dp[i + 1][j + 1][k + 1] = min(dp[i + 1][j + 1][k + 1], dp[i][j][k]);
          }
        }
        else {
          int last = 0;
          if (i - k + 1 > 0) last = h.at(i - k);
          if (last < h.at(i + 1)) {
            dp[i + 1][j][0] = min(dp[i + 1][j][0], dp[i][j][k] + h.at(i + 1) - last);
            dp[i + 1][j + 1][k + 1] = min(dp[i + 1][j + 1][k + 1], dp[i][j][k]);
          }
          else {
            dp[i + 1][j][0] = min(dp[i + 1][j][0], dp[i][j][k]);
            dp[i + 1][j + 1][k + 1] = min(dp[i + 1][j + 1][k + 1], dp[i][j][k]);
          }
        }
      }
    }
  }
  
  ll ans = 1e18;
  for (int j = 0; j <= K; j++) {
    for (int k = 0; k <= K; k++) {
      ans = min(ans, dp[n - 1][j][k]);
    }
  }
  
  cout << ans << '\n';
}

Measured memory_bytes: 219160