akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdbool.h>
#define N 8
#define FREE -1
#define NOTFREE 1

int row[N],col[N],dpos[2*N-1],dneg[2*N-1];
void initialize(void);
int printBoard(void);
int recursive(int);

bool X[N][N];

int main(){
  int i,j,k,r,c;
 
  initialize();

  for(i = 0; i < N; i++)
    for(j = 0; j < N; j++)
      X[i][j] = false;

  scanf("%d",&k);
  for(i = 0; i < k; i++){
    scanf("%d%d",&r,&c);
    X[r][c] = true;
  }

  recursive(0);

  return 0;
  
}

void initialize(){
  int i;
  for(i = 0; i < N; i++){
    row[i] = FREE;
    col[i] = FREE;
  }

  for(i = 0; i < 2*N-1; i++){
    dpos[i] = FREE;
    dneg[i] = FREE;
  }
}

int printBoard(){
  int i,j;

  for(i = 0; i < N; i++){
    for(j = 0; j < N; j++){
      if(X[i][j]){
	if(row[i] != j) return 0;
      }
    }
  }
  for(i = 0; i < N; i++){
    for(j = 0; j < N; j++){
      if(row[i] == j) printf("Q");
      else printf(".");
    }
    printf("\n");
  }
}

int recursive(int i){
  int j;
  if(i == N){
    printBoard();
    return 0;
  }
  for(j = 0; j < N; j++){

    if(NOTFREE == col[j] || NOTFREE == dpos[i+j] || NOTFREE == dneg[i-j+N-1]) continue;
    row[i] = j;
    col[j] = dpos[i+j] = dneg[i-j+N-1] = NOTFREE;

    recursive(i+1);

    row[i] = col[j] = dpos[i+j] = dneg[i-j+N-1] = FREE;
  }
}

Measured memory_bytes: 572
# -*- coding: utf-8 -*-

def main():
    N ,K  =  [int(i) for i in input().split()]
    As =   [int(i) for i in input().split()]

    rireki = []
    loop = ""

    ind = 1
    flags = [0 for _ in range(N)]
    while(1):
        if flags[ind-1] == 1:
            loop = ind
            break
        else:
            rireki.append(ind)
            flags[ind-1] = 1
            ind = As[ind-1]

        #print(flags)
    #print(rireki,loop)
    loop_c = len(rireki) - rireki.index(loop)
    if K <= len(rireki)-1:
        print(rireki[K])
    else:
        nokori = K-len(rireki)+1
        ans = nokori % loop_c
        if ans == 0:
            print(rireki[-1])
        else:
            print(rireki[rireki.index(loop)+ans-1])

if __name__ == "__main__":
    main()


Measured memory_bytes: 106776
x=int(input())
fifth_power=[0]*200
for i in range(200):
    fifth_power[i]=(i+1)**5
for i in range(200):
    t=abs(x-fifth_power[i])
    if x==1:
        print(0,-1)
        break
    elif fifth_power.count(t)==1:
        if fifth_power[i]-t==x:
            print(i+1,fifth_power.index(t)+1)
            break
        else:
            print(i+1,-fifth_power.index(t)-1)
            break

Measured memory_bytes: 9152
n = gets.chomp.to_i
ary = gets.split(" ").map(&:to_i).sort.reverse.group_by(&:itself).map{ |key, value| [key, value.size] }

h = 0
w = 0

ary.size.times do |i|
  if h == 0 && ary[i][1] >= 4 
    puts ary[i][0] ** 2
    exit
  end

  if h == 0 && ary[i][1] >= 2
    h = ary[i][0]
  elsif w == 0 && ary[i][1] >= 2
    w = ary[i][0]
  end

  if h != 0 && w != 0
    puts h * w
    exit
  end
end

puts 0

Measured memory_bytes: 27624
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
    
		// 整数の入力
		int n = sc.nextInt();
        String[] sList = ("" + n).split("");
        int sum = 0;
        for(int i = 0; i < sList.length; i++) {
          sum += Integer.parseInt(sList[i]);
        }
    
		// 出力
		System.out.println(n % sum == 0 ? "Yes" : "No");
	}
}

