akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <math.h>
using namespace std;
class Point{
        public:
                double y,x;
                Point(double x=0,double y=0):x(x),y(y){};
                Point operator-(Point other){
                        return Point(x-other.x,y-other.y);
                }Point operator+(Point other){
                        return Point(x+other.x,y+other.y);
                }
};
double absolute(double x){
        return x>=0?x:x*-1;
}
class Vector{
        public:
                Point start,end;
                double norm(Point tmp){
                        return tmp.y*tmp.y + tmp.x*tmp.x;
                }double abs_len(Point tmp){
                        return sqrt(norm(tmp));
                }
                double dot(Point a,Point b){
                        return a.x*b.x + a.y*b.y;
                }
                double cross(Point a,Point b){
                        return a.x*b.y-a.y*b.x;
                }
};
int main(){
        int N;
        Vector s1,s2,all;
        cin >> N;
        for(int i=0 ; i<N ; i++ ){
                cin >> s1.start.x >> s1.start.y;
                cin >> s1.end.x >> s1.end.y;
                cin >> s2.start.x >> s2.start.y;
                cin >> s2.end.x >> s2.end.y;
                double dot=all.dot(s1.end-s1.start,s2.end-s2.start);
                double cross=all.cross(s1.end-s1.start,s2.end-s2.start);
                if(dot==0)cout <<"1"<<endl;
                else if(cross==0)cout<<"2"<<endl;
                else    cout<<"0"<<endl;
        }
        return 0;
}



Measured memory_bytes: 3220
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define erep(i,a,n) for(int i = a;i<=n;i++)
typedef long long ll;
#define int long long
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vdouble vector<double>
#define vll vector<ll>:
#define vbool vector<bool>
#define INF 1101010101010101010
#define MOD 1000000007
#define P = pair<int,int>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }

signed main(){
  int n,k;
  cin >> n >> k;
  vbool ans(n);
  rep(i,0,k){
    int a;
    cin >> a;
    rep(i,0,a){
      int b;
      cin >> b;
      b--;
      ans[b] = true;
    }
  }
  int ANS = 0;
  rep(i,0,n){
    if(!ans[i]) ANS++;
  }
  cout << ANS << endl;
}

Measured memory_bytes: 3632
n = gets.chomp.to_i
times = gets.chomp.split.map {|i| i.to_i}
base_total_time = times.inject(:+)
m = gets.chomp.to_i
 
m.times do |i|
  p, x = gets.chomp.split.map {|item| item.to_i}
  diff = times[p-1] - x
  puts base_total_time - diff
end

Measured memory_bytes: 14268
#include <stdio.h>
#include <stdlib.h>

int main()
{
  int i,n,minv,maxv;
  int *array;

  scanf("%d",&n);

  array = (int *)malloc(sizeof(int) * n);
  if(array == NULL) exit(0);

  for(i = 0;i < n;i++){
    scanf("%d",&array[i]);
  }

  maxv = array[1] - array[0];
  minv = array[0];
  for(i = 1;i < n;i++){
    if(maxv < (array[i] - minv)) maxv = array[i] - minv;
    if(minv > array[i]) minv = array[i];
  }

  printf("%d\n",maxv);

  return 0;
}

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

int main(){
	int n,m;	cin>>n>>m;
	int city[n]={0};

	int x;
	for(int i=0;i<m*2;i++){
		cin>>x;
		city[x-1]++;
	}

	for(int i=0;i<n;i++)cout<<city[i]<<endl;

	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
long abc(char,long,long,long);
int main(void){
int n,k;
  scanf("%d%d",&n,&k);
  long p,s,r;
  scanf("%ld%ld%ld",&r,&s,&p);
  char t[n];
  scanf("%s",&t);
  long score=0,flag[n];
  for(int i=0;i<n;i++){
    flag[i]=0;
  }
  for(int i=0;i<k;i++){
score+=abc(t[i],p,s,r);
    flag[i]=1;
  }
  
  for(int i=k;i<n;i++){
    //printf("%c\t",t[i]);
    if(t[i-k]!=t[i]){
      score+=abc(t[i],p,s,r);
  //    printf("%ld獲得\n",abc(t[i],p,s,r));
      flag[i]=1;
    }
    else if(flag[i-k]==0)
    {score+=abc(t[i],p,s,r);
     //printf("%ld獲得\n",abc(t[i],p,s,r));
      flag[i]=1;
    }
    else{flag[i]=1-flag[i-k];}
        
  }
  printf("%ld",score);
  return 0;
}
  
  long abc(char x,long p,long s,long r){
if(x=='r')return p;
    if(x=='s')return r;
    else return s;
  }

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

#define whole(f, x, ...)                                 \
  ([&](decltype((x)) whole) {                            \
    return (f)(begin(whole), end(whole), ##__VA_ARGS__); \
  })(x)

using namespace std;
using ll = long long;

const int MOD = 1e9 + 7;

template <int mod>
struct ModInt {
  int x;

  ModInt() : x(0) {}

  ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}

  ModInt &operator+=(const ModInt &p) {
    if ((x += p.x) >= mod) x -= mod;
    return *this;
  }

  ModInt &operator-=(const ModInt &p) {
    if ((x += mod - p.x) >= mod) x -= mod;
    return *this;
  }

  ModInt &operator*=(const ModInt &p) {
    x = (int)(1LL * x * p.x % mod);
    return *this;
  }

  ModInt &operator/=(const ModInt &p) {
    *this *= p.inverse();
    return *this;
  }

  ModInt operator-() const { return ModInt(-x); }

  ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }

  ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }

  ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }

  ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }

  bool operator==(const ModInt &p) const { return x == p.x; }

  bool operator!=(const ModInt &p) const { return x != p.x; }

  ModInt inverse() const {
    int a = x, b = mod, u = 1, v = 0, t;
    while (b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }

  ModInt pow(int64_t n) const {
    ModInt ret(1), mul(x);
    while (n > 0) {
      if (n & 1) ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }

  friend ostream &operator<<(ostream &os, const ModInt &p) { return os << p.x; }

  friend istream &operator>>(istream &is, ModInt &a) {
    int64_t t;
    is >> t;
    a = ModInt<mod>(t);
    return (is);
  }

  static int get_mod() { return mod; }
};

using modint = ModInt<MOD>;

void solve() {
  int n, m;
  cin >> n >> m;
  vector<int> a(m);
  for (int i = 0; i < m; i++) {
    cin >> a[i];
  }
  vector<modint> fibo(n + 1);
  fibo[1] = 1;
  fibo[2] = 1;
  for (int i = 3; i <= n; i++) {
    fibo[i] = fibo[i - 1] + fibo[i - 2];
  }

  if (m == 0) {
    cout << fibo[n] + fibo[n - 1] << endl;
    return;
  }

  modint sum(fibo[a[0]]);
  for (int i = 1; i < m; i++) {
    const int t = a[i] - a[i - 1] - 1;
    if (t == 0) {
      cout << 0 << endl;
      return;
    }
    sum *= fibo[t];
  }
  sum *= fibo[n - a[m - 1]];

  cout << sum << endl;
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);

  solve();
  return 0;
}


