akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < n; i++)

using namespace std;

int main(void) {
  long H, W, N;
  long sr, sc;
  string S, T;

  // S: 高橋、落としたい
  // T: 青木、残したい

  cin >> H >> W >> N >> sr >> sc >> S >> T;
  sr--;
  sc--;

  long minH = -1, maxH = H, minW = -1, maxW = W;
  for (long i = N-1; i >= 0; i--) {
    // 青木ターン
    if (T[i] == 'L' and maxW < W) {
      maxW ++;
    }
    if (T[i] == 'R' and minW > -1) {
      minW --;
    }
    if (T[i] == 'U' and maxH < H) {
      maxH ++;
    }
    if (T[i] == 'D' and minH > -1) {
      minH --;
    }
    // 高橋ターン
    if (S[i] == 'L') {
      minW ++;
      if (minW == maxW - 1) {
        cout << "NO" << endl;
        return 0;
      }
    }
    if (S[i] == 'R') {
      maxW --;
      if (minW == maxW - 1) {
        cout << "NO" << endl;
        return 0;
      }
    }
    if (S[i] == 'U') {
      minH ++;
      if (minH == maxH - 1) {
        cout << "NO" << endl;
        return 0;
      }
    }
    if (S[i] == 'D') {
      maxH --;
      if (minH == maxH - 1) {
        cout << "NO" << endl;
        return 0;
      }
    }
  }
  if (sr <= minH or maxH <= sr) {
    cout << "NO" << endl;
    return 0;
  }
  if (sc <= minW or maxW <= sc) {
    cout << "NO" << endl;
    return 0;
  }
  cout << "YES" << endl;
  return 0;
}


Measured memory_bytes: 776
N, W = map(int, input().split())
dp = [[0]*(W+1) for _ in range(N+1)]
for i in range(N):
    w, v = map(int, input().split())
    for j in range(1, W+1):
        if j<w:
            dp[i+1][j] = dp[i][j]
        if w<=j:
            dp[i+1][j] = max(dp[i][j], dp[i][j-w]+v)
print(dp[-1][-1])

Measured memory_bytes: 149288
n = gets.to_i
a = gets.split(" ").map(&:to_i)

colors = [0] * 8
legend = 0

a.each do |a_i|
  case a_i
  when 1..399 then
    colors[0] = 1
  when 400..799 then
    colors[1] = 1
  when 800..1199 then
    colors[2] = 1
  when 1200..1599 then
    colors[3] = 1
  when 1600..1999 then
    colors[4] = 1
  when 2000..2399 then
    colors[5] = 1
  when 2400..2799 then
    colors[6] = 1
  when 2800..3199 then
    colors[7] = 1
  else
    legend += 1
  end
end

normal_colors_count = colors.inject(0, &:+)
min = legend > 0 ? [normal_colors_count, 1].max : normal_colors_count
max = normal_colors_count + legend
puts "#{min} #{max}"


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

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

    vector<int> a(M);
    vector<int> b(M);
    vector<vector<int>> c(M);
    for (int i = 0; i < M; i++)
    {
        cin >> a[i] >> b[i];
        for (int j = 0; j < b[i]; j++)
        {
            int tmp;
            cin >> tmp;
            tmp--;
            c[i].push_back(tmp);
        }
    }

    vector<int> dp(1 << N, INT_MAX);
    dp[0] = 0;
    for (int i = 0; i < M; i++)
    {
        for (int j = 0; j < (1 << N); j++)
        {
            if (dp[j] == INT_MAX)
            {
                continue;
            }
            int cost = dp[j] + a[i];
            int next = j;
            for (int x : c[i])
            {
                next |= (1 << x);
            }
            dp[next] = min(dp[next], cost);
        }
    }

    if (dp.back() == INT_MAX)
    {
        cout << -1 << endl;
    }
    else
    {
        cout << dp.back() << endl;
    }
}


Measured memory_bytes: 384
# -*- coding: utf-8 -*-
def inpl(): return list(map(int, input().split()))

N = int(input())
stations = []
for _ in range(N-1):
    stations.append(inpl())

P = []

