akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {
	public static void main(String args[]) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		Solver solver = new Solver();
		solver.init();
		solver.readHead(in.readLine());
		// for (; solver.hasNext();) {
		// solver.readBody(in.readLine());
		// }
		// solver.solve();
	}
}

class Solver {
	int N;
	int cnt;

	public void init() {
		N = 0;
		cnt = 0;
	}

	public void readHead(String str) {
		String[] strArr = str.split("\\s+");
		N = Integer.parseInt(strArr[0]);
		// System.out.println(N);
		System.out.println(N * N * N);
	}

	public boolean hasNext() {
		return cnt < N;
	}

	public void readBody(String str) {
		// System.out.println(str);
		cnt++;
	}

	public void solve() {

	}
}


Measured memory_bytes: 21588
X,Y=map(int,input().split())
A,B=X,Y
while A>=2 or B>=2:
    if A>B:
        a = A//2
        A-=2*a
        B+=a
    else:
        b = B//2
        B-=2*b
        A+=b
if X-Y == A-B:
    print("Brown")
else:
    print("Alice")


Measured memory_bytes: 38512
#!/usr/bin/env ruby
_n, m, q = gets.chomp.split.map(&:to_i)


a = []
b = []
c = []
d = []

1.upto(q) do |i|
  input = gets.chomp.split.map(&:to_i)
  a << input[0]
  b << input[1]
  c << input[2]
  d << input[3]
end

ans = 0

1.upto(m) do |i_1|
  a_1 = i_1
  i_1.upto(m) do |i_2|
    a_2 = i_2
    i_2.upto(m) do |i_3|
      a_3 = i_3
      i_3.upto(m) do |i_4|
        a_4 = i_4
        i_4.upto(m) do |i_5|
          a_5 = i_5
          i_5.upto(m) do |i_6|
            a_6 = i_6
            i_6.upto(m) do |i_7|
              a_7 = i_7
              i_7.upto(m) do |i_8|
                a_8 = i_8
                i_8.upto(m) do |i_9|
                  a_9 = i_9
                  i_9.upto(m) do |i_10|
                    a_10 = i_10

                    arr = [a_1, a_2, a_3, a_4, a_5, a_6, a_7, a_8, a_9, a_10]
                    score = 0
                    a.each_with_index do |a_i, i|
                      score += d[i] if arr[b[i] - 1] - arr[a_i - 1] == c[i]
                    end
                    ans = [score, ans].max
                  end
                end
              end
            end
          end
        end
      end
    end
  end
end

puts ans


Measured memory_bytes: 14248
def g(A,l,m,r):
 global c
 L,R=A[l:m]+[1e10],A[m:r]+[1e10]
 i=j=0
 for k in range(l,r):
  if L[i]<R[j]:A[k]=L[i];i+=1
  else:A[k]=R[j];j+=1
  c+=1
def s(A,l,r):
 if l+1<r:
  m=(l+r)//2
  s(A,l,m);s(A,m,r)
  g(A,l,m,r)
c=0
n=int(input())
A=list(map(int,input().split()))
s(A,0,n)
print(*A)
print(c)


Measured memory_bytes: 61660
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
const int mod =1e+9+7;

int main(){
    ll n,k; cin>>n>>k;
    vector<ll>a(n);
    rep(i,n)cin>>a[i];
    for(ll i=k;i<n;i++){
        if(a[i]>a[i-k])cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
}


























































































Measured memory_bytes: 4844
import java.util.Deque;
import java.util.ArrayDeque;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] hw = br.readLine().split(" ");
        int h = Integer.parseInt(hw[0]);
        int w = Integer.parseInt(hw[1]);
        char[][] grid = new char[h+2][w+2];
        int[][] distance = new int[h+2][w+2];
        
        int sharp = 0;
        for (int i = 0; i < h; i++) {
            String row = br.readLine();
            for (int j = 0; j < w; j++) {
                grid[i+1][j+1] = row.charAt(j);
                if (grid[i+1][j+1]=='#') sharp++;
            }
        }
        
        Deque<Integer> xs = new ArrayDeque<Integer>();
        Deque<Integer> ys = new ArrayDeque<Integer>();
        
        xs.add(1);
        ys.add(1);
        distance[1][1] = 1;
        //distance[h][w] = -1;
        int[][] nexts = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
        int x = xs.remove();
        int y = ys.remove();
        boolean[][] visited = new boolean[h+2][w+2];
        
        int a = 0;
        boolean reachable = true;
        while (x!=w || y!=h) {
            for (int[] next: nexts) {
                if (visited[y-next[0]][x-next[1]]) continue;
                if (grid[y-next[0]][x-next[1]] == '.') {
                    visited[y-next[0]][x-next[1]] = true;
                    distance[y-next[0]][x-next[1]] = distance[y][x]+1; 
                    xs.add(x-next[1]);
                    ys.add(y-next[0]);
                    
                }
                /*else if (grid[y-next[0]][x-next[1]] == '#'){
                    //visited[y-next[0]][x-next[1]] = true;
                    //a++;
                }*/
                
            }
            if (xs.isEmpty()) {
                reachable = false;
                break;
            }
            x = xs.remove();
            y = ys.remove();
        }
        
        if (reachable) System.out.println(h*w-distance[y][x] - sharp);
        else System.out.println(-1);
        
    }
}


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


int main(){
  ll i,j;
  ll h,w,k;
  cin>>h>>w>>k;
  vector<ll> v;
  ll ans[h][w];
  ll e=inf;
  int s=1;
  for(i=0;i<h;i++){
    int u=0;
    for(j=0;j<w;j++){
      char c;
      cin>>c;
      if(c=='#') {
        if(u!=0) s++;
        u=1;
      }
      ans[i][j]=s;
    }
    if(u!=0) {
      e=min(e,i);
      s++;
    }
    else  v.pb(i);
  }
  if(e!=inf){
    for(i=e-1;i>=0;i--){
      for(j=0;j<w;j++){
        ans[i][j]=ans[i+1][j];
      }
    }
  }
  for(i=0;i<v.size();i++){
    for(j=0;j<w;j++){
      if(v[i]>e) {
      ans[v[i]][j]=ans[v[i]-1][j];
      }
    }
  }
  for(i=0;i<h;i++){
    for(j=0;j<w;j++){
      cout<<ans[i][j]<<" ";
    }
    cout<<endl;
  }

}

