akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
const int MaxN = 2000;
using namespace std;
char s[MaxN + 5][MaxN + 5];
int n , m , q;
int f[MaxN + 5][MaxN + 5];
int up[MaxN + 5][MaxN + 5] , r[MaxN + 5][MaxN + 5];
void Init(){
	for(int i = 1;i <= n;i++) scanf("%s" , s[i] + 1);
	for(int i = 1;i <= n;i++){
		for(int j = 1;j <= m;j++){
			if(s[i][j] == '1') f[i][j] = 1;
		}
	}
	for(int i = 1;i < n;i++){
		for(int j = 1;j <= m;j++){
			if(s[i][j] == s[i + 1][j] && s[i][j] == '1') up[i][j] = 1;
		}
	}
	for(int i = 1;i <= n;i++){
		for(int j = 1;j < m;j++){
			if(s[i][j] == s[i][j + 1] && s[i][j] == '1') r[i][j] = 1;
		}
	}
	for(int i = 1;i <= n;i++){
		for(int j = 1;j <= m;j++){
			up[i][j] += up[i - 1][j] + up[i][j - 1] - up[i - 1][j - 1];
			r[i][j] += r[i - 1][j] + r[i][j - 1] - r[i - 1][j - 1];
			f[i][j] += f[i - 1][j] + f[i][j - 1] - f[i - 1][j - 1];
		}
	}
}
int Get(int a , int b , int c , int d){
	int res , t , tt , ttt , tttt;
	t = f[c][d] - f[c][b - 1] - f[a - 1][d] + f[a - 1][b - 1];
	tt = up[c - 1][d] - up[c - 1][b - 1] - up[a - 1][d] + up[a - 1][b - 1];
	ttt = r[c][d - 1] - r[c][b - 1] - r[a - 1][d - 1] + r[a - 1][b - 1];
	return (t - tt - ttt);
}
void Solve(){
	for(int i = 1;i <= q;i++){
		int x_1 , y_1 , x_2 , y_2;
		scanf("%d%d%d%d" , &x_1 , &y_1 , &x_2 , &y_2);
		int ans = Get(x_1 , y_1 , x_2 , y_2);
		printf("%d\n" , ans);
	}
}
int main()
{
	while(~scanf("%d%d%d" , &n , &m, &q)){
		Init();
		Solve();
	}
}

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

typedef long long ll;

int N;
vector<int> A, B;

int main() {
  cin >> N;
  int a,b;
  rep(i, N+1) {
    scanf("%d", &a);
    A.push_back(a);
  }
  rep(i, N) {
    scanf("%d", &b);
    B.push_back(b);
  }
  ll sum=0;
  int used=0;
  for(int i=0; i<N; i++) {
    int p = min(B[i], A[i] - used);
    /* cout << "p : " << p << endl; */
    used = min(B[i]-p, A[i+1]);
    /* cout << "used : " << used << endl; */
    sum += (p+used);
  }
  cout << sum << endl;
  return 0;
}



Measured memory_bytes: 1400
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <string>
#include <string.h>

using namespace std;

int main() {
  int n,k;
  cin >> n >> k;
  if(n % k == 0) cout << 0 << endl;
  else cout << 1 << endl;
}

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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define itn long long

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


