akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <climits>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

// using
using namespace std;

// typedef
typedef long long ll;

// define
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REVERSE(c) reverse(ALL(c))
#define UNIQ(c) unique(ALL(c))
#define FOR(i, a, b, c) for (int i = (int)(a); i < (int)(b); i += (int)(c))
#define REP(i, n) FOR(i, 0, n, 1)
#define RFOR(i, a, b, c) for (int i = (int)(a); i >= (int)(b); i -= (int)(c))
#define RREP(i, n) RFOR(i, n, 0, 1)

// functions
template <class T> T ceil(T a, T b) {
    return (a + b - 1) / b;
}
template <class T> T round(T a, T b) {
    return (a + b / 2) / b;
}
template <class T> T gcd(T a, T b) {
    return b ? gcd(b, a % b) : a;
}
template <class T> T lcm(T a, T b) {
    return a * b / gcd(a, b);
}
template <class T> bool amax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> bool amin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

// main
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> X(N), Y(N), H(N);
    int x, y, h;
    REP(i, N) {
        cin >> X[i] >> Y[i] >> H[i];
        if (H[i] > 0) {
            x = X[i], y = Y[i], h = H[i];
        }
    }
    REP(cx, 101) {
        REP(cy, 101) {
            bool f = true;
            int A = h + abs(x - cx) + abs(y - cy);
            REP(i, N) {
                int d = abs(X[i] - cx) + abs(Y[i] - cy);
                if (H[i] > 0) {
                    f = H[i] + d == A;
                } else {
                    f = A <= d;
                }
                if (!f) {
                    break;
                }
            }
            if (f) {
                cout << cx << " " << cy << " " << A << endl;
                return 0;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 256
from math import sqrt
n = int(input())
p1 = complex(0, 0)
p2 = complex(100, 0)
phi = complex(1/2, sqrt(3)/2)

def makeCurve(p1, p2, cnt):
    if cnt >= n:
        return
    s = p1 + (p2-p1)/3
    t = p1 + (p2-p1)*2/3
    u = (t-s)*phi+s
    
    
    makeCurve(p1, s, cnt + 1)
    print(s.real, s.imag)
    makeCurve(s, u, cnt + 1)
    print(u.real, u.imag)
    makeCurve(u, t, cnt + 1)
    print(t.real, t.imag)
    makeCurve(t, p2, cnt + 1)

print(p1.real, p1.imag)
makeCurve(p1, p2, 0)
print(p2.real, p2.imag)


Measured memory_bytes: 5744
N,K = map(int,input().split())
R,S,P = map(int,input().split())
T = input()

mods = [[] for i in range(K)]
for i in range(N):
    mods[i%K].append(T[i])

ans = 0
for mod in mods:
    L = len(mod)
    before = 'N'
    for i in range(L):
        if mod[i] != before:
            if mod[i] == 'r':
                ans += P
            elif mod[i] == 's':
                ans+= R
            else:
                ans+= S
            before = mod[i]
        else:
            before = 'N'
#         print(ans)
#     print('mod',ans)
print(ans)
            
        

Measured memory_bytes: 13428
n = int(input())
sd = {}
hl = ["M","A","R","C","H"]
for i in range(n):
    s = input()
    head = s[0]
    
    if not head in hl:
        continue
        
    if head in sd:
        sd[head] += 1
    else:
        sd[head] = 1
        
values = list(sd.values())
#print(values)
length = len(values)
counts = 0
if length < 3:
    print(0)
else:
    for i in range(length-2):
        for j in range(i+1,length-1):
            for k in range(j+1,length):
#                print(i,j,k)
                counts += values[i]*values[j]*values[k]

    print(counts)

Measured memory_bytes: 3064
// https://atcoder.jp/contests/abc174/tasks/abc174_e

#include "algorithm"
#include "bitset"
#include "cmath"
#include "functional"
#include "iomanip"
#include "iostream"
#include "map"
#include "numeric"
#include "queue"
#include "set"
#include "string"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define rep1(i, to) for (ll i = 1; i <= (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
#define repr(i, from) for (ll i = from - 1; i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define unless(cond) if (!(cond))
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
using VVL = V<VL>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;

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

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

template <typename T>
inline ll len(V<T> arr) {
  return arr.size();
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}

const ll INF = 1e18;

void solve();

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

  try {
    solve();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

void solve() {
  ll N, K;
  cin >> N >> K;

  VL as(N);
  rep(i, N) cin >> as[i];

  ll ng = 0;
  ll ok = 1e9;

  while (ok - ng > 1) {
    ll mid = (ok + ng) / 2;

    ll ct = 0;

    for (ll a : as) {
      if (a <= mid) continue;
      ct += a / mid;

      if (ct > K) break;
    }

    if (ct > K) {
      ng = mid;
    } else {
      ok = mid;
    }
  }

  drop(ok);
}


Measured memory_bytes: 4780
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    ll N, M, K;
    cin >> N >> M >> K;
    vector<ll> A(N+1, 0), B(M+1, 0);
    for (int i = 1; i <= N; i++) {
        cin >> A[i];
        A[i] += A[i-1];
    }
    for (int i = 1; i <= M; i++) {
        cin >> B[i];
        B[i] += B[i-1];
    }
    ll ans = 0;
    for (int i = 0; i <= N && A[i] <= K; i++) {
        ll a = i, b = upper_bound(B.begin(), B.end(), K-A[i])-B.begin()-1;
        ans = max(ans, a+b);
    }
    cout << ans << endl;
}

Measured memory_bytes: 6432
#include <stdio.h>
#define ll long long int

int main() {
    int n;
    scanf("%d", &n);
    ll arr[n], max = 1e18, prod = 1, flag = 0, zero = 0;
    for (int i = 0; i < n; i++) {
        scanf("%lld", &arr[i]);
        arr[i] > max ? flag = 1 : flag = flag;
        prod *= arr[i];
        arr[i] ? max /= arr[i] : zero = 1;
    }
    if (zero) {
        puts("0");
    }
    else {
        flag ? printf("-1\n") : printf("%lld\n", prod);
    }
    return 0;
}


Measured memory_bytes: 2464
import java.util.* ;
class Main {
  public static void main(String[] args) {
    
    Scanner scan = new Scanner(System.in);
    String s = scan.next();
    char c[] = s.toCharArray();
    int x = 700 ;
    for(int i = 0 ; i < 3 ; i++){
      if(c[i] == 'o'){
        x+=100 ;
      }
    }
    System.out.println(x);
    
  }
}


Measured memory_bytes: 20820
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
       
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int sum = a * b;
        if(a >= 1 && a<= 9 && b >=1 && b<=9){
            
                System.out.println(sum);
        }else{
            System.out.println("-1");
        }
    }
}

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

int main(){
	int n,t;
	int a[200010];
	scanf("%d%d",&n,&t);
	for(int i = 0 ; i < n ; i ++){
		scanf("%d",&a[i]);
	}
	
	int ret = t;
	for(int i = 1 ; i < n ; i ++){
		if(a[i] < a[i-1]+t){
			ret -= a[i-1]+t-a[i];
		}
		ret += t;
	}
	cout << ret << endl;
}



Measured memory_bytes: 1024
#include <stdio.h>

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

int h,w;
int ans;
int flg[10],t[10][10000];

int count(void){
  int i,j;
  int tmp, res = 0;

  rep(j,w){
    //1Ìð¦é
    tmp = 0;
    rep(i,h) if(flg[i] && !t[i][j] || !flg[i] && t[i][j]) tmp++;

    if(tmp < h - tmp) //jñÚð Ôµ½ûª¢¢
      res += h - tmp;
    else //jñÚð Ô³È¢ûª¢¢
      res += tmp;
  }

  return res;
}

void solve(int idx){
  int res;

  if(idx == h){
    res = count();
    if(ans < res) ans = res;
    return;
  }

  //idxsÚð Ô³È¢
  flg[idx] = 0;
  solve(idx+1);

  //idxsÚð Ô·
  flg[idx] = 1;
  solve(idx+1);
}

int main(void){
  int i,j;

  while(scanf("%d%d",&h,&w) && (h||w)){
    rep(i,h) rep(j,w) scanf("%d",&t[i][j]);
    ans = 0;
    solve(0);
    printf("%d\n",ans);
  }

  return 0;
}

Measured memory_bytes: 800
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
 
using namespace std;
 
int main()
{
    int n;
    cin >> n;
    
    string sl, su;
    
    int lower = n - 1;
    int upper = 0;
    
    cout << upper << '\n';
    cin >> su;
    cout << lower << '\n';
    cin >> sl;
    if (su != "Vacant" && sl != "Vacant") {
        for (int i = 1; i < 20; i++) {
            
            cout << (lower+upper+1)/2 << '\n';
            cin >> sl;
            if (sl == "Vacant") {
                break;
            }
            if (! (sl == su ^ ((lower+upper+1)/2 - upper)%2 == 0)) {
                upper = (lower+upper+1)/2;
                su = sl;
            } else {
                lower = (lower+upper+1)/2;
            }
        }
    }
 
    return 0;
}

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

int main(){
	int a, b, c, x;
	cin >> a >> b >> c;

	if(a>b){
		x=a;
		a=b;
		b=x;
	}
	if(a>c){
		x=a;
		a=c;
		c=x;
	}
	if(b>c){
		x=b;
		b=c;
		c=x;
	}
	cout << a << " " << b << " " << c << endl;

	return 0;
}

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

int main(){
    int K, A, B;
    cin >> K >> A >> B;
    if(A % K == 0 || (A / K) - (B / K) != 0){
        cout << "OK" << endl;
    }else {
        cout << "NG" << endl;
    }
    return 0;
}

Measured memory_bytes: 3628
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>

#define int long long int
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

int solve(const vector<vector<int>>& b, const vector<int>& s, const vector<int>& p, int n, int x){
    int res = 0;
    rep(i, 5){
        if(x < b[n][i]){
            break;
        }
        x -= b[n][i];
        if(i % 2 == 1){
            res += p[n-1];
        }
        if(i == 2){
            res += 1;
        }
    }

    if(x != 0){
        res += solve(b, s, p, n-1, x);
    }

    return res;
}

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

    int n, x;
    cin >> n >> x;

    vector<vector<int>> b(51, vector<int>(5));
    vector<int> s(51);
    vector<int> p(51);
    b[0][0] = 1;
    s[0] = 1;
    p[0] = 1;

    rep(i, 50){
        b[i+1][0] = 1;
        b[i+1][1] = s[i];
        b[i+1][2] = 1;
        b[i+1][3] = s[i];
        b[i+1][4] = 1;

        rep(j, 5){
            s[i+1] += b[i+1][j];
        }
        p[i+1] = 1 + p[i] * 2;
    }

    cout << solve(b, s, p, n, x) << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>
#include <vector>

#define ll long long

int D[101][2];

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

    for(int i=0; i < N; i++) {
        std::cin >> D[i][0] >> D[i][1];
    }

    bool success = false;
    int count = 0;
    for(int i=0; i < N; i++) {
        if(D[i][0] == D[i][1]) {
            count++;
            if(count >= 3) {
                success = true;
                break;
            }
        }
        else {
            count = 0;
        }
    }
    std::cout << (success ? "Yes" : "No") << std::endl;
}

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

