akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <climits>
#include <cmath>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
using namespace std;

const int MAX = 100001;
const int MOD = 1000000007;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;

int ceil(int x, int y) { return (x % y == 0) ? x / y : x / y + 1; }

int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }

int lcm(int x, int y) { return x / gcd(x, y) * y; }

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

  int k, x;
  cin >> k >> x;

  if (500 * k >= x)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep1(i,n) for(int i=1; i<=(n); ++i)
#define repi(i,a,b) for(int i=a; i<=(b); ++i)
#define rrep(i,n) for(int i=(n-1); i>=0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define pb push_back
#define mp make_pair
#define to_s to_string
#define sz(v) (int)v.size()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define pr(x) cout<<(x)<<'\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
#define yes "Yes"
#define no "No"
using ll = long long;
using namespace std;
typedef pair<int,int> P;
struct aaa{aaa(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}aaaaaaa;
int MOD = 1e9 + 7;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return (a*b)/gcd(a,b);}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int N;
int main(){
    cin >> N;
    vector<int> h(N);
    rep(i,N) cin >> h[i];
    int dp[N+3];
    dp[0] = 0, dp[1] = abs(h[1]-h[0]);
    rep(i,N) dp[i+2] = min(dp[i]+abs(h[i+2]-h[i]),dp[i+1]+abs(h[i+2]-h[i+1]));
    pr(dp[N-1]);
}

Measured memory_bytes: 1024
a = 3.times.map{ gets.split.map(&:to_i) }.flatten
n = gets.to_i
n.times do
  b = gets.to_i
  i = a.index(b)
  a[i] = 0 if !i.nil?
end
ok = false
ok = true if a[0] + a[1] + a[2] == 0
ok = true if a[3] + a[4] + a[5] == 0
ok = true if a[6] + a[7] + a[8] == 0
ok = true if a[0] + a[3] + a[6] == 0
ok = true if a[1] + a[4] + a[7] == 0
ok = true if a[2] + a[5] + a[8] == 0
ok = true if a[0] + a[4] + a[8] == 0
ok = true if a[2] + a[4] + a[6] == 0
puts (ok) ? "Yes" : "No"


Measured memory_bytes: 1788
#include <cstdio>
#include <vector>
#include <algorithm>
#include <queue>
#include <cstring>
using namespace std;

typedef vector<int> vint;

int h, w, c, ans;
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, 1, 0, -1};

vint bfs(const vector<vint> &p){
	vint ret;
	bool visit[10][10] = {};
	queue<int> q;
	q.push(1 << 8 | 1);
	visit[1][1] = true;

	int clr = p[1][1];

	while(!q.empty()){
		ret.push_back(q.front());
		int y = q.front() >> 8;
		int x = q.front() & 0xff;
		q.pop();

		for(int i = 0; i < 4; ++i){
			int ny = y + dy[i], nx = x + dx[i];
			if(!visit[ny][nx] && p[ny][nx] == clr){
				visit[ny][nx] = true;
				q.push(ny << 8 | nx);
			}
		}
	}
	return ret;
}


void recur(int k, vector<vint> &p){
	vint con = bfs(p);

	if(k == 0){
		ans = max<int>(ans, con.size());
	}
	else{
		int lt = 1, rt = 6;
		if(k == 1){ lt = rt = c; }

		vector<vint> q = p;
		for(int i = lt; i <= rt; ++i){
			for(int j = 0; j < con.size(); ++j){
				q[con[j] >> 8][con[j] & 0xff] = i;
			}
			recur(k - 1, q);
		}
	}
}

int main(){
	while(scanf("%d%d%d", &h, &w, &c), h){
		ans = 0;

		vector<vint> p(h + 2, vint(w + 2, -1));
		for(int i = 1; i <= h; ++i)
		for(int j = 1; j <= w; ++j){
			scanf("%d", &p[i][j]);
		}

		recur(5, p);
		printf("%d\n", ans);
	}
}

Measured memory_bytes: 1060
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> h(n);
    rep(i, 0, n){
        cin >> h[i];
    } 
    int ans = 1;
    rep(i, 1, n){
        bool f = true;
        rep(j, 0, i){
            if(h[j] > h[i]) f = false;
        }
        if(f) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define ll long long
#define rep(i,l,r) for(ll i=(l);i<(r);i++)
#define max(p,q) ((p)>(q)?(p):(q))
#define min(p,q) ((p)<(q)?(p):(q))
#define abs(p) ((p)>=(0)?(p):(-(p)))
int cmp(const void *a, const void *b);
int main(void){
    ll N, K, a=0, A[10];
    scanf("%lld %lld", &N, &K);
    rep(i, 0, N) scanf("%lld", A);
    while(N>0){
        if(a==0){
            N-=K;
            a++;
        }
        else{
            N-=K-1;
            a++;
        }
    }
    printf("%lld\n", a);
    return 0;
}
int cmp(const void *a, const void *b){
    ll A=*(ll *)a, B=*(ll *)b;
    if(A==B)return 0;
    else return A>B ? 1:-1;//昇順ソート
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
//const int N = 1000000;
const ll mod = 1000000007;
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
  
ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * (B / gcd(A, B));
}
  
/*------------------------------------------------------------------*/
int main(){
    ll x, y; cin >> x >> y;
    ll count = 1;
    while(true){
        x *= 2;
        if(x > y){
            cout << count << endl;
            return 0;
        }
        count++;
    }
}

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

int main()
{
    string s;
    ll k;
    cin >> s;
    cin >> k;
    int one = 0;
    rep(i, s.size()) {
        if(s[i] != '1') {
            one = i;
            break;
        }
    }
    one++;
    if(one <= k) cout << s[one - 1] << endl;
    else cout << 1 << endl;
    return 0;
}


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

int main() {
  int A,B,C ;
  cin >> A >> B >> C ;
  if (A==B && A!=C)
    cout << "Yes" << endl ;
  else if (B==C && B!=A)
    cout << "Yes" << endl ;
  else if (C==A && C!=B)
    cout << "Yes" << endl ;
  else 
    cout << "No" << endl ;
}


Measured memory_bytes: 256
n, k = list(map(int, input().split()))
trees = []

for _ in range(n):
	h = int(input())
	trees.append(h)

trees.sort()
subs = []
for i in range(n - k + 1):
	subs.append(trees[i + k - 1] - trees[i])

print(min(subs))

Measured memory_bytes: 11292
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<set>
#include<string>
#include<bitset>
#include<queue>
#include<map>
using namespace std;

vector<int> factor(int mod_K) {
	vector<int> list(1000009);
	list[0] = 7%mod_K;
	for (int i = 1; i <= 1000000; i++) {
		list[i] = (10 * list[i - 1] + 7) % mod_K;
	}
	return list;
}

int main() {
	int K; 
	int ans = -1;
	cin >> K;
	vector<int> list;
	list = factor(K);
	for (int i = 0; i <= 1000000; i++) {
		if (list[i] == 0) {
			ans = i+1;
			break;
		}
	}

	cout << ans << endl;

	return 0;
}

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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())

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

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const long long INF = 1000000007;

