akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define Data_Nerd ios_base::sync_with_stdio(); cin.tie(0); cout.tie(0);
#define files freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
using namespace std;
using ll = long long;

const int N = 1e5 + 1;

ll arr[N];

int main() {
	Data_Nerd
	int n, m; scanf("%d%d", &n, &m);

	for(int i = 0; i < n; ++i)
		scanf("%lld", arr + i);

	arr[0] %= m;

	for(int i = 1; i < n; ++i) {
		arr[i] = (arr[i] + arr[i - 1]) % m;
	}

	map <ll, ll> freq;

	for(int i = 0; i < n; ++i) {
		++freq[arr[i]];
	}

	ll ans = 0;

	for(auto i : freq) {
		ans += i.second * (i.second - 1) / 2;
		if(i.first == 0)
			ans += i.second;
	}

	cout << ans;
}


Measured memory_bytes: 4992
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
#include<numeric>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
constexpr ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int>P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);


int d;
int s[365][26];
int c[26];

int calc(vector<int> &v) {
	int sum = 0;
	int las[26]; rep(i, 26)las[i] = -1;
	

	int dec = 0;

	int aldec = 0;

	rep(i, d) {
		if (las[v[i]] >= 0) {
			aldec -= c[v[i]] * (i - las[v[i]]);
		}
		else {
			dec += c[v[i]];
		}

		sum += s[i][v[i]];
		las[v[i]] = i;




		sum -= aldec;
		aldec += dec;
	}
	return max(sum, 0);
}

void query(vector<int> v) {
	rep(i, d) {
		cout << v[i] + 1 << "\n";
	}
}
void solve() {
	cin >> d;
	rep(i, 26)cin >> c[i];
	rep(i, d)rep(j, 26)cin >> s[i][j];

	//init_answer
	vector<int> v;
	int las[26]; rep(j, 26)las[j] = -1;
	int sum = 0;

	rep(i, d) {
		int ma = -mod;
		int chk = -1;
		rep(j, 26) {
			int ad = s[i][j];
			if (las[j] >= 0) {
				ad += c[j] * (i - las[j]);
			}
			if (ma < ad) {
				ma = ad;
				chk = j;
			}
		}
		v.push_back(chk);
		las[chk] = i;

		sum += s[i][chk];
		rep(j, 26)if (las[j] >= 0) {
			sum -= c[j] * (i - las[j]);
		}
	}

	random_device rnd;
	mt19937 mt(rnd());
	uniform_int_distribution<> ud(0, d - 1);
	vector<int> alt = v;


	int cur=sum;
	rep(i, 5000) {
		int id = ud(mt);
		rep(j, 26) {
			if (j == v[id])continue;
			alt[id] = j;
			int val = calc(alt);
			if (cur < val) {
				swap(v, alt);
				cur = val;
				break;
			}
		}
	}

	query(v);
}


signed main() {
	solve();
		return 0;
}


Measured memory_bytes: 3692
#include <stdio.h>

#define HI 20
#define MA 2000

int main(){
 
  int i, n, f, t;
  int ans[MA+1] = {0};
 
  scanf("%d", &n);
  for (i = 0; i < n; i++){
    scanf("%d", &t);
    for(f = MA-t; 0 < f; f--){
      if(ans[f]){
        ans[f+t] = 1;
      }
    }
    ans[t] = 1;
  }
 
  scanf("%d", &f);
  for(i = 0; i < f; i++){
    scanf("%d", &t);
    if(ans[t]){
      printf("yes\n");
    }
    else printf("no\n");
  }
 
  return 0;
}

Measured memory_bytes: 588
import java.util.Scanner;

public class Main {
    static Scanner sc = new Scanner(System.in);
    static int n = sc.nextInt();
    static int vac[][] = new int[n][3];
    static int dp[][] = new int[n][3];

    public static void main(String[] args) {
        //初期化
        for (int i = 0; i < n; i++){
            vac[i][0] = sc.nextInt();
            vac[i][1] = sc.nextInt();
            vac[i][2] = sc.nextInt();
            for (int j = 0; j < 3; j++){
                dp[i][j] = 0;
            }
        }
        //dp埋めていく
        dp[0][0] = vac[0][0];
        dp[0][1] = vac[0][1];
        dp[0][2] = vac[0][2];
        for (int i = 1; i < n; i++){
            for (int j = 0; j < 3; j++){
                for (int k = 0; k < 3; k++){
                    if (k != j)
                        dp[i][j] = chmax(dp[i][j], dp[i - 1][k] + vac[i][j]);
                }
            }
        }
        System.out.println(Math.max(dp[n - 1][0], Math.max(dp[n - 1][1], dp[n - 1][2])));

    }
    public static int chmax(int a, int b){
        if (a > b)
            return a;
        else
            return b;
    }
}


Measured memory_bytes: 103220
def main():
    A, B = map(int, input().split())
    ans = 0
    if B == 1:
        print(0)
        exit()
    while True:
        ans += 1
        if (A - 1) * ans + 1 >= B:
            break
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 61848
#include<bits/stdc++.h>
    #define ll long long
    #define pb push_back
    using namespace std;

    const int mod = 1e9 + 9;
    const ll inf = 1e18;
    long long n , m , a  , b , mx = -1e9 , mx1 ,cnt;
    string s;
    int main()
    {
        cin >> n >> m;
        cout << n * m << endl;
    }


Measured memory_bytes: 3620
#pragma target("avx")
#pragma optimize("O3")
#include<bits/stdc++.h>
using ll = int_fast64_t;
using P = std::pair<ll,ll>;
using PP = std::pair<ll,P>;
using V = std::vector<ll>;
template<typename T> using pq = std::priority_queue<T>;
template<typename T> using rpq = std::priority_queue<T, std::vector<T>, std::greater<T>>;

#define REP(i,b,e) for(ll i=b; i<e; i++)
#define ALL(vec) vec.begin(),vec.end()
#define PRINT(vec) printf("[ ");for(auto &i:vec)printf("%ld ",i);puts("]");
#define SCAN(vec) for(auto &i:vec)scanf("%ld",&i)
#define fi first
#define se second

