akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <random>

using namespace std;

const int N = 3002;
const int MOD = 998244353;

typedef long long ll;

int add(int a, int b) {
	if (a + b >= MOD) {
		return a + b - MOD;
	} else {
		return a + b;
	}
}

int mul(int a, int b) {
	return ((ll)a * b) % MOD;
}

int dp[N][N];

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	int n, s;
	cin >> n >> s;
	vector<int> a(n);
	for (auto &t : a) {
		cin >> t;
	}
	int ans = 0;
	dp[0][0] = 1;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j <= s + 1; j++) {
			int nw = min(s + 1, j + a[i]);
			if (j == 0) {
				dp[i + 1][nw] = i + 1;
			} else {
				dp[i + 1][nw] = add(dp[i + 1][nw], dp[i][j]);
			}
			dp[i + 1][j] = add(dp[i + 1][j], dp[i][j]);
		}
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j <= s + 1; j++) {
			if (j + a[i] == s) {
				if (j > 0)
					ans = add(ans, mul(dp[i][j], n - i));
				else 
					ans = add(ans, mul(i + 1, n - i));
			}
		}
	}
	cout << ans << endl;
} 

Measured memory_bytes: 35456
#include <cstdio>
#include <climits>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <string>
#include <cstdio>
#include <climits>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <utility>
#include <queue>
#include <cstring>
#include <set>
#include <map>
#include <complex>

#define rep(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
long long MOD = 1000000007;
long long INF = 1000000000000000; //10^15
typedef long long ll;
typedef unsigned long long ull;


ll powMod(ll x, ll n, ll mod) {
  if (n == 0) return 1;
  ll t = powMod(x, n/2, mod);
  t = t * t % mod;
  if (n & 1) return t * x % mod;
  return t;
}

ll gcd(ll a, ll b) {
  if (a == 0 || b == 0) return a + b;
  if (b > a) return gcd(b, a);
  return gcd(b, a % b);
}

int n, m, q, a[100], b[100],c[100], d[100];
int st[100], ans = 0;


void dfs(int i, int t) {
  if (t == n) {
    int k = 0;
    rep(w, q) {
      if (st[b[w]-1] - st[a[w]-1] == c[w]) k += d[w];
    }
    ans = max(ans, k);
    return;
  }
  for (int j = st[i-1]; j <= m; j++) {
    st[i] = j;
    dfs(i + 1, t + 1);
  }
  return;
}
  


int main(void) {

  cin >> n >> m >> q;
  rep(i, q) cin >> a[i] >> b[i] >> c[i] >> d[i];

  st[0] = 1;

  dfs(1, 1);

  cout << ans << endl;

}
  


Measured memory_bytes: 3636
#include<stdio.h>
#include<string.h>

int main()
{
int num=0,i;
char a[3]={};
  scanf("%s",a);
  for(i=0;i<=3;i++)
  {
   if(a[i]=='1'){num++;} 
  }
  printf("%d\n",num);
  return 0;
}

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

int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
	ll A,B,N;
    cin>>A>>B>>N;
    ll ans;
    if(N>=B){
        ans = (A*(B-1))/B;
    }else{
        ans = (A*N)/B;
    }

    cout<<ans<<"\n";
	
	return 0;
}


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