#define CLR(a) memset((a), 0 ,sizeof(a))

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

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main(void){
    char c[3][3]; REP(i,3)REP(j,3) cin >> c[i][j];
    REP(i,3) cout << c[i][i];
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
    int A, B, all, field, road;
    //cout << "縦の長さを入力" << endl;
    cin >> A;
    //cout << "横の長さを入力" << endl;
    cin >> B;
    all = A * B; //全体の面積
    road = A * 1 + B * 1 - (1 * 1);
    field = all - road;
    cout << field << endl;
}

Measured memory_bytes: 256
//g++ -std=c++14 test.cpp -o test.out

#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <unordered_map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (1LL<<60);
const int INF_INT = 2147483647-1e6-1;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

//引用元
//http://drken1215.hatenablog.com/entry/2019/03/03/224600
//union くっつける
//find  どのグループか調べる
struct UnionFind {
    vector<LL> parent;
    
    UnionFind(LL n) : parent(n, -1) { }
    void init(LL n) { parent.assign(n, -1); }
    
    //xの属している木の根っこを返す
    LL root(LL x) {
        if (parent[x] < 0) return x;
        else return parent[x] = root(parent[x]);//経路圧縮
    }
    
    LL size(LL x) {return -parent[root(x)];}//xの属する木の要素数を求める
    bool is_same_tree(LL x,LL y) {return root(x)==root(y);}
    
    bool merge(LL x,LL y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (parent[x] > parent[y]) swap(x, y);//xの親の方がyの親より小さくなるようにする
        parent[x] += parent[y];//経路の長さを加算
        parent[y] = x;//yの親をxとする
        return true;
    }
};

LL N,M;
vector<LL> K;
vector<vector<LL>> L;

string ans = "YES";

void solve(){
	UnionFind uf(M);
	vector<int> used(M,0);//言語iが既に登場したかどうかをused[i]とする
	int lang_num = 0;//既に登場した言語の総数
	for(int i=0;i<N;i++){
		for(int j=0;j<K[i];j++){
			if(!used[L[i][j]]){
				used[L[i][j]] = 1;
				lang_num++;
			}
		}
	}

	for(int i=0;i<N;i++){
		for(int j=1;j<K[i];j++){
			uf.merge(L[i][j],L[i][j-1]);
		}
	}
	for(int i=0;i<M;i++){
		if(used[i]){
			if(uf.size(i)<lang_num) ans = "NO";
		}
	}
}

int main(){
    cin >> N >> M;
    K = vector<LL>(N);
    L = vector<vector<LL>>(N);
    for(int i=0;i<N;i++){
    	cin >> K[i];
    	for(int j=0;j<K[i];j++){
    		LL a;cin>>a;a--;
    		L[i].push_back(a);
    	}
    }

    solve();

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

Measured memory_bytes: 7680
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
 
namespace AtCoder_Beginner_Contest_129
{
    class Program
    {
        static public int[] Sarray() { return ReadLine().Split().Select(int.Parse).ToArray(); }
        static public List<int> Slist() { return ReadLine().Split().Select(int.Parse).ToList(); }
 
        static void Main(string[] args)
        {
            var NM = Sarray();
            var N = NM[0];
            var M = NM[1];
            var am = new int[N];
            for (var i = 0; i < M; ++i)
            {
                am[Sarray()[0] - 1] = 1;
            }
            var num = new long[N];
            if (N == 1)//1の場合
            {
                WriteLine(1);
                return;
            }
            if (0 == am[0]) num[0] = 1;
            if (0 == am[1]) num[1] = 1 + num[0];
            if (num[0] == 0 & num[1] == 0)
            {
                WriteLine(0);
                return;
            }
            for (var i = 2; i < N; ++i)
            {
                if (0 != am[i])
                { continue; }
                num[i] = (num[i - 1] + num[i - 2])%1000000007;
            }
            WriteLine(num[N - 1]);
        }
    }
}

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

long long s;
int a, b, c, d, t;

int main() {
	cin >> s;
	t = ceil(sqrt(s)-1e-6)+1e-6;
	a = b = t;
	c = 1;
	d = (long long)a*b - s;
	printf("0 0 %d %d %d %d", a, c, d, b);
}


Measured memory_bytes: 256
S = input()

ans = [0 for i in range(len(S))]
stage = 0 # 0:counting R, 1:counting L
R_count = 0
L_count = 0
RL_index = 0
for i in range(len(S)):
    s = S[i]
    if stage == 0:
        if s == "R":
            R_count += 1
        else:
            L_count += 1
            stage = 1
            RL_index = i-1
    elif stage == 1:
        if s == "L":
            L_count += 1
        else:
            stage = 0
            if (L_count + R_count) % 2 == 0:
                ans[RL_index] = (L_count+R_count)//2
                ans[RL_index+1] = (L_count+R_count)//2
            else:
                if R_count > L_count:
                    if R_count % 2 == 0:
                        ans[RL_index] = (L_count+R_count)//2
                        ans[RL_index+1] = (L_count+R_count)//2+1
                    else:
                        ans[RL_index] = (L_count+R_count)//2+1
                        ans[RL_index+1] = (L_count+R_count)//2
                else:
                    if L_count % 2 == 0:
                        ans[RL_index] = (L_count+R_count)//2+1
                        ans[RL_index+1] = (L_count+R_count)//2
                    else:
                        ans[RL_index] = (L_count+R_count)//2
                        ans[RL_index+1] = (L_count+R_count)//2+1

            R_count = 1
            L_count = 0
    # print("R_count : {}, L_count : {}".format(R_count, L_count))
if (L_count + R_count) % 2 == 0:
    ans[RL_index] = (L_count+R_count)//2
    ans[RL_index+1] = (L_count+R_count)//2
else:
    if R_count > L_count:
        if R_count % 2 == 0:
            ans[RL_index] = (L_count+R_count)//2
            ans[RL_index+1] = (L_count+R_count)//2+1
        else:
            ans[RL_index] = (L_count+R_count)//2+1
            ans[RL_index+1] = (L_count+R_count)//2
    else:
        if L_count % 2 == 0:
            ans[RL_index] = (L_count+R_count)//2+1
            ans[RL_index+1] = (L_count+R_count)//2
        else:
            ans[RL_index] = (L_count+R_count)//2
            ans[RL_index+1] = (L_count+R_count)//2+1

res = ""
for i in ans:
    res += str(i) + " "
print(res[:-1])


Measured memory_bytes: 4980
using System.Linq;
using System;

public class Hello
{
    public static int a, b;
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        string[] line = Console.ReadLine().Trim().Split(' ');
        a = int.Parse(line[0]);
        b = int.Parse(line[1]);
        line = Console.ReadLine().Trim().Split(' ');
        var p = Array.ConvertAll(line, int.Parse);
        var c = new int[3];
        for (int i = 0; i < n; i++) CLS(c, p[i]);
        Console.WriteLine(c.Min());
    }
    static void CLS(int[] c, int t)
    {
        if (t <= a) c[0]++;
        else if (t <= b) c[1]++;
        else c[2]++;
    }
}

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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

