akhauriyash/Code-Regression huggingface dataset:
h, w = map(int, input().split())

s = []
for si in range(h):
  s.append(list(input()))

def up_left(s, x, y):
  if x - 1 < 0 or y - 1 < 0:
    return 0
  return 1 if s[y - 1][x - 1] == '#' else 0

def up(s, x, y):
  if y - 1 < 0:
    return 0
  return 1 if s[y - 1][x] == '#' else 0

def up_right(s, x, y, w):
  if y - 1 < 0 or x + 1 >= w:
    return 0
  return 1 if s[y - 1][x + 1] == '#' else 0

def left(s, x, y):
  if x - 1 < 0:
    return 0
  if s[y][x-1] == '#':
    return 1
  return 0

def right(s, x, y, w):
  if x + 1 >= w:
    return 0
  return 1 if s[y][x + 1] == '#' else 0

def down_left(s, x, y, h):
  if y + 1 >= h or x - 1 < 0:
    return 0
  return 1 if s[y + 1][x - 1] == '#' else 0

def down(s, x, y, h):
  if y + 1 >= h:
    return 0
  return 1 if s[y + 1][x] == '#' else 0

def down_right(s, x, y, h, w):
  if y + 1 >= h or x + 1 >= w:
    return 0
  return 1 if s[y + 1][x + 1] == '#' else 0
  
rr = []
for y_i, sy in enumerate(s):
  r = []
  for x_i, x in enumerate(sy):
    bomb_count = 0
    if x == '#':
      r.append(x)
    else:
      # 1
      bomb_count += up_left(s, x_i, y_i)
      bomb_count += up(s, x_i, y_i)
      bomb_count += up_right(s, x_i, y_i, w)
      bomb_count += left(s, x_i, y_i)
      bomb_count += right(s, x_i, y_i, w)
      bomb_count += down_left(s, x_i, y_i, h)
      bomb_count += down(s, x_i, y_i, h)
      bomb_count += down_right(s, x_i, y_i, h, w)
      r.append(str(bomb_count))
  rr.append(r)
    
for ri in rr:
  print(''.join(ri))
  

Measured memory_bytes: 3192
n = gets.to_i
dices = []
n.times do
    dice = gets.chomp.split(" ").map(&:to_i)
    dices.push(dice)
end

dices.combination(2) do |dice1, dice2|
    [
        [0,1,2,3,4,5],[0,3,1,4,2,5],[0,4,3,2,1,5],[0,2,4,1,3,5],
        [1,5,2,3,0,4],[1,3,5,0,2,4],[1,0,3,2,5,4],[1,2,0,5,3,4],
        [2,5,4,1,0,3],[2,1,5,0,4,3],[2,0,1,4,5,3],[2,4,0,5,1,3],
        [3,5,1,4,0,2],[3,4,5,0,1,2],[3,0,4,1,5,2],[3,1,0,5,4,2],
        [4,5,3,2,0,1],[4,2,5,0,3,1],[4,0,2,3,5,1],[4,3,0,5,2,1],
        [5,4,2,3,1,0],[5,3,4,1,2,0],[5,1,3,2,4,0],[5,2,1,4,3,0]
    ].each do |pattern|
        if pattern.map {|i| dice1[i] } == dice2
            puts "No"
            exit
        end
    end    
end

puts "Yes"


Measured memory_bytes: 7776
import java.util.*
import kotlin.comparisons.compareByDescending
import kotlin.comparisons.thenBy

fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val count = HashMap<String, Int>()
    repeat(n) {
        val s = readLine()!!
        val c = count.getOrPut(s, { 0 }) + 1
        count[s] = c
    }
    val ans = count.toList().sortedWith(compareByDescending<Pair<String, Int>> { it.second }.thenBy { it.first })
    for (x in ans) {
        if (x.second != ans[0].second) {
            break
        }
        println(x.first)
    }
}


Measured memory_bytes: 93624
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;

