akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>
#define INF 1000000000
#define NMAX 10
#define HWMAX 200
int dist[NMAX][NMAX];

void Floyd(int);
int main(void)
{
  int i, j, h, w, a, ans = 0;
  scanf("%d %d", &h, &w);
  for (i = 0; i < NMAX; i++) {
    for (j = 0; j < NMAX; j++) {
      scanf("%d", &dist[i][j]);
    }
  }
  Floyd(NMAX);
  for (i = 0; i < h; i++) {
    for (j = 0; j < w; j++) {
      scanf("%d", &a);
      if (a != -1) ans += dist[a][1];
    }
  }
  printf("%d\n", ans);
  return 0;
}

void Floyd(int size)
{
  int k, i, j;
  for (k = 0; k < size; k++) {
    for (i = 0; i < size; i++) {
      for (j = 0; j < size; j++) {
        if (dist[i][j] > dist[i][k] + dist[k][j]) {
          dist[i][j] = dist[i][k] + dist[k][j];
        }
      }
    }
  }
}


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

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

    string s;
    cin >> s;

    stack<char> st;
    int n = s.size(), cnt = 0;
    for(int i = 0; i < n; i++){
        if(i > 0 and s[i] == 'T'){
            if(st.size() < 1) continue;
            char tmp = st.top();
            if(tmp == 'S'){
                st.pop();
                cnt++;
                continue;
            }
        }
        st.push(s[i]);
    }

    cout << n - cnt * 2 << endl;

    return 0;
}

Measured memory_bytes: 720
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using vi = vector<int64_t>;
using vvi = vector<vi>;
using ll = int64_t;
using P = pair<ll,ll>;
ll INF = 1000000007;
// ll INF = 9223372036854775807;
// ll INF = 998244353;

int main() {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    ll a,b,k;
    cin >> a >> b >> k;
    rep(i,k/2){
        if(a%2==1) a -= 1;
        b += a/2;
        a /= 2;
        if(b%2==1) b -= 1;
        a += b/2;
        b /= 2;
    }
    if(k%2==1){
        if(a%2==1) a -= 1;
        b += a/2;
        a /= 2;
    }
    cout << a << " " << b << endl;
}

Measured memory_bytes: 3568
#pragma region cp-helper
#include <bits/stdc++.h>
using namespace std;
#define AC ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll long long
#define ull unsigned long long
#define ii pair<int, int>
#define lll pair<ll, ll>
#define vi vector<int>
#define vvi vector<vi>
#define vl vector<ll>
#define vll vector<lll>
#define vvl vector<vl>
#define vii vector<ii>
#define all(a) a.begin(), a.end()
#define qsort(a) sort(all(a))
#define qsortd(a) sort(all(a), greater<>())
#define qsortf(a, f) sort(all(a), f)
#define pb(n) push_back(n)
#define eb(n) emplace_back(n)
#define pp(a, b) emplace_back(a, b)
#define umap unordered_map
#define nl '\n'
#define fileio(in, out) freopen(in, "r", stdin); freopen(out, "w", stdout)
#define qmod %mod
#define pls int
#define give main()
const int mod = 1000000007;
#pragma endregion
const ll N = 200009;


pls give {
    AC;
    string a;
    cin >> a;
    int ans = 0;
    for (auto i : a) {
        if (i == '+') ans++;
        else ans--;
    }
    cout << ans;
}

Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
gosa = 1.0 / 10**9
mod = 10**9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()


def main():
    N,M = LI()
    a = [LI() for _ in range(M)]
    t = set()
    s = set()
    for i,j in a:
        if i==1:
            t.add(j)
        elif i==N:
            s.add(j)
        if j==1:
            t.add(i)
        elif j==N:
            s.add(i)
    if t&s:
        return 'POSSIBLE'

    return 'IMPOSSIBLE'



print(main())



Measured memory_bytes: 49128
n, k = gets.split(" ").map(&:to_i)

i = 1
sum = 0
[n, k - 1].min.times do
  sum += 2**(-Math.log(k.to_f / i, 2).ceil)
  i += 1
end

if n >= k
  puts (sum / n.to_f) + (1 - (k - 1) / n.to_f)
else
  puts sum/ n.to_f
end

Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n, ans = 0;
    cin>>n;
    int d1[n], d2[n];
    for(int i = 0; i < n; ++i)
    {
        cin>>d1[i]>>d2[i];
    }
    for(int i = 0; i < n - 2; ++i)
    {
        if((d1[i] == d2[i]) && (d1[i + 1] == d2[i + 1]) && (d1[i + 2] == d2[i + 2]))
        {
            ans = 1;
            break;
        }
    }
    if(ans)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 3644
fun main() {
    val (d, t, s) = nextIntList()
    println(if (t * s >= d) "Yes" else "No")
}
// # Utils
// ## Input
fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ")
fun nextIntList() = next().split(" ").map(String::toInt)
fun nextLongList() = next().split(" ").map(String::toLong)
fun nextDoubleList() = next().split(" ").map(String::toDouble)
// ## Array
inline fun <reified T> sizedArray(size: Int, default: T) = Array(size) { default }
inline fun <reified T> sized2DArray(row: Int, column: Int, default: T) = Array(row) { Array(column) { default } }
// ## mod^-1
//    [NOTE] CANNOT use this for 0, mod, 2mod, 3mod ...(return wrong value)
fun modinv(num: Long, mod: Long): Long {
    var a = num
    var b = mod
    var u = 1L
    var v = 0L
    while (b > 0) {
        val t = a.div(b)
        a -= t * b
        a = b.also { b = a } // swap a and b
        u -= t * v
        u = v.also { v = u } // swap u and v
    }
    u %= mod
    if (u < 0) u += mod
    return u
}

Measured memory_bytes: 36392
s=list(input())	
tmp = 0
ans = 0
for word in s:
    if word == "A":
        tmp += 1
    elif word == "T":
        tmp += 1
    elif word == "G":
        tmp += 1
    elif word == "C":
        tmp += 1
    else:
        tmp = 0
    if ans < tmp :
        ans = tmp

print(ans)