Measured memory_bytes: 1408
#include<iostream>
#include<string>
#include<cstring>
using namespace std;
bool fun(string a){
  for(int i=0;i<a.length();i++){
    if(isupper(a[i])){
      return false;
    }
  }
  return true;
}
int main(){
  int k;
  cin>>k;
  string s;
  cin>>s;
  string s1="...";
 if(fun(s))
 {
   if(s.length()<=k){
     cout<<s;
   }
   else{
     s.resize(k);
     s.append(s1);
     cout<<s;
   }
 }
   
 return 0;
 }



Measured memory_bytes: 3100
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <complex>
#include <set>
#include <list>
#include <iomanip>
#include <map>
#include <memory.h>



using namespace std;
static const double EPS = 1e-9;
typedef long long ll;
typedef unsigned long long ull;
#define FOR(i,n) for(int i=0;i<(int)n;++i)
#define FORNUM(p, x) for (int num = p; num < (int)(x); ++num)
#define FORI(p, x) for (int i = p; i < (int)(x); ++i)
#define FORJ(p, x) for (int j = p; j < (int)(x); ++j)
#define FORK(p, x) for (int k = p; k < (int)(x); ++k)
#define FORL(p, x) for (int l = p; l < (int)(x); ++l)

typedef pair<int,int>P;
#define INF 1000000000
 
struct edge { 
	int from, to; 
	edge (int from, int to){
		this->from=from; this->to=to;
	}
};
 
int V,E;
typedef vector<edge> edges;
vector<edges> G;


int a[200005];
int n;
int main(){
	scanf("%d ", &n);
	ll sum = 0LL;
	FORI(0, n) {
		scanf("%d ", &a[i]);
		sum += a[i];
	}
	ll x = 0LL, y = sum;
	ll ans = 10000000000000LL;
	for (int i = 0; i < n - 1; i++) {
		x += a[i];
		y -= a[i];
		ans = min(ans, abs(x - y));
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace AtCoder
{
    class Program
    {
        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        static void Main(string[] args)
        {
            int[] V = ReadInts();
            int N = V[0], K = V[1];
            Console.WriteLine(N - K + 1);
        }
    }
}


Measured memory_bytes: 13140
import math

class weightedUnionTree:
    def __init__(self,n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)
        self.weight = [0] * (n+1)

    def find(self,x):
        if self.par[x] == x:
            return x
        else:
            y = self.find(self.par[x])
            self.weight[x] += self.weight[self.par[x]]
            self.par[x] = y
            return y

    def union(self,x, y, w):
        rx = self.find(x)
        ry = self.find(y)
        #self.isThere[x] = True; self.isThere[y] = True

        if self.rank[rx] < self.rank[ry]:
            self.par[rx] = ry
            self.weight[rx] = w - self.weight[x] + self.weight[y]

        else:
            self.par[ry] = rx
            self.weight[ry] = -w - self.weight[y] + self.weight[x]

            if self.rank[rx] == self.rank[ry]:
                self.rank[rx] += 1

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def diff(self, x, y):
        """
        print("diff: ",end="")
        print(self.weight[x],end=" ")
        print(self.weight[y],end=" ")
        #print(self.isThere)
        """

        if(self.same(x, y)): #conditional branch
            print(self.weight[x] - self.weight[y])
        else:
            print("?")


if __name__ == "__main__":
    n, q = (int(p) for p in input().split())
    tree = weightedUnionTree(n)
    #for i in range(n):
    #    queue.append(0)
    for i in range(q):
        question, num = input().split(' ', 1)
        #print(question)
        #print(input)
        if(int(question) == 0):
            #print("relate")
            x, y, z = num.split(' ')
            tree.union(int(x), int(y), int(z))
        else:
            #print("diff")
            x, y = num.split(' ')
            tree.diff(int(x), int(y))



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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

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

    ll N;
    cin >> N;

   	ll x = -1;
    REP(i, N+2){
    	if(i*(i-1) == 2*N) x = i;
    }
    if(x == -1){
    	cout << "No" << endl;
    	exit(0);
    }
    cout << "Yes" << endl;
    vector<ll> res[x];
    ll ind = 1;
    REP(i, x){
    	REP(j, x){
    		if(i >= j) continue;
    		res[i].push_back(ind);
    		res[j].push_back(ind);
    		ind++;
    	}
    }
    cout << x << endl;
    REP(i, x){
    	cout << res[i].size() << " ";
    	REP(j, res[i].size()) cout << res[i][j] << " ";
    	cout << endl;
    }
    return 0;
}

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

using namespace std;

typedef long long ll;

#define sz(x) ((int)(x).size())
#define in(x) int x;cin>>x
#define bit(n) (1<<(n))

#define rep(i,n) for (int i=0;i<(n);i++)
#define repp(i,n) for (int i=1;i<=(n);i++)

int main(){
	int n, m, l, r, b=0, e=100002, a=0;
	cin >> n >> m;
	rep(i, m) {
		cin >> l >> r;
		if (l >= b) b = l;
		if (r <= e) e = r;
	}
	a =  e - b + 1;
	if (a < 0) a = 0;
	cout << a << endl;

	return 0;
}


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

using namespace std;
int main(){
int N;
cin >>N;
int A[100001]={};//０で初期化、各値の数
int a;
for(int i=0;i<N;i++){
    cin >>a;
    A[a]++;//a階にあるをたす。
}
long long sum;
long long ans=A[0]+A[1];
for(int i=1;i<100000;i++){
sum=A[i-1]+A[i]+A[i+1];
ans=max(sum,ans);
}



cout << ans <<endl;


 return 0;
}
/*
7
3 1 4 1 5 9 2

4




*/


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int a, b;
    cin >> a >> b;
    if (a % 2 == 1 && b % 2 == 1)
 	    cout << "Odd" << endl;
    else
        cout << "Even" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

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

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  int px, py;
  while (cin >> px >> py) {
    if (px == 0 && py == 0) break;
    int n;
    cin >> n;
    vector<int> x(n), y(n);
    for (int i = 0; i < n; i++) {
      cin >> x[i] >> y[i];
      x[i]--, y[i]--;
    }
    bool ok = false;
    auto check = [&](int a, int b, int c, int d) {
      return c - a >= 0 && c - a <= 2 && d - b >= 0 && d - b <= 2;
    };
    using P = pair<int, pii>;
    stack<P> st;
    st.emplace(-1, pii(py, px));
    while (!st.empty()) {
      P p = st.top(); st.pop();
      int id = p.first, sy, sx;
      tie(sy, sx) = p.second;
      if (id == n - 1) {
        ok = true;
        break;
      }
      for (int i = 0; i < 12; i++) {
        int ny = sy + dy[i], nx = sx + dx[i];
        if (ny >= 0 && ny < 10 && nx >= 0 && nx < 10 && check(y[id + 1], x[id + 1], ny, nx)) {
          st.emplace(id + 1, pii(ny, nx));
        }
      }
    }
    cout << (ok ? "OK" : "NA") << endl;
  }

  return 0;
}


