akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
long long dp[3005][3005]; // curr len with last digit is j
long long prefix[3005][3005]; 
int main(){
  int n;string s;
  cin>>n>>s;
  
  int len = s.length()+1;
  int mod = 1e9+7;
  dp[1][1] = 1;
  prefix[1][1] = 1;
  for(int i=2;i<=len;++i){
    for(int curr=1;curr<=i;++curr){
      int sindex = i-2;
        if(s[sindex]=='>'){
          // from curr to i-1
          dp[i][curr] += (prefix[i-1][i-1] + mod - prefix[i-1][curr-1])%mod;
          dp[i][curr] %= mod;
          prefix[i][curr] = dp[i][curr];
        }
        if(s[sindex]=='<'){
          // fomr 1 to curr -1 
          dp[i][curr] += (prefix[i-1][curr-1] + mod - prefix[i-1][0])%mod;
          dp[i][curr] %= mod;
          prefix[i][curr] = dp[i][curr];
        } 
    }
	for(int j=1;j<=i;++j){
		prefix[i][j] += prefix[i][j-1];
        prefix[i][j] %= mod;
	}
  }
  cout<<prefix[len][len]<<endl;
  return 0;
}


Measured memory_bytes: 139648
//😄😄😄😄😄😄😄😄😄😄😄😄😄
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pi pair<int,int>
#define vp vector<pi>
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define For(i,a,b) for(int i=a;i<b;i++)
#define debug(x) cout<<"DEBUG------> "<<#x<<" -> "<<x<<endl
#define endl "\n"
#define all(x) x.begin(),x.end()

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int a; cin >> a;
	cout << a + a*a + a*a*a << endl;
	return 0;
}



Measured memory_bytes: 3644
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define ll long long

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

  ll N,X,b,ans = 1; cin >> N >> X;
  ll dist = 0;
  for (ll i = 0; i < N; ++i) {
  	cin >> b;
    dist += b;
    if (dist <= X) ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        var AP = ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
        var (A, P) = (AP[0], AP[1]);
        var ans = (A * 3 + P) / 2;

        WriteLine(ans);
    }
}


Measured memory_bytes: 27928
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main( String[] args ) {	
          
		Scanner input = new Scanner (System.in);
		int n = input.nextInt();
		int []  arr = new int [n];
		int []  arr2 = new int [n];
		for (int i = 0; i < n ; i++) {
	
           		arr[i] = input.nextInt();
           		arr2[i] = arr[i];
			
		}
		
		Arrays.sort(arr2);
int c =0 ;
		for (int i =0 ; i < n ;i++) {
			
			if (arr[i]!= arr2[i]) {
				c++;
			}
		}
		if (c<=2) {
			System.out.println("YES");
		}
		else {
			System.out.println("NO");
		}
		input.close();
		
	} 
	
}

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

int main()
{
    int n;
    string str;

    cin>>n>>str;

    if(n%2 != 0)
        cout<<"No";
    else{
        if(str.substr(0, (n/2)) == (str.substr((n/2), (n/2))))
            cout<<"Yes";
        else
             cout<<"No";
    }

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#ifdef ENABLE_DEBUG
#define dump(a) cerr<<#a<<"="<<a<<endl
#define dumparr(a,n) cerr<<#a<<"["<<n<<"]="<<a[n]<<endl
#else
#define dump(a) 
#define dumparr(a,n) 
#endif
#define FOR(i, a, b) for(int i = a;i < b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(int i = b-1;i >= a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)

typedef long long int ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<ll, ll> pll;
typedef pair<ll,pll> ppll;
typedef vector<ll> vll;

const ll INF=(1LL<<50);

template<class S,class T>
std::ostream& operator<<(std::ostream& os,pair<S,T> a){
  os << "(" << a.first << "," << a.second << ")";
  return os;
}
template<class T>
std::ostream& operator<<(std::ostream& os,vector<T> a){
  os << "[ ";
  REP(a.size()){
    os<< a[i] << " ";
  }
  os<< " ]";
  return os;
}


void solve(long long A, long long B, long long C){
  cout<<max(0LL,C-(A-B))<<endl;
}

int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long C;
    scanf("%lld",&C);
    solve(A, B, C);
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    // Your code here!

    int H,W;
    while(1){
      scanf("%d %d",&H,&W);
      if((H+W)==0)break;
      for(int i=0; i<W; i++){
        printf("#");
      }  printf("\n");
      for(int i=0; i<H-2; i++){  
        printf("#");
        for(int i=0; i<W-2; i++){
          printf(".");
        } printf("#\n");
      }
      for(int i=0; i<W; i++){
        printf("#");
      }  printf("\n\n");
      
    }
      
}



Measured memory_bytes: 1992
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define per(i,a,b) for(int i =(b)-1;i>=(a);--i)
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define sz(x) (int) (x).size()
#define mp make_pair
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef double db;
typedef vector<int> vi;
const int mod = 1e9 + 7;
const int maxn = 2e6 + 10;
int f[maxn]; 
vi edge[maxn];
int a[maxn];
int ans[maxn];
vi lsh;
void dfs(int x,int fa,int len){
	if(a[x] > f[len]){
		f[++len] = a[x];
		ans[x] = len;
		for(auto it:edge[x]){
			if(it != fa)
				dfs(it,x,len);
		}
		f[len] = -1;
		--len;
	}
	else{
		int pos = lower_bound(f,f+len,a[x]) - f;
		int count = f[pos];
		f[pos] = a[x]; 
		ans[x] = len;
		for(auto it:edge[x]){
			if(it != fa)
				dfs(it,x,len);
		}
		f[pos] = count;
	}
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	rep(i,1,n+1)cin >> a[i];
	rep(i,1,n){
		int u,v;
		cin >> u >> v;
		edge[u].pb(v);
		edge[v].pb(u);
	}
	memset(f,-1,sizeof(f));
	dfs(1,0,0);
	rep(i,1,n+1)cout << ans[i] << '\n';	
	return 0;
}