void init() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}

void solve() {
  int n, a, b; scanf("%d%d%d", &n, &a, &b);
  if (a > b) {
    printf("0");
    return;
  }
  if (n == 1 && a != b) {
    printf("0");
    return;
  }
  long long big = (long long)b*(n-1)+a, small = (long long)a*(n-1)+b;
  printf("%lld", big-small+1);
}

int main() {
  init();
  int t = 1; //scanf("%d", &t);
  while (t--) {
    solve();
  }
  return 0;
}


Measured memory_bytes: 3784
n=int(input())
a=[int(input()) for i in range(n)]
b=sorted(a)

if b[-1]==b[-2]:
    for i in range(n):
        print(b[-1])
else:
    for i in range(n):
        if a[i]==b[-1]:
            print(b[-2])
        else:
            print(b[-1])

Measured memory_bytes: 70360
using System;

namespace Battle
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);

            var result = WillTakahashiWin(input);

            Console.WriteLine(result);
        }

        private static string WillTakahashiWin(int[] input)
        {
            int takahashiHealth = input[0];
            int takahashiStrength = input[1];

            int aokiHealth = input[2];
            int aokiStrength = input[3];

            bool takaHashiTurn = true;

            while (takahashiHealth > 0 && aokiHealth > 0)
            {
                if (takaHashiTurn)
                {
                    aokiHealth -= takahashiStrength;
                }
                else
                {
                    takahashiHealth -= aokiStrength;
                }
                takaHashiTurn = !takaHashiTurn;
            }

            return takahashiHealth > 0 ? "Yes" : "No"; 
        }
    }
}

Measured memory_bytes: 27396
#pragma GCC optimize "O3"

#define F first
#define S second
#define ALL(x) x.begin(), x.end()

#include<bits/stdc++.h>

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;

constexpr int N = 2001 * 2001;

int n, s;
bitset<N> b;

int main() {
  scanf("%d", &n);
  b[0] = 1;
  for(int i = 0; i < n; ++i) {
    int x; scanf("%d", &x);
    s += x;
    b |= (b << x);
  }
  s = (s + 1) / 2;
  for(int x = s; ; ++x)
    if(b[x]) {
      printf("%d\n", x);
      return 0;
    }
}


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

using namespace std;

#define DEBUG

template <typename T1, typename T2>
inline std::ostream& operator << (std::ostream& os, const std::pair<T1, T2>& p)
{
    return os << "(" << p.first << ", " << p.second << ")";
}

template<typename T>
inline std::ostream &operator << (std::ostream & os, const std::vector<T>& v)
{
    bool first = true;
    os << "[";
    for(unsigned int i = 0; i < v.size(); i++)
    {
        if(!first)
            os << ", ";
        os << v[i];
        first = false;
    }
    return os << "]";
}

template<typename T>
inline std::ostream &operator << (std::ostream & os, const std::set<T>& v)
{
    bool first = true;
    os << "[";
    for (typename std::set<T>::const_iterator ii = v.begin(); ii != v.end(); ++ii)
    {
        if(!first)
            os << ", ";
        os << *ii;
        first = false;
    }
    return os << "]";
}

template<typename T1, typename T2>
inline std::ostream &operator << (std::ostream & os, const std::map<T1, T2>& v)
{
    bool first = true;
    os << "[";
    for (typename std::map<T1, T2>::const_iterator ii = v.begin(); ii != v.end(); ++ii)
    {
        if(!first)
            os << ", ";
        os << *ii ;
        first = false;
    }
    return os << "]";
}

struct debugger
{
	bool first;

	debugger() {
		first = true;
	}

    template<typename T> debugger& operator , (const T& v)
    {
    	if (!first) cout << ", ";
        cout << v;
        first = false;
        return *this;    
    }
};

// Debug macro that prints out "expression: value" for clarity
#ifdef DEBUG
    #define debug(args...)          { cout << #args << ": "; (debugger()), args; cout << endl; }