Measured memory_bytes: 3096
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();

		int[] L = new int[N];

		for(int i = 0; i < N; i++) {
			L[i] = sc.nextInt();
		}

		int max = 0;

		for(int i = 0; i < N; i++) {
			if(max < L[i]) {
				max = L[i];
			}
		}

		int sum = 0;
		for(int i = 0; i < N; i++) {
			sum += L[i];
		}
		sum -= max;

		if(max < sum) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 22612
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
''' 
------------------------
author : iiou16
------------------------
'''

def main():
    N, M = list(map(int, input().split()))
    A = list(map(int, input().split()))

    ss = sum(A)
    if ss > N:
        print(-1)
    else:
        print(N - ss)


if __name__ == '__main__':
    main()

Measured memory_bytes: 10056
#include<stdio.h>
int main(void){
int W,H,x,y,r;
scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
if(x-r<0 || x+r>W || y-r<0 || y+r>H){
printf("No\n");
}if(x-r>=0 && x+r<=W){
 if(y-r>=0 && y+r<=H){
 printf("Yes\n");
 }
}
return 0;
}


Measured memory_bytes: 2104
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define pi 3.14159265359
#define all(i) i.begin(),i.end()
using namespace std;
const long long INF=1e9+7;
const string alp="abcdefghijklmnopqrstuvwxyz"; //26
const string ALP="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
//const ll MOD=998244353LL;
//const ll MOD=1777777777LL;


int main() {
  ll N;
  cin>>N;
  ll a[N];
  ll ans=0;
  rep(i,N) cin>>a[i];
  rep(i,N){
    if(i%2==0&&a[i]%2==1) ans++;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3600
using System;
using System.Text;
using System.Collections.Generic;
using System.Collections;
using static System.Math;
using System.Linq;
using static System.Array;

namespace ConsoleApp2
{
    class Program
    {
        static int N;
        static long mod = 1000000007;
        static char[] az = Enumerable.Range('a', 'z' - 'a' + 1).Select(i => (Char)i).ToArray();
        static void Main(string[] args)
        {
            N = int.Parse(Console.ReadLine());
            //R = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
            //var S = Console.ReadLine();

            Solve(1, new List<char>(),1);
        }

        static void Solve(int count,List<char> tmp,int avail)
        {
            if(N < count)
            {
                Console.WriteLine(String.Join("", tmp));
            }
            else
            {
                for (int i = 0; i < avail && i < 26; i++)
                {
                    var tmp2 = new List<char>(tmp);
                    tmp2.Add(az[i]);
                    Solve(count + 1, tmp2, Max(i + 2, avail));
                }
            }
        }


    }
}


Measured memory_bytes: 46512
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

use std::collections::VecDeque;
use std::cmp::max;
fn main() {
    input!{
        h: usize,
        w: usize,
        s: [chars;h],
    }
    // println!("{:?}", s);
    let mut ans = 1;
    for i in 0..h {
        for j in 0..w {
            if s[i][j] == '#' {
                continue;
            }
            let mut s = s.clone(); // table
            let mut q = VecDeque::new(); // queue
            s[i][j] = '#';
            q.push_back((i,j,0)); // これなに
            while let Some((i,j,d)) = q.pop_front() {
                ans = max(d, ans);
                let direction = if i==0 &&j==0 {
                    vec![(i+1, j), (i, j+1)]
                }else if i==0 {
                    vec![(i+1, j), (i, j+1), (i, j-1)]
                }else if j==0 {
                    vec![(i+1, j), (i-1, j), (i, j+1)]
                }else{
                    vec![(i+1, j), (i-1, j), (i, j+1), (i, j-1)]
                };
                for &(x,y) in direction.iter() {
                    if x < h && y < w && s[x][y]=='.' {
                        s[x][y] = '#';
                        q.push_back((x, y, d + 1));
                    }
                }
            }
        }
    }
    println!("{}", ans);
}

Measured memory_bytes: 4352
#include <stdio.h>
    
int main(void){
    int a,b;
    scanf("%d%d",&a,&b);
    if (a <= 5){
        printf("0");
    } else if (a <= 12){
        printf("%d",(b / 2));
    } else {
        printf("%d",b);
    }
    return 0;
}

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

s_list = []
t_list = []
for _ in range(N):
    s, t = input().split()
    s_list.append(s)
    t_list.append(int(t))

X = input()


idx = s_list.index(X)
ans = sum(t_list[idx+1:])
print(ans)



Measured memory_bytes: 38384
#include <iostream>

using namespace std;

int main()
{
	int ans;
	string s;
	char m;

	m = 'a';
	cin >> s;

	ans = -1;

	for (int i = 0; i < s.size(); i++){
		if (s[i] != m){
			ans++;
			m = s[i];
		}
	}
	cout << ans << endl;
	return (0);
}


Measured memory_bytes: 512
#include<stdio.h>
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
struct pr{
	ll x,y;
	pr(ll a,ll b){
		ll g=gcd(a,b);
		x=a/g;
		y=b/g;
	}
};
pr operator-(pr a,pr b){
	if(a.x*b.y<a.y*b.x)return pr(-1,1);
	return pr(a.x*b.y-a.y*b.x,a.y*b.y);
};
int main(){
	ll n,i,j;
	pr t(0,1);
	scanf("%lld",&n);
	for(i=1;i<=3500;i++){
		for(j=1;j<=3500;j++){
			t=pr(4,n)-pr(1,i)-pr(1,j);
			if(t.x==1){
				printf("%lld %lld %lld\n",i,j,t.y);
				return 0;
			}
		}
	}
}

Measured memory_bytes: 128
N, K = map(int, input().split())
S = [input().split() for _ in range(K*2)]
new_list = []
for i in range(5):
    S.append([])
S.append([])
for i in range(1,len(S)-2,2):
    for j in S[i]:
        new_list.append(j)

new_list = set(new_list)
print(N - len(new_list))


Measured memory_bytes: 9352
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        
        int x;
        int y;
  
  while(true){
    x = sc.nextInt();
    y = sc.nextInt();
    if ( x == 0 && y == 0 ) break;  

  
        if(x<y){
             System.out.println(x + " " + y);
        }else{
             System.out.println(y + " " + x);
        }
    }
    }
}