Measured memory_bytes: 1024
// Copyright (C) 2017 Sayutin Dmitry.
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation; version 3

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program; If not, see <http://www.gnu.org/licenses/>.

#include <iostream>
#include <vector>
#include <stdint.h>
#include <algorithm>
#include <set>
#include <map>
#include <array>
#include <queue>
#include <stack>
#include <functional>
#include <utility>
#include <string>
#include <assert.h>
#include <iterator>
#include <cstdint>
#include <cinttypes>
#include <string.h>
#include <random>
#include <numeric>
#include <tuple>


using std::cin;
using std::cout;
using std::cerr;

using std::vector;
using std::map;
using std::array;
using std::set;
using std::string;

using std::pair;
using std::make_pair;

using std::min;
using std::abs;
using std::max;

using std::unique;
using std::sort;
using std::generate;
using std::reverse;
using std::min_element;
using std::max_element;

#ifdef LOCAL
#define LASSERT(X) assert(X)
#else
#define LASSERT(X) {}
#endif

template <typename T>
T input() {
    T res;
    cin >> res;
    LASSERT(cin);
    return res;
}

template <typename IT>
void input_seq(IT b, IT e) {
    std::generate(b, e, input<typename std::remove_reference<decltype(*b)>::type>);
}

#define SZ(vec)         int((vec).size())
#define ALL(data)       data.begin(),data.end()
#define RALL(data)      data.rbegin(),data.rend()
#define TYPEMAX(type)   std::numeric_limits<type>::max()
#define TYPEMIN(type)   std::numeric_limits<type>::min()

#define pb push_back
#define eb emplace_back


int main() {
    std::iostream::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    
    // code here.
    int h = input<int>();
    int w = input<int>();
    int d = input<int>();
    
    const char* s = "RYGB";

    if (d % 2 == 0) {
        for (int i = 0; i != h; ++i, cout << "\n")
            for (int j = 0; j != w; ++j) {
                int A = (i + j) / d;
                int B = (1000 + i - j) / d;
                cout << s[A % 2 + 2 * (B % 2)];
            }
    } else {
        for (int i = 0; i != h; ++i, cout << "\n")
            for (int j = 0; j != w; ++j)
                cout << s[(i + j) % 2];
    }
    
    
    
    return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int n,m,ans=1e9,col[705],cnt[2];
bool a[705][705],s[705],t[705];
void dfs(int x,int c){
	col[x]=c;cnt[c==1]++;
	for(int i=1;i<=n;i++){
		if(i==x||a[i][x])continue;
		if(!col[i])dfs(i,-c);
		else if(col[i]==c){
			puts("-1");
			exit(0);
		}
	}
}
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++){
		int u,v;
		scanf("%d%d",&u,&v);
		a[u][v]=a[v][u]=1;
	}
	s[0]=1;
	for(int i=1;i<=n;i++){
		if(col[i])continue;
		cnt[0]=cnt[1]=0;
		dfs(i,1);
		memset(t,0,sizeof t);
		for(int j=0;j<=n;j++){
			t[j+cnt[0]]|=s[j];
			t[j+cnt[1]]|=s[j];
		}
		for(int j=0;j<=n;j++)s[j]=t[j];
	}
	for(int i=0;i<=n;i++)
		if(s[i])ans=min(ans,i*(i-1)/2+(n-i)*(n-i-1)/2);
	printf("%d",ans);
}

Measured memory_bytes: 4276
#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;

int main(){
  int N;
  cin >> N;
  int p[N+1];
  for(int i=1;i<=N;i++) cin >> p[i];

  int cnt = 0;
  for(int i=1;i<=N;i++){
    if(i == N && i== p[i]){
      int tmp = p[i];
      p[i] = p[i-1];
      p[i-1] = tmp;
      cnt++;
    }
    if(i == p[i]){
      int tmp = p[i];
      p[i] = p[i+1];
      p[i+1] = tmp;
      cnt++;
    }
  }

  cout << cnt << endl;
  return 0;
}

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

#define mod      1e9+7;
#define INF      1e9+9;
#define ps(x,y)  fixed<<setprecision(y)<<x
# define PI 3.14159265358979323846264338327950 L
typedef long long ll;
typedef unsigned long long ull;
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#ifndef ONLINE_JUDGE
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
#endif
	int n,k,k1,co=0;
	cin>>n>>k;
	k1=k;
	while(n/k1!=0){
		co++;
		k1=k1*k;
	}
	cout<<co+1<<endl;
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public class MainClass
{
	public const long Giri = 1000000007;
	public const long DpInf = 99999999999999;
	
	public static void Main(string[] args)
	{
		var n = Console.ReadLine().ToInt();
		
		
		Console.WriteLine(n * 800 - (n/15)*200);

	}

	
	static long GCD(long a, long b)
	{
		var v = new[] { a, b };
		while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
		return v[0];
	}
	public static string[] Input() { return Console.ReadLine().Split(); }
}

public static class Smarter
{
	public static int ToInt(this string str) { return int.Parse(str); }
	public static long ToLong(this string str) { return long.Parse(str); }
	public static int[] ToInt(this string[] str, int offset = 0)
	{
		var r = new int[str.Length];
		for(int i = 0; i < str.Length; i++) r[i] = str[i].ToInt() + offset;
		return r;
	}
}