int main()
{
  int n;
  cin >> n;
  vector<int> v(n, 0);
  for(int i = 0; i < n; i++)
  {
    cin >> v[i];
  }

  sort(all(v));
  cout << v[n-1] - v[0] << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define maxn 100005
#define mo 1000000007
int a[maxn],fac[maxn],inv[maxn];
int Pow(int a,int b){
	int ans=1;
	while(b){
		if(b&1)ans=1ll*ans*a%mo;
		a=1ll*a*a%mo,b>>=1;
	}
	return ans;
}
inline int C(int n,int m){return m>n?0:1ll*fac[n]*inv[m]%mo*inv[n-m]%mo;}
int main(){
	int n,k,ans=0;scanf("%d%d",&n,&k);
	fac[0]=1;for(int i=0;i<n;i++)scanf("%d",a+i),fac[i+1]=1ll*fac[i]*(i+1)%mo;
	inv[n]=Pow(fac[n],mo-2);sort(a,a+n);
	for(int i=n;i;i--)inv[i-1]=1ll*inv[i]*i%mo;
	for(int i=0;i<n;i++){
		(ans+=1ll*a[i]*(C(i,k-1)-C(n-i-1,k-1))%mo)%=mo;
	}
	printf("%d",(ans+mo)%mo);
	return 0;
}

Measured memory_bytes: 1408
get_number(Number) :-
    get_string(String),
    number_string(Number, String).

get_string(String) :-
    current_input(Input),
    read_string(Input, ' \n', '', _, String).

/* memo
    string_code(1, S, C),
*/

main:-
    get_string(S),
    string_code(3, S, C3),
    string_code(4, S, C4),
    string_code(5, S, C5),
    string_code(6, S, C6),
    (C3 =:= C4 , C5 =:= C6) -> writeln("Yes") ; writeln("No").


Measured memory_bytes: 7940
import math


X = int(input())
if X == 2:
    print(X)
    exit()

if X % 2 == 0:
    X += 1

while True:
    for k in range(3, int(math.sqrt(X)) + 1, 2):
        if X % k == 0:
            break
    else:
        print(X)
        exit()
    X += 2


Measured memory_bytes: 38384
#include <cstdio>
using namespace std;

const int N = 2e5 + 10;
const int inf = 0x3f3f3f3f;
struct E {int v, nt;} e[N<<1];
int n, m, tot, h[N], q[N], inq[N], boats[N];

inline void add(int u, int v) {e[++tot] = (E){v, h[u]}, h[u] = tot;}
template <class T> inline void in(T &x) {
	x = 0; int f = 1; char ch = getchar();
	for (; ch<'0' || ch>'9';) {if (ch=='-') f=-1; ch = getchar();}
	for (; ch>='0' && ch<='9';) x = x*10 + ch-'0', ch = getchar();
	x *= f;
}

inline int bfs(int s, int t) {
	int i, u, v, l = 0, r = 0;
	for (inq[q[++r] = s] = 1; l < r;) {
		if (boats[u = q[++l]] > 1) continue;
		for (i = h[u]; i; i = e[i].nt)
			if (!inq[v = e[i].v])
				inq[v] = 1, boats[q[++r] = v] = boats[u] + 1;
	}
	return inq[t];
}

inline void work() {
	int u, v; in(n), in(m);
	for (int i = 1; i <= m; ++i) in(u), in(v), add(u, v);
	if (bfs(1, n)) puts("POSSIBLE");
	else puts("IMPOSSIBLE");
}

int main() {work(); return 0;}

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

int main()
{
	long n;
    cin>>n;
    long p=0,q=0,r=0,t=0;
    while(n--)
    {
        string s;
        cin>>s;
        if(s=="AC")
        {
            ++p;
        }
        else if(s=="WA")
        {
            ++q;
        }
        else if(s=="TLE")
        {
            ++r;
        }
        else if(s=="RE")
        {
            ++t;
        }
        else
            continue;
    }
    cout<<"AC x "<<p<<endl;
    cout<<"WA x "<<q<<endl;
    cout<<"TLE x "<<r<<endl;
    cout<<"RE x "<<t<<endl;
	return 0;
}

Measured memory_bytes: 3628
/******************************************************************************

                         بسم الله الرحمن الرحيم
                     Author: Mst: Mhamuda Khatun
                               RUCSE27

*******************************************************************************/

#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define ull unsigned long long
#define OrderSetTree tree<ll,null_type/*mapped_type*/,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
#define pi 2*acos(0.0)
#define f first
#define s second
#define pb push_back
#define gap ' '
#define fastio {ios_base::sync_with_stdio(false);cin.tie(NULL);}
#define mod 1000000007
#define MAX 1000000000000
#define N 305

int main()
{
    fastio;
    //OrderSetTree ost;
    ll i,j,t,n,k,p,num;
    bool flag=true;
    vector<bool>v(10);

    cin>>n>>k;

    for(i=0;i<k;i++)
    {
        cin>>p;
        v[p]=true;
    }

    for(i=n; ;i++)
    {
        num=i;
        flag=true;

        while(num>0)
        {
            if(v[num%10])
            {
                flag=false;
                break;
            }
            num/=10;
        }
        if(flag)
            break;
    }

    cout<<i;
    cout<<"\n";
    return 0;   //:D
}




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

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

int main(void){
    ll N,K;
    cin>>N>>K;
    
    vector<P> a(N);
    vector<bool> b(100001,false);
    
    for(int i=0;i<N;i++) cin>>a[i].second>>a[i].first;
    sort(a.begin(),a.end(),greater<P>());
    
    priority_queue<ll,vector<ll>,greater<ll>> que;
    
    ll sum=0,ans=0,kind=0;
    
    for(int i=0;i<K;i++){
        sum+=a[i].first;
        if(b[a[i].second]==false){
            kind++;
            b[a[i].second]=true;
        }else{
            que.push(a[i].first);
        }
    }
    
    ans=sum+kind*kind;
    
    for(int i=K;i<N;i++){
        if(que.empty())break;
        
        if(b[a[i].second]==false){
            sum-=que.top();
            que.pop();
            kind++;
            sum+=a[i].first;
            b[a[i].second]=true;
            ans=max(ans,sum+kind*kind);
        }
    }
    
    cout<<ans<<endl;
    
}

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

typedef pair<int,int> P;

bool involve(P a, P b) {
  return (a.first<b.first && a.second<b.second);
}

int main() {
  int n, m, s, t;
  int a[200];
  P dolls[201];
  while (1) {
    cin >> n;
    if (!n) break;
    dolls[0].first = dolls[0].second = 0;
    for (int i=1; i<=n; i++) {
      cin >> dolls[i].first >> dolls[i].second;
    }
    cin >> m;
    for (int i=1; i<=m; i++) {
      cin >> dolls[i+n].first >> dolls[i+n].second;
    }
    s = n+m;
    sort(dolls, dolls+s+1);
    for (int i=0; i<=s; i++) {
      a[i] = 0;
    }
    for (int i=1; i<=s; i++) {
      for (int j=0; j<i; j++) {
        if (involve(dolls[j], dolls[i])) {
          a[i] = max(a[i], a[j]+1);
        }
      }
    }
    t = 0;
    for (int i=0; i<=s; i++) {
      if (t < a[i]) {
        t = a[i];
      }
    }
    cout << t << endl;
  }
  return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (in i = 0; i < (in)(n); i++)
const double PI=3.14159265358979323846;
const int64_t waru = 1000000007;
const in INF=1<<30;
#define vec2(a,y,x) vector<vector<int>> a(y,vector<int>(x))
#define vec1(a,n) vector<in> a(n);rep(i,n)cin>>a[i]

int main(){
  int x;cin>>x;
  int d=x%10;x/=10;
  int c=x%10;x/=10;
  int b=x%10;x/=10;
  int a=x;
  int aa,bb,cc,dd;
  char cb,ccc,cd;
  
for (int tmp = 0; tmp < (1 << 3); tmp++) {
  bitset<3> s(tmp);
  if(s.test(0)) {bb =(-1)*b;cb='-';} else{ bb=b;cb='+';}
  if(s.test(1)) {cc =(-1)*c;ccc='-';} else{ cc=c;ccc='+';}
  if(s.test(2)) {dd =(-1)*d;cd='-';} else{ dd=d;cd='+';}
  if(a+bb+cc+dd==7){
     cout<<a<<cb<<b<<ccc<<c<<cd<<d<<"=7";
    break;
  }
}
}


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

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n;
    cin >> n;
    int p[n];
    for (int i = 0; i < n; i ++ ) {
        cin >> p[i];
    }
    int cnt = 0;
    for (int i = 0; i < n - 2; i ++) {
        if (p[i + 1] > p[i] && p[i + 1] < p[i + 2] || p[i + 1] < p[i] && p[i + 1] > p[i + 2]) {
            cnt ++;
        }
    }
    cout << cnt << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()

int main(void){
    ld a, b, x;
    cin >> a >> b >> x;

    x /= a;

    if(x <= a * b / 2.0){
        ld ans = atan2(b, 2 * x / b);
        ans = ans / M_PI * 180;
        if(ans < 0){
            ans += 360;
        }
        printf("%.12Lf", ans);
    }else{
        ld ans = atan2((2*b-2*x/a),a);
        ans = ans / M_PI * 180;
        if(ans < 0){
            ans += 360;
        }
        printf("%.12Lf", ans);
    }
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;
using System.Diagnostics;
using static System.Console;
//using System.Numerics;
//using static System.Math;
 
class Program
{
    static void Main()
    {
        //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().solve();
        Out.Flush();
    }
    Scanner cin = new Scanner();
    readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑
    readonly int mod = 1000000007;
 
 
    void solve()
    {
        var N = cin.nextlong;
        var M =cin.nextlong;
 
        var SUM = 1900 * M + 100 * (N - M);
        for (int i = 0; i < M; i++)
        {
            SUM *= 2;
        }
        WriteLine(SUM);
    }
 
}
 
class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan { get { return ReadLine().Split(); } }
    public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } }
    public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } }
    public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } }
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint { get { return int.Parse(next); } }
    public long nextlong { get { return long.Parse(next); } }
    public double nextdouble { get { return double.Parse(next); } }
}

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

