akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;
#define _for(i,j,N) for(int i = (j);i < (N);i++)
#define _rep(i,j,N) for(int i = (j);i <= (N);i++)
#define _dec(i,N,j) for(int i = (N-1);i >= (j);i--)
#define _rec(i,N,j) for(int i = (N);i >=(j);i--)
#define ALL(x) x.begin(),x.end()
#define MEM(a,n) memset(a,n,sizeof(a))
#define fst first
#define scd second
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef long double LD;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

int get_int(){int x;scanf("%d",&x);return x;}
LL get_ll(){LL x;scanf("%lld",&x);return x;}
double get_db(){double x;scanf("%lf",&x);return x;}

template<typename T> int chmin(T &a,T b){if(a > b){a = b;return 1;}else return 0;}
template<typename T> int chmax(T &a,T b){if(a < b){a = b;return 1;}else return 0;}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& v) {_for(i,0,v.size()) os << v[i] << " ";return os;}
template<typename T>
ostream& operator<<(ostream& os,const set<T>& v){for(auto a:v) os << a <<" ";return os;}
template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& v){os << v.fst <<" "<<v.scd << " ";return os;}
template<typename T1,typename T2>
ostream& operator<<(ostream& os,const map<T1,T2>& v){for(auto a:v) cout << a << endl;return os;}

static const int dx[8] = { -1,  0, 1, 0,  1, -1,  1, -1};
static const int dy[8] = {0,  1, 0,  -1,  1, -1, -1,  1};
const double pi  = acos(-1.0);
const double eps = 1e-8;
const LL  INF  = 0x3f3f3f3f3f3f3f3f;
const int inf  = 0x3f3f3f3f;

const int maxn = 2e5 + 5;
const LL maxm = LL(1e18)+5;

LL N,B,R;

int main()
{
    cin >> N >> B >> R;
    if(B == 0 && R == 0){
        cout << 0 << endl;
        return 0;
    }
    LL cnt = N/(B+R);
    LL ans = 0;
    ans += cnt * B;
    cnt = N - (B+R)*cnt;
    if(cnt >= B) ans += B;
    else ans += cnt;
    cout << ans << endl;
    return 0;
}


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

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

  int n;cin>>n;
  int cur=1;
  int ans=0;
  int ok=0;
  for(int i=0;i<n;i++){
    int a;cin>>a;
    if(a==1)ok=1;
    if(cur==a){
      cur++;
    }else{
      ans++;
    }
  }
  if(!ok)ans=-1;
  cout<<ans<<endl;

  return 0;
}


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

int checkEven(int *ary, int n)
{
  int i;
  for (i = 0; i < n; i++) {
    if (ary[i] % 2 == 1) {
      return -1;
    }
  }
  return 0;
}

void half(int *ary, int n)
{
  int i;
  for (i = 0; i < n; i++) {
    ary[i] = ary[i] / 2;
  }
}

int main()
{
  int n;
  int *ary;
  int i;
  int count = 0;

  scanf("%d", &n);
  ary = (int *)malloc(sizeof(int) * n);
  if (ary == NULL) {
    return -1;
  }
  
  for (i = 0; i < n; i++) {
    scanf("%d", &ary[i]);
  }

  for (;;) {
    int chk = checkEven(ary, n);
    if (chk == 0) {
      half(ary, n);
      count++;
    } else {
      break;
    }
  }
  printf("%d\n", count);

  free(ary);

  return 0;
}

Measured memory_bytes: 128
#include <iostream>

using namespace std;

int main() {
    string s,t;
    cin >> s >>t;
    bool ans =true;
    if(s.size()<t.size()){
        cout <<"LESS"<<endl;
        ans =false;
    }
    else if( s.size()>t.size()){
        cout<<"GREATER"<<endl;
        ans =false;
    }
    else{
        for(int i=0;i<s.size();i++){
            int   aa =s.at(i);
            int  aaa =t.at(i);

            if(aa<aaa){
                cout <<"LESS"<<endl;
                ans =false;
                break;
            }
            else if(aa>aaa){
                cout<<"GREATER"<<endl;
                ans =false;
                break;
            }
        }
    }
    if(ans){
        cout <<"EQUAL"<<endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
static const int MAX = 100;
static const ll INF = 10000000;
ll d[MAX][MAX];
int N, M;
 
struct  Data {
  int u, v;
  ll c;
  Data() {}
  Data(int u, int v, ll c) : u(u), v(v), c(c){}
};
 
void warshall_floyd() {
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < N; j++) {
  for (int k = 0; k < N; k++) {
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
      }
    }
  }
}
 
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> N >> M;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      if(i == j) d[i][j] = 0;
      else d[i][j] = INF;
    }
  }
 
  Data data[M];
  for (int i = 0; i < M; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    a--;
    b--;
    data[i] = Data(a, b, c);
    d[a][b] = c;
    d[b][a] = c;
  }
  int cnt = 0;
  warshall_floyd();
  warshall_floyd();
  warshall_floyd();
 
  for (int i = 0; i < M; i++) {
    int a = data[i].u;
    int b = data[i].v;
    bool flag = true;
    for (int j = 0; j < N; j++) {
      for (int k = 0; k < N; k++) {
        ll d1 = d[j][a] + data[i].c + d[b][k];
        ll d2 = d[j][k];
        if(d1 == d2) {
          flag = false;
          goto loop;
        }
      }
    }
    loop:
    if(flag) cnt++;
  }
  cout << cnt << "\n";
  return 0;
}

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

#define rep(l, r) for (int i = (l); i < (r); i++)

typedef long long ll;
 
using namespace std;

int main() {
    string s1, s2;
    cin >> s1 >> s2;

    string rs1 = s1, rs2 = s2;
    reverse(rs1.begin(), rs1.end());
    reverse(rs2.begin(), rs2.end());

    cout << (s1 == rs2 && s2 == rs1 ? "YES" : "NO") << endl;

    return 0;
}


Measured memory_bytes: 256
C = [[i for i in range(1, 14)] for j in range(4)]
n = int(input())
for _ in range(n):
    m, n = input().split()
    if m == 'S':
        C[0].remove(int(n))
    elif m == 'H':
        C[1].remove(int(n))
    elif m == 'C':
        C[2].remove(int(n))
    elif m == 'D':
        C[3].remove(int(n))
