akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll MOD = 1000000007;

#define vec                vector<int>
#define vecll              vector<ll>
#define vecd               vector<double>
#define vecst              vector<string>
#define vecb               vector<bool>
#define vec2(var, n, m)    vector<vector<int>>  var(n, vector<int>(m, 0))
#define vecb2(var, n, m)   vector<vector<bool>> var(n, vector<bool>(m, false))
#define vecll2(var, n, m)  vector<vector<ll>>   var(n, vector<ll>(m, 0))

#define rep(i,n)         for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n)       for(ll i=(ll)m; i<(ll)n; i++)
#define arr(var, n)      vec var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n)    vecll var(n); rep(i,n){cin >> var[i];}
#define arrst(var, n)    vecst var(n); rep(i,n){cin >> var[i];}
#define all(var)         (var).begin(), (var).end()
#define sortall(var)     sort(all(var))
#define uniqueall(v)     v.erase(unique(v.begin(), v.end()), v.end());
#define f_sum(var)       accumulate(all(var), 0)
#define f_sumll(var)     accumulate(all(var), 0LL)
#define chmin(v1, v2)    v1 = min(v1, v2)
#define chmax(v1, v2)    v1 = max(v1, v2)
#define pb(var)          push_back(var)
#define prt(var)         cout << (var) << "\n"
#define prtd(n, var)     cout << fixed << setprecision(n) << (var) << "\n"
#define prtfill(n, var)  cout << setw(n) << setfill('0') << (var);
#define prt2(v1, v2)     cout << (v1) << " " << (v2) << "\n"
#define prt3(v1, v2, v3) cout << (v1) << " " << (v2) << " " << (v3) << "\n"
#define prtall(v)        rep(i,v.size()){cout<<v[i]<<(i!=v.size()-1?" ":"\n");}
void prtok(bool ok){prt(ok ? "YES" : "NO");}
//----------------------------------------------------------------

int main(void) {
  string s, t;
  cin >> s >> t;

  int n = s.size();

  map<char, char> mps, mpt;
  rep(i,n){
    if(mps.find(s[i])==mps.end()){
      mps.emplace(s[i], t[i]);
    } else if(mps[s[i]]!=t[i]) {
      prt("No");
      return 0;
    }
    if(mpt.find(t[i])==mpt.end()){
      mpt.emplace(t[i], s[i]);
    } else if(mpt[t[i]]!=s[i]) {
      prt("No");
      return 0;
    }
  }

  prt("Yes");
}


Measured memory_bytes: 3920
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(ll i = n;i >= 0;--i)
#define FOR(i,m,n) for(ll i = m, i##_len=(n);i <i##_len; ++i)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const int INF = 1e9;
const ll LLINF = 1e16;

ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}


int main(void)
{
    int n,m;
    cin >> n >> m;
    int mostleft = -1;
    int mostright = n+1;
    REP(i,m){
        int left,right;
        cin >> left >> right;
        if(mostleft < left){
            mostleft = left;
        }
        if(mostright > right){
            mostright = right;
        }
    }


    cout << max(0,mostright - mostleft + 1) << endl;


    return 0;
}

Measured memory_bytes: 256
a = gets.chomp.split("")#.split(" ").map(&:to_i)

list = [-1,-1]

a.each_cons(3).with_index do |l,i|
 if (l[0]==l[1] || l[1]==l[2] || l[0]==l[2]) 
   list[0] = i+1
   list[1] = i+3
   break
 end
end
a.each_cons(2).with_index do |l,i|
 if (l[0]==l[1])
   list[0] = i+1
   list[1] = i+2
   break
 end
end


puts "#{list[0]} #{list[1]}"


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

int main(){
  int K,S,c = 0;
  cin >> K >> S;
  for(int i = 0; i <= K; i++){
    for(int j = 0; j <= K ; j++){
      if((S - i - j ) <= K && (S - i - j ) >= 0){
        c += 1;
      }
    }
  }
  cout << c << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <string>
using namespace std;
char s[4], op[4]; int x[4];
int found = 0;
void rec(int sum, int p) {
  if(found || p > 3) return;
  sum += x[p]; op[p] = '+';
  if(p == 3 && sum == 7) found = 1;
  rec(sum, p+1);
  if(found) return;
  sum -= 2*x[p]; op[p] = '-';
  if(p == 3 && sum == 7) found = 1;
  rec(sum, p+1);
  sum += x[p];
}
int main() {
  scanf("%s", s);
  for(int i = 0; i < 4; i++) x[i] = s[i] - '0';
  rec(0, 0);
  printf("%d%c%d%c%d%c%d=7", x[0], op[1], x[1], op[2], x[2], op[3], x[3]);
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cmath>
using namespace std;
 
typedef long long ll;


int main(){
	int a,b,c;
	cin >> a >> b >> c;
	
	int d = a-b;
	if(c-d <= 0) cout << 0 <<endl;
	else cout << c-d  << endl;
	
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static long H;
	public static long W;
	public static long K;
	public static String[][] C;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		H = sc.nextLong();
		W = sc.nextLong();
		K = sc.nextLong();
		C = new String[(int) (1 + H)][(int) (1 + W)];
		for (int h = 1; h <= H; h++) {
			String inh = sc.next();
			for (int w = 1; w <= W; w++) {
				C[h][w] = String.valueOf(inh.charAt((int)(w-1)));
			}
		}

		long res = 0;
		long hmax = (long) Math.pow(2, H);
		long wmax = (long) Math.pow(2, W);
		for (long eh = 0; eh < hmax; eh++) {
			for (long ew = 0; ew < wmax; ew++) {
				if (isKuroK(eh, ew))
					res++;
			}
		}
		System.out.println(res);
	}

	static boolean isKuroK(long eh, long ew) {
		long black = 0;
		for (int h = 1; h <= H; h++) {
			long ph = (long) Math.pow(2, h-1);
			if ((eh & ph) == ph) {
				continue;
			}
			for (int w = 1; w <= W; w++) {
				long pw = (long) Math.pow(2, w-1);
				if ((ew & pw) == pw) {
					continue;
				}
				if (C[h][w].equals("#")) {
					black++;
				}
			}
		}
		return black == K;
	}
}


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

using namespace std;

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

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

  c = a + b;
  if (c < 10) {
    cout << c << endl;
  } else {
    cout << "error" << endl;
  }
}


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