const int MOD = 1e9+7;
const ll INF = 1e18;
int dx[] = {0, 1, 0, -1, 1, 1, -1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

int main(){
	std::vector<bool> isPrime(60000, true);
	isPrime[0] = isPrime[1] = false;
	V primes;
	REP(i, 2, 60000) if(isPrime[i]) {
		for(int j=i+i; j<60000; j+=i){
			isPrime[j] = false;
		}
		primes.push_back(i);
	}

	int n;
	scanf("%d", &n);
	for(ll x: primes){
		if(x%5==1){
			printf("%ld ", x);
			if(--n==0) break;
		}
	}
	return 0;
}



Measured memory_bytes: 384
n = int(input())
s = input()
# 暗証番号のパターンは、000, 001, ,,,999の1000パターンしかない。
# このうち作れるモノを、sから探すか。
# その場合、O(1000 * 30000) でまぁ間に合いそう。
patterns = []
for i in range(10):
    for j in range(10):
        for k in range(10):
            patterns.append(str(i) + str(j) + str(k))

ans = 0
for pattern in patterns:
    i = j = 0
    while i < n:
        if s[i] == pattern[j]:
            i += 1
            j += 1
            if j == 3:
                ans += 1
                break
        else:
            i += 1
print(ans)

Measured memory_bytes: 40812
import sys
S = input()
if len(S)<26:
    for i in range(26):
        ans = S + chr(97+i)
        if len(ans) == len(list(set(ans))):
            print(ans)
            break
else:
    if S == 'zyxwvutsrqponmlkjihgfedcba':
        print(-1)
    else:
        SS = S[0:-1]
        while True:
            SS = SS[0:-1]
            for i in range(26):
                ans = SS + chr(97+i)
                if len(ans) == len(list(set(ans))) and S < ans:
                    print(ans)
                    sys.exit()

Measured memory_bytes: 3064
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <limits>

using namespace std;

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

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

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

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

	cout << max(a - 2 * b, 0) << endl;
	return 0;
}

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

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

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;
typedef pair<int, int> P;

const int MAX = 200005;
const int INF = 1001001001;
const int MOD = 1000000007;

int main(){
    int N;
    cin >> N;

    vector<int> L(N);
    rep(i, N) cin >> L[i];

    sort(L.begin(), L.end());

    int ans = 0;
    rep(i, N) {
        rep(j, i) {
            ans += L.begin() + j - upper_bound(L.begin(), L.begin() + j, L[i] - L[j]);
        }
    }

    cout << ans << endl;
}

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

int N,x;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
    
	cin >> N >> x;
	vector<int> arr(N);
	for(int i = 0; i < N; i++) {
		cin >> arr[i];
	}
    
	sort(arr.begin(), arr.end());
	
    int ans = 0;
	for(int i = 0; i < N-1; i++) {
		if(arr[i] <= x) {
			ans++;
			x-= arr[i];
		} else {
			cout << ans;
			return 0;
		}
	}
	if(x == arr[N-1]) {
		ans++;
	}
	cout << ans;
	return 0;
}



Measured memory_bytes: 256
n,m=map(int,input().split())
comb = []
for _ in range(m):
    comb.append(list(map(int,input().split()))[1:])
point = list(map(int,input().split()))
ans = 0
for i in range(2**n): #スイッチのon/offの組み合わせは2**n通りある
    on = [0]*m
    for j in range(n): #それぞれ何個めがonになっているか調べる
        if (i>>j)&1: #j個目がonになっているとき
            for k in range(m): #それぞれの電球に対して
                if j+1 in comb[k]: #もしj個目のon/offが電球kに関係するなら
                    on[k] += 1 #電球kに関してonポイントを与える
                    on[k] %= 2 #onポイントは偶奇のみ議論する
    if all(point[l]==on[l] for l in range(m)): #もしこの組み合わせのon/offパターンが所与の条件に一致するなら
        ans += 1 #全ての電灯が一致する組み合わせが一つ見つかったことになる
print(ans)

Measured memory_bytes: 9216
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
const ll mod = 1000000007;
const ll INF = 9223372036854775807;
#define Sort(a) sort(a.begin(), a.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define Pi acos(-1)

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << setprecision(15) << fixed;
  string s;
  cin >> s;
  deque <char> u;
  rep(i,s.size()) {
    u.push_back(s[i]);
  }
  ll n;
  cin >> n;
  ll a = 0;
  rep(i,n) {
    ll t;
    cin >> t;
    if (a%2 == 0) {
      if (t == 1) {
        a++;
      }
      else {
        ll f;
        char c;
        cin >> f >> c;
        if (f == 1) {
          u.push_front(c);
        }
        else {
          u.push_back(c);
        }
      }
    }
    else if (a%2 == 1) {
      if (t == 1) {
        a++;
      }
      else {
        ll f;
        char c;
        cin >> f >> c;
        if (f == 2) {
          u.push_front(c);
        }
        else {
          u.push_back(c);
        }
      }
    }
  }
  if (a%2 == 1) Reverse(u);
  rep(i,u.size()) cout << u[i];
  cout << '\n';
}

Measured memory_bytes: 4012
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define between(a,x,b) ((a)<=(x)&&(x)<(b))
using namespace std;
int t, h, w, n;
char town[32][32], cmd[128];

void shot(int y, int x){
   int dx[] = {0,0,-1,1}, dy[] = {-1,1,0,0}; // U D L R
  int d;
  switch(town[y][x]){
  case '^': d = 0; break;
  case 'v': d = 1; break;
  case '<': d = 2; break;
  case '>': d = 3; break;
  }
  //  printf("%d\n", d);
  while(true){
    if(between(0,y+dy[d], h) && between(0, x+dx[d], w)){
      y+=dy[d]; x+=dx[d];
      if(town[y][x] == '*'){
	town[y][x] = '.';
	break;
      }else if(town[y][x] == '#'){
	break;
      }
    }else break;
  }
  return;
}