Measured memory_bytes: 80452
n = int(input())
total = []
for i in range(n):
    a, b, c = map(int, input().split())
    total.append((a,b,c))


dp = [[0 for i in range(3)] for j in range(n)]
dp[0][0] = total[0][0]
dp[0][1] = total[0][1]
dp[0][2] = total[0][2]

for i in range(1, n):
    dp[i][0] = total[i][0] + max(dp[i-1][1], dp[i-1][2])
    dp[i][1] = total[i][1] + max(dp[i-1][0], dp[i-1][2])
    dp[i][2] = total[i][2] + max(dp[i-1][0], dp[i-1][1])

print(max(dp[-1]))

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

struct Node{
    int key;
    struct Node *right, *left, *parent;
};

struct Node *root, *NIL;

struct Node *find(struct Node *u, int k){
  while(u != NIL && k != u->key){
    if(k < u->key)  u = u->left;
    else  u = u->right;
  }
  return u;
}

void insert(int k){
  struct Node *y = NIL;
  struct Node *x =root;
  struct Node *z;

  z = malloc(sizeof(struct Node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL){
    y = x;
    if(z->key < x->key) x = x->left;
    else  x = x->right;
  }
  z->parent = y;
  if(y == NIL)  root = z;
  else{
    if(z->key < y->key){
      y->left = z;
    }
    else{
      y->right = z;
    }
  }
}

void inorder(struct Node *u){
  if(u == NIL)  return ;
  inorder(u->left);
  printf(" %d", u->key);
  inorder(u->right);
}

void preorder(struct Node *u){
  if(u == NIL)  return ;
  printf(" %d", u->key);
  preorder(u->left);
  preorder(u->right);
}

int main(void){
  int n, i, x;
  char s[20];

  scanf("%d", &n);

  for(i = 0; i < n; i++){
    scanf("%s", s);
    if(s[0] == 'f'){
      scanf("%d", &x);
      struct Node *t = find(root,x);
      if(t != NIL)  printf("yes\n");
      else  printf("no\n");
    }
    else if(strcmp(s, "insert")==0){
      scanf("%d", &x);
      insert(x);
    }
    else if(strcmp(s ,"print")==0){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }
  return 0;
}



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

int main() {
  int N;
  cin >> N;
  vector<int> data(N);
  for(int i = 0; i < N ; i++) {
    cin >> data.at(i);
  }
  sort(data.begin(), data.end());
  bool ans = true;
  for(int i = 1; i < N; i++) {
    if(data.at(i - 1) == data.at(i)) {
      ans = false;
      break;
    }
  }
  if(ans) {
    cout << "YES" << endl;
  }
  else {
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define inf 2000000000
#define INF 1e18
typedef long long ll;
typedef pair<ll,ll> ii;
typedef pair<ii,ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
#define getbit(n,i) (((n)&(1LL<<(i)))!=0)
#define setbit0(n,i) ((n)&(~(1LL<<(i))))
#define setbit1(n,i) ((n)|(1LL<<(i)))
#define togglebit(n,i) ((n)^(1LL<<(i)))
#define lastone(n) ((n)&(-(n)))
#define read freopen("debug\\in.txt","r",stdin)
#define write freopen("debug\\out.txt","w",stdout)
#define fi first
#define se second
#define getI(a) scanf("%d",&a)
#define getII(a,b) scanf("%d%d",&a,&b)
#define PI (acos(-1))
#define fastread ios_base::sync_with_stdio(false);cin.tie(NULL)
#define mod (1000000007)
#define asz 500005
#define pb push_back
#define ppf pop_front
#define ppb pop_back
#define pf push_front
ll a[100005];
int main()
{
    fastread;
     ll i,j,k,n,m,y,t;
    cin>>n;
   // m=(ll)(pow(n,1/5));
    //cout<<m;
    ll res;
   for(i=-200;i<=200;i++){
   // k=(ll)(pow(i,5));
   for(j=-200;j<=200;j++){
    res=(i*i*i*i*i)-(j*j*j*j*j);
    if(res==n){
        cout<<i<<" "<<j;
        return 0;
              }
         }
     }
   return 0;
}

Measured memory_bytes: 3652
import java.util.*;
class Main{
     public static void main(String[] args){
         Scanner sc=new Scanner(System.in);
         while(true){
         int H = sc.nextInt();
         int W = sc.nextInt();
         if(H==0 && W==0)  break; 
         int i,j;
         for(i=0;i<H;i++)
         {
             for(j=0;j<W;j++)
             {
                 System.out.print("#");
             }
             System.out.println();
         }
         System.out.println();
     }
     }
}


Measured memory_bytes: 33008
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>
using namespace std;

int main() {
	long long int n,m,a,b,c,d,e;
	long double z,w;
	string str;
	char ch;
	long long int x[130]={};
	cout << fixed << setprecision(10);
	cin>>z>>w;
	cout<<z/w;



	cout<<endl;
} 


Measured memory_bytes: 256
#include <stdio.h>

void
priArr(int [], int);
void
sort(int [], int);

int
main(void)
{
    int arr[3];
    scanf("%d %d %d", arr, arr + 1, arr + 2);
    sort(arr, 3);
    priArr(arr, 3);
    return 0;
}

void
priArr(int arr[], int len)
{
    int i = 0;
    printf("%d", arr[i++]);
    for ( ; i < len; i++)
        printf(" %d", arr[i]);
    putchar('\n');
}

void
sort(int arr[], int len)
{
    int i, j, tmp;
    for (i = 1; i < len; i++) {
        tmp = arr[i];
        for (j = i - 1; j >= 0 && arr[j] > tmp; j--) {
            arr[j + 1] = arr[j];
        }
        arr[j + 1] = tmp;
    }
}


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

int n;

int main() {
    cin >> n;
    int a[n];
    for (int i=0; i<n; i++) cin >> a[i];
    sort(a, a+n);
    cout << a[0];
    for (int i=1; i<n; i++) cout << " " << a[i];
    cout << endl;
}


Measured memory_bytes: 10820
n = int(input())
lst = list(map(int, input().split()))
for i in range(1, n):
  lst[i] += lst[i - 1]
z = lst[-1]
res = 10 ** 20
for i in range(n - 1):
  res = min(res, abs(lst[i] - (z - lst[i])))
print(res)

Measured memory_bytes: 30644
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define INF 1e18
typedef pair<int,int> P;

struct edge{
    int to;
    int cost;
};

int V;
vector<edge> G[100001];
int d[100001];
void dijkstra(int s){
    priority_queue<P,vector<P>,greater<P>> que;
    fill(d,d+V+1,INF);
    d[s]=0;
    que.push(P(0,s));
    
    while(que.size()){
        P p=que.top();que.pop();
        int v=p.second;
        if(d[v]<p.first)continue;
        for(int i=0;i<G[v].size();i++){
            edge e=G[v][i];
            if(d[e.to]>d[v]+e.cost){
                d[e.to]=d[v]+e.cost;
                que.push(P(d[e.to],e.to));
            }
        }
    }
}

signed main(){
    cin>>V;
    for(int i=0;i<V-1;i++){
        int a,b,c;
        cin>>a>>b>>c;
        G[a].push_back({b,c});
        G[b].push_back({a,c});
    }
    int q,k;
    cin>>q>>k;
    dijkstra(k);
    for(int i=0;i<q;i++){
        int f,t;
        cin>>f>>t;
        cout<<d[f]+d[t]<<endl;
    }
    return 0;
}

Measured memory_bytes: 11120
#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll=long long;
using vi=vector<int>;
using vl=vector<long long>;
using pii=pair<int,int>;
using pll=pair<long long,long long>;
#define ITR(i,c) for(auto i=begin(c);i!=end(c);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define REPW(i,n) for(i=0;i<(int)(n);++i)
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)   // c++14
#define SZ(c) ((int)c.size())
#define EXIST(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) (y<0||x<0||y>=h||x>=w)
#define dump(...)
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
#define INF (1001001001)
#define INFLL (1001001001001001001ll)
template<class T> ostream& operator << (ostream &os,const vector<T> &v) {
    ITR(i,v) os << *i << (i==end(v)-1 ? "" : "\n"); return os; }
template<class T> istream& operator >> (istream &is,vector<T> &v) {
    ITR(i,v) is >> * i; return is; }
template<class T> istream& operator >> (istream &is, pair<T,T> &p) {
        is >> p.first >> p.second; return is; }
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
//------------------------------------------------------------------------------
struct before_main_function {
    before_main_function() {
        #ifdef int
            #undef INF
            #define INF INFLL
            #define stoi stoll
        #endif
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
    }
} before_main_function;
//------------------------------------------------------------------------------

signed main() {
    int a,b;
    cin>>a>>b;
    cout<<(a+b>=10?"error":to_string(a+b))<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);

  int N, T, t, tt;

  std::cin >> N >> T >> t;

  long long S = T;

  for (int i = 1; i < N; i ++) {
    std::cin >> tt;

    S += std::min(T, tt - t);
    
    t = tt;
  }

  std::cout << S << std::endl;

  return 0;
}


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

const int MAXN = 5 + 100000;
int N;
int h[MAXN];
int memo[MAXN];

int dp(int i) {
    if(i == 0) {
        return 0;
    }
    int& ans = memo[i];
    if(ans == -1) {
        ans = abs(h[i] - h[i - 1]) + dp(i - 1);
        if(i - 2 >= 0) {
            ans = min(ans, abs(h[i] - h[i - 2]) + dp(i - 2));
        }
    }
    return ans;
}

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    cin >> N;
    foi(i,0,N) {
        cin >> h[i];
    }
    memset(memo, -1, sizeof memo);
    cout << dp(N - 1) << '\n';
    return 0;
}


Measured memory_bytes: 4224
#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 30;

inline void chmin(int& a, int b)
{
  a = min(a, b);
}

int main()
{
  int N;
  string S[14];
  int dp[1 << 14][14];
  int match[14][14];
                    
  while(cin >> N, N) {
    for(int i = 0; i < N; i++) {
      cin >> S[i];
    }

    int Mask = 0;
    for(int i = 0; i < N; i++) {
      for(int j = 0; j < N; j++) {
        if(i == j) continue;
        match[i][j] = S[j].size();
        if(S[i].find(S[j]) != string::npos) {
          Mask |= 1 << j;
          continue;
        }
        for(int k = min(S[i].size(), S[j].size()); k >= 1; k--) {
          if(S[i].substr(S[i].size() - k, k) == S[j].substr(0, k)) {
            chmin(match[i][j], S[j].size() - k);
            break;
          }
        }
      }
    }
    
    fill_n(*dp, (1 << 14) * 14, INF);
    for(int i = 0; i < N; i++) dp[Mask | (1 << i)][i] = S[i].size();
    for(int i = 0; i < 1 << N; i++) {
      for(int j = 0; j < N; j++) {
        if(!((i >> j) & 1)) continue;
        for(int k = 0; k < N; k++) {
          if((i >> k) & 1) continue;
          chmin(dp[i | (1 << k)][k], dp[i][j] + match[j][k]);
        }
      }
    }
    int ret = INF;
    for(int i = 0; i < N; i++) chmin(ret, dp[(1 << N) - 1][i]);
    cout << ret << endl;
  }
}

Measured memory_bytes: 2108
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000000 + 7
#define vpi vector<pair<int, int>>
#define ll long long int
#define MAX 1000000
#define minus_inf -1000000000

int main(){
    // int t; cin>>t;while(t--){
        int N, M; cin>>N>>M;
        int ans = 0;
        if(N>=2) ans += (N*(N-1))/2;
        if(M>=2) ans += (M*(M-1))/2;
        cout<<ans<<endl;
    // }
}

Measured memory_bytes: 256
MOD = 10 ** 9 + 7

S = input()
N = len(S)

dp = [[0 for _ in range(13)] for _ in range(N + 5)]
dp[0][0] = 1

for i, s in enumerate(S):
    if s == "?":
        c = -1
    else:
        c = int(s)

    for j in range(10):
        if c != -1 and c != j:
            continue

        for r in range(13):
            dp[i + 1][(r * 10 + j) % 13] += dp[i][r]

        for r in range(13):
            dp[i + 1][r] %= MOD

print(dp[N][5])


Measured memory_bytes: 67036
#include<iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <map>
#include <bitset>
#include <stack>
#include <queue>
#include <fstream>

using namespace std;
using ll=long long;

#define PRI(n) cout << n <<endl;
#define PRI2(n, m) cout << n << " " << m << endl;
#define PRI3(n, m, o) cout << n << " " << m<< " " << o << endl;

#define REP(i, n)  for(int i = 0; i < (int)n; ++i)
#define REPInv(i, n)  for(int i = n-1; i >= 0; --i)

#define FOR(i, t, n)  for(int i = t; i <= (int)n; ++i)
#define FORInv(i, t, n)  for(int i = t; i >= (int)n; --i)

const char alphabet[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
                           's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
const ll MOD = 1e9 + 7;

ll GCD(ll a, ll b) {
    if (b == 0)return a;
    return GCD(b, a % b);
}

ll LCM(ll a, ll b) {
    ll gcd = GCD(a, b);
    return a / gcd * b;
}

ll nCr(int n, int r) {
    vector<ll> C(r + 1);
    C[0] = 1;
    FOR(i, 1, n) FORInv (j, min(i, r), 1)C[j] = (C[j] + C[j - 1]) % MOD;
    return C[r];
}

struct edge {
    int to, cost;
    bool flag = false;
};
double N, M;
int A;
string S;
vector<edge> X[100010];
bool B[100010];
int D[100010];

int main() {
    cin >> N >> M;
    REP(i, N)cin >> D[i];
    ll cnt = 0;
    FOR(i, 1, N - 1) {
        if (D[i - 1] + D[i] > M) {
            if (D[i - 1] + D[i] - M > D[i]) {
                cnt += D[i];
                D[i] = 0;
                cnt += D[i - 1] - M;
                D[i-1] -= D[i - 1] - M;

            } else {
                cnt += D[i - 1] + D[i] - M;
                D[i] -= D[i - 1] + D[i] - M;
            }
        }
    }
    PRI(cnt)
    return 0;

}

Measured memory_bytes: 2944
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * y / gcd(x, y); }

long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{
	auto N = RD;
	auto a = new long[](N+1);
	a[0] = 2;
	a[1] = 1;
	foreach (i; 2..N+1)
	{
		a[i] = a[i-1] + a[i-2];
	}

	writeln(a[N]);
	stdout.flush();
	debug readln();
}

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

using namespace std;
#define Pi acos(-1)
#define _terminated return 0
#define endl "\n"
#define yes cout << "yes" << endl 
#define no cout << "no" << endl 
#define booster ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);


typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<long> > v2l;

const int mod = 1e+5;
const int mx = 2e+5;
const ll inf = 1e18;

using namespace std;
#define max 101 
void solvio(){ 	
     int N,L; 
     string S[max];
     cin >> N >> L; 
     for(int i=0; i<N; i++)
         cin >> S[i];
         sort(S,S+N);
     for(int i=0;i<N;i++) 
         cout << S[i]; cout << endl; 
}

int main(){ 
    booster;
    solvio(); 
    _terminated;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
//const int64 INF = 1LL << 58;
#define dame { puts("-1"); return 0;}
#define YES { cout << "YES" << endl; return 0; }
#define NO { cout << "NO" << endl; return 0; }
#define Yes { cout << "Yes" << endl; return 0; }
#define No { cout << "No" << endl; return 0; }
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};


int eras(int x){
	int cnt = 0;
	rep1(i,x+1){
		if(x%i==0){cnt++;}
	}
	return cnt;
}


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

	int n;
	cin >> n;
	int ans = 0;
	rep1(i,n+1){
		if(i%2==1 && eras(i)==8) {ans++;}
		//cout << i << endl;
	}
	cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int K, S;

int main() {
    cin >> K >> S;

    long long ans = 0;

    for (int i = 0; i <= K; i++)
        for (int j = 0; j <= K; j++) {
            if(0<=S-i-j&&S-i-j<=K)
                ans++;
        }
    cout << ans << endl;
    return 0;
}

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

int main(){
  int a,b,ans=0;
  cin >> a >> b;
  for(int i=a;i<=b;i++){
    if(i/10000 == i%10000%1000%100%10 && i%10000/1000 == i/10%1000%100%10){
        ans+=1;
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
n, k = [int(x) for x in input().split()]

while n > abs(n-k):
    if k == 1:
        n = 0
        break
    elif n%k == 0:
        n = 0
        break

    if n > k:
        n = n%k
    else:
        n = abs(n-k)    
    

print(n)

Measured memory_bytes: 38256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const ll inf = 1e14;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	
	int n, m, l; cin >> n >> m >> l;
	vector<vector<ll>> d(n, vector<ll>(n, inf)), e(n, vector<ll>(n, inf));
	rep(i, m){
		int a, b, c; cin >> a >> b >> c; a--; b--;
		d[a][b] = d[b][a] = c;
	}
	rep(i, n) d[i][i] = 0;
	rep(k, n) rep(i, n) rep(j, n) d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
	
	rep(i, n) rep(j, n) if(d[i][j] <= l) e[i][j] = 1;
	rep(k, n) rep(i, n) rep(j, n) e[i][j] = min(e[i][j], e[i][k] + e[k][j]);
	
	int q; cin >> q;
	while(q--){
		int s, t; cin >> s >> t;
		ll ans = e[s - 1][t - 1];
		if(ans >= inf) ans = 0;
		cout << ans-1 << endl;
	}
	
	return 0;
}

Measured memory_bytes: 2048
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>

using namespace std;

#define forn(i, s, f) for (int i = s; i < f; i++)
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair <int, int>
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    int n;
    cin >> n;
    int x = 1, p;
    for (p = 0;; p++, x *= 2) 
        if (x > n) 
            break;
    x /= 2, p--;
    vector <pii> e;
    for (int i = p; i >= 0; i--) {
        if (n - x >= 0) {
            n -= x;
            e.pb({n, i});
        }
        x /= 2;
    }
    cout << p + 1 << " " << 2 * p + sz(e) - 1 << "\n";
    forn (i, 1, sz(e))
        cout << "1 " << p + 1 - e[i].sc << " " << e[i].fs << "\n";
    cout << "1 2 " << e[0].fs << "\n1 2 " << (1 << (p - 1)) + e[0].fs << "\n";
    forn (i, 1, p)
        cout << i + 1 << " " << i + 2 << " 0\n" << i + 1 << " " << i + 2 << " " << (1 << (p - i - 1)) << "\n";

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pie 3.142857143
#define ll long long int
#define fr(i,a,n) for(ll i=a;i<n;i++)
#define vi vector<int>
#define vlli vector<ll>
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define fv(i,a) for(auto i:a)
#define sz(a) int((a).size())
#define all(c) (c).begin(),(c).end()
#define frv(i,c) for(auto i = c.begin(); i != c.end(); i++)

void solve()
{
	ll n, k;
	cin >> n >> k;
	ll a[n];
	fr(i, 0, n)
	cin >> a[i];
	vlli d(n, INT_MAX);
	d[0] = 0;
	fr(i, 0, n)
	{
		fr(j, i + 1, i + k + 1)
		{
			if (j < n)
			{
				d[j] = min(d[j], d[i] + abs(a[j] - a[i]));
			}
		}
	}
	cout << d[n - 1] << endl;


}


int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen ("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t;
	//cin>>t;
	t = 1;
	while (t--)
	{
		solve();
	}


	return 0;
}

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

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<pair<int, int>, int> PP;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;

//------------------------------------------------------------------------------------------------------------------------------

int main(void) { 
    ll N;
    cin >> N;
    ll mi = INF;
    for (ll i = 1; i * i <= N; i++) {
        if (N % i == 0) { mi = min(mi, i + N / i - 2); }
    }
    cout << mi << endl;

}


Measured memory_bytes: 256
n,k = map(int, input().split())
p = list(map(int, input().split()))
dp = [0]*(n+1)
j = 0
for i in range(k):
    j += p[i]
dp[k] = j
for i in range(k, n):
    dp[i+1] = dp[i] + p[i] - p[i-k]
print((max(dp) + k) / 2)

Measured memory_bytes: 25060
//A.cpp
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <math.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b!=0?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
const ll mod=1e9+7;

int main(){
  ll n,k;
  cin >> n >> k;
  n %= k;
  if(abs(n-k) < n) printf("%lld\n", abs(n-k));
  else printf("%lld\n", n);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define ll long long
#define pi pair<int,int>
#define pl pair<ll,ll>
#define pd pair<double,double>
#define ld long double
#define pld pair<ld,ld>
#define lg length()
#define sz size()
#define pb push_back
#define INF 1000000005
#define LINF 1000000000000000005

int n;

ll dp[405][405],a[405],s[405];

void Calc(int l, int r){
    dp[l][r]=LINF;
    if(l==r){
        dp[l][r]=0;
        return;
    }
    for(int i=l;i<r;i++){
        dp[l][r]=min(dp[l][r],dp[l][i]+dp[i+1][r]+s[r]-s[l-1]);
    }
}

int32_t main(){
    ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();
    cin >> n;
    for(int i=1;i<=n;i++){
        cin >> a[i];
        s[i]=s[i-1]+a[i];
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n-i+1;j++){
            Calc(j,j+i-1);
        }
    }
    cout << dp[1][n];
}


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

int main(){
	int a, b;
	char op;

	while(1){
		cin >> a >> op >> b;

		if(op == '+'){
			cout << a + b << endl;
		}else if(op == '-'){
			cout << a - b << endl;
		}else if(op == '*'){
			cout << a * b << endl;
		}else if(op == '/'){
			cout << a / b << endl;
		}else{
			break;
		}
	}

	return(0);
}

Measured memory_bytes: 1160
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
typedef pair<int,int> Pint;
typedef pair<ll, ll> P;
//typedef pair<int, pair<int, int>> P;
//typedef tuple<int,int,int> T;
ll INFL = 1000000000000000010;//10^18 = 2^60
int INF = 2147483600;//10^9
ll MOD  = 1000000007;
vector<int> dy = {0,0,1,-1};
vector<int> dx = {1,-1,0,0};



int main(void){
    int N, K;
    cin >> N >> K;
    string S;
    cin >> S;
    for(int i = 0; i < N; i++){
        if(i != K-1){
            cout << S[i];
        }else{
            
            
            cout << char(S[i] + 0x20);
        }
    }
    cout << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll INF = 1000000000000000005;
int main()
{
    ll n,w,max_val=0,ans=0;
    cin>>n>>w;
    ll weights[n],values[n];
    for(ll i=0;i<n;i++)
    {
        cin>>weights[i]>>values[i];
        max_val += values[i];
    }
    ll dp[max_val+1];
    for(ll i=0;i<=max_val;i++) dp[i] = INF; 
    dp[0]=0;
    for(ll i=0;i<n;i++)
    {
        ll cur_val = values[i], cur_w = weights[i];
        for(ll havevalue = max_val - cur_val; havevalue >= 0; havevalue--)
        {
            dp[havevalue+cur_val] = min(dp[havevalue+cur_val],dp[havevalue]+cur_w);
        }
    }
    for(ll i=0;i<=max_val;i++)
    {
        if(dp[i]<=w) ans=i;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <math.h>
int main(){
    int n;
    double d;
    double x,y;
    scanf("%d %lf",&n,&d);
    int cnt;
    cnt=0;
    for(int i=0;i<n;i++){
        scanf("%lf %lf",&x,&y);
        //printf("%f",sqrt(x * x + y* y));
        if(d >= sqrt(x * x + y* y)){
            cnt++;
        }
    }
    printf("%d\n",cnt);
    return 0;
}


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

int main(){
  int64_t n;
  int64_t x;
  cin >> n >> x;
  vector<int64_t> a(n);
  for(int64_t i;i<n;i++){
    cin >> a.at(i);
  }
  
  int64_t cnt= 0;
  if(a.at(0) + a.at(1) > x){
    if(a.at(1) >= a.at(0) + a.at(1) - x){
      cnt += a.at(0) + a.at(1) - x;
      a.at(1) -= a.at(0) + a.at(1) - x;
    }else{
      cnt += a.at(0) + a.at(1) - x;
      a.at(0) -= a.at(0) + a.at(1) - x - a.at(1);
      a.at(1) = 0;
    }
  }
  
  if(a.at(n-2) + a.at(n-1) > x){
    if(a.at(n-2) >= a.at(n-2) + a.at(n-1) - x){
      cnt += a.at(n-2) + a.at(n-1)  - x;
      a.at(n-2) -= a.at(n-2) + a.at(n-1)  - x;
    }else{
      cnt += a.at(n-2) + a.at(n-1)  - x;
      a.at(n-1) -= a.at(n-2) + a.at(n-1) - x - a.at(n-2);
      a.at(n-2) = 0;
    }
  } 
  
  int64_t b;
  int64_t sum = 0;
  for(int64_t i=0;i<n-1;i++){
    b = a.at(i) + a.at(i+1);
    if(b > x){
      if(a.at(i+1) >= a.at(i) + a.at(i+1) - x){
        cnt += a.at(i) + a.at(i+1) - x;
        a.at(i+1) -= a.at(i) + a.at(i+1) - x;
      }else{
        cnt += a.at(i) + a.at(i+1) - x;
        a.at(i) -= a.at(i) + a.at(i+1) - x - a.at(i+1);
        a.at(i+1) = 0;
      }
    }
  }
  cout << cnt<< endl;
}
    
    

Measured memory_bytes: 1024
import java.util.Scanner;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        while(true){
            int n = sc.nextInt();
            int x = sc.nextInt();
            
            if(n==0 && x==0){
                break;
            }else{
                com(n,x);
            }
        }
    }
    static void com(int n,int x){
        int count=0;
       for(int i=1; i<n; i++){
            for(int j=2; j<n; j++){
                for(int k=3; k<=n; k++){
                	// 重複なし(同一数字)
                    if(i!=j && j!=k && i!=k){
                    	// 重複なし(同じパターン)
                        if(i<j && j<k){
                            if((i+j+k) == x) count++;
                        }
                    }
                }
            }
        }
        System.out.println(count);
    }
}


Measured memory_bytes: 26608
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int table[111111][26];


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);

  std::string s, t;

  std::cin >> s >> t;
  
  memset(table, -1, sizeof(table));

  int a[26] = {0};

  for (int i = 0, size = s.size(); i < size; i ++) {
    int x = s[i] - 'a';

    for (int j = i; j >= 0 && table[j][x] == -1; j --)
      table[j][x] = i;
  }

  long long C = 0;

  for (int i = 0, j = 0, size = t.size(); i < size; ) {
    int x = t[i] - 'a', y = table[j][x];

    if (y == -1) {
      if (j == 0) {
        std::cout << -1 << std::endl;

        return 0;
      }
      else {
        C += s.size();
        j  = 0;

        continue;
      }
    }

    if (i == size - 1) {
      C += y + 1;
      
      break;
    }
    else {
      j = y + 1;
      
      i ++;
    }
  }

  std::cout << C << std::endl;

  return 0;
}


Measured memory_bytes: 11856
import java.util.Scanner;

class Main{
  public static void main(String[] args){
  	Scanner scanner = new Scanner(System.in);
    int count=0;
	int num1= scanner.nextInt();
    int num2= scanner.nextInt();
    
    int[][] a = new int[num1][2];
    for(int i=0;i<num1;i++) for(int k=0;k<2;k++) a[i][k] = scanner.nextInt();
    
    scanner.close();
    
    for(int i=0;i<num1;i++) if(Math.sqrt( Math.pow(a[i][0],2) + Math.pow(a[i][1],2) ) <= num2) count++;
    System.out.println(count);
  }
}

Measured memory_bytes: 65676
#include<bits/stdc++.h>
using namespace std;
#define debug(x) cout << '>' << #x << ':' << x << endl;
#define ll long long

int main() {
	ll a, b, c, d;
	scanf("%lld%lld%lld%lld", &a, &b, &c, &d);
	ll least_common_multiblier = c * d / __gcd(c, d);
	ll number_divisible_by_c_in_b = b / c;
	ll number_divisible_by_c_in_a = (a - 1) / c;


	ll number_divisible_by_d_in_b = b / d;
	ll number_divisible_by_d_in_a = (a - 1) / d;


	ll ans = (number_divisible_by_c_in_b + number_divisible_by_d_in_b
			- (b / least_common_multiblier))
			- (number_divisible_by_c_in_a + number_divisible_by_d_in_a
					- ((a - 1) / least_common_multiblier));
	cout << (b - a) - ans + 1;
}


Measured memory_bytes: 3768
INF = 2*10**7


def main():
    N, M = (int(i) for i in input().split())
    A = []
    B = []
    C = []
    for _ in range(M):
        a, b = (int(i) for i in input().split())
        A.append(a)
        B.append(b)
        C.append({int(i) for i in input().split()})
    dp = [[INF]*(1 << N) for _ in range(M+1)]
    dp[0][0] = 0
    for i in range(M):
        for j in range(1 << N):
            dp[i+1][j] = min(dp[i+1][j], dp[i][j])
            if dp[i][j] != INF:
                next_bit = j
                for bit in C[i]:
                    next_bit |= (1 << (bit-1))
                dp[i+1][next_bit] = min(dp[i+1][next_bit], dp[i][j] + A[i])
    ans = dp[-1][-1]
    if ans == INF:
        print(-1)
    else:
        print(ans)
    # print(*dp, sep="\n")


if __name__ == '__main__':
    main()


Measured memory_bytes: 78056
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            StringBuilder sb = new StringBuilder();

            string input;

            while (!string.IsNullOrEmpty(input = Console.ReadLine()))
            {
                for (int i = 0; i < input.Length; i++)
                {
                    if (input[i] == '@')
                    {
                        for (int j = '0'; j < input[i + 1]; j++)
                        {
                            sb.Append(input[i + 2]);
                        }
                        i += 2;
                    }
                    else sb.Append(input[i]);
                }
                sb.Append("\n");
            }
            Console.Write(sb);
        }
    }
}

