akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <memory>
#include <stack>

using namespace std;

int main()
{
       int X, Y;
        cin >> X >> Y;
        const int mod = 1e9 + 7;
        vector<vector<int>> dp(X + 1, vector<int>(Y + 1));

        for (int i = 0; i < X; i++)
        {
            for (int j = 0; j < Y; j++)
            {
                char c;
                cin >> c;
                if (i == 0 && j == 0)
                {
                    dp[i][j] = 1;
                    continue;
                }
                if (c == '#' || (i==0 && j== 0))
                {
                    dp[i][j] = 0;
                    continue;
                }
                if (i == 0)
                {
                    dp[i][j] = dp[i][j-1];
                    continue;
                }
                if (j == 0)
                {
                    dp[i][j] = dp[i-1][j];
                    continue;
                }
                dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % mod;
            }
        }

        cout << dp[X - 1][Y - 1] << endl;
  return 0;
}

Measured memory_bytes: 4224
#include<bits/stdc++.h>
    using namespace std;
    #define ll long long 
    #define ull unsigned long long
     
    void fast_IO() { ios_base::sync_with_stdio(false);cin.tie(NULL);}
    void test_here_once(){ freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);}
     
    int main()
    {
    	ll n,w; cin>>n>>w;
    	ll wt[n], val[n];
    	for(ll i=0;i<n;i++) cin>>wt[i]>>val[i];
     
    	vector<vector<ll> > dp(n+1, vector<ll>(w+1,0));
     
    	for(ll i=1;i<=n;i++)
    	{
    		for(ll j=1;j<=w;j++)
    		{
    			if(wt[i-1]<=j)
    			{
    				dp[i][j]= max(val[i-1] + dp[i-1][j-wt[i-1]], dp[i-1][j]);
    			}
    			else dp[i][j]= dp[i-1][j];			
    		}
    	}
    	cout<<dp[n][w];
    }

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

int main()
{
	int d;
	while(cin >> d){
		int S = 0;
	for (int i = 1; i < 600 / d; ++i)
	{
		S += i * d * i * d * d;
	}
	cout << S << endl;
}
	return 0;
}

Measured memory_bytes: 1160
#include <iostream>

using namespace std;

int main(void)
{
	int e;
	while(cin >> e, e > 0){
		int mini = e;
		for(int z=0; z*z*z <= e; z++){
			for(int y=0; y*y <= e; y++){
				int x = e - z*z*z - y*y;
				if (x < 0) break;
				mini = min(mini, x+y+z);
			}
		}
		cout << mini << endl;
	}
	return 0;
}


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

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

using namespace std;

vector<vector<int>> G;
vector<int> color;
bool ng;

pair<int,int> dfs(int u,int c){
	color[u]=c;

	pair<int,int> res;
	(c==0?res.first:res.second)++;
	for(int v:G[u]){
		if(color[v]==c){
			ng=true;
			return {0,0};
		}
		else if(color[v]==-1){
			auto tmp=dfs(v,1-c);
			res.first+=tmp.first;
			res.second+=tmp.second;
		}
	}
	return res;
}

int main(){
	int n,m; scanf("%d%d",&n,&m);
	static bool A[700][700];
	rep(i,m){
		int u,v; scanf("%d%d",&u,&v); u--; v--;
		A[u][v]=A[v][u]=true;
	}

	G.assign(n,vector<int>());
	rep(u,n) rep(v,n) if(u!=v && !A[u][v]) G[u].emplace_back(v);

	vector<pair<int,int>> P;
	color.assign(n,-1);
	rep(u,n) if(color[u]==-1) P.emplace_back(dfs(u,0));
	if(ng) return puts("-1"),0;

	bool dp[701]={true};
	for(auto p:P){
		bool next[701]={};
		auto update=[&](int a){ for(int w=n;w>=a;w--) next[w]|=dp[w-a]; };
		update(p.first);
		update(p.second);
		rep(w,n+1) dp[w]=next[w];
	}

	int ans=n*n;
	rep(w,n+1) if(dp[w]) ans=min(ans,w*(w-1)/2+(n-w)*(n-w-1)/2);
	printf("%d\n",ans);

	return 0;
}


Measured memory_bytes: 3072
import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = {
    //nextLineとnextを同時に使ったら死ぬ
    val sc = new Scanner(System.in)
    val w,h, x, y = sc.nextLong()
    val ans = (h * w) / 2.0

    debug(w / 2.0, h / 2.0)
    val value =
      if (x == w / 2.0 && y == h / 2.0) {
        1
      } else {
        0
      }

    printf("%f %d", ans, value)
    println()

  }
  def debug(args: Any*): Unit = {
    Console.err.println(args.mkString(" "))
  }
}


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

#define FOR(i, m, n) for(int (i) = (m); (i) < (n); (i)++)
#define REP(i, n) FOR(i, 0, n)
#define co(n) cout << (n) << endl
#define cosp(n) cout << (n) << ' '
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
typedef long long ll;
typedef pair<int, int> P;

const ll INF = 2e9;
const ll MOD = 1e9+7;
//const ll MOD 998244353;

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

	vector<int> l(n);
	REP(i, n) cin >> l[i];
	sort(all(l));

	ll ans = 0;
	REP(i, n-2){
		FOR(j, i+1, n-1){
			FOR(k, j+1, n){
				if(l[i] + l[j] > l[k]) ans++;
				else break;
			}
		}
	}

	co(ans);

	return 0;
}


Measured memory_bytes: 384
#pragma region include
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <cstdio>
#include <tuple>
#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = (int)(n); i >= 0; i--)
#define FOR(i,n,m) for(int i = (int)(n); i < int(m); i++)
#define MOD (1e9+7)
#define INF (1e9)
#define LLINF (4e18)
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
void input() {}
template<typename... R> void input(int& f, R&... r) { scanf("%d", &f); input(r...); }
template<typename... R> void input(double& f, R&... r) { scanf("%lf", &f); input(r...); }
template<typename... R> void input(ll& f, R&... r) { scanf("%lld", &f); input(r...); }
template<typename... R> void input(char& f, R&... r) { scanf("%c", &f); input(r...); }
template<typename... R> void input(string& f, R&... r) { cin >> f; input(r...); }
template<typename T, typename... R> void input(vector<T>& f, R&... r) { REP(i, f.size())input(f[i]); input(r...); }
#pragma endregion

