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

#define pii pair<int, int>
#define mp make_pair

const int maxN = 305, mod = 1e9 + 7;

int n, m;
int f[maxN + 1][maxN + 1][maxN + 1];

vector<pii> q[maxN + 1];

inline void update(int &x, int y) { x = x + y >= mod ? x + y - mod : x + y; }

inline bool check(int x, int a, int b, int c)
{
	for(int i = 0; i < q[x].size(); i++)
	{
		int p = q[x][i].first;
		if((a >= p) + (b >= p) + (c >= p) != q[x][i].second) return false;
	}
	return true;
}

int main()
{
	scanf("%d %d", &n, &m);
	for(int i = 1; i <= m; i++)
	{
		int x, y, t;
		scanf("%d %d %d", &x, &y, &t);
		q[y].push_back( mp(x, t) );
	}

	f[0][0][0] = 1;
	for(int i = 0; i <= n; i++)
		for(int j = 0; j <= n; j++)
			for(int k = 0; k <= n; k++)
			{
				if(!f[i][j][k]) continue;
				int r = max(i, max(j, k)), res = f[i][j][k];
				bool f1 = true, f2 = true, f3 = true;
				for(int t = 0; t < q[r + 1].size(); t++)
				{
					int p = q[r + 1][t].first, w = q[r + 1][t].second - 1;
					if((j >= p) + (k >= p) != w) f1 = false;
					if((i >= p) + (k >= p) != w) f2 = false;
					if((i >= p) + (j >= p) != w) f3 = false;
				}
				if(f1) update(f[r + 1][j][k], res);
				if(f2) update(f[i][r + 1][k], res);
				if(f3) update(f[i][j][r + 1], res);
			}
	
	int ans = 0;
	for(int i = 0; i < n; i++)
		for(int j = 0; j < n; j++)
		{
			update(ans, f[n][i][j]);
			update(ans, f[i][n][j]);
			update(ans, f[i][j][n]);
		}
	
	printf("%d\n", ans);
	return 0;
}


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

int main() {
  int A, B;
  int N, ans;
  ans = 0;
  cin >> A >> B;
  for (A; A < B + 1; A++) {
    if ((A / 10000 == A % 10) && (A / 1000 % 10 == A / 10 % 10)) {
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#ifdef __GNUC__
#pragma GCC target("avx2")
#pragma GCC optimize ("O20")
#pragma GCC optimize ("tree-vectorize")
#pragma GCC optimize("unroll-loops")
#define iss std::cin
#endif
#include "bits/stdc++.h"
#define rep(i, times) for(ll i = 0; i < (times); ++i)
#define p(x) (cout << x << "\n")
using ll = long long; using ld = long double; using namespace std;

class Switches
{
	ll N{0}, M{0}, allS{0}, cnt{0};
	vector<vector<ll>> s;
	vector<ll> p;
	void inp( ) {
		iss >> N >> M;
		s.resize(M);
		rep(m, M) {
			ll K; iss >> K;	s[m].resize(K);
			rep(k, K) { iss >> s[m][k]; }
		}
		p.resize(M); rep(m, M) { iss >> p[m]; }
	}
	inline ll Non(ll m) {//m番目の電球につながっているスイッチでonのものの個数
		ll con{0};
		for (auto &p : s[m]) {// m番目の電球につながっているp番目のスイッチ
			if ((allS >> (p - 1)) & 1) ++con; //スイッチpがonかどうか
		}
		return con;
	}
	inline bool light(ll m) {//m番目の電球がつくか？
		return ((Non(m) % 2) == p[m]);
	}
	inline bool allonQ( ) {//全部の電球がつくか
		rep(m, M) { if (!light(m)) return false; }
		return true;
	}
	void changeSwitch( ) {
		for (ll b = 0; b < ll(1 << N); ++b) {
			allS = b;//スイッチの状態を変える
			if (allonQ( )) ++cnt;
		}
	}
public:
	void procedures( ) {
		inp( );
		changeSwitch( );
		p(cnt);
	}
};

int main( ) {
	cin.tie(0);	ios::sync_with_stdio(0);
	class Switches a; a.procedures( );
}

Measured memory_bytes: 3640
#!/usr/bin/env python3

#import
#import math
#import numpy as np
n = int(input())
V = list(map(int, input().split()))

even = {0:0}
odd = {0:0}

for i in range(n):
    v = V[i]
    if i % 2 == 0:
        if v in even:
            even[v] += 1
        else:
            even[v] = 1
    else:
        if v in odd:
            odd[v] += 1
        else:
            odd[v] = 1

omax = 0
emax = 0
onext = 0
enext = 0

for e in even:
    if even[e] > even[emax]:
        if even[emax] > even[enext]:
            enext = emax
        emax = e
    elif even[e] > even[enext]:
        enext = e

for o in odd:
    if odd[o] > odd[omax]:
        if odd[omax] > odd[onext]:
            onext = omax
        omax = o
    elif odd[o] > odd[onext]:
        onext = o

if omax != emax:
    print(n - even[emax] - odd[omax])
else:
    print(n - even[emax] - odd[omax] + min(even[emax] - even[enext], odd[omax] - odd[onext]))


Measured memory_bytes: 22860
#include<iostream>
#include<iomanip>
#include<cstdlib>
#include<stdio.h>
#include<time.h>
#include<math.h>
#include<algorithm>
#include<string>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<deque>
#include<set>
#include<map>
#define REP(i, N) for(ll i = 0; i < N; ++i)
#define FOR(i, a, b) for(ll i = a; i < b; ++i)
#define ALL(a) (a).begin(),(a).end()
#define pb push_back
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int qx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
int qy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

int main(void) {
	int n;
	cin>>n;
	REP(i, n){
		int y, m, d;
		cin>>y>>m>>d;
		ll ans = 0;
		ans += 195 * (y - 1) + (y - 1) / 3 * 5;
		if(m % 2 == 1) {
			ans += (m - 1) / 2 * 39;
			if(y % 3 == 0) {
				ans += (m - 1) / 2;
			}
		} else {
			ans += m / 2 * 20 + (m / 2 - 1) * 19;
			if(y % 3 == 0) {
				ans += m / 2 - 1;
			}
		}
		ans += d;
		cout<<196471 - ans<<endl;
	}
}

Measured memory_bytes: 3104
#!/usr/bin/env python3

# N = int(input())
S = input()
T = input()

# N, K = map(int, input().split())
# A = list(map(int, input().split()))

if len(T) < len(S):
    print("No")
    exit()

for i in range(len(S)):
    if S[i] != T[i]:
        print("No")
        exit()
if len(T) == len(S) + 1:
    print("Yes")
else:
    print("No")
    

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

#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,ans=0,num=0;
    cin>>n;
    ll a[n];
    for(ll i=0;i<n;i++) {cin>>a[i];a[i]-=i;}
    sort(a,a+n);
    if(n%2==0){
        ll b=n/2,c=b-1;

        for(int i=0;i<n;i++){
            num+=abs(a[i]-a[b]);
        }
        for(int i=0;i<n;i++){
            ans+=abs(a[i]-a[c]);
        }
        ans=min(ans,num);
    }
    else{
        ll b=n/2;
        for(int i=0;i<n;i++){
            ans+=abs(a[i]-a[b]);
        }
    }
    cout << ans<<endl;
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define itn int
#define REP(i, n) for (int i = 0; i < (n); i++)
#define IREP(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, k, n) for (int i = (k); i < (n); i++)
#define REPEACH(itr, k) for (auto &&itr : k)
#define MOD 1000000007

using namespace std;
typedef long long ll;

const ll INF = 1LL << 60;


int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    set<int> s;
    REP(i,n){
        cin >> a[i];
        s.insert(a[i]);
    }
    if(s.size()%2==0){
        cout << s.size()-1 << endl;
    }
    else{
        cout << s.size() << endl;
    }
}

Measured memory_bytes: 5376
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

void rotate(char& c, int k) {
	while (k--) {
		if (c == 'A') c = 'z';
		else if (c == 'a') c = 'Z';
		else c--;
	}
}

int main() {
	for (;;) {
		int n; cin >> n;
		if (n == 0) break;
		vector<int> k(n);
		for (int i = 0; i < n; i++) cin >> k[i];
		string s; cin >> s;
		for (int j = 0; j < s.length(); j++)
			rotate(s[j], k[j % n]);
		cout << s << endl;
	}
}

Measured memory_bytes: 1208
import java.io._
import scala.io.StdIn.{readInt, readLine}

object Main {
  val out:BufferedWriter =
    new BufferedWriter(new OutputStreamWriter(new FileOutputStream(java.io.FileDescriptor.out), "ASCII"), 512)
  var count = 0
  class Node(var key:Int, var left:Node = null, var right:Node = null) { }

  def insert(tree:Node, key:Node) = {
    val keyNode = key
    def getNodeToInsert(node:Node):Node =
      if(node.key > keyNode.key) {
        if(node.left == null) node
        else getNodeToInsert(node.left)
      } else {
        if(node.right == null) node
        else getNodeToInsert(node.right)
      }

    val target = getNodeToInsert(tree)

    if(keyNode.key < target.key) target.left = keyNode
    else target.right = keyNode
  }

  def inOrder(tree:Node):Unit =
    if(tree == null) return
    else {
      inOrder(tree.left)
      out.write(" ")
      out.write(tree.key.toString)
      if(count<100) count += 1
      else {
        out.flush
        count = 0
      }
      inOrder(tree.right)
    }

  def preOrder(tree:Node):Unit =
    if(tree == null) return
    else {
      out.write(" ")
      out.write(tree.key.toString)
      if(count<100) count += 1
      else {
        out.flush
        count = 0
      }
      preOrder(tree.left)
      preOrder(tree.right)
    }

  def main(args:Array[String]) = {
    val n = readInt
    val tree = new Node(-1)

    for(i<-0 until n) {
      val s = readLine.split(" ")
      s(0) match {
        case "insert" =>
          if(tree.key == -1) tree.key = s(1).toInt
          else insert(tree, new Node(s(1).toInt))
        case _ => {
          inOrder(tree)
          out.write("\n")
          out.flush()
          preOrder(tree)
          out.write("\n")
          out.flush()
        }
      }
    }
  }
}

Measured memory_bytes: 285876
main::IO()
main = do
    _ <- getLine
    n <- map read . words <$> getLine
    putStrLn $ if check n then "APPROVED" else "DENIED"
    
check (x:xs) = if even x 
                 then if ((x `mod` 3 == 0) || (x `mod` 5 ==0))
                         then check xs
                         else False
                 else check xs
check [] = True

Measured memory_bytes: 4132
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		long n = Long.parseLong(scn.next());
		long kaisuu = n / 11 * 2;

		if (n % 11 != 0) {
			if (n % 11 > 6) {
				kaisuu += 2;
			} else {
				kaisuu++;
			}
		}
		scn.close();
		System.out.println(kaisuu);
	}
}