using namespace std;

using ll = long long;

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

    int H, W, h, w;
    cin >> H >> W >> h >> w;
    cout << (H - h) * (W - w) << endl;

    return 0;
}


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

struct Data {
    int number;
    int count;
};

int main() {
    int n;
    cin >> n;
    auto a = vector<int>(n);
    auto counts = vector<int>(n);
    for (int i = 1; i <= n; i++) {
        int a_i;
        cin >> a_i;
        a_i--;
        counts[a_i] = i;
    }
    for (auto i : counts)
        cout << i << " ";

    return 0;
}


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

using namespace std;

long long n;

int main(){
	scanf("%lld",&n);
	printf("0 0 ");
	long long x2=1000000000,y3=(n+x2-1)/x2,x3=1,y2=x2*y3-n;
	printf("%lld %lld %lld %lld\n",x2,y2,x3,y3);
	
	return 0;
}
			

Measured memory_bytes: 256
s = input()
l = len(s)//2
s_ = s[::-1]
s1 = s[:l]
s1_ = s1[::-1]
s2 = s[l+1:]
s2_ = s2[::-1]

if s == s_ and s1 == s1_ and s2 == s2_:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9016
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define all(a) (a).begin(), (a).end()

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

using ll = long long;
using P = std::pair<ll, ll>;

ll H, W, D;
ll A[310][310];
ll Q;

std::map<ll, P> mp;
std::vector<std::vector<ll>> S;

int main()
{
  std::cin >> H >> W >> D;

  rep( i, H ) rep( j, W )
  {
    std::cin >> A[i][j];

    mp[A[i][j]] = P( i, j );
  }

  rep( d, D )
  {
    ll prv = 0;

    S.emplace_back( std::vector<ll>( 1, 0 ) );

    rep( x, (H*W-d+D-1)/D+2 ) if( x > 0 )
    {
      P np = mp[d+x*D];
      P pp = mp[d+(x-1)*D];

      prv += llabs(np.first-pp.first)+llabs(np.second-pp.second);

      S[d].emplace_back( prv );
    }
  }

  std::cin >> Q;
  
  rep( q, Q )
  {
    ll L, R;
    std::cin >> L >> R;

    ll d = L%D;
    ll x1 = (L-d)/D;
    ll x2 = (R-L)/D;
    
    std::cout << S[d][x2+x1]-S[d][x1] << std::endl;
  }

  return 0;
}

Measured memory_bytes: 24368
#ABC079C

a,b,c,d=map(int,raw_input())
if a-b-c-d==7:
 print str(a)+'-'+str(b)+'-'+str(c)+'-'+str(d)+'=7'
elif a-b-c+d==7:
 print str(a)+'-'+str(b)+'-'+str(c)+'+'+str(d)+'=7'
elif a-b+c-d==7:
 print str(a)+'-'+str(b)+'+'+str(c)+'-'+str(d)+'=7'
elif a-b+c+d==7:
 print str(a)+'-'+str(b)+'+'+str(c)+'+'+str(d)+'=7'
elif a+b-c-d==7:
 print str(a)+'+'+str(b)+'-'+str(c)+'-'+str(d)+'=7'
elif a+b-c+d==7:
 print str(a)+'+'+str(b)+'-'+str(c)+'+'+str(d)+'=7'
elif a+b+c-d==7:
 print str(a)+'+'+str(b)+'+'+str(c)+'-'+str(d)+'=7'
elif a+b+c+d==7:
 print str(a)+'+'+str(b)+'+'+str(c)+'+'+str(d)+'=7'


Measured memory_bytes: 2696
N, K = map(int, input().split())
X = list(map(int, input().split()))
INF = 1000000000
distances = [INF]*(2*(N-K+1))
for l in range(N-K+1):
    distances[l] = abs(X[l]) + abs(X[l] - X[l+K-1])
    distances[l+N-K+1] = abs(X[l+K-1]) + abs(X[l] - X[l+K-1])

print(min(distances))


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

// aを常に小さい値にする　大きい値にする
template<class T> bool chmin(T &a, T b){
    if(a>b) {
        a = b;
        return true;
    }
    return false;

}
template<class T> void chmax(T &a, T b){ if(a<b) a = b; }

// 二分探索 前方のindexを返すもの（自分自身を含む） 前方: -INF側のこと
template<class T> int former(const vector<T> &v, T x){
    return upper_bound(v.begin(), v.end(), x) - v.begin() -1; // upper_bound : keyより大きい要素の内の一番左側のイテレータを返す
}
// 二分探索 後方のindexを返すもの（自分自身を含む）後方: INF側のこと
template<class T> int latter(const vector<T> &v, T x){
    return lower_bound(v.begin(), v.end(), x) - v.begin(); // lower_bound : key以上の要素の内の一番左側のイテレータを返す
}

// 最大公約数を求める GCD
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }


/*
 * 最大人数送り出すのを繰り返す貪欲法では10^15はTLEとなってしまうのでダメ
 *
 * 定員の人数が最も小さいところがボトルネックになることに着目する（人が詰まってしまう）
 *
 * すなわち
   ・最初の人がボトルネックに到達するまで
   ・ボトルネックを N 人分裁くまで
   ・最後にボトルネックが通過した人がゴールするまで
   を足したものが答えになる。1 と 3 は実は合計して必ず 4 になる。ちょっと色々試してみるとわかる。
   2 は、ボトルネックの定員を mi 人として、N を mi を割って余りを切り上げた値になる。その値は (N+mi−1)/mi になる。
 * */

int main() {

    ll N; cin >> N;
    vector<ll> A(5);
    ll mi = 1LL<<60;
    for (int i = 0; i < 5; ++i) cin >> A[i], mi = min(mi, A[i]);
    cout << (N + mi - 1) / mi + 4 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <ctype.h>
#include <math.h>
#include <stack>
#include <string>
#include <string.h>
using namespace std;
double PI = 3.1415926535897932;
long mod = 1000000007;

const long INF = 1e9 + 1;

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

  while(1) {
    if(n[0] == n[1] & n[1] == n[2]){
      cout << n << endl;
      return 0;
    }
    else {
      int t = stoi(n);
      t++;
      n = to_string(t);
    }
  }
}

Measured memory_bytes: 3604
import sys
input = sys.stdin.readline