//gcd
template<typename T>
T gcd(T a, T b) {
    return b ? gcd(b, a%b) : a;
}

int main() {
    string s; input(s);
    REP(i, s.size()) {
        if (i + 1 < s.size() && s[i] == s[i + 1]) {
            cout << i + 1 << " " << i + 2 << endl;
            return 0;
        }
        else if (i + 2 < s.size() && s[i] == s[i + 2]) {
            cout << i + 1 << " " << i + 3 << endl;
            return 0;
        }
    }
    cout << "-1 -1" << endl;
    getchar(); getchar();
}

Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<bitset>
using namespace std;

int nikara (const string &sig);
void tenkara ( int );

int main () {
	string sig[10] = {"0111111","0000110","1011011","1001111","1100110","1101101","1111101","0100111","1111111","1101111"};
	string before,hoge;
	int n,num;
	int var = 0x0001;
	int bvar,piyo;
	
	while ( cin >> n, n != -1 ){
		bvar = 0;
		for ( int i = 0; i < n; i++ ) {
			cin >> num;
			hoge = sig[num];
			
			var = nikara ( hoge );
			piyo = var ^ bvar;
			tenkara ( piyo );
			
			bvar = var;
		}
	}
}

int nikara (const string &sig) {
	int out = 0;
	for (int i = 0, size = sig.size(); i < size ; ++i ) {
		out *= 2;
		out += ((int)sig[i] == 49) ? 1 : 0;
	}
	return out;
}

void tenkara (int hoge) {
	string sig;
	for ( int i = 0; i < 7; i++ ) {
		sig[i] = hoge % 2 + '0';
		hoge = hoge / 2;
	}
	
	for ( int i = 6; i >= 0; i-- ) {
		cout << sig[i];
	}
	cout << endl;
}

Measured memory_bytes: 1200
//package atcoder;
 
import java.util.*;
import java.math.BigDecimal;
 
public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		for(int i=0;i<=1000;i++) {
			if((int)(i*0.08)==A&&(int)(i*0.1)==B) {
				System.out.println(i);
				System.exit(0);
			}
		}
		System.out.println(-1);
		
		}
}


Measured memory_bytes: 22740
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
#include <numeric>
#include <string>
#include <functional>

using namespace std;
 
int main() {
  int a,b,c;
  cin >> a >> b >> c;
  
  int ans1;
  int ans2;
  int ans3;
  int ans;
  
  ans1 = a + b;
  ans2 = a + c;
  ans3 = b + c;
  
  ans = min(min(ans1,ans2),ans3);
  std::cout << ans << std::endl;

  return 0;
}


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

int main(void)
{
  char word[11];
  char text[1001];
  int i;
  int cnt = 0;

  scanf("%s", word);
  
  while(1){
    scanf("%s", text);
    if(strcmp(text, "END_OF_TEXT") == 0){
      break;
    }
    else{
      for(i = 0; i < strlen(text); i++){
	text[i] = tolower(text[i]);
      }
      if(strcmp(text, word) == 0){
	cnt++;
      }
    }
  }

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


  return 0;
}

Measured memory_bytes: 548
import java.util.*;
import java.io.*;
class Main{
  public static void main(String args[]){
    int n=readI();
    int a[]={0,0,0,0};
    for(int i=0;i<n;i++){
      String str = readL();
      char c = str.charAt(0);
      if(c=='A'){
        a[0]++;
      }else if(c=='W'){
        a[1]++;
      }else if(c=='T'){
        a[2]++;
      }else if(c=='R'){
        a[3]++;
      }
    }
    pl("AC x "+a[0]);
    pl("WA x "+a[1]);
    pl("TLE x "+a[2]);
    pl("RE x "+a[3]);
  }

  static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  public static void pr(String str){
    System.out.print(str);
  }
  public static void pl(String str){
    System.out.println(str);
  }
  public static String read(){
    try{
      return ctos((char)br.read());
    }catch(IOException e){
      e.printStackTrace();
      return "";
    }
  }
  public static char readC(){
    try{
      return (char)br.read();
    }catch(IOException e){
      e.printStackTrace();
      return (char)-1;
    }
  }
  public static String readL(){
    try{
      return br.readLine();
    }catch(IOException e){
      e.printStackTrace();
      return "";
    }
  }
  public static String readS(){
    StringBuilder sb = new StringBuilder();
    while(true){
      try{
        int k = br.read();
        if(k==-1||(char)k==' '||(char)k=='\n'){break;}
        sb.append((char)k);
      }catch(IOException e){
        e.printStackTrace();
      }
    }
    return sb.toString();
  }
  public static long readLong(){
    return stol(readS());
  }
  public static long stol(String s){
    return Long.parseLong(s);
  }
  public static int readI(){
    return stoi(readS());
  }
  public static String[] readSs(){
    return readL().split(" ");
  }
  public static int[] readIs(){
    return stoi(readSs());
  }
  public static int stoi(String s){
    return Integer.parseInt(s);
  }
  public static int[] stoi(String s[]){
    int a[]=new int[s.length];
    for(int i=0;i<s.length;i++){
      a[i]=stoi(s[i]);
    }
    return a;
  }
  public static String itos(int i){
    return String.valueOf(i);
  }
  public static String[] itos(int[] a){
    String s[]=new String[a.length];
    for(int i=0;i<a.length;i++){
      s[i]=itos(a[i]);
    }
    return s;
  }
  public static String ctos(char c){
    return String.valueOf(c);
  }
  public static String cstos(char[] c){
    return new String(c);
  }
  public static char stoc(String s){
    return s.charAt(0);
  }
  public static char[] stocs(String s){
    return s.toCharArray();
  }
  public static int[] Itoi(Integer a[]){
    int[]result=new int[a.length];
    for(int i=0;i<a.length;i++){
      result[i]=a[i];
    }
    return result;
  }
}


Measured memory_bytes: 43204
cnt1 = 0
cnt2 = 0
try:
    while(True):
        a, b, c = map(int, input().split(","))
        if a**2 + b**2 == c**2:
            cnt1+=1
        if a==b:
            cnt2+=1