Measured memory_bytes: 8716
import std.stdio;
import std.algorithm;
import std.string;
import std.range;
import std.array;
import std.conv;
import std.complex;
import std.math;
import std.ascii;
import std.bigint;
import std.container;
import std.typecons;

auto readInts() {
	return array(map!(to!int)(readln().strip().split()));
}
auto readInt() {
	return readInts()[0];
}
auto readLongs() {
	return array(map!(to!long)(readln().strip().split()));
}
auto readLong() {
	return readLongs()[0];
}

const real eps = 1e-10;

void main(){
mainLoop:
	while(true) {
		auto nm = readInts();
		auto n = nm[0];
		auto m = nm[1];
		if(n == 0 && m == 0) {
			return;
		}
		int[] taro, hanako;
		for(int i; i < n; ++i) {
			taro ~= readInt();
		}
		for(int i; i < m; ++i) {
			hanako ~= readInt();
		}
		auto taroSum = reduce!("a+b")(0, taro);
		auto hanakoSum = reduce!("a+b")(0, hanako);
		if((taroSum + hanakoSum)%2 == 1) {
			writeln(-1);
			continue;
		}
		auto mid = (taroSum + hanakoSum)/2;
		sort(taro);
		sort(hanako);
		foreach(s; taro) {
			if(canFind(hanako, hanakoSum - mid + s)) {
				writeln(s, " ", hanakoSum-mid+s);
				continue mainLoop;
			}
		}
		writeln(-1);
	}
}

