akhauriyash/Code-Regression huggingface dataset:
// Simple C++ program to count occurrences 
// of pat in txt. 
#include<bits/stdc++.h> 
using namespace std; 

int countFreq(string &pat, string &txt) 
{ 
	int M = pat.length(); 
	int N = txt.length(); 
	int res = 0; 
	
	/* A loop to slide pat[] one by one */
	for (int i = 0; i <= N - M; i++) 
	{ 
		/* For current index i, check for 
		pattern match */
		int j; 
		for (j = 0; j < M; j++) 
			if (txt[i+j] != pat[j]) 
				break; 

		// if pat[0...M-1] = txt[i, i+1, ...i+M-1] 
		if (j == M) 
		{ 
		res++; 
		j = 0; 
		} 
	} 
	return res; 
} 
	

int main() 
{ 
  long long n;
  cin>>n;
string txt ; 
  cin>>txt;
string pat = "ABC"; 
cout << countFreq(pat, txt); 
return 0; 
} 


Measured memory_bytes: 256
N = int(input())
a = []
for i in range(N):
    a.append(int(input()))
    
start = 0
count = 0

for i in range(N):
    count+=1
    next = a[start]
    if(next == 2):
        print(count)
        break
    start = next -1
else:
    print(-1)

Measured memory_bytes: 7084
n = int(input())
ns = list(map(int, input().split()))

rslt = []
ttl = sum(ns)
x = ttl - 2 * sum(ns[i] for i in range(1, n, 2))
rslt.append(x)
for i in range(0, n-1):
    x = 2 * ns[i] - x
    rslt.append(x)
print(*rslt)

Measured memory_bytes: 14032
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, N) for (int i = 0; i < (int)N; i++)

int main () {
  int a,b,c;
  cin >> a >> b >> c;
  cout << (a <= c && c <= b ? "Yes" : "No") << endl;
  return 0;
}


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

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

    sort(A.begin(),A.end());
    int ans=0;
    int cnt=1;
    for (int i = 0; i < N-1; i++){
        if(A[i]==A[i+1]){
            cnt++;
            if(i==N-2){
                ans=ans+cnt%2;
            }
        }
        else{
            ans=ans+cnt%2;
            cnt=1;
            if(i==N-2){
                ans++;
            }
        }
    }

    cout << ans << endl;

}

Measured memory_bytes: 3960
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
  int i,j;
  int a[1000],b[1000],m,n,p;
  char s[1000][17];
  while(cin>>n>>m&&n&&m){
    for(i=0;i<n;i++)
      cin>>s[i]>>a[i]>>b[i];
    for(i=0;i<m;i++){
      cin>>p;
      for(j=0;j<n;j++){
	if(b[j]-a[j]<p&&p<=b[j])
	  break;
      }
      if(j==n)
	cout<<"Unknown"<<endl;
      else
	cout<<s[j]<<" "<<a[j]-b[j]+p<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 900
fun main(args : Array<String>) {
    val n = readLine()!!.toInt()
    val songs = mutableListOf<Pair<String, Int>>()

    repeat(n) {
        val (s, t) = readLine()!!.split(" ")
        songs.add(Pair(s, t.toInt()))
    }

    val x = readLine()!!

    var sec = 0
    var shouldCount = false
    songs.forEach {
        if (shouldCount) sec += it.second
        if (it.first.equals(x)) shouldCount = true
    }

    println(sec)
}

Measured memory_bytes: 36044
#include <bits/stdc++.h>
#include <vector>
#include <queue>
using namespace std;
typedef long long LL;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)

int main(){
    int N;
    cin >> N;
    vector<LL> A(N,0);
    REP(i,N)cin>>A[i];

    long long ans = 0;
    
    int mode = 0; //0:不定, 1:非減少, 2:非増加
    FOR(i,1,N){
        LL pre_val = A[i-1];
        LL val = A[i];

        if(mode==0){
            if(pre_val < val){
                mode = 1;
            }else if (pre_val > val){
                mode = 2;
            }
        }else if(mode==1){
            if(pre_val > val){
                ans+=1;mode=0;
            }
        }else if(mode==2){
            if(pre_val < val){
                ans+=1;mode=0;
            }
        }

    }

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

Measured memory_bytes: 3964
N, M ,K = map(int, input().split())
# aN + bM - ab =　K となるA,Bが存在するか。

for a in range(M + 1):
  for b in range(N + 1):
    if a * N + b * M - 2 * a * b == K:
      print("Yes")
      exit()
print("No")



Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
string a,b;
int main()
{
    cin>>a;
    b=a;
    int l=a.size();
    reverse(a.begin(),a.end());
    for(int i=0;i<l;i++)
    {
        if(a[i]=='b') a[i]='d';
        else if(a[i]=='d') a[i]='b';
        else if(a[i]=='p') a[i]='q';
        else if(a[i]=='q') a[i]='p';
    }
    if(a==b) printf("Yes\n");
    else printf("No\n");
    return 0;
}

Measured memory_bytes: 512
/*
[nikkei2019-qual] E - Weights on Vertices and Edges
*/

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;

const int MAX_N = 1e5;
const int MAX_M = 1e5;

class UnionFind {
public:
    vector<ll> data;
    UnionFind(int size) : data(size, -1) {}
    bool unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) {
            return false;
        }
        if (data[y] < data[x]) {
            swap(x, y);
        }
        data[x] += data[y];
        data[y] = x;

        return true;
    }
    bool same(int x, int y) { return root(x) == root(y); }
    int root(int x) { return data[x] < 0 ? x : (data[x] = root(data[x])); }
    ll size(int x) { return -data[root(x)]; }
};