#n = int(input())
#l = list(map(int, input().split()))

'''
a=[]
b=[]
for i in range():
    A, B = list(map(int, input().split()))map(int, input().split())
    a.append(A)   
    b.append(B)'''

n,x=map(int, input().split())
a=list(map(int, input().split()))
ans=0
if a[0]>x:
    ans+=a[0]-x
    a[0]=x
#print(a)
for i in range(1,n):
    if a[i-1]+a[i]>x:
        ans+=a[i]-x+a[i-1]
        a[i]-=a[i]-x+a[i-1]
#        print(a)
print(ans)

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

int main() {
	int n, k;
	int ans;

	std::cin >> n >> k;
	if (n % k != 0) {
		ans = 1;
	}
	else {
		ans = 0;
	}
	std::cout << ans << std::endl;

	return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<queue>
#include<vector>
using namespace std;

typedef long long ll;
typedef short int sh;

const int inf=0x3f3f3f3f;
const int MAX=2e5+10;
const int mod=1e9+7;

char judge[4][5]={"AC","WA","TLE","RE"};
int sum[26];

int main()
{
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        memset(sum,0,sizeof(sum));
        while(n--)
        {
            char str[5];
            scanf("%s",str);
            sum[str[0]-'A']++;
        }
        for(int i=0;i<4;i++)
        {
            char ch=judge[i][0];
            printf("%s x %d\n",judge[i],sum[judge[i][0]-'A']);
        }
    }
    return 0;
}


Measured memory_bytes: 3224
# ABC168c


def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)
    # 再帰関数を使わない限りPypyで出すこと

    def dump(*args):
        sys.stderr.write(str(args))

    a, b, h, m = map(int, input().split())

    hun = m / 60 * 360
    zikan = h / 12 * 360 + hun / 12
    kakudo = abs(hun - zikan)
    import math
    c = a ** 2 + b ** 2 - 2 * a * b * math.cos(kakudo * math.pi / 180)
    print(c**0.5)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9516
#include<stdio.h>
int main()
{
  int X;
  int hs=0;
  int fh,f;
  scanf("%d",&X);
  fh = X/500;
  hs += fh*1000;
  X -= fh*500;
  hs += X/5 * 5 ;
  printf("%d",hs);
  return 0; 
}

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

const int mxN=2e5;
int n, m;
ll k, a[mxN+1], b[mxN+1];

void solve()
{
	
	cin >> n >> m >> k;
	for(int i=0; i<n; ++i) {
		cin >> a[i+1];
		a[i+1]+=a[i];
	}
	for(int i=0; i<m; ++i) {
		cin >> b[i+1];
		b[i+1]+=b[i];
	}
	int ans=0;
	for(int i=0, j=m; i<=n; ++i) {
		if(a[i]>k)
			break;
		while(a[i]+b[j]>k)
			--j;
		ans=max(i+j, ans);
	}
	cout << ans;

}

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

	solve();

	return 0;
} 

Measured memory_bytes: 6768
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL MOD = 998244353;
template <bool P = 0> struct SegmentTree {
  #define lson L, R, N[u].l
  #define rson L, R, N[u].r
  #define OUT R <= N[u].L || N[u].R <= L
  #define IN  L <= N[u].L && N[u].R <= R
  struct Node { int L, R, l, r;
    LL sum, mul, add;
  };
  vector<Node> N; int p, n; vector<int> rt;
  inline void init(int _n) { N.resize(_n * (P ? 40:4));
    n = _n; p = 1; rt.assign(1, build(0, n));
  }
  inline int copy(Node u) { return N[p] = u, p++; }
  int build(int L, int R) {
    int u = copy({L, R}), M = (L + R) >> 1;
    N[u].mul = 1;
    if (R - L == 1) return u;
    return pull(u, build(L, M), build(M, R));
  }
  inline int push(int u) {
    if (N[u].mul != 1) {
        (N[u].sum *= N[u].mul) %= MOD;
        if (N[u].l) {
            (N[N[u].l].mul *= N[u].mul) %= MOD;
            (N[N[u].l].add *= N[u].mul) %= MOD;
        }
        if (N[u].r) {
            (N[N[u].r].mul *= N[u].mul) %= MOD;
            (N[N[u].r].add *= N[u].mul) %= MOD;
        }
        N[u].mul = 1;
    }
    if (N[u].add) {
        (N[u].sum += 1ll * (N[u].R - N[u].L) * N[u].add % MOD) %= MOD;
        if (N[u].l) {
            (N[N[u].l].add += N[u].add) %= MOD;
        }
        if (N[u].r) {
            (N[N[u].r].add += N[u].add) %= MOD;
        }
        N[u].add = 0;
    }
    return u;
  }
  inline int pull(int u, int l, int r) {
    if (!l || !r) return l ? l : r;
    N[u].L = N[l].L; N[u].R = N[r].R;
    push(N[u].l = l); push(N[u].r = r);
    N[u].sum = (N[l].sum + N[r].sum) % MOD;
    return u;
  }
  int m(int L, int R, int u, int op, LL v) {
    if (OUT) return u; push(u);
    if (P) u = copy(N[u]);
    if (IN) {
        if (op == 0)
            (N[u].mul *= v) %= MOD;
        else
            (N[u].add += v) %= MOD;
        return u;
    }
    return pull(u, m(lson, op, v), m(rson, op, v));
  }
  int q(int L, int R, int u) {
    if (OUT) return 0; push(u); if (IN) return u;
    return pull(copy(N[u]), q(lson), q(rson));
  }
  inline void modify(int L, int R, int ver, int op, LL v) {
    rt[ver] = m(L, R, rt[ver], op, v);
  }
  inline Node& query(int L, int R, int ver) {
    if (!P) p = 2 * n; return N[q(L, R, rt[ver])];
  }
};
SegmentTree solver;
int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int n, q; cin >> n >> q;
    solver.init(n);
    for (int i = 0 ; i < n ; i++) {
        LL v; cin >> v;
        solver.modify(i, i + 1, 0, 1, v);
    }
    while (q--) {
        int op; cin >> op;
        if (op == 0) {
            int l, r; LL b, c; cin >> l >> r >> b >> c;
            solver.modify(l, r, 0, 0, b);
            solver.modify(l, r, 0, 1, c);
        } else {
            int l, r; cin >> l >> r;
            cout << solver.query(l, r, 0).sum << '\n';
        }
    }
}