int main(){
  scanf("%d", &t);
  bool f = false;
  while(t--){
    scanf("%d%d", &h, &w);
    rep(i, h) scanf("%s", town[i]);
 
    scanf("%d", &n);
    scanf("%s", cmd);
    int x, y;
    rep(i, h) rep(j, w) 
      if(town[i][j]=='^' || town[i][j]=='v' || town[i][j]=='<' || town[i][j]=='>')x=j,y=i;
    rep(i, n){
      //      printf("%d %d\n", y, x);
      switch(cmd[i]){
      case 'U':
	if(y-1 >= 0 && town[y-1][x] == '.'){ town[y][x] = '.'; town[--y][x] = '^';}
	else town[y][x] = '^';
	break;
       case 'D':
	if(y+1 < h && town[y+1][x] == '.'){ town[y][x] = '.'; town[++y][x] = 'v';}
	else town[y][x] = 'v';
	break;
      case 'L':
	if(x-1 >= 0 && town[y][x-1] == '.'){ town[y][x] = '.'; town[y][--x] = '<';}
	else town[y][x] = '<';
	break;
      case 'R':
	if(x+1 < w && town[y][x+1] == '.'){ town[y][x] = '.'; town[y][++x] = '>';}
	else town[y][x] = '>';
	break;
      case 'S':
	shot(y, x);
	break;
      }
    }      
    if(f) puts("");
    rep(i, h){
      rep(j, w) printf("%c", town[i][j]);
      puts("");
    }
    
    f = 1;
  }
  return 0;
}

Measured memory_bytes: 1176
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	var n int
	fmt.Scan(&n)
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	as := make([]int, n)
	for i := range as {
		sc.Scan()
		as[i], _ = strconv.Atoi(sc.Text())
	}
	var sum, ph int
	for i := range as {
		if as[i] < ph {
			sum += ph - as[i]
		} else {
			ph = as[i]
		}
	}
	fmt.Println(sum)
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}


Measured memory_bytes: 5940
#include <bits/stdc++.h>
#define ll long long
#define pq priority_queue
using namespace std;
const ll INF=(ll)1e9;
const ll MOD=(ll)1e9+7;
const ll MAX=510000;
vector<int> dx={1,0,-1,0},dy={0,1,0,-1};
template<class T> inline bool chmax(T& a, T b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a>b) { a=b; return 1; } return 0; }