Measured memory_bytes: 21716
//
// Created by yamunaku on 2019/11/05.
//

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repl(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perl(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD9 998244353
#define MOD1 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)
#define CST(x) cout<<fixed<<setprecision(x)

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> mti;
typedef vector<ll> vl;
typedef vector<vector<ll>> mtl;

int main(){
    int n;
    cin >> n;
    repl(i,1,10){
        repl(j,1,10){
            if(i*j==n){
                CYES;
                return 0;
            }
        }
    }
    CNO;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  char c; cin>>c;
  string s = "abcdefghijklmnopqrstuwxyz";
  for(int i = 0 ; i < 24; i++)
    if(s[i]==c)
      cout<<s[i+1]<<endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        String s = scanner.next();
        String t = scanner.next();
        int a = scanner.nextInt();
        int b = scanner.nextInt();
        String u = scanner.next();

        if (u.equals(s)){
            a -= 1;
        }else if (u.equals(t)){
            b -= 1;
        }

        System.out.println(a + " " + b);
    }

}

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

using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pf push_front
#define iter(v, i) for (__typeof__((v).begin()) i = (v).begin(); i != (v).end(); i++)
#define fast_io_without_cstdio ios_base::sync_with_stdio(false), cin.tie(NULL)
#define all(v) (v).begin(), (v).end()

#ifdef __linux__
#define gc getchar_unlocked
#define pc putchar_unlocked
#else
#define gc getchar
#define pc putchar
#endif

#if __cplusplus <= 199711L
template<class BidirIt>
BidirIt prev(BidirIt it, typename iterator_traits<BidirIt>::difference_type n = 1) {
    advance(it, -n);
    return it;
}

template<class ForwardIt>
ForwardIt next(ForwardIt it, typename iterator_traits<ForwardIt>::difference_type n = 1) {
    advance(it, n);
    return it;
}
#endif

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

const double EPS = 1e-9;
const double PI = 3.141592653589793238462;

template<typename T>
inline T sq(T a) { return a * a; }

const int MAXN = 1e5 + 5;

ll dp[MAXN];
int x[MAXN];

int main() {
    //freopen("", "rt", stdin);
    //freopen("", "wt", stdout);
    int n, a, b;
    scanf("%d %d %d", &n, &a, &b);
    for (int i = 1; i <= n; i++)
        scanf("%d", &x[i]);
    dp[1] = 0;
    for (int i = 2; i <= n; i++)
        dp[i] = dp[i-1] + min(a * 1LL * (x[i] - x[i-1]), ( ll )b);
    printf("%lld\n", dp[n]);
    return 0;
}



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


using namespace std;

/* macros */
#define all(v)			((v).begin()), ((v).end())
#define SIZE(v)			((int)((v).size()))
#define LOG(x)			log((double)x)
#define TOLOWER(x)          transform(all(x),x.begin(),::tolower)
#define TOUPPER(x)          transform(all(x),x.begin(),::toupper)
#define ROUND(x,m)			(round((double)x/m)*m)
#define DIGITS(x)			(floor(log10((double)x))+1)
#define READSTR(x)			getline(cin,x)
#define sort_g(a,b)              sort(a, b, greater<int>());
#define IOS() ios_base::sync_with_stdio(0);cin.tie(NULL);
#define REP(i, n) for (int i = 0; i < n; i++)
#define FILE_INPUT() 	freopen( "input.txt", "r", stdin)
#define FILE_OUTPUT()   freopen( "output.txt", "w", stdout)

/*typedefs*/
typedef long long ll;

/*functions*/
bool myCmp(pair<int,int> &p1 , pair<int,int>&p2)
{
    return p1.first > p2.first;
}
unsigned long long
choose(unsigned long long n, unsigned long long k) {
    if (k > n) {
        return 0;
    }
    unsigned long long r = 1;
    for (unsigned long long d = 1; d <= k; ++d) {
        r *= n--;
        r /= d;
    }
    return r;
}
int toInt(string str) {
    int num;
    istringstream iss(str); //put string in input stream
    iss>>num; return num; //read from stream as integer
}

template <class T> string toStr(T par) {
    ostringstream oss;  //output stream string
    oss<<par;    //write par to the stream
    return oss.str(); //return string of output
}



int main() {
    IOS();
    set<int> s;
    int A,B,C;
    cin>>A>>B>>C;
    s.insert(A),s.insert(B),s.insert(C);
    if(s.size() == 2)
    {
        cout<<"Yes";
    }
    else
    {
        cout<<"No";
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <math.h>
#include <stdlib.h>
#include <algorithm>

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

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_MAX	2,147,483,647 = 2*1.0e9

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

  int sum = 0;
  vector<int> L(N);
  rep(i, N){
    cin >> L[i];
    sum += L[i];
  }

  sort(L.rbegin(), L.rend());
  sum -= 2 * L[0];
  if(sum > 0) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}



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

#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define repr(i,n) for(int i=(n);i>=0;--i)
#define step(i,s,n,c) for(int i=(s);i<(n);i+=(c))
#define REP(i,s,n) for(int i=(s);i<(n);++i)
#define each(i,vec) for(auto i:vec)
#define cinv(n,vec) VL vec(n);for(auto&v:vec)cin>>v;
#define int long long
#define itn int
#define pb push_back
#define eb emplace_back
#define m_p make_pair
#define m_t make_tuple
#define p_p(a,b) pb(m_p(a,b))
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(all(a),greater<>())
#define UNIQUE(a) a.erase(unique(all(a)),a.end())
#define SZ(a) (signed)(a.size())
#define debg(a) cout<<#a<<" "<<a<<endl;
#define debgp(a) cout<<#a<<" "<<a.fi<<" : "<<a.se<<endl
#define call(a) for(auto i:a)cout<<i<<" ";cout<<endl
#define callp(a) for(auto [k,v]:a)cout<<k<<":"<<v<<endl
#define show(a) for(cont &y:a){for(cont &x:y){cout<<x<<" ";}cout<<endl;}
#define out(a) cout<<(a)<<endl
#define ENDL cout<<endl
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define fi first
#define se second
#define V vector
#define P pair
#define T tuple
#define PQ priority_queue
#define cont const auto
#define VV(type,name,y,x,a) vector<vector<type>> name = vector<vector<type>>(y,vector<type>(x,a))
typedef long long ll;
typedef double D;
typedef long double LD;
typedef string str;
typedef vector<ll> VL;
typedef pair<ll,ll> PL;
typedef vector<pair<ll,ll>> VP;
typedef tuple<ll,ll,ll> T3;
typedef tuple<ll,ll,ll,ll> T4;
const signed INF = (1LL<<30);
const long long MOD = (1e9+7);
const long long LINF = (1LL<<60);
const long long LMAX = LLONG_MAX;
void YN(bool b){cout<<(b?"Yes":"No")<<endl;}
template<class T>inline T gcd(T a,T b){if(b==0)return a; return(gcd(b,a%b));}
template<class T>inline T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T>inline bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(10);
  
  str s;
  cin>>s;
  int ans=0,l=0,r=SZ(s)-1;
  while(r-l>=1){
    //debg(s[l]);debg(s[r]);
    if(s[l]==s[r])r--,l++;
    else if(s[l]=='x')l++,ans++;
    else if(s[r]=='x')r--,ans++;
    else {ans=-1;break;}
  }
  out(ans);


  return 0;
}


Measured memory_bytes: 512
# include <bits/stdc++.h>
# define rep(i, n) for(ll i = 0; i < (n); ++i)
# define reps(i, n) for(ll i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(ll i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(ll i=((int)(n)); i>0; --i)
# define ll long long
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
# define P pair<int, int>
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll lmax(ll a, ll b){if(a>= b) return a;return b;}
ll lmin(ll a, ll b){if(a>= b) return b;return a;}


int main() {
  int n; cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];

  sort(ALL(a));
  bool flag = true;
  rep(i, n-1){
    if(a[i] == a[i+1]) flag = false;
  }

  if(flag) cout << "YES" << endl;
  else cout << "NO" << endl;
}