Measured memory_bytes: 35772
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod=1e18+1;
ll a[150];
ll gcd(ll a,ll b)
{
	if(a%b==0) return b;
	else return gcd(b,a%b);
}
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		cin>>a[i]; 
	}
//	cout<<mod<<endl;
	ll g;
	ll ans;
	g=a[0];
	ans=a[0];
	for(int i=1;i<n;i++)
	{
		g=gcd(ans,a[i]);
		ans=ans/g;
		ans=ans*a[i];
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <map>
#include <numeric>
#include <queue>
#include <sstream>
#include <string>
#include <string.h>
#include <tuple>
#include <vector>

#define REP(i,x) for(int i{ 0 }; i < (int)(x); i++)
#define REPC(i,x) for(int i{ 0 }; i <= (int)(x); i++)
#define RREP(i,x) for(int i{ (int)(x) - 1 }; i >= 0 ;i--)
#define RREPC(i,x) for(int i{ (int)(x)}; i >= 0; i--)
#define REP1O(i,x) for(int i{ 1 }; i < (int)(x); i++)
#define REP1C(i,x) for(int i{ 1 }; i <= (int)(x); i++)

#define PB push_back
#define MP make_pair
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

using namespace std;

typedef int64_t ll;
typedef double dbl;
typedef vector<bool> Vb;
typedef vector<char> Vc;
typedef vector<double> Vd;
typedef vector<int> Vi;
typedef vector<ll> Vl;
typedef vector<string> Vs;
typedef vector<vector<int>> VVi;
typedef vector<vector<ll>> VVl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;

template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
inline void swap(ll& a, ll& b) { a ^= b; b ^= a; a ^= b; }
inline void swap(int& a, int& b) { a ^= b; b ^= a; a ^= b; }
inline void YES() { cout << "YES" << endl; } inline void Yes() { cout << "Yes" << endl; }
inline void NO() { cout << "NO" << endl; } inline void No() { cout << "No" << endl; }

const int inf = 1 << 30;
const ll linf = 1LL << 60;
const int MOD = 1000000007;

string s;
int n;
Vi rightRL, leftRL;
Vi ans;

void init()
{
	cin >> s; n = SZ(s);
	rightRL.resize(n, n);
	leftRL.resize(n, -1);
	ans.resize(n, 0);

	for(int i = n - 2; i >= 0; --i)
	{
		if (s[i] == 'R' && s[i + 1] == 'L')
			rightRL[i] = i;
		else
			rightRL[i] = rightRL[i + 1];
	}

	for (int i = 1; i <= n - 1; ++i)
	{
		if (s[i - 1] == 'R' && s[i] == 'L')
			leftRL[i] = i;
		else
			leftRL[i] = leftRL[i - 1];
	}
}


int main()
{
	init();

	REP(i, n)
	{
		if (s[i] == 'R')
		{
			if (1 & rightRL[i] - i)
				++ans[rightRL[i] + 1];
			else
				++ans[rightRL[i]];
		}

		else
		{
			if (1 & i - leftRL[i])
				++ans[leftRL[i] - 1];
			else
				++ans[leftRL[i]];
		}
	}

	REP(i, n)
		cout << ans[i] << " ";
	cout << endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <math.h>
#include <bitset>
#include <cmath>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i,s,n)for(int i = s;i<n;i++)
#define repe(i,s,n)for(ll i = s;i<=n;i++)
#define rep_r(i,s,n)for(ll i = n-1;i>s;i--)
#define rep_re(i,s,n)for(ll i = n-1;i>=s;i--)
ll MOD = 1e9 + 7;

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

	if (s[0] == s[1] && s[1] == s[2]){
		cout << "No" << endl;
}
	else {
		cout << "Yes" << endl;
	}

	return 0;
}


Measured memory_bytes: 256
//神题
//分析性质+k进制数位DP
#include<cstdio>
#include<cstring>
#include<algorithm>
#define mod 1000000007
#define N 4010
using namespace std;
int n, m, K, f[N][N], x1, x2, ans, top;
int main(){
	scanf("%d%d%d", &n, &m, &K);
	x1=n%(K-1); x2=(m-1)%(K-1);
	memset(f, 0, sizeof(f)); f[0][0]=1; ans=0;
	for(int i=1; i<=(n+m-1)/(K-1); i++){
		top=i*(K-1);
		for(int j=0; j<=top; j++)
			for(int k=0; k<=min(K-1, j); k++)f[i][j]=(f[i][j]+f[i-1][j-k])%mod;
		for(int j=0; j<=top; j++)if(j<=n&&j%(K-1)==x1&&(top-j)<=m-1&&(top-j)%(K-1)==x2){
			ans=(ans+f[i][j])%mod;
			ans=(ans-f[i-1][j]+mod)%mod;
		}
	}
	printf("%d", ans);
	return 0;
}

Measured memory_bytes: 63104
#include "bits/stdc++.h"
#define rep(i,b) for(ll i=0;i<b;i++)
#define ll long long
using namespace std;
/*--Input//////////////////////////////////////////////////*/
inline void IN(void){return;}
template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){cin >> first;IN(rest...);return;}
#define SS(T, ...)      T __VA_ARGS__; IN(__VA_ARGS__);
#define SV(type,c,n) vector<type> c(n);for(auto& i:c)cin >> i;
/*--Output/////////////////////////////////////////////////*/
inline int p(void){cout << endl; return 0;}
template<class Head> int p(Head&& head){cout << head;p();return 0;} template<class Head,class... Tail> int p(Head&& head,Tail&&... tail){cout<<head<<" ";p(forward<Tail>(tail)...);return 0;}
struct ProconInit {
    static constexpr bool AUTOFLUSH = false;
    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(15);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vvvl vector<vector<vector<ll>>>
#define debug(x) cerr<<#x<<" "<<x<<'\n';
#define all(x) (x).begin(),(x).end()
#define bit(n) (1LL<<(n))
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; }
bool cmp(pair<ll,ll> a, pair<ll,ll> b) { return a.first+a.second > b.first+b.second; }