Measured memory_bytes: 2532
//#define _GRIBCXX_DEBUG
#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iomanip>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;


// ?????¬???????????¬??????
#pragma region MACRO
#define P(x) cout << (x) << endl
#define p(x) cout << (x)
#define PED cout << "\n"
#define rep(i,n) for(int i=0; i<(int)n; ++i)
#define REP(i,x,n) for(int i=x; i<(int)n; ++i)
#define repi(i,n) for(int i=0; i<=(int)n; ++i)
#define REPI(i,x,n) for(int i=x; i<=(int)n; ++i)
#define ILP while(true)
#define FOR(i,c) for(__typeof((c).begin())!=(c).begin(); i!=(c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
#define mp make_pair
#pragma endregion

// ???
#pragma region TYPE_DEF
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<string, string> pss;
typedef pair<string, int> psi;
typedef pair<int, string> pis;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long> vl;
typedef vector<long long> vll;
typedef vector<string> vs;
#pragma endregion

// Effective std
#pragma region ESTD
template<typename C, typename T>
constexpr int count(C& c, T t) { return count(ALL(c), t); }
template<typename C, typename F>
constexpr int count_if(C& c, F f) { return count_if(ALL(c), f); }
template<typename C, typename T>
void erase(C& c, T t) { remove(ALL(c), t), c.end(); }
template<typename C>
void remove(vector<C>& c, unsigned int index) { c.erase(c.begin()+index); }
template<typename C, typename T, typename U>
constexpr void replace(C& c, T t, U u) { replace(ALL(c), t, u); }
template<typename C, typename F, typename U>
constexpr void replace_if(C& c, F f, U u) { (ALL(c), f, u); }
template<typename C>
constexpr void reverse(C& c) { reverse(ALL(c)); }
template<typename C>
constexpr void sort(C& c) { sort(ALL(c)); }
template<typename C, typename Pred>
constexpr void sort(C& c, Pred p) { sort(ALL(c), p); }
#pragma endregion