int main()
{
    int n;
    cin>>n;
    int a[n]={},m1=-1,m2=-1;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        if(a[i]>m1)
        {
            m2=m1;
            m1=a[i];
            continue;
        }
        if(a[i]>=m2)
            m2=a[i];

    }
    for(int i=0;i<n;i++)
    {
        if(a[i]==m1)
            cout<<m2;
        else
            cout<<m1;
        cout<<'\n';
    }

    return 0;
}



Measured memory_bytes: 4404
#include <stdio.h>
//#include <stdlib.h>
//#include <string.h>
//#include <limits.h>
//#include <math.h>

int main() {
  int n;
  scanf("%d", &n);
  for (int i=1; i<10; i++) {
    for (int j=1; j<10; j++) {
      if (n == i*j) {
        printf("Yes\n");
        return 0;
      }
    }
  }
  printf("No\n");
  return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<string>
#include<cstring>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<bitset>
#define endl "\n"
using namespace std;

int main()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  char a[100], b[100], c[100];
  cin >> a >> b >> c;
  int len_a = strlen(a);
  int len_b = strlen(b);
  int len_c = strlen(c);
  int index_a=0, index_b=0, index_c=0;
  char turn='a';

  while (1)
  {
    if (turn == 'a')
    {
      if (index_a == len_a)
      {
        cout << "A" << endl;
        break;
      }
      turn = a[index_a];
      index_a += 1;
    }
    else if (turn == 'b')
    {
      if (index_b == len_b)
      {
        cout << "B" << endl;
        break;
      }
      turn = b[index_b];
      index_b += 1;
    }
    else if (turn == 'c')
    {
      if (index_c == len_c)
      {
        cout << "C" << endl;
        break;
      }
      turn = c[index_c];
      index_c += 1;
    }
    else
    {
      cout << "error" << endl;
      break;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;


int main(){
  int M1, D1, M2, D2;
  cin >> M1 >> D1 >> M2 >> D2;

  if(M1 != M2) cout << 1 << endl;
  else cout << 0 << endl;
  
  return 0;
}



Measured memory_bytes: 768
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)
int main(){
    int n, m;
    cin >> n >> m;
    vector<bool> ng(n+1);
    rep(i, m) {
        int a;
        cin >> a;
        ng[a] = true;
    }
    vector<ll> dp(n+1, 0);
    dp[0] = 1;
    rep(i, n) {
        if ( !ng[i+1] ) {
            dp[i+1] = ( dp[i+1] + dp[i] ) % mod;
        }
        if ( i + 2 >= n + 1 ) continue;
        if ( !ng[i+2] ) {
            dp[i+2] = ( dp[i+2] + dp[i] ) % mod;
        }
    }
    cout << dp[n] << endl;
    return 0;
}

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

int main() {
    int A, B; cin >> A >> B;
    int ans = 0;
    for (int i = A; i <= B; i++) {
        string S_reverse = to_string(i);
        reverse(S_reverse.begin(), S_reverse.end());
        string S = to_string(i);
        if (S == S_reverse) {
            ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3688
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <x86intrin.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define V vector
template <typename T> bool chmin(T &a, const T &b) {if(a > b){a = b; return true;} return false;}
template <typename T> bool chmax(T &a, const T &b) {if(a < b){a = b; return true;} return false;}
template<typename A, size_t N, typename T> void Fill (A (&array)[N], const T & val) {fill ((T*)array, (T*)(array+N), val);}
V<int> dx = {-1, 1,  0, 0, -1, -1,  1, 1};
V<int> dy = { 0, 0, -1, 1, -1,  1, -1, 1};

int main () {
    int n; cin >> n;
    V<bool> z(n, false);
    rep(i, n) {
        int a, b; cin >> a >> b;
        if (a == b) z[i] = true;
    }
    bool flag = false;
    rep(i, n-2) {
        if (z[i] && z[i+1] && z[i+2]) flag = true;
    }
    if (flag) puts("Yes");
    else puts("No");

    return 0;
}

Measured memory_bytes: 3628
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <set>
using namespace std;
const int Maxn=2005;
int n,k,q,a[Maxn],c[Maxn],bit[Maxn],ans=1e9;
set <int> s;
inline int min(int a,int b) {return a<b?a:b;}
inline void upd(int x) {for (;x<=n;x+=x&-x) bit[x]++;}
inline int qry(int x) {int r=0;for(;x;x-=x&-x) r+=bit[x];return r;}
int cmp(const void* __a,const void* __b){return a[*(int*)__a]-a[*(int*)__b];}
int main()
{
	scanf("%d%d%d",&n,&k,&q);
	for (int i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
		c[i]=i;
	}
	qsort(c,n,sizeof(int),cmp);
	for (int i=0;i+q<=n;i++)
	{
		int cnt=0;memset(bit,0,sizeof(bit));
		for (int j=i;j<n;j++)
		{
			int x=c[j],lp,rp;
			set <int>::iterator l=s.lower_bound(x),r=l;
			lp=(l!=s.begin()?(*--l):-1);rp=(r!=s.end()?(*r):n);
			if (rp-lp-1-(qry(rp)-qry(lp+1))>=k) upd(x+1),cnt++;
			if (cnt>=q)
			{
				ans=min(ans,a[c[j]]-a[c[i]]);
				break;
			}
		}
		s.insert(c[i]);
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 380
import java.util.Scanner;

public class Main {

	private static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		int h = sc.nextInt(), w = sc.nextInt();
		char[][] board = new char[h][w];
		for (int i = 0; i < h; i++) {
			String s = sc.next();
			for (int j = 0; j < w; j++) {
				board[i][j] = s.charAt(j);
			}
		}
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				if (board[i][j] == '#') {
					continue;
				}
				char count = '0';
				for (int k = -1; k <= 1; k++) {
					if (i == 0 && k == -1 || i == h - 1 && k == 1) {
						continue;
					}
					for (int l = -1; l <= 1; l++) {
						if (j == 0 && l == -1 || j == w - 1 && l == 1 || k == 0 && l == 0) {
							continue;
						}
						if (board[i + k][j + l] == '#') {
							count++;
						}
					}
				}
				board[i][j] = count;
			}
		}
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				sb.append(board[i][j]);
			}
			sb.append("\n");
		}
		System.out.println(sb);
	}
}

Measured memory_bytes: 23124
// Problem : A - Plural Form
// Contest : AtCoder - AtCoder Beginner Contest 179
// URL : https://atcoder.jp/contests/abc179/tasks/abc179_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

/*ヽ｀、ヽ｀｀、ヽ｀ヽ｀、、ヽ ｀ヽ 、ヽ｀🌙｀ヽヽ｀ヽ、ヽ｀
ヽ｀、ヽ｀｀、ヽ 、｀｀、 ｀、ヽ｀ 、｀ ヽ｀ヽ、ヽ ｀、ヽ｀｀、
ヽ、｀｀、｀、ヽ｀｀、 、ヽヽ｀、｀、、ヽヽ、｀｀、 、 ヽ｀、
ヽ｀｀、 ヽ｀ヽ｀、、ヽ ｀ヽ 、 🚶ヽ｀｀｀｀ヽヽヽ｀、、ヽ｀、、ヽ*/
#include <bits/stdc++.h> 
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
 
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long   ll;
typedef long double ld;
typedef complex< ld > cd;
 
typedef pair<int, int> pi;
typedef pair<ll, ll>   pl;
typedef pair<ld, ld>   pd;
 
typedef vector< int > vi;
typedef vector< ld >  vd;
typedef vector< ll >  vl;
typedef vector< pi >  vpi;
typedef vector< pl >  vpl;
typedef vector< cd >  vcd;
 
#define l00p(i, a, b) for (int i=a; i<(b); i++)
#define loop(i, a)    for (int i=0; i<(a); i++)
#define rep1(i, a, b) for (int i = (b)-1; i >= a; i--)
#define rep(i, a)     for (int i = (a)-1; i >= 0; i--)
#define trav(a, x)    for (auto& a : x)
#define uid(a, b)     uniform_int_distribution<int>(a, b)(rng)
#define vt vector
#define bug(x) cout<<#x<<"="<<x<<endl;

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f  first
#define s  second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define ins insert
//#define MOD 998244353
 
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ld pii=3.14159265359; 
const int MOD = 1000000007;
const char cl = '\n';
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); 
	string s;
	cin>>s;
	cout<<s;
	if(s[sz(s)-1]=='s')
	cout<<"es";
	else
	cout<<"s";
	return 0;
}
// read the question correctly (ll vs int)
// template by bqi343