int main() {
    SS(ll,n);
    map<ll, bool> mp;
 
    rep(i, n) {
        SS(ll,tmp);
        if(mp[tmp] == 0)
            mp[tmp] = 1;
        else
            mp.erase(tmp);
    }
    p(mp.size());
}

Measured memory_bytes: 6528
import Data.List(sort)
import Data.List(groupBy)

main = do
  s <- getLine
  let n = (read :: String -> Int) s
  ss <- getContents
--       "1 1 3 8\n3 2 2 7\n4 3 8 1\n"
  let tra = map (map (read::(String->Int)) . words ) . lines $ ss
--      [[1,1,3,8],[3,2,2,7],[4,3,8,1]]
  let rst = aux (tra ++ kuu)
  putStr $  fmt rst [4,3,10]
  where
    kuu = [[b,f,r,0]|b<-[1..4],f<-[1..3],r<-[1..10]]

aux :: [[Int]] -> [[Int]]
aux lst =gat $ grp $ lst

grp :: [[Int]] ->[[[Int]]]   
grp lst = groupBy (\a b->(init a) == (init b)) $ sort lst

gat :: [[[Int]]] -> [[Int]]
gat v= map (\z->(init.head $ z) ++ [sum $ map (last) z]) v

--        [[1,1,1,0],[1,1,2,1],[1,1,2,2],[1,1,3,0]]
-- grp -> [[[1,1,1,0]],[[1,1,2,1],[1,1,2,2]],[[1,1,3,0]]]
-- gat -> [[1,1,1,0]],[1,1,2,3],[1,1,3,0]]

-- fmt [[1,1,1,0],[1,1,2,3],[1,1,3,0]] [4,3,10]
fmt :: [[Int]]->[Int]->String
fmt [] _ = ""
fmt (x:xs) [nb,nf,nr] =
   " " ++ (show (last x))
  ++ (if (x!!2) ==nr then "\n" else "")
  ++ (if (x!!2) ==nr && (x!!1) ==nf && (x!!0) /=nb then (concat $ replicate (2*nr) "#")++"\n" else "")
  ++ (fmt xs [nb,nf,nr] )

Measured memory_bytes: 4260
N = int(input())
Nminus1 = N - 1
# lines = []

CSF = []
# S = [0 for _ in range(Nminus1)]
# F = [0 for _ in range(Nminus1)]

for i in range(Nminus1):
    c, s, f = input().split()
    CSF.append((int(c), int(s), int(f)))
    # C[i] = int(c)
    # S[i] = int(s)
    # F[i] = int(f)

# for line in lines:
#     c, s, f = line.split()
#     C.append(int(c))
#     S.append(int(s))
#     F.append(int(f))

ans = []

for i in range(Nminus1):
    a = 0
    for j in range(i, Nminus1):
        C, S, F = CSF[j]
        if a <= S:
            n = S - a
        else:
            mod = a % F 
            n = F - mod if mod != 0 else 0
        a = a + C + n
    ans.append(a)

ans.append(0)
print('\n'.join(map(str, ans)))

Measured memory_bytes: 3064
#include<stdio.h>

int main()
{
	double height,highest,lowest,diff;
	
	scanf("%lf",&height);
	highest=height;
	lowest=height;

	while(scanf("%lf",&height)!=EOF)
	{
		if(height>highest)
		{
			highest=height;
		}
		else if(height<lowest)
		{
			lowest=height;
		}
	}
	
	diff=highest-lowest;
	printf("%lf\n",diff);
	return 0;
}

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

int main(){
    int n, l;
    string tmp[110];
    cin >> n >> l;

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

    sort(tmp, tmp+n);

    for(int i = 0;i < n;i++){
        cout << tmp[i];
    }

    cout << endl;
    return 0;
}

Measured memory_bytes: 256
lines = []
while line = gets
    lines << line.chomp.split(' ').map(&:to_i)
end

N = lines[0][0]

current_max = 0
ans = 0
for i in 1..N do
  if lines[1][i-1] < current_max then
    ans += current_max - lines[1][i-1]
  else
    current_max = lines[1][i-1]
  end
end
  
puts ans

Measured memory_bytes: 30324
import sys
input = sys.stdin.buffer.readline