int main(){
  string S,T;
  cin>>S>>T;
  vector<char> vec(1000,'0');
  vector<int> vec2(1000,0);
  
  for(int i=0;i<S.size();i++){
    if(vec.at(S.at(i))=='0'){
      vec.at(S.at(i)) = T.at(i);
      vec2.at(T.at(i))++;
      if(vec2.at(T.at(i)) != 1){
        cout<<"No"<<endl;
        return 0;
      }
    }
    else if(vec.at(S.at(i)) != T.at(i)){
      cout<<"No"<<endl;
      return 0;
    }
  }
  cout<<"Yes"<<endl;
}

Measured memory_bytes: 776
/*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
*$* WRITER:kakitamasziru/OxOmisosiru *$*
~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=*/
#ifdef LOCAL_JUDGE
#define _GLIBCXX_DEBUG //FOR THE DEBUG! COMMENT OUT THIS WHEN SUBMITTING!
#endif
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <iomanip>
#include <limits>//setprecision
//#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
//#include <unordered_set> //unordered_set
#include <stack> // stack
#include <deque> // deque
#include <math.h>//pow,,,
#include <cmath>//abs,,,
#include <bitset> // bitset
#define endl "\n";
//It is so troublesome that I include bits/stdc++.h !
using namespace std;

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const long long INF = 10010010010010;
const long long MOD = 1000000007;
typedef pair<int,int> P;

//Solve N^M. This, mod_pow use Iterative Square Method.
long long mod_pow(long long N, long long M) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % MOD, M / 2);
    //最下位ビット(*N)が1の時は単独でNをかける
    if (M & 1) res = (res * N) % MOD;

    return res %= MOD;
}

long long gcd(long long a, long long b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
    return a / gcd(a, b) * b ;
}

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

    int X,N;cin >> X >> N;
    vector<int> retu(N);
    bool ok = true;
    int ans = 0;
    int minisa = 114514;
    for(int i = 0;i<N;i++) cin >> retu.at(i);
    for(int i = -114514;i<=114514;i++){
        ok = true;
        int sa = abs(i-X);
        for(int j = 0;j<N;j++){
            if(retu.at(j) == i) ok = false;
        }
        if(ok){
            if(minisa > sa){
                ans = i;
                minisa = sa;
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3656
fn read_string() -> String {
    let mut input = String::new();
    let _ = std::io::stdin().read_line(&mut input);
    input.trim().to_string()
}

fn read_usize() -> usize {
    let mut input = String::new();
    let _ = std::io::stdin().read_line(&mut input);
    input.trim().parse::<usize>().unwrap()
}

fn main() {
    let s = read_string();
    let mut chars = s.chars();
    let k = read_usize();
    let mut i: usize = 0;

    while let Some(c) = chars.next() {
        if i >= k {
            break;
        }
        if c != '1' {
            println!("{}", c);
            return;
        }
        i += 1;
    }
    println!("1");
}

Measured memory_bytes: 4476
n = int(input())
stones = list(input())

a = 0
rlist = []
wlist = []
for i in range(n):
  if stones[i] == "W":
    wlist.append(i+1)
  elif stones[i] == "R":
    rlist.append(i+1)
rlist.sort(reverse=True)
r_numbers =  len(rlist)
w_numbers =  len(wlist)

if r_numbers == 0 or w_numbers == 0:
  print(0)
elif r_numbers>=w_numbers:
  count = 0
  while rlist[count] > wlist[count] and count < w_numbers-1:
    count += 1
  if rlist[count] > wlist[count]:
    print(count+1)
  else:
    print(count)
elif r_numbers<=w_numbers:
  count = 0
  while rlist[count] > wlist[count] and count < r_numbers-1:
    count += 1
  if rlist[count] > wlist[count]:
    print(count+1)
  else:
    print(count)
    

Measured memory_bytes: 18732
p = 10**9+7
kai_ = [1]
for i in range(1, 10 ** 7):
    kai_.append(kai_[-1] * i % p)


def kai(x):
    return kai_[x]


def comb(a, b):
    if a < 0 or b < 0:
        return 0
    elif a < b:
        return 0
    c = 1
    c *= kai(a)
    c *= pow(kai(b), p - 2, p)
    c *= pow(kai(a - b), p - 2, p)
    return c % p


r1, c1, r2, c2 = [int(i) for i in input().split()]


def s(r, c):
    return comb(r+c+2,r+1)


print((s(r2, c2) - s(r2, c1 - 1) - s(r1 - 1, c2) + s(r1 - 1, c1 - 1)) % p)


Measured memory_bytes: 189876
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define pvec(v) rep(i,v.size()){cout << v[i] << " ";};cout<<endl;
#define pb push_back
#define pf push_front
#define mod 1e9+7
#define m_p make_pair
 
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef vector<pii> vpii;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
const double pi = acos(-1.0);
 
ll gcd(ll x, ll y) { return (y == 0) ? x : gcd(y, x % y); }
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return false;
        }
    }
    return true;
}

int main()
{
    ll n;
    bool b=true;
    map<ll,ll> mp;
    cin >> n;
    vll a(n);
    rep(i,n){
        cin >> a[i];
        mp[a[i]]++;
    }
    if(n%2==0){
        rep(i,n/2){
            if(mp[i*2+1]!=2) b=false;
        }
    }
    else{
        if(mp[0]!=1) b=false;
        rep(i,n/2){
            if(mp[(i+1)*2]!=2) b=false;
        }
    }
    ll ans=1;
    rep(i,n/2){
        ans*=2;
        ans%=1000000007;
    }
    cout << (b?ans:0) << endl;
    return 0;
}