int main(){
    ll N,ans,B=0,W=0;
    string S;
    cin>>N>>S;
    vector<ll> b(N,0),w(N,0);
    for(ll i=0;i<N;i++){
        if(S[i]=='#'){
            b[i]++;
            B++;
        }else{
            w[i]++;
            W++;
        }
        if(i!=N-1){
            b[i+1]=b[i];
            w[i+1]=w[i];
        }
    }
    ans=min(B,W);
    for(ll i=0;i<N;i++){
        ans=min(ans,b[i]+W-w[i]);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3716
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> iint;
typedef pair<ll,ll> llll;
#define ALL(x) (x).begin(),(x).end()
const ll zero = 0;
const ll INF = 3000000000000000000; //10^18
const int inINF = 1000000000; //10^9
const ll MOD = 1000000007; //10^9+7
const ll MOD2 = 998244353;

int main(){
    int H, W, K;
    cin >> H >> W >> K;
    vector<string> S(H);
    for (int i = 0; i < H; i++) {
        cin >> S[i];
    }

    vector<bool> tate(W,false), yoko(H, false);

    int tmp;
    int cnt;
    int ans = 0;
    for (int i = 0; i < 1<<(H+W); i++) {
        fill(ALL(tate), false);
        fill(ALL(yoko), false);
        tmp = i;
        for (int j = 0; j < H; j++) {
            if(tmp % 2 == 1){
                yoko[j] = true;
            }
            tmp = tmp / 2;
        }
        for (int j = 0; j < W; j++) {
            if(tmp % 2 == 1){
                tate[j] = true;
            }
            tmp = tmp / 2;            
        }

        cnt = 0;
        for (int j = 0; j < H; j++) {
            for (int k = 0; k < W; k++) {
                if(yoko[j] == false && tate[k] == false && S[j][k] == '#'){
                    cnt++;
                }
            }
        }
        if(cnt == K){
            ans++;
        }


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


}   

Measured memory_bytes: 3736
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;

int main(void) {
	ll a, b, k;
	cin >> a >> b >> k;
	if (a < k) {
		b = a + b - k;
		a = 0;
	}
	else {
		a = a - k;
	}
	if (b < 0) {
		b = 0;
	}
	cout << a << " " << b;
}


Measured memory_bytes: 256
#include<stdio.h>
int MIN(int a,int b){return a<b?a:b;}
int d[1000010],c[1000010],M=1000005,a,i,j;
int main(){
  for(i=0;i<M;i++)d[i]=c[i]=1e7;
  d[0]=c[0]=0;
  for(i=1;i<210;i++){
    a=(i*(i+1)*(i+2))/6;
    for(j=0;j+a<M;j++)d[j+a]=MIN(d[j+a],d[j]+1);
    if(a%2){
      for(j=0;j+a<M;j++)c[j+a]=MIN(c[j+a],c[j]+1);
    }
  }
  while(scanf("%d",&a),a)printf("%d %d\n",d[a],c[a]);
  return 0;
}

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

using namespace std;
using ll=long long;
#define all(a) (a).begin(), (a).end()
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, a, n) for(int i = (a); i < (n); i++)

int main(){
  cin.tie(nullptr);ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  int n,k;cin>>n>>k;
  int cnt=0,ind=0;
  vector<int> hoge(k,0);
  while(cnt!=n){
    hoge[ind]++;
    cnt++;
    ind++;
    if(ind==k)ind=0;
  }
  sort(all(hoge));
  cout<<hoge[k-1]-hoge[0]<<endl;
}


Measured memory_bytes: 256
#define DBG 0 //submit 0
#define ll long long
#if DBG
    #include <algorithm>
    #include <array>
    #include <ctime>
    #include <cstdlib>
    #include <string>
    #include <vector>
    #include <unordered_map>
    #include <iostream>
    #include <cmath>
    #include <queue>
    #include <numeric>
#else
    #include <bits/stdc++.h>
#endif
 
using namespace std;
 
 
int main(){
    int m,n,ans=0;
    bool flag=false;
    string s;
   
    //cin >> n;
    cin >> s;
    //for(int i=0;i<n;i++) cin >> s[i];
    if(s=="SUN") ans=7;
    if(s=="MON") ans=6;
    if(s=="TUE") ans=5;
    if(s=="WED") ans=4;
    if(s=="THU") ans=3;
    if(s=="FRI") ans=2;
    if(s=="SAT") ans=1;
    
    
    //cout << (!flag ? "Yes" : "No");
    cout << ans;
    //printf("%.10f",ans_d);

    cout << endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int N, A, B, L, a[109], b[109];
int main() {
	cin >> N >> A >> B >> L;
	for (int i = 0; i < N; i++) cin >> a[i] >> b[i];
	bool flag = false;
	int r = 0;
	while (!flag) {
		for (int i = 0; i < N; i++) {
			if (a[i] > 0) r += 10, a[i]--, A++;
			else r += 100, b[i]--, B++;
			if (r >= 90 && A <= L) {
				a[i] += (r - 90) / 10;
				A -= (r - 90) / 10;
				r = 0;
			}
			if (A > L || A < 0 || a[i] == -1) {
				cout << i + 1 << endl;
				flag = true; break;
			}
		}
	}
	return 0;
}

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

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

int main() {
  int a, b, ans = 0;

  cin >> a >> b;

  for (int i = a; i <= b; ++i) {
    std::string s = std::to_string(i), t = s;
    std::reverse(t.begin(), t.end());

    if (s == t) {
      ans++;
    }
  }

  cout << ans << endl;

  return 0;
}

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

using namespace std;

int main() {
    int k, n;
    double tans = 0.0, ans = -0.1;
    cin >> n >> k;
    vector<int> pi(n, 0);
    for (int i = 0; i < n; ++i) cin >> pi[i];
    for (int j = 0; j < k; ++j) {
      tans += pi[j];
    }
    for (int i = 0; i < n - k + 1; ++i) {
      if (i >= 1) {
        tans = tans - pi[i - 1];
        tans = tans + pi[i + k - 1];
      }
      double ttans = tans;
    	ttans += k;
    	ttans /= 2.0;
    	ans = max(ttans, ans);
    }
    cout << fixed << setprecision(8) << ans << '\n';
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<utility>
#include<map>
#include<stack>
#include<set>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
const ll mod = 1000000007;
const ll INF = mod * mod;

#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define stop char nyaa;cin>>nyaa;

void solve() {
	int a, b; cin >> a >> b;
	cout << max(0, a - 2 * b) << endl;
}
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	solve();

	//stop
	return 0;
}


Measured memory_bytes: 256
'use strict'
const main = arg => {
	const input = arg.trim().split("\n");
	let S = input[0].split(' ')[0]
	let T = input[0].split(' ')[1]
	let A = input[1].split(' ')[0]
	let B = input[1].split(' ')[1]
	let U = input[2].split(' ')[0]
	if(U === S) {
		A = A - 1
	}
	if(U === T) {
		B = B - 1
	} 
	console.log(A + ' ' + B)
}   
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 21064
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vout(x) rep(i,x.size()) cout << x[i] << " "
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 100005;

//dinic法
struct max_flow {
    struct edge {int to, cap, rev;};
    int V;
    vector<vector<edge>> G;
    vector<int> itr, level;

    max_flow(int V) : V(V), G(V){}

    void add_edge(int from, int to, int cap) {
        G[from].push_back((edge){to, cap, (int)G[to].size()});
        G[to].push_back((edge){from, 0, (int)G[from].size()-1});
    }

    void bfs(int s) {
        level.assign(V,-1);
        queue<int> q;
        level[s] = 0; q.push(s);
        while (!q.empty()) {
            int v = q.front(); q.pop();
            for (auto &e: G[v]) {
                if (e.cap > 0 && level[e.to] < 0) {
                    level[e.to] = level[v] + 1;
                    q.push(e.to);
                }
            }
        }
    }

    int dfs(int v, int t, int f) {
        if (v == t) return f;
        for (int &i = itr[v]; i < (int)G[v].size(); i++) {
            edge &e = G[v][i];
            if (e.cap > 0 && level[v] < level[e.to]) {
                int d = dfs(e.to, t, min(f,e.cap));
                if (d > 0) {
                    e.cap -= d;
                    G[e.to][e.rev].cap += d;
                    return d;
                }
            }
        }
        return 0;
    }
    
    int run(int s, int t) {
        int ret = 0, f;
        while (bfs(s), level[t] >= 0) {
            itr.assign(V,0);
            while ((f = dfs(s,t,inf)) > 0) ret += f;
        }
        return ret;
    }
};

int main() {
    int n; cin >> n;
    vint x(2*n), y(2*n);
    rep(i,2*n) cin >> x[i] >> y[i];
    max_flow dinic(2*n+2);
    int s = 2 * n, t = s + 1;
    rep(i,n) dinic.add_edge(s,i,1);
    rep(i,n) dinic.add_edge(n+i,t,1);
    rep(i,n) {
        rep(j,n) {
            if (x[i] < x[n+j] && y[i] < y[n+j]) {
                dinic.add_edge(i,n+j,1);
            }
        }
    }
    cout << dinic.run(s,t) << endl;
}

Measured memory_bytes: 384
#include <algorithm>
#include <iostream>
#include <map>
#include <vector>

using namespace std;

int main() {
  long long h, w;
  cin >> h >> w;
  if (h == 1 && w == 1) {
    cout << 1 << endl;
  } else if (h == 1) {
    cout << max(w - 2, 0LL) << endl;
  } else if (w == 1) {
    cout << max(h - 2, 0LL) << endl;
  } else {
    cout << max((h - 2) * (w - 2), 0LL) << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

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

#define DEBUG

#ifdef DEBUG
#define var_dump(...) fprintf(stdout, __VA_ARGS__)
#define dump(a) cout << a << "\n";
#else
#define var_dump(...) 42
#define dump(a) 42
#endif

// https://beta.atcoder.jp/contests/abc067/tasks/abc067_b

int main() {
    int N, K; cin >> N >> K;
    int arr[N]; REP(i, N) cin >> arr[i];

    sort(arr, arr+N, greater<int>());

    int sum = 0;
    REP(i, K) {
        sum += arr[i];
    }

    cout << sum << "\n";

    return 0;
}


Measured memory_bytes: 256
/************************************
/ AUTHOR : YATHARTH GOSWAMI         /  
/ ALIAS : hacker_yg                 /
/ INSTITUTE : IIT Kanpur            /
************************************/
//          TEMPLATE                //

#include <bits/stdc++.h>

#define ll long long
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define F first
#define S second

using namespace std;

int main(){
    int s, w;
    cin >> s >> w;
    if (w >= s) puts("unsafe");
    else puts("safe");
    return 0;
}




Measured memory_bytes: 3636
'use strict'

function main (n, array) {
  let counter = {}
  for (let a of array) {
    counter[a] = counter[a] || 0
    counter[a]++
  }
  let nums = Object.keys(counter)
  let evenCount = nums.reduce((count, num) => {
    if (counter[num] % 2 === 0) {
      return count + 1
    } else {
      return count
    }
  }, 0)
  let answer
  if (evenCount % 2 === 0) {
    answer = nums.length
  } else {
    answer = nums.length - 1
  }
  console.log(answer)
}

function doMain () {
  let input = ''
  process.stdin.resume()
  process.stdin.setEncoding('utf8')
  process.stdin.on('data', (chunk) => {
    input += chunk
  })
  process.stdin.on('end', () => {
    input = input.trim().split('\n')
    let n = Number(input[0])
    let array = input[1].split(' ').map(a => Number(a))
    main(n, array)
  })
}

doMain()


Measured memory_bytes: 27992
// AOJ 2106 Enegy Transporter
// 2018.3.4

#include <stdio.h>
#include <string.h>

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0;
	int c = getchar_unlocked();
	while (c <= ' ') c = getchar_unlocked();
	do n = (n<<3)+(n<<1) + (c & 0xf), c = getchar_unlocked();
	while (c >= '0');
	return n;
}

#define N 82
int e[82];
char dp[2][N][N];

int main()
{
	int cno, w, n, i, j, k, k1, k2, t, ans;

	cno = in(); while (cno--) {
		w = in(), n = w-1;
		for (i = 0; i < w; i++) e[i] = in();
		if (n < 2) { printf("%d\n", e[n]); continue; }

		ans = e[n];
		memset(dp, 0, sizeof(dp));
		for (k1 = 1, k2 = 0, i = 1; i < n; i++, k1 = k2, k2 = !k2) {
			memset(dp[k2], 0, sizeof(dp[k2]));
			dp[k1][e[i-1]][e[i]] = 1;
			t = e[i+1];
			for (j = 0; j < N; j++) for (k = 0; k < N; k++) {
				if (!dp[k1][j][k]) continue;
				if (!k) {
					if (i+2 < w) dp[k2][k][t] = 1;
					else if (t > ans) ans = t;
				} else {
					if (i+2 < w) dp[k2][k][t] = dp[k2][k-1][t+j] = 1;
				    else if (t+j > ans) ans = t+j;
				}
		    }
	    }
		printf("%d\n", ans);
	}
	return 0;
}


Measured memory_bytes: 2036
n, l = map(int, input().split())
aji = []
for i in range(1, n+1):
    aji.append(l + i - 1)
aji_sum = sum(aji)
sa = 1000000007
for i in range(n):
    if abs(sum(aji[:i]) + sum(aji[i+1:]) - aji_sum) <= sa:
        sa = abs(sum(aji[:i]) + sum(aji[i+1:]) - aji_sum)
        ans = sum(aji[:i]) + sum(aji[i+1:])
print(ans)

Measured memory_bytes: 38640
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  int cnt=0;
  for(int i=0;i<s.size();i++)if(s[i]==s[i+1] && s[i+1]==s[i+2])cnt++;
  if(cnt)cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

int main () {
  vector<int> v;
  for (int i = 1; i <= 4; i++) {
    v.push_back(i);  
  }
  set<int> box[5];
  for (int i = 0; i < 3; i++) {
    int s, ss;
    cin >> s >> ss;
    box[s].insert(ss);
    box[ss].insert(s);  
  } 
  do {
    if (box[v[0]].count(v[1]) == 1 && box[v[1]].count(v[2]) == 1 && box[v[2]].count(v[3]) == 1) {
      cout << "YES" << endl;
      return 0;  
    }  
  } while(next_permutation(v.begin(), v.end()));
  cout << "NO" << endl;
}

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

using namespace std;

int n,m,q,i,j,node[2005][2005],h[2005][2005],v[2005][2005];
char s[2005][2005];

int getn(int x, int y, int xx, int yy){
	int tmp = node[xx][yy];
	if(x)
	tmp -= node[x - 1][yy];
	if(y)
	tmp -= node[xx][y - 1];
	if(x && y)
	tmp += node[x - 1][y - 1];
	
	return tmp;
}

int getv(int x, int y, int xx, int yy){
	int tmp = v[xx][yy];
	tmp -= v[x][yy];
	if(y){
		tmp -= v[xx][y - 1];
		tmp += v[x][y - 1];
	}
	
	return tmp;
}

int geth(int x, int y, int xx, int yy){
	int tmp = h[xx][yy];
	tmp -= h[xx][y];
	if(x){
		tmp -= h[x - 1][yy];
		tmp += h[x - 1][y];
	}
	
	return tmp;
}

int main(){
	scanf("%d%d%d", &n, &m, &q);
	
	for(i = 0; i < n; i++)
	scanf("%s", s[i]);
	
	for(i = 0; i < n; i++){
		for(j = 0; j < m; j++){
			if(i && s[i][j] == '1' && s[i - 1][j] == '1')
			v[i][j] = 1;
			if(j && s[i][j] == '1' && s[i][j - 1] == '1')
			h[i][j] = 1;
			
			if(s[i][j] == '1')
			node[i][j] = 1;
			
			if(i){
				v[i][j] += v[i - 1][j];
				h[i][j] += h[i - 1][j];
				node[i][j] += node[i - 1][j];
			}
			
			if(j){
				v[i][j] += v[i][j - 1];
				h[i][j] += h[i][j - 1];
				node[i][j] += node[i][j - 1];
			}
			
			if(i && j){
				v[i][j] -= v[i - 1][j - 1];
				h[i][j] -= h[i - 1][j - 1];
				node[i][j] -= node[i - 1][j - 1];
			}
		}
	}
	
	for(i = 0; i < q; i++){
		int x, y, xx, yy;
		scanf("%d%d%d%d", &x, &y, &xx, &yy);
		x--; y--; xx--; yy--;
		
		int pt = getn(x, y, xx, yy);
		int ho = geth(x, y, xx, yy);
		int ve = getv(x, y, xx, yy);
		
		printf("%d\n", pt - ho - ve);
	}
}

Measured memory_bytes: 52864
#include<iostream>
#include<string>
using namespace std;

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

    int N=S.size();
    int A[N];

    for(int i=0; i<N; i++) A[i]=0;

    // counting R
    int count=0;
    bool flag=true;
    for(int i=0; i<N; i++){
        if(S[i]=='L' && flag){
            A[i-1]+=(int) (count-1)/2 + 1;
            A[i]  +=(int) (count-1)/2 + (count-1)%2 + 1;
            count=0;
            flag=false;
        }else if(!flag && S[i]=='R'){
            count++;
            flag=true;
        }else if(flag){
            count++;
        }
    }


    // counting L
    count=0;
    flag=true;
    for(int i=N-1; i>=0; i--){
        if(S[i]=='R' && flag){
            A[i+1]+=(int) (count-1)/2;
            A[i]  +=(int) (count-1)/2 + (count-1)%2;
            count=0;
            flag=false;
        }else if(!flag && S[i]=='L'){
            count++;
            flag=true;
        }else if(flag){
            count++;
        }
    }

    for(int i=0; i<N; i++){
        cout << A[i];
        if(i<N-1) cout << " ";
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
#define int long long
#define ull unsigned long long
#define ld long double
#define rep(a) rep1(i,a)
#define rep1(i,a) rep2(i,0,a)
#define rep2(i,b,a) for(int i=(b); i<((int)(a)); i++)
#define rep3(i,b,a) for(int i=(b); i>=((int)(a)); i--)
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define sz(a) ((int)a.size())
#define pow2(x) (1ll<<(x))
#define ceiling(a,b) (((a)+(b)-1)/(b))
#define print0(a) cout << (a) << ' '
#define print1(a) cout << (a) << '\n'
#define print2(a,b) cout << (a) << ' ',print1(b)
#define print3(a,b,c) cout << (a) << ' ',print2(b,c)
#define print4(a,b,c,d) cout << (a) << ' ',print3(b,c,d)
#ifdef i_am_noob
#define debug(a) print2(#a,a)
#else
#define debug(a) 
#endif
#define ordered_set tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
 
using namespace std;
using namespace __gnu_pbds;
 
const int Mod=1000000007,Mod2=998244353;
const int MOD=Mod2;
 
inline int add(int a, int b){return (a+b>=MOD?a+b-MOD:a+b);}
inline int sub(int a, int b){return (a+MOD-b>=MOD?a-b:a+MOD-b);}
int Pow(int a, int b){
	if(!b) return 1;
	int tmp=Pow(a*a%MOD,b>>1);
	return (b&1?tmp*a%MOD:tmp);
}
inline int inverse(int n){return Pow(n,MOD-2);}

const int maxn=100005;
//i_am_noob
int n;

signed main(){
	ios_base::sync_with_stdio(0),cin.tie(0);
	cin >> n;
	print1((n/2)*((n+1)/2));
	return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
#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;
 
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << endl;
    err(++it, args...);
}
 
 
#define F first
#define S second
#define ll long long
#define pb push_back
#define db double
#define ld long double
#define ppb pop_back
#define pii pair<int, int>
#define pll pair<long long, long long>
#define piii pair<int, pii>
#define all(x) (x).begin(),(x).end()
#define __ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define watch(x) cout << (#x) << " is " << (x) << endl
#define rep(i, a, n) for (int i = a; i <= n; i++)
#define TEST int T; cin >> T; while(T--)
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define int long long
 
const int N = 1e5 + 1, inf = 2e9 + 7, mod = 1e9 + 7;
const ll INF = 2e18 + 7, MOD = 1e15 + 7;

int n;
int dp[1 << 21];
bool v[21][21], was[1 << 21];

bool has(int mask, int i) {
    return (mask >> i) & 1;
}

int rec(int mask) {
    if (was[mask]) return dp[mask];
    int ans = 0;
    int bits = __builtin_popcount(mask);
    for (int i = 0; i < n; i++) {
        if(!has(mask, i) && v[bits][i])
            ans = (ans * 1LL + rec(mask | (1 << i))) % mod;
    }
    dp[mask] = ans;
    was[mask] = 1;
    return ans;
}

signed main() { __
//    freopen("lcm.in", "r", stdin);
//    freopen("lcm.out", "w", stdout);
    cin >> n;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            cin >> v[i][j];
        }
    }
    dp[(1 << n) - 1] = 1;
    was[(1 << n) - 1] = 1;
    cout << rec(0);
    return 0;
}



Measured memory_bytes: 18688
#include <iostream>
#include <map>
#include <algorithm>
#include <vector>
#include <string>
#define rep(i, n)   for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

int main(){
    int n;  cin >> n;
    vector<string>s(n);
    rep(i, n)   cin >> s[i];
    map<string, int>m;
    rep(i, n)   m[s[i]]++;
    cout << m.size() << endl;
}


Measured memory_bytes: 25120
#include <vector>
#include <iostream>
#include <algorithm>

using namespace std;

struct Team
{
    int id, cnt, time;
    vector<bool> b;
    vector<int> es;
};


int main()
{
    int T, P, R;
    while(cin >> T >> P >> R, T){
        vector<Team> ts{};
        
        for(int i=0;i<T;++i){
            Team t = {i+1, 0, 0, vector<bool>(P, false), vector<int>(P, 0)};
            ts.emplace_back(move(t));
        }
        
        for(int i=0;i<R;++i){
            int tid, pid, time;
            string msg;
            cin >> tid >> pid >> time >> msg;
            auto& t = ts[tid-1];
            if(msg == "CORRECT"){
                t.b[pid-1] = true;
                t.time += t.es[pid-1]*1200 + time;
                t.cnt += 1;
            }else{
                t.es[pid-1] += 1;
            }
        }
        
        sort(ts.begin(), ts.end(), [&](Team const& t1, Team const& t2){
            if(t1.cnt == t2.cnt){
                if(t1.time == t2.time) return t1.id < t2.id;
                else return t1.time < t2.time;
            }else return t1.cnt > t2.cnt;
        });
        
        for(auto& e: ts){
            cout << e.id << ' ' << e.cnt << ' ' << e.time << endl;
        }
    }
}

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

using namespace std;

int main () {

	int N;
	cin >> N;

	vector<int> h(N + 1);
	vector<int> c(N + 1);
	
	for (int i = 1; i <= N; i++) {
		cin >> h[i];
	}

	c[1] = 0;
	c[2] = abs(h[2] - h[1]);

	int pos = 3;

	while (pos <= N) {

		c[pos] = min(
			c[pos - 2] + abs(h[pos] - h[pos - 2]),
			c[pos - 1] + abs(h[pos] - h[pos - 1])
		);

		pos += 1;

	}
	
	cout << c[N] << "\n";

}


Measured memory_bytes: 1024
#include<iostream>

using namespace std;

const int MAX = 5001;
const int INF = (1<<20);

int dp[MAX];
int price[2][6] = {
  {200,1000,300,1200,500,1500},
  {380,(380*5)*0.8,550,(550*4)*0.85,850,(850*3)*0.88}
};

void make(){

  fill(dp,dp+MAX,INF);

  for(int i = 0; i < 6; i++)
    dp[price[0][i]] = price[1][i];


  for(int i = 100; i < MAX; i+=100)
    for(int j = 0; j < 6; j++)
      if(i-price[0][j] >=0)
	dp[i] = min(dp[i],dp[i-price[0][j]]+price[1][j]);

    
     
}

int main(){
  int in;
  make();
  while(cin >> in && in) cout << dp[in] << endl;
  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn=2e5+5;
map<int,int> mp;
int a[maxn],n;
ll ans;
int main()
{
	cin>>n;
	for(int i=i=1;i<=n;i++)cin>>a[i];
	for(int i=1;i<=n;i++)
	if(i-a[i]>0)mp[i-a[i]]++;
	for(int i=1;i<=n;i++)
	if(mp[i+a[i]])ans+=mp[i+a[i]];
	cout<<ans;
    return 0;
}

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

int main()
{
int n , x, t;
cin>>n>>x>>t;

int d = n/x;
int m = n%x;

if(m==0)
cout<<t*d<<endl;
else
cout<<t*(d+1)<<endl;

return 0;
}

Measured memory_bytes: 3636
#define f(I,H)(p[I]+h[I]*(h[I]-2*H))
long C,h[2<<17],p[2<<17],X;
P[2<<17];
s,t=-1,i;
c(x,y,z){
	return (h[y]-h[x])*(f(y,0)-f(z,0))>=
	(h[z]-h[y])*(f(x,0)-f(y,0));
}
main(){
	for(scanf("%*d%ld",&C);~scanf("%ld",h+i);){
		for(;X=f(P[s],h[i]),s<t&&X>=f(P[s+1],h[i]);s++);
		X=p[i]=i?h[i]*h[i]+C+X:0;
		for(;s<t&&c(P[t-1],P[t],i);t--);
		P[++t]=i++;
	}
	printf("%ld",X);
}

Measured memory_bytes: 4608
#include<iostream>
#include<string>
using namespace std;
int main(){
	int n,m;
	int x[100],y[100];
	while(true){
		cin>>n>>m;
		if(n==0&&m==0)
			break;
		int w=0,h=0;
		for(int i=0;i<n;i++){
			cin>>x[i];
			w+=x[i];
		}
		for(int i=0;i<m;i++){
			cin>>y[i];
			h+=y[i];
		}
		for(int i=0;i<n-1;i++){
			for(int j=n-1;j>i;j--){
				if(x[j]<x[j-1]){
					int tmp=x[j];
					x[j]=x[j-1];
					x[j-1]=tmp;
				}
			}
		}
		for(int i=0;i<m-1;i++){
			for(int j=m-1;j>i;j--){
				if(y[j]<y[j-1]){
					int tmp=y[j];
					y[j]=y[j-1];
					y[j-1]=tmp;
				}
			}
		}
		int i=0,j=0;
		bool broken=true;
		while(true){
			j=0;
			while(true){
				if(x[i]*2+h==y[j]*2+w){
					broken=false;
					break;
				}
				j++;
				if(j==m)
					break;
			}
			if(broken==false)
				break;
			i++;
			if(i==n)
				break;
		}
		if(broken==true)
			cout<<"-1"<<endl;
		else
			cout<<x[i]<<" "<<y[j]<<endl;
	}
    return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <algorithm>
#include <vector>
typedef std::vector<int> TList;

TList Input()
{
    int Count;
    std::cin >> Count;
    TList List(Count);
    for(int i = 0; i < Count; ++i){
        std::cin >> List[i];
    }
    return List;
}
int Count(const TList& S, const TList& T)
{
    int Sum = 0;
    for(TList::const_iterator It = T.begin(); It != T.end(); ++It){
        Sum += std::find(S.begin(), S.end(), *It) != S.end() ? 1 : 0;
    }
    return Sum;
}
int main()
{
    TList S = Input();
    TList T = Input();
    std::cout << Count(S, T) << std::endl;
}

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

int main() {
	int n;
	cin>>n;
	int h[n];
	for(int i=0;i<n;i++)
	cin>>h[i];
	int minsum[n];
	minsum[n-1]=0;
	minsum[n-2]=abs(h[n-1]-h[n-2]);
	
	for(int i=n-3;i>=0;i--)
	{
	    minsum[i] = min(abs(h[i]-h[i+1])+minsum[i+1],abs(h[i]-h[i+2])+minsum[i+2]);
	}
	cout<<minsum[0]<<endl;
	return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>


int main(void)
{
    int a[4];
    int min1,min2,i;
    for(i=0;i<4;i++) 
        scanf("%d",&a[i]);
    if(a[0]<a[1]) min1=a[0];
    else min1=a[1];
    if(a[2]<a[3]) min2=a[2];
    else min2=a[3];
    printf("%d\n",min1+min2);
    return 0;
}



Measured memory_bytes: 128
import java.util.Scanner;


public class Main {

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

		int N = sc.nextInt();
		int sum = 0;

		for(int i = 1; i <= N; i++) {
			for(int j = 1; j <= N; j++) {
				for (int k = 1; k <= N; k++) {
					sum = sum + gcd(i, j, k);
				}
			}
		}

		System.out.println(sum);
	}

	public static final int gcd(final int... param) {
	    final int len = param.length;
	    int g = getCommonDivisor(param[0], param[1]);    //gcd(a, b) は以前作ったもの
	    for (int i = 1; i < len - 1; i++) {
	        g = getCommonDivisor(g, param[i + 1]);       //gcd(a, b) は以前作ったもの
	    }
	    return g;
	}

	private static int getCommonDivisor(int x, int y) {
        int biggerNum = Math.max(x, y);
        int smallerNum = Math.min(x, y);

        // 大きい方から小さい方を割った余を求める
        int surplus = biggerNum % smallerNum;

        // 割り切れていれば、それを返す
        if (surplus == 0) {
            return smallerNum;
        }
        // 割り切れなければ再帰的に自信を呼び出す
        surplus = getCommonDivisor(smallerNum, surplus);

        return surplus;
    }
}

Measured memory_bytes: 30456
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    int N;
    cin >> N;
    vector<int> P(N);
    vector<int> Q(N);
    for ( int i = 0; i < N; i++ ) {
        cin >> P.at(i);
    }
    for ( int i = 0; i < N; i++ ){
        Q.at(i) = i + 1;
    }
    
    if ( P == Q ){
        cout << "YES" << endl;
    }
    
    else {
    int A,B,X,Y;
    A = B = X = Y = 0;
    for ( int i = 0; i < N - 1; i++ ) {
          if ( P.at(i) > P.at(i+1) && A != 0 && B == 0) {
            B += P.at(i+1);
            Y += (i + 1);
            break;
        }
        if ( P.at(i) > P.at(i+1) && A == 0 && B == 0 ) {
           A += P.at(i);
           X += i;
        }
       }
    
        P.at(Y) = A;
        P.at(X) = B;
   
    if ( P == Q ) {
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }
    }
}


Measured memory_bytes: 256
class cumulative_sum:
    def __init__(self,A):
        N = len(A)
        self.S = [0]*(N+1)
        for i in range(N):
            self.S[i+1] = self.S[i] + A[i]
    def get(self,i,j=None):
        if j==None:j=len(self.S)-1
        if j<=i:return 0
        return self.S[j]-self.S[i]

N,K = map(int,input().split())
*A, = map(int,input().split())
B = [max(0,a) for a in A]
SA = cumulative_sum(A)
SB = cumulative_sum(B)
ans = 0
for i in range(N-K+1):
    tmp = max(0,SA.get(i,i+K)) + SB.get(0,i) + SB.get(i+K)
    ans = max(ans,tmp)
print(ans)

Measured memory_bytes: 17744
//的場梨沙★担当
//結城晴★副担当
//日野茜★副担当
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string.h>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <cctype>
#include <complex>
#include <regex>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <stdio.h>


using namespace std;

int main(void) {
    int A,B,C;
    cin>>A>>B>>C;

    cout<<C<<" "<<A<<" "<<B<<endl;


}


Measured memory_bytes: 256
# include "iostream"
# include "cstdio"
# include "algorithm"

using namespace std;

const int maxm=1e3+10;
const int maxn=1e4+10;

int N;
long long DP[maxn<<1];

struct thing{
	int W;
	int S;
	int V;
	# define W(x) Thing[x].W
	# define S(x) Thing[x].S
	# define V(x) Thing[x].V
}Thing[maxm];

inline bool Comp(thing x,thing y){
	return x.S+x.W<y.S+y.W;
}

int main(){
	register int i,j,Max=0;
	register long long Ans=0;
	scanf("%d",&N);
	for(i=1;i<=N;i++) scanf("%d%d%d",&W(i),&S(i),&V(i)),Max=max(Max,S(i)+W(i));
	sort(Thing+1,Thing+1+N,Comp);
	for(i=1;i<=N;i++){
		for(j=S(i);j>=0;j--){
			DP[j+W(i)]=max(DP[j+W(i)],DP[j]+V(i));
		}
	}
	for(i=1;i<=Max;i++) Ans=max(Ans,DP[i]);
	printf("%lld",Ans);
	return 0;
}

Measured memory_bytes: 384
package main

import "fmt"

func main() {
	var a, b int

	fmt.Scan(&a, &b)

	n := [3]int{a + b, a - b, a * b}
	m := n[0]
	for i := 1; i < len(n); i++ {
		if m < n[i] {
			m = n[i]
		}
	}

	fmt.Println(m)
}


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

using namespace std;

using ll = long long int;

int main() {
    ll N,M; cin >> N >> M;
    vector<ll> A(N);

    for(auto& a : A) cin >> a;

    ll sum = 0;
    map<ll,ll> pos;
    pos[0] = 1;

    for(int i=0;i<N;i++) {
        sum += A[i];
        pos[sum%M]++;
    }

    ll ans = 0ll;
    for(auto p : pos) {
        ans += (p.second * (p.second-1))/2;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 4992
#include<iostream>
#include<algorithm>
int main(){
    int N,i,sum=0,L[202];
    std::cin >> N;
    for(i=0; i<N*2; ++i) std::cin >> L[i];
    std::sort(L,L+N*2);
    for(i=0; i<N*2; i+=2) sum += L[i];
    std::cout << sum;
}

Measured memory_bytes: 256