struct Edge {
    int u, v;
    ll w;
    bool operator<(Edge e) { return w < e.w; }
};

int N, M;
ll X[MAX_N];
Edge es[MAX_M];
vector<pii> g[MAX_N];
bool is_cand[MAX_M];
bool used[MAX_M];

ll solve() {
    sort(es, es + M);

    UnionFind uf(N);
    for (int i = 0; i < N; i++) {
        uf.data[i] = -X[i];
    }
    for (int i = 0; i < M; i++) {
        g[es[i].u].push_back({es[i].v, i});
        g[es[i].v].push_back({es[i].u, i});

        uf.unite(es[i].u, es[i].v);
        if (uf.size(es[i].v) >= es[i].w) {
            is_cand[i] = true;
        }
    }

    int ans = M;
    for (int i = M - 1; i >= 0; i--) {
        if (used[i] || !is_cand[i]) {
            continue;
        }

        queue<int> q;
        q.push(es[i].u);
        q.push(es[i].v);
        used[i] = true;
        ans--;
        while (!q.empty()) {
            int v = q.front();
            q.pop();
            for (pii p : g[v]) {
                int to = p.first, m = p.second;
                if (used[m] || es[m].w > es[i].w) {
                    continue;
                }
                used[m] = true;
                ans--;
                q.push(to);
            }
        }
    }

    return ans;
}

int main() {
    cin >> N >> M;
    for (int i = 0; i < N; i++) {
        cin >> X[i];
    }
    for (int i = 0; i < M; i++) {
        cin >> es[i].u >> es[i].v >> es[i].w;
        es[i].u--;
        es[i].v--;
    }

    cout << solve() << endl;

    return 0;
}


Measured memory_bytes: 9600
#include<iostream>
#include<vector>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;

int main(){
	long long int a,b,n;
	cin>>a>>b>>n;
	long long int x;
	if(b-1<=n)x = b-1;
	else x = n;

	cout<<a*x/b<<endl;

	return 0;
}

Measured memory_bytes: 3620
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<cstring>
#include<vector>
using namespace std;
#define INT(x) int x; scanf("%d",&x)
#define INPUT(x) scanf("%d",&x)
#define REP1(x,n) for(int x = 0; x < n; x++)
#define REP2(s,e) for(int x = s; x <= e; x++)
#define BR printf("\n")
#define INF 2000000000

// Node(parent)
int Node[10000] = {};

int same(int x, int y){
    int x_i = x,y_i = y;
    while (x_i != Node[x_i]) {
        x_i = Node[x_i];
    }
    while (y_i != Node[y_i]) {
        y_i = Node[y_i];
    }
    
    if (x_i - y_i) {
        return 0;
    }else{
        return 1;
    }
}

void unite(int x, int y){
    
    if (same(x,y) == 1) {
        return;
    }
    
    int x_i = x,y_i = y;
    while (x_i != Node[x_i]) {
        x_i = Node[x_i];
    }
    while (y_i != Node[y_i]) {
        y_i = Node[y_i];
    }
    
    Node[y_i] = x_i;
    Node[y] = x_i;
}

int main(){
    INT(n);
    INT(q);
    REP1(i,n) Node[i] = i;
    REP1(i,q){
        INT(com);INT(x);INT(y);
        if (com) {
            printf("%d\n",same(x,y));
        }else{
            unite(x,y);
        }
    }
    return 0;
}

Measured memory_bytes: 1228
#include<bits/stdc++.h>
using namespace std;
#define int             long long int
#define pb              push_back
#define se              second
#define mp              make_pair
#define fi              first
#define del(a,vec)      vec.erase(std::remove(vec.begin(), vec.end(), a), vec.end());
#define search(f,l,v)   binary_search(f,l,v)
#define iter(a,b)       vector<int>::iterator a,b
#define lower(v,num)    lower_bound (v.begin(), v.end(), num);
#define upper(v,num)    upper_bound (v.begin(), v.end(), num); 
#define removecopy(a)   unique(a.begin(), a.end()); 
#define vi              vector<int> 
#define pi              pair<int,int>    
#define vpi             vector<pi>      
#define mlbb            ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)    
int mod =1000000007;
namespace Rahul{
    bool isPrime(int n) 
    {if (n <= 1)  return false; if (n <= 3)  return true; 
    if (n%2 == 0 || n%3 == 0) return false; 
    for (int i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
    return true; }
    int pow (int x, int n,int mod) {//calculate x^n
    if (n == 0) return 1;

    int res = pow (x, n / 2,mod);

    res = (res * res) % mod;
    if (n % 2) res = (res * x ) % mod;

    return res;
    }
    int _gcd(int a,int b)
    {
        if(a==0)
            return b;
        else    
            return _gcd(b%a,a);
    }
    //s.erase(s.find(2)) where s={1,2,3,3,2}; 
};
using namespace Rahul;
int32_t main()
{
        
     mlbb;   
      int n;
      cin>>n;
      string s1,s2;
      cin>>s1>>s2;
      for(int i=0;i<n;i++)  
      cout<<s1[i]<<s2[i];
      
      cout<<endl;
     
}


Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var n, k, q, a int
	fmt.Scan(&n, &k, &q)
	m := map[int]int{}
	for i := 0; i < q; i++ {
		fmt.Scan(&a)
		m[a]++
	}

	for i := 1; i <= n; i++ {
		if k-(q-m[i]) <= 0 {
			fmt.Println("No")
		} else {
			fmt.Println("Yes")
		}
	}
}


Measured memory_bytes: 9516
#include<iostream>