Measured memory_bytes: 2940
n=int(input())
#下２桁を実現させる最小個数を考えよう
l=[0]
for i in range(1,100):
  num=i
  l.append((num-1)//5+1)
w=str(n)
if n<100:
  print(0)
else:
  num=int(w[-2]+w[-1])
  index=l[num]
  if n<index*100+num:
    print(0)
  else:
    print(1)
  
  

Measured memory_bytes: 3060
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
using namespace std;

int main() {
	int N, K, l[51], ans=0;
	cin >> N >> K;
	for (int i = 0;i < N;i++) {
		cin >> l[i];
	}

	sort(l, l + N);

	for (int i = N - 1;i >= N - K;i--) {
		ans += l[i];
	}

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

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

typedef long long ll;
using namespace std;

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

	string s;
	while(cin >> s){
		int aj = 0, ai = 0;
	
		for (int i = 0;i < s.size()-2;i++){
			if(s[i] == 'J' && s[i+1] == 'O' && s[i+2] == 'I')aj++;
			if(s[i] == 'I' && s[i+1] == 'O' && s[i+2] == 'I')ai++;
		}
		cout << aj << endl << ai << endl;
	}

	return 0;

}



Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main() {
    int n,m,c;
    cin >> n >> m >> c;
    vector<int>Bs(m);
    int cnt = 0;
    for(int i=0;i<m; i++){
        cin >> Bs.at(i);
    }
    for(int i=0; i<n; i++){
        vector<int>As(m);
        int point = c;
        for(int j=0; j<m; j++){
            cin >> As.at(j);
        }
        for(int j=0; j<m; j++){
            point += As[j]*Bs[j];
        }
        if (point > 0) cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 384
import sys
import heapq

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inl = lambda: [int(x) for x in sys.stdin.readline().split()]
ins = lambda: sys.stdin.readline().rstrip()

N, M = inl()


class MinHeap(object):
    def __init__(self):
        self.h = []

    def push(self, x):
        heapq.heappush(self.h, x)

    def pop(self):
        return heapq.heappop(self.h)

    def __getitem__(self, i):
        return self.h[i]

    def __len__(self):
        return len(self.h)

    def __bool__(self):
        return bool(self.h)


class MaxHeap(MinHeap):
    class Negator(object):
        def __init__(self, val):
            self.val = val

        def __lt__(self, other):
            return self.val > other.val

        def __eq__(self, other):
            return self.val == other.val

        def __str__(self):
            return str(self.val)

    def push(self, x):
        heapq.heappush(self.h, self.Negator(x))

    def pop(self):
        return heapq.heappop(self.h).val


def solve():
    jobs = []
    for i in range(N):
        a, b = inl()
        jobs.append((a, b))
    jobs.sort()

    hp = MaxHeap()
    ans = 0
    j = 0
    for d in range(1, M + 1):
        while j < N and jobs[j][0] == d:
            a, b = jobs[j]
            hp.push(b)
            j += 1
        if hp:
            ans += hp.pop()
    return ans


print(solve())


Measured memory_bytes: 39036
using System;
using System.IO;

class Program
{
    const int A = 65;
    const int Z = 90;
    const int a = 97;
    const int z = 122;
    static int[] sum = new int[Z - A + 1];
    public static void Main()
    {
        initialize(sum);
        while (true)
        {
            string str = Console.ReadLine();
            if (str == null) break;
            char[] inputChar = str.ToCharArray();
            CountUpUpper(inputChar, sum);
            CountUpLower(inputChar, sum);
        }
        OutputResult(sum);
    }
    static void OutputResult(int[] result)
    {
        for (int i = 0; i <= z - a; i++)
        {
            Console.WriteLine((char)(a + i) + " : " + result[i]);
        }
    }
    static void initialize(int[] alphabetArray)
    {
        for (int i = 0; i <= Z - A; i++)
        {
            alphabetArray[i] = 0;
        }
    }
    static void CountUpUpper(char[] inputChar, int[] count)
    {
        for (int i = 0; i < inputChar.Length; i++)
        {
            for (int j = A; j <= Z; j++)
            {
                if (j == inputChar[i]) count[j - A]++;
            }
        }
    }
    static void CountUpLower(char[] inputChar, int[] count)
    {
        for (int i = 0; i < inputChar.Length; i++)
        {
            for (int k = a; k <= z; k++)
            {
                if (k == inputChar[i]) count[k - a]++;
            }
        }
    }
    
}


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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007LL

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    ll N;
    cin >> N;
    list<ll> A;
    rep(i, N) {
        ll temp;
        cin >> temp;
        A.push_back(temp);
    }
    A.sort();
    ll ANS = 0;
    {
        ll ans = 0;
        list<ll> B, temp;
        temp = A;
        rep(i, N) {
            if(i % 2 == 0) B.push_back(temp.back()), temp.pop_back();
            else B.push_back(temp.front()), temp.pop_front();
        }
        if(abs(B.back() - B.front()) > abs(*----B.end() - B.back())) B.push_front(B.back()), B.pop_back();
        vector<ll> C(B.begin(), B.end());
        rep(i, N - 1) ans += abs(C[i + 1] - C[i]);
        ANS = ans;
    }
    {
        ll ans = 0;
        list<ll> B, temp;
        temp = A;
        rep(i, N) {
            if(i % 2) B.push_back(temp.back()), temp.pop_back();
            else B.push_back(temp.front()), temp.pop_front();
        }
        if(abs(B.back() - B.front()) > abs(*----B.end() - B.back())) B.push_front(B.back()), B.pop_back();
        vector<ll> C(B.begin(), B.end());
        rep(i, N - 1) ans += abs(C[i + 1] - C[i]);
        if(ANS < ans) ANS = ans;
    }
    cout << ANS << endl;
    return 0;
}


Measured memory_bytes: 10568
from bisect import bisect_left
from collections import deque
n = int(input())

ary = deque([])
for i in range(n):
    a = int(input())
    idx = bisect_left(ary, a)
    if idx == 0:
        ary.appendleft(a)
    else:
        ary[idx-1] = a
print(len(ary))

Measured memory_bytes: 47960
#include <iostream>
using namespace std;
   
int F[102][102];
int xg,yg,w,h;
   
   
void DFS(int Y,int X,int c){
  //if(Y < 1 || X < 1)
    //return;
  if(F[Y][X] != c){
    return;
  }
   
  F[Y][X] = -1;
  DFS(Y+1,X  ,c);
  DFS(Y-1  ,X,c);
  DFS(Y,X+1  ,c);
  DFS(Y  ,X-1,c);
}
   
   
int main(){
  int xs,ys,n;
  while(1){
    cin >> w >> h;
    if(w == 0 && h == 0)
      break;
for(int i=0; i<102; i++){
      for(int j=0; j<102; j++){
        F[i][j] = 10;
      }
    }
    cin >> xs >> ys >> xg >> yg >> n;
   
   
    for(int i=0;i<n;i++){
      int c,d,x,y;
      cin >> c >> d >> x >> y;

      if(d == 0){
        for(int j=0;j<4;j++){
          F[x+j][y] = c;
          F[x+j][y+1] = c;
        }
      } else {
        for(int j=0;j<4;j++){
          F[x][y+j] = c;
          F[x+1][y+j] = c;
        }
      }
    }
  DFS(xs,ys,F[xs][ys]);
   
  if(F[xg][yg] == -1){
    cout << "OK" << endl;
  } else {
    cout << "NG" <<endl;
  }
  }
}


Measured memory_bytes: 3728
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <cstdio>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const int INF = 1e9+1;

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> L(M), R(M), D(M);
  rep(i, M) {
    cin >> L[i] >> R[i] >> D[i];
    L[i]--; R[i]--;
  }
  vector<vector<int>> to(N), co(N);
  rep(i, M) {
    to[L[i]].push_back(R[i]);
    co[L[i]].push_back(D[i]);
    to[R[i]].push_back(L[i]);
    co[R[i]].push_back(-D[i]);
  }
  vector<int> node(N, INF);
  rep(i, N) {
    if(node[i] == INF) {
      queue<int> que;
      node[i] = 0;
      que.push(i);
      while(!que.empty()) {
        int tmp = que.front();
        que.pop();
        rep(j, to[tmp].size()) {
          if(node[to[tmp][j]] != INF) {
            if(node[tmp]+co[tmp][j] != node[to[tmp][j]]) {
              cout << "No" << endl;
              return 0;
            }
          } else {
            node[to[tmp][j]] = node[tmp]+co[tmp][j];
            que.push(to[tmp][j]);
          }
        }
      }
    }
  }
  cout << "Yes" << endl;
  return 0;
}

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

int main() {
  int i,j;
  cin >> i >> j;
  vector<string> v(i+2,"");
  char sharp = '#';
  for (int k=0;k<i+2;k++){
    if(k == 0 || k == i+1){
      for(int m=0;m<j+2;m++){
        cout << sharp;
      }
      cout <<endl;
    }
    else if(0<k<i+1){
      cin >> v.at(k);
      cout << sharp << v.at(k) << sharp << endl;
  }
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,  n) for (int i  =  0; i < (int)(n); ++i)
#define REPR(i,  n) for (int i  =  n - 1; i >= 0; --i)
using namespace std;
#define int long long int
//------------ATCODER TEMPLATE-------------

template<typename T>
istream& operator >> (istream& is, vector<T>& vs){
  for(T& v: vs) is >> v;
  return is;
}

signed main() {
  for (int i = 1; i <= 5; ++i) {
    int x; cin >> x;
    if (x == 0) {
      cout << i << endl;
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 3632
#include <stdio.h>
#define N 100000
#define Q 50000

int main()
{
  int S[N],T[Q],C=0;
  int n,q,i;
  int left,right,mid,key;

  scanf("%d",&n);
  for(i=0; i<n; i++)
    scanf("%d",&S[i]);
  scanf("%d",&q);
  for(i=0; i<q; i++)
    scanf("%d",&T[i]);

  for(i=0; i<q; i++){
    key = T[i];
    left = 0;
    right = n;
    while (left < right){
      mid = (left + right)/ 2;
      if(S[mid] == key){
	C++;
	break;
      }
      else if (key < S[mid])
	right = mid;
      else left = mid +1;
    }

  }
  printf("%d\n",C);
  return 0;
}

Measured memory_bytes: 1184
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
#define ref(i,x,y)for(int i=x;i<=y;++i)
#define def(i,x,y)for(int i=x;i>=y;--i)
const int mod=998244353;
const int N=10001;
int f[N], F[N], n, a, b;
char s1[N], s2[N];
void inc(int &a,int b){ (a+=b)%=mod; }
int C(int n,int m){
	if(n<m||n<0||m<0)return 0;
	return 1LL*f[n]*F[m]%mod*F[n-m]%mod;
}
int mi(int a,int b){
	int s=1;
	for(;b;b>>=1,a=1LL*a*a%mod)
		if(b&1)s=1LL*s*a%mod;
	return s;
}
int A[N], ans;
int main(){
	scanf("%s",s1+1);
	scanf("%s",s2+1);
	n=strlen(s1+1);
	f[0] = 1;
	ref(i,1,n)f[i] = 1LL*f[i-1]*i%mod;
	F[n] = mi(f[n], mod-2);
	def(i,n,1)F[i-1] = 1LL*F[i]*i%mod;
	ref(i,1,n)if(s1[i]=='1'&&s2[i]=='1')b++;else
		if(s1[i]=='1')a++;
	A[0]=1;
	def(i,a,1){
		ref(j,0,a+b)if(A[j])A[j+1]=(1LL*A[j]*i+A[j+1])%mod;
		def(j,a+b,1)A[j]=A[j-1];A[0]=0;
	}
	ref(i,a,a+b)A[i]=1LL*A[i]*f[a]%mod*f[b]%mod*F[b-(i-a)]%mod;
	ref(i,a,a+b)inc(ans,1LL*A[i]*f[a+b-i]%mod*f[a+b-i]%mod*C(a+b,i)%mod);
	cout<<1LL*ans*f[a]%mod<<endl;
}

Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int i = sc.nextInt();
        while (i > 0){
            int pointA = 0;
            int pointB = 0;
            for (int j = 0; j < i; j++){
                int a = sc.nextInt();
                int b = sc.nextInt();
                if (a > b){
                    pointA += a + b;
                }
                else if (a < b){
                    pointB += a + b;
                }
                else {
                    pointA += a;
                    pointB += b;
                }
            }
            System.out.println(pointA + " " + pointB);
            i = sc.nextInt();
        }
    }
}



Measured memory_bytes: 57820
#include <iostream>
#include <vector>
#include <map>
#include <utility>

int main(int argc, char const *argv[]) {
  int N;
  std::vector<std::pair<int,int>> POS;
  std::map<std::pair<int,int>, int> m;
  std::cin >> N;
  for (size_t i = 0; i < N; i++) {
    int x,y;
    std::cin >> x >> y;
    std::pair<int,int> p = std::make_pair(x,y);
    POS.push_back(p);

  }
  int currentMax = 0;
  std::pair<int,int> arg_max;
  for (auto p : POS) {
    for (auto q : POS){
      if (p == q) continue;
      std::pair<int,int> diffp = std::make_pair(p.first - q.first,p.second-q.second);
      if(!m.insert(std::make_pair(diffp, 1)).second){
        m[diffp] += 1;
      }
    }
  }
  for(auto it = m.cbegin(); it != m.cend(); ++it ) {
      if (it ->second > currentMax) {
          arg_max = it->first;
          currentMax = it->second;
      }
  }
  std::cout << N - currentMax<< '\n';
  return 0;
}


Measured memory_bytes: 384
a ,b  = map(int, input().split())
g2 =  [4,6,9,11]
g1 =[1,3,5,7,8,10,12]
if a in g2 and b in g2:
    print("Yes")
elif a == 2 and b ==2:
    print("Yes")
elif a in g1 and b in g1:
    print("Yes")
else:print("No")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>

#define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
#define fb(i,a,b) for(int (i) = (a); (i) >= (b); --(i))
#define mod 998244353
#define xx first
#define yy second
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define ll long long
#define pii pair<int,int>


using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>,rb_tree_tag, tree_order_statistics_node_update> ordered_set;/// find_by_order(x)(x+1th) , order_of_key() (strictly less)
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());



vector<int> prvi, drugi;


int main()
{

    ios_base::sync_with_stdio(false); cin.tie(0);
    int n;

    cin >> n;
    ff(i,0,n - 1){
        int a,b;
        cin >> a >> b;
        prvi.pb(a); drugi.pb(b);
    }
    sort(prvi.begin(), prvi.end());
    sort(drugi.begin(), drugi.end());
    int x1 = prvi[n/2];
    if(n%2 == 0)x1 += prvi[n/2 - 1];
    int x2 = drugi[n/2];
    if(n%2 == 0)x2 += drugi[n/2 - 1];
    cout << x2 - x1 + 1 << "\n";
    return 0;
}


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

int main() {
  int n;
  string s;
  cin>>n>>s;
  int x=0,ans=0;
  for(int i=0;i<s.size();i++){
    if(s[i]=='I'){
      x++;
      ans=max(ans,x);
    }
    else x--;
  }
  cout<<ans<<endl;
  return 0;
}

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


#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define F .first
#define S .second 
#define endl "\n"
using ll=long long;
using ld=long double;
using namespace std;
const ll mod=1e9+7;
ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }
ll a[210000];
main(){
  ll n,ans=0;
  cin>>n;
  rep(i,0,n)cin>>a[i];
  ll tmp=0;
  rep(i,0,n){
    if(a[i]==tmp+1)tmp++;
  }
  if(tmp==0)cout<<-1;
  else cout<<n-tmp;
}

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

adj = [ [] for _ in range (n) ]

for i in range(n):
    _, _, *adj[i] = list(map(int, input().split()))

d = [0] * n
f = [0] * n
flag = [0] * n
time = 0

def dfs(u):
    global time
    time += 1
    flag[u-1] = 1
    d[u-1] = time
    
    for v in adj[u-1]:
        if flag[v-1] == 0:
            dfs(v)

    time += 1
    f[u-1] = time

for i in range(n):
    if flag[i] == 0:
        dfs(i+1)

for i in range(n):
    print(i+1, d[i], f[i]) 


Measured memory_bytes: 5720
// 求组合数的几种方法:(求组合数要用到逆元)
#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
#include<cstdio>
#include<vector>
#include<stack>
#include<deque>
#include<queue>
#include<map>
#include<set>
using namespace std;
typedef long long LL;
const int MOD = 1e9 + 7;
const int maxn = 1e6 + 10;
LL fac[maxn];               //存储阶乘
int main(void) {
	void init();
	init();
	LL Com2(LL n,LL m);
	int x,y;
	scanf("%d%d",&x,&y);
	bool flag = false;
	LL k,t;
	for(int i = 0; i <= x; i ++) {           // i是可以为 0 的
		if(2 * y - 3 * i == x) {             // 这里注意不要搞混 
			t = y - 2 * i;
			k = i;
			flag = true;
			break;
		}
	}
	if(flag)
		printf("%lld\n",Com2(k + t,k));
	else
		printf("0\n");
	return 0;
}

// 预处理阶乘 (注意取余)

void init() {
	fac[0] = 1;
	for(LL i = 1; i < maxn; i ++) {
		fac[i] = fac[i - 1] * i % MOD;
	}
	return;
}
 
//扩展欧几里得 

LL exgcd(LL a,LL b,LL &x, LL &y) {
	if(!b) {
		x = 1;
		y = 0;
		return a;
	}
	LL d = exgcd(b,a%b,x,y);
	LL z = x;
	x = y, y = z - a / b * y;
	return d;
}
LL inv(LL a,LL mod) {
	LL x,y;
	exgcd(a,mod,x,y);
	return (x % mod + mod) % mod;  // 这里是 求解的 x 就是 a 的逆元 (x % mod 是为了防止出现负数)
}
LL Com1(LL n,LL m) {
	// 除以一个数再取模等同于乘以这个数的逆元再取模 
	return fac[n] % MOD * inv(fac[m] * fac[n - m] % MOD,MOD) % MOD;  // 乘法逆元 
}

// 快速幂 + 费马小定理(求逆元)

LL quick_pow_mod(LL a,LL b) {
	LL ans = 1;
	while(b) {
		if(b & 1) ans = ans * a % MOD;
		a = a * a % MOD;
		b >>= 1; 
	}
	return ans;
} 
LL Com2(LL n,LL m) {
	return fac[n] * quick_pow_mod( (fac[m] % MOD * fac[n - m] % MOD),MOD - 2) % MOD;
}

Measured memory_bytes: 8064
#include <iostream>
#include <vector>
#include <algorithm>
#include <ctime>
#include <cmath>
#include <string>
#include <stdlib.h>
#include <fstream>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <iterator>
#include <iomanip>
using namespace std;

const int MAXN = 1e5;

struct FndUn{
    int sz[MAXN], p[MAXN];
    
    void MakeSet(int x){
        p[x] = x;
        sz[x] = 1;
    }

    int Find(int x){
        if(p[x] != x) p[x] = Find(p[x]);
        return p[x];
    }

    void Union(int x, int y){
        x = Find(x), y = Find(y);
        if(sz[x] > sz[y]) swap(x, y);
        if(p[x] == y || p[y] == x) return;
        p[x] = y;
        sz[y] += sz[x];
    }
};

int main(){
    long long n, m;
    cin >> n >> m;
    vector<long long> a(n);
    for(int i = 0; i < n; ++i){
        cin >> a[i];
        a[i]--;
    }
    FndUn f;
    for(int i = 0; i < n; ++i) f.MakeSet(i);
    long long m1, m2;
    for(int i = 0; i < m; ++i){
        cin >> m1 >> m2;
        m1--, m2--;
        f.Union(m1, m2);
    }
    long long ans = 0;
    for(int i = 0; i < n; ++i){
        if(f.Find(a[i]) == f.Find(i)) ans++;
    }
    cout << ans;
}

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

int kaizyou(int n){
    if(n<=1){
        return 1;
    }
    else{
        return( n* kaizyou(n-1));
    }
}

int main() {
    int N;
    cin >> N;
    vector< pair<int,int> > vec(N);
    for(int i=0; i<N; i++){
        cin >> vec.at(i).first;
        cin >> vec.at(i).second;
        // cout << i << ":" << vec.at(i).first << " " << vec.at(i).second << endl; 
    }
    // cout << endl;
    vector<int> perm(N);
    for(int i=0; i<N; i++){
        perm.at(i) = i+1;
        // cout << perm.at(i) << endl;
    }
    double sum =0;
    do{
        for(int i=0; i<N-1; i++){
            int niten = 0;
            niten += pow(vec.at(perm.at(i+1)-1).first - vec.at(perm.at(i)-1).first ,2);
            niten += pow(vec.at(perm.at(i+1)-1).second - vec.at(perm.at(i)-1).second ,2);
            sum += sqrt(niten);

        }
        // cout << sum << endl;
    }while(next_permutation(perm.begin(),perm.end()));

    // cout << "N!=" << kaizyou(N) << endl;

    cout << fixed << setprecision(8) << sum / kaizyou(N) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,a,b,c,d;
  cin >> N;
  a=N/1000;
  b=(N/100)%10;
  c=((N/10)%100)%10;
  d=N-a*1000-b*100-c*10;
  if((a == b && b == c)||(b == c && c == d)) cout << "Yes" << endl;
  else cout << "No" << endl;
}
  
  

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(int i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(int i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define uniq(x) (x).erase(unique((x).begin(), (x).end()), (x).end())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n;
    cin >> n;
    vector<int> a(n);
    double ave;
    double mv = INT_MAX, mi = 0;
    
    rep(i, n) {
        cin >> a[i];
        ave += a[i];
    }
    
    ave = accumulate(all(a), 0) / (double)n;
    
    rep(i, n) {
        double d = abs(ave - a[i]);
        
        if (mv > d) {
            mv = d;
            mi = i;
        }
    }
    
    cout << mi << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <string>
#include <cctype>

using namespace std;

int main() {
	string s;
	cin >> s;
	bool ok = s[0] == 'A';

	int idx_c = -1;
	for (int i = 2; i <= s.size() - 2; i++) {
		if (s[i] == 'C') {
			idx_c = i;
			break;
		}
	}
	if (idx_c < 0) {
		ok = false;
	}

	for (int i = 1; i < s.size(); i++) {
		if (i == idx_c) {
			continue;
		}

		if (isupper(s[i])) {
			ok = false;
			break;
		}
	}

	cout << (ok ? "AC": "WA") << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const long long mod = 1e9+7;
long long power(long long a, long long b, long long m = mod) {
    if(b < 0) {
        return power(power(a, -b), mod-2);
    }
    long long x = 1;
    while(b) {
        if(b & 1) {
            x = 1ll * x * a % m;
        }
        a = 1ll * a * a % m;
        b /= 2;
    }
    return x;
}
const int N = 2e5+9;
ll f[N], pre[N];
signed main() {  
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    
    int n, p;
    cin >> n >> p;
    string s; cin >> s;
    ll ans = 0;
    if(p != 2 && p != 5) {
        reverse(s.begin(), s.end());
        int x = 1;
        for(int i = 1; i <= n; i++) {
            pre[i] = (pre[i-1] + (s[i-1]-'0')*x%p)%p;
            // pre[i] %= p;
            // cout << pre[i] << " ";
            x = x*10%p;
        }
        // cout << endl;
        f[0] = 1;
        for(int i = 1; i <= n; i++) {
            ans += f[pre[i]];

            f[pre[i]]++;
        }
        
    } else {
        for(int i = 1; i <= n; i++) {
            int d = s[i-1] - '0';
            if(d % p == 0) {
                ans += i;
            }
        }
        
    } 
    cout << ans << "\n";








    return 0;
    
}

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

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

    int n, h, w;
    cin >> h >> w >> n;
    cout << (h < w ? (n + w - 1) / w : (n + h - 1) / h) << '\n';
}

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

  rep(i,n) {
    ans += (n-1)/(i+1);
  }
  
  cout << ans << endl;
}

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

class Main {

	public static void main(String[] args) throws Exception {
		final Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		int[] p = new int[(int) (N)];
		for (int i = 0; i < N; i++) {
			p[i] = sc.nextInt();
		}

		double a = 0;
		for (int i = 0; i < K; i++) {
			a += p[i] + 1;
		}
		double answer = a;

		for (int i = K; i < N; i++) {
			a -= p[i - K] + 1;
			a += p[i] + 1;
			answer = Math.max(a, answer);
		}

		System.out.println(answer / 2.0);
	}
}


Measured memory_bytes: 64896
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = (a); i <= int(b); i++)
#define per(i, a, b) for (int i = (a); i >= int(b); i--)
#define fir first
#define sec second
#define tct template<class type>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
const int maxn = 2e5, maxm = 1 << 19, mod = 1e9 + 7;
int n, p[maxn + 5], a[maxn + 5], cnt[maxn + 5];
char s[maxn + 5];

inline void red(int &x) { x += x >> 31 & mod; }
tct inline void cmax(type &x, type y) { x < y ? x = y : 0; }
tct inline void cmin(type &x, type y) { x > y ? x = y : 0; }

struct tree {
	int mx[maxm + 5];
	#define ls (x << 1)
	#define rs (ls | 1)
	#define mid ((l + r) >> 1)
	void upd(int x) {
		mx[x] = max(mx[ls], mx[rs]);
	}
	void build(int x, int l, int r) {
		mx[x] = -1e9;
		if (l == r) return;
		build(ls, l, mid), build(rs, mid + 1, r);
	}
	void modify(int x, int l, int r, int y, int z) {
		if (l == r) return mx[x] = z, void();
		y <= mid ? modify(ls, l, mid, y, z) : modify(rs, mid + 1, r, y, z);
		upd(x);
	}
	int query(int x, int l, int r, int lx, int rx) {
		if (l >= lx && r <= rx) return mx[x];
		int y = -1e9;
		if (lx <= mid) cmax(y, query(ls, l, mid, lx, rx));
		if (rx > mid) cmax(y, query(rs, mid + 1, r, lx, rx));
		return y;
	}
} odd, eve;

bool check(int x, int y) {
	if (y < 0) return false;
	if (y & 1) return odd.query(1, 1, n, x, n) >= y;
	return eve.query(1, 1, n, x, n) >= y;
}

int main() {
	scanf("%d", &n);
	for (int i = 1, x = 0; i <= n; i++) {
		scanf("%d", &p[i]);
		if (x < p[i]) a[i] = 1, x = p[i];
	}
	odd.build(1, 1, n);
	per(i, n, 1) {
		int x = odd.query(1, 1, n, p[i], n), y = eve.query(1, 1, n, p[i], n);
		if (a[i]) odd.modify(1, 1, n, p[i], x + 2), eve.modify(1, 1, n, p[i], y + 2);
		else odd.modify(1, 1, n, p[i], y + 1), eve.modify(1, 1, n, p[i], x + 1);
	}
	per(i, n, 1) cnt[i] = cnt[i + 1] + a[i];
	int xc = 0, yc = 0, xm = 0, ym = 0;
	rep(i, 1, n) {
		odd.modify(1, 1, n, p[i], -1e9), eve.modify(1, 1, n, p[i], 0);
		int nxc = xc + (p[i] > xm);
		if (check(ym, nxc + cnt[i + 1] - yc) || check(max(xm, p[i]), yc + cnt[i + 1] - nxc)) {
			s[i] = '0', xc += p[i] > xm, xm = max(xm, p[i]);
		} else {
			s[i] = '1', yc += p[i] > ym, ym = max(ym, p[i]);
		}
	}
	if (xc != yc) puts("-1"), exit(0);
	puts(s + 1);
	return 0;
}

Measured memory_bytes: 10300
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a),i##formax=(b);i<i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formax=(b);i>=i##formax;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)
#define show(x) cout<<#x<<" = "<<x<<endl;
#define all(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))
#define uniq(v) sort(all(v));v.erase(unique(all(v)), v.end());
#define bit(n) (1LL<<(n))
#define randInt(l,r) (uniform_int_distribution<ll>(l,r)(rnd))
#define randDouble(l,r) (uniform_real_distribution<double>(l,r)(rnd))

