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

const int maxn = 100005;
char a[maxn],b[maxn];
int s1[maxn],s2[maxn];
int q;

int main ()
{
    //freopen("main.inp","r",stdin);
    //freopen("main.out","w",stdout);

    scanf("%s ",a+1);
    scanf("%s ",b+1);

    int na=strlen(a+1);

    for(int i=1; i<=na; ++i)
        if(a[i]=='A')
            s1[i]=s1[i-1]+1;
        else
            s1[i]=s1[i-1]-1;

    int nb=strlen(b+1);

    for(int i=1; i<=nb; ++i)
        if(b[i]=='A')
            s2[i]=s2[i-1]+1;
        else
            s2[i]=s2[i-1]-1;

    scanf("%d ",&q);

    for(int i=1; i<=q; ++i)
    {
        int x,y,z,t;

        scanf("%d %d %d %d ",&x,&y,&z,&t);

        if((s1[y]-s1[x-1]+3*maxn)%3==(s2[t]-s2[z-1]+3*maxn)%3)
            printf("YES\n");
        else
            printf("NO\n");
    }
}


Measured memory_bytes: 1536
#include<bits/stdc++.h>
#define LL long long
#define rep(i,n) for(int i=0;i<n;++i)
#define per(i,n) for(int i=n;i>0;i--)
#define FOR(i,a,b) for(int i=a;i<=b;++i)
#define ROF(i,a,b) for(int i=a;i>=b;i--);
#define push_back PB;
#define pop_back PPB;
using namespace std;
static const LL INF = 1LL<<61LL;
static const double EPS = 1e-8;
static const int mod = 100000;
typedef pair<int,int> PII;

LL dp[51][3001];

int main(){
    while(1){
        LL N,M,S;
        cin>>N>>M>>S;
        if(N==0&&M==0&&S==0)break;
        N*=N;
        memset(dp,0,sizeof(dp));
        dp[0][0]=1;
        FOR(i,1,M){
            per(j,N){
                FOR(k,i,S){
                    dp[j][k]+=(mod+dp[j-1][k-i])%mod;
                }
            }
        }
        cout<<dp[N][S]%mod<<endl;
    }
    return 0;
}

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

using namespace std;

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

    string s,s1="";
    cin>>s;

    for(int i=0;i<s.length();i++){
        switch(s[i]){

        case '0':
            s1+='0';
            break;
        case '1':
            s1+='1';
            break;
        case 'B':
            if(s1!=""){
                s1.erase(s1.length()-1,1);
            }

            break;
        }
    }

    cout<<s1<<"\n";

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<bits/stdc++.h>
using namespace std;
/*---------------------DEBUGGING------------------------------------*/
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
/*-------------------------------------------------------------------------------------*/
#define mp make_pair
#define pb push_back
#define ll long long
#define pii pair<int,int>
#define pcc pair<char,char>
#define F first
#define S second
#define int long long
#define pi 3.141592653589793238462643383279502
#define M  1000000009
#define rep(i,n) for(int i=0;i<n;i++)
#define N 2010000
#define vi vector<int>
bool vis[105][105]={false};

signed main()
{
   ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
   int n,d;
   cin>>n>>d;
   d=2*d+1;
   if(n%d==0)
    cout<<n/d;
   else
    cout<<n/d +1<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vll = vector<ll>;
using vpii = vector<pii>;
using vpll = vector<pll>;
using vs = vector<string>;
template <typename T>
using ost = tree<T, null_type, less<T>, rb_tree_tag,
    tree_order_statistics_node_update>;
#define forn(i,n) for(int i=0; i<int(n); ++i)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define ff first
#define ss second

int gcd(int a, int b) {
    return b==0? a:gcd(b, a%b);
}

int main() {
    ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    vi xs(n);
    for (int& x:xs) cin >> x;
    int d=0;
    for (int x:xs) d=gcd(d, x);
    if (k%d || k>*max_element(all(xs))) return cout << "IMPOSSIBLE\n", 0;
    cout << "POSSIBLE\n";
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>

using namespace std;

#define PB push_back
#define ALL(v) (v).begin(), (v).end()
#define SZ size()
#define FOR(i, a, b) for(int (i) = (a); (i) < (b); (i)++)
#define REP(i, n) FOR((i), 0, (n))
#define GET(a) cin >> (a)
#define GET2(a, b) cin >> (a) >> (b)
#define GET3(a, b, c) cin >> (a) >> (b) >> (c)
#define SHOW(v) cout << (v) << endl
#define SHOW2(a, b) cout << (a) << " " << (b) << endl
#define SHOW3(a, b, c) cout << (a) << " " << (b) << " " << (c) << endl
#define MOD 1000000007
template<class T> void GETV(T &v) { REP(i, v.size()) { GET(v[i]); } }
template<class T> void SHOWV(T &v) { REP(i, v.size()) { SHOW(v[i]); } }

typedef long long ll;

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

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int a, b, c, d, e;
	scanf("%d %d",&a, &b);
	if(a<b){
		printf("a < b\n");
	}
	if(a>b){
		printf("a > b\n");
	}
	if(a==b){
		printf("a == b\n");
	}
	return 0;
}

Measured memory_bytes: 2584
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define mp make_pair
#define ff first
#define ar array
#define ss second
#define ll long long int
#define mem(x) memset(x,0,sizeof(x))
#define setbits(x)  __builtin_popcount(x)
#define ull unsigned long long int
#define all(c) (c).begin(),(c).end()
#define debug(x) cout<<#x<<" :: "<<x<<endl;
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
#define db double
#define endl "\n"
#define  fbo(x) find_by_order(x)
#define  ook(x) order_of_key(x)
 
using namespace __gnu_pbds;
using namespace std;
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef pair<ll,ll > iil;
typedef pair<ll,int> li;
typedef pair<int,int> ii;
typedef tree<int, null_type, less<int>, rb_tree_tag,
            tree_order_statistics_node_update>
    os1;
typedef tree<int, null_type, greater<int>, rb_tree_tag,
            tree_order_statistics_node_update>
    os2;

inline void fast()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}
const ll pi=31;
const ll MOD[2] = {1187278649, 1149736019};//for double hashing
const ll mod=(ll)(1e9)+7;
ll pmod(ll x,ll n){
  ll r=1;
  while(n>0)
  {
    if(n&1LL)
      r=(r*x)%mod;
    x=(x*x)%mod;
    n=n/2;
    n%=mod;
  }
  return r;
}
ll pMod(ll x,ll n,ll mod)
{ ll r=1;
  while(n>0)
  {
    if(n&1LL)
      r=(r*x)%mod;
    x=(x*x)%mod;
    n=n/2;
    n%=mod;
  }
  return r;
 
}
 