Measured memory_bytes: 4720
#include<iostream>

#define int long long
using namespace std;

int a, b, c;
int ans;

signed main()
{
	cin >> a >> b >> c;
	if (a + b + 1 >= c) {
		ans = b + c;
	}
	else {
		ans = a + b + 1 + b;
	}
	cout << ans << endl;


    return 0;
}



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

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

int main(){
    int n;
    cin >> n;
    vector<int> l(n);

    rep(i,n){
        cin >> l[i];
    }

    sort(l.begin(),l.end());
    
    int count=0;
    rep(i,n){
        for(int j = i+1;j<n;j++){
            for(int k = j+1;k<n;k++){
                if(l[i] + l[j] <= l[k])break;
                count++;
            }
        }
    }

    cout << count;

    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
// Custom Header <<<
#define ALL(x) x.begin(), x.end()
#define rep(i, s, n)      for(int i(s); i < int(n); ++i)
#define endl '\n'
#ifndef YDK
#define eprintf(...)
#endif
using namespace std;
using i64 = long long;
using pii = pair<int, int>;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD  = int(1e9) + 7;
// >>>

struct FastIO {
    FastIO() { cin.tie(nullptr); ios::sync_with_stdio(false); }
} fastIO_ydk ;

signed main()
{
    int N;

    cin >> N;
    vector<int> p, n;

    rep(i, 0, N) {
        int a; cin >> a;
        if (a > 0) {
            p.push_back(a);
        } else {
            n.push_back(a);
        }
    }

    sort(ALL(p));
    sort(ALL(n), greater<>());

    int ans;
    vector<pii> log;

    if (p.empty()) {
        int tmp = n.front();
        rep(i, 1, N) {
            log.emplace_back(tmp, n[i]);
            tmp = tmp - n[i];
        }
        ans = tmp;
    } else if (n.empty()) {
        int tmp = p.front();
        rep(i, 1, N-1) {
            log.emplace_back(tmp, p[i]);
            tmp = tmp - p[i];
        }
        log.emplace_back(p.back(), tmp);
        tmp = p.back() - tmp;
        ans = tmp;
    } else {
        while(p.size() + n.size() > 1) {
            int plus = p.back();
            int minus = n.back();
            p.pop_back();
            n.pop_back();
            if (p.size() == 0) {
                log.emplace_back(plus, minus);
                p.push_back(plus - minus);
            } else {
                log.emplace_back(minus, plus);
                n.push_back(minus - plus);
            }
        }
        ans = p.front();
    }

    cout << (ans) << endl;
    for (const auto &e : log) {
        cout << e.first << ' ' << e.second << endl;
    }

    return 0;
}

/* vim:set foldmethod=marker foldmarker=<<<,>>> : */


Measured memory_bytes: 3444
import bisect
n = int(input())
l = sorted(list(map(int,input().split())))
cnt = 0

for i in range(n):
  for j in range(1+i,n):
    a,b = l[i],l[j]
    cnt += bisect.bisect_left(l,a+b)-(j+1)
    
print(cnt)

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

int main(){
    int M,D;
    cin >> M >> D;
    int ans = 0;
    for(int month = 1; month <= M; month++){
        for(int day = 1; day <= D; day++){
            if(day%10 >= 2 && day/10 >= 2 && (day%10)*(day/10) == month) ans++; 
        }
    }
    
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 256
import sys
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()
from collections import deque
def resolve():
    k = int(input())
    dist = [INF] * k
    dist[1] = 1
    queue = deque([1])

    while queue:
        v = queue.pop()
        if dist[10 * v % k] > dist[v]:
            dist[10 * v % k] = dist[v]
            queue.appendleft(10 * v % k)
        if dist[(v + 1) % k] > dist[v] + 1:
            dist[(v + 1) % k] = dist[v] + 1
            queue.append((v + 1) % k)

    print(dist[0])
resolve()

Measured memory_bytes: 79416
#include<iostream>
#include<vector>
#include<map>
#include<string>
using namespace std;

void a(){
    string arc = "ARC";
    string abc = "ABC";
    string s;
    cin >> s;
    if(s.compare(arc)){
        cout<<arc;
    }else{
        cout<<abc;
    }
    return;
}

void b(){
    int n,k;
    cin >> n >> k;
    vector<int>vec(n,0);
    for(int i=0;i<k;i++)
    {
        int d;
        cin >>d;
        for(int j=0;j<d;j++)
        {
            int a;
            cin >>a;
            vec[a-1]++;
        }
    }
    int count = 0;
    for(int i=0;i<n;i++)
    {
        if(vec[i]==0)count++;
    }
    cout<<count;
    return;
}

void c(){
   int n,m;
   cin>>n>>m;
   vector<int>h;
   for(int i=0;i<n;i++)
   {
       int t;
       cin >> t;
       h.push_back(t);
   }
   vector<int>f(n,0);
   for(int j=0;j<m;j++)
   {
       int a,b;
       cin >> a>>b;
       if(h[a-1]>h[b-1])
       {
           f[b-1]=1;
       }
       else if(h[a-1]<h[b-1])
       {
           f[a-1]=1;
       }
       else
       {
           f[a-1]=1;
           f[b-1]=1;
       }
   }
   int count=0;
   for(int i=0;i<n;i++)
   {
       if(f[i]==0)count++;
   }
   cout<<count;
   return;
}

void d(){
    
}
int main(void){
    //a();
    //b();
    c();

}

Measured memory_bytes: 4056
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <cassert>
#include <exception>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int,int> P;
#define rep(i,a,n) for(ll i = (a);i < (n);i++)
#define per(i,a,n) for(ll i = (a);i > (n);i--)
#define lep(i,a,n) for(ll i = (a);i <= (n);i++)
#define pel(i,a,n) for(ll i = (a);i >= (n);i--)
#define clr(a,b) memset((a),(b),sizeof(a))
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define sz size()
#define print(X) cout << (X) << endl
const ll INF = 1e+9+7;
ll n,m,l;
string s,t;
ll d[100000],dp[100][100];

int gcd(int x,int y){
  if(y == 0)return x;
  return gcd(y,x % y);
}

int main(){
  cin >> n;
  s = "Yes";
  int o = 0,p = 0,q = 0;
  rep(i,0,n){
    int a,b,c;
    int x = 0;
    cin >> a >> b >> c;
    if(abs(o-a) < abs(p-b)+abs(q-c))s = "No";
    if((abs(o-a) != abs(p-b)+abs(q-c))){
      if(abs(o-a) % 2 != (abs(p-b)+abs(q-c)) % 2)s = "No";
    }
    o = a;p = b;q = c;
    // print(s);
  }
  print(s);
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
using namespace std;
int n,a[100010],t,ans;
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
	}
	t=1;
	for (int i=2;i<=n;i++)
	 if (a[i]==a[i-1]){
	 	t++;
	 }
	 else
	 {
	 	if (t>=2) ans+=t/2;
	 	t=1;
	 }
	 if (t>=2) ans+=t/2;
	 printf("%d",ans);
 } 

Measured memory_bytes: 128
#include <bits/stdc++.h> 
#define int long long
using namespace std;
const int N = 2555,M = 5555;


int32_t main(){
	cin.tie(0)->sync_with_stdio(0);
	#ifdef LOCAL
	freopen("input.txt", "r", stdin);
	#endif
	int x,k,d;
	cin>>x>>k>>d;
	int v = abs(x);
	int lol = v/d;
	lol = min(lol,k);
	if(x>0)
	{
		x-=lol*d;
	}
	else{
		x+=lol*d;
	}
	k-=lol;
	// cout<<x<<"\n";
	// cout<<k<<"\n";
	if(k&1)
	{
		// cout<<"*";
		if(x>0)
		{
			x-=d;
		}
		else x+=d;

	}
	cout<<abs(x)<<"\n";
}


Measured memory_bytes: 3644
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

using namespace std;
typedef long long int ll;
#define MAX_N 10000

int par[MAX_N];

void init(){
	rep(i,MAX_N){
		par[i] = i;
	}
}

int root(int i){
	if(par[i] == i) return i;
	par[i] = root(par[i]);
	return par[i];
}

bool isSame(int i,int j){
	i = root(par[i]);
	j = root(par[j]);
	return i == j;
}

void unite(int i, int j){
	i = root(i);
	j = root(j);
	if(i == j) return;
	par[i] = j;
}


int main()
{
	init();
	int n,q;
	cin>>n>>q;
	rep(i,q){
		int command,x,y;
		cin>>command>>x>>y;
		if(command == 0){
			unite(x,y);
		}else{
			cout<<isSame(x,y)<<endl;
		}
		/*rep(i,n){
			cout<<par[i]<<" ";
		}
		cout<<endl;*/
	}
	
	return 0;
}



Measured memory_bytes: 3224
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;
import java.util.Arrays;
import java.util.Random;
public class Main 
{
    public static void main(String[] args) 
    {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(2, in, out);
        out.close();
    }

    static class TaskC 
    {
        static boolean prime(int n)
        {
            for(int i=2;i<=Math.sqrt(n);i++)
            {
                if(n%i==0)
                {
                    return false;
                }
            }
            return true;
        }

        static void reverse(long[] a,long start,long end)
        {
            long temp = 0;
            while(start<end)
            {
                temp = a[(int)start];
                a[(int)start] = a[(int)end];
                a[(int)end] = temp;
                start++;
                end--;
            }
        }


   
        
        public void solve(int testNumber, Scanner in, PrintWriter out) 
        {
            long t = in.nextLong();
            long a = in.nextLong();
            long b = in.nextLong();
            if(t==a && a==b)
            {
                System.out.println("Yes");
            }
            else{
                System.out.println("No");
            }
        }


      
        
        
        static long maxdiff(long[] arr,long size)
        {
            long max = arr[1]-arr[0];
            long min = arr[0];
            for(int i=1;i<(int)size;i++)
            {
                if(arr[i]-min>max)
                {
                    max = arr[i]-min;
                }
                if(arr[i]<min)
                {
                    min = arr[i];
                }

            }
            return max;
        }

                
    }

}

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

using namespace std;

int main(){
    long N;
    cin >> N;
    int ans =0;
    for(long i=2;i*i<N;i++){
      int crt=0;
      while(N%i==0){crt++;N/=i;}
      int j=1;
      while(crt>=j){crt-=j;ans++;j++;}
    }
    if(N!=1){
      ans++;
    }

    cout << ans << endl;
}


Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <numeric>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <bitset>
#include <queue>
#include <unordered_set>
#include <unordered_map>

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
#define rep(i, n) for(int i = 0;i < n;i++)
const int INF = 1LL << 30;

int MOD = 1000000007;

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

    int n; cin >> n;
    std::vector<int> d(n); rep(i,n) cin >> d[i];

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

    if(d[n/2]==d[n/2-1]){
        cout << 0 << endl;
    } else {
        cout << d[n/2]-d[n/2-1] << endl;
    }

    return 0;
}

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