for i, mrk in enumerate(['S', 'H', 'C', 'D']):
    for j in C[i]:
        print(mrk + ' ' + str(j))


Measured memory_bytes: 5600
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <fstream>
#include <unordered_map>
#include <unordered_set>
#include <assert.h>
using namespace std;


#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007
#define P pair<ll, ll>

ll n, dp[2200][2200], s[2100];
vector<P> v;
int main() {
	cin >> n;
	REP(i, n) {
		cin >> s[i];
		v.push_back(P(s[i], i));
	}
	sort(ALL(v), greater<P>());
	REP(i, 2100) {
		REP(j, 2100) {
			ll now = i + j;
			if (i + j >= n)break;
			dp[i + 1][j] = max(dp[i + 1][j], dp[i][j] + abs(i - v[now].second) * v[now].first);
			dp[i][j + 1] = max(dp[i][j + 1], dp[i][j] + abs((n - j - 1) - v[now].second) * v[now].first);
		}
	}
	ll ans = 0;
	REP(i, n + 1) {
		ans = max(ans, dp[i][n - i]);
	}
	cout << ans << endl;
}


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

int main() {
    int K, X;
    cin >> K >> X;
    if (500 * K >= X)
    {
        cout << "Yes" << endl;
    } else
    {
        cout << "No" << endl;
    }
    
    
  return 0;
}


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

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		Scanner sc=new Scanner(System.in);
		Stack <Integer> stack = new Stack <Integer>();
		while(sc.hasNext()){		
		int a = sc.nextInt();
		int i = -1;
		if(a != 0 ){
			stack.push(a);
			i ++ ;
		}else{
			System.out.println(stack.pop());
		}
		}
	}

}

Measured memory_bytes: 26316
//ex3_2
//TKC001

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

int main(void){
    double N, K, logKN;
    int digits;

    scanf("%lf", &N);
    scanf("%lf", &K);

    logKN = log(N) / log(K);

    digits = logKN;

    printf("%d", digits+1);

    return 0;

}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
constexpr int MOD = 1000000007;
constexpr int INF = numeric_limits<int>::max() / 2;
typedef pair<int,int> P;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int K;
	string S;
	int N = S.size();
	cin >> K;
	cin >> S;
	string T = S.substr(0, K);
	if(S.size() <= K){
		cout << S << endl;
	}
	else{
		cout << T << "..." << endl;
	}
}

