akhauriyash/Code-Regression huggingface dataset:
#define debug_interval ','
#define dump_interval ' '
#define debug_toggle 1
//{
#include<bits/stdc++.h>
using namespace std;
#define hi cout<<"hi"<<endl;
#define int long long
#define INT_MAX LLONG_MAX
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define fi first
#define se second
#define mp make_pair
#define rev reverse
#define dans dump(ans)
#define MOD 1000000007
#define amp(v,n) (v).count(n)?v[n]++:v[n]=1;

//{
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class...A> inline void dump(){cout<<endl;}
template<class...A> inline void dump_rest() {cout<<endl;}
template<class T, class...A> inline void dump_rest(const T& first, const A&... rest){cout<<dump_interval<<first;dump_rest(rest...);}
template<class T,class...A> inline void dump(const T&first,const A&...rest){cout<<first;dump_rest(rest...);}
template<class...A> inline void debug(){cerr<<endl;}
template<class...A> inline void debug_rest() {cerr<<endl;}
template<class T, class...A> inline void debug_rest(const T& first, const A&... rest){cerr<<debug_interval<<first;debug_rest(rest...);}
template<class T,class...A> inline void debug(const T&first,const A&...rest){if(debug_toggle)cerr<<first,debug_rest(rest...);}
//}

typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}
template<int m>class mint{private:int i;public:mint() : i(0){}mint(int i): i((i%m+m)%m){}mint operator+(const mint& o){return o.i+i;}mint operator*(const mint& o){return o.i*i;}mint operator-(){return -i;}operator int() {return i;}};

int ans;
string s;

main(){
    cin>>s;
    if(s.size()==2)cout<<s<<endl;
    else {
        reverse(all(s));
        cout<<s<<endl;
    }
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define IO(i, o) freopen(i, "r", stdin), freopen(o, "w", stdout)

using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());

string s;

int main(){
	//IO("input.txt", "output.txt");
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> s;
	for(auto i : s)
		if(i == ',') cout << ' ';
		else cout << i;
	cout << "\n";
	return 0;
}

Measured memory_bytes: 256
// -*- coding:utf-8-unix -*-

use proconio::input;
use petgraph::unionfind::UnionFind;

// ABC086C - Traveling
// https://atcoder.jp/contests/abs/fasks/arc089_a

fn main() {
    input! {
        n: usize,
        uvw: [(usize, usize, usize); n-1],  // Vec<(i32, i32, i32)>
    }

    let mut dist_is_even :UnionFind<usize> = UnionFind::new(n*2);
    for (u,v,w) in uvw {
        if w % 2 == 0 {
            dist_is_even.union(u-1, v-1);
            dist_is_even.union(u-1+n, v-1+n);
        } else {
            dist_is_even.union(u-1, v-1+n);
            dist_is_even.union(u-1+n, v-1);
        }
    }

    for i in 0..n {
        if dist_is_even.equiv(0, i) {
            println!("0");
        } else {
            println!("1");
        }
    }
}


Measured memory_bytes: 8280
#include <stdio.h>

int main(void)
{
    int h,m,s;
    scanf("%d", &s);

    h = s / 3600;   s %= 3600;
    m = s / 60;     s %= 60;
    printf("%d:%d:%d\n", h, m, s);

    return 0;
}

Measured memory_bytes: 592
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repb(i, a, b) for (int i = (a); i < (b); i++)
#define ALL(a) (a).begin(),(a).end()
#define PRINT(V) for(auto v:(V))cout<<v<<" "<<endl
inline int GCD(int a, int b){return b ? GCD(b, a % b) : a;}
const int MOD = 1000000007;