Measured memory_bytes: 81236
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (true) {
			int n = sc.nextInt();
			if (n == 0)
				break;
			String[] f = new String[n];
			int[][] fi = new int[n][n];
			for (int i = 0; i < n; i++)
				f[i] = sc.next();
			for (int i = 0; i < n; i++)
				for (int j = 0; j < n; j++) {
					if (f[i].charAt(j) == '.')
						fi[i][j] = 1;
					else if (f[i].charAt(j) == '*')
						fi[i][j] = 0;
				}
			for (int i = 1; i < n; i++)
				for (int j = 1; j < n; j++)
					if (fi[i][j] == 1 && fi[i - 1][j] != 0 && fi[i][j - 1] != 0
							&& fi[i - 1][j - 1] != 0)
						fi[i][j] = Math.min(fi[i - 1][j - 1],
								Math.min(fi[i - 1][j], fi[i][j - 1])) + 1;
			int max = 0;
			for (int i = 0; i < n; i++)
				for (int j = 0; j < n; j++)
					max = Math.max(max, fi[i][j]);
			System.out.println(max);
		}
		sc.close();
	}
}

Measured memory_bytes: 62604
#include <stdio.h>

int main(void)
{
	int W;
	int H;
	int x;
	int y;
	int r;

	scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);

	if((0 <= (x - r)) &&
	   (0 <= (y - r)) &&
	   ((x + r) <= W) &&
	   ((y + r) <= H)){
		printf("Yes\n");
	}else{
		printf("No\n");
	}

	return 0;
}

Measured memory_bytes: 584
#include <iostream>
#include <bits/stdc++.h>
#define i_love_u_Phuong ios_base::sync_with_stdio(0); cin.tie(0);
#define FOR(x,a,b) for(int x=a; x<=b; ++x)
#define FORD(x,a,b) for(int x=a; x>=b; --x)
using ll = long long;
using namespace std;
typedef pair<int,int> ii;
const int MAXN = 1005;
int dp[MAXN][MAXN];

#define Phuong
int main()
{
#ifndef ONLINE_JUDGE
    //freopen("input.txt", "r", stdin);
#endif //  <3 Phuong
    i_love_u_Phuong;
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n,d;
    cin >> n >> d;
    int ans=0;
    FOR(i,1,n){
        FOR(j,10, d){
            int a= j/10;
            if (a<2) continue;
            int b= j%10;
            if (b<2) continue;
            if (a*b==i) ans++;
        }
    }
    cout << ans;
    return(0);
}


Measured memory_bytes: 256
from itertools import permutations
Road = [[int(i) for i in input().split()] for j in range(3)]

graph = [[float('inf')] * 4 for _ in range(4)]
for a, b in Road:
    graph[a - 1][b - 1] = 1
    graph[b - 1][a - 1] = 1

ans = 'NO'
for v in permutations([0, 1, 2, 3], 4):
    for i in range(3):
        if graph[v[i]][v[i + 1]] != 1:
            break
    else:
        ans = 'YES'
        break
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn=1e5+5;
const int mod=1e9+7;


int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int a,b;
	int k;
	cin>>k>>a>>b;
	int flag=0;
	for(int i=a;i<=b;i++)
    {
        if(i%k==0)
        {
            flag=1;
        }
    }
    if(flag)
        cout<<"OK"<<'\n';
    else
        cout<<"NG"<<'\n';

}


Measured memory_bytes: 3652
#include<bits/stdc++.h> 
using namespace std;
//#define int long long
#include<algorithm>
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<vi> vvi;
#define F first
#define S second
#define pb push_back
#define mk make_pair
#define M 1000000007
#define watch(x) cout << (#x) << " is " << (x) << endl
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define rep(i,a,b) for(int i = a; i<= b; i++)
#define all(c) c.begin(), c.end()
#define ws " "
#define ln "\n"
#define get(x) int x; cin >> x;
#define prt printf("hello world\n")
#define MOD 1e16 + 7;

main()
{   
    IOS;
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
        float rad;
        cin >> rad;
        float twopi = atan(1)*8;
        cout << twopi*rad << ln;
       return 0;
}


Measured memory_bytes: 3800
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {
    private static int[] data = new int[10];

    public static void main(String... args) {
        BufferedReader input = new BufferedReader(new InputStreamReader(System.in));

        try {
            for (int i = 0; i < 10; i++) {
                data[i] = Integer.parseInt(input.readLine());
            }
        } catch (IOException e) {
        }
        Arrays.sort(data);
        for (int i = 9; i > 6; i--) {
            System.out.println(data[i]);
        }
    }
}

Measured memory_bytes: 16860
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#define MULT(a,b) (((a)*(b))%1000000007)
typedef long long int llint;

template<typename T>
T gcd(T a, T b) {
  if(a < b) gcd(b, a);
  T r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

template<typename T>
T gcd(std::vector<T> v){
  if(v.size() == 1) return v[0];

  T temp = v[0];
  for(int i=1; i<v.size(); i++){
    temp = gcd(v[i], temp);
  }
  return temp;
}



int main(void){
  llint n, k;
  std::cin >> n >> k;
  std::vector<llint> A(n);
  std::vector<llint> temp;
  for(int i=0; i<n; i++){
    std::cin >> A[i];
  }

  if(n==1){
    if(A[0]==k) std::cout << "POSSIBLE"   << std::endl;
    else        std::cout << "IMPOSSIBLE" << std::endl;
    return 0;
  }

  std::sort(A.begin(), A.end());
  /*
  for(int i=1; i<n; i++){
    temp.push_back(A[i]-A[i-1]);
  }

  llint ret = gcd(temp);
  */
  llint ret = gcd(A);

  if((A[A.size()-1]>=k) && ((A[A.size()-1]-k) % ret == 0)){
    std::cout << "POSSIBLE" << std::endl;
  }else{
    std::cout << "IMPOSSIBLE" << std::endl;
  }

  return 0;
}

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

main(){
    int N;
    int a[100];
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> a[i];    
    }

    sort(a,a + N, greater<int>());

    int Alice = 0;
    int Bob = 0;
    for (int i = 0;i < N;i++){
        if (i % 2 == 0){ 
            Alice += a[i];
        } else {
            Bob += a[i];
        }
    }

    cout << Alice - Bob << endl;
    return 0;
}

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