int solve_testcase() {
    int N; scanf("%d", &N);
    if(N == 0) return 1;

    vector<string> vs(N);
    vector<char> cmp;
    for(int i=0; i<N; i++) {
        cin >> vs[i];
        reverse(vs[i].begin(), vs[i].end());
        for(auto c : vs[i]) cmp.emplace_back(c);
    }
    sort(cmp.begin(), cmp.end());
    cmp.erase(unique(cmp.begin(), cmp.end()), cmp.end());

    vector< vector<int> > dec(N);
    for(int i=0; i<N; i++) {
        for(auto c : vs[i]) {
            int k = lower_bound(cmp.begin(), cmp.end(), c) - cmp.begin();
            dec[i].emplace_back(k);
        }
    }
    
    int M = cmp.size(), ans = 0;
    vector<int> use(10);
    for(int i=0; i<M; i++) use[10-1-i] = 1;
    do {
        vector<int> vec;
        for(int i=0; i<10; i++) if(use[i]) vec.emplace_back(i);
        
        do {
            int give = 0, ok = true;

            for(int i=0; i<N; i++) {
                if(dec[i].size() >= 2 and vec[ dec[i].back() ] == 0) {
                    ok = false;
                    break;
                }
            }
            if(!ok) continue;

            for(int d=0; d<10; d++) {
                int s = give;
                for(int i=0; i+1<N; i++) {
                    if(d >= dec[i].size()) continue;
                    s += vec[ dec[i][d] ];
                }
                int t = (d >= dec[N-1].size() ? 0 : vec[ dec[N-1][d] ]);
                ok &= (s % 10 == t);
                if(!ok) break;
                give = s / 10;
            }
            if(ok) ans++;
        }while(next_permutation(vec.begin(), vec.end()));
    }while(next_permutation(use.begin(), use.end()));

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

int main() {
    while(!solve_testcase());
    return 0;
}



Measured memory_bytes: 3328
A, B = map(int, input().split(" "))

if A <= B:
    print("Impossible")
    exit(0)

chain = []
N = A + B

def ask(i, j):
    print("? %d %d" % (i, j))
    return input() == 'Y'

for i in range(0, N):
    if len(chain) == 0:
        chain.append(i)
        continue
    last = chain[-1]
    if ask(last, i):
        chain.append(i)
    else:
        chain.pop()

main = chain.pop()
ret = [ ('1' if ask(main, x) else '0') for x in range(0, N) ]

print("! %s" % ("".join(ret)))


Measured memory_bytes: 3528
N,M = map(int,input().split())
ks = []
for i in range(M):
  ks.append(list(map(int,input().split())))
p = list(map(int, input().split()))
c = 0

for i in range(2 ** N):
  sw = [0]*N
  for j in range(N):
    if ((i >> j) & 1):
      sw[j] = 1
  frg = True
  for j in range(M):
    a = ks[j][0]
    aa = 0
    for k in range(1,a+1):
      aa += sw[ks[j][k]-1]
    if aa%2 != p[j]:
      frg = False
  if frg:
    c += 1
    
print(c)

Measured memory_bytes: 3064
import sys,math

n=0
max_v=-math.pow(10,10)
s=math.pow(10,10)
for line in sys.stdin:
    l=int(line)
    if n == 0:
        n=l
        continue
    diff=l-s
    if diff>max_v:
        max_v=diff
    if diff<0:
        s=l
        

print max_v

Measured memory_bytes: 6680
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ll long long
#define MOD 1000000007
#define MAX 100010
#define cout(v) REP(i,v.size()) cout << v[i] << " "; cout << endl;
using namespace std;
using Graph = vector<vector<int>>;
 
int main(){
  int n; cin >> n;
  string s; cin >> s;
  vector<int> r,g,b;
  REP(i,n){
    if(s[i] == 'R') r.push_back(i);
    else if(s[i] == 'G') g.push_back(i);
    else if(s[i] == 'B') b.push_back(i);
    else cout << "unti";
  }
  
  ll all = r.size()*g.size()*b.size();
  ll sub = 0;
  FOR(i,0,n){
    FOR(j,i+1,n){
      if(s[i] == s[j]) continue;
      int k = 2*j-i;
      if (k >= n || s[k] == s[i] || s[k] == s[j]) continue;
      sub++;
    }
  }
  cout << all - sub;
}

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

using namespace std;

bool used[8];
int roads[201][201];
int visitTowns[8];
int minDist=1<<29;

void gen(int (&soFar)[8], int depth, int n)
{
    //generate all permutations
    if (depth == n)
    {
        //calculate distance
        int dist=0;
        for (int i = 0; i < n-1; i++)
        {
            dist += roads[visitTowns[soFar[i]]][visitTowns[soFar[i+1]]];
        }
        minDist = min(minDist, dist);
    } else
    {
        for (int i = 0; i < n; i++)
        {
            if (!used[i])
            {
                soFar[depth] = i;
                used[i]=true;
                gen(soFar, depth+1, n);
                used[i] = false;
            }
        }
    }
}

int main()
{
    for (int i = 0; i < 8; i++)
    {
        used[i] = false;
    }

    int towns, numRoads, n;
    cin >> towns >> numRoads >> n;

    for (int i = 0; i < n; i++)
    {
        cin >> visitTowns[i];
    }

    for (int i = 1; i <= 200; i++)
    {
        for (int j = 1; j <= 200; j++)
        {
            if (i == j)
            {
                roads[i][j] = 0;
            } else
            {
                roads[i][j] = 1<<29;
            }
        }
    }

    for (int i = 0; i < numRoads; i++)
    {
        int from, to, dist;
        cin >> from >> to >> dist;
        if (roads[from][to] > dist)
        {
            roads[from][to] = dist;
            roads[to][from] = dist;
        }
    }

    //floyd-warshall
    for (int k = 1; k <= towns; k++)
    {
        for (int i = 1; i <= towns; i++)
        {
            for (int j = 1; j <= towns; j++)
            {
                roads[i][j] = min(roads[i][j], roads[i][k]+roads[k][j]);
            }
        }
    }

    /*for (int i = 1; i <= towns; i++)
    {
        for (int j = 1; j <= towns; j++)
        {
            cout << roads[i][j] << " ";
        }
        cout << endl;
    }*/

    int x[8];
    gen(x, 0, n);

    cout << minDist << endl;
    return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<deque>
#include<bitset>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
typedef long long ll;
typedef pair<ll,ll> P;
template<class T> inline bool chmax(T&a , T b){ if(a<b){ a=b; return true; } else{ return false; } }
template<class T> inline bool chmin(T&a , T b){ if(a>b){ a=b; return true; } else{ return false; } } 

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main(){
    int n,k;
    cin >> n >> k;
    vector<bool> b(n);
    for(int i=0;i<k;i++){
        int d;
        int a;
        cin >> d;
        rep(j,d){
            cin >> a;
            a--;
            b[a] = true;
        }
    }

    ll cnt=0;
    rep(i,n){
        if(!b[i]) cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 3632
my_str = input()

s1 = []
s2 = []
sum = 0

for idx, letter in enumerate(my_str):
    if letter == '\\':
        s1.append(idx)

    elif letter == '/' and s1:
        jdx = s1.pop()
        a = idx -jdx
        sum += a

        while s2 and s2[-1][0] > jdx:
            a += s2.pop()[1]
        s2.append([jdx, a])

print(sum)
print(len(s2), *(a for _, a in s2))


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

using namespace std;

int N, mini, maxi, a[2009], ap[2009];

void Bad ()
{
    printf ("Impossible");
    exit (0);
}

int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

scanf ("%d", &N);
for (int i=1; i<=N; i++)
{
    scanf ("%d", &a[i]), ap[a[i]] ++;
    if (i == 1) mini = maxi = a[i];
    else
    {
        if (a[i] > maxi) maxi = a[i];
        if (a[i] < mini) mini = a[i];
    }
}
int cnt_max = ap[maxi], cnt_min = ap[mini];
if (cnt_min != 1 + maxi % 2 || cnt_max == 1 || (maxi + 1) / 2 != mini) Bad ();
for (int i=mini + 1; i<maxi; i++)
{
    ap[i] -= 2;
    if (ap[i] < 0) Bad ();
}
printf ("Possible\n");
return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#define MAXQ 55
using namespace std;

int n, m, q, a[MAXQ], b[MAXQ], c[MAXQ], d[MAXQ], ans;
vector<int> arr;

void solve(int p, int depth) {
	if (depth == n) {
		int score = 0;
		for (int i=0; i<q; i++) {
			if (arr[b[i]] - arr[a[i]] == c[i])
				score += d[i];
		}
		ans = max(ans, score);
		return;
	}
	for (int i=p; i<=m; i++) {
		arr.push_back(i);
		solve(i, depth + 1);
		arr.pop_back();
	}
}

int main() {
	cin >> n >> m >> q;
	for (int i=0; i<q; i++) {
		cin >> a[i] >> b[i] >> c[i] >> d[i];
	}
	arr.push_back(-1);
	solve(1, 0);
	cout << ans;
}

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

int main() {
  int h, w;
  while (cin >> h >> w, h | w) {
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        cout << "#";
      }
      cout << endl;
    }
    cout << endl;
  }
}

Measured memory_bytes: 3072
using System;
using System.Collections.Generic;
using System.Linq;
namespace program{
    public class ABC167{
        public static void Main(string[] args){
            var input = Console.ReadLine().Split();
            var N = long.Parse(input[0]);
            var K = long.Parse(input[1]);
            var A = Console.ReadLine().Split().Select(a => long.Parse(a)).ToArray();
            long before = 0;
            long[] loop = new long[N + 1];
            loop[0] = 1;
            var visited = new bool[N];
            visited[0] = true;
            //ループを見つける
            long position = 0;
            var i = 1;
            for(i = 1; i < N + 1; i++){
                if(visited[A[position]-1]){
                    before = Array.IndexOf(loop, A[position]);
                    break;
                }else{
                    loop[i] = A[position];
                    visited[A[position]-1] = true;
                    position = A[position] - 1;
                }
            }
            
            if(K <= before){
                Console.WriteLine(loop[(int)K]);
            }else{
                var j = (int)((K-before) % (i - before));
                Console.WriteLine(loop[j+(int)before]);
            }
        }
    }
}

Measured memory_bytes: 45252
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef pair<P,int> T;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}

int main (){
	while(1){
		ll b;
		cin >> b;
		if(b == 0)return 0;
		ll base = 0;
		ll i;
		ll res = 0;
		for(i=sqrt(b)*2;i>=0;i--){
			base = i * (i + 1) / 2;
			if(base > b)continue;
			res = b - base;
			if(res % i == 0){
				cout << (res / i) + 1 << " " << i << endl;
				break; 
			}
		}
	}
	return 0;



}


Measured memory_bytes: 3084
n, a, b = map(int, input().split())
ary = []
c = []
for i in range(n):
	num = str(i+1)
	ary = list(map(int, num))
	if(sum(ary) >= a and sum(ary) <= b):
		c.append(i+1)

print (sum(c))

Measured memory_bytes: 3440
#!/usr/bin/env python3
import sys
import math


def solve(N: int, D: int):
    return math.ceil(N/(1+D*2))


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    D = int(next(tokens))  # type: int
    print(solve(N, D))

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

A, B = [0], [0]
for i in range(n):
    A.append(A[i] + a[i])
for i in range(m):
    B.append(B[i] + b[i])

ans, j = 0, m
for i in range(n+1):
    if A[i] > k:
        break
    while B[j] > k - A[i]:
        j -= 1
    ans = max(ans, i+j)
print(ans)


Measured memory_bytes: 47504
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,Q,K,A,B;
string S;
const ll MOD = 998244353;
//const ll MOD = (1e+9) + 7;
typedef pair<ll, ll> P;
const ll INF = (1LL<<50);
template<class T> bool chmin(T &a, const T &b){
    if(a > b) {a = b; return true;}
    else return false;
}
template<class T> bool chmax(T &a, const T &b){
    if(a < b) {a = b; return true;}
    else return false;
}

vec a(50), b(50), c(50), d(50);
ll calc(vec &v){
    ll res = 0;
    rep(i,Q){
        if(v[b[i]] - v[a[i]] == c[i]) res += d[i];
    }
    return res;
}
ll dfs(vec &v){
    int n = v.size();
    if(n == N) return calc(v);
    int j = (n ? v[n-1] : 1);
    ll res = 0;
    reps(i,j,M + 1){
        v.push_back(i);
        chmax(res, dfs(v));
        v.pop_back();
    }
    return res;
}

int main() {
    cin>>N>>M>>Q;
    rep(i,Q) {
        cin>>a[i]>>b[i]>>c[i]>>d[i];
        --a[i];
        --b[i];
    }
    vec v(0);
    cout<<dfs(v)<<endl;
}

Measured memory_bytes: 3636
#include<iostream>
#include<iomanip>
#include<math.h>
#include<algorithm>
#include<utility>
#include<functional>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int MOD = 1000000007;
const ll INF=2e18;

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


Measured memory_bytes: 764
#include <bits/stdc++.h>
#define rep2(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) rep2(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
using namespace std;
using ll = long long;
template <typename T>
T sq(T x) {
  return x * x;
}

signed main() {
  char A, B;
  cin >> A >> B;
  if (A == B) {
    cout << "=" << endl;
  } else if (A < B) {
    cout << "<" << endl;
  } else {
    cout << ">" << endl;
  }

  return 0;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define vi vector<int>
#define vs vector<string>
#define vll vector<ll>

int main() {
    int n, k, tmp;
    cin >> n >> k;
    map<int, int> ma;
    int l, mi, mv, ans = 0;
    
    rep(i, n) {
        cin >> tmp;
        ma[tmp]++;
    }
    
    l = ma.size();
    vector<int> mav(l);
    int cnt = 0;
    
    for (auto u : ma) {
        mav[cnt++] = u.second;
    }
    
    sort(mav.begin(), mav.end());
    
    for (int i = 0; i < (l - k); i++) {
        ans += mav[i];
    }
    
    cout << ans << endl;
    return 0;
}

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

using ll = long long;

#define pb push_back
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
#define sz(a) (int)(a.size())
#define clr(a, b) memset(a, b, sizeof(a))
#define REP(i, a, b) for(int i=(int)(a); i<(int)(b); ++i)
#define REPD(i, a, b) for(int i=(int)(a)-1; i>=(int)(b); --i)

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

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

    int N, x;
    cin >> N >> x;
    N = 2*N - 1;
    if(x == N || x == 1) {
        cout << "No\n";
    } else {
        vector<int> res(N, -1);
        if(N == 2) {
            res[0] = 1, res[1] = 2;
        } else {
            res[N/2] = x;
            res[N/2 + 1] = N;
            res[N/2 - 1] = 1;
            int ind = N/2 + 2, tot = 3;
            REPD(j, N, 2) { 
                if(j == x) continue;
                if(tot == N) break;
                while(res[ind] != -1 && tot <= N) {
                    ++ind;
                    ind %= N;
                }
                res[ind] = j;
                ++tot;
            }
            cout << "Yes\n";
            REP(i, 0, N)
                cout << res[i] << "\n";
        }
    }
    return 0;
}


Measured memory_bytes: 3880
#include <stdio.h>
#include<iostream>
#include<cctype>
using namespace std;

int main(){
	char ch;

	while (1) {
		scanf("%c", &ch);
		if (isalpha(ch)) {
			if (islower(ch)) printf("%c", toupper(ch));
			else printf("%c", tolower(ch));
		}
		else printf("%c", ch);
		if (ch == '\n') break;
	}
	return 0;
}

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

int main()
{
int i;
int N;
char C;

	ios::sync_with_stdio( false );
	cin.tie( 0 );

	cin >> N;
	for( i = 0; i < N; i++ )
	{
		cin >> C;
		if( C == 'Y' )
		{
			cout << "Four" << endl;

			return 0;
		}
	}

	cout << "Three" << endl;

	return 0;
}






Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
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; }