// ?????°
#pragma region CONST_VAL
#define PI (2*acos(0.0))
#define EPS (1e-9)
#define MOD (int)(1e9+7)
#pragma endregion


int main()
{
    int n;
    while(cin>>n) {
        int ans = 1;
        for(int i=n; i>0; i--) ans+=i;
        P(ans);
    }
    return 0;
}

Measured memory_bytes: 3084
//Link : https://codeforces.com/contest/1253

#include <stdio.h>
#include <vector>


using namespace std;
#define ll long long
#define N 3005
#define mod 998244353
/*
#include <limits.h>
INT_MAX
LLONG_MAX
*/
int add(int x, int y) {
	return ((x + y) % mod + mod) % mod;
}
int mul(int x, int y) {
	return (ll)x*y%mod;
}
int mypow(int x, int c) {
	int ret = 1;
	while (c > 0) {
		if (c & 1) {
			ret = mul(ret, x);
		}
		x = mul(x, x);
		c /= 2;
	}
	return ret;
}
int a[N], pp[N], tmp[N], ppp[N];
void solve() {
	int n, s;
	scanf("%d %d", &n,&s);
	int ret = 0;
	for (int i = 1; i <= n; ++i) {
		int x;
		scanf("%d", &x);
		for (int j = s - x; j >= 0; --j) {
			pp[j + x] = add(pp[j + x], pp[j]);
		}
		if (x <= s) {
			pp[x] = add(pp[x], i);
		}
		ret = add(ret, pp[s]);
	}
	printf("%d\n", ret);
}