int main() {
  int h, w;
  cin >> h >> w;

  vector<string> m(h + 2);
  for (int i = 1; i <= h; i++) cin >> m[i];

  for (int i = 1; i <= h; i++) m[i] = '.' + m[i] + '.';
  string d(w + 2, '.');
  m[h + 1] = d;
  m[0] = d;

  bool ans = true;
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      if (m[i][j] == '.') continue;
      if ((m[i + 1][j] == '#' && m[i][j + 1] == '#') ||
          (m[i - 1][j] == '#' && m[i][j - 1] == '#')) {
        ans = false;
        break;
      }
    }
  }
  if (ans) {
    cout << "Possible" << endl;
  } else {
    cout << "Impossible" << endl;
  }
}


Measured memory_bytes: 3604
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <tuple>
#include <cassert>
#include <memory>
using namespace std;
typedef long long ll;
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;

int main ()
{
    ll K; cin >> K;

    reversed_priority_queue<ll> que;
    for (ll i = 1LL; i <= 9LL; i++) {
        que.push(i);
    }

    ll cnt = 0;
    ll ans = -1;
    while (cnt < K) {
        ans = que.top();
        que.pop();
        ll d = ans % 10LL;
        if (d > 0) {
            que.push(ans * 10LL + (d - 1LL));
        }
        if (d < 9) {
            que.push(ans * 10LL + (d + 1LL));
        }
        que.push(ans * 10LL + d);
        cnt++;
    }

    cout << ans << endl;

    return 0;
}


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