class UnionFind:
    __slots__ = ["data"]
    
    def __init__(self, n=0):
        self.data = [-1]*(n+1)
    
    def root(self, x):
        if self.data[x] < 0:
            return x
        self.data[x] = self.root(self.data[x])
        return self.data[x]
    
    def unite(self, x, y):
        x = self.root(x)
        y = self.root(y)
        if x != y:
            if self.data[x] < self.data[y]:
                self.data[x] += self.data[y]
                self.data[y] = x
            else:
                self.data[y] += self.data[x]
                self.data[x] = y
    
    def same(self, x, y):
        return self.root(x) == self.root(y)
    
    def size(self, x):
        return -self.data[self.root(x)]
                


def main():
    n, m, k = map(int, input().split())
    friends = [0]*(n+1)
    blocks = [[] for _ in range(n+1)]
    uf = UnionFind(n)
    for _ in range(m):
        a, b = map(int, input().split())
        friends[a] += 1
        friends[b] += 1
        uf.unite(a, b)
    for _ in range(k):
        c, d = map(int, input().split())
        blocks[c].append(d)
        blocks[d].append(c)
    for i in range(1, n+1):
        nf = friends[i]
        nb = 0
        for b in blocks[i]:
            if uf.same(i, b):
                nb += 1
        ans = uf.size(i) - 1 - nf - nb
        print(ans)


if __name__ == "__main__":
    main()

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

int main() {
  int n, m, t, p;
  while (cin >> n >> m >> t >> p, n) {
    vector<pair<int, int>> d(t), x(p);
    for (auto &e : d) cin >> e.first >> e.second;
    for (auto &e : x) cin >> e.first >> e.second;

    vector<vector<int>> a((t + 1) * m, vector<int>((t + 1) * n));
    for (int i = 0; i < m; i++) {
      for (int j = 0; j < n; j++) {
        a[i][j] = 1;
      }
    }
    int x0 = 0, y0 = 0;
    for (auto e : d) {
      if (e.first == 1) {
        x0 += e.second;
        for (int i = 0; a[y0 + i][x0]; i++) {
          for (int j = 0; x0 - j - 1 >= 0 && (a[y0 + i][x0 + j] || a[y0 + i][x0 - j - 1]); j++) {
            a[y0 + i][x0 + j] += a[y0 + i][x0 - j - 1];
            a[y0 + i][x0 - j - 1] = 0;
          }
        }
      } else {
        y0 += e.second;
        for (int j = 0; a[y0][x0 + j]; j++) {
          for (int i = 0; y0 - i - 1 >= 0 && (a[y0 + i][x0 + j] || a[y0 - i - 1][x0 + j]); i++) {
            a[y0 + i][x0 + j] += a[y0 - i - 1][x0 + j];
            a[y0 - i - 1][x0 + j] = 0;
          }
        }
      }
    }

    for (auto e : x) {
      cout << a[y0 + e.second][x0 + e.first] << endl;
    }
  }
}



Measured memory_bytes: 3916
#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(){
    int A, B;
    cin>>A>>B;

    int ans=-1;
    rep(i, 1001){
        if(i==0) continue;
        if(floor(i*(0.08))==A && floor(i*(0.1))==B){
            ans=i;
            break;
        }
    }

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

Measured memory_bytes: 3596
import java.util.*

fun main(args: Array<String>) {
    val scn = Scanner(System.`in`)
    val A = scn.nextInt()
    val B = scn.nextInt()

    for(i in 1..10000){
        if((i*0.08).toInt()==A && (i*0.10).toInt()==B){
            println(i)
            return
        }
    }

    println(-1)
}

Measured memory_bytes: 31396
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int[] arr = new int[n];
        int count = 0;
        for(int i = 0; i < n; i++) {
            arr[i] = sc.nextInt();
        }
        for(int j = 0; j < n; j++) {
            if(arr[j] >= k) {
                count++;
            }
        }
        System.out.println(count);
    }
}


Measured memory_bytes: 50568
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll (i) = 0; (i) < (n); (i)++)
#define rep1(i, n) for(ll (i) = 1; (i) <= (n); (i)++)
#define rrep(i, n) for(ll (i) = (n) - 1; (i) >= 0; (i)--)
#define rrep1(i, n) for(ll (i) = (n); (i) >= 1; (i)--)
const ll INF = 1145141919;
const ll MOD = 1000000007;
template<class T> void chmax(T &a, const T &b){if(a < b){a = b;}}
template<class T> void chmin(T &a, const T &b){if(a > b){a = b;}}

int main(){

    ll N;
    cin >> N;
    string s(N, '0');
    rep(i, N)cin >> s[i];
    for(ll i = 0;; i++){
        if(s.find(to_string(i)) == string::npos){
            cout << i << endl;
            break;
        }
    }

    return 0;
}


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



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

     int n,a,b;
     cin>>n>>a>>b;
     if(n*a<b)
     {
         cout<<(n*a)<<endl;
     }
     else
        cout<<b<<endl;
     return 0;


}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,a,b) for(int i=(a);i<(b);++i)

template<class T> inline void chmin(T& a, T b) {if (a > b) a = b;}
template<class T> inline void chmax(T& a, T b) {if (a < b) a = b;}

//vector出力
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){
  o<<"{";
  for(int i=0;i<(int)v.size();i++) o << (i>0?", ":"") << v[i];
  o<<"}";
  return o;
}




int main() {
  int K;
  string S;
  cin >> K >> S;
  if (S.size()<=K) cout << S;
  else cout << S.substr(0,K)+"...";
  cout << endl;
}

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

using namespace std;

int main(void)
{
  	int K = 0;
    cin >> K;
  
	string S;
  	cin >> S;

  	if (S.size() <= K) {
  		cout << S << endl;
    }
  	else {
      string S2;
      for (int i = 0; i < K; i++) {
    	S2 += S[i];
      }
      S2 += "...";
      cout << S2 << endl;
    }
}

Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define inf (int)1e9+7
#define eb emplace_back
#define eps 1e-10