using namespace std;
int main()
{
  int n;
  cin >> n;
  bool flag = false;
  if(n % 10 == 9)
    flag = true;
  if(n / 10 % 10 == 9)
    flag = true;
  if(flag)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
namespace CsProgramSpace
{
    class Program
    {
        static void Main(string[] args)
        {
            ushort[] u = (Console.ReadLine().Split(' ').Select(_ => ushort.Parse(_)).ToArray());
            Array.Sort(u);
            for(int i = 0; i<u.Length;i++)
            {
                if (i == 0)
                    Console.Write(u[i]);
                else
                    Console.Write(string.Format(" {0}", u[i]));
            }
            Console.Write("\r\n");
        }
    }
}


Measured memory_bytes: 18536
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "../../dump.hpp"
#else
#define dump(...)
#endif

#define int ll
#define rep(i, n) for (int i = 0, i##_cond = (n); i < i##_cond; ++i)
#define FOR(i, a, b) for (int i = (a), i##_cond = (b); i < i##_cond; ++i)
#define ROF(i, a, b)                                                           \
  for (int i = (a)-1, i##_cond = (b); i >= i##_cond; --i) // ROF(i,n,0)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend() // sortで降順
#define SUM(a) accumulate(all(a), int(0))
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using pii = pair<int, int>;
constexpr ll inf = 1ll << 61;
constexpr ll mod = 1e9 + 7;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> T add(const T &a, const T &b) { return (a + b) % mod; }

map<int, int> pf(int n) {
  map<int, int> res;
  FOR(i, 2, sqrt(n) + 1) {
    if (n == 1)
      break;
    while (n % i == 0) {
      res[i]++;
      n /= i;
    }
  }
  if (n != 1)
    res[n]++;
  return res;
}

signed main() {
  int n;
  cin >> n;
  auto m = pf(n);

  int ans = 0;
  for (auto p : m) {
    int tmp = sqrt(2 * p.second); // tmp or tmp-1
    dump(tmp, p.second);
    int a = tmp;
    dump(p.second, a * (a + 1) / 2);
    if (p.second < a * (a + 1) / 2)
      ans += a - 1;
    else
      ans += a;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3704
#include <iostream>
using namespace std;
 
#define MOD 1000000007
#define MAXN 1010
 
long long dp[MAXN][MAXN];
int grid[MAXN][MAXN];
 
int H,W;
 
int main() {
  cin >> H >> W;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      char c; cin >> c;
      if (c == '#') {
        grid[i][j] = 1;
      }
    }
  }
  for (int i = H-1; i >= 0; i--) {
    for (int j = W-1; j >= 0; j--) {
      if (grid[i][j] == 1) {
        dp[i][j] = 0;
      } else {
        if (i == H-1 && j == W-1) {
          dp[i][j] = 1;
        } else if (i == H-1) {
          dp[i][j] = dp[i][j+1];
        } else if (j == W-1) {
          dp[i][j] = dp[i+1][j];
        } else {
          dp[i][j] = (dp[i+1][j]+dp[i][j+1])%MOD;
        }
      }
    }
  }
  cout << dp[0][0] << endl;
}
      

Measured memory_bytes: 12160
#include<bits/stdc++.h>
using namespace std;
const int N=100005;
int a[N];
int main()
{
    int n,x,ans=0,ans2=0;
    scanf("%d%d",&n,&x);
    for(int i=1;i<=n;i++)
    	scanf("%d",&a[i]);
    sort(a+1,a+n+1);
    for(int i=1;i<n;i++)
    	ans=__gcd(ans,a[i+1]-a[i]);
    for(int i=1;i<=n;i++)
    	ans2=max(ans2,__gcd(ans,abs(a[i]-x)));
    printf("%d\n",ans2);
	return 0;
}


Measured memory_bytes: 640
def extraction(array, design):
    for i in range(1, 14):
        if i not in array:
            print(design, i)
            
n = int(input())
S = []
H = []
C = []
D = []
for i in range(n):
    design, num = input().split()
    if design == "S":
        S.append(int(num))
    elif design == "H":
        H.append(int(num))
    elif design == "C":
        C.append(int(num))
    else:
        D.append(int(num))
extraction(S, "S")
extraction(H, "H")
extraction(C, "C")
extraction(D, "D")

Measured memory_bytes: 7704
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#define all(a) a.begin(),a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef long double ld;
typedef complex<ld> com;
constexpr int inf = 1000000000;
constexpr ll INF = 1000000000000000000;
constexpr ld EPS = 1e-12;
constexpr ld PI = 3.141592653589793238;
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }


signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);

	int n, l;
	cin >> n >> l;
	vector<string> s(n);
	rep(i, n) cin >> s[i];
	sort(all(s));
	rep(i, n) cout << s[i];
	cout << '\n';
}

Measured memory_bytes: 256
n, x = map(int, input().split())
l = [int(i) for i in input().split()] 

d = 0
i = 0
if x > 0:
    while d <= x:
        d = d + l[i]
        i = i + 1
        if i >= n:
            break
    if d > x:
        print(i)
    elif d <= x:
        print(n+1)
elif x <= 0:
    print(1)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int N = 100010;
 
int main() {
  int n, m, h[N], ma[N];
  cin >> n >> m;
  for(int i = 1; i <= n; i++){
    cin >> h[i];
    ma[i] = 0;
  }
  for(int i = 0; i < m; i++){
    int a, b;
    cin >> a >> b;
    ma[a] = max(ma[a], h[b]);
    ma[b] = max(ma[b], h[a]);
  }
  int ans = 0;
  for(int i = 1; i <= n; i++){
    ans+=h[i]>ma[i];
  }
  cout << ans << endl;
}