for i in range(N-1):
    C, S, F = stations[i]
    P = [C + max(S, F*(p//F + int(p%F!=0))) for p in P]
    P.append(S+C)  

for p in P:
    print(p)
print(0)

Measured memory_bytes: 3188
import java.util.Scanner;
import java.io.File;
import java.io.FileNotFoundException;

public class Main
{
  public static void main(String[] args) throws FileNotFoundException
  {
    Scanner scanner = new Scanner(System.in);//new File("input.txt"));
    int n = scanner.nextInt();
    int[] arr = new int[n];
    for(int i = 0 ; i < n ; i++){
      arr[i] = scanner.nextInt();
    }

    int min = (1 << 30), ans = 0;
    for(int i = 0 ; i < n ; i++){
      if(arr[i] < min){
        min = arr[i];
        ans += 1;
      }
    }
    System.out.println(ans);
  }
}


Measured memory_bytes: 65784
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
using namespace std;
typedef long long ll;

int n;
vector<string> s;
vector<int> t;
string x;

int main(){
    cin >> n;
    s.resize(n);
    t.resize(n);

    ll ans =0;

    rep(i,n){
        cin >> s[i] >> t[i];
        ans += t[i];
    }
    cin >> x;

    rep(i,n){
        ans -= t[i];
        if(x == s[i]){
            break;
        }
    }

    dunk(ans);
}

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

int main(){
    string str;
    cin>>str;
    for(int i=0;i<3;i++){
        if(str[i]=='1')str[i]='9';
        else if(str[i]=='9') str[i]='1';
    }
    cout<<str<<endl;
    return 0;
}

Measured memory_bytes: 256
object Main {
  def main(args: Array[String]) {
    if (sys.env.getOrElse("TEST", "") == "1") {
      println(test());
    } else {
      val input = io.Source.stdin.getLines().mkString("\n");
      println(solve(input).trim());
    }
  }

  def solve(input: String): String = {
    val arr = input.split(" ").map(_.toInt)
    return (arr ++ arr.map(_ - 1)).sortWith(_ < _).drop(2).sum.toString()
  }

  val tests = List(
    """3 5""" -> """9""",
    """3 4""" -> """7""",
    """6 6""" -> """12""");

  def test(): String = {
    return tests.map { case (i, o) => (i.trim(), o.trim()) }
      .zipWithIndex.map {
      case ((input, outputExpect), i) => {
        val output = solve(input).trim();
        s"test${i + 1}:" + (if (output == outputExpect) {
          "Passed"
        } else {
          s"Failed\nexpect:\n${outputExpect}\noutput:\n${output}"
        })
      }
    }
      .mkString("\n");
  }
}


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

int main() {
  vector<char> A{'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
  char S;
  cin >> S;
  for(int i=0;i<26;i++){
    if(A[i]==S){
      cout << A[i+1];
      break;
    }
  }
}


Measured memory_bytes: 256
N = int(input())
D,X = map(int,input().split())
A = []
for i in range(N):
    A.append(int(input()))

eat = []
# i番目の参加者はeat[i]個食った
# i番目の参加者は1, A[i]+1, 2*A[i]+1 …日目に食べる
for i in range(N):
    cnt = 0
    eat.append(0)
    while True:
        day = cnt * A[i] + 1
        if day > D: break
        eat[i] = eat[i] + 1
        cnt = cnt + 1
print(sum(eat) + X)


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

int main(){
int N; 
string S;
cin >> N >> S; 
int ans = 0;  
for(int i = 1; i <= N; i++){
  int M = 0;
  for(char c = 'a'; c <= 'z'; c++){
      int existc = 0; 
    for(int k = 0; k < i; k++){
     for(int l = i; l < N; l++){ 
      if(S.at(k) == c && S.at(l) == c){
       existc = 1;}
     }
    }
     M += existc; 
   }
  ans = max(ans, M);
  }
cout << ans << endl; 
}

Measured memory_bytes: 256
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
//問題文および制約はちゃんと確認しよう！
//サイズは10^5じゃなくて2×10^5とかかもしれないし、重要な制約・条件を見落としているかも
//とりあえずサンプルを読んでから解法を考えよう？
map<lint,lint> ma;
int main()
{
	int n;lint m,su=0,a,out=0;
	cin>>n>>m;
	ma[0]++;
	rep(i,n){
		cin>>a;su+=a;ma[su%m]++;
	}
	map<lint,lint>::iterator it=ma.begin();
	while(it!=ma.end()){
		out+=(*it).se*((*it).se-1)/2;
		it++;
	}
	cout<<out<<endl;
}


Measured memory_bytes: 4224
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
using pll = pair<ll,ll>;
using Graph = vector<vector<ll>>;
#define all(v) v.begin(), v.end()
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i,l,r) for(ll i = (l); i <= (ll)(r); i++)
#define rep3(i,l,r) for(ll i = (l); i >= (ll)(r); i--)
#define dup(x,y) (((x)+(y)-1)/(y)) // x/yの除算の切り上げ
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int inf = 1001001001;
const ll INF = 1LL << 60;
const ll mod = 1000000007; //1000000007
const ld pi = acos(-1);
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};
 
int main(){
 
    ios::sync_with_stdio(false);
    cin.tie(0);

    ll h, w;
    cin >> h >> w;
    ll si, sj, ei, ej;
    cin >> si >> sj >> ei >> ej;
    si--; sj--; ei--; ej--;
    vector<string> s(h);
    rep(i,h) cin >> s[i];
    vector<vector<ll>> dist(h, vector<ll>(w, INF));
    deque<pll> q;
    dist[si][sj] = 0;
    q.emplace_back(si,sj);
    while(!q.empty()){
        ll i = q.front().first;
        ll j = q.front().second;
        ll d = dist[i][j];
        q.pop_front();
        rep(v,4){
            ll ni = (i + di[v]);
            ll nj = (j + dj[v]);
            if(ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
            if(s[ni][nj] == '#') continue;
            if(dist[ni][nj] <= d) continue;
            dist[ni][nj] = d;
            q.emplace_front(ni,nj);
        }
        rep2(ei,-2,2){
            rep2(ej,-2,2){
                ll ni = (i + ei);
                ll nj = (j + ej);
                if(ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
                if(s[ni][nj] == '#') continue;
                if(dist[ni][nj] <= (d + 1)) continue;
                dist[ni][nj] = (d + 1);
                q.emplace_back(ni,nj);
            }
        }
    }

    ll ans = dist[ei][ej];
    if(ans == INF) ans = -1;
    cout << ans << '\n';

}

Measured memory_bytes: 12780
using System;
using System.Linq;
using System.Collections.Generic;

class Test
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        int[] A = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int q = int.Parse(Console.ReadLine());

        for (int i = 0; i < q; i++)
        {
            int[] query = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int[] B = new int[query[1] - query[0]];

            Array.Copy(A, query[0], B, 0, query[1] - query[0]);
            B = B.Reverse().ToArray();
            for (int j = 0; j < B.Length; j++)
            {
                A[query[0] + j] = B[j];
            }
        }

        Console.WriteLine(string.Join(" ", A));
    }
}




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

typedef long long ll;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define mod 998244353

ll mod_pow(ll x,ll n){
  ll res=1;
  while(n>0){
    if(n&1)res=res*x%mod;
    x=x*x%mod;
    n>>=1;
  }
  return res;
}


typedef double D;
typedef complex<D> P;
#define X real()
#define Y imag()
const D eps=1e-8;
const D inf=1e12;
D cross(P a,P b){ return (conj(a)*b).Y; }
struct L : public vector<P> { // line and segment
  L(const P& a,const P &b){
    push_back(a);
    push_back(b);
  }
};
bool intersectLP(L l,P p){
  return abs(cross(l[1]-p,l[0]-p))<eps;
}

int N;
vector<P> ps;

int main(){
  cin>>N;
  rep(i,N){
    D x,y;
    cin>>x>>y;
    ps.push_back(P(x,y));
  }
  ll res=(mod_pow(2,N)+(mod-N)+(mod-((N*(N-1)/2)%mod))+(mod-1))%mod;
  rep(i,N)repl(j,i+1,N){
    ll cnt=0;
    bool ok=true;
    rep(k,N){
      if(intersectLP(L(ps[i],ps[j]),ps[k])){
        if(k<i||(k!=i&&k<j))ok=false;
        else cnt++;
      }
    }
    if(!ok)continue;
    ll sub=(mod_pow(2,cnt)+(mod-cnt)%mod+(mod-((cnt*(cnt-1)/2)%mod))%mod+(mod-1))%mod;
    (res+=mod-sub)%=mod;
  }
  cout<<res<<endl;
  return 0;
}


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

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<vpll> vvpll;
typedef vector<double> vd;
typedef vector<vd> vdd;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)
#define RFOR(i,x,y) for(ll i=(ll)x; i>=(ll)y; --i)
#define RREP(i,x) RFOR(i, x, 0)
#define ALL(a) a.begin(), a.end()
#define pb push_back
#define debug_print(x...) cerr << "line " << __LINE__ << " : "; debug_print_in(x);

template <typename First>
void debug_print_in(First first){
  cerr << first << endl;
  return;
}

template <typename First, typename... Rest>
void debug_print_in(First first, Rest... rest){
  cerr << first << " ";
  debug_print_in(rest...);
  return;
}

void IN(void){
  return;
}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
  cin >> first;
  IN(rest...);
  return;
}