Measured memory_bytes: 3656
#include <cstdio>
using namespace std;
int main(){
    long long n, a, b;
    scanf("%lld %lld %lld", &n, &a, &b);
    long long res = n / (a + b) * a;
    n = n % (a + b);
    if(n >= a){
        n = a;
    }
    res += n;
    printf("%lld\n", res);
    return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
using namespace std;
#define ll long long
int main(){
    int N;
    cin >> N;
    cout << "ABC" << N;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define all(x)begin(x),end(x)
using namespace std;int f,Q,T,F;char C;string S;deque<char>q;main(){for(cin>>S>>Q,q={all(S)};Q--;){cin>>T;if(T&1)f^=1;else cin>>F>>C,F-1^f?q.push_back(C):q.push_front(C);}S={all(q)};if(f)reverse(all(S));cout<<S;}

Measured memory_bytes: 1280
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <functional>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cctype>
#include <cstdio>
#include <bitset>
#include <complex>
#define ll long long
#define INF 1000000000000000001
#define MOD 1000000007
using namespace std;


int main(){
    int a,b;
    cin >> a >> b;
    cout<<max(a-2*b,0)<<endl;
    return 0;
    
}


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

int main(void){

	int H, W;
	while (1){
		cin >> H >> W;
		if (H == 0 && W == 0){
			break;
		}
		for (int i = 0; i < H; i++){
			for (int j = 0; j < W; j++){
				if (0 < j&&j < W - 1 && 0 < i&&i < H - 1){
					cout << ".";
				}
				else{
					cout << "#";
				}
				
			}
			cout << endl;//??±??????????????????
			
		}
		cout << endl;//?¬??????±??????????????????
		
	}
	//system("pause");
	return 0;
}

Measured memory_bytes: 1156
def num2alpha(num):
    if num<=26:
        return chr(64+num)
    elif num%26==0:
        return num2alpha(num//26-1)+chr(90)
    else:
        return num2alpha(num//26)+chr(64+num%26)

n = int(input())
ans = num2alpha(n)
ans = ans.lower()
print(ans)

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

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let n: usize = iterator.next().unwrap().parse().unwrap();
    let a: Vec<usize> = (0..n).map(|_| iterator.next().unwrap().parse().unwrap()).collect();

    if a.iter().all(|it| *it % 2 == 0) {
        "second".to_string()
    } else {
        "first".to_string()
    }
}


Measured memory_bytes: 3840
#include<bits/stdc++.h>
using namespace std;
const int maxn=100010,mod=998244353;
#define lson o<<1,l,mid
#define rson o<<1|1,mid+1,r
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define ROF(i,a,b) for(int i=(a);i>=(b);i--)
#define MEM(x,v) memset(x,v,sizeof(x))
inline int read(){
	int x=0,f=0;char ch=getchar();
	while(ch<'0' || ch>'9') f|=ch=='-',ch=getchar();
	while(ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();
	return f?-x:x;
}
int n,m,lim,wsum,e[15][15],f[1<<15][15],tot[1<<15];
inline void chkmax(int &x,int y){if(x<y) x=y;}
int main(){
	n=read();m=read();lim=1<<n;
	FOR(i,1,m){
		int u=read()-1,v=read()-1;
		wsum+=e[u][v]=e[v][u]=read();
	}
	FOR(i,0,lim-1) FOR(j,0,n-1) if((i>>j)&1) FOR(k,j+1,n-1) if((i>>k)&1) tot[i]+=e[j][k];
	MEM(f,~0x3f);
	f[1][0]=0;
	FOR(i,1,lim-1) FOR(j,0,n-1) if((i>>j)&1){
		FOR(k,0,n-1) if(!((i>>k)&1) && e[j][k]) chkmax(f[i|(1<<k)][k],f[i][j]+e[j][k]);
		int re=(lim-1)^i;
		for(int k=re;k;k=((k-1)&re)) chkmax(f[i|k][j],f[i][j]+tot[k|(1<<j)]);
	}
	printf("%d\n",wsum-f[lim-1][n-1]);
}

Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin >> n;
	vector<int> x(n);
	vector<int> y(n);
	vector<int> h(n);
	
	for(int i=0;i<n;i++) {
		cin >>x[i] >> y[i] >> h[i];
	}
	int cx,cy,H;
	int st=0;
  for(int i = 0;i<n;i++)
  {
    if(h[i] != 0) {
      st = i;
      break;
    }
  }
  
	for(int i=0 ;i<=100;i++)
	{
		cx = i;
		for(int j=0; j<=100;j++){
			cy = j;
			H=abs(x[st]-cx)+abs(y[st]-cy)+h[st];
			
			for(int k=0;k<n;k++) {
              	int tmp = H-abs(x[k]-cx)-abs(y[k]-cy);
           		if(tmp < 0)
             		tmp = 0;
				if(h[k] != tmp){
					break;
				}
				if(k==n-1)
				{
					cout << cx << " " << cy << " " << H << endl;
					return 0;
				}
			}
		}
		
	}	
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
#include<utility>
#include<cmath>
using namespace std;
#define all(a) a.begin(),a.end()


int main()
{
	long long a[40]={0,1,1,1};
	for(int i=0;i<=30;i++)
	{
		for(int j=1;j<=3;j++)
		{
			a[i+j]+=a[i];
		}
	}
	
	int n;
	while(cin>>n&&n)
	{
		int ans=a[n];
		ans=ans/10+(ans%10?1:0);
		ans=ans/365+(ans%365?1:0);
		cout<<ans<<endl;
	}
	
}

Measured memory_bytes: 2984
m, d = map(int, input().split())
ans = 0

for i in range(1, m+1):
    for j in range(20, d+1):
        a = j // 10
        b = j % 10
        if a == 1 or b == 1:
            continue
        if a * b == i:
            ans += 1

print(ans)


Measured memory_bytes: 2940
import math

n, h = [int(i) for i in input().split(" ")]
t = []

for i in range(0, n):
    a, b = [int(i) for i in input().split(" ")]
    t.append((a, "a"))
    t.append((b, "b"))

t = sorted(t, key=lambda k: k[0], reverse=True)

c = 0
i = 0

while h > 0:
    if t[i][1] == "b":
        h -= t[i][0]
        c += 1
        i += 1
    else:
        c += math.ceil(h / t[i][0])
        h = 0

print(c)

Measured memory_bytes: 28292
import sys
def printans(t):
    print(t)
    sys.exit()

N=int(input())
A=[int(i) for i in input().split()]

if all([a==A[0] for a in A]):#全部同じ
    shurui=A[0]
    if shurui==N-1 or shurui*2<=N:
        printans("Yes")
    else:printans("No")
else:#少ないやつは自分だけの色、そいつら以外で上と同じ処理
    maxshurui = max(A)
    if all([a in (maxshurui,maxshurui-1) for a in A]):
        unique = A.count(maxshurui-1)
        shurui = maxshurui-unique
        if shurui<=0:
            printans("No")
        if shurui*2<=N-unique:
            printans("Yes")
        else:printans("No")
    else:printans("No")

Measured memory_bytes: 13964
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  scanf("%d",&n);
  int a[n],b[n],c[n];
  for(int i=0;i<n;i++)
  {
    scanf("%d",&c[i]);
    a[i]=c[i];
    b[i]=c[i];
  }  
  b[n-1]=c[n-1];
  for(int i=1;i<n;i++)
    a[i]+=a[i-1];
  for(int i=n-2;i>=0;i--)
   b[i]+=b[i+1];
  
  
  
  int ans=100000000;
  for(int i=0;i<n;i++)
  {
	int max=a[i],min=b[i],mid=c[i];
    if(max<min)
    {
      max=b[i];
      min=a[i];
    }
    int d=max-min-mid;
    if(d<0) d=-d;
    if(ans>d) ans=d;
  }
  printf("%d",ans);
  return 0;
}


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

bool Look_like_105(int n){
    int count = 0;
    if(n%2 == 1){
        for(int i=1;i<=n;i++){
            if(n%i == 0){
                count++;
            }
        }
    }

    if(count == 8){
        return true;
    }else{
        return false;
    }
}

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

    int count = 0;
    for(int i=1;i<=n;i++){
        if(Look_like_105(i)){
            count++;
        }
    }

    cout << count << endl;
}

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

using namespace std;

int main() {
  int N;
  cin >> N;
  vector<int64_t> V(N + 1);
  V[0] = 2;
  V[1] = 1;
  for (int i = 2; i <= N; i++) {
    V[i] = V[i - 1] + V[i - 2];
  }
  cout << V[N];

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int n,m,x,tmp,ans=10000000,tmp1;
int main()
{
    scanf("%d%d%d",&n,&m,&x);
    tmp=min(n,m),tmp1=max(n,m);
    for(int i=1; i<=tmp; i++)
        if(i*tmp1>=x)
        {
            printf("%d",i);
            return 0;
        }
}


Measured memory_bytes: 256
// B.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>
using namespace std;

int main()
{
    int n, k;
    int ans = 0;
    cin >> n >> k;

    while (n >= k) {

        n = n / k;
        ans++;
    }

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

// プログラムの実行: Ctrl + F5 または [デバッグ] > [デバッグなしで開始] メニュー
// プログラムのデバッグ: F5 または [デバッグ] > [デバッグの開始] メニュー

// 作業を開始するためのヒント: 
//    1. ソリューション エクスプローラー ウィンドウを使用してファイルを追加/管理します 
//   2. チーム エクスプローラー ウィンドウを使用してソース管理に接続します
//   3. 出力ウィンドウを使用して、ビルド出力とその他のメッセージを表示します
//   4. エラー一覧ウィンドウを使用してエラーを表示します
//   5. [プロジェクト] > [新しい項目の追加] と移動して新しいコード ファイルを作成するか、[プロジェクト] > [既存の項目の追加] と移動して既存のコード ファイルをプロジェクトに追加します
//   6. 後ほどこのプロジェクトを再び開く場合、[ファイル] > [開く] > [プロジェクト] と移動して .sln ファイルを選択します


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	int A,B;
	scanf("%d %d",&A,&B);

	if(A==B){ printf("Draw\n"); }
	else if(A==1){ printf("Alice\n"); }
	else if(B==1){ printf("Bob\n" ); }
	else if(A>B) { printf("Alice\n"); }
	else { printf("Bob\n"); }
}

Measured memory_bytes: 128
import java.util.*;

public class Main{
	private static final Scanner scan = new Scanner(System.in);

	public static void main(String[] args){
		String s = scan.next();
		String ss = s + s;
		String p = scan.next();
		boolean flag = false;
		for(int i = 0; i < ss.length() - p.length(); i++){
			String div = ss.substring(i,i + p.length());
			if(div.equals(p)){
				flag = true;
				break;
			}
		}
		System.out.println(flag? "Yes" : "No");
	}
}

Measured memory_bytes: 26260
#include <stdio.h>

int main(){
	int n,i,j,k;
	int sum,count=0;
	
	scanf("%d\n",&n);
	while(n!=0){
		count=0;
	for(i=2;i<=n;i++){
		sum=0;
		for(j=1;j<=n;j++){
			sum=0;
			for(k=0;k<i;k++){
				sum+=j+k;
			}
			if(sum==n){
				count++;
				break;
			}
		}
	}
		printf("%d\n",count);
		scanf("%d\n",&n);
	}
	return 0;
}
		

Measured memory_bytes: 1032
#include <iostream>

using namespace std;

int n;
int r[555][555];
int z[555][555];
int p[555*555];

void dfs(int y, int x, int c, int f) {
	if (y < 1 || x < 1 || y > n || x > n) return;
	if (f && r[y][x] <= c) return;
	r[y][x] = c;
	dfs(y-1,x,r[y][x]+z[y][x],1);
	dfs(y+1,x,r[y][x]+z[y][x],1);
	dfs(y,x-1,r[y][x]+z[y][x],1);
	dfs(y,x+1,r[y][x]+z[y][x],1);
}

int main() {
	cin >> n;
	for (int i = 1; i <= n*n; i++) cin >> p[i];
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			int m1 = min(i-1,n-i);
			int m2 = min(j-1,n-j);
			r[i][j] = min(m1,m2);
			z[i][j] = 1;
		}
	}
	int t = 0;
	for (int i = 1; i <= n*n; i++) {
		int y = (p[i]-1)/n+1;
		int x = (p[i]-1)%n+1;
		t += r[y][x];
		z[y][x] = 0;
		dfs(y,x,r[y][x],0);
	}
	cout << t << "\n";
}


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

using namespace std;

typedef long long ll;

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

	double t, x;
	cin >> t >> x;
	cout << fixed << setprecision(6);
	cout << t / x << endl;
}


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