int main()
{
  string s;
  cin >> s;
  int c = 0;
  for (int i = 0; i < s.size(); i++)
  {
    if (s[i] == '1') c++;
  }
  cout << c << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int64_t INF=1e18+1;
const int mod = 1000000007;

int main(){
  int N;
  cin>>N;
  cout<<N*N*N<<endl;
  return 0;                       
}

Measured memory_bytes: 3604
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <queue>
#include <stack>
#include <deque>
#include <utility>
#include <functional>
#define rep(i,n) for(int i=0;i<n;++i)
#define FOR(i,s) for(int i=s;i>=0;--i)

using ll = long long;
using namespace std;

const ll INF = 1010101010;
const ll MOD = 1000000007;

int f(int i, int j) {
	if (i%j == 0)
		return i / j;
	else
		return i / j + 1;
}
int main() {
	ll n, m, a, b, c, ans = 0, A[10101];
	cin >> n >> m;
	cout << f(n, m)-n/m << endl;
	return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
edgelist = []
edgelistappend = edgelist.append
for i in range(M):
    edgelistappend(set(map(int, input().split())))
bridge = set()
S = set()

for e in edgelist:
    if tuple(e) not in S:
        flag = True
        E = list(e)
        start = E[0]
        goal = E[1]
        n = [start]
        R = [e]
        L = [[i for i in edgelist if (n[-1] in i) and (i not in bridge) and (i != e)]]
        while n != []:
            if n[-1] == goal:
                for x in R:
                    S.add(tuple(x))
                R.pop()
                L.pop()
                n.pop()
                flag = False
            elif L[-1] == []:
                R.pop()
                L.pop()
                n.pop()
            else:
                p = L[-1].pop()
                R.append(p)
                lp = list(p)
                if lp[0]==n[-1]:
                    n.append(lp[1])
                else:
                    n.append(lp[0])
                L.append([i for i in edgelist if (n[-1] in i) and (i not in bridge) and ((list(i)[0] not in n) or (list(i)[1] not in n))])
        if flag:
            bridge.add(tuple(e))
print(len(bridge))

Measured memory_bytes: 3188
class WeightedUnionFind():
    def __init__(self, n):
        self.par = [i for i in range(n)]
        self.rank = [0 for i in range(n)]
        # 親ノードとの重み
        self.diff_weight = [0 for i in range(n)]

    def find(self, x):
        if self.par[x] == x:
            return x
        # 親ノードはまだ上書きしない
        root = self.find(self.par[x])
        self.diff_weight[x] += self.diff_weight[self.par[x]]
        self.par[x] = root
        return self.par[x]

    def weight(self, x):
        """ x 根に対する重みを返す """
        self.find(x)
        return self.diff_weight[x]

    def diff(self, x, y):
        """ x と y の差分をとる """
        return self.weight(y) - self.weight(x)

    def unite(self, x, y, w):
        """ ノード x の下にノード y をつける。辺の重みは、w """
        # ただし、実際には、x の根と y の 根をくっつけるので、補正
        w += self.weight(x); w -= self.weight(y)
        x = self.find(x); y = self.find(y)
        if x == y:
            return
        if self.rank[x] < self.rank[y]:
            # y の下に x をつけることになるので、重さは反転させる
            self.par[x] = y
            w = -w
            self.diff_weight[x] = w
        elif self.rank[y] < self.rank[x]:
            self.par[y] = x
            self.diff_weight[y] = w
        else:
            self.par[y] = x
            self.rank[x] += 1
            self.diff_weight[y] = w

N, M = map(int, input().split())
wuf = WeightedUnionFind(N)
for i in range(M):
    l, r, d = map(int, input().split())
    l -= 1; r -= 1
    # これまでに入力されたものと等しくないか確認する
    if wuf.find(l) == wuf.find(r):
        if wuf.diff(l, r) != d:
            print('No')
            break
    else:
        wuf.unite(l, r, d)
else:
    print('Yes')


Measured memory_bytes: 10016
#include<iostream>
#include<iomanip>
#include<math.h>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<unordered_map>
#include<queue>
#include<stack>
#include<string>
#include<bitset>
#include<random>
#include<time.h>
#define MOD 1000000007ll
#define INF 1000000000ll
#define EPS 1e-10
#define REP(i,m) for(long long i=0; i<(ll)m; i++)
#define FOR(i,n,m) for(long long i=n; i<(ll)m; i++)
#define DUMP(a) for(long long dump=0; dump<(ll)a.size(); dump++) { cout<<a[dump]; if(dump!=(ll)a.size()-1) cout<<" "; else cout<<endl; }
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v) sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end());
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef long double ld;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	vector<bool> b(55556,false);
	vector<ll> ans;
	FOR(i,2,55556) {
		if(!b[i]) {
			if(i%5==1) ans.pb(i);
			for(ll j=1; i*j<55556; j++) b[i*j]=true;
		}
	}
	ll n;
	cin>>n;
	ans.resize(n);
	DUMP(ans);
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
#define SF scanf
#define PF printf
#define MAXN 1000010
#define INF 0x3FFFFFFF
#define MOD 1000000007
using namespace std;
typedef long long ll;
ll n,n1;
ll a[MAXN];
map<ll,ll> mp;
ll p(ll x){
	if(mp.count(x))
		return mp[x];
	if(x<=1000000)
		return a[x];
	if(x==1)
		return 1;
	if(x%2ll==1ll)
		mp[x]=(p(x/2ll)+p(x/2ll+1ll))%MOD;
	else
		mp[x]=p(x/2ll);
	return mp[x];
}
ll que(ll x){
	if(x==1)
		return 1;
	if(x%2ll==1ll)
		return (que(x/2ll)*3ll+p(x/2ll+1ll))%MOD;
	else
		return (que(x/2ll)*3ll-p(x/2ll)+MOD)%MOD;
}
void prepare(){
	a[1]=1;
	for(int i=1;i<=1000000;i++){
		if(i%2==1)
			a[i]=(a[i/2]+a[i/2+1])%MOD;	
		else
			a[i]=a[i/2];
	}
}	
int main(){
	prepare();
	SF("%lld",&n1);
	n1++;
	PF("%lld\n",que(n1));
}	