Measured memory_bytes: 6144
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
  int n,p;
  while(cin >> n >> p, n!=0 && p!=0){
    int s[n];
    int index = 0;
    int stone = p;
    for(int i=0;i<n;i++){
      s[i] = 0;
    }
    while(true){
      if(stone > 0){
	s[index]++;
	stone--;
      }else if(stone == 0){
	stone = s[index];
	s[index] = 0;
      }
    
      if(s[index] == p) break;
      if(index == n-1){
	index = 0;
      }else{
	index++;
      }
    }
    cout << index << endl;
  }
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr long long INFL = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



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

    int N;
    cin >> N;
    int L[N];
    map<int,int> m;
    rep(i,N){
        cin >> L[i];
        m[L[i]]++;
    }
    int ans=0;
    sort(L,L+N);
    for(int i=0;i<N-2;i++){
        for(int j=i+1;j<N-1;j++){
            for(int k=j+1;k<N;k++){
                if(L[k]<L[i]+L[j]) ans++;
                else break;
            }
        }
    }
    cout << ans << endl;



}


Measured memory_bytes: 256
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    n::Int=parseInt(readline())
    cnt=Dict{String,Int}("AC"=>0,"WA"=>0,"TLE"=>0,"RE"=>0)
    for i in 1:n
        s=readline()
        cnt[s]+=1
    end
    print("AC x ")
    println(cnt["AC"])
    print("WA x ")
    println(cnt["WA"])
    print("TLE x ")
    println(cnt["TLE"])
    print("RE x ")
    println(cnt["RE"])
end
main()

Measured memory_bytes: 167888
#include<bits/stdc++.h>
using namespace std;
int main(){
    while(1){
        int h,w;
        cin>>h>>w;
        if(h==0&&w==0){
            break;
        }
        else{
            for(int i=0;i<h;i++){
                for(int j=0;j<w;j++){
                    cout<<'#';
                }
                cout<<endl;
            }
        }
        cout<<endl;
    }
}


Measured memory_bytes: 3072
n,c,k=map(int,input().split())
T=[int(input()) for i in range(n)]
T.sort()
ans=1
now=T[0]
pas=0 #passenger

for t in T:
    pas+=1
    if t>now+k or pas>c:
        ans+=1
        now=t
        pas=1

print(ans)

Measured memory_bytes: 81012
#include <iostream>
#include <math.h>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

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

typedef long long lint;

using namespace std;