int n;
int main() {
    cin >> n;
    vector<int> x(n, 0);
    vector<int> y(n, 0);
    vector<int> h(n, 0);
    for(int i = 0; i < n; ++i) cin >> x.at(i) >> y.at(i) >> h.at(i);

    int anscx = 0, anscy = 0, ansH = 0;
    for(int cx = 0; cx <= 100; ++cx) {
        for(int cy = 0; cy <= 100; ++cy) {
            bool flg = true;
            int H = 0;
            for(int i = 0; i < n; ++i) {
                if(h.at(i) != 0) {
                    H = h.at(i) + abs(x.at(i)-cx) + abs(y.at(i)-cy);
                    break;
                }
            }
            for(int i = 0; i < n; ++i) {
                int check = H - abs(x.at(i)-cx) -abs(y.at(i)-cy);
                if(h.at(i) != max(check, 0)) {
                    flg = false;
                    break;
                }
            }
            if(flg) {
                anscx = cx; anscy = cy; ansH = H;
                break;
            }
        }
    }

    cout << anscx << " " << anscy << " " << ansH << endl;
}

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

dp = Array.new(h.size, 10**9)

dp[0] = 0
dp[1] = (h[1] - h[0]).abs

2.upto(h.size-1) do |i|
  dp[i] = [dp[i-2] + (h[i] - h[i-2]).abs, dp[i-1] + (h[i] - h[i-1]).abs].min