int main()
{
    int H, W;
    cin >> H >> W;
    int h, w;
    cin >> h >> w;
    int ans = (H-h)*(W-w);
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n,m,k,a,x;
int main() {
  cin>>n>>m>>k;
  string s[n];
  for(int i=0;i<n;i++) {
    cin>>s[i];
    x=0;
    for(int j=0;j<m;j++) {
      x+=s[i][j]=='#'?-x:1;
      a+=x>=k;
    }
  }
  for(int j=0;j<m;j++) {
    x=0;
    for(int i=0;i<n;i++) {
      x+=s[i][j]=='#'?-x:1;
      a+=x>=k;
    }
  }
  cout<<a<<endl;
  return 0;
}


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

int main() {
  //----------変数置いたり代入したり----------
  
  int H, W, K; // それぞれの変数は問で与えられた通り
  cin >> H >> W >> K;
  
  vector<vector<char>> clist(H, vector<char>(W)); 
  // H×Wの配列に "." or "#"を代入
  for(int i=0; i<H; i++) {
    for(int j=0; j<W; j++) {
      char c;
      cin >> c;
      clist.at(i).at(j) = c;
    }
  }
  
  //----------ここまでは問題なしと思われる----------

  //----------処理していく(ここから不安)----------
  
  int ans = 0; 
  // ansは答えとして出力したい値を表す変数, 
  // 条件に合致する行列の選び方をしたときに+1していく
 
  //----------ビット全探索で行列の選び方を決定していく----------
  for (int tmp1 = 0; tmp1 < (1 << H); tmp1++) {
    bitset<6> s(tmp1);
    for (int tmp2 = 0; tmp2 < (1 << W); tmp2++) {
      bitset<6> t(tmp2);

      int jud=0; // "#"の個数を数えるための変数, 見つけ次第+1していく
      for(int i=0; i<H; i++) {
        for(int j=0; j<W; j++) {
          
          //----------最も怪しいと思われる部分----------
          //自分の考えでは、clistの要素のうち、選ばれていない行と列に属し、
          //かつ、"#"であればカウントする
          if(!s.test(i) && !t.test(j) && clist.at(i).at(j)=='#') {
            jud++;
          }
          //------------------------------------------
          
        }
      }
      
      //judによりカウントされた"#"の数がKであれば、
      //その行列の選び方がOKということになるため、ansに+1する
      if (jud==K) {
        ans++;
      }
    }
  }
  cout << ans << endl;
}


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

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

typedef long long ll;

const int INF = 1 << 30;
const ll LLINF = 1LL << 62;

int mod = 1000000007;

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N; cin >> N;
    //kC2 = N
    //N = 6のときk = 4。3個の要素を持つ4つのグループに分ける
    //{1,2,3},{1,4,5},{2,4,6},{3,5,6}
    int K = 2;
    bool ok = false;
    while((K-1)*K/2 <= N){
        if((K-1)*K/2 == N){
            ok = true;
            break;
        }
        K++;
    }
    if(ok){
        cout << "Yes" << endl;
        cout << K << endl;
        vector<int> ans[K];
        rep(i, K) ans[i].resize(K-1);
        rep(i, K-1) ans[0][i] = i+1;
        int idx[K] = {};
        int num = K;
        for(int i = 1; i < K; i++){
            //ans[i-1]までのを一個ずつ取ってくる
            int c = 0;
            for(int j = 0; j <= i-1; j++){
                ans[i][c] = ans[j][idx[j]];
                idx[j]++;
                c++;
            }
            for(; c < K-1; c++){
                ans[i][c] = num;
                num++;
            }
            idx[i] = i;
        }
        rep(i, K){
            cout << K-1 << " ";
            rep(j, K-1) cout << ans[i][j] << " ";
            cout << endl;
        }
    }
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 2176
from math import pi, cos, sqrt

A, B, H, M = map(int, input().split())

theta_a = 2 * pi * (H%12)/12 + 2 * pi / 12 * M/60
theta_b = 2 * pi * M/60

theta = abs(theta_a - theta_b)

ans = sqrt( A**2 + B**2 - 2*A*B*cos(theta) )
print(ans)


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

int main() {
  
  int N, K; cin >> N >> K;
  
  if ((N - 1) % (K - 1) == 0) {
    
    cout << (N - 1) / (K - 1) << endl;
    
  }
  
  else {
    
    cout << (N - 1) / (K - 1) + 1 << endl;
    
  }
  
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)

//-----------------------------------------------

//------------------------------------------------
int main(){
  string s,t,u;
  int a,b;
  cin>>s>>t>>a>>b>>u;
  if(s==u)  {
    cout<<a-1<<endl;
    cout<<b<<endl;
  }
  if(t==u)  {
    cout<<a<<endl;
    cout<<b-1<<endl;
  }
}


Measured memory_bytes: 384
#include <algorithm>
#include <cassert>
#include <iostream>
#include <vector>

#include <limits.h>

using namespace std;

typedef long long ll;

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

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

const int INF = INT_MAX / 4;

// vector<vector<struct Edge>> edges;
vector<vector<int>> edges;
vector<vector<int>> dp;

int solve(const int bits, const int g, const int V, const int E) {
    if (dp[bits][g] < INF) {
        return dp[bits][g];
    }
    // printf("bits: 0x%x, g: %d\n", bits, g);

    assert(bits & 1);
    assert(bits & (1 << g));

    for (int i = 1; i < V; i++) {
        if (i == g) continue;
        if ((bits & (1 << i)) == 0) continue;
        if (edges[i][g] == INF) continue;
        int new_bits = bits & (~(1 << g));
        int res = solve(new_bits, i, V, E) + edges[i][g];
        // printf("bits: 0x%x, g: %d, i: %d, res: %d\n", bits, g, i, res);
        chmin(dp[bits][g], res);
    }

    return dp[bits][g];
}

int main(void) {
    int V, E;
    cin >> V >> E;

    edges.resize(V, vector<int>(V, INF));
    for (int i = 0; i < E; i++) {
        int s, t, d;
        cin >> s >> t >> d;
        edges[s][t] = d;
    }
    for (int i = 0; i < V; i++) {
        edges[i][i] = 0;
    }

    // assume that start vertex is 0.
    dp.resize(1 << V, vector<int>(V, INF));
    for (int i = 0; i < V; i++) {
        dp[1 | (1 << i)][i] = edges[0][i];
    }

    int ans = INF;
    for (int i = 1; i < V; i++) {
        int res = solve(((1 << V) - 1), i, V, E);
        chmin(ans, res + edges[i][0]);
    }
    if (ans == INF) {
        cout << -1 << endl;
    } else {
        cout << ans << endl;
    }

    return 0;
}



Measured memory_bytes: 6248
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<functional>
#include<numeric>
#include <unordered_map>

using namespace std;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	long long h, w, n;
	cin >> h >> w >> n;
	unordered_map<long long, int> kuro;
	long long a, b;
	for (int i = 0; i < n; i++) {
		cin >> a >> b;
		a--; b--;
		for (long long j = max(1LL, a - 1); j <= min(a + 1, h - 2); j++) {
			for (long long k = max(1LL, b - 1); k <= min(b + 1, w - 2); k++) {
				kuro[j*w+k]++;
			}
		}
	}
	vector<long long> ans(10);
	for (auto& e : kuro) {
		ans[e.second]++;
	}
	ans[0] = (h - 2)*(w - 2);
	for (int i = 1; i < 10; i++) {
		ans[0] -= ans[i];
	}
	for (int i = 0; i < 10; i++) {
		cout << ans[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 36624
#include <algorithm>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

typedef unsigned long ul;
typedef pair<ul, ul> P;
map<int, int> dp;
#define REP(i, n) for (int i = 0; i < n; i++)

ul N, M,  T;
std::string S;
ul gcd(ul m, ul n) {
  if ((0 == m) || (0 == n)) return 0;
  while (m != n) {
    if (m > n)
      m = m - n;
    else
      n = n - m;
  }
  return m;
}  // gcd

ul lcm(ul m, ul n) {
  if ((0 == m) || (0 == n)) return 0;
  return ((m / gcd(m, n)) * n);  // lcm = m * n / gcd(m,n)
}  // lcm

ul A,B,C;
ul ans;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> A >> B >> C;
  ans = std::min(A+B, C) + B;
  if((A+B) < C) {
    ans += 1;
  }
  cout <<  ans << endl;
 
}

Measured memory_bytes: 256
/*
　　　　　　 ＿＿
　　　　　／＞　　 フ
　　　　　| 　_　 _ l
　 　　　／` ミ＿xノ
　　 　 /　　　 　 |　見ちゃだめだよ！
　　　 /　 ヽ　　 ﾉ　　
　 　 │　　|　|　|　　
　／￣|　　 |　|　|
　| (￣ヽ＿_ヽ_)__)
　＼二つ
*/

#include <bits/stdc++.h>
using namespace std;
#define SORT(a) sort((a).begin(), (a).end())
#define RSORT(a) reverse((a).begin(), (a).end())
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
const long long INF = 1LL << 60;
int main() {
  int n, T;
  cin >> n >> T;
  vector<int> t(n);
  rep(i, n) cin >> t[i];
  int total = 0;
  rep(i, n - 1) { total += min(t[i + 1] - t[i], T); }
  cout << total + T << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
using namespace std;
#define MAX_N 1121
#define MAX_K 15
typedef long long ll;

bool prime[MAX_N];
ll dp[MAX_N][MAX_K];

void Prime(){
  fill(prime,prime+MAX_N,true);
  prime[0] = prime[1] = false;

  for(int i = 2 ; i*i < MAX_N ; i++)
    if(prime[i])
      for(int j = i*i ; j < MAX_N ; j += i)
	prime[j] = false;
}

void init(){
  Prime();
  vector<int> P;
  for(int i = 0 ; i < MAX_N ; i++){
    if(prime[i]){
      P.push_back(i);
    }
  }

  dp[0][0] = 1;

  for(int i = 0 ; i < (int)P.size() ; i++){
    for(int j = MAX_K-2 ; j >= 0 ; j--){
      for(int k = 0 ; k < MAX_N-P[i] ; k++){
	if(P[i] + k < MAX_N)
	  dp[P[i]+k][j+1] += dp[k][j];
      }
    }
  }
}

int main(){
  int n,k;

  init();

  while(cin >> n >> k, n | k){
    cout << dp[n][k] << endl;
  }

  return 0;
}

Measured memory_bytes: 1348
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;



int main()
{
    ll n,i,j,m,t,sum=0,zeroj=-1,tt=0;
    string s;
    float mm;
    cin>>n>>m;
    mm=m*1.0;
    float a[n];
    for(i=0;i<n;i++)
    {cin>>a[i];sum+=a[i];}
    sort(a, a+n,greater<int>());
    
    //cout<<a[m-1];
    float k=a[m-1]/sum;
    float c=1/(4*mm);
    //cout<<"k="<<k<<" "<<c;
    if(k>=c)
    cout<<"Yes";
    else
    cout<<"No";

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(v, a, b) for(int v = (a); v < (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define UNWORDS(vec, str) for(int i = 0; i < (vec).size(); ++i) cout << (i ? str : "") << (vec)[i]
#define UNLINES(vec) for(int i = 0; i < (vec).size(); ++i) cout << (vec)[i] << endl
#define RS resize
#define CLR clear
#define PB push_back
#define ALL(x) (x).begin(), (x).end()
using namespace std;

int main(){
	int n;
	stringstream ss;
	string sign = "-0+", str;
	
	cin >> n;
	
	while(n){
		ss << sign[(n + 1) % 3];
		n = (n + 1) / 3;
	}
	str = ss.str();
	reverse(ALL(str));
	cout << str << endl;
	
	return 0;
}

Measured memory_bytes: 1216
#include<algorithm>
#include<array>
#include<cmath>
#include<iostream>
#include<iomanip>
#include<iso646.h>
#include<queue>
#include<stack>
#include<string>
#include<vector>

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

#define FOR(counter,initial_value,condition) for(int counter = initial_value; counter < condition;counter++)


int main()
{
	int n, k;
	cin >> n >> k;
	int ans = k;
	FOR(i, 0, n-1) {
		ans *= k - 1;
	}
	cout << ans << endl;
}


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

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

      int x = sc.nextInt();
      int y = sc.nextInt();
      boolean possible = false;
      for(int i = 0; i <= x; i++){
          int crane = i;
          int turtle = x - i;
          if(2*crane + 4*turtle == y){
              possible = true;
              break;
          }
      }
      System.out.println(possible ? "Yes" : "No");
    }
}

Measured memory_bytes: 35700
#include <bits/stdc++.h>
using namespace std;
using ull = unsigned long long;

int main() {
    int N, M, S[10][10] = {0}, P[10]; // S[電球][スイッチ] P[電球]
    int ans = 0;
    cin >> N >> M;
    for (int i=0; i<M; i++) {
        int k, si;
        cin >> k;
        for (int j=0; j<k; j++) {
            cin >>si;
            S[i][si-1] = 1;
        }
    }
    for (int i=0; i<M; i++) {
        int pi;
        cin >> pi;
        P[i] = pi;
    }

    for (int n=0; n<(1<<N); n++) {
        int sw_no = n, sw_state[N] = {0};
        bool all_light = true;
        for (int k=0; k<N; k++) {
            if (sw_no & 1) sw_state[k] = 1;
            sw_no >>= 1;
        }
        for (int m=0; m<M; m++) {
            int on_num = 0;
            for (int ni=0; ni<N; ni++) {
                if ((sw_state[ni] == 1) && (S[m][ni] == 1)) on_num += 1;
            }
            if (on_num % 2 != P[m]) all_light = false;
        }
        if (all_light) ans++;
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int a,b,i,j;
    while(1){
    scanf("%d %d", &a, &b);
    if ( a == 0 && b == 0 ) break; 
   
       for(i=0;i<a;i++){
           for(j=0;j<b;j++){
           printf("#");}
           printf("\n");
       }
          printf("\n");
   }

    return 0;
}



Measured memory_bytes: 2104
//ABC179_A
#include <stdio.h>
#include <string.h>
int main(){
	char s[1005];
	int len;
	scanf("%s",s);
	len = strlen(s);
	if(s[len-1]=='s'){
		printf("%s",s);
		printf("es");
	}
	else {
		printf("%s",s);
		printf("s");
	}

	return 0;
}


Measured memory_bytes: 1732
int f[2003],n,k,ans;
const int md=1e9+7;
int main(){
	__builtin_scanf("%d%d",&n,&k);
	f[n+1]=1;
	for(int i=1;i<k;++i)for(int j=n-i+1;j>1;--j)(f[j]+=f[j+1])%=md;
	for(int i=2;i<=n-k+2;++i)ans=(ans+f[i])%md;
	for(int i=n-k-1;i>0;--i)ans=ans*2%md;
	__builtin_printf("%d",ans);
	return 0;
}

Measured memory_bytes: 128
import math
N, K = list(map(int, input().split(' ')))
ret = 0
c = 0
kmax = N*(N+1)//2
for k in range(N+1, K-1, -1):
    kmax = kmax - c
    kmin = (k-1)*k // 2
    ret += kmax - kmin + 1
    if k <= N:
        c += 1
modq = int(1e9) + 7
print(ret % modq)

Measured memory_bytes: 9224
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,m;
  cin >> n >> m;
  int t[m];
  for(int i=0; i<m; i++) cin >> t[i];
  int a[n];
  memset(a,0,sizeof(a));
  for(int i=0; i<m; i++) {
    int c=0;
    for(int j=0,x; j<n; j++) {
      cin >> x;
      if(x==t[i]) {
        c++;
        a[j]++;
      }
    }
    a[t[i]-1]+=n-c;
  }
  for(int i=0; i<n; i++) cout << a[i] << endl;
  return 0;
}


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

int gcd(int a, int b) {
	if (a == 0 || b == 0) return a + b;
  return (a >= b) ? gcd(b, a % b) : gcd(a, b % a);
}

int main() {
  int n, ans = 0;
  cin >> n;
  vector<int> a(n);
  vector<int> l(n + 1, 0), r(n + 2, 0);
  for (int i = 0; i < n; i++) cin >> a[i];

  for (int i = 0; i < n; i++) l[i + 1] = gcd(l[i], a[i]);
  for (int i = n; i > 0; i--) r[i] = gcd(r[i + 1], a[i - 1]);

  for (int i = 0; i <= n; i++) ans = max(ans, gcd(l[i], r[i + 2]));
  cout << ans << "\n";
}

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

int n,p,a[100001];

int main()
{
	scanf("%d%d",&n,&p);
	scanf("%d",&a[1]);
	int ans=abs(p-a[1]);
	for(int i=2;i<=n;++i)
	{
		scanf("%d",a+i);
		ans=__gcd(ans,abs(p-a[i]));
	}
	printf("%d\n",ans);
}

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

bool edge[8][8];
int dfs(int v,int n,vector<bool>visited){

  bool all_visited=true;

  for(int i=0;i<n;i++){
    if(visited[i]==false)all_visited=false;
  }

  if(all_visited)return 1;

  int ans=0;

  for(int i=0;i<n;i++){
    if(edge[v][i]==false)continue;
    if(visited[i])continue;
    visited[i]=true;
    ans+=dfs(i,n,visited);
    visited[i]=false;}
  return ans;
}

int main(){
  //入力準備
  int n,m;
  cin>>n>>m;
  int x,y;
  for(int i=0;i<m;i++){
    cin>>x>>y;
    edge[x-1][y-1]=edge[y-1][x-1]=true;
  }
  
  vector<bool>visited(n);
  visited[0]=true;
  //dfsを用いた。具体的には、すべての頂点を通ればans１増加
  //出力
  cout<<dfs(0,n,visited)<<endl;
  return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rrep(i,n) for(int i=(int)(n)-1; i>=0; i--)
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define iter(c) __typeof((c).begin())
#define tr(it,c) for(iter(c) it=(c).begin(); it!=(c).end(); it++)
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define pr(a) cout << (a) << endl
#define PR(a,b) cout << (a) << " " << (b) << endl
#define F first
#define S second
typedef long long ll;
typedef pair<int,int> P;
const int MAX=1000000001;
const ll MAXL=1000000000000000001LL;
const ll mod=1000000007;
int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

map<double,string> m;

void make(string s) {
  if(s.size()==12) {
    double a=(1<<7);
    double sum=0;
    rep(i,s.size()) {
      if(s[i]=='1') sum+=a;
      a/=2;
    }
    m[sum]=s.substr(0,8)+'.'+s.substr(8);
  } else {
    make(s+'0');
    make(s+'1');
  }
}

int main() {
  make("");
  double x;
  while(cin >> x && x!=-1.0) {
    if(m.count(x)) pr(m[x]);
    else pr("NA");
  }
  return 0;
}


Measured memory_bytes: 1684
#define fi first
#define se second
#define mp make_pair
#define pb push_back

#define LOCAL 1

#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#define dbg(...) cout<<#__VA_ARGS__ ": ["; for(auto e: __VA_ARGS__){cout<<e<<", ";} cout<<"]\n"
#define dbg1(...) cout<<#__VA_ARGS__ " "<< __VA_ARGS__ 
#else
#define dbg(...) 1;
#define dbg1(...) 1;
#endif

typedef long long ll;
typedef unsigned long long ull;
constexpr int R=5e6+69, INF=2e9+6969;

int x,y;

int main()
{
	cin>>x>>y;
	if(y<2*x || y>4*x) puts("No");
	else
	{
		puts((y-2*x)%2==1 ? "No" : "Yes");
	}
	return 0;
}


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

using namespace std;
typedef long long ll;
typedef unsigned long ul;
typedef pair<ul, ul> P;

const int INF = 1e9;
const int MOD =1e9+7;
const ll LINF = 1e18;

int main(){
    string S;
    cin >> S;

    int price = 700;

    if(S[0] == 'o') price += 100;
    if(S[1] == 'o') price += 100;
    if(S[2] == 'o') price += 100;

    cout << price << endl;
} 

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stdio.h>
#include <stack>
#include <queue>
#include <deque>
#include <numeric>
using namespace std;
using ll = long long;
map <int ,int> mpa,mpb;
typedef pair<ll, ll> P;
priority_queue<P, vector<P>, greater<P>> pque;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int a,b;
  cin >> a >> b;
  if(a+b==15){
    cout << '+' << endl;
  }else if(a*b==15){
    cout << '*' << endl;
  }else{
    cout << 'x' << endl;
  }
  return 0;
}

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

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

	int k; cin >> k;
	string s; cin >> s;
	if (s.length() > k){
		for (int i = 0; i < k; ++i){
			cout << s[i];
		}
		cout << "...";
	}
	else {
		cout << s;
	}
	
    
    return 0; 
}



Measured memory_bytes: 3580
#include<stdio.h>
int main(void)
{
	int a,b,d,r ;
	double f ;
	scanf("%d %d",&a,&b);
	d=a/b;
	r=a%b;
	f=(double)a/b;
	printf("%d %d %lf\n",d,r,f);
	return 0 ;
}

Measured memory_bytes: 636
#include <bits/stdc++.h>
#define FOR(i, n) for(ll i = 0; i < n; i++)
#define FORR(i, n) for(ll i = n; i >= 0; i--)
#define FORS(i, m, n) for(int i = m;i < n;i++)
#define ALL(v) accumulate(v.begin(),v.end(),0)
#define OUT(n) (cout << n << endl)
#define IN1(a) (cin >> a)
#define IN2(a,b) (cin >> a >> b)
#define IN3(a,b,c) (cin >> a >> b >> c)
#define IN4(a,b,c,d) (cin >> a >> b >> c >> d)
using namespace std;
typedef long long ll;

int main(){
  string s;
  IN1(s);
  if (s == "ABC"){
    OUT("ARC");
  }
  else
  {
    OUT("ABC");
  }
  
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define int long long int
#define MOD(x) ((x % MOD_N) + MOD_N) % MOD_N
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define RFORE(i,a,b) for(int i=(b);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(c) (c).begin(),(c).end()
#define RALL(c) (c).rbegin(),(c).rend()
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define SZ(c) (int)((c).size())
#define EACH(i,v) for(auto i=v.begin();i!=v.end();++i)
#define REACH(i,v) for(auto i=v.rbegin();i!=v.rend();++i)
#define LB(c,x) distance((c).begin(),lower_bound(ALL(c),x))
#define UB(c,x) distance((c).begin(),upper_bound(ALL(c),x))
#define COUNT(c,x) (upper_bound(ALL(c),x)-lower_bound(ALL(c),x))
#define UNIQUE(c) SORT(c); (c).erase(unique(ALL(c)),(c).end());
#define COPY(c1,c2) copy(ALL(c1),(c2).begin())
#define EXIST(s,e) (bool)((s).find(e)!=(s).end())
#define PB push_back
#define MP make_pair
#define DUMP(x)  cerr<<#x<<" = "<<(x)<<endl;
#define NL cerr<<endl;
using namespace std;
template<typename T,typename U> using P=pair<T,U>;
template<typename T> using V=vector<T>;
template<typename T>bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<typename T>T sum(vector<T>&v){return accumulate(ALL(v),T());}
template<typename T>T sum(vector<T>&v,int a,int b){return accumulate(v.begin()+a,v.begin()+b,T());}
template<typename T>T max(vector<T>&v){return *max_element(ALL(v));}
template<typename T>T min(vector<T>&v){return *min_element(ALL(v));}
template<typename T>T max_index(vector<T>&v){return distance((v).begin(),max_element(ALL(v)));}
template<typename T>T min_index(vector<T>&v){return distance((v).begin(),min_element(ALL(v)));}

struct edge { int to, cost; };

template<typename T>auto&operator<<(ostream&s,const vector<T>&v){s<<"[";bool a=1;for(auto e:v){s<<(a?"":" ")<<e;a=0;}s<<"]";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const pair<T,U>&p){s<<"("<<p.first<<","<<p.second<<")";return s;}
template<typename T>auto&operator<<(ostream&s,const set<T>&st){s<<"{";bool a=1;for(auto e:st){s<<(a?"":" ")<<e;a=0;}s<<"}";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const map<T,U>&m){s<<"{";bool a=1;for(auto e:m){s<<(a?"":" ")<<e.first<<":"<<e.second;a=0;}s<<"}";return s;}

const int INF = 1e18;
const int MOD_N = 1e9+7;

signed main()
{
   int n; cin >> n;
   string s; cin >> s;

   map<P<string,string>, int> cnt1, cnt2;
   REP(k, 1<<n) {
      string str1, str2;
      REP(i, n) {
         if (k >> i & 1) str1 += s[i];
         else            str2 += s[i];
      }
      cnt1[MP(str1, str2)]++;
   }
   REP(k, 1<<n) {
      string str1, str2;
      REP(i, n) {
         if (k >> i & 1) str1 += s[2*n-1-i];
         else            str2 += s[2*n-1-i];
      }
      cnt2[MP(str1, str2)]++;
   }

   int ans = 0;
   for (auto i: cnt1) {
      ans += i.second * cnt2[i.first];
   }
   cout << ans << endl;

   return 0;
}


Measured memory_bytes: 108288
#include<bits/stdc++.h>
#include<boost/variant.hpp>
using namespace std;
typedef long long ll;
typedef vector<boost::variant<bool, ll, int, string, double, char*, const char*>> any;
template<typename T> inline void pr(const vector<T> &xs){
	for(int i=0; i<xs.size()-1; i++) cout<<xs[i]<<" ";
	(xs.empty()?cout:(cout<<xs[xs.size()-1]))<<endl;
}
#ifdef DEBUG
#define debug(...) pr(any{__VA_ARGS__})
#define debugv(x) pr((x))
#else
#define debug(...)
#define debugv(x)
#endif

int main(){
	int N;
	cin >> N;
	string S;
	cin >> S;

	int ans = 0;
	for(int i=0; i<N-1; i++){
		if(S[i]!=S[i+1]) ans += 1;
	}
	cout << ans+1 << endl;

	return 0;
}


Measured memory_bytes: 512
#include <queue>
#include <vector>
#include <cstdio>
#include <cstring>
#include <iostream>

using namespace std;
const int N = 2e6;

int n, m;
int tot = 0, tag = 0, cnt = 0;
int vis[N], b[N], fa[N], num[N], Link[N], dis[N]; 
struct node { int x, y; }; 
struct edge { int y, next, v; } e[N*2];
vector < node > a[N];

int read(void)
{
	int s = 0, w = 0; char c = getchar();
	while (c < '0' || c > '9') w |= c == '-', c = getchar();
	while (c >= '0' && c <= '9') s = s*10+c-48, c = getchar();
	return w ? -s : s;
}

int get(int x) {
	if (fa[x] == x) return x;
	return fa[x] = get(fa[x]);
}

void add(int x,int y,int v) {
	e[++tot] = edge{y,Link[x],v};
	Link[x] = tot;
}

void work(int x)
{
	int t = 0;
	tag ++;
	for (int i=0;i<a[x].size();++i)
	{
		int p1 = a[x][i].x, p2 = a[x][i].y;
		if (vis[p1] != tag) b[++t] = p1, vis[p1] = tag;
		if (vis[p2] != tag) b[++t] = p2, vis[p2] = tag;
	}
	for (int i=1;i<=t;++i) fa[b[i]] = b[i];
	for (int i=0;i<a[x].size();++i) 
	{
		int p1 = a[x][i].x, p2 = a[x][i].y;
		fa[get(p1)] = get(p2);
	}
	tag ++;
	for (int i=1;i<=t;++i)
	{
		int r = get(b[i]);
		if (vis[r] != tag) 
		{
			vis[r] = tag;
			num[r] = ++ cnt;
		}
		add(b[i],num[r],1);
		add(num[r],b[i],1);
	}
	return;
}

int Dijkstra(void)
{
	memset(vis,0,sizeof vis);
	memset(dis,30,sizeof dis);
	dis[1] = 0;
	priority_queue < pair<int,int> > q;
	q.push(make_pair(0,1));
	while (q.size())
	{
		int x = q.top().second; q.pop();
		if (vis[x]) continue; vis[x] = 1;
		if (x == n) return dis[x] / 2; 
		for (int i=Link[x];i;i=e[i].next)
		{
			int y = e[i].y, v = e[i].v;
			if (dis[x] + v < dis[y]) {
				dis[y] = dis[x] + v;
				q.push(make_pair(-dis[y],y));
			}
		}
	}
	return -1;
}

int main(void)
{
	n = cnt = read(), m = read();
	for (int i=1;i<=m;++i)
	{
		int x = read(), y = read(), v = read();
		a[v].push_back(node{x,y});
	}
	for (int i=1;i<=1e6;++i)
	    if (a[i].size()) work(i);
	printf("%d", Dijkstra());
	return 0;
} 

Measured memory_bytes: 92412
#include<bits/stdc++.h>
#define ll long long
const int N=100005;
using namespace std;
int ans=2e9+7;
int n,C,B,A,l[10];
void dfs(int i,int a,int b,int c,int mp)
{
	if(i==n+1)
	{
		if(!a||!b||!c) return;
		else
		{
			ans=min(ans,abs(a-A)+abs(b-B)+abs(c-C)+mp);
			return;
		}
	}
	dfs(i+1,a,b,c,mp);
	dfs(i+1,a+l[i],b,c,mp+(a==0?0:10));
	dfs(i+1,a,b+l[i],c,mp+(b==0?0:10));
	dfs(i+1,a,b,c+l[i],mp+(c==0?0:10));
}
int main(){
	cin>>n>>A>>B>>C;
	for(int i=1;i<=n;i++) cin>>l[i];
	dfs(1,0,0,0,0);
	cout<<ans;
    return 0;
}

Measured memory_bytes: 256
/*
　　　　　　 ＿＿
　　　　　／＞　　 フ
　　　　　| 　_　 _ l
　 　　　／` ミ＿xノ
　　 　 /　　　 　 |　見ちゃだめだよ！
　　　 /　 ヽ　　 ﾉ　　
　 　 │　　|　|　|　　
　／￣|　　 |　|　|
　| (￣ヽ＿_ヽ_)__)
　＼二つ
*/

#include <bits/stdc++.h>
using namespace std;
#define SORT(a) sort((a).begin(), (a).end())
#define RSORT(a) reverse((a).begin(), (a).end())
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
const long long INF = 1LL << 60;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  int f = 0;
  int t = 0;
  rep(i, n) {
    if (a[i] % 4 == 0)
      f++;
    else if (a[i] % 2 == 0)
      t++;
  }
  if (f + t / 2 >= n / 2)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

bool check(string &s){
	if(s.size() < 6) return false;
	bool f1, f2, f3;
	f1 = f2 = f3 = false;
	for(int i=0;i<s.size();i++){
		if('0' <= s[i] && s[i] <= '9') f1 = true;
		if('A' <= s[i] && s[i] <= 'Z') f2 = true;
		if('a' <= s[i] && s[i] <= 'z') f3 = true;
	}
	return f1 && f2 && f3;
}

int main(){
	string s;
	cin >> s;
	cout << (check(s) ? "VALID" : "INVALID") << endl;
	return 0;
}

Measured memory_bytes: 1180
#include<stdio.h>
#include<algorithm>
#include<functional>
#include<cmath>
using namespace std;
long long  mod = 1000000007;
long long a[100000];
int main()
{
	int N;
	int count = 1;
	scanf("%d", &N);
	for (int i = 0; i < N; i++) {
		scanf("%lld", &a[i]);
	}
	sort(a, a + N);
	long long number = a[0];
	long long bit;
	int count0 = 1;
	int count1 = 0;
	int count2 = 0;
	if (N % 3 == 0) {
		if (a[0] == 0) {
			for (int i = 1; i < N; i++) {
				if (a[i] == 0) {
					count0++;
				}
				if (a[i] != number) {
					number = a[i];
					count++;
				}
			}
			if (count == 2 && count0 == N / 3) {
				printf("Yes");
				return 0;
			}
		}
		else {
			for (int i = 1; i < N; i++) {
				if (a[i] == a[0]) {
					count0++;
				}
				if (a[i] == a[N / 3]) {
					count1++;
				}
				if (a[i] == a[N / 3 * 2]) {
					count2++;
				}
				if (a[i] != number) {
					number = a[i];
					count++;
				}
			}
			if (count == 3 && count0 == N / 3 && count1 == N / 3 && count2 == N / 3) {
				bit = a[0] ^ a[N / 3];
				if (bit == a[N / 3 * 2]) {
					printf("Yes");
					return 0;
				}
			}
		}
	}
	count0 = 0;
	for (int i = 0; i < N; i++) {
		if (a[i] == 0) {
			count0++;
		}
	}
	if (count0 == N) {
		printf("Yes");
	}
	else {
		printf("No");
	}
	return 0;
}

Measured memory_bytes: 896
//
//  main.cpp

#include <iostream>
using namespace std;


int main(){	
		int n,m;
		int time[101][101];
		string matrix[101];
	
		cin >> n >> m;
		for(int i=0;i<n;i++){
			cin >> matrix[i];
		}
		for(int i=0;i<n;i++){
			for(int j=0;j<m;j++){
				if(matrix[i][j] == 'c'){
				time[i][j] = 0;
			}else{
				if(j == 0){
					time[i][j] = -1;
				}else if(time[i][j-1] == -1){
					time[i][j] = -1;
				}else{
					time[i][j] = time[i][j-1] + 1;
				}
			}
		}
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			cout << time[i][j];
			if(j != m-1){
				cout << " ";
			}
		}
		cout << endl;
	}
	
	return 0;
}

Measured memory_bytes: 3244
K,N=map(int,input().split())
l=list(map(int,input().split()))
max_distance=0
for i in range(N-1):
    if l[i+1]-l[i]>max_distance:
        max_distance= l[i+1]-l[i]
if K+l[0]-l[N-1]>max_distance:
    max_distance=K+l[0]-l[N-1]
print(K-max_distance)


Measured memory_bytes: 26444
#include <iostream>
#define REP(i, a, n) for(int i = a; i < n; i++)
using namespace std;


int n, k;
int a[100000];
int s, m;

int main(void) {
  while(cin >> n >> k, !(n == 0 && k == 0)) {
    REP(i, 0, n) {
      cin >> a[i];
    }

    s = 0;
    REP(i, 0, k) {
      s += a[i];
    }

    m = s;
    REP(i, k, n) {
      s += a[i] - a[i - k];
      if(s > m) m = s;
    }

    cout << m << endl;
  }

  return 0;
}

Measured memory_bytes: 1548
IDENTIFICATION DIVISION.
PROGRAM-ID. PROGRAM_ID.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 LN           PIC X(500).
01 N            PIC 9(3).
01 cur          PIC 9(10) VALUE 1.
01 i            PIC 9(18) VALUE 1.
01 j            PIC 9(18).
01 len          PIC 9(10). 
01 A            PIC 9(4) VALUE 1.
01 FLG          PIC 9(1) VALUE 1.

PROCEDURE DIVISION.
MAIN.
    ACCEPT N.
    ACCEPT LN.
    PERFORM N TIMES
        PERFORM VARYING j FROM cur BY 1 UNTIL LN(j:1) = SPACE
        END-PERFORM
        COMPUTE len = j - cur
        MOVE LN(cur:len) TO A
        IF FUNCTION MOD(A, 2) = ZERO AND FUNCTION MOD(A, 3) NOT = ZERO
            AND FUNCTION MOD(A, 5) NOT = ZERO THEN
            MOVE ZERO TO FLG
            EXIT PERFORM
        END-IF
        COMPUTE cur = j + 1
        ADD 1 TO i
    END-PERFORM.
    IF FLG = 1
        DISPLAY "APPROVED"
    ELSE
        DISPLAY "DENIED"
    END-IF.

MAIN-EXIT.
    STOP RUN.


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

#define for_(i,a,b) for(int i=a;i<b;++i)
#define allof(a) a.begin(),a.end()

typedef pair< int, int > pii;

int N, Q;
vector< int > s, id;
set< int > leader;

int count(int r) {
	if ((int)leader.size() == 0) return N;
	
	set< int >::iterator it = leader.begin(), eit = leader.end();
	int res = 0, p = 0;
	
	for (; it != eit; ++it) {
		int L = lower_bound(allof(s), s[*it] - r) - s.begin();
		res += max(0, L - p);
		int R = upper_bound(allof(s), s[*it]) - s.begin();
		p = R;
	}
	
	res += N - p;
	return res;
}

int check(int x) {
	int lb = -1, ub = (int)1e9 + 10;
	
	while (ub - lb > 1) {
		int med = (lb + ub) / 2;		
		if (x < count(med)) lb = med;
		else ub = med;
	}
	
	return ub;
}

void query() {
	for_(i,0,Q) {
		string t; int a; cin >> t >> a;
		
		if (t == "ADD") leader.insert(id[a-1]);	
		
		if (t == "REMOVE") leader.erase(id[a-1]);
		
		if (t == "CHECK") {
			int res = check(a);
			if (res > (int)1e9) cout << "NA" << endl;
			else cout << res << endl;
		} 
	}
}

int main() {
	cin >> N >> Q;
	
	vector< pii > vp;
	for_(i,0,N) {
		int s; cin >> s;
		vp.push_back(pii(s, i));
	}
	
	sort(allof(vp));
	
	s.assign(N, 0);
	id.assign(N, 0);
		
	for_(i,0,N) {
		s[i] = vp[i].first;
		id[vp[i].second] = i;
	}
	
	query();
	
	return 0;
}

Measured memory_bytes: 16840
// ~/Remember,remember the 6th of March
#include <functional>
#include <iomanip>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include<complex>
#include <unordered_map>
#include<unordered_set>
#include <numeric>
#include <string>
#include<iostream>
#include <fstream>
#include <assert.h>
#include <ctype.h>
#include <limits.h>
#include <math.h>
#include<cmath>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <sstream>
using namespace std;
const double PI = acos(-1.0);
const double  EPS = 1e-11;
typedef long long ll;
const ll MOD = 1000000007;
const int N = 100000 + 7;
typedef unsigned long long ull;
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
void fast()
{
	std::ios_base::sync_with_stdio(0);
}
int n;
int ans = 0;
bool isok(ll x)
{
	vector<int>arr(9,0);
	while (x)
	{
		arr[x % 10]++;
		x /= 10;
	}
	return (arr[3] > 0 && arr[5] > 0 && arr[7] > 0);
}
void backtrack(ll x)
{
	if (x > n)
		return;
	if (isok(x))
		ans++;
	backtrack(x * 10 + 3);
	backtrack(x * 10 + 5);
	backtrack(x * 10 + 7);
}
int main()
{
/*#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
#endif*/
	cin >> n;
	backtrack(0);
	cout << ans << endl;
	return 0;
}

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

using namespace std;

int a[15],l[15],r[15];
int flag;

void dfs(int i,int j,int k)
{
    if(i>10)
    flag=1;
    if(flag)
    return;
    else
    {
        if(a[i]>l[j-1])
        {
            l[j]=a[i];
            dfs(i+1,j+1,k);
        }
        if(a[i]>r[k-1])
        {
            r[k]=a[i];
            dfs(i+1,j,k+1);
        }
    }

}

int main()
{
    int N;
    cin>>N;
    while(N--)
    {
        memset(a,0,sizeof(0));
        for(int i=1;i<=10;i++)
        cin>>a[i];
        flag=0;
        dfs(1,1,1);
        if(flag)
        cout<<"YES"<<endl;
        else
        cout<<"NO"<<endl;
    }
    return 0;
}

Measured memory_bytes: 3028
#include<cstdio>
#include<vector>
using namespace std;

#define ran 101101

int n, m;
vector<int> e[ran];
int deg[ran], d[ran];
int q[ran], l, r;

int main() {
	scanf("%d%d", &n, &m);
	for(int i=0;i<m;i++) {
		int x, y;
		scanf("%d%d", &x, &y);
		deg[y]++;
		e[x].push_back(y);
	}
	l = r = 0;
	for(int i=1;i<=n;i++)
		if (deg[i]==0) q[r++] = i;
	
	int ans = 0;
	while(l<r) {
		int cur = q[l++];
		for(int i=0;i<(int)e[cur].size();i++) {
			int nxt = e[cur][i];
			d[nxt] = max(d[nxt], d[cur]+1);
			deg[nxt]--;
			if (!deg[nxt]) q[r++] = nxt;
		}
		ans = max(ans, d[cur]);
	}
	printf("%d\n", ans);
	
	return 0;
}

Measured memory_bytes: 7040
#include <cstdio>
#define MAX 10000
#define NIL -1

struct Node{
	int parent,left,right;
};

Node T[MAX];
int n;

void preParse(int u){
	if(u==NIL) return;
	printf(" %d",u);
	preParse(T[u].left);
	preParse(T[u].right);
} 

void inParse(int u){
	if(u==NIL) return;
	inParse(T[u].left);
	printf(" %d",u);
	inParse(T[u].right);
}

void posParse(int u){
	if(u==NIL) return;
	posParse(T[u].left);
	posParse(T[u].right);
	printf(" %d",u);
}

int main() {
	
	int v,l,r,root = 0;
	scanf("%d",&n);
	for(int i=0;i<n;i++) T[i].parent = NIL;
	
	for(int i=0;i<n;i++){
		scanf("%d %d %d",&v,&l,&r);
		T[v].left=l;
		T[v].right=r;
		if(l != NIL) T[l].parent = v;
		if(r!=NIL) T[r].parent = v;
	}
	
	for(int i=0;i<n;i++) 
		if(T[i].parent == NIL) 
			root = i;
	
	
	printf("Preorder\n");
	preParse(root);
	printf("\n");
	
	printf("Inorder\n");
	inParse(root);
	printf("\n");
	
	printf("Postorder\n");
	posParse(root);
	printf("\n");
	
	
	return 0;
}

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

public class Main {
    private static void solve(InputReader sc, PrintWriter out) throws Exception {
        int n = sc.nextInt();
        long arr[] = new long[n];
        for(int i=0; i<n; i++) arr[i] = sc.nextLong();
        long ans=0;
        long curmax= arr[0];
        for(int i=1; i<n; i++){
            if(arr[i] < curmax){
                ans += curmax - arr[i];
            }else curmax = arr[i];
        }
        out.println(ans);

    }

    public static Set<Integer> seive(int n) {
        boolean[] arr = new boolean[n + 1];
        Set<Integer> hs = new HashSet<>();
        Arrays.fill(arr, true);
        for (int i = 2; i <= n; i++) {
            if (arr[i]) {
                for (int j = i + i; j <= n; j += i) {
                    arr[j] = false;
                }
            }
        }
        for (int i = 2; i <= n; i++) {
            if (arr[i]) hs.add(i);
        }
        return hs;
    }

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

    public static void main(String[] args) throws Exception {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        solve(in, out);
        out.close();
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

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

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


Measured memory_bytes: 56084
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <ctype.h>
#include <stdint.h>
#include <string.h>
#include <wchar.h>
#include <math.h>

#define N_MAX (100)
#define P_MAX (100)
#define DP_ARRAY_SIZE (N_MAX * P_MAX / 32 + 1)

#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define ABS(a) ((a) < 0 ? -(a) : (a))
#define ABSS(a, b) ((a) > (b) ? (a) - (b) : (b) - (a))

int compare_sz_asc(const void* a, const void* b) {
    return *((size_t*)a) < *((size_t*)b) ? -1 : 1;
}

int compare_sz_desc(const void* a, const void* b) {
    return *((size_t*)a) > * ((size_t*)b) ? -1 : 1;
}

int compare_i64_asc(const void* a, const void* b) {
    return *((int64_t*)a) < *((int64_t*)b) ? -1 : 1;
}

int compare_i64_desc(const void* a, const void* b) {
    return *((int64_t*)a) > * ((int64_t*)b) ? -1 : 1;
}

int compare_c_asc(const void* a, const void* b) {
    return *((char*)a) < *((char*)b) ? -1 : 1;
}

int compare_c_desc(const void* a, const void* b) {
    return *((char*)a) > * ((char*)b) ? -1 : 1;
}

static size_t comb(const size_t n, const size_t r) {
    size_t result = 1;

    for (size_t i = 0; i < r; i++) {
        result *= n - i;
        result /= i + 1;
    }

    return result;
}

static uint64_t combU64(const uint64_t n, const uint64_t r) {
    uint64_t result = 1;

    for (uint64_t i = 0; i < r; i++) {
        result *= n - i;
        result /= i + 1;
    }

    return result;
}

static size_t gcdZu(size_t m, size_t n) {
    size_t temp;

    while (m % n != 0) {
        temp = n;
        n = m % n;
        m = temp;
    }

    return n;
}

static uint64_t gcdU64(uint64_t m, uint64_t n)
{
    uint64_t temp;

    while (m % n != 0) {
        temp = n;
        n = m % n;
        m = temp;
    }

    return n;
}

int main(void) {
    size_t N,s[100];

    size_t sum = 0;

    scanf("%zu\n", &N);
    for (size_t i = 0; i < N; i++) {
        scanf("%zu", &(s[i]));
        if (i < N - 1) {
            scanf("\n");
        }

        sum += s[i];
    }

    size_t result = 0;

    if (sum % 10 == 0) {
#define IV (10000)
        size_t omitIdx = IV;

        qsort(s, N, sizeof(size_t), compare_sz_asc);

        for (size_t i = 0; i < N; i++) {
            if (s[i] % 10 != 0) {
                omitIdx = i;
                break;
            }
        }

        result = (omitIdx == IV ? 0 : sum - s[omitIdx]);
    }
    else {
        result = sum;
    }

    printf("%zu\n", result);

    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define MOD (1000000007)
#define INF (1e9)
#define INFL (1e18)

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
template<class T>using arr=vector<vector<T>>;
template<class T>int popcount(T &a){int c=0; rep(i, 8*(int)sizeof(a)){if((a>>i)&1) c++;} return c;}
template<class T>void pr(T x){cout << x << endl;}
template<class T>void prvec(vector<T>& a){rep(i, a.size()-1){cout << a[i] << " ";} pr(a[a.size()-1]);}
template<class T>void prarr(arr<T>& a){rep(i, a.size()) if(a[i].empty()) pr(""); else prvec(a[i]);}
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; }

int main()
{
    ll l, r; cin >> l >> r;
    ll ans;
    if(r-l>=2018){
        ans = 0;
    }else{
        ans = INFL;
        l %= 2019;
        r %= 2019;
        for(ll i=l; i<r; i++) for(ll j=i+1; j<r+1; j++) chmin(ans, (i*j)%2019);
    }
    pr(ans);
    return 0;}

Measured memory_bytes: 3604
var
	N,i,j:Longint;
	ans:int64;
begin
	read(N);
	j:=round(sqrt(N));
	if j*j>N then dec(j);
	for i:=1 to j do inc(ans,(N div i)*(N div i+1)*i-i*i*i);
	writeln(ans);
end.

Measured memory_bytes: 1368
#include<iostream>
#include <cmath>

using namespace std;

int main(){

        int X;
        int i,j;
        int ANS;

        ANS=0;

        cin >> X;

        for(i = 2; i <= 1000 ; i++){
                for(j=1; j <= 1000 ; j++){
                        if(ANS <= pow(j,i)){

                                if(pow(j,i) > X){
                                        break;
                                }

                                ANS=pow(j,i);

                        }
                }
        }

        cout << ANS << endl;

        return 0;


}

Measured memory_bytes: 256
n=int(input())

a=[int(x) for x in input().split()]

a.sort()

ans=True
if n%2==0:
  for i in range(n//2):
    if a[i*2]!= 2*i+1 or a[i*2+1]!=2*i+1:
      ans=False
else:
  if a[0]!=0:
    ans=False
  for i in range(n//2):
    if a[i*2+1]!=i*2+2 or a[i*2+1]!=i*2+2:
      ans=False
      
      
if(ans):
  print(2**(n//2)%1000000007)
else:
  print(0)

Measured memory_bytes: 13880
#include <bits/stdc++.h>
using namespace std;
#define for0(i, n) for(int i = 0; i < n; i++)
#define for1(i, n) for(int i = 1; i <= n; i++)
#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define V vector<int>
#define VP vector<pair<int, int> >
#define FASTIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define index INDEX
#ifndef ONLINE_JUDGE
#define print(x) PRINT(x, #x)
template<typename T> inline const void PRINT(T VARIABLE, const string& NAME) {
    cerr << NAME << " = " << fixed << VARIABLE << '\n';
}
#else
#define print(x) 0
#endif
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll INFLL = 2 * (ll)1e18 + 100;
const int INFINT = 2 * (int)1e9 + 100;
const double PI = atan(1) * 4;
const double EPS = 1e-6;
const int SEED = (int)1e3 + 7;
const int MOD = (int)1e9 + 7;
const int NMAX = (int)1e6 + 5;
string s;
#define int ll

int32_t main() {
    FASTIO;
    cin >> s;
    int ans = 0;
    int cnt_b = 0;

    for(auto i: s) 
    {
        if(i == 'B') {
            cnt_b++;
        }
        else {
            ans += cnt_b;
        }
    }

    cout << ans;


    return 0;
}


Measured memory_bytes: 720