using namespace std;

int main(){
	//入力
    string s;
	cin >> s;
	int n = s.size();

	long long ans = 0;//答え

	for (int bit = 0; bit < (1 << (n - 1)); bit++){//2のn-1乗まで回す
		long long tmp = s[0] - '0';//現在の値
		for (int i = 0; i < n - 1; i++){
			if (bit & (1 << i)){//bitと2のi乗が同じ時
				ans += tmp;//現在の値をたす
				tmp = s[i+1] - '0';//現在の値を更新する

			}
			else{//bitと2のi乗が同じでない時
				tmp = 10 * tmp + s[i+1] - '0';//現在の値を10倍して次の値を足したものに更新する
			}
		}
		ans += tmp;//最後は現在の値を答えに足す
		tmp = 0;//初期化
	}
	cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))

def sequence(plus_start):
    cost = 0
    cum = 0

    for i in range(N):
        tmp = cum + A[i]
        target = tmp
        if plus_start:
            if i % 2 == 0:
                if tmp <= 0:
                    target = 1
            else:
                if tmp >= 0:
                    target = -1
        else:
            if i % 2 == 0:
                if tmp >= 0:
                    target = -1
            else:
                if tmp <= 0:
                    target = 1
        diff = target - tmp
        cum += A[i] + diff
        cost += abs(diff)
    return cost

print(min(sequence(True), sequence(False)))



Measured memory_bytes: 14468
import copy

N=int(input())

def arrange(List,n=N):  #先頭がup末尾がdownの総数をList[up][down]に入れる;Listは10×10で0が入ってる
    for i in range(1,n+1):
        Len=len(str(i))
        up=int(str(i)[0])
        down=int(str(i)[Len-1])
        List[up][down]+=1
    return List

original=[]
component=[]
for x in range(10):
    component.append(0)
for y in range(10):
    original.append(copy.deepcopy(component))


L=arrange(original)

ans=0

for j in range(10):
    for k in range(10):
        ans+=L[j][k]*L[k][j]

print(ans)



        
        

Measured memory_bytes: 3444
#include <stdio.h>
#include <cmath>
#include <algorithm>
 
int main(){
    int n,tmp,count = 0,limit;
    scanf("%d",&n);
 
    for(int i = 0; i < n; i++)
    {
        scanf("%d",&tmp);
        limit = sqrt(tmp);
        for(int j = 2; j <= limit; j++){
            if(tmp%j==0){
                count++;
                break;
            }
        }
    }
    printf("%d\n",n-count);
}


Measured memory_bytes: 2740
(function(input) {
  var p = input.replace(/\n$/, '').split('\n');
  var n = p.length;
  var m = new Array(10);
  for (var i = 0; i < m.length; i++) {
    m[i] = (new Array(11)).join('0').split('').map(Number);
  }
  for (i = 0; i < n; i++) {
    var a = p.shift().split(',').map(Number);
    var x = a.shift();
    var y = a.shift();
    var s = a.shift();
    drop(m, x, y, s);
  }
  var max = 0;
  var space = 0;
  //console.log(m);
  for (i = 0; i < 10; i++) {
    for (var j = 0; j < 10; j++) {
      var c = m[i][j];
      //console.log(c);
      if (c > max) {
        max = c;
      }
      if (c === 0) {
        space++;
      }
    }
  }
  console.log(space);
  console.log(max);
})(require('fs').readFileSync('/dev/stdin', 'utf8'));

function drop(m, x, y, s) {
  drop_(m, x, y);
  drop_(m, x, y - 1);
  drop_(m, x - 1, y);
  drop_(m, x + 1, y);
  drop_(m, x, y + 1);
  if (s >= 2) {
    drop_(m, x - 1, y - 1);
    drop_(m, x + 1, y - 1);
    drop_(m, x - 1, y + 1);
    drop_(m, x + 1, y + 1);
  }
  if (s >= 3) {
    drop_(m, x, y - 2);
    drop_(m, x - 2, y);
    drop_(m, x + 2, y);
    drop_(m, x, y + 2);
  }
}