Measured memory_bytes: 26980
program main
  implicit none
  type pairtype
    integer :: v, k
  end type pairtype
  integer(8) :: n, i, j, pos
  integer, allocatable :: a(:)
  integer(8), allocatable :: dp(:),  dppre(:)
  type(pairtype), allocatable :: a1(:), a2(:)
  read *, n
  allocate (a(n), a1(n), a2(n), dp(0:n), dppre(0:n))
  read *, a
  do i = 1, n
    a1(i) = pairtype(a(i), i)
  end do
  call quicksort(a1)

  dp(:) = -1 * 10_8 ** 18
  dp(0) = 0
  do i = n, 1, -1
    dppre = dp

    do j = 0, n - i
      ! 左に入れる
      pos = j + 1
      dp(j + 1) = max(dp(j + 1), dppre(j) + (a1(i) % v) * abs(a1(i) % k - pos))

      ! 右に入れる
      pos = i + j
      dp(j) = max(dp(j), dppre(j) + (a1(i) % v) * abs(a1(i) % k - pos))
    end do
  end do

  print "(i0)", maxval(dp)

  contains

  recursive subroutine quicksort(a)
    type(pairtype), intent(inout) :: a(:)
    type(pairtype) :: pivot, tmp
    integer :: i, j, k, n
    real(4) :: r
    n = size(a)
    if (n <= 1) return
    i = 1
    j = n
    call random_number(r)
    k = 1 + floor(r * n)
    k = max(1, min(k, n))
    pivot = a(k)
    do
      do while (.not. pivot % v <= a(i) % v)
        i = i + 1
      end do
      do while (.not. a(j) % v <= pivot % v)
        j = j - 1
      end do
      if (i >= j) exit
      tmp = a(i)
      a(i) = a(j)
      a(j) = tmp
      i = i + 1
      j = j - 1
    end do
    call quicksort(a(1:i - 1))
    call quicksort(a(j + 1:n))
  end subroutine quicksort
end program main


Measured memory_bytes: 3004
#include<bits/stdc++.h>
#define N 100010
#define ll long long
#define inf 1e9
#define MOD 1000000007
#define pii pair<ll, ll>