#else
    #define debug(args...)
#endif

#define int long long

// Union-Find Disjoint-Sets data structure with path compresion and efficient union
// class UnionFind {
//     private:
//         vector<int> p, rank;
//     UnionFind(int n) {
//         rank.assign(n, 0);
//         for (int i = 0; i < n; i++) {
//             p[i] = i;
//         }
//     }
//     int findSet(int i) {
//         return (p[i] == i) : i ? (p[i] = findSet(i));
//     }
//     int unionSet(int i, int j) {
//         int x = findSet(i), y = findSet(j);
//         if (x != y) {
//             if (rank[x] < rank[y]) p[x] = y;
//             else {
//                 p[y] = x;
//                 if (rank[x] == rank[y]) rank[y]++;
//             }
//         }
//     }
// }

int32_t main(void) {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n; cin >> n;
    map<int, int> m;
    for (int i = 0; i < n; i++) {
        int a; cin >> a;
        m[a]++;
    }
    int ans = 0;
    for (auto x : m) {
        if (x.first < x.second) ans += x.second - x.first;
        else if (x.first > x.second) ans += x.second;
    }
    cout << ans << endl;
}

Measured memory_bytes: 6272
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL<<60;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP2(i,m,n) for(int i=m;i<n;i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }


int change(string time){
    int num = (int(time[0]) -48)*100000+(int(time[1]) -48)*10000 +(int(time[3]) -48)*1000+(int(time[4]) -48)*100 + (int(time[6]) -48)*10 + (int(time[7]) -48);

    return num;
}

int main(){
    
    while(true){
        int n;
        cin >> n;
        if(n==0) break;
        // cout<<"n"<<n<<endl;
        vector<pair<int,int> > a;
        int ans=0;
        REP(i,n){
            string tmp1,tmp2;
            cin >> tmp1>>tmp2;
            pair<int,int> tmp={change(tmp1),change(tmp2)};
            // ASC2 48~57は数字
            a.push_back(tmp);
        }
        sort(a.begin(),a.end());
        // REP(i,n){
        //     cout<<a[i].first<<" "<<a[i].second<<endl;
        // }
        
        vector<pair<int,int> > b;
        REP(i,n){
            bool flag = true;
            pair<int,int> tmp3= a[i];
            REP(j,b.size()){
                if(b[j].second <= tmp3.first) {
                    flag = false;
                    b[j]=tmp3;
                    break;
                }
                
            }

            if(flag){
                b.push_back(tmp3);
                ans++;
            }
        }
        
        cout<<ans<<endl;

       
    }

    
}


Measured memory_bytes: 3312
from collections import defaultdict
def main():
    n = int(input())
    d = defaultdict(int)
    for i in range(n):
        num = str(i + 1)
        head = num[0]
        tail = num[-1]
        d[(head, tail)] += 1

    ans = 0
    for (head, tail), cnt in list(d.items()):
        ans += cnt * d[(tail, head)]
    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 3316
//My_Template

#include<bits/stdc++.h>

#define ll long long int
#define vec vector<long long int>
#define pb(a) push_back(a)
#define myfor(n) for(long long int i = 0; i < n; i++)
#define tc(t) long long int t; cin>>t; while(t--)
#define sortt(a) sort(a.begin(), a.end())
#define summ(a) accumulate(a.begin(), a.end(), 0ll)
#define M 1000000007ll

using namespace std;