/*
 a b c d e
 一例
 a - b
 (a - b) - c
 d - ((a - b) - c)
 (d - ((a - b) - c)) - e = - a + b - c + d - e
 
 1. 途中によらず符号を割振れる?
 
 all +, all -は不可
 a - bつくった
 以降a, bの符号は逆であり続ける
 
 a1 ≤ a2 ≤ ... ≤ an
 -               +
 あとは正のやつ+、負のやつ-にする
 
 2. 実装
 a + b + c + d + e - f - g - h (符号を除くと正)
 +                           -
 
 基本的に後ろに引いていく方針
 前の全体を符号変えたくない
 
 a - (- g)
 (a - (- g)) - (- f)
 
 - h - b
 (- h - b) - c
 ((- h - b) - c) - d
 (((- h - b) - c) - d) - e
 
 ((a - (- g)) - (- f)) - ((((- h - b) - c) - d) - e)
 = a + b + ... + g + h
 
 
 */
int main() {
    cin.tie(0); ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<int> plus;
    vector<int> minus;
    rep(i, n) {
        int tmp; cin >> tmp;
        if (tmp >= 0) plus.eb(tmp);
        else minus.eb(tmp);
    }
    sort(plus.begin(), plus.end());
    sort(minus.begin(), minus.end());
    int ans = 0;
    if (plus.size() == 0) {
        ans += minus[minus.size() - 1];
        rep(i, minus.size() - 1) {
            ans -= minus[i];
        }
    } else if (minus.size() == 0) {
        ans -= plus[0];
        rrep(i, 1, plus.size()) {
            ans += plus[i];
        }
    } else {
        rep(i, plus.size()) {
            ans += plus[i];
        }
        rep(i, minus.size()) {
            ans -= minus[i];
        }
    }
    cout << ans << endl;
    //rep(i, minus.size()) cout << minus[i] << " "; cout << endl;
    //rep(i, plus.size()) cout << plus[i] << " "; cout << endl;
    int l, s;
    if (minus.size() == 0) {
        l = plus[plus.size() - 1];
        s = plus[0];
        rrep(i, 1, plus.size() - 1) {
            cout << s << " " << plus[i] << endl;
            s -= plus[i];
        }
        cout << l << " " << s << endl;
        return 0;
    } else if (plus.size() == 0) {
        l = minus[minus.size() - 1];
        s = minus[0];
        rrep(i, 1, minus.size() - 1) {
            cout << l << " " << minus[i] << endl;
            l -= minus[i];
        }
        cout << l << " " << s << endl;
        return 0;
    }
    l = plus[plus.size() - 1];
    s = minus[0];
    rrep(i, 1, minus.size()) {
        cout << l << " " << minus[i] << endl;
        l -= minus[i];
    }
    rep(i, plus.size() - 1) {
        cout << s << " " << plus[i] << endl;
        s -= plus[i];
    }
    cout << l << " " << s << endl;
}



Measured memory_bytes: 2424
from collections import defaultdict
from collections import deque
N = int(input())
# A_i,j = A[i-1][j-1]
A = [list(map(int,input().split(' '))) for i in [0]*N]

dic = defaultdict(int)
ns = [0] * N

ls = range(1,N+1)
ans = 0
while(True):
	new_ls = set([])
	for i in ls:
		if ns[i-1] >= N-1:
			continue
		j = A[i-1][ns[i-1]]
		dic[(i*j,i+j)] += 1
		if dic[(i*j,i+j)] == 2:
			new_ls.add(i)
			new_ls.add(j)
	if not new_ls:
		break
	for ind in new_ls:
		ns[ind-1] += 1
	ls = new_ls
	ans += 1

for i in range(N):
	if ns[i] != N-1:
		print(-1)
		exit()
print(ans)








Measured memory_bytes: 129500
#include <bits/stdc++.h>
using namespace std;
#define INF 2e9
#define ll long long


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

    if((a-b)<=c){
        cout<<c-(a-b)<<endl;
    }
    else{
        cout<<"0"<<endl;
    }



    return 0;
}

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

using namespace std;

int dp[101][1 << 16];

int main()
{
  int N;
  while(cin >> N, N){
    int L[101];
    int mask[101] = {0};
    for(int i = 0; i < N; i++){
      int M;
      cin >> M >> L[i];
      for(int j = 0; j < M; j++){
	int S, E;
	cin >> S >> E;
	S -= 6; E -= 6;
	for(int k = S; k < E; k++) mask[i] |= (1 << k);
      }
    }
    memset(dp, 0, sizeof(dp));
    for(int bit = 0; bit < (1 << 16); bit++){
      if(bit & mask[0]) continue;
      dp[0][bit | mask[0]] = L[0];
    }
    for(int i = 1; i < N; i++){
      for(int bit = 0; bit < (1 << 16); bit++){
	dp[i][bit] = max(dp[i][bit], dp[i-1][bit]);
	if(bit & mask[i]) continue;
	dp[i][bit | mask[i]] = max(dp[i][bit | mask[i]], dp[i-1][bit] + L[i]);
      }
    }
    cout << *max_element(dp[N-1], dp[N-1] + (1 << 16)) << endl;
  }
  return 0;
}

Measured memory_bytes: 27024
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val e = (1..n-1).map { readLine()!!.split(" ").map { it.toInt() } }
    val ans = IntArray(n+1){0}
    val visit = BooleanArray(n+1){false}
    val g = readGraph(n,e)
    dfs(1,g,visit,ans,0)
    println( ans.drop(1).map { if(it%2==0) 0 else 1 }.joinToString("\n") )
}

fun dfs (v:Int, g:List<List<Int>>, visit: BooleanArray, ans: IntArray, len: Int){
    ans[v] = len
    g[v].forEach {
        val u = Math.abs(it)
        if(visit[u]) return@forEach
        visit[u] = true
        dfs(u, g, visit, ans, len + if(it<0) 1 else 0)
        visit[u] = false
    }
}

fun readGraph(n: Int, e: List<List<Int>>): List<List<Int>> {
    val adj = Array(n+1) { mutableListOf<Int>() }
    e.forEach {
        val (u,v,w) = it
        adj[u].add(if(w%2==0) v else -v)
        adj[v].add(if(w%2==0) u else -u)
    }
    return adj.map { it.toList() }
}