Measured memory_bytes: 8064
n,m=map(int,input().split())
p=[]
for _ in range(m):
  a,b=map(int,input().split())
  p.append([a,b])
#print(p)
p.sort(key=lambda x:x[1])
#print(p)
ans=0
cur=0
for i in range(m):
  if cur<=p[i][0]:
    #print("i:%d残す,cur:%d,p[i][1]:%d,p[i][0]:%d" % (i,cur,p[i][1],p[i][0]))
    ans+=1
    cur=p[i][1]
print(ans)


Measured memory_bytes: 25468
import java.util.Scanner;
public class Main{
    public void solve(){
        Scanner sc = new Scanner(System.in);
        int N,k;
        int a=0;
        int b=1;
        N=sc.nextInt(); 
      
        while(N!=0){ 
            for(int i=0;i<N;i++){
                k=sc.nextInt();
                if(k>=2){
                    b++;
                }else if(k==1){
                    a++;
                }
            }
            if(b>=2){
                System.out.println(a+b);
            }else{     
                System.out.println("NA");
            }
            a=0;
            b=1;
            N=sc.nextInt();
        }
    }
    public static void main(String[] args){
        Main obj = new Main();
        obj.solve();
    }
}

Measured memory_bytes: 158452
#include <stdio.h>

int main(void) {
  int n,i,a[100],max = 0,min = 1000000000;
  scanf("%d",&n);
  for (i = 0;i < n;i++) {
    scanf("%d",&a[i]);
  }
  for (i = 0;i < n;i++) {
    if (a[i] > max) max = a[i];
    if (a[i] < min) min = a[i];
  }
  printf("%d\n",max - min);
  return 0;
}


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

using namespace std;

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

const double PI = 3.1415926535897932384626433832795;
const ll MOD = 1000000007;

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

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

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

	int n;
	cin >> n;

	vector<ll> b(n - 1);
	for (int i = 0; i < n - 1; i++) {
		cin >> b[i];
	}

	vector<ll> a(n, INT_MAX);
	for (int i = n - 2; i >= 0; i--) {
		a[i + 1] = min(a[i + 1], b[i]);
		a[i] = min(a[i], b[i]);
	}

	ll ans = 0;
	for (auto &v : a) {
		ans += v;
	}
	
	cout << ans << endl;
	return 0;
}


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

/*BigInteger
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/rational.hpp>
namespace xxx = boost::multiprecision;
using Bint = xxx::cpp_int;
using Real = xxx::number<xxx::cpp_dec_float<1024>>;
*/

#define int long long
#define pb(x) push_back(x)
#define m0(x) memset((x), 0, sizeof(x))
#define mm(x) memset((x), -1, sizeof(x))

//container
#define ALL(x) (x).begin(), (x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
#define PERM(c) \
  sort(ALL(c)); \
  for (bool c##p = 1; c##p; c##p = next_permutation(ALL(c)))

// debug
#define GET_VAR_NAME(variable) #variable
#define test(x) cout << GET_VAR_NAME(x) << " = " << x << endl;

// bit_macro
#define bit(n) (1LL << (n))
#define bitset(a, b) (a) |= (1 << (b))
#define bitunset(a, b) (a) &= ~(1 << (b))
#define bitcheck(a, b) ((((a) >> (b)) & 1) == 1)
#define bitcount(a) __builtin_popcountll((a))

//typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

//constant
constexpr int INF = (int)1e18;
constexpr int MOD = (int)1e9 + 7;
constexpr double PI = (double)acos(-1);
constexpr double EPS = (double)1e-10;
constexpr int dx[] = {-1, 0, 0, 1, 0, -1, -1, 1, 1};
constexpr int dy[] = {0, -1, 1, 0, 0, 1, -1, 1, -1};

//
template <typename T>
void chmax(T &a, T b) { a = max(a, b); }
template <typename T>
void chmin(T &a, T b) { a = min(a, b); }
//
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

//
struct Accelerate_Cin {
  Accelerate_Cin() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);
  };
};

//Ｏ(m^3 log n)
//m項間漸化式の場合

//A*Bの計算
mat mul(mat &A, mat &B) {
  mat C(A.size(), vec(B[0].size()));

  for (int i = 0; i < A.size(); i++) {
    for (int k = 0; k < B.size(); k++) {
      for (int j = 0; j < B[0].size(); j++) {
        C[i][j] = (C[i][j] % MOD + (A[i][k] % MOD * B[k][j] % MOD) % MOD) % MOD; //<-演算子＋と＊は、演算子xorとandのように半環をなす場合、変更可能。
      }
    }
  }
  return C;
}

//A^nの計算。
mat pow(mat A, int n) {
  mat B(A.size(), vec(A.size()));

  for (int i = 0; i < B.size(); i++) {
    B[i][i] = 1; //<-演算子を変更する場合は、*に対応する方の演算子の単位元とする。andなら-1
  }
  while (n > 0) {
    if (n & 1) B = mul(B, A);
    A = mul(A, A);
    n >>= 1;
  }
  return B;
}

signed main() {
  int N, K;
  cin >> N >> K;
  mat a(N, vec(N));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      cin >> a[i][j];
    }
  }

  mat tmp = pow(a, K);

  int ans = 0;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      ans = (ans + tmp[i][j]) % MOD;
    }
  }

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


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