end

p dp[h.size-1]


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

int main() {
  string s;
  cin>>s;
  vector<int> memo;
  for(int i=0;i<s.size();i++){
    if(s[i]=='1') memo.push_back(1);
    else if(s[i]=='0') memo.push_back(0);
    else if(memo.size()>0) memo.pop_back();
    else continue;
  }
  for(int i=0;i<memo.size();i++) cout<<memo.at(i);
  cout<<endl;
  return 0;
}

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

using namespace std;

#define ll long long 
#define mod 100000007
#define MAX 100000

int main()
{
    ll n, a[200005];
    
    cin >> n;
    map<ll,ll>mp;
    for(int i = 1; i <= n; i++) 
    {
		cin>> a[i];
		mp[a[i]]++;
	}
	map<ll,ll>mp2;
	ll total = 0;
	for(auto it : mp)
	{
		ll times = (it.second*(it.second-1))/2;
		total += times;
		mp2[it.first] = times;
	}
	for(ll i = 1;i <= n; i++)
	{
		ll rest = total - mp2[a[i]];
		ll baki = mp[a[i]];
		baki--;
		ll hoi = (baki*(baki-1))/2;
		cout<< rest+hoi << endl;
	}
	return 0;
}


Measured memory_bytes: 18944
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int num = sc.nextInt();
		int length = sc.nextInt();
		ArrayList<String> starray = new ArrayList<String>();
		for(int i = 0; num >= i; i++) {
			starray.add(sc.nextLine());
		}
		sc.close();
		Collections.sort(starray);
		for(int a = 0; starray.size() > a; a++) {
			System.out.print(starray.get(a));
		}
	}

}


Measured memory_bytes: 21716
#include<bits/stdc++.h>
#define pir pair<int,int>
#define qmin(x,y) (x=min(x,y))
#define qmax(x,y) (x=max(x,y))
#define rsort(x,y) sort(x,y),reverse(x,y)
#define fr first
#define se second
using namespace std;
typedef long long ll;
const int Maxn=2100000;
const int inf=0x3f3f3f3f;