function drop_(m, x, y) {
  if (x < 0 || x > 9 || y < 0 || y > 9) {
    return;
  }
  m[x][y]++;
}

Measured memory_bytes: 7640
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
    static BufferedReader reader;
    static PrintWriter writer;
    static StringTokenizer tokenizer;

    static String nextToken() throws IOException {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(reader.readLine());
        }
        return tokenizer.nextToken();
    }

    static int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    static long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    static void banana() throws IOException {
        String s = nextToken();
        int res = 0;
        String last = "";
        String curr = "";
        for (char c : s.toCharArray()) {
            curr += c;
            if (!curr.equals(last)) {
                last = curr;
                curr = "";
                res++;
            }
        }
        writer.println(res);
    }

    public static void main(String[] args) throws IOException {
        reader = new BufferedReader(new InputStreamReader(System.in));
        writer = new PrintWriter(System.out);
        tokenizer = null;
        banana();
        reader.close();
        writer.close();
    }
}

Measured memory_bytes: 43780
#include<bits/stdc++.h>
#pragma GCC optimize("O2")
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define all(c) c.begin(), c.end()
#define endl "\n"
#define sz(u) (int)(u.size())
#define L(x)(2*x)
#define R(x)(2*x+1)
#define M(x,y)((x+y)/2)
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
void solve(){
    string s,t;
    cin>>s>>t;
    if(t.length()<=s.length()){
        cout<<"No";
        return ;
    }
    for(int i=0;i<s.length();i++){
        if(s[i]!=t[i]){
            cout<<"No";
            return ;
        }
    }
    cout<<"Yes";
}
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //int t;
    //cin>>t;
    //while(t--){
        solve();
        //cout<<endl;
    //}
}



Measured memory_bytes: 3608
import re
st = ""
try:
	while 1:
		st += raw_input()
except:
	pass

num = re.compile("\d+")
i = 0
li = []

while 1:
	m = num.search(st, i)
	
	if m:
		s = m.start()
		e = m.end()
		i = e + 1
		li.append(int(st[s:e]))
	else:
		break

print sum(li)

Measured memory_bytes: 4216
#include <queue>
#include <string>
#include <iostream>
using namespace std;
int main () {
  priority_queue<int> Q;
  string a;
  while (cin >> a && a != "end") {
    int b;
    if (a == "insert") {
      cin >> b;
      Q.push(b);
    }
    else {
      cout << Q.top() << endl;
      Q.pop();
    }
  }
}
      

Measured memory_bytes: 5980
#include "bits/stdc++.h"
using namespace std;
#define long int64_t

int main() {
	ios_base::sync_with_stdio( false );

	long H;
	cin >> H;

	long a = 0;
	while( H /= 2 ) { a += 1; }

	cout << (1LL << (a+1))-1 << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
/**
*   author: j o s e m a g o
*   date:
**/
using namespace std;
#pragma GCC optimize ("Ofast")
#define f first
#define s second
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define mset(a,v) memset(a,v,sizeof(a))
#define pb push_back
#define sz(x) ((int)(x).size())
#define rsz resize
#define ln "\n"

typedef double db;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
const ld PI = 2*acos(0.0);
const int MOD = 1000000007;


int matriz[100009][3];
int dp[100009][3];



int main(){

  //freopen("input.in","r",stdin);
  //freopen("input.out","w",stdout);

    ios_base::sync_with_stdio(0); cin.tie(0);


    int n;
    cin >> n;
    for(int i = 0;i < n;i++){
        for(int j = 0;j < 3;j++){
            cin >> matriz[i][j];
        }
    }
    int m = 0;
    dp[0][0] = matriz[0][0]; dp[0][1] = matriz[0][1]; dp[0][2] = matriz[0][2];
    for(int i = 1;i < n;i++){

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

            for(int k = 0;k < 3;k++){
                if(k != j){
                    m = max(dp[i-1][k],m);
                }
            }
            dp[i][j]+=m;
            dp[i][j]+= matriz[i][j];
            m = 0;
        }
    }

    int sol = 0;
    for(int i = 0;i < 3;i++){
        sol = max(dp[n-1][i],sol);
    }
    cout<<sol;



    return 0;
}
/*
7
6 7 8
8 8 3
2 5 2
7 8 6
4 6 8
2 3 4
7 5 1



*/


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

const int maxn=(int)1e5+5;
struct node
{
	int s,t;
	friend  bool operator <(const node &a,const node &b)
	{
		if(a.s!=b.s)return a.s<b.s;
		else return a.t<b.t;
	}
};
int s[maxn];


int main()
{
	int n,m;
	scanf("%d%d",&n,&m);
	vector<node>v[40];
	for(int i=0;i<n;i++)
	{
		int l,r,p;
		scanf("%d%d%d",&l,&r,&p);
		v[p].push_back(node{l,r});
	}
	for(int i=1;i<=m;i++)
	{
		sort(v[i].begin(),v[i].end());
		if(v[i].size()>0)
		{
			int pt=0;
			for(int j=1;j<v[i].size();j++)
			{
				if(v[i][j].s==v[i][pt].t)
				{
					v[i][pt].t=v[i][j].t;
					v[i][j].s=-1;
					v[i][j].t=-1;
				}
				else
				{
					pt=j;
				}
			}
		}
	}
	for(int i=1;i<=m;i++)
	{
		for(int j=0;j<v[i].size();j++)
		{
			if(v[i][j].s!=-1)
			{

				s[v[i][j].s]++;
				s[v[i][j].t+1]--;
			}
		}
	}
	int maxx=0;
	for(int i=1;i<maxn;i++)
	{
		s[i]+=s[i-1];
		maxx=max(maxx,s[i]);
	}
	cout<<maxx<<"\n";



	return 0;
}


Measured memory_bytes: 1792
import copy
N = int(input())
A = list(map(int, input().split()))
X = copy.deepcopy(A)
X.sort()
for i in range(N):
    if A[i] >= X[int(N/2)]:
        print(X[int(N/2)-1])
    else:
        print(X[int(N/2)])