Measured memory_bytes: 99568
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <map>
#include <utility>
#include <set>
#include <climits>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

int press(int& a, int& b) {
    int coin;
    if (a > b) {
        coin = a;
        --a;
    } else {
        coin = b;
        --b;
    }
    return coin;
}

int main() {
    int a, b;
    scanf ("%d %d", &a, &b);
    int total = 0;
    total += press(a, b);
    total += press(a, b);
    printf("%d\n", total);
    return 0;
}



Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
#define repl(i, l, r) for (int i = l; i < r; i++)
#define rep(i, n) repl(i, 0, n)
const ll MOD = 1000000007;
int main() {
	int n, q;
	string s;
	cin >> n >> q >> s;
	vector<int> a(n + 1);
	rep(i, n - 1) {
		if (s[i] == 'A' and s[i + 1] == 'C') a[i + 1] = 1;
	}
	rep(i, n) a[i + 1] += a[i];
	while (q--) {
		int l, r;
		cin >> l >> r;
		cout << a[r - 1] - a[l - 1] << endl;
	}
	return 0;
}

Measured memory_bytes: 1408
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter,defaultdict
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)
# INF =  float("inf")
INF = 10**18
import bisect
import statistics
mod = 10**9+7
# mod = 998244353

N = int(input())
S = input()

if N % 2 == 0:
    if S[:N//2] == S[N//2:]:
        print("Yes")
    else:
        print("No")
else:
    print("No")

Measured memory_bytes: 77512
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<assert.h>

#define max(a,b) ((a)>(b))?(a):(b)
#define min(a,b) ((a)>(b))?(b):(a)

typedef long long ll;
typedef unsigned long long ull;

int gcd(int a, int b) {
    static int note[201][201] = { 0 };
    if (a % b)
    {
        if (note[a][b] || note[b][a])
        {
            return note[a][b];
        }
        int r = gcd(b, a % b);
        note[a][b] = note[b][a] = r;
        return r;
    }
    return b;
}

int main(void)
{
    int k, sum = 0;
    scanf("%d", &k);
    for (size_t i = 1; i <= k; i++)
    {
        for (size_t j = 1; j <= k; j++)
        {
            for (size_t l = 1; l <= k; l++)
            {
                sum += gcd(gcd(j, l),i);
            }
        }
    }
    printf("%d", sum);
}

Measured memory_bytes: 1860
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

struct P {
    bool operator<(const P& p) const {
        return a + b > p.a + p.b;
    }
    int a, b;
};

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

    int n;
    cin >> n;

    vector<P> p(n);
    for (int i = 0; i < n; i++) {
        cin >> p[i].a >> p[i].b;
    }
    sort(p.begin(), p.end());

    ll r = 0;
    for (int i = 0; i < n; i++) {
        r += i % 2 == 0 ? p[i].a : -p[i].b;
    }

    cout << r << endl;

    return 0;
}

Measured memory_bytes: 1024
N = gets.to_i
MOD = 10 ** 9 + 7

class ModCombination
  attr_reader :fac, :inv, :finv, :mod

  MOD = 10 ** 9 + 7

  def initialize(n, mod: MOD)
    @mod = mod
    @fac = [1, 1]
    @inv = [1, 1]
    @finv = [1, 1]

    (2..n).each do |i|
      @fac[i] = fac[i - 1] * i % mod
      @inv[i] = mod - inv[mod % i] * (mod / i) % mod
      @finv[i] = finv[i - 1] * inv[i] % mod
    end
  end

  def combination(n, k)
    return 0 if n < k
    return 0 if n < 0 || k < 0
    fac[n] * (finv[k] * finv[n - k] % mod) % mod
  end
end

A = gets.split.map(&:to_i)
counter = Hash.new
l = r = -1

mc = ModCombination.new(N + 1)

A.each_with_index do |a, i|
  if counter[a]
    l = counter[a]
    r = i
    break
  else
    counter[a] = i
  end
end

1.upto(N + 1) do |k|
  puts (mc.combination(N + 1, k) - mc.combination(l + N - r, k - 1)) % MOD
end


Measured memory_bytes: 20460
#include<bits/stdc++.h>
using namespace std;
/*#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
/*template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
*/typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> pl;
typedef pair<int,int> pii;

#define LOCAL 0
#define dbg(x) cout << #x << " is " << x << "\n"
#define gll(x) scanf("%d",&x)
#define gll2(x,y) scanf("%d%d",&x,&y)
#define gll3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define gllarr(arr,n) f(i,n) gll(arr[i]);
#define sz(x) ((int)x.size())
#define s(x) sort(x.begin(),x.end())
#define all(v) v.begin(),v.end()
#define rs(v) { s(v) ; r(v) ; }
#define r(v) {reverse(all(v));}
#define pb push_back
#define f(i,n) for(int i=0;i<n;i++)
#define fr(i,n) for(int i=n-1;i>=0;i--)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)

const ll mod = (ll)1e9 + 7;
const ll inf = (ll)1e16;
const ld eps = 1e-12;
const ll N = (int)1e5 + 5;
const ll LOGN = 19;
const ld PI = 3.14159265358979323846;
inline ll mul(ll a, ll b, ll m = mod) { return (ll)(a * b) % m;}
inline ll add(ll a, ll b, ll m = mod) { a += b; if(a >= m) a -= m; if(a < 0) a += m; return a;}
inline ll power(ll a, ll b, ll m = mod) { if(b == 0) return 1; if(b == 1) return (a % m); ll x = power(a, b / 2, m); x = mul(x, x, m); if(b % 2) x = mul(x, a, m); return x;}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    if (LOCAL) {
        freopen("C:\\Users\\Dishant\\Desktop\\Collection-DEV c++\\input.txt", "r", stdin);
        freopen("C:\\Users\\Dishant\\Desktop\\Collection-DEV c++\\output.txt", "w", stdout);
    }
    int n, k;
    cin>>n>>k;
    cout<<n - k + 1;
    return 0;
}

Measured memory_bytes: 256