int main() {

	//code_goes_here-->

	ll n, ans = 0;
	cin>>n;

	vec a(n);

	myfor(n)
		cin>>a[i];

	for(ll i = 1; i < n; i++){
		if(a[i] < a[i - 1]){
			ans += a[i - 1] - a[i];
			a[i] += a[i - 1] - a[i];
		}
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 4760
def second_smallest(numbers):
    m1, m2 = float('inf'), float('inf')
    for x in numbers:
        if x <= m1:
            m1, m2 = x, m1
        elif x < m2:
            m2 = x
    return m2

count=0
N = int(input())
L = list(map(int, input().split()))
for i in range(len(L)-2):
    for j in range(i+1, len(L)-1):
        for k in range(j+1, len(L)):
            if L[i]!=L[j] and L[j]!=L[k] and L[k]!=L[i]:
                if max(L[i], L[j], L[k]) < second_smallest([L[i], L[j], L[k]])+min(L[i], L[j], L[k]):
                    count=count+1
                    
print(count)


Measured memory_bytes: 9240
#include<stdio.h>
int main(){
  int a,b[100],i,j,n,key;
  scanf("%d",&a);
  if(1<=a && a<=100){
    for(i=0;i<a;i++){
      scanf("%d",&b[i]);
    }

    for(i=0;i<a;i++){
      key=b[i];
      j=i-1;
      while(j>=0 && b[j]>key){
	b[j+1]=b[j];
	j-=1;
	b[j+1]=key;
      }
     for(n=0;n<a-1;n++){
	printf("%d ",b[n]);
      }
     printf("%d\n",b[n]);
    }
  }
  return 0;
}

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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll A, B;
    cin >> A >> B;
    if (A % 3 == 0 || B % 3 == 0 || (A + B) % 3 == 0)
        cout << "Possible" << endl;
    else
        cout << "Impossible" << endl;
    return 0;
}

Measured memory_bytes: 256
def gcd(a,b):
    if a<b:
        a,b=b,a

    if a%b==0:
        return b
    else:
        a,b=b,a%b
        return gcd(a,b)

N=int(input())
for i in range(N):
    if i==0:
        b=int(input())
    else:
        a=int(input())
        c=gcd(a,b)
        b=c*(a//c)*(b//c)

print(b)

Measured memory_bytes: 3060
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<utility>
#include<string>
#include<stack>
#include<queue>
#include<set>
#include<math.h>
#include <map>
using namespace std;
typedef long long int ll;
#define repi(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,a) repi(i,0,a)
#define all(u) u.begin(),u.end()
#define pl pair<ll,ll>
#define f first
#define s second
#define inf 1000000007





ll N;
double t[110];
double v[110];
double T[110];
vector<double> maxv(40040);

double min(double a, double b){
    if (a < b) return a;
    else return b;
}

int main() {
    cin >> N;
    rep(i,N) cin >> t[i+1];
    rep(i,N) cin >> v[i+1];
    v[0] = 0;
    v[N+1] = 0;
    t[0] = 0;
    t[N+1] = 0;
    rep(i,N){
        T[i+1] = T[i] + t[i+1];
    }
    rep(i,(2*T[N]+1)){
        rep(j,N+1){
            if (i*0.5 < T[j]){
                maxv[i] = v[j];
                break;
            }
        }
    }
    maxv[2*T[N]] = 0;
    maxv[0] = 0;
    repi(i,1,N){
        maxv[2*T[i]] = min(maxv[2*T[i]],min(maxv[2*T[i]-1],maxv[2*T[i]+1]));
    }
    // rep(i,2*T[N]+1) cout << i*0.5 << " " << maxv[i] << endl;
    for(ll i = 1; i <=2*T[N]; i++){
        maxv[i] = min(maxv[i],maxv[i-1]+0.5);
    }
    for(ll i = 2*T[N]-1; i>=0; i--){
        maxv[i] = min(maxv[i],maxv[i+1]+0.5);
    }
    // rep(i,2*T[N]+1){cout << i*0.5 << " " << maxv[i] << endl;}
    double ans = 0;
    rep(i,2*T[N]){
        ans += (maxv[i]+maxv[i+1])*0.25;
    }
    printf("%.9f\n",ans);
    return 0;
}


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

int main(){
    int n, x, y;
    cin >> n >> x >> y;
    vector<int> lis(n-1, 0);

    for(int i = 0; i < n; i++){
        int disx = min(abs(x-i-1), abs(y-i-1));
        for(int j = i+1; j < n; j++){
            int a = j - i;
            int b = disx + 1 + min(abs(y-j-1), abs(x-j-1));
            int dist = min(a, b);
            lis[dist-1] += 1;
        }
    }
    for(int i = 0; i < n-1; i++){
        cout << lis[i] << endl;
    }
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
#sys.setrecursionlimit(150000)


def solve(N: int, M: int, A: "List[int]"):
    print(N-sum(A) if N>=sum(A) else -1)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(M)]  # type: "List[int]"
    solve(N, M, A)

if __name__ == '__main__':
    main()


Measured memory_bytes: 10096
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<sstream>
#include<map>
#include<queue>
using namespace std;
#define int long long
int N, K, S;
vector<vector<int> >ne;
vector<vector<int> >cost;
int kasanari(int x1, int x2) {
	if (x1 > x2) {
		swap(x1, x2);
	}
	if (x1 + S <= x2)return 0;
	return x1 + S - x2;
}

signed main() {
	while (true) {
		cin >> N >> K >> S;
		if (N == 0)break;
		vector<int> X(N);
		vector<int> Y(N);
		vector<int> Z(N);
		for (int i = 0; i < N; i++) {
			cin >> X[i] >> Y[i] >> Z[i];
		}
		ne.clear();
		ne.resize(N);
		cost.clear();
		cost.resize(N);
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < i; j++) {
				int dx = kasanari(X[i], X[j]);
				int dy = kasanari(Y[i], Y[j]);
				int dz = kasanari(Z[i], Z[j]);
				if (dx == 0 || dy == 0 || dz == 0) {
					continue;
				}
				int c = 2 * (dx*dy + dy*dz + dz*dx);
				ne[i].push_back(j);
				ne[j].push_back(i);
				cost[i].push_back(c);
				cost[j].push_back(c);
			}
		}
		/*for (int i = 0; i < N; i++) {
			cerr << ne[i][0] << " " << ne[i][1] <<  endl;
		}*/
		int INF = (int)1 << 60;
		vector<int> A(N, 0);


		vector<pair<int, int> > deg(N);
		for (int i = 0; i < N; i++) {
			deg[i].first = ne[i].size();
			deg[i].second = i;
		}
		sort(deg.begin(), deg.end());
		int nc;
		int snc = 0;
		int res = INF;
		for (auto d : deg) {
			int ii = d.second;
			if (A[ii] == 0) {

				vector<int> cs;
				if ((int)cost[ii].size() == 2)cs.push_back(cost[ii][1]);
				int cur = ii;
				A[cur] = 1;

				while (true) {
					//cerr << cur << endl;
					for (int j = 0; j < ne[cur].size(); j++) {
						if (A[ne[cur][j]] == 0) {
							nc = cost[cur][j];
							cur = ne[cur][j];

							break;
						}
					}
					if (A[cur] == 1)break;
					A[cur] = 1;
					cs.push_back(nc);
				}
				if ((int)cs.size() > K || ((int)cs.size() == K && cost[ii].size() <= 1)) {
					//cerr << "ok" << endl;
					int sm = 0;
					for (int i = 0; i < K - 1; i++) {
						sm += cs[i];
					}
					res = min(res, 6 * K*S*S - sm);
					int l;
					if ((int)cost[ii].size() == 2) {
						l = cs.size();
					}
					else {
						l = cs.size() - K + 1;
					}
					for (int i = 0; i < l; i++) {
						sm -= cs[i];
						sm += cs[(i + K - 1) % cs.size()];
						res = min(res, 6 * K*S*S - sm);
					}
					if (res == 1424) {
						cerr << "1" << endl;
					}
				}
				else if (cs.size() == K) {
					int sm = 0;
					for (int i = 0; i < cs.size(); i++) {
						sm += cs[i];
					}
					res = min(res, 6 * K*S*S - sm);
					
				}
				else if (cs.size() == K - 1) {
					//cerr << "ok" << endl;
					if ((int)cost[ii].size() != 2) {
						int sm = 0;
						for (int i = 0; i < cs.size(); i++) {
							sm += cs[i];
						}
						res = min(res, 6 * K*S*S - sm);
					}
				}
				else {

				}


			}
		}
		if (res == INF) {
			cout << -1 << endl;
		}
		else {
			cout << res << endl;
		}
	}
}


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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int a, b;
	cin >> a >> b;
	for (int i = 1; i <= 3; ++i) {
		if (i != a && i != b) {
			dunk(i);
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, char *argv[])
{
    long divident, divisor;
    scanf("%ld %ld", &divident, &divisor);
    const long   quotient   = divident / divisor;
    const long   remainder  = divident % divisor;
    const double realnumber = (double)divident / divisor;
    printf("%ld %ld %.5f\n", quotient, remainder, realnumber);
    return 0;
}



Measured memory_bytes: 2148
#include <iostream>
using namespace std;
int main()
{
    int n,b; char a;
    bool mouth[4][13]={{0}};
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>a>>b;
        if(a=='S'){ mouth[0][b-1]=true;}
        if(a=='H'){ mouth[1][b-1]=true;}
        if(a=='C'){ mouth[2][b-1]=true;}
        if(a=='D'){ mouth[3][b-1]=true;}
        
    }
    for(int s=0;s<13;s++){if(mouth[0][s]==0){cout<<"S "<<s+1<<endl;}}
    for(int h=0;h<13;h++){if(mouth[1][h]==0){cout<<"H "<<h+1<<endl;}}
    for(int c=0;c<13;c++){if(mouth[2][c]==0){cout<<"C "<<c+1<<endl;}}
    for(int d=0;d<13;d++){if(mouth[3][d]==0){cout<<"D "<<d+1<<endl;}}
  
    return 0;
}