int main() {
	string s;
	cin >> s;
	long long ans = 0;
	int n = s.size();
	bool isA = false;
	bool isAbefore = false;
	bool isD = false;
	bool isDbefore = false;
	long long anum = 0;
	long long dnum = 0;

	for (int i = 0; i < s.size() - 1; i++) {
		if (s[i] == 'B' && s[i + 1] == 'C') {
			s.erase(s.begin() + i, s.begin() + i + 2);
			s.insert(s.begin() + i, 'D');
		}
	}
	int N = s.size();
	for (int i = 0; i <= N; i++) {
		isAbefore = isA;
		isDbefore = isD;
		if (s[i] == 'A') isA = true; else isA = false;
		if (s[i] == 'D') isD = true; else isD = false;

		if (!isD && isDbefore) ans += anum * dnum;

		if (isA) {
			anum++;
		}
		if (isD) {
			dnum++;
		}

		if (!isA && !isD) {
			anum = 0;
		}
		if (!isD) {
			dnum = 0;
		}
	}

	cout << ans << endl;

	return 0;
}

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

int main(){
  int N,Y;
  cin>>N>>Y;
  int higuchi,noguchi,yukichi;

  /*
    yukichi+noguchi+higuchi = N
    10000yukichi+5000noguchi+1000higuchi = Y
    N = 
  */

  

  for(int higuchi = 0; higuchi <=N; higuchi++){
    for(int yukichi=0; yukichi <= N; yukichi++){
      int noguchi = N-higuchi-yukichi;
      int sum = 10000*yukichi+5000*higuchi+1000*noguchi;
      if(sum == Y && noguchi+yukichi+higuchi == N && noguchi >= 0){
        cout<<yukichi<<" "<<higuchi<<" "<<noguchi<<endl;
        return 0;
      }
    }
  }
  

  cout<<"-1"<<" "<<"-1"<<" "<<"-1"<<endl;

  return 0;
  
}


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

public class Main {
    public static void main(String[] args) throws IOException {
        final BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        int n = Integer.parseInt(br.readLine());
        boolean res = false;

        for (int i = 0, chain = 0; i < n; ++i) {
            String[] line = br.readLine().split(" ");
            int a = Integer.parseInt(line[0]), b = Integer.parseInt(line[1]);
            if (a == b) {
                res |= ++chain >= 3;
            } else {
                chain = 0;
            }
        }

        bw.write(res ? "Yes" : "No");

        bw.close();
        br.close();
    }
}


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

using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
#define REP(i,N) for(int i=0;i<N;i++)

int main()
{
    int n; cin>>n;
    vector<int> d(n,0);
    REP(i,n){
        cin>>d[i];
    }
    sort(all(d));
    int a = d[n/2-1];
    int b = d[n/2];
    cout<<b-a<<endl;
    return 0;
}


Measured memory_bytes: 640
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;

class Program {
    static void Main(string[] args) {
        int N;
        Input(out N);
        int[] P;
        InputArray(out P);
        int min = P[0];
        int count = 0;
        for(int i = 0; i < N; i++) {
            if(P[i] <= min) {
                count++;
                min = P[i];
            }
        }
        Console.WriteLine(count);
    }
    static T ChangeT<T>(string s) => (T)Convert.ChangeType(s, typeof(T));
    static void Input<A>(out A a) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
    }
    static void Input<A, B>(out A a, out B b) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
    }
    static void Input<A, B, C>(out A a, out B b, out C c) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
        c = ChangeT<C>(words[2]);
    }
    static void Input<A, B, C, D>(out A a, out B b, out C c, out D d) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
        c = ChangeT<C>(words[2]);
        d = ChangeT<D>(words[3]);
    }
    static void Input<A, B, C, D, E>(out A a, out B b, out C c, out D d, out E e) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
        c = ChangeT<C>(words[2]);
        d = ChangeT<D>(words[3]);
        e = ChangeT<E>(words[4]);
    }
    static void Input<A, B, C, D, E, F>(out A a, out B b, out C c, out D d, out E e, out F f) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
        c = ChangeT<C>(words[2]);
        d = ChangeT<D>(words[3]);
        e = ChangeT<E>(words[4]);
        f = ChangeT<F>(words[5]);
    }
    static void InputArray<T>(out T[] array) {
        array = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries).Select(s => ChangeT<T>(s)).ToArray();
    }
}

