akhauriyash/Code-Regression huggingface dataset:
//include
//------------------------------------------
#include <bits/stdc++.h>

using namespace std;

//typedef
//------------------------------------------
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vbb;
typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;

//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 iter(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)

//repetition
//------------------------------------------
#define loop(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  loop(i,0,n)

//constant
//--------------------------------------------
const double eps = 1e-10;
const double pi  = acos(-1.0);
const double inf = (int)1e8;

// output vector
// ------------------------------------------
namespace std {
    template<typename T> ostream & operator<<(ostream& os, vector<T> const& v){
        for(auto it=v.begin(); it!=v.end(); ++it){
            os << *it << (it+1==v.end() ? "" : ",");
        }
        return os;
    }
}

//clear memory
#define clr(a) memset((a), 0 ,sizeof(a))

bool pairCompare(const std::pair<string, int>& firstElem, const std::pair<string, int>& secondElem) {
    return firstElem.second > secondElem.second;
}

int main(){
    int n, m;
    while(cin >> n >> m, n+m){
        vector<pair<string, int> > t;
        vs h;
        rep(i, n){
            string p; int q;
            cin >> p >> q;
            t.pb(mp(p, q));
        }
        rep(i, m){
            string p;
            cin >> p;
            h.pb(p);
        }
        sort(all(t), pairCompare);

        int ans = 0;
        rep(i, m){
            rep(j, n){
                int star = 0;
                rep(k, t[j].first.size()){
                    if(t[j].first.substr(k, 1) == "*") star++;
                    else break;
                }
                string s = h[i];
                if(s.substr(star) == t[j].first.substr(star)){
                    ans += t[j].second;
                    break;
                }
            }
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 1288
#include <stdio.h>
#include <iostream>
#include <vector>
#include <list>
#include <cmath>
#include <fstream>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <iterator>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <cassert>

using namespace std;

#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) (EQ((a).real(),(b).real()) && EQ((a).imag(),(b).imag()))

typedef complex<double> P;
typedef long long ll;

int h,w;
char field[40][40];
map<char,int> idxs;
int idx;
bool passed[1<<12][31][31];
const int dy[]={-1,0,0,1};
const int dx[]={0,-1,1,0};

class Sit{
public:
  int s;
  int x;
  int y;
};

int bfs(pair<int,int> sp,pair<int,int> goal){
  queue<Sit> *prv=new queue<Sit>();
  queue<Sit> *nxt=new queue<Sit>();
  Sit ssit;
  ssit.s=0;
  ssit.x=sp.second;
  ssit.y=sp.first;
  prv->push(ssit);
  int dist=0;
  passed[0][sp.first][sp.second]=true;
  while(prv->size()){
    while(prv->size()){
      Sit cp=prv->front();prv->pop();
      if(cp.x==goal.second&&cp.y==goal.first){
	delete prv;delete nxt;
	return dist;
      }
      for(int i = 0; i < 4; i++){
	int ny=cp.y+dy[i];
	int nx=cp.x+dx[i];
	if(ny>=0&&nx>=0&&ny<h&&nx<w){
	  int bases=cp.s;
	  // carpet
	  if(field[ny][nx]>='a'&&field[ny][nx]<='z'){
	    int x=idxs[(char)(field[ny][nx])];
	    if((bases>>x)&1)
	      bases&=~(1<<x);
	    else
	      bases|=(1<<x);
	  }
	  if(field[ny][nx]!='#'
	     &&!passed[bases][ny][nx]){
	    // iwa
	    if(field[ny][nx]>='A'&&field[ny][nx]<='Z'){
	      if(idxs.find((char)(field[ny][nx]+32))
		 ==idxs.end()){
		continue;
	      }
	      int x=idxs[field[ny][nx]+32];
	      if(!((bases>>x)&1))
		continue;
	    }
	    passed[bases][ny][nx]=true;
	    Sit nsit;
	    nsit.s=bases;
	    nsit.x=nx;
	    nsit.y=ny;
	    nxt->push(nsit);
	  }
	}
      }
    }
    dist++;
    swap(prv,nxt);
  }
  delete prv;
  delete nxt;
  return -1;
}

int main(){
while(cin>>w>>h&&!(w==0&&h==0)){
    memset(passed,0,sizeof(passed));
    pair<int,int> sp,gp;
    idxs.clear();
    idx=0;
    for(int i = 0; i < h; i++){
      for(int j = 0; j < w; j++){
	cin>>field[i][j];
	if(field[i][j]=='@'){
	  sp.first=i;sp.second=j;
	  field[i][j]='.';
	}
	else if(field[i][j]=='<'){
	  gp.first=i;gp.second=j;
	  field[i][j]='.';
	}
	else if(field[i][j]!='#'&&field[i][j]!='.'){
	  char ch=field[i][j];
	  if(ch>='a'&&ch<='z'){
	    if(idxs.find(ch)==idxs.end())
	      idxs[ch]=idx++;
	  }
	}
      }
    }
    int res=bfs(sp,gp);
    cout<<res<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace D
{
    class Program
    {
        static void Main(string[] args)
        {
            long[] X = new long[3];
            string[] str = Console.ReadLine().Split(' ');
            for (int i = 0; i < 3; i++)
            {
                X[i] = long.Parse(str[i]);
            }
            long K = long.Parse(str[3]);

            List<long> a = new List<long>();
            List<long> b = new List<long>();
            List<long> c = new List<long>();
         //   long[] a = new long[X[0]];
           // long[] b = new long[X[1]];
            //long[] c = new long[X[2]];
            
            str = Console.ReadLine().Split(' ');
            for (int i = 0; i < X[0]; i++)
            {
                a.Add(long.Parse(str[i]));
                //a[i]= long.Parse(str[i]);
            }
            str = Console.ReadLine().Split(' ');
            for (int i = 0; i < X[1]; i++)
            {
                b.Add(long.Parse(str[i]));
            //    b[i] = long.Parse(str[i]);
            }
            str = Console.ReadLine().Split(' ');
            for (int i = 0; i < X[2]; i++)
            {
                c.Add(long.Parse(str[i]));
             //   c[i] = long.Parse(str[i]);
            }
            a.Sort(CompareDesending);
            b.Sort(CompareDesending);
            c.Sort(CompareDesending);
            List<long> lis = new List<long>();
            for (int i = 0; i < X[0]; i++)
            {
                for (int k = 0; k < X[1]; k++)
                {
                    if ((i+1) * (k+1) > K) { break; }
                    for (int l = 0;  l < X[2];  l++)
                    {
                        if ((i + 1) * (k + 1) * (l + 1) > K) { break; }
                        lis.Add(a[i] + b[k] + c[l]);
                    }
                }
            }
            lis.Sort(CompareDesending);
            for (int i = 0; i < K; i++)
            {
                Console.WriteLine(lis[i]);
            }
            
        }
        static int CompareDesending(long x, long y)
        {
            return y.CompareTo(x);
        }
    }
   
}


Measured memory_bytes: 15584
#include<bits/stdc++.h>
using namespace std;
string s,t;
long long x[100],n,ans;
vector<long long> v[100];
int main(){
	cin>>s>>t;
	for (int i=0;i<s.size();i++) x[s[i]-'a']++;
	for (int i=0;i<t.size();i++)
		if (x[t[i]-'a']==0){
			cout<<-1<<endl;
			return 0;
		}
	for (int i=0;i<s.size();i++) v[s[i]-'a'].push_back(i);
	n=-1;
	for (int i=0;i<t.size();i++){
		int lbound=0,rbound=v[t[i]-'a'].size()-1;
		while (lbound<rbound){
			int mid=(lbound+rbound)/2;
			if (v[t[i]-'a'][mid]>n)
				rbound=mid;
			else
				lbound=mid+1;
		}
		int z=v[t[i]-'a'].size();
		for (int j=max(0,lbound-1000);j<min(z,lbound+1000);j++)
			if (v[t[i]-'a'][j]>n){
				lbound=j;
				break;
			}
		if (v[t[i]-'a'][lbound]<=n){
			ans++;
			n=v[t[i]-'a'][0];
		}
		else
			n=v[t[i]-'a'][lbound];
	}
	cout<<ans*s.size()+n+1<<endl;
	return 0;
}

Measured memory_bytes: 1724
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5;
int n;
string s;
map<string,int>Hash;
struct per{
    string s;
    int num;
    bool operator < (const per &a) const {
        return num==a.num?s<a.s:num>a.num;
    }
}pers[N];
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>s;
        Hash[s]++;
    }
    int cnt=0;
    for(auto &x:Hash){
        pers[cnt++]={x.first,x.second};
    }
    sort(pers,pers+Hash.size());
    int maxx=pers[0].num;
    for(int i=0;i<Hash.size();i++){
        if(pers[i].num==maxx)cout<<pers[i].s<<endl;
        else break;
    }
    return 0;
}

Measured memory_bytes: 28288
#include <stdio.h>
#include <string>
#include <iostream>
#include <iomanip>
#include <map>
#include <algorithm>
#include <vector>
#include <math.h>
#define MOD (long long)1000000007
using namespace std;

int main(void){
    string s;
    cin >> s;
    s=s.substr(5,2);
    if(stoi(s)<=4)cout << "Heisei" << endl;
    else cout << "TBD" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <ctype.h>

int main(){
   char ch;

   scanf("%c", &ch);
   while(ch != 0x0a){
      if( isalpha(ch) ){
         if( islower(ch) ){
            ch = toupper(ch);
            printf("%c", ch);
            scanf("%c", &ch);
         } else{
             ch = tolower(ch);
             printf("%c", ch);
             scanf("%c", &ch);
         }
      } else{
           printf("%c", ch);
           scanf("%c", &ch);
      }
   }

   printf("\n");
   return 0;
}



Measured memory_bytes: 2040
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < n; ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
#define FORV(i, v) for (auto i = v.begin(); i != v.end(); i++)
using namespace std;

typedef int64_t ll;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const int INF = 1001001001;
const long long INFL = (1LL<<60);
const double eps = (1e-9);

bool can_exterminate(const vector<ll>& h, const ll& n, const ll& a, const ll& b) {
  ll ext = a - b;
  ll nn = n;
  rep(i, h.size()) {
    ll rem = h[i] - b * n;
    if (rem > 0) {
      nn -= (rem + ext - 1) / ext;
    }
    if (nn < 0) return false;
  }
  return true;
}

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

  ll n, a, b;
  cin >> n >> a >> b;
  vector<ll> h(n);
  rep(i, n) cin >> h[i];
  sort(ALL(h), greater<ll>());

  ll lb = 0;
  ll ub = 1e+9;

  while (ub - lb > 1) {
    ll mid = lb + (ub - lb) / 2;
    if (can_exterminate(h, mid, a, b)) ub = mid;
    else lb = mid;
  }

  cout << ub << endl;

  return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
int main(void);

int main(void){
    
    int a, b;
    int Menseki, Syuu;
    
    scanf("%d", &a);    scanf("%d", &b);
    
    Menseki = a * b;
    Syuu = 2 * (a + b);
    
    printf("%d %d\n", Menseki, Syuu);
    
    return 0;
}


Measured memory_bytes: 2028
#!/usr/bin/env python3
# vim: set fileencoding=utf-8

# pylint: disable=unused-import, invalid-name, missing-docstring, bad-continuation


"""Module docstring
"""

import sys
from collections import deque


def solve(values, nb, max_jump_size):
    max_jump_size = min(nb, max_jump_size)
    cost_to = [0]
    for i in range(1, nb):
        new_cost = min(
            cost_to[i - k] + abs(values[i] - values[i - k])
            for k in range(1, max_jump_size + 1)
            if i - k >= 0
        )
        cost_to.append(new_cost)
    return new_cost


def do_job():
    "Do the work"
    # first line is number of test cases
    N, K = map(int, input().split())
    values = list(map(int, input().split()))
    result = solve(values, N, K)
    print(result)


def print_output(testcase, result) -> None:
    "Formats and print result"
    if result is None:
        result = "IMPOSSIBLE"
    print("Case #{}: {}".format(testcase + 1, result))


def main(argv=None):
    "Program wrapper."
    if argv is None:
        argv = sys.argv[1:]
    do_job()
    return 0


if __name__ == "__main__":
    import doctest

    doctest.testmod()
    sys.exit(main())


Measured memory_bytes: 94500
package main

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

func main() {
	scanner := makeWordScanner()
	n := eGetInt(scanner)
	k := 0
	for i := 1; i <= n; i++ {
		p := eGetInt(scanner)
		if p != i {
			k++
		}
	}
	if k <= 2 {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

////////////////////////////////////////////////////////////////////////////////
// ライブラリ
////////////////////////////////////////////////////////////////////////////////
func makeScanner(maxByte int) *bufio.Scanner {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Buffer(make([]uint8, 0, 8192), maxByte)
	return scanner
}
func makeWordScanner() *bufio.Scanner {
	scanner := makeScanner(8192)
	scanner.Split(bufio.ScanWords)
	return scanner
}
func eGetLine(r *bufio.Scanner) string {
	if r.Scan() {
		return r.Text()
	}
	err := r.Err()
	if err != nil {
		log.Fatal(err)
	}
	// EOF
	return ""
}
func eGetInt(r *bufio.Scanner) int {
	line := eGetLine(r)
	return eAtoi(line)
}
func eGetInt64(r *bufio.Scanner) int64 {
	line := eGetLine(r)
	return eAtoInt64(line)
}
func eGetFields(r *bufio.Scanner) []string {
	line := eGetLine(r)
	return strings.Fields(line)
}
func eGetInts(r *bufio.Scanner) []int {
	fields := eGetFields(r)
	ints := make([]int, len(fields))
	for i := 0; i < len(ints); i++ {
		ints[i] = eAtoi(fields[i])
	}
	return ints
}
func eGetInt64s(r *bufio.Scanner) []int64 {
	fields := eGetFields(r)
	ints := make([]int64, len(fields))
	for i := 0; i < len(ints); i++ {
		ints[i] = eAtoInt64(fields[i])
	}
	return ints
}
func eGetChars(r *bufio.Scanner) []string {
	line := eGetLine(r)
	return strings.Split(line, "")
}
func eAtoi(s string) int {
	n, err := strconv.Atoi(s)
	if err != nil {
		log.Fatal(err)
	}
	return n
}
func eAtoInt64(s string) int64 {
	n, err := strconv.ParseInt(s, 10, 64)
	if err != nil {
		log.Fatal(err)
	}
	return n
}


Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<cmath>
#include<stack>
#include<queue>
#include<vector>

using namespace std;

int main() {
  vector<int> a(5);
  cin >> a[0] >> a[1] >> a[2] >> a[3] >> a[4];

  int res = 1000000;
  for (int i=0; i<5; i++) {
    int tmp = 0;
    for (int j=0; j<5; j++) {
      if (i == j) continue;
      tmp += a[j];
      if (0 != tmp%10) {
        tmp += 10 - tmp%10;
      }
    }

    tmp += a[i];
    res = min(res, tmp);
  }

  cout << res << endl;
}


Measured memory_bytes: 256
/*input

*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}

//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		
		b>>=1;
	}
	return res;
}

int main()
{
	IOS;
	int n,a,b;
	cin>>n>>a>>b;
	cout<<min(a,b)<<' '<<max(0,a+b-n);
	return 0;
}


Measured memory_bytes: 256
n , *a_s = map(int,open(0).read().split())
tmp = [3] + [0 for _ in range(n+1)]
ans = 1
for a in a_s:
  ans = ans * tmp[a] % 1000000007
  tmp[a] -= 1
  tmp[a+1] += 1
  
print(ans)

Measured memory_bytes: 13980
#include <bits/stdc++.h>
	
using namespace std;
	
#define endl "\n"
#define ll unsigned long long
#define int long long
#define vi vector <int >
#define vii vector < pii >
#define vll vector <ll >
#define pii pair <int, int>
#define pdd pair< double, double>
#define piii pair < pii, int > 
#define pll pair<ll, ll >
#define umap unordered_map
#define pb push_back
#define pq priority_queue
#define forn(i, n) for(int i = 0; i < (int)n; i++)
#define rep(i,b,c) for(int i = (int)b; i < (int)c; i++)
#define a first
#define b second
int n;

int dp[11000];
vii arr(1100);


int f(int health){
    if(health <= 0){
        return 0;
    }
    if(~dp[health]) return dp[health];

    int ans = INT_MAX;
    forn(i, n){
        ans = min(ans, arr[i].b + f(health - arr[i].a));
    }

    return dp[health] = ans;
}

 
 
int32_t main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);

    int h;
    cin >> h >> n;
    memset(dp, -1, sizeof dp);
    forn(i, n){
        cin >> arr[i].a >> arr[i].b;
    }
    cout << f(h) << endl;



    

    return 0;
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define P pair<ll,ll> 
#define rep(i,n) for(ll (i)=0; (i)<(n); ++(i))
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,m,a,b,from=0,to=0,ans=0;cin>>n>>m;
  lvector v(n-1,0); rep(i,n-1) v[i]=i+1;
  map<P,ll> mp;
  rep(i,m) {
    cin>>a>>b;
    a--,b--;
    mp[P(a,b)]=1,mp[P(b,a)]=1;
  }
  bool isok=true;
  do{
    from=0;
    isok=true;
    for(ll i:v) {
      to=i;
      if(mp[P(from,to)]==1) from=i;
      else {isok=false;break;}
    }
    if(isok) ans++;
  }
  while(next_permutation(v.begin(),v.end()));
  print(ans);
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <numeric>
#include <regex>
#include <climits>

#define FOR(i, f, n) for(int (i) = (f); (i) < (n); (i)++)
#define RFOR(i, f, n) for(int (i) = (f); (i) >= (n); (i)--)
#define REP(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define RREP(i, n) for(int (i) = (n); (i) >= 0; (i)--)
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for(int (i) = (n); (i) >= 0; (i)--)
#define forin(i, a) for(auto i: (a))
#define p(...) printf(__VA_ARGS__); cout << endl;
#define in(...) __VA_ARGS__; input__(__VA_ARGS__);
#define input(...) in(__VA_ARGS__)
#define out(...) output__(__VA_ARGS__);
#define output(...) out(__VA_ARGS__)
#define list_input(x, n) x[(n)]; for(int (i) = 0; (i) < (n); (i)++) cin >> x[i];
#define lambda(a, b, c) [](auto const &a, auto const &b){ return c ;}
#define key(t, x, compare) [](const t &a, const t &b){ return a x compare b x ;}
#define unless(a) if(!(a))

using namespace std;

using pii = pair<int, int>;

template <class... T>
void input__(T &...a) {
  for(auto v: {&a...}) {
    cin >> *v;
  }
}

void output__(){
  cout << endl;
}

template <class Head, class... T>
void output__(Head const &v, T const &...a) {
  if(sizeof...(a) == 0) {
    cout << v;
  } else {
    cout << v << " ";
  }
  output__(a...);
}

int main(){
  long long in(n);
  long long list_input(x, n);

  long long step[n];
  step[0] = abs(x[1]);
  step[n - 1] = abs(x[n - 2]);
  FOR(i, 1, n - 1) {
    step[i] = abs(x[i - 1] - x[i + 1]);
  }

  long long sum[n + 1];
  sum[0] = abs(x[0]);
  FOR(i, 1, n) {
    sum[i] = sum[i - 1] + abs(x[i - 1] - x[i]);
  }
  sum[n] = sum[n - 1] + abs(x[n - 1]);
  out(sum[n] - sum[1] + step[0]);
  FOR(i, 1, n) {
    out(sum[n] - sum[i + 1] + sum[i - 1] + step[i]);
  }
}


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

int main() {
  int N; cin >> N;
  
  int ten = N / 10;
  int one = N % 10;
  
  if(ten == 9 || one == 9) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
  return 0;
}

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

int main() {
  long long  a,b,c;
  cin>>a>>b>>c;
  if(a+b>=c||a>=c||b>=c){
    cout<<"No"<<endl;
    return 0;
  }
  if((a-b)*(a-b)+(b-c)*(b-c)+(c-a)*(c-a)>a*a+b*b+c*c){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
}


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

#define rep(i, n) for ( int i = 0; i < (n); ++i )
using namespace std;
using ll =  long long;
using P = pair<ll, ll>;

int main( void )
{
	ll r;

	cin >> r;

	cout << (2 * r *3.1415926535) << endl;

	return 0;
}


Measured memory_bytes: 3776
N,M = gets.split.map &:to_i
S = gets.split.map &:to_i
T = gets.split.map &:to_i
Mod = 10**9+7
V = (0..N).map{ Array.new(M+1,0) }
(0..N).each{ |i| V[i][0] = 1 }
(0..M).each{ |i| V[0][i] = 1 }
(1..N).each{ |i|
  vii = V[i-1]
  vi  = V[i]
  sii = S[i-1]
  (1..M).each{ |j|
    u = sii != T[j-1] ? 0 : vii[j-1]
    vi[j] = (u + vii[j] + vi[j-1] - vii[j-1]) % Mod
  }
}
p V[-1][-1]


Measured memory_bytes: 33276
#include<bits/stdc++.h>
using namespace std;
int a[1000001];
int b[1000001];
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<n;i++)
		scanf("%d",&b[i]);
	a[1]=b[1];
	for(int i=2;i<n;i++)
		a[i]=min(b[i-1],b[i]);
	a[n]=b[n-1];
	int ans=0;
	for(int i=1;i<=n;i++)
		ans+=a[i];
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 2304
#define M 1000001
T[M];long long p[M];
main(i,j){
for(i=0;i<M;i++)p[i]=i;
for(i=2;i<M;i++)if(!T[i])for(j=i;j<M;j+=i)T[j]=1,p[j]-=p[j]/i;
for(i=1;i<M;i++)p[i]+=p[i-1];
for(scanf("%d",&i);i;i--)scanf("%d",&j),printf("%lld\n",p[j]+1);
exit(0);}

Measured memory_bytes: 12312
import java.util.*;
public class Main {
  public static void main(String[] args) {
    
    Scanner sc = new Scanner(System.in);
    
    int N = sc.nextInt();
    
    int preT = 0;
    int preX = 0;
    int preY = 0;
    
    // 標準入力
    
    for (int i = 0 ; i<N ; i++){
        
        int postT = sc.nextInt();
        int postX = sc.nextInt();
        int postY = sc.nextInt();

        // 移動距離
        int distance = Math.abs(postX-preX)+Math.abs(postY-preY);

        // 目的地到達までの時間
        int dt = postT-preT;

        if(distance > dt || (dt - distance) % 2 != 0){

            System.out.println("No");
            return;
        }

        preT = postT;
        preX = postX;
        preY = postY;
        
    }
    sc.close();
    System.out.println("Yes");
  }
 
}

Measured memory_bytes: 85020
s=input()

a=""
for i in range(len(s)):
    if s[i]=="0":
        a+="0"
    elif s[i]=="1":
        a+="1"
    elif len(a)!=0 and s[i]=="B":
        a=a[0:-1]
    else:
        continue
print(a)

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

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

	int n;
	cin >> n;
	vector<ll>	V(3 * n);
	rep(i, 3 * n)
		cin >> V.at(i);
	sort(V.begin(), V.end());
	int j;
	j = V.size() - 2;
	ll sum;
	sum = 0;
	rep(i, n)
	{
		sum += V.at(j);
		j -= 2;
	}
	cout << sum << endl;
}


Measured memory_bytes: 2560
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<time.h>

int main()
{
    int n, i,q, r;
    scanf("%d", &n);
    for (i = 1; i <= 9;i++)
    {
        if((r=n%i)==0)
        {
            if((q=n/i)>=1&&q<=9)
            {
                printf("Yes");
                return 0;
            }
        }
    }
    printf("No");

    return 0;
}

Measured memory_bytes: 128
def main():
    cost, dislike = map(int, input().split())
    dislike_numbers = list(input().split())
    answer = cost
    while True:
        if not set(str(answer)) & set(dislike_numbers):
            print(answer)
            break
        else:
            answer += 1


if __name__ == '__main__':
    main()



Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main(){
  ll n;
  in(n);
  out("Christmas");
  rep(i, 25 - n){
    hina;
    out("Eve");
  }
  memi;
}

Measured memory_bytes: 256
N,Y = map(int,input().split())
sum = 0

for x in range(N+1):
    for y in range(N-x+1):
        z = N-x-y
        if x*1000+y*5000+z*10000 == Y:
            print(z,y,x)
            exit()
print(-1,-1,-1)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define _MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define _rep(i,n) _repl(i,0,n)
#define rep(...) _MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define pb push_back
#define all(x) begin(x),end(x)
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#ifdef LOCAL
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cerr<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cerr<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream &o, const pair<T,U> &p){o<<"("<<p.first<<","<<p.second<<")";return o;}
template<class T> ostream& operator<<(ostream &o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}
#else
#define dbg(...) {}
#endif

int main(){
  long n,m;
  cin>>n>>m;

  long g = __gcd(n,m);

  string s,t;
  cin>>s>>t;

  long ll = n*m/g;

  rep(i,g){
    if(s[n/g*i] != t[m/g*i]){
      cout << -1 << endl;
      return 0;
    }
  }

  cout << ll << endl;

  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define FIN         ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ii          pair<int,int>
#define F           first
#define S           second
#define pb          push_back
#define all(x)      (x).begin(),(x).end()
#define rall(x)     (x).rbegin(),(x).rend()
#define fore(i,a,b) for(int i = a;i < b; i+= 1)
#define forr(i,a)   for(int i = a; i >= 0; i--)
#define fori(i,m)   for(auto i = m.begin(); i != m.end(); i++) 
#define w(t)        while(t--)
#define sz(s)       int(s.size())
#define cls(a,car)  memset(a,car,sizeof (a))
#define db(x)       cerr << #x << " is " << x << '\n'
#define FL          freopen("input.txt", "r", stdin),freopen("output.txt", "w", stdout);
#define EjecuteTime cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"
#define angle(x)    double(x * acos(-1) / 180.0)
using namespace std;
typedef long long   ll;
typedef vector<int> vi;
typedef vector<ii>  vii;
const int N = 1 * 1e5 + 5;
const ll mod = 1e9 + 7;
const double E = 1e-9;
//int dx[] = {1, 0}, dy[] = {0, 1};
//int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
//int dx[] = {2, 1, -1, -2, -2, -1, 1, 2}, dy[] = {1, 2, 2, 1, -1, -2, -2, -1};
//int dx[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy[] = {0 ,1, 1, 1, 0, -1, -1, -1};
// fflush(stdout)
// cout << flush
// a + b = a ^ b + 2 * (a & b)
int n, W;
int w[101], v[101];
ll dp[2][N];
ll f(int i, int cost){
    if(cost < 0)
        return -1e18;
    if(i == n)
        return 0;
    ll &ans = dp[i][cost];
    if(ans == -1){
        ans = max(f(i + 1, cost), f(i + 1, cost - w[i]) + v[i]);
    }return ans;
}
int main(){
    //FL;
    FIN;
    //optimizando memoria
    cin >> n >> W;
    for(int i = 0; i < n; i++)
        cin >> w[i] >> v[i];
    for(int i = n; i >= 0; i--){
        for(int cost = 0; cost <= W; cost++){
            ll &ans = dp[i & 1][cost];    
            if(i == n){
                ans = 0;
                continue;
            }
            ans = max(ans, dp[(i + 1) & 1][cost]);
            if(cost - w[i] >= 0)
                ans = max(ans, dp[(i + 1) & 1][cost - w[i]] + v[i]);
        }
    }
    cout << dp[0][W] << '\n';
    EjecuteTime;
    return 0;
}       

Measured memory_bytes: 5364
n = int(input())
a = list(map(int, input().split()))
f = []
b = []
now = 0
for ai in a:
    now ^= ai
    f.append(now)
now = 0
for ai in reversed(a):
    now ^= ai
    b.append(now)
b.reverse()
for i in range(n):
    ans = 0
    if i > 0:
        ans ^= f[i-1]
    if i < n-1:
        ans ^= b[i+1]
    print(ans, end=' ' if i < n - 1 else '\n')


Measured memory_bytes: 32820
def main():
    import sys
    def input(): return sys.stdin.readline().rstrip()
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    mod = 10 ** 9+ 7
    ans = 1

    def answer(a):
        ans =1
        for x in a:
            ans *= x
            ans %= mod
        return ans

    if n == k:
        print(answer(a))
        return
    a.sort(reverse=True, key= lambda x:abs(x))
    if sum(x<0 for x in a[:k])%2 == 0:
        print(answer(a[:k]))
    else:
        if all(x < 0 for x in a):
            print(answer(a[-k:]))
        else:
            try:
                x1, y1= min([x for x in a[:k] if x > 0]), min([x for x in a[k:] if x < 0])
            except ValueError:
                x1, y1 = 1, 0
            try:
                x2, y2= max([x for x in a[:k] if x < 0]),\
                    max([x for x in a[k:] if x >= 0])
            except ValueError:
                x2, y2 = 1, 0
            if abs(x2*y1) > abs(x1*y2):           
                a[a.index(x1)] = y1
            else:
                a[a.index(x2)] = y2
            print(answer(a[:k]))
            


if __name__ == '__main__':
    main()

Measured memory_bytes: 31968
// // -*- coding:utf-8-unix -*-

// #[macro_use]
// extern crate lazy_static;
// extern crate num_bigint; // 0.2.2
// extern crate num_traits; // 0.2.8
// use num_bigint::BigInt;
// use num_traits::Pow;
// use petgraph::algo::dijkstra;
// use petgraph::Directed;

// // use proconio::derive_readable;
// use proconio::fastout;
// use proconio::input;
// // use std::convert::TryInto;
// use ascii::{AsciiChar, AsciiString};
// use itertools::concat;
// use lazy_static::lazy_static;
// use libm::*;
// use petgraph::Graph;
// use std::cmp::*;
// use std::collections::{BinaryHeap, HashMap, HashSet, VecDeque};
// use std::io::*;
// use std::ops::Range;
// use std::str::FromStr;
// use std::sync::Mutex;
// use superslice::*;

// pub fn read<T: FromStr>() -> T {
//     let stdin = stdin();
//     let stdin = stdin.lock();
//     let token: String = stdin
//         .bytes()
//         .map(|c| c.expect("failed to read char") as char)
//         .skip_while(|c| c.is_whitespace())
//         .take_while(|c| !c.is_whitespace())
//         .collect();
//     token.parse().ok().expect("failed to parse token")
// }

// // lazy_static! {
// //     static ref H: Mutex<Vec<i32>> = Mutex::default();
// //     static ref W: Mutex<Vec<i32>> = Mutex::default();
// // }

// // let mut values = VALUES.lock().unwrap();
// // values.extend_from_slice(&[1, 2, 3, 4]);
// // assert_eq!(&*values, &[1, 2, 3, 4]);

use proconio::{input, marker::Chars};
use std::collections::HashMap;

// static ASCII_LOWER: [char; 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',
// ];

// abc064-D
fn main() {
    input! {
        n: usize,
        s: Chars
    }

    let mut from_l = vec![-1; n];
    let mut from_r = vec![-1; n];

    from_l[0] = if s[0] == ')' { -1 } else { 1 };
    for (i, s) in s.iter().enumerate() {
        if (i == 0) {
            continue;
        }

        from_l[i] = from_l[i - 1] + if *s == ')' { -1 } else { 1 };
    }

    from_r[0] = if *s.last().unwrap() == '(' { -1 } else { 1 };
    for (i, s) in s.iter().rev().enumerate() {
        if (i == 0) {
            continue;
        }

        from_r[i] = from_r[i - 1] + if *s == '(' { -1 } else { 1 };
    }

    let to_fill_l = if *from_l.iter().min().unwrap() >= 0 {
        0
    } else {
        from_l.iter().min().unwrap() * -1
    };
    let to_fill_r = (from_r.last().unwrap() - to_fill_l) * -1;
    // eprintln!("{},{}, {}", to_fill_l, to_fill_r, from_r.last().unwrap());

    for _ in 0..to_fill_l {
        print!("(");
    }
    for s in s.iter() {
        print!("{}", s);
    }
    for _ in 0..to_fill_r {
        print!(")");
    }
    println!("");

    return;
}


Measured memory_bytes: 2172
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<int, int>;
#define rep(i,n) for(int i=0; i<(n); i++)
#define precision(x) fixed << setprecision(x)
#define all(x) (x).begin(),(x).end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(all(x))
#define SUM(x) accumulate(all(x),0LL)
#define SIZE(x) ((ll)(x).size())
#define INF 1000000000000

int gcd(int a,int b){return b?gcd(b,a%b):a;}
const double PI = acos(-1);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main() {
    int h, w;
    while(1){
        cin >> h >> w;
        if(h == 0 && w == 0) break;
        rep(i,h){
            rep(j,w){
                if(i == 0 || i == h-1 || j == 0 || j == w-1) cout << "#";
                else cout << ".";
            }
            cout << endl;
        }
        cout << endl;
    }
}


Measured memory_bytes: 3132
l = [[int(i) for i in input().split()] for M in range(3)]

ans = "No"
for i in range(min(l[0])+1): # a1
    for j in range(min(l[1])+1): #a2
        for k in range(min(l[2])+1):
            if (l[0][0] - i) == (l[1][0] - j) and (l[0][0] - i) == (l[2][0] - k) and\
                (l[0][1] - i) == (l[1][1] - j) and (l[0][1] - i) == (l[2][1] - k) and\
                (l[0][2] - i) == (l[1][2] - j) and (l[0][2] - i) == (l[2][2] - k):
                ans = "Yes"
print(ans)
        

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

typedef long long ll;

int main()
{
  ll n,a[101],ans=1<<30;

  cin>>n;
  for(int i=0;i<n;i++)cin>>a[i];

  for(int i=-100;i<101;i++){
    ll res=0;
    for(int j=0;j<n;j++)res+=(a[j]-i)*(a[j]-i);
    ans=min(ans,res);
  }

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
 
#define INF (1<<31)//INT_MAX/2
#define MOD 1000000007
 
using ll  = long long;
using ull = unsigned long long;
 
int main(int argc, char *argv[])
{
    int X, Y;
    std::cin >> X >> Y;

    std::cout << X + Y/2 << std::endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
ll pows(ll a,ll b)
{
    ll m=1;
    while(b--)
    {
        m*=a;
    }
    return m;
}
int main()
{
    //int t;cin>>t;while(t--)
    {
        ll a,b,c,d,i,j,k,l,m,n,cnt=0,sum=0,o,p=0;
        ll arr[100];
        for(i=0;i<=10;i++)
        {
            arr[i]=pows(26,p);
            p++;
        }

        cin>>n;
        string ans;
        if(n==1)
        {
            cout<<'a';
            return 0;
        }
        while(n>0)
        {

            k=n%26;
            if(k==0)
                k=26;
           // cout<<"yo "<<k<<endl;
            n-=k;
            ans+=char(k-1+'a');

            n/=26;

        }
        reverse(ans.begin(),ans.end());
        cout<<ans<<endl;







    }
}


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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP (i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back

using namespace std;

typedef long long ll;

const int INF = 1 << 29;

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

    if (s.size() == 2 && s[0] == s[1]) {
        cout << "1 2" << endl;
        return 0;
    }

    rep (i, s.size() - 2) {
        set<char> sc;
        sc.insert(s[i]);
        sc.insert(s[i + 1]);
        sc.insert(s[i + 2]);
        if (sc.size() < 3) {
            cout << i + 1 << ' ' << i + 3 << endl;
            return 0;
        }
    }

    cout << "-1 -1" << endl;
    return 0;
}


Measured memory_bytes: 512
n, m = gets.split.map(&:to_i)

steps = Array.new(n+1)
steps[0] = 1
steps[1] = 1

m.times.map{|i| steps[gets.to_i] = 0 }

(2..n+1).each do |i|
  next if steps[i]
  steps[i] = (steps[i-1] + steps[i-2]) % 1_000_000_007
end

p steps[n]


Measured memory_bytes: 3508
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <random>
#include <algorithm>
#include <chrono>
#include <map>
#define tNow chrono::duration_cast<msec>(chrono::system_clock::now().time_since_epoch())
#define INF (1 << 30)
using namespace std;

typedef chrono::milliseconds msec;

int d, lastVal = -INF, bestVal = -INF, times = 0, groups = 0, updates = 0, positiveUpdates = 0;
vector<int> c(27), cur, ans;
vector< vector<int> > s, ss;

int calc() {
    int sum = 0;
    vector<int> last(27, 0);
    for (int i = 1; i <= d; ++i) {
        sum += s.at(i).at(cur.at(i));
        last.at(cur.at(i)) = i;
        for (int j = 1; j <= 26; ++j) sum -= c.at(j) * (i - last.at(j));
    }
    return sum;
}

void update(int curVal) {
    lastVal = curVal;
    if (bestVal < curVal) {
        bestVal = curVal;
        ans = cur;
        ++positiveUpdates;
    }
    ++updates;
}

int choose(int i, mt19937 m) {
    return lower_bound(ss.at(i).begin(), ss.at(i).end(), m() % ss.at(i).back() + 1) - ss.at(i).begin();
}

int main() {
    random_device r;
    msec st = tNow;
    msec lm = st + chrono::milliseconds(1980);
    cin >> d;
    ss = (s = vector< vector<int> >(d + 1, vector<int>(27)));
    cur.resize(d + 1);
    for (int i = 1; i <= 26; ++i) cin >> c.at(i);
    for (int i = 1; i <= d; ++i) for (int j = 1; j <= 26; ++j) cin >> s.at(i).at(j), ss.at(i).at(j) += ss.at(i).at(j - 1) + s.at(i).at(j);
    // for (int i = 1; i <= d; ++i) for (int j = 1; j <= 26; ++j) cin >> s.at(i).at(j), ss.at(i).at(j) += ss.at(i).at(j - 1) + s.at(i).at(j) + c.at(j);
    mt19937 m(r());
    for (int i = 1; i <= d; ++i) cur.at(i) = max_element(s.at(i).begin(), s.at(i).end()) - s.at(i).begin();;
    update(calc());
    // cur = {0, 1, 17, 13, 14, 13};
    // update(calc());
    // cout << bestVal << endl;
    // for (int i = 1; i <= d; ++i) cout << ans.at(i) << endl;

    while (tNow < lm) {
        ++groups;
        mt19937 m(r());
        for (int i = 0; i < 100; ++i) {
            int changeAt = m() % d + 1, changeTo = choose(changeAt, m), changedFrom = cur.at(changeAt);
            if (changedFrom == changeTo) continue;
            cur.at(changeAt) = changeTo;
            int curVal = calc();
            if (m() % max(1, (lastVal - curVal) / 24) == 0) update(curVal);
            else cur.at(changeAt) = changedFrom;
            ++times;
        }
    }

    for (int i = 1; i <= d; ++i) cout << ans.at(i) << endl;
    msec ed = tNow;
    #ifdef ___DEBUG
    cout << "Best Value: " << bestVal << endl;
    cout << "Best Score: " << max(bestVal + 1000000, 0) << endl;
    cout << "Tried: " << times << "times, " << groups << "groups\n";
    cout << "Updated: " << updates << "times\n";
    cout << (ed - st).count() << "ms\n";
    #endif
    return 0;
}


Measured memory_bytes: 3760
import java.util.*;
import java.io.*;

class Main
{
    public static void main(String[] args)
    {
	    // Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		// Scanner in = new Scanner(Syste8
    	Scanner in = new Scanner(System.in);
    	Main s = new Main();
    	int a = in.nextInt(), b = in.nextInt(), k = in.nextInt();
    	s.qb(a, b, k);
	}

	void qb(int a, int b, int k)
	{
		int taka = a, aoki = b, p = 0;
		while(k-- > 0)
		{
			if(p == 0)
			{
				if(taka % 2 != 0) taka--;
				aoki += taka / 2;
				taka /= 2;
			}
			else
			{
				if(aoki % 2 != 0) aoki--;
				taka += aoki / 2;
				aoki /= 2;
			}
			p = 1 - p;
		}
		System.out.printf("%d %d\n", taka, aoki);
	}

	void qa(String str)
	{
		String rev = new StringBuilder(str).reverse().toString();
		if(str.length() == 2) System.out.println(str);
		else System.out.println(rev);
	}
}

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

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i, a, b) for(int i = (int)(a); i < (int)(b); ++i)
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())
#define RSORT(c) sort((c).rbegin(), (c).rend())
#define CLR(a) memset((a), 0, sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

int main() {
  int w_n, h_n;
  while(cin >> w_n >> h_n, w_n | h_n) {
    map<int, int> ps;
    {
      vi xs;
      int x = 0, dx;
      xs.push_back(x);
      REP(i, w_n){
        cin >> dx;
        x += dx;
        xs.push_back(x);
      }

      int y = 0, dy;
      for(int xx : xs) {
        ps[xx - y]++;
      }
      REP(i, h_n){
        cin >> dy;
        y += dy;
        for(int xx : xs) {
          ps[xx - y]++;
        }
      }
    }

    int sum = 0;
    for(auto t : ps) {
      int n = t.second;
      sum += n * (n - 1) / 2;
    }

    cout << sum << endl;
  }
}

Measured memory_bytes: 29800
#include <iomanip>
#include <iostream>
#include <memory>
#include <vector>
#include <cassert>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main(void) {
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  string S;
  cin >> S;

  int heap_size = 1;
  while (heap_size < 2*N) heap_size *= 2;

  vector<vector<int>> tree(heap_size, vector<int>(32, 0));
  for (int i = 0; i < N; ++i) {
    int pos = i + N;
    int newChar = S[i] - 'a';
    assert(0 <= newChar && newChar <= 26);
    while (pos) {
      tree[pos][newChar]++;
      pos /= 2;
    }
  }

  int Q;
  cin >> Q;
  vector<int> answer;
  rep(j, Q) {
    int t;
    cin >> t;
    if (t == 1) {
      int i;
      char c;
      cin >> i >> c;
      i--;
      if (S[i] == c) continue;

      int pos = i + N;
      assert(pos < 2 * N);
      int oldChar = S[i] - 'a';
        assert(0 <= oldChar && oldChar <= 26);
      int newChar = c - 'a';
      if (newChar < 0 || 26 < newChar) {
        cout << "i=" << i << endl;
        cout << "c=" << c << endl;
        cout << "newChar=" << newChar << endl;
      }
      // assert(0 <= newChar && newChar <= 26);
      S[i] = c;
      while (pos) {
        tree[pos][oldChar]--;
        tree[pos][newChar]++;
        pos /= 2;
      }

    } else {
      int l, r;
      cin >> l >> r;
      l = l - 1 + N;
      r = r - 1 + N;
      vector<int> sum(26, 0);
      while (l <= r) {
        assert(0 <= l && l <= 2 * N);
        assert(0 <= r && r <= 2 * N);
        if (l % 2) {
          rep(k, 26) sum[k] += tree[l][k];
          l++;
        }
        if ((r % 2) == 0) {
          rep(k, 26) sum[k] += tree[r][k];
          r--;
        }
        l /= 2;
        r /= 2;
      }
      int ans = 0;
      rep(k, 26) if (sum[k] != 0) ans++;
      answer.push_back(ans);
    }
  }
  for (auto ans : answer) cout << ans << endl;
  return 0;
}


Measured memory_bytes: 173084
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st;
        PrintWriter pw = new PrintWriter(System.out);

        st = new StringTokenizer(br.readLine());
        int n = Integer.parseInt(st.nextToken());
        int m = Integer.parseInt(st.nextToken());
        if(n==m) for(int i=0 ; i<n ; i++)pw.print(n);
        else if(n < m) for(int i=0 ; i<m ; i++) pw.print(n);
        else for(int i=0 ; i<n ; i++) pw.print(m);


        pw.flush();
        pw.close();
    }
}


Measured memory_bytes: 21204
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define Fast_IO ios::sync_with_stdio(false);
inline int read()
{
	char ch=getchar(); int nega=1; while(!isdigit(ch)) {if(ch=='-') nega=-1; ch=getchar();}
	int ans=0; while(isdigit(ch)) {ans=ans*10+ch-48;ch=getchar();}
	if(nega==-1) return -ans;
	return ans;
}
signed main()
{
#ifdef __LOCAL__
	freopen("in.txt","r",stdin);
#endif
	string s;
	cin>>s;
	int n=s.length();
	s=' '+s;
	int ans=0;
	for(int i=1;i<=n/2;i++)
	{
		if(s[i]!=s[n-i+1]) ans++;
	}
	cout<<ans<<endl;
#ifdef __LOCAL__
	printf("Time Used : %d\n",clock());
#endif
	return 0;
}



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

int a[3];

int main() {
	scanf("%d%d%d", &a[0], &a[1], &a[2]);
	sort(a,a+3);
	printf("%s\n", (a[0]==5&&a[1]==5&&a[2]==7) ? "YES" : "NO");
	
	return 0;
}

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

typedef long long ll;
int main()
{
	ll Q,H,S,D,N;
	cin>>Q>>H>>S>>D>>N;
	N=N*4;
	if(H>2*Q)	H=2*Q;
	if(S>2*H)	S=2*H;
	if(D>2*S)	D=2*S;
	ll sum=0;
	sum+=(N/8)*D;
	N=N%8;
	sum+=(N/4)*S;
	N=N%4;
	sum+=(N/2)*H;
	N=N%2;
	sum+=N*Q;
	cout<<sum<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n,q;
    cin>>n>>q;
    string str;
    cin>>str;
    int a[n]={0};
    a[0]=0;
    for(int i=1;i<n;i++){
       if(str[i] == 'C' && str[i-1] == 'A'){
           a[i]  = a[i-1] + 1;
       }else{
           a[i] = a[i-1];
       }
    }
    for(int i=0;i<q;i++){
        int l,r;
        cin>>l>>r;
        l--;
        r--;
        ///cout<<l<<" "<<r<<"\n";
        if(l == 0){
            cout<<a[r]<<"\n";
        }else{
           // cout<<a[r]<<" "<<a[l-1]<<"\n";
            cout<<a[r] - a[l]<<"\n";
        }
    }
    return 0;
}


Measured memory_bytes: 1408
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
using ll = long long;
using P = pair<ll,ll>;

int main(){
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
ll n,w;
cin >> n >> w;
vector<ll> weight(n);
vector<ll> value(n);
    rep(i,n){
    cin >> value[i] >> weight[i];
}
vector<vector<ll>> dp(110,vector<ll> (10010,0));
for(ll i = 0; i < n; i++){
    for(ll j = 0; j <= w; j++){
        dp[i + 1][j] = dp[i][j];
        if(j - weight[i] >= 0){
            dp[i + 1][j] = max(dp[i][j], dp[i][j - weight[i]] + value[i]);
        }

    }
}
cout << dp[n][w] << endl;
}


Measured memory_bytes: 11596