Measured memory_bytes: 3084
#include<bits/stdc++.h>
using namespace std;
#define pi acos(-1)
int sqr(int x){
  return x*x;
}
double miin(double a,double b){
  if(a>b) return a;
  else return b;
}
int main(){
   int a, b, h,m;
   cin>>a>>b>>h>>m;
   double goc,c;
   goc=miin(abs(1.0*2*pi*(h+m/60.0)/12-1.0*2*pi*m/60),2*pi-abs(1.0*2*pi*(h+m/60.0)/12-1.0*2*pi*m/60));
   c=sqrt(sqr(a)+sqr(b)-2*a*b*cos(goc));
   cout<<fixed<<setprecision(15)<<c;
  /* double goc_h,goc_p,res;
   goc_h=(1.0)*(2*pi*(h+m/60.0))/12;
   goc_p=(1.0)*(2*pi*m)/60;
   res=abs(goc_h-goc_p);
   res=miin(res,2*pi-res);
   res=sqrt(sqr(a)+sqr(b)-2*a*b*cos(res));
   cout<<fixed<<setprecision(30)<<res;*/

    return 0;
}


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

def solve():
    S = input()
    if S == "SUN":
        ans = 7
    elif S == "MON":
        ans = 6
    elif S == "TUE":
        ans = 5
    elif S == "WED":
        ans = 4
    elif S == "THU":
        ans = 3
    elif S == "FRI":
        ans = 2
    elif S == "SAT":
        ans = 1
    print(ans)


if __name__ == "__main__":
    solve()


Measured memory_bytes: 2940
S = list(input())
a = 0
b = 0
c = 0

for s in S:
    if s == 'a':
        a += 1
    elif s == 'b':
        b += 1
    else:
        c += 1

if max(a, b, c) - min(a, b, c) < 2:
    print('YES')
else:
    print('NO')


Measured memory_bytes: 3956
S = list(input())

even_list = ['R', 'U', 'D']
odd_list = ['L', 'U', 'D']

is_even = all(list(map(lambda x: x in even_list, S[0::2])))
is_odd = all(list(map(lambda x: x in odd_list, S[1::2])))

if is_even and is_odd:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#define REP(i, a, n) for(int i = ((int) a); i < ((int) n); i++)
using namespace std;

int N, A[100000];

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

  sort(A, A + N);

  if(A[N - 1] - A[0] > 1) {
    cout << "No" << endl;
    return 0;
  }

  int k;
  for(k = 0; k < N; k++) if(A[0] != A[k]) break;
  if(k < N) {
    cout << (1 <= A[N - 1] - k && A[N - 1] - k <= (N - k) / 2 ? "Yes" : "No") << endl;
  } else {
    cout << (A[0] * 2 <= N || A[0] + 1 == N ? "Yes" : "No") << endl;
  }

  return 0;
}


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

#define rep(i, n) for(long long i=0;i<(long long)(n);i++)
#define rep2(i, s, n) for(long long i=(s);i<(long long)(n);i++)
#define repi(i, n) for(int i=0;i<(int)(n);i++)
#define rep2i(i, s, n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(), v.end()

using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;

const ll INF = (1LL<<60);
const int INFi = (1<<29);

int main(){

    ll n; cin >> n;
    ll in, sum = 0;
    map<ll, ll> mp;
    rep(i, n){
        cin >> in;
        mp[in]++;
        sum += in;
    }
    ll q; cin >> q;
    vll b(q), c(q);
    rep(i, q) cin >> b[i] >> c[i];

    rep(i, q){
        sum -= (b[i]-c[i])*mp[b[i]];
        mp[c[i]] += mp[b[i]];
        mp[b[i]] = 0;
        cout << sum << endl;
    }

    return 0;
}