Measured memory_bytes: 26724
#include <cstdio>
#include <map>

using namespace std;

const int MAXN=2e5+10;

int N;


int main(){
    map<int,int> m;
    scanf("%d",&N);

    for(int i=1;i<=N;i++) {
        int temp;
        scanf("%d",&temp);
        m[temp]++;
    }

    auto ans=0;
    auto maxele=(*m.rbegin()).first;
    for(auto i:m){
        for(int k=2;i.first*k<=maxele;k++){
            int temp=i.first*k;
            auto multiple=m.find(temp);
            if (multiple==m.end()) continue;
            m.erase(multiple);
        }
        if (i.second>1) continue;
        ans++;
    }

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

    return 0;
}

Measured memory_bytes: 12652
/*
* Note: This template uses some c++11 functions , so you have to compile it with c++11 flag.
*       Example:-   $ g++ -std=c++11 c++Template.cpp
*
* Author : Akshay Pratap Singh
* Handle: code_crack_01
*
*/
 
/********   All Required Header Files ********/
#include <iostream>
#include <string>
#include <vector>
#include <unordered_map>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

using namespace std;

/*******  All Required define Pre-Processors and typedef Constants *******/
#define SCD(t) scanf("%d",&t)
#define SCLD(t) scanf("%ld",&t)
#define SCLLD(t) scanf("%lld",&t)
#define SCC(t) scanf("%c",&t)
#define SCS(t) scanf("%s",t)
#define SCF(t) scanf("%f",&t)
#define SCLF(t) scanf("%lf",&t)
#define MEM(a, b) memset(a, (b), sizeof(a))
#define FOR(i, j, k, in) for(int i=j ; i<k ; i+=in)
#define RFOR(i, j, k, in) for(int i=j ; i>=k ; i-=in)
#define REP(i, j) FOR(i, 0, j, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define IN(A, B, C) assert( B <= A && A <= C)
#define MP make_pair
#define PB push_back
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define read(type) readInt<type>()
typedef long long int ll;
typedef unsigned long long int  ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<ll> vll;
typedef vector<vi> vvi;

#define MAX 100005