int main(){
  lint N,A,B;
  cin>>N>>A>>B;
  lint ans=0;
  lint X;
  cin>>X;
  REP(i,N-1){
    lint temp;
    cin>>temp;
    ans+=min(B,A*(temp-X));
    X=temp;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 384
#include <iostream>
using namespace std;
int main() {
    int n = 0;
    int time[100];
    int m = 0;
    int drinknunm;
    int drinktime;
    int ans[100];
    int buff = 0;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> time[i];
    }
    cin >> m;
    for (int j = 0; j < m; ++j) {
        cin >> drinknunm;
        cin >> drinktime;
        buff = time[drinknunm -1];
        time[drinknunm -1] = drinktime;
        ans[j] = 0;
        for (int i = 0; i < n; ++i) {
            ans[j] += time[i];
        }
        time[drinknunm -1] = buff;
    }
    for (int k = 0; k <m; ++k) {
        cout << ans[k] << endl;
    }
    return 0;
}

Measured memory_bytes: 256
class Dice:
    def __init__(self,dice):
        self.dice = dice
    def n_roll(self):
        self.dice = [self.dice[1],self.dice[5],self.dice[2],self.dice[3],self.dice[0],self.dice[4]]
    def s_roll(self):
        self.dice = [self.dice[4],self.dice[0],self.dice[2],self.dice[3],self.dice[5],self.dice[1]]
    def e_roll(self):
        self.dice = [self.dice[3],self.dice[1],self.dice[0],self.dice[5],self.dice[4],self.dice[2]]
    def w_roll(self):
        self.dice = [self.dice[2],self.dice[1],self.dice[5],self.dice[0],self.dice[4],self.dice[3]]
dice = list(map(int, input().split()))
dice1 = Dice(dice)
s = input()
for i in s:
    if i == "N":
        dice1.n_roll()
    elif i == "S":
        dice1.s_roll()
    elif i == "E":
        dice1.e_roll()
    elif i == "W":
        dice1.w_roll()
print(dice1.dice[0])


Measured memory_bytes: 5608
N, M = gets.split.map(&:to_i)
p = []
y = []
# 県=>市の配列 のハッシュ
c = {}
# ソートしちゃうので何番目に入力された市か覚えておく必要がある
# yearはユニークなので，year=>入力順の辞書を作っておく
dict = {}

M.times do |i|
  p[i], y[i] = gets.split.map(&:to_i)
  if c[p[i]].nil?
    c[p[i]] = []
  end
  c[p[i]].push(y[i])
  # 何番目の入力か記憶しておく
  dict[y[i]] = i
end

c.each do |a|
  # 各県の市を誕生順に昇順ソートする
  a[1].sort!
end

# puts "#{c}"

ans = {}
c.each do |key, val|
  i = 1
  val.each do |v|
    ans[dict[v]] = format('%06d', key) + format('%06d', i)
    i += 1
  end
end

# ansを添え字（つまり入力順）でソート
ans = ans.sort
ans.each do |a|
  puts a[1]
end

Measured memory_bytes: 41968
import collections
n = int(input())
l = [0]*250939
count = 0
for x in range(1,500):
    for y in range(1,500):
        for z in range(1,500):
            tmp = (x+y+z)**2-(x*y+y*z+z*x)
            if tmp <= 10**4:
                l[count] = tmp
                count+=1
            else:
                break
l = sorted(l)
C = collections.Counter(l)
for j in range(1,n+1):
    print(C[j])

Measured memory_bytes: 21652
#include <bits/stdc++.h>
#include <iostream>
#include <math.h>
using namespace std;
int main() {
    int64_t N, K;
    cin >> N >> K;
    vector<int64_t>vec(N);
    vector<bool>seen(N);
    for (int i=0; i < N; i++) {
        cin >> vec.at(i);
    }

    int64_t count = 1;
    int64_t i = vec[0];
    int64_t loop_start_index = 0;
    seen[0] = true;
    while (true) {
        i = vec[i -1];
        count += 1;
        if (seen[i-1]) {
            loop_start_index = i -1;
            break;
        }
        seen[i-1] = true;
    }

    int64_t b_l_count = 0;
    int64_t j = 1;
    while ((j -1) != loop_start_index) {
        j = vec[j -1];
        b_l_count += 1;
    }

    int64_t jc = 0;
    if (0 >= K - b_l_count) {
        jc = K;
        int64_t now = vec[0];
        if (jc == 0) {
            cout << 1 << endl;
        } else {
            jc -= 1;
            while(jc > 0) {
                now = vec[now -1];
                jc -= 1;
            }
            cout << now << endl;
        }
    } else {
        jc = (K - b_l_count) % (count - b_l_count);
        int64_t now = vec[loop_start_index];
        if (jc == 0) {
            cout << loop_start_index + 1 << endl;
        } else {
            jc -= 1;
            while(jc > 0) {
                now = vec[now -1];
                jc -= 1;
            }
            cout << now << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 4844
#include <stdio.h>
typedef long long ll;
using namespace std;

int main(void) {
  ll i, n, max = 0, min = 2000, x;
  scanf("%lld", &n);
  for(i = 0; i < n; i++) {
    scanf("%lld", &x);
    if(max < x) max = x;
    if(min > x) min = x;
  }
  printf("%lld\n", (max - min + 1) / 2);
  return 0;
}


Measured memory_bytes: 2760
// https://atcoder.jp/contests/arc084/tasks/arc084_a

fun main() {
    arc084a()
}

fun arc084a() {
    val n = readLine()!!.toInt()
    val a = readLine()!!.split(" ").map { it.toLong() }
    val b = readLine()!!.split(" ").map { it.toLong() }
    val c = readLine()!!.split(" ").map { it.toLong() }
    val head = a.sortedDescending()
    val middle = b.sortedDescending()
    val bottom = c.sortedDescending()
    val pattern = LongArray(n) { 0L }
    if (head.last() >= middle.first() || middle.last() >= bottom.first()) {
        // 上部のパーツの最も小さいものでさえ、下部の最も大きいパーツより大きいのであればそもそも祭壇を組めない
        println(0)
        return
    }
    var j = n - 1
    // 一度に中段・上段の組み合わせ＋DPの更新をやろうとしてるからおかしくなるのだろうか
    // 上段と中段のみで作れる祭壇の組み合わせを計算する
    for (i in n - 1 downTo 0) {
        if (i < middle.lastIndex) pattern[i] += pattern[i + 1]
        while (j >= 0 && head[j] < middle[i]) {
            j--
        }
        // head[j]がmiddle[i]より大きいindexが示されているので
        j = (j + 1).coerceAtMost(n - 1)
        if (head[j] < middle[i]) {
            pattern[i] += (n - j).toLong()
        }
    }
    // 計算したパターンを使って下部と中段で作れる組み合わせのパターンを求めていく
    var count = 0L
    j = 0
    for (i in 0 until n) {
        while (j < n && middle[j] >= bottom[i]) {
            j++
        }
        count += if (j < n) pattern[j] else 0L
    }
    println(count)
}

Measured memory_bytes: 69860
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <tuple>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<double, double> P;
typedef tuple<int, int, int> T;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

string s;
int q;
int t[200100], f[200100];
char c[200100];

string solve() {
    deque<char> dq;
    for (char a : s) {
        dq.push_back(a);
    }

    int r = 0;
    for (int i = 0; i < q; i++) {
        if (t[i] == 1) {
            r = 1 - r;
        } else if ((r == 0 && f[i] == 1) || (r == 1 && f[i] == 2)) {
            dq.push_front(c[i]);
        } else {
            dq.push_back(c[i]);
        }
    }

    string res = "";
    if (r == 0) {
        while (!dq.empty()) {
            res += dq.front(); dq.pop_front();
        }
    } else {
        while (!dq.empty()) {
            res += dq.back(); dq.pop_back();
        }
    }
    return res;
}

void input() {
    cin >> s >> q;
    for (int i = 0; i < q; i++) {
        cin >> t[i];
        if (t[i] == 2) {
            cin >> f[i] >> c[i];
        }
    }
}

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

    input();
    cout << solve() << endl;
}


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

int factorial(int n) {
    int x=1;
    for (int i=1; i<=n; i++) x*=i;
    return x;
}

int main() {
    int n;
    double n2;
    cin>>n;
    n2=factorial(n);
    double sum=0;
    vector<int> x(n),y(n),a(n);
    rep(i,n) {
        cin>>x[i]>>y[i];
        a.at(i)=i;
    }
    do {
        rep(i,n-1) {
            sum+=sqrt(pow((x[a[i]]-x[a[i+1]]),2)+pow((y[a[i]]-y[a[i+1]]),2));
        }
    }while(next_permutation(a.begin(),a.end()));
    sum/=n2;
    printf("%.10f\n",sum);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FOR(i,a,b) for(int i=a;i<=b;i++)
using namespace std;

typedef unsigned long long ULL;
typedef long long ll;

int n;

struct node{
    double x,y;
    char dir[4];
}A[100050];

double cal(double x){
    double ml=1e10,mr=-1e10,mu=-1e10,md=1e10;
    FOR(i,1,n){
        pair<double,double>tmp;
        tmp.first=A[i].x,tmp.second=A[i].y;
        switch(A[i].dir[0]){
            case 'U':tmp.second+=x;break;
            case 'D':tmp.second-=x;break;
            case 'L':tmp.first-=x;break;
            case 'R':tmp.first+=x;break;
        }
        ml=min(ml,tmp.first);
        mr=max(mr,tmp.first);
        mu=max(mu,tmp.second);
        md=min(md,tmp.second);
    }
    //cout<<x<<" "<<(mr-ml)*(mu-md)<<endl;
    return (mr-ml)*(mu-md);
}

int main(){
    cin>>n;
    FOR(i,1,n){
        scanf("%lf%lf%s",&A[i].x,&A[i].y,A[i].dir);
    }
    double l=0,r=1e12,ans=1e18;
    FOR(k,0,300){
        double m1=(l+(r-l)/3),m2=(l+(r-l)*2/3);
        double tmp1=cal(m1),tmp2=cal(m2);
        if(tmp1>tmp2)l=m1;
        else r=m2;
        ans=min(ans,tmp1);
        ans=min(ans,tmp2);
    }
    printf("%.10f",ans);
}

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

int main() {
  int n; cin >> n;
  int cnt = 0;
  for (int i = 0; i < n; ++i) {
    int p; cin >> p;
    if (p != i + 1) ++cnt;
  }
  cout << (cnt <= 2 ? "YES" : "NO") << endl;
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/arc081/tasks/arc081_b
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
const int MOD = (int)1e9 + 7;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    string s1, s2;
    cin >> s1 >> s2;
    ll ans = 1;
    int status = 0;
    REP(i, n) {
        // 縦が不一致
        if (s1[i] != s2[i]) {
            if (status == 0) {
                ans *= 6;
            } else if (status == 1) {
                ans *= 3;
            } else {
                ans *= 2;
            }
            status = 1;
            i++;
        } else {
            if (status == 0) {
                ans *= 3;
            } else if (status == 2) {
                ans *= 2;
            }
            status = 2;
        }
        ans %= MOD;
    }
    cout << ans << endl;
    return 0;
}


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

int main(){
  int A, B;
  double T;

  cin >> A >> B >> T;

  T += 0.5;
  int counter;
  counter = T / A;
  
  counter *= B;

  cout << counter << endl;

}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
   int N = sc.nextInt();
   if(N <10) System.out.println(N);
   else if (N<100) System.out.println(9);
   else if (N<1000) System.out.println(N - 90);
   else if (N<10000) System.out.println(909);
   else if (N<100000) System.out.println(N - 9090);
   else System.out.println(90909);
 }
}

Measured memory_bytes: 23764
#include<iostream>
#define ll long long 
int n,m,k;
ll dp[150][20];
ll pre[9];
int main()
{
    std::cin>>n>>m>>k;
    for (int i=0; i<m; ++i)
    {
        dp[0][i]=i==0;
        pre[i]=(i<2)?1:pre[i-1]+pre[i-2];
    }
    for (int i=1; i<=n; ++i)
        for (int j=0; j<m;++j)
            dp[i][j]=(dp[i-1][j]*pre[j]*pre[m-j-1]+(j>0)*dp[i-1][j-1]*pre[j-1]*pre[m-j-1]+(j<m-1)*dp[i-1][j+1]*pre[j]*pre[m-j-2])%1000000007;
    std::cout<<dp[n][k-1];
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n, y;
  cin >> n >> y;
  int a=-1,b=-1,c=-1;
  for (int i=0;i<=n;i++){
    for (int j=0;j<=n-i;j++){
      if(10000*i+5000*j+1000*(n-i-j)==y){
        a=i;
        b=j;
        c=n-i-j;
      }
    }
  }
  cout << a << ' ' << b << ' ' << c << endl;
}

Measured memory_bytes: 256
S = input()
n = len(S)

cnt1 = 0   #10101010...に必要な回数
cnt2 = 0   #01010101...
#min(cnt1, cnt2)
for i in range(n):
    if i % 2 == 0:
        if S[i] == '0':
            cnt1 += 1
        else:
            cnt2 += 1
    else:
        if S[i] == '1':
            cnt1 += 1
        else:
            cnt2 += 1
            
print(min(cnt1, cnt2))

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


//TEMPLATE
#define pb              push_back
#define mp              make_pair
#define ll              long long
#define ld              long double
//#define pi              3.1415926536
#define pi              acos(-1)
//#define mod             1000000007
#define newline         printf("\n")
#define printminusone   printf("-1\n")
#define scl1(n)         scanf("%lld", &n)
#define scl2(a, b)      scanf("%lld %lld", &a, &b)
#define scl3(a, b, c)   scanf("%lld %lld %lld", &a, &b, &c)
#define printl(n)       printf("%lld\n", n)
#define ssl1(str)       scanf(" %[^\n]", str)
#define scd1(n)         scanf("%lf", &n)
#define scd2(a, b)      scanf("%lf %lf", &a, &b)
#define printd(n)       printf("%lf\n", n)
#define printld(n)      printf("%Lf\n", n)
#define printcase       printf("Case %lld: ", i)
#define reversed(s)     reverse(s.begin(), s.end())
#define asorted(s)      sort(s.begin(), s.end())
#define dsorted(s)      sort(s.begin(), s.end(), cmp)
#define for0(i, n)      for (i = 0; i < n; i++)
#define for1(i, n)      for (i = 1; i <= n; i++)
#define fori(itt, stt)  for(itt = stt.begin(); itt != stt.end(); itt++)
#define pii             pair <ll, ll>
#define piii            pair <ll, pii>
//#define SIZE            100005
//#define INF             1000000005
#define F               first
#define S               second
#define FR              ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ms(arr, x)      memset(arr, x, sizeof arr)
#define bitcount(n)     __builtin_popcountll(n)

const ll INF = 1e18;
const ll SIZE = 1e5+5;
const ll mod = 1e9+7;


bool ok1, ok2;

int main() {
    ll t = 0, n, x, y, z, i, j, k, g, p, q, ans = 0, sum = 0, c = 0;
    string s, s1, s2;

//    cin >> n >> k >> s;
//
//    s[k-1] += 32;
//
//    cout << s << "\n";

    cin >> s;


    if(s[0] >= '0' && s[0] <= '9' && s[1] >= '0' && s[1] <= '9') {
        if((s[2] == '0' && s[3] >= '1' && s[3] <= '9') || (s[2] == '1' && (s[3] == '1' || s[3] == '2'))) {
            ok1 = 1;
        }
    }

    if((s[0] == '0' && s[1] >= '1' && s[1] <= '9') || (s[0] == '1' && (s[1] == '1' || s[1] == '2'))) {
        if(s[2] >= '0' && s[2] <= '9' && s[3] >= '0' && s[3] <= '9') {
            ok2 = 1;
        }
    }

    if(ok1 && ok2) puts("AMBIGUOUS");
    else if(ok1) puts("YYMM");
    else if(ok2) puts("MMYY");
    else puts("NA");


    return 0;
}



Measured memory_bytes: 256
from collections import Counter
N = int(input())
blue = Counter()
for _ in range(N):
    blue[input()] += 1

M = int(input())
red = Counter()
for _ in range(M):
    red[input()] += 1


res = 0
for k in blue.keys():
    res = max(blue[k]-red[k], res)

print(res)

Measured memory_bytes: 3316
#include<bits/stdc++.h>
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
const int N=2e5+5;
ll p[N];
int pre[N],bk[N],ans[N];
int n;
char s[N];
int get(int x)
{
    int ans=0;
    while(x)
        x=x%__builtin_popcount(x),ans++;
    return ans;
}
void solve(int x,int sum)
{
    if(sum<=0) return;
    p[0]=1;for(int i=1;i<N;i++) p[i]=p[i-1]*2%sum;
    for(int i=1;i<=n;i++)
        pre[i]=(pre[i-1]+(s[i]=='1')*p[i-1])%sum;
    for(int i=n;i>=1;i--)
        bk[i]=(bk[i+1]+(s[i]=='1')*p[i-1])%sum;
    for(int i=1;i<=n;i++)
        if(x==1&&s[i]=='1')
    {
        int res=(pre[i-1]+bk[i+1])%sum;
        ans[i]=1+get(res);
    }
    else if(x==0&&s[i]=='0')
    {
        int res=(pre[i-1]+bk[i+1]+p[i-1])%sum;
        ans[i]=1+get(res);
    }
}
int main()
{
    scanf("%d%s",&n,s+1);
    reverse(s+1,s+1+n);
    int sum=0;
    for(int i=1;i<=n;i++) sum+=s[i]=='1';
    solve(1,sum-1);
    solve(0,sum+1);
    reverse(ans+1,ans+1+n);
    for(int i=1;i<=n;i++) printf("%d\n",ans[i]);
}


Measured memory_bytes: 7852
n, m, l = map(int, input().split())
gyouretsu1 = []
gyouretsu2 = []
gyouretsu_ans = []
for i in range(n):
  gyouretsu1.append(list(map(int, input().split())))
for i in range(m):
  gyouretsu2.append(list(map(int, input().split())))
for i in range(n):
  gyou = []
  for j in range(l):
    factor = 0
    for k in range(m):
      factor += gyouretsu1[i][k]*gyouretsu2[k][j]
    gyou.append(str(factor))
  print(" ".join(gyou))


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

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

  int r;cin>>r;
  cout<<(3*r*r)<<endl;

  return 0;
}


Measured memory_bytes: 256
def gcd(x,y):
    if y == 0:
        return x
    elif x == 1 or y == 1:
        return 1
    else:
        return gcd(y,x%y)

G = []
i,j = 1,1
while i < 201:
    j = 1
    g0 = []
    while j < 201:
        g0.append(gcd(i,j))
        j += 1
    g0 = tuple(g0)
    G.append(g0)
    i += 1
n = int(input())
i = 1
j = 1
k = 1
ans = 0
while i < n+1:
    j = 1
    while j < n+1:
        k = 1
        p = G[i-1][j-1]
        while k < n+1:
            ans += G[k-1][p-1]
            k += 1
        j += 1
    i += 1
print(ans)

Measured memory_bytes: 9528
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <tuple>
#include <cassert>
#include <exception>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<P> vp;
#define rep(i,a,n) for(ll i = (a);i < (n);i++)
#define per(i,a,n) for(ll i = (a);i > (n);i--)
#define lep(i,a,n) for(ll i = (a);i <= (n);i++)
#define pel(i,a,n) for(ll i = (a);i >= (n);i--)
#define clr(a,b) memset((a),(b),sizeof(a))
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define sz size()
#define print(X) cout << (X) << endl
static const int INF = 1e+9+7;
ll n,m,l;
string s,t;
int d[200010],dp[1010][1010];
double w[1000],v[1000];
double box[200010];

int main(){
  while(1){
    int a[101],b[101];
    cin >> n >> m;
    if(!n && !m)break;
    int suma = 0,sumb = 0;
    bool f = false;
    rep(i,0,n){
      cin >> a[i];
      suma += a[i];
    }
    rep(i,0,m){
      cin >> b[i];
      sumb += b[i];
    }
    sort(a,a+n);
    sort(b,b+m);
    rep(i,0,n){
      rep(j,0,m){
        if(suma - a[i] + b[j] == sumb - b[j] + a[i]){
          cout << a[i] << " " << b[j] << endl;
          f = true;
          break;
        }
      }
      if(f)break;
    }
    if(f)continue;
    puts("-1");
  }
  return 0;
}


Measured memory_bytes: 3112
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
int a[100010];
bool pos[100010] = {};
int main(){
  int n, m;
  cin >> n >> m;
  pos[1] = true;
  for (int i = 1; i <= n; i++) {
    a[i] = 1;
  }
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    a[x]--;
    a[y]++;
    if (pos[x]) {
      if (a[x] == 0) {
        pos[y] = 1;
        pos[x] = 0;
      } else {
        pos[y] = 1;
      }
    }
  }
  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    cnt += pos[i];
  }
  cout << cnt << endl;
  return 0;
}


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