Measured memory_bytes: 10892
#include<iostream>
#include<algorithm>
using namespace std;
main()
{
    string s;
    cin>>s;
    int n=s.length();
    string w="";
    for(int i=0;i<(int)s.length();i++)if(s[i]!='x')w+=s[i];
    string ww=w;
    reverse(begin(ww),end(ww));
    if(w!=ww)
    {
        printf("%d\n",-1);
        return 0;
    }
    int ans=0;
    int i=0,j=n-1;
    while(i<j)
    {
        if(s[i]==s[j])
        {
            i++;
            j--;
            continue;
        }
        ans++;
        if(s[i]=='x')i++;
        else j--;
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 512
import math
a,b,c=map(int,input().split())
k=int(input())
t,s=0,0
while True:
    if b>a:
        break
    b*=2
    t+=1
while True:
    if c>b:
        break
    c*=2
    s+=1
if t+s<=k:
    print('Yes')
else:
    print('No')

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

int main(){
    int s;
    string S,ans;
    cin >> s;
    S = to_string(s);
    for (int i = 0;i<3;i++){
        if (S[i] == S[i+1]){
            ans = "Bad";
            break;
        }
        if(i == 2) ans = "Good";
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
int main(void)
{
    int n;
    int a[100000],dp[1000001];

    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    dp[0]=0;
    dp[1]=abs(a[1]-a[0]);
    for(int i=2;i<n;i++){
        if(dp[i-1]+abs(a[i]-a[i-1])>dp[i-2]+abs(a[i]-a[i-2])){
            dp[i]=dp[i-2]+abs(a[i]-a[i-2]);
        }
        else{
            dp[i]=dp[i-1]+abs(a[i]-a[i-1]);
        }
    }
    printf("%d\n",dp[n-1]);
    return 0;
}


Measured memory_bytes: 2816
// https://atcoder.jp/contests/abc068/tasks/arc079_a

#include <bits/stdc++.h>

using namespace std;

#define REP(i,n)   for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); i++)
#define DUMP(a, n) REP(_i, n) printf("%d%c", a[_i], _i + 1 == n ? '\n' : ' ')
#define DUMP2D(a, n, m) REP(_i, n) REP(_j, m) printf("%d%c", a[_i][_j], _j + 1 == m ? '\n' : ' '); puts("")

const int N_MAX = 200'000;
const int M_MAX = 200'000;

int N, M;
int a[M_MAX];
int b[M_MAX];

int f[N_MAX];

void solve() {
  bool cond = false;
  REP(i, M) {
    int g = 0;
    if (a[i] == 1) g = (f[b[i]] |= 1);
    if (b[i] == N) g = (f[a[i]] |= 2);
    if (g == 3) {
      cond = true;
      break;
    };
  }
  puts(cond ? "POSSIBLE" : "IMPOSSIBLE");
}

void input() {
  scanf("%d%d", &N, &M);
  REP(i, M) scanf("%d%d", a + i, b + i);
}

int main() {
  input();
  solve();
  return 0;
}


Measured memory_bytes: 2560
#include <iostream> // cin, cout, cerr
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota
#include <cstdio> // printf, scanf
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <iomanip> // cout<<setprecision(n)
#include <functional> // function<void(int)>
#include <cmath>

#ifdef DEBUG
#include "debug.hpp"
#else
#define debug(...)
#endif

#define int long long // at least int64 > 9*10^18
#define ENDL '\n'
#define rep(i,n) for(int i = 0; i < (n); i++)
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
/* libraries */

struct UnionFind
{
  int n;
  std::vector<int> par,size;
  UnionFind(int sz) : n(sz), par(sz,0), size(sz,1) {
    std::iota(par.begin(),par.end(),0);
  }
  int find(int x) {
    if(par[x]==x) return x;
    return par[x] = find(par[x]);
  }
  void unite(int x, int y) {
    x=find(x);y=find(y);
    if(x==y) return;
    if(size[x]<size[y]) std::swap(x,y);
    size[x]+=size[y];
    par[y]=x;
  }
};

int convert(int x, int y, int w) {
	return x*w+y;
}

signed main() {
	int h,w;
	std::cin >> h >> w;
	std::vector<std::string> g(h);
	rep(i,h) std::cin >> g[i];
	UnionFind uf(h*w);
	rep(x,h) {
		rep(y,w) {
			for(int dx=-1;dx<=1;dx++) {
				for(int dy=-1;dy<=1;dy++) {
					if(dx*dy!=0) continue;
					if(dx==0&&dy==0) continue;
					if(x+dx<0||x+dx>=h) continue;
					if(y+dy<0||y+dy>=w) continue;
					if(g[x][y]!=g[x+dx][y+dy]) uf.unite(convert(x,y,w),convert(x+dx,y+dy,w));
					debug(uf.par);
				}
			}
		}
	}
	std::map<int,int> mapw;
	std::map<int,int> mapb;
	debug(h,w);
	rep(i,h*w) {
		if(g[i/w][i%w]=='.') mapw[uf.find(i)]++;
		else mapb[uf.find(i)]++;
	}
	debug(mapw,mapb);
	debug(uf.par);
	int count = 0;
	for(auto x:mapw) {
		count+=x.second*mapb[x.first];
	}
	print(count);

	return 0;
}


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

using namespace std;

int main(void)
{
  int n,a;

  cin>>n>>a;

  n = n - (n/500)*500;

  if(n-a<=0)
  {
      cout<<"Yes"<<endl;
  }
  else
  {
      cout<<"No"<<endl;
  }
}


Measured memory_bytes: 256
//	created : 16/05/09
// 	author   : Rp7rf
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <set>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define rep(i,a) for(int i = 0 ; i < a ; i ++)
#define loop(i,a,b) for(int i = a ; i < b ; i ++)
#define vi vector<int>
#define mp make_pair
#define pb push_back
#define MOD 1000000007
#define INF 1e9


int main(void){
  int n,m;
  while(cin>>n>>m){
    if(n == m && n == 0)break;
    vi nn(n),mm(m);
    int nsum,msum;
    nsum = msum = 0;
    rep(i,n){cin>>nn[i];nsum += nn[i];}
    rep(i,m){cin>>mm[i];msum += mm[i];}
    sort(nn.begin(),nn.end());
    sort(mm.begin(),mm.end());
    bool find = false;
    int sn , sm;
    int ma = 100000000;
    rep(i,n)rep(j,m){
      if(msum +  nn[i] - mm[j] == nsum + mm[j] - nn[i]){
        if(ma > nn[i] + mm[j]){
          ma = nn[i] + mm[j];
          sn = nn[i];
          sm = mm[j];
        }
      //  cout<<sn<<" "<<sm<<endl;
        find = true;
        break;
      }
      if(find)break;
    }
    if(!find)cout<<-1<<endl;
    else cout<<sn<<" "<<sm<<endl;
  }
}

Measured memory_bytes: 1216
#include<stdio.h>
#include<math.h>
int main(void){
   int n, count = 0, i, s, key;
   long a;
   scanf("%d", &n);
   for ( i = 0;  i < n; i++ ) {
      s = key = 2;
      scanf("%ld", &a);
      if ( a == 1 ) a;
      else if ( a == 2 ) {/*printf("sosuu\n")*/;count++;}
      else {
         while ( s < sqrt(a) + 2 && key != 0) {
            if ( a % s == 0 ) key = 0;
            else key = 1;
            s++;
         }
      }
      if ( a != 1 && s > sqrt(a) + 1) {/*printf("sosuu\n")*/;count++;}
   }
   printf("%d\n", count);
   return 0;
}

Measured memory_bytes: 1812
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  s=list(S())

  a1=list('dream')
  a2=list('dreamer')
  a3=list('erase')
  a4=list('eraser')

  while len(s)>4:
    if s[-5:]==a1:
      for _ in range(5):
        s.pop()
    elif s[-7:]==a2:
      for _ in range(7):
        s.pop()
    elif s[-5:]==a3:
      for _ in range(5):
        s.pop()
    elif s[-6:]==a4:
      for _ in range(6):
        s.pop()
    else:
      break

  if s==[]:
    return 'YES'
  return 'NO'

# main()
print(main())


Measured memory_bytes: 8004
//Moh_K_Imar .......
//29/08/2020  ... 5,25.
//Ya Rab....
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
int main(){
    ll a;
    cin>>a;
    if(a==7||a==5||a==3)cout<<"YES"<<endl;
    else
        cout<<"NO"<<endl;

    return 0;
}



Measured memory_bytes: 3636
#include <stdio.h>

int main(){

    int W,H,x,y,r;
    
  		scanf("%d",&W);
		scanf("%d",&H);
		scanf("%d",&x);
		scanf("%d",&y);
		scanf("%d",&r);
  
        if((x+r<=W)&&(y+r<=H)&&(x-r>=0)&&(y-r)>=0) {
			printf("Yes\n");
		}else{
			printf("No\n");
		}
		return 0;
}

Measured memory_bytes: 580
n, a, b = map(int, input().split())
mod = 10**9+7
ans = pow(2, n, mod)-1

def comb(n, a, mod):
    ans = 0
    u = 1
    for i in range(a):
        u *= n-i
        u %= mod
    d = 1
    for i in range(a):
        d *= i+1
        d %= mod
    ans = u*pow(d, mod-2, mod) % mod
    return ans
ans -= comb(n, a, mod)
ans -= comb(n, b, mod)
ans %= mod

print(ans)

Measured memory_bytes: 3064
def dfs(i, j)
  c = @map[i][j]
  @map[i][j] = '.'

  stack = []
  stack.push [i, j]

  mv = [[-1, 0], [1, 0], [0, -1], [0, 1]]

  while !stack.empty?
    i, j = stack.pop

    mv.each do |mi, mj|
      ii = i + mi; jj = j + mj
      if 0 <= ii && ii < @h && 0 <= jj && jj < @w && @map[ii][jj] == c
        @map[ii][jj] = '.'
        stack.push [ii, jj]
      end
    end
  end
end

def solve
  ans = 0
  0.upto(@h - 1) do |i|
    0.upto(@w - 1) do |j|
      unless @map[i][j] == '.'
        dfs(i, j)
        ans += 1
      end
    end
  end
  ans
end

while true
  @h, @w = gets.split.map(&:to_i)
  break if @h == 0 && @w == 0

  @map = []
  @h.times do
    @map.push gets.chomp.split('')
  end

  puts solve
end

Measured memory_bytes: 6744
from collections import defaultdict

n, m = map(int, input().split())
count = defaultdict(int)
for _ in range(m):
    c1, c2 = map(int, input().split())
    count[c1] += 1
    count[c2] += 1
for i in range(1, n + 1):
    print(count[i])

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

using namespace std;

int main(){
    int a,b,c,k;
    cin >> a >> b >> c >> k;
    int ans=0;
    vector<int> list(3);
    list[0] = a;
    list[1] = b;
    list[2] = c;

    for (int i=0;i<k;i++){
        int max_flag=0;
        int max = list[0];
        if (max<list[1]) {
            max=list[1];
            max_flag = 1;
        }
        if (max<list[2]){
            max=list[2];
            max_flag=2;
        }
        list[max_flag] = list[max_flag]*2;
    }
    for (int i=0;i<3;i++){
        ans += list[i];
    }
    cout << ans << endl;
}

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

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

typedef long long ll;
using namespace std;
int mod = 1000000007;

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N; cin >> N;
    int A[N]; rep(i, N) cin >> A[i];
    sort(A, A+N);
    //N = 6 -> A[2]より大きくA[3]以下
    if(N % 2 == 1) cout << 0 << endl;
    else{
        cout << A[N/2] - A[N/2-1] << endl;
    }
    return 0;
}

Measured memory_bytes: 640
import java.util.HashSet;
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();

        HashSet<Integer> hs = new HashSet<>();
        for(int i=0; i<K; i++){
            int d = sc.nextInt();
            for(int j=0; j<d; j++){
                hs.add(sc.nextInt());
            }
        }

        System.out.println(N-hs.size());

        sc.close();
        
    }
}

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

using namespace std;

int main(){
        int fir,sec;
        string s;
        bool yymm=false,mmyy=false;
        cin>>s;

        fir = (s[0]-'0')*10+(s[1]-'0');
        sec = (s[2]-'0')*10+(s[3]-'0');

        if((0<sec)&&(sec<13)) yymm=true;
        if((0<fir)&&(fir<13)) mmyy=true;

        if(yymm&&mmyy) cout<<"AMBIGUOUS"<<endl;
        else if(yymm) cout<<"YYMM"<<endl;
        else if(mmyy) cout<<"MMYY"<<endl;
        else cout<<"NA"<<endl;

        return 0;
}


Measured memory_bytes: 256