int main(){

    int n, c; cin >> n >> c;
    vvi A(c, vi(MAX, 0));
    // vi A(MAX, 0);

    int s, t, __c;
    REP(i, n){
        cin >> s >> t >> __c;
		__c--;
        for(int j=s; j<=t; ++j){
		    A[__c][j]++;
		}
		
    }

    int res = 0;
    REP(i, MAX){
        int r = 0;
        REP(j, c){
            if( A[j][i]>0 ) r += 1;
        }
        res = max(res, r);
	}

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 12416
def m():
    n = int(input())
    s = str(input())
    ans = 0
    for i in range(1, n):
        cnt = 0
        left = set(s[i:])
        right = set(s[:i])
        for j in left:
            if j in right:
                cnt +=1
        ans = max(cnt, ans)
    return ans

print(m())

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

int main()
{
	char a,b;
	cin >> a >> b;
	if (a == 'H') cout << b << endl;
	else
	{
		if (b == 'H') cout << 'D' << endl;
		else cout << 'H' << endl;
	}
	return 0;
}

Measured memory_bytes: 256
N = int(input())
s = [input() for _ in range(N)]
M = int(input())
t = [input() for _ in range(M)]

cnt = 0
for i in range(N):
    tmp = s.count(s[i]) - t.count(s[i])
    if tmp > cnt:
        cnt = tmp
print(max(cnt, 0))


Measured memory_bytes: 38256
import java.util.*;

public class Main {
    static Scanner scanner = new Scanner(System.in);

    public static void main(String[]$) {
        int n = scanner.nextInt();
        int x = scanner.nextInt();
        int count = 1;
        for (int i = 0, j = 0; i < n; i++) {
            j += scanner.nextInt();
            if (j <= x) {
                count++;
            }
        }
        System.out.println(count);
    }
}

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

int main(){
  int a,b;
  cin >> a >> b;
  if(a<10&&b<10) cout << a*b << endl;
  else cout << "-1" << endl;
  return 0;
}


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

void stringEqui(int n,int i, char *a, char c){
    if(i==n){
        a[i]='\0';
        cout<<a<<endl;
        return;
    }
    for(char ch='a'; ch<=c; ch++){
        a[i]=ch;
        if(ch==c){
            stringEqui(n,i+1,a,c+1);
        }
        else{
            stringEqui(n,i+1,a,c);
        }
    }
}
int main() {
	
// 	int t=3;
// 	while(t--){
	    int n;cin>>n;
	    char a[100];
	    stringEqui(n,0,a,'a');
	   // cout<<endl; 
// 	}
	
}


Measured memory_bytes: 1536
#include <iostream>
#include<algorithm>
#include <stdio.h>
#include <string>
#include <string.h>
#include <map>
#include <math.h>
#include <vector>
#include <set>
#include <map>
#include <deque>
using namespace std;
typedef long long ll;
const int N=2e5+9;
int l,r;
map<int,int>mp;
int a[N],b[N];
struct sa
{
    int x;
    int y;
}p[N];
int cmp(const sa &a,const sa &b)
{
    return a.y>b.y;
}
int main()
{
    int n,m;
    while(scanf("%d %d",&n,&m)!=-1)
    {
        for(int i=1;i<=n;i++)
            scanf("%d",&a[i]);
        for(int i=1;i<=m;i++)
        {
            scanf("%d %d",&p[i].x,&p[i].y);
        }
        sort(a+1,a+n+1);
        sort(p+1,p+m+1,cmp);
        int j=1;
        for(int i=1;i<=n;i++)
        {
            if(p[j].x==0)
                j++;
            if(j>m)
                break;
            if(a[i]<p[j].y&&p[j].x>0)
            {
                a[i]=p[j].y;
                p[j].x--;
            }
        }
        ll ans=0;
        for(int i=1;i<=n;i++)
        {
            ans+=a[i];
        }
        printf("%lld\n",ans);
    }
    return 0;
}


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

using namespace std;

struct UnionFind
{
	//number of parents(par[i] = i => root)
	vector<int> par;
	//rank of tree
	vector<int> rank;

	UnionFind(int n) : par(n), rank(n, 1)
	{
		//initialize
		for (int i = 0; i < n; i++) par[i] = i;
	}

	//find root (keiroasshuku at the same time)
	int root(int x)
	{
		if (par[x] == x)
			return x;
		else
			return par[x] = root(par[x]);
	}

	//unite
	void unite(int x, int y)
	{
		x = root(x);
		y = root(y);
		if (x == y) return;
		if (rank[x] > rank[y]) swap(x, y);
		par[x] = y;
		rank[y] += rank[x];
	}

	//same tree?
	bool same(int x, int y)
	{
		return root(x) == root(y);
	}
};

void solve()
{
	int N, M;
	cin >> N >> M;
	UnionFind uf(M);
	bitset<100010> exist;
	while(N--)
	{
		int K, pre = -1;
		cin >> K;
		while(K--)
		{
			int L;
			cin >> L;
			L--;
			exist[L] = 1;
			if (pre >= 0)
			{
				uf.unite(L, pre);
			}
			pre = L;
		}
	}

	set<int> s;

	for (int m = 0; m < M; m++)
	{
		if (!exist[m]) continue;
		s.insert(uf.root(m));
	}

	cout << (s.size() == 1 ? "YES" : "NO") << endl;
}

int main()
{
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define int long long
#define double long double
#define INF 1e18
using namespace std;
signed main() {
  int N; cin >> N;
  int ans = 0;
  for (int i = 0; i < N; i++) {
    int a; cin >> a;
    if (a%2==0) ans++;
  }
  cout<<ans<<endl;
}



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

int main(){
        ll n;
        scanf("%lld", &n);
        ll a[n], b[n], c[n];
        for(ll i=0; i<n; i++) scanf("%lld", &a[i]);
        for(ll i=0; i<n; i++) scanf("%lld", &b[i]);
        for(ll i=0; i<n; i++) c[i] = a[i] - b[i];

        ll luck = 0, ans = 0;
        std::priority_queue<ll> que;
        for(ll i=0; i<n; i++){
                if(c[i]<0){
                        luck -= c[i];
                        ans++;
                }else que.push(c[i]);
        }

        while(!que.empty()){
                if(luck<=0) break;
                ll tmp = que.top(); que.pop();
                luck -= tmp;
                ans++;
        }

        if(luck>0) puts("-1");
        else printf("%lld\n", ans);
        return 0;
}

Measured memory_bytes: 3576
import java.util.*;

public class Main {
    public static void main(String args[]) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        Map<Integer, Integer> headTailFreq = new HashMap<>();

        String s = "";
        for(int i = 1; i <= n; i++) {
        	s = String.valueOf(i);
        	int head = s.charAt(0) - '0';
        	int tail = s.charAt(s.length()-1) - '0';
        	if(tail == 0) continue;
        	int key = head * 10 + tail;
        	headTailFreq.put(key, headTailFreq.getOrDefault(key, 0) + 1);
        }
        int cnt = 0;
        for(Map.Entry<Integer, Integer> entry : headTailFreq.entrySet()) {
        	int head = entry.getKey() / 10;
        	int tail = entry.getKey() % 10;
        	cnt += entry.getValue() * headTailFreq.getOrDefault(tail * 10 + head, 0);
        }
        System.out.println(cnt);
    }
}


Measured memory_bytes: 40232
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		new Main().solveA();
		// new Main().solveB();
		// new Main().solveC();
		// new Main().solveD();
	}

	private void solveA() {
		Scanner scanner = null;
		String date = "";

		try {
			scanner = new Scanner(System.in);
			date = scanner.next();
			SimpleDateFormat sdFormat = new SimpleDateFormat("yyyy/MM/dd");
			Date uDate = sdFormat.parse(date);
			Date tDate = sdFormat.parse("2019/04/30");

			int diff = tDate.compareTo(uDate);
			if (diff == 0) {
				System.out.println("Heisei");
			} else if (diff > 0) {
				System.out.println("Heisei");
			} else {
				System.out.println("TBD");
			}

		} catch (ParseException e) {
			e.printStackTrace();
		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private void solveB() {
		Scanner scanner = null;
		int numN = 0;
		int numK = 0;
		int numS = 0;

		try {
			scanner = new Scanner(System.in);
			numN = scanner.nextInt();

			System.out.println("");

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private void solveC() {
		Scanner scanner = null;
		int numN = 0;
		int numK = 0;
		int numS = 0;

		try {
			scanner = new Scanner(System.in);
			numN = scanner.nextInt();

			System.out.println("");

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private void solveD() {
		Scanner scanner = null;
		int numN = 0;
		int numK = 0;
		int numS = 0;

		try {
			scanner = new Scanner(System.in);
			numN = scanner.nextInt();

			System.out.println("");

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}
}

Measured memory_bytes: 23248
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <iomanip>
using namespace std;

void solve(){
  string s; cin >> s;
  unsigned long long k; cin >> k;
  vector<int> v(s.length());
  for(int i = 0; i < s.length(); i++){
    v[i] = (int)s[i] - '0';
  }
  for(int i = 0; i < v.size(); i++){
    if(v[i] == 1){
      if(k <= i + 1){
        cout << 1 << endl;
        return;
      }
    }
    else{
      cout << v[i] << endl;
      return;
    }
  }
  if(v[0] == 1){
    if(k == 1) cout << v[0] << endl;
    else cout << v[1] << endl;
  }
  else cout << v[0] << endl;
  return;
}
int main(){
  solve();
  return 0;
}


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

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
Int G[1000][1000];
signed main(){
  Int n,m;
  cin>>n>>m;
  memset(G,0,sizeof(G));
  for(Int i=0;i<m;i++){
    Int a,b;
    cin>>a>>b;
    a--;b--;
    G[a][b]=G[b][a]=1;
  }
  for(Int i=0;i<n;i++) G[i][i]=1;

  vector<Int> used(n,0);
  vector<Int> x,y;
  for(Int i=0;i<n;i++){
    if(used[i]) continue;
    queue<Int> q;
    used[i]=1;
    q.emplace(i);
    Int c[3]={};
    while(!q.empty()){
      Int v=q.front();q.pop();
      c[used[v]]++;
      for(Int u=0;u<n;u++){
	if(G[v][u]) continue;
	if(used[v]==used[u]){
	  cout<<-1<<endl;
	  return 0;
	}
	if(used[u]) continue;
	used[u]=3-used[v];
	q.emplace(u);
      }
    }
    x.emplace_back(c[1]);
    y.emplace_back(c[2]);
  }

  vector<Int> dp(n+1,0);
  dp[0]=1;
  for(Int i=0;i<(Int)x.size();i++){
    vector<Int> nx(n+1,0);
    for(Int j=0;j<=n;j++){
      if(j+x[i]<=n) nx[j+x[i]]|=dp[j];
      if(j+y[i]<=n) nx[j+y[i]]|=dp[j];
    }
    swap(dp,nx);
  }
  
  Int ans=m;
  for(Int x=0;x<=n;x++){
    if(!dp[x]) continue;
    Int y=n-x;
    //cout<<x<<":"<<y<<endl;
    chmin(ans,x*(x-1)/2+y*(y-1)/2);
  }
  
  cout<<ans<<endl;
  
  return 0;
}


Measured memory_bytes: 8064
inp = input()
F = int(inp[:2])
B = int(inp[2:])
flagMMYY = False
flagYYMM = False
if F>=1 and F<=12:
  flagMMYY = True
if B>=1 and B<=12:
  flagYYMM = True
if flagMMYY and flagYYMM:
  print ('AMBIGUOUS')
elif flagMMYY:
  print ('MMYY')
elif flagYYMM:
  print ('YYMM')
else:
  print ('NA')

Measured memory_bytes: 3064
while line = gets
  data = line.split(",").map(&:to_i)
  sum = data[0,10].inject{|elem,sum| sum += elem}
  v1 = data[10]
  v2 = data[11]
  rate = 1.0*v1/(v1+v2)
  s = 0.0
  data.each_with_index do |elem,index|
    s += elem
    if s/sum >= rate
      puts index+1 
      break
    end
  end
end

Measured memory_bytes: 6116
#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))

using namespace std;
typedef pair<llint, llint> P;
typedef pair<P, llint> E;

llint n;
llint a[6005];
llint dp[2005][2005];
llint rmax[2005], cmax[2005], gmax;
vector<E> vec;

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;
	for(int i = 1; i <= 3*n; i++) cin >> a[i];
	
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= n; j++){
			dp[i][j] = -inf;
		}
	}
	dp[a[1]][a[2]] = 0;
	
	for(int i = 1; i <= n; i++) rmax[i] = cmax[i] = -inf;
	rmax[a[1]] = cmax[a[2]] = 0;
	
	llint add = 0;
	for(int i = 1; i <= n-1; i++){
		
		llint b[3] = {a[i*3], a[i*3+1], a[i*3+2]};
		vec.clear();
		
		if(b[0] == b[1] && b[1] == b[2]){
			add++;
			continue;
		}
		
		for(int j = 0; j < 3; j++){
			for(int k = 0; k < 3; k++){
				if(j == k) continue;
				vec.push_back(E(P(b[j], b[k]), gmax));
				vec.push_back(E(P(b[j], b[k]), dp[b[3-(j+k)]][b[3-(j+k)]] + 1));
			}
		}
		
		for(int j = 1; j <= n; j++){
			for(int k = 0; k < 3; k++){
				vector<llint> tmp;
				for(int l = 0; l < 3; l++){
					if(k != l) tmp.push_back(b[l]);
				}
				vec.push_back(E(P(j, b[k]), rmax[j]));
				if(tmp[0] == tmp[1]) vec.push_back(E(P(j, b[k]), dp[j][tmp[0]] + 1));
			}
		}
		for(int j = 1; j <= n; j++){
			for(int k = 0; k < 3; k++){
				vector<llint> tmp;
				for(int l = 0; l < 3; l++){
					if(k != l) tmp.push_back(b[l]);
				}
				vec.push_back(E(P(b[k], j), cmax[j]));
				if(tmp[0] == tmp[1]) vec.push_back(E(P(b[k], j), dp[tmp[0]][j] + 1));
			}
		}
		
		for(int i = 0; i < vec.size(); i++){
			llint r = vec[i].first.first, c = vec[i].first.second, x = vec[i].second;
			chmax(dp[r][c], x), chmax(rmax[r], x), chmax(cmax[c], x), chmax(gmax, x);
		}
	}
	dp[a[3*n]][a[3*n]]++;
	
	llint ans = 0;
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= n; j++){
			ans = max(ans, dp[i][j]);
		}
	}
	ans += add;
	cout << ans << endl;
	
	return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  int pre = -999;
  rep(i,n) {
    if (pre <= a[i]-1) {
      pre = a[i]-1;
    } else if (pre <= a[i]) {
      pre = a[i];
    } else {
      puts("No");
      return 0;
    }
  }
  puts("Yes");
  return 0;
}

Measured memory_bytes: 640
#include<stdio.h>
int main(void) {
	int a;
  scanf("%d",&a);
	if (a>=2800) {
		printf("AGC\n");
	}
	else if (a<1200) {
		printf("ABC\n");
	}
	else {
		printf("ARC\n");
	}
	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define forr(x,n) for(int x = 0; x < n; ++x)
#define pr pair<int,int>
#define ll long long int
const int mod=1e9+7;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n,a,b;
    cin>>n>>a>>b;
    ll x=n/(a+b);
    ll ans=x*a;
    x=n%(a+b);
    ans+=min(x,a);
    cout<<ans;
}



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


int main()
{
	int a,b,c;
	cin >>a>>b>>c ;
	if (a < c && c < b)cout << "Yes" << endl;
	else if(b<c&&c<a)cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Linq;
using System.Diagnostics;
using System.Globalization;
using static System.Console;
using static System.Math;


namespace abc101_b
{
    class Program
    {
        static void Main(string[] args)
        {
            string str = Console.ReadLine();
            int num = int.Parse(str);
            int cnt=0;

            for(int i=0; i<str.Length; i++){
                cnt += int.Parse(str[i].ToString());
            }

            if(num % cnt == 0)WriteLine("Yes");
            else WriteLine("No");
            //Write("改行なし a = {0} b = {1} c = {2}", a, b, c);
            //WriteLine("改行あり a = {0} b = {1} c = {2}", a, b, c);
            //WriteLine($"答えは{input[0]+input[1]}");
        }

        /// 値のスワップ
        static void Swap<T>(ref T lhs, ref T rhs)
        {
            T temp;
            temp = lhs;
            lhs = rhs;
            rhs = temp;
        }


    }
}

Measured memory_bytes: 11092