using namespace std;
int a[N];
int main()
{
    int n;
    cin>>n;
    ll ans=0;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        ans+=a[i];
    }
    int m;
    cin>>m;
    for(int i=0;i<m;i++)
    {
        int p,x;
        cin>>p>>x;
        ll temp=ans-a[p];
        temp+=x;
        cout<<temp<<endl;

    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(long long i=0; i<n; i++)
#define Rep(i,n) for(long long i=1; i<n; i++)
#define ll long long
#include <math.h>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <set>
#include <vector>


using namespace std;
#define PI acos(-1)

int main(){
    string s;
    cin>>s;
    if(s=="ABC")cout<<"ARC"<<endl;
     else cout<<"ABC"<<endl;
   
}



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

bool comp(const int& lh, const int& rh) {
    
    if(rh % 10 == 0 || lh % 10 == 0) return lh%10 < rh%10; 
    else return lh%10 > rh%10;
}
 
 
int main(void){
    
  int data[5];
  int ans = 0;
  for(int i=0;i<5;i++) cin >> data[i];
  
  sort(data,data+5,comp);
  
  for(int i=0;i<5;i++) {
      
      ans += data[i];
      
      if(data[i] % 10 != 0 && i!=4){
          ans += (10 - data[i] % 10);
      }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 3600
import scala.io.StdIn._

object Main extends App {


  val Array(a,b,k) = readLine().split(" ").map(_.toLong)

  def solve() = {
    val x = Math.max(a-k,0)
    val y = Math.max(b-Math.max(k-a,0),0)
    s"$x $y"
  }

  println(solve())

}



Measured memory_bytes: 54796
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define frw(i, a, b) for(int i = a; i < b; i++)
#define bck(i, a, b) for(int i = a; i > b; i--)
#define fi first
#define se second
#define pub push_back
#define in insert
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define sz(a) int(a.size())
#define pii pair<int, int>
#define pll pair<ll, ll>
#define plll pair<ll, pll>
#define vpll vector<pll>
#define vpii vector<pii>

int main(){
	ios::sync_with_stdio(0);
	int n, k; cin >> n >> k;
	vll a(n + 1, 0), dp(n + 1, 0);
	frw(i, 1, n + 1)	cin >> a[i];
	dp[2] = abs(a[2] - a[1]);
	frw(i, 3, n + 1){
		ll mn = 1e11;
		bck(j, i - 1, max(0, i - k - 1)){
			mn = min(mn, dp[j] + abs(a[i] - a[j]));
		}
		dp[i] = mn;
	}
	cout << dp[n];
}


Measured memory_bytes: 1792
#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 D;
    cin >> D;
    vector<int> c(26);
    vector<vector<int>> s(D, vector<int>(26));
    rep(i, 26) cin >> c[i];
    rep(i, D) {
        rep(j, 26) { cin >> s[i][j]; }
    }
    vector<int> ans(D);
    rep(i, D) {
        auto it = max_element(s[i].begin(), s[i].end());
        ans[i] = it - s[i].begin() + 1;
    }
    rep(i, D - 1) cout << ans[i] << " ";
    cout << ans[D - 1] << endl;
}

Measured memory_bytes: 3680
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <stack>
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
constexpr ll MOD = 1000000007;
constexpr ll MAX = 2000;

ll N, ans;

vector<pair<ll, ll>> prime_factorize(ll N)
{
    vector<pair<ll, ll>> res;
    for (ll a = 2; a * a <= N; ++a)
    {
        if (N % a != 0)
            continue;
        ll ex = 0;
        while (N % a == 0)
        {
            ++ex;
            N /= a;
        }
        res.push_back({a, ex});
    }
    if (N != 1)
        res.push_back({N, 1});
    return res;
}

int main()
{
    ans = 0;
    cin >> N;
    for (int c = 1; c < N; c++)
    {
        const auto &pf = prime_factorize(N - c);
        ll res = 1;
        for (auto p : pf)
        {
            res *= p.second + 1;
        }
        ans += res;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3628
fun main(args: Array<String>){
    val (n, m) = readLine()!!.split(" ").map { it.toInt() }
    val zyx = Array(m){ readLine()!!.split(" ").map { it.toInt() }.let { Triple(it[0], it[1], it[2]) }}

    val tree = UnionFind(n)
    zyx.forEach {
        tree.unite(it.first - 1, it.second - 1)
    }
    println(tree.size())
}

class UnionFind(n: Int) {

    private val parent = IntArray(n){ i -> i }

    fun root(x: Int): Int{
        if(parent[x] == x){
            return x
        }else{
            parent[x] = root(parent[x])
            return parent[x]
        }
    }

    fun unite(x: Int, y: Int){
        val rx = root(x)
        val ry = root(y)
        if(rx != ry){
            parent[rx] = ry
        }
    }

    fun size(): Int{
        return (parent.indices).map { root(it) }.distinct().size
    }
}

Measured memory_bytes: 83256
from collections import OrderedDict

spade = {i for i in range(1, 13+1)}
heart = spade.copy()
crub = spade.copy()
diamond = spade.copy()

cards = OrderedDict()
cards['S'] = spade
cards['H'] = heart
cards['C'] = crub
cards['D'] = diamond

num_cards = int(input())

for i in range(num_cards):
    line = input().split()
    card, number = line[0], int(line[1])
    cards[card].remove(number)

for k, v in cards.items():
    sorted(v)
    for card in v:
        print(k, card)


Measured memory_bytes: 6004
#n = int(input())
s = input()
#a,b = map(int,input().split())
#da = list(map(int,input().split()))
#a = [int(input()) for i in range(n)]

def cal(x):
    for i in range(len(x)):
        if x[i] != x[-i-1]:
            return False
    return True

n = len(s)
if cal(s) and cal(s[:n//2]) and cal(s[n//2+1:n]):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int i;
    string s;
    cin>>s;
    if( s[0]=='R' && s[1]=='R' && s[2]=='R')
        cout<<"3"<<endl;
    else if( s[0]=='R' && s[1]=='R' && s[2]=='S')
        cout<<"2"<<endl;
       else  if( s[0]=='S' && s[1]=='R' && s[2]=='R')
        cout<<"2"<<endl;
      else  if( s[0]=='R' && s[1]=='S' && s[2]=='S')
        cout<<"1"<<endl;
        else if( s[0]=='S' && s[1]=='R' && s[2]=='S')
        cout<<"1"<<endl;
         else if( s[0]=='S' && s[1]=='S' && s[2]=='R')
        cout<<"1"<<endl;
         else if( s[0]=='R' && s[1]=='S' && s[2]=='R')
        cout<<"1"<<endl;
        else
            cout<<"0"<<endl;
   return 0;
}


Measured memory_bytes: 3624
n, m, q = gets.split.map(&:to_i)
condition = q.times.map{gets.split.map(&:to_i)}

ans = 0
(1..m).to_a.repeated_combination(n) do |x|
  t = 0
  condition.each do |a, b, c, d|
    t += d if x[b - 1] - x[a - 1] == c
  end
  ans = [ans, t].max
end

puts ans


Measured memory_bytes: 14592
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int syozyun(const void* x, const void* y) {
	char a = *(const char*)x, b = *(const char*)y;
	return a < b ? -1 : a > b;
}

int kozyun(const void* x, const void* y) {
	char a = *(const char*)x, b = *(const char*)y;
	return a > b ? -1 : a < b;
}

int main(void) {
	char s[128], t[128];
	if (scanf("%127s", s) != 1) return 1;
	if (scanf("%127s", t) != 1) return 1;
	qsort(s, strlen(s), sizeof(*s), syozyun);
	qsort(t, strlen(t), sizeof(*t), kozyun);
	puts(strcmp(s, t) < 0 ? "Yes" : "No");
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#ifdef DEBUG
#include "_debug.cpp"
#include "callable.hpp/callable.hpp"
#endif
#define endl '\n'
using namespace std;
using ll = long long;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    int ans = 0;
    for(int i = 0; i < n; i++) {
        int l, r;
        cin >> l >> r;
        ans += r - l + 1;
    }
    cout << ans << endl;
    return 0;
}


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

int main() {
  while(1) {
    int w,d;
    cin >> w >>d;
    if(w==0 && d==0) break;
    vector <int> front;
    int ans =0;
    front.resize(w);
    for(int i=0;i<w;i++) cin >> front[i],ans+= front[i];

    for(int i=0;i<d;i++) {
      int side,flg = 0;
      cin >> side;
      for(int j=0;j<front.size();j++)
	if(side == front[j]) {
	  front.erase(front.begin()+j);
	  flg = 1;
	  break;
	}
      if(flg == 0) ans+= side;
    }
    cout << ans <<endl;
  }
  return 0;
}

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

int main(){
  int n; cin >> n;
  map<int, int> mp;
  for(int i = 0; i < n; ++i){
    int tmp; cin >> tmp;
    mp[tmp]++;
  }
  int ans = 0;
  for(auto p: mp){
    if(p.second % 2 == 1) ans++;
  }
  cout << ans << endl;
  return 0; 
}

Measured memory_bytes: 8328
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <random>
#include <iomanip>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<pair<ll,ll> > vpll;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
typedef map<int, int> mii;
typedef set<int> si;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define arep(i,v) for(auto i : v)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STLL(s) strtoll(s.c_str(), NULL, 10)
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int
// #define endl '\n';
#define fi first
#define se second
#define NONVOID [[nodiscard]]
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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;}
template <class T> inline void dump(T &v){irep(i, v){cout<<*i<<((i==--v.end())?'\n':' ');}}
inline string getline(){string s; getline(cin,s); return s;}
inline void yn(const bool b){b?fin("yes"):fin("no");}
inline void Yn(const bool b){b?fin("Yes"):fin("No");}
inline void YN(const bool b){b?fin("YES"):fin("NO");}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
constexpr ll LLINF = 1LL<<60;
constexpr ll MOD = 1000000007;
constexpr double EPS = 1e-9;



int main() {


    ll a,b,n;
    cin>>a>>b>>n;
    if(b-1<=n)cout<<a*(b-1)/b<<endl;
    else {
        ll ans=a*n/b-a*(n/b);
        fin(ans);
    }
}



Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define _CRT_SECURE_NO_WARNINGS
#define ll long long
#define BUF 1e5
#define INF 1<<30
using namespace std;
ll MOD = 1e9 + 7;
ll A, B, C, D, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S;
ll ans = 0;
int main() {
	cin >> A >> B >> C;
	if (A == B)cout << C << endl;
	else if (A == C)cout << B << endl;
	else cout << A << endl;
}

Measured memory_bytes: 256
/*******Bismillahir-Rahmanir-Rahim**********/
/*
Name         : Abu Rifat Muhammed Al Hasib
Institution  : University of Barisal, Bangladesh
Github       : abu-rifat
Codeforces   : AbuRifatMuhammed
AtCoder      : aburifat
codechef     : aburifat
SPOJ         : abu_rifat
UvaOJ        : aburifat
DevSkill     : abu_rifat
lightoj      : Abu Rifat Muhammed Al Hasib
facebook     : https://www.facebook.com/a.r.m.al.hasib/
linkedin     : https://www.linkedin.com/in/abu-rifat-534258142/
Email        : rifat.cse4.bu@gmail.com, armalhasib@gmail.com
*/

/*
Contest         : Beginner Contest 158
Online Judge    : AtCoder
Solving Method  :
*/

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define MX 250009
#define pb push_back


int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    ll t;
    t=1;
    //cin>>t;
    for(ll T=1;T<=t;T++)
    {
        ll a, b;
        cin>>a>>b;
        ll ck=1;
        for(ll i=1; i<1010;i++){
            ll m=i*(0.08);
            ll n=i/10;
            if(m==a&&n==b&&m>0&&n>0){
                cout<<i<<endl;
                ck=0;
                break;
            }
        }
        if(ck)cout<<"-1"<<endl;
    }
    return 0;
}

/***********Alhamdulillah***********/



Measured memory_bytes: 256
#include <stdio.h>

int bsort(int a[] , int n);

int main(void)
{
	int n , count , i;
	scanf("%d",&n);
	int a[n];
	for( i = 0; i < n; i++)
	{
		scanf("%d",&a[i]);
	}
	count = bsort(a,n);
	for( i = 0; i < n; i++)
	{
		if( i != n-1)printf("%d ",a[i]);
		else printf("%d\n",a[i]);
	}
	printf("%d\n",count);
	return 0;
}

int bsort(int a[] , int n)
{
	int i , j , tmp , count = 0;
	for( i = 0; i < n; i++)
	{
		for( j = n-1; j > i; j--)
		{
			if(a[j] < a[j-1])
			{
				tmp = a[j];
				a[j] = a[j-1];
				a[j-1] = tmp;
				count++;
			}
		}
	}
	
	return count;
}


Measured memory_bytes: 2080
#![allow(non_snake_case)]
use std::io::prelude::*;
use std::io::stdin;
use std::str::FromStr;

fn main() {
    let x: usize = read();
    let y: usize = read();
    let z: usize = read();
    let K: usize = read();
    let mut a: Vec<i64> = (0..x).map(|_| read()).collect();
    let mut b: Vec<i64> = (0..y).map(|_| read()).collect();
    let mut c: Vec<i64> = (0..z).map(|_| read()).collect();

    a.sort_by(|a, b| b.cmp(a));
    b.sort_by(|a, b| b.cmp(a));
    c.sort_by(|a, b| b.cmp(a));

    let mut v = vec![];

    for i in 0..x {
        for j in 0..y {
            for k in 0..z {
                if (i + 1) * (j + 1) * (k + 1) <= K {
                    v.push(a[i] + b[j] + c[k]);
                } else {
                    break;
                }
            }
        }
    }
    v.sort_by(|a, b| b.cmp(a));

    for x in v.iter().take(K) {
        println!("{}", x);
    }
}

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


Measured memory_bytes: 4352
import math
import sys

def getinputdata():

    # 配列初期化
    array_result = []
    
    data = input()

    
    array_result.append(data.split(" "))

    flg = 1

    try:


        while flg:

            data = input()

            array_temp = []

            if(data != ""):
                
                array_result.append(data.split(" "))

                flg = 1

            else:

                flg = 0
    finally:


        return array_result





arr_data = getinputdata()

s = arr_data[0][0]

chkflg=True

#print(len(s))

strresult=""
for v in range(0,len(s)):
    
#    print(s[v])
    
    if chkflg:
        
        strresult+=s[v]
        chkflg=False
       
    else:
        
        chkflg=True
        
        
print(strresult)

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

int main() {
  int n,m;
  cin >> n >> m;
  long cnt=0;
  vector <int> a(n+1);
  for (int i=0;i<n;i++)
    cin >> a.at(i);
  priority_queue <long> b;
  for (int i=0;i<n;i++)
    b.push(a.at(i));
  for(int i=0;i<m;i++){
    cnt=b.top()/2;
    b.pop();
        b.push(cnt);
    
  }
  cnt=0;
  while(!b.empty()){
  cnt+=b.top();
    b.pop();
  }
 cout << cnt << endl;
  
  
}

Measured memory_bytes: 1784
N = int(input())
cnt = 0
s = 'No'

for i in range(N):
    D1,D2 = map(int, input().split())
    if D1 == D2:
        cnt += 1
    else:
        cnt = 0
    if cnt == 3:
        s = 'Yes'
        break

print(s)

Measured memory_bytes: 9164
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include <sstream>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
#include <iomanip>
#include <numeric>
using namespace std;


int main(void){
    string s = ">";
    cin >> s;
    vector <int>table(s.size()+1, 0);

    for(int cnt =0; cnt < 1000000; cnt++){
        int flag = 0;
        for(int i =0;i < s.size(); i++){
            if(s[i] == '<' && table[i] >= table[i+1]){
                table[i+1] = table[i] + 1;
                flag = 1;
            }
        }
        for(int i = s.size() -1 ; i >= 0; i-- ){
            if(s[i] == '>' && table[i] <= table[i+1]){
                table[i] = table[i+1] + 1;
                flag = 1;
            }
        }

        if(flag == 0) break;
    }
    
    long sum = accumulate(table.begin(), table.end(),0L);
    cout << sum << endl;
    return 0;
}   

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

int main() {
    int w,h,x,y;
    cin >>w>>h>>x>>y;
    double ans = (double)w*(double)h/2;
    if(x==(double)w/2 && y==(double)h/2){
        cout<<ans<<" "<<1<<endl;
    }else{
        cout<<ans<<" "<<0<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(i,a,b) for (int i=a; i<b; ++i)
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int N;
    cin >> N;
    deque <double> X(N);
    loop(i,0,N) cin >> X[i];
    sort(X.begin(), X.end());
    loop(i,0,N-1)
    {
        double x=X[0], y=X[1];
        X.pop_front(); X.pop_front();
        X.push_front((x+y)/2);
    }
    cout << fixed << setprecision(10) << X[0] << endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws IOException {
		InputStreamReader isr = new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader(isr);
		String buf = br.readLine();
		int time = Integer.parseInt(buf);
		int h = time / 60 / 60;
		time -= h * 60 *60;
		int m = time /60 ;
		int s = time -= m * 60;


		System.out.println(h + ":" + m + ":" + s );
	}
}

Measured memory_bytes: 24436
import java.util.*;
public class Main {
    public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
    	int[] ary = new int[3];
    	ary[0]=sc.nextInt();
    	ary[1]=sc.nextInt();
    	ary[2]=sc.nextInt();

    	if(ary[0]<ary[1]&&ary[1]<ary[2]){
    		System.out.println("Yes");
    	}else{
    		System.out.println("No");
    	}
    }
}



Measured memory_bytes: 26208
#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define mod 1000000007
using namespace std;
int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    string s;
    cin>>s;
    int cnt=0;
    for(auto x:s) 
    {
        cnt+=(x=='R');
    }    
    int ans=0;
    for(int i=0;i<cnt;i++)
    {
        ans+=(s[i]=='R');
    }
    cout<<cnt-ans;
    return 0;
}

Measured memory_bytes: 3768
#include <iostream>
using namespace std;
int n, t, r[10][10];
int main() {
	while(scanf("%d", &n), n) {
		int c = 0;
		for(int i = 0; i <= 2 * n - 2; i++) {
			for(int j = 0; j <= i; j++) {
				if(j < n && i - j < n) {
					if(i % 2 == 1) r[j][i - j] = ++c;
					else r[i - j][j] = ++c;
				}
			}
		}
		printf("Case %d:\n", ++t);
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < n; j++) printf(r[i][j] < 10 ? "  %d" : " %d", r[i][j]);
			printf("\n");
		}
	}
}