template <typename First>
void OUT(First first){
  cout << first << endl;
  return;
}

template <typename First, typename... Rest>
void OUT(First first, Rest... rest){
  cout << first << " ";
  OUT(rest...);
  return;
}

template<class t, class u> void chmax(t&a,u b){if(a<b)a=b;};
template<class t, class u> void chmin(t&a,u b){if(a>b)a=b;};
int popcount(int t){return __builtin_popcount(t);} //GCC
int popcount(ll t){return __builtin_popcountll(t);} //GCC

template <typename T>
void vec_print(vector<T> VEC){
  REP(i, VEC.size()){
    cerr << VEC[i] << " ";
  }
  cerr << endl;
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  REP(i,MAT.size()){
    REP(j,MAT[i].size()){
      cerr << MAT[i][j] << " ";
    }
    cerr << endl;
  }
};

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;
constexpr ll MOD = (ll)((1E+9)+7);

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  string S;
  IN(S);
  string ans = "";
  ll N = S.size();
  REP(i,N){
    if(S[i]=='B'){
      if(ans.size()>0){
        string ans_tmp = "";
        REP(j,ans.size()-1){
          ans_tmp += ans[j];
        }
        ans = ans_tmp;
      }
    }else{
      ans += S[i];
    }
  }

  OUT(ans);


  return 0;
}

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

using namespace std;

int sumOfDigit(int n){
  int sum = 0;
  while ((n / 10) != 0) { 
    sum+= n % 10;
    n /= 10;
  }
  sum +=n;
  return sum;
}

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

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

  int alice = 0;
  int bob = 0;
  for(int i=0; i<n;i++){
    if (i % 2 == 0) {
      alice += a[i];
    } else {
      bob += a[i];
    }
  }
  cout << alice - bob << endl;
}



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

int main() {
    ll a, v, b, w, t;
    cin >> a >> v >> b >> w >> t;
    long double dist = abs(b - a);
    if (dist / t + w <= v) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(),(obj).end()
#define SORTD(s) sort((s).rbegin(),(s).rend())
#define rep(i,n) for(int i=0;i<(n);i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
#define PI 3.14159265358979323846264338327950L
const int mod=1000000007,MAX=200005,INF=1<<30;

int main() {
	string s;
  	cin>>s;
  
  	int ans=0;
  	rep(i,3){
    	if(s[i]=='R'){
			ans++;
        }
      if (s[1]=='S'){
        	ans=1;
      }
       if(s[0]=='S'&&s[1]=='S'&&s[2]=='S') {
       		ans=0;
       }
      
    }
	
  	cout<<ans<<endl;

}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

int main(){
    int n;
    cin >>n;
    vector<ll> a(n);
    rep(i,n) cin >>a[i];

    ll s[2]={};
    rep(i,n) s[i%2] += a[i];

    vector<ll> x(n);
    x[0] = (s[0]-s[1])/2;
    for(int i=1; i<n; ++i) x[i] = a[i-1]-x[i-1];

    rep(i,n) cout << 2*x[i] << " \n"[i==n-1];
    return 0;
}


Measured memory_bytes: 2944
# -*- coding: utf-8 -*-
"""
A - Cookie Exchanges
https://atcoder.jp/contests/agc014/tasks/agc014_a

"""
import sys


def solve(A, B, C):
    res = sorted([A, B, C])
    ans = 0
    seen = set()
    seen.add(tuple(res))
    while all([r%2== 0 for r in res]):
        a = res[1]//2 + res[2]//2
        b = res[0]//2 + res[2]//2
        c = res[0]//2 + res[1]//2
        res = sorted([a, b, c])
        ans += 1
        t = tuple(res)
        if t in seen:
            return -1
    return ans


def main(args):
    A, B, C = map(int, input().split())
    ans = solve(A, B, C)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])