//think recursively also;

void solve()
{ 
  double d,t,s;
  cin>>d>>t>>s;
  double t1=(1.0*d)/(s*1.0);
  if(t1<=t)
  {
    cout<<"Yes\n";
  }
  else
  {
    cout<<"No\n";
  }
}
int main()
{
  fast();
   // int t;
   // cin>>t;
   // for(int casee=1;casee<=t;casee++)
  {//cout<<"Case #"<<casee<<": ";
    solve();
  }
 
 
 
}

Measured memory_bytes: 3736
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#define rep(i, n) for(i = 0; i < n; i++)
#define int long long
using namespace std;

int Abs(int x) {
	if (x > 0) return x;
	return -x;
}

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

int INF = 1e+15;
int L;
int a[200000];
int b[200000];
int dp[200001][3][3];	//dp[i][j(非0)][k(odd)] = min_cost

signed main() {
	int i, j, k, l;
	
	cin >> L;
	rep(i, L) {
		cin >> a[i];
		if (a[i] % 2 == 1) b[i] = 1;
		else if (a[i] % 2 == 0 && a[i] >= 2) b[i] = 2;
		else b[i] = 0;
	}
	
	rep(i, L + 1) rep(j, 3) rep(k, 3) dp[i][j][k] = INF;
	dp[0][0][0] = 0;
	
	rep(i, L) {
		//選択肢0
		chmin2(dp[i][0][0] + a[i], dp[i + 1][0][0]);
		chmin2(dp[i][0][1] + a[i], dp[i + 1][0][2]);
		chmin2(dp[i][0][2] + a[i], dp[i + 1][0][2]);
		chmin2(dp[i][1][0] + a[i], dp[i + 1][2][0]);
		chmin2(dp[i][2][0] + a[i], dp[i + 1][2][0]);
		rep(j, 3) {
			rep(k, 3) {
				if (j >= 1 && k >= 1)
					chmin2(dp[i][j][k] + a[i], dp[i + 1][2][2]);
			}
		}
				
		//選択肢1
		rep(j, 2) {
			rep(k, 2) {
				chmin2(dp[i][j][k] + Abs(b[i] - 1), dp[i + 1][1][1]);
			}
		}
		
		//選択肢2
		rep(j, 2) {
			rep(k, 3) {
				if (k == 0) {
					chmin2(dp[i][j][k] + Abs(b[i] - 2), dp[i + 1][1][0]);
				}
				else {
					chmin2(dp[i][j][k] + Abs(b[i] - 2), dp[i + 1][1][2]);
				}
			}
		}
	}
	
	int ans = INF;
	rep(j, 3) rep(k, 3) ans = min(ans, dp[L][j][k]);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 17408
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int main(){
	int n,m;
	string l;
	cin >> n;

	vector<string> s(n);
	for (int i = 0;i<n;i++){
		cin >> l;
		s[i] = l;
	}
	cin >> m;
	vector<string> t(m);
	for (int i = 0;i<m;i++){
		cin >> l;
		t[i] = l;
	}

	int ans = 0;
	for (int i = 0;i<n;i++){
		int counter = 1;
		for(int j = i+1;j< n;j++){
			if (j != i){
				if(s[i] == s[j]){
					counter++;
				}
			}
		}
		for(int k = 0;k<m;k++){
			if (s[i] == t[k]){
				counter--;
			}
		}
		ans = max(ans,counter);
	}
	cout << ans << endl; 
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int h,m,h_2,m_2,k;
    cin >> h >> m >> h_2 >> m_2 >> k;
    int hun_1=h*60+m;
    int hun_2=h_2*60+m_2;
    cout << hun_2-hun_1-k;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n) ;i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b){ a = b; return 1; } return 0; }



int main(int argc, char const *argv[]) {
  int a,b;
  cin >> a >> b;
  cout << max(max(a+b,a-b),a*b) << endl;
  return 0;
}


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