int main() {
	//freopen("input.txt","r",stdin);
	solve();
	return 0;
}


Measured memory_bytes: 256
a1, b1 = input().split()
a2, b2 = input().split()
a3, b3 = input().split()

s = a1 + b1 + a2 + b2 + a3 + b3
i1 = s.count("1")
i2 = s.count("2")
i3 = s.count("3")
i4 = s.count("4")

ans ="YES"
if (i1>2) or (i2>2) or (i3>2) or (i4>2):
    ans = "NO"
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <fstream>
#include <string>

using namespace std;
typedef long long  ll;
#define rep(i,s,n)for(ll i = s;i<n;i++)

int main() {
	int W, H, N; cin >> W >> H >> N;
	int x[101], y[101], a[101];
	int S = W * H;
	int x_1 = 0, x_2 = W, y_1 = 0, y_2 = H;
	rep(i, 1, N + 1) {
		cin >> x[i] >> y[i] >> a[i];
		if (a[i] == 1 && x_1 < x[i]) {
			x_1 = x[i];
		}
		else if (a[i] == 2 && x_2 > x[i]) {
			x_2 = x[i];
		}
		else if (a[i] == 3 && y_1 < y[i]) {
			y_1 = y[i];
		}
		else if (a[i] == 4 && y_2 > y[i]) {
			y_2 = y[i];
		}
	}
	if ((x_1 < x_2) && (y_1 < y_2)) {
		cout << ((x_2 - x_1) * (y_2 - y_1)) << endl;
	}
	else {
		cout << 0 << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repe(i, n) for (int i = 0; i <= (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;
const int INF = 1e9;
const ll mod = 1000000007;
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 main() {
    int x,a,b;
    cin >> x >> a >> b;
    if (abs(x-a) <= abs(x-b)) {
        cout << 'A' << "\n";
    } else {
        cout << 'B' << "\n";
    }
}


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

bool is_uruu(int x, vector<int> A) {
    for (int i = 0; i < A.size(); i++) {
        if (x % A[i] != 0) continue;
        return ((i + 1) % 2 != 0);
    }
    return (A.size() % 2 == 0);
}

int main() {
    int n, l, r;
    while (cin >> n >> l >> r, n + l + r) {
        vector<int> A(n);
        for(int i = 0; i < n; i++) cin >> A[i];

        int ans = 0;
        for (; l <= r; l++) ans += is_uruu(l, A);
        cout << ans << endl;
    }
}



Measured memory_bytes: 3048
#include <iostream>
#include <vector>
#include <cstring>
#include <algorithm>
#include <cassert>
#include <deque>
#include <map>
#include <queue>
#include <climits>
#include <set>
#include <stack>
#include <cmath>
#include <unordered_map>
#include <unordered_set>

using namespace std;

#define ll long long
#define MAX 100000
#define MAX1 10000
#define MAX2 100000
#define inf 1000000000
#define eps 1e-12
#define MOD 1000000007

int main() {

    ios_base::sync_with_stdio(0);
    cin.tie(0);
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif

    int n, x, t, i, ans = 0;
    cin >> n >> x >> t;
    i=0;
    while(i<n) {
        i+=x;
        ans+=t;
    }
    cout << ans;

    return 0;
}


Measured memory_bytes: 3608
function main(input: string): void {
  let count: number = 0
  let numbers: number[] = input.split('\n')[1].split(' ').map(n => parseInt(n, 10))

  while (numbers.every(num => num % 2 === 0)) {
    count ++
    numbers = numbers.map(num => {
      return num / 2
    })
  }

  console.log(count)
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))

Measured memory_bytes: 7500