Measured memory_bytes: 4424
N, *L,  = [list(map(int, s.split())) for s in open(0)]
A = L[0]

A_sorted = sorted(A)
flag = 0
if A == A_sorted:
    flag += 1
for i in range(len(A) - 1):
    for j in range(i+1, len(A)):
        A_ = A.copy()
        tmp = A_[i]
        A_[i] = A_[j]
        A_[j] = tmp
        if A_sorted == A_:
            flag += 1
if flag:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3064
N, M=map(int, input().split())
s=[list(map(int, input().split())) for i in range(M)]
p=list(map(int, input().split()))

ans=0

for i in range(2**N):
    swi=bin(i)[2:].rjust(N, "0")
    lights=1

    for j in range(M):
        cnt=0
        for k in range(1, s[j][0]+1):
            if swi[s[j][k] -1] == "1":
                cnt+=1

        if cnt%2 != p[j]:
            lights=0
    
    if lights==1:
        ans+=1

print(ans)

Measured memory_bytes: 3064
#include<iostream>

using namespace std;

int main(void){
	int b,r,g,c,s,t,ans;
	while(1){
		cin >> b >> r >> g >> c >> s >> t;
		if(b==0 && r==0 && g==0 && c==0 && s==0 && t==0)break;
		ans=100;
		ans+=b*15*6;
		ans+=r*15*4;
		ans+=g*7;
		ans+=c*2;
		ans-=(t-s-b*5-r*3)*3;
		ans-=b*5*2+r*3*2;
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 0
import sys
from collections import Counter

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 19
MOD = 10 ** 9 + 7
EPS = 10 ** -10

N = INT()

C = Counter()
for x in range(1, N+1):
    for y in range(1, N+1):
        if x**2 + y**2 + x*y > N:
            break
        for z in range(1, N+1):
            n = x**2 + y**2 + z**2 + x*y + y*z + z*x
            if n > N:
                break
            C[n] += 1

for i in range(1, N+1):
    print(C[i])


Measured memory_bytes: 70680
#include<iostream>
using namespace std;
 
int main(){
  
  int a,b;
  double f;
  
  cin >> a >> b;

  f = 1.0 * a/b;
  
  cout << a/b <<" "<< a%b <<" "<< fixed << f << endl;
  
  return 0;		 
}


Measured memory_bytes: 3256
import java.util.HashMap;
import java.util.Scanner;

public class Main {

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


    public static void main(String[] args) {

        int a = sc.nextInt();
        if (a < 105) {
            System.out.println(0);
            return;
        }
        int ans = 0;
        int start = a;
        if (a % 2 == 0) {
            start = a - 1;
        }

        while (start >= 1) {
            if (calc(start)) {
//                System.out.println(start);
                ans++;
            }
            start = start - 2;
        }
        System.out.println(ans);
    }

    private static boolean calc(int start) {
        int num = start;
        int count = 2;
        HashMap<Integer, Integer> map = new HashMap<>();
        while (num > 1) {
            if (num % count == 0) {
                num = num / count;
                if (map.containsKey(count)) {
                    map.put(count, map.get(count) + 1);
                } else {
                    map.put(count, 1);
                }
            } else {
                count++;
            }
        }
        int ans = 1;
        for (Integer key : map.keySet()) {
            ans *= (map.get(key) + 1);
        }
        return ans == 8;
    }
}


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

//define-----------------------------------------------------------------------------------------------------------------------
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define FOR(i, s, n) for(int i = s; i < (int)n; i++)
#define per(i, n) for(int i = n; i >= 0; i--)
#define ROF(i, s, n) for(int i = s; i >= (int)n; i--)
#define FORIT(i, A) for (auto i : A)
#define PRINT(x) cout << (x) << "\n"
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define MP make_pair
#define EACH(i, n) for (__typeof((n).begin()) i = (n).begin(); i != (n).end(); ++i)
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define CLR(a) memset((a), 0 ,sizeof(a))
#define dump(x) cout << #x << " = " << (x) << "\n";
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << "\n";
#define sq(n) (n) * (n)

//typedef----------------------------------------------------------------------------------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef priority_queue<int> maxpq;
typedef priority_queue< int, vector<int>, greater<int> > minpq;
//const------------------------------------------------------------------------------------------------------------------------
static const double EPS = 1e-10;
static const double PI = acos( -1.0 );
static const int mod = 1000000007;
static const int INF = 1 << 25;
static const LL LL_INF = 1152921504606846976;
//global-----------------------------------------------------------------------------------------------------------------------
int n, m, ans;
VS ar;
set<string> s;
//#define DEBUG
//int dp[200000000][]
int solve( int now, string str ) {
	if ( now == m ) {
		if ( s.count( str ) ) {
			return 0;
		}
		s.insert( str );
		return 1;
	}
	int res = 0;
	for ( int i = now; i < n; i++ ) {
		swap( ar[ now ], ar[ i ] );
		res += solve( now + 1, str + ar[ now ] );
		swap( ar[ now ], ar[ i ] );
	}
	return res;
}
int main() {
	while ( scanf( "%d %d", &n, &m ) != EOF && n && m ) {
		ar.resize( n );
		for ( int i = 0; i < n; i++ ) {
			cin >> ar[ i ];
		}
		SORT( ar );
		printf( "%d\n", solve( 0, "" ) );
		s.clear();
	}
	return 0;
}

Measured memory_bytes: 1504
#include<iostream>
using namespace std;
int main() {
	int n;
	cin>>n;
	int b=0;
	for(int i=1; i<=9; i++) {
		for(int j=1; j<=9; j++) {
			if(i*j==n)  {
				b=1;
			}
		}
	}
	if(b==1)  cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
	int a, b,x;
	char ap='+';
	while (1){
		cin >> a >> ap >> b;
		if (ap == '+')
			x = a + b;
		else if (ap == '-')
			x = a - b;
		else if (ap == '*')
			x = a*b;
		else if (ap == '/')
			x = a / b;
		else if (ap == '?')
			break;
		cout << x<<endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int main()
{
    int h,n,x,s=0;
    cin>>h>>n;
    for(int i=1;i<=n;i++)
    {
    	cin>>x;
    	s+=x;
	}
	if(s>=h)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) (y<0||x<0||y>=h||x>=w)
#define dump(...)
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
#define INF (1001001001)
#define INFLL (1001001001001001001ll)
template<class T> ostream& operator << (ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v)) os<<*i<<(i==end(v)-1?"":"\n"); return os; }
template<class T> istream& operator >> (istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i; return is; }
template<class T> istream& operator >> (istream &is, pair<T,T> &p) {
    is>>p.first>>p.second; return is; }
template<class T>bool chmax(T &a,const T &b) {if(a<b) {a=b;return 1;} return 0;}
template<class T>bool chmin(T &a,const T &b) {if(b<a) {a=b;return 1;} return 0;}
//------------------------------------------------------------------------------
struct before_main_function {
    before_main_function() {
        #ifdef int
            #undef INF
            #define INF INFLL
            #define stoi stoll
        #endif
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
        #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    set<int> s;
    int n;
    cin>>n;
    REP(i,n) {
        int a;
        cin>>a;
        if(CONTAIN(s,a)) {
            s.erase(a);
        } else {
            s.insert(a);
        }
    }
    cout<<SZ(s)<<endl;
    return 0;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
 
#define for_(i,a,b) for(int i=(a);i<(b);++i)
typedef long long lint;
 
int N;
lint x, a[2020];
 
int main() {
	cin >> N >> x;
	for_(i,0,N) cin >> a[i];
	
	vector< lint > min_a(N, 1 << 30);
	lint ans = 1LL << 60;
	
	for_(k,0,N) {
		lint ans_k = 0;
		for_(i,0,N) ans_k += (min_a[i] = min(min_a[i], a[(i - k + N) % N]));
		ans = min(ans, ans_k + (lint)k * x);
	}
	
	cout << ans << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>

#define REP(_i,_len) for(int _i=0;_i<_len;++_i)
#define REP2(_i,_len,N) for(int _i=0,_len=N;_i<_len;++_i)
#define VREP(v,_itr,_end) for(auto _itr=v.begin(),_end=v.end();_itr!=_end;++_itr)
#define VCREP(v,_itr,_end) for(auto _itr=v.cbegin(),_end=v.cend();_itr!=_end;++_itr)

using namespace std;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<vi > vvi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll > vvll;

typedef map<int, int> mii;
typedef vector<mii > vmii;

#define SIZE 1000

int main(int argc, const char * argv[]) {
    int N,W;
    cin>>N>>W;
    
    vi w(N),v(N);
    REP(i,N){
        cin>>w[i]>>v[i];
    }
    
    const int maxV=SIZE*N+1;
    vi dp1(maxV),dp2(maxV);
    bool flg1=true;
    REP(i,N){
        vi &dpN=flg1?dp1:dp2,&dpO=flg1?dp2:dp1;
        REP(j,maxV){
            if(i==0){
                if(j<=v[0]){
                    dpN[j]=w[0];
                }else{
                    dpN[j]=INT32_MAX;
                }
                continue;
            }
            if(j<=v[i]){
                dpN[j]=min(w[i],dpO[j]);
            }else{
                dpN[j]=(int)min((ll)dpO[j-v[i]]+w[i],(ll)dpO[j]);
            }
        }
        flg1=!flg1;
    }
    vi &dpO=(flg1?dp2:dp1);
    int val=0;
    for(int j=maxV-1;j>=0;--j){
        if(dpO[j]<=W){
            val=j;
            break;
        }
    }
    cout<<val<<endl;
    
    return 0;
}


Measured memory_bytes: 3568
#include<iostream>
#include<vector>
using namespace std;
int main(){
  int N;
  cin>>N;
  int ans=N;
  vector<int> datea(N),dateb(N);
  for(int i=0;i<N;i++){
    cin>>datea[i]>>dateb[i];
  }
  for(int i=0;i<N;i++){
    ans+=dateb[i]-datea[i];
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
let () = Scanf.scanf "%d %d\n" @@ fun n k ->
  let ps = Array.init n @@ fun _ -> Scanf.scanf "%d " @@ fun p -> p in
  Array.sort compare ps;
  Printf.printf "%d\n" @@
  Array.fold_left ( + ) 0 @@
  Array.sub ps 0 k


Measured memory_bytes: 4088
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define ctoi(x) x-'0'
#define pshb(a) cin >> x;a.push_back(x)
#define fr(i,n) for(ll i=0;i<n;i++)
#define fast ios_base::sync_with_stdio(false);
using namespace std;
int main()
{
    ll n  ,cnt=1 , ans =0 ;
    cin>>n  ;
    n/=2 ;
    ll s=2 ;
    while (n>0)
    {
        cnt+=s ;
        s*=2 ;
        n/=2 ;
    }
    cout<<cnt ;
}




Measured memory_bytes: 256
N = int(input())

cache = []
abc = ''
ngflag = False
for i in range(N):
    word = input()
    if abc == '':
        pass
    elif word[0] != abc:
        ngflag = True

    if word in cache:
        ngflag = True
    abc = word[-1]
    cache.append(word)

if ngflag:
    print('No')
else:
    print('Yes')

Measured memory_bytes: 3060
def work(a,b,c,A,B,C):
 if A==0:
  return work(b,c,'',B,C,0)
 if B==0:
  if C==0:
   return a*A
  else:
   return work(a,c,'',A,C,0)
 if C==0:
  return work(a+b*(B/A),a+b*(B/A+1),'',A-B%A,B%A,0)
 cmod = C%A
 if B <= A-cmod:
  return work(a+c*(C/A),a+c*(C/A)+b,a+c*(C/A+1),A-cmod-B,B,cmod)
 else:
  bmod = B%(A-cmod)
  return work(a+c*(C/A)+b*(B/(A-cmod)),a+c*(C/A)+b*(B/(A-cmod)+1),a+c*(C/A+1),A-bmod-cmod,bmod,cmod)

if __name__ == '__main__':
 s = raw_input()
 a,b,c = [int(i) for i in s.split()]
 print(work('a','b','c',a,b,c))


Measured memory_bytes: 2696
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>

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 RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define FIND(s, e) ((s).find(e) != (s).end())
#define EB emplace_back

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

void solve(int N) {
    vector<set<int>> p(N);
    REP(i, N) {
        int m; cin >> m;
        REP(_, m) {
            int n; cin >> n;
            p[i].insert(n);
        }
    }
    int K; cin >> K;
    VI l(K);
    REP(i, K) cin >> l[i];
    int ans = -1;
    int cnt = 0;
    REP(i, N) {
        bool f = true;
        FORE(e, l) {
            if (!FIND(p[i], e)) f = false;
        }
        if (f) {
            ans = i;
            cnt++;
        }
    }
    if (cnt != 1) {
        cout << -1 << endl;
    } else {
        cout << ans + 1 << endl;
    }
    return;
}

signed main(void) {
    int n, m, p, a, b, c, x, y, z, q;
    string s;
    bool f = false;
    while (cin >> n, n) {
        solve(n);
        //return 0;
    }
}

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

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

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

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

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

int main() {
    ll A,B,C,K; cin >> A >> B >> C >> K;
    corner(A>=K,K);
    corner(A+B>=K,A);
    ll L = A, R = K-(A+B);
    cout << L - R << endl;
    return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S, T, U;
  int A, B;
  cin >> S >> T >> A >> B >> U;
  if (S == U) {
	A -= 1;
  }
  else {
    B -= 1;
  }
  cout << A << " " << B << endl;
  return 0;
}

Measured memory_bytes: 256
program main
    use,intrinsic :: iso_fortran_env
    implicit none
    character(200000):: cn
    integer(int32):: ds, i

    read*, cn

    ds = 0
    do i=1,len_trim(cn)
        ds=ds+(ichar(cn(i:i))-ichar("0"))
    end do

    if (mod(ds,9)==0) then
        print'(a)', 'Yes'
    else
        print'(a)', 'No'
    end if
    

end program main

Measured memory_bytes: 3188
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>

using namespace std;



int main(){
	int N;
	long long H;

	scanf("%d %lld", &N, &H);

	long long a[100000];
	long long b[100000];
	for(int i=0;i<N;i++){
		scanf("%lld %lld", &a[i], &b[i]);
	}

	sort(a,a+N);
	reverse(a,a+N);
	sort(b,b+N);
	reverse(b,b+N);

	long long ans = 0;
	for(int i=0;i<N;i++){
		if(b[i]<a[0]) break;
		H -= b[i];
		ans++;
		if(H<=0) break;
	}
	//printf("%lld\n", H);
	if(H>0) ans += (H+a[0]-1)/a[0];

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

	return 0;
}


Measured memory_bytes: 1664
N = int(input())
S = input()
  
ans = 0
for i1 in range(10):
  for i2 in range(10):
    for i3 in range(10):
      p = 1
      for f in range(N):
        if(p == 1 and S[f] == str(i1)):
          p = 2
        elif(p == 2 and S[f] == str(i2)):
          p = 3
        elif(p == 3 and S[f] == str(i3)):
          ans += 1
          break
        
print(ans)

Measured memory_bytes: 45712
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
typedef pair<int, int> P;
const int MAX_H = 30;
const int MAX_W = 30;
const int inf = 1<<30;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, 1, 0, -1};
int H, W;
char maze[MAX_H][MAX_W];
int d[MAX_H][MAX_W];
int sx, sy, gx, gy;

int bfs() {
  queue<P> que;
  for(int i = 0; i < H; i++) {
    for(int j = 0; j < W; j++) d[i][j] = inf;
  }
  que.push(P(sx, sy));
  d[sy][sx] = 0;

  while(que.size()) {
    P p = que.front(); que.pop();
    if(p.first == gx && p.second == gy) break;
    for(int i = 0; i < 4; i++) {
      int nx = p.first + dx[i];
      int ny = p.second + dy[i];
      if(0 <= nx && nx < W && 0 <= ny && ny < H && maze[ny][nx] != '#' && d[ny][nx] == inf) {
        que.push(P(nx, ny));
        d[ny][nx] = d[p.second][p.first] + 1;
      }
    }
  }
  return d[gy][gx];
}

int main() {
  cin >> H >> W;
  for(int i = 0; i < H; i++) {
    for(int j = 0; j < W; j++) {
      cin >> maze[i][j];
    }
  }

  int res = 0;
  for(int i = 0; i < H; i++) {
    for(int j = 0; j < W; j++) {
      for(int k = 0; k < H; k++) {
        for(int l = 0; l < W; l++) {
          sy = i, sx = j;
          gy = k, gx = l;
          if(maze[sy][sx] == '#' || maze[gy][gx] == '#') continue;
          res = max(res, bfs());
        }
      }
    }
  }
  cout << res << endl;
  return 0;
}



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

int main() {
	int K;
	string S;

	cin >> K >> S;

	if (S.size() <= K) {
		cout << S << endl;
	}
	else {
		for (int i = 0; i < K; i++) {
			cout << S.at(i);
		}
		cout << "..." << endl;
	}
	return 0;
}

Measured memory_bytes: 3040
#![allow(unused_imports, non_snake_case)]
use proconio::{
    input, fastout,
    marker::{Chars, Bytes, Usize1}
};

#[fastout]
fn main() {
    input!{
        s: Chars,
        t: Chars,
    }
    let n = s.len();
    let m = t.len();
    let mut ans = m;
    for i in 0..n-m+1 {
        let mut cur = 0;
        for j in 0..m {
            if s[i+j] != t[j] {cur += 1};
        }
        ans = std::cmp::min(ans, cur);
    }
    println!("{}", ans);
}


Measured memory_bytes: 2184
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder
{
	class Program
	{
		static void Main(string[] args)
		{
			slove();
		}

		static void slove()
		{
			int N = int.Parse(Console.ReadLine());
			int A = int.Parse(Console.ReadLine());

			if (N % 500 - A <= 0)
			{
				Console.WriteLine("Yes");
			}
			else
			{
				Console.WriteLine("No");
			}
			Console.ReadKey();
		}
	}
}


Measured memory_bytes: 11092
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <queue>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int mod = 1000000007;
int dp[100005][2];
int main() {
    string s;
    cin >> s;
    int n = s.size();
    dp[0][0] = 1;
    rep(i, n) {
        {
            //a+b=0
            if (s[i] == '0') {
                dp[i+1][0] = dp[i][0];
                dp[i+1][1] = dp[i][1];
            } else {
                dp[i+1][1] = (dp[i][1] + dp[i][0]) % mod;
            }
        }
        {
            //a+b=1
            if(s[i] == '0') {
                (dp[i+1][1] += dp[i][1]*2 % mod) %= mod;
            } else {
                (dp[i+1][0] += dp[i][0]*2 % mod) %= mod;
                (dp[i+1][1] += dp[i][1]*2 % mod) %= mod;
            }
        }
    }

    int ans = (dp[n][0]+dp[n][1]) % mod;
    cout << ans << endl;
}

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

int main() {
  int a, b;
  string one = "";

  cin >> a >> b;

  for (int i = 0;i < max(a, b);i++) {
    one += to_string(min(a,b));
  }

  cout << one;

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include<string>
#include<queue>
using namespace std;

int main(){
    int n,q,t;
    string name;
    queue<pair<string,int> > Q;

    cin>>n>>q;
    for(int i=0;i<n;i++){
        cin>>name>>t;
        Q.push(make_pair(name,t));
    }   
    pair<string,int> u;
    int elaps=0,a;

    while(!Q.empty()){
        u=Q.front(); Q.pop();
        a=min(u.second,q);
        u.second-=a;
        elaps+=a;
        if(u.second>0){
            Q.push(u);
        }else{
            cout<<u.first<<" "<<elaps<<"\n";               
        }   
    }   
    return 0;
}



Measured memory_bytes: 6328
import java.io.IOException;

import java.io.BufferedReader;
import java.io.InputStreamReader;

import java.io.PrintWriter;

import java.util.Arrays;
import java.util.ArrayList;

class Edge implements Comparable<Edge> {
    // 頂点番号 最小コスト
    int to;
    int cost;

    Edge(int to, int cost) {
        this.to = to;
        this.cost = cost;
    }

    // x.compereTo(y)
    // x は cost
    // y は Edge.cost
    @Override
    public int compareTo(Edge edge) {
        return this.cost - edge.cost;
    }
}

@SuppressWarnings("unchecked")
public class Main {
    static final String sp = " ";

    public static void main(String[] args) throws IOException {
        final String s;

        try (
            BufferedReader reader = new BufferedReader(
                new InputStreamReader(System.in))) {
            s = reader.readLine();
        }

        PrintWriter out = new PrintWriter(System.out);

        int L = Integer.parseInt(s);

        // log 2
        int r = (int)Math.floor(Math.log(L) / Math.log(2.0));

        int N = r + 1;

        ArrayList<Edge>[] routeList = new ArrayList[N];

        for (int i = 0; i < N; i++) routeList[i] = new ArrayList<>();

        int cnt = 0;

        // t = {0, 1, …, N - 1}
        // 頂点 t + 1 から t + 2 へ
        // コスト 2^t と 0 の辺を張る
        for (int t = 0; t < N - 1; t++) {
            // 0-indexed
            routeList[t].add(new Edge(t + 1, (int)Math.pow(2,t)));
            routeList[t].add(new Edge(t + 1, 0));
            cnt++;
            cnt++;
        }

        // t = {N - 1, N - 2, …, 1}
        // 2^r <= L - 2^(t-1) 満たすなら
        // 頂点 t から 頂点 N に対してコスト L - 2^(t-1) の辺を張る
        // L から 2^(t-1)を引く
        for (int t = N - 1; 0 < t; t--) {
            int num1 = (int)Math.pow(2, r);

            int num2 = (int)Math.pow(2, t - 1);
            if (num1 - 1 < L - num2) {
                // 0-indexed
                routeList[t - 1].add(new Edge(N - 1, L - num2));
                cnt++;
                L -= num2;
            }
        }

        // 頂点の数 辺の数
        out.println(N + sp + cnt);
        for (int i = 0; i < N; i++) {
            for (Edge e : routeList[i]) {
                // 0-indexed
                Integer from = i + 1;
                int to = e.to + 1;
                int cost = e.cost;
                out.println(from + sp + to + sp + cost);
            }
        }

        out.flush();
    }
}


Measured memory_bytes: 22356
import Control.Applicative
import Control.Monad
import Data.List

main :: IO ()
main = do
    [h, w] <- fmap read . words <$> getLine :: IO [Int]
    xs <- fmap concat . replicateM h $ words <$> getLine
    let is = [(h, w) | h <- [1 .. h], w <- take w ['A' ..]]
    let cs = zip xs is
    let Just (h, w) = lookup "snuke" cs
    putStrLn $ w : show h

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

bool checkIncluded(const int *ls, int length, int x){
    int index = length/2;
    bool even = false;
    if((length % 2) == 0)
        even = true;
    if(ls[index] == x)
        return true;
    if(index <= 0)
        return false;
    int temp[index];
    int len = index;
    if(ls[index] < x){
        if(even){
            memcpy(temp, &ls[index+1], sizeof(int)*(index-1));
            len = index - 1;
        }else{
            memcpy(temp, &ls[index+1], sizeof(int)*index);
        }
    }else{
        memcpy(temp, &ls[0], sizeof(int)*index);
    }
    return checkIncluded(temp, len, x);
}

int main(){
    int x;
    cin >> x;
    int ls[x];
    for(int i=0; i<x; i++){
        cin >> ls[i];
    }
    int num;
    cin >> num;
    int count = 0;
    for(int i=0; i<num; i++){
        int temp;
        cin >> temp;
        if(checkIncluded(ls, x, temp))
            count ++;
    }
    cout << count << "\n";
}


Measured memory_bytes: 3832
#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define dbg(...) cerr << #__VA_ARGS__ << " ->", debug_out(__VA_ARGS__)
#define dbg_p(x) cerr<<#x": "<<(x).first<<' '<<(x).second<<endl
#define dbg_v(x, n) {cerr<<#x"[]: ";for(long long _=0;_<n;++_)cerr<<(x)[_]<<' ';cerr<<endl;}
#define all(v) v.begin(), v.end()
#define fi first
#define se second
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...);}

template<typename T1, typename T2>
ostream& operator <<(ostream &out, const pair<T1, T2> &item) {
	out << '(' << item.first << ", " << item.second << ')';
	return out;
}

template <typename T>
ostream& operator <<(ostream &out, const vector<T>& v) {
	for(const auto &item : v) out << item << ' ';
	return out;
}

const int N = 2010;

bool ok[3][3][N];
string s[3];

bool eq(char c1, char c2) {
	if(c1 == '?' || c2 == '?') return true;
	return c1 == c2;
}

void pre(int i, int j) {
	for(int p = 0; p <= s[i].length(); ++p) {
		ok[i][j][p] = true;
		for(int k = 0; ok[i][j][p] && k < s[j].length() && p + k < s[i].length(); ++k) {
			if(!eq(s[i][p + k], s[j][k])) ok[i][j][p] = false;
		}
	}
}

int solve(int i, int j, int k) {
	int res = 3 * N;
	//dbg(s[i].length(), s[j].length());
	for(int p1 = 0; p1 <= s[i].length(); ++p1)
		for(int p2 = p1; p2 <= s[i].length() || p2 <= p1 + s[j].length(); ++p2) {
			if(!ok[i][j][p1]) continue;
			if(p2 - p1 < s[j].length() && !ok[j][k][p2 - p1]) continue;
			if(p2 < s[i].length() && !ok[i][k][p2]) continue;

			int len = max({s[i].length(), p1 + s[j].length(), p2 + s[k].length()});
			//dbg(p1, p2, len);
			res = min(res, len);
		}

	return res;
}

int main()
{
	ios_base::sync_with_stdio(false);
	
	cin >> s[0] >> s[1] >> s[2];
	for(int i = 0; i < 3; ++i)
		for(int j = 0; j < 3; ++j)
			if(i != j) pre(i, j);

	int ans = 3 * N;
	ans = min(ans, solve(0, 1, 2));
	ans = min(ans, solve(0, 2, 1));
	ans = min(ans, solve(1, 0, 2));
	ans = min(ans, solve(1, 2, 0));
	ans = min(ans, solve(2, 0, 1));
	ans = min(ans, solve(2, 1, 0));

	cout << ans << '\n';

	return 0;
}



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

using namespace std;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> a;
  int i;
  i = 0;
  for(i = 0;i < n;i++) {
    int x;
    cin >> x;
    a.push_back(x);
  }
  vector<int> b;
  for(i = 0;i < n;i++) {
    int x;
    cin >> x;
    b.push_back(x);
  }
  vector<int> c;
  for(i = 0;i < n-1;i++) {
    int x;
    cin >> x;
    c.push_back(x);
  }
  int stock;
  int result;
  stock = -1;
  result = 0;
  for(i = 0;i < n;i++) {
    result += b[a[i]-1];
    if(a[i] - stock == 1) {
      result += c[stock-1];
    }
    stock = a[i];
  }

  cout << result << '\n';
}



Measured memory_bytes: 256
a, b, c, d = map(str, list(input()))
data = ["+", "-"]
for x in range(2):
    for y in range(2):
        for z in range(2):
            if eval(a + data[x] + b + data[y] + c + data[z] + d) == 7:
                print("{}{}{}{}{}{}{}{}{}".format(a, data[x], b, data[y], c, data[z], d, "=", "7"))
                exit()


Measured memory_bytes: 9016