Measured memory_bytes: 3116
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define REP(i,x,n) for(int i = (x); i < (n); ++i)
#define ll long long
#define P pair<ll,ll>
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1);

int main(void)
{
    ll n, m, ans=1;
    cin >> n >> m;
    rep(i,m){
        ans *= 2;
    }
    cout << ans*(1900*m + 100*(n-m)) << endl;
    return 0;
}


Measured memory_bytes: 3632
#include <iostream>

using namespace std;

int main(int argc, char **argv)
{
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0), cout.precision(15);
    int A, B, C;
    cin >> A >> B >> C;
    cout << min(B / A, C) << endl;
    
    return 0;
}

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

using namespace std;

void one()
{
	cout << 1;
	exit(0);
}

void zero()
{
	cout << 0;
	exit(0);
}

main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	
	int n;
	cin >> n;
	
	int p = n % 100;
	
	while(p > 0)
	{
		if(p >= 5)
		{
			n -= 105;
			p -= 5;
		}
		else
		{
			n -= (100 + p);
			p = 0;
		}
	}
	
	if(n >= 0)
		cout << 1;
	else
		cout << 0;
}

Measured memory_bytes: 256
line = input()
numbers = [int(n) for n in line.split()]
time = numbers[2]*10 + 5
biscuits = numbers[1]
time_taken = numbers[0] * 10
predicted_value = 0
while time >= 0:
    if time - time_taken >= 0:
        predicted_value += biscuits
    time -= time_taken