int main(){
    int n, d, x;
    cin >> n ;
    cin >> d >> x;
    int a[n];
    rep(i, n) cin >> a[i];

    int res = 0, date = 1;
    for(int i=0; i<n; i++){
        res++; // 一日目
        date = 1;
        while(true){
            date += a[i];
            if(date <=d){
                res++;
            }else if(date > d){
                break;
            }
        }
    }
    cout << (res + x) << endl;
    return 0;
}

Measured memory_bytes: 3608
a,b,c = sorted(map(int,input().split()))
if a % 2 == b % 2:
  d1 = (b - a) // 2
  d2 = c - b
  print(d1 + d2)
else:
  d1 = (b - a) // 2
  d1 += 1
  d2 = c - b
  d2 += 1
  print(d1 + d2)

Measured memory_bytes: 3060
# One Quadrillion and One Dalmatians
from string import ascii_lowercase as alp
N = int(input())

# 27進法に直す
def f(n):
    digits = []
    while n != 0:
        n -= 1
        rem = n % 26
        digits.append(rem)
        n = n // 26
    return digits

ans = ''.join([alp[e] for e in f(N)])[::-1]
print(ans)

Measured memory_bytes: 9880
#include <iostream>
#include <algorithm>
#include <math.h> 
#include <string>
#include <iomanip>
#include <vector>
#include <chrono>
using namespace std;
using namespace std::chrono;
int main(){
    int a, b;
    cin >> a >> b;
    string s;
    cin >> s;
    int count = 0;
    if(s.length() == a+b+1 && s[a] == '-'){
        for(int i = 0; i < s.length(); i++){
            if(s[i] == '-') count++;
        }
        if(count == 1) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    else cout << "No" << endl;
}

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

using namespace std;

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

int main(){
    int i;
    //入力
    long long h;
    cin>>h;
    //処理
    long long cou=0,b=0;
    while(h>1){
        cou++;
        h=h/2;
    }
    
    b=pow(2,cou+1)-1;
    
    //出力
    cout<<b<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define SZ(vvv) ((int)vvv.size())
#define fastIO cout << fixed << setprecision(12), ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
using namespace std;

const int N = 5e5 + 5, M = 5e4 + 9, INF = 1e9, MOD = 998244353;

int freq[N], L[12], R[12];

int add(ll x, int y) {
	x += y;
	while(x >= MOD)
		x -= MOD;
	while(x < 0)
		x += MOD;
	return x;
}

int mul(int x, int y) {
	return (1ll * x * y) % MOD;
}

int fastpow(int x, int pow) {
	int ret = 1;
	while(pow) {
		if(pow & 1)
			ret = mul(ret, x);
		pow /= 2;
		x = mul(x, x);
	}
	return ret;
}

int sub(int x, int y) {
	return (x - y + MOD) % MOD;
}

int modInv(int x) {
	return fastpow(x, MOD - 2);
}

int divide(int x, int y) {
	return mul(x, modInv(y));
}

void runtestcase() {
	int n, k;
	cin >> n >> k;
	for (int i = 0; i < k; ++i)
		cin >> L[i] >> R[i];
	freq[1] = 1;
	freq[2] = -1;
	for (int i = 1; i <= n; ++i) {
		freq[i] = add(freq[i], freq[i - 1]);
		for (int j = 0; j < k; ++j) {
			int l = i + L[j], r = i + R[j];
			r = min(r, n);
			if(l > r) continue;
			freq[l] = add(freq[l], freq[i]);
			freq[r + 1] = sub(freq[r + 1], freq[i]);
		}
	}
	cout << freq[n];
}


int main() {
    fastIO;
#ifdef LOCAL
    freopen("input.in", "rt", stdin);
//    freopen("cache.out", "wt", stdout);
#endif
  int t = 1, tt = 1;
//	cin >> t;
  while(t) {
//		cout << "Case #" << tt << ':' << ' ';
    runtestcase();
    if(t)
    	cout << '\n';
    --t, ++tt;
  }
}


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

void fnInput(vector<int> &rvnTrg, vector<int> &rvnSch)
{
  int nTrgCnt;
  cin >> nTrgCnt;

  rvnTrg.resize(nTrgCnt);
  for (int i = 0; i < nTrgCnt; i++)
    cin >> rvnTrg[i];

  int nSchCnt;
  cin >> nSchCnt;

  rvnSch.resize(nSchCnt);
  for (int i = 0; i < nSchCnt; i++)
    cin >> rvnSch[i];
}

void fnBinSch(const vector<int> &cnrvnTrg, const vector<int> &cnrvnSch, int &rnFnd)
{
  for (int i = 0; i < cnrvnSch.size(); i++)
  {
    int nLow  = 0;
    int nHigh = cnrvnTrg.size();
    while (nLow < nHigh)
    {
      int nMid = (nLow + nHigh) / 2;
      if (cnrvnSch[i] == cnrvnTrg[nMid])
      {
        rnFnd++;
        break;
      }
      else if (cnrvnSch[i] < cnrvnTrg[nMid])
        nHigh = nMid;
      else
        nLow  = nMid + 1;
    }
  }
}

void fnResult(int nFnd)
{
  cout << nFnd << endl;
}

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

  vector<int> vnTrg, vnSch;
  int nFnd = 0;

  fnInput(vnTrg, vnSch);
  fnBinSch(vnTrg, vnSch, nFnd);
  fnResult(nFnd);

  return 0;
}

Measured memory_bytes: 3332
n = int(input())
a = []
for i in range(n):
	a.append([int(n) for n in input().split()])
	a[i][0], a[i][2] = a[i][2], a[i][0]
a = sorted(a)
for x in range(101):
	for y in range(101):
		h = a[n - 1][0] + abs(x - a[n - 1][2]) + abs(y - a[n - 1][1])
		for k in range(n):
			d = h - abs(x - a[k][2]) - abs(y - a[k][1])
			if a[k][0] != max(d, 0):
				break
			if k == n - 1:
				print(x, y, h)
				exit()

Measured memory_bytes: 3064
N, K = map(int, input().split())

flag = True

min = N

if K == 1:
    ans = 0
elif N % K == 0:
    ans = 0
elif abs(N - K) > N:
    ans = N
else:
    if (N % K) > (K / 2):
        ans = abs((N % K) - K)
    else:
        ans = N % K

print(ans)


Measured memory_bytes: 3060
import sys
import numpy as np

input = sys.stdin.readline
n, m = map(int, input().split())
x_list = list(map(int, input().split()))
x_list.sort()
dis_list = []
start = x_list[0]
for i in range(1, m):
    dis_list.append(abs(start-x_list[i]))
    start = x_list[i]
dis_list.sort(reverse=True)
ans = sum(dis_list[n-1:])
print(ans)


Measured memory_bytes: 23016
#include <cstdio>
#include <iostream>
#include <queue>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>

using namespace std;
int main(){
    long long unsigned int i,n,a_i,b_i;
    cin >> n;
    vector<pair<long long unsigned int,long long unsigned int>>ba;
    for(i=0;i<n;i++){
        cin>>a_i>>b_i;
        ba.push_back(make_pair(b_i,a_i));
    }
    sort(ba.begin(),ba.end());
    long long unsigned int sum=0;
    for(auto j=0;j!=ba.end()-ba.begin();j++){
        sum+=ba[j].second;
        if(sum>ba[j].first){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 6512