int n,k;
char s[Maxn];

signed main() {
    // freopen("test.in","r",stdin);
    scanf("%d%d",&n,&k);
    scanf("%s",s);
    for(int i=0;i<n;i++) s[i+n]=s[n-i-1];
    int temp=0;
    for(int i=1;i<=n;i++) {
        int flag=0;
        for(int j=0;j<n;j++)
            if(s[temp+j]<s[i+j]) break;
            else if(s[temp+j]>s[i+j]) {
                flag=1;
                break;
            }
        if(flag) temp=i; 
    }
    int sxz=1,nh=n;
    for(int i=1;i<n;i++) {
        if(s[temp+i]!=s[temp]) {
            nh=i;
            break;
        }
        sxz++;
    }
    for(int i=1;i<k&&sxz<=n;i++) sxz<<=1;
    qmin(sxz,n);
    for(int i=1;i<=sxz;i++) putchar(s[temp]);
    for(int i=0;i<n-sxz;i++) putchar(s[temp+nh+i]);
    return 0;
}


Measured memory_bytes: 3748
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <numeric>
#include <string>
#include <string.h>
#include <map>
#include <set>
#include <functional>
#include <complex>
#include <stack>
#include <tuple>
#include <array>
using namespace std;
#define rep(i,n) for (int i=0; i < (n); i++)


typedef long long int ll;
typedef double D;      // ??§?¨?????????????double???long double?????????
typedef complex<D> P;  // Point
typedef pair<P, P> L;  // Line
typedef vector<P> VP;


const int INF = (1<<30) - 1;
const D EPS = 1e-9;

#define X real()
#define Y imag()
#define LE(n,m) ((n) < (m) + EPS)
#define GE(n,m) ((n) + EPS > (m))
#define EQ(n,m) (abs((n)-(m)) < EPS)

bool check(int N, vector<pair<int, int>> vec, int E){
    int x = 0;
    int i = 0;
    while(i < N && x < E){
        if(x < vec[i].first)
            return false;
        x = max(x, vec[i].second);
        i++;
    }
    if(x < E)
        return false;
    
    return true;
}

void solve(){
    int N, W, H;
    cin >> N >> W >> H;
    
    vector<pair<int, int>> xs, ys;
    for(int i=0; i<N; i++){
        int x, y, w;
        cin >> x >> y >> w;
        xs.push_back({x-w, x+w});
        ys.push_back({y-w, y+w});
    }
    sort(xs.begin(), xs.end());
    sort(ys.begin(), ys.end());
    
    cout << (check(N, xs, W)||check(N, ys, H) ? "Yes" : "No") << endl;
}

//g++ -std=c++0x -msse4.2 -O3
//#include <bits/stdc++.h>
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    //cout.precision(16);
    
    solve();
    
    return 0;
}

Measured memory_bytes: 4408
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	n := getInt()

	as := make([]int, n)
	for i := range as {
		as[i] = getInt()
	}

	b := make([]int, 0, n)
	i := n - 1
	for ; i >= 0; i -= 2 {
		b = append(b, as[i])
	}

	if i == -2 {
		i = 1
	} else {
		i = 0
	}

	for ; i < n; i += 2 {
		b = append(b, as[i])
	}

	for _, x := range b {
		fmt.Println(x)
	}
}

// -----------------------------------------

var scanner = wordScanner()

func wordScanner() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	return sc
}