print(predicted_value)

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

int main() {
  string s;
  cin >> s;
  
  bool ok = true;
  while(ok){
    s.pop_back();
    s.pop_back();
    int l = s.size();
    bool can = true;
    for(int i = 0; i < l / 2; i++){
      if(s.at(i) != s.at(i + l / 2)) can = false;
    }
    if(can) ok = false;
  }
  
  cout << s.size() << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,k,n) for(int i=(k);i<(int)(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) begin(x),end(x)

using namespace std;

#define MAX_V 10000
int V;

typedef int Weight;
const Weight INF = 1000000000;
// const Weight eps = 1e-8;

struct Edge{
  int src, dest;
  int cap, rev;
  Weight weight;
  bool operator < (const Edge &rhs) const {return weight > rhs.weight;}
};

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
typedef vector<Weight> Array;
typedef vector<Array> Matrix;

Weight h[MAX_V];                // potential
Weight dist[MAX_V];             // minimum distance
int prevv[MAX_V], preve[MAX_V]; // previous vertex and edge

void add_edge(Graph &g, int src, int dest, int cap, Weight weight) {
  g[src].push_back((Edge){src, dest, cap, (int)g[dest].size(), weight});
  g[dest].push_back((Edge){dest, src, 0, (int)g[src].size() - 1, -weight});
}

Weight min_cost_flow(Graph &g, int s, int t, int f) {
  Weight res = 0; V = g.size();
  memset(h, 0, sizeof(h));
  typedef pair<Weight, int> P;
  while (f > 0) {
    priority_queue<P, vector<P>, greater<P> > que;
    fill(dist, dist + V, INF);
    dist[s] = 0;
    que.push(P(0, s));
    while (!que.empty()) {
      P p = que.top(); que.pop();
      int v = p.second; 
      if (dist[v] < p.first) continue;
      REP(i, g[v].size()) {
        Edge &e = g[v][i];
        if (e.cap > 0 && dist[e.dest] > dist[v] + e.weight + h[v] - h[e.dest] /* + eps */) {
          dist[e.dest] = dist[v] + e.weight + h[v] - h[e.dest];
          prevv[e.dest] = v;
          preve[e.dest] = i;
          que.push(P(dist[e.dest], e.dest));
        }
      }
    }
    if (dist[t] == INF) return -1;
    REP(v, V) h[v] += dist[v];

    int d = f;
    for (int v = t; v != s; v = prevv[v]) d = min(d, g[prevv[v]][preve[v]].cap);
    f -= d;
    res += d * h[t];
    for (int v = t; v != s; v = prevv[v]) {
      Edge &e = g[prevv[v]][preve[v]];
      e.cap -= d;
      g[v][e.rev].cap += d;
    }
  }
  return res;
}

int main() {
  int n;
  cin>>n;
  Matrix w(n, Array(n));
  REP(i,n)REP(j,n) cin >> w[i][j];
  Matrix e(n, Array(n));
  REP(i,n)REP(j,n) cin >> e[i][j];
  vector<string> m(n);
  //Matrix mat(n, Array(n));
  Graph g(2*n+2);
  int cost = 0;
  REP(i,n) {
    cin>>m[i];
    REP(j,n) {
      if (m[i][j] == 'o') {
        //mat[i][j] = 1000 - e[i][j];
        add_edge(g, i, n+j, 1, 1000 - e[i][j]);
        cost += e[i][j];
      } else {
        //mat[i][j] = 1000 + w[i][j];
        add_edge(g, i, n+j, 1, 1000 + w[i][j]);
      }
    }
  }
  REP(i,n) {
    add_edge(g, n+i, 2*n+1, 1, 0);
    add_edge(g, 2*n, i, 1, 0);
  }
  //auto res = hungarian(mat);
  auto resc = min_cost_flow(g, 2*n, 2*n+1, n);
  cout << (resc - n*1000 + cost) << endl;
  
  stringstream ss;
  int count = 0;
  REP(i,n)REP(j,n) {
    if (g[i][j].cap == 0) {
      if (m[i][j] == '.') {
        ss << (i+1) << ' ' << (j+1) << " write" << endl;
        ++count;
      }
    } else {
      if (m[i][j] == 'o') {
        ss << (i+1) << ' ' << (j+1) << " erase" << endl;
        ++count;
      }
    }
  }
  cout << count << endl;
  cout << ss.str() << flush;
  return 0;
}

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

#define endl '\n'
#define fi first
#define se second
#define pb push_back
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
const int MOD = 1e9 + 7;
const int maxn = 3e3 + 5;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;

char s[maxn], t[maxn];
int dp[maxn][maxn];

int main() {
    scanf("%s", s + 1);
    scanf("%s", t + 1);
    int n = strlen(s + 1), m = strlen(t + 1), l, r;
    for (int i = n; i > 0; i--) {
        for (int j = m; j > 0; j--) {
            if (s[i] == t[j]) dp[i][j] = dp[i + 1][j + 1] + 1;
            else dp[i][j] = max(dp[i + 1][j], dp[i][j + 1]);
        }
    }
    l = r = 1;
    while (l <= n && r <= m) {
        if (s[l] == t[r]) {
            printf("%c", s[l]);
            l++;
            r++;
        } else if (dp[l][r] == dp[l + 1][r]) l++;
        else r++;
    }
    puts("");
    return 0;
}


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

using namespace std;

struct Edge {
    int to, len;
    string cost;
    Edge(int to, int len, string cost) : to(to), len(len), cost(cost){}
    Edge(){}
    bool operator < (const Edge &x) const {
        return (cost < x.cost);
    }
    bool operator > (const Edge &x) const {
        return (x < *this);
    }
};

int main()
{
    int n, a, st, gl;

    while (scanf("%d %d %d %d", &n, &a, &st, &gl) && n){
        vector<Edge> g[128];
        string dist[40][501];

        for (int i = 0; i < n; i++){
            for (int j = 0; j <= 500; j++){
                dist[i][j] = "~";
            }
        }

        for (int i = 0; i < a; i++){
            int x, y;
            char label[128];
            scanf("%d %d %s", &x, &y, label);
            g[x].push_back(Edge(y, strlen(label), (string)label));
        }

        priority_queue<Edge, vector<Edge>, greater<Edge>> pq;
        dist[st][0] = (string)"";
        pq.push(Edge(st, 0, (string)""));
        while (!pq.empty()){
            Edge x = pq.top(); pq.pop();
            if (x.cost != dist[x.to][x.len]) continue;

            for (int i = 0; i < g[x.to].size(); i++){
                Edge e = g[x.to][i];
                Edge nxt = Edge(e.to, x.len + e.len, x.cost + e.cost);
                if (nxt.len <= 500 && nxt.cost < dist[nxt.to][nxt.len]){
                    dist[nxt.to][nxt.len] = nxt.cost;
                    pq.push(nxt);
                }
            }
        }

        string ans = "~";
        bool ng = false;
        for (int i = 0; i <= 500; i++){
            if (dist[gl][i] != "~"){
                if (dist[gl][i] < ans) ans = dist[gl][i];
            }
        }

        printf("%s\n", (ans == "~" || ans.size() > 240) ? "NO" : ans.c_str());
    }
}

Measured memory_bytes: 25492
import collections , sys



n = int(input())
v = [int(i) for i in input().split()]


c2 = collections.Counter(v[::2])
c1 = collections.Counter(v[1::2])

if len(list(set(v))) == 1:
    print(n//2)
    sys.exit()

ceven = c2.most_common()[0][:]
codd = c1.most_common()[0][:]

if ceven[0] == codd[0]:
    if ceven[1] > codd[1]:
        codd = c1.most_common()[1][:]
    elif ceven[1] < codd[1]:
        ceven = c2.most_common()[1][:]
    else:
        ceven2 = c2.most_common()[1][:]
        codd2 = c1.most_common()[1][:]
        if  ceven2[1] > codd2[1]:
            ceven = ceven2
        else :
            codd = codd2
            
ans = n - codd[1] - ceven[1]

print(ans)
        
        
    


Measured memory_bytes: 22336
N, M = map(int, input().split())
ks = [list(map(int, input().split())) for _ in range(M)]
p = list(map(int, input().split()))

num = 2 ** N
result = 0

for i in range(num):
    flag = True
    pattern = bin(i)[2:]
    pattern = '0' * (N-len(pattern)) + pattern

    for j in range(M):
        sw = 0
        for k in range(ks[j][0]):
            if pattern[ks[j][k+1]-1] == '1':
                sw += 1

        if sw % 2 != p[j]:
            flag = False
            break

    if flag:
        result += 1

print(result)


Measured memory_bytes: 3188
# -*- coding: utf-8 -*-


#----------
S = input().strip()
#----------
all_alphabet=[chr(ord('a') + i) for i in range(26)]

check_alphabet=all_alphabet
for word in S:
    if word in check_alphabet:
        check_alphabet.remove(word)

if len(check_alphabet) == 0:
    print("None")
else:
    print(check_alphabet[0])


Measured memory_bytes: 3188
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>

using namespace std;

int main()
{
	int n;
	vector<int> v[100000];
	scanf("%d", &n);
	for(int i=0; i<n-1; i++){
		int x, y;
		scanf("%d %d", &x, &y);
		x--;
		y--;
		v[x].push_back(y);
		v[y].push_back(x);
	}
	int d[100000];
	fill(d, d+n, -1);
	d[0]=0;
	queue<int> que;
	que.push(0);
	while(!que.empty()){
		int x=que.front();
		que.pop();
		for(int i=0; i<v[x].size(); i++){
			if(d[v[x][i]]==-1){
				d[v[x][i]]=d[x]+1;
				que.push(v[x][i]);
			}
		}
	}
	multimap<int, int> mp;
	for(int i=0; i<n; i++){
		mp.insert(make_pair(-d[i], i));
	}
	int g[100000];
	for(auto itr=mp.begin(); itr!=mp.end(); itr++){
		int x=itr->second;
		g[x]=0;
		for(int i=0; i<v[x].size(); i++){
			if(d[v[x][i]]>d[x]){
				g[x]=g[x]^(g[v[x][i]]+1);
			}
		}
	}
	if(g[0]==0){
		printf("%s\n", "Bob");
	}else{
		printf("%s\n", "Alice");
	}
	return 0;
}

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

const int N = 1005;

int h, w;
char s[N][N];

int dist[N][N];

int dx[4] = {0, -1, 0, 1};
int dy[4] = {1, 0, -1, 0};

int main() {
  scanf("%d %d", &h, &w);
  for (int i=0; i<h; i++) {
    scanf("%s", s + i);
  }
  
  queue<pair<int, int>> q;
  memset(dist, -1, sizeof dist);
  for (int i=0; i<h; i++) {
    for (int j=0; j<w; j++) {
      if (s[i][j] == '#') {
        q.push({i, j});
        dist[i][j] = 0;
      }
    }
  }
  
  int ans = 0;
  while (q.size()) {
    int x = q.front().first;
    int y = q.front().second;
    q.pop();
    
    ans = dist[x][y];
    
    for (int i=0; i<4; i++) {
      int nx = x + dx[i];
      int ny = y + dy[i];
      if (nx < 0 || nx >= h || ny < 0 || ny >= w) continue;
      if (dist[nx][ny] != -1) continue;
      
      dist[nx][ny] = dist[x][y] + 1;
      q.push({nx, ny});
    }
  }
  
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 13328
from copy import copy, deepcopy
from collections import Counter
from math import sqrt

MOD = 10**9 + 7

S = list(input())
if S[0] == '>':
    S.insert(0, '<')
if S[-1] == '<':
    S.insert(len(S), '>')

low = [i for i, v in enumerate(S) if i > 0 and S[i-1] == '>' and S[i] == '<']
high = [i for i, v in enumerate(S) if i > 0 and S[i-1] == '<' and S[i] == '>']

if S[0] == '<':
    low.insert(0, 0)
elif S[0] == '>':
    high.insert(0, 0)

if S[-1] == '<':
    high.append(len(S))
elif S[-1] == '>':
    low.append(len(S))

ans = 0


def s(i):
    return i * (i+1) // 2


for i in range(len(high)):
    lh = abs(high[i] - low[i])
    hl = abs(low[i+1] - high[i])
    ans += s(max(lh, hl)) + s(min(lh, hl)-1)

print(ans)

Measured memory_bytes: 20076
#include <stdio.h>
#include <limits.h>

int myabs(int a, int b) {
	if (a < b)
		return b - a;
	else
		return a - b;
}

int main()
{
	long i, j, n, l, non_eat, eated, tmp, force = 0;

	scanf("%ld%ld", &n, &l);

	for (i = 0, non_eat = 0; i < n; i++)
		non_eat += l + i;

	for (i = 0, eated = 0; i < n; i++) {
		for (j = 0, tmp = 0; j < n; j++) {
			if (j != i)
				tmp += l + j;
		}
		if (force == 0 || myabs(non_eat, tmp) < myabs(non_eat, eated)) {
			force = 1;
			eated = tmp;
		}
	}

	printf("%ld\n", eated);
	return 0;
}


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

#include <assert.h>    // LON
#include <math.h>    // sqrt()


using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
typedef long long ll;
//typedef pair<int, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = LONG_LONG_MAX;
const ll MINF = -10e10;
//const int INF = INT_MAX;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)


//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

//typedef priority_queue<P, vector<P>, greater<P>> PQ_ASK;
const int mod = 1000000007;

void ok() {
    cout << "Possible" <<endl;
}

int main() {
    int a, b;
    cin >> a >>b;

    if( a % 3 == 0 ) {
        ok();
    }else if(b % 3 == 0) {
        ok();
    }else if( (a+b)%3 == 0) {
        ok();
    }else {
        cout << "Impossible" <<endl;
    }

}

Measured memory_bytes: 256