int main() {
    int n;
    int min_num = 200010;
    int ans = 0;
    cin >> n;
    vector<int> p(n);
    rep(i,n) {
        cin >> p[i];
        if(p[i] <= min_num) {
            min_num = p[i];
            ans++;
        }
    } 
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
n = int(input())
c = [tuple(map(int, input().split())) for _ in range(n)]
s = {(0, 0): 0}
for i in range(n):
    for j in range(n):
        if i != j:
            (p, q) = [b - a for a, b in zip(c[i], c[j])]
            s[(p, q)] = s.get((p, q), 0) + 1
print(n - max(s.values()))

Measured memory_bytes: 40944
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main(void){
    char S[10],T[10],U[10];
    int A,B;
    scanf("%s%s",S,T);
    scanf("%d%d",&A,&B);
    scanf("%s",U);
   
   if(*S==*U){
       A = A-1;
   }
   else{
       B=B-1;
   }
   printf("%d %d\n",A,B);
    return 0;
}

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

class Dice{
	public:
		Dice(){
			num = new int[6];
			s = new int[6];
		};
		void setlabel(int n,int number){
			num[n] = number;
		}
		void roll(char ch){
			for(int i=0;i<6;i++){
				s[i] = num[i];
			}
			switch(ch){
				case 'N':
					changenum(s[1],s[5],s[2],s[3],s[0],s[4]);
					break;
				case 'E':
					changenum(s[3],s[1],s[0],s[5],s[4],s[2]);
					break;
				case 'S':
					changenum(s[4],s[0],s[2],s[3],s[5],s[1]);
					break;
				case 'W':
					changenum(s[2],s[1],s[5],s[0],s[4],s[3]);
					break;
			}
		};
		int top(){
			return num[0];
		}
	private:	
		void changenum(int n1,int n2,int n3,int n4,int n5,int n6){
			num[0] = n1;
			num[1] = n2;
			num[2] = n3;
			num[3] = n4;
			num[4] = n5;
			num[5] = n6;
		};
		
	private:
		int* num;
		int* s;
};


int main() {
	Dice dice;
	int label;
	char ch;
	for(int i=0;i<6;i++){
		cin >> label;
		dice.setlabel(i,label);
	}
	while(cin>>ch){
		dice.roll(ch);
	}
	cout << dice.top() << endl;
	return 0;
}


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

int main() {
 
  int n,a ;
  cin >>n;
  int P[n];
  a =0 ;
  for (int i = 0; i < n; i++){
    cin >>P[i];
  }
   for (int i = 1; i < n-1; i++){
    if((P[i-1]<P[i]&&P[i]<P[i+1])||(P[i-1]>P[i]&&P[i]>P[i+1])){
      a++;
    }
    }
     cout << a << endl;
  }



Measured memory_bytes: 256
n = gets.to_i
as = gets.strip.split.map(&:to_i)
as.unshift(0)
as << 0

total = 0
for i in 0..n
  total += (as[i] - as[i + 1]).abs
end

(1..n).each do |i|
  c1 = (as[i - 1] - as[i]).abs + (as[i] - as[i + 1]).abs
  c2 = (as[i - 1] - as[i + 1]).abs
  puts (total - c1 + c2)
end


Measured memory_bytes: 12548
#include <bits/stdc++.h>
using namespace std;
#define fastIO ios::sync_with_stdio(0), cin.tie(0)
#define endl '\n'
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin, (x).rend()
typedef long long ll;
typedef pair<int,int> pii;

void A(){
	int a,b; cin>>a>>b;
	int cnt=0;
	while(a>0){
		a-=b;
		cnt++;
	}
	cout<<cnt<<endl;
	
}

void B(){
	int a,b,x,t=0;
	cin>>a>>b;
	while(b--){
		cin>>x;
		t+=x;
	}
	cout<<(t>=a?"Yes":"No")<<endl;
}void C(){
	int n,k; cin>>n>>k;
	int arr[n];
	for(int i=0; i<n; i++){
		cin>>arr[i];
	}
	sort(arr, arr+n);
	ll ans = 0;
	for(int i=0; i<(n-k); i++){
		ans+=arr[i];
	}
	cout<<ans<<endl;
}

int main(){
	ll h,cnt=0; cin>>h;
	while(h>0){
		h/=2; 
		cnt++;
	}
	ll ans = pow(2, cnt)-1;
	cout<<ans<<endl;
}


Measured memory_bytes: 4060
package main

import "fmt"

var N, M int
var a []int
func main() {
	fmt.Scan(&N, &M)
	a = make([]int, M)
	for i := range a {
		fmt.Scan(&a[i])
	}
	ans := N
	for i := range a {
		ans -= a[i]
	}
	if ans < 0 {
		fmt.Println(-1)
	} else {
		fmt.Println(ans)
	}
}


Measured memory_bytes: 2448
#include<stdio.h>


int main(void)
{
    int i=0, n;
    char s[5];

    scanf("%s",s);

    while(s[i]!='\0'){
        if(s[i]=='+')
            n++;
        else if(s[i]=='-')
            n--;
        i++;
    }

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

    return 0;
}


Measured memory_bytes: 128
#!/usr/bin/env ruby

# k = gets.chomp.split(' ').map(&:to_i)

# if k[0] == k[2] * 2 && k[1] == k[3] * 2
#   puts "#{k[0] * k[1] /2} 1"
# else
#   puts "#{k[0] * k[1] /2} 0"
# end


k = gets.chomp.split.map(&:to_i)

puts k[0] >= k[1] ? '10' : '0'

Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    string s,t,u="";
    cin>>s>>t;
    for(int i=0;i<s.size()+t.size();i++)
    {
        if(i%2==0) u+=s[i/2];
        else u+=t[i/2];
    }
    cout<<u<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
int main(){
  int n,d;
  cin >> n >> d;
  int ans = (n+2*d+0.99)/(2*d+1);
  cout << ans << endl;
}

Measured memory_bytes: 256
import qualified Data.ByteString.Char8 as BS
import Data.List (group, sort, sortBy)

main = do
  n <- getLine
  s <- BS.lines <$> BS.getContents
  mapM_ (\x -> putStrLn $ BS.unpack $ fst x)
        $ sort
        $ removeExceptMax
        $ map (\list -> (head list, length list))
        $ group
        $ sort s

removeExceptMax :: [(BS.ByteString, Int)] -> [(BS.ByteString, Int)]
removeExceptMax xs =
  filter (\x -> snd x == m) xs 
  where
    m = maximum $ map snd xs

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

int main(){
  string s;
  cin>>s;
  map<char,ll> m;
  for(ll i=0;i<s.size();i++) m[s[i]]++;
  ll ans=INF,cnt,x;
  for(auto a:m){
      cnt=0;
      x=0;
      for(ll i=0;i<s.size();i++){
          if(a.first==s[i]){
              if(x>cnt) cnt+=x-cnt;
              x=0;
          }else x++;
      }
      if(x>cnt) cnt+=x-cnt;
      chmin(ans,cnt);
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define for0(n) for(i=0; i<(n); i++)
#define for1(n) for(i=1; i<=(n); i++)


int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll _,i,j,n,a,b,e,k,u,t,x=1,m,y,q,f=1,c=0,d=0,l,p,z,o,r,g;
    string ss,s;
    cin>>n>>m;
    if(m/4==n&&m%4==0)c=1;
    while(n--&&m>0)
    {
        m-=2;
        if(m/4==n&&m%4==0)c=1;
    }
    if(c)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}



Measured memory_bytes: 3616
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        var nums = Console.ReadLine().Split(' ');

        var n = int.Parse(nums[0]);
        var k = int.Parse(nums[1]);

        nums = Console.ReadLine().Split(' ');

        var array = new int[200001];

        var p = 1;
        foreach(var num in nums)
        {
            array[p] = int.Parse(num);
            p++;
        }

        for (var i = k + 1; i <= n; i++)
        {
            var scoreCurrent = array[i];
            var scoreOld = array[i - k];
            if(scoreCurrent > scoreOld)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }




        Console.ReadLine();
    }


}