Measured memory_bytes: 32092
import java.util.*;
public class Main{
        public static void main(String[] args){
                Scanner sc = new Scanner(System.in);
                int n = sc.nextInt();
                int[][] a = new int[2][n];
                int[] yono = new int[n];
                for(int i = 0 ; i < n ; i++){
                        a[0][i] = i + 1;
                        a[1][i] = sc.nextInt() - 1;
                }
                for(int i = 0 ; i < n ; i++){
                        yono[a[1][i]] = a[0][i];
                }
                for(int i = 0 ; i < n ; i++){
                        System.out.print(yono[i]);
                        if(i != n - 1){
                                System.out.print(" ");
                        }else{
                                System.out.println();
                        }
                }
        }
}
//早く正確なコードを書けるように頑張ります

Measured memory_bytes: 60948
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>

using namespace std;

typedef long long ll;

long long GCD(long long a, long long b){if(b==0)return a;return GCD(b,a%b);}

int main() {
    long long N; cin >> N;

    string res = "";

    while (N != 0) {
        if (N % -2 == 0) res = "0" + res, N /= -2;
        else res = "1" + res, N = (N-1) / -2;
    }

    if (res == "") cout << 0 << endl;
    else cout << res << endl;
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) begin(x), end(x)
using namespace std;
using ll = long long;
constexpr ll Mod = 998244353;
constexpr ll mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;
const double PI = acos(-1);
template <typename T> constexpr bool chmax(T &a, const T &b) {
    if(a >= b) return false;
    a = b;
    return true;
}
template <typename T> constexpr bool chmin(T &a, const T &b) {
    if(a <= b) return false;
    a = b;
    return true;
}

/*-------------------------------------------*/

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

    int a[5];
    rep(i, 5) cin >> a[i];

    rep(i, 5) {
        if(a[i] == 0) cout << i + 1 << endl;
    }

    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
using namespace std;
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <functional> //sort(A,A.end(),greater<int>());???????????????
#include <queue>
#include <stack>
#include <vector>

#define INF 10 << 10

int map[128][128];
bool flg[128][128];
int y_move[2][6] = { {-1,-1,0,0,+1,+1},{-1,-1,0,0,+1,+1} };
int x_move[2][6] = { {0,+1,-1,+1,0,+1},{-1,0,-1,+1,-1,0} };
int cnt = 0;

int rec(int y, int x);

int main() {
	memset(map, 0, sizeof(map));
	memset(flg, true, sizeof(flg));

	int w, h;
	cin >> w >> h;
	for (int i = 0; i <= h + 3; ++i) {
		for (int i2 = 0; i2 <= w + 3; ++i2) {
			if (i <= 1 || i2 <= 1 || i >= h + 2 || i2 >= w + 2) {
				if (i == 0 || i2 == 0 || i == h + 3 || i2 == w + 3) { map[i][i2] = -1; }
			}
			else { cin >> map[i][i2]; }
		}
	}

	rec(1,1);

	cout << cnt << endl;

	return 0;
}

int rec(int y,int x) {
	
	flg[y][x] = false;
	for (int k = 0; k < 6; ++k) {
		int y1 = y + y_move[y % 2][k], x1 = x + x_move[y % 2][k];
		if (flg[y1][x1]) {
			if (map[y1][x1] == 1) { cnt++; }
			else if(map[y1][x1] == 0) { rec(y1, x1); }
		}
	}

	return 0;
}

Measured memory_bytes: 3392
import math

n, k = map(int,input().split())
p = 0

for i in range(1,n+1):
    l = math.ceil(math.log2(k/i))
    if i < k:
        p = p + (1/n)*((1/2)**l)
    else:
        p = p + (1/n)

print(p)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define MAX 1000001
int n;
vector<int> nums;
bool canDiv[MAX] = {};
void eratos() {
  int before = 0;
  for (int i = 0; i<n;i++) {
    int base = nums[i];
    if (before == base) {
      canDiv[before] = true;
    }
    if (canDiv[base]) {
      continue;
    }
    for (int val = base*2; val < MAX; val+=base) {
      canDiv[val] = true;
    }
    before = base;
  }
}

int main(){
  cin >> n;
  int cnt = 0;
  for (int i=0; i<n;i++) {
    int a;
    cin >> a;
    nums.push_back(a);
  }
  sort(nums.begin(), nums.end());
  eratos();
  for (int i=0; i<n;i++) {
    if (!canDiv[nums[i]]) {
      cnt++;
    }
  }
  cout << cnt << endl;
}

Measured memory_bytes: 5084
#include<stdio.h>
#include<stdlib.h>
int compUp(const void* a, const void* b){
    int* A = (int*)a;
    int* B = (int*)b;
    if(*A == *B){
        A++; B++;
        return *A - *B;
    }
    else{
        return *A - *B;
    }
}

int MIN(int a, int b){return a>b?b:a;}

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

    int d[m][2];
    for(int i = 0; i < m; i++){scanf("%d%d", &d[i][0], &d[i][1]);}
    qsort(d, m, 2*sizeof(int), compUp);

    int max, min;
    int flag = 1;
    for(int i = 0; i < m-1; i++){
        max = d[i][1];
        min = d[i+1][0];
        if(max < min){
            flag = 0;
            break;
        }

        max = MIN(max, d[i+1][1]);
        d[i+1][0] = min;
        d[i+1][1] = max;
    }

    if(flag == 0){printf("0\n");}
    else{printf("%d\n", d[m-1][1] - d[m-1][0] + 1);}
    return 0;
}

Measured memory_bytes: 1788
#include <stdio.h>

int gcd(int a, int b){
  return b ? gcd(b,a%b) : a;
}