except:
    print(cnt1)
    print(cnt2)


Measured memory_bytes: 5592
from collections import deque
"""
01-BFS
"""

h, w = map(int, input().split())
ch, cw = map(int, input().split())
dh, dw = map(int, input().split())
ch-=1; cw-=1; dh-=1; dw-=1
area = [list(input()) for _ in range(h)]
inf = 10**100
dist = [[inf]*w for i in range(h)]
dwalk = [(0, 1), (0, -1), (1, 0), (-1, 0)]

q = deque([(ch, cw)])
dist[ch][cw] = 0
while q:
    y, x = q.popleft()
    for dy, dx in dwalk:
        py = y+dy; px = x+dx
        if not 0<=py<h: continue
        if not 0<=px<w: continue
        if area[py][px]=='#': continue
        if dist[py][px]>dist[y][x]:
            dist[py][px] = dist[y][x]
            q.appendleft((py, px))
    for dy in range(-2, 3):
        for dx in range(-2, 3):
            py = y+dy; px = x+dx
            if not 0<=py<h: continue
            if not 0<=px<w: continue
            if area[py][px]=='#': continue
            if dist[py][px]>dist[y][x]+1:
                dist[py][px] = dist[y][x]+1
                q.append((py, px))

if dist[dh][dw] == inf:
    print(-1)
else:
    print(dist[dh][dw])

Measured memory_bytes: 128552
#include <stdio.h>
#include <stdlib.h>

int *sort_sub(int *T, int N){
	int *ans = (int *)malloc(sizeof(int) * N);
	if(N == 1){
		ans[0] = T[0];
	}
	else{
		int N1 = N / 2;
		int N2 = (N + 1) / 2;
		int *sub1 = sort_sub(&T[0] , N1);
		int *sub2 = sort_sub(&T[N1], N2);
		int i, j, k;
		for(i = 0, j = 0, k = 0; i < N; i++){
			if((sub1[j] < sub2[k] && j != N1) || (k == N2)){
				ans[i] = sub1[j];
				j++;
			}
			else{
				ans[i] = sub2[k];
				k++;
			}
		}
		free(sub1);
		free(sub2);
	}
	return ans;
}

int *sort(int *T, int N){
	int *ans = sort_sub(T, N);
	free(T);
	return ans;
}