Measured memory_bytes: 23124
N = int(input())
S = []
for i in range(N):
    S.append(input())
T = []
M = int(input())
for i in range(M):
    T.append(input())
res = 0
for i in range(N):
    temp = S.count(S[i])-T.count(S[i])
    if res < temp:
        res = temp
print(res)

Measured memory_bytes: 38384
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define lol(i,n) for(ll i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;

using namespace std;
#define N 410
#define M 100010
ll n,m,x[M],y[M];
bool t[N][N],ok[N];
int main(){
    cin>>n>>m;
    for(ll i=m-1;~i;i--){
	cin>>x[i]>>y[i];
	x[i]--,y[i]--;
    }
    lol(i,n){
	lol(j,n)t[i][j]=0;
	t[i][i]=1;
	ok[i]=1;
	lol(j,m){
	    bool sx=t[i][x[j]],sy=t[i][y[j]];
	    if(sx==1&&sy==1)ok[i]=0;
	    if(sx==0&&sy==0)continue;
	    if(sx)t[i][y[j]]=1;
	    if(sy)t[i][x[j]]=1;
	}
    }
    ll ans=0;
    lol(i,n)lol(j,i){
	if(ok[i]==0||ok[j]==0)continue;
	bool cad=1;
	lol(k,n)if(t[i][k]&t[j][k])cad=0;
	ans+=cad;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1920
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>

using namespace std;

typedef long long ll;

int main(){

    int X, Y;

    cin >> X >> Y;

    for (int i = 0; i <= X; i++) {
        if (Y == i * 2 + (X - i) * 4) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <iomanip>

int main()
{
    int k,n,ind=0;
    std::cin>>n>>k;
    std::vector<int> p(n);
    for (int i=0; i<n; i++) std::cin>>p[i];
    double max_sum=0,sum=0,first;
    first=1.0*p[0]*(p[0]+1)/2/p[0];
    for (int i=0; i<k; i++)
    {
        sum+=1.0*p[i]*(p[i]+1)/2/p[i];
    }
    max_sum=sum;
    for (int i=k; i<n; i++)
    {
        sum-=first;
        first=1.0*p[++ind]*(p[ind]+1)/2/p[ind];
        sum+=1.0*p[i]*(p[i]+1)/2/p[i];
        if (sum>max_sum) max_sum=sum;
    }
    std::cout << std::setprecision(10) << std::fixed << max_sum;
    return 0;
}


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

int main()
{
    int N, M, X;
    cin >> N >> M >> X;

    int C[N];
    int A[N][M];
    for (int i = 0; i < N; i++) {
        cin >> C[i];
        for (int j = 0; j < M; j++) {
            cin >> A[i][j];
        }
    }

    int ans = INT_MAX;
    for (int bit = 0; bit < (1 << N); bit++) {
        int sumAmount = 0;
        int sumSkill[M] = {0};
        for (int i = 0; i < N; i++) {
            if (bit & (1 << i)) {
                sumAmount += C[i];
                for (int j = 0; j < M; j++) {
                    sumSkill[j] += A[i][j];
                }
            }
        }
        bool flg = true;
        for (int i = 0; i < M; i++) {
            if (sumSkill[i] < X) {
                flg = false;
                break;
            }
        }
        if (flg) {
            ans = min(ans, sumAmount);
        }
    }

    if (ans == INT_MAX) {
        cout << -1 << endl;
    }
    else {
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3552
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = Integer.parseInt(sc.next());
		int[] a = new int[n];

		for (int i = 0; i < n; i++) {
			a[Integer.parseInt(sc.next())]++;
		}

		long ans = 1;
		boolean flag = false;
		for (int i = 0; i < n; i++) {
			if (n % 2 == 1) {
				if (i % 2 == 0) {
					if (i == 0) {
						if (a[i] != 1) {
							flag = true;
							break;
						}
					} else {
						if (a[i] != 2) {
							flag = true;
							break;
						}
					}
				} else {
					if (a[i] != 0) {
						flag = true;
						break;
					}
				}
			} else {
				if (i % 2 == 1) {
					if (a[i] != 2) {
						flag = true;
						break;
					}
				} else {
					if (a[i] != 0) {
						flag = true;
						break;
					}
				}
			}
		}
		if (!flag) {
			for (int i = 0; i < n / 2; i++) {
				ans *= 2;
				ans %= 1000000007;
			}
			System.out.println(ans);
		} else {
			System.out.println(0);
		}
		sc.close();
	}
}


Measured memory_bytes: 48592
K = int(input())

def count(idx, n):
    if idx==0:
        return 1
    if n==0:
        return count(idx-1, 1)+count(idx-1, 0)
    elif n==9:
        return count(idx-1, 9)+count(idx-1, 8)
    else:
        return count(idx-1, n-1)+count(idx-1, n)+count(idx-1, n+1)

lists = []
def count_2(idx, n, list_b):
    lis = list_b[:]
    lis.append(str(n))
    if idx==0:
        lists.append(int(''.join(lis)))
        return 1
    if n==0:
        count_2(idx-1, 1, lis)
        count_2(idx-1, 0, lis)
    elif n==9:
        count_2(idx-1, 9, lis)
        count_2(idx-1, 8, lis)
    else:
        count_2(idx-1, n-1, lis)
        count_2(idx-1, n, lis)
        count_2(idx-1, n+1, lis)

d = 0
now = 0
while 1:
    p = sum([count(d, i) for i in range(1, 10)])
    now += p
    if now>K:
        now -= p
        break
    d += 1

sump = 0
for i in range(1, 10):
    sump_old = sump
    sump += count(d, i)
    if sump+now>=K:
        break
count_2(d, i, [])
lists.sort()
if K<10:
    print(K)
else:
    print(lists[K-now-sump_old-1])

Measured memory_bytes: 3684
import math
a,b,x=map(int,input().split())

menseki=1.0*x/a
teihen=2.0*menseki/b
#print(menseki,teihen)

if teihen<=a:
  print(math.degrees(math.atan(b/teihen)))
else:
  print(math.degrees(math.atan(2*(a*b-menseki)/(a*a))))

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <string>
#include <cctype>
#include <cmath>
#include <iomanip>
#include <climits>
#include <cfloat>
#include <algorithm>
#define ll long long
#define ull unsigned long long
#define uint unsigned
#define MOD 1000000007;
using namespace std;

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

    size_t n {};
    cin >> n;
    // bool three {false};
    // bool five {false};

    while (n--) {
    	int num {};
    	cin >> num;

    	if (!(num%2)) {
    		if (!(num%3) || !(num%5)) continue;
    		else {
    			cout<<"DENIED"<<endl;
    			return 0;
    		}
    	}
    }
    cout<<"APPROVED"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;
const int inf=1e9+7;
const ll INF=1LL<<61;
const ll mod=1e9+7;

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;
}

string calc(string s){
    int p=0;
    s+='$';
    string t;
    while(1){
        int cnt=1;
        while(s[p+1]==s[p]){
            p++;
            cnt++;
        }
        t+=to_string(cnt);
        t+=s[p];
        p++;
        if(p==s.size()-1) break;
    }
    return t;
}

int main(){
    int i,j;
    int n;
    string s;
    while(1){
        cin>>n;
        if(n==0) break;
        cin>>s;
        for(i=0;i<n;i++) s=calc(s);
        cout<<s<<endl;
    }

}


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

using namespace std;

int main(void) {
    char b;
    cin >> b;

    if (b == 'A') {
        cout << "T" << endl;
    } else if (b == 'T') {
        cout << "A" << endl;
    } else if (b == 'C') {
        cout << "G" << endl;
    } else {
        cout << "C" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0;
#define ll long long

int n, x, y, z;
vector <int> c, s, f;

int solve(int cur){
    int time = 0;
    while(cur != n-1){
        while(time < s[cur] || time%f[cur]) time++;
        time += c[cur];
        cur++;
    }
    return time;
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    cin >> n;
    for(int i = 1 ; i < n && cin >> x >> y >> z ; i++)
        c.push_back(x), s.push_back(y), f.push_back(z);
    for(int i = 0 ; i < n ; i++)
        cout << solve(i) << endl;
    return 0;
}


Measured memory_bytes: 256
N = int(input())
ab = [list(map(int, input().split())) for _ in range(N)]

l = sorted(ab, key=lambda x: x[0])
r = sorted(ab, key=lambda x: x[1])

if N % 2 == 0:
    maxab = ab[(N // 2) - 1][1]
    minab = ab[N // 2][0]
    x1 = (l[(N // 2) - 1][0] + l[N // 2][0])
    x2 = (r[(N // 2) - 1][1] + r[N // 2][1])
    print(x2 - x1 + 1)

else:
    print(r[N // 2][1] - l[N // 2][0] + 1)

Measured memory_bytes: 51784
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi acos(-1.0)
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
 
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <assert.h>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) c.begin(), c.end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

const ll INF = 1e17;

struct edge{ll to, cost;};
vector<edge> es[1000];
VI einv[1000];

int main(){
    int n, m;
    cin >> n >> m;
    while (m--){
        int a, b, c;
        scanf("%d %d %d", &a, &b, &c);
        a--;
        b--;
        edge e;
        e.cost = c;
        e.to = b;
        es[a].push_back(e);
        einv[b].push_back(a);
    }

    VI r(n);
    r[n-1] = 1;
    queue<int> que;
    que.push(n-1);
    while (!que.empty()){
        int u = que.front();
        que.pop();
        for (auto next : einv[u]){
            if (r[next]) continue;
            r[next] = 1;
            que.push(next);
        }
    }

    assert(r[0] == 1);

    // REP(i,n) cout << r[i] << endl;

    VL d(n, -INF);
    int ans;
    d[0] = 0;
    REP(i,30000){
        bool update = false;
        REP(j,n){
            REP(k,es[j].size()){
                edge e = es[j][k];
                // if (!r[e.to]) continue;
                if (d[e.to] < d[j] + e.cost){
                    d[e.to] = d[j] + e.cost;
                    update = true;
                    if (i >= n && r[e.to]){
                        cout << "inf" << endl;
                        return 0;
                    }
                }
            }
        }
        if (i == n-1) ans = d[n-1];
        if (d[0] > 0){
            cout << "inf"<< endl;
            return 0;
        }
    }
    assert(d[n-1] > -INF);
    cout << d[n-1] << endl;

    return 0;
}

Measured memory_bytes: 384
#coding:utf-8
import sys
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = lambda *something : print(*something) if DEBUG else 0
DEBUG = False
def main(given = sys.stdin.readline):
    input = lambda : given().rstrip()
    LMIIS = lambda : list(map(int,input().split()))
    II = lambda : int(input())
    XLMIIS = lambda x : [LMIIS() for _ in range(x)]
    N = II()
    S = input()
    count = 0

    i = 0
    while i < len(S)-2:
        if S[i] == 'A' and S[i+1] == 'B' and S[i+2] == 'C':
            count += 1
            i += 2
        i += 1
    print(count)



if __name__ == '__main__':
    main()

Measured memory_bytes: 38384
#include <stdio.h>
#include <math.h>

int is(int);

int main(){
  int n,count=0,i;
  scanf("%d",&n);
  int a[n],b=3,c;
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }

  for(i=0;i<n;i++){
    c=is(a[i]);
    if(c==1) count++;
  }
  printf("%d\n",count);
  
  return 0;
}

int is(int x){
  int b=3;
  if(x==2) return 1;
  if(x<2||x%2==0) return 0;
  while(b<=sqrt(x)){
    if(x%b==0) return 0;
    b=b+2;
  }
  return 1;
}  
 



Measured memory_bytes: 2124
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <sstream>
#include <math.h>
#include <queue>
#include <map>
#include <set>
#include <ios>     // std::left, std::right
#include <iomanip> // std::setw(int), std::setfill(char)
using namespace std;

vector<int> G[200000];
int tree[200000]={};

void dfs1(int x){
  for(int j=0;j<G[x].size();j++){
    if(tree[G[x][j]]<0){
    tree[G[x][j]]=tree[x]+1;
    dfs1(G[x][j]);}
  }
  return;
}


int main(){
int N;
cin>>N;
int a,b;
for(int i=0;i<N;++i){
  tree[i]=(-1);
  if(i<N-1){
  cin>>a>>b;
  a--;
  b--;
  G[a].push_back(b);
  G[b].push_back(a);}
}

tree[0]=0;
dfs1(0);

int x,y,xd,yd;
x=0;
xd=-1;
y=0;
yd=-1;
for(int i=0;i<N;++i){
  if(xd<tree[i]){
    xd=tree[i];
    x=i;
  }
  tree[i]=(-1);
}

tree[x]=0;
dfs1(x);

for(int i=0;i<N;++i){
  if(yd<tree[i]){
    yd=tree[i];
    y=i;
  }
}
if(yd%3==1){
  cout<<"Second"<<"\n";
}
else{
  cout<<"First"<<"\n";
}
return 0;
}

Measured memory_bytes: 21376
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	map<int, ll> mp1;
	map<int, ll> mp2;
	rep(i, n) {
		int a;
		cin >> a;
		mp1[a + i]++;
		mp2[i - a]++;
	}
	ll ans = 0;
	for (auto& c : mp1) {
		if (mp2[c.first] >= 1) {
			ans += c.second * mp2[c.first];
		}
	}
	cout << ans << endl;
	return 0;
}


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

typedef long long ll;

int main() {
    int A, B, C;
    cin >> A >> B >> C;
    if (A + B < C) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }
}

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

using namespace std;

int counter(int x)
{
   if (x == 0)
      return 0;
   return counter(x >> 1) + (x & 1);
}

int main()
{
   int N;
   cin >> N;
   int A[20];
   int x[20][20];
   int y[20][20];

   for (int i = 1; i <= N; i++)
   {
      cin >> A[i];
      for (int j = 1; j <= A[i]; j++)
      {
         cin >> x[i][j] >> y[i][j];
      }
   }

   int ans = 0;
   for (int bits = 1; bits < (1 << N); bits++)
   {
      bool ok = true;
      for (int i = 1; i <= N; i++)
      {
         if (!(bits & (1 << (i - 1))))
            continue;
         for (int j = 1; j <= A[i]; j++)
         {
            if (((bits >> (x[i][j] - 1)) & 1) ^ y[i][j])
               ok = false;
         }
      }
      if (ok)
         ans = max(ans, counter(bits));
   }
   cout << ans << endl;
}


Measured memory_bytes: 256
N=map(int,input().split())
List=list(map(int,input().split()))
List_even = [i for i in List if i % 2 == 0]
count=len(List_even)
ok_counter=0
for i in range(count):
    if List_even[i] % 3 == 0:
        ok_counter+=1
        continue
    if List_even[i] % 5 == 0:
        ok_counter+=1
        continue
if ok_counter == count:
    print('APPROVED')
else:
    print('DENIED')

Measured memory_bytes: 3064
from fractions import gcd

def lcm(c,d):
    return c//gcd(c,d)*d
mod=10**9+7
n=int(input())
a=[int(i) for i in input().split()]
l=a[0]
for i in range(1,n):
    l=lcm(l,a[i])
ans=0
for i in range(n):
    ans+=l//a[i]
    #ans%=mod
print(ans%mod)


Measured memory_bytes: 6108
#include <bits/stdc++.h>
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++) 
#define FOR(i, a, b) for(int (i) = a; (i) < (int)b; i++)
#define RREP(i, n) for(int (i)=((int)(n)-1); (i)>=0; i--)
#define RFOR(i, a, b) for(int (i) =((int)(b)-1); (i)>=(int)a; i--)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define F first
#define S second

using namespace std ;
typedef long long ll;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef pair<int, int> pint;
const int Inf = 1e9;
const double EPS = 1e-9;



int main()
{
  int n ;
  cin >> n ;
  ll power = 1 ;
  
  FOR(i,1,n+1){
    power = power*i ;
    power = power%MOD ;
  }
  
  cout << power <<endl ;
    

  return 0 ;
}




Measured memory_bytes: 256
#include <iostream>
#include <string>
using std::string;
using namespace std;
int main()
{
string s;
int total=1;
cin>>s;
string str[8];
str[1]="SAT";
str[2]="FRI";
str[3]="THU";
str[4]="WED";
str[5]="TUE";
str[6]="MON";
str[7]="SUN";
for(int i=1;i<8;i++){
    if(s!=str[i]){
        total++;
        continue;}
    else{
        cout<<total;
        break;}
}
}


Measured memory_bytes: 256
#include<stdio.h>
 
int main(){
  int n;
  scanf("%d",&n);
  char s[100000];
  int ans=n;
  
  
  scanf("%s",s);
  
  for(int i=0;i<n-1;i++){
    if(s[i]==s[i+1]){
      ans--;
    }
  }
  printf("%d",ans);
  return 0;
}

Measured memory_bytes: 256
// Complete Binary Tree
#include <stdio.h>

#define MAX 500000

int H; // ヒープサイズ

int parent(int i){
  return i / 2; // 親の接点番号
}

int left(int i){
  return 2 * i; // 左の子の接点番号
}

int right(int i){
  return 2 * i + 1; // 右の子の接点番号
}

// iの左の子と右の子のうち、キーが大きい方を選び、それが現在のキーよりも大きければ、交換していく
void maxHeapify(int *A, int i){
  int l, r, largest, swp;
  l = left(i);
  r = right(i);

  // 左の子、自分、右の子で値が最大のノードを選ぶ
  if(l <= H && A[l] > A[i]){
    largest = l;
  }
  else largest = i;
  
  if(r <= H && A[r] > A[largest]){
    largest = r;
  }
  if(largest != i){ // i の子の方が値が大きい場合
    swp = A[i];  A[i] = A[largest];  A[largest] = swp; // A[i] と A[largest] を交換
    maxHeapify(A, largest); // 再帰的に呼び出し
  }
}

// max-ヒープを構築する
void buildMaxHeap(int *A){
  int i;
  for(i=H/2; i > 0; i--){
    maxHeapify(A, i);
  }
}

int main(){
  int i, A[MAX];

  scanf("%d", &H);

  for(i=1; i <= H; i++){
    scanf("%d", &A[i]);
  }

  buildMaxHeap(A);
  
  for(i=1; i <= H; i++){
    printf(" %d", A[i]);
  }
  printf("\n");
  
  return 0;
}



Measured memory_bytes: 3632
import sys

n = int(sys.stdin.readline().strip())
numbers = tuple(map(int, sys.stdin.readline().strip().split()))
kinds = set(numbers)


def answer(ans):
    print(ans)
    sys.exit()


if kinds == {0}:
    answer("Yes")

elif len(kinds) == 2:
    a, b = sorted(kinds)
    if a == 0:
        if numbers.count(a) * 3 == n:
            answer("Yes")
        else:
            answer("No")
    else:
        answer("No")

elif len(kinds) == 3:
    a, b, c = tuple(kinds)
    if (numbers.count(a) == numbers.count(b)) and (numbers.count(b) == numbers.count(c)):
        if a ^ b == c:
            answer("Yes")
        else:
            answer("No")
    else:
        answer("No")
else:
    answer("No")


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

public class Main{
    public static void main(String[] args)throws Exception{
        Scanner sc=new Scanner(System.in);
        String str=sc.next();
        int count=0;
        for(int i=0;i<str.length()/2;i++){
            if(str.charAt(i)!=str.charAt(str.length()-1-i)){
                count++;
            }
        }
        System.out.println(count);
    }
}

Measured memory_bytes: 21844
use std::io::*;
use std::str::FromStr;
use std::cmp::min;

const INF: i64 = 1_i64 << 60;

fn func(x: i64, s: &Vec<i64>) -> (i64, i64) {
    let mut ok = 0;
    let mut ng = s.len();
    while ok + 1 < ng {
        let mid = (ok + ng) / 2;
        if s[mid] < x {
            ok = mid;
        } else {
            ng = mid;
        }
    }
    if ok == s.len()-1 {
        (s[ok], s[ok])
    } else {
        (s[ok], s[ok+1])
    }
}

fn calc(x: i64, s: i64, t: i64) -> i64 {
    min((s - x).abs() + (t - s).abs(),
        (t - x).abs() + (t - s).abs())
}

fn main() {
    let a: usize = read();
    let b: usize = read();
    let q: usize = read();
    let s: Vec<i64> = (0..a).map(|_| read()).collect();
    let t: Vec<i64> = (0..b).map(|_| read()).collect();

    for _ in 0..q {
        let x: i64 = read();
        let (s1, s2) = func(x, &s);
        let (t1, t2) = func(x, &t);
        let mut ans = INF;
        ans = min(ans, calc(x, s1, t1));
        ans = min(ans, calc(x, s1, t2));
        ans = min(ans, calc(x, s2, t1));
        ans = min(ans, calc(x, s2, t2));
        println!("{}", ans);
    }
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


Measured memory_bytes: 7420
using System;
class ProgramB
    {
        static void Main(string[] args)
        {
        var line = Console.ReadLine();
        var data = line.Split(' ');
        var a1 = int.Parse(data[0]); //first integer
        var b1 = int.Parse(data[1]); //sec
          
         Console.WriteLine(((a1-2*b1)<=0?0:a1-2*b1));
           
        }
    }


Measured memory_bytes: 13140
import Control.Applicative
import Control.Monad

main = solve

solve = do
    ns <- fmap (read :: String -> Int) . words <$> getLine
    let h = ns !! 0
        w = ns !! 1
    drawRectangle h w

drawRectangle :: Int -> Int -> IO ()
drawRectangle h w
    | h == 0 && w == 0 = return ()
    | otherwise = do
        mapM_ (\x -> putStrLn $ createBlock x w) [1..h]
        putStrLn ""
        solve

createBlock :: Int -> Int -> String
createBlock x w
    | odd x = createLine w "#."
    | otherwise = createLine w ".#"

createLine :: Int -> String -> String
createLine w = (take w) . concat . (replicate w)

Measured memory_bytes: 4024
#include<iostream>
#include<algorithm>
#include<string>
#include<sstream>
#include<cstring>
#include<vector>
#include<stack>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#include<functional>
#define io ios::sync_with_stdio(false)
#define inf 0x3f3f3f3f
#define ll long long
#define P pair<int,int>
#define lc rt*2
#define rc rt*2+1
const int maxn = 1e5 + 10;
const int mod = 1e9 + 7;

using namespace std;

double dp[6][4][3];
int main()
{
	string s, t;
	cin >> s >> t;
	int a, b;
	string u;
	cin >> a >> b >> u;
	if (u == s)
		a--;
	else
		b--;
	cout << a << ' ' << b;
	return 0;
 }

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


int main() {
  int N,L;
  cin>>N>>L;
 vector<string> a(N);
  for(int i=0;i<N;i++){
  cin>>a.at(i);
  }
  sort(a.begin(),a.end());
  string ans="";
  for(int i=0;i<N;i++){
  ans+=a.at(i);
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int N = 0;
    while(true){
        cin >> N;
        if(N==0) break;
        
        int a[1010];
        a[0] = 0;
        for(int i = 1; i < 1000; i++) {
            a[i] = a[i-1] + i;
        }
        int ans = 0;
        for(int i = 1; i < N; i++){
            for(int j = 0; j < i; j++){
                if(a[i] - a[j] == N) ans++;
            }
        }
        cout << ans << endl;
    }
}



Measured memory_bytes: 3000
from collections import defaultdict
n,m=map(int,input().split())
h=list(map(int,input().split()))
dd=defaultdict(set)
for i in range(m):
  a,b=map(int,input().split())
  dd[a-1].add(b-1)
  dd[b-1].add(a-1)
cnt=0
for i,hh in enumerate(h):
  flg=True
  for j in dd[i]:
    if hh <= h[j]:
      flg=False
      break
  if flg:
    cnt+=1
print(cnt)
  


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

using namespace std;

typedef long long int ll;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
#define sz(a) (ll)(a.size())
#define endl "\n"

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

    ll A, B, T;
    cin >> A >> B >> T;

    cout << B*(T/A) << endl;
    

    return 0;
}

Measured memory_bytes: 256
n=int(input())
s=[int(i) for i in input()]
#print(s)
def my_index(l,x,ind):
    global n
    if ind==n:
        return -1
    for i in range(ind,n):
        if l[i]==x:
            return i
    else:
        return -1

c=0
for i in range(10):
    #print(i)
    x1=my_index(s,i,0)
    #print(c)
    if x1!=-1:
        #print(i)
        for j in range(10):
            x2=my_index(s,j,x1+1)
            if x2!=-1:
                for k in range(10):
                    if my_index(s,k,x2+1)!=-1:
                        #print(i,j,k)
                        c+=1
print(c)


Measured memory_bytes: 3572
use std::collections::BTreeMap;

fn main() {
    let mut sc = Scanner::new();
    let n = sc.read();
    let m = sc.read::<usize>();
    let a = (0..n).map(|_| sc.read::<usize>() % m).collect::<Vec<_>>();

    let mut ans: usize = 0;
    let mut cur = 0;
    let mut map = BTreeMap::new();
    map.insert(0, 1);
    for &a in a.iter() {
        cur += a;
        cur %= m;

        let add = *map.get(&cur).unwrap_or(&0);
        ans += add;
        *map.entry(cur).or_insert(0) += 1;
    }

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

struct Scanner {
    ptr: usize,
    length: usize,
    buf: Vec<u8>,
    small_cache: Vec<u8>,
}

#[allow(dead_code)]
impl Scanner {
    fn new() -> Scanner {
        Scanner {
            ptr: 0,
            length: 0,
            buf: vec![0; 1024],
            small_cache: vec![0; 1024],
        }
    }

    fn load(&mut self) {
        use std::io::Read;
        let mut s = std::io::stdin();
        self.length = s.read(&mut self.buf).unwrap();
    }

    fn byte(&mut self) -> u8 {
        if self.ptr >= self.length {
            self.ptr = 0;
            self.load();
            if self.length == 0 {
                self.buf[0] = b'\n';
                self.length = 1;
            }
        }

        self.ptr += 1;
        return self.buf[self.ptr - 1];
    }

    fn is_space(b: u8) -> bool {
        b == b'\n' || b == b'\r' || b == b'\t' || b == b' '
    }

    fn read_vec<T>(&mut self, n: usize) -> Vec<T>
    where
        T: std::str::FromStr,
        T::Err: std::fmt::Debug,
    {
        (0..n).map(|_| self.read()).collect()
    }

    fn usize_read(&mut self) -> usize {
        self.read()
    }

    fn read<T>(&mut self) -> T
    where
        T: std::str::FromStr,
        T::Err: std::fmt::Debug,
    {
        let mut b = self.byte();
        while Scanner::is_space(b) {
            b = self.byte();
        }

        for pos in 0..self.small_cache.len() {
            self.small_cache[pos] = b;
            b = self.byte();
            if Scanner::is_space(b) {
                return String::from_utf8_lossy(&self.small_cache[0..(pos + 1)])
                    .parse()
                    .unwrap();
            }
        }

        let mut v = self.small_cache.clone();
        while !Scanner::is_space(b) {
            v.push(b);
            b = self.byte();
        }
        return String::from_utf8_lossy(&v).parse().unwrap();
    }
}


Measured memory_bytes: 6396
A = int(input())
B = int(input())
C = int(input())
X = int(input())

res = 0

for a in range(1 + A):
  for b in range(1 + B):
    for c in range(1 + C):
      if a*500 + b*100 + 50*c == X:
        res += 1

print(res)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const int64_t LINF=8931145141919364364,LMOD=998244353;
// const int dy[]={0,-1,0,1,1,-1,-1,1};
// const int dx[]={1,0,-1,0,1,1,-1,-1};

int main() {
	int64_t n, k; cin >> n >> k;
	int64_t ans = n - n / k * k;
	ans = min(ans, abs(ans - k));
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int a[3];
  for(int i=0;i<3;i++)
  {
    
  cin>>a[i];
  }
  sort(a,a+3);
  
  if((a[0]+a[1])==a[2])
  {
    cout<<"Yes"<<endl;
  }
  else
  {
    cout<<"No"<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
N,C = gets.split.map(&:to_i)
ch = Array.new(C){[]}
N.times do
  s,t,c = gets.split.map(&:to_i)
  ch[c-1] << [s,t]
end
ch.each{|seq| seq.sort_by!(&:first)}
merged_ch = Array.new(C){[]}
ch.each_with_index do |seq, i|
  m_seq = merged_ch[i]
  seq.each do |s, t|
    if m_seq.empty?
      m_seq << [s,t]
    elsif m_seq[-1][1] == s
      m_seq[-1][1] = t
    else
      m_seq << [s,t]
    end
  end
end

max = 10**5+10
imos = Array.new(max, 0)
merged_ch.each do |seq|
  seq.each do |s, t|
    imos[s-1] += 1
    imos[t] -= 1
  end
end

(max-1).times do |i|
  imos[i+1] += imos[i]
end
puts imos.max

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

ans = 0
xy = [[] for _ in range(n)]
for i in range(n):
    a = int(input())
    for j in range(a):
        x, y = map(int, input().split())
        xy[i].append((x-1, y))

for bit in range(1<<n):
    flag = 0
    for j in range(n):
        if (bit & (1<<j)) > 0:
            for x, y in xy[j]:
                if y == 1 and ((bit & (1<<x)) == 0):
                    flag = 1
                    break
                elif y == 0 and ((bit & (1<<x)) > 0):
                    flag = 1
                    break
    if flag:
        continue
    count = 0
    for j in range(n):
        if (bit & (1<<j)) > 0:
            count += 1
    ans = max(ans, count)

print(ans)


Measured memory_bytes: 45548
fun main(args: Array<String>) {
    val s = readLine()!!

    val a = s.take(2).toInt()
    val b = s.takeLast(2).toInt()

    val ans = if (a in (1..12) && b in (1..12)) {
        "AMBIGUOUS"
    } else if (a in (1..12) && b !in (1..12)) {
        "MMYY"
    } else if (b in (1..12) && a !in (1..12)) {
        "YYMM"
    } else {
        "NA"
    }

    println(ans)
}


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

int main(){
  int n;
  cin >> n;
  string s;
  cin >> s;
  int ans = 0;
  for(int i=1;i<n-1;++i){
    set<char> st;
    for(int j=0;j<i;++j){
      st.insert(s[j]);
    }
    int cnt = 0;
    set<char> used;
    for(int j=i;j<n;++j){
      if(!used.count(s[j]))cnt += st.count(s[j]);
      used.insert(s[j]);
    }
    ans = max(ans, cnt);
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <queue>
#include <vector>
const int N = 200050;
int a[2][N];
int nxt[N];
int son[N][3];
int st[2][N][20];
void build(int n, int *A, int st[][20]) {
  for (int i = 0; i < n; ++i)
    st[i][0] = i;
  for (int j = 1, k = 2; k <= n; ++j, k <<= 1)
    for (int i = 0; i + k <= n; ++i) {
      int a = st[i][j - 1], b = st[i + k / 2][j - 1];
      st[i][j] = A[a] < A[b] ? a : b;
    }
}
int get(int *A, int st[][20], int l, int r) {
  int d = 1, k = 0;
  while ((d << 1) <= r - l + 1) d <<= 1, ++k;
  int a = st[l][k], b = st[r - d + 1][k];
  return A[a] < A[b] ? a : b;
}
int solve(int l, int r) {
  if (l > r) return -1;
  int ansl = get(a[l & 1], st[l & 1], l / 2, (r - 1) / 2);
  int ansr = get(a[~l & 1], st[~l & 1], ansl + (l & 1), r / 2);
  ansl = ansl * 2 + (l & 1), ansr = ansr * 2 + (~l & 1);
  nxt[ansl] = ansr;
  son[ansl][0] = solve(l, ansl - 1);
  son[ansl][1] = solve(ansl + 1, ansr - 1);
  son[ansl][2] = solve(ansr + 1, r);
  return ansl;
}
struct cmp{
  bool operator()(int x, int y)const{
    return a[x & 1][x >> 1] > a[y & 1][y >> 1];
  }
};
std::priority_queue<int, std::vector<int>, cmp> PQ;
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i)
    scanf("%d", &a[i & 1][i >> 1]);
  build(n >> 1, a[0], st[0]);
  build(n >> 1, a[1], st[1]);
  int root = solve(0, n - 1);
  while (!PQ.empty()) PQ.pop();
  PQ.push(root);
  while (!PQ.empty()) {
    int x = PQ.top(); PQ.pop();
    printf("%d %d ", a[x & 1][x >> 1], a[nxt[x] & 1][nxt[x] >> 1]);
    for (int i = 0; i < 3; ++i) if (~son[x][i]) PQ.push(son[x][i]);
  }
  return 0;

}


Measured memory_bytes: 29056
#include <bits/stdc++.h>
#define FIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define FOR(a,b,c) for(int a = (b); a <= (c); a++)
#define RFOR(a,b,c) for(int a = (b); a >= (c); a--)
#define all(x) (x).begin(), (x).end()
#define vi vector <int>
#define vvi vector <vi>
#define ll long long
#define vll vector <ll>
#define vvl vector <vll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define eb emplace_back
#define ep emplace
#define fs first
#define sd second
#define mod 998244353
#define EPS 1e-9
#define tc int t; cin >> t; while(t--)
using namespace std;

int main() {
	FIO;
	ll a, b, n;
	cin >> a >> b >> n;
	cout << a * min(n, b - 1) / b << '\n';
	return 0;
}

Measured memory_bytes: 3652
//submitted by sldinkar
#include <algorithm>
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>

using namespace std;

#define fast ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define mod (int)1000000007
#define MOD (int)10000000007
#define infinity (int)(1e18)

#define all(a) a.begin(),a.end()
#define ll long long
#define int long long
#define pb push_back
#define precision(n) fixed<<setprecision(n)
#define endl "\n"
#define no "NO"
#define yes "YES"


#define for0(i, n) for (int i = 0; i < n; i++)
#define for1(i, n) for (int i = 1; i <= n; i++)
#define loop(i,a,b) for (int i = a; i < b; i++)
#define bloop(i,a,b) for (int i = a ; i>=b;i--)
#define test(t) int t; cin >> t; while (t--)
#define init(a, i) memset(a, i, sizeof(a))


#define vi vector<int>
#define vll vector<ll>
#define pi pair<int, int>
#define vii vector<pi>

#define f first
#define s second

int gcd(int a,int b) { if (a == 0) return b; return gcd(b%a, a);}
int lcm(int a,int b) {return a*b/gcd(a,b);}
int max(int a,int b){if(a>b) return a; else return b;}
int min(int a,int b){if(a<b) return a; else return b;}

bool isPrime(int N){ for(int i=2;i*i<=N;++i){if(N%i==0) return false;}return true;}
bool isPowerOfTwo(int x) {   return x && (!(x&(x-1))); }



// main code starts from here

int arr[100001]={0};
int n,k;

int Cost(int ind,vector<int>&dp){
    if(ind==n-1)return 0;
    if(dp[ind]!=-1)return dp[ind];
    int mini=INT_MAX;
    for(int i=ind+1;i<=min(ind+k,n-1);i++)
    {
        int cost=abs(arr[ind]-arr[i])+Cost(i,dp);
        mini=min(cost,mini);
    }
    return dp[ind]=mini;
}

signed main()
{

    fast;
    cin>>n>>k;
    for(int i=0;i<n;i++)cin>>arr[i];
    vector<int>dp(n,-1);
    cout<<Cost(0,dp)<<endl;
    return 0;
}

Measured memory_bytes: 12556
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <vector>
#include <math.h>
using namespace std;

int main(){

    int N;
    string S;
    //N=3 abc
    //1<S<100
    //if S[i]!=LorRorUorD
    bool flag=false;
    bool flag2=false;
    cin>>S; //U0D1U2D3U4D5U6D7L8R9
    int i=0;
    //cout << S;
    //0 1 2 3 4 5->１文字目 ２文字目
    //R U D L U D R
    for(i=0;i<S.size();i++){
      if(S[i]=='L' ||S[i]=='R' ||S[i]=='U' ||S[i]=='D'){
        flag=false;
        if(i%2==0 && (S[i]=='R' ||S[i]=='U' ||S[i]=='D') ){
          flag=true;
          //cout << "Yes1";
        }
        else if(i%2!=0 && (S[i]=='L' ||S[i]=='U'||S[i]=='D')) {
          flag=true;
          //cout << "Yes2";
        }
        //cout << flag;
        else{
          flag2=true;
        }
      }
      else{
        flag2=true;
        //cout << "No";
        //exit ;
      }
  }
  if(flag2==true){
    cout << "No";
  }
  else if(flag==true){
    cout << "Yes";
  }
  else{
    ;
  }
}


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

int main(){
  int n;
  cin >> n;
  vector<int> v(n);
  vector<int> c(n);
  for(int i=0;i<n;i++){
    cin >> v.at(i);
  }
  for(int i=0;i<n;i++){
    cin >> c.at(i);
  }
  int sum = 0;
  for(int i=0;i<n;i++){
    if(v.at(i) > c.at(i)){
      sum += v.at(i)-c.at(i);
    }
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 256
#include <cstring>
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstdlib>
#include <cmath>
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define ROOT 1,n,1
using namespace std;
const int maxn=2e5+10;
const int INF=0x3f3f3f3f;
char ch;
inline void read(int &x){
    x=0;ch=getchar();
    while(ch<'0'||'9'<ch)ch=getchar();
    while('0'<=ch&&ch<='9') x=x*10+ch-'0',ch=getchar();
}
inline void MIN(int &x,int y){if (y<x) x=y;}
struct adjs{int to,nx;}edge[maxn];
int h[maxn],sz;
void init(int n){for (int i=0;i<=n;i++) h[i]=-1;sz=0;}
void addedge(int u,int v){
    edge[sz].to=v;edge[sz].nx=h[u];h[u]=sz++;
}
int tree[maxn<<2];
void build(int l,int r,int rt){
    tree[rt]=INF;
    if (l==r) return;
    int mid=(l+r)>>1;
    build(lson);build(rson);
}
int query(int l,int r,int rt,int pos){
    if (l==r) return tree[rt];
    int mid=(l+r)>>1;
    if (pos<=mid) return min(query(lson,pos),tree[rt]);
    else return min(query(rson,pos),tree[rt]);
}
void update(int l,int r,int rt,int L,int R,int val){
    if (L<=l&&r<=R) {MIN(tree[rt],val);return;}
    int mid=(l+r)>>1;
    if (L<=mid) update(lson,L,R,val);
    if (R>mid) update(rson,L,R,val);
}
void pt(int l,int r,int rt){
    printf("[%d,%d]=%d\n",l,r,tree[rt]);
    if (l==r) return;
    int mid=(l+r)>>1;
    pt(lson);pt(rson);
}
int n,a[maxn],sum[maxn],dp[maxn];
int m,u,v;
int main(){
    #ifdef VGel
    freopen("F.in","r",stdin);
    freopen("F.out","w",stdout);
    #endif // VGel
    while (~scanf("%d",&n)){
        sum[0]=dp[0]=0;
        for (int i=1;i<=n;i++) read(a[i]),sum[i]=sum[i-1]+!a[i];
        init(n);
        read(m);
        while (m--){
            read(u);read(v);
            addedge(v,u);
        }
        build(ROOT);

        for (int r=1;r<=n;r++){
            dp[r]=dp[r-1]+a[r];
            for (int i=h[r];~i;i=edge[i].nx){
                int l=edge[i].to;
                int tmp=dp[l-1]+sum[r]-sum[l-1];//xuan
                int tmp2=query(ROOT,l)+sum[r];
                MIN(tmp,tmp2);
                update(ROOT,l,r,tmp-sum[r]);
                MIN(dp[r],tmp);
            }
        }
        printf("%d\n",dp[n]);
    }
    return 0;
}


Measured memory_bytes: 8064
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        //入力準備
        Scanner sc = new Scanner(System.in);
        
        int a = sc.nextInt();
        int b = sc.nextInt();
        
        System.out.print(a/b);
        System.out.print(" ");
        System.out.print(a%b);
        System.out.print(" ");
        System.out.println(String.format("%.5f",(double)a/b));
        
    }
}



Measured memory_bytes: 26524