Measured memory_bytes: 3064
h, w = gets.split(" ").map(&:to_i)
puts (if h == 1 or w == 1
  1
elsif h % 2 == 0 and w % 2 == 0
  w * h / 2
elsif h % 2 == 1 and w % 2 == 0
  w * (h / 2) + w / 2
elsif h % 2 == 0 and w % 2 == 1
  h * (w / 2) + h / 2
else
  (h / 2) * (w / 2) * 2 + w / 2 + h / 2 + 1
end)

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

int main()
{
    std::string base_str;
	uint32_t k = 0;
	std::cin >> k;
	std::cin >> base_str;

	if (base_str.length() <= k) {
		std::cout << base_str << std::endl;
	}
	else {
		std::string sub_s = base_str.substr(0, k);
		std::cout << sub_s << "..." << std::endl;
	}

    return 0;

}

Measured memory_bytes: 3136
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <typeinfo>
#include <fstream>

using namespace std;

int main(void){
    string s;
    cin>>s;
    reverse(s.begin(),s.end());
    if(s[0]=='2'||s[0]=='4'||s[0]=='5'||s[0]=='7'||s[0]=='9'){
        cout<<"hon"<<endl;
    }else if(s[0]=='3'){
        cout<<"bon"<<endl;
    }else{
        cout<<"pon"<<endl;
    }
    return 0;
}


Measured memory_bytes: 3624
import java.util.Scanner;

public class Main {

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

		String S = sc.next();
		int count = 0;

		for (int i = 0; i < S.length(); i++ ) {
			if (S.charAt(i) == 'o' ) {
				count++;
			}
		}
		System.out.println( 700 + (100 * count) );
	}
}

Measured memory_bytes: 23636
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,x;
  x=0;
  cin>>N;
  vector<int> vec(N);
  for(int i=0;i<N;i++){
    cin>>vec.at(i);
  }
  sort(vec.begin(),vec.end());
  for(int j=N-1;j>0;j-=2){
    x+=(vec.at(j)-vec.at(j-1));
  }
  if(N%2!=0){
    x+=vec.at(0);
  }
  cout<<x<<endl;
}
  
  

Measured memory_bytes: 256
c = [0] * 3
for i in range(3):
    c[i] = list(map(int, input().split()))

sum_mat = (sum(c[0]) + sum(c[1]) + sum(c[2])) / 3
print('Yes' if sum_mat == c[0][0] + c[1][1] + c[2][2] else 'No')

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>

using namespace std;

int bubbleSort(vector<int> &a, int n){
	bool flag = true;
	int count = 0;
	while (flag){
		flag = false;
		for (int j = n - 1; j >= 1; j--){
			if (a[j] < a[j - 1]){
				swap(a[j], a[j - 1]);
				flag = true;
				count++;
			}
		}
	}
	return count;
}

int main(){
	int n, count;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) cin >> a[i];
	count = bubbleSort(a, n);
	for (int i = 0; i < n; i++){
		cout << a[i];
		if (i != n - 1) cout << " ";
	}
	cout << endl << count << endl;
}

Measured memory_bytes: 3080
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<set>
#include<map>
#include<vector>
#include<stack>

using namespace std;

using ll = long long;

constexpr ll inf = 1e18;