int main() {
	int count[10][10];
	memset(count, 0, sizeof count);
	int n; cin >> n;
	
	for(int i = 1; i <= n; i++){
		string i_str = to_string(i);
		int length = i_str.size();
		
		count[i_str[0] - '0'][i_str[length - 1] - '0']++;
	}
	
	long long ans = 0;
	for(int i = 0; i < 10; i++) 
		for(int j = 0; j < 10; j++)
			ans += count[i][j] * count[j][i];
	
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <fstream>
#include <bitset>
#include <queue>
#include <stack>
#include <deque>
#include <complex>
#include <iomanip>
#include <stdio.h>
#include <string.h>
#include <unordered_map>
#include <unordered_set>

using std::cin;
using std::cout;
using std::cerr;
using std::endl;

using std::map;
using std::set;
using std::bitset;
using std::vector;
using std::string;
using std::multimap;
using std::multiset;
using std::deque;
using std::queue;
using std::stack;
using std::pair;
using std::iterator;

using std::sort;
using std::stable_sort;
using std::reverse;
using std::max_element;
using std::min_element;
using std::unique;
using std::ios_base;
using std::swap;
using std::fill;

using std::setprecision;
using std::fixed;

using std::min;
using std::max;

//#define int long long

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<long long> vl;
//typedef string S;

namespace MySpace{

};

#define F(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define fi first
#define se second
#define re return
#define all(x) (x).begin(), (x).end()

inline int nextInt()
{
    int x = 0;
    char c = getchar();
    int mi = (c == '-');
    if (c == '-') c = getchar();
    while ('0' <= c && c <= '9')
    {
        x = 10 * x + c - '0';
        c = getchar();
    }
    if (mi) return x * -1;
    return x;
}

int n;
int a[500000];
int b[500000];
int p[500000];
int pos[500000];

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> p[i];
    for (int i = 1; i <= n; i++) pos[p[i]] = i;
    for (int i = 1; i <= n; i++) a[i] = b[n - i + 1] = n * i;
    for (int i = 1; i <= n; i++) b[p[i]] += i;
    for (int i = 1; i <= n; i++) cout << a[i] << " "; cout << "\n";
    for (int i = 1; i <= n; i++) cout << b[i] << " "; cout << "\n";
}


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

int main()
{
  ll x, y;
  cin >> x >> y;

  string ans = "No";

  if (y % 2 != 0)
  {
    cout << ans << endl;
    return 0;
  }

  if (2 * x <= y && y <= 4 * x)
  {
    ans = "Yes";
  }
  cout << ans << endl;
  return 0;
}


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


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

  vector<int> A(N);
  for (int i = 0; i < N; i++)
  {
    cin >> A.at(i);
  }

  sort(A.begin(), A.end());
  int ans = A.at(N - 1) - A.at(0);

  cout << ans << endl;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
ch = [0]*2
i = 0
j = 2
ans = 1
a.sort()
a = a[::-1]
while True:
    if a[i] == a[i+1]:
        ch[0] = a[i]
        break
    else:
        i += 1
    if i == n-1:
        ans = 0
        break

while True:
    if ans == 0:
        break
    if a[i+j] == a[i+j+1]:
        ch[1] = a[i+j]
        break
    else:
        j += 1
    if i+j == n-1:
        ans = 0

if ans == 0:
    print(0)
else:
    print(ch[0]*ch[1])


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

int main(){
  int N;
  cin >> N;
  string a;
  bool b = false;
  
  for (int i = 0; i < N; i++){
    cin >> a;
    if (a == "Y"){
      cout << "Four" << endl;
      b = true;
      break;
    }
  }
  if (b == false){
  cout << "Three" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include<cmath>
#include<algorithm>
#include<vector>
using namespace std;
#define ll long long
#define ld long double


int main(){

int n;
cin>>n;
vector<vector<int>> vec(2,vector<int>(n+1,0));
for(int i=1;i<=n;i++){
    cin>>vec[0][i];
}
for(int i=1;i<=n;i++){
    cin>>vec[1][i];
}
for(int i=1;i<=n;i++){
    vec[0][i]+=vec[0][i-1];
 //   cout<<vec[0][i]<<" "<<vec[1][i]<<" ";
    vec[1][i]=vec[1][i] + max(vec[0][i],vec[1][i-1]);
  //  cout<<vec[1][i]<<" "<<endl;
    
}
cout<<vec[1][n];
}

Measured memory_bytes: 3160
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

int main() {
#ifdef DEBUG
  ifstream ifs("in.txt");
  cin.rdbuf(ifs.rdbuf());
#endif
  int K;
  while (cin >> K) {
    vector<ll> res;
    for (int i = 1; i < 10; i++) res.push_back(i);
    for (int i = 0; res.size() < K; i++) {
      int x = res[i] % 10;
      for (int dx = -1; dx <= 1; dx++) {
        int d = x + dx;
        if (d >= 0 && d < 10) {
          res.push_back(res[i] * 10 + d); 
        }
      }
    }
    cout << res[K - 1] << endl;
  }
  return 0;
}


Measured memory_bytes: 1400
import sys
from collections import deque

H,W=map(int,input().split())
si,sj=[int(x)-1 for x in input().split()]
ti,tj=[int(x)-1 for x in input().split()]
A=list(sys.stdin)

dirs=[-2,-1,0,1,2]
dist=[[float('inf')]*W for _ in range(H)]
dist[si][sj]=0
dq=deque()
dq.append((0,si,sj))
ok=False
while dq:
    k,i,j=dq.popleft()
    if i==ti and j==tj:
        ok=True
        break
    if k>dist[i][j]:
        continue
    for di in dirs:
        for dj in dirs:
            if di==dj==0:
                continue
            ni,nj=i+di,j+dj
            if not (0<=ni<H and 0<=nj<W):
                continue
            if A[ni][nj]=='#':
                continue
            if abs(di)+abs(dj)==1:
                append=dq.appendleft
                nk=k
            else:
                append=dq.append
                nk=k+1
            if k>=dist[ni][nj]:
                continue
            dist[ni][nj]=nk
            append((nk,ni,nj))
      
if ok:
    ans=dist[ti][tj]
else:
    ans=-1

print(ans)


Measured memory_bytes: 226888
#include<bits/stdc++.h>
#define FOR0(i,n) for(int i=0;i<n;i++)
#define FOR1(i,n) for(ll i=1;i<=n;i++)
#define FORl(i,l,n) for(ll i=l;i<n;i++)
using namespace std;
#define pi pair<ll, ll>
#define pb push_back
#define ll long long
#define ld long double	
#define ff first
#define ss second
#define mp make_pair
#define mst0(x) memset(x,0,sizeof(x));
#define vi vector<ll>
#define sync ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define sp <<" "<<
#define intmax 1e18
// double power(double num, double g) {
// 	if (g == 0)return 1;
// 	if (g % 2 == 1)return (num * power((num * num), g / 2));
// 	return power( (num * num) , g / 2);
// }

int main(){
	ll n, m, cnt = 0, x , y;
	cin >> n >> m;
	vi v[n+1];
	ll h[n+1];
	FOR1(i, n) cin >> h[i];
	FOR0(i, m){
		cin >> x >> y;
		v[x].pb(y);
		v[y].pb(x);
	}
	FOR1(i, n){
		bool chk = true;
		for(auto u : v[i]){
			if (h[u]>=h[i]) chk = false;
		}
		if (chk) cnt++;
	}
	cout << cnt;
}



Measured memory_bytes: 10192
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

ll waru(ll i,ll j){
    if(i%j==0){
        return i/j;
    }
    return 1+(i/j);
}
            
int main(){
    ll n,a,b;cin>>n>>a>>b;
    ll h[n];rep(i,0,n-1)cin>>h[i];
    ll x[n];
    ll sum;
    ll l=0;
    ll r=pow(10,9)+1;
    ll mid;
    while(r-l>1){
        mid=(r+l)/2;
        sum=0;
        rep(i,0,n-1){
            x[i]=h[i]-mid*b;
            if(x[i]<=0){
                continue;
            }else{
                sum+=waru(x[i],a-b);
            }
        }
        if(sum<=mid){
            r=mid;
        }else{
            l=mid;
        }
    }
    cout<<r<<endl;
    
    return 0;
}


Measured memory_bytes: 1792
s = input()[::-1]

MOD = 2019

cum = 0
cnt = [0] * 2019
cnt[0] = 1

d = 1
for c in s:
    cum += int(c) * d
    cum %= MOD
    cnt[cum] += 1
    d *= 10
    d %= MOD

ans = 0
for v in cnt:
    ans += v * (v - 1) // 2

print(ans)


Measured memory_bytes: 74072
#include<bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;
typedef long long ll;

int main(){
	int N, x; cin >> N >> x;
	if(N != 2){
		if(x == 1 || x == 2*N-1) cout << "No" << "\n";
		else{
			cout << "Yes" << "\n";
			int ans[2*N-1];
			if(x != 2*N-2){
				ans[N-2] = x+2;
				ans[N-1] = 1;
				ans[N] = x;
				ans[N+1] = x+1;
				vector<int> arr;
				for(int i=2; i<=2*N-1; i++){
					if(i<x || i>x+2) arr.push_back(i);
				}
				for(int i=0; i<N-2; i++) cout << arr[i] << endl;
				for(int i=N-2; i<N+2; i++) cout << ans[i] << endl;
				for(int i=N+2; i<2*N-1; i++) cout << arr[i-4] << endl;
			}else{
				ans[N-2] = 1;
				ans[N-1] = 2*N-2;
				ans[N] = 2*N-1;
				ans[N+1] = 2;
				vector<int> arr;
				for(int i=3; i<=2*N-3; i++){
					arr.push_back(i);
				}
				for(int i=0; i<N-2; i++) cout << arr[i] << endl;
				for(int i=N-2; i<N+2; i++) cout << ans[i] << endl;
				for(int i=N+2; i<2*N-1; i++) cout << arr[i-4] << endl;
			}
		}
	}else{
		if(x == 1 || x == 3) cout << "No" << "\n";
		else{
			cout << "Yes" << "\n";
			for(int i=1; i<=3; i++) cout << i << "\n";
		}
	}
	return 0;
}


Measured memory_bytes: 2420
import sys
import math
import collections
import bisect
import itertools

# import numpy as np

sys.setrecursionlimit(10 ** 7)
INF = 10 ** 20
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline().rstrip())
ns = lambda: map(int, sys.stdin.readline().rstrip().split())
na = lambda: list(map(int, sys.stdin.readline().rstrip().split()))
na1 = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().rstrip().split()))