Measured memory_bytes: 3668
a,b,c = gets.chomp.split().map(&:to_i)
k = gets.chomp.to_i
count = 0
while(true)
    if (a < b) && (b < c)
        print 'Yes'
        break
    end
    if a >= b
        b = b*2
        count += 1
    elsif b >= c
        c = c*2
        count += 1
    end
    if count > k
        print 'No'
        break
    end
end



Measured memory_bytes: 14416
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <iomanip>

using namespace std;

int main() {
  int n,m;
  cin>>n>>m;
  vector<int> a(n);
  int sum=0;
  int k=0;
  for(int i=0;i<n;i++){
    cin>>k;
    a[i]=k;
    sum+=k;
  }
  sort(a.begin(),a.end(),greater<int>());

  if(a[m-1]*4*m>=sum)cout<<"Yes"<<endl;
  else
    cout<<"No"<<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); cout.tie(0);
    int n, x, t; cin >> n >> x >> t;
    ll a = 0;
    while (n > 0)
    {
        a += t;
        n -= x;
    }
    cout << a << '\n';
    return 0;
}

Measured memory_bytes: 3600
import java.util.Scanner;

public class Main{
    public static void main (String[] args) {
    Scanner sc = new Scanner(System.in);
    while (true){
        int m = sc.nextInt();
        int f = sc.nextInt();
        int r = sc.nextInt();
        int score = m+f;
        if(m==-1 && f==-1 && r==-1){
            break;
        }
        if(score<30 || m==-1 || f==-1){
            System.out.println("F");
        }else if(score>=80){
            System.out.println("A");
        }else if(score>=65){
            System.out.println("B");
        }else if(score>=50){
            System.out.println("C");
        }else if(score>=30 && r>=50){
            System.out.println("C");
        }else{
            System.out.println("D");
        }
    }
    }   
}


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