int main() {
    int n; cin >> n;
    vector<ll> a(n);
    for(int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    vector<vector<ll>> dp(n + 1, vector<ll>(2, -inf));
    dp[0][0] = a[0];
    for(int i = 1; i < n; ++i) {
        dp[i][0] = max(dp[i - 1][0], dp[i - 1][1]) + a[i];
        dp[i][1] = max(dp[i - 1][0] - a[i - 1] + (-a[i - 1] - a[i]), dp[i - 1][1] + a[i - 1] + (a[i - 1] - a[i]));
    }
    cout << max(dp[n - 1][0], dp[n - 1][1]) << endl;
}



Measured memory_bytes: 6528
require 'pp'

n = gets.chomp!.to_i
points = []
zero_points = []
n.times do |i|
    x, y, h = gets.chomp!.split(' ').map(&:to_i)
    if h == 0
        zero_points << [x, y]
    else
        points << [x, y, h]
    end
end

0.upto(100) do |c_x|
    0.upto(100) do |c_y|
        ok = true
        before = nil
        points.each do |x, y, h|
            h_tmp = h + (x - c_x).abs + (y - c_y).abs
            before ||= h_tmp
            if before != h_tmp
                ok = false
                break
            end
        end
            
        if ok
            ok2 = zero_points.all? {|point|
                [before - (point[0] - c_x).abs - (point[1] - c_y).abs, 0].max == 0
            }
            if ok2
                puts "#{c_x} #{c_y} #{before}"
                exit 0
            end
        end
    end
end


Measured memory_bytes: 4348
import math
import sys
import os
from operator import mul

sys.setrecursionlimit(10**7)

def _S(): return sys.stdin.readline().rstrip()
def I(): return int(_S())
def LS(): return list(_S().split())
def LI(): return list(map(int,LS()))

if os.getenv("LOCAL"):
    inputFile = basename_without_ext = os.path.splitext(os.path.basename(__file__))[0]+'.txt'
    sys.stdin = open(inputFile, "r")
INF = float("inf")


D,T,S = LI()
if T < D/S:
    ans = 'No'
else:
    ans = 'Yes'


print(ans)

Measured memory_bytes: 9136
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
#define reps(i,b,n) for(int i = b ; i < (int)n ; ++i )
#define rep(i,n) reps(i,0,n)
bool flg[26];
int buff[26];
vector<int> vc[26];
void dfs(int c){
  flg[c] = false;
  rep(i,vc[c].size()) if(flg[vc[c][i]]) dfs(vc[c][i]);
}
int main(){
  int n;
  string str;
  while(cin >> n , n){
    bool ok = true;
    rep(i,26)vc[i].clear();
    fill_n(flg,26,false);
    fill_n(buff,26,0);
    int l,r;
    rep(i,n){
      cin >> str;
      l = str[0] - 'a' , r = str[str.size()-1] - 'a';
      vc[l].push_back(r);
      buff[l]++ , buff[r]--;
      flg[l] = flg[r] = true;
    }
    dfs(l);
    rep(i,26){
      if(flg[i]||buff[i]){
        ok = false;
        break;
      }
    }
    cout << (ok ? "OK" : "NG") << endl;
  }
}


Measured memory_bytes: 3228
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
int N,M;
int a[300000];
int b[300000];
ll c[300000];
ll sum[300001];
int main(){
  cin>>N;
  for(int i=0;i<N;i++)cin>>a[i];
  cin>>M;
  for(int i=0;i<M;i++)cin>>b[i];
  for(int i=0;i<M;i++)cin>>c[i];
  sort(a,a+N);
  sum[0]=a[0];
  for(int i=1;i<N;i++)sum[i]=a[i]+sum[i-1];
  for(int i=0;i<M;i++){
    int* it=upper_bound(a,a+N,b[i]);
    ll d=(it==a?0:sum[it-a-1]);
    if(d>=c[i])cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
  }
  return 0;
}

Measured memory_bytes: 8196
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <stdio.h>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional> //operator[]
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;

signed main(){
    string s; cin >> s;
    if(s[0]=='7'||s[1]=='7'||s[2]=='7') cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 3640
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
using ll = long long;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()
ll MOD = 1000000007;
const ll INF = 1LL << 60;
const double EPS = 1e-10;

int main() {
  //
  ll n, m;
  cin >> n >> m;
  vl s(m), c(m);
  rep(i, m) cin >> s[i] >> c[i];
  REP(i, 0, 1000) {
    string str = to_string(i);
    if (str.size() != n) continue;
    bool ok = true;
    rep(j, m) {
      if (str[s[j] - 1] - '0' != c[j]) ok = false;
    }
    if (ok) {
      cout << str << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}


Measured memory_bytes: 256
#line 2 "/Users/kaage/Desktop/ProgrammingWorkspace/library/other/template.hpp"
#define _CRT_SECURE_NO_WARNINGS
#pragma target("avx2")
#pragma optimize("O3")
#pragma optimize("unroll-loops")
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define all(V) V.begin(),V.end()
typedef long long lint;
typedef unsigned long long ulint;
typedef std::pair<int, int> P;
typedef std::pair<lint, lint> LP;
constexpr int INF = INT_MAX/2;
constexpr lint LINF = LLONG_MAX/2;
constexpr double eps = DBL_EPSILON;
constexpr double PI=3.141592653589793238462643383279;
template<class T>
class prique :public std::priority_queue<T, std::vector<T>, std::greater<T>> {};
template <class T, class U>
inline bool chmax(T& lhs, const U& rhs) {
	if (lhs < rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
template <class T, class U>
inline bool chmin(T& lhs, const U& rhs) {
	if (lhs > rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
inline lint gcd(lint a, lint b) {
	while (b) {
		lint c = a;
		a = b; b = c % b;
	}
	return a;
}
inline lint lcm(lint a, lint b) {
	return a / gcd(a, b) * b;
}
bool isprime(lint n) {
	if (n == 1)return false;
	for (int i = 2; i * i <= n; i++) {
		if (n % i == 0)return false;
	}
	return true;
}
template<typename T>
T mypow(T a, lint b) {
	T res(1);
	while(b){
		if(b&1)res*=a;
		a*=a;
		b>>=1;
	}
	return res;
}
lint modpow(lint a, lint b, lint m) {
	lint res(1);
	while(b){
		if(b&1){
			res*=a;res%=m;
		}
		a*=a;a%=m;
		b>>=1;
	}
	return res;
}
template<typename T>
void printArray(std::vector<T>& vec) {
	rep(i, vec.size()){
		std::cout << vec[i];
		std::cout<<(i==(int)vec.size()-1?"\n":" ");
	}
}
template<typename T>
void printArray(T l, T r) {
	T rprev = std::prev(r);
	for (T i = l; i != rprev; i++) {
		std::cout << *i << " ";
	}
	std::cout << *rprev << std::endl;
}
LP extGcd(lint a,lint b) {
	if(b==0)return {1,0};
	LP s=extGcd(b,a%b);
	std::swap(s.first,s.second);
	s.second-=a/b*s.first;
	return s;
}
LP ChineseRem(const lint& b1,const lint& m1,const lint& b2,const lint& m2) {
	lint p=extGcd(m1,m2).first;
	lint tmp=(b2-b1)*p%m2;
	lint r=(b1+m1*tmp+m1*m2)%(m1*m2);
	return std::make_pair(r,m1*m2);
}
/*template<typename F>
inline constexpr decltype(auto) lambda_fix(F&& f){
	return [f=std::forward<F>(f)](auto&&... args){
		return f(f,std::forward<decltype(args)>(args)...);
	};
}*/
#line 2 "main.cpp"
int main(){
	std::string s;
	std::cin>>s;
	if(s=="RRR")puts("3");
	else if(s=="SSS")puts("0");
	else if(s=="SRR"||s=="RRS")puts("2");
	else puts("1");
	return 0;
}

Measured memory_bytes: 3624
from bisect import bisect_left


def main():
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    mask = 1
    target = 1
    ans = 0
    for _ in range(29):
        AA = sorted([a & mask for a in A], reverse=True)
        BB = sorted([b & mask for b in B])
        cnt = 0
        idx1 = 0  # idx of target*1-a
        idx2 = 0  # idx of target*2-a
        idx3 = 0  # idx of target*3-a
        for a in AA:
            while idx1 < N and a+BB[idx1] < target*1:
                idx1 += 1
            while idx2 < N and a+BB[idx2] < target*2:
                idx2 += 1
            while idx3 < N and a+BB[idx3] < target*3:
                idx3 += 1
            cnt += (N - idx3) + (idx2 - idx1)
        ans += target * (cnt % 2)
        mask <<= 1
        mask |= 1
        target <<= 1
    print(ans)


if __name__ == "__main__":
    main()


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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

vector<string> convert(string s)
{
    vector<string> ret;

    int i=0;
    while(s[i]!=':') ++i;
    ret.pb(s.substr(0,i));

    int st=i+1;
    i=st;
    while(st<s.size())
    {
        while(s[i]!=',' && s[i]!='.') ++i;
        ret.pb(s.substr(st,i-st));
        st=i+1;
        i=st;
    }

    return ret;
}

int main()
{
    int n;
    while(cin >>n,n)
    {
        vector<vector<string>> s(n);
        rep(i,n)
        {
            string tmp;
            cin >>tmp;
            s[i]=convert(tmp);
        }

        map<string,int> group2id;
        rep(i,n) group2id[s[i][0]]=i;

        set<string> names;
        queue<int> que;
        for(int i=1; i<s[0].size(); ++i)
        {
            if(group2id.find(s[0][i]) == group2id.end()) names.insert(s[0][i]);
            else que.push(group2id[s[0][i]]);
        }

        vector<bool> vis(n);
        vis[0]=true;

        while(!que.empty())
        {
            int v=que.front();
            que.pop();
            for(int i=1; i<s[v].size(); ++i)
            {
                if(group2id.find(s[v][i]) == group2id.end()) names.insert(s[v][i]);
                else
                {
                    int nx=group2id[s[v][i]];
                    if(!vis[nx])
                    {
                        vis[nx]=true;
                        que.push(nx);
                    }
                }
            }
        }

        cout << names.size() << endl;
    }
    return 0;
}

Measured memory_bytes: 3184
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define llu long long unsigned
int main()
{
        ll n,y,mx,ans=0;
        scanf("%lld",&n);
        scanf("%lld",&y);
        mx=y;
        for(int j=1;j<n;j++){
            scanf("%lld",&y);
            if(y<mx) ans+=(mx-y);
            mx=max(mx,y);
        }

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



    return 0;
}




Measured memory_bytes: 3828
// ConsoleApplicationc.cpp: 定义控制台应用程序的入口点。
//
#include<iostream>
using namespace std;
long long  a, b, c, x, y;
long long one1(long long  a, long long b, long long  c, long long x, long long y)
{
	return (a*x + b * y);
}
long long two2(long long  a, long long b, long long  c, long long x, long long y)
{
	if (y > x)
	{
		return (c * 2 * x + (y - x)*b);
	}
	else
	{
		return (c * 2 * y + (x-y)*a);
	}
}
long long three3(long long  a, long long b, long long  c, long long x, long long y)
{
	if (x > y)
	{
		return (2 * c*x);
	}
	else
	{
		return (2 * c*y);
	}
}
long long  min(long long  x, long long  y)
{
	if (x < y)
		return x;
	else
		return y;
}
int main()
{
	scanf("%lld%lld%lld%lld%lld", &a, &b, &c, &x, &y);
	long long  one, two, three;
	one = two = three=0;
	one=one1(a, b, c, x, y);
	two = two2(a, b, c, x, y);
	three =three3(a, b, c, x, y);

	printf("%lld", min(one, min(two, three)));
    return 0;
}



Measured memory_bytes: 256
s=input()
a='0'
b='0'
p=False
for i in range(len(s)):
  if s[i]==' ':
    p=True
  if p==False:
    a+=s[i]
  else:
    b+=s[i]
a=a.replace('0','')
b=b.replace('0','')
b=b.replace(' ','')
b+=a
print(b)

Measured memory_bytes: 3060
use std::io::*;
use std::str::FromStr;

//https://qiita.com/tubo28/items/e6076e9040da57368845
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: usize = read();
    let mut a: Vec<u64> = (0..n).map(|_| read()).collect();

    //降順ソート
    a.sort_by(|x, y| y.cmp(x));

    let mut ans: u64 = 0;
    //足せる回数の初期値設定
    let mut t = n-1;
    //大きい順に到着していく
    for i in 0..n{
        //足せる回数の設定、1人目のみ1回になる
        let mut lim = 2;
        if i == 0 {
            lim = 1;
        }
        //足せる分だけ足す
        //n-1まで到着を処理するが、足し込んでいるのはt>0となっている場合まで
        for _ in 0..lim{
            if t > 0 {
                ans += a[i];
                t -= 1;
            }
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4384
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <regex>
#include <vector>

#define fix(n)          cout<<fixed<<setprecision(n)
#define rep(i,n)        for (int i = 0; i < (n); ++i)
#define sort(a)         sort((a).begin(), (a).end())
#define uniq(a)         sort(a);(a).erase(unique((a).begin(), (a).end()), (a).end())
#define reverse(a)      reverse((a).begin(), (a).end())
#define ctos(c)         string(1, (c))
#define out(d)          cout << (d)
#define outl(d)         std::cout<<(d)<<"\n"
#define YES()           cout << "YES" << endl
#define NO()            cout << "NO" << endl
#define Yes()           cout << "Yes" << endl
#define No()            cout << "No" << endl
#define ceil(x, y)      ((x + y - 1) / (y))
#define debug(x)        cerr << #x << ": " << (x) << '\n'
#define debug2(x, y)    cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v)          for (size_t _ = 0; _ < v.size(); ++_){ cerr << #v << "[" << _ << "] : " << v[_] << '\n'; }

using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;

const ll MOD = 1000000007; // 10^9 + 7
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

void solve() {
  int n; cin >> n;
  vector<int> a(n); rep(i, n) cin >> a[i];
  sort(a); reverse(a);
  int sum1 = 0, sum2 = 0;
  for (int i = 0; i < n; i++) {
    if (i % 2 == 0) sum1 += a[i];
    else sum2 += a[i];
  }
  outl(sum1 - sum2);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));
  fix(12);

  solve();
}


Measured memory_bytes: 256
#include <cmath>
#include <vector>
#include <map>
#include <functional>
#include <queue>
#include <iostream>
#include <string>
#include <iomanip>
#include <algorithm>
#include <functional>

using namespace std;

#define ll long long int
#define ti4 tuple<int,int,int,int>
#define pii pair<ll,ll>

int main()
{
    int n;
    cin >> n;
    vector<int> v;
    for(int i = 0;i < 2 * n;i++)
    {
        int s;
        cin >> s;
        v.push_back(s);
    }
    sort(v.begin(), v.end(), greater<int>());
    ll sum = 0;
    for(int i = 0; i < 2 * n;i+=2)
    {
        int f = v[i];
        int s = v[i + 1];
        sum += min(f,s);
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>

#define int long long

signed main() {
  int n;
  std::cin >> n; n--;

  std::vector<char> ans;
  while(true) {
    ans.push_back((char) ('a' + (n%26)));
    if(n < 26)
      break;
    n = (n/26)-1;
  }

  std::reverse(ans.begin(), ans.end());

  for(char c : ans)
    std::cout << c;

  std::cout << std::endl;
  return 0;
}




Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define EPS 0.0000000001
#define INF 1000000000
#define MOD 1000000007
typedef long long ll;

int x[100][100];

void rere(int a,int b){
    
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            x[a+i][b+j]++;
        }
    }
    return;
}

int main()
{
    int h,w;
    cin>>h>>w;
    vector<string> s(h);
    for(int i=0;i<h;i++){
        cin>>s.at(i);
    }

    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(s[i][j]=='#'){
                rere(i,j);
            }
        }
    }

    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(s[i][j]=='#'){
                cout<<"#";
            }
            else{
                cout<<x[i+1][j+1];
            }
        }
        cout<<endl;
    }

    
}


Measured memory_bytes: 256
function Main(input){
	input=input.split(/\n/);
	var arr=input.splice(0,1);
	var arr=arr[0].split(/\s/);
	arr.forEach(function(e,i,a){a[i]=Number(a[i]);});
	
	var ans="Yes";
	for(var i=0;i<arr[0];i=(i+1)|0){
		for(var j=0;j<arr[1];j=(j+1)|0){
			if(input[i][j]=="#"){
				if(i==0||input[i-1][j]!=="#"){
				if(i==arr[0]-1||input[i+1][j]!=="#"){
				if(j==0||input[i][j-1]!=="#"){
				if(j==arr[1]-1||input[i][j+1]!=="#"){
					ans="No";
					break;
				}}}}
			}
		}
	}
	console.log(ans);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#include <stdio.h>

int main(void){
    int a,ans=0,min=10;
    for (int i=0; i<5; i++){
        scanf("%d",&a);
        ans+=(a+9)/10;
        if (a%10!=0){
            min=min<a%10?min:a%10;
        }
    }
    printf("%d\n",ans*10-10+min);
    return 0 ;
}


Measured memory_bytes: 128
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <functional>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)

typedef long long ll;

#define N 1000000

int x[1000001]={} , y[1000001]={};

int main(void) {
    vector<int> a,b;
    int i=1;
    while (i*(i+1)*(i+2)/6<=N){
        int f = i*(i+1)*(i+2)/6;
        a.push_back(f);
        if (f%2==1)
            b.push_back(f);
        i++;
    }
    int n = a.size() , m = b.size();
    FOR(i,1,N){
        x[i] = N;
        y[i] = N;
    }
    FOR(i,0,N-1){
        REP(j,n){
            if (i+a[j]>N)
                break;
            x[i+a[j]] = min(x[i+a[j]],x[i]+1);
        }
        REP(j,m){
            if (i+b[j]>N)
                break;
            y[i+b[j]] = min(y[i+b[j]],y[i]+1);
        }
    }
    while (cin >> n && n){
        cout << x[n] << " " << y[n] << endl;
    }

    return 0;
}

Measured memory_bytes: 9036
import sys
from collections import Counter

MOD = 10 ** 9 + 7

n, *a = map(int, sys.stdin.read().split())

def main():
    c = Counter(a)
    if n & 1:
        if c.get(0, 0) != 1:
            return 0
        for i in range(2, n, 2):
            if c.get(i, 0) != 2:
                return 0
    else:
        for i in range(1, n, 2):
            if c.get(i, 0) != 2:
                return 0

    return pow(2, n // 2, MOD)
    
if __name__ == '__main__':
    ans = main()
    print(ans)

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

a = [int(input()) for i in range(n)]



cursor = 0
roots = [0] * n

for i in range(1,n):
    roots[cursor] = 1
    cursor = a[cursor]-1
    if (cursor == 1):
        print(i)
        break
    elif (roots[cursor] == 1):
        print(-1)
        break



Measured memory_bytes: 7888
use proconio::{input, fastout};

#[fastout]
fn main() {
    input!{
        k: i32,
        n: usize,
        a: [i32; n]
    };
    let mut c = a[0] + k - a[n-1];
    for i in 0..n-1 { c = std::cmp::max(c, a[i+1] - a[i]);}
    println!("{}", k - c)
}


Measured memory_bytes: 4048
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define NDEBUG
#define eprintf(...) do {} while (0)
#endif
#include<cassert>

using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}

int N;
LL X;

struct Data {
    LL b, l, u;
    LL d;

    bool operator<(const Data &o) const {
	return d > o.d;
    }
} D[100011];

bool ok(LL mid) {
    if (mid >= X*N) return true;

    LL p = mid / X;
    if (p >= N) return true;
    LL rest = mid % X;

    LL sum = 0;
    REP (i, p) sum += D[i].u * (X - D[i].b);

    LL tmp = 0;
    for (int i=p; i<N; i++) {
	sum -= D[i].l * D[i].b;
	if (rest <= D[i].b) amax(tmp, D[i].l * rest);
	else amax(tmp, (D[i].l-D[i].u)*D[i].b + D[i].u*rest);
    }

    if (sum + tmp >= 0) return true;
    if (p == 0) return false;

    sum += D[p].l * D[p].b;
    sum += D[p].u * (X-D[p].b);

    REP (i, p) {
	LL g = sum - D[i].u * (X - D[i].b);
	g += max(D[i].l*(rest-D[i].b), D[i].u*(rest-D[i].b));
	if (g >= 0) return true;
    }
    return false;
}

void MAIN() {
    scanf("%d%lld", &N, &X);
    REP (i, N) {
	LL b, l, u;
	scanf("%lld%lld%lld", &b, &l, &u);
	D[i].b = b;
	D[i].l = l;
	D[i].u = u;
	D[i].d = u*(X-b)+l*b;
    }

    sort(D, D+N);
    LL lo = -1, hi = N*X;
    while (hi - lo > 1) {
	LL mid = (lo + hi) / 2;
	(ok(mid)? hi: lo) = mid;
    }

    printf("%lld\n", hi);
}

int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}



Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
int main(void){
  
  int a,b,c,d;
  
  
  cin >> a  >> b >> c;
  
  if(a == c)
  {
    cout << 0;
  }
  else
  {
    cout << 1;
  }
  
    
    return 0;
}

Measured memory_bytes: 256
W,H,x,y,r=map(int,input().split())
if -100<=x<=100 and -100<=y<=100 and 0<=W<=100 and 0<=H<=100 and 0<=r<=100: 
    if x-r<0 or x+r>W:
        print("No")
    if x-r>=0 and x+r<=W:
        if y-r>=0 and y+r<=H:
            print("Yes")
        if y-r<0 or y+r>H:
            print("No")


Measured memory_bytes: 5596
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
typedef long long ll;

int main(){
    int i, n, k, count = 0;
    cin >> n >> k;
    while(n > 0){
        count++;
        n /= k;
    }
    cout << count;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int compare(const void * a, const void * b) 
{ 
    return ( *(int*)a - *(int*)b ); 
} 
int main()
{
 int n,b,i,count=0,j=0,flag1=0,flag2=0,t[100000]={0},s[100000]={0},countn=0,k;

scanf("%d\n",&n);
    for(i=0;i<n;i++)
    {
        scanf("%d",&s[i]);
       
        
       
    }
    
    qsort(s, n, sizeof(int), compare); 
    for(i=0;i<n;)
    {
        k=s[i];
        countn=0;
        while(s[i]==k)
        {
            countn++;
            i++;
             
        }
        if(countn>k)
        {
            count+=countn-k;
            
        }else{
            if(countn<k)
            {
                count+=countn;
            }
        }
       
    }
printf("%d",count);
    return 0;
}


Measured memory_bytes: 892
#include<stdio.h>
int main()
{
	int a, b, c;
	scanf("%d %d %d", &a, &b, &c);
	int i;
	int ans = 0;
	for (i = a; i <= b; i++)
		if (c % i == 0)
			ans++;
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 2100
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

ll MOD = 1000000007;

int main(){
  int N;
  string S;
  cin >> N >> S;
  ll cnt[26] = {};
  for(int i=0;i<N;i++){
    int ind = S[i] - 'a';
    cnt[ind]++;
  }

  ll ans = 1LL;
  for(int i=0;i<26;i++){
    ans *= (cnt[i]+1);
    ans %= MOD;
  }

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

Measured memory_bytes: 1020
#include <iostream>
#include <vector>
#include <set>
#include <string>
#include <algorithm>
#include <iomanip>

using namespace std;

#ifdef DEBUG_MODE
	#define DBG(n) n;
#else
	#define DBG(n) ;
#endif

#define REP(i,n) for(ll (i) = (0); (i) < (n); ++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define ALL(v) v.begin(),v.end()
#define INF 1100000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007

typedef long long ll;
typedef pair<ll, ll> P;


int main()
{
  int N, M;
  cin >> N >> M;
  vector<int> P(M), Y(M);
  vector<set<pair<int, int>>> vv(N + 1);
  REP(i, M) {
    cin >> P[i] >> Y[i];
    vv[P[i]].insert(make_pair(Y[i], i));
  }

  for (int i = 1; i <= N; i++) {
    int cnt = 1;
    for (auto e : vv[i]) {
      Y[e.second] = cnt;
      cnt++;
    }
  }
  REP(i, M) {
    cout << setw(6) << setfill('0') << P[i] 
         << setw(6) << setfill('0') << Y[i] << endl;
  }

	return 0;
}



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

#define pii pair<int,int>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pf push_front
#define pb2 pop_back
#define pf2 pop_front
#define line printf("\n")
#define pq priority_queue
#define rep(k,i,j) for(int k = (int)i;k<(int)j;k++)
#define repd(k,i,j) for(int k = (int)i;k>=(int)j;k--)
#define ll long long

using namespace std;

double EPS = 1e-9;
int INF = 1e9+7;;
long long INFLL = 1e17;
double pi = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};

inline void OPEN (string s) {
  freopen ((s + ".in").c_str (), "r", stdin);
  freopen ((s + ".out").c_str (), "w", stdout);
}

//end of template

int dist(pii a,pii b){return abs(a.fi-b.fi) + abs(a.se-b.se);}

int n,m;

pii a[100],b[100];
int main(){
	scanf("%d%d",&n,&m);
	
	rep(k,0,n)scanf("%d%d",&a[k].fi,&a[k].se);
	rep(k,0,m)scanf("%d%d",&b[k].fi,&b[k].se);
	
	rep(k,0,n){
		pair<int,int> ret;
		ret.fi = INF;
		rep(i,0,m)ret = min(ret,mp(dist(b[i],a[k]),i));
		
		printf("%d\n",ret.se+1);
	}
	return 0;
}


Measured memory_bytes: 256