# ===CODE===

def main():
    n = ni()
    e = [[] for _ in range(n)]

    for _ in range(n - 1):
        a, b = ns()
        a, b = a - 1, b - 1
        e[a].append(b)
        e[b].append(a)

    dist_f = [-1 for _ in range(n)]
    dist_s = [-1 for _ in range(n)]
    dist_f[0] = 0
    dist_s[n - 1] = 0

    def bfs(que, dist):
        while que:
            q = que.popleft()
            for ei in e[q]:
                if dist[ei] == -1:
                    dist[ei] = dist[q] + 1
                    que.append(ei)
        return dist

    dist_f = bfs(collections.deque([0]), dist_f)
    dist_s = bfs(collections.deque([n - 1]), dist_s)

    f = 0
    s = 0
    for df, ds in zip(dist_f, dist_s):
        if df <= ds:
            f += 1
        else:
            s += 1

    print("Fennec" if f > s else "Snuke")


if __name__ == '__main__':
    main()


Measured memory_bytes: 33940
import sys

input = sys.stdin.readline


def main():
    n = int(input())
    points = sorted(
        [[int(i) for i in input().split()] for _ in range(n)],
        key=lambda x: x[2],
        reverse=True,
    )
    hoge = 101
    for cx in range(hoge):
        for cy in range(hoge):
            x, y, z = points[0]
            h = z + abs(x - cx) + abs(y - cy)

            if h < 1:
                continue
            if all([z == max(h - abs(x - cx) - abs(y - cy), 0) for x, y, z in points]):
                print(cx, cy, h)
                return


if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
#include<iostream>
using namespace std;
int n,m,cnt,x,y,nothing;
int f[100001];
int find(int x){
	if(x!=f[x])
		f[x]=find(f[x]);
	return f[x];
}
void _union(int x,int y){
	int fx=find(x);
	int fy=find(y);
	if(fx!=fy){
		f[fy]=fx;
		++cnt;
	}
}
int main(){
	cin>>n>>m;
	for(int i=1;i<=n;++i)
		f[i]=i;
	while(m--){
		cin>>x>>y>>nothing;
		_union(x,y);
	}
	cout<<n-cnt;
	return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
//T+N
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")
#define endl "\n"
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template<class T, class T2> inline bool chkmax(T &x, const T2 &y) { return x < y ? x = y, 1 : 0; }
template<class T, class T2> inline bool chkmin(T &x, const T2 &y) { return x > y ? x = y, 1 : 0; }
const ll mod = 1e9 + 7;
template<class T> inline void fix(T &x) {if(x >= mod | x <= -mod) {x %= mod;} if(x < 0) {x += mod;}}
#define out(x) cout << __LINE__ << ": " << (#x) << " = " << (x) << endl

map<ll, ll> cnt;

signed main() {
    //ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    ll n;
    cin >> n;
    ll ans = 0;
    for(int i = 1; i <= n; i ++) {
        ll h;
        cin >> h;
        ans += cnt[i - h];
        cnt[i + h] ++;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 26136