import sys, re
from collections import deque, defaultdict, Counter
from math import sqrt, hypot, factorial, pi, sin, cos, radians
if sys.version_info.minor >= 5: from math import gcd
else: from fractions import gcd 
from heapq import heappop, heappush, heapify, heappushpop
from bisect import bisect_left, bisect_right
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from functools import reduce, partial
from fractions import Fraction
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def ceil(a, b=1): return int(-(-a // b))
def round(x): return int((x*2+1) // 2)
def fermat(x, y, MOD): return x * pow(y, MOD-2, MOD) % MOD
def lcm(x, y): return (x * y) // gcd(x, y)
def lcm_list(nums): return reduce(lcm, nums, 1)
def gcd_list(nums): return reduce(gcd, nums, nums[0])
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

A, B, C = MAP()

if A % 2 or B % 2 or C % 2:
    print(0)
    exit()
if A == B == C:
    print(-1)
    exit()

cnt = 0
while True:
    if A % 2 or B % 2 or C % 2: 
        break
    A, B, C = B//2+C//2, A//2+C//2, A//2+B//2
    # print(A, B, C)
    cnt += 1
print(cnt)


Measured memory_bytes: 5284
#include <vector>
#include <iostream>
#include <iomanip>
#include <map>
#include <string.h>
#include <cstring>
#include <queue>
#include <limits>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <cmath>
#include <stdio.h>
#include <set>
#include <cstdio>
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
#define pb push_back
#define FOR(i, a) for(int i = 0; i < (a); i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef long double ld;
const int N = 1e5 + 10;
double esp = 1e-10;
int n ,h;
int a[N], b[N];
int main() {
    while (cin >> n >> h) {
        int ma = -1000000005;
        int id = -1;
        for (int i = 0; i < n; i++) {
            cin >> a[i] >> b[i];
            if (a[i] == ma) {
                if (b[i] < b[id]) {
                    id = i;
                }
            } else if (a[i] > ma) {
                id = i;
            }
            ma = max(a[i], ma);
        }
        vector<int> vec;
        for (int i = 0; i < n; i++) {
            if (b[i] >= ma) {
                if (id != i) {
                    vec.push_back(b[i]);
                }
            }
        }
        sort(vec.begin(), vec.end());
        int res = 0;
        int t = b[id];
        int x = a[id];
        for (int i = (int)vec.size() - 1; i >= 0; i--) {
            int v = vec[i];
            if (v >= t) {
                h -= v;
                res++;
                if (h <= 0) break;
            } else {
                if (t >= h) {
                    res++;
                    break;
                } else {
                    h -= v;
                    res++;
                    if (h <= 0) break;
                }
            }
        }
        if (h > 0) {
            res++;
            h -= t;
            if (h > 0) {
                res += (h + x - 1) / x;
            }
        }
        cout << res << endl;
    }
    return 0;
}




Measured memory_bytes: 1660
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
l = Counter(a)
q = int(input())
ans = sum(a)

for _ in range(q):
    b,c = map(int, input().split())
    tmp = l[b]
    l[c] += tmp
    l[b] = 0
    ans += (c-b) * tmp
    print(ans)

Measured memory_bytes: 24128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
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; }

const int MOD = 1000000007;
const int INF = 1e9;

const int mod = 1000000007;
const int inf = 1e9;
#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};

ld dp[310][310][310] = {(ld)0};
int n;

ld rec(int i, int j, int k) {
    if(dp[i][j][k] != (ld)0) return dp[i][j][k];
    if(i == 0 && j == 0 && k == 0) return (ld)0.0;

    ld res = 0;
    if(i > 0)res += i * rec(i-1, j, k);
    if(j > 0)res += j * rec(i+1, j-1, k);
    if(k > 0)res += k * rec(i, j+1, k-1);
    res += n;
    res *= (ld)1.0 / (i + j + k);

    return dp[i][j][k] = res;
}

int main(){
    cin >> n;
    int one = 0, two = 0, three = 0;
    for(int i = 0; i < n; i++) {
        int a;
        cin >> a;
        if(a == 1) one++;
        else if(a == 2) two++;
        else three++;
    }
    ld ans = rec(one, two, three);
    cout << fixed << setprecision(20) << ans << endl;
}

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

vector < pair < int, int > > adj[16];

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

	for ( int i = 0; i < n; i++ ) {
		int m;
		cin >> m;

		for ( int j = 0; j < m; j++ ) {
			int x, y;
			cin >> x >> y;
			x--;
			adj[i].push_back( { x, y } );
		} 
	}
	int ans = 0;

	for ( int i = 0; i < (1 << n); i++ ) {
		vector < int > a(n);
		int ok = 1;

		for ( int j = 0; j < n; j++ ) {
			if ( i & (1 << j) ) {
				a[j] = 1;
			}
		}

		for ( int j = 0; j < n; j++ ) {
			if ( i & (1 << j) ) {
				
				for ( auto p: adj[j] ) {
					if ( a[ p.first ] != p.second ) {
						ok = 0;
						break;
					}
				}
			}
		}
		if ( ok ) {
			ans = max( ans, __builtin_popcount(i) );
		}
	}
	cout << ans;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int ll;

#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;

int main()
{
	int n;
	cin >> n;
	vector<int> a(n);
	for(int i = 0; i < n; i++){
		cin >> a[i];
	}
	int four=0,two=0,odd=0;
	for(int i = 0; i < n; i++){
		if(a[i]%4==0) four++;
		else if(a[i]%2==0) two++;
		else odd++;
	}

	if(two>0){
		if(four>=odd) cout << "Yes" << endl;
		else cout << "No" << endl;
	}else{
		if(four>=odd-1) cout << "Yes" << endl;
		else cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 640
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		
		Map<String, Integer> map = new HashMap<>();
		map.put("AC", 0);
		map.put("WA", 0);
		map.put("TLE", 0);
		map.put("RE", 0);
		
		for (int i = 0; i < n; i++) {
			String key = sc.next();
			map.put(key, map.get(key) + 1);
		}
		
		System.out.println("AC x " + map.get("AC"));
		System.out.println("WA x " + map.get("WA"));
		System.out.println("TLE x " + map.get("TLE"));
		System.out.println("RE x " + map.get("RE"));
		
		sc.close();
	}
	
}



Measured memory_bytes: 49480
/* Great things never come from comfort zones,
"whatever the mind of a man can conceive and believe,it can achieve." */
 
#include <bits/stdc++.h>
#define ll long long
#define scf(n) scanf("%d",&n)
#define lscf(n) scanf("%lld",&n)
#define lpri(n) printf("%lld ",n)
#define pri(n) printf("%d ",(int)n)
#define prin(n) printf("%d\n",(int)n)
#define lprin(n) printf("%lld\n",n)
#define rep(i,ini,n) for(int i=ini;i<(int)n;i++)
#define pb push_back
#define pf push_front
#define mp make_pair
#define F first
#define S second
#define all(x)     x.begin(),x.end()
#define tc   int tt; scf(tt); while(tt--)
#define inf INT_MAX
#define ninf INT_MIN
#define gcd __gcd
#define bitcount(n) __builtin_popcount(n)
typedef double dd;
using namespace std;
const ll mod =10;
const int N = 1e6+7;

void my_dbg() { cout << endl; }
template<typename Arg, typename... Args> void my_dbg(Arg A, Args... B) 
{ cout << ' ' << A; my_dbg(B...); }
#define dbg(...) cout << "(" << #__VA_ARGS__ << "):", my_dbg(__VA_ARGS__)

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

  map<char,int>m;

  rep(i,0,s.size())
  m[s[i]]++;

  bool f=1;
  for(auto it:m)
    if(it.S&1)
      f=0;

    f?printf("Yes\n"):printf("No\n");


  
  
    
} 
  


Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define ll long long
#define R register
using namespace std;
const int N = 2e6+200;
template <class Ruby> inline void read(Ruby &x)
{
	x=0;
	char ch=getchar(), w=0;
	while(!isdigit(ch))w=(ch=='-'), ch=getchar();
	while(isdigit(ch))x=(x<<1)+(x<<3)+(ch^48), ch=getchar();
	x=w?-x:x;
}
int n;
char s[N];
int main()
{
	int ans=0;
	read(n);
	scanf("%s", s+1);
	for(R int i=1; i<=n; i++)
	{
		if(i+2<=n){
			if(s[i]=='A' && s[i+1]=='B' && s[i+2]=='C')ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
// VABC049_C
#include <iostream>
#include <string>
#include <vector>
#include <iterator>  // std::prev(iter, n) n 個分デクリメントしたイテレータ
#include <tuple>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <stack>
#include <queue>
#include <algorithm>
#include <functional>  // std::greater<T>()
#include <utility>  // std::swap()
#include <numeric>  // accumulate(ALL(vec), 0)  0 は初期値
#include <bitset>  // static_cast<std::bitset<8>>
#include <sstream>  // std::stringstream
#include <cmath>
#include <climits>  // INT_MIN
#include <cctype>  // std::isdigit()
#include <iomanip>  // std::setprecision()
using namespace std;
using ll = long long;

#define REP(i, n) for (ll i=0; i < n; i++)  // 0 ~ n-1
#define MIN(vec) min_element(vec.begin(), vec.end())  // イテレータのため、値を取り出すときは * を先頭につける
#define MAX(vec) max_element(vec.begin(), vec.end())
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define SUM(vec) accumulate(vec.begin(), vec.end(), 0LL)  // 0 は初期値
#define pll pair<ll, ll>
#define F first
// #define S second
const ll INF = 1LL<<60;  // 10^18

int main() {
    // input(sunippets: inpv, inpn, inps)
    string S;
    cin >> S;
    
    // calculation
    reverse(S.begin(), S.end());
    ll idx = 0; string sub5, sub6, sub7;
    while (idx != S.length()) {
        sub5 = S.substr(idx, 5);
        sub6 = S.substr(idx, 6);
        sub7 = S.substr(idx, 7);
        if (sub5 == "maerd" || sub5 == "esare") {
            idx += 5;
        } else if (sub6 == "resare") {
            idx += 6;
        } else if (sub7 == "remaerd") {
            idx += 7;
        } else {
            cout << "NO" << "\n";
            return 0;
        }
    }
    
    if (idx == (ll)S.length()) {
        cout << "YES" << "\n";
    } else {
        cout << "NO" << "\n";
    }

    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define M_PI       3.14159265358979323846
#define Speed_UP  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define 	pb	push_back 
#define 	ff	first 
#define 	ss	second 
#define sz(x) (int)x.size()
#warning Remeber to change t
using namespace std;
typedef long long ll;
inline void setIO(string name="") {
	#ifndef ONLINE_JUDGE 
	freopen((name+".in").c_str(), "r", stdin); 
	freopen((name+".out").c_str(), "w", stdout);
	#endif
	}

int main(){
	Speed_UP
	ll t;
	t=1;
	while(t--){
		ll n;
		cin>>n;
		ll ans=1000-n;
		while(ans<0)
			ans+=1000;
		cout<<ans;
		
		
		
	}





}


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

int a,b;
int main(){
  cin >> a >> b;
  if (a==b){
    cout << 2*a;
  }
  else if(a>b){
    cout << 2*a-1;
  }
  else{
    cout << b*2-1;
  }
  return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
A = [0] * n
B = [0] * m
for i in range(n):
    A[i] = list(input())
for i in range(m):
    B[i] = list(input())

check = 0


for k in range(n-m+1):
    if check == m:
        break
    C = A[k:k+m]
    for i in range(n-m+1):
        if check == m:
            break
        check = 0
        for j in range(m): 
            if C[j][i:i+m] == B[j]:
                check += 1   
            if check == m:
                print('Yes')  
         


if check != m:
    print('No')


#%%

#%%


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define PI acos(-1)
typedef  long long ll;
ll gcd(ll x,ll y){
   if(y==0) return x;
   else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
   return x/gcd(x,y)*y;
}



int main(){
   
   int n;
   cin>>n;
   vector<int> a(n,0);
   rep(i,n){
      cin>>a[i];
   }
   int ans=0;
   rep(i,n){
      if(i%2==0){
         if(a[i]%2!=0){
            ans++;
         }
      }
   }
   cout<<ans;
   





return 0;
}


Measured memory_bytes: 3620
using System;
using System.Collections.Generic;

using System;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args)
    {
        string s = Console.ReadLine();
        string t = Console.ReadLine();

        char[] ss = s.ToCharArray();
        char[] tt = t.ToCharArray();

        int r = int.MaxValue;

        for (int i = 0; i < ss.Length; i++)
        {
            int rr = tt.Length;
            for (int j = 0; j < tt.Length; j++)
            {
                if (i + j < ss.Length)
                {
                    if (ss[i + j] == tt[j])
                    {
                        rr--;
                    }
                }
                else
                {
                    rr = int.MaxValue;
                }
            }

            if (rr < r) 
            {
                r = rr;
            }
        }

        Console.WriteLine(r);
    }
}

Measured memory_bytes: 17580
#include<stdio.h>
#include<string.h>

int n,a[110][110],vis[110],d[110],f[110],tag=0;
void dfs(int x){
    int u,v,stack[110],top=0;
    top++;
    stack[top]=x;
    vis[x]=1;
    tag++;
    d[x]=tag;
    while(top){
        u=stack[top];
        for(v=1;v<=n;v++)
            if(vis[v]==0){
                if(a[u][v]){
                    top++;
                    stack[top]=v;
                    vis[v]=1;
                    tag++;
                    d[v]=tag;
                    break;
                }
            }
        if(v==n+1){
            tag++;
            f[u]=tag;
            top--;
        }
    }
}
int main(){
    int u,k,v,i,j;
    memset(a,0,sizeof(a));
    memset(vis,0,sizeof(vis));
    scanf("%d", &n);
    for(i=1; i<=n; i++){
        scanf("%d%d",&u,&k);
        for(j=1; j<=k;j++){
            scanf("%d",&v);
            a[u][v]=1;
        }
    }
    for(i=1; i<=n; i++)
        if(vis[i]==0)
            dfs(i);
    for(i=1; i<=n; i++)
        printf("%d %d %d\n",i,d[i],f[i]);
    return 0;
}


Measured memory_bytes: 2044
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1<<32


def solve(S: str):
    print(''.join(['x']*len(S)))
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <cassert>
#include <random>
using namespace std;
using ll = long long;


int main() {
	int n; cin >> n;
	for (int i = 1; i <= 9; i++) {
		for (int j = 1; j <= 9; j++) {
			if (n == i*j) {
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
struct Dice{
  int s[6];
  void roll(char c){
    int b;
    if(c=='E'){
      b=s[0];
      s[0]=s[3];
      s[3]=s[5];
      s[5]=s[2];
      s[2]=b;
    }
    if(c=='W'){
      b=s[0];
      s[0]=s[2];
      s[2]=s[5];
      s[5]=s[3];
      s[3]=b;
    }
    if(c=='N'){
      b=s[0];
      s[0]=s[1];
      s[1]=s[5];
      s[5]=s[4];
      s[4]=b;
    }
    if(c=='S'){
      b=s[0];
      s[0]=s[4];
      s[4]=s[5];
      s[5]=s[1];
      s[1]=b;
    }
  }
  int top() {
    return s[0];
  }
};
int main(){
  Dice d;
  for(int i=0;i<6;i++) cin >> d.s[i];
  string s;cin >> s;
  for(int i=0;i<s.size();i++) d.roll(s[i]);
  cout << d.top() << endl;
  return 0;
}


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

using namespace std;

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

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

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

ll R[200005];


struct TestCase {
    TestCase() {
        std::random_device rnd;
        mMt = std::mt19937(rnd());
    }

    int get(int low, int height) {
        if (low > height)
            swap(low, height);
        int d = height - low;
        if (d == 0)
            return low;
        std::uniform_int_distribution<> rand(0, d);
        return low + rand(mMt);
    }

    std::mt19937 mMt;
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, P;
    cin >> N >> P;
    //    while (true) {
#if false
    TestCase test;
    string S = "";
    REP(i, N) {
        S.push_back('0' + (test.get(0, 9)));
    }
#else
    string S;
    cin >> S;
#endif
    ll p = 1;
    REP(i, P - 2) {
        p = (p * 10LL) % P;
    }
    map<ll, ll> M;
    M[0]++;
    ll n = 0;
    ll pp = 1;
    ll ans = 0;
    if (P == 2) {
        REP(i, N) {
            if ((S[i] - '0') % 2 == 0) {
                ans += i + 1;
            }
        }
    }
    else if (P == 5) {
        REP(i, N) {
            if ((S[i] - '0') % 5 == 0) {
                ans += i + 1;
            }
        }
    }
    else {
        REP(i, N) {
            n = (S[i] - '0') + n * 10;
            n %= P;
            ll m = n * pp % P;
            ans += M[m];
            M[m]++;
            pp = (pp * p) % P;
        }
    }
    cout << ans << endl;

#if false
    ll ans1 = 0;
    REP(i, N) {
        ll s = 0;
        FOR(j, N, i) {
            s = (s * 10) + S[j] - '0';
            if (s % P == 0)
                ans1++;
        }
    }

    if (ans != ans1) {
        cout << S << endl;
        cout << ans << " " << ans1 << endl;
        break;
    }
}

#endif
    return 0;
}

Measured memory_bytes: 1044
#include <iostream>
#include <cstring>

using namespace std;

typedef long long int ll;

const int N = 4 * 1e3;
ll numbers[N], dp[N][N][2];

ll result(ll currScore, int i, int j, int turn) {
  if (i == j)
    return currScore + turn * numbers[i];

  int dpTurn = (turn < 0 ? 0 : 1);

  if (dp[i][j][dpTurn] != 0)
    return currScore + dp[i][j][dpTurn];

  ll res = (ll)turn * max((ll)turn * result(currScore + turn * numbers[i], i+1, j, -turn), (ll)turn * result(currScore + turn * numbers[j], i, j-1, -turn));
  dp[i][j][dpTurn] = res - currScore;
  return res;
}

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> numbers[i];

  memset(dp, 0, sizeof(dp));

  cout << result(0, 0, n-1, 1) << endl;
}


Measured memory_bytes: 253380
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    a,b=STRM()
    c=a+b
    c=int(c)
    c_root=int(c**0.5)
    if int(c_root**2.0-c)==0:
        print('Yes')
    else:
        print('No')
if __name__ == '__main__':
    do()

Measured memory_bytes: 3064
# include <bits/stdc++.h>
using namespace std;
long long n,m,f[200005],ww,a,b;
int main()
{
	cin>>n>>m;
	
	
	for (int i=1; i<=1000; i++)
	{
		f[i]=-1;
	}
	for (int i=1; i<=m; i++)
	{
		cin>>a>>b;
		//cout<<f[a]<<" "<<b<<endl;
		if (f[a]==-1)
		f[a]=b;
		else
		{
			if (f[a]!=b)
			{
				ww=1;
			}
		}
	}
	
	if (ww==1)
	{
		cout<<"-1"<<endl;
		return 0;
	}
	if (n==1 && (f[1]==0 || f[1]==-1))
	{
		cout<<0<<endl;
		return 0;
	}
	if (f[1]==0)
	{
		cout<<"-1"<<endl;
		return 0;
	}
	for (int i=1; i<=n; i++)
	{
		if (f[i]==-1 && i!=1) cout<<0;
		else
		if (f[i]==-1 && i==1) cout<<1;
		else cout<<f[i];
	}
}

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

#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(a) (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define RSORT(a) sort((a).rbegin(),(a).rend())
#define ll long long
#define pb(a) push_back(a)

#define PRINTV(v) {for(ll deB=0; deB<(v).size(); deB++){cout << (v)[deB] << " ";}cout << endl;}

int main(){
	
	
	ll N, M;
	cin >> N >> M;
	vector<ll> X(M);
	REP(i,M) cin >> X[i];

	SORT(X);

	vector<ll> D(M-1);
	REP(i, X.size()-1){
		D[i] = X[i+1] - X[i];
	}

	sort(D.begin(), D.end(), std::greater<int>() );

	N--;
	ll ans = 0;
	REP(i, D.size()){
		if(N > 0){
			N--;
		}else{
			ans += D[i];
		}
	}
	
	cout << ans << endl;
	return 0;

abnormal:
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 4652
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan0
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/














int N, L[101];
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N;
	rep(i, 0, N) cin >> L[i];
	sort(L, L + N);

	int ans = 0;
	rep(i, 0, N) rep(j, i + 1, N) rep(k, j + 1, N) {
		bool distinct = L[i] < L[j] && L[j] < L[k];
		bool triangle = L[k] < L[i] + L[j];
		if (distinct && triangle) ans++;
	}
	cout << ans << endl;
}







Measured memory_bytes: 3628
package main

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

func main() {
	N := readint()
	K := readint()
	P := make([]int, N)
	maxksum := 0
	preksum := 0
	maxleft := 0
	for i := 0; i < N; i++ {
		P[i] = readint()
		if i < K {
			maxksum += P[i]
			preksum = maxksum
		}
		if K <= i {
			left := i + 1 - K
			ksum := preksum + P[i] - P[left-1]
			if maxksum < ksum {
				maxksum = ksum
				maxleft = left
			}
			preksum = ksum
		}
	}

	// 範囲内の期待値の最大値を求める
	var ans float64 = 0.0
	for i := 0; i < K; i++ {
		ans += (float64(P[i+maxleft]) + 1.0) / 2.0
	}
	fmt.Println(ans)
}

const (
	iobufsize = 1 * 1024 * 1024 // 1 MB
)

var stdinsc = func() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Buffer(make([]byte, iobufsize), iobufsize)
	sc.Split(bufio.ScanWords)
	return sc
}()

func readint() int {
	stdinsc.Scan()
	v, err := strconv.Atoi(stdinsc.Text())
	if err != nil {
		panic(err)
	}
	return v
}

func readstr() string {
	stdinsc.Scan()
	return stdinsc.Text()
}

func pow(x, y int) int {
	if y < 1 {
		return 1
	}
	return x * pow(x, y-1)
}

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}


Measured memory_bytes: 4096
N, Y = gets.chomp.split(' ').map(&:to_i)
result = []
2001.times do |x|
  2001.times do |y|
    if 9000 * x + 4000 * y == Y - 1000 * N && x + y <= N
      result = [x, y]
    end
  end
end

if result.empty?
  puts '-1 -1 -1'
else
  puts "#{result[0]} #{result[1]} #{N - result[1] - result[0]}"
end

Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using vpii = vector<pair<int, int>>;
using vpll = vector<pair<ll, ll>>;
// ceil() 切り上げ, floor() 切り捨て
// next_permutation(all(x))

int		main(void)
{
	string J;
	cin >> J;
	bool N, W, S, E;
	N = W = S = E = false;
	for (int i = 0; J[i]; i++)
	{
		if (J[i] == 'N')
			N = true;
		if (J[i] == 'W')
			W = true;
		if (J[i] == 'S')
			S = true;
		if (J[i] == 'E')
			E = true;
	}
	if (N == S && W == E)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    int A,B; cin>>A>>B;
    string S; cin>>S;
    bool can=true;
    if(S[A]!='-'){
        can=false;
    }
    for(int i=0;i<A;i++){
        if(S[i]<=47||S[i]>=58){
            can=false;
        }
    }
    for(int i=A+1;i<A+B+1;i++){
        if(S[i]<=47||S[i]>=58){
            can=false;
        }
    }
    if(can){
        cout<<"Yes";
    }
    else{
        cout<<"No";
    }
    return 0;
}

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

int cal_digit(ll X){
  int count = 0;
  while(X){
    X/= 26;
    count++;
  }
  return count;
}

int main(){
  ll N;
  cin >> N;
  int x = cal_digit(N);
  
  vector<ll>A(x); //26進数の桁数ぶんの配列
  
  for(int i = 0; i<x; i++){

    A[i] = N % 26;
    N /= 26;
  }
  
  for(int i = 0; i< x; i++){
    if(A[i] <= 0){
      
      if(i == x-1){
        A[i] = 26;
        A.pop_back();
        x--;
        break;
      }
      A[i] += 26;
      A[i+1]--;
    }

    
  }

  reverse(A.begin(), A.end());
  
  for(int i = 0; i < x; i++){
    char x;
    x = A[i] + 96;
    cout << x;
  }
  
  cout << endl;
  
}

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

int main()
{
   //B
    int n,sum=0;
    cin>>n;
    int a[n],b[n],c[n-1];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    for(int i=0;i<n;i++)
    {
        cin>>b[i];
    }
        for(int i=0;i<n-1;i++)
    {
        cin>>c[i];
    }
    
    for(int i=0;i<n;i++)
    {
        if(i==0)
        {
            sum+=b[a[i]-1];
        }
        else if(a[i]-1==a[i-1])
        {
            sum=sum+b[a[i]-1]+c[a[i]-2];
        } 
        else
        {
            sum+=b[a[i]-1];
        }
    }

    cout<<sum<<endl;
    
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
const ll INF = 0x3f3f3f3f;
const ll LINF = 1ll << 55;
const ll MOD = 1e9 + 7;
const ll MAXN = 400 + 5;
const ll MAXK = 1e5 + 10;

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

int main() {
    ll N, M;
    cin >> N;
    string s, t;
    unordered_map<string, ll> hashMap;
    for (int i = 0; i < N; ++i) {
        cin >> s;
        hashMap[s]++;
    }
    cin >> M;
    for (int j = 0; j < M; ++j) {
        cin >> t;
        hashMap[t]--;
    }
    ll ans = 0;
    for (auto& p : hashMap) {
        ans = max(ans, p.second);
    }
    cout << ans << endl;
    return 0;
}

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))

using namespace std;

using i32 = int;
using i64 = long long;
using u64 = unsigned long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vu64 = vector<u64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); return a / gcd(a, b) * b; }
inline u64 xorshift() { static u64 x = 88172645463325252ull; x = x ^ (x << 7); return x = x ^ (x >> 9); }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> inline T bis(T ok, T ng, function<bool(T)> f, T eps = 1) { while (abs(ok - ng) > eps) { T mi = (ok + ng) / 2; (f(mi) ? ok : ng) = mi; } return ok; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

void solve() {
  string s;
  cin >> s;
  int n = s.size();
  bool f = true;
  rep(i, n) {
    if (i % 2 == 0) {
      if (s[i] == 'L') f = false;
    } else {
      if (s[i] == 'R') f = false;
    }
  }
  if (f) yes(); no();
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
#define fix10 cout << fixed << setprecision(10);
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define MOD 1000000007

int main(){
  int n,k;
  cin >> n >> k;
  long ans = 0;
  for(int b=k+1;b<=n;b++){
    long tmp = (n+1)/b;
    ans += (b-k)*tmp;
    int tmp1 = n - (tmp)*b - k + 1;
    ans += max(tmp1,0);
    if(k == 0) ans--;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <int,int> pi;
char a[105][105];
int n,m,c[105][105];

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> n >> m;
	for(int i = 1;i <= n;i++) for(int j = 1;j <= m;j++) cin >> a[i][j];
	priority_queue <pair<pair<int,char>,pair<int,int>>> q;
	q.push({{0,a[1][1]},{1,1}});
	while(!q.empty()) {
		auto p = q.top();
		q.pop();
		int x = p.second.first;
		int y = p.second.second;
		int co = -p.first.first;
		char ch = p.first.second;
		//cout << x << ' ' << y << '\n';
		if(c[x][y]) continue;
		c[x][y] = 1;
		if(x == n&&y == m) {
			if(ch == '#') co++;
			cout << co;
			return 0;
		}

		if(x+1 <= n) q.push({{-co-(a[x+1][y] != ch&&ch == '#'),a[x+1][y]},{x+1,y}});
		if(y+1 <= m) q.push({{-co-(a[x][y+1] != ch&&ch == '#'),a[x][y+1]},{x,y+1}});

	}
}


Measured memory_bytes: 384
#pragma warning(disable:4996)
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("Ofast")

#include<bits/stdc++.h>

#define pb push_back
#define X first
#define Y second
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define f(i, a ,b) for(int i = (int)a; i <=(int)(b);i++)
#define endl "\n"
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;

using namespace std;

const int N = 1e5+5,MOD = 1000000007;
const long long int INF = 0xFFFFFFFFFFFFFFFL;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int a[N][3], dp[N][3];
int n;
void IOS()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
   	cout.precision(10);
   	cout << fixed;
}

int rec(int i, int j)
{
	if(i == n)return 0;
	if(dp[i][j] != -1)return dp[i][j];
	if(j == 0)return dp[i][j] = a[i][0] + max(rec(i+1,1),rec(i+1,2));
	if(j == 1)return dp[i][j] = a[i][1] + max(rec(i+1,0),rec(i+1,2));
	else return dp[i][j] = a[i][2] + max(rec(i+1,0),rec(i+1,1)); 	
}	

int32_t main()
{
	IOS();
	memset(dp,-1,sizeof(dp));
	cin >> n;
	for(int i = 0; i < n; i++)
	 	for(int j = 0; j < 3;j++)
	 		cin >> a[i][j];
	int ans = max({rec(0,0),rec(0,1),rec(0,2)});
	cout << ans;
	return 0;
}

Measured memory_bytes: 7296
#include<stdio.h>


int main(void){
  int n;
  int i;

  scanf("%d",&n);

  int a[n];

  for(i=0;i<n;i++){
    scanf("%d", &a[i]);
  }

  for(i=i-1;i>0;i--){
        printf("%d ", a[i]);
    }
    printf("%d\n", a[0]);
  return 0;
}

Measured memory_bytes: 1836
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <functional>
#include <iomanip>
#include <bitset>
#include <numeric>
#include <queue>
#include <map>
#include <cstdint>
#include <set>
using namespace std;
#define rep(i, n) for (ll i = 0; i < n; i++)
const long long mod = 1000000007;
typedef long long int ll;
typedef pair<ll, ll> P;
const vector<int> di = { -1, 0, 1, 0 };
const vector<int> dj = { 0, 1, 0, -1 };
const double PI = 3.14159265358979323846;


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

	ll ans = 0;

	if (n < b) {
		ans = (a * n) / b - a * (n / b);
		cout << ans << endl;
	}
	else {
		ll cnt = n / b;
		ll num = 0;
		for (ll i = (cnt - 1); i < cnt; i++) {
			num = b * (i + 1) - 1;
			ans = max(ans, (a * num) / b - a * (num / b));
		}
		cout << ans << endl;
	}
	
	return 0;
	
}



Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>

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

using namespace std;
typedef long long ll;

struct Team {
    int id,time,score;
    int p[100];

    void addscore() {
        score++;
    }

    bool operator<(const Team &t) const {
        if(score == t.score) {
            if(time == t.time)  {
                return id > t.id;
            }
            return time > t.time;
        }
        return score < t.score;
    }
};

int main() {
    int t,p,r;
    while(cin >> t >> p >> r) {
        if(t == 0 && p == 0 && r == 0) break;
        vector<Team> v;
        rep(i,t) {
            Team team;
            team.id = i;
            team.time = 0;
            team.score = 0;
            memset(team.p,0,sizeof(team.p));
            v.push_back(team);
        }

        rep(i,r) {
            int tid,pid,time;
            string mes;

            cin >> tid >> pid >> time >> mes;
            tid--;
            pid--;

            if(mes == "CORRECT") {
                v[tid].addscore();
                v[tid].time += 1200 * v[tid].p[pid] + time;
            }
            else {
                v[tid].p[pid]++;
            }
        }

        sort(v.begin(),v.end());
        rep(i,t) {
            cout << v[t-1-i].id+1 << " " << v[t-1-i].score << " " << v[t-1-i].time << endl;
        }

    }
    return 0;
}

Measured memory_bytes: 1292
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<string>
#include<utility>
#include<numeric>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;

using ll = long long;

class Stream{
public:
    Stream(){

    }
    //配列以外の入力を受け取る
    void read(){

    }
    template<typename First, typename... Rest>
    void read(First& first, Rest&... rest){
        cin >> first;
        read(rest...);
    }
    //配列を区切って出力する
    template<typename T>
    void write_vec(vector<T>& v, char divider){
        for(size_t i = 0; i < v.size(); i++){
            cout << v[i] << divider;
        }
    }
}; 

int main(){
    Stream io;
    
    int A, B, C, X;
    io.read(A, B, C, X);
    int ans = 0;
    for(int a = 0; a <= A; a++){
        for(int b = 0; b <= B; b++){
            for(int c = 0; c <= C; c++){
                if(X == 500 * a + 100 * b + 50 * c) ans++;
            }
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	char str[1000];
	int i;
	
	fgets(str, 1000, stdin);	

	i = 0;
	while(str[i] != '\0'){
		if ('a' <= str[i] && str[i] <= 'z'){
			str[i] -= 0x20;
		}
		i++;
	}
	
	printf("%s", str);
	
	return (0);
}

Measured memory_bytes: 524
#include <bits/stdc++.h>
#define eb emplace_back
#define all(v) (v).begin(), (v).end()
#define fi first
#define se second

using namespace std;
typedef pair <int, int> pii;

int arr[301010], brr[301010];
vector <int> ta, tb;

map <int, vector <int> > g;

set <int> chk;
int dfs(int k) {
	if(chk.find(k) != chk.end()) return 0;
	chk.insert(k);
	int ret = 0;
	for(auto i : g[k]) {
		if(i == k) continue;
		ret++;
		ret += dfs(i);
	}
	return ret;
}

int main() {
	ios::sync_with_stdio(false); cin.tie(0);
	int n;
	cin >> n;
	for(int i = 1; i <= n; i++) {
		cin >> arr[i];
		arr[0] ^= arr[i];
		ta.eb(arr[i]);
	}
	ta.eb(arr[0]);
	for(int i = 1; i <= n; i++) {
		cin >> brr[i];
		brr[0] ^= brr[i];
		tb.eb(brr[i]);
	}
	tb.eb(brr[0]);
	sort(all(ta));
	sort(all(tb));

	for(int i = 0; i <= n; i++) {
		if(ta[i] != tb[i]) {
			cout << -1;
			return 0;
		}
	}
	for(int i = 0; i <= n; i++) {
		g[arr[i]].eb(brr[i]);
	}
	int ans = max(1, dfs(arr[0])) - 1;
	if(arr[0] == brr[0] && ans != 0) ans++;
	for(int i = 1; i <= n; i++) {
		if(arr[i] != brr[i] && chk.find(arr[i]) == chk.end()) ans += dfs(arr[i]) + 1;
	}
	cout << ans;
}

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

using namespace std;

const int maxn = 112345;



int main()
{

    int n;
    scanf("%d",&n);
    int ai=0,bi=0;
    for(int i=0;i<n;i++)
    {
        int a,b;
        scanf("%d%d",&a,&b);
        if(a>ai)
        {
            ai=a;
            bi=b;
        }
    }
    cout<<ai+bi<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<cctype>

using namespace std;

string max(string a, string b){
    if(a.size()>b.size()) return a;
    if(a.size()<b.size()) return b;
    for(int i=0;i<a.size();i++){
        if(a[i] > b[i]) return a;
        if(a[i] < b[i]) return b;
    }
    return a;
}

int main(void){
  int w,h;
  string grid[71],dp[71][71];

  while(cin >> w >> h,w|h){
    for(int i=0;i<71;i++)
      for(int j=0;j<71;j++)dp[i][j].clear();

    for(int i=0;i<h;i++)cin >> grid[i];

    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	if(!isupper(grid[i][j])){
	  dp[i][j]=grid[i][j];
	  string a="",b="";
	  if(i>0)a=dp[i-1][j]+grid[i][j];
	  if(j>0)b=dp[i][j-1]+grid[i][j];
	  
	  while(a[0]=='0')a.erase(a.begin());
	  while(b[0]=='0')b.erase(b.begin());

	  dp[i][j]=max(dp[i][j],max(a,b));
	}
      }
    }

    string s="";
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	s=max(s,dp[i][j]);
      }
    }
    cout << s << endl;
  }
  return 0;
}

Measured memory_bytes: 1380
n, x, y = map(int, input().split())

x -= 1
y -= 1
ans = [0] * n

for i in range(n):
    for j in range(i+1, n):
        if i <= x and y <= j:
            dist = j - i - (y - x) + 1
        else:
            dist = min(j - i, abs(i-x) + abs(j-y) + 1)
        ans[dist] += 1

for i in range(1,n):
    print(ans[i])


Measured memory_bytes: 3444
//============================================================================
// Name        : svdzva.cpp
// Author      : 
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
using namespace std;

int main() {
	int poi[5],sum=0,bre;
	for(int i = 0;i<5;i++){
		cin >> poi[i];
		if(poi[i] < 40){
			poi[i] = 40;
		}
		sum = sum + poi[i];
	}
	bre = sum / 5;
	cout << bre << endl;
	return 0;
}

Measured memory_bytes: 1160
#include <cstdio>
using namespace std;
int main ()
{
	int n,l,r,Ans=0; scanf ("%d",&n);
	for (int i=1;i<=n;++i) scanf ("%d%d",&l,&r),Ans+=r-l+1;
	return !printf ("%d\n",Ans);
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <list>
#include <set>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>

using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
using pii=pair<int,int>;
using vs=vector<string>;
using vvi=vector<vi>;
using vpii=vector<pii>;
using si=set<int>;

#define REP(i,a) for(int i=0;i<a;i++)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rREP(i,a) for(int i=(a)-1;i>=0;i--)
#define rFOR(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define out(S) cout<<(S)<<endl;
#define beginend(v) (v).begin(),(v).end()
#define IfOut(condition,text) if(condition){out(text);return 0;}
#define IfOutElse(condition,if_text,else_text) if(condition){out(if_text);return 0;}else{out(else_text);return 0;}
#define mod(s) ((s)%(ll)(1e9+7))
ll modpow(ll i, ll j) { ll tmp = 1; while (j) { if (j % 2)tmp = mod(tmp*i); i = mod(i*i); j /= 2; }return tmp; }
#define divmod(a,b) (mod(a*modpow((ll)b,(ll)(1e9+5))))
#define pb(i) push_back(i)
#define fst first
#define snd second
#define Foreach(item,collection) for(auto item:collection)
#define INF (int)1e10
#define removeAll(vec,deleg) auto itr=remove_if(beginend(vec),deleg);vec.erase(itr,vec.end());
void removeAt(string& s, int index) { s.erase(index, 1); }
template<typename T> void removeAt(vector<T>& v, int index) { v.erase(v.begin() + index); }
ll manhattanDistance(ll x1, ll y1, ll x2, ll y2) { return (abs(x2 - x1) + abs(y2 - y1)); }
vector<ll> sieveOfEratosthenes(int max) {ll prime;double sqrtmax = sqrt(max);vector<ll> primeVec, searchVec;FOR(i, 2, max + 1) searchVec.push_back(i);do{prime = searchVec[0];primeVec.push_back(prime);auto itr = remove_if(beginend(searchVec), [=](ll x)->bool {return x%prime == 0; });searchVec.erase(itr, searchVec.end());} while (prime < sqrtmax);primeVec.reserve(primeVec.size() + searchVec.size());primeVec.insert(primeVec.end(), beginend(searchVec));return primeVec;}
ll sum(vi v) {ll sum=0;Foreach(i,v){sum+=i;}return sum;}
#define ShowAll(v) Foreach(i,v) out(i);
bool isInnerIndex(int kx,int ky,int mx,int my){ return (kx>=0&&kx<mx&&ky>=0&&ky<my); }


int main(){
    int dx[]{-1,0,1,0},dy[]{0,-1,0,1};

    int n;
    while (cin>>n,n)
    {
        int xmax=0,xmin=0,ymax=0,ymin=0;
        vpii box;
        box.pb(pii(0,0));
        REP(i,n-1){
            int ni,di;
            cin>>ni>>di;
            int nx=box[ni].fst+dx[di],ny=box[ni].snd+dy[di];
            box.pb(pii(nx,ny));
            xmax=max(nx,xmax);xmin=min(nx,xmin);
            ymax=max(ny,ymax);ymin=min(ny,ymin);
        }
        cout<<xmax-xmin+1<<" "<<ymax-ymin+1<<endl;
    }
    
    return 0;
}

Measured memory_bytes: 3012
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define pb push_back
const int maxn = 10000;
const int INF32 = 1'050'000'000;
const long long INF64 = 4'000'000'000'000'000'000;
const int MOD7 = 1'000'000'007;
const int MOD9 = 1'000'000'009;
const int mod = MOD7;

void ERROR(int num) { printf("ERROR%d!\n",num); }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
int dx[8]={-1,0,1,0,1,1,-1,-1};
int dy[8]={0,-1,0,1,1,-1,1,-1};


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

    ll A, B, C, K;
    cin >>  A >> B >> C >> K;

    ll total = 0;
    if(K>=A){
        total += A;
        K-=A;
    }else{
        total += K;
        K=0;
    }

    if(K>0){
        if(K>=B){
            K-=B;
        }else{
            K=0;
        }
    }

    if(K>0){
        if(K>=C){
            total -= C;
            K-=C;
        }else{
            total -= K;
            K = 0;
        }
    }

    cout << total << endl;
    

}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define mp          make_pair
#define pii         pair<int,int>
#define vi          vector<int>
#define all(a)      (a).begin(),(a).end()
#define sz(x)       (int)x.size()
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define ios         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
ll dp[100005];
ll h[100005];
int n,k;
ll func(int i){
    if(i>=n-1){
        return 0;
    }

    if(dp[i]!=-1)
        return dp[i];

    ll ans=1e9;

    for(int j=1;j+i<n and j<=k;j++){
        ans=min(ans,func(i+j)+abs(h[i+j]-h[i]));
    }
    return dp[i]=ans;
}
int main(){
    cin>>n>>k;

    memset(dp,-1,sizeof dp);
    for(int i=0;i<n;i++)
        cin>>h[i];

    cout<<func(0);
}

Measured memory_bytes: 6528