int main(){
	int N, C, K, i;
	scanf("%d%d%d", &N, &C, &K);
	int *T = (int *)malloc(sizeof(int) * N);
	for(i = 0; i < N; i++){
		scanf("%d", &T[i]);
	}
	T = sort(T, N);
	int ans = 0, Ti, j;
	i = 0;
	while(i < N){
		Ti = T[i] + K;
		j = i;
		ans++;
		while(T[i] <= Ti && i < j + C && i < N){
			i++;
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 1520
#include "bits/stdc++.h"

using namespace std;

using ll = long long int;
using ld = long double;

using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<double, double>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vd = vector<double>;
using vvd = vector<vd>;
using vs = vector<string>;
using vb = vector<bool>;
using vvb = vector<vb>;

const int INF = (1 << 30) - 1;
const ll INF64 = ((ll)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

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

int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

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

	int a, b;
	cin >> a >> b;

	cout << (a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0 ? "Possible" : "Impossible") << endl;
	return 0;
}

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

using namespace std;

class Answer {
  private:
    long long m;
    vector<long long> d;
    vector<vector<char>> w;
  public:
    Answer();
    Answer(long long mm, vector<long long> dd, vector<vector<char>> ww);
    long long get_m();
    vector<long long> get_d();
    vector<vector<char>> get_w();
    bool operator==(const Answer & lhs) const;
};

Answer::Answer() {
  m = 0;
  vector<long long> dd;
  d = dd;
  vector<vector<char>> ww;
  w = ww;
}

Answer::Answer(long long mm, vector<long long> dd, vector<vector<char>> ww) {
  m = mm;
  d = dd;
  w = ww;
}

bool Answer::operator== (const Answer & lhs) const {
  if(m == lhs.m && d == lhs.d && w == lhs.w)
    return true;
  return false;
}

long long Answer::get_m() {
  return m;
}

vector<long long> Answer::get_d() {
  return d;
}

vector<vector<char>> Answer::get_w() {
  return w;
}

Answer robot_arms(long long n, vector<long long> x, vector<long long> y) {
  Answer a;
  vector<long long> u, v;
  int bit = abs((x[0] + y[0]) % 2);
  for(long long i=0; i<x.size(); i++) {
    if(abs(((x[i] + y[i]) % 2)) != bit) {
      return a;
    }
    u.push_back(x[i] + y[i]);
    v.push_back(x[i] - y[i]);
  }
  vector<long long> d;

  for(int i=1<<30;0<i;i=i>>1) {
    d.push_back(i);
  }
  if(bit == 0) {
    d.push_back(1);
  }
  /*
  for(auto iter = d.begin();iter != d.end();++iter) {
    cout << *iter << endl;
  }
  */
  vector<vector<char>> w;
  for(long long i=0;i< u.size();i++) {
    vector<char> ww;
    long long c_u = 0;
    long long c_v = 0;
    for(int j=0;j<d.size();j++) {
      //cout << "u: " << c_u << "v: " << c_v << endl;
      if(c_u <= u[i] && c_v <= v[i]) {
	    c_u += d[j];
	    c_v += d[j];
	    ww.push_back('R');
	    continue;
      }
      if(c_u <= u[i] && c_v > v[i]) {
	    c_u += d[j];
	    c_v -= d[j];
	    ww.push_back('U');
	    continue;
      }
      if(c_u > u[i] && c_v > v[i]) {
	    c_u -= d[j];
	    c_v -= d[j];
	    ww.push_back('L');
	    continue;
      }
      if(c_u > u[i] && c_v <= v[i]) {
	    c_u -= d[j];
	    c_v += d[j];
	    ww.push_back('D');
	    continue;
      }
    }
    w.push_back(ww);
  }
  return Answer(d.size(), d, w);
}

int main() {
  long long n;
  cin >> n;
  vector<long long> x;
  vector<long long> y;
  for (long long i= 0;i<n;i++) {
    long long xx, yy;
    cin >> xx;
    cin >> yy;
    x.push_back(xx);
    y.push_back(yy);
  }
  Answer a = robot_arms(n, x, y);
  if(a.get_m() == 0) {
    cout << -1;
    return 0;
  }
  cout << a.get_m() << endl;
  vector<long long> d = a.get_d();
  for(int i = 0;i<d.size();i++) {
    cout << d[i];
    if(i != d.size() -1)
      cout << " ";
  }
  cout << endl;
  vector<vector<char>> w = a.get_w();
  for(long long i=0;i<w.size();i++) {
    vector<char> ww = w[i];
    for(long long j=0;j<ww.size();j++) {
      cout << ww[j];
    }
    if(i != w.size()-1){
      cout << endl;
    }
  }
}

Measured memory_bytes: 512
N, M = list(map(int, input().split()))
H = list(map(int, input().split()))

roads = []
for i in range(N):
    roads.append([])
    
for i in range(M):
    r = list(map(lambda x: int(x)-1, input().split()))
    roads[r[0]].append(r[1])
    roads[r[1]].append(r[0])

goodcount = 0
for i in range(len(H)):
    isgood = True
    for r in roads[i]:
        if H[i] <= H[r]:
            isgood = False
    if isgood:
        goodcount += 1

print(goodcount)

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

int main(){
  int d[10];
  for(int i = 1; i<=4; i++) d[i]=0;
  for(int i = 0; i<6; i++){
    int z;
    cin >>z;
    d[z]++;
  }
  if(d[1]<=2 && d[2]<=2 && d[3]<=2 && d[4]<=2) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}

Measured memory_bytes: 256
n,x=gets.split.map(&:to_i)
ls = gets.split.map(&:to_i)
array=[0]
i=0
ls.each do |l|
  array.push(array[i]+l)
  i+=1
end

cnt = 0
array.each do |a|
  cnt+=1 if a <= x 
end

p cnt


Measured memory_bytes: 3836
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define all(v) begin(v), end(v)
#define debug(x) cerr<< #x <<": "<<x<<endl
#define debug2(x,y) cerr<< #x <<": "<< x <<", "<< #y <<": "<< y <<endl

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;
template<class T> using vv=vector<vector< T > >;

int main() {
  int n;
  cin >> n;
  string s_;
  cin >> s_;
  vi s(n, 0);
  rep (i, n) {
    if (s_[i] == 'x') {
      s[i] = 1;
    }
  }
  vi a(n, 0);
  rep (i, 4) {
    a[0] = i/2;
    a[1] = (i&1);
    FOR (j, 2, n) {
      a[j] = a[j-2] ^ ((s[j-1] + a[j-1]) % 2);
    }
    if ((((a[n-2] ^ a[0]) ^ a[n-1]) == s[n-1]) && (((a[n-1] ^ a[1]) ^ a[0]) == s[0])) {
      rep (i, n) {
        char tmp;
        if (a[i] == 0) {
          tmp = 'S';
        } else {
          tmp = 'W';
        }
        printf("%c", tmp);
      }
      printf("\n");
      return 0;
    }
  }
  printf("-1\n");

  return 0;
}


Measured memory_bytes: 1344
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define BUGAVOID(x) x
#define rep(...) BUGAVOID(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c) c.begin(),c.end()
#define mp make_pair
#define write(x) cout<<(x)<<"\n"
using namespace std; typedef long long ll;
typedef vector<int> vi; typedef vector<ll> vll; template<class T>using vv = vector<vector<T>>;
template<class T>vv<T> vvec(size_t n, size_t m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T>bool chmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
template<class T>bool chmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 28, MOD = 1e9 + 7; constexpr ll LINF = 1ll << 60; constexpr double EPS = 1e-6;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); }; }aaaa;

int N, T;
vi A;

int main() {
    cin >> N >> T;
    A.resize(N);
    rep(i, N) cin >> A[i];

    vector<pair<int, int>> Amax(N);
    Amax[N - 1] = mp(A[N - 1], 1);
    for (int i = N - 2; i >= 0; --i) {
        if (A[i] > Amax[i + 1].first) {
            Amax[i] = mp(A[i], 1);
        }
        else if (A[i] == Amax[i + 1].first) {
            Amax[i] = mp(Amax[i + 1].first, Amax[i + 1].second + 1);
        }
        else {
            Amax[i] = mp(Amax[i + 1].first, Amax[i + 1].second);
        }
    }

    int maxProfit = 0;
    rep(i, N) {
        maxProfit = max(maxProfit, Amax[i].first - A[i]);
    }

    map<int, int> m;
    rep(i, N) {
        if (Amax[i].first - A[i] == maxProfit) {
            m[A[i]]++;
        }
    }

    int ans = 0;
    set<int> s_s, s_b;
    rep(i, N) {
        if (Amax[i].first - A[i] == maxProfit && s_s.find(Amax[i].first) == s_s.end() && s_b.find(A[i]) == s_b.end()) {
            ans += min(m[A[i]], Amax[i].second);
            s_s.insert(Amax[i].first);
            s_b.insert(A[i]);
        }
    }
    write(ans);
}

Measured memory_bytes: 8448
#include <stdio.h>

int main() {
    int x = 0;

    char s[5];
    for (int i = 0; i < 4; i++) {
        scanf("%c", &s[i]);
    }

    for (int i = 0; i < 4; i++) {
        if (s[i] == '+') {
            x++;
        } else {
            x--;
        }
    }

    printf("%d", x);
    return 0;
}

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

using namespace std;

template<typename S, typename T>
ostream& operator<<(ostream& out, const pair<S, T> p) {
    out << "(" << p.first << "," << p.second << ")";
    return out;
}

template<typename T>
ostream& operator<<(ostream& out, const vector<T>& v) {
    for (auto a: v)
        out << a << " ";
    return out;
}

template<typename T>
ostream& operator<<(ostream& out, const set<T>& S) {
    for (auto a: S)
        cout << a << " ";
    return out;
}

template<typename T>
ostream& operator<<(ostream& out, const multiset<T>& S) {
    for (auto a: S)
        cout << a << " ";
    return out;
}

template<typename S, typename T>
ostream& operator<<(ostream& out, const map<S, T>& M) {
    for (auto m: M)
        cout << "(" << m.first << "->" << m.second << ") ";
    return out;
}

template<typename S, typename T>
pair<S, T> operator+(pair<S, T> a, pair<S, T> b) {
    return make_pair(a.first + b.first, a.second + b.second);
}

template<typename S, typename T>
pair<S, T> operator-(pair<S, T> a, pair<S, T> b) {
    return make_pair(a.first - b.first, a.second - b.second);
}

long long query_value(vector<int>& A, int len) {
    long long ans = 0;
    for (auto a: A) {
        int cnt = (a + len - 1) / len;
        ans += cnt - 1;
    }
    return ans;
}

int solve(vector<int>& A, int k) {
    int left = 1;
    int right = *max_element(A.begin(), A.end());
    if (query_value(A, left) <= k)
        return left;
    while (right - left > 1) {
        int mid = left + (right - left) / 2;
        if (query_value(A, mid) <= k)
            right = mid;
        else
            left = mid;
    }
    return right;
}

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int n, k;
    vector<int> A;
    cin >> n >> k;
    A.resize(n);
    for (int i = 0; i < n; i++)
        cin >> A[i];
    cout << solve(A, k) << endl;
    return 0;
}