int lcm(int a, int b){
  return a / gcd(a,b) * b;
}

int main(void){
  int i;
  int n, a[10];
  int ans;

  scanf("%d", &n);
  for(i=0;i<n;i++)
    scanf("%d", a+i);

  ans=a[0];
  for(i=1;i<n;i++)
    ans=lcm(ans, a[i]);

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

  return 0;
}


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

public class Main {

	public static void main(String[] args) {
		
		new Main().run();
		
	}

	Scanner scanner = new Scanner(System.in);
	int n;
	int q;
	
	private class Data implements Comparable<Data> {
		
		String en;
		int eby;
		int wy;
		
		private Data(String en, int eby, int wy) {
			
			this.en = en;
			this.eby = eby;
			this.wy = wy;
			
		}

		@Override
		public int compareTo(Data o) {
			
			return wy - o.wy;
			
		}
		
	}
	
	Data[] db;
	
	private void run() {
		
		for(;nq();) {
			
			db = new Data[n];
			
			for (int i = 0; i < db.length; i++) {
				
				db[i] = new Data(scanner.next(), scanner.nextInt(), scanner.nextInt());
				
			}
			
			Arrays.sort(db);
			
			for (int i = 0; i < q; i++) {
				
				Data qry = new Data("", 0, scanner.nextInt());
				int ip = Arrays.binarySearch(db, qry);
				
				if (ip < 0) {
					
					ip = - ip - 1;
					
				}
				
				if (ip < db.length) {
					
					qry.wy = qry.wy - db[ip].wy + db[ip].eby;
					
					if (qry.wy > 0) {
						
						System.out.println(db[ip].en + " " + qry.wy);
						continue;
					}
					
				}
				
				System.out.println("Unknown");
				
			}
			
		}
		
	}

	private boolean nq() {
		
		n = scanner.nextInt();
		q = scanner.nextInt();
		
		return (n | q) != 0;
		
	}

}

Measured memory_bytes: 14000
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main{
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb = new StringBuilder();
        String line = br.readLine();
        int n = Integer.parseInt(line);
        for(int i = 1; i <= n; i++){
            int x = i;
            if( x % 3 == 0 ){
                sb.append(" ").append(i);
            }else{
                do{
                    if( x % 10 == 3 ){
                        sb.append(" ").append(i);
                                                x = 0;
                    }
                    x /= 10;
                }while( x != 0 );
            }
        }
        sb.append("\n");
        System.out.print(sb);
    }
}

Measured memory_bytes: 25392
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
long long N,M,a[100009][3],maxn=-(1LL<<60);

int main(){
	ios::sync_with_stdio(0);
	cin>>N>>M;
	for(int i=1;i<=N;++i){
		for (int j=0;j<3;++j){
			cin>>a[i][j];
		}
	}
	for(int i=0;i<8;++i){
		vector<long long>vec;
		for(int j=1;j<=N;++j){
			long long S=0;
			for(int k=0;k<3;++k){
				if((i/(1<<k))%2==0)S+=a[j][k];
				else S-=a[j][k];
			}vec.push_back(S);
		}
		sort(vec.begin(),vec.end());
		reverse(vec.begin(),vec.end());
		long long ans=0;
		for(int j=0;j<M;++j)ans+=vec[j];
		maxn=max(maxn,ans);
	}
	cout<<maxn<<"\n";
	return 0;
}

Measured memory_bytes: 256
def main():
    H, W, M = map(int, input().split())
    hw = [tuple(list(map(int, input().split()))) for _ in [0]*M]
    hw_set = set(hw)
    h_count = [0 for i in range(H+1)]
    w_count = [0 for i in range(W+1)]
    for h, w in hw:
        h_count[h] += 1
        w_count[w] += 1
    h_m = max(h_count)
    w_m = max(w_count)
    h_list = []
    w_list = []
    for i in range(H+1):
        if h_count[i] == h_m:
            h_list.append(i)
    for i in range(W+1):
        if w_count[i] == w_m:
            w_list.append(i)
    #print(h_list, w_list)
    for i in h_list:
        for j in w_list:
            if (i, j) not in hw_set:
                print(h_m+w_m)
                return
    print(h_m+w_m-1)


main()


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

int main(){
    int a,b,m;
    cin >> a >> b >> m;
    vector<int> ref(a),mic(b);
    int minref=100000,minmic=100000;
    rep(i,a) {
        cin >> ref.at(i);
        minref = min(minref,ref.at(i));
    }
    rep(i,b) {
        cin >> mic.at(i);
        minmic = min(minmic,mic.at(i));
    }
    vector< vector <int> > dis(m,vector<int>(3)); 
    rep(i,m) {
        rep(j,3)cin >> dis.at(i).at(j);
        dis.at(i).at(0)--;
        dis.at(i).at(1)--;
    }

    int totalcost = minref + minmic;

    rep(i,m)totalcost = min(totalcost,ref.at(dis.at(i).at(0)) + mic.at(dis.at(i).at(1)) - dis.at(i).at(2));
    
    cout << totalcost << endl;
}

Measured memory_bytes: 9520
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
/* clang-format off */
#define MOD 1000000007
#define REP(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)

/* clang-format on */
int main() {
  int_fast64_t n, k;
  scanf("%zu %zu", &n, &k);
  int_fast64_t a = (n + 1) * (n + 2) / 2;
  int_fast64_t b = k * (k - 1) / 2;
  int_fast64_t ans = (-a * (2 * n + 3) / 3) % MOD + MOD +
                     b * (2 * k - 1) / 3 % MOD + ((n + 1) * (a - b)) % MOD + n -
                     k + 2;
  printf("%zu\n", ans % MOD);
  return 0;
}


Measured memory_bytes: 3796
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;