Measured memory_bytes: 43508
def examC():
    N = I()
    a = LI()
    d = defaultdict(int)
    for i in a:
        d[min(i//400,8)] += 1
    ansL = len(d)
    ansR = len(d)
    if d[8]!=0:
        ansL = max(ansL-1,1)
        ansR = ansR + d[8]-1
    print(ansL, ansR)


import sys
import copy
import bisect
import heapq
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examC()

Measured memory_bytes: 38512
#include <stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h> 
#define ll unsigned long long
#define length 100000   //10万
#define kw_len 10
ll factor[1000]; 
ll memory[1000];
int primefac(ll num){
    int i = 0,kosuu=0,flag=0,sum,n=0;
    while(*(factor+i) != 0){
        sum =1;
        flag=0;
        while(num % *(factor+i)==0){
            num /= *(factor+i);
            memory[*(factor+i)] +=1;
        }
        i++;
    }
    return sum;
}

/*グローバルにあるfactorに素数書き込む.個数を返すので配列は-1しろ*/
int elast(ll number){    
    ll tmp=0;
    int flag=0;
    *factor = 2;
    for(int i=3;i <= number;i++){
        flag=0;
        for(int j=0;j <= tmp ;j++){
            if(i % (*(factor+j)) == 0){
                flag=1;
                break;
            }
        }
        if(flag)continue;
        tmp += 1;
        *(factor+tmp) = i;
    }
        return tmp+2;
}



ll nCr(int n,int r){
  ll val=1;
  int i;
  if(r==0)return 1;
  for(i=0;i<n-r;i++){
		val *= (n-i);
		val /= (i+1);
	}
  return val;
}

ll nPr(int n,int r){
  ll val=1;
  int i;
  for(i=0;i<r;i++){
    val *= (n-i);
  }
  return val;
}

int main(){
    ll three=0,nago=0,nigo=0,igo=0;
    ll five=0;
    ll N,i,j;
    ll sum=0;
    memset(factor ,0, sizeof(factor));
    memset(memory,0,sizeof(memory));
    scanf("%llu",&N);
    elast(N);
    for(i=1;i<N;i++){
      primefac(i+1);
    }
    for(i=0;i<N;i++){
      if(memory[i]+1>=75)nago++;
      if(memory[i]+1>=25)nigo++;
      if(memory[i]+1>=15)igo++;
      if(memory[i]+1>=5){
        five++;
        three++;
      }
      else if(memory[i]+1>=3){
        three++;
      }
    }
    if(three>=2){
     sum += nCr(five,2)*(three-2);
     sum +=nago;
     sum += nigo*(three-1);
     sum += igo*(five-1);
    }
    printf("%llu",sum);

    return 0;
}


Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var NM = ReadInts();
            int[] wa = new int[NM[0]+1];
            int[] ac = new int[NM[0]+1];

            var Count_AC = 0;
            var Count_WA = 0;

            for (int i = 0; i < NM[1]; i++)
            {
                var pS = Reads();
                var p = int.Parse(pS[0]);
                var S = pS[1];

                if(ac[p] == 0)
                {
                    if (S == "WA")
                    {
                        wa[p]++;
                    }
                    else
                    {
                        ac[p]=1;
                        Count_WA += wa[p];
                        Count_AC++;
                    }
                }
            }

            WriteLine($"{Count_AC} {Count_WA}");
        }
        private static string Read() { return ReadLine(); }
        private static string[] Reads() { return (Read().Split()); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 17760
#include <stdio.h>
int main(){
  int n,m,k,a[50]={0};
  scanf("%d%d",&n,&m);
  for(int i=0;i<m*2;i++){
    scanf("%d",&k);
    a[k-1]++;
  }
  for(int i=0;i<n;i++)printf("%d\n",a[i]);
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <map>

using namespace std;

int main() {
    int n;
    cin >> n;
    long x[n];
    long y[n];
    for (int i=0; i<n; i++) {
        cin >> x[i] >> y[i];
    }
    long p, q;
    int maxNum=0;
    _Rb_tree_iterator<pair<pair<int, int> const, int>> maxIt;

    map<pair<int, int>, int> pqMap;
    for (int i=0; i<n; i++) {
        for(int j=0; j<n; j++) {
            if (i==j) continue;
            p = x[i] - x[j];
            q = y[i] - y[j];
            const auto& temp = pqMap.insert(make_pair(make_pair(p,q), 1));
            if(!temp.second){
                ++temp.first->second;
            }
            if(temp.first->second > maxNum) {
                maxNum = temp.first->second;
            }
        }
    }
    cout << n - maxNum << endl;
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	ll n;
	cin>>n;
	ll a[n];
	for(int i=0;i<n;i++)
	  cin>>a[i];
	ll c1=0,c2=0,sum=0;
	for(int i=0;i<n;i++){
		if(i%2==0){
			sum=sum+a[i];
			if(sum<0)
			  continue;
			c1+=abs(-1-sum);
			sum=-1;
		}
		else{
			sum=sum+a[i];
			if(sum>0)
			  continue;
			c1+=abs(1-sum);
			sum=1;
		}
	}
	sum=0;
	for(int i=0;i<n;i++){
		if(i%2==1){
			sum=sum+a[i];
			if(sum<0)
			  continue;
			c2+=abs(-1-sum);
			sum=-1;
		}
		else{
			sum=sum+a[i];
			if(sum>0)
			  continue;
			c2+=abs(1-sum);
			sum=1;
		}
	}
	cout<<min(c1,c2)<<endl;
	return 0;
}

Measured memory_bytes: 1024
def c_attention(N, S):
    count_east = [0] * N  # i番より西にいる人のうち西向きの人数
    count_west = [0] * N  # i番より東にいる人のうち東向きの人数

    for k in range(N - 2, -1, -1):
        count_east[k] = count_east[k + 1] + 1 \
            if S[k + 1] == 'E' else count_east[k + 1]
    for k in range(1, N):
        count_west[k] = count_west[k - 1] + 1 \
            if S[k - 1] == 'W' else count_west[k - 1]

    count = [0] * N  # i番は、i番の人を向いていない人数
    for k in range(N):
        count[k] = count_east[k] + count_west[k]
    ans = min(count)
    return ans

N = int(input())
S = input().strip()
print(c_attention(N, S))

Measured memory_bytes: 29472
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto N = readln.chomp.to!int;
    auto AS = readln.split.to!(int[]);
    sort(AS);
    foreach (i; 0..N-1) if (AS[i] == AS[i+1]) {
        writeln("NO");
        return;
    }
    writeln("YES");
}

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

int main() {
  int N;
  cin >> N;
  vector<int> a(N+1);
  for (int i=1; i<=N; i++) cin >> a[i];
  vector<int> v(N+1, 0); // 光ったボタン

  int now = a[1];
  v[1] = 1;
  int cnt = 1;
  while (true) {
    if (now == 2) {
      break;
    } else {
      if (v[now] != 0 || cnt > N) {
        cnt = -1;
        break;
      } else {
        v[now] = 1;
        now = a[now];
        cnt++;
      }
    }
  }

  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;


int main(){
  ll n,x,y; cin >> n >> x >> y; vl count(n);
  
  for(ll i=1; i < n+1; i++){
    for(ll j=1; j < n+1; j++){
      if(i < j){
      ll t; ll g = j-i;
      t = min(g,abs(i-x)+1+abs(y-j));
      count[t]++;
      }
    }
  }
  
  for(ll i=1; i < n; i++){
    cout << count[i] << endl;
  }
}

Measured memory_bytes: 256
HWK = input().split()
H = int(HWK[0])
W = int(HWK[1])
K = int(HWK[2])

image = [0]*H*W
# black : 0
# white : 1
# red : 2
for row in range(H):
    c_values = input()
    for col in range(W):
        if c_values[col] == ".":
            image[W*row + col] = 1
        if c_values[col] == "#":
            image[W*row + col] = 0

result = 0
for i in range(2**H):
    for j in range(2**W):
        rows = [int(x) for x in bin(i)[2:]] # 0 : remove, 1 : keep
        rows = max((H - len(rows)), 0)*[0] + rows

        cols = [int(x) for x in bin(j)[2:]]
        cols = max((W - len(cols), 0))*[0] + cols
        # print(cols)
        count_black = 0
        for row in range(H):
            for col in range(W):
                if rows[row] == 0:
                    continue
                if cols[col] == 0:
                    continue
                if image[row*W + col] == 0:
                    count_black += 1
        if count_black == K:
            result += 1



print(result)

Measured memory_bytes: 9204
#include<cstdio>
#include<cstdlib>
#include<string>
#include<iostream>
using namespace std;

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

Node *root, *NIL;

Node *find(Node *u,int k){
  while((u != NIL) && (k!=u->key)){
    if(k < u->key) u = u->left;
    else u = u->right;
  }
  return u;
}
void insert(int k){
  Node *y = NIL;
  Node *x = root;
  Node *z;

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

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

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

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

int main(){
  int n,i,x;
  string com;

  scanf("%d",&n);

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



Measured memory_bytes: 22076
#define _CRT_SECURE_NO_WARNINGS // #pragma warning(disable:4996)
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <functional>
#include <sstream>
#include <cmath>
#include <set>
#include <map>
#include <stack>
using namespace std; 

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define pb push_back
#define mp(a,b) make_pair(a,b)
#define all(a) a.begin(),a.end()
#define len(x) ((int)(x).size())
#define tmax(a,b,c) max((a),max((b),(c)))
#define tmin(a,b,c) min((a),min((b),(c)))
#define debug(x) cerr << #x << " is " << x << endl;

typedef pair<int, int> Pii;
typedef vector<int> Vi;
typedef vector<vector<int> > VVi;
typedef long long ll;
const int inf = 2e9;
const ll ll_inf = 1e17;
const int mod = 1e9 + 7;
const long double eps = 1e-10;

int main()
{
	while(1) {
		int h, w;
		cin >> h >> w;
		if (!h && !w) break;
		int q = h*h + w*w;
		int ans = inf;
		Pii pos = mp(inf, inf);
		rep(i,1,151) {
			rep(j,i+1,152) {
				int x = i*i + j*j;
				if (x < q) continue;
				if (x == q && i <= h) continue;
				
				if (x < ans) {
					ans = x;
					pos = mp(i,j);
				}
				else if (x == ans && i < pos.first) {
					pos = mp(i,j);
				}
			}
		}
		cout << pos.first << " " << pos.second << endl;
	}

	return 0;
}

Measured memory_bytes: 1160
c = []
for _ in range(3):
    c.append(tuple(map(int, input().split())))

#print(c)

for a1 in range(0,1):
    b1=c[0][0]-a1
    b2=c[0][1]-a1
    b3=c[0][2]-a1
    a2=c[1][0]-b1
    a3=c[2][0]-b1
    if c[1][1]==a2+b2 and c[1][2]==a2+b3 and c[2][1]==a3+b2 and c[2][2]==a3+b3:
        print('Yes')
        #print(b1,b2,b3,a1,a2,a3)
        break
else:
    print('No')


Measured memory_bytes: 3064
n=int(input())
a_list=list(map(int,input().split()))
A_list=[format(a_list[i],'b').zfill(20) for i in range(n)]
count=[0]*20
r=0
ans=0
for l in range(n):
    while not 2 in count and r<=n-1:
        for j in range(20):
            count[j]=count[j]+int(A_list[r][j])
        r=r+1
    if not 2 in count:
        ans=ans+n-l
    else:
        ans=ans+r-l-1
    for j in range(20):
        count[j]=count[j]-int(A_list[l][j])
print(ans)

    


Measured memory_bytes: 106444
S = input()
l = len(S)
a = [0]
b = [0]*2019
c = [1]
d = 0
e = 0
for n in range(l-1):
    c.append(c[n]*10%2019)
for n in range(l):
    d += int(S[-n-1])*c[n]
    a.append(d%2019)
for n in range(l+1):
    b[a[n]] += 1
for n in range(2019):
    e += int(b[n]*(b[n]-1)/2)
print(e)

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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

int main() {
  int n, m, a, b;
  cin >> n >> m;
  vector<int> vb;
  unordered_multimap<int, int> ummp;
  vector<pair<int, int>> vp;

  rep(i, m) {
    cin >> a >> b;
    if (a == 1)
      vb.emplace_back(b);
    else
      // vp.emplace_back(a, b)
      ummp.emplace(a, b);
  }

  bool flg = false;
  for (auto x : vb) {
    auto range = ummp.equal_range(x);
    for (auto iterator = range.first; iterator != range.second; iterator++) {
      auto target = *iterator;
      if (target.second == n) {
        cout << "POSSIBLE";
        return 0;
      }
    }
  }

  cout << "IMPOSSIBLE" << endl;
  return 0;
}


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

int main(int argc, char const *argv[]) {
  int h, w;
  string a;
  cin >> h >> w;
  for (int i = 0;i < h;i++) {
    cin >> a;
    if(i == 0) {
      for(int u = 0;u < a.size() + 2;u++) {
        cout << "#";
      }
      cout << endl;
    }
    cout << "#" << a << "#" << endl;
    if(i == h - 1) {
      for(int u = 0;u < a.size() + 2;u++) {
        cout << "#";
      }
      cout << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 256
"""

AtCoder Beginner Contest 127  E - Cell Distance


x,yは独立して考えられるので分ける。
差分の絶対値の和の問題は
ある項について、＋として働くのが何回か、－として働くのが何回か
を考えてその分を足してあげればいい

例1の 2 x 2で考えると、x=2,y=1のについて、
xが＋に働くのは、x=2より小さい、(x,y)=(1,1),(1,2)
xが±0なのは、xが同じ、(x,y)=(2,2)
xが－に働くのはなし（x=2までなので）
的な。



Kについて考えると、ある駒a,b間のコストが求められる回数は、nCr(N*M-2, K-2)
（全部でK個選ぶときにa,bを先に選んで、残りのN-2からK-2個選ぶから。）

N x Mのマスで、(ax,ay)の物のコストについて、
X：+ax*(ax - 1) * N - ax * (M - ax) * N = ax*N*(ax-1-M+ax) = ax*N*(2ax-1-M)
これがマスの高さの分だけある(ayが1~Nまで)&これがnCr(N*M-2, K-2)回
Yも同様
"""


N,M,K = map(int, input().split())

MOD = 10**9+7
 
MAXN = N*M + 10
fac = [1,1] + [0]*MAXN
finv = [1,1] + [0]*MAXN
inv = [0,1] + [0]*MAXN
for i in range(2,MAXN+2):
    fac[i] = fac[i-1] * i % MOD
    inv[i] = -inv[MOD%i] * (MOD // i) % MOD
    finv[i] = finv[i-1] * inv[i] % MOD
 
def nCr(n,r):
    if n < r: return 0
    if n < 0 or r < 0: return 0
    return fac[n] * (finv[r] * finv[n-r] % MOD) % MOD


#X：+ax*(ax - 1) * N - ax * (M - ax) * N = ax*N*(ax-1-M+ax) = ax*N*(2ax-1-M)がN個＆nCr(N*M-2, K-2))回
ans = 0

for i in range(1,M+1):
    tmp = (((((i * N) % MOD) * (2*i - 1 - M)) % MOD) * N) % MOD
    
    #print("~~~", i*N, 2*i - 1 - M,tmp, nCr(N*M-2, K-2))

    tmp *= nCr(N*M-2, K-2)

    tmp %= MOD
    #print("pppp", tmp)
    ans += tmp

    ans %= MOD


for i in range(1,N+1):
    tmp = (((((i * M) % MOD) * (2*i - 1 - N)) % MOD) * M) % MOD

    tmp *= nCr(N*M-2, K-2)

    tmp %= MOD
    ans += tmp
    ans %= MOD


print(ans)


Measured memory_bytes: 28248
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        Set<String> dicionary = new HashSet<>();
        for (int i = 0; i < n; i++) {
            String s1 = scanner.next();
            String s2 = scanner.next();
            if (s1.equals("insert")) {
                dicionary.add(s2);
            }
            else {
                System.out.println(dicionary.contains(s2) ? "yes" : "no");
            }
        }
    }
}


Measured memory_bytes: 254736
import queue

"""
N = int(input())
#S = input()
# (N,M) = (int(i) for i in input().split(" "))
# A = [int(i) for i in input().split()]
A = []
for i in range(N):
	A.append(int(input()))

print(A)

"""

(N,D) = (int(i) for i in input().split(" "))
X = [[int(t) for t in input().split()]for i in range(N)]

def dist(A,B,D):
	C = 0
	for i in range(D):
		C += (A[i]-B[i])**2
	return C**.5
ans = 0
for i in range(N-1):
	for j in  range(i+1, N):
		dis = dist(X[i],X[j],D)
		if dis == int(dis):
			ans += 1
print(ans)

Measured memory_bytes: 3952
use std::io::*;

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let d: usize = itr.next().unwrap().parse().unwrap();
    let g: usize = itr.next().unwrap().parse().unwrap();
    let mut p: Vec<usize> = vec![0; d];
    let mut c: Vec<usize> = vec![0; d];
    for i in 0..d {
        p[i] = itr.next().unwrap().parse().unwrap();
        c[i] = itr.next().unwrap().parse().unwrap();
    }

    let mut ans = 1 << 30;
    for bit in 0..1 << d {
        let mut cnt = 0;
        let mut tmp = 0;
        for i in 0..d {
            if bit >> i & 1 == 1 {
                tmp += p[i] * 100 * (i + 1) + c[i];
                cnt += p[i];
            }
        }
        if tmp >= g {
            ans = std::cmp::min(ans, cnt);
        } else {
            for i in (0..d).rev() {
                if bit >> i & 1 == 0 {
                    if tmp + p[i] * 100 * (i + 1) < g {
                        tmp += p[i] * 100 * (i + 1);
                        cnt += p[i];
                    } else {
                        cnt += (g - tmp + 100 * i) / (100 * (i + 1));
                        tmp = g + 1;
                        break;
                    }
                }
            }
            if tmp >= g {
                ans = std::cmp::min(ans, cnt);
            }
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
my $s = <>;
chomp $s;
my $Q = <>;
my $stat = 0;
my $fstr="";
for(my $i=0;$i<$Q;$i++){
    my @dat = split(/\s+/,<>);
    if($dat[0]==1){
        if($stat){
            $stat = 0;
        }else{
            $stat = 1;
        }
    }else{
      if(($dat[1]+$stat)%2){
        $fstr .= "$dat[2]";
      }else{
        $s = "$s$dat[2]";
      }
    }
}
$fstr = reverse($fstr);
$s = "$fstr$s";

if($stat==1){
    $s = reverse($s);
}
print "$s";


Measured memory_bytes: 1788
#include<bits/stdc++.h>
#define Mx 1000000000005 
#define ll long long  
#define pi 3.141592653
#define vi vector<ll>
#define Mo 1000000007
#define mp make_pair
#define M map<ll,ll>
#define fr(i,a,b) for(ll i=a;i<b;i++)
#define vii vector<pair<ll,ll> > 
#define fi first
#define se second
#define pb push_back
#define ld long double
#define fill(a,x) memset(a,x,sizeof(a))
using namespace std;
bool comp(const pair<ll,ll> &a, const pair<ll,ll> &b)
{
  return a.second<b.second;
}
/*vi b=v;
   sort(b.begin(), b.end());
  b.resize(unique(b.begin(), b.end()) - b.begin());
  ll t; cin>>t; fr(f,0,t){ 
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
 */
int main()
{
  ll n,m; cin>>n>>m;
  char a[n][m];
  fr(i,0,n)
    fr(j,0,m)
      cin>>a[i][j];

  vector<vector<ll>> dp(n+1,vector<ll>(m+1,0));

  fr(j,1,m+1)
  {
    if(a[0][j-1]=='.') dp[1][j]=1;
    else break;
  }
  fr(i,1,n+1)
  {
    if(a[i-1][0]=='.') dp[i][1]=1;
    else break;
  }

  fr(i,2,n+1)
  {
    fr(j,2,m+1)
    {
      if(a[i-2][j-1]=='.') dp[i][j]+=dp[i-1][j];
      if(a[i-1][j-2]=='.') dp[i][j]+=dp[i][j-1];
      dp[i][j]%=Mo;
    }
  }

  cout<<dp[n][m];
}

Measured memory_bytes: 12180
#include <iostream>
#include <map>
using namespace std;
int main(){
        int n;
        cin >> n;
        int a[n];
        map<int,int> m;
        for(int i=0; i<n; i++) {
                cin >> a[i];
                m[a[i]]++;
        }
        int ans=0;
        for(auto p:m) {
                int x=p.first;
                int n=p.second;
                if(n<x) ans+=n;
                else ans+=n-x;
        }
        cout << ans <<endl;
}


Measured memory_bytes: 5120
#include <bits/stdc++.h>
#define bug(x) cout << #x << " = " << x << endl
using namespace std;
typedef long long int ll;
ll n,m,x[100005],y[100005],mod = 1e9+7, xsum=0,ysum=0,Ti=0,t;
int main(){
    cin>>n>>m;
    for(int i=1;i<=n;i++) cin>>x[i];
    for(int i=1;i<=m;i++) cin>>y[i];
    sort(x+1,x+n+1);
    sort(y+1,y+m+1);
    t=1;
    for(int i=m;i>1;i--){
        ysum+=(y[i]-y[i-1])*(i-1)*t;
        t++;
        ysum%=mod;
    }
    t=1;
    for(int i=n;i>1;i--){
        xsum+=(x[i]-x[i-1])*(i-1)*t;
        t++;
        xsum%=mod;
    }
    Ti=xsum*ysum;
    Ti%=mod;
    cout<<Ti<<endl;
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>

using namespace std;

int main()
{
    int N;
    cin >> N;
    int B[N - 1];
    for (int i = 0; i < N - 1; i++)
    {
        cin >> B[i];
    }
    long sum = B[0] + B[N - 2];
    for (int i = 1; i < N - 1; i++)
    {
        sum += min(B[i - 1], B[i]);
    }
    cout << sum << endl;
}


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

const int N = 21;
int dp[N + 1][(1 << N) + 1];
int a[N + 1][N + 1];
#define pb push_back
vector <int> adj[N];
const int MOD = 1e9 + 7;

int recur(int id, int n, int mask, int totMask)
{
    //cout << id << " " << mask << "\n";

    if(id == n)
    {
        if(mask == totMask)
            return 1;
        return 0;
    }

    if(dp[id][mask] != -1)  
        return dp[id][mask] % MOD;

    int ways = 0;

    for(auto i : adj[id])
    {
        if(mask & (1 << i))
            continue;
        
        ways += recur(id + 1, n, mask | (1 << i), totMask);
    }
    return dp[id][mask] = ways % MOD;
}

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

    //cout << n << "\n";
    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < n; j++)
        {
            cin >> a[i][j];
            //cout << a[i][j] << "\n";
            if(a[i][j] == 1)
            {
                adj[i].pb(j);
            }
        }
    }

    int totMask = (1 << n) - 1;
    memset(dp, -1, sizeof(dp));

    cout << recur(0, n, 0, totMask) << "\n";
}

Measured memory_bytes: 360704
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int X,Y,x[1005],y[1005];
ll dis(int a,int b){return 1ll*abs(a-X)+abs(b-Y);}
int main()
{
    int n,t0=0,t1=0;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d%d",&x[i],&y[i]);
        if((x[i]+y[i])&1)t1=1;
        else t0=1;
    }
    if(t0&&t1){puts("-1");return 0;}
    printf("%d\n",31+t0);
    if(t0)printf("1 ");
    for(int i=30;i>=0;i--)printf("%d ",1<<i);
    puts("");
    for(int i=1;i<=n;i++)
    {
        if(t0)putchar('L'),x[i]++;
        int nx=0,ny=0;X=x[i],Y=y[i];
        for(int k=30;k>=0;k--)
        {
            ll d1=dis(nx+(1<<k),ny),d2=dis(nx-(1<<k),ny),
            d3=dis(nx,ny+(1<<k)),d4=dis(nx,ny-(1<<k)),mn=min(d1,min(d2,min(d3,d4)));
            if(mn==d1)putchar('R'),nx+=(1<<k);
            else if(mn==d2)putchar('L'),nx-=(1<<k);
            else if(mn==d3)putchar('U'),ny+=(1<<k);
            else putchar('D'),ny-=(1<<k);
        }
        puts("");
    }
    return 0;
}

Measured memory_bytes: 3828
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mx 4000007
#define mod 1000000007
int main()
{
    ll a,b,c;
    cin>>a>>b>>c;
    if(a==b)
    {
        cout<<c<<endl;
    }
    else if(b==c)
    {
        cout<<a<<endl;
    }
    else
    {
        cout<<b<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <climits>
#include <string>
#include <queue>
#include <vector>
#include <set>
#include <unordered_map>
using namespace std;

int main() {
  int N;
  cin >> N;
  int smax = 0;
  for (int i = 1; ; i++) {
    if (i * i > N) {
      cout << (i - 1) * (i - 1) << endl;
      return 0;
    }
  }
}


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

int main()
{
  string s;
  cin >> s;
  for(int i = 0; i < s.size() - 1; i++)
  {
    if(s[i] == 'A' && s[i + 1] == 'C')
    {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3604
A_list = []

def my_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default

for i in range(3):
  a, b, c = map(int, input().split())
  A_list.append(a)
  A_list.append(b)
  A_list.append(c)

N = int(input())
flag=True

for i in range(N):
  num = int(input())

  tmp = my_index(A_list, num, -100)
  if tmp != -100:
    A_list[tmp] = -1
  
  if ((A_list[0] == A_list[3]) and (A_list[0] == A_list[6]) and (A_list[3] == A_list[6])) or \
     ((A_list[1] == A_list[4]) and (A_list[1] == A_list[7]) and (A_list[4] == A_list[7])) or \
     ((A_list[2] == A_list[5]) and (A_list[2] == A_list[8]) and (A_list[5] == A_list[8])) or \
     ((A_list[0] == A_list[4]) and (A_list[0] == A_list[8]) and (A_list[4] == A_list[8])) or \
     ((A_list[2] == A_list[4]) and (A_list[2] == A_list[6]) and (A_list[4] == A_list[6])) or \
     ((A_list[0] == A_list[1]) and (A_list[0] == A_list[2]) and (A_list[1] == A_list[2])) or \
     ((A_list[3] == A_list[4]) and (A_list[3] == A_list[5]) and (A_list[4] == A_list[5])) or \
     ((A_list[6] == A_list[7]) and (A_list[6] == A_list[8]) and (A_list[7] == A_list[8])):
    print("Yes")
    flag=False
    break

if flag:
  print("No")


Measured memory_bytes: 3188
x, n = map(int, input().split())
p = list(map(int, input().split()))

candidates = list(map(lambda elm: (abs(x - elm), elm), range(102)))
for p_i in p:
    candidates[p_i] = (10000, p_i)

sorted_candidates = sorted(candidates, key=lambda elm: elm[0])
min_val = sorted_candidates[0][0]
res = []
for candidate in sorted_candidates:
    if min_val == candidate[0]:
        res.append(candidate[1])
print(sorted(res)[0])


Measured memory_bytes: 62020
import math
from collections import deque
N,D,A = map(int,input().split(' '))
XHn = [ list(map(int,input().split(' '))) for _ in range(N)]
ans = 0
XHn.sort()
attacks = deque([]) # (区間,攻撃回数)
attack = 0
ans = 0
for i  in range(N):
    x = XHn[i][0]
    h = XHn[i][1]
    while len(attacks) > 0 and x > attacks[0][0]:
        distance,attack_num = attacks.popleft()
        attack -= attack_num*A
    if h > attack:
        diff = h - attack 
        distance_attack = x + D*2
        need_attack = math.ceil(diff/A)
        attacks.append((distance_attack,need_attack))
        attack += A*need_attack
        ans += need_attack
print(ans)

Measured memory_bytes: 92120
#define LL unsigned long long
#include <bits/stdc++.h>

using namespace std;

const int N=1<<9,B=65537;

set<LL> st;
LL pw[N]={1};
int n,a[N],cnt[N],S[N];

struct Node
{
	vector<int> v;
	Node(vector<int>& t)
	{
		for(int i=0;i<t.size();i++)
			v.push_back(t[i]);
	}
	bool operator<(const Node f)const
	{
		assert(v.size()==f.v.size());
		for(int i=0;i<v.size();i++)
			if(v[i]!=f.v[i]) return v[i]<f.v[i];
		assert(0);
	}
};

vector<Node> v;

void Init()
{
	for(int i=1;i<N;i++)
		pw[i]=pw[i-1]*B;
}

bool update(int l,int r,int u,int val)
{
	for(int i=0;i<=n;i++)
		if(i<=l || i>=r)
		{
			int p=i<=l?S[u]-S[i]:S[i]-S[u];
			if(val==-1 && (p<0 || !cnt[p]))
			{
				for(int j=0;j<i;j++)
					if(j<=l || j>=r) cnt[abs(S[j]-S[u])]++;
				return 0;
			}
			else
				cnt[p]+=val;
		}
	return 1;
}

void dfs(int u,int l,int r,LL H)
{
	if(st.find(H)!=st.end())
		return;
	st.insert(H);

	if(r-l==1)
	{
		vector<int> t;
		for(int i=0;i<=n;i++)
			t.push_back(S[i]);
		v.push_back(t);
	}
	else
	{
		for(;!cnt[a[u]];u++);

		S[l+1]=a[0]-a[u];
		if(update(l,r,l+1,-1))
		{
			dfs(u+1,l+1,r,H+S[l+1]*pw[l+1]);
			update(l,r,l+1,1);
		}

		S[r-1]=a[u];
		if(update(l,r,r-1,-1))
		{
			dfs(u+1,l,r-1,H+S[r-1]*pw[r-1]);
			update(l,r,r-1,1);
		}
	}
}

int main()
{
	for(Init();cin>>n,n;)
	{
		n--,v.clear(),st.clear();
		memset(cnt,0,sizeof(cnt));
		for(int i=0;i<n*(n+1)/2;i++)
			scanf("%d",a+i),cnt[a[i]]++;

		S[n]=a[0],dfs(1,0,n,S[n]*pw[n]);

		sort(v.begin(),v.end());
		for(int i=0;i<v.size();i++)
		{
			vector<int>& t=v[i].v;
			for(int j=1;j<t.size();j++)
				printf("%d%c",t[j]-t[j-1]," \n"[j==n]);
		}
		puts("-----");
	}
}

Measured memory_bytes: 3312