func getInt() int {
	scanner.Scan()
	i, err := strconv.Atoi(scanner.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func getString() string {
	scanner.Scan()
	s := scanner.Text()
	return s
}


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

using namespace std;

using ll = long long; 

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

    int n, x;
    cin >> n >> x;
    long long pre, cur;
    cin >> pre;
    long long total = 0;
    for (int i = 1; i < n; ++i) {
        cin >> cur;
        long long diff = pre + cur - x;
        if (diff > 0) {
            total += diff;
            cur -= min(cur, diff);
        }
        pre = cur;
    }

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

    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
typedef unsigned long long ll;


int main()
{
	int n;
	cin>>n;
	vector<int> A(n);
	vector<int> B(n);
	vector<int> C(n);
	rep(i,n) cin>>A[i];
	rep(i,n) cin>>B[i];
	rep(i,n) cin>>C[i];
	sort(A.begin(),A.end());
	sort(B.begin(),B.end());
	sort(C.begin(),C.end());
	ll ans = 0;
	rep(i,n){
		auto left = lower_bound(A.begin(),A.end(),B[i]) - A.begin();
		auto right = C.end() -  upper_bound(C.begin(),C.end(),B[i]);
		ans += right * left;
	}
	cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 1408
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
int gcd(int a, int b){
	return (b > 0)? gcd(b, a % b) : a ;
}
int main(){
int N, X; 
int A[114514] = {0};
int D[114514] = {0};  
cin >> N >> X; 
for(int i = 0; i < N; i++){
cin >> A[i]; 
D[i] = A[i] - X; 
}
int G = abs(D[0]); 
for(int i = 1; i < N; i++){
G = gcd(abs(D[i]), G); 
}
cout << G << endl; 
}

Measured memory_bytes: 1152
#include <bits/stdc++.h> //Andrei Alexandru a.k.a Sho10
#define ll long long int
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define all(a) (a).begin(), (a).end()
#define sz size
#define f first
#define s second
#define pb push_back
#define er erase
#define in insert
#define mp make_pair
#define pi pair
#define rc(s) return cout<<s,0
#define endl '\n'
#define mod 1000000007
#define PI 3.14159265359
#define CODE_START  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
ll k,a,b;
int32_t main(){
CODE_START;
cin>>k;
cin>>a>>b;
for(ll i=a;i<=b;i++)
{
    if(i%k==0){
        cout<<"OK";
        return 0;
    }
}
cout<<"NG";
}


Measured memory_bytes: 3652
# 約数のリストを得る
def make_divisors(n):
    divisors = []
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n // i)
    return divisors

N, M = map(int, input().split())
l = make_divisors(M)
# mの約数
res = 1
# 全ての約数において、kと仮定する
for k in l:
    x = M // k
    # この際、Mをkで除した数列bがN以上であるかを判定する
    if x >= N:
        res = max(res, k)
print(res)

Measured memory_bytes: 38640
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const ll mod = 1e9 + 7;



int main(void) {
  int n;
  cin >> n;
  VI a(n);
  int x = 0;
  REP(i, 0, n) {
    cin >> a[i];
    a[i]--;
  }
  REP(i, 0, n) {
    if (a[i] == i) {
      if (i < n - 1) {
	swap(a[i], a[i + 1]);
	x += 1;
      } else {
	swap(a[n - 2], a[n - 1]);
	x += 1;
      }
    }
  }
  cout << x << endl;
}


Measured memory_bytes: 640
x,y = [int(i) for i in input().split()]
ans = []
for i in range(x):
	ans.append(list(input()))
for i in range(x):
	for j in range(y):
		if ans[i][j] == '.':
			d = 0
			for k in range(i-1,i+2):
				for l in range(j-1,j+2):
					if 0 <= k and k < x and 0 <= l and l < y:
						if ans[k][l] == '#':
							d += 1
							ans[i][j] = str(d)
for i in range(x):
	for j in range(y):
		if ans[i][j] == '.':
			ans[i][j] = '0'
for i in ans:
	print(''.join(i))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define mp make_pair
#define pb emplace_back
#define x first
#define y second
#define sz(a) ((int)(a).size())
#define rep(i,begin,end) for(__typeof(end) i = (begin)-((begin)>(end)); i != (end)-((begin)>(end)); i += 1-2*((begin)>(end)))
#define clr(a,v) memset(a, v, sizeof(a))
#define all(a) (a).begin(),(a).end()
#define EPS 1e-8
#define fcin ios_base::sync_with_stdio(false)
#define db(x) cerr << #x << " == " << x << endl
#define _ << " " <<
#define MAXN 101010
#define LOGN 20
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;

int n, vet[MAXN];

int main(){
	ll x, y;
	scanf("%lld%lld", &x, &y);
	int ans = 0;
	while(x <= y){
		x <<= 1;
		ans++;
	}
	printf("%d\n", ans);
}



Measured memory_bytes: 256
#이런식으로 코드 짜니까 이문제가 왜 이런걸 물어보는건지 이해가 감... 대단하다
class Node():
    def __init__(self, parent = -1, left = -1, right = -1): ##초기값 설정
        self.parent = parent
        self.left = left
        self.right = right
##초기 Node()class는 parent,left,right모두 -1
n = int(input())
ns = [Node()for i in range(n)] ##ns[0~(n-1)]모두 Node class 인스턴스화
for i in range(n):
    p, l, r = map(int, input().split())
    if (l != -1):
        ns[l].parent = p ##클래스변수 (메소드 아님,()없음)
        ns[p].left = l
    if (r != -1):
        ns[r].parent = p
        ns[p].right = r
        
        
def preorder(ns, i):  ##여기서의 i는 root 
    print(" "+str(i), end ='')  ##preorder은 루트 쪽부터 print
    if (ns[i].left != -1):  ##left쪽으로 쭉감
        preorder(ns, ns[i].left) ##ns[i].left를 root로써 재귀함수!
    if (ns[i].right != -1):
        preorder(ns, ns[i].right) ##left다했으면 right으로도 똑같이 해줌

def inorder(ns, i):
    if (ns[i].left != -1):
        inorder(ns, ns[i].left)  ##inorder는 일단 재귀함수로 왼쪽 끝까지 감
    print(' ' + str(i), end = '') ##왼쪽 끝가지 간 후 print (더이상 왼쪽으로 갈 수 없을때 print)
    if (ns[i].right != -1):
        inorder(ns, ns[i].right)  ##left로 갈수없을때 실행됨 (오른쪽으로 한번)

def postorder(ns, i):
    if (ns[i].left != -1):
        postorder(ns, ns[i].left)  ##inorder는 일단 재귀함수로 왼쪽 끝까지 감
    if (ns[i].right != -1):
        postorder(ns, ns[i].right)  ##left로 갈수없을때 오른쪽으로 끝까지 감
    print(' ' + str(i), end = '')  ##더이상 갈 수 없을때 print

for i in range(n):
    if (ns[i].parent == -1): ##root를 찾아서 위의 세 함수에 대입하여 print
        print('Preorder')
        preorder(ns, i)
        print()
        print('Inorder')
        inorder(ns, i)
        print()
        print('Postorder')
        postorder(ns, i)
        print()
        break


Measured memory_bytes: 5620
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>

using namespace std;

typedef long long ll;
typedef long double ld;

#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep1(i,n) for(int i=1; i<=(int)(n); i++)
#define all(c) c.begin(),c.end()
#define psb push_back
#define ppb pop_back

const int I_INF = 1001001001;
const ll LL_INF = 1001001001001001001;
const ld EPS = 0.001;

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

    cout << S.substr(0, 3) << endl;
}


Measured memory_bytes: 3628
#include<stdio.h>

int main(){
    int A = 0,B=0,C;
scanf("%d %d",&A,&B);
  if(A==B)
    C=A*2;
  else if(A>B)
    C=A*2-1;
  else
    C=B*2-1;
  
  printf("%d",C);
  return 0;
}

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

int main(){
  string s;
  cin >> s;
  int n=s.size();
  char a[n],b[n];
  for(int i=0;i<n;i+=2){
    a[i]='0';
    b[i]='1';
  }
  for(int i=1;i<n;i+=2){
    a[i]='1';
    b[i]='0';
  }
  int x=0,y=0;
  for(int i=0;i<n;i++){
    if(s[i]!=a[i]){
      x++;
    }
    if(s[i]!=b[i]){
      y++;
    }
  }
  cout << min(x,y) << endl;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <iostream>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <stack>
#include <list>
#include <deque>
using namespace std;
long long n, m, i, j, k, t, l;
long long a[110];
long long gcd(long long a, long long b){
	long long t1=a, t2=b;
	long long i;
	for(i=1;;i++){
		if(t1==0||t2==0) break;
		t1=t1%t2;
		if(t1==0||t2==0) break;
		t2=t2%t1;
	}
	return t1+t2;
}
long long lcm(long long a,long long b){
	return a/gcd(a,b)*b;
}
int main(){
	l=1;
	cin>>n;
	for(i=1;i<=n;i++){
		cin>>t;
		l=lcm(l,t);
	}
	cout<<l;
	return 0;
}

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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;

li a[100100];
li maa[100100];

int main() {
    li n, t;
    cin >> n >> t;
    rin{
        cin >> a[i];
    }

    maa[n - 1] = a[n - 1];
    for (li i = n - 2; i >= 0; --i) {
        maa[i] = max(maa[i + 1], a[i]);
    }
    li mad = 0;
    rep(i, n - 1) {
        mad = max(mad, maa[i + 1] - a[i]);
    }

    set<li> st;
    st.insert(a[0]);
    li res = 0;
    repp(i, 1, n) {
        if (st.find(a[i] - mad) != st.end()) {
            ++res;
        }
        st.insert(a[i]);
    }
    cout << res << endl;


    return 0;
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define FORR(I,A,B) for(ll I = ((B)-1); I >= (A); --I)
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;else return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;

struct Bellman_Ford{
	struct edge{ll from, to, cost;};
	ll inf = 1e15;
	vector<edge> es;
	vector<ll> d;
	ll V,E;
	void init(ll v,ll e){
		V = v; E = e;
		d.resize(V);
	}
	void shortest_path(ll s){
		FOR(i,0,V) d[i] = inf;
		d[s] = 0;
		FOR(i,0,V){
			FOR(j,0,E){
				edge e = es[j];
				if(d[e.from]!=inf && d[e.to]>d[e.from] + e.cost){
					d[e.to] = d[e.from] + e.cost;
				}
			}
		}
	}
	bool find_negative_loop(){
		FOR(i,0,V)d[i] = 0;
		FOR(i,0,V){
			FOR(j,0,E){
				edge e = es[j];
				if(d[e.to]>d[e.from] + e.cost){
					d[e.to] = d[e.from] + e.cost;
					if(i == V-1) return true;
				}
			}
		}
		return false;
	}
	bool shortest_path(int s, int t){ // t: destination
		FOR(i,0,V)d[i] = inf;
		d[s] = 0;
		FOR(i,0,2*V){
			FOR(j,0,E){
				edge e = es[j];
				if(d[e.from]!=inf && d[e.to]>d[e.from] + e.cost){
					d[e.to] = d[e.from] + e.cost;
					if(i>=V-1 && e.to==t) return true;
				}
			}
		}	
		return false;
	}
};

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	Bellman_Ford bf;
	ll N,M;
	cin >> N >> M;
	bf.init(N,M);
	ll minc = INF;
	FOR(i,0,M){
		ll a,b,c;
		cin >> a >> b >> c;
		minc = min(minc,c);
		bf.es.push_back({a-1,b-1,-c});
	}
	bf.inf = 1e18+1;
	// 0 -> N-1
	if(bf.shortest_path(0,N-1)){
		cout << "inf" << endl;
	}else{
		cout << -bf.d[N-1] << endl;
	}
}

Measured memory_bytes: 384
package main

import (
	"fmt"
	"math"
)

// trial division approach
// n > 2
// ２から√nまで試し割りする。
// 割り切れた場合その値の素数性をチェック。
// 素数の場合スライスに追加する。
// 最大値を返すため、スライスの一番最後を返す
func trialDivision(n int) int {
	var ans int
	for i := n; ; i++ {
		if primeNaive(i) {
			ans = i
			break
		}
	}
	return ans
}

func primeNaive(n int) bool {
	if n < 2 {
		return false
	}
	for i := 2; i <= int(math.Sqrt(float64(n))); i++ {
		if n%i == 0 {
			return false
		}
	}
	return true
}

func main() {
	var x int
	fmt.Scan(&x)
	fmt.Println(trialDivision(x))
}


Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

int main() {
    int n, q;
    cin >> n >> q;
    string s;
    cin >> s;

    vector<int> l(q), r(q);
    rep(i, q) {
        cin >> l[i] >> r[i];
    }
    vector<int> sum(n+1, 0);

    for(int i = 1; i < n; i++) {

        sum[i+1] = sum[i];
        if(s[i-1] == 'A' && s[i] == 'C') {
            sum[i+1]++;
        }
    }

    rep(i, q) {
        int ans = sum[r[i]] - sum[l[i]];
        cout << ans << "\n";
    }

    cout << endl;
    return 0;
}

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

#define ll long long int
#define li int64_t

int main()
{
	string s;
	cin>>s;
	ll sum = 0;
	for(int i=0;i<s.length();i++)
	{
		sum+= (int)(s[i]-'0');
	}	
	if(sum % 9 == 0)
	{
		cout<<"Yes";
	}
	else
	{
		cout<<"No";
	}
}

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

int main() {
  int n,k,ans = 1e9;
  cin >> n >> k;
  vector<int>h(n);
  rep(i,n) cin >> h[i];
  sort(h.begin(),h.end());
  rep(i,n-k+1) ans = min(ans,h[i+k-1]-h[i]);
  cout << ans << endl;
}

Measured memory_bytes: 768
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        int Q = sc.nextInt();
        StringBuilder sb = new StringBuilder(S.length() + Q);
        sb.append(S);
        StringBuilder sb_head = new StringBuilder(Q);
        boolean flipped = false;
        for(int i=0; i<Q; i++) {
            String cmd = sc.next();
            if(cmd.equals("1")) {
                // filp
                flipped = !flipped;
            } else {
                String cmd2 = sc.next();
                String cmd3 = sc.next();
                // add
                switch(cmd2) {
                    case "1":
                        // add head
                        if(!flipped) {
                            sb_head.append(cmd3);
                        } else {
                            sb.append(cmd3);
                        }
                        break;
                    case "2":
                        // add tail
                        if(!flipped) {
                            sb.append(cmd3);
                        } else {
                            sb_head.append(cmd3);
                        }
                        break;
                }
            }
        }
        if(!flipped) {
            System.out.println(sb_head.reverse().toString() + sb.toString());
        } else {
            System.out.println(sb.reverse().toString() + sb_head);
//            System.out.println(reverse(sb));
        }
    }

    static String reverse(StringBuilder sb) {
        StringBuilder result = new StringBuilder();
        for(int i=sb.length()-1; i>=0; i--) {
            result.append(sb.substring(i, i+1));
        }
        return result.toString();
    }
}


Measured memory_bytes: 94684
#include<cstdio>
#include<cstring>
#include<vector>
#include<stack>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#define maxn 200100
using namespace std;
struct node
{
    int l,r,w,min,max;
}tree[4*maxn];


int o;
long long ans=0;
void build(int l,int r,int k)
{
    tree[k].l=l;tree[k].r=r;
    if(l==r)
    {
        tree[k].w=1;
        return ; 
    }
    int m=(l+r)/2;
    build(l,m,k*2);
    build(m+1,r,k*2+1);
	tree[k].w=1;
}
int  addSc(int k)
{
    if(tree[k].l==tree[k].r)
        {
			
            if(tree[k].w)
			{
				tree[k].w=0;
				return 1;
			}
			else
				return 0;
         }
    int m=(tree[k].l+tree[k].r)/2;
	if(!tree[k].w)
		return 0;
	int y=0;
	if(o<=m&&tree[2*k].w) 
		y=addSc(k*2);
    if(!y)
		y=addSc(k*2+1);
	
	if(tree[2*k].w||tree[2*k+1].w)
		tree[k].w=1;
	else
		tree[k].w=0;
	return y;
}
struct PP
{
	int a,b;
	bool operator < (const PP &h)
	{
		return b>h.b;
	}
}s[maxn];
int main()
{
	int N,M;
	scanf("%d%d",&N,&M);
	for(int i=0;i<N;i++)
		scanf("%d%d",&s[i].a,&s[i].b);
	sort(s,s+N);
	build(1,M,1);
	for(int i=0;i<N;i++)
		if(s[i].a<=M)
		{
			o=s[i].a;
			if(addSc(1))
				ans+=s[i].b;
		}
	printf("%lld\n",ans);
}
				
		

Measured memory_bytes: 7680
#include <stdio.h>
long abs(long);
int main(){
  int n,h[100000],dp[100000],f1,f2;
  scanf("%d",&n);
  for (int i=0;i<n;i++) scanf("%d",&h[i]);
  dp[0]=0;
  dp[1]=abs(h[0]-h[1]);
  for (int i=2;i<n;i++){
    f1=dp[i-1]+abs(h[i]-h[i-1]);
    f2=dp[i-2]+abs(h[i]-h[i-2]);
    if (f1>f2) dp[i]=f2;
    else dp[i]=f1;
  }
  printf("%ld\n",dp[n-1]);
  return 0;
}
long abs(long num){
  if (num<0) num=-num;
  return num;
}

Measured memory_bytes: 896
N = int(input())
S_dic = {}
mode_list = []
mode_num = 0
for i in range(N):
    S = input()
    if S in S_dic:
        l = S_dic[S]+1
        S_dic[S] = S_dic[S]+1
    else:
        l=1
        S_dic[S]=1
    if mode_num==l:
        mode_list.append(S)
    elif mode_num<l:
        mode_list = []
        mode_list.append(S)
        mode_num = l

mode_list.sort()

for w in mode_list:
    print(w)

Measured memory_bytes: 33416
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<string>
#include<stdio.h>
#include<stdlib.h>
#include<set>
#include<cmath>
#define MAX 2000050
#define ll long long int
using namespace std;

int n;
int a[500];
int main(){
  cin>>n;
  double avg = 0;
  for(int i=0;i<n;i++){
    cin>>a[i];
    avg+=a[i];
  }
  avg/=n*1.0;
  int norm = round(avg);
  int cost = 0;
  for(int i=0;i<n;i++){
    if(a[i]!=norm){
      cost+=(norm-a[i])*(norm-a[i]);
    }
  }
  cout<<cost<<endl;
  return 0;
}


Measured memory_bytes: 256
m,d=map(int, input().split())
count=0
for i in range(1,m+1):
    for j in range(10,d+1):
        if j>10:
            a=int(str(j)[0])
            b=int(str(j)[1])
            if a>1 and b>1 and i==a*b:
                count+=1
                #print(i,j)
print(count)

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

const int m=1000000007;

int main(){
  int n;
  cin >> n;
  vi a(n);
  rep(i,n){
    char x;
    cin >> x;
    a[i]=x-'a';
  }
  sort(a.begin(),a.end());
  a[n]=-1;
  ll ans=1;
  int now=a[0];
  int cnt=0;
  rep(i,n+1){
    if(a[i]!=now){
      ans*=cnt+1;
      ans%=m;
      now=a[i];
      cnt=1;
    }else{cnt++;}
  }
  ans--;
  ans%=m;
  cout << ans;
  return 0;
}

Measured memory_bytes: 3784