int main() {
	char a[81];
	int cn=0,i,s,k;
	while (cin >> a) {
     s=strlen(a); k=1;
	 for (i=s-1;i>=0;i--) { 
		 if (a[i]>='0' && a[i]<='9') {
			 cn+=k*(a[i]-'0');
			 k*=10;
		 }
		 else k=1;
	   }
	}
	cout << cn << endl;
	return 0;
}

Measured memory_bytes: 1140
#S->Tができるなら逆も可
#アルファベットが1対1に対応していたら絶対に作れる
#1対多または多対1はだめ

S = input()
T = input()
alpS = [-1 for i in range(26)] #a:0, z:25
alpT = [-1 for i in range(26)]
lenS = len(S)
flg = 1
#Sの1つのアルファベットがTの複数のアルファベットに対応していないか調べる
for i in range(lenS):
    alp = ord(S[i]) - 97
    if alpS[alp] == -1:
        alpS[alp] = ord(T[i]) - 97
    else:
        if alpS[alp] != ord(T[i]) - 97:
            flg = 0
            break
#Sの2種類以上のアルファベットがTの同じアルファベットに対応していないか調べる
for i in range(lenS):
    alp = ord(T[i]) - 97
    if alpT[alp] == -1:
        alpT[alp] = ord(S[i]) - 97
    else:
        if alpT[alp] != ord(S[i]) - 97:
            flg = 0
            break

if flg == 1:
    print("Yes")
else:
    print("No")


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

#define ALL(obj) (obj).begin(),(obj).end()
#define SPEED cin.tie(0);ios::sync_with_stdio(false);

template<class T> using PQ = priority_queue<T>;
template<class T> using PQR = priority_queue<T,vector<T>,greater<T>>;

constexpr long long MOD = (long long)1e9 + 7;
constexpr long long MOD2 = 998244353;
constexpr long long HIGHINF = (long long)1e18;
constexpr long long LOWINF = (long long)1e15;
constexpr long double PI = 3.1415926535897932384626433L;

template <class T> vector<T> multivector(size_t N,T init){return vector<T>(N,init);}
template <class... T> auto multivector(size_t N,T... t){return vector<decltype(multivector(t...))>(N,multivector(t...));}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "{" << obj.first << ", " << obj.second << "}"; return o;}
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
void print(void) {cout << endl;}
template <class Head> void print(Head&& head) {cout << head;print();}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head << " ";print(forward<Tail>(tail)...);}
template <class T> void chmax(T& a, const T b){a=max(a,b);}
template <class T> void chmin(T& a, const T b){a=min(a,b);}
void YN(bool flg) {cout << (flg ? "YES" : "NO") << endl;}
void Yn(bool flg) {cout << (flg ? "Yes" : "No") << endl;}
void yn(bool flg) {cout << (flg ? "yes" : "no") << endl;}

int main() {
    string S,T; cin >> S >> T;
    Yn(T.substr(0,S.size())==S);


    return 0;
}


Measured memory_bytes: 3632
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>
#include <cassert>

using namespace std;

const int MOD = int(1e9) + 7;

char S[305];
int tb[305][305][305];

int main()
{
    int K; scanf("%s%d", S+1, &K);
    int N = strlen(S+1);
    for(int i = 1; i <= N; i++) {
      for(int k = 0; k <= K; k++) {
        tb[i][i][k] = 1;
      }
    }
    for(int l = 2; l <= N; l++) {
      for(int i = 1, j = l; j <= N; i++, j++) {
        tb[i][j][0] = max(
          max(tb[i+1][j][0], tb[i][j-1][0]),
          tb[i+1][j-1][0] + (S[i] == S[j] ? 2 : 0)
        );
        for(int k = 1; k <= K; k++) {
          tb[i][j][k] = max(
            max(tb[i+1][j][k], tb[i][j-1][k]),
            tb[i+1][j-1][S[i] == S[j] ? k : k-1] + 2
          );
        }
      }
    }

    int ans = 0;
    for(int i = 1; i <= N; i++) {
      for(int j = i; j <= N; j++) {
        for(int k = 0; k <= K; k++) {
          ans = max(ans, tb[i][j][k]);
        }
      }
    }

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

	return 0;
}

Measured memory_bytes: 110336
mod = 10 ** 9 + 7
h, w, a, b = map(int, raw_input().split())

fm = [1]
for i in xrange(1, 300000):
    fm.append(fm[-1] * i % mod)

def f(x):
    return fm[x]

def inv(x):
    return pow(x, mod - 2, mod)

def c(x, y):
    return f(x + y) * inv(f(x)) % mod * inv(f(y)) % mod

x, y = b - 1, h - a
ans = c(w-1, h-1)
while h - a <= y < h and 0 <= x < b:
    ans = (ans + mod - c(x, y) * c(w - 1-x, h-1 - y) % mod) % mod
    x -= 1
    y += 1

print ans



Measured memory_bytes: 12164
#include<stdio.h>
	int main(){
	int H,W,h,w,x,y;
	scanf("%d",&H);
	scanf("%d",&W);
	scanf("%d",&h);
	scanf("%d",&w);
	x = H * W;
	y = h * W + ((H - h) * w);
	x = x - y;
	printf("%d",x);
return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>

using namespace std;
#define TOSTRING(x) #x
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REPR(i,n) for(int i=(n)-1;i>=0;i--)
#define ALL(s) (s).begin(), (s).end()
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());
#define PAU system("pause")

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<vb> vvb;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = (1 << 28);
const double PI = acos(-1);


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	int x;
	cin >> x;
	vi A(N);
	REP(i, N)cin >> A[i];
	so(A);
	int ans = 0;
	REP(i, N) {
		if (x < A[i])break;
		x -= A[i];
		ans++;
	}
	if (ans == N && x > 0)ans--;
	cout << ans << endl;
	PAU;
	return 0;
}


Measured memory_bytes: 504