typedef long long ll;
typedef __int128_t lll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>ostream& operator<<(ostream& o,const pair<T,Y>& p){return o<<"("<<p.fi<<", "<<p.se<<")";}
template<class T>ostream& operator<<(ostream& o,const vector<T>& v){for(T t:v) o<<t<<", ";return o<<endl;}
template<class T>ostream& operator<<(ostream& o,const set<T>& s){each(i,s) o<<*s<<", ";return o<<endl;}
template<typename A,size_t N,typename T>void Fill(A (&array)[N],const T&v){fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll gcd(ll a,ll b){lll x=0,y=0;return gcd(a,b,x,y);}
ll modPow(lll a,lll n,ll m){if(!a)return a;lll p=1;for(;n>0;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
bool isPrime(ll n){if(n<2||n%2==0)return n==2;lll t=n-1,d=t/(t&-t);for(lll a:{2,325,9375,28178,450775,9780504,1795265022})if(a%n){for(t=d,a=modPow(a,t,n);t!=n-1&&a!=1&&a!=n-1;a=a*a%n,t=t*2%n);if(a!=n-1&&t%2==0)return 0;}return 1;}
void dout(double d){printf("%.12f\n",d);}
const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7;
const double PI = acos(-1);
const double EPS = 1e-10;
static random_device rd;
static mt19937 rnd(rd());

const int N = 40;
ll n, k, any[N+1], c[N];
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> k;
  FOR(i, 0, n){
    ll a;
    cin >> a;
    FOR(j, 0, N){
      if(a&1) c[j]++;
      a >>= 1;
    }
  }
  FOR(i, 0, N) any[i+1] = any[i] + bit(i)*max(n-c[i], c[i]);
  ll t = 0, ans = 0;
  FORR(i, N-1, 0){
    if(k & bit(i)){
      maxs(ans, t + bit(i)*c[i] + any[i]);
      t += bit(i)*(n-c[i]);
    }else{
      t += bit(i)*c[i];
    }
  }
  cout << max(ans, t) << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    int t, i, j;
    scanf("%d", &t);

    int n[t];
    for (i = 0; i < t; i++)
    {
        scanf("%d", &n[i]);
    }
    for (i = 0, j = 0; i < t; i++)
    {
        if (n[i] % 2 == 0)
        {
            n[j++] = n[i];
        }
    }
    int count = 0;
    for (i = 0; i < j; i++)
    {
        if (n[i] % 3 == 0 || n[i] % 5 == 0)
            count++;
    }
    if (count == j)
        printf("APPROVED\n");
    else
        printf("DENIED\n");

    return 0;
}

Measured memory_bytes: 128
require 'pp'

# 空白区切の入力値を数値の配列で返却する
def gets_i_list()
  gets.chomp.split(" ").map(&:to_i)
end

b = []
b.push(gets_i_list)
b.push(gets_i_list)
b.push(gets_i_list)

b.each_with_index do |row, i|
  b1,  b2,  b3  = row
  bb1, bb2, bb3 = b[i - 1]

  if b1-bb1 == b2-bb2 && b2-bb2 == b3-bb3 && b1-bb1 == b3-bb3
  else
    puts "No"
    exit
  end
end
puts "Yes"


Measured memory_bytes: 2300
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <numeric>
#include <climits>
#include <math.h>
#include <memory.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, k, n) for(int i = (k); i < (int)(n); i++)
using namespace std;
using ll = long long;
int N, M;
int cnt = 0;
ll ans = 0LL;
int i_index;
int dh[4] = {1, 0, -1, 0};
int dw[4] = {0, 1, 0, -1};
string board[64];
int main(){
    string s;
    int K;
    cin >> s >> K;
    int len = (int)s.length();
    set<string> st;

    rep(i, len){
        string t;
        for(int j = i; j < len; j++){
            if((int)t.length() > K) break;
            t += s[j];
            st.insert(t);
        }
    }
    int cnt = 0;
    for(auto i: st){
        cnt++;
        if(cnt == K){
            cout << i << endl;
            return 0;
        }
    }
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef long double ld;
typedef vector<ld> vd;
typedef bool bl;
typedef vector<bl> vb;
typedef unordered_map<ll,unordered_map<ll,ll>> graph;

const ll e5 = 1 << 20;
const ll mod = 1000000007;
const ll e3 = 1 << 13;
const ll INF = 1ll << 60;


ll q;
priority_queue<ll> pq;
priority_queue<ll,vl,greater<ll>> qp;
ll r,l;
ll mem;


int main(){
  cin >> q;
  for(ll i = 0;i < q;i++){
    ll x;
    cin >> x;
    if(x == 1){
      ll a,b;
      cin >> a >> b;
      pq.push(a);
      r += a;
      mem += b;
      r -= pq.top();
      l += pq.top();
      qp.push(pq.top());
      pq.pop();
      l -= qp.top();
      r += qp.top();
      pq.push(qp.top());
      qp.pop();

      if(pq.size()-qp.size() > 1){
        qp.push(pq.top());
        l += pq.top();
        r -= pq.top();
        pq.pop();
      }
    }else{
      ll a = pq.top();
      ll ans = a*pq.size()-r+l-a*qp.size()+mem;
      cout << a << " " << ans << endl;
    }
  }
}


Measured memory_bytes: 3828
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
#define dbg(x) cerr << #x << ": " << x << endl
int main() {
  int t[2];
  cin >> t[0] >> t[1];
  ll a[2], b[2];
  cin >> a[0] >> a[1];
  cin >> b[0] >> b[1];

  if(a[0] < b[0]) {
    swap(a[0], b[0]);
    swap(a[1], b[1]);
  } else if(a[0] == b[0]) {
    cout << "infinity" << endl;
    return 0;
  }

  ll c[2] = {a[0] - b[0], a[1] - b[1]};
  ll d[2] = {c[0] * t[0], c[1] * t[1]};

  if(0 < d[0] + d[1]) {
    cout << 0 << endl;
    return 0;
  }

  if(d[0] == -d[1]) {
    cout << "infinity" << endl;
    return 0;
  }

  ll dx = -d[1] - d[0];
  ll ans = 1;
  ans += 2 * (d[0] / dx);
  if(d[0] % dx == 0) ans--;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
    int n, l; cin >> n >> l;
    string s[n];
    for (int i=0;i<n;++i) {
        cin >> s[i];
    }
    sort(s,s+n);
    string ans;
    for (int i=0;i<n;++i){
        ans += s[i];
    }
    cout << ans << endl;
}

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

using namespace std;

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

	int sz = s.size(), a = -1, b = 1;
	while (++b < sz) {
		char c = s[a = b];
		if (s[--a] == c || s[--a] == c) break;
	}
	if (b >= sz)
		if (sz >= 2 && s[0] == s[1]) cout << "1 2";
		else cout << "-1 -1";
	else cout << (a + 1) << " " << (b + 1);
	cout << endl;
}


Measured memory_bytes: 512
<?php
fscanf(STDIN, "%d %d %d",  $A, $B, $C);
$ans = "NO";
for($i=1;$i<=$B;$i++){
    $rem = ($A*$i) % $B;
    if($rem == $C){
        $ans = "YES";
        break;
    }
}
echo $ans;

Measured memory_bytes: 4604
import sys
from networkx import*
i=sys.stdin.readline
m=10**15
N,M,S,T=map(int,i().split())
G=Graph()
G.add_nodes_from(range(1,N+1))
for _ in range(M):
  u,v,a,b=map(int,input().split())
  G.add_edge(u,v,y=a,s=b)
y=single_source_dijkstra_path_length(G,S,weight='y')
s=single_source_dijkstra_path_length(G,T,weight='s')
a=[m]*(N+1)
for j in range(N,0,-1):
  a[j-1]=min(a[j],y[j]+s[j])
for x in a[:N]:
  print(m-x)

Measured memory_bytes: 186608
#include<algorithm>
#include<iostream>
#include<cstring>
#include<fstream>
#include<bitset>
#include<cstdio>
#include<string>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<set>
#define INF 0X3F3F3F3F
#define N 100005
#define M 200005
#define LL long long
#define ULL unsigned long long
#define FF(i, a, b) for(int i = a; i <= b; ++i)
#define RR(i, a, b) for(int i = a; i >= b; --i)
#define FJ(i, a, b) for(int i = a; i < b; ++i)
#define SC(x) scanf("%d", &x)
#define SCC(x, y) scanf("%d%d", &x, &y)
#define SCCC(x, y, z) scanf("%d%d%d", &x, &y, &z)
#define SS(x) scanf("%s", x)
#define PR(x) printf("%d\n", x)
#define CL(a, x) memset(a, x, sizeof(a))
#define _P fd[rt]
#define _L fd[rt << 1]
#define _R fd[rt << 1 | 1]
#define MID int mid = ((l + r) >> 1)
#define lson rt<<1 ,l, mid
#define rson rt<<1 | 1, mid + 1, r
#define VI vector<int>
#define db double
#define PII pair<int, int>
#define PLL pair<unsigned long long, unsigned long long>
#define MP make_pair
#define PB push_back
#define IN freopen("in.txt", "r", stdin)
#define OUT freopen("out.txt", "w", stdout)
using namespace std;
const int MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-8;
const int dir[4][2] = {{-1, 0}, {0, -1}, {0, 1}, {1, 0}};
inline void II(int &n){char ch = getchar(); n = 0; bool t = 0;
for(; ch < '0'; ch = getchar()) if(ch == '-') t = 1;
for(; ch >= '0'; n = n * 10 + ch - '0', ch = getchar()); if(t) n =- n;}
inline void OO(int a){if(a < 0) {putchar('-'); a = -a;}
if(a >= 10) OO(a / 10); putchar(a % 10 + '0');}
inline int sgn(double x){return (x > EPS) - (x < -EPS);}
struct EE{int v, w, nx;}E[M * 2 + N * 2]; int hd[N], EN;
void init_edge(int num){EN = 0; memset(hd, -1, (num + 2) << 2);}
void add_edge(int u, int v, int w){
    E[EN].w = w; E[EN].v = v; E[EN].nx = hd[u]; hd[u] = EN++;
    E[EN].w = w; E[EN].v = u; E[EN].nx = hd[v]; hd[v] = EN++;
}
int n, a, b, c;
int main(){
    //IN;
    SC(n);
    int x = n;
    int sum = 0;
    while(x){
        sum += x % 10;
        x /= 10;
    }
    if(n % sum == 0) puts("Yes");
    else puts("No");
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main(void){
    char a[100],b[100];
    int i,n,da,db,carry,ans[100];
    
    scanf("%d",&n);
    while(n--){
        scanf("%s %s",a,b);
        if(strlen(a)>80 || strlen(b)>80){
            puts("overflow");
            continue;
        }
        da=strlen(a);
        db=strlen(b);
       // puts(a);
       // puts(b);

        i=0;
        carry=0;
        while(da>0 || db>0){
            ans[i]=carry;
            if(da>0) ans[i]+=a[da-1] - '0';
            if(db>0) ans[i]+=b[db-1] - '0';
            carry=ans[i]/10;
            ans[i]%=10;
            da--;db--;i++;
            //printf("%d %d %d %d\n",da,db,a[i],carry);
        }
        
        if(carry) ans[i]=1;
        else i--;
        
        if(i>=80){
            puts("overflow");
            continue;
        }
        
        for(;i>=0;i--){
            printf("%d",ans[i]);
        }
            puts("");
        
    }
    
    return 0;
}

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

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

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

    ll N,M; cin >> N >> M;

    ll l = 1, r = N;
    map<ll,bool>  st;

    for (int i = 0;i < M;i++){
        while(st[r-l] || st[N-(r-l)] || r-l == N-(r-l)) l++;
        
            cout << l << " " << r << endl;
            st[r-l] = true; st[N-(r-l)] = true;
            l++;r--;
        
    }

    /*if(N%2 == 0){
        cout << 1 << " " << N-1 << endl;
        for (int i = 1;i < M;i++){
            cout << 1+i << " " << N-2-i << endl;
        }
    }else{
        for (int i = 0;i < M;i++){
            cout << i+1 << " " << N-1-i << endl;
        }
    }*/

    return 0;

}

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

#define ff              first
#define ss              second
#define ll             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<ll,ll>
#define vi              vector<ll>
#define mii             map<ll,ll>
#define pqb             priority_queue<ll>
#define pqs             priority_queue<ll,vi,greater<ll> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            ll x; cin>>x; while(x--)
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define mx 3000
ll n,m;

int main()
{
    FIO;
    ll c,d,e,f=0,sum=0,ck,k,p,q,r,t,add=0,w,x,y,z;

    cin>>n>>m;
    c=n*2;
    d=n*4;
    if(m%2!=0)cout<<"No"<<endl;
    else{
        if(m>=c && m<=d){
            cout<<"Yes"<<endl;
        }
        else{
            cout<<"No"<<endl;
        }
    }


    return 0;
}




Measured memory_bytes: 3648
from math import factorial
import sys

x, y = map(int, input().split())

maxim = 10**6+10
mod = 10**9 + 7

fac = [None] * maxim
finv = [None] * maxim
inv = [None] * maxim

def cominit():
    fac[0], fac[1] = 1, 1
    finv[0], finv[1] = 1, 1
    inv[1] = 1

    for i in range(2, maxim):
        fac[i] = fac[i-1] * i % mod
        inv[i] = mod - inv[mod % i] * (mod // i) % mod
        finv[i] = finv[i-1] * inv[i] % mod

def com(n, k):
    if (n < k):
        return 0
    if (n < 0 or k < 0):
        return 0
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod


def main():
    if (x + y) % 3 != 0:
        return 0
    else:

        b = (2*y - x) // 3 
        a = b + x -y
        if a < 0 or b < 0:
            print(0)
            sys.exit()
        
        cominit()
        ans = com(a+b, b)
        return ans 
    # answer = (a+b)! / a!b! mod 10^9+7


    
print(main())

# 999999 999999

Measured memory_bytes: 101980