typedef long long ll;
typedef pair<int,int> ii;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	string s; cin>>s;
	int n=3;
	for (int i=0; i<(1<<n); i++) {
		int cur=s[0]-'0';
		string ret; ret+=s[0];
		for (int j=0; j<n; j++) {
			if(i&(1<<j)) cur+=s[j+1]-'0', ret+='+';
			else cur-=s[j+1]-'0', ret+='-';
			ret+=s[j+1];
		}
		ret+="=7";
		if(cur==7) {
			cout<<ret<<"\n";
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
#define len(n) (int)n.length()
#define pb push_back
#define ll long long
#define make_pair mkp
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define ALL(v) (v).begin(), (v).end()
#ifdef DBGPRT
#define dbg(n) cerr << "//" << #n << ":" << n <<endl
#else
#define dbg(n) ;
#endif
typedef pair<ll, ll> LLARR;
#define INF 999999999
const double PI = 3.1415926535897932384626433832795;
const ll MOD = 1000000007;

ll ans=1;
vector<ll> prime = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53 ,59 ,61 ,67 ,71 ,73 ,79 ,83 ,89 ,97 ,101 ,103 ,107 ,109 ,113 ,127 ,131 ,137 ,139 ,149 ,151 ,157 ,163 ,167 ,173 ,179 ,181 ,191 ,193 ,197 ,199 ,211 ,223 ,227 ,229 ,233 ,239 ,241 ,251 ,257 ,263 ,269 ,271 ,277 ,281 ,283 ,293 ,307 ,311 ,313 ,317 ,331 ,337 ,347 ,349 ,353 ,359 ,367 ,373 ,379 ,383 ,389 ,397 ,401 ,409 ,419 ,421 ,431 ,433 ,439 ,443 ,449 ,457 ,461 ,463 ,467 ,479 ,487 ,491 ,499 ,503 ,509 ,521 ,523 ,541 ,547 ,557 ,563 ,569 ,571 ,577 ,587 ,593 ,599 ,601 ,607 ,613 ,617 ,619 ,631 ,641 ,643 ,647 ,653 ,659 ,661 ,673 ,677 ,683 ,691 ,701 ,709 ,719 ,727 ,733 ,739 ,743 ,751 ,757 ,761 ,769 ,773 ,787 ,797 ,809 ,811 ,821 ,823 ,827 ,829 ,839 ,853 ,857 ,859 ,863 ,877 ,881 ,883 ,887 ,907 ,911 ,919 ,929 ,937 ,941 ,947 ,953 ,967 ,971 ,977 ,983 ,991 ,997 };
vector<ll> aa(prime.size(), 0);

void frac(int n, int curr)
{
	FOR(j,2,n+1)
	{
		for(int i = 0; i < prime.size(); i++)
		{
			if (n < prime[i])
				break;

			ll tmp = j;
			while((tmp%prime[i]) == 0)
			{
					aa[i]++;
					tmp /= prime[i];
			}
		}


	}
}

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

	int n;
	cin >> n;
	frac(n,1);

	REP(i , aa.size())
	{
		ans = ans * (aa[i] + 1) % MOD;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>//cout<<right で右揃え
#include <iomanip>//cout<<setw(数字) で空白による桁揃え
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <algorithm>
#include <cstdlib>//abs()で整数絶対値
#include <cmath>//abs()かfabs()で少数絶対値
#include <functional>//sort第三引数greater<型名>()で降順
#include <map>

using namespace std;
using ll = long long int;

int main(){
    int X,N;cin>>X>>N;
    map<int,bool> m;
    for(int i=0;i<N;i++){
        int a;cin>>a;
        m[a] = true;
    }
    for(int i=0;;i++){
        if(!m[X-i]){
            cout << X-i << endl;
            break;
        }
        if(!m[X+i]){
            cout << X+i << endl;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;
#define int long long int
const int INF = 1001001001001001LL;

int di[] = {-1, 0, 1, 0, -1, 1, 1, -1};
int dj[] = {0, 1, 0, -1, 1, 1, -1, -1};

// えびちゃんの make_vector (ここから)
template <typename Tp, size_t N>
std::vector<Tp> make_vector_detail(std::vector<size_t>& sizes, typename std::enable_if<(N == 1), const Tp&>::type x) {
  return std::vector<Tp>(sizes[0], x);
}
template <typename Tp, size_t N>
auto make_vector_detail(std::vector<size_t>& sizes, typename std::enable_if<(N > 1), const Tp&>::type x) {
  size_t size = sizes[N-1];
  sizes.pop_back();
  return std::vector<decltype(make_vector_detail<Tp, N-1>(sizes, x))>(size, make_vector_detail<Tp, N-1>(sizes, x));
}

template <typename Tp, size_t N>
auto make_vector(const size_t(&sizes)[N], const Tp& x) {
  std::vector<size_t> s(N);
  for (size_t i = 0; i < N; ++i) s[i] = sizes[N-i-1];
  return make_vector_detail<Tp, N>(s, x);
}
// えびちゃんの make_vector (ここまで)

signed main(){
    
    int r, d, x; cin >> r >> d >> x;
    for(int i = 0; i < 10; i++){
        x = r * x - d;
        cout << x << endl;
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        HashMap<String, Integer> hashmap = new HashMap<>();
        hashmap.put("A", 10);
        hashmap.put("B", 11);
        hashmap.put("C", 12);
        hashmap.put("D", 13);
        hashmap.put("E", 14);
        hashmap.put("F", 15);
        
        String x = sc.next();
        String y = sc.next();
        
        if (hashmap.get(x) > hashmap.get(y)) {
            System.out.println(">");
        } else if (hashmap.get(x) < hashmap.get(y)) {
            System.out.println("<");
        } else {
            System.out.println("=");
        }
    }
}


Measured memory_bytes: 21716
while True:
    h, w = map(int, input().split())
    if not h:
        break
    diagonal = h**2 + w**2
    ans = []
    append = ans.append
    for y in range(1, 151):
        for x in range(y+1, 151):
            if x**2+y**2 > diagonal or x**2+y**2 == diagonal and y > h:
                append((x**2+y**2, y, x))
                break
    print(*sorted(ans)[0][1:])


Measured memory_bytes: 5596
# coding: utf-8
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, M = lr()
LR = np.array([lr() for _ in range(M)])
L = LR[:, 0]; R = LR[:, 1]
answer = R.min() - L.max() + 1
if answer < 0:
    answer = 0
print(answer)


Measured memory_bytes: 37896
// Problem : B - String Palindrome
// Contest : AtCoder Beginner Contest 159
// URL : https://atcoder.jp/contests/abc159/tasks/abc159_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
ordered_set;	

#define FOR(i,a,b) for(int i = (a); i <= (b); ++i)
#define FORD(i,a,b) for(int i = (a); i >= (b); --i)
#define RI(i,n) FOR(i,1,(n))
#define REP(i,n) FOR(i,0,(n)-1)
#define mini(a,b) a=min(a,b)
#define maxi(a,b) a=max(a,b)
#define mp make_pair
#define pb push_back
#define st first
#define nd second
#define sz(w) (int) w.size()
typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<pii, int> para;
const ll inf = 1e18 + 7;
const ll maxN = 1e6 + 5;
const ll MOD = 1e9 + 7;

bool palindrome(string s) {
	string t = s;
	reverse(t.begin(), t.end());
	return s == t;
}

int main() {
	ios_base::sync_with_stdio(0);
	string s;
	cin >> s;
	int n = sz(s);
	string s1 = s.substr(0, (n - 1) / 2);
	string s2 = s.substr((n + 3) / 2 - 1, string::npos);
	//cout << s1 << " " << s2 << endl;
	if (palindrome(s) && palindrome(s1) && palindrome(s2)) {
		cout << "Yes\n";
	} else {
		cout << "No\n";
	}
	return 0;
}
 


Measured memory_bytes: 256
import java.util.Scanner;
class Main {
	
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        String a = sc.next();
        char[] b = a.toCharArray();
        int[] c = new int[b.length];
        int i=0;
        for (char b1 : b) {
        		c[i] = (int)b1;
        		i++;
        }
        for(int j=0; j<c.length; j++) {
        		int d = (c[j]-65+N)%26+65;
        		System.out.print((char)d);
        } 
    }
}

Measured memory_bytes: 25168
import std.stdio, std.conv, std.string, std.array, std.algorithm, std.range;

void main() {
  auto N = readln.split[0].to!int;
  auto H = readln.split.to!(int[]);

  H ~= int.max;

  auto maxNum = 0;
  auto num = 0;
  size_t i = 0;
  while(i < H.length - 1) {
    if(H[i+1]<=H[i]) {
      num++;
    } else {
      maxNum = max(maxNum, num);
      num = 0;
    }
    i++;
  }

  maxNum.writeln;
}

Measured memory_bytes: 4476
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main{
	public static void main(String[] args) throws IOException {

		BufferedReader input = new BufferedReader(new InputStreamReader(System.in));


		        	     //???????????\??????????????¨
		        	   String strings = input.readLine();

		        	   //?????????????????????????´????
			           String strings_words = strings;

			           //String??????strings_words???toCharArray()??§char????????????
			           char[] c=strings_words.toCharArray();

			           //
			           for(char cl: c){

			        	   //cl???String??????????????¨
			        	   String str__conversion= String.valueOf(cl);

			        	   String output="";

			        	   //cl?????????????????§??????????¢????
			        	   if(Character.isUpperCase(cl)){

			        		   //?°??????????
			        		   output=  str__conversion.toLowerCase();

			        		   //?°?????????????
			        	   }else{

			        		    output= str__conversion.toUpperCase();

			        	   }

			        	   System.out.print(output);

			           }
  System.out.println("");


	}

}

Measured memory_bytes: 25196
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll store[110][100010];
ll n,Wei;
ll v[100010],w[100010];
ll dp(ll i,ll cap)
{
    if(i==n+1) return 0;
    if(store[i][cap]!=-1) return store[i][cap];
    ll profit1=0,profit2=0;
    if(cap+w[i]<=Wei)
    {
        profit1=v[i]+dp(i+1,cap+w[i]);
    }
    else
    {
        profit1=0;
    }
    profit2=dp(i+1,cap);
    return store[i][cap]=max(profit1,profit2);
}
int main()
{
    //freopen("take.in","r",stdin);
    cin>>n>>Wei;
    for(ll i=1;i<=n;i++)
    {
        cin>>w[i]>>v[i];
    }
    memset(store,-1,sizeof store);
    ll ans=dp(1,0);
    cout<<ans<<endl;
}

Measured memory_bytes: 86272
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stdio.h>
#include <string>
#include <vector>

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const double PI = 3.1415926535897932;

/* a と b の最大公約数を返す関数 */
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

int main()
{
	int N;
	cin >> N;
	
	vector<vector<int> > xy(N, vector<int>(2, 0));
	rep(i, N) cin >> xy[i][0] >> xy[i][1];

	vector<int> vec(N);
	vector<vector<int> > pt;
	iota(vec.begin(), vec.end(), 0);

	do {
		pt.push_back(vec);
	} while (next_permutation(vec.begin(), vec.end()));

	double total_dist = 0;
	int dist_cnt = 0;
	for (auto v : pt)
	{
		for (int i = 0; i < (N - 1); ++i)
		{
			int crt = v[i];
			int nxt = v[i + 1];
			total_dist += sqrt((xy[nxt][0] - xy[crt][0]) * (xy[nxt][0] - xy[crt][0]) +
								(xy[nxt][1] - xy[crt][1]) * (xy[nxt][1] - xy[crt][1]));
		}
		dist_cnt += 1;
	}

	printf("%.7f", total_dist / (double)dist_cnt);
	return 0;
}

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

int main(){
  ll n, ans;
  cin >> n;
  vector<ll> a(n);
  for(ll i = 0; i < n; i++) cin >> a[i];
  sort(a.begin(), a.end());
  for(ll i = 0; i < n; i++){
    ll k = i;
    for(ll j = i + 1; j < n; j++){
      while(k + 1 < n && a[i] + a[j] > a[k + 1]) k++;
      ans += k - j;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
N=int(input())
A=list(map(int,input().split()))
bittable=[0]*60
x=0
p=10**9+7
for i in range(N):
    x=A[i]
    for j in range(60):
        if (x>>j)&1:
            bittable[j]=bittable[j]+1
#print(bittable)
ans=0
for i in range(60):
    if bittable[i]!=0:
        ans=(ans+((N-bittable[i])*bittable[i]*pow(2,i,p))%p)%p
print(ans)


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

int main() {
    int H, W;
    cin >> H >> W;
    int C[10][10];
    rep(i, 10) {
        rep(j, 10) cin >> C[i][j];
    }

    rep(k, 10) {
        rep(i, 10) {
            rep(j, 10) C[i][j] = min(C[i][j], C[i][k] + C[k][j]);
        }
    }


    int ans = 0, ai;

    rep(i, H) {
        rep(j, W) {
            cin >> ai;
            if ((ai == -1) || (ai == 1)) continue;
            else ans += C[ai][1];
        }
    }

    cout << ans << endl;  

    return 0;
}



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

constexpr double EPS = 1e-15;

double calc(long long x){
  double ret = x;
  long long y = 0;
  while(x > 0){
    y += x%10;
    x /= 10;
  }
  ret /= y;
  return ret;
}

int main(){
  long long K;
  cin >> K;
  long long b = 1, s = 0;
  vector<pair<long long, double>> S;
  for(int i = 0; i <= 15; ++i){
    for(int j = 1; j < 10; ++j){
      if(j < i){
        for(int k = 0; k < 9; ++k){
          long long t = j*b + b/10*k + s/10;
          //cout << t << endl;
          //S.insert(t);
          S.emplace_back(t,calc(t));
        }
      }
      long long t = j*b + s;
      //cout << t << endl;
      //S.insert(t);
      S.emplace_back(t,calc(t));
    }
    for(int j = 10; j < i; ++j){
      for(int k = 0; k < 9; ++k){
        long long t = j*b + b/10*k + s/10;
        //S.insert(t);
        S.emplace_back(t,calc(t));
      }
    }
    b *= 10;
    s *= 10;
    s += 9;
    //if(S.size() >= K) break;
  }
  sort(S.begin(), S.end());
  double m = 1e18;
  vector<long long> A;

  for(size_t i = S.size() - 1; i+1 > 0; --i){
    if(m + EPS < S[i].second) continue;
    m = S[i].second;
    A.push_back(S[i].first);
  }

  assert(A.size() > (size_t)K);
  reverse(A.begin(), A.end());
  // for(auto a: A)
  //   cerr << a << endl;
  for(int i = 0; i < K; ++i)
    cout << A[i] << endl;

  // for(auto x : S){
  //   cout << x << endl;
  //   --K;
  //   assert(x <= (1e15));
  //   if(!K) break;
  // }
  return 0;
}


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

// #define int ll
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using si = set<int>;
using ii = pair<int, int>;
using vii = vector<ii>;

#define rep(i, n) for (int i = 0; i < n; i++)
#define dotc()    int tcs; if (cin >> tcs) rep(tc, tcs)
#define sz(x)     (int)x.size()
#define eb        emplace_back
#define pb        push_back
#define mp        make_pair
#define all(x)    x.begin(), x.end()
#define rall(x)   x.rbegin(), x.rend()
#define fi        first
#define se        second

int inf(0x3fffffff);
int mod(998244353);
double pi(acos(-1.0));

ll iv(ll a, ll b) {
  return a > 1 ? b - iv(b % a, a) * b / a : 1;
}

ll modExp(ll b, ll e) {
  ll r = 1;
  while (e) {
    if (e & 1) r = r * b % mod;
    b = b * b % mod;
    e /= 2;
  }
  return r;
}

vector<ll> dpc;

ll C(int n, int r) {
  if (dpc.empty()) {
    dpc.pb(1);
    for (int i = 1; i <= n; i++) {
      dpc.pb(dpc[i - 1] * (n - i + 1) % mod * iv(i, mod) % mod);
    }
  }
  return dpc[r];
}

int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
#ifdef LOCAL
  freopen("io\\in.txt", "r", stdin);
  freopen("io\\out.txt", "w", stdout);
#endif

  int n, m, k;
  cin >> n >> m >> k;

  ll cnt = 0;
  rep(i, k + 1) {
    cnt = (cnt + m * modExp(m - 1, n - i - 1) % mod *
           C(n - 1, i)) % mod;
  }

  cout << cnt;


  return 0;
}


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

int main(){
    long long a,b,k;
    cin >> a >> b >> k;

    if(a>=k){
        cout << a-k << " " << b << endl;
    }
    else if(k>a && a+b>k){
        cout << 0 << " " << b-(k-a) << endl;
    }
    else{
        cout << 0 << " " << 0 << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std ; 
#define pb push_back
#define f first 
#define s second
vector<int> adj[400005] , adj1[400005] ; 
int vis[400005] , dp[400005] , ind = 0 ; 
set<int> st[400005]  , st1[400005] , st2[400005] ; 
void dfs( int x ) 
{
	vis[x] = 1 ;
	st[ind].insert(x) ; 
	for( int i = 0 ; i < adj[x].size() ; i++ ) 
	{
		if( !vis[ adj[x][i] ] )
			dfs( adj[x][i] ) ; 
	}
}
signed main()
{
    ios_base::sync_with_stdio( false ) ; 
    cin.tie(0) ;
    cout.tie(0) ; 
    int n , m , k ; 
    cin >> n >> m >> k ; 
    for( int i = 0 ; i < m ; i++ )
    {
    	int x , y ; 
    	cin >> x >> y ; 
    	adj[x].pb(y) ; 
    	adj[y].pb(x) ; 
    	st1[x].insert(y) ; 
    	st1[y].insert(x) ; 
    }
    for( int i = 0 ; i < k ; i++ ) 
    {
    	int x , y ; 
    	cin >> x >> y ; 
    	adj1[x].pb(y) ; 
    	adj1[y].pb(x) ; 
    	st2[x].insert(y) ; 
    	st2[y].insert(x) ; 
    }
    for( int i = 1 ; i <= n ; i++ ) 
    {
    	if( !vis[i] ) 
    		dfs(i) , ind++ ; 
    }
    ///cout << ind << '\n' ; 
    auto it = st[0].begin() ; 
    int cnt[n+5] = {0} ; 
    for( int i = 0 ; i < ind ; i++ ) 
    {
    	for( it = st[i].begin() ; it != st[i].end() ; it++ ) 
    	{
    		dp[*it] = st[i].size() - adj[*it].size() - 1 ; 
    		auto it1 = st2[*it].begin() ; 
    		for( ; it1 != st2[*it].end() ; it1++ ) 
    		{
    			if( st[i].find( *it1 ) != st[i].end() ) 
    				dp[*it]-- ; 
    		}
    	}
    }
    for( int i = 1 ; i <= n ; i++ ) 
    	cout << dp[i] << ' ' ; 
    cerr << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
}

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}
struct edge {
  ll to, cost;
};

int main() {
  ll N, M, K; cin >> N >> M >> K;
  vector<ll> A(N), B(M); REP(i, N) cin >> A[i];
  REP(i, M) cin >> B[i];
  ll sum = 0;
  ll ans = 0;
  vector<ll> C(M + 1), D(N + 1); C[0] = 0; D[0] = 0;
  for(int i = 1; i < N + 1; ++i) D[i] = D[i - 1] + A[i - 1];
  for(int i = 1; i < M + 1; ++i) C[i] = C[i - 1] + B[i - 1];
  for(int i = 0; i <= N; ++i) {
    sum = D[i];
    if(sum > K) break;
    ll target = K - sum;
    ll ng = -1;
    ll ok = M;
    while(abs(ok - ng) > 1) {
      ll mid = (ok + ng) / 2;
      if(C[mid] >= target) {
        ok = mid;
      } else {
        ng = mid;
      }
    }
    ll tmp;
    //cout << ok << " " << i << endl;
    if(C[ok] > target) tmp = (ok - 1) + i;
    else tmp = ok + i;
    if(tmp > ans) ans = tmp;
  }
  cout << ans << endl;
}

Measured memory_bytes: 9544
import java.io.PrintWriter

val br = System.`in`.bufferedReader()
val out = PrintWriter(System.out)

fun main() {
    br.use { out.use {
        solve()
        out.flush()
    } }
}

fun solve() {
    val d = readInteger()
    val cList = readLongList()
    val satisfyTable = Array(d) { readLongList() }

    fun score(tmp: IntArray): Long {
//        out.println(tmp.joinToString(" "))
        var s = 0L

        val last = IntArray(26)
        for ((i, t) in tmp.withIndex()) {
            s += satisfyTable[i][t]

//            out.println("$i ${t  - 1}")
//            out.println(satisfyTable[i][t - 1])
            last[t] = i + 1
//            println(last.joinToString(" "))

            var tmp = 0L
            for (j in 0 until 26) {
                tmp += cList[j] * (i + 1 - last[j])
            }
            s -= tmp

            out.println(s)
        }

        return s
    }

//    var maxScore = 0L
//    var maxList = IntArray(0)
//    repeat (50000) {
//        val tmp = IntArray(d)
//        for (i in 0 until d) {
//            tmp[i] = Random.nextInt(26)
//        }
//        val score = score(tmp)
//
//        if (score > maxScore) {
//            maxList = tmp
//            maxScore = score
//        }
//    }

//    out.println(maxScore)
//    out.println(maxList.map {it + 1}.joinToString("\n"))

    val tlist = IntArray(d) { readInteger() - 1 }
    score(tlist)
}

fun readInteger() = Integer.parseInt(br.readLine())
fun readLong() = java.lang.Long.parseLong(br.readLine())
fun readStringList() = br.readLine()!!.split(' ')
fun readIntegerList() = readStringList().map(Integer::parseInt)
fun readLongList() = readStringList().map(java.lang.Long::parseLong)
fun readDoubleList() = readStringList().map(java.lang.Double::parseDouble)


Measured memory_bytes: 38212
#include<stdio.h>
#include<math.h>
#define TRUE 1
#define FALSE 0
#define POWER_NUM 2
int func_cal(int a, int b, int c);
void func_output(int r);
int func_cal(int a, int b, int c)
{
	int num_a = 0, num_b = 0, num_c = 0;
	num_a = pow(a, POWER_NUM);
	num_b = pow(b, POWER_NUM);
	num_c = pow(c, POWER_NUM);
	
	if((num_a + num_b) == num_c)
	{
		return TRUE;
	}
	else if((num_a + num_c) == num_b)
	{
		return TRUE;
	}
	else if((num_c + num_b) == num_a)
	{
		return TRUE;
	}
	else
	{
		return FALSE;
	}
}
void func_output(int r)
{
	if(r == 1)
	{
		puts("YES");
	}
	else
	{
		puts("NO");
	}
}
main()
{
	int a = 0, b = 0, c = 0, n = 0, i = 0, result = 0;
	scanf("%d", &n);
	while(i < n)
	{
		scanf("%d %d %d", &a, &b, &c);
		result = func_cal(a, b, c);
		func_output(result);
		i++;
	}
	return 0;
}

Measured memory_bytes: 580
#include <iostream>
#include <queue>
using namespace std;
long long calcString(string s){
    queue<char> q;
    long long sum = 0;
    for(int i = 0; i < s.size(); ++i){
        q.push(s[i]);
    }
    long long tmp = 0;
    while(!q.empty()){
        if(q.front() != '+'){
            int x = q.front()-'0'; q.pop();
            tmp *= 10;
            tmp += x;
        }
        else{
            q.pop();
            sum += tmp;
            tmp = 0;
        }
    }
    sum += tmp;
    return sum;
}
long long calcNum(string s){
    long long ans = 0;
    for(int i = 0; i < 1<<(s.size()-1); ++i){
        string tmp = "";
        for(int j = 0; j < s.size()-1; ++j){
            tmp += s[j];
            if((i>>j)&1) tmp += '+';
        }
        tmp += s[s.size()-1];
        ans += calcString(tmp);
    }
    return ans;
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s; cin >> s;
    cout << calcNum(s) << endl;
    return 0;
}

Measured memory_bytes: 3596
#include <iostream>
#include <vector>
#include <set>
#include <queue>
using namespace std;

#define INF 999999999

typedef pair<int,int> P;

int n;
int c[10][10];
int p[10];

int myswap(int x, int i, int j){
  int a = (x / p[i]) % 10;
  int b = (x / p[j]) % 10;
  return x - a * p[i] - b * p[j] + b * p[i] + a * p[j];
}

void solve(){
  int y = 1234;
  int s = 0;
  for(int i = 0; i < n; i++){
    s *= 10;
    s += i;
  }

  int ans = 0;
  set<int> closed;
  priority_queue<P, vector<P>, greater<P> > open;

  open.push(P(0, s));

  while(!open.empty()){
    P p = open.top(); open.pop();
    if(closed.find(p.second) != closed.end()) continue;
    closed.insert(p.second);

    ans = max(ans, p.first);

    for(int i = 0; i < n; i++){
      for(int j = i + 1; j < n; j++){
        open.push(P(p.first + c[i][j], myswap(p.second, i, j)));
      }
    }
  }

  cout << ans << endl;
}

int main(){
  p[0] = 1;
  for(int i = 1; i < 8; i++){
    p[i] = p[i - 1] * 10;
  }

  while(cin >> n){
    for(int i = 0; i < n; i++){
      for(int j = 0; j < n; j++){
        cin >> c[i][j];
      }
    }

    solve();
  }
}

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

int main(){
	int N,d[100];
	cin>>N;
  	for(int i=0;i<N;++i)cin>>d[i];
  	sort(d,d+N);
  	int eq=d[0];int count=1;
  	for(int i=1;i<N;++i){
    	if(eq!=d[i]){eq=d[i];++count;}
    }cout<<count<<endl;
  	return 0;
}

Measured memory_bytes: 256
#include <iostream>

#define MAX_N 52
#define MOD   1000000007

int  N;
char S[2][MAX_N];

long solve() {
    bool prev = (S[0][0] == S[1][0]) ? true:false;
    int idx = (prev) ? 1:2;
    long res = (prev) ? 3:6;
    while (idx < N) {
        bool curr = (S[0][idx] == S[1][idx]) ? true:false;
        if (prev && curr) {
            res *= 2;
            res %= MOD;
            ++idx;
        } else if (prev && !curr) {
            res *= 2;
            res %= MOD;
            idx += 2;
        } else if (!prev && curr) {
            ++idx;
        } else {
            res *= 3;
            res %= MOD;
            idx += 2;
        }
        prev = curr;
    }
    return res;
}

int main() {
    std::cin >> N;
    for (int i=0; i<2; ++i) {
        for (int j=0; j<N; ++j) std::cin >> S[i][j];
    }
    std::cout << solve() << std::endl;
    return 0;
}

Measured memory_bytes: 256