Measured memory_bytes: 3996
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
using namespace std;
typedef long long ll;
int main()
{
	char s[100];
	cin>>s;
	if (s[2]==s[3]&&s[4]==s[5])
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
} 

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

using namespace std;

int main(){
    int n; cin >> n;
    string s; cin >> s;
    vector<pair<int, int>> acc(n+1);
    acc[0]=make_pair(0, 0); // (num white, num black)
    for(int i=0; i<n; ++i){
        acc[i+1]=make_pair(acc[i].first+(s[i]=='.'), acc[i].second+(s[i]=='#'));
    }
    int ans=n;
    for(int i=0; i<n; ++i){
        int left_white=acc[i].first;
        int left_black=acc[i].second;
        int right_white=acc[n].first-acc[i].first;
        int right_black=acc[n].second-acc[i].second;
        ans=min(ans, left_white+right_white);
        ans=min(ans, left_black+right_black);
        ans=min(ans, left_black+right_white);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 2180
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n = sc.nextInt()
  val p = List.fill(n)(sc.nextInt()-1).zipWithIndex

  def solve(p: List[(Int, Int)]): Int = {
    p match {
      case (p1, idx1) :: (p2, idx2) :: rest if p1 == idx1 && p2 == idx2 => 1 + solve(rest)
      case (p1, idx1) :: rest if p1 == idx1 => 1 + solve(rest)
      case (p1, idx1) :: rest => solve(rest)
      case Nil => 0
    }
  }

  println(solve(p))
}


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

#define endl '\n'
#define fi first
#define se second
#define pb push_back
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
const int MOD = 1e9 + 7;
const int maxn = 1e6 + 5;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-8;
const double PI = acos(-1.0);

void header() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}

ll a[maxn], cnt[maxn];

void solve() {
    int n;
    cin >> n;
    ll sum = 0, res;
    for (int i = 1; i <= n; i++) cin >> a[i], cnt[a[i]]++, sum += a[i];
    int q, b, c;
    cin >> q;
    while (q--) {
        cin >> b >> c;
        sum -= b * cnt[b];
        sum += c * cnt[b];
        cnt[c] += cnt[b];
        cnt[b] = 0;
        cout << sum << endl;
    }
}

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


Measured memory_bytes: 5132
import java.io.*;
import java.math.*;
import java.util.*;
import java.lang.*;
public class Main { 
 
	public static void main(String[] args) { 
		FastScanner I = new FastScanner(); //Input
		OutPut O = new OutPut(); //Output
		int N = I.nextInt();
		long[][] sch = new long[N+1][3]; //[Speed,first departure, frequency after ceremony]
		for (int i = 1; i <= N-1; i++) {
			sch[i][0] = I.nextLong();
			sch[i][1] = I.nextLong();
			sch[i][2] = I.nextLong();
		}
		for (int start = 1; start <= N; start++) {
			int cur = start;
			long curans = 0;
			while (cur<N) {
				if (curans<sch[cur][1]) curans = sch[cur][1];
				else {
					long late = curans-sch[cur][1];
					long mod = late%sch[cur][2];
					long add = 0;
					if (mod>0) {
						add=sch[cur][2]-mod; //If late by 5 and frequency is 6, only 1 more 
						//minute is needed
					}
					curans+=add;
				}
				curans+=sch[cur][0]; //Speed of current train to reach station i+1 
				//from station i
				cur++;
			}
			O.pln(curans);
		}
	}
	public static void sort(long[] a) {Arrays.sort(a);}
	public static void sort(int[] a) {Arrays.sort(a);}
	public static void sort(String[] a) {Arrays.sort(a);}
	public static void sort(char[] a) {Arrays.sort(a);}
	public static long ceil(long num, long den) {long ans = num/den; if (num%den!=0) 
	ans++; return ans;}
	public static long GCD(long a, long b) {
		if (a==0||b==0) return Math.max(a,b);
		return GCD(Math.min(a, b),Math.max(a, b)%Math.min(a, b));
	}
	public static long FastExp(long base, long exp, long mod) {
		long ans=1;
		while (exp>0) {
			if (exp%2==1) ans*=base;
			exp/=2;
			base*=base;
			base%=mod;
			ans%=mod;
		}
		return ans;
	}
	public static long ModInv(long num,long mod) {return FastExp(num,mod-2,mod);}
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				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());};
	}
	static class OutPut{
		PrintWriter w = new PrintWriter(System.out);
		void pln(int x) {w.println(x);w.flush();}
		void pln(long x) {w.println(x);w.flush();}
		void pln(String x) {w.println(x);w.flush();}
		void pln(char x) {w.println(x);w.flush();}
		void pln(StringBuilder x) {w.println(x);w.flush();}
		void p(int x) {w.print(x);w.flush();}
		void p(long x) {w.print(x);w.flush();}
		void p(String x) {w.print(x);w.flush();}
		void p(char x) {w.print(x);w.flush();}
		void p(StringBuilder x) {w.print(x);w.flush();}
	}
}


Measured memory_bytes: 27048
sx, sy, tx, ty = map(int, input().split())
x = tx - sx
y = ty - sy
ans = ''
ans += 'R' * x + 'U' * y
ans += 'L' * x + 'D' * y
ans += 'D' + 'R' * (x + 1) + 'U' * (y + 1) + 'L'
ans += 'U' + 'L' * (x + 1) + 'D' * (y + 1) + 'R'
print(ans)

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

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

    int a[5];
    for (int i = 0; i < 5; ++i) cin >> a[i];
    int k;
    cin >> k;
 
    for (int i = 0; i < 5; ++i) {
       for (int j = i; j < 5; ++j) {
          if (a[j] - a[i] > k) {
            cout << ":(\n";
            return 0;
          }
       }
    }
 
    cout << "Yay!\n";
}

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

bool prime(int N) {
  if (N == 1) return false;
  bool judge = true;
  for (int i = 2; i * i <= N; ++i) if (N % i == 0) judge = false;
  return judge;
}

int main() {
  int N;
  cin >> N;
  
  vector<int> P;
  for (int i = 1; i <= N; ++i) if (prime(i)) P.push_back(i);
  vector<int> Q;
  for (int i = 0; i < P.size(); ++i) {
    int p = P[i];
    int cnt = 0;
    while (p <= N) {
      cnt += N / p;
      p *= P[i];
    }
    Q.push_back(cnt);
  }
  
  int a = 0;
  int b = 0;
  int c = 0;
  int d = 0;
  int e = 0; // a74 b24 c14 d4 e2
  for (int i = 0; i < P.size(); ++i) {
    if (Q[i] >= 74) ++a;
    if (Q[i] >= 24) ++b;
    if (Q[i] >= 14) ++c;
    if (Q[i] >= 4) ++d;
    if (Q[i] >= 2) ++e;
  }
  int ans = 0;
  ans += a;
  ans += b * (e - 1);
  ans += c * (d - 1);
  ans += d * (d - 1) * (e - 2) / 2; 
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cctype>

using namespace std;

int main() {
    char ch;
    while (true) {
        scanf("%c", &ch);
        if (ch == '\n') break;
        else if (isalpha(ch)) {
            if (isupper(ch)) printf("%c", tolower(ch));
            else printf("%c", toupper(ch));
        }
        else printf("%c", ch);
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 2600
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define FOR(i,k,n) for(int(i)=(k);(i)<(n);++(i))
#define rep(i,n) FOR(i,0,n)
#define all(v) begin(v),end(v)
#define debug(x) std::cerr<<#x<<": "<<x<<"\n"
#define debug2(x,y) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<"\n"
#define debug3(x,y,z) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<", "<<#z<<": "<<z<<"\n"

using ll=long long;
using vi=std::vector<int>;
using vvi=std::vector<vi>;
using vll=std::vector<ll>;
using vvll=std::vector<vll>;
template<typename T> using vvec=std::vector<std::vector<T>>;
template<typename T>
auto make_v(size_t sz){return std::vector<T>(sz);}
template<typename T,typename... Ts>
auto make_v(size_t sz,Ts...ts){return std::vector<decltype(make_v<T>(ts...))>(sz,make_v<T>(ts...));}
template<typename T>
void fill_v(T&var,const T&x){var=x;}
template<typename V,typename T>
void fill_v(V&v,const T&x){for(auto&& w:v){fill_v(w,x);}}

template<typename T> std::ostream& operator<<(std::ostream&s,const std::vector<T>&v){
  int sz=v.size();s<<"\n";rep(i,sz){s<<v[i];if(i<sz-1){s<<"\t";}}s<<"\n";return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::vector<std::vector<T>>&v){
  for(auto&& w:v){s<<w;}return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::deque<T>&v){
  int sz=v.size();s<<"\n";rep(i,sz){s<<v[i];if(i<sz-1){s<<"\t";}}s<<"\n";return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::deque<std::deque<T>>&v){
  for(auto&& w:v){s<<w;}return s;}
template<typename T> std::ostream& operator<<(std::ostream&s, const std::set<T>&v){
  s<<"\n";for(auto&& elm:v){s<<elm<<"\t";}s<<"\n";return s;}

inline void scan(int&a){scanf("%d",&a);}
inline void scan(ll&a){scanf("%lld",&a);}
inline void scan(char&a){scanf(" %c",&a);}
inline void scan(double&a){scanf("%lf",&a);}
inline void scan(std::string&s){char BUF[3000000];scanf(" %s",BUF);s=std::string(BUF);}
template<typename T>
inline void scan(std::vector<T>&v){for(auto&& sv:v){scan(sv);}}
template<typename First,typename...Args>
inline void scan(First&f,Args&...args){scan(f);scan(args...);}
inline void print(int a){printf("%d\n",a);}
inline void print(ll a){printf("%lld\n",a);}
inline void print(double a){printf("%.12f\n",a);}
inline void print(std::string s){std::cout<<s<<"\n";}

using namespace std;

int main() {
  int n;
  scan(n);
  vi p(n);
  scan(p);
  int cnt = 0;
  rep (i, n-2) {
    int a = p[i];
    int b = p[i+1];
    int c = p[i+2];
    if (a > c) {
      swap(a, c);
    }
    if (a < b && b < c) {
      cnt += 1;
    }
  }
  print(cnt);

  return 0;
}


Measured memory_bytes: 888
#include<stdio.h>
#include<stdlib.h>
#include<string.h>


int pop(void);
void push(int);

int top,S[100];

int main(){
  int x;
  char s[100];
  int a,b;
  
  while( scanf("%s", s) != EOF ){
    if ( s[0] == '+' ){
      a=pop();
      b=pop();
      push(a+b);
    } else if ( s[0] == '-' ){
      a=pop();
      b=pop();
      push(b-a);
    } else if ( s[0] == '*' ){
      a=pop();
      b=pop();
      push(a*b);
    } else {
      x = atoi(s);
      push(x);
    }
  }
  printf("%d\n",pop());
  
  return 0;
}
int pop(void){
    top--;
  return S[top+1];
}
void push(int x){
    top++;
    S[top]=x;
  
}

Measured memory_bytes: 548
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
ll d,g;
ll p[15],c[15];
ll ans=10000000000000000;
int main(void){
    cin>>d>>g;
    for(int i=0;i<d;i++){
        cin>>p[i]>>c[i];
    }
    for(int bit=0;bit<(1<<d);bit++){
        ll cnt=0;
        ll C=0;
        for(int i=0;i<d;i++){
            if(bit&(1<<i)){
                cnt+=(i+1)*100*p[i]+c[i];
                C+=p[i];
            }
        }
        int i=d-1;
        while(cnt<g&&i>=0){
            if((bit&(1<<i))==0){
                if(g-cnt>(i+1)*100*(p[i]-1)){
                    cnt+=(i+1)*100*(p[i]-1);
                    C=C+p[i]-1;
                }else{
                    C=C+(g-cnt+(i+1)*100-1)/((i+1)*100);
                    cnt=g;
                }
            }
            i--;
        }
        if(cnt>=g){
            ans=min(ans,C);
        }
    }
    cout<<ans<<endl;
    
}


Measured memory_bytes: 256
#include <stdio.h>

int main () {
	int  a, b, c, d, e, average=0;
	scanf("%d%d%d%d%d", &a ,&b, &c, &d, &e);
	if(a < 40) a = 40;
	if(b < 40) b = 40;
	if(c < 40) c = 40;
	if(d < 40) d = 40;
	if(e < 40) e = 40;
	average = (a + b + c + d + e) / 5;
	printf("%d\n", average); 
	return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

typedef long long ll;

constexpr ll INF = 1LL << 60;

struct Edge {
    int from, to;
    ll cost;
    Edge(int f, int t, ll c): from(f), to(t), cost(c) {}
    bool operator<(const Edge &e) const {
        return cost < e.cost;
    }
    bool operator==(const Edge &e) const {
        return (from == e.from) && (to == e.to) && (cost == e.cost);
    }
};

class UnionFind {
    public:
    int n;
    vector<int> par, rank, size;  //親, 深さ, その木の要素数

    UnionFind(int n): n(n) {
        for(int i=0;i<n;++i){
            par.push_back(i);
            rank.push_back(0);
            size.push_back(1);
        }
    }

    //根を求める
    int find(int x){
        if(par[x] == x){
            return x;
        }else{
            int p = find(par[x]);
            size[x] = size[p];
            return par[x] = p;
        }
    }

    //xとyの属する集合の併合
    void unite(int x, int y){
        x = find(x);
        y = find(y);
        if(x == y) return;
        
        size[x] += size[y];
        size[y] = size[x];
        if(rank[x] < rank[y]){
            par[x] = y;
        }else{
            par[y] = x;
            if(rank[x] == rank[y]) rank[x]++;
        }
    }

    //同じ集合に属するか否か
    bool are_same(int x, int y){
        return find(x) == find(y);
    }
};


ll kruskal(int &n, vector<Edge> &edges, vector<Edge> &used_edges, Edge unused_edge) {
    bool is_all = (unused_edge.cost == -1);
    UnionFind uf = UnionFind(n);
    ll cost = 0LL;
    for(Edge e: edges) {
        if(e == unused_edge) continue;
        if(!uf.are_same(e.from, e.to)) {
            uf.unite(e.from, e.to);
            cost += e.cost;
            if(is_all) used_edges.push_back(e);
        }
    }

    int p = uf.find(0);
    for(int i=1;i<n;++i) {
        if(uf.find(i) != p) return INF;
    }

    return cost;
}

int main() {
    int n, m;
    cin >> n >> m;
    int s,d; ll c;
    vector<Edge> edges;
    vector<int> degrees(n, 0);
    for(int i=0;i<m;++i){
        cin >> s >> d >> c;
        --s; --d;
        Edge e = Edge(s, d, c);
        edges.push_back(e);
    }
    sort(edges.begin(), edges.end());

    vector<Edge> used_edges;
    ll min_cost = kruskal(n, edges, used_edges, Edge(-1, -1, -1));

    int ans_cnt = 0;
    ll ans_cost = 0LL;
    for(Edge e: used_edges) {
        if(kruskal(n, edges, used_edges, e) > min_cost) {
            ++ans_cnt;
            ans_cost += e.cost;
        }
    }

    cout << ans_cnt << " " << ans_cost << endl;

}


Measured memory_bytes: 3876
{-# LANGUAGE OverloadedStrings #-}

import Data.List (foldl')
import Control.Applicative ((<$>))
import Text.Parsec as P

{- Let's play with Parsec a bit. -}

type Input = String

data Term = N Int
          | O Operator

type Operator = (Int -> Int -> Int)

instance Show Term where
    show (N n) = "N " ++ show n
    show (O op) = "O " ++ case 1 `op` 1 of
                              2 -> "(+)"
                              0 -> "(-)"
                              1 -> "(*)"

fromChar :: Char -> Operator
fromChar '+' = (+)
fromChar '-' = (-)
fromChar '*' = (*)

expr :: Parsec Input u [Term]
expr = term `sepEndBy` spaces

term :: Parsec Input u Term
term = (N <$> int) <|> (O <$> operator)

operator :: Parsec Input u Operator
operator = fromChar <$> (char '+' <|> char '-' <|> char '*')

int :: Parsec Input u Int
int = read <$> many1 digit

-- unsafe !!!
calc :: [Term] -> Int
calc = head . foldl' f [] where
    f stack (N n) = n:stack
    f stack (O op) = let
        (x:y:ns) = stack
        in
            (y `op` x) : ns

main = do
    e <- parse expr "" <$> getLine
    case e of
        Right e' -> print . calc $ e'
        Left _ -> print "ERROR!"

Measured memory_bytes: 4448
import java.util.Scanner;
public class Main {

	public static void main(String[] args)throws Exception {
		Scanner stdIn=new Scanner(System.in);
		int N=stdIn.nextInt();
		int key;
		int a[]=new int[N+10];
		int b[]=new int[N+10];
		int z=0,y=0,x=0,fin=0;
		int i=1;
		while(N>z) {
			a[z]=stdIn.nextInt();
			b[a[z]]++;
			if(b[a[z]]>2) {
				fin=1;
				break;
			}
			if(b[0]>1) {
				fin=1;
				break;
			}
			z++;
		}z=0;
		if(fin==1)
			System.out.println(0);
		else {
			while(N/2>z) {
				i*=2;
				if(i>1000000007)
					i%=1000000007;
				z++;
			}
			System.out.println(i);
		}
	}
}

Measured memory_bytes: 49032
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
vector<int> g[202020];
int done[202020];
pair<int, int> dfs(int cur) {
  int u = 0, v = 0;
  for (int nbr : g[cur]) {
    if (done[nbr]) continue;
    done[nbr] = true;
    pair<int, int> res = dfs(nbr);
    u += res.first;
    v += res.second;
  }
  if (cur < 100000) u++;
  else v++;
  return make_pair(u, v);
}
signed main() { 
  ios::sync_with_stdio(false); cin.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    g[x].push_back(y + 100000);
    g[y + 100000].push_back(x);
  }
  long long ans = 0;
  for (int i = 0; i < 202020; i++) {
    if (done[i]) continue;
    done[i] = true;
    pair<int, int> res = dfs(i);
    ans += 1LL * res.first * res.second;
  }
  cout << ans - n << endl;
  return 0;
}

Measured memory_bytes: 11904
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;

class Program
{
    const string Yes = "Yes";
    const string No = "No";
    const long Mod = 1000000007;

    static void Main(string[] args) {
#if DEBUG
        MyDebugger.Test(process, "../TextFile1.txt");
#else
        object ret = process(new StreamReader(Console.OpenStandardInput()));
        Console.WriteLine(ret);
#endif
    }

    static object process(TextReader input) {
        var s = input.ReadLine();
        var t = input.ReadLine();

        var n = s.Length;

        for(int i=0; i<n; i++) {
            bool ok = true;
            for(int j=0; j<n; j++) {
                if(s[(i + j) % n] != t[j]) {
                    ok = false;
                    break;
                }
            }
            if (ok) return Yes;
        }
        return No;
    }

    static int[] ToIntArray(string strs, int n) {
        var ret = new int[n];
        var spl = strs.Split(' ');
        for (int i = 0; i < n; i++)
            ret[i] = int.Parse(spl[i]);
        return ret;
    }
}


Measured memory_bytes: 11092
import itertools
n = list(input())

f = [1,1,1,-1,-1,-1]
def m(n):
    if n == -1:
        return "-"
    else:
        return "+"

for v in itertools.permutations(f,3):
    if int(n[0]) + (v[0] * int(n[1])) + (v[1] * int(n[2])) + (v[2] * int(n[3])) == 7:
        print(n[0],m(v[0]),n[1],m(v[1]),n[2],m(v[2]),n[3],"=7", sep="")
        break



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

typedef long long ll;

ll n;

inline int digit(ll x) {
    return to_string(x).size();
}

inline ll solve(ll n) {
    ll a;
    int digit_num, ret = digit(n);
    if (n == 1) return 1;
    for (ll i = 1; i <= sqrt(n); i++) {
        if (n % i == 0) {
            a = n / i;
            digit_num = max(digit(a), digit(i));
            if (ret < digit_num) {
                break;
            }
            else {
                ret = digit_num;
            }
        }
    }

    return ret;
}

int main() {
    cin >> n;
    cout << solve(n) << endl;
    return 0;
}

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

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    double l;
    cin >> l;
    cout << fixed << setprecision(6);
    double w = l / 3.0;
    cout << w * w * w;
    return 0;
}


Measured memory_bytes: 256
#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

fn main() {
    loop {
        let mut s: String = read::<String>();
        if s == "-" {
            break;
        }

        let m = read::<usize>();
        let slen = s.len();

        for _ in 0..m {
            let h = read::<usize>();
            let s2 = &mut s;

            let sadd = {
                let (first, last) = s2.split_at(h);
                let mut s3 = String::from(last);
                s3.push_str(&first);
                s3
            };
            s2.push_str(&sadd);

            for _ in 0..slen {
                s2.remove(0);
            }
        }
        println!("{}", s);
    }
}



Measured memory_bytes: 5044
#include<bits/stdc++.h>
using namespace std;
 int main()
 {
     long long int a,b,c,d,e,f,g,h,j,i;
     cin>>a>>b>>c;
     d=0;e=0;
     long long int ans=0,sum=0;
     e=a%(b+c);
     d=a/(b+c);
     ans=d*b;
     ans+=min(e,b);

     cout<<ans<<endl;
 }


Measured memory_bytes: 256
import heapq as h
import math
import numpy as np
import copy
import itertools
import sys
 

# n, w = map(int, input().split())
n = int(input())
g = [[-1 for _ in range(n)] for _ in range(n)]

for i in range(n):
    a_cn = int(input())
    for j in range(a_cn):
        x,y = map(int, input().split())
        if y == 1:
            g[i][x-1] = 1
        elif y == 0:
            g[i][x-1] = 0


ans2 = 0
for i in range(2**n):
    cnt = 0
    bag = [0] * n 
    for j in range(n):
        if ((i >> j) & 1):
            bag[j] = 1
    ok = True
    for ix, v in enumerate(bag):
        if v == 1:
            for jx, jv in enumerate(g[ix]):
                if jv == 1:
                    if bag[jx] != 1:
                        ok = False
                elif jv == 0:
                    if bag[jx] != 0:
                        ok = False
    if ok == True:
        ans = sum(bag)
    else:
        ans = 0
    ans2 = max(ans2,ans)
print(ans2)

Measured memory_bytes: 12484
N,K,Q = map(int,input().split())
A = []

sanka = [K] * N

for i in range(Q):
  a = int(input())	
  A.append(a-1)
  
  sanka[A[i]] += 1
  
for i in range(N):
  if sanka[i] > Q:
    print('Yes')
  else:
    print('No')


Measured memory_bytes: 10472
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M,a,b;
  cin >> N >> M;
  vector<vector<bool>> ab(N,vector<bool>(N));
  while (M--) {
    cin >> a >> b;
    ab[--a][--b] = true;
    ab[b][a] = true;
  }
  int answer = 0, x[N];
  for (int i = 0; i < N; i++) {
    x[i] = i;
  }
  do {
    bool valid = true;
    for (int i = 1; i < N; i++) {
      if (!ab[x[i]][x[i-1]]) {
        valid = false;
      }
    }
    answer += valid;
  } while (next_permutation(x+1,x+N));
  cout